Passed
Push — master ( c93677...8aa7be )
by Brian
10:03 queued 04:50
created
widgets/subscriptions.php 2 patches
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -46,25 +46,25 @@
 block discarded – undo
46 46
         parent::__construct( $options );
47 47
     }
48 48
 
49
-	/**
50
-	 * The Super block output function.
51
-	 *
52
-	 * @param array $args
53
-	 * @param array $widget_args
54
-	 * @param string $content
55
-	 *
56
-	 * @return mixed|string|bool
57
-	 */
49
+    /**
50
+     * The Super block output function.
51
+     *
52
+     * @param array $args
53
+     * @param array $widget_args
54
+     * @param string $content
55
+     *
56
+     * @return mixed|string|bool
57
+     */
58 58
     public function output( $args = array(), $widget_args = array(), $content = '' ) {
59 59
 
60
-	    ob_start();
60
+        ob_start();
61 61
 
62
-	    do_action( 'wpinv_before_user_subscriptions' );
63
-	    wpinv_get_template_part( 'wpinv-subscriptions-history' );
64
-	    do_action( 'wpinv_after_user_subscriptions' );
62
+        do_action( 'wpinv_before_user_subscriptions' );
63
+        wpinv_get_template_part( 'wpinv-subscriptions-history' );
64
+        do_action( 'wpinv_after_user_subscriptions' );
65 65
 
66
-	    $output = ob_get_clean();
67
-	    return trim($output);
66
+        $output = ob_get_clean();
67
+        return trim($output);
68 68
 
69 69
     }
70 70
 
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit;
4 4
 }
5 5
 
@@ -22,15 +22,15 @@  discard block
 block discarded – undo
22 22
             'block-keywords'=> "['invoicing','subscriptions']",
23 23
             'class_name'     => __CLASS__,
24 24
             'base_id'       => 'wpinv_subscriptions',
25
-            'name'          => __('GetPaid > Subscriptions History','invoicing'),
25
+            'name'          => __('GetPaid > Subscriptions History', 'invoicing'),
26 26
             'widget_ops'    => array(
27 27
                 'classname'   => 'wpinv-checkout-class  wpi-g',
28
-                'description' => esc_html__('Displays subscriptions history.','invoicing'),
28
+                'description' => esc_html__('Displays subscriptions history.', 'invoicing'),
29 29
             ),
30 30
             'arguments'     => array(
31 31
                 'title'  => array(
32
-                    'title'       => __( 'Widget title', 'invoicing' ),
33
-                    'desc'        => __( 'Enter widget title.', 'invoicing' ),
32
+                    'title'       => __('Widget title', 'invoicing'),
33
+                    'desc'        => __('Enter widget title.', 'invoicing'),
34 34
                     'type'        => 'text',
35 35
                     'desc_tip'    => true,
36 36
                     'default'     => '',
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
         );
42 42
 
43 43
 
44
-        parent::__construct( $options );
44
+        parent::__construct($options);
45 45
     }
46 46
 
47 47
 	/**
@@ -53,13 +53,13 @@  discard block
 block discarded – undo
53 53
 	 *
54 54
 	 * @return mixed|string|bool
55 55
 	 */
56
-    public function output( $args = array(), $widget_args = array(), $content = '' ) {
56
+    public function output($args = array(), $widget_args = array(), $content = '') {
57 57
 
58 58
 	    ob_start();
59 59
 
60
-	    do_action( 'wpinv_before_user_subscriptions' );
61
-	    wpinv_get_template_part( 'wpinv-subscriptions-history' );
62
-	    do_action( 'wpinv_after_user_subscriptions' );
60
+	    do_action('wpinv_before_user_subscriptions');
61
+	    wpinv_get_template_part('wpinv-subscriptions-history');
62
+	    do_action('wpinv_after_user_subscriptions');
63 63
 
64 64
 	    $output = ob_get_clean();
65 65
 	    return trim($output);
Please login to merge, or discard this patch.
includes/class-getpaid-subscriptions-query.php 2 patches
Indentation   +476 added lines, -476 removed lines patch added patch discarded remove patch
@@ -16,481 +16,481 @@
 block discarded – undo
16 16
  */
17 17
 class GetPaid_Subscriptions_Query {
18 18
 
19
-	/**
20
-	 * Query vars, after parsing
21
-	 *
22
-	 * @since 1.0.19
23
-	 * @var array
24
-	 */
25
-	public $query_vars = array();
26
-
27
-	/**
28
-	 * List of found subscriptions.
29
-	 *
30
-	 * @since 1.0.19
31
-	 * @var array
32
-	 */
33
-	private $results;
34
-
35
-	/**
36
-	 * Total number of found subscriptions for the current query
37
-	 *
38
-	 * @since 1.0.19
39
-	 * @var int
40
-	 */
41
-	private $total_subscriptions = 0;
42
-
43
-	/**
44
-	 * The SQL query used to fetch matching subscriptions.
45
-	 *
46
-	 * @since 1.0.19
47
-	 * @var string
48
-	 */
49
-	public $request;
50
-
51
-	// SQL clauses
52
-
53
-	/**
54
-	 * Contains the 'FIELDS' sql clause
55
-	 *
56
-	 * @since 1.0.19
57
-	 * @var string
58
-	 */
59
-	public $query_fields;
60
-
61
-	/**
62
-	 * Contains the 'FROM' sql clause
63
-	 *
64
-	 * @since 1.0.19
65
-	 * @var string
66
-	 */
67
-	public $query_from;
68
-
69
-	/**
70
-	 * Contains the 'WHERE' sql clause
71
-	 *
72
-	 * @since 1.0.19
73
-	 * @var string
74
-	 */
75
-	public $query_where;
76
-
77
-	/**
78
-	 * Contains the 'ORDER BY' sql clause
79
-	 *
80
-	 * @since 1.0.19
81
-	 * @var string
82
-	 */
83
-	public $query_orderby;
84
-
85
-	/**
86
-	 * Contains the 'LIMIT' sql clause
87
-	 *
88
-	 * @since 1.0.19
89
-	 * @var string
90
-	 */
91
-	public $query_limit;
92
-
93
-	/**
94
-	 * Class constructor.
95
-	 *
96
-	 * @since 1.0.19
97
-	 *
98
-	 * @param null|string|array $query Optional. The query variables.
99
-	 */
100
-	public function __construct( $query = null ) {
101
-		if ( ! is_null( $query ) ) {
102
-			$this->prepare_query( $query );
103
-			$this->query();
104
-		}
105
-	}
106
-
107
-	/**
108
-	 * Fills in missing query variables with default values.
109
-	 *
110
-	 * @since 1.0.19
111
-	 *
112
-	 * @param  string|array $args Query vars, as passed to `GetPaid_Subscriptions_Query`.
113
-	 * @return array Complete query variables with undefined ones filled in with defaults.
114
-	 */
115
-	public static function fill_query_vars( $args ) {
116
-		$defaults = array(
117
-			'status'            => 'all',
118
-			'customer_in'       => array(),
119
-			'customer_not_in'   => array(),
120
-			'product_in'        => array(),
121
-			'product_not_in'    => array(),
122
-			'include'           => array(),
123
-			'exclude'           => array(),
124
-			'orderby'           => 'id',
125
-			'order'             => 'DESC',
126
-			'offset'            => '',
127
-			'number'            => 10,
128
-			'paged'             => 1,
129
-			'count_total'       => true,
130
-			'fields'            => 'all',
131
-		);
132
-
133
-		return wp_parse_args( $args, $defaults );
134
-	}
135
-
136
-	/**
137
-	 * Prepare the query variables.
138
-	 *
139
-	 * @since 1.0.19
140
-	 *
141
-	 * @global wpdb $wpdb WordPress database abstraction object.
142
-	 *
143
-	 * @param string|array $query {
144
-	 *     Optional. Array or string of Query parameters.
145
-	 *
146
-	 *     @type string|array $status              The subscription status to filter by. Can either be a single status or an array of statuses.
147
-	 *                                             Default is all.
148
-	 *     @type int[]        $customer_in         An array of customer ids to filter by.
149
-	 *     @type int[]        $customer_not_in     An array of customer ids whose subscriptions should be excluded.
150
-	 *     @type int[]        $product_in          An array of product ids to filter by.
151
-	 *     @type int[]        $product_not_in      An array of product ids whose subscriptions should be excluded.
152
-	 *     @type array        $date_created_query  A WP_Date_Query compatible array use to filter subscriptions by their date of creation.
153
-	 *     @type array        $date_expires_query  A WP_Date_Query compatible array use to filter subscriptions by their expiration date.
154
-	 *     @type array        $include             An array of subscription IDs to include. Default empty array.
155
-	 *     @type array        $exclude             An array of subscription IDs to exclude. Default empty array.
156
-	 *     @type string|array $orderby             Field(s) to sort the retrieved subscription by. May be a single value,
157
-	 *                                             an array of values, or a multi-dimensional array with fields as
158
-	 *                                             keys and orders ('ASC' or 'DESC') as values. Accepted values are
159
-	 *                                             'id', 'customer_id', 'frequency', 'period', 'initial_amount,
160
-	 *                                             'recurring_amount', 'bill_times', 'parent_payment_id', 'created', 'expiration'
161
-	 *                                             'transaction_id', 'product_id', 'trial_period', 'include', 'status', 'profile_id'. Default array( 'id' ).
162
-	 *     @type string       $order               Designates ascending or descending order of subscriptions. Order values
163
-	 *                                             passed as part of an `$orderby` array take precedence over this
164
-	 *                                             parameter. Accepts 'ASC', 'DESC'. Default 'DESC'.
165
-	 *     @type int          $offset              Number of subscriptions to offset in retrieved results. Can be used in
166
-	 *                                             conjunction with pagination. Default 0.
167
-	 *     @type int          $number              Number of subscriptions to limit the query for. Can be used in
168
-	 *                                             conjunction with pagination. Value -1 (all) is supported, but
169
-	 *                                             should be used with caution on larger sites.
170
-	 *                                             Default 10.
171
-	 *     @type int          $paged               When used with number, defines the page of results to return.
172
-	 *                                             Default 1.
173
-	 *     @type bool         $count_total         Whether to count the total number of subscriptions found. If pagination
174
-	 *                                             is not needed, setting this to false can improve performance.
175
-	 *                                             Default true.
176
-	 *     @type string|array $fields              Which fields to return. Single or all fields (string), or array
177
-	 *                                             of fields. Accepts 'id', 'customer_id', 'frequency', 'period', 'initial_amount,
178
-	 *                                             'recurring_amount', 'bill_times', 'parent_payment_id', 'created', 'expiration'
179
-	 *                                             'transaction_id', 'product_id', 'trial_period', 'status', 'profile_id'.
180
-	 *                                             Use 'all' for all fields. Default 'all'.
181
-	 * }
182
-	 */
183
-	public function prepare_query( $query = array() ) {
184
-		global $wpdb;
185
-
186
-		if ( empty( $this->query_vars ) || ! empty( $query ) ) {
187
-			$this->query_limit = null;
188
-			$this->query_vars  = $this->fill_query_vars( $query );
189
-		}
190
-
191
-		if ( ! empty( $this->query_vars['fields'] ) && 'all' !== $this->query_vars['fields'] ) {
192
-			$this->query_vars['fields'] = wpinv_parse_list( $this->query_vars['fields'] );
193
-		}
194
-
195
-		do_action( 'getpaid_pre_get_subscriptions', array( &$this ) );
196
-
197
-		// Ensure that query vars are filled after 'getpaid_pre_get_subscriptions'.
198
-		$qv                =& $this->query_vars;
199
-		$qv                = $this->fill_query_vars( $qv );
200
-		$table             = $wpdb->prefix . 'wpinv_subscriptions';
201
-		$this->query_from  = "FROM $table";
202
-
203
-		// Prepare query fields.
204
-		$this->prepare_query_fields( $qv, $table );
205
-
206
-		// Prepare query where.
207
-		$this->prepare_query_where( $qv, $table );
208
-
209
-		// Prepare query order.
210
-		$this->prepare_query_order( $qv, $table );
211
-
212
-		// limit
213
-		if ( isset( $qv['number'] ) && $qv['number'] > 0 ) {
214
-			if ( $qv['offset'] ) {
215
-				$this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['offset'], $qv['number'] );
216
-			} else {
217
-				$this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] );
218
-			}
219
-		}
220
-
221
-		do_action_ref_array( 'getpaid_after_subscriptions_query', array( &$this ) );
222
-	}
223
-
224
-	/**
225
-	 * Prepares the query fields.
226
-	 *
227
-	 * @since 1.0.19
228
-	 *
229
-	 * @param array $qv Query vars.
230
-	 * @param string $table Table name.
231
-	 */
232
-	protected function prepare_query_fields( &$qv, $table ) {
233
-
234
-		if ( is_array( $qv['fields'] ) ) {
235
-			$qv['fields'] = array_unique( $qv['fields'] );
236
-
237
-			$query_fields = array();
238
-			foreach ( $qv['fields'] as $field ) {
239
-				$field          = sanitize_key( $field );
240
-				$query_fields[] = "$table.`$field`";
241
-			}
242
-			$this->query_fields = implode( ',', $query_fields );
243
-		} else {
244
-			$this->query_fields = "$table.*";
245
-		}
246
-
247
-		if ( isset( $qv['count_total'] ) && $qv['count_total'] ) {
248
-			$this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields;
249
-		}
250
-
251
-	}
252
-
253
-	/**
254
-	 * Prepares the query where.
255
-	 *
256
-	 * @since 1.0.19
257
-	 *
258
-	 * @param array $qv Query vars.
259
-	 * @param string $table Table name.
260
-	 */
261
-	protected function prepare_query_where( &$qv, $table ) {
262
-		global $wpdb;
263
-		$this->query_where = 'WHERE 1=1';
264
-
265
-		// Status.
266
-		if ( 'all' !== $qv['status'] ) {
267
-			$statuses           = wpinv_clean( wpinv_parse_list( $qv['status'] ) );
268
-			$prepared_statuses  = join( ',', array_fill( 0, count( $statuses ), '%s' ) );
269
-			$this->query_where .= $wpdb->prepare( " AND $table.`status` IN ( $prepared_statuses )", $statuses );
270
-		}
271
-
272
-		if ( ! empty( $qv['customer_in'] ) ) {
273
-			$customer_in        = implode( ',', wp_parse_id_list( $qv['customer_in'] ) );
274
-			$this->query_where .= " AND $table.`customer_id` IN ($customer_in)";
275
-		} elseif ( ! empty( $qv['customer_not_in'] ) ) {
276
-			$customer_not_in    = implode( ',', wp_parse_id_list( $qv['customer_not_in'] ) );
277
-			$this->query_where .= " AND $table.`customer_id` NOT IN ($customer_not_in)";
278
-		}
279
-
280
-		if ( ! empty( $qv['product_in'] ) ) {
281
-			$product_in         = implode( ',', wp_parse_id_list( $qv['product_in'] ) );
282
-			$this->query_where .= " AND $table.`product_id` IN ($product_in)";
283
-		} elseif ( ! empty( $qv['product_not_in'] ) ) {
284
-			$product_not_in     = implode( ',', wp_parse_id_list( $qv['product_not_in'] ) );
285
-			$this->query_where .= " AND $table.`product_id` NOT IN ($product_not_in)";
286
-		}
287
-
288
-		if ( ! empty( $qv['include'] ) ) {
289
-			$include            = implode( ',', wp_parse_id_list( $qv['include'] ) );
290
-			$this->query_where .= " AND $table.`id` IN ($include)";
291
-		} elseif ( ! empty( $qv['exclude'] ) ) {
292
-			$exclude            = implode( ',', wp_parse_id_list( $qv['exclude'] ) );
293
-			$this->query_where .= " AND $table.`id` NOT IN ($exclude)";
294
-		}
295
-
296
-		// Date queries are allowed for the subscription creation date.
297
-		if ( ! empty( $qv['date_created_query'] ) && is_array( $qv['date_created_query'] ) ) {
298
-			$date_created_query = new WP_Date_Query( $qv['date_created_query'], "$table.created" );
299
-			$this->query_where .= $date_created_query->get_sql();
300
-		}
301
-
302
-		// Date queries are also allowed for the subscription expiration date.
303
-		if ( ! empty( $qv['date_expires_query'] ) && is_array( $qv['date_expires_query'] ) ) {
304
-			$date_expires_query = new WP_Date_Query( $qv['date_expires_query'], "$table.expiration" );
305
-			$this->query_where .= $date_expires_query->get_sql();
306
-		}
307
-
308
-	}
309
-
310
-	/**
311
-	 * Prepares the query order.
312
-	 *
313
-	 * @since 1.0.19
314
-	 *
315
-	 * @param array $qv Query vars.
316
-	 * @param string $table Table name.
317
-	 */
318
-	protected function prepare_query_order( &$qv, $table ) {
319
-
320
-		// sorting.
321
-		$qv['order'] = isset( $qv['order'] ) ? strtoupper( $qv['order'] ) : '';
322
-		$order       = $this->parse_order( $qv['order'] );
323
-
324
-		// Default order is by 'id' (latest subscriptions).
325
-		if ( empty( $qv['orderby'] ) ) {
326
-			$qv['orderby'] = array( 'id' );
327
-		}
328
-
329
-		// 'orderby' values may be an array, comma- or space-separated list.
330
-		$ordersby      = array_filter( wpinv_parse_list(  $qv['orderby'] ) );
331
-
332
-		$orderby_array = array();
333
-		foreach ( $ordersby as $_key => $_value ) {
334
-
335
-			if ( is_int( $_key ) ) {
336
-				// Integer key means this is a flat array of 'orderby' fields.
337
-				$_orderby = $_value;
338
-				$_order   = $order;
339
-			} else {
340
-				// Non-integer key means that the key is the field and the value is ASC/DESC.
341
-				$_orderby = $_key;
342
-				$_order   = $_value;
343
-			}
344
-
345
-			$parsed = $this->parse_orderby( $_orderby, $table );
346
-
347
-			if ( $parsed ) {
348
-				$orderby_array[] = $parsed . ' ' . $this->parse_order( $_order );
349
-			}
350
-
351
-		}
352
-
353
-		// If no valid clauses were found, order by id.
354
-		if ( empty( $orderby_array ) ) {
355
-			$orderby_array[] = "id $order";
356
-		}
357
-
358
-		$this->query_orderby = 'ORDER BY ' . implode( ', ', $orderby_array );
359
-
360
-	}
361
-
362
-	/**
363
-	 * Execute the query, with the current variables.
364
-	 *
365
-	 * @since 1.0.19
366
-	 *
367
-	 * @global wpdb $wpdb WordPress database abstraction object.
368
-	 */
369
-	public function query() {
370
-		global $wpdb;
371
-
372
-		$qv =& $this->query_vars;
373
-
374
-		// Return a non-null value to bypass the default GetPaid subscriptions query and remember to set the
375
-		// total_subscriptions property.
376
-		$this->results = apply_filters_ref_array( 'getpaid_subscriptions_pre_query', array( null, &$this ) );
377
-
378
-		if ( null === $this->results ) {
379
-			$this->request = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit";
380
-
381
-			if ( ( is_array( $qv['fields'] ) && 1 != count( $qv['fields'] ) ) || 'all' == $qv['fields'] ) {
382
-				$this->results = $wpdb->get_results( $this->request );
383
-			} else {
384
-				$this->results = $wpdb->get_col( $this->request );
385
-			}
386
-
387
-			if ( isset( $qv['count_total'] ) && $qv['count_total'] ) {
388
-				$found_subscriptions_query = apply_filters( 'getpaid_found_subscriptions_query', 'SELECT FOUND_ROWS()', $this );
389
-				$this->total_subscriptions   = (int) $wpdb->get_var( $found_subscriptions_query );
390
-			}
391
-		}
392
-
393
-		if ( 'all' == $qv['fields'] ) {
394
-			foreach ( $this->results as $key => $subscription ) {
395
-				$this->results[ $key ] = new WPInv_Subscription( $subscription );
396
-			}
397
-		}
398
-
399
-	}
400
-
401
-	/**
402
-	 * Retrieve query variable.
403
-	 *
404
-	 * @since 1.0.19
405
-	 *
406
-	 * @param string $query_var Query variable key.
407
-	 * @return mixed
408
-	 */
409
-	public function get( $query_var ) {
410
-		if ( isset( $this->query_vars[ $query_var ] ) ) {
411
-			return $this->query_vars[ $query_var ];
412
-		}
413
-
414
-		return null;
415
-	}
416
-
417
-	/**
418
-	 * Set query variable.
419
-	 *
420
-	 * @since 1.0.19
421
-	 *
422
-	 * @param string $query_var Query variable key.
423
-	 * @param mixed $value Query variable value.
424
-	 */
425
-	public function set( $query_var, $value ) {
426
-		$this->query_vars[ $query_var ] = $value;
427
-	}
428
-
429
-	/**
430
-	 * Return the list of subscriptions.
431
-	 *
432
-	 * @since 1.0.19
433
-	 *
434
-	 * @return WPInv_Subscription[]|array Found subscriptions.
435
-	 */
436
-	public function get_results() {
437
-		return $this->results;
438
-	}
439
-
440
-	/**
441
-	 * Return the total number of subscriptions for the current query.
442
-	 *
443
-	 * @since 1.0.19
444
-	 *
445
-	 * @return int Number of total subscriptions.
446
-	 */
447
-	public function get_total() {
448
-		return $this->total_subscriptions;
449
-	}
450
-
451
-	/**
452
-	 * Parse and sanitize 'orderby' keys passed to the subscriptions query.
453
-	 *
454
-	 * @since 1.0.19
455
-	 *
456
-	 * @param string $orderby Alias for the field to order by.
457
-	 *  @param string $table The current table.
458
-	 * @return string Value to use in the ORDER clause, if `$orderby` is valid.
459
-	 */
460
-	protected function parse_orderby( $orderby, $table ) {
461
-
462
-		$_orderby = '';
463
-		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' ) ) ) {
464
-			$_orderby = "$table.`$orderby`";
465
-		} elseif ( 'id' === strtolower( $orderby ) ) {
466
-			$_orderby = "$table.id";
467
-		} elseif ( 'include' === $orderby && ! empty( $this->query_vars['include'] ) ) {
468
-			$include     = wp_parse_id_list( $this->query_vars['include'] );
469
-			$include_sql = implode( ',', $include );
470
-			$_orderby    = "FIELD( $table.id, $include_sql )";
471
-		}
472
-
473
-		return $_orderby;
474
-	}
475
-
476
-	/**
477
-	 * Parse an 'order' query variable and cast it to ASC or DESC as necessary.
478
-	 *
479
-	 * @since 1.0.19
480
-	 *
481
-	 * @param string $order The 'order' query variable.
482
-	 * @return string The sanitized 'order' query variable.
483
-	 */
484
-	protected function parse_order( $order ) {
485
-		if ( ! is_string( $order ) || empty( $order ) ) {
486
-			return 'DESC';
487
-		}
488
-
489
-		if ( 'ASC' === strtoupper( $order ) ) {
490
-			return 'ASC';
491
-		} else {
492
-			return 'DESC';
493
-		}
494
-	}
19
+    /**
20
+     * Query vars, after parsing
21
+     *
22
+     * @since 1.0.19
23
+     * @var array
24
+     */
25
+    public $query_vars = array();
26
+
27
+    /**
28
+     * List of found subscriptions.
29
+     *
30
+     * @since 1.0.19
31
+     * @var array
32
+     */
33
+    private $results;
34
+
35
+    /**
36
+     * Total number of found subscriptions for the current query
37
+     *
38
+     * @since 1.0.19
39
+     * @var int
40
+     */
41
+    private $total_subscriptions = 0;
42
+
43
+    /**
44
+     * The SQL query used to fetch matching subscriptions.
45
+     *
46
+     * @since 1.0.19
47
+     * @var string
48
+     */
49
+    public $request;
50
+
51
+    // SQL clauses
52
+
53
+    /**
54
+     * Contains the 'FIELDS' sql clause
55
+     *
56
+     * @since 1.0.19
57
+     * @var string
58
+     */
59
+    public $query_fields;
60
+
61
+    /**
62
+     * Contains the 'FROM' sql clause
63
+     *
64
+     * @since 1.0.19
65
+     * @var string
66
+     */
67
+    public $query_from;
68
+
69
+    /**
70
+     * Contains the 'WHERE' sql clause
71
+     *
72
+     * @since 1.0.19
73
+     * @var string
74
+     */
75
+    public $query_where;
76
+
77
+    /**
78
+     * Contains the 'ORDER BY' sql clause
79
+     *
80
+     * @since 1.0.19
81
+     * @var string
82
+     */
83
+    public $query_orderby;
84
+
85
+    /**
86
+     * Contains the 'LIMIT' sql clause
87
+     *
88
+     * @since 1.0.19
89
+     * @var string
90
+     */
91
+    public $query_limit;
92
+
93
+    /**
94
+     * Class constructor.
95
+     *
96
+     * @since 1.0.19
97
+     *
98
+     * @param null|string|array $query Optional. The query variables.
99
+     */
100
+    public function __construct( $query = null ) {
101
+        if ( ! is_null( $query ) ) {
102
+            $this->prepare_query( $query );
103
+            $this->query();
104
+        }
105
+    }
106
+
107
+    /**
108
+     * Fills in missing query variables with default values.
109
+     *
110
+     * @since 1.0.19
111
+     *
112
+     * @param  string|array $args Query vars, as passed to `GetPaid_Subscriptions_Query`.
113
+     * @return array Complete query variables with undefined ones filled in with defaults.
114
+     */
115
+    public static function fill_query_vars( $args ) {
116
+        $defaults = array(
117
+            'status'            => 'all',
118
+            'customer_in'       => array(),
119
+            'customer_not_in'   => array(),
120
+            'product_in'        => array(),
121
+            'product_not_in'    => array(),
122
+            'include'           => array(),
123
+            'exclude'           => array(),
124
+            'orderby'           => 'id',
125
+            'order'             => 'DESC',
126
+            'offset'            => '',
127
+            'number'            => 10,
128
+            'paged'             => 1,
129
+            'count_total'       => true,
130
+            'fields'            => 'all',
131
+        );
132
+
133
+        return wp_parse_args( $args, $defaults );
134
+    }
135
+
136
+    /**
137
+     * Prepare the query variables.
138
+     *
139
+     * @since 1.0.19
140
+     *
141
+     * @global wpdb $wpdb WordPress database abstraction object.
142
+     *
143
+     * @param string|array $query {
144
+     *     Optional. Array or string of Query parameters.
145
+     *
146
+     *     @type string|array $status              The subscription status to filter by. Can either be a single status or an array of statuses.
147
+     *                                             Default is all.
148
+     *     @type int[]        $customer_in         An array of customer ids to filter by.
149
+     *     @type int[]        $customer_not_in     An array of customer ids whose subscriptions should be excluded.
150
+     *     @type int[]        $product_in          An array of product ids to filter by.
151
+     *     @type int[]        $product_not_in      An array of product ids whose subscriptions should be excluded.
152
+     *     @type array        $date_created_query  A WP_Date_Query compatible array use to filter subscriptions by their date of creation.
153
+     *     @type array        $date_expires_query  A WP_Date_Query compatible array use to filter subscriptions by their expiration date.
154
+     *     @type array        $include             An array of subscription IDs to include. Default empty array.
155
+     *     @type array        $exclude             An array of subscription IDs to exclude. Default empty array.
156
+     *     @type string|array $orderby             Field(s) to sort the retrieved subscription by. May be a single value,
157
+     *                                             an array of values, or a multi-dimensional array with fields as
158
+     *                                             keys and orders ('ASC' or 'DESC') as values. Accepted values are
159
+     *                                             'id', 'customer_id', 'frequency', 'period', 'initial_amount,
160
+     *                                             'recurring_amount', 'bill_times', 'parent_payment_id', 'created', 'expiration'
161
+     *                                             'transaction_id', 'product_id', 'trial_period', 'include', 'status', 'profile_id'. Default array( 'id' ).
162
+     *     @type string       $order               Designates ascending or descending order of subscriptions. Order values
163
+     *                                             passed as part of an `$orderby` array take precedence over this
164
+     *                                             parameter. Accepts 'ASC', 'DESC'. Default 'DESC'.
165
+     *     @type int          $offset              Number of subscriptions to offset in retrieved results. Can be used in
166
+     *                                             conjunction with pagination. Default 0.
167
+     *     @type int          $number              Number of subscriptions to limit the query for. Can be used in
168
+     *                                             conjunction with pagination. Value -1 (all) is supported, but
169
+     *                                             should be used with caution on larger sites.
170
+     *                                             Default 10.
171
+     *     @type int          $paged               When used with number, defines the page of results to return.
172
+     *                                             Default 1.
173
+     *     @type bool         $count_total         Whether to count the total number of subscriptions found. If pagination
174
+     *                                             is not needed, setting this to false can improve performance.
175
+     *                                             Default true.
176
+     *     @type string|array $fields              Which fields to return. Single or all fields (string), or array
177
+     *                                             of fields. Accepts 'id', 'customer_id', 'frequency', 'period', 'initial_amount,
178
+     *                                             'recurring_amount', 'bill_times', 'parent_payment_id', 'created', 'expiration'
179
+     *                                             'transaction_id', 'product_id', 'trial_period', 'status', 'profile_id'.
180
+     *                                             Use 'all' for all fields. Default 'all'.
181
+     * }
182
+     */
183
+    public function prepare_query( $query = array() ) {
184
+        global $wpdb;
185
+
186
+        if ( empty( $this->query_vars ) || ! empty( $query ) ) {
187
+            $this->query_limit = null;
188
+            $this->query_vars  = $this->fill_query_vars( $query );
189
+        }
190
+
191
+        if ( ! empty( $this->query_vars['fields'] ) && 'all' !== $this->query_vars['fields'] ) {
192
+            $this->query_vars['fields'] = wpinv_parse_list( $this->query_vars['fields'] );
193
+        }
194
+
195
+        do_action( 'getpaid_pre_get_subscriptions', array( &$this ) );
196
+
197
+        // Ensure that query vars are filled after 'getpaid_pre_get_subscriptions'.
198
+        $qv                =& $this->query_vars;
199
+        $qv                = $this->fill_query_vars( $qv );
200
+        $table             = $wpdb->prefix . 'wpinv_subscriptions';
201
+        $this->query_from  = "FROM $table";
202
+
203
+        // Prepare query fields.
204
+        $this->prepare_query_fields( $qv, $table );
205
+
206
+        // Prepare query where.
207
+        $this->prepare_query_where( $qv, $table );
208
+
209
+        // Prepare query order.
210
+        $this->prepare_query_order( $qv, $table );
211
+
212
+        // limit
213
+        if ( isset( $qv['number'] ) && $qv['number'] > 0 ) {
214
+            if ( $qv['offset'] ) {
215
+                $this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['offset'], $qv['number'] );
216
+            } else {
217
+                $this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] );
218
+            }
219
+        }
220
+
221
+        do_action_ref_array( 'getpaid_after_subscriptions_query', array( &$this ) );
222
+    }
223
+
224
+    /**
225
+     * Prepares the query fields.
226
+     *
227
+     * @since 1.0.19
228
+     *
229
+     * @param array $qv Query vars.
230
+     * @param string $table Table name.
231
+     */
232
+    protected function prepare_query_fields( &$qv, $table ) {
233
+
234
+        if ( is_array( $qv['fields'] ) ) {
235
+            $qv['fields'] = array_unique( $qv['fields'] );
236
+
237
+            $query_fields = array();
238
+            foreach ( $qv['fields'] as $field ) {
239
+                $field          = sanitize_key( $field );
240
+                $query_fields[] = "$table.`$field`";
241
+            }
242
+            $this->query_fields = implode( ',', $query_fields );
243
+        } else {
244
+            $this->query_fields = "$table.*";
245
+        }
246
+
247
+        if ( isset( $qv['count_total'] ) && $qv['count_total'] ) {
248
+            $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields;
249
+        }
250
+
251
+    }
252
+
253
+    /**
254
+     * Prepares the query where.
255
+     *
256
+     * @since 1.0.19
257
+     *
258
+     * @param array $qv Query vars.
259
+     * @param string $table Table name.
260
+     */
261
+    protected function prepare_query_where( &$qv, $table ) {
262
+        global $wpdb;
263
+        $this->query_where = 'WHERE 1=1';
264
+
265
+        // Status.
266
+        if ( 'all' !== $qv['status'] ) {
267
+            $statuses           = wpinv_clean( wpinv_parse_list( $qv['status'] ) );
268
+            $prepared_statuses  = join( ',', array_fill( 0, count( $statuses ), '%s' ) );
269
+            $this->query_where .= $wpdb->prepare( " AND $table.`status` IN ( $prepared_statuses )", $statuses );
270
+        }
271
+
272
+        if ( ! empty( $qv['customer_in'] ) ) {
273
+            $customer_in        = implode( ',', wp_parse_id_list( $qv['customer_in'] ) );
274
+            $this->query_where .= " AND $table.`customer_id` IN ($customer_in)";
275
+        } elseif ( ! empty( $qv['customer_not_in'] ) ) {
276
+            $customer_not_in    = implode( ',', wp_parse_id_list( $qv['customer_not_in'] ) );
277
+            $this->query_where .= " AND $table.`customer_id` NOT IN ($customer_not_in)";
278
+        }
279
+
280
+        if ( ! empty( $qv['product_in'] ) ) {
281
+            $product_in         = implode( ',', wp_parse_id_list( $qv['product_in'] ) );
282
+            $this->query_where .= " AND $table.`product_id` IN ($product_in)";
283
+        } elseif ( ! empty( $qv['product_not_in'] ) ) {
284
+            $product_not_in     = implode( ',', wp_parse_id_list( $qv['product_not_in'] ) );
285
+            $this->query_where .= " AND $table.`product_id` NOT IN ($product_not_in)";
286
+        }
287
+
288
+        if ( ! empty( $qv['include'] ) ) {
289
+            $include            = implode( ',', wp_parse_id_list( $qv['include'] ) );
290
+            $this->query_where .= " AND $table.`id` IN ($include)";
291
+        } elseif ( ! empty( $qv['exclude'] ) ) {
292
+            $exclude            = implode( ',', wp_parse_id_list( $qv['exclude'] ) );
293
+            $this->query_where .= " AND $table.`id` NOT IN ($exclude)";
294
+        }
295
+
296
+        // Date queries are allowed for the subscription creation date.
297
+        if ( ! empty( $qv['date_created_query'] ) && is_array( $qv['date_created_query'] ) ) {
298
+            $date_created_query = new WP_Date_Query( $qv['date_created_query'], "$table.created" );
299
+            $this->query_where .= $date_created_query->get_sql();
300
+        }
301
+
302
+        // Date queries are also allowed for the subscription expiration date.
303
+        if ( ! empty( $qv['date_expires_query'] ) && is_array( $qv['date_expires_query'] ) ) {
304
+            $date_expires_query = new WP_Date_Query( $qv['date_expires_query'], "$table.expiration" );
305
+            $this->query_where .= $date_expires_query->get_sql();
306
+        }
307
+
308
+    }
309
+
310
+    /**
311
+     * Prepares the query order.
312
+     *
313
+     * @since 1.0.19
314
+     *
315
+     * @param array $qv Query vars.
316
+     * @param string $table Table name.
317
+     */
318
+    protected function prepare_query_order( &$qv, $table ) {
319
+
320
+        // sorting.
321
+        $qv['order'] = isset( $qv['order'] ) ? strtoupper( $qv['order'] ) : '';
322
+        $order       = $this->parse_order( $qv['order'] );
323
+
324
+        // Default order is by 'id' (latest subscriptions).
325
+        if ( empty( $qv['orderby'] ) ) {
326
+            $qv['orderby'] = array( 'id' );
327
+        }
328
+
329
+        // 'orderby' values may be an array, comma- or space-separated list.
330
+        $ordersby      = array_filter( wpinv_parse_list(  $qv['orderby'] ) );
331
+
332
+        $orderby_array = array();
333
+        foreach ( $ordersby as $_key => $_value ) {
334
+
335
+            if ( is_int( $_key ) ) {
336
+                // Integer key means this is a flat array of 'orderby' fields.
337
+                $_orderby = $_value;
338
+                $_order   = $order;
339
+            } else {
340
+                // Non-integer key means that the key is the field and the value is ASC/DESC.
341
+                $_orderby = $_key;
342
+                $_order   = $_value;
343
+            }
344
+
345
+            $parsed = $this->parse_orderby( $_orderby, $table );
346
+
347
+            if ( $parsed ) {
348
+                $orderby_array[] = $parsed . ' ' . $this->parse_order( $_order );
349
+            }
350
+
351
+        }
352
+
353
+        // If no valid clauses were found, order by id.
354
+        if ( empty( $orderby_array ) ) {
355
+            $orderby_array[] = "id $order";
356
+        }
357
+
358
+        $this->query_orderby = 'ORDER BY ' . implode( ', ', $orderby_array );
359
+
360
+    }
361
+
362
+    /**
363
+     * Execute the query, with the current variables.
364
+     *
365
+     * @since 1.0.19
366
+     *
367
+     * @global wpdb $wpdb WordPress database abstraction object.
368
+     */
369
+    public function query() {
370
+        global $wpdb;
371
+
372
+        $qv =& $this->query_vars;
373
+
374
+        // Return a non-null value to bypass the default GetPaid subscriptions query and remember to set the
375
+        // total_subscriptions property.
376
+        $this->results = apply_filters_ref_array( 'getpaid_subscriptions_pre_query', array( null, &$this ) );
377
+
378
+        if ( null === $this->results ) {
379
+            $this->request = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit";
380
+
381
+            if ( ( is_array( $qv['fields'] ) && 1 != count( $qv['fields'] ) ) || 'all' == $qv['fields'] ) {
382
+                $this->results = $wpdb->get_results( $this->request );
383
+            } else {
384
+                $this->results = $wpdb->get_col( $this->request );
385
+            }
386
+
387
+            if ( isset( $qv['count_total'] ) && $qv['count_total'] ) {
388
+                $found_subscriptions_query = apply_filters( 'getpaid_found_subscriptions_query', 'SELECT FOUND_ROWS()', $this );
389
+                $this->total_subscriptions   = (int) $wpdb->get_var( $found_subscriptions_query );
390
+            }
391
+        }
392
+
393
+        if ( 'all' == $qv['fields'] ) {
394
+            foreach ( $this->results as $key => $subscription ) {
395
+                $this->results[ $key ] = new WPInv_Subscription( $subscription );
396
+            }
397
+        }
398
+
399
+    }
400
+
401
+    /**
402
+     * Retrieve query variable.
403
+     *
404
+     * @since 1.0.19
405
+     *
406
+     * @param string $query_var Query variable key.
407
+     * @return mixed
408
+     */
409
+    public function get( $query_var ) {
410
+        if ( isset( $this->query_vars[ $query_var ] ) ) {
411
+            return $this->query_vars[ $query_var ];
412
+        }
413
+
414
+        return null;
415
+    }
416
+
417
+    /**
418
+     * Set query variable.
419
+     *
420
+     * @since 1.0.19
421
+     *
422
+     * @param string $query_var Query variable key.
423
+     * @param mixed $value Query variable value.
424
+     */
425
+    public function set( $query_var, $value ) {
426
+        $this->query_vars[ $query_var ] = $value;
427
+    }
428
+
429
+    /**
430
+     * Return the list of subscriptions.
431
+     *
432
+     * @since 1.0.19
433
+     *
434
+     * @return WPInv_Subscription[]|array Found subscriptions.
435
+     */
436
+    public function get_results() {
437
+        return $this->results;
438
+    }
439
+
440
+    /**
441
+     * Return the total number of subscriptions for the current query.
442
+     *
443
+     * @since 1.0.19
444
+     *
445
+     * @return int Number of total subscriptions.
446
+     */
447
+    public function get_total() {
448
+        return $this->total_subscriptions;
449
+    }
450
+
451
+    /**
452
+     * Parse and sanitize 'orderby' keys passed to the subscriptions query.
453
+     *
454
+     * @since 1.0.19
455
+     *
456
+     * @param string $orderby Alias for the field to order by.
457
+     *  @param string $table The current table.
458
+     * @return string Value to use in the ORDER clause, if `$orderby` is valid.
459
+     */
460
+    protected function parse_orderby( $orderby, $table ) {
461
+
462
+        $_orderby = '';
463
+        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' ) ) ) {
464
+            $_orderby = "$table.`$orderby`";
465
+        } elseif ( 'id' === strtolower( $orderby ) ) {
466
+            $_orderby = "$table.id";
467
+        } elseif ( 'include' === $orderby && ! empty( $this->query_vars['include'] ) ) {
468
+            $include     = wp_parse_id_list( $this->query_vars['include'] );
469
+            $include_sql = implode( ',', $include );
470
+            $_orderby    = "FIELD( $table.id, $include_sql )";
471
+        }
472
+
473
+        return $_orderby;
474
+    }
475
+
476
+    /**
477
+     * Parse an 'order' query variable and cast it to ASC or DESC as necessary.
478
+     *
479
+     * @since 1.0.19
480
+     *
481
+     * @param string $order The 'order' query variable.
482
+     * @return string The sanitized 'order' query variable.
483
+     */
484
+    protected function parse_order( $order ) {
485
+        if ( ! is_string( $order ) || empty( $order ) ) {
486
+            return 'DESC';
487
+        }
488
+
489
+        if ( 'ASC' === strtoupper( $order ) ) {
490
+            return 'ASC';
491
+        } else {
492
+            return 'DESC';
493
+        }
494
+    }
495 495
 
496 496
 }
Please login to merge, or discard this patch.
Spacing   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -97,9 +97,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 	/**
@@ -180,45 +180,45 @@  discard block
 block discarded – undo
180 180
 	 *                                             Use 'all' for all fields. Default 'all'.
181 181
 	 * }
182 182
 	 */
183
-	public function prepare_query( $query = array() ) {
183
+	public function prepare_query($query = array()) {
184 184
 		global $wpdb;
185 185
 
186
-		if ( empty( $this->query_vars ) || ! empty( $query ) ) {
186
+		if (empty($this->query_vars) || !empty($query)) {
187 187
 			$this->query_limit = null;
188
-			$this->query_vars  = $this->fill_query_vars( $query );
188
+			$this->query_vars  = $this->fill_query_vars($query);
189 189
 		}
190 190
 
191
-		if ( ! empty( $this->query_vars['fields'] ) && 'all' !== $this->query_vars['fields'] ) {
192
-			$this->query_vars['fields'] = wpinv_parse_list( $this->query_vars['fields'] );
191
+		if (!empty($this->query_vars['fields']) && 'all' !== $this->query_vars['fields']) {
192
+			$this->query_vars['fields'] = wpinv_parse_list($this->query_vars['fields']);
193 193
 		}
194 194
 
195
-		do_action( 'getpaid_pre_get_subscriptions', array( &$this ) );
195
+		do_action('getpaid_pre_get_subscriptions', array(&$this));
196 196
 
197 197
 		// Ensure that query vars are filled after 'getpaid_pre_get_subscriptions'.
198
-		$qv                =& $this->query_vars;
199
-		$qv                = $this->fill_query_vars( $qv );
198
+		$qv                = & $this->query_vars;
199
+		$qv                = $this->fill_query_vars($qv);
200 200
 		$table             = $wpdb->prefix . 'wpinv_subscriptions';
201 201
 		$this->query_from  = "FROM $table";
202 202
 
203 203
 		// Prepare query fields.
204
-		$this->prepare_query_fields( $qv, $table );
204
+		$this->prepare_query_fields($qv, $table);
205 205
 
206 206
 		// Prepare query where.
207
-		$this->prepare_query_where( $qv, $table );
207
+		$this->prepare_query_where($qv, $table);
208 208
 
209 209
 		// Prepare query order.
210
-		$this->prepare_query_order( $qv, $table );
210
+		$this->prepare_query_order($qv, $table);
211 211
 
212 212
 		// limit
213
-		if ( isset( $qv['number'] ) && $qv['number'] > 0 ) {
214
-			if ( $qv['offset'] ) {
215
-				$this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['offset'], $qv['number'] );
213
+		if (isset($qv['number']) && $qv['number'] > 0) {
214
+			if ($qv['offset']) {
215
+				$this->query_limit = $wpdb->prepare('LIMIT %d, %d', $qv['offset'], $qv['number']);
216 216
 			} else {
217
-				$this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] );
217
+				$this->query_limit = $wpdb->prepare('LIMIT %d, %d', $qv['number'] * ($qv['paged'] - 1), $qv['number']);
218 218
 			}
219 219
 		}
220 220
 
221
-		do_action_ref_array( 'getpaid_after_subscriptions_query', array( &$this ) );
221
+		do_action_ref_array('getpaid_after_subscriptions_query', array(&$this));
222 222
 	}
223 223
 
224 224
 	/**
@@ -229,22 +229,22 @@  discard block
 block discarded – undo
229 229
 	 * @param array $qv Query vars.
230 230
 	 * @param string $table Table name.
231 231
 	 */
232
-	protected function prepare_query_fields( &$qv, $table ) {
232
+	protected function prepare_query_fields(&$qv, $table) {
233 233
 
234
-		if ( is_array( $qv['fields'] ) ) {
235
-			$qv['fields'] = array_unique( $qv['fields'] );
234
+		if (is_array($qv['fields'])) {
235
+			$qv['fields'] = array_unique($qv['fields']);
236 236
 
237 237
 			$query_fields = array();
238
-			foreach ( $qv['fields'] as $field ) {
239
-				$field          = sanitize_key( $field );
238
+			foreach ($qv['fields'] as $field) {
239
+				$field          = sanitize_key($field);
240 240
 				$query_fields[] = "$table.`$field`";
241 241
 			}
242
-			$this->query_fields = implode( ',', $query_fields );
242
+			$this->query_fields = implode(',', $query_fields);
243 243
 		} else {
244 244
 			$this->query_fields = "$table.*";
245 245
 		}
246 246
 
247
-		if ( isset( $qv['count_total'] ) && $qv['count_total'] ) {
247
+		if (isset($qv['count_total']) && $qv['count_total']) {
248 248
 			$this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields;
249 249
 		}
250 250
 
@@ -258,50 +258,50 @@  discard block
 block discarded – undo
258 258
 	 * @param array $qv Query vars.
259 259
 	 * @param string $table Table name.
260 260
 	 */
261
-	protected function prepare_query_where( &$qv, $table ) {
261
+	protected function prepare_query_where(&$qv, $table) {
262 262
 		global $wpdb;
263 263
 		$this->query_where = 'WHERE 1=1';
264 264
 
265 265
 		// Status.
266
-		if ( 'all' !== $qv['status'] ) {
267
-			$statuses           = wpinv_clean( wpinv_parse_list( $qv['status'] ) );
268
-			$prepared_statuses  = join( ',', array_fill( 0, count( $statuses ), '%s' ) );
269
-			$this->query_where .= $wpdb->prepare( " AND $table.`status` IN ( $prepared_statuses )", $statuses );
266
+		if ('all' !== $qv['status']) {
267
+			$statuses           = wpinv_clean(wpinv_parse_list($qv['status']));
268
+			$prepared_statuses  = join(',', array_fill(0, count($statuses), '%s'));
269
+			$this->query_where .= $wpdb->prepare(" AND $table.`status` IN ( $prepared_statuses )", $statuses);
270 270
 		}
271 271
 
272
-		if ( ! empty( $qv['customer_in'] ) ) {
273
-			$customer_in        = implode( ',', wp_parse_id_list( $qv['customer_in'] ) );
272
+		if (!empty($qv['customer_in'])) {
273
+			$customer_in        = implode(',', wp_parse_id_list($qv['customer_in']));
274 274
 			$this->query_where .= " AND $table.`customer_id` IN ($customer_in)";
275
-		} elseif ( ! empty( $qv['customer_not_in'] ) ) {
276
-			$customer_not_in    = implode( ',', wp_parse_id_list( $qv['customer_not_in'] ) );
275
+		} elseif (!empty($qv['customer_not_in'])) {
276
+			$customer_not_in    = implode(',', wp_parse_id_list($qv['customer_not_in']));
277 277
 			$this->query_where .= " AND $table.`customer_id` NOT IN ($customer_not_in)";
278 278
 		}
279 279
 
280
-		if ( ! empty( $qv['product_in'] ) ) {
281
-			$product_in         = implode( ',', wp_parse_id_list( $qv['product_in'] ) );
280
+		if (!empty($qv['product_in'])) {
281
+			$product_in         = implode(',', wp_parse_id_list($qv['product_in']));
282 282
 			$this->query_where .= " AND $table.`product_id` IN ($product_in)";
283
-		} elseif ( ! empty( $qv['product_not_in'] ) ) {
284
-			$product_not_in     = implode( ',', wp_parse_id_list( $qv['product_not_in'] ) );
283
+		} elseif (!empty($qv['product_not_in'])) {
284
+			$product_not_in     = implode(',', wp_parse_id_list($qv['product_not_in']));
285 285
 			$this->query_where .= " AND $table.`product_id` NOT IN ($product_not_in)";
286 286
 		}
287 287
 
288
-		if ( ! empty( $qv['include'] ) ) {
289
-			$include            = implode( ',', wp_parse_id_list( $qv['include'] ) );
288
+		if (!empty($qv['include'])) {
289
+			$include            = implode(',', wp_parse_id_list($qv['include']));
290 290
 			$this->query_where .= " AND $table.`id` IN ($include)";
291
-		} elseif ( ! empty( $qv['exclude'] ) ) {
292
-			$exclude            = implode( ',', wp_parse_id_list( $qv['exclude'] ) );
291
+		} elseif (!empty($qv['exclude'])) {
292
+			$exclude            = implode(',', wp_parse_id_list($qv['exclude']));
293 293
 			$this->query_where .= " AND $table.`id` NOT IN ($exclude)";
294 294
 		}
295 295
 
296 296
 		// Date queries are allowed for the subscription creation date.
297
-		if ( ! empty( $qv['date_created_query'] ) && is_array( $qv['date_created_query'] ) ) {
298
-			$date_created_query = new WP_Date_Query( $qv['date_created_query'], "$table.created" );
297
+		if (!empty($qv['date_created_query']) && is_array($qv['date_created_query'])) {
298
+			$date_created_query = new WP_Date_Query($qv['date_created_query'], "$table.created");
299 299
 			$this->query_where .= $date_created_query->get_sql();
300 300
 		}
301 301
 
302 302
 		// Date queries are also allowed for the subscription expiration date.
303
-		if ( ! empty( $qv['date_expires_query'] ) && is_array( $qv['date_expires_query'] ) ) {
304
-			$date_expires_query = new WP_Date_Query( $qv['date_expires_query'], "$table.expiration" );
303
+		if (!empty($qv['date_expires_query']) && is_array($qv['date_expires_query'])) {
304
+			$date_expires_query = new WP_Date_Query($qv['date_expires_query'], "$table.expiration");
305 305
 			$this->query_where .= $date_expires_query->get_sql();
306 306
 		}
307 307
 
@@ -315,24 +315,24 @@  discard block
 block discarded – undo
315 315
 	 * @param array $qv Query vars.
316 316
 	 * @param string $table Table name.
317 317
 	 */
318
-	protected function prepare_query_order( &$qv, $table ) {
318
+	protected function prepare_query_order(&$qv, $table) {
319 319
 
320 320
 		// sorting.
321
-		$qv['order'] = isset( $qv['order'] ) ? strtoupper( $qv['order'] ) : '';
322
-		$order       = $this->parse_order( $qv['order'] );
321
+		$qv['order'] = isset($qv['order']) ? strtoupper($qv['order']) : '';
322
+		$order       = $this->parse_order($qv['order']);
323 323
 
324 324
 		// Default order is by 'id' (latest subscriptions).
325
-		if ( empty( $qv['orderby'] ) ) {
326
-			$qv['orderby'] = array( 'id' );
325
+		if (empty($qv['orderby'])) {
326
+			$qv['orderby'] = array('id');
327 327
 		}
328 328
 
329 329
 		// 'orderby' values may be an array, comma- or space-separated list.
330
-		$ordersby      = array_filter( wpinv_parse_list(  $qv['orderby'] ) );
330
+		$ordersby      = array_filter(wpinv_parse_list($qv['orderby']));
331 331
 
332 332
 		$orderby_array = array();
333
-		foreach ( $ordersby as $_key => $_value ) {
333
+		foreach ($ordersby as $_key => $_value) {
334 334
 
335
-			if ( is_int( $_key ) ) {
335
+			if (is_int($_key)) {
336 336
 				// Integer key means this is a flat array of 'orderby' fields.
337 337
 				$_orderby = $_value;
338 338
 				$_order   = $order;
@@ -342,20 +342,20 @@  discard block
 block discarded – undo
342 342
 				$_order   = $_value;
343 343
 			}
344 344
 
345
-			$parsed = $this->parse_orderby( $_orderby, $table );
345
+			$parsed = $this->parse_orderby($_orderby, $table);
346 346
 
347
-			if ( $parsed ) {
348
-				$orderby_array[] = $parsed . ' ' . $this->parse_order( $_order );
347
+			if ($parsed) {
348
+				$orderby_array[] = $parsed . ' ' . $this->parse_order($_order);
349 349
 			}
350 350
 
351 351
 		}
352 352
 
353 353
 		// If no valid clauses were found, order by id.
354
-		if ( empty( $orderby_array ) ) {
354
+		if (empty($orderby_array)) {
355 355
 			$orderby_array[] = "id $order";
356 356
 		}
357 357
 
358
-		$this->query_orderby = 'ORDER BY ' . implode( ', ', $orderby_array );
358
+		$this->query_orderby = 'ORDER BY ' . implode(', ', $orderby_array);
359 359
 
360 360
 	}
361 361
 
@@ -369,30 +369,30 @@  discard block
 block discarded – undo
369 369
 	public function query() {
370 370
 		global $wpdb;
371 371
 
372
-		$qv =& $this->query_vars;
372
+		$qv = & $this->query_vars;
373 373
 
374 374
 		// Return a non-null value to bypass the default GetPaid subscriptions query and remember to set the
375 375
 		// total_subscriptions property.
376
-		$this->results = apply_filters_ref_array( 'getpaid_subscriptions_pre_query', array( null, &$this ) );
376
+		$this->results = apply_filters_ref_array('getpaid_subscriptions_pre_query', array(null, &$this));
377 377
 
378
-		if ( null === $this->results ) {
378
+		if (null === $this->results) {
379 379
 			$this->request = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit";
380 380
 
381
-			if ( ( is_array( $qv['fields'] ) && 1 != count( $qv['fields'] ) ) || 'all' == $qv['fields'] ) {
382
-				$this->results = $wpdb->get_results( $this->request );
381
+			if ((is_array($qv['fields']) && 1 != count($qv['fields'])) || 'all' == $qv['fields']) {
382
+				$this->results = $wpdb->get_results($this->request);
383 383
 			} else {
384
-				$this->results = $wpdb->get_col( $this->request );
384
+				$this->results = $wpdb->get_col($this->request);
385 385
 			}
386 386
 
387
-			if ( isset( $qv['count_total'] ) && $qv['count_total'] ) {
388
-				$found_subscriptions_query = apply_filters( 'getpaid_found_subscriptions_query', 'SELECT FOUND_ROWS()', $this );
389
-				$this->total_subscriptions   = (int) $wpdb->get_var( $found_subscriptions_query );
387
+			if (isset($qv['count_total']) && $qv['count_total']) {
388
+				$found_subscriptions_query = apply_filters('getpaid_found_subscriptions_query', 'SELECT FOUND_ROWS()', $this);
389
+				$this->total_subscriptions = (int) $wpdb->get_var($found_subscriptions_query);
390 390
 			}
391 391
 		}
392 392
 
393
-		if ( 'all' == $qv['fields'] ) {
394
-			foreach ( $this->results as $key => $subscription ) {
395
-				$this->results[ $key ] = new WPInv_Subscription( $subscription );
393
+		if ('all' == $qv['fields']) {
394
+			foreach ($this->results as $key => $subscription) {
395
+				$this->results[$key] = new WPInv_Subscription($subscription);
396 396
 			}
397 397
 		}
398 398
 
@@ -406,9 +406,9 @@  discard block
 block discarded – undo
406 406
 	 * @param string $query_var Query variable key.
407 407
 	 * @return mixed
408 408
 	 */
409
-	public function get( $query_var ) {
410
-		if ( isset( $this->query_vars[ $query_var ] ) ) {
411
-			return $this->query_vars[ $query_var ];
409
+	public function get($query_var) {
410
+		if (isset($this->query_vars[$query_var])) {
411
+			return $this->query_vars[$query_var];
412 412
 		}
413 413
 
414 414
 		return null;
@@ -422,8 +422,8 @@  discard block
 block discarded – undo
422 422
 	 * @param string $query_var Query variable key.
423 423
 	 * @param mixed $value Query variable value.
424 424
 	 */
425
-	public function set( $query_var, $value ) {
426
-		$this->query_vars[ $query_var ] = $value;
425
+	public function set($query_var, $value) {
426
+		$this->query_vars[$query_var] = $value;
427 427
 	}
428 428
 
429 429
 	/**
@@ -457,16 +457,16 @@  discard block
 block discarded – undo
457 457
 	 *  @param string $table The current table.
458 458
 	 * @return string Value to use in the ORDER clause, if `$orderby` is valid.
459 459
 	 */
460
-	protected function parse_orderby( $orderby, $table ) {
460
+	protected function parse_orderby($orderby, $table) {
461 461
 
462 462
 		$_orderby = '';
463
-		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' ) ) ) {
463
+		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'))) {
464 464
 			$_orderby = "$table.`$orderby`";
465
-		} elseif ( 'id' === strtolower( $orderby ) ) {
465
+		} elseif ('id' === strtolower($orderby)) {
466 466
 			$_orderby = "$table.id";
467
-		} elseif ( 'include' === $orderby && ! empty( $this->query_vars['include'] ) ) {
468
-			$include     = wp_parse_id_list( $this->query_vars['include'] );
469
-			$include_sql = implode( ',', $include );
467
+		} elseif ('include' === $orderby && !empty($this->query_vars['include'])) {
468
+			$include     = wp_parse_id_list($this->query_vars['include']);
469
+			$include_sql = implode(',', $include);
470 470
 			$_orderby    = "FIELD( $table.id, $include_sql )";
471 471
 		}
472 472
 
@@ -481,12 +481,12 @@  discard block
 block discarded – undo
481 481
 	 * @param string $order The 'order' query variable.
482 482
 	 * @return string The sanitized 'order' query variable.
483 483
 	 */
484
-	protected function parse_order( $order ) {
485
-		if ( ! is_string( $order ) || empty( $order ) ) {
484
+	protected function parse_order($order) {
485
+		if (!is_string($order) || empty($order)) {
486 486
 			return 'DESC';
487 487
 		}
488 488
 
489
-		if ( 'ASC' === strtoupper( $order ) ) {
489
+		if ('ASC' === strtoupper($order)) {
490 490
 			return 'ASC';
491 491
 		} else {
492 492
 			return 'DESC';
Please login to merge, or discard this patch.
includes/wpinv-subscription.php 2 patches
Indentation   +949 added lines, -949 removed lines patch added patch discarded remove patch
@@ -15,127 +15,127 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class WPInv_Subscription extends GetPaid_Data {
17 17
 
18
-	/**
19
-	 * Which data store to load.
20
-	 *
21
-	 * @var string
22
-	 */
23
-	protected $data_store_name = 'subscription';
24
-
25
-	/**
26
-	 * This is the name of this object type.
27
-	 *
28
-	 * @var string
29
-	 */
30
-	protected $object_type = 'subscription';
31
-
32
-	/**
33
-	 * Item Data array. This is the core item data exposed in APIs.
34
-	 *
35
-	 * @since 1.0.19
36
-	 * @var array
37
-	 */
38
-	protected $data = array(
39
-		'customer_id'       => 0,
40
-		'frequency'         => 1,
41
-		'period'            => 'D',
42
-		'initial_amount'    => null,
43
-		'recurring_amount'  => null,
44
-		'bill_times'        => 0,
45
-		'transaction_id'    => '',
46
-		'parent_payment_id' => null,
47
-		'product_id'        => 0,
48
-		'created'           => '0000-00-00 00:00:00',
49
-		'expiration'        => '0000-00-00 00:00:00',
50
-		'trial_period'      => '',
51
-		'status'            => 'pending',
52
-		'profile_id'        => '',
53
-		'gateway'           => '',
54
-		'customer'          => '',
55
-	);
56
-
57
-	/**
58
-	 * Stores the status transition information.
59
-	 *
60
-	 * @since 1.0.19
61
-	 * @var bool
62
-	 */
63
-	protected $status_transition = false;
64
-
65
-	private $subs_db;
66
-
67
-	/**
68
-	 * Get the subscription if ID is passed, otherwise the subscription is new and empty.
69
-	 *
70
-	 * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
71
-	 * @param  bool $deprecated
72
-	 */
73
-	function __construct( $subscription = 0, $deprecated = false ) {
74
-
75
-		parent::__construct( $subscription );
76
-
77
-		if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
78
-			$this->set_id( $subscription );
79
-		} elseif ( $subscription instanceof self ) {
80
-			$this->set_id( $subscription->get_id() );
81
-		} elseif ( ! empty( $subscription->id ) ) {
82
-			$this->set_id( $subscription->id );
83
-		} elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
84
-			$this->set_id( $subscription_id );
85
-		} else {
86
-			$this->set_object_read( true );
87
-		}
88
-
89
-		// Load the datastore.
90
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
91
-
92
-		if ( $this->get_id() > 0 ) {
93
-			$this->data_store->read( $this );
94
-		}
95
-
96
-	}
97
-
98
-	/**
99
-	 * Given an invoice id, profile id, transaction id, it returns the subscription's id.
100
-	 *
101
-	 *
102
-	 * @static
103
-	 * @param string $value
104
-	 * @param string $field Either invoice_id, transaction_id or profile_id.
105
-	 * @since 1.0.19
106
-	 * @return int
107
-	 */
108
-	public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
18
+    /**
19
+     * Which data store to load.
20
+     *
21
+     * @var string
22
+     */
23
+    protected $data_store_name = 'subscription';
24
+
25
+    /**
26
+     * This is the name of this object type.
27
+     *
28
+     * @var string
29
+     */
30
+    protected $object_type = 'subscription';
31
+
32
+    /**
33
+     * Item Data array. This is the core item data exposed in APIs.
34
+     *
35
+     * @since 1.0.19
36
+     * @var array
37
+     */
38
+    protected $data = array(
39
+        'customer_id'       => 0,
40
+        'frequency'         => 1,
41
+        'period'            => 'D',
42
+        'initial_amount'    => null,
43
+        'recurring_amount'  => null,
44
+        'bill_times'        => 0,
45
+        'transaction_id'    => '',
46
+        'parent_payment_id' => null,
47
+        'product_id'        => 0,
48
+        'created'           => '0000-00-00 00:00:00',
49
+        'expiration'        => '0000-00-00 00:00:00',
50
+        'trial_period'      => '',
51
+        'status'            => 'pending',
52
+        'profile_id'        => '',
53
+        'gateway'           => '',
54
+        'customer'          => '',
55
+    );
56
+
57
+    /**
58
+     * Stores the status transition information.
59
+     *
60
+     * @since 1.0.19
61
+     * @var bool
62
+     */
63
+    protected $status_transition = false;
64
+
65
+    private $subs_db;
66
+
67
+    /**
68
+     * Get the subscription if ID is passed, otherwise the subscription is new and empty.
69
+     *
70
+     * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
71
+     * @param  bool $deprecated
72
+     */
73
+    function __construct( $subscription = 0, $deprecated = false ) {
74
+
75
+        parent::__construct( $subscription );
76
+
77
+        if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
78
+            $this->set_id( $subscription );
79
+        } elseif ( $subscription instanceof self ) {
80
+            $this->set_id( $subscription->get_id() );
81
+        } elseif ( ! empty( $subscription->id ) ) {
82
+            $this->set_id( $subscription->id );
83
+        } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
84
+            $this->set_id( $subscription_id );
85
+        } else {
86
+            $this->set_object_read( true );
87
+        }
88
+
89
+        // Load the datastore.
90
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
91
+
92
+        if ( $this->get_id() > 0 ) {
93
+            $this->data_store->read( $this );
94
+        }
95
+
96
+    }
97
+
98
+    /**
99
+     * Given an invoice id, profile id, transaction id, it returns the subscription's id.
100
+     *
101
+     *
102
+     * @static
103
+     * @param string $value
104
+     * @param string $field Either invoice_id, transaction_id or profile_id.
105
+     * @since 1.0.19
106
+     * @return int
107
+     */
108
+    public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
109 109
         global $wpdb;
110 110
 
111
-		// Trim the value.
112
-		$value = trim( $value );
111
+        // Trim the value.
112
+        $value = trim( $value );
113 113
 
114
-		if ( empty( $value ) ) {
115
-			return 0;
116
-		}
114
+        if ( empty( $value ) ) {
115
+            return 0;
116
+        }
117 117
 
118
-		if ( 'invoice_id' == $field ) {
119
-			$field = 'parent_payment_id';
120
-		}
118
+        if ( 'invoice_id' == $field ) {
119
+            $field = 'parent_payment_id';
120
+        }
121 121
 
122 122
         // Valid fields.
123 123
         $fields = array(
124
-			'parent_payment_id',
125
-			'transaction_id',
126
-			'profile_id'
127
-		);
128
-
129
-		// Ensure a field has been passed.
130
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
131
-			return 0;
132
-		}
133
-
134
-		// Maybe retrieve from the cache.
135
-		$subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
136
-		if ( ! empty( $subscription_id ) ) {
137
-			return $subscription_id;
138
-		}
124
+            'parent_payment_id',
125
+            'transaction_id',
126
+            'profile_id'
127
+        );
128
+
129
+        // Ensure a field has been passed.
130
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
131
+            return 0;
132
+        }
133
+
134
+        // Maybe retrieve from the cache.
135
+        $subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
136
+        if ( ! empty( $subscription_id ) ) {
137
+            return $subscription_id;
138
+        }
139 139
 
140 140
         // Fetch from the db.
141 141
         $table            = $wpdb->prefix . 'wpinv_subscriptions';
@@ -143,34 +143,34 @@  discard block
 block discarded – undo
143 143
             $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
144 144
         );
145 145
 
146
-		if ( empty( $subscription_id ) ) {
147
-			return 0;
148
-		}
146
+        if ( empty( $subscription_id ) ) {
147
+            return 0;
148
+        }
149 149
 
150
-		// Update the cache with our data.
151
-		wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
150
+        // Update the cache with our data.
151
+        wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
152 152
 
153
-		return $subscription_id;
154
-	}
153
+        return $subscription_id;
154
+    }
155 155
 
156
-	/**
156
+    /**
157 157
      * Clears the subscription's cache.
158 158
      */
159 159
     public function clear_cache() {
160
-		wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' );
161
-		wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' );
162
-		wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' );
163
-		wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' );
164
-	}
160
+        wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' );
161
+        wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' );
162
+        wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' );
163
+        wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' );
164
+    }
165 165
 
166
-	/**
166
+    /**
167 167
      * Checks if a subscription key is set.
168 168
      */
169 169
     public function _isset( $key ) {
170 170
         return isset( $this->data[$key] ) || method_exists( $this, "get_$key" );
171
-	}
171
+    }
172 172
 
173
-	/*
173
+    /*
174 174
 	|--------------------------------------------------------------------------
175 175
 	| CRUD methods
176 176
 	|--------------------------------------------------------------------------
@@ -179,57 +179,57 @@  discard block
 block discarded – undo
179 179
 	|
180 180
     */
181 181
 
182
-	/*
182
+    /*
183 183
 	|--------------------------------------------------------------------------
184 184
 	| Getters
185 185
 	|--------------------------------------------------------------------------
186 186
 	*/
187 187
 
188
-	/**
189
-	 * Get customer id.
190
-	 *
191
-	 * @since 1.0.19
192
-	 * @param  string $context View or edit context.
193
-	 * @return int
194
-	 */
195
-	public function get_customer_id( $context = 'view' ) {
196
-		return (int) $this->get_prop( 'customer_id', $context );
197
-	}
198
-
199
-	/**
200
-	 * Get customer information.
201
-	 *
202
-	 * @since 1.0.19
203
-	 * @param  string $context View or edit context.
204
-	 * @return WP_User|false WP_User object on success, false on failure.
205
-	 */
206
-	public function get_customer( $context = 'view' ) {
207
-		return get_userdata( $this->get_customer_id( $context ) );
208
-	}
209
-
210
-	/**
211
-	 * Get parent invoice id.
212
-	 *
213
-	 * @since 1.0.19
214
-	 * @param  string $context View or edit context.
215
-	 * @return int
216
-	 */
217
-	public function get_parent_invoice_id( $context = 'view' ) {
218
-		return (int) $this->get_prop( 'parent_payment_id', $context );
219
-	}
220
-
221
-	/**
222
-	 * Alias for self::get_parent_invoice_id().
223
-	 *
224
-	 * @since 1.0.19
225
-	 * @param  string $context View or edit context.
226
-	 * @return int
227
-	 */
188
+    /**
189
+     * Get customer id.
190
+     *
191
+     * @since 1.0.19
192
+     * @param  string $context View or edit context.
193
+     * @return int
194
+     */
195
+    public function get_customer_id( $context = 'view' ) {
196
+        return (int) $this->get_prop( 'customer_id', $context );
197
+    }
198
+
199
+    /**
200
+     * Get customer information.
201
+     *
202
+     * @since 1.0.19
203
+     * @param  string $context View or edit context.
204
+     * @return WP_User|false WP_User object on success, false on failure.
205
+     */
206
+    public function get_customer( $context = 'view' ) {
207
+        return get_userdata( $this->get_customer_id( $context ) );
208
+    }
209
+
210
+    /**
211
+     * Get parent invoice id.
212
+     *
213
+     * @since 1.0.19
214
+     * @param  string $context View or edit context.
215
+     * @return int
216
+     */
217
+    public function get_parent_invoice_id( $context = 'view' ) {
218
+        return (int) $this->get_prop( 'parent_payment_id', $context );
219
+    }
220
+
221
+    /**
222
+     * Alias for self::get_parent_invoice_id().
223
+     *
224
+     * @since 1.0.19
225
+     * @param  string $context View or edit context.
226
+     * @return int
227
+     */
228 228
     public function get_parent_payment_id( $context = 'view' ) {
229 229
         return $this->get_parent_invoice_id( $context );
230
-	}
230
+    }
231 231
 
232
-	/**
232
+    /**
233 233
      * Alias for self::get_parent_invoice_id().
234 234
      *
235 235
      * @since  1.0.0
@@ -239,390 +239,390 @@  discard block
 block discarded – undo
239 239
         return $this->get_parent_invoice_id( $context );
240 240
     }
241 241
 
242
-	/**
243
-	 * Get parent invoice.
244
-	 *
245
-	 * @since 1.0.19
246
-	 * @param  string $context View or edit context.
247
-	 * @return WPInv_Invoice
248
-	 */
249
-	public function get_parent_invoice( $context = 'view' ) {
250
-		return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
251
-	}
252
-
253
-	/**
254
-	 * Alias for self::get_parent_invoice().
255
-	 *
256
-	 * @since 1.0.19
257
-	 * @param  string $context View or edit context.
258
-	 * @return WPInv_Invoice
259
-	 */
242
+    /**
243
+     * Get parent invoice.
244
+     *
245
+     * @since 1.0.19
246
+     * @param  string $context View or edit context.
247
+     * @return WPInv_Invoice
248
+     */
249
+    public function get_parent_invoice( $context = 'view' ) {
250
+        return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
251
+    }
252
+
253
+    /**
254
+     * Alias for self::get_parent_invoice().
255
+     *
256
+     * @since 1.0.19
257
+     * @param  string $context View or edit context.
258
+     * @return WPInv_Invoice
259
+     */
260 260
     public function get_parent_payment( $context = 'view' ) {
261 261
         return $this->get_parent_invoice( $context );
262
-	}
263
-
264
-	/**
265
-	 * Get subscription's product id.
266
-	 *
267
-	 * @since 1.0.19
268
-	 * @param  string $context View or edit context.
269
-	 * @return int
270
-	 */
271
-	public function get_product_id( $context = 'view' ) {
272
-		return (int) $this->get_prop( 'product_id', $context );
273
-	}
274
-
275
-	/**
276
-	 * Get the subscription product.
277
-	 *
278
-	 * @since 1.0.19
279
-	 * @param  string $context View or edit context.
280
-	 * @return WPInv_Item
281
-	 */
282
-	public function get_product( $context = 'view' ) {
283
-		return new WPInv_Item( $this->get_product_id( $context ) );
284
-	}
285
-
286
-	/**
287
-	 * Get parent invoice's gateway.
288
-	 *
289
-	 * Here for backwards compatibility.
290
-	 *
291
-	 * @since 1.0.19
292
-	 * @param  string $context View or edit context.
293
-	 * @return string
294
-	 */
295
-	public function get_gateway( $context = 'view' ) {
296
-		return $this->get_parent_invoice( $context )->get_gateway();
297
-	}
298
-
299
-	/**
300
-	 * Get the period of a renewal.
301
-	 *
302
-	 * @since 1.0.19
303
-	 * @param  string $context View or edit context.
304
-	 * @return string
305
-	 */
306
-	public function get_period( $context = 'view' ) {
307
-		return $this->get_prop( 'period', $context );
308
-	}
309
-
310
-	/**
311
-	 * Get number of periods each renewal is valid for.
312
-	 *
313
-	 * @since 1.0.19
314
-	 * @param  string $context View or edit context.
315
-	 * @return int
316
-	 */
317
-	public function get_frequency( $context = 'view' ) {
318
-		return (int) $this->get_prop( 'frequency', $context );
319
-	}
320
-
321
-	/**
322
-	 * Get the initial amount for the subscription.
323
-	 *
324
-	 * @since 1.0.19
325
-	 * @param  string $context View or edit context.
326
-	 * @return float
327
-	 */
328
-	public function get_initial_amount( $context = 'view' ) {
329
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
330
-	}
331
-
332
-	/**
333
-	 * Get the recurring amount for the subscription.
334
-	 *
335
-	 * @since 1.0.19
336
-	 * @param  string $context View or edit context.
337
-	 * @return float
338
-	 */
339
-	public function get_recurring_amount( $context = 'view' ) {
340
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
341
-	}
342
-
343
-	/**
344
-	 * Get number of times that this subscription can be renewed.
345
-	 *
346
-	 * @since 1.0.19
347
-	 * @param  string $context View or edit context.
348
-	 * @return int
349
-	 */
350
-	public function get_bill_times( $context = 'view' ) {
351
-		return (int) $this->get_prop( 'bill_times', $context );
352
-	}
353
-
354
-	/**
355
-	 * Get transaction id of this subscription's parent invoice.
356
-	 *
357
-	 * @since 1.0.19
358
-	 * @param  string $context View or edit context.
359
-	 * @return string
360
-	 */
361
-	public function get_transaction_id( $context = 'view' ) {
362
-		return $this->get_prop( 'transaction_id', $context );
363
-	}
364
-
365
-	/**
366
-	 * Get the date that the subscription was created.
367
-	 *
368
-	 * @since 1.0.19
369
-	 * @param  string $context View or edit context.
370
-	 * @return string
371
-	 */
372
-	public function get_created( $context = 'view' ) {
373
-		return $this->get_prop( 'created', $context );
374
-	}
375
-
376
-	/**
377
-	 * Alias for self::get_created().
378
-	 *
379
-	 * @since 1.0.19
380
-	 * @param  string $context View or edit context.
381
-	 * @return string
382
-	 */
383
-	public function get_date_created( $context = 'view' ) {
384
-		return $this->get_created( $context );
385
-	}
386
-
387
-	/**
388
-	 * Retrieves the creation date in a timestamp
389
-	 *
390
-	 * @since  1.0.0
391
-	 * @return int
392
-	 */
393
-	public function get_time_created() {
394
-		$created = $this->get_date_created();
395
-		return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
396
-	}
397
-
398
-	/**
399
-	 * Get GMT date when the subscription was created.
400
-	 *
401
-	 * @since 1.0.19
402
-	 * @param  string $context View or edit context.
403
-	 * @return string
404
-	 */
405
-	public function get_date_created_gmt( $context = 'view' ) {
262
+    }
263
+
264
+    /**
265
+     * Get subscription's product id.
266
+     *
267
+     * @since 1.0.19
268
+     * @param  string $context View or edit context.
269
+     * @return int
270
+     */
271
+    public function get_product_id( $context = 'view' ) {
272
+        return (int) $this->get_prop( 'product_id', $context );
273
+    }
274
+
275
+    /**
276
+     * Get the subscription product.
277
+     *
278
+     * @since 1.0.19
279
+     * @param  string $context View or edit context.
280
+     * @return WPInv_Item
281
+     */
282
+    public function get_product( $context = 'view' ) {
283
+        return new WPInv_Item( $this->get_product_id( $context ) );
284
+    }
285
+
286
+    /**
287
+     * Get parent invoice's gateway.
288
+     *
289
+     * Here for backwards compatibility.
290
+     *
291
+     * @since 1.0.19
292
+     * @param  string $context View or edit context.
293
+     * @return string
294
+     */
295
+    public function get_gateway( $context = 'view' ) {
296
+        return $this->get_parent_invoice( $context )->get_gateway();
297
+    }
298
+
299
+    /**
300
+     * Get the period of a renewal.
301
+     *
302
+     * @since 1.0.19
303
+     * @param  string $context View or edit context.
304
+     * @return string
305
+     */
306
+    public function get_period( $context = 'view' ) {
307
+        return $this->get_prop( 'period', $context );
308
+    }
309
+
310
+    /**
311
+     * Get number of periods each renewal is valid for.
312
+     *
313
+     * @since 1.0.19
314
+     * @param  string $context View or edit context.
315
+     * @return int
316
+     */
317
+    public function get_frequency( $context = 'view' ) {
318
+        return (int) $this->get_prop( 'frequency', $context );
319
+    }
320
+
321
+    /**
322
+     * Get the initial amount for the subscription.
323
+     *
324
+     * @since 1.0.19
325
+     * @param  string $context View or edit context.
326
+     * @return float
327
+     */
328
+    public function get_initial_amount( $context = 'view' ) {
329
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
330
+    }
331
+
332
+    /**
333
+     * Get the recurring amount for the subscription.
334
+     *
335
+     * @since 1.0.19
336
+     * @param  string $context View or edit context.
337
+     * @return float
338
+     */
339
+    public function get_recurring_amount( $context = 'view' ) {
340
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
341
+    }
342
+
343
+    /**
344
+     * Get number of times that this subscription can be renewed.
345
+     *
346
+     * @since 1.0.19
347
+     * @param  string $context View or edit context.
348
+     * @return int
349
+     */
350
+    public function get_bill_times( $context = 'view' ) {
351
+        return (int) $this->get_prop( 'bill_times', $context );
352
+    }
353
+
354
+    /**
355
+     * Get transaction id of this subscription's parent invoice.
356
+     *
357
+     * @since 1.0.19
358
+     * @param  string $context View or edit context.
359
+     * @return string
360
+     */
361
+    public function get_transaction_id( $context = 'view' ) {
362
+        return $this->get_prop( 'transaction_id', $context );
363
+    }
364
+
365
+    /**
366
+     * Get the date that the subscription was created.
367
+     *
368
+     * @since 1.0.19
369
+     * @param  string $context View or edit context.
370
+     * @return string
371
+     */
372
+    public function get_created( $context = 'view' ) {
373
+        return $this->get_prop( 'created', $context );
374
+    }
375
+
376
+    /**
377
+     * Alias for self::get_created().
378
+     *
379
+     * @since 1.0.19
380
+     * @param  string $context View or edit context.
381
+     * @return string
382
+     */
383
+    public function get_date_created( $context = 'view' ) {
384
+        return $this->get_created( $context );
385
+    }
386
+
387
+    /**
388
+     * Retrieves the creation date in a timestamp
389
+     *
390
+     * @since  1.0.0
391
+     * @return int
392
+     */
393
+    public function get_time_created() {
394
+        $created = $this->get_date_created();
395
+        return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
396
+    }
397
+
398
+    /**
399
+     * Get GMT date when the subscription was created.
400
+     *
401
+     * @since 1.0.19
402
+     * @param  string $context View or edit context.
403
+     * @return string
404
+     */
405
+    public function get_date_created_gmt( $context = 'view' ) {
406 406
         $date = $this->get_date_created( $context );
407 407
 
408 408
         if ( $date ) {
409 409
             $date = get_gmt_from_date( $date );
410 410
         }
411
-		return $date;
412
-	}
413
-
414
-	/**
415
-	 * Get the date that the subscription will renew.
416
-	 *
417
-	 * @since 1.0.19
418
-	 * @param  string $context View or edit context.
419
-	 * @return string
420
-	 */
421
-	public function get_next_renewal_date( $context = 'view' ) {
422
-		return $this->get_prop( 'expiration', $context );
423
-	}
424
-
425
-	/**
426
-	 * Alias for self::get_next_renewal_date().
427
-	 *
428
-	 * @since 1.0.19
429
-	 * @param  string $context View or edit context.
430
-	 * @return string
431
-	 */
432
-	public function get_expiration( $context = 'view' ) {
433
-		return $this->get_next_renewal_date( $context );
434
-	}
435
-
436
-	/**
437
-	 * Retrieves the expiration date in a timestamp
438
-	 *
439
-	 * @since  1.0.0
440
-	 * @return int
441
-	 */
442
-	public function get_expiration_time() {
443
-		$expiration = $this->get_expiration();
444
-
445
-		if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
446
-			return current_time( 'timestamp' );
447
-		}
448
-
449
-		$expiration = strtotime( $expiration, current_time( 'timestamp' ) );
450
-		return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
451
-	}
452
-
453
-	/**
454
-	 * Get GMT date when the subscription will renew.
455
-	 *
456
-	 * @since 1.0.19
457
-	 * @param  string $context View or edit context.
458
-	 * @return string
459
-	 */
460
-	public function get_next_renewal_date_gmt( $context = 'view' ) {
411
+        return $date;
412
+    }
413
+
414
+    /**
415
+     * Get the date that the subscription will renew.
416
+     *
417
+     * @since 1.0.19
418
+     * @param  string $context View or edit context.
419
+     * @return string
420
+     */
421
+    public function get_next_renewal_date( $context = 'view' ) {
422
+        return $this->get_prop( 'expiration', $context );
423
+    }
424
+
425
+    /**
426
+     * Alias for self::get_next_renewal_date().
427
+     *
428
+     * @since 1.0.19
429
+     * @param  string $context View or edit context.
430
+     * @return string
431
+     */
432
+    public function get_expiration( $context = 'view' ) {
433
+        return $this->get_next_renewal_date( $context );
434
+    }
435
+
436
+    /**
437
+     * Retrieves the expiration date in a timestamp
438
+     *
439
+     * @since  1.0.0
440
+     * @return int
441
+     */
442
+    public function get_expiration_time() {
443
+        $expiration = $this->get_expiration();
444
+
445
+        if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
446
+            return current_time( 'timestamp' );
447
+        }
448
+
449
+        $expiration = strtotime( $expiration, current_time( 'timestamp' ) );
450
+        return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
451
+    }
452
+
453
+    /**
454
+     * Get GMT date when the subscription will renew.
455
+     *
456
+     * @since 1.0.19
457
+     * @param  string $context View or edit context.
458
+     * @return string
459
+     */
460
+    public function get_next_renewal_date_gmt( $context = 'view' ) {
461 461
         $date = $this->get_next_renewal_date( $context );
462 462
 
463 463
         if ( $date ) {
464 464
             $date = get_gmt_from_date( $date );
465 465
         }
466
-		return $date;
467
-	}
468
-
469
-	/**
470
-	 * Get the subscription's trial period.
471
-	 *
472
-	 * @since 1.0.19
473
-	 * @param  string $context View or edit context.
474
-	 * @return string
475
-	 */
476
-	public function get_trial_period( $context = 'view' ) {
477
-		return $this->get_prop( 'trial_period', $context );
478
-	}
479
-
480
-	/**
481
-	 * Get the subscription's status.
482
-	 *
483
-	 * @since 1.0.19
484
-	 * @param  string $context View or edit context.
485
-	 * @return string
486
-	 */
487
-	public function get_status( $context = 'view' ) {
488
-		return $this->get_prop( 'status', $context );
489
-	}
490
-
491
-	/**
492
-	 * Get the subscription's profile id.
493
-	 *
494
-	 * @since 1.0.19
495
-	 * @param  string $context View or edit context.
496
-	 * @return string
497
-	 */
498
-	public function get_profile_id( $context = 'view' ) {
499
-		return $this->get_prop( 'profile_id', $context );
500
-	}
501
-
502
-	/*
466
+        return $date;
467
+    }
468
+
469
+    /**
470
+     * Get the subscription's trial period.
471
+     *
472
+     * @since 1.0.19
473
+     * @param  string $context View or edit context.
474
+     * @return string
475
+     */
476
+    public function get_trial_period( $context = 'view' ) {
477
+        return $this->get_prop( 'trial_period', $context );
478
+    }
479
+
480
+    /**
481
+     * Get the subscription's status.
482
+     *
483
+     * @since 1.0.19
484
+     * @param  string $context View or edit context.
485
+     * @return string
486
+     */
487
+    public function get_status( $context = 'view' ) {
488
+        return $this->get_prop( 'status', $context );
489
+    }
490
+
491
+    /**
492
+     * Get the subscription's profile id.
493
+     *
494
+     * @since 1.0.19
495
+     * @param  string $context View or edit context.
496
+     * @return string
497
+     */
498
+    public function get_profile_id( $context = 'view' ) {
499
+        return $this->get_prop( 'profile_id', $context );
500
+    }
501
+
502
+    /*
503 503
 	|--------------------------------------------------------------------------
504 504
 	| Setters
505 505
 	|--------------------------------------------------------------------------
506 506
 	*/
507 507
 
508
-	/**
509
-	 * Set customer id.
510
-	 *
511
-	 * @since 1.0.19
512
-	 * @param  int $value The customer's id.
513
-	 */
514
-	public function set_customer_id( $value ) {
515
-		$this->set_prop( 'customer_id', (int) $value );
516
-	}
517
-
518
-	/**
519
-	 * Set parent invoice id.
520
-	 *
521
-	 * @since 1.0.19
522
-	 * @param  int $value The parent invoice id.
523
-	 */
524
-	public function set_parent_invoice_id( $value ) {
525
-		$this->set_prop( 'parent_payment_id', (int) $value );
526
-	}
527
-
528
-	/**
529
-	 * Alias for self::set_parent_invoice_id().
530
-	 *
531
-	 * @since 1.0.19
532
-	 * @param  int $value The parent invoice id.
533
-	 */
508
+    /**
509
+     * Set customer id.
510
+     *
511
+     * @since 1.0.19
512
+     * @param  int $value The customer's id.
513
+     */
514
+    public function set_customer_id( $value ) {
515
+        $this->set_prop( 'customer_id', (int) $value );
516
+    }
517
+
518
+    /**
519
+     * Set parent invoice id.
520
+     *
521
+     * @since 1.0.19
522
+     * @param  int $value The parent invoice id.
523
+     */
524
+    public function set_parent_invoice_id( $value ) {
525
+        $this->set_prop( 'parent_payment_id', (int) $value );
526
+    }
527
+
528
+    /**
529
+     * Alias for self::set_parent_invoice_id().
530
+     *
531
+     * @since 1.0.19
532
+     * @param  int $value The parent invoice id.
533
+     */
534 534
     public function set_parent_payment_id( $value ) {
535 535
         $this->set_parent_invoice_id( $value );
536
-	}
536
+    }
537 537
 
538
-	/**
538
+    /**
539 539
      * Alias for self::set_parent_invoice_id().
540 540
      *
541 541
      * @since 1.0.19
542
-	 * @param  int $value The parent invoice id.
542
+     * @param  int $value The parent invoice id.
543 543
      */
544 544
     public function set_original_payment_id( $value ) {
545 545
         $this->set_parent_invoice_id( $value );
546
-	}
547
-
548
-	/**
549
-	 * Set subscription's product id.
550
-	 *
551
-	 * @since 1.0.19
552
-	 * @param  int $value The subscription product id.
553
-	 */
554
-	public function set_product_id( $value ) {
555
-		$this->set_prop( 'product_id', (int) $value );
556
-	}
557
-
558
-	/**
559
-	 * Set the period of a renewal.
560
-	 *
561
-	 * @since 1.0.19
562
-	 * @param  string $value The renewal period.
563
-	 */
564
-	public function set_period( $value ) {
565
-		$this->set_prop( 'period', $value );
566
-	}
567
-
568
-	/**
569
-	 * Set number of periods each renewal is valid for.
570
-	 *
571
-	 * @since 1.0.19
572
-	 * @param  int $value The subscription frequency.
573
-	 */
574
-	public function set_frequency( $value ) {
575
-		$value = empty( $value ) ? 1 : (int) $value;
576
-		$this->set_prop( 'frequency', absint( $value ) );
577
-	}
578
-
579
-	/**
580
-	 * Set the initial amount for the subscription.
581
-	 *
582
-	 * @since 1.0.19
583
-	 * @param  float $value The initial subcription amount.
584
-	 */
585
-	public function set_initial_amount( $value ) {
586
-		$this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
587
-	}
588
-
589
-	/**
590
-	 * Set the recurring amount for the subscription.
591
-	 *
592
-	 * @since 1.0.19
593
-	 * @param  float $value The recurring subcription amount.
594
-	 */
595
-	public function set_recurring_amount( $value ) {
596
-		$this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
597
-	}
598
-
599
-	/**
600
-	 * Set number of times that this subscription can be renewed.
601
-	 *
602
-	 * @since 1.0.19
603
-	 * @param  int $value Bill times.
604
-	 */
605
-	public function set_bill_times( $value ) {
606
-		$this->set_prop( 'bill_times', (int) $value );
607
-	}
608
-
609
-	/**
610
-	 * Get transaction id of this subscription's parent invoice.
611
-	 *
612
-	 * @since 1.0.19
613
-	 * @param string $value Bill times.
614
-	 */
615
-	public function set_transaction_id( $value ) {
616
-		$this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
617
-	}
618
-
619
-	/**
620
-	 * Set date when this subscription started.
621
-	 *
622
-	 * @since 1.0.19
623
-	 * @param string $value strtotime compliant date.
624
-	 */
625
-	public function set_created( $value ) {
546
+    }
547
+
548
+    /**
549
+     * Set subscription's product id.
550
+     *
551
+     * @since 1.0.19
552
+     * @param  int $value The subscription product id.
553
+     */
554
+    public function set_product_id( $value ) {
555
+        $this->set_prop( 'product_id', (int) $value );
556
+    }
557
+
558
+    /**
559
+     * Set the period of a renewal.
560
+     *
561
+     * @since 1.0.19
562
+     * @param  string $value The renewal period.
563
+     */
564
+    public function set_period( $value ) {
565
+        $this->set_prop( 'period', $value );
566
+    }
567
+
568
+    /**
569
+     * Set number of periods each renewal is valid for.
570
+     *
571
+     * @since 1.0.19
572
+     * @param  int $value The subscription frequency.
573
+     */
574
+    public function set_frequency( $value ) {
575
+        $value = empty( $value ) ? 1 : (int) $value;
576
+        $this->set_prop( 'frequency', absint( $value ) );
577
+    }
578
+
579
+    /**
580
+     * Set the initial amount for the subscription.
581
+     *
582
+     * @since 1.0.19
583
+     * @param  float $value The initial subcription amount.
584
+     */
585
+    public function set_initial_amount( $value ) {
586
+        $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
587
+    }
588
+
589
+    /**
590
+     * Set the recurring amount for the subscription.
591
+     *
592
+     * @since 1.0.19
593
+     * @param  float $value The recurring subcription amount.
594
+     */
595
+    public function set_recurring_amount( $value ) {
596
+        $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
597
+    }
598
+
599
+    /**
600
+     * Set number of times that this subscription can be renewed.
601
+     *
602
+     * @since 1.0.19
603
+     * @param  int $value Bill times.
604
+     */
605
+    public function set_bill_times( $value ) {
606
+        $this->set_prop( 'bill_times', (int) $value );
607
+    }
608
+
609
+    /**
610
+     * Get transaction id of this subscription's parent invoice.
611
+     *
612
+     * @since 1.0.19
613
+     * @param string $value Bill times.
614
+     */
615
+    public function set_transaction_id( $value ) {
616
+        $this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
617
+    }
618
+
619
+    /**
620
+     * Set date when this subscription started.
621
+     *
622
+     * @since 1.0.19
623
+     * @param string $value strtotime compliant date.
624
+     */
625
+    public function set_created( $value ) {
626 626
         $date = strtotime( $value );
627 627
 
628 628
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -630,94 +630,94 @@  discard block
 block discarded – undo
630 630
             return;
631 631
         }
632 632
 
633
-		$this->set_prop( 'created', '' );
633
+        $this->set_prop( 'created', '' );
634 634
 
635
-	}
635
+    }
636 636
 
637
-	/**
638
-	 * Alias for self::set_created().
639
-	 *
640
-	 * @since 1.0.19
641
-	 * @param string $value strtotime compliant date.
642
-	 */
643
-	public function set_date_created( $value ) {
644
-		$this->set_created( $value );
637
+    /**
638
+     * Alias for self::set_created().
639
+     *
640
+     * @since 1.0.19
641
+     * @param string $value strtotime compliant date.
642
+     */
643
+    public function set_date_created( $value ) {
644
+        $this->set_created( $value );
645 645
     }
646 646
 
647
-	/**
648
-	 * Set the date that the subscription will renew.
649
-	 *
650
-	 * @since 1.0.19
651
-	 * @param string $value strtotime compliant date.
652
-	 */
653
-	public function set_next_renewal_date( $value ) {
654
-		$date = strtotime( $value );
647
+    /**
648
+     * Set the date that the subscription will renew.
649
+     *
650
+     * @since 1.0.19
651
+     * @param string $value strtotime compliant date.
652
+     */
653
+    public function set_next_renewal_date( $value ) {
654
+        $date = strtotime( $value );
655 655
 
656 656
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
657 657
             $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) );
658 658
             return;
659
-		}
660
-
661
-		$this->set_prop( 'expiration', '' );
662
-
663
-	}
664
-
665
-	/**
666
-	 * Alias for self::set_next_renewal_date().
667
-	 *
668
-	 * @since 1.0.19
669
-	 * @param string $value strtotime compliant date.
670
-	 */
671
-	public function set_expiration( $value ) {
672
-		$this->set_next_renewal_date( $value );
673
-    }
674
-
675
-	/**
676
-	 * Set the subscription's trial period.
677
-	 *
678
-	 * @since 1.0.19
679
-	 * @param string $value trial period e.g 1 year.
680
-	 */
681
-	public function set_trial_period( $value ) {
682
-		$this->set_prop( 'trial_period', $value );
683
-	}
684
-
685
-	/**
686
-	 * Set the subscription's status.
687
-	 *
688
-	 * @since 1.0.19
689
-	 * @param string $new_status    New subscription status.
690
-	 */
691
-	public function set_status( $new_status ) {
692
-
693
-		// Abort if this is not a valid status;
694
-		if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
695
-			return;
696
-		}
697
-
698
-		$old_status = $this->get_status();
699
-		$this->set_prop( 'status', $new_status );
700
-
701
-		if ( true === $this->object_read && $old_status !== $new_status ) {
702
-			$this->status_transition = array(
703
-				'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
704
-				'to'     => $new_status,
705
-			);
706
-		}
707
-
708
-	}
709
-
710
-	/**
711
-	 * Set the subscription's (remote) profile id.
712
-	 *
713
-	 * @since 1.0.19
714
-	 * @param  string $value the remote profile id.
715
-	 */
716
-	public function set_profile_id( $value ) {
717
-		$this->set_prop( 'profile_id', sanitize_text_field( $value ) );
718
-	}
719
-
720
-	/*
659
+        }
660
+
661
+        $this->set_prop( 'expiration', '' );
662
+
663
+    }
664
+
665
+    /**
666
+     * Alias for self::set_next_renewal_date().
667
+     *
668
+     * @since 1.0.19
669
+     * @param string $value strtotime compliant date.
670
+     */
671
+    public function set_expiration( $value ) {
672
+        $this->set_next_renewal_date( $value );
673
+    }
674
+
675
+    /**
676
+     * Set the subscription's trial period.
677
+     *
678
+     * @since 1.0.19
679
+     * @param string $value trial period e.g 1 year.
680
+     */
681
+    public function set_trial_period( $value ) {
682
+        $this->set_prop( 'trial_period', $value );
683
+    }
684
+
685
+    /**
686
+     * Set the subscription's status.
687
+     *
688
+     * @since 1.0.19
689
+     * @param string $new_status    New subscription status.
690
+     */
691
+    public function set_status( $new_status ) {
692
+
693
+        // Abort if this is not a valid status;
694
+        if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
695
+            return;
696
+        }
697
+
698
+        $old_status = $this->get_status();
699
+        $this->set_prop( 'status', $new_status );
700
+
701
+        if ( true === $this->object_read && $old_status !== $new_status ) {
702
+            $this->status_transition = array(
703
+                'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
704
+                'to'     => $new_status,
705
+            );
706
+        }
707
+
708
+    }
709
+
710
+    /**
711
+     * Set the subscription's (remote) profile id.
712
+     *
713
+     * @since 1.0.19
714
+     * @param  string $value the remote profile id.
715
+     */
716
+    public function set_profile_id( $value ) {
717
+        $this->set_prop( 'profile_id', sanitize_text_field( $value ) );
718
+    }
719
+
720
+    /*
721 721
 	|--------------------------------------------------------------------------
722 722
 	| Boolean methods
723 723
 	|--------------------------------------------------------------------------
@@ -726,45 +726,45 @@  discard block
 block discarded – undo
726 726
 	|
727 727
 	*/
728 728
 
729
-	/**
729
+    /**
730 730
      * Checks if the subscription has a given status.
731
-	 *
732
-	 * @param string|array String or array of strings to check for.
733
-	 * @return bool
731
+     *
732
+     * @param string|array String or array of strings to check for.
733
+     * @return bool
734 734
      */
735 735
     public function has_status( $status ) {
736 736
         return in_array( $this->get_status(), wpinv_parse_list( $status ) );
737
-	}
737
+    }
738 738
 
739
-	/**
739
+    /**
740 740
      * Checks if the subscription has a trial period.
741
-	 *
742
-	 * @return bool
741
+     *
742
+     * @return bool
743 743
      */
744 744
     public function has_trial_period() {
745
-		$period = $this->get_trial_period();
745
+        $period = $this->get_trial_period();
746 746
         return ! empty( $period );
747
-	}
748
-
749
-	/**
750
-	 * Is the subscription active?
751
-	 *
752
-	 * @return bool
753
-	 */
754
-	public function is_active() {
755
-		return $this->has_status( 'active trialling' ) && $this->get_expiration_time() > current_time( 'mysql' );
756
-	}
757
-
758
-	/**
759
-	 * Is the subscription expired?
760
-	 *
761
-	 * @return bool
762
-	 */
763
-	public function is_expired() {
764
-		return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) );
765
-	}
766
-
767
-	/*
747
+    }
748
+
749
+    /**
750
+     * Is the subscription active?
751
+     *
752
+     * @return bool
753
+     */
754
+    public function is_active() {
755
+        return $this->has_status( 'active trialling' ) && $this->get_expiration_time() > current_time( 'mysql' );
756
+    }
757
+
758
+    /**
759
+     * Is the subscription expired?
760
+     *
761
+     * @return bool
762
+     */
763
+    public function is_expired() {
764
+        return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) );
765
+    }
766
+
767
+    /*
768 768
 	|--------------------------------------------------------------------------
769 769
 	| Additional methods
770 770
 	|--------------------------------------------------------------------------
@@ -773,27 +773,27 @@  discard block
 block discarded – undo
773 773
 	|
774 774
 	*/
775 775
 
776
-	/**
777
-	 * Backwards compatibilty.
778
-	 */
779
-	public function create( $data = array() ) {
776
+    /**
777
+     * Backwards compatibilty.
778
+     */
779
+    public function create( $data = array() ) {
780 780
 
781
-		// Set the properties.
782
-		if ( is_array( $data ) ) {
783
-			$this->set_props( $data );
784
-		}
781
+        // Set the properties.
782
+        if ( is_array( $data ) ) {
783
+            $this->set_props( $data );
784
+        }
785 785
 
786
-		// Save the item.
787
-		return $this->save();
786
+        // Save the item.
787
+        return $this->save();
788 788
 
789
-	}
789
+    }
790 790
 
791
-	/**
792
-	 * Backwards compatibilty.
793
-	 */
794
-	public function update( $args = array() ) {
795
-		return $this->create( $args );
796
-	}
791
+    /**
792
+     * Backwards compatibilty.
793
+     */
794
+    public function update( $args = array() ) {
795
+        return $this->create( $args );
796
+    }
797 797
 
798 798
     /**
799 799
      * Retrieve renewal payments for a subscription
@@ -803,15 +803,15 @@  discard block
 block discarded – undo
803 803
      */
804 804
     public function get_child_payments() {
805 805
         return get_posts(
806
-			array(
807
-            	'post_parent'    => $this->get_parent_payment_id(),
808
-            	'numberposts'    => -1,
809
-            	'post_status'    => array( 'publish', 'wpi-processing', 'wpi-renewal' ),
810
-            	'orderby'        => 'ID',
811
-            	'order'          => 'DESC',
812
-            	'post_type'      => 'wpi_invoice'
813
-			)
814
-		);
806
+            array(
807
+                'post_parent'    => $this->get_parent_payment_id(),
808
+                'numberposts'    => -1,
809
+                'post_status'    => array( 'publish', 'wpi-processing', 'wpi-renewal' ),
810
+                'orderby'        => 'ID',
811
+                'order'          => 'DESC',
812
+                'post_type'      => 'wpi_invoice'
813
+            )
814
+        );
815 815
     }
816 816
 
817 817
     /**
@@ -821,16 +821,16 @@  discard block
 block discarded – undo
821 821
      * @return int
822 822
      */
823 823
     public function get_total_payments() {
824
-		global $wpdb;
824
+        global $wpdb;
825 825
 
826
-		$count = (int) $wpdb->get_var(
827
-			$wpdb->prepare(
828
-				"SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
829
-				$this->get_parent_invoice_id()
830
-			)
831
-		);
826
+        $count = (int) $wpdb->get_var(
827
+            $wpdb->prepare(
828
+                "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
829
+                $this->get_parent_invoice_id()
830
+            )
831
+        );
832 832
 
833
-		// Maybe include parent invoice.
833
+        // Maybe include parent invoice.
834 834
         if ( ! $this->has_status( 'pending' ) ) {
835 835
             $count++;
836 836
         }
@@ -859,57 +859,57 @@  discard block
 block discarded – undo
859 859
      *
860 860
      * @since  2.4
861 861
      * @param  array $args Array of values for the payment, including amount and transaction ID
862
-	 * @param  WPInv_Invoice $invoice If adding an existing invoice.
862
+     * @param  WPInv_Invoice $invoice If adding an existing invoice.
863 863
      * @return bool
864 864
      */
865 865
     public function add_payment( $args = array(), $invoice = false ) {
866 866
 
867
-		// Process each payment once.
867
+        // Process each payment once.
868 868
         if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) {
869 869
             return false;
870 870
         }
871 871
 
872
-		// Are we creating a new invoice?
873
-		if ( empty( $invoice ) ) {
874
-			$invoice = $this->create_payment();
872
+        // Are we creating a new invoice?
873
+        if ( empty( $invoice ) ) {
874
+            $invoice = $this->create_payment();
875 875
 
876
-			if ( empty( $invoice ) ) {
877
-				return false;
878
-			}
876
+            if ( empty( $invoice ) ) {
877
+                return false;
878
+            }
879 879
 
880
-			$invoice->set_status( 'wpi-renewal' );
880
+            $invoice->set_status( 'wpi-renewal' );
881 881
 
882
-		}
882
+        }
883 883
 
884
-		// Maybe set a transaction id.
885
-		if ( ! empty( $args['transaction_id'] ) ) {
886
-			$invoice->set_transaction_id( $args['transaction_id'] );
887
-		}
884
+        // Maybe set a transaction id.
885
+        if ( ! empty( $args['transaction_id'] ) ) {
886
+            $invoice->set_transaction_id( $args['transaction_id'] );
887
+        }
888 888
 
889
-		// Set the completed date.
890
-		$invoice->set_completed_date( current_time( 'mysql' ) );
889
+        // Set the completed date.
890
+        $invoice->set_completed_date( current_time( 'mysql' ) );
891 891
 
892
-		// And the gateway.
893
-		if ( ! empty( $args['gateway'] ) ) {
894
-			$invoice->set_gateway( $args['gateway'] );
895
-		}
892
+        // And the gateway.
893
+        if ( ! empty( $args['gateway'] ) ) {
894
+            $invoice->set_gateway( $args['gateway'] );
895
+        }
896 896
 
897
-		$invoice->save();
897
+        $invoice->save();
898 898
 
899
-		if ( ! $invoice->get_id() ) {
900
-			return 0;
901
-		}
899
+        if ( ! $invoice->get_id() ) {
900
+            return 0;
901
+        }
902 902
 
903
-		do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
904
-		do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
903
+        do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
904
+        do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
905 905
         do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() );
906 906
 
907 907
         update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id );
908 908
 
909 909
         return $invoice->get_id();
910
-	}
910
+    }
911 911
 
912
-	/**
912
+    /**
913 913
      * Creates a new invoice and returns it.
914 914
      *
915 915
      * @since  1.0.19
@@ -917,104 +917,104 @@  discard block
 block discarded – undo
917 917
      */
918 918
     public function create_payment() {
919 919
 
920
-		$parent_invoice = $this->get_parent_payment();
921
-
922
-		if ( ! $parent_invoice->get_id() ) {
923
-			return false;
924
-		}
925
-
926
-		// Duplicate the parent invoice.
927
-		$invoice = new WPInv_Invoice();
928
-		$invoice->set_props( $parent_invoice->get_data() );
929
-		$invoice->set_id( 0 );
930
-		$invoice->set_items( $parent_invoice->get_items() );
931
-		$invoice->set_parent_id( $parent_invoice->get_id() );
932
-		$invoice->set_transaction_id( '' );
933
-		$invoice->set_key( $invoice->generate_key( 'renewal_' ) );
934
-		$invoice->set_number( '' );
935
-		$invoice->set_completed_date( '' );
936
-		$invoice->set_status( 'wpi-pending' );
937
-		$invoice->recalculate_total();
938
-		$invoice->save();
939
-
940
-		return $invoice->get_id() ? $invoice : false;
941
-    }
942
-
943
-	/**
944
-	 * Renews or completes a subscription
945
-	 *
946
-	 * @since  1.0.0
947
-	 * @return int The subscription's id
948
-	 */
949
-	public function renew() {
950
-
951
-		// Complete subscription if applicable
952
-		if ( $this->get_bill_times() > 0 && $this->get_times_billed() >= $this->get_bill_times() ) {
953
-			return $this->complete();
954
-		}
955
-
956
-		// Calculate new expiration
957
-		$frequency      = $this->get_frequency();
958
-		$period         = $this->get_period();
959
-		$new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
960
-
961
-		$this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) );
962
-		$this->set_status( 'active' );
963
-		return $this->save();
964
-
965
-		do_action( 'getpaid_subscription_renewed', $this );
966
-
967
-	}
968
-
969
-	/**
970
-	 * Marks a subscription as completed
971
-	 *
972
-	 * Subscription is completed when the number of payments matches the billing_times field
973
-	 *
974
-	 * @since  1.0.0
975
-	 * @return int|bool Subscription id or false if the subscription is cancelled.
976
-	 */
977
-	public function complete() {
978
-
979
-		// Only mark a subscription as complete if it's not already cancelled.
980
-		if ( $this->has_status( 'cancelled' ) ) {
981
-			return false;
982
-		}
983
-
984
-		$this->set_status( 'completed' );
985
-		return $this->save();
986
-
987
-	}
988
-
989
-	/**
990
-	 * Marks a subscription as expired
991
-	 *
992
-	 * @since  1.0.0
993
-	 * @param  bool $check_expiration
994
-	 * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
995
-	 */
996
-	public function expire( $check_expiration = false ) {
997
-
998
-		if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
999
-			// Do not mark as expired since real expiration date is in the future
1000
-			return false;
1001
-		}
1002
-
1003
-		$this->set_status( 'expired' );
1004
-		return $this->save();
1005
-
1006
-	}
1007
-
1008
-	/**
1009
-	 * Marks a subscription as failing
1010
-	 *
1011
-	 * @since  2.4.2
1012
-	 * @return int Subscription id.
1013
-	 */
1014
-	public function failing() {
1015
-		$this->set_status( 'failing' );
1016
-		return $this->save();
1017
-	}
920
+        $parent_invoice = $this->get_parent_payment();
921
+
922
+        if ( ! $parent_invoice->get_id() ) {
923
+            return false;
924
+        }
925
+
926
+        // Duplicate the parent invoice.
927
+        $invoice = new WPInv_Invoice();
928
+        $invoice->set_props( $parent_invoice->get_data() );
929
+        $invoice->set_id( 0 );
930
+        $invoice->set_items( $parent_invoice->get_items() );
931
+        $invoice->set_parent_id( $parent_invoice->get_id() );
932
+        $invoice->set_transaction_id( '' );
933
+        $invoice->set_key( $invoice->generate_key( 'renewal_' ) );
934
+        $invoice->set_number( '' );
935
+        $invoice->set_completed_date( '' );
936
+        $invoice->set_status( 'wpi-pending' );
937
+        $invoice->recalculate_total();
938
+        $invoice->save();
939
+
940
+        return $invoice->get_id() ? $invoice : false;
941
+    }
942
+
943
+    /**
944
+     * Renews or completes a subscription
945
+     *
946
+     * @since  1.0.0
947
+     * @return int The subscription's id
948
+     */
949
+    public function renew() {
950
+
951
+        // Complete subscription if applicable
952
+        if ( $this->get_bill_times() > 0 && $this->get_times_billed() >= $this->get_bill_times() ) {
953
+            return $this->complete();
954
+        }
955
+
956
+        // Calculate new expiration
957
+        $frequency      = $this->get_frequency();
958
+        $period         = $this->get_period();
959
+        $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
960
+
961
+        $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) );
962
+        $this->set_status( 'active' );
963
+        return $this->save();
964
+
965
+        do_action( 'getpaid_subscription_renewed', $this );
966
+
967
+    }
968
+
969
+    /**
970
+     * Marks a subscription as completed
971
+     *
972
+     * Subscription is completed when the number of payments matches the billing_times field
973
+     *
974
+     * @since  1.0.0
975
+     * @return int|bool Subscription id or false if the subscription is cancelled.
976
+     */
977
+    public function complete() {
978
+
979
+        // Only mark a subscription as complete if it's not already cancelled.
980
+        if ( $this->has_status( 'cancelled' ) ) {
981
+            return false;
982
+        }
983
+
984
+        $this->set_status( 'completed' );
985
+        return $this->save();
986
+
987
+    }
988
+
989
+    /**
990
+     * Marks a subscription as expired
991
+     *
992
+     * @since  1.0.0
993
+     * @param  bool $check_expiration
994
+     * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
995
+     */
996
+    public function expire( $check_expiration = false ) {
997
+
998
+        if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
999
+            // Do not mark as expired since real expiration date is in the future
1000
+            return false;
1001
+        }
1002
+
1003
+        $this->set_status( 'expired' );
1004
+        return $this->save();
1005
+
1006
+    }
1007
+
1008
+    /**
1009
+     * Marks a subscription as failing
1010
+     *
1011
+     * @since  2.4.2
1012
+     * @return int Subscription id.
1013
+     */
1014
+    public function failing() {
1015
+        $this->set_status( 'failing' );
1016
+        return $this->save();
1017
+    }
1018 1018
 
1019 1019
     /**
1020 1020
      * Marks a subscription as cancelled
@@ -1023,19 +1023,19 @@  discard block
 block discarded – undo
1023 1023
      * @return int Subscription id.
1024 1024
      */
1025 1025
     public function cancel() {
1026
-		$this->set_status( 'cancelled' );
1027
-		return $this->save();
1026
+        $this->set_status( 'cancelled' );
1027
+        return $this->save();
1028 1028
     }
1029 1029
 
1030
-	/**
1031
-	 * Determines if a subscription can be cancelled both locally and with a payment processor.
1032
-	 *
1033
-	 * @since  1.0.0
1034
-	 * @return bool
1035
-	 */
1036
-	public function can_cancel() {
1037
-		return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1038
-	}
1030
+    /**
1031
+     * Determines if a subscription can be cancelled both locally and with a payment processor.
1032
+     *
1033
+     * @since  1.0.0
1034
+     * @return bool
1035
+     */
1036
+    public function can_cancel() {
1037
+        return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1038
+    }
1039 1039
 
1040 1040
     /**
1041 1041
      * Returns an array of subscription statuses that can be cancelled
@@ -1048,82 +1048,82 @@  discard block
 block discarded – undo
1048 1048
         return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) );
1049 1049
     }
1050 1050
 
1051
-	/**
1052
-	 * Retrieves the URL to cancel subscription
1053
-	 *
1054
-	 * @since  1.0.0
1055
-	 * @return string
1056
-	 */
1057
-	public function get_cancel_url() {
1058
-		$url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'subscription_cancel', 'sub_id' => $this->get_id() ) ), 'getpaid-nonce' );
1059
-		return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1060
-	}
1061
-
1062
-	/**
1063
-	 * Determines if subscription can be manually renewed
1064
-	 *
1065
-	 * This method is filtered by payment gateways in order to return true on subscriptions
1066
-	 * that can be renewed manually
1067
-	 *
1068
-	 * @since  2.5
1069
-	 * @return bool
1070
-	 */
1071
-	public function can_renew() {
1072
-		return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1073
-	}
1074
-
1075
-	/**
1076
-	 * Retrieves the URL to renew a subscription
1077
-	 *
1078
-	 * @since  2.5
1079
-	 * @return string
1080
-	 */
1081
-	public function get_renew_url() {
1082
-		$url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' );
1083
-		return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1084
-	}
1085
-
1086
-	/**
1087
-	 * Determines if subscription can have their payment method updated
1088
-	 *
1089
-	 * @since  1.0.0
1090
-	 * @return bool
1091
-	 */
1092
-	public function can_update() {
1093
-		return apply_filters( 'wpinv_subscription_can_update', false, $this );
1094
-	}
1095
-
1096
-	/**
1097
-	 * Retrieves the URL to update subscription
1098
-	 *
1099
-	 * @since  1.0.0
1100
-	 * @return string
1101
-	 */
1102
-	public function get_update_url() {
1103
-		$url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) );
1104
-		return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1105
-	}
1106
-
1107
-	/**
1108
-	 * Retrieves the subscription status label
1109
-	 *
1110
-	 * @since  1.0.0
1111
-	 * @return string
1112
-	 */
1113
-	public function get_status_label() {
1114
-		return getpaid_get_subscription_status_label( $this->get_status() );
1115
-	}
1116
-
1117
-	/**
1118
-	 * Retrieves the subscription status class
1119
-	 *
1120
-	 * @since  1.0.19
1121
-	 * @return string
1122
-	 */
1123
-	public function get_status_class() {
1124
-		$statuses = getpaid_get_subscription_status_classes();
1125
-		return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary';
1126
-	}
1051
+    /**
1052
+     * Retrieves the URL to cancel subscription
1053
+     *
1054
+     * @since  1.0.0
1055
+     * @return string
1056
+     */
1057
+    public function get_cancel_url() {
1058
+        $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'subscription_cancel', 'sub_id' => $this->get_id() ) ), 'getpaid-nonce' );
1059
+        return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1060
+    }
1061
+
1062
+    /**
1063
+     * Determines if subscription can be manually renewed
1064
+     *
1065
+     * This method is filtered by payment gateways in order to return true on subscriptions
1066
+     * that can be renewed manually
1067
+     *
1068
+     * @since  2.5
1069
+     * @return bool
1070
+     */
1071
+    public function can_renew() {
1072
+        return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1073
+    }
1074
+
1075
+    /**
1076
+     * Retrieves the URL to renew a subscription
1077
+     *
1078
+     * @since  2.5
1079
+     * @return string
1080
+     */
1081
+    public function get_renew_url() {
1082
+        $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' );
1083
+        return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1084
+    }
1085
+
1086
+    /**
1087
+     * Determines if subscription can have their payment method updated
1088
+     *
1089
+     * @since  1.0.0
1090
+     * @return bool
1091
+     */
1092
+    public function can_update() {
1093
+        return apply_filters( 'wpinv_subscription_can_update', false, $this );
1094
+    }
1095
+
1096
+    /**
1097
+     * Retrieves the URL to update subscription
1098
+     *
1099
+     * @since  1.0.0
1100
+     * @return string
1101
+     */
1102
+    public function get_update_url() {
1103
+        $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) );
1104
+        return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1105
+    }
1106
+
1107
+    /**
1108
+     * Retrieves the subscription status label
1109
+     *
1110
+     * @since  1.0.0
1111
+     * @return string
1112
+     */
1113
+    public function get_status_label() {
1114
+        return getpaid_get_subscription_status_label( $this->get_status() );
1115
+    }
1116
+
1117
+    /**
1118
+     * Retrieves the subscription status class
1119
+     *
1120
+     * @since  1.0.19
1121
+     * @return string
1122
+     */
1123
+    public function get_status_class() {
1124
+        $statuses = getpaid_get_subscription_status_classes();
1125
+        return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary';
1126
+    }
1127 1127
 
1128 1128
     /**
1129 1129
      * Retrieves the subscription status label
@@ -1133,11 +1133,11 @@  discard block
 block discarded – undo
1133 1133
      */
1134 1134
     public function get_status_label_html() {
1135 1135
 
1136
-		$status_label = sanitize_text_field( $this->get_status_label() );
1137
-		$class        = esc_attr( $this->get_status_class() );
1138
-		$status       = sanitize_html_class( $this->get_status_label() );
1136
+        $status_label = sanitize_text_field( $this->get_status_label() );
1137
+        $class        = esc_attr( $this->get_status_class() );
1138
+        $status       = sanitize_html_class( $this->get_status_label() );
1139 1139
 
1140
-		return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>";
1140
+        return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>";
1141 1141
     }
1142 1142
 
1143 1143
     /**
@@ -1148,63 +1148,63 @@  discard block
 block discarded – undo
1148 1148
      * @return bool
1149 1149
      */
1150 1150
     public function payment_exists( $txn_id = '' ) {
1151
-		$invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1151
+        $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1152 1152
         return ! empty( $invoice_id );
1153
-	}
1154
-
1155
-	/**
1156
-	 * Handle the status transition.
1157
-	 */
1158
-	protected function status_transition() {
1159
-		$status_transition = $this->status_transition;
1160
-
1161
-		// Reset status transition variable.
1162
-		$this->status_transition = false;
1163
-
1164
-		if ( $status_transition ) {
1165
-			try {
1166
-
1167
-				// Fire a hook for the status change.
1168
-				do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1169
-				do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1170
-
1171
-				if ( ! empty( $status_transition['from'] ) ) {
1172
-
1173
-					/* translators: 1: old subscription status 2: new subscription status */
1174
-					$transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1175
-
1176
-					// Note the transition occurred.
1177
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1178
-
1179
-					// Fire another hook.
1180
-					do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1181
-					do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1182
-
1183
-				} else {
1184
-					/* translators: %s: new invoice status */
1185
-					$transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1186
-
1187
-					// Note the transition occurred.
1188
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1189
-
1190
-				}
1191
-			} catch ( Exception $e ) {
1192
-				$this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1193
-			}
1194
-		}
1195
-
1196
-	}
1197
-
1198
-	/**
1199
-	 * Save data to the database.
1200
-	 *
1201
-	 * @since 1.0.19
1202
-	 * @return int subscription ID
1203
-	 */
1204
-	public function save() {
1205
-		parent::save();
1206
-		$this->status_transition();
1207
-		return $this->get_id();
1208
-	}
1153
+    }
1154
+
1155
+    /**
1156
+     * Handle the status transition.
1157
+     */
1158
+    protected function status_transition() {
1159
+        $status_transition = $this->status_transition;
1160
+
1161
+        // Reset status transition variable.
1162
+        $this->status_transition = false;
1163
+
1164
+        if ( $status_transition ) {
1165
+            try {
1166
+
1167
+                // Fire a hook for the status change.
1168
+                do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1169
+                do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1170
+
1171
+                if ( ! empty( $status_transition['from'] ) ) {
1172
+
1173
+                    /* translators: 1: old subscription status 2: new subscription status */
1174
+                    $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1175
+
1176
+                    // Note the transition occurred.
1177
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1178
+
1179
+                    // Fire another hook.
1180
+                    do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1181
+                    do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1182
+
1183
+                } else {
1184
+                    /* translators: %s: new invoice status */
1185
+                    $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1186
+
1187
+                    // Note the transition occurred.
1188
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1189
+
1190
+                }
1191
+            } catch ( Exception $e ) {
1192
+                $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1193
+            }
1194
+        }
1195
+
1196
+    }
1197
+
1198
+    /**
1199
+     * Save data to the database.
1200
+     *
1201
+     * @since 1.0.19
1202
+     * @return int subscription ID
1203
+     */
1204
+    public function save() {
1205
+        parent::save();
1206
+        $this->status_transition();
1207
+        return $this->get_id();
1208
+    }
1209 1209
 
1210 1210
 }
Please login to merge, or discard this patch.
Spacing   +216 added lines, -216 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * The Subscription Class
@@ -70,27 +70,27 @@  discard block
 block discarded – undo
70 70
 	 * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
71 71
 	 * @param  bool $deprecated
72 72
 	 */
73
-	function __construct( $subscription = 0, $deprecated = false ) {
73
+	function __construct($subscription = 0, $deprecated = false) {
74 74
 
75
-		parent::__construct( $subscription );
75
+		parent::__construct($subscription);
76 76
 
77
-		if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
78
-			$this->set_id( $subscription );
79
-		} elseif ( $subscription instanceof self ) {
80
-			$this->set_id( $subscription->get_id() );
81
-		} elseif ( ! empty( $subscription->id ) ) {
82
-			$this->set_id( $subscription->id );
83
-		} elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
84
-			$this->set_id( $subscription_id );
77
+		if (!$deprecated && !empty($subscription) && is_numeric($subscription)) {
78
+			$this->set_id($subscription);
79
+		} elseif ($subscription instanceof self) {
80
+			$this->set_id($subscription->get_id());
81
+		} elseif (!empty($subscription->id)) {
82
+			$this->set_id($subscription->id);
83
+		} elseif ($deprecated && $subscription_id = self::get_subscription_id_by_field($subscription, 'profile_id')) {
84
+			$this->set_id($subscription_id);
85 85
 		} else {
86
-			$this->set_object_read( true );
86
+			$this->set_object_read(true);
87 87
 		}
88 88
 
89 89
 		// Load the datastore.
90
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
90
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
91 91
 
92
-		if ( $this->get_id() > 0 ) {
93
-			$this->data_store->read( $this );
92
+		if ($this->get_id() > 0) {
93
+			$this->data_store->read($this);
94 94
 		}
95 95
 
96 96
 	}
@@ -105,17 +105,17 @@  discard block
 block discarded – undo
105 105
 	 * @since 1.0.19
106 106
 	 * @return int
107 107
 	 */
108
-	public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
108
+	public static function get_subscription_id_by_field($value, $field = 'profile_id') {
109 109
         global $wpdb;
110 110
 
111 111
 		// Trim the value.
112
-		$value = trim( $value );
112
+		$value = trim($value);
113 113
 
114
-		if ( empty( $value ) ) {
114
+		if (empty($value)) {
115 115
 			return 0;
116 116
 		}
117 117
 
118
-		if ( 'invoice_id' == $field ) {
118
+		if ('invoice_id' == $field) {
119 119
 			$field = 'parent_payment_id';
120 120
 		}
121 121
 
@@ -127,28 +127,28 @@  discard block
 block discarded – undo
127 127
 		);
128 128
 
129 129
 		// Ensure a field has been passed.
130
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
130
+		if (empty($field) || !in_array($field, $fields)) {
131 131
 			return 0;
132 132
 		}
133 133
 
134 134
 		// Maybe retrieve from the cache.
135
-		$subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
136
-		if ( ! empty( $subscription_id ) ) {
135
+		$subscription_id = wp_cache_get($value, "getpaid_subscription_{$field}s_to_subscription_ids");
136
+		if (!empty($subscription_id)) {
137 137
 			return $subscription_id;
138 138
 		}
139 139
 
140 140
         // Fetch from the db.
141 141
         $table            = $wpdb->prefix . 'wpinv_subscriptions';
142 142
         $subscription_id  = (int) $wpdb->get_var(
143
-            $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
143
+            $wpdb->prepare("SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value)
144 144
         );
145 145
 
146
-		if ( empty( $subscription_id ) ) {
146
+		if (empty($subscription_id)) {
147 147
 			return 0;
148 148
 		}
149 149
 
150 150
 		// Update the cache with our data.
151
-		wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
151
+		wp_cache_set($value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids");
152 152
 
153 153
 		return $subscription_id;
154 154
 	}
@@ -157,17 +157,17 @@  discard block
 block discarded – undo
157 157
      * Clears the subscription's cache.
158 158
      */
159 159
     public function clear_cache() {
160
-		wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' );
161
-		wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' );
162
-		wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' );
163
-		wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' );
160
+		wp_cache_delete($this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids');
161
+		wp_cache_delete($this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids');
162
+		wp_cache_delete($this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids');
163
+		wp_cache_delete($this->get_id(), 'getpaid_subscriptions');
164 164
 	}
165 165
 
166 166
 	/**
167 167
      * Checks if a subscription key is set.
168 168
      */
169
-    public function _isset( $key ) {
170
-        return isset( $this->data[$key] ) || method_exists( $this, "get_$key" );
169
+    public function _isset($key) {
170
+        return isset($this->data[$key]) || method_exists($this, "get_$key");
171 171
 	}
172 172
 
173 173
 	/*
@@ -192,8 +192,8 @@  discard block
 block discarded – undo
192 192
 	 * @param  string $context View or edit context.
193 193
 	 * @return int
194 194
 	 */
195
-	public function get_customer_id( $context = 'view' ) {
196
-		return (int) $this->get_prop( 'customer_id', $context );
195
+	public function get_customer_id($context = 'view') {
196
+		return (int) $this->get_prop('customer_id', $context);
197 197
 	}
198 198
 
199 199
 	/**
@@ -203,8 +203,8 @@  discard block
 block discarded – undo
203 203
 	 * @param  string $context View or edit context.
204 204
 	 * @return WP_User|false WP_User object on success, false on failure.
205 205
 	 */
206
-	public function get_customer( $context = 'view' ) {
207
-		return get_userdata( $this->get_customer_id( $context ) );
206
+	public function get_customer($context = 'view') {
207
+		return get_userdata($this->get_customer_id($context));
208 208
 	}
209 209
 
210 210
 	/**
@@ -214,8 +214,8 @@  discard block
 block discarded – undo
214 214
 	 * @param  string $context View or edit context.
215 215
 	 * @return int
216 216
 	 */
217
-	public function get_parent_invoice_id( $context = 'view' ) {
218
-		return (int) $this->get_prop( 'parent_payment_id', $context );
217
+	public function get_parent_invoice_id($context = 'view') {
218
+		return (int) $this->get_prop('parent_payment_id', $context);
219 219
 	}
220 220
 
221 221
 	/**
@@ -225,8 +225,8 @@  discard block
 block discarded – undo
225 225
 	 * @param  string $context View or edit context.
226 226
 	 * @return int
227 227
 	 */
228
-    public function get_parent_payment_id( $context = 'view' ) {
229
-        return $this->get_parent_invoice_id( $context );
228
+    public function get_parent_payment_id($context = 'view') {
229
+        return $this->get_parent_invoice_id($context);
230 230
 	}
231 231
 
232 232
 	/**
@@ -235,8 +235,8 @@  discard block
 block discarded – undo
235 235
      * @since  1.0.0
236 236
      * @return int
237 237
      */
238
-    public function get_original_payment_id( $context = 'view' ) {
239
-        return $this->get_parent_invoice_id( $context );
238
+    public function get_original_payment_id($context = 'view') {
239
+        return $this->get_parent_invoice_id($context);
240 240
     }
241 241
 
242 242
 	/**
@@ -246,8 +246,8 @@  discard block
 block discarded – undo
246 246
 	 * @param  string $context View or edit context.
247 247
 	 * @return WPInv_Invoice
248 248
 	 */
249
-	public function get_parent_invoice( $context = 'view' ) {
250
-		return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
249
+	public function get_parent_invoice($context = 'view') {
250
+		return new WPInv_Invoice($this->get_parent_invoice_id($context));
251 251
 	}
252 252
 
253 253
 	/**
@@ -257,8 +257,8 @@  discard block
 block discarded – undo
257 257
 	 * @param  string $context View or edit context.
258 258
 	 * @return WPInv_Invoice
259 259
 	 */
260
-    public function get_parent_payment( $context = 'view' ) {
261
-        return $this->get_parent_invoice( $context );
260
+    public function get_parent_payment($context = 'view') {
261
+        return $this->get_parent_invoice($context);
262 262
 	}
263 263
 
264 264
 	/**
@@ -268,8 +268,8 @@  discard block
 block discarded – undo
268 268
 	 * @param  string $context View or edit context.
269 269
 	 * @return int
270 270
 	 */
271
-	public function get_product_id( $context = 'view' ) {
272
-		return (int) $this->get_prop( 'product_id', $context );
271
+	public function get_product_id($context = 'view') {
272
+		return (int) $this->get_prop('product_id', $context);
273 273
 	}
274 274
 
275 275
 	/**
@@ -279,8 +279,8 @@  discard block
 block discarded – undo
279 279
 	 * @param  string $context View or edit context.
280 280
 	 * @return WPInv_Item
281 281
 	 */
282
-	public function get_product( $context = 'view' ) {
283
-		return new WPInv_Item( $this->get_product_id( $context ) );
282
+	public function get_product($context = 'view') {
283
+		return new WPInv_Item($this->get_product_id($context));
284 284
 	}
285 285
 
286 286
 	/**
@@ -292,8 +292,8 @@  discard block
 block discarded – undo
292 292
 	 * @param  string $context View or edit context.
293 293
 	 * @return string
294 294
 	 */
295
-	public function get_gateway( $context = 'view' ) {
296
-		return $this->get_parent_invoice( $context )->get_gateway();
295
+	public function get_gateway($context = 'view') {
296
+		return $this->get_parent_invoice($context)->get_gateway();
297 297
 	}
298 298
 
299 299
 	/**
@@ -303,8 +303,8 @@  discard block
 block discarded – undo
303 303
 	 * @param  string $context View or edit context.
304 304
 	 * @return string
305 305
 	 */
306
-	public function get_period( $context = 'view' ) {
307
-		return $this->get_prop( 'period', $context );
306
+	public function get_period($context = 'view') {
307
+		return $this->get_prop('period', $context);
308 308
 	}
309 309
 
310 310
 	/**
@@ -314,8 +314,8 @@  discard block
 block discarded – undo
314 314
 	 * @param  string $context View or edit context.
315 315
 	 * @return int
316 316
 	 */
317
-	public function get_frequency( $context = 'view' ) {
318
-		return (int) $this->get_prop( 'frequency', $context );
317
+	public function get_frequency($context = 'view') {
318
+		return (int) $this->get_prop('frequency', $context);
319 319
 	}
320 320
 
321 321
 	/**
@@ -325,8 +325,8 @@  discard block
 block discarded – undo
325 325
 	 * @param  string $context View or edit context.
326 326
 	 * @return float
327 327
 	 */
328
-	public function get_initial_amount( $context = 'view' ) {
329
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
328
+	public function get_initial_amount($context = 'view') {
329
+		return (float) wpinv_sanitize_amount($this->get_prop('initial_amount', $context));
330 330
 	}
331 331
 
332 332
 	/**
@@ -336,8 +336,8 @@  discard block
 block discarded – undo
336 336
 	 * @param  string $context View or edit context.
337 337
 	 * @return float
338 338
 	 */
339
-	public function get_recurring_amount( $context = 'view' ) {
340
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
339
+	public function get_recurring_amount($context = 'view') {
340
+		return (float) wpinv_sanitize_amount($this->get_prop('recurring_amount', $context));
341 341
 	}
342 342
 
343 343
 	/**
@@ -347,8 +347,8 @@  discard block
 block discarded – undo
347 347
 	 * @param  string $context View or edit context.
348 348
 	 * @return int
349 349
 	 */
350
-	public function get_bill_times( $context = 'view' ) {
351
-		return (int) $this->get_prop( 'bill_times', $context );
350
+	public function get_bill_times($context = 'view') {
351
+		return (int) $this->get_prop('bill_times', $context);
352 352
 	}
353 353
 
354 354
 	/**
@@ -358,8 +358,8 @@  discard block
 block discarded – undo
358 358
 	 * @param  string $context View or edit context.
359 359
 	 * @return string
360 360
 	 */
361
-	public function get_transaction_id( $context = 'view' ) {
362
-		return $this->get_prop( 'transaction_id', $context );
361
+	public function get_transaction_id($context = 'view') {
362
+		return $this->get_prop('transaction_id', $context);
363 363
 	}
364 364
 
365 365
 	/**
@@ -369,8 +369,8 @@  discard block
 block discarded – undo
369 369
 	 * @param  string $context View or edit context.
370 370
 	 * @return string
371 371
 	 */
372
-	public function get_created( $context = 'view' ) {
373
-		return $this->get_prop( 'created', $context );
372
+	public function get_created($context = 'view') {
373
+		return $this->get_prop('created', $context);
374 374
 	}
375 375
 
376 376
 	/**
@@ -380,8 +380,8 @@  discard block
 block discarded – undo
380 380
 	 * @param  string $context View or edit context.
381 381
 	 * @return string
382 382
 	 */
383
-	public function get_date_created( $context = 'view' ) {
384
-		return $this->get_created( $context );
383
+	public function get_date_created($context = 'view') {
384
+		return $this->get_created($context);
385 385
 	}
386 386
 
387 387
 	/**
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 	 */
393 393
 	public function get_time_created() {
394 394
 		$created = $this->get_date_created();
395
-		return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
395
+		return empty($created) ? current_time('timestamp') : strtotime($created, current_time('timestamp'));
396 396
 	}
397 397
 
398 398
 	/**
@@ -402,11 +402,11 @@  discard block
 block discarded – undo
402 402
 	 * @param  string $context View or edit context.
403 403
 	 * @return string
404 404
 	 */
405
-	public function get_date_created_gmt( $context = 'view' ) {
406
-        $date = $this->get_date_created( $context );
405
+	public function get_date_created_gmt($context = 'view') {
406
+        $date = $this->get_date_created($context);
407 407
 
408
-        if ( $date ) {
409
-            $date = get_gmt_from_date( $date );
408
+        if ($date) {
409
+            $date = get_gmt_from_date($date);
410 410
         }
411 411
 		return $date;
412 412
 	}
@@ -418,8 +418,8 @@  discard block
 block discarded – undo
418 418
 	 * @param  string $context View or edit context.
419 419
 	 * @return string
420 420
 	 */
421
-	public function get_next_renewal_date( $context = 'view' ) {
422
-		return $this->get_prop( 'expiration', $context );
421
+	public function get_next_renewal_date($context = 'view') {
422
+		return $this->get_prop('expiration', $context);
423 423
 	}
424 424
 
425 425
 	/**
@@ -429,8 +429,8 @@  discard block
 block discarded – undo
429 429
 	 * @param  string $context View or edit context.
430 430
 	 * @return string
431 431
 	 */
432
-	public function get_expiration( $context = 'view' ) {
433
-		return $this->get_next_renewal_date( $context );
432
+	public function get_expiration($context = 'view') {
433
+		return $this->get_next_renewal_date($context);
434 434
 	}
435 435
 
436 436
 	/**
@@ -442,12 +442,12 @@  discard block
 block discarded – undo
442 442
 	public function get_expiration_time() {
443 443
 		$expiration = $this->get_expiration();
444 444
 
445
-		if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
446
-			return current_time( 'timestamp' );
445
+		if (empty($expiration) || '0000-00-00 00:00:00' == $expiration) {
446
+			return current_time('timestamp');
447 447
 		}
448 448
 
449
-		$expiration = strtotime( $expiration, current_time( 'timestamp' ) );
450
-		return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
449
+		$expiration = strtotime($expiration, current_time('timestamp'));
450
+		return $expiration < current_time('timestamp') ? current_time('timestamp') : $expiration;
451 451
 	}
452 452
 
453 453
 	/**
@@ -457,11 +457,11 @@  discard block
 block discarded – undo
457 457
 	 * @param  string $context View or edit context.
458 458
 	 * @return string
459 459
 	 */
460
-	public function get_next_renewal_date_gmt( $context = 'view' ) {
461
-        $date = $this->get_next_renewal_date( $context );
460
+	public function get_next_renewal_date_gmt($context = 'view') {
461
+        $date = $this->get_next_renewal_date($context);
462 462
 
463
-        if ( $date ) {
464
-            $date = get_gmt_from_date( $date );
463
+        if ($date) {
464
+            $date = get_gmt_from_date($date);
465 465
         }
466 466
 		return $date;
467 467
 	}
@@ -473,8 +473,8 @@  discard block
 block discarded – undo
473 473
 	 * @param  string $context View or edit context.
474 474
 	 * @return string
475 475
 	 */
476
-	public function get_trial_period( $context = 'view' ) {
477
-		return $this->get_prop( 'trial_period', $context );
476
+	public function get_trial_period($context = 'view') {
477
+		return $this->get_prop('trial_period', $context);
478 478
 	}
479 479
 
480 480
 	/**
@@ -484,8 +484,8 @@  discard block
 block discarded – undo
484 484
 	 * @param  string $context View or edit context.
485 485
 	 * @return string
486 486
 	 */
487
-	public function get_status( $context = 'view' ) {
488
-		return $this->get_prop( 'status', $context );
487
+	public function get_status($context = 'view') {
488
+		return $this->get_prop('status', $context);
489 489
 	}
490 490
 
491 491
 	/**
@@ -495,8 +495,8 @@  discard block
 block discarded – undo
495 495
 	 * @param  string $context View or edit context.
496 496
 	 * @return string
497 497
 	 */
498
-	public function get_profile_id( $context = 'view' ) {
499
-		return $this->get_prop( 'profile_id', $context );
498
+	public function get_profile_id($context = 'view') {
499
+		return $this->get_prop('profile_id', $context);
500 500
 	}
501 501
 
502 502
 	/*
@@ -511,8 +511,8 @@  discard block
 block discarded – undo
511 511
 	 * @since 1.0.19
512 512
 	 * @param  int $value The customer's id.
513 513
 	 */
514
-	public function set_customer_id( $value ) {
515
-		$this->set_prop( 'customer_id', (int) $value );
514
+	public function set_customer_id($value) {
515
+		$this->set_prop('customer_id', (int) $value);
516 516
 	}
517 517
 
518 518
 	/**
@@ -521,8 +521,8 @@  discard block
 block discarded – undo
521 521
 	 * @since 1.0.19
522 522
 	 * @param  int $value The parent invoice id.
523 523
 	 */
524
-	public function set_parent_invoice_id( $value ) {
525
-		$this->set_prop( 'parent_payment_id', (int) $value );
524
+	public function set_parent_invoice_id($value) {
525
+		$this->set_prop('parent_payment_id', (int) $value);
526 526
 	}
527 527
 
528 528
 	/**
@@ -531,8 +531,8 @@  discard block
 block discarded – undo
531 531
 	 * @since 1.0.19
532 532
 	 * @param  int $value The parent invoice id.
533 533
 	 */
534
-    public function set_parent_payment_id( $value ) {
535
-        $this->set_parent_invoice_id( $value );
534
+    public function set_parent_payment_id($value) {
535
+        $this->set_parent_invoice_id($value);
536 536
 	}
537 537
 
538 538
 	/**
@@ -541,8 +541,8 @@  discard block
 block discarded – undo
541 541
      * @since 1.0.19
542 542
 	 * @param  int $value The parent invoice id.
543 543
      */
544
-    public function set_original_payment_id( $value ) {
545
-        $this->set_parent_invoice_id( $value );
544
+    public function set_original_payment_id($value) {
545
+        $this->set_parent_invoice_id($value);
546 546
 	}
547 547
 
548 548
 	/**
@@ -551,8 +551,8 @@  discard block
 block discarded – undo
551 551
 	 * @since 1.0.19
552 552
 	 * @param  int $value The subscription product id.
553 553
 	 */
554
-	public function set_product_id( $value ) {
555
-		$this->set_prop( 'product_id', (int) $value );
554
+	public function set_product_id($value) {
555
+		$this->set_prop('product_id', (int) $value);
556 556
 	}
557 557
 
558 558
 	/**
@@ -561,8 +561,8 @@  discard block
 block discarded – undo
561 561
 	 * @since 1.0.19
562 562
 	 * @param  string $value The renewal period.
563 563
 	 */
564
-	public function set_period( $value ) {
565
-		$this->set_prop( 'period', $value );
564
+	public function set_period($value) {
565
+		$this->set_prop('period', $value);
566 566
 	}
567 567
 
568 568
 	/**
@@ -571,9 +571,9 @@  discard block
 block discarded – undo
571 571
 	 * @since 1.0.19
572 572
 	 * @param  int $value The subscription frequency.
573 573
 	 */
574
-	public function set_frequency( $value ) {
575
-		$value = empty( $value ) ? 1 : (int) $value;
576
-		$this->set_prop( 'frequency', absint( $value ) );
574
+	public function set_frequency($value) {
575
+		$value = empty($value) ? 1 : (int) $value;
576
+		$this->set_prop('frequency', absint($value));
577 577
 	}
578 578
 
579 579
 	/**
@@ -582,8 +582,8 @@  discard block
 block discarded – undo
582 582
 	 * @since 1.0.19
583 583
 	 * @param  float $value The initial subcription amount.
584 584
 	 */
585
-	public function set_initial_amount( $value ) {
586
-		$this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
585
+	public function set_initial_amount($value) {
586
+		$this->set_prop('initial_amount', wpinv_sanitize_amount($value));
587 587
 	}
588 588
 
589 589
 	/**
@@ -592,8 +592,8 @@  discard block
 block discarded – undo
592 592
 	 * @since 1.0.19
593 593
 	 * @param  float $value The recurring subcription amount.
594 594
 	 */
595
-	public function set_recurring_amount( $value ) {
596
-		$this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
595
+	public function set_recurring_amount($value) {
596
+		$this->set_prop('recurring_amount', wpinv_sanitize_amount($value));
597 597
 	}
598 598
 
599 599
 	/**
@@ -602,8 +602,8 @@  discard block
 block discarded – undo
602 602
 	 * @since 1.0.19
603 603
 	 * @param  int $value Bill times.
604 604
 	 */
605
-	public function set_bill_times( $value ) {
606
-		$this->set_prop( 'bill_times', (int) $value );
605
+	public function set_bill_times($value) {
606
+		$this->set_prop('bill_times', (int) $value);
607 607
 	}
608 608
 
609 609
 	/**
@@ -612,8 +612,8 @@  discard block
 block discarded – undo
612 612
 	 * @since 1.0.19
613 613
 	 * @param string $value Bill times.
614 614
 	 */
615
-	public function set_transaction_id( $value ) {
616
-		$this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
615
+	public function set_transaction_id($value) {
616
+		$this->set_prop('transaction_id', sanitize_text_field($value));
617 617
 	}
618 618
 
619 619
 	/**
@@ -622,15 +622,15 @@  discard block
 block discarded – undo
622 622
 	 * @since 1.0.19
623 623
 	 * @param string $value strtotime compliant date.
624 624
 	 */
625
-	public function set_created( $value ) {
626
-        $date = strtotime( $value );
625
+	public function set_created($value) {
626
+        $date = strtotime($value);
627 627
 
628
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
629
-            $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) );
628
+        if ($date && $value !== '0000-00-00 00:00:00') {
629
+            $this->set_prop('created', date('Y-m-d H:i:s', $date));
630 630
             return;
631 631
         }
632 632
 
633
-		$this->set_prop( 'created', '' );
633
+		$this->set_prop('created', '');
634 634
 
635 635
 	}
636 636
 
@@ -640,8 +640,8 @@  discard block
 block discarded – undo
640 640
 	 * @since 1.0.19
641 641
 	 * @param string $value strtotime compliant date.
642 642
 	 */
643
-	public function set_date_created( $value ) {
644
-		$this->set_created( $value );
643
+	public function set_date_created($value) {
644
+		$this->set_created($value);
645 645
     }
646 646
 
647 647
 	/**
@@ -650,15 +650,15 @@  discard block
 block discarded – undo
650 650
 	 * @since 1.0.19
651 651
 	 * @param string $value strtotime compliant date.
652 652
 	 */
653
-	public function set_next_renewal_date( $value ) {
654
-		$date = strtotime( $value );
653
+	public function set_next_renewal_date($value) {
654
+		$date = strtotime($value);
655 655
 
656
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
657
-            $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) );
656
+        if ($date && $value !== '0000-00-00 00:00:00') {
657
+            $this->set_prop('expiration', date('Y-m-d H:i:s', $date));
658 658
             return;
659 659
 		}
660 660
 
661
-		$this->set_prop( 'expiration', '' );
661
+		$this->set_prop('expiration', '');
662 662
 
663 663
 	}
664 664
 
@@ -668,8 +668,8 @@  discard block
 block discarded – undo
668 668
 	 * @since 1.0.19
669 669
 	 * @param string $value strtotime compliant date.
670 670
 	 */
671
-	public function set_expiration( $value ) {
672
-		$this->set_next_renewal_date( $value );
671
+	public function set_expiration($value) {
672
+		$this->set_next_renewal_date($value);
673 673
     }
674 674
 
675 675
 	/**
@@ -678,8 +678,8 @@  discard block
 block discarded – undo
678 678
 	 * @since 1.0.19
679 679
 	 * @param string $value trial period e.g 1 year.
680 680
 	 */
681
-	public function set_trial_period( $value ) {
682
-		$this->set_prop( 'trial_period', $value );
681
+	public function set_trial_period($value) {
682
+		$this->set_prop('trial_period', $value);
683 683
 	}
684 684
 
685 685
 	/**
@@ -688,19 +688,19 @@  discard block
 block discarded – undo
688 688
 	 * @since 1.0.19
689 689
 	 * @param string $new_status    New subscription status.
690 690
 	 */
691
-	public function set_status( $new_status ) {
691
+	public function set_status($new_status) {
692 692
 
693 693
 		// Abort if this is not a valid status;
694
-		if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
694
+		if (!array_key_exists($new_status, getpaid_get_subscription_statuses())) {
695 695
 			return;
696 696
 		}
697 697
 
698 698
 		$old_status = $this->get_status();
699
-		$this->set_prop( 'status', $new_status );
699
+		$this->set_prop('status', $new_status);
700 700
 
701
-		if ( true === $this->object_read && $old_status !== $new_status ) {
701
+		if (true === $this->object_read && $old_status !== $new_status) {
702 702
 			$this->status_transition = array(
703
-				'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
703
+				'from'   => !empty($this->status_transition['from']) ? $this->status_transition['from'] : $old_status,
704 704
 				'to'     => $new_status,
705 705
 			);
706 706
 		}
@@ -713,8 +713,8 @@  discard block
 block discarded – undo
713 713
 	 * @since 1.0.19
714 714
 	 * @param  string $value the remote profile id.
715 715
 	 */
716
-	public function set_profile_id( $value ) {
717
-		$this->set_prop( 'profile_id', sanitize_text_field( $value ) );
716
+	public function set_profile_id($value) {
717
+		$this->set_prop('profile_id', sanitize_text_field($value));
718 718
 	}
719 719
 
720 720
 	/*
@@ -732,8 +732,8 @@  discard block
 block discarded – undo
732 732
 	 * @param string|array String or array of strings to check for.
733 733
 	 * @return bool
734 734
      */
735
-    public function has_status( $status ) {
736
-        return in_array( $this->get_status(), wpinv_parse_list( $status ) );
735
+    public function has_status($status) {
736
+        return in_array($this->get_status(), wpinv_parse_list($status));
737 737
 	}
738 738
 
739 739
 	/**
@@ -743,7 +743,7 @@  discard block
 block discarded – undo
743 743
      */
744 744
     public function has_trial_period() {
745 745
 		$period = $this->get_trial_period();
746
-        return ! empty( $period );
746
+        return !empty($period);
747 747
 	}
748 748
 
749 749
 	/**
@@ -752,7 +752,7 @@  discard block
 block discarded – undo
752 752
 	 * @return bool
753 753
 	 */
754 754
 	public function is_active() {
755
-		return $this->has_status( 'active trialling' ) && $this->get_expiration_time() > current_time( 'mysql' );
755
+		return $this->has_status('active trialling') && $this->get_expiration_time() > current_time('mysql');
756 756
 	}
757 757
 
758 758
 	/**
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
 	 * @return bool
762 762
 	 */
763 763
 	public function is_expired() {
764
-		return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) );
764
+		return $this->has_status('expired') || ($this->has_status('active cancelled trialling') && $this->get_expiration_time() < current_time('mysql'));
765 765
 	}
766 766
 
767 767
 	/*
@@ -776,11 +776,11 @@  discard block
 block discarded – undo
776 776
 	/**
777 777
 	 * Backwards compatibilty.
778 778
 	 */
779
-	public function create( $data = array() ) {
779
+	public function create($data = array()) {
780 780
 
781 781
 		// Set the properties.
782
-		if ( is_array( $data ) ) {
783
-			$this->set_props( $data );
782
+		if (is_array($data)) {
783
+			$this->set_props($data);
784 784
 		}
785 785
 
786 786
 		// Save the item.
@@ -791,8 +791,8 @@  discard block
 block discarded – undo
791 791
 	/**
792 792
 	 * Backwards compatibilty.
793 793
 	 */
794
-	public function update( $args = array() ) {
795
-		return $this->create( $args );
794
+	public function update($args = array()) {
795
+		return $this->create($args);
796 796
 	}
797 797
 
798 798
     /**
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
 			array(
807 807
             	'post_parent'    => $this->get_parent_payment_id(),
808 808
             	'numberposts'    => -1,
809
-            	'post_status'    => array( 'publish', 'wpi-processing', 'wpi-renewal' ),
809
+            	'post_status'    => array('publish', 'wpi-processing', 'wpi-renewal'),
810 810
             	'orderby'        => 'ID',
811 811
             	'order'          => 'DESC',
812 812
             	'post_type'      => 'wpi_invoice'
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
 		);
832 832
 
833 833
 		// Maybe include parent invoice.
834
-        if ( ! $this->has_status( 'pending' ) ) {
834
+        if (!$this->has_status('pending')) {
835 835
             $count++;
836 836
         }
837 837
 
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
     public function get_times_billed() {
848 848
         $times_billed = $this->get_total_payments();
849 849
 
850
-        if ( $this->has_trial_period() && $times_billed > 0 ) {
850
+        if ($this->has_trial_period() && $times_billed > 0) {
851 851
             $times_billed--;
852 852
         }
853 853
 
@@ -862,49 +862,49 @@  discard block
 block discarded – undo
862 862
 	 * @param  WPInv_Invoice $invoice If adding an existing invoice.
863 863
      * @return bool
864 864
      */
865
-    public function add_payment( $args = array(), $invoice = false ) {
865
+    public function add_payment($args = array(), $invoice = false) {
866 866
 
867 867
 		// Process each payment once.
868
-        if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) {
868
+        if (!empty($args['transaction_id']) && $this->payment_exists($args['transaction_id'])) {
869 869
             return false;
870 870
         }
871 871
 
872 872
 		// Are we creating a new invoice?
873
-		if ( empty( $invoice ) ) {
873
+		if (empty($invoice)) {
874 874
 			$invoice = $this->create_payment();
875 875
 
876
-			if ( empty( $invoice ) ) {
876
+			if (empty($invoice)) {
877 877
 				return false;
878 878
 			}
879 879
 
880
-			$invoice->set_status( 'wpi-renewal' );
880
+			$invoice->set_status('wpi-renewal');
881 881
 
882 882
 		}
883 883
 
884 884
 		// Maybe set a transaction id.
885
-		if ( ! empty( $args['transaction_id'] ) ) {
886
-			$invoice->set_transaction_id( $args['transaction_id'] );
885
+		if (!empty($args['transaction_id'])) {
886
+			$invoice->set_transaction_id($args['transaction_id']);
887 887
 		}
888 888
 
889 889
 		// Set the completed date.
890
-		$invoice->set_completed_date( current_time( 'mysql' ) );
890
+		$invoice->set_completed_date(current_time('mysql'));
891 891
 
892 892
 		// And the gateway.
893
-		if ( ! empty( $args['gateway'] ) ) {
894
-			$invoice->set_gateway( $args['gateway'] );
893
+		if (!empty($args['gateway'])) {
894
+			$invoice->set_gateway($args['gateway']);
895 895
 		}
896 896
 
897 897
 		$invoice->save();
898 898
 
899
-		if ( ! $invoice->get_id() ) {
899
+		if (!$invoice->get_id()) {
900 900
 			return 0;
901 901
 		}
902 902
 
903
-		do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
904
-		do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
905
-        do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() );
903
+		do_action('getpaid_after_create_subscription_renewal_invoice', $invoice, $this);
904
+		do_action('wpinv_recurring_add_subscription_payment', $invoice, $this);
905
+        do_action('wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id());
906 906
 
907
-        update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id );
907
+        update_post_meta($invoice->get_id(), '_wpinv_subscription_id', $this->id);
908 908
 
909 909
         return $invoice->get_id();
910 910
 	}
@@ -919,21 +919,21 @@  discard block
 block discarded – undo
919 919
 
920 920
 		$parent_invoice = $this->get_parent_payment();
921 921
 
922
-		if ( ! $parent_invoice->get_id() ) {
922
+		if (!$parent_invoice->get_id()) {
923 923
 			return false;
924 924
 		}
925 925
 
926 926
 		// Duplicate the parent invoice.
927 927
 		$invoice = new WPInv_Invoice();
928
-		$invoice->set_props( $parent_invoice->get_data() );
929
-		$invoice->set_id( 0 );
930
-		$invoice->set_items( $parent_invoice->get_items() );
931
-		$invoice->set_parent_id( $parent_invoice->get_id() );
932
-		$invoice->set_transaction_id( '' );
933
-		$invoice->set_key( $invoice->generate_key( 'renewal_' ) );
934
-		$invoice->set_number( '' );
935
-		$invoice->set_completed_date( '' );
936
-		$invoice->set_status( 'wpi-pending' );
928
+		$invoice->set_props($parent_invoice->get_data());
929
+		$invoice->set_id(0);
930
+		$invoice->set_items($parent_invoice->get_items());
931
+		$invoice->set_parent_id($parent_invoice->get_id());
932
+		$invoice->set_transaction_id('');
933
+		$invoice->set_key($invoice->generate_key('renewal_'));
934
+		$invoice->set_number('');
935
+		$invoice->set_completed_date('');
936
+		$invoice->set_status('wpi-pending');
937 937
 		$invoice->recalculate_total();
938 938
 		$invoice->save();
939 939
 
@@ -949,20 +949,20 @@  discard block
 block discarded – undo
949 949
 	public function renew() {
950 950
 
951 951
 		// Complete subscription if applicable
952
-		if ( $this->get_bill_times() > 0 && $this->get_times_billed() >= $this->get_bill_times() ) {
952
+		if ($this->get_bill_times() > 0 && $this->get_times_billed() >= $this->get_bill_times()) {
953 953
 			return $this->complete();
954 954
 		}
955 955
 
956 956
 		// Calculate new expiration
957 957
 		$frequency      = $this->get_frequency();
958 958
 		$period         = $this->get_period();
959
-		$new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
959
+		$new_expiration = strtotime("+ $frequency $period", $this->get_expiration_time());
960 960
 
961
-		$this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) );
962
-		$this->set_status( 'active' );
961
+		$this->set_expiration(date('Y-m-d H:i:s', $new_expiration));
962
+		$this->set_status('active');
963 963
 		return $this->save();
964 964
 
965
-		do_action( 'getpaid_subscription_renewed', $this );
965
+		do_action('getpaid_subscription_renewed', $this);
966 966
 
967 967
 	}
968 968
 
@@ -977,11 +977,11 @@  discard block
 block discarded – undo
977 977
 	public function complete() {
978 978
 
979 979
 		// Only mark a subscription as complete if it's not already cancelled.
980
-		if ( $this->has_status( 'cancelled' ) ) {
980
+		if ($this->has_status('cancelled')) {
981 981
 			return false;
982 982
 		}
983 983
 
984
-		$this->set_status( 'completed' );
984
+		$this->set_status('completed');
985 985
 		return $this->save();
986 986
 
987 987
 	}
@@ -993,14 +993,14 @@  discard block
 block discarded – undo
993 993
 	 * @param  bool $check_expiration
994 994
 	 * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
995 995
 	 */
996
-	public function expire( $check_expiration = false ) {
996
+	public function expire($check_expiration = false) {
997 997
 
998
-		if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
998
+		if ($check_expiration && $this->get_expiration_time() > current_time('timestamp')) {
999 999
 			// Do not mark as expired since real expiration date is in the future
1000 1000
 			return false;
1001 1001
 		}
1002 1002
 
1003
-		$this->set_status( 'expired' );
1003
+		$this->set_status('expired');
1004 1004
 		return $this->save();
1005 1005
 
1006 1006
 	}
@@ -1012,7 +1012,7 @@  discard block
 block discarded – undo
1012 1012
 	 * @return int Subscription id.
1013 1013
 	 */
1014 1014
 	public function failing() {
1015
-		$this->set_status( 'failing' );
1015
+		$this->set_status('failing');
1016 1016
 		return $this->save();
1017 1017
 	}
1018 1018
 
@@ -1023,7 +1023,7 @@  discard block
 block discarded – undo
1023 1023
      * @return int Subscription id.
1024 1024
      */
1025 1025
     public function cancel() {
1026
-		$this->set_status( 'cancelled' );
1026
+		$this->set_status('cancelled');
1027 1027
 		return $this->save();
1028 1028
     }
1029 1029
 
@@ -1034,7 +1034,7 @@  discard block
 block discarded – undo
1034 1034
 	 * @return bool
1035 1035
 	 */
1036 1036
 	public function can_cancel() {
1037
-		return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1037
+		return apply_filters('wpinv_subscription_can_cancel', $this->has_status($this->get_cancellable_statuses()), $this);
1038 1038
 	}
1039 1039
 
1040 1040
     /**
@@ -1045,7 +1045,7 @@  discard block
 block discarded – undo
1045 1045
      * @return      array
1046 1046
      */
1047 1047
     public function get_cancellable_statuses() {
1048
-        return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) );
1048
+        return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing'));
1049 1049
     }
1050 1050
 
1051 1051
 	/**
@@ -1055,8 +1055,8 @@  discard block
 block discarded – undo
1055 1055
 	 * @return string
1056 1056
 	 */
1057 1057
 	public function get_cancel_url() {
1058
-		$url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'subscription_cancel', 'sub_id' => $this->get_id() ) ), 'getpaid-nonce' );
1059
-		return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1058
+		$url = wp_nonce_url(add_query_arg(array('getpaid-action' => 'subscription_cancel', 'sub_id' => $this->get_id())), 'getpaid-nonce');
1059
+		return apply_filters('wpinv_subscription_cancel_url', $url, $this);
1060 1060
 	}
1061 1061
 
1062 1062
 	/**
@@ -1069,7 +1069,7 @@  discard block
 block discarded – undo
1069 1069
 	 * @return bool
1070 1070
 	 */
1071 1071
 	public function can_renew() {
1072
-		return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1072
+		return apply_filters('wpinv_subscription_can_renew', true, $this);
1073 1073
 	}
1074 1074
 
1075 1075
 	/**
@@ -1079,8 +1079,8 @@  discard block
 block discarded – undo
1079 1079
 	 * @return string
1080 1080
 	 */
1081 1081
 	public function get_renew_url() {
1082
-		$url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' );
1083
-		return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1082
+		$url = wp_nonce_url(add_query_arg(array('getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id)), 'getpaid-nonce');
1083
+		return apply_filters('wpinv_subscription_renew_url', $url, $this);
1084 1084
 	}
1085 1085
 
1086 1086
 	/**
@@ -1090,7 +1090,7 @@  discard block
 block discarded – undo
1090 1090
 	 * @return bool
1091 1091
 	 */
1092 1092
 	public function can_update() {
1093
-		return apply_filters( 'wpinv_subscription_can_update', false, $this );
1093
+		return apply_filters('wpinv_subscription_can_update', false, $this);
1094 1094
 	}
1095 1095
 
1096 1096
 	/**
@@ -1100,8 +1100,8 @@  discard block
 block discarded – undo
1100 1100
 	 * @return string
1101 1101
 	 */
1102 1102
 	public function get_update_url() {
1103
-		$url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) );
1104
-		return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1103
+		$url = add_query_arg(array('action' => 'update', 'subscription_id' => $this->get_id()));
1104
+		return apply_filters('wpinv_subscription_update_url', $url, $this);
1105 1105
 	}
1106 1106
 
1107 1107
 	/**
@@ -1111,7 +1111,7 @@  discard block
 block discarded – undo
1111 1111
 	 * @return string
1112 1112
 	 */
1113 1113
 	public function get_status_label() {
1114
-		return getpaid_get_subscription_status_label( $this->get_status() );
1114
+		return getpaid_get_subscription_status_label($this->get_status());
1115 1115
 	}
1116 1116
 
1117 1117
 	/**
@@ -1122,7 +1122,7 @@  discard block
 block discarded – undo
1122 1122
 	 */
1123 1123
 	public function get_status_class() {
1124 1124
 		$statuses = getpaid_get_subscription_status_classes();
1125
-		return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary';
1125
+		return isset($statuses[$this->get_status()]) ? $statuses[$this->get_status()] : 'text-white bg-secondary';
1126 1126
 	}
1127 1127
 
1128 1128
     /**
@@ -1133,9 +1133,9 @@  discard block
 block discarded – undo
1133 1133
      */
1134 1134
     public function get_status_label_html() {
1135 1135
 
1136
-		$status_label = sanitize_text_field( $this->get_status_label() );
1137
-		$class        = esc_attr( $this->get_status_class() );
1138
-		$status       = sanitize_html_class( $this->get_status_label() );
1136
+		$status_label = sanitize_text_field($this->get_status_label());
1137
+		$class        = esc_attr($this->get_status_class());
1138
+		$status       = sanitize_html_class($this->get_status_label());
1139 1139
 
1140 1140
 		return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>";
1141 1141
     }
@@ -1147,9 +1147,9 @@  discard block
 block discarded – undo
1147 1147
      * @param  string $txn_id The transaction ID from the merchant processor
1148 1148
      * @return bool
1149 1149
      */
1150
-    public function payment_exists( $txn_id = '' ) {
1151
-		$invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1152
-        return ! empty( $invoice_id );
1150
+    public function payment_exists($txn_id = '') {
1151
+		$invoice_id = WPInv_Invoice::get_invoice_id_by_field($txn_id, 'transaction_id');
1152
+        return !empty($invoice_id);
1153 1153
 	}
1154 1154
 
1155 1155
 	/**
@@ -1161,35 +1161,35 @@  discard block
 block discarded – undo
1161 1161
 		// Reset status transition variable.
1162 1162
 		$this->status_transition = false;
1163 1163
 
1164
-		if ( $status_transition ) {
1164
+		if ($status_transition) {
1165 1165
 			try {
1166 1166
 
1167 1167
 				// Fire a hook for the status change.
1168
-				do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1169
-				do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1168
+				do_action('wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition);
1169
+				do_action('getpaid_subscription_' . $status_transition['to'], $this, $status_transition);
1170 1170
 
1171
-				if ( ! empty( $status_transition['from'] ) ) {
1171
+				if (!empty($status_transition['from'])) {
1172 1172
 
1173 1173
 					/* translators: 1: old subscription status 2: new subscription status */
1174
-					$transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1174
+					$transition_note = sprintf(__('Subscription status changed from %1$s to %2$s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['from']), getpaid_get_subscription_status_label($status_transition['to']));
1175 1175
 
1176 1176
 					// Note the transition occurred.
1177
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1177
+					$this->get_parent_payment()->add_note($transition_note, false, false, true);
1178 1178
 
1179 1179
 					// Fire another hook.
1180
-					do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1181
-					do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1180
+					do_action('getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this);
1181
+					do_action('getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to']);
1182 1182
 
1183 1183
 				} else {
1184 1184
 					/* translators: %s: new invoice status */
1185
-					$transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1185
+					$transition_note = sprintf(__('Subscription status set to %s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['to']));
1186 1186
 
1187 1187
 					// Note the transition occurred.
1188
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1188
+					$this->get_parent_payment()->add_note($transition_note, false, false, true);
1189 1189
 
1190 1190
 				}
1191
-			} catch ( Exception $e ) {
1192
-				$this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1191
+			} catch (Exception $e) {
1192
+				$this->get_parent_payment()->add_note(__('Error during subscription status transition.', 'invoicing') . ' ' . $e->getMessage());
1193 1193
 			}
1194 1194
 		}
1195 1195
 
Please login to merge, or discard this patch.
includes/wpinv-template-functions.php 1 patch
Spacing   +532 added lines, -532 removed lines patch added patch discarded remove patch
@@ -4,99 +4,99 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Displays an invoice.
11 11
  * 
12 12
  * @param WPInv_Invoice $invoice.
13 13
  */
14
-function getpaid_invoice( $invoice ) {
15
-    if ( ! empty( $invoice ) ) {
16
-        wpinv_get_template( 'invoice/invoice.php', compact( 'invoice' ) );
14
+function getpaid_invoice($invoice) {
15
+    if (!empty($invoice)) {
16
+        wpinv_get_template('invoice/invoice.php', compact('invoice'));
17 17
     }
18 18
 }
19
-add_action( 'getpaid_invoice', 'getpaid_invoice', 10 );
19
+add_action('getpaid_invoice', 'getpaid_invoice', 10);
20 20
 
21 21
 /**
22 22
  * Displays the invoice footer.
23 23
  */
24
-function getpaid_invoice_footer( $invoice ) {
25
-    if ( ! empty( $invoice ) ) {
26
-        wpinv_get_template( 'invoice/footer.php', compact( 'invoice' ) );
24
+function getpaid_invoice_footer($invoice) {
25
+    if (!empty($invoice)) {
26
+        wpinv_get_template('invoice/footer.php', compact('invoice'));
27 27
     }
28 28
 }
29
-add_action( 'getpaid_invoice_footer', 'getpaid_invoice_footer', 10 );
29
+add_action('getpaid_invoice_footer', 'getpaid_invoice_footer', 10);
30 30
 
31 31
 /**
32 32
  * Displays the invoice top bar.
33 33
  */
34
-function getpaid_invoice_header( $invoice ) {
35
-    if ( ! empty( $invoice ) ) {
36
-        wpinv_get_template( 'invoice/header.php', compact( 'invoice' ) );
34
+function getpaid_invoice_header($invoice) {
35
+    if (!empty($invoice)) {
36
+        wpinv_get_template('invoice/header.php', compact('invoice'));
37 37
     }
38 38
 }
39
-add_action( 'getpaid_invoice_header', 'getpaid_invoice_header', 10 );
39
+add_action('getpaid_invoice_header', 'getpaid_invoice_header', 10);
40 40
 
41 41
 /**
42 42
  * Displays actions on the left side of the header.
43 43
  */
44
-function getpaid_invoice_header_left_actions( $invoice ) {
45
-    if ( ! empty( $invoice ) ) {
46
-        wpinv_get_template( 'invoice/header-left-actions.php', compact( 'invoice' ) );
44
+function getpaid_invoice_header_left_actions($invoice) {
45
+    if (!empty($invoice)) {
46
+        wpinv_get_template('invoice/header-left-actions.php', compact('invoice'));
47 47
     }
48 48
 }
49
-add_action( 'getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10 );
49
+add_action('getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10);
50 50
 
51 51
 /**
52 52
  * Displays actions on the right side of the invoice top bar.
53 53
  */
54
-function getpaid_invoice_header_right_actions( $invoice ) {
55
-    if ( ! empty( $invoice ) ) {
56
-        wpinv_get_template( 'invoice/header-right-actions.php', compact( 'invoice' ) );
54
+function getpaid_invoice_header_right_actions($invoice) {
55
+    if (!empty($invoice)) {
56
+        wpinv_get_template('invoice/header-right-actions.php', compact('invoice'));
57 57
     }
58 58
 }
59
-add_action( 'getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10 );
59
+add_action('getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10);
60 60
 
61 61
 /**
62 62
  * Displays the invoice title, watermark, logo etc.
63 63
  */
64
-function getpaid_invoice_details_top( $invoice ) {
65
-    if ( ! empty( $invoice ) ) {
66
-        wpinv_get_template( 'invoice/details-top.php', compact( 'invoice' ) );
64
+function getpaid_invoice_details_top($invoice) {
65
+    if (!empty($invoice)) {
66
+        wpinv_get_template('invoice/details-top.php', compact('invoice'));
67 67
     }
68 68
 }
69
-add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_top', 10 );
69
+add_action('getpaid_invoice_details', 'getpaid_invoice_details_top', 10);
70 70
 
71 71
 /**
72 72
  * Displays the company logo.
73 73
  */
74
-function getpaid_invoice_logo( $invoice ) {
75
-    if ( ! empty( $invoice ) ) {
76
-        wpinv_get_template( 'invoice/invoice-logo.php', compact( 'invoice' ) );
74
+function getpaid_invoice_logo($invoice) {
75
+    if (!empty($invoice)) {
76
+        wpinv_get_template('invoice/invoice-logo.php', compact('invoice'));
77 77
     }
78 78
 }
79
-add_action( 'getpaid_invoice_details_top_left', 'getpaid_invoice_logo' );
79
+add_action('getpaid_invoice_details_top_left', 'getpaid_invoice_logo');
80 80
 
81 81
 /**
82 82
  * Displays the type of invoice.
83 83
  */
84
-function getpaid_invoice_type( $invoice ) {
85
-    if ( ! empty( $invoice ) ) {
86
-        wpinv_get_template( 'invoice/invoice-type.php', compact( 'invoice' ) );
84
+function getpaid_invoice_type($invoice) {
85
+    if (!empty($invoice)) {
86
+        wpinv_get_template('invoice/invoice-type.php', compact('invoice'));
87 87
     }
88 88
 }
89
-add_action( 'getpaid_invoice_details_top_right', 'getpaid_invoice_type' );
89
+add_action('getpaid_invoice_details_top_right', 'getpaid_invoice_type');
90 90
 
91 91
 /**
92 92
  * Displays the invoice details.
93 93
  */
94
-function getpaid_invoice_details_main( $invoice ) {
95
-    if ( ! empty( $invoice ) ) {
96
-        wpinv_get_template( 'invoice/details.php', compact( 'invoice' ) );
94
+function getpaid_invoice_details_main($invoice) {
95
+    if (!empty($invoice)) {
96
+        wpinv_get_template('invoice/details.php', compact('invoice'));
97 97
     }
98 98
 }
99
-add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_main', 50 );
99
+add_action('getpaid_invoice_details', 'getpaid_invoice_details_main', 50);
100 100
 
101 101
 /**
102 102
  * Returns a path to the templates directory.
@@ -125,8 +125,8 @@  discard block
 block discarded – undo
125 125
  * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'.
126 126
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
127 127
  */
128
-function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
129
-    return getpaid_template()->display_template( $template_name, $args, $template_path, $default_path );
128
+function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
129
+    return getpaid_template()->display_template($template_name, $args, $template_path, $default_path);
130 130
 }
131 131
 
132 132
 /**
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
  * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'.
140 140
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
141 141
  */
142
-function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
143
-	return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path );
142
+function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') {
143
+	return getpaid_template()->get_template($template_name, $args, $template_path, $default_path);
144 144
 }
145 145
 
146 146
 /**
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
  * @return string
150 150
  */
151 151
 function wpinv_template_path() {
152
-    return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() );
152
+    return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name());
153 153
 }
154 154
 
155 155
 /**
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
  * @return string
159 159
  */
160 160
 function wpinv_get_theme_template_dir_name() {
161
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
161
+	return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing'));
162 162
 }
163 163
 
164 164
 /**
@@ -170,56 +170,56 @@  discard block
 block discarded – undo
170 170
  * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'.
171 171
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
172 172
  */
173
-function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) {
174
-    return getpaid_template()->locate_template( $template_name, $template_path, $default_path );
173
+function wpinv_locate_template($template_name, $template_path = '', $default_path = '') {
174
+    return getpaid_template()->locate_template($template_name, $template_path, $default_path);
175 175
 }
176 176
 
177
-function wpinv_get_template_part( $slug, $name = null, $load = true ) {
178
-	do_action( 'get_template_part_' . $slug, $slug, $name );
177
+function wpinv_get_template_part($slug, $name = null, $load = true) {
178
+	do_action('get_template_part_' . $slug, $slug, $name);
179 179
 
180 180
 	// Setup possible parts
181 181
 	$templates = array();
182
-	if ( isset( $name ) )
182
+	if (isset($name))
183 183
 		$templates[] = $slug . '-' . $name . '.php';
184 184
 	$templates[] = $slug . '.php';
185 185
 
186 186
 	// Allow template parts to be filtered
187
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
187
+	$templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name);
188 188
 
189 189
 	// Return the part that is found
190
-	return wpinv_locate_tmpl( $templates, $load, false );
190
+	return wpinv_locate_tmpl($templates, $load, false);
191 191
 }
192 192
 
193
-function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
193
+function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) {
194 194
 	// No file found yet
195 195
 	$located = false;
196 196
 
197 197
 	// Try to find a template file
198
-	foreach ( (array)$template_names as $template_name ) {
198
+	foreach ((array) $template_names as $template_name) {
199 199
 
200 200
 		// Continue if template is empty
201
-		if ( empty( $template_name ) )
201
+		if (empty($template_name))
202 202
 			continue;
203 203
 
204 204
 		// Trim off any slashes from the template name
205
-		$template_name = ltrim( $template_name, '/' );
205
+		$template_name = ltrim($template_name, '/');
206 206
 
207 207
 		// try locating this template file by looping through the template paths
208
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
208
+		foreach (wpinv_get_theme_template_paths() as $template_path) {
209 209
 
210
-			if( file_exists( $template_path . $template_name ) ) {
210
+			if (file_exists($template_path . $template_name)) {
211 211
 				$located = $template_path . $template_name;
212 212
 				break;
213 213
 			}
214 214
 		}
215 215
 
216
-		if( !empty( $located ) ) {
216
+		if (!empty($located)) {
217 217
 			break;
218 218
 		}
219 219
 	}
220 220
 
221
-	if ( ( true == $load ) && ! empty( $located ) )
222
-		load_template( $located, $require_once );
221
+	if ((true == $load) && !empty($located))
222
+		load_template($located, $require_once);
223 223
 
224 224
 	return $located;
225 225
 }
@@ -228,155 +228,155 @@  discard block
 block discarded – undo
228 228
 	$template_dir = wpinv_get_theme_template_dir_name();
229 229
 
230 230
 	$file_paths = array(
231
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
232
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
231
+		1 => trailingslashit(get_stylesheet_directory()) . $template_dir,
232
+		10 => trailingslashit(get_template_directory()) . $template_dir,
233 233
 		100 => wpinv_get_templates_dir()
234 234
 	);
235 235
 
236
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
236
+	$file_paths = apply_filters('wpinv_template_paths', $file_paths);
237 237
 
238 238
 	// sort the file paths based on priority
239
-	ksort( $file_paths, SORT_NUMERIC );
239
+	ksort($file_paths, SORT_NUMERIC);
240 240
 
241
-	return array_map( 'trailingslashit', $file_paths );
241
+	return array_map('trailingslashit', $file_paths);
242 242
 }
243 243
 
244 244
 function wpinv_checkout_meta_tags() {
245 245
 
246 246
 	$pages   = array();
247
-	$pages[] = wpinv_get_option( 'success_page' );
248
-	$pages[] = wpinv_get_option( 'failure_page' );
249
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
250
-	$pages[] = wpinv_get_option( 'invoice_subscription_page' );
247
+	$pages[] = wpinv_get_option('success_page');
248
+	$pages[] = wpinv_get_option('failure_page');
249
+	$pages[] = wpinv_get_option('invoice_history_page');
250
+	$pages[] = wpinv_get_option('invoice_subscription_page');
251 251
 
252
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
252
+	if (!wpinv_is_checkout() && !is_page($pages)) {
253 253
 		return;
254 254
 	}
255 255
 
256 256
 	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
257 257
 }
258
-add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
258
+add_action('wp_head', 'wpinv_checkout_meta_tags');
259 259
 
260
-function wpinv_add_body_classes( $class ) {
261
-	$classes = (array)$class;
260
+function wpinv_add_body_classes($class) {
261
+	$classes = (array) $class;
262 262
 
263
-	if( wpinv_is_checkout() ) {
263
+	if (wpinv_is_checkout()) {
264 264
 		$classes[] = 'wpinv-checkout';
265 265
 		$classes[] = 'wpinv-page';
266 266
 	}
267 267
 
268
-	if( wpinv_is_success_page() ) {
268
+	if (wpinv_is_success_page()) {
269 269
 		$classes[] = 'wpinv-success';
270 270
 		$classes[] = 'wpinv-page';
271 271
 	}
272 272
 
273
-	if( wpinv_is_failed_transaction_page() ) {
273
+	if (wpinv_is_failed_transaction_page()) {
274 274
 		$classes[] = 'wpinv-failed-transaction';
275 275
 		$classes[] = 'wpinv-page';
276 276
 	}
277 277
 
278
-	if( wpinv_is_invoice_history_page() ) {
278
+	if (wpinv_is_invoice_history_page()) {
279 279
 		$classes[] = 'wpinv-history';
280 280
 		$classes[] = 'wpinv-page';
281 281
 	}
282 282
 
283
-	if( wpinv_is_subscriptions_history_page() ) {
283
+	if (wpinv_is_subscriptions_history_page()) {
284 284
 		$classes[] = 'wpinv-subscription';
285 285
 		$classes[] = 'wpinv-page';
286 286
 	}
287 287
 
288
-	if( wpinv_is_test_mode() ) {
288
+	if (wpinv_is_test_mode()) {
289 289
 		$classes[] = 'wpinv-test-mode';
290 290
 		$classes[] = 'wpinv-page';
291 291
 	}
292 292
 
293
-	return array_unique( $classes );
293
+	return array_unique($classes);
294 294
 }
295
-add_filter( 'body_class', 'wpinv_add_body_classes' );
295
+add_filter('body_class', 'wpinv_add_body_classes');
296 296
 
297
-function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) {
298
-    $args = array( 'nopaging' => true );
297
+function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') {
298
+    $args = array('nopaging' => true);
299 299
 
300
-    if ( ! empty( $status ) )
300
+    if (!empty($status))
301 301
         $args['post_status'] = $status;
302 302
 
303
-    $discounts = wpinv_get_discounts( $args );
303
+    $discounts = wpinv_get_discounts($args);
304 304
     $options   = array();
305 305
 
306
-    if ( $discounts ) {
307
-        foreach ( $discounts as $discount ) {
308
-            $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) );
306
+    if ($discounts) {
307
+        foreach ($discounts as $discount) {
308
+            $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID));
309 309
         }
310 310
     } else {
311
-        $options[0] = __( 'No discounts found', 'invoicing' );
311
+        $options[0] = __('No discounts found', 'invoicing');
312 312
     }
313 313
 
314
-    $output = wpinv_html_select( array(
314
+    $output = wpinv_html_select(array(
315 315
         'name'             => $name,
316 316
         'selected'         => $selected,
317 317
         'options'          => $options,
318 318
         'show_option_all'  => false,
319 319
         'show_option_none' => false,
320
-    ) );
320
+    ));
321 321
 
322 322
     return $output;
323 323
 }
324 324
 
325
-function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
326
-    $current     = date( 'Y' );
327
-    $start_year  = $current - absint( $years_before );
328
-    $end_year    = $current + absint( $years_after );
329
-    $selected    = empty( $selected ) ? date( 'Y' ) : $selected;
325
+function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) {
326
+    $current     = date('Y');
327
+    $start_year  = $current - absint($years_before);
328
+    $end_year    = $current + absint($years_after);
329
+    $selected    = empty($selected) ? date('Y') : $selected;
330 330
     $options     = array();
331 331
 
332
-    while ( $start_year <= $end_year ) {
333
-        $options[ absint( $start_year ) ] = $start_year;
332
+    while ($start_year <= $end_year) {
333
+        $options[absint($start_year)] = $start_year;
334 334
         $start_year++;
335 335
     }
336 336
 
337
-    $output = wpinv_html_select( array(
337
+    $output = wpinv_html_select(array(
338 338
         'name'             => $name,
339 339
         'selected'         => $selected,
340 340
         'options'          => $options,
341 341
         'show_option_all'  => false,
342 342
         'show_option_none' => false
343
-    ) );
343
+    ));
344 344
 
345 345
     return $output;
346 346
 }
347 347
 
348
-function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) {
348
+function wpinv_html_month_dropdown($name = 'month', $selected = 0) {
349 349
 
350 350
     $options = array(
351
-        '1'  => __( 'January', 'invoicing' ),
352
-        '2'  => __( 'February', 'invoicing' ),
353
-        '3'  => __( 'March', 'invoicing' ),
354
-        '4'  => __( 'April', 'invoicing' ),
355
-        '5'  => __( 'May', 'invoicing' ),
356
-        '6'  => __( 'June', 'invoicing' ),
357
-        '7'  => __( 'July', 'invoicing' ),
358
-        '8'  => __( 'August', 'invoicing' ),
359
-        '9'  => __( 'September', 'invoicing' ),
360
-        '10' => __( 'October', 'invoicing' ),
361
-        '11' => __( 'November', 'invoicing' ),
362
-        '12' => __( 'December', 'invoicing' ),
351
+        '1'  => __('January', 'invoicing'),
352
+        '2'  => __('February', 'invoicing'),
353
+        '3'  => __('March', 'invoicing'),
354
+        '4'  => __('April', 'invoicing'),
355
+        '5'  => __('May', 'invoicing'),
356
+        '6'  => __('June', 'invoicing'),
357
+        '7'  => __('July', 'invoicing'),
358
+        '8'  => __('August', 'invoicing'),
359
+        '9'  => __('September', 'invoicing'),
360
+        '10' => __('October', 'invoicing'),
361
+        '11' => __('November', 'invoicing'),
362
+        '12' => __('December', 'invoicing'),
363 363
     );
364 364
 
365 365
     // If no month is selected, default to the current month
366
-    $selected = empty( $selected ) ? date( 'n' ) : $selected;
366
+    $selected = empty($selected) ? date('n') : $selected;
367 367
 
368
-    $output = wpinv_html_select( array(
368
+    $output = wpinv_html_select(array(
369 369
         'name'             => $name,
370 370
         'selected'         => $selected,
371 371
         'options'          => $options,
372 372
         'show_option_all'  => false,
373 373
         'show_option_none' => false
374
-    ) );
374
+    ));
375 375
 
376 376
     return $output;
377 377
 }
378 378
 
379
-function wpinv_html_select( $args = array() ) {
379
+function wpinv_html_select($args = array()) {
380 380
     $defaults = array(
381 381
         'options'          => array(),
382 382
         'name'             => null,
@@ -385,8 +385,8 @@  discard block
 block discarded – undo
385 385
         'selected'         => 0,
386 386
         'placeholder'      => null,
387 387
         'multiple'         => false,
388
-        'show_option_all'  => _x( 'All', 'all dropdown items', 'invoicing' ),
389
-        'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ),
388
+        'show_option_all'  => _x('All', 'all dropdown items', 'invoicing'),
389
+        'show_option_none' => _x('None', 'no dropdown items', 'invoicing'),
390 390
         'data'             => array(),
391 391
         'onchange'         => null,
392 392
         'required'         => false,
@@ -394,74 +394,74 @@  discard block
 block discarded – undo
394 394
         'readonly'         => false,
395 395
     );
396 396
 
397
-    $args = wp_parse_args( $args, $defaults );
397
+    $args = wp_parse_args($args, $defaults);
398 398
 
399 399
     $data_elements = '';
400
-    foreach ( $args['data'] as $key => $value ) {
401
-        $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
400
+    foreach ($args['data'] as $key => $value) {
401
+        $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"';
402 402
     }
403 403
 
404
-    if( $args['multiple'] ) {
404
+    if ($args['multiple']) {
405 405
         $multiple = ' MULTIPLE';
406 406
     } else {
407 407
         $multiple = '';
408 408
     }
409 409
 
410
-    if( $args['placeholder'] ) {
410
+    if ($args['placeholder']) {
411 411
         $placeholder = $args['placeholder'];
412 412
     } else {
413 413
         $placeholder = '';
414 414
     }
415 415
     
416 416
     $options = '';
417
-    if( !empty( $args['onchange'] ) ) {
418
-        $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"';
417
+    if (!empty($args['onchange'])) {
418
+        $options .= ' onchange="' . esc_attr($args['onchange']) . '"';
419 419
     }
420 420
     
421
-    if( !empty( $args['required'] ) ) {
421
+    if (!empty($args['required'])) {
422 422
         $options .= ' required="required"';
423 423
     }
424 424
     
425
-    if( !empty( $args['disabled'] ) ) {
425
+    if (!empty($args['disabled'])) {
426 426
         $options .= ' disabled';
427 427
     }
428 428
     
429
-    if( !empty( $args['readonly'] ) ) {
429
+    if (!empty($args['readonly'])) {
430 430
         $options .= ' readonly';
431 431
     }
432 432
 
433
-    $class  = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
434
-    $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>';
433
+    $class  = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
434
+    $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>';
435 435
 
436
-    if ( $args['show_option_all'] ) {
437
-        if( $args['multiple'] ) {
438
-            $selected = selected( true, in_array( 0, $args['selected'] ), false );
436
+    if ($args['show_option_all']) {
437
+        if ($args['multiple']) {
438
+            $selected = selected(true, in_array(0, $args['selected']), false);
439 439
         } else {
440
-            $selected = selected( $args['selected'], 0, false );
440
+            $selected = selected($args['selected'], 0, false);
441 441
         }
442
-        $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
442
+        $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>';
443 443
     }
444 444
 
445
-    if ( !empty( $args['options'] ) ) {
445
+    if (!empty($args['options'])) {
446 446
 
447
-        if ( $args['show_option_none'] ) {
448
-            if( $args['multiple'] ) {
449
-                $selected = selected( true, in_array( "", $args['selected'] ), false );
447
+        if ($args['show_option_none']) {
448
+            if ($args['multiple']) {
449
+                $selected = selected(true, in_array("", $args['selected']), false);
450 450
             } else {
451
-                $selected = selected( $args['selected'] === "", true, false );
451
+                $selected = selected($args['selected'] === "", true, false);
452 452
             }
453
-            $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
453
+            $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>';
454 454
         }
455 455
 
456
-        foreach( $args['options'] as $key => $option ) {
456
+        foreach ($args['options'] as $key => $option) {
457 457
 
458
-            if( $args['multiple'] && is_array( $args['selected'] ) ) {
459
-                $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false );
458
+            if ($args['multiple'] && is_array($args['selected'])) {
459
+                $selected = selected(true, (bool) in_array($key, $args['selected']), false);
460 460
             } else {
461
-                $selected = selected( $args['selected'], $key, false );
461
+                $selected = selected($args['selected'], $key, false);
462 462
             }
463 463
 
464
-            $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
464
+            $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>';
465 465
         }
466 466
     }
467 467
 
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
     return $output;
471 471
 }
472 472
 
473
-function wpinv_item_dropdown( $args = array() ) {
473
+function wpinv_item_dropdown($args = array()) {
474 474
     $defaults = array(
475 475
         'name'              => 'wpi_item',
476 476
         'id'                => 'wpi_item',
@@ -478,14 +478,14 @@  discard block
 block discarded – undo
478 478
         'multiple'          => false,
479 479
         'selected'          => 0,
480 480
         'number'            => 100,
481
-        'placeholder'       => __( 'Choose a item', 'invoicing' ),
482
-        'data'              => array( 'search-type' => 'item' ),
481
+        'placeholder'       => __('Choose a item', 'invoicing'),
482
+        'data'              => array('search-type' => 'item'),
483 483
         'show_option_all'   => false,
484 484
         'show_option_none'  => false,
485 485
         'show_recurring'    => false,
486 486
     );
487 487
 
488
-    $args = wp_parse_args( $args, $defaults );
488
+    $args = wp_parse_args($args, $defaults);
489 489
 
490 490
     $item_args = array(
491 491
         'post_type'      => 'wpi_item',
@@ -494,44 +494,44 @@  discard block
 block discarded – undo
494 494
         'posts_per_page' => $args['number']
495 495
     );
496 496
 
497
-    $item_args  = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults );
497
+    $item_args  = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults);
498 498
 
499
-    $items      = get_posts( $item_args );
499
+    $items      = get_posts($item_args);
500 500
     $options    = array();
501
-    if ( $items ) {
502
-        foreach ( $items as $item ) {
503
-            $title = esc_html( $item->post_title );
501
+    if ($items) {
502
+        foreach ($items as $item) {
503
+            $title = esc_html($item->post_title);
504 504
             
505
-            if ( !empty( $args['show_recurring'] ) ) {
506
-                $title .= wpinv_get_item_suffix( $item->ID, false );
505
+            if (!empty($args['show_recurring'])) {
506
+                $title .= wpinv_get_item_suffix($item->ID, false);
507 507
             }
508 508
             
509
-            $options[ absint( $item->ID ) ] = $title;
509
+            $options[absint($item->ID)] = $title;
510 510
         }
511 511
     }
512 512
 
513 513
     // This ensures that any selected items are included in the drop down
514
-    if( is_array( $args['selected'] ) ) {
515
-        foreach( $args['selected'] as $item ) {
516
-            if( ! in_array( $item, $options ) ) {
517
-                $title = get_the_title( $item );
518
-                if ( !empty( $args['show_recurring'] ) ) {
519
-                    $title .= wpinv_get_item_suffix( $item, false );
514
+    if (is_array($args['selected'])) {
515
+        foreach ($args['selected'] as $item) {
516
+            if (!in_array($item, $options)) {
517
+                $title = get_the_title($item);
518
+                if (!empty($args['show_recurring'])) {
519
+                    $title .= wpinv_get_item_suffix($item, false);
520 520
                 }
521 521
                 $options[$item] = $title;
522 522
             }
523 523
         }
524
-    } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) {
525
-        if ( ! in_array( $args['selected'], $options ) ) {
526
-            $title = get_the_title( $args['selected'] );
527
-            if ( !empty( $args['show_recurring'] ) ) {
528
-                $title .= wpinv_get_item_suffix( $args['selected'], false );
524
+    } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
525
+        if (!in_array($args['selected'], $options)) {
526
+            $title = get_the_title($args['selected']);
527
+            if (!empty($args['show_recurring'])) {
528
+                $title .= wpinv_get_item_suffix($args['selected'], false);
529 529
             }
530
-            $options[$args['selected']] = get_the_title( $args['selected'] );
530
+            $options[$args['selected']] = get_the_title($args['selected']);
531 531
         }
532 532
     }
533 533
 
534
-    $output = wpinv_html_select( array(
534
+    $output = wpinv_html_select(array(
535 535
         'name'             => $args['name'],
536 536
         'selected'         => $args['selected'],
537 537
         'id'               => $args['id'],
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
         'show_option_all'  => $args['show_option_all'],
543 543
         'show_option_none' => $args['show_option_none'],
544 544
         'data'             => $args['data'],
545
-    ) );
545
+    ));
546 546
 
547 547
     return $output;
548 548
 }
@@ -562,16 +562,16 @@  discard block
 block discarded – undo
562 562
     );
563 563
 
564 564
     $options = array();
565
-    if ( $items ) {
566
-        foreach ( $items as $item ) {
567
-            $options[ $item->ID ] = esc_html( $item->post_title ) . wpinv_get_item_suffix( $item->ID, false );
565
+    if ($items) {
566
+        foreach ($items as $item) {
567
+            $options[$item->ID] = esc_html($item->post_title) . wpinv_get_item_suffix($item->ID, false);
568 568
         }
569 569
     }
570 570
 
571 571
     return $options;
572 572
 }
573 573
 
574
-function wpinv_html_checkbox( $args = array() ) {
574
+function wpinv_html_checkbox($args = array()) {
575 575
     $defaults = array(
576 576
         'name'     => null,
577 577
         'current'  => null,
@@ -582,17 +582,17 @@  discard block
 block discarded – undo
582 582
         )
583 583
     );
584 584
 
585
-    $args = wp_parse_args( $args, $defaults );
585
+    $args = wp_parse_args($args, $defaults);
586 586
 
587
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
587
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
588 588
     $options = '';
589
-    if ( ! empty( $args['options']['disabled'] ) ) {
589
+    if (!empty($args['options']['disabled'])) {
590 590
         $options .= ' disabled="disabled"';
591
-    } elseif ( ! empty( $args['options']['readonly'] ) ) {
591
+    } elseif (!empty($args['options']['readonly'])) {
592 592
         $options .= ' readonly';
593 593
     }
594 594
 
595
-    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />';
595
+    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />';
596 596
 
597 597
     return $output;
598 598
 }
@@ -600,30 +600,30 @@  discard block
 block discarded – undo
600 600
 /**
601 601
  * Displays a hidden field.
602 602
  */
603
-function getpaid_hidden_field( $name, $value ) {
604
-    $name  = sanitize_text_field( $name );
605
-    $value = esc_attr( $value );
603
+function getpaid_hidden_field($name, $value) {
604
+    $name  = sanitize_text_field($name);
605
+    $value = esc_attr($value);
606 606
 
607 607
     echo "<input type='hidden' name='$name' value='$value' />";
608 608
 }
609 609
 
610
-function wpinv_html_text( $args = array() ) {
610
+function wpinv_html_text($args = array()) {
611 611
     // Backwards compatibility
612
-    if ( func_num_args() > 1 ) {
612
+    if (func_num_args() > 1) {
613 613
         $args = func_get_args();
614 614
 
615 615
         $name  = $args[0];
616
-        $value = isset( $args[1] ) ? $args[1] : '';
617
-        $label = isset( $args[2] ) ? $args[2] : '';
618
-        $desc  = isset( $args[3] ) ? $args[3] : '';
616
+        $value = isset($args[1]) ? $args[1] : '';
617
+        $label = isset($args[2]) ? $args[2] : '';
618
+        $desc  = isset($args[3]) ? $args[3] : '';
619 619
     }
620 620
 
621 621
     $defaults = array(
622 622
         'id'           => '',
623
-        'name'         => isset( $name )  ? $name  : 'text',
624
-        'value'        => isset( $value ) ? $value : null,
625
-        'label'        => isset( $label ) ? $label : null,
626
-        'desc'         => isset( $desc )  ? $desc  : null,
623
+        'name'         => isset($name) ? $name : 'text',
624
+        'value'        => isset($value) ? $value : null,
625
+        'label'        => isset($label) ? $label : null,
626
+        'desc'         => isset($desc) ? $desc : null,
627 627
         'placeholder'  => '',
628 628
         'class'        => 'regular-text',
629 629
         'disabled'     => false,
@@ -633,51 +633,51 @@  discard block
 block discarded – undo
633 633
         'data'         => false
634 634
     );
635 635
 
636
-    $args = wp_parse_args( $args, $defaults );
636
+    $args = wp_parse_args($args, $defaults);
637 637
 
638
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
638
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
639 639
     $options = '';
640
-    if( $args['required'] ) {
640
+    if ($args['required']) {
641 641
         $options .= ' required="required"';
642 642
     }
643
-    if( $args['readonly'] ) {
643
+    if ($args['readonly']) {
644 644
         $options .= ' readonly';
645 645
     }
646
-    if( $args['readonly'] ) {
646
+    if ($args['readonly']) {
647 647
         $options .= ' readonly';
648 648
     }
649 649
 
650 650
     $data = '';
651
-    if ( !empty( $args['data'] ) ) {
652
-        foreach ( $args['data'] as $key => $value ) {
653
-            $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" ';
651
+    if (!empty($args['data'])) {
652
+        foreach ($args['data'] as $key => $value) {
653
+            $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" ';
654 654
         }
655 655
     }
656 656
 
657
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
658
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>';
659
-    if ( ! empty( $args['desc'] ) ) {
660
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
657
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
658
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
659
+    if (!empty($args['desc'])) {
660
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
661 661
     }
662 662
 
663
-    $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] )  . '" autocomplete="' . esc_attr( $args['autocomplete'] )  . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>';
663
+    $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>';
664 664
 
665 665
     $output .= '</span>';
666 666
 
667 667
     return $output;
668 668
 }
669 669
 
670
-function wpinv_html_date_field( $args = array() ) {
671
-    if( empty( $args['class'] ) ) {
670
+function wpinv_html_date_field($args = array()) {
671
+    if (empty($args['class'])) {
672 672
         $args['class'] = 'wpiDatepicker';
673
-    } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) {
673
+    } elseif (!strpos($args['class'], 'wpiDatepicker')) {
674 674
         $args['class'] .= ' wpiDatepicker';
675 675
     }
676 676
 
677
-    return wpinv_html_text( $args );
677
+    return wpinv_html_text($args);
678 678
 }
679 679
 
680
-function wpinv_html_textarea( $args = array() ) {
680
+function wpinv_html_textarea($args = array()) {
681 681
     $defaults = array(
682 682
         'name'        => 'textarea',
683 683
         'value'       => null,
@@ -688,31 +688,31 @@  discard block
 block discarded – undo
688 688
         'placeholder' => '',
689 689
     );
690 690
 
691
-    $args = wp_parse_args( $args, $defaults );
691
+    $args = wp_parse_args($args, $defaults);
692 692
 
693
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
693
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
694 694
     $disabled = '';
695
-    if( $args['disabled'] ) {
695
+    if ($args['disabled']) {
696 696
         $disabled = ' disabled="disabled"';
697 697
     }
698 698
 
699
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
700
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
701
-    $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
699
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
700
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>';
701
+    $output .= '<textarea name="' . esc_attr($args['name']) . '" placeholder="' . esc_attr($args['placeholder']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>';
702 702
 
703
-    if ( ! empty( $args['desc'] ) ) {
704
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
703
+    if (!empty($args['desc'])) {
704
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
705 705
     }
706 706
     $output .= '</span>';
707 707
 
708 708
     return $output;
709 709
 }
710 710
 
711
-function wpinv_html_ajax_user_search( $args = array() ) {
711
+function wpinv_html_ajax_user_search($args = array()) {
712 712
     $defaults = array(
713 713
         'name'        => 'user_id',
714 714
         'value'       => null,
715
-        'placeholder' => __( 'Enter username', 'invoicing' ),
715
+        'placeholder' => __('Enter username', 'invoicing'),
716 716
         'label'       => null,
717 717
         'desc'        => null,
718 718
         'class'       => '',
@@ -721,13 +721,13 @@  discard block
 block discarded – undo
721 721
         'data'        => false
722 722
     );
723 723
 
724
-    $args = wp_parse_args( $args, $defaults );
724
+    $args = wp_parse_args($args, $defaults);
725 725
 
726 726
     $args['class'] = 'wpinv-ajax-user-search ' . $args['class'];
727 727
 
728 728
     $output  = '<span class="wpinv_user_search_wrap">';
729
-        $output .= wpinv_html_text( $args );
730
-        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>';
729
+        $output .= wpinv_html_text($args);
730
+        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>';
731 731
     $output .= '</span>';
732 732
 
733 733
     return $output;
@@ -743,20 +743,20 @@  discard block
 block discarded – undo
743 743
  * 
744 744
  * @param string $template the template that is currently being used.
745 745
  */
746
-function wpinv_template( $template ) {
746
+function wpinv_template($template) {
747 747
     global $post;
748 748
 
749
-    if ( ! is_admin() && ( is_single() || is_404() ) && ! empty( $post->ID ) && getpaid_is_invoice_post_type( get_post_type( $post->ID ) ) ) {
749
+    if (!is_admin() && (is_single() || is_404()) && !empty($post->ID) && getpaid_is_invoice_post_type(get_post_type($post->ID))) {
750 750
 
751 751
         // If the user can view this invoice, display it.
752
-        if ( wpinv_user_can_view_invoice( $post->ID ) ) {
752
+        if (wpinv_user_can_view_invoice($post->ID)) {
753 753
 
754
-            return wpinv_get_template_part( 'wpinv-invoice-print', false, false );
754
+            return wpinv_get_template_part('wpinv-invoice-print', false, false);
755 755
 
756 756
         // Else display an error message.
757 757
         } else {
758 758
 
759
-            return wpinv_get_template_part( 'wpinv-invalid-access', false, false );
759
+            return wpinv_get_template_part('wpinv-invalid-access', false, false);
760 760
 
761 761
         }
762 762
 
@@ -764,46 +764,46 @@  discard block
 block discarded – undo
764 764
 
765 765
     return $template;
766 766
 }
767
-add_filter( 'template_include', 'wpinv_template', 10, 1 );
767
+add_filter('template_include', 'wpinv_template', 10, 1);
768 768
 
769 769
 function wpinv_get_business_address() {
770 770
     $business_address   = wpinv_store_address();
771
-    $business_address   = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : '';
771
+    $business_address   = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : '';
772 772
     
773 773
     $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : '';
774 774
     
775
-    return apply_filters( 'wpinv_get_business_address', $business_address );
775
+    return apply_filters('wpinv_get_business_address', $business_address);
776 776
 }
777 777
 
778 778
 /**
779 779
  * Displays the company address.
780 780
  */
781 781
 function wpinv_display_from_address() {
782
-    wpinv_get_template( 'invoice/company-address.php' );
782
+    wpinv_get_template('invoice/company-address.php');
783 783
 }
784
-add_action( 'getpaid_invoice_details_left', 'wpinv_display_from_address', 10 );
784
+add_action('getpaid_invoice_details_left', 'wpinv_display_from_address', 10);
785 785
 
786
-function wpinv_watermark( $id = 0 ) {
787
-    $output = wpinv_get_watermark( $id );
788
-    return apply_filters( 'wpinv_get_watermark', $output, $id );
786
+function wpinv_watermark($id = 0) {
787
+    $output = wpinv_get_watermark($id);
788
+    return apply_filters('wpinv_get_watermark', $output, $id);
789 789
 }
790 790
 
791
-function wpinv_get_watermark( $id ) {
792
-    if ( !$id > 0 ) {
791
+function wpinv_get_watermark($id) {
792
+    if (!$id > 0) {
793 793
         return NULL;
794 794
     }
795 795
 
796
-    $invoice = wpinv_get_invoice( $id );
796
+    $invoice = wpinv_get_invoice($id);
797 797
     
798
-    if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) {
799
-        if ( $invoice->is_paid() ) {
800
-            return __( 'Paid', 'invoicing' );
798
+    if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) {
799
+        if ($invoice->is_paid()) {
800
+            return __('Paid', 'invoicing');
801 801
         }
802
-        if ( $invoice->is_refunded() ) {
803
-            return __( 'Refunded', 'invoicing' );
802
+        if ($invoice->is_refunded()) {
803
+            return __('Refunded', 'invoicing');
804 804
         }
805
-        if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) {
806
-            return __( 'Cancelled', 'invoicing' );
805
+        if ($invoice->has_status(array('wpi-cancelled'))) {
806
+            return __('Cancelled', 'invoicing');
807 807
         }
808 808
     }
809 809
     
@@ -813,140 +813,140 @@  discard block
 block discarded – undo
813 813
 /**
814 814
  * @deprecated
815 815
  */
816
-function wpinv_display_invoice_details( $invoice ) {
817
-    return getpaid_invoice_meta( $invoice );
816
+function wpinv_display_invoice_details($invoice) {
817
+    return getpaid_invoice_meta($invoice);
818 818
 }
819 819
 
820 820
 /**
821 821
  * Displays invoice meta.
822 822
  */
823
-function getpaid_invoice_meta( $invoice ) {
823
+function getpaid_invoice_meta($invoice) {
824 824
 
825
-    $invoice = new WPInv_Invoice( $invoice );
825
+    $invoice = new WPInv_Invoice($invoice);
826 826
 
827 827
     // Ensure that we have an invoice.
828
-    if ( 0 == $invoice->get_id() ) {
828
+    if (0 == $invoice->get_id()) {
829 829
         return;
830 830
     }
831 831
 
832 832
     // Load the invoice meta.
833
-    $meta    = array(
833
+    $meta = array(
834 834
 
835 835
         'number' => array(
836 836
             'label' => sprintf(
837
-                __( '%s Number', 'invoicing' ),
838
-                ucfirst( $invoice->get_type() )
837
+                __('%s Number', 'invoicing'),
838
+                ucfirst($invoice->get_type())
839 839
             ),
840
-            'value' => sanitize_text_field( $invoice->get_number() ),
840
+            'value' => sanitize_text_field($invoice->get_number()),
841 841
         ),
842 842
 
843 843
         'status' => array(
844 844
             'label' => sprintf(
845
-                __( '%s Status', 'invoicing' ),
846
-                ucfirst( $invoice->get_type() )
845
+                __('%s Status', 'invoicing'),
846
+                ucfirst($invoice->get_type())
847 847
             ),
848 848
             'value' => $invoice->get_status_label_html(),
849 849
         ),
850 850
 
851 851
         'date' => array(
852 852
             'label' => sprintf(
853
-                __( '%s Date', 'invoicing' ),
854
-                ucfirst( $invoice->get_type() )
853
+                __('%s Date', 'invoicing'),
854
+                ucfirst($invoice->get_type())
855 855
             ),
856
-            'value' => getpaid_format_date( $invoice->get_created_date() ),
856
+            'value' => getpaid_format_date($invoice->get_created_date()),
857 857
         ),
858 858
 
859 859
         'date_paid' => array(
860
-            'label' => __( 'Paid On', 'invoicing' ),
861
-            'value' => getpaid_format_date( $invoice->get_completed_date() ),
860
+            'label' => __('Paid On', 'invoicing'),
861
+            'value' => getpaid_format_date($invoice->get_completed_date()),
862 862
         ),
863 863
 
864 864
         'gateway'   => array(
865
-            'label' => __( 'Payment Method', 'invoicing' ),
866
-            'value' => sanitize_text_field( $invoice->get_gateway_title() ),
865
+            'label' => __('Payment Method', 'invoicing'),
866
+            'value' => sanitize_text_field($invoice->get_gateway_title()),
867 867
         ),
868 868
 
869 869
         'transaction_id' => array(
870
-            'label' => __( 'Transaction ID', 'invoicing' ),
871
-            'value' => sanitize_text_field( $invoice->get_transaction_id() ),
870
+            'label' => __('Transaction ID', 'invoicing'),
871
+            'value' => sanitize_text_field($invoice->get_transaction_id()),
872 872
         ),
873 873
 
874 874
         'due_date'  => array(
875
-            'label' => __( 'Due Date', 'invoicing' ),
876
-            'value' => getpaid_format_date( $invoice->get_due_date() ),
875
+            'label' => __('Due Date', 'invoicing'),
876
+            'value' => getpaid_format_date($invoice->get_due_date()),
877 877
         ),
878 878
 
879 879
         'vat_number' => array(
880 880
             'label' => sprintf(
881
-                __( '%s Number', 'invoicing' ),
881
+                __('%s Number', 'invoicing'),
882 882
                 getpaid_tax()->get_vat_name()
883 883
             ),
884
-            'value' => sanitize_text_field( $invoice->get_vat_number() ),
884
+            'value' => sanitize_text_field($invoice->get_vat_number()),
885 885
         ),
886 886
 
887 887
     );
888 888
 
889 889
     // If it is not paid, remove the date of payment.
890
-    if ( ! $invoice->is_paid() ) {
891
-        unset( $meta[ 'date_paid' ] );
892
-        unset( $meta[ 'transaction_id' ] );
890
+    if (!$invoice->is_paid()) {
891
+        unset($meta['date_paid']);
892
+        unset($meta['transaction_id']);
893 893
     }
894 894
 
895
-    if ( ! $invoice->is_paid() || 'none' == $invoice->get_gateway() ) {
896
-        unset( $meta[ 'gateway' ] );
895
+    if (!$invoice->is_paid() || 'none' == $invoice->get_gateway()) {
896
+        unset($meta['gateway']);
897 897
     }
898 898
 
899 899
     // Only display the due date if due dates are enabled.
900
-    if ( ! $invoice->needs_payment() || ! wpinv_get_option( 'overdue_active' ) ) {
901
-        unset( $meta[ 'due_date' ] );
900
+    if (!$invoice->needs_payment() || !wpinv_get_option('overdue_active')) {
901
+        unset($meta['due_date']);
902 902
     }
903 903
 
904 904
     // Only display the vat number if taxes are enabled.
905
-    if ( ! wpinv_use_taxes() ) {
906
-        unset( $meta[ 'vat_number' ] );
905
+    if (!wpinv_use_taxes()) {
906
+        unset($meta['vat_number']);
907 907
     }
908 908
 
909
-    if ( $invoice->is_recurring() ) {
909
+    if ($invoice->is_recurring()) {
910 910
 
911 911
         // Link to the parent invoice.
912
-        if ( $invoice->is_renewal() ) {
912
+        if ($invoice->is_renewal()) {
913 913
 
914
-            $meta[ 'parent' ] = array(
914
+            $meta['parent'] = array(
915 915
 
916 916
                 'label' => sprintf(
917
-                    __( 'Parent %s', 'invoicing' ),
918
-                    ucfirst( $invoice->get_type() )
917
+                    __('Parent %s', 'invoicing'),
918
+                    ucfirst($invoice->get_type())
919 919
                 ),
920 920
 
921
-                'value' => wpinv_invoice_link( $invoice->get_parent_id() ),
921
+                'value' => wpinv_invoice_link($invoice->get_parent_id()),
922 922
 
923 923
             );
924 924
 
925 925
         }
926 926
 
927
-        $subscription = wpinv_get_subscription( $invoice );
927
+        $subscription = wpinv_get_subscription($invoice);
928 928
 
929
-        if ( ! empty ( $subscription ) ) {
929
+        if (!empty ($subscription)) {
930 930
 
931 931
             // Display the renewal date.
932
-            if ( $subscription->is_active() && 'cancelled' != $subscription->status ) {
932
+            if ($subscription->is_active() && 'cancelled' != $subscription->status) {
933 933
 
934
-                $meta[ 'renewal_date' ] = array(
934
+                $meta['renewal_date'] = array(
935 935
 
936
-                    'label' => __( 'Renews On', 'invoicing' ),
937
-                    'value' => getpaid_format_date( $subscription->expiration ),
936
+                    'label' => __('Renews On', 'invoicing'),
937
+                    'value' => getpaid_format_date($subscription->expiration),
938 938
         
939 939
                 );
940 940
 
941 941
             }
942 942
 
943
-            if ( $invoice->is_parent() ) {
943
+            if ($invoice->is_parent()) {
944 944
 
945 945
                 // Display the recurring amount.
946
-                $meta[ 'recurring_total' ] = array(
946
+                $meta['recurring_total'] = array(
947 947
 
948
-                    'label' => __( 'Recurring Amount', 'invoicing' ),
949
-                    'value' => wpinv_price( wpinv_format_amount( $subscription->recurring_amount ), $invoice->get_currency() ),
948
+                    'label' => __('Recurring Amount', 'invoicing'),
949
+                    'value' => wpinv_price(wpinv_format_amount($subscription->recurring_amount), $invoice->get_currency()),
950 950
         
951 951
                 );
952 952
 
@@ -956,20 +956,20 @@  discard block
 block discarded – undo
956 956
     }
957 957
 
958 958
     // Add the invoice total to the meta.
959
-    $meta[ 'invoice_total' ] = array(
959
+    $meta['invoice_total'] = array(
960 960
 
961
-        'label' => __( 'Total Amount', 'invoicing' ),
962
-        'value' => wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() ),
961
+        'label' => __('Total Amount', 'invoicing'),
962
+        'value' => wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency()),
963 963
 
964 964
     );
965 965
 
966 966
     // Provide a way for third party plugins to filter the meta.
967
-    $meta = apply_filters( 'getpaid_invoice_meta_data', $meta, $invoice );
967
+    $meta = apply_filters('getpaid_invoice_meta_data', $meta, $invoice);
968 968
 
969
-    wpinv_get_template( 'invoice/invoice-meta.php', compact( 'invoice', 'meta' ) );
969
+    wpinv_get_template('invoice/invoice-meta.php', compact('invoice', 'meta'));
970 970
 
971 971
 }
972
-add_action( 'getpaid_invoice_details_right', 'getpaid_invoice_meta', 10 );
972
+add_action('getpaid_invoice_details_right', 'getpaid_invoice_meta', 10);
973 973
 
974 974
 /**
975 975
  * Retrieves the address markup to use on Invoices.
@@ -981,29 +981,29 @@  discard block
 block discarded – undo
981 981
  * @param  string $separator How to separate address lines.
982 982
  * @return string
983 983
  */
984
-function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) {
984
+function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') {
985 985
 
986 986
     // Retrieve the address markup...
987
-    $country= empty( $billing_details['country'] ) ? '' : $billing_details['country'];
988
-    $format = wpinv_get_full_address_format( $country );
987
+    $country = empty($billing_details['country']) ? '' : $billing_details['country'];
988
+    $format = wpinv_get_full_address_format($country);
989 989
 
990 990
     // ... and the replacements.
991
-    $replacements = wpinv_get_invoice_address_replacements( $billing_details );
991
+    $replacements = wpinv_get_invoice_address_replacements($billing_details);
992 992
 
993
-    $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format );
993
+    $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format);
994 994
     
995 995
 	// Remove unavailable tags.
996
-    $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address );
996
+    $formatted_address = preg_replace("/\{\{\w+\}\}/", '', $formatted_address);
997 997
 
998 998
     // Clean up white space.
999
-	$formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
1000
-    $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );
999
+	$formatted_address = preg_replace('/  +/', ' ', trim($formatted_address));
1000
+    $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address);
1001 1001
     
1002 1002
     // Break newlines apart and remove empty lines/trim commas and white space.
1003
-	$formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
1003
+	$formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address)));
1004 1004
 
1005 1005
     // Add html breaks.
1006
-	$formatted_address = implode( $separator, $formatted_address );
1006
+	$formatted_address = implode($separator, $formatted_address);
1007 1007
 
1008 1008
 	// We're done!
1009 1009
 	return $formatted_address;
@@ -1015,88 +1015,88 @@  discard block
 block discarded – undo
1015 1015
  * 
1016 1016
  * @param WPInv_Invoice $invoice
1017 1017
  */
1018
-function wpinv_display_to_address( $invoice = 0 ) {
1019
-    if ( ! empty( $invoice ) ) {
1020
-        wpinv_get_template( 'invoice/billing-address.php', compact( 'invoice' ) );
1018
+function wpinv_display_to_address($invoice = 0) {
1019
+    if (!empty($invoice)) {
1020
+        wpinv_get_template('invoice/billing-address.php', compact('invoice'));
1021 1021
     }
1022 1022
 }
1023
-add_action( 'getpaid_invoice_details_left', 'wpinv_display_to_address', 40 );
1023
+add_action('getpaid_invoice_details_left', 'wpinv_display_to_address', 40);
1024 1024
 
1025 1025
 
1026 1026
 /**
1027 1027
  * Displays invoice line items.
1028 1028
  */
1029
-function wpinv_display_line_items( $invoice_id = 0 ) {
1029
+function wpinv_display_line_items($invoice_id = 0) {
1030 1030
 
1031 1031
     // Prepare the invoice.
1032
-    $invoice = new WPInv_Invoice( $invoice_id );
1032
+    $invoice = new WPInv_Invoice($invoice_id);
1033 1033
 
1034 1034
     // Abort if there is no invoice.
1035
-    if ( 0 == $invoice->get_id() ) {
1035
+    if (0 == $invoice->get_id()) {
1036 1036
         return;
1037 1037
     }
1038 1038
 
1039 1039
     // Line item columns.
1040
-    $columns = getpaid_invoice_item_columns( $invoice );
1041
-    $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice );
1040
+    $columns = getpaid_invoice_item_columns($invoice);
1041
+    $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice);
1042 1042
 
1043
-    wpinv_get_template( 'invoice/line-items.php', compact( 'invoice', 'columns' ) );
1043
+    wpinv_get_template('invoice/line-items.php', compact('invoice', 'columns'));
1044 1044
 }
1045
-add_action( 'getpaid_invoice_line_items', 'wpinv_display_line_items', 10 );
1045
+add_action('getpaid_invoice_line_items', 'wpinv_display_line_items', 10);
1046 1046
 
1047 1047
 /**
1048 1048
  * Displays invoice notices on invoices.
1049 1049
  */
1050 1050
 function wpinv_display_invoice_notice() {
1051 1051
 
1052
-    $label  = wpinv_get_option( 'vat_invoice_notice_label' );
1053
-    $notice = wpinv_get_option( 'vat_invoice_notice' );
1052
+    $label  = wpinv_get_option('vat_invoice_notice_label');
1053
+    $notice = wpinv_get_option('vat_invoice_notice');
1054 1054
 
1055
-    if ( empty( $label ) && empty( $notice ) ) {
1055
+    if (empty($label) && empty($notice)) {
1056 1056
         return;
1057 1057
     }
1058 1058
 
1059 1059
     echo '<div class="mt-4 mb-4 wpinv-vat-notice">';
1060 1060
 
1061
-    if ( ! empty( $label ) ) {
1062
-        $label = sanitize_text_field( $label );
1061
+    if (!empty($label)) {
1062
+        $label = sanitize_text_field($label);
1063 1063
         echo "<h5>$label</h5>";
1064 1064
     }
1065 1065
 
1066
-    if ( ! empty( $notice ) ) {
1067
-        echo '<small class="form-text text-muted">' . wpautop( wptexturize( $notice ) ) . '</small>';
1066
+    if (!empty($notice)) {
1067
+        echo '<small class="form-text text-muted">' . wpautop(wptexturize($notice)) . '</small>';
1068 1068
     }
1069 1069
 
1070 1070
     echo '</div>';
1071 1071
 }
1072
-add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100 );
1072
+add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100);
1073 1073
 
1074 1074
 /**
1075 1075
  * @param WPInv_Invoice $invoice
1076 1076
  */
1077
-function wpinv_display_invoice_notes( $invoice ) {
1077
+function wpinv_display_invoice_notes($invoice) {
1078 1078
 
1079 1079
     // Retrieve the notes.
1080
-    $notes = wpinv_get_invoice_notes( $invoice->get_id(), 'customer' );
1080
+    $notes = wpinv_get_invoice_notes($invoice->get_id(), 'customer');
1081 1081
 
1082 1082
     // Abort if we have non.
1083
-    if ( empty( $notes ) ) {
1083
+    if (empty($notes)) {
1084 1084
         return;
1085 1085
     }
1086 1086
 
1087 1087
     // Echo the note.
1088 1088
     echo '<div class="getpaid-invoice-notes-wrapper border position-relative w-100 mb-4 p-0">';
1089
-    echo '<h3 class="getpaid-invoice-notes-title text-dark bg-light border-bottom m-0 d-block">' . __( 'Notes', 'invoicing' ) .'</h3>';
1089
+    echo '<h3 class="getpaid-invoice-notes-title text-dark bg-light border-bottom m-0 d-block">' . __('Notes', 'invoicing') . '</h3>';
1090 1090
     echo '<ul class="getpaid-invoice-notes mt-4 p-0">';
1091 1091
 
1092
-    foreach( $notes as $note ) {
1093
-        wpinv_get_invoice_note_line_item( $note );
1092
+    foreach ($notes as $note) {
1093
+        wpinv_get_invoice_note_line_item($note);
1094 1094
     }
1095 1095
 
1096 1096
     echo '</ul>';
1097 1097
     echo '</div>';
1098 1098
 }
1099
-add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60 );
1099
+add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60);
1100 1100
 
1101 1101
 /**
1102 1102
  * Loads scripts on our invoice templates.
@@ -1104,32 +1104,32 @@  discard block
 block discarded – undo
1104 1104
 function wpinv_display_style() {
1105 1105
 
1106 1106
     // Make sure that all scripts have been loaded.
1107
-    if ( ! did_action( 'wp_enqueue_scripts' ) ) {
1108
-        do_action( 'wp_enqueue_scripts' );
1107
+    if (!did_action('wp_enqueue_scripts')) {
1108
+        do_action('wp_enqueue_scripts');
1109 1109
     }
1110 1110
 
1111 1111
     // Register the invoices style.
1112
-    wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice.css' ) );
1112
+    wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice.css'));
1113 1113
 
1114 1114
     // Load required styles
1115
-    wp_print_styles( 'open-sans' );
1116
-    wp_print_styles( 'wpinv-single-style' );
1117
-    wp_print_styles( 'ayecode-ui' );
1115
+    wp_print_styles('open-sans');
1116
+    wp_print_styles('wpinv-single-style');
1117
+    wp_print_styles('ayecode-ui');
1118 1118
 
1119 1119
     // Maybe load custom css.
1120
-    $custom_css = wpinv_get_option( 'template_custom_css' );
1120
+    $custom_css = wpinv_get_option('template_custom_css');
1121 1121
 
1122
-    if ( isset( $custom_css ) && ! empty( $custom_css ) ) {
1123
-        $custom_css     = wp_kses( $custom_css, array( '\'', '\"' ) );
1124
-        $custom_css     = str_replace( '&gt;', '>', $custom_css );
1122
+    if (isset($custom_css) && !empty($custom_css)) {
1123
+        $custom_css     = wp_kses($custom_css, array('\'', '\"'));
1124
+        $custom_css     = str_replace('&gt;', '>', $custom_css);
1125 1125
         echo '<style type="text/css">';
1126 1126
         echo $custom_css;
1127 1127
         echo '</style>';
1128 1128
     }
1129 1129
 
1130 1130
 }
1131
-add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' );
1132
-add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' );
1131
+add_action('wpinv_invoice_print_head', 'wpinv_display_style');
1132
+add_action('wpinv_invalid_invoice_head', 'wpinv_display_style');
1133 1133
 
1134 1134
 
1135 1135
 /**
@@ -1141,41 +1141,41 @@  discard block
 block discarded – undo
1141 1141
     // Retrieve the current invoice.
1142 1142
     $invoice_id = getpaid_get_current_invoice_id();
1143 1143
 
1144
-    if ( empty( $invoice_id ) ) {
1144
+    if (empty($invoice_id)) {
1145 1145
 
1146 1146
         return aui()->alert(
1147 1147
             array(
1148 1148
                 'type'    => 'warning',
1149
-                'content' => __( 'Invalid invoice', 'invoicing' ),
1149
+                'content' => __('Invalid invoice', 'invoicing'),
1150 1150
             )
1151 1151
         );
1152 1152
 
1153 1153
     }
1154 1154
 
1155 1155
     // Can the user view this invoice?
1156
-    if ( ! wpinv_user_can_view_invoice( $invoice_id ) ) {
1156
+    if (!wpinv_user_can_view_invoice($invoice_id)) {
1157 1157
 
1158 1158
         return aui()->alert(
1159 1159
             array(
1160 1160
                 'type'    => 'warning',
1161
-                'content' => __( 'You are not allowed to view this invoice', 'invoicing' ),
1161
+                'content' => __('You are not allowed to view this invoice', 'invoicing'),
1162 1162
             )
1163 1163
         );
1164 1164
 
1165 1165
     }
1166 1166
 
1167 1167
     // Ensure that it is not yet paid for.
1168
-    $invoice = new WPInv_Invoice( $invoice_id );
1168
+    $invoice = new WPInv_Invoice($invoice_id);
1169 1169
 
1170 1170
     // Maybe mark it as viewed.
1171
-    getpaid_maybe_mark_invoice_as_viewed( $invoice );
1171
+    getpaid_maybe_mark_invoice_as_viewed($invoice);
1172 1172
 
1173
-    if ( $invoice->is_paid() ) {
1173
+    if ($invoice->is_paid()) {
1174 1174
 
1175 1175
         return aui()->alert(
1176 1176
             array(
1177 1177
                 'type'    => 'success',
1178
-                'content' => __( 'This invoice has already been paid.', 'invoicing' ),
1178
+                'content' => __('This invoice has already been paid.', 'invoicing'),
1179 1179
             )
1180 1180
         );
1181 1181
 
@@ -1185,14 +1185,14 @@  discard block
 block discarded – undo
1185 1185
     $wpi_checkout_id = $invoice_id;
1186 1186
 
1187 1187
     // We'll display this invoice via the default form.
1188
-    $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
1188
+    $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form());
1189 1189
 
1190
-    if ( 0 == $form->get_id() ) {
1190
+    if (0 == $form->get_id()) {
1191 1191
 
1192 1192
         return aui()->alert(
1193 1193
             array(
1194 1194
                 'type'    => 'warning',
1195
-                'content' => __( 'Error loading the payment form', 'invoicing' ),
1195
+                'content' => __('Error loading the payment form', 'invoicing'),
1196 1196
             )
1197 1197
         );
1198 1198
 
@@ -1200,7 +1200,7 @@  discard block
 block discarded – undo
1200 1200
 
1201 1201
     // Set the invoice.
1202 1202
     $form->invoice = $invoice;
1203
-    $form->set_items( $invoice->get_items() );
1203
+    $form->set_items($invoice->get_items());
1204 1204
 
1205 1205
     // Generate the html.
1206 1206
     return $form->get_html();
@@ -1208,7 +1208,7 @@  discard block
 block discarded – undo
1208 1208
 }
1209 1209
 
1210 1210
 function wpinv_empty_cart_message() {
1211
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1211
+	return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>');
1212 1212
 }
1213 1213
 
1214 1214
 /**
@@ -1225,38 +1225,38 @@  discard block
 block discarded – undo
1225 1225
         )
1226 1226
     );
1227 1227
 }
1228
-add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1228
+add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart');
1229 1229
 
1230
-function wpinv_receipt_billing_address( $invoice_id = 0 ) {
1231
-    $invoice = wpinv_get_invoice( $invoice_id );
1230
+function wpinv_receipt_billing_address($invoice_id = 0) {
1231
+    $invoice = wpinv_get_invoice($invoice_id);
1232 1232
 
1233
-    if ( empty( $invoice ) ) {
1233
+    if (empty($invoice)) {
1234 1234
         return NULL;
1235 1235
     }
1236 1236
 
1237 1237
     $billing_details = $invoice->get_user_info();
1238
-    $address_row = wpinv_get_invoice_address_markup( $billing_details );
1238
+    $address_row = wpinv_get_invoice_address_markup($billing_details);
1239 1239
 
1240 1240
     ob_start();
1241 1241
     ?>
1242 1242
     <table class="table table-bordered table-sm wpi-billing-details">
1243 1243
         <tbody>
1244 1244
             <tr class="wpi-receipt-name">
1245
-                <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th>
1246
-                <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td>
1245
+                <th class="text-left"><?php _e('Name', 'invoicing'); ?></th>
1246
+                <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td>
1247 1247
             </tr>
1248 1248
             <tr class="wpi-receipt-email">
1249
-                <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th>
1250
-                <td><?php echo $billing_details['email'] ;?></td>
1249
+                <th class="text-left"><?php _e('Email', 'invoicing'); ?></th>
1250
+                <td><?php echo $billing_details['email']; ?></td>
1251 1251
             </tr>
1252 1252
             <tr class="wpi-receipt-address">
1253
-                <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th>
1254
-                <td><?php echo $address_row ;?></td>
1253
+                <th class="text-left"><?php _e('Address', 'invoicing'); ?></th>
1254
+                <td><?php echo $address_row; ?></td>
1255 1255
             </tr>
1256
-            <?php if ( $billing_details['phone'] ) { ?>
1256
+            <?php if ($billing_details['phone']) { ?>
1257 1257
             <tr class="wpi-receipt-phone">
1258
-                <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th>
1259
-                <td><?php echo esc_html( $billing_details['phone'] ) ;?></td>
1258
+                <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th>
1259
+                <td><?php echo esc_html($billing_details['phone']); ?></td>
1260 1260
             </tr>
1261 1261
             <?php } ?>
1262 1262
         </tbody>
@@ -1264,7 +1264,7 @@  discard block
 block discarded – undo
1264 1264
     <?php
1265 1265
     $output = ob_get_clean();
1266 1266
     
1267
-    $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id );
1267
+    $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id);
1268 1268
 
1269 1269
     echo $output;
1270 1270
 }
@@ -1272,56 +1272,56 @@  discard block
 block discarded – undo
1272 1272
 /**
1273 1273
  * Filters the receipt page.
1274 1274
  */
1275
-function wpinv_filter_success_page_content( $content ) {
1275
+function wpinv_filter_success_page_content($content) {
1276 1276
 
1277 1277
     // Ensure this is our page.
1278
-    if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) {
1278
+    if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) {
1279 1279
 
1280
-        $gateway = sanitize_text_field( $_GET['payment-confirm'] );
1281
-        return apply_filters( "wpinv_payment_confirm_$gateway", $content );
1280
+        $gateway = sanitize_text_field($_GET['payment-confirm']);
1281
+        return apply_filters("wpinv_payment_confirm_$gateway", $content);
1282 1282
 
1283 1283
     }
1284 1284
 
1285 1285
     return $content;
1286 1286
 }
1287
-add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 );
1287
+add_filter('the_content', 'wpinv_filter_success_page_content', 99999);
1288 1288
 
1289
-function wpinv_invoice_link( $invoice_id ) {
1290
-    $invoice = wpinv_get_invoice( $invoice_id );
1289
+function wpinv_invoice_link($invoice_id) {
1290
+    $invoice = wpinv_get_invoice($invoice_id);
1291 1291
 
1292
-    if ( empty( $invoice ) ) {
1292
+    if (empty($invoice)) {
1293 1293
         return NULL;
1294 1294
     }
1295 1295
 
1296
-    $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>';
1296
+    $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>';
1297 1297
 
1298
-    return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice );
1298
+    return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice);
1299 1299
 }
1300 1300
 
1301
-function wpinv_invoice_subscription_details( $invoice ) {
1302
-    if ( !empty( $invoice ) && $invoice->is_recurring() && ! wpinv_is_subscription_payment( $invoice ) ) {
1303
-        $subscription = wpinv_get_subscription( $invoice, true );
1301
+function wpinv_invoice_subscription_details($invoice) {
1302
+    if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) {
1303
+        $subscription = wpinv_get_subscription($invoice, true);
1304 1304
 
1305
-        if ( empty( $subscription ) ) {
1305
+        if (empty($subscription)) {
1306 1306
             return;
1307 1307
         }
1308 1308
 
1309 1309
         $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($subscription->period, $subscription->frequency);
1310
-        $billing = wpinv_price(wpinv_format_amount($subscription->recurring_amount), $invoice->get_currency() ) . ' / ' . $frequency;
1311
-        $initial = wpinv_price(wpinv_format_amount($subscription->initial_amount), $invoice->get_currency() );
1310
+        $billing = wpinv_price(wpinv_format_amount($subscription->recurring_amount), $invoice->get_currency()) . ' / ' . $frequency;
1311
+        $initial = wpinv_price(wpinv_format_amount($subscription->initial_amount), $invoice->get_currency());
1312 1312
 
1313 1313
         $payments = $subscription->get_child_payments();
1314 1314
         ?>
1315 1315
         <div class="wpinv-subscriptions-details">
1316
-            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3>
1316
+            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3>
1317 1317
             <table class="table">
1318 1318
                 <thead>
1319 1319
                     <tr>
1320
-                        <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th>
1321
-                        <th><?php _e( 'Start Date', 'invoicing' ) ;?></th>
1322
-                        <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th>
1323
-                        <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th>
1324
-                        <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th>
1320
+                        <th><?php _e('Billing Cycle', 'invoicing'); ?></th>
1321
+                        <th><?php _e('Start Date', 'invoicing'); ?></th>
1322
+                        <th><?php _e('Expiration Date', 'invoicing'); ?></th>
1323
+                        <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th>
1324
+                        <th class="text-center"><?php _e('Status', 'invoicing'); ?></th>
1325 1325
                     </tr>
1326 1326
                 </thead>
1327 1327
                 <tbody>
@@ -1329,35 +1329,35 @@  discard block
 block discarded – undo
1329 1329
                         <td><?php printf(_x('%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing'), $initial, $billing); ?></td>
1330 1330
                         <td><?php echo date_i18n(get_option('date_format'), strtotime($subscription->created, current_time('timestamp'))); ?></td>
1331 1331
                         <td><?php echo date_i18n(get_option('date_format'), strtotime($subscription->expiration, current_time('timestamp'))); ?></td>
1332
-                        <td class="text-center"><?php echo $subscription->get_times_billed() . ' / ' . (($subscription->bill_times == 0) ? __( 'Until Cancelled', 'invoicing' ) : $subscription->bill_times); ?></td>
1332
+                        <td class="text-center"><?php echo $subscription->get_times_billed() . ' / ' . (($subscription->bill_times == 0) ? __('Until Cancelled', 'invoicing') : $subscription->bill_times); ?></td>
1333 1333
                         <td class="text-center wpi-sub-status"><?php echo $subscription->get_status_label(); ?></td>
1334 1334
                     </tr>
1335 1335
                 </tbody>
1336 1336
             </table>
1337 1337
         </div>
1338
-        <?php if ( !empty( $payments ) ) { ?>
1338
+        <?php if (!empty($payments)) { ?>
1339 1339
         <div class="wpinv-renewal-payments">
1340
-            <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3>
1340
+            <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3>
1341 1341
             <table class="table">
1342 1342
                 <thead>
1343 1343
                     <tr>
1344 1344
                         <th>#</th>
1345
-                        <th><?php _e( 'Invoice', 'invoicing' ) ;?></th>
1346
-                        <th><?php _e( 'Date', 'invoicing' ) ;?></th>
1347
-                        <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th>
1345
+                        <th><?php _e('Invoice', 'invoicing'); ?></th>
1346
+                        <th><?php _e('Date', 'invoicing'); ?></th>
1347
+                        <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th>
1348 1348
                     </tr>
1349 1349
                 </thead>
1350 1350
                 <tbody>
1351 1351
                     <?php
1352 1352
                         $i = 1;
1353
-                        foreach ( $payments as $payment ) {
1353
+                        foreach ($payments as $payment) {
1354 1354
                             $invoice_id = $payment->ID;
1355 1355
                     ?>
1356 1356
                     <tr>
1357
-                        <th scope="row"><?php echo $i;?></th>
1358
-                        <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td>
1357
+                        <th scope="row"><?php echo $i; ?></th>
1358
+                        <td><?php echo wpinv_invoice_link($invoice_id); ?></td>
1359 1359
                         <td><?php echo$invoice->get_date_created(); ?></td>
1360
-                        <td class="text-right"><?php echo wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() ); ?></td>
1360
+                        <td class="text-right"><?php echo wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency()); ?></td>
1361 1361
                     </tr>
1362 1362
                     <?php $i++; } ?>
1363 1363
                 </tbody>
@@ -1367,64 +1367,64 @@  discard block
 block discarded – undo
1367 1367
         <?php
1368 1368
     }
1369 1369
 }
1370
-add_action( 'getpaid_invoice_line_items', 'wpinv_invoice_subscription_details', 20 );
1370
+add_action('getpaid_invoice_line_items', 'wpinv_invoice_subscription_details', 20);
1371 1371
 
1372
-function wpinv_cart_total_label( $label, $invoice ) {
1373
-    if ( empty( $invoice ) ) {
1372
+function wpinv_cart_total_label($label, $invoice) {
1373
+    if (empty($invoice)) {
1374 1374
         return $label;
1375 1375
     }
1376 1376
 
1377 1377
     $prefix_label = '';
1378
-    if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) {
1379
-        $prefix_label   = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice );
1380
-    } else if ( $invoice->is_renewal() ) {
1381
-        $prefix_label   = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> ';        
1378
+    if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) {
1379
+        $prefix_label   = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice);
1380
+    } else if ($invoice->is_renewal()) {
1381
+        $prefix_label   = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> ';        
1382 1382
     }
1383 1383
 
1384
-    if ( $prefix_label != '' ) {
1385
-        $label  = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
1384
+    if ($prefix_label != '') {
1385
+        $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
1386 1386
     }
1387 1387
 
1388 1388
     return $label;
1389 1389
 }
1390
-add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
1391
-add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
1392
-add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
1390
+add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2);
1391
+add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2);
1392
+add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2);
1393 1393
 
1394
-function wpinv_get_invoice_note_line_item( $note, $echo = true ) {
1395
-    if ( empty( $note ) ) {
1394
+function wpinv_get_invoice_note_line_item($note, $echo = true) {
1395
+    if (empty($note)) {
1396 1396
         return NULL;
1397 1397
     }
1398 1398
 
1399
-    if ( is_int( $note ) ) {
1400
-        $note = get_comment( $note );
1399
+    if (is_int($note)) {
1400
+        $note = get_comment($note);
1401 1401
     }
1402 1402
 
1403
-    if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) {
1403
+    if (!(is_object($note) && is_a($note, 'WP_Comment'))) {
1404 1404
         return NULL;
1405 1405
     }
1406 1406
 
1407
-    $note_classes   = array( 'note' );
1408
-    $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : '';
1407
+    $note_classes   = array('note');
1408
+    $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : '';
1409 1409
     $note_classes[] = $note->comment_author === 'System' ? 'system-note' : '';
1410
-    $note_classes   = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note );
1411
-    $note_classes   = !empty( $note_classes ) ? implode( ' ', $note_classes ) : '';
1410
+    $note_classes   = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note);
1411
+    $note_classes   = !empty($note_classes) ? implode(' ', $note_classes) : '';
1412 1412
 
1413 1413
     ob_start();
1414 1414
     ?>
1415
-    <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?> mt-4 pl-3 pr-3">
1415
+    <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?> mt-4 pl-3 pr-3">
1416 1416
         <div class="note_content bg-light border position-relative p-4">
1417 1417
 
1418
-            <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
1418
+            <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?>
1419 1419
 
1420
-            <?php if ( ! is_admin() ) : ?>
1420
+            <?php if (!is_admin()) : ?>
1421 1421
                 <em class="meta position-absolute form-text">
1422 1422
                     <?php
1423 1423
                         printf(
1424
-                            __( '%1$s - %2$s at %3$s', 'invoicing' ),
1424
+                            __('%1$s - %2$s at %3$s', 'invoicing'),
1425 1425
                             $note->comment_author,
1426
-                            date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ),
1427
-                            date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) )
1426
+                            date_i18n(get_option('date_format'), strtotime($note->comment_date)),
1427
+                            date_i18n(get_option('time_format'), strtotime($note->comment_date))
1428 1428
                         );
1429 1429
                     ?>
1430 1430
                 </em>
@@ -1432,12 +1432,12 @@  discard block
 block discarded – undo
1432 1432
 
1433 1433
         </div>
1434 1434
 
1435
-        <?php if ( is_admin() ) : ?>
1435
+        <?php if (is_admin()) : ?>
1436 1436
 
1437 1437
             <p class="meta px-4 py-2">
1438
-                <abbr class="exact-date" title="<?php echo esc_attr( $note->comment_date ); ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr>&nbsp;&nbsp;
1439
-                <?php if ( $note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing() ) { ?>
1440
-                    <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a>
1438
+                <abbr class="exact-date" title="<?php echo esc_attr($note->comment_date); ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr>&nbsp;&nbsp;
1439
+                <?php if ($note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing()) { ?>
1440
+                    <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a>
1441 1441
                 <?php } ?>
1442 1442
             </p>
1443 1443
 
@@ -1446,9 +1446,9 @@  discard block
 block discarded – undo
1446 1446
     </li>
1447 1447
     <?php
1448 1448
     $note_content = ob_get_clean();
1449
-    $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo );
1449
+    $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo);
1450 1450
 
1451
-    if ( $echo ) {
1451
+    if ($echo) {
1452 1452
         echo $note_content;
1453 1453
     } else {
1454 1454
         return $note_content;
@@ -1458,36 +1458,36 @@  discard block
 block discarded – undo
1458 1458
 function wpinv_invalid_invoice_content() {
1459 1459
     global $post;
1460 1460
 
1461
-    $invoice = wpinv_get_invoice( $post->ID );
1461
+    $invoice = wpinv_get_invoice($post->ID);
1462 1462
 
1463
-    $error = __( 'This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing' );
1464
-    if ( !empty( $invoice->get_id() ) && $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) {
1465
-        if ( is_user_logged_in() ) {
1466
-            if ( wpinv_require_login_to_checkout() ) {
1467
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
1468
-                    $error = __( 'You are not allowed to view this invoice.', 'invoicing' );
1463
+    $error = __('This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing');
1464
+    if (!empty($invoice->get_id()) && $invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) {
1465
+        if (is_user_logged_in()) {
1466
+            if (wpinv_require_login_to_checkout()) {
1467
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
1468
+                    $error = __('You are not allowed to view this invoice.', 'invoicing');
1469 1469
                 }
1470 1470
             }
1471 1471
         } else {
1472
-            if ( wpinv_require_login_to_checkout() ) {
1473
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
1474
-                    $error = __( 'You must be logged in to view this invoice.', 'invoicing' );
1472
+            if (wpinv_require_login_to_checkout()) {
1473
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
1474
+                    $error = __('You must be logged in to view this invoice.', 'invoicing');
1475 1475
                 }
1476 1476
             }
1477 1477
         }
1478 1478
     } else {
1479
-        $error = __( 'This invoice is deleted or does not exist.', 'invoicing' );
1479
+        $error = __('This invoice is deleted or does not exist.', 'invoicing');
1480 1480
     }
1481 1481
     ?>
1482 1482
     <div class="row wpinv-row-invalid">
1483 1483
         <div class="col-md-6 col-md-offset-3 wpinv-message error">
1484
-            <h3><?php _e( 'Access Denied', 'invoicing' ); ?></h3>
1484
+            <h3><?php _e('Access Denied', 'invoicing'); ?></h3>
1485 1485
             <p class="wpinv-msg-text"><?php echo $error; ?></p>
1486 1486
         </div>
1487 1487
     </div>
1488 1488
     <?php
1489 1489
 }
1490
-add_action( 'wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content' );
1490
+add_action('wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content');
1491 1491
 
1492 1492
 /**
1493 1493
  * Function to get privacy policy text.
@@ -1496,21 +1496,21 @@  discard block
 block discarded – undo
1496 1496
  * @return string
1497 1497
  */
1498 1498
 function wpinv_get_policy_text() {
1499
-    $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 );
1499
+    $privacy_page_id = get_option('wp_page_for_privacy_policy', 0);
1500 1500
 
1501
-    $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' ));
1501
+    $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]'));
1502 1502
 
1503
-    if(!$privacy_page_id){
1504
-        $privacy_page_id = wpinv_get_option( 'privacy_page', 0 );
1503
+    if (!$privacy_page_id) {
1504
+        $privacy_page_id = wpinv_get_option('privacy_page', 0);
1505 1505
     }
1506 1506
 
1507
-    $privacy_link    = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' );
1507
+    $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing');
1508 1508
 
1509 1509
     $find_replace = array(
1510 1510
         '[wpinv_privacy_policy]' => $privacy_link,
1511 1511
     );
1512 1512
 
1513
-    $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text );
1513
+    $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text);
1514 1514
 
1515 1515
     return wp_kses_post(wpautop($privacy_text));
1516 1516
 }
@@ -1518,21 +1518,21 @@  discard block
 block discarded – undo
1518 1518
 function wpinv_oxygen_fix_conflict() {
1519 1519
     global $ct_ignore_post_types;
1520 1520
 
1521
-    if ( ! is_array( $ct_ignore_post_types ) ) {
1521
+    if (!is_array($ct_ignore_post_types)) {
1522 1522
         $ct_ignore_post_types = array();
1523 1523
     }
1524 1524
 
1525
-    $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item' );
1525
+    $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item');
1526 1526
 
1527
-    foreach ( $post_types as $post_type ) {
1527
+    foreach ($post_types as $post_type) {
1528 1528
         $ct_ignore_post_types[] = $post_type;
1529 1529
 
1530 1530
         // Ignore post type
1531
-        add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 );
1531
+        add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999);
1532 1532
     }
1533 1533
 
1534
-    remove_filter( 'template_include', 'wpinv_template', 10, 1 );
1535
-    add_filter( 'template_include', 'wpinv_template', 999, 1 );
1534
+    remove_filter('template_include', 'wpinv_template', 10, 1);
1535
+    add_filter('template_include', 'wpinv_template', 999, 1);
1536 1536
 }
1537 1537
 
1538 1538
 /**
@@ -1540,10 +1540,10 @@  discard block
 block discarded – undo
1540 1540
  * 
1541 1541
  * @param GetPaid_Payment_Form $form
1542 1542
  */
1543
-function getpaid_display_payment_form( $form ) {
1543
+function getpaid_display_payment_form($form) {
1544 1544
 
1545
-    if ( is_numeric( $form ) ) {
1546
-        $form = new GetPaid_Payment_Form( $form );
1545
+    if (is_numeric($form)) {
1546
+        $form = new GetPaid_Payment_Form($form);
1547 1547
     }
1548 1548
 
1549 1549
     $form->display();
@@ -1553,16 +1553,16 @@  discard block
 block discarded – undo
1553 1553
 /**
1554 1554
  * Helper function to display a item payment form on the frontend.
1555 1555
  */
1556
-function getpaid_display_item_payment_form( $items ) {
1556
+function getpaid_display_item_payment_form($items) {
1557 1557
 
1558
-    $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
1559
-    $form->set_items( $items );
1558
+    $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form());
1559
+    $form->set_items($items);
1560 1560
 
1561
-    if ( 0 == count( $form->get_items() ) ) {
1561
+    if (0 == count($form->get_items())) {
1562 1562
         echo aui()->alert(
1563 1563
 			array(
1564 1564
 				'type'    => 'warning',
1565
-				'content' => __( 'No published items found', 'invoicing' ),
1565
+				'content' => __('No published items found', 'invoicing'),
1566 1566
 			)
1567 1567
         );
1568 1568
         return;
@@ -1574,75 +1574,75 @@  discard block
 block discarded – undo
1574 1574
 /**
1575 1575
  * Helper function to display an invoice payment form on the frontend.
1576 1576
  */
1577
-function getpaid_display_invoice_payment_form( $invoice_id ) {
1577
+function getpaid_display_invoice_payment_form($invoice_id) {
1578 1578
     global $invoicing;
1579 1579
 
1580
-    $invoice = wpinv_get_invoice( $invoice_id );
1580
+    $invoice = wpinv_get_invoice($invoice_id);
1581 1581
 
1582
-    if ( empty( $invoice ) ) {
1582
+    if (empty($invoice)) {
1583 1583
 		return aui()->alert(
1584 1584
 			array(
1585 1585
 				'type'    => 'warning',
1586
-				'content' => __( 'Invoice not found', 'invoicing' ),
1586
+				'content' => __('Invoice not found', 'invoicing'),
1587 1587
 			)
1588 1588
 		);
1589 1589
     }
1590 1590
 
1591
-    if ( $invoice->is_paid() ) {
1591
+    if ($invoice->is_paid()) {
1592 1592
 		return aui()->alert(
1593 1593
 			array(
1594 1594
 				'type'    => 'warning',
1595
-				'content' => __( 'Invoice has already been paid', 'invoicing' ),
1595
+				'content' => __('Invoice has already been paid', 'invoicing'),
1596 1596
 			)
1597 1597
 		);
1598 1598
     }
1599 1599
 
1600 1600
     // Get the form elements and items.
1601
-    $form     = wpinv_get_default_payment_form();
1602
-	$elements = $invoicing->form_elements->get_form_elements( $form );
1603
-	$items    = $invoicing->form_elements->convert_checkout_items( $invoice->cart_details, $invoice );
1601
+    $form = wpinv_get_default_payment_form();
1602
+	$elements = $invoicing->form_elements->get_form_elements($form);
1603
+	$items    = $invoicing->form_elements->convert_checkout_items($invoice->cart_details, $invoice);
1604 1604
 
1605 1605
 	ob_start();
1606 1606
 	echo "<form class='wpinv_payment_form'>";
1607
-	do_action( 'wpinv_payment_form_top' );
1607
+	do_action('wpinv_payment_form_top');
1608 1608
     echo "<input type='hidden' name='form_id' value='$form'/>";
1609 1609
     echo "<input type='hidden' name='invoice_id' value='$invoice_id'/>";
1610
-	wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' );
1611
-	wp_nonce_field( 'vat_validation', '_wpi_nonce' );
1610
+	wp_nonce_field('wpinv_payment_form', 'wpinv_payment_form');
1611
+	wp_nonce_field('vat_validation', '_wpi_nonce');
1612 1612
 
1613
-	foreach ( $elements as $element ) {
1614
-		do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $form );
1615
-		do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form );
1613
+	foreach ($elements as $element) {
1614
+		do_action('wpinv_frontend_render_payment_form_element', $element, $items, $form);
1615
+		do_action("wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form);
1616 1616
 	}
1617 1617
 
1618 1618
 	echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>";
1619
-	do_action( 'wpinv_payment_form_bottom' );
1619
+	do_action('wpinv_payment_form_bottom');
1620 1620
 	echo '</form>';
1621 1621
 
1622 1622
 	$content = ob_get_clean();
1623
-	return str_replace( 'sr-only', '', $content );
1623
+	return str_replace('sr-only', '', $content);
1624 1624
 }
1625 1625
 
1626 1626
 /**
1627 1627
  * Helper function to convert item string to array.
1628 1628
  */
1629
-function getpaid_convert_items_to_array( $items ) {
1630
-    $items    = array_filter( array_map( 'trim', explode( ',', $items ) ) );
1629
+function getpaid_convert_items_to_array($items) {
1630
+    $items    = array_filter(array_map('trim', explode(',', $items)));
1631 1631
     $prepared = array();
1632 1632
 
1633
-    foreach ( $items as $item ) {
1634
-        $data = array_map( 'trim', explode( '|', $item ) );
1633
+    foreach ($items as $item) {
1634
+        $data = array_map('trim', explode('|', $item));
1635 1635
 
1636
-        if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) {
1636
+        if (empty($data[0]) || !is_numeric($data[0])) {
1637 1637
             continue;
1638 1638
         }
1639 1639
 
1640 1640
         $quantity = 1;
1641
-        if ( isset( $data[1] ) && is_numeric( $data[1] ) ) {
1641
+        if (isset($data[1]) && is_numeric($data[1])) {
1642 1642
             $quantity = (int) $data[1];
1643 1643
         }
1644 1644
 
1645
-        $prepared[ $data[0] ] = $quantity;
1645
+        $prepared[$data[0]] = $quantity;
1646 1646
 
1647 1647
     }
1648 1648
 
@@ -1652,13 +1652,13 @@  discard block
 block discarded – undo
1652 1652
 /**
1653 1653
  * Helper function to convert item array to string.
1654 1654
  */
1655
-function getpaid_convert_items_to_string( $items ) {
1655
+function getpaid_convert_items_to_string($items) {
1656 1656
     $prepared = array();
1657 1657
 
1658
-    foreach ( $items as $item => $quantity ) {
1658
+    foreach ($items as $item => $quantity) {
1659 1659
         $prepared[] = "$item|$quantity";
1660 1660
     }
1661
-    return implode( ',', $prepared );
1661
+    return implode(',', $prepared);
1662 1662
 }
1663 1663
 
1664 1664
 /**
@@ -1666,22 +1666,22 @@  discard block
 block discarded – undo
1666 1666
  * 
1667 1667
  * Provide a label and one of $form, $items or $invoice.
1668 1668
  */
1669
-function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) {
1670
-    $label = sanitize_text_field( $label );
1669
+function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) {
1670
+    $label = sanitize_text_field($label);
1671 1671
     $nonce = wp_create_nonce('getpaid_ajax_form');
1672 1672
 
1673
-    if ( ! empty( $form ) ) {
1674
-        $form  = esc_attr( $form );
1673
+    if (!empty($form)) {
1674
+        $form = esc_attr($form);
1675 1675
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-form='$form'>$label</button>"; 
1676 1676
     }
1677 1677
 	
1678
-	if ( ! empty( $items ) ) {
1679
-        $items  = esc_attr( $items );
1678
+	if (!empty($items)) {
1679
+        $items = esc_attr($items);
1680 1680
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-item='$items'>$label</button>"; 
1681 1681
     }
1682 1682
     
1683
-    if ( ! empty( $invoice ) ) {
1684
-        $invoice  = esc_attr( $invoice );
1683
+    if (!empty($invoice)) {
1684
+        $invoice = esc_attr($invoice);
1685 1685
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-invoice='$invoice'>$label</button>"; 
1686 1686
     }
1687 1687
 
@@ -1692,17 +1692,17 @@  discard block
 block discarded – undo
1692 1692
  *
1693 1693
  * @param WPInv_Invoice $invoice
1694 1694
  */
1695
-function getpaid_the_invoice_description( $invoice ) {
1695
+function getpaid_the_invoice_description($invoice) {
1696 1696
     $description = $invoice->get_description();
1697 1697
 
1698
-    if ( empty( $description ) ) {
1698
+    if (empty($description)) {
1699 1699
         return;
1700 1700
     }
1701 1701
 
1702
-    $description = wp_kses_post( $description );
1702
+    $description = wp_kses_post($description);
1703 1703
     echo "<small class='getpaid-invoice-description text-dark p-2 form-text'><em>$description</em></small>";
1704 1704
 }
1705
-add_action( 'getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100 );
1705
+add_action('getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100);
1706 1706
 
1707 1707
 /**
1708 1708
  * Render element on a form.
@@ -1710,41 +1710,41 @@  discard block
 block discarded – undo
1710 1710
  * @param array $element
1711 1711
  * @param GetPaid_Payment_Form $form
1712 1712
  */
1713
-function getpaid_payment_form_element( $element, $form ) {
1713
+function getpaid_payment_form_element($element, $form) {
1714 1714
 
1715 1715
     // Set up the args.
1716
-    $element_type    = trim( $element['type'] );
1716
+    $element_type    = trim($element['type']);
1717 1717
     $element['form'] = $form;
1718
-    extract( $element );
1718
+    extract($element);
1719 1719
 
1720 1720
     // Try to locate the appropriate template.
1721
-    $located = wpinv_locate_template( "payment-forms/elements/$element_type.php" );
1721
+    $located = wpinv_locate_template("payment-forms/elements/$element_type.php");
1722 1722
     
1723 1723
     // Abort if this is not our element.
1724
-    if ( empty( $located ) || ! file_exists( $located ) ) {
1724
+    if (empty($located) || !file_exists($located)) {
1725 1725
         return;
1726 1726
     }
1727 1727
 
1728 1728
     // Generate the class and id of the element.
1729
-    $wrapper_class = 'getpaid-payment-form-element-' . trim( esc_attr( $element_type ) );
1730
-    $id            = isset( $id ) ? $id : uniqid( 'gp' );
1729
+    $wrapper_class = 'getpaid-payment-form-element-' . trim(esc_attr($element_type));
1730
+    $id            = isset($id) ? $id : uniqid('gp');
1731 1731
 
1732 1732
     // Echo the opening wrapper.
1733 1733
     echo "<div class='getpaid-payment-form-element $wrapper_class'>";
1734 1734
 
1735 1735
     // Fires before displaying a given element type's content.
1736
-    do_action( "getpaid_before_payment_form_{$element_type}_element", $element, $form );
1736
+    do_action("getpaid_before_payment_form_{$element_type}_element", $element, $form);
1737 1737
 
1738 1738
     // Include the template for the element.
1739 1739
     include $located;
1740 1740
 
1741 1741
     // Fires after displaying a given element type's content.
1742
-    do_action( "getpaid_payment_form_{$element_type}_element", $element, $form );
1742
+    do_action("getpaid_payment_form_{$element_type}_element", $element, $form);
1743 1743
 
1744 1744
     // Echo the closing wrapper.
1745 1745
     echo '</div>';
1746 1746
 }
1747
-add_action( 'getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2 );
1747
+add_action('getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2);
1748 1748
 
1749 1749
 /**
1750 1750
  * Shows a list of gateways that support recurring payments.
@@ -1752,17 +1752,17 @@  discard block
 block discarded – undo
1752 1752
 function wpinv_get_recurring_gateways_text() {
1753 1753
     $gateways = array();
1754 1754
 
1755
-    foreach ( wpinv_get_payment_gateways() as $key => $gateway ) {
1756
-        if ( wpinv_gateway_support_subscription( $key ) ) {
1757
-            $gateways[] = sanitize_text_field( $gateway['admin_label'] );
1755
+    foreach (wpinv_get_payment_gateways() as $key => $gateway) {
1756
+        if (wpinv_gateway_support_subscription($key)) {
1757
+            $gateways[] = sanitize_text_field($gateway['admin_label']);
1758 1758
         }
1759 1759
     }
1760 1760
 
1761
-    if ( empty( $gateways ) ) {
1762
-        return "<span class='form-text text-danger'>" . __( 'No active gateways support subscription payments.', 'invoicing' ) ."</span>";
1761
+    if (empty($gateways)) {
1762
+        return "<span class='form-text text-danger'>" . __('No active gateways support subscription payments.', 'invoicing') . "</span>";
1763 1763
     }
1764 1764
 
1765
-    return "<span class='form-text text-muted'>" . wp_sprintf( __( 'Subscription payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ) ."</span>";
1765
+    return "<span class='form-text text-muted'>" . wp_sprintf(__('Subscription payments only supported by: %s', 'invoicing'), implode(', ', $gateways)) . "</span>";
1766 1766
 
1767 1767
 }
1768 1768
 
@@ -1772,5 +1772,5 @@  discard block
 block discarded – undo
1772 1772
  * @return GetPaid_Template
1773 1773
  */
1774 1774
 function getpaid_template() {
1775
-    return getpaid()->get( 'template' );
1775
+    return getpaid()->get('template');
1776 1776
 }
Please login to merge, or discard this patch.
includes/class-wpinv-subscriptions.php 1 patch
Spacing   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 /**
9 9
  * Main Subscriptions class.
10 10
  *
@@ -14,22 +14,22 @@  discard block
 block discarded – undo
14 14
     /**
15 15
 	 * Class constructor.
16 16
 	 */
17
-    public function __construct(){
17
+    public function __construct() {
18 18
 
19 19
         // Fire gateway specific hooks when a subscription changes.
20
-        add_action( 'getpaid_subscription_status_changed', array( $this, 'process_subscription_status_change' ), 10, 3 );
20
+        add_action('getpaid_subscription_status_changed', array($this, 'process_subscription_status_change'), 10, 3);
21 21
 
22 22
         // Handles subscription cancelations.
23
-        add_action( 'getpaid_authenticated_action_subscription_cancel', array( $this, 'user_cancel_single_subscription' ) );
23
+        add_action('getpaid_authenticated_action_subscription_cancel', array($this, 'user_cancel_single_subscription'));
24 24
 
25 25
         // Create a subscription whenever an invoice is created, (and update it when it is updated).
26
-        add_action( 'getpaid_new_invoice', array( $this, 'maybe_create_invoice_subscription' ) );
27
-        add_action( 'getpaid_update_invoice', array( $this, 'maybe_update_invoice_subscription' ) );
26
+        add_action('getpaid_new_invoice', array($this, 'maybe_create_invoice_subscription'));
27
+        add_action('getpaid_update_invoice', array($this, 'maybe_update_invoice_subscription'));
28 28
 
29 29
         // Handles admin subscription update actions.
30
-        add_action( 'getpaid_authenticated_admin_action_update_single_subscription', array( $this, 'admin_update_single_subscription' ) );
31
-        add_action( 'getpaid_authenticated_admin_action_subscription_manual_renew', array( $this, 'admin_renew_single_subscription' ) );
32
-        add_action( 'getpaid_authenticated_admin_action_subscription_manual_delete', array( $this, 'admin_delete_single_subscription' ) );
30
+        add_action('getpaid_authenticated_admin_action_update_single_subscription', array($this, 'admin_update_single_subscription'));
31
+        add_action('getpaid_authenticated_admin_action_subscription_manual_renew', array($this, 'admin_renew_single_subscription'));
32
+        add_action('getpaid_authenticated_admin_action_subscription_manual_delete', array($this, 'admin_delete_single_subscription'));
33 33
     }
34 34
 
35 35
     /**
@@ -39,15 +39,15 @@  discard block
 block discarded – undo
39 39
      * @param string $from
40 40
      * @param string $to
41 41
 	 */
42
-    public function process_subscription_status_change( $subscription, $from, $to ) {
42
+    public function process_subscription_status_change($subscription, $from, $to) {
43 43
 
44 44
         $gateway = $subscription->get_gateway();
45 45
 
46
-        if ( ! empty( $gateway ) ) {
47
-            $gateway = sanitize_key( $gateway );
48
-            $from    = sanitize_key( $from );
49
-            $to      = sanitize_key( $to );
50
-            do_action( "getpaid_{$gateway}subscription_$to", $subscription, $from );
46
+        if (!empty($gateway)) {
47
+            $gateway = sanitize_key($gateway);
48
+            $from    = sanitize_key($from);
49
+            $to      = sanitize_key($to);
50
+            do_action("getpaid_{$gateway}subscription_$to", $subscription, $from);
51 51
         }
52 52
 
53 53
     }
@@ -59,29 +59,29 @@  discard block
 block discarded – undo
59 59
      * @param int $frequency_count The frequency of the period.
60 60
      * @return mixed|string|void
61 61
      */
62
-    public static function wpinv_get_pretty_subscription_frequency( $period, $frequency_count = 1) {
62
+    public static function wpinv_get_pretty_subscription_frequency($period, $frequency_count = 1) {
63 63
 
64 64
         $frequency = '';
65 65
         //Format period details
66
-        switch ( strtolower( $period ) ) {
66
+        switch (strtolower($period)) {
67 67
             case 'day' :
68 68
             case 'd' :
69
-                $frequency = sprintf( _n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count);
69
+                $frequency = sprintf(_n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count);
70 70
                 break;
71 71
             case 'week' :
72 72
             case 'w' :
73
-                $frequency = sprintf( _n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count);
73
+                $frequency = sprintf(_n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count);
74 74
                 break;
75 75
             case 'month' :
76 76
             case 'm' :
77
-                $frequency = sprintf( _n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count);
77
+                $frequency = sprintf(_n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count);
78 78
                 break;
79 79
             case 'year' :
80 80
             case 'y' :
81
-                $frequency = sprintf( _n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count);
81
+                $frequency = sprintf(_n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count);
82 82
                 break;
83 83
             default :
84
-                $frequency = apply_filters( 'wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count );
84
+                $frequency = apply_filters('wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count);
85 85
                 break;
86 86
         }
87 87
 
@@ -96,29 +96,29 @@  discard block
 block discarded – undo
96 96
      * @since       1.0.0
97 97
      * @return      void
98 98
      */
99
-    public function user_cancel_single_subscription( $data ) {
99
+    public function user_cancel_single_subscription($data) {
100 100
 
101 101
         // Ensure there is a subscription to cancel.
102
-        if ( empty( $data['sub_id'] ) ) {
102
+        if (empty($data['sub_id'])) {
103 103
             return;
104 104
         }
105 105
 
106
-        $subscription = new WPInv_Subscription( (int) $data['sub_id'] );
106
+        $subscription = new WPInv_Subscription((int) $data['sub_id']);
107 107
 
108 108
         // Ensure that it exists and that it belongs to the current user.
109
-        if ( ! $subscription->get_id() || $subscription->get_customer_id() != get_current_user_id() ) {
110
-            wpinv_set_error( 'invalid_subscription', __( 'You do not have permission to cancel this subscription', 'invoicing' ) );
109
+        if (!$subscription->get_id() || $subscription->get_customer_id() != get_current_user_id()) {
110
+            wpinv_set_error('invalid_subscription', __('You do not have permission to cancel this subscription', 'invoicing'));
111 111
 
112 112
         // Can it be cancelled.
113
-        } else if ( ! $subscription->can_cancel() ) {
114
-            wpinv_set_error( 'cannot_cancel', __( 'This subscription cannot be cancelled as it is not active.', 'invoicing' ) );
113
+        } else if (!$subscription->can_cancel()) {
114
+            wpinv_set_error('cannot_cancel', __('This subscription cannot be cancelled as it is not active.', 'invoicing'));
115 115
             
116 116
 
117 117
         // Cancel it.
118 118
         } else {
119 119
 
120 120
             $subscription->cancel();
121
-            wpinv_set_error( 'cancelled', __( 'This subscription is now cancelled.', 'invoicing' ), 'info' );
121
+            wpinv_set_error('cancelled', __('This subscription is now cancelled.', 'invoicing'), 'info');
122 122
         }
123 123
 
124 124
 
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
             )
131 131
         );
132 132
 
133
-        wp_safe_redirect( esc_url( $redirect ) );
133
+        wp_safe_redirect(esc_url($redirect));
134 134
         exit;
135 135
 
136 136
     }
@@ -142,15 +142,15 @@  discard block
 block discarded – undo
142 142
      * @param       WPInv_Invoice $invoice
143 143
      * @since       1.0.0
144 144
      */
145
-    public function maybe_create_invoice_subscription( $invoice ) {
145
+    public function maybe_create_invoice_subscription($invoice) {
146 146
 
147 147
         // Abort if it is not recurring.
148
-        if ( $invoice->is_free() || ! $invoice->is_recurring() || $invoice->is_renewal() ) {
148
+        if ($invoice->is_free() || !$invoice->is_recurring() || $invoice->is_renewal()) {
149 149
             return;
150 150
         }
151 151
 
152 152
         $subscription = new WPInv_Subscription();
153
-        return $this->update_invoice_subscription( $subscription, $invoice );
153
+        return $this->update_invoice_subscription($subscription, $invoice);
154 154
 
155 155
     }
156 156
 
@@ -161,33 +161,33 @@  discard block
 block discarded – undo
161 161
      * @param       WPInv_Invoice $invoice
162 162
      * @since       1.0.19
163 163
      */
164
-    public function maybe_update_invoice_subscription( $invoice ) {
164
+    public function maybe_update_invoice_subscription($invoice) {
165 165
 
166 166
         // Do not process renewals.
167
-        if ( $invoice->is_renewal() ) {
167
+        if ($invoice->is_renewal()) {
168 168
             return;
169 169
         }
170 170
 
171 171
         // (Maybe) create a new subscription.
172
-        if ( ! $invoice->get_subscription_id() ) {
173
-            return $this->maybe_create_invoice_subscription( $invoice );
172
+        if (!$invoice->get_subscription_id()) {
173
+            return $this->maybe_create_invoice_subscription($invoice);
174 174
         }
175 175
 
176
-        $subscription = new WPInv_Subscription( $invoice->get_subscription_id() );
176
+        $subscription = new WPInv_Subscription($invoice->get_subscription_id());
177 177
 
178 178
         // In case the subscription was deleted...
179
-        if ( ! $subscription->get_id() ) {
179
+        if (!$subscription->get_id()) {
180 180
             $invoice->set_subscription_id(0);
181 181
             $invoice->save();
182
-            return $this->maybe_create_invoice_subscription( $invoice );
182
+            return $this->maybe_create_invoice_subscription($invoice);
183 183
         }
184 184
 
185 185
         // Abort if an invoice is paid and already has a subscription.
186
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
186
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
187 187
             return;
188 188
         }
189 189
 
190
-        return $this->update_invoice_subscription( $subscription, $invoice );
190
+        return $this->update_invoice_subscription($subscription, $invoice);
191 191
 
192 192
     }
193 193
 
@@ -199,53 +199,53 @@  discard block
 block discarded – undo
199 199
      * @param       WPInv_Invoice $invoice
200 200
      * @since       1.0.19
201 201
      */
202
-    public function update_invoice_subscription( $subscription, $invoice ) {
202
+    public function update_invoice_subscription($subscription, $invoice) {
203 203
 
204 204
         // Delete the subscription if an invoice is free.
205
-        if ( $invoice->is_free() || ! $invoice->is_recurring() ) {
205
+        if ($invoice->is_free() || !$invoice->is_recurring()) {
206 206
             return $subscription->delete();
207 207
         }
208 208
 
209
-        $subscription->set_customer_id( $invoice->get_customer_id() );
210
-        $subscription->set_parent_invoice_id( $invoice->get_id() );
211
-        $subscription->set_initial_amount( $invoice->get_initial_total() );
212
-        $subscription->set_recurring_amount( $invoice->get_recurring_total() );
213
-        $subscription->set_date_created( current_time( 'mysql' ) );
214
-        $subscription->set_status( $invoice->is_paid() ? 'active' : 'pending' );
209
+        $subscription->set_customer_id($invoice->get_customer_id());
210
+        $subscription->set_parent_invoice_id($invoice->get_id());
211
+        $subscription->set_initial_amount($invoice->get_initial_total());
212
+        $subscription->set_recurring_amount($invoice->get_recurring_total());
213
+        $subscription->set_date_created(current_time('mysql'));
214
+        $subscription->set_status($invoice->is_paid() ? 'active' : 'pending');
215 215
 
216 216
         // Get the recurring item and abort if it does not exist.
217
-        $subscription_item = $invoice->get_recurring( true );
218
-        if ( ! $subscription_item->get_id() ) {
217
+        $subscription_item = $invoice->get_recurring(true);
218
+        if (!$subscription_item->get_id()) {
219 219
             return $subscription->delete();
220 220
         }
221 221
 
222
-        $subscription->set_product_id( $subscription_item->get_id() );
223
-        $subscription->set_period( $subscription_item->get_recurring_period( true ) );
224
-        $subscription->set_frequency( $subscription_item->get_recurring_interval() );
225
-        $subscription->set_bill_times( $subscription_item->get_recurring_limit() );
222
+        $subscription->set_product_id($subscription_item->get_id());
223
+        $subscription->set_period($subscription_item->get_recurring_period(true));
224
+        $subscription->set_frequency($subscription_item->get_recurring_interval());
225
+        $subscription->set_bill_times($subscription_item->get_recurring_limit());
226 226
 
227 227
         // Calculate the next renewal date.
228
-        $period       = $subscription_item->get_recurring_period( true );
228
+        $period       = $subscription_item->get_recurring_period(true);
229 229
         $interval     = $subscription_item->get_recurring_interval();
230 230
 
231 231
         // If the subscription item has a trial period...
232
-        if ( $subscription_item->has_free_trial() ) {
233
-            $period   = $subscription_item->get_trial_period( true );
232
+        if ($subscription_item->has_free_trial()) {
233
+            $period   = $subscription_item->get_trial_period(true);
234 234
             $interval = $subscription_item->get_trial_interval();
235
-            $subscription->set_trial_period( $interval . ' ' . $period );
236
-            $subscription->set_status( 'trialling' );
235
+            $subscription->set_trial_period($interval . ' ' . $period);
236
+            $subscription->set_status('trialling');
237 237
         }
238 238
 
239 239
         // If initial amount is free, treat it as a free trial even if the subscription item does not have a free trial.
240
-        if ( $invoice->has_free_trial() ) {
241
-            $subscription->set_trial_period( $interval . ' ' . $period );
242
-            $subscription->set_status( 'trialling' );
240
+        if ($invoice->has_free_trial()) {
241
+            $subscription->set_trial_period($interval . ' ' . $period);
242
+            $subscription->set_status('trialling');
243 243
         }
244 244
 
245 245
         // Calculate the next renewal date.
246
-        $expiration = date( 'Y-m-d H:i:s', strtotime( "+ $interval $period", strtotime( $subscription->get_date_created() ) ) );
246
+        $expiration = date('Y-m-d H:i:s', strtotime("+ $interval $period", strtotime($subscription->get_date_created())));
247 247
 
248
-        $subscription->set_next_renewal_date( $expiration );
248
+        $subscription->set_next_renewal_date($expiration);
249 249
         return $subscription->save();
250 250
 
251 251
     }
@@ -256,21 +256,21 @@  discard block
 block discarded – undo
256 256
      * @param       array $data
257 257
      * @since       1.0.19
258 258
      */
259
-    public function admin_update_single_subscription( $args ) {
259
+    public function admin_update_single_subscription($args) {
260 260
 
261 261
         // Ensure the subscription exists and that a status has been given.
262
-        if ( empty( $args['subscription_id'] ) || empty( $args['subscription_status'] ) ) {
262
+        if (empty($args['subscription_id']) || empty($args['subscription_status'])) {
263 263
             return;
264 264
         }
265 265
 
266 266
         // Retrieve the subscriptions.
267
-        $subscription = new WPInv_Subscription( $args['subscription_id'] );
267
+        $subscription = new WPInv_Subscription($args['subscription_id']);
268 268
 
269
-        if ( $subscription->get_id() ) {
269
+        if ($subscription->get_id()) {
270 270
 
271
-            $subscription->set_status( $args['subscription_status'] );
271
+            $subscription->set_status($args['subscription_status']);
272 272
             $subscription->save();
273
-            getpaid_admin()->show_info( __( 'Your changes have been saved', 'invoicing' ) );
273
+            getpaid_admin()->show_info(__('Your changes have been saved', 'invoicing'));
274 274
 
275 275
         }
276 276
 
@@ -282,25 +282,25 @@  discard block
 block discarded – undo
282 282
      * @param       array $data
283 283
      * @since       1.0.19
284 284
      */
285
-    public function admin_renew_single_subscription( $args ) {
285
+    public function admin_renew_single_subscription($args) {
286 286
 
287 287
         // Ensure the subscription exists and that a status has been given.
288
-        if ( empty( $args['id'] ) ) {
288
+        if (empty($args['id'])) {
289 289
             return;
290 290
         }
291 291
 
292 292
         // Retrieve the subscriptions.
293
-        $subscription = new WPInv_Subscription( $args['id'] );
293
+        $subscription = new WPInv_Subscription($args['id']);
294 294
 
295
-        if ( $subscription->get_id() ) {
295
+        if ($subscription->get_id()) {
296 296
 
297
-            $args = array( 'transaction_id', $subscription->get_parent_invoice()->generate_key( 'renewal_' ) );
297
+            $args = array('transaction_id', $subscription->get_parent_invoice()->generate_key('renewal_'));
298 298
 
299
-            if ( $subscription->add_payment( $args ) ) {
299
+            if ($subscription->add_payment($args)) {
300 300
                 $subscription->renew();
301
-                getpaid_admin()->show_info( __( 'This subscription has been renewed and extended.', 'invoicing' ) );
301
+                getpaid_admin()->show_info(__('This subscription has been renewed and extended.', 'invoicing'));
302 302
             } else {
303
-                getpaid_admin()->show_error( __( 'We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing' ) );
303
+                getpaid_admin()->show_error(__('We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing'));
304 304
             }
305 305
     
306 306
             wp_safe_redirect(
@@ -323,20 +323,20 @@  discard block
 block discarded – undo
323 323
      * @param       array $data
324 324
      * @since       1.0.19
325 325
      */
326
-    public function admin_delete_single_subscription( $args ) {
326
+    public function admin_delete_single_subscription($args) {
327 327
 
328 328
         // Ensure the subscription exists and that a status has been given.
329
-        if ( empty( $args['id'] ) ) {
329
+        if (empty($args['id'])) {
330 330
             return;
331 331
         }
332 332
 
333 333
         // Retrieve the subscriptions.
334
-        $subscription = new WPInv_Subscription( $args['id'] );
334
+        $subscription = new WPInv_Subscription($args['id']);
335 335
 
336
-        if ( $subscription->delete() ) {
337
-            getpaid_admin()->show_info( __( 'This subscription has been deleted.', 'invoicing' ) );
336
+        if ($subscription->delete()) {
337
+            getpaid_admin()->show_info(__('This subscription has been deleted.', 'invoicing'));
338 338
         } else {
339
-            getpaid_admin()->show_error( __( 'We are unable to delete this subscription. Please try again.', 'invoicing' ) );
339
+            getpaid_admin()->show_error(__('We are unable to delete this subscription. Please try again.', 'invoicing'));
340 340
         }
341 341
     
342 342
         wp_safe_redirect(
Please login to merge, or discard this patch.
templates/wpinv-subscriptions-history.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 global $wpdb;
14 14
 
15 15
 $db = new WPInv_Subscriptions_DB;
16
-$page = isset($_GET['cpage']) ? abs((int)$_GET['cpage']) : 1;
16
+$page = isset($_GET['cpage']) ? abs((int) $_GET['cpage']) : 1;
17 17
 $items_per_page = get_option('posts_per_page');
18 18
 $offset = ($page * $items_per_page) - $items_per_page;
19 19
 $args = array('customer_id' => $user_id, 'offset' => $offset);
@@ -30,16 +30,16 @@  discard block
 block discarded – undo
30 30
     <table class="table table-bordered table-hover table-responsive wpi-user-subscriptions">
31 31
         <thead>
32 32
         <tr>
33
-            <th class="sub-no"><span class="nobr"><?php _e( 'No.', 'invoicing' ); ?></span></th>
34
-            <th class="sub-amount"><span class="nobr"><?php _e( 'Initial Amount', 'invoicing' ); ?></span></th>
35
-            <th class="sub-cycle"><span class="nobr"><?php _e( 'Billing Cycle', 'invoicing' ); ?></span></th>
36
-            <th class="sub-billed"><span class="nobr"><?php _e( 'Times Billed', 'invoicing' ); ?></span></th>
37
-            <th class="sub-status"><span class="nobr"><?php _e( 'Status', 'invoicing' ); ?></span></th>
38
-            <th class="sub-invoice"><span class="nobr"><?php _e( 'Invoice', 'invoicing' ); ?></span></th>
39
-            <th class="sub-item"><span class="nobr"><?php _e( 'Item', 'invoicing' ); ?></span></th>
40
-            <th class="sub-gateway"><span class="nobr"><?php _e( 'Gateway', 'invoicing' ); ?></span></th>
41
-            <th class="sub-expiry"><span class="nobr"><?php _e( 'Expires On', 'invoicing' ); ?></span></th>
42
-            <th class="sub-actions"><span class="nobr"><?php _e( 'Actions', 'invoicing' ); ?></span></th>
33
+            <th class="sub-no"><span class="nobr"><?php _e('No.', 'invoicing'); ?></span></th>
34
+            <th class="sub-amount"><span class="nobr"><?php _e('Initial Amount', 'invoicing'); ?></span></th>
35
+            <th class="sub-cycle"><span class="nobr"><?php _e('Billing Cycle', 'invoicing'); ?></span></th>
36
+            <th class="sub-billed"><span class="nobr"><?php _e('Times Billed', 'invoicing'); ?></span></th>
37
+            <th class="sub-status"><span class="nobr"><?php _e('Status', 'invoicing'); ?></span></th>
38
+            <th class="sub-invoice"><span class="nobr"><?php _e('Invoice', 'invoicing'); ?></span></th>
39
+            <th class="sub-item"><span class="nobr"><?php _e('Item', 'invoicing'); ?></span></th>
40
+            <th class="sub-gateway"><span class="nobr"><?php _e('Gateway', 'invoicing'); ?></span></th>
41
+            <th class="sub-expiry"><span class="nobr"><?php _e('Expires On', 'invoicing'); ?></span></th>
42
+            <th class="sub-actions"><span class="nobr"><?php _e('Actions', 'invoicing'); ?></span></th>
43 43
         </tr>
44 44
         </thead>
45 45
 
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
                     $initial = wpinv_price(wpinv_format_amount($sub->initial_amount), wpinv_get_invoice_currency_code($sub->parent_payment_id));
58 58
                     printf(_x('%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing'), $initial, $billing); ?>
59 59
                 </td>
60
-                <td><?php echo $sub->get_times_billed() . ' / ' . (($sub->bill_times == 0) ? __( 'Until Cancelled', 'invoicing' ) : $sub->bill_times); ?></td>
60
+                <td><?php echo $sub->get_times_billed() . ' / ' . (($sub->bill_times == 0) ? __('Until Cancelled', 'invoicing') : $sub->bill_times); ?></td>
61 61
                 <td><?php echo $sub->get_status_label_html(); ?></td>
62 62
                 <td><a href="<?php echo get_permalink($invoice); ?>" target="_blank">#<?php echo $invoice; ?></a></td>
63 63
                 <td><?php echo get_the_title($sub->product_id); ?></td>
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
                 <td><?php echo date_i18n(get_option('date_format'), strtotime($sub->expiration, current_time('timestamp'))); ?></td>
66 66
                 <td><?php
67 67
                     if ($sub->can_cancel()) {
68
-                        $message = esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' );
68
+                        $message = esc_attr__('Are you sure you want to cancel this subscription?', 'invoicing');
69 69
                         echo '<a class="btn btn-sm btn-primary" onclick="return confirm(\'' . $message . '\')" href="' . $sub->get_cancel_url() . '" >' . __("Cancel", "invoicing") . '</a>';
70 70
                     }
71 71
                     do_action('wpinv_subscription_item_actions', $sub);
Please login to merge, or discard this patch.