Passed
Pull Request — master (#518)
by
unknown
06:06
created
includes/invoice-functions.php 2 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
  * Checks if the current user cna view an invoice receipt.
68 68
  */
69 69
 function wpinv_can_view_receipt( $invoice ) {
70
-	return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice );
70
+    return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice );
71 71
 }
72 72
 
73 73
 /**
@@ -1215,8 +1215,8 @@  discard block
 block discarded – undo
1215 1215
         $subscription = wpinv_get_subscription( $invoice );
1216 1216
 
1217 1217
         // Check is it one time payment
1218
-		$item = new WPInv_Item( $subscription->get_product_id() );
1219
-		$is_one_time_payment = $item->is_one_time_recurring();
1218
+        $item = new WPInv_Item( $subscription->get_product_id() );
1219
+        $is_one_time_payment = $item->is_one_time_recurring();
1220 1220
         
1221 1221
         if ( ! empty ( $subscription ) ) {
1222 1222
 
@@ -1269,21 +1269,21 @@  discard block
 block discarded – undo
1269 1269
  */
1270 1270
 function getpaid_get_invoice_status_classes() {
1271 1271
 
1272
-	return apply_filters(
1273
-		'getpaid_get_invoice_status_classes',
1274
-		array(
1272
+    return apply_filters(
1273
+        'getpaid_get_invoice_status_classes',
1274
+        array(
1275 1275
             'wpi-quote-declined' => 'badge-danger',
1276 1276
             'wpi-failed'         => 'badge-danger',
1277
-			'wpi-processing'     => 'badge-info',
1278
-			'wpi-onhold'         => 'badge-warning',
1279
-			'wpi-quote-accepted' => 'badge-success',
1280
-			'publish'            => 'badge-success',
1281
-			'wpi-renewal'        => 'badge-primary',
1277
+            'wpi-processing'     => 'badge-info',
1278
+            'wpi-onhold'         => 'badge-warning',
1279
+            'wpi-quote-accepted' => 'badge-success',
1280
+            'publish'            => 'badge-success',
1281
+            'wpi-renewal'        => 'badge-primary',
1282 1282
             'wpi-cancelled'      => 'badge-secondary',
1283 1283
             'wpi-pending'        => 'badge-dark',
1284 1284
             'wpi-quote-pending'  => 'badge-dark',
1285 1285
             'wpi-refunded'       => 'badge-secondary',
1286
-		)
1287
-	);
1286
+        )
1287
+    );
1288 1288
 
1289 1289
 }
Please login to merge, or discard this patch.
Spacing   +349 added lines, -349 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
  * Retrieves the current invoice.
@@ -14,15 +14,15 @@  discard block
 block discarded – undo
14 14
 function getpaid_get_current_invoice_id() {
15 15
 
16 16
     // Ensure that we have an invoice key.
17
-    if ( empty( $_GET['invoice_key'] ) ) {
17
+    if (empty($_GET['invoice_key'])) {
18 18
         return 0;
19 19
     }
20 20
 
21 21
     // Retrieve an invoice using the key.
22
-    $invoice = new WPInv_Invoice( $_GET['invoice_key'] );
22
+    $invoice = new WPInv_Invoice($_GET['invoice_key']);
23 23
 
24 24
     // Compare the invoice key and the parsed key.
25
-    if ( $invoice->get_id() != 0 && $invoice->get_key() == $_GET['invoice_key'] ) {
25
+    if ($invoice->get_id() != 0 && $invoice->get_key() == $_GET['invoice_key']) {
26 26
         return $invoice->get_id();
27 27
     }
28 28
 
@@ -32,42 +32,42 @@  discard block
 block discarded – undo
32 32
 /**
33 33
  * Checks if the current user cna view an invoice.
34 34
  */
35
-function wpinv_user_can_view_invoice( $invoice ) {
36
-    $invoice = new WPInv_Invoice( $invoice );
35
+function wpinv_user_can_view_invoice($invoice) {
36
+    $invoice = new WPInv_Invoice($invoice);
37 37
 
38 38
     // Abort if the invoice does not exist.
39
-    if ( 0 == $invoice->get_id() ) {
39
+    if (0 == $invoice->get_id()) {
40 40
         return false;
41 41
     }
42 42
 
43 43
     // Don't allow trash, draft status
44
-    if ( $invoice->is_draft() ) {
44
+    if ($invoice->is_draft()) {
45 45
         return false;
46 46
     }
47 47
 
48 48
     // If users are not required to login to check out, compare the invoice keys.
49
-    if ( ! wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && trim( $_GET['invoice_key'] ) == $invoice->get_key() ) {
49
+    if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && trim($_GET['invoice_key']) == $invoice->get_key()) {
50 50
         return true;
51 51
     }
52 52
 
53 53
     // Always enable for admins..
54
-    if ( wpinv_current_user_can_manage_invoicing() || current_user_can( 'view_invoices', $invoice->get_id() ) ) { // Admin user
54
+    if (wpinv_current_user_can_manage_invoicing() || current_user_can('view_invoices', $invoice->get_id())) { // Admin user
55 55
         return true;
56 56
     }
57 57
 
58 58
     // Else, ensure that this is their invoice.
59
-    if ( is_user_logged_in() && $invoice->get_user_id() == get_current_user_id() ) {
59
+    if (is_user_logged_in() && $invoice->get_user_id() == get_current_user_id()) {
60 60
         return true;
61 61
     }
62 62
 
63
-    return apply_filters( 'wpinv_current_user_can_view_invoice', false, $invoice );
63
+    return apply_filters('wpinv_current_user_can_view_invoice', false, $invoice);
64 64
 }
65 65
 
66 66
 /**
67 67
  * Checks if the current user cna view an invoice receipt.
68 68
  */
69
-function wpinv_can_view_receipt( $invoice ) {
70
-	return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice );
69
+function wpinv_can_view_receipt($invoice) {
70
+	return (bool) apply_filters('wpinv_can_view_receipt', wpinv_user_can_view_invoice($invoice), $invoice);
71 71
 }
72 72
 
73 73
 /**
@@ -77,11 +77,11 @@  discard block
 block discarded – undo
77 77
  */
78 78
 function getpaid_get_invoice_post_types() {
79 79
     $post_types = array(
80
-        'wpi_quote'   => __( 'Quote', 'invoicing' ),
81
-        'wpi_invoice' => __( 'Invoice', 'invoicing' ),
80
+        'wpi_quote'   => __('Quote', 'invoicing'),
81
+        'wpi_invoice' => __('Invoice', 'invoicing'),
82 82
     );
83 83
 
84
-    return apply_filters( 'getpaid_invoice_post_types', $post_types );
84
+    return apply_filters('getpaid_invoice_post_types', $post_types);
85 85
 }
86 86
 
87 87
 /**
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
  * 
91 91
  * @param string $post_type The post type to check for.
92 92
  */
93
-function getpaid_is_invoice_post_type( $post_type ) {
94
-    return is_scalar( $post_type ) && ! empty( $post_type ) && array_key_exists( $post_type, getpaid_get_invoice_post_types() );
93
+function getpaid_is_invoice_post_type($post_type) {
94
+    return is_scalar($post_type) && !empty($post_type) && array_key_exists($post_type, getpaid_get_invoice_post_types());
95 95
 }
96 96
 
97 97
 /**
@@ -101,9 +101,9 @@  discard block
 block discarded – undo
101 101
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
102 102
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
103 103
  */
104
-function wpinv_create_invoice( $data = array(), $deprecated = null, $wp_error = false ) {
105
-    $data[ 'invoice_id' ] = 0;
106
-    return wpinv_insert_invoice( $data, $wp_error );
104
+function wpinv_create_invoice($data = array(), $deprecated = null, $wp_error = false) {
105
+    $data['invoice_id'] = 0;
106
+    return wpinv_insert_invoice($data, $wp_error);
107 107
 }
108 108
 
109 109
 /**
@@ -113,36 +113,36 @@  discard block
 block discarded – undo
113 113
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
114 114
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
115 115
  */
116
-function wpinv_update_invoice( $data = array(), $wp_error = false ) {
116
+function wpinv_update_invoice($data = array(), $wp_error = false) {
117 117
 
118 118
     // Backwards compatibility.
119
-    if ( ! empty( $data['ID'] ) ) {
119
+    if (!empty($data['ID'])) {
120 120
         $data['invoice_id'] = $data['ID'];
121 121
     }
122 122
 
123 123
     // Do we have an invoice id?
124
-    if ( empty( $data['invoice_id'] ) ) {
125
-        return $wp_error ? new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) ) : 0;
124
+    if (empty($data['invoice_id'])) {
125
+        return $wp_error ? new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing')) : 0;
126 126
     }
127 127
 
128 128
     // Retrieve the invoice.
129
-    $invoice = wpinv_get_invoice( $data['invoice_id'] );
129
+    $invoice = wpinv_get_invoice($data['invoice_id']);
130 130
 
131 131
     // And abort if it does not exist.
132
-    if ( empty( $invoice ) ) {
133
-        return $wp_error ? new WP_Error( 'missing_invoice', __( 'Invoice not found.', 'invoicing' ) ) : 0;
132
+    if (empty($invoice)) {
133
+        return $wp_error ? new WP_Error('missing_invoice', __('Invoice not found.', 'invoicing')) : 0;
134 134
     }
135 135
 
136 136
     // Do not update totals for paid / refunded invoices.
137
-    if ( $invoice->is_paid() || $invoice->is_refunded() ) {
137
+    if ($invoice->is_paid() || $invoice->is_refunded()) {
138 138
 
139
-        if ( ! empty( $data['items'] ) || ! empty( $data['cart_details'] ) ) {
140
-            return $wp_error ? new WP_Error( 'paid_invoice', __( 'You can not update cart items for invoices that have already been paid for.', 'invoicing' ) ) : 0;
139
+        if (!empty($data['items']) || !empty($data['cart_details'])) {
140
+            return $wp_error ? new WP_Error('paid_invoice', __('You can not update cart items for invoices that have already been paid for.', 'invoicing')) : 0;
141 141
         }
142 142
 
143 143
     }
144 144
 
145
-    return wpinv_insert_invoice( $data, $wp_error );
145
+    return wpinv_insert_invoice($data, $wp_error);
146 146
 
147 147
 }
148 148
 
@@ -153,34 +153,34 @@  discard block
 block discarded – undo
153 153
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
154 154
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
155 155
  */
156
-function wpinv_insert_invoice( $data = array(), $wp_error = false ) {
156
+function wpinv_insert_invoice($data = array(), $wp_error = false) {
157 157
 
158 158
     // Ensure that we have invoice data.
159
-    if ( empty( $data ) ) {
159
+    if (empty($data)) {
160 160
         return false;
161 161
     }
162 162
 
163 163
     // The invoice id will be provided when updating an invoice.
164
-    $data['invoice_id'] = ! empty( $data['invoice_id'] ) ? (int) $data['invoice_id'] : false;
164
+    $data['invoice_id'] = !empty($data['invoice_id']) ? (int) $data['invoice_id'] : false;
165 165
 
166 166
     // Retrieve the invoice.
167
-    $invoice = new WPInv_Invoice( $data['invoice_id'] );
167
+    $invoice = new WPInv_Invoice($data['invoice_id']);
168 168
 
169 169
     // Do we have an error?
170
-    if ( ! empty( $invoice->last_error ) ) {
171
-        return $wp_error ? new WP_Error( 'invalid_invoice_id', $invoice->last_error ) : 0;
170
+    if (!empty($invoice->last_error)) {
171
+        return $wp_error ? new WP_Error('invalid_invoice_id', $invoice->last_error) : 0;
172 172
     }
173 173
 
174 174
     // Backwards compatibility (billing address).
175
-    if ( ! empty( $data['user_info'] ) ) {
175
+    if (!empty($data['user_info'])) {
176 176
 
177
-        foreach ( $data['user_info'] as $key => $value ) {
177
+        foreach ($data['user_info'] as $key => $value) {
178 178
 
179
-            if ( $key == 'discounts' ) {
179
+            if ($key == 'discounts') {
180 180
                 $value = (array) $value;
181
-                $data[ 'discount_code' ] = empty( $value ) ? null : $value[0];
181
+                $data['discount_code'] = empty($value) ? null : $value[0];
182 182
             } else {
183
-                $data[ $key ] = $value;
183
+                $data[$key] = $value;
184 184
             }
185 185
 
186 186
         }
@@ -188,30 +188,30 @@  discard block
 block discarded – undo
188 188
     }
189 189
 
190 190
     // Backwards compatibility.
191
-    if ( ! empty( $data['payment_details'] ) ) {
191
+    if (!empty($data['payment_details'])) {
192 192
 
193
-        foreach ( $data['payment_details'] as $key => $value ) {
194
-            $data[ $key ] = $value;
193
+        foreach ($data['payment_details'] as $key => $value) {
194
+            $data[$key] = $value;
195 195
         }
196 196
 
197 197
     }
198 198
 
199 199
     // Set up the owner of the invoice.
200
-    $user_id = ! empty( $data['user_id'] ) ? wpinv_clean( $data['user_id'] ) : get_current_user_id();
200
+    $user_id = !empty($data['user_id']) ? wpinv_clean($data['user_id']) : get_current_user_id();
201 201
 
202 202
     // Make sure the user exists.
203
-    if ( ! get_userdata( $user_id ) ) {
204
-        return $wp_error ? new WP_Error( 'wpinv_invalid_user', __( 'There is no user with that ID.', 'invoicing' ) ) : 0;
203
+    if (!get_userdata($user_id)) {
204
+        return $wp_error ? new WP_Error('wpinv_invalid_user', __('There is no user with that ID.', 'invoicing')) : 0;
205 205
     }
206 206
 
207
-    $address = wpinv_get_user_address( $user_id );
207
+    $address = wpinv_get_user_address($user_id);
208 208
 
209
-    foreach ( $address as $key => $value ) {
209
+    foreach ($address as $key => $value) {
210 210
 
211
-        if ( $value == '' ) {
212
-            $address[ $key ] = null;
211
+        if ($value == '') {
212
+            $address[$key] = null;
213 213
         } else {
214
-            $address[ $key ] = wpinv_clean( $value );
214
+            $address[$key] = wpinv_clean($value);
215 215
         }
216 216
 
217 217
     }
@@ -222,103 +222,103 @@  discard block
 block discarded – undo
222 222
         array(
223 223
 
224 224
             // Basic info.
225
-            'template'             => isset( $data['template'] ) ? wpinv_clean( $data['template'] ) : null,
226
-            'email_cc'             => isset( $data['email_cc'] ) ? wpinv_clean( $data['email_cc'] ) : null,
227
-            'date_created'         => isset( $data['created_date'] ) ? wpinv_clean( $data['created_date'] ) : null,
228
-            'due_date'             => isset( $data['due_date'] ) ? wpinv_clean( $data['due_date'] ) : null,
229
-            'date_completed'       => isset( $data['date_completed'] ) ? wpinv_clean( $data['date_completed'] ) : null,
230
-            'number'               => isset( $data['number'] ) ? wpinv_clean( $data['number'] ) : null,
231
-            'key'                  => isset( $data['key'] ) ? wpinv_clean( $data['key'] ) : null,
232
-            'status'               => isset( $data['status'] ) ? wpinv_clean( $data['status'] ) : null,
233
-            'post_type'            => isset( $data['post_type'] ) ? wpinv_clean( $data['post_type'] ) : null,
234
-            'user_ip'              => isset( $data['ip'] ) ? wpinv_clean( $data['ip'] ) : wpinv_get_ip(),
235
-            'parent_id'            => isset( $data['parent'] ) ? intval( $data['parent'] ) : null,
236
-            'mode'                 => isset( $data['mode'] ) ? wpinv_clean( $data['mode'] ) : null,
237
-            'description'          => isset( $data['description'] ) ? wp_kses_post( $data['description'] ) : null,
225
+            'template'             => isset($data['template']) ? wpinv_clean($data['template']) : null,
226
+            'email_cc'             => isset($data['email_cc']) ? wpinv_clean($data['email_cc']) : null,
227
+            'date_created'         => isset($data['created_date']) ? wpinv_clean($data['created_date']) : null,
228
+            'due_date'             => isset($data['due_date']) ? wpinv_clean($data['due_date']) : null,
229
+            'date_completed'       => isset($data['date_completed']) ? wpinv_clean($data['date_completed']) : null,
230
+            'number'               => isset($data['number']) ? wpinv_clean($data['number']) : null,
231
+            'key'                  => isset($data['key']) ? wpinv_clean($data['key']) : null,
232
+            'status'               => isset($data['status']) ? wpinv_clean($data['status']) : null,
233
+            'post_type'            => isset($data['post_type']) ? wpinv_clean($data['post_type']) : null,
234
+            'user_ip'              => isset($data['ip']) ? wpinv_clean($data['ip']) : wpinv_get_ip(),
235
+            'parent_id'            => isset($data['parent']) ? intval($data['parent']) : null,
236
+            'mode'                 => isset($data['mode']) ? wpinv_clean($data['mode']) : null,
237
+            'description'          => isset($data['description']) ? wp_kses_post($data['description']) : null,
238 238
 
239 239
             // Payment info.
240
-            'disable_taxes'        => ! empty( $data['disable_taxes'] ),
241
-            'currency'             => isset( $data['currency'] ) ? wpinv_clean( $data['currency'] ) : wpinv_get_currency(),
242
-            'gateway'              => isset( $data['gateway'] ) ? wpinv_clean( $data['gateway'] ) : null,
243
-            'transaction_id'       => isset( $data['transaction_id'] ) ? wpinv_clean( $data['transaction_id'] ) : null,
244
-            'discount_code'        => isset( $data['discount_code'] ) ? wpinv_clean( $data['discount_code'] ) : null,
245
-            'payment_form'         => isset( $data['payment_form'] ) ? intval( $data['payment_form'] ) : null,
246
-            'submission_id'        => isset( $data['submission_id'] ) ? wpinv_clean( $data['submission_id'] ) : null,
247
-            'subscription_id'      => isset( $data['subscription_id'] ) ? wpinv_clean( $data['subscription_id'] ) : null,
248
-            'is_viewed'            => isset( $data['is_viewed'] ) ? wpinv_clean( $data['is_viewed'] ) : null,
249
-            'fees'                 => isset( $data['fees'] ) ? wpinv_clean( $data['fees'] ) : null,
250
-            'discounts'            => isset( $data['discounts'] ) ? wpinv_clean( $data['discounts'] ) : null,
251
-            'taxes'                => isset( $data['taxes'] ) ? wpinv_clean( $data['taxes'] ) : null,
240
+            'disable_taxes'        => !empty($data['disable_taxes']),
241
+            'currency'             => isset($data['currency']) ? wpinv_clean($data['currency']) : wpinv_get_currency(),
242
+            'gateway'              => isset($data['gateway']) ? wpinv_clean($data['gateway']) : null,
243
+            'transaction_id'       => isset($data['transaction_id']) ? wpinv_clean($data['transaction_id']) : null,
244
+            'discount_code'        => isset($data['discount_code']) ? wpinv_clean($data['discount_code']) : null,
245
+            'payment_form'         => isset($data['payment_form']) ? intval($data['payment_form']) : null,
246
+            'submission_id'        => isset($data['submission_id']) ? wpinv_clean($data['submission_id']) : null,
247
+            'subscription_id'      => isset($data['subscription_id']) ? wpinv_clean($data['subscription_id']) : null,
248
+            'is_viewed'            => isset($data['is_viewed']) ? wpinv_clean($data['is_viewed']) : null,
249
+            'fees'                 => isset($data['fees']) ? wpinv_clean($data['fees']) : null,
250
+            'discounts'            => isset($data['discounts']) ? wpinv_clean($data['discounts']) : null,
251
+            'taxes'                => isset($data['taxes']) ? wpinv_clean($data['taxes']) : null,
252 252
             
253 253
 
254 254
             // Billing details.
255 255
             'user_id'              => $data['user_id'],
256
-            'first_name'           => isset( $data['first_name'] ) ? wpinv_clean( $data['first_name'] ) : $address['first_name'],
257
-            'last_name'            => isset( $data['last_name'] ) ? wpinv_clean( $data['last_name'] ) : $address['last_name'],
258
-            'address'              => isset( $data['address'] ) ? wpinv_clean( $data['address'] ) : $address['address'] ,
259
-            'vat_number'           => isset( $data['vat_number'] ) ? wpinv_clean( $data['vat_number'] ) : $address['vat_number'],
260
-            'company'              => isset( $data['company'] ) ? wpinv_clean( $data['company'] ) : $address['company'],
261
-            'zip'                  => isset( $data['zip'] ) ? wpinv_clean( $data['zip'] ) : $address['zip'],
262
-            'state'                => isset( $data['state'] ) ? wpinv_clean( $data['state'] ) : $address['state'],
263
-            'city'                 => isset( $data['city'] ) ? wpinv_clean( $data['city'] ) : $address['city'],
264
-            'country'              => isset( $data['country'] ) ? wpinv_clean( $data['country'] ) : $address['country'],
265
-            'phone'                => isset( $data['phone'] ) ? wpinv_clean( $data['phone'] ) : $address['phone'],
266
-            'address_confirmed'    => ! empty( $data['address_confirmed'] ),
256
+            'first_name'           => isset($data['first_name']) ? wpinv_clean($data['first_name']) : $address['first_name'],
257
+            'last_name'            => isset($data['last_name']) ? wpinv_clean($data['last_name']) : $address['last_name'],
258
+            'address'              => isset($data['address']) ? wpinv_clean($data['address']) : $address['address'],
259
+            'vat_number'           => isset($data['vat_number']) ? wpinv_clean($data['vat_number']) : $address['vat_number'],
260
+            'company'              => isset($data['company']) ? wpinv_clean($data['company']) : $address['company'],
261
+            'zip'                  => isset($data['zip']) ? wpinv_clean($data['zip']) : $address['zip'],
262
+            'state'                => isset($data['state']) ? wpinv_clean($data['state']) : $address['state'],
263
+            'city'                 => isset($data['city']) ? wpinv_clean($data['city']) : $address['city'],
264
+            'country'              => isset($data['country']) ? wpinv_clean($data['country']) : $address['country'],
265
+            'phone'                => isset($data['phone']) ? wpinv_clean($data['phone']) : $address['phone'],
266
+            'address_confirmed'    => !empty($data['address_confirmed']),
267 267
 
268 268
         )
269 269
 
270 270
     );
271 271
 
272 272
     // Backwards compatibililty.
273
-    if ( ! empty( $data['cart_details'] ) && is_array( $data['cart_details'] ) ) {
273
+    if (!empty($data['cart_details']) && is_array($data['cart_details'])) {
274 274
         $data['items'] = array();
275 275
 
276
-        foreach( $data['cart_details'] as $_item ) {
276
+        foreach ($data['cart_details'] as $_item) {
277 277
 
278 278
             // Ensure that we have an item id.
279
-            if ( empty(  $_item['id']  ) ) {
279
+            if (empty($_item['id'])) {
280 280
                 continue;
281 281
             }
282 282
 
283 283
             // Retrieve the item.
284
-            $item = new GetPaid_Form_Item(  $_item['id']  );
284
+            $item = new GetPaid_Form_Item($_item['id']);
285 285
 
286 286
             // Ensure that it is purchasable.
287
-            if ( ! $item->can_purchase() ) {
287
+            if (!$item->can_purchase()) {
288 288
                 continue;
289 289
             }
290 290
 
291 291
             // Set quantity.
292
-            if ( ! empty( $_item['quantity'] ) && is_numeric( $_item['quantity'] ) ) {
293
-                $item->set_quantity( $_item['quantity'] );
292
+            if (!empty($_item['quantity']) && is_numeric($_item['quantity'])) {
293
+                $item->set_quantity($_item['quantity']);
294 294
             }
295 295
 
296 296
             // Set price.
297
-            if ( isset( $_item['item_price'] ) ) {
298
-                $item->set_price( $_item['item_price'] );
297
+            if (isset($_item['item_price'])) {
298
+                $item->set_price($_item['item_price']);
299 299
             }
300 300
 
301
-            if ( isset( $_item['custom_price'] ) ) {
302
-                $item->set_price( $_item['custom_price'] );
301
+            if (isset($_item['custom_price'])) {
302
+                $item->set_price($_item['custom_price']);
303 303
             }
304 304
 
305 305
             // Set name.
306
-            if ( ! empty( $_item['name'] ) ) {
307
-                $item->set_name( $_item['name'] );
306
+            if (!empty($_item['name'])) {
307
+                $item->set_name($_item['name']);
308 308
             }
309 309
 
310 310
             // Set description.
311
-            if ( isset( $_item['description'] ) ) {
312
-                $item->set_custom_description( $_item['description'] );
311
+            if (isset($_item['description'])) {
312
+                $item->set_custom_description($_item['description']);
313 313
             }
314 314
 
315 315
             // Set meta.
316
-            if ( isset( $_item['meta'] ) && is_array( $_item['meta'] ) ) {
316
+            if (isset($_item['meta']) && is_array($_item['meta'])) {
317 317
 
318
-                $item->set_item_meta( $_item['meta'] );
318
+                $item->set_item_meta($_item['meta']);
319 319
 
320
-                if ( isset( $_item['meta']['description'] ) ) {
321
-                    $item->set_custom_description( $_item['meta']['description'] );
320
+                if (isset($_item['meta']['description'])) {
321
+                    $item->set_custom_description($_item['meta']['description']);
322 322
                 }
323 323
 
324 324
             }
@@ -329,14 +329,14 @@  discard block
 block discarded – undo
329 329
     }
330 330
 
331 331
     // Add invoice items.
332
-    if ( ! empty( $data['items'] ) && is_array( $data['items'] ) ) {
332
+    if (!empty($data['items']) && is_array($data['items'])) {
333 333
 
334
-        $invoice->set_items( array() );
334
+        $invoice->set_items(array());
335 335
 
336
-        foreach ( $data['items'] as $item ) {
336
+        foreach ($data['items'] as $item) {
337 337
 
338
-            if ( is_object( $item ) && is_a( $item, 'GetPaid_Form_Item' ) && $item->can_purchase() ) {
339
-                $invoice->add_item( $item );
338
+            if (is_object($item) && is_a($item, 'GetPaid_Form_Item') && $item->can_purchase()) {
339
+                $invoice->add_item($item);
340 340
             }
341 341
 
342 342
         }
@@ -347,30 +347,30 @@  discard block
 block discarded – undo
347 347
     $invoice->recalculate_total();
348 348
     $invoice->save();
349 349
 
350
-    if ( ! $invoice->get_id() ) {
351
-        return $wp_error ? new WP_Error( 'wpinv_insert_invoice_error', __( 'An error occured when saving your invoice.', 'invoicing' ) ) : 0;
350
+    if (!$invoice->get_id()) {
351
+        return $wp_error ? new WP_Error('wpinv_insert_invoice_error', __('An error occured when saving your invoice.', 'invoicing')) : 0;
352 352
     }
353 353
 
354 354
     // Add private note.
355
-    if ( ! empty( $data['private_note'] ) ) {
356
-        $invoice->add_note( $data['private_note'] );
355
+    if (!empty($data['private_note'])) {
356
+        $invoice->add_note($data['private_note']);
357 357
     }
358 358
 
359 359
     // User notes.
360
-    if ( !empty( $data['user_note'] ) ) {
361
-        $invoice->add_note( $data['user_note'], true );
360
+    if (!empty($data['user_note'])) {
361
+        $invoice->add_note($data['user_note'], true);
362 362
     }
363 363
 
364 364
     // Created via.
365
-    if ( isset( $data['created_via'] ) ) {
366
-        update_post_meta( $invoice->get_id(), 'wpinv_created_via', $data['created_via'] );
365
+    if (isset($data['created_via'])) {
366
+        update_post_meta($invoice->get_id(), 'wpinv_created_via', $data['created_via']);
367 367
     }
368 368
 
369 369
     // Backwards compatiblity.
370
-    if ( $invoice->is_quote() ) {
370
+    if ($invoice->is_quote()) {
371 371
 
372
-        if ( isset( $data['valid_until'] ) ) {
373
-            update_post_meta( $invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until'] );
372
+        if (isset($data['valid_until'])) {
373
+            update_post_meta($invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until']);
374 374
         }
375 375
         return $invoice;
376 376
 
@@ -385,18 +385,18 @@  discard block
 block discarded – undo
385 385
  * @param $bool $deprecated
386 386
  * @return WPInv_Invoice|null
387 387
  */
388
-function wpinv_get_invoice( $invoice = 0, $deprecated = false ) {
388
+function wpinv_get_invoice($invoice = 0, $deprecated = false) {
389 389
 
390 390
     // If we are retrieving the invoice from the cart...
391
-    if ( $deprecated && empty( $invoice ) ) {
391
+    if ($deprecated && empty($invoice)) {
392 392
         $invoice = (int) getpaid_get_current_invoice_id();
393 393
     }
394 394
 
395 395
     // Retrieve the invoice.
396
-    $invoice = new WPInv_Invoice( $invoice );
396
+    $invoice = new WPInv_Invoice($invoice);
397 397
 
398 398
     // Check if it exists.
399
-    if ( $invoice->get_id() != 0 ) {
399
+    if ($invoice->get_id() != 0) {
400 400
         return $invoice;
401 401
     }
402 402
 
@@ -409,15 +409,15 @@  discard block
 block discarded – undo
409 409
  * @param array $args Args to search for.
410 410
  * @return WPInv_Invoice[]|int[]|object
411 411
  */
412
-function wpinv_get_invoices( $args ) {
412
+function wpinv_get_invoices($args) {
413 413
 
414 414
     // Prepare args.
415 415
     $args = wp_parse_args(
416 416
         $args,
417 417
         array(
418
-            'status'   => array_keys( wpinv_get_invoice_statuses() ),
418
+            'status'   => array_keys(wpinv_get_invoice_statuses()),
419 419
             'type'     => 'wpi_invoice',
420
-            'limit'    => get_option( 'posts_per_page' ),
420
+            'limit'    => get_option('posts_per_page'),
421 421
             'return'   => 'objects',
422 422
         )
423 423
     );
@@ -435,24 +435,24 @@  discard block
 block discarded – undo
435 435
         'post__in'       => 'include',
436 436
     );
437 437
 
438
-    foreach ( $map_legacy as $to => $from ) {
439
-        if ( isset( $args[ $from ] ) ) {
440
-            $args[ $to ] = $args[ $from ];
441
-            unset( $args[ $from ] );
438
+    foreach ($map_legacy as $to => $from) {
439
+        if (isset($args[$from])) {
440
+            $args[$to] = $args[$from];
441
+            unset($args[$from]);
442 442
         }
443 443
     }
444 444
 
445 445
     // Backwards compatibility.
446
-    if ( ! empty( $args['email'] ) && empty( $args['user'] ) ) {
446
+    if (!empty($args['email']) && empty($args['user'])) {
447 447
         $args['user'] = $args['email'];
448
-        unset( $args['email'] );
448
+        unset($args['email']);
449 449
     }
450 450
 
451 451
     // Handle cases where the user is set as an email.
452
-    if ( ! empty( $args['author'] ) && is_email( $args['author'] ) ) {
453
-        $user = get_user_by( 'email', $args['user'] );
452
+    if (!empty($args['author']) && is_email($args['author'])) {
453
+        $user = get_user_by('email', $args['user']);
454 454
 
455
-        if ( $user ) {
455
+        if ($user) {
456 456
             $args['author'] = $user->user_email;
457 457
         }
458 458
 
@@ -463,31 +463,31 @@  discard block
 block discarded – undo
463 463
 
464 464
     // Show all posts.
465 465
     $paginate = true;
466
-    if ( isset( $args['paginate'] ) ) {
466
+    if (isset($args['paginate'])) {
467 467
 
468 468
         $paginate = $args['paginate'];
469
-        $args['no_found_rows'] = empty( $args['paginate'] );
470
-        unset( $args['paginate'] );
469
+        $args['no_found_rows'] = empty($args['paginate']);
470
+        unset($args['paginate']);
471 471
 
472 472
     }
473 473
 
474 474
     // Whether to return objects or fields.
475 475
     $return = $args['return'];
476
-    unset( $args['return'] );
476
+    unset($args['return']);
477 477
 
478 478
     // Get invoices.
479
-    $invoices = new WP_Query( apply_filters( 'wpinv_get_invoices_args', $args ) );
479
+    $invoices = new WP_Query(apply_filters('wpinv_get_invoices_args', $args));
480 480
 
481 481
     // Prepare the results.
482
-    if ( 'objects' === $return ) {
483
-        $results = array_map( 'wpinv_get_invoice', $invoices->posts );
484
-    } elseif ( 'self' === $return ) {
482
+    if ('objects' === $return) {
483
+        $results = array_map('wpinv_get_invoice', $invoices->posts);
484
+    } elseif ('self' === $return) {
485 485
         return $invoices;
486 486
     } else {
487 487
         $results = $invoices->posts;
488 488
     }
489 489
 
490
-    if ( $paginate ) {
490
+    if ($paginate) {
491 491
         return (object) array(
492 492
             'invoices'      => $results,
493 493
             'total'         => $invoices->found_posts,
@@ -505,8 +505,8 @@  discard block
 block discarded – undo
505 505
  * @param string $transaction_id The transaction id to check.
506 506
  * @return int Invoice id on success or 0 on failure
507 507
  */
508
-function wpinv_get_id_by_transaction_id( $transaction_id ) {
509
-    return WPInv_Invoice::get_invoice_id_by_field( $transaction_id, 'transaction_id' );
508
+function wpinv_get_id_by_transaction_id($transaction_id) {
509
+    return WPInv_Invoice::get_invoice_id_by_field($transaction_id, 'transaction_id');
510 510
 }
511 511
 
512 512
 /**
@@ -515,8 +515,8 @@  discard block
 block discarded – undo
515 515
  * @param string $invoice_number The invoice number to check.
516 516
  * @return int Invoice id on success or 0 on failure
517 517
  */
518
-function wpinv_get_id_by_invoice_number( $invoice_number ) {
519
-    return WPInv_Invoice::get_invoice_id_by_field( $invoice_number, 'number' );
518
+function wpinv_get_id_by_invoice_number($invoice_number) {
519
+    return WPInv_Invoice::get_invoice_id_by_field($invoice_number, 'number');
520 520
 }
521 521
 
522 522
 /**
@@ -525,8 +525,8 @@  discard block
 block discarded – undo
525 525
  * @param string $invoice_key The invoice key to check.
526 526
  * @return int Invoice id on success or 0 on failure
527 527
  */
528
-function wpinv_get_invoice_id_by_key( $invoice_key ) {
529
-    return WPInv_Invoice::get_invoice_id_by_field( $invoice_key, 'key' );
528
+function wpinv_get_invoice_id_by_key($invoice_key) {
529
+    return WPInv_Invoice::get_invoice_id_by_field($invoice_key, 'key');
530 530
 }
531 531
 
532 532
 /**
@@ -536,19 +536,19 @@  discard block
 block discarded – undo
536 536
  * @param string $type Optionally filter by type i.e customer|system
537 537
  * @return array|null
538 538
  */
539
-function wpinv_get_invoice_notes( $invoice = 0, $type = '' ) {
539
+function wpinv_get_invoice_notes($invoice = 0, $type = '') {
540 540
 
541 541
     // Prepare the invoice.
542
-    $invoice = wpinv_get_invoice( $invoice );
543
-    if ( empty( $invoice ) ) {
542
+    $invoice = wpinv_get_invoice($invoice);
543
+    if (empty($invoice)) {
544 544
         return NULL;
545 545
     }
546 546
 
547 547
     // Fetch notes.
548
-    $notes = getpaid_notes()->get_invoice_notes( $invoice->get_id(), $type );
548
+    $notes = getpaid_notes()->get_invoice_notes($invoice->get_id(), $type);
549 549
 
550 550
     // Filter the notes.
551
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice->get_id(), $type );
551
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice->get_id(), $type);
552 552
 }
553 553
 
554 554
 /**
@@ -556,10 +556,10 @@  discard block
 block discarded – undo
556 556
  * 
557 557
  * @param string $post_type
558 558
  */
559
-function wpinv_get_user_invoices_columns( $post_type = 'wpi_invoice' ) {
559
+function wpinv_get_user_invoices_columns($post_type = 'wpi_invoice') {
560 560
 
561
-    $label   = getpaid_get_post_type_label( $post_type, false );
562
-    $label   = empty( $label ) ? __( 'Invoice', 'invoicing' ) : sanitize_text_field( $label );
561
+    $label   = getpaid_get_post_type_label($post_type, false);
562
+    $label   = empty($label) ? __('Invoice', 'invoicing') : sanitize_text_field($label);
563 563
     $columns = array(
564 564
 
565 565
             'invoice-number'  => array(
@@ -568,22 +568,22 @@  discard block
 block discarded – undo
568 568
             ),
569 569
 
570 570
             'created-date'    => array(
571
-                'title' => __( 'Created Date', 'invoicing' ),
571
+                'title' => __('Created Date', 'invoicing'),
572 572
                 'class' => 'text-left'
573 573
             ),
574 574
 
575 575
             'payment-date'    => array(
576
-                'title' => __( 'Payment Date', 'invoicing' ),
576
+                'title' => __('Payment Date', 'invoicing'),
577 577
                 'class' => 'text-left'
578 578
             ),
579 579
 
580 580
             'invoice-status'  => array(
581
-                'title' => __( 'Status', 'invoicing' ),
581
+                'title' => __('Status', 'invoicing'),
582 582
                 'class' => 'text-center'
583 583
             ),
584 584
 
585 585
             'invoice-total'   => array(
586
-                'title' => __( 'Total', 'invoicing' ),
586
+                'title' => __('Total', 'invoicing'),
587 587
                 'class' => 'text-right'
588 588
             ),
589 589
 
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
 
595 595
         );
596 596
 
597
-    return apply_filters( 'wpinv_user_invoices_columns', $columns, $post_type );
597
+    return apply_filters('wpinv_user_invoices_columns', $columns, $post_type);
598 598
 }
599 599
 
600 600
 /**
@@ -604,59 +604,59 @@  discard block
 block discarded – undo
604 604
 
605 605
     // Find the invoice.
606 606
     $invoice_id = getpaid_get_current_invoice_id();
607
-    $invoice = new WPInv_Invoice( $invoice_id );
607
+    $invoice = new WPInv_Invoice($invoice_id);
608 608
 
609 609
     // Abort if non was found.
610
-    if ( empty( $invoice_id ) || $invoice->is_draft() ) {
610
+    if (empty($invoice_id) || $invoice->is_draft()) {
611 611
 
612 612
         return aui()->alert(
613 613
             array(
614 614
                 'type'    => 'warning',
615
-                'content' => __( 'We could not find your invoice', 'invoicing' ),
615
+                'content' => __('We could not find your invoice', 'invoicing'),
616 616
             )
617 617
         );
618 618
 
619 619
     }
620 620
 
621 621
     // Can the user view this invoice?
622
-    if ( ! wpinv_can_view_receipt( $invoice_id ) ) {
622
+    if (!wpinv_can_view_receipt($invoice_id)) {
623 623
 
624 624
         return aui()->alert(
625 625
             array(
626 626
                 'type'    => 'warning',
627
-                'content' => __( 'You are not allowed to view this receipt', 'invoicing' ),
627
+                'content' => __('You are not allowed to view this receipt', 'invoicing'),
628 628
             )
629 629
         );
630 630
 
631 631
     }
632 632
 
633 633
     // Load the template.
634
-    return wpinv_get_template_html( 'invoice-receipt.php', compact( 'invoice' ) );
634
+    return wpinv_get_template_html('invoice-receipt.php', compact('invoice'));
635 635
 
636 636
 }
637 637
 
638 638
 /**
639 639
  * Displays the invoice history.
640 640
  */
641
-function getpaid_invoice_history( $user_id = 0, $post_type = 'wpi_invoice' ) {
641
+function getpaid_invoice_history($user_id = 0, $post_type = 'wpi_invoice') {
642 642
 
643 643
     // Ensure that we have a user id.
644
-    if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
644
+    if (empty($user_id) || !is_numeric($user_id)) {
645 645
         $user_id = get_current_user_id();
646 646
     }
647 647
 
648
-    $label = getpaid_get_post_type_label( $post_type );
649
-    $label = empty( $label ) ? __( 'Invoices', 'invoicing' ) : sanitize_text_field( $label );
648
+    $label = getpaid_get_post_type_label($post_type);
649
+    $label = empty($label) ? __('Invoices', 'invoicing') : sanitize_text_field($label);
650 650
 
651 651
     // View user id.
652
-    if ( empty( $user_id ) ) {
652
+    if (empty($user_id)) {
653 653
 
654 654
         return aui()->alert(
655 655
             array(
656 656
                 'type'    => 'warning',
657 657
                 'content' => sprintf(
658
-                    __( 'You must be logged in to view your %s.', 'invoicing' ),
659
-                    strtolower( $label )
658
+                    __('You must be logged in to view your %s.', 'invoicing'),
659
+                    strtolower($label)
660 660
                 )
661 661
             )
662 662
         );
@@ -667,23 +667,23 @@  discard block
 block discarded – undo
667 667
     $invoices = wpinv_get_invoices(
668 668
 
669 669
         array(
670
-            'page'      => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1,
670
+            'page'      => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1,
671 671
             'user'      => $user_id,
672 672
             'paginate'  => true,
673 673
             'type'      => $post_type,
674
-            'status'    => array_keys( wpinv_get_invoice_statuses( false, false, $post_type ) ),
674
+            'status'    => array_keys(wpinv_get_invoice_statuses(false, false, $post_type)),
675 675
         )
676 676
 
677 677
     );
678 678
 
679
-    if ( empty( $invoices->total ) ) {
679
+    if (empty($invoices->total)) {
680 680
 
681 681
         return aui()->alert(
682 682
             array(
683 683
                 'type'    => 'info',
684 684
                 'content' => sprintf(
685
-                    __( 'No %s found.', 'invoicing' ),
686
-                    strtolower( $label )
685
+                    __('No %s found.', 'invoicing'),
686
+                    strtolower($label)
687 687
                 )
688 688
             )
689 689
         );
@@ -691,38 +691,38 @@  discard block
 block discarded – undo
691 691
     }
692 692
 
693 693
     // Load the template.
694
-    return wpinv_get_template_html( 'invoice-history.php', compact( 'invoices', 'post_type' ) );
694
+    return wpinv_get_template_html('invoice-history.php', compact('invoices', 'post_type'));
695 695
 
696 696
 }
697 697
 
698 698
 /**
699 699
  * Formats an invoice number given an invoice type.
700 700
  */
701
-function wpinv_format_invoice_number( $number, $type = '' ) {
701
+function wpinv_format_invoice_number($number, $type = '') {
702 702
 
703 703
     // Allow other plugins to overide this.
704
-    $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type );
705
-    if ( null !== $check ) {
704
+    $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type);
705
+    if (null !== $check) {
706 706
         return $check;
707 707
     }
708 708
 
709 709
     // Ensure that we have a numeric number.
710
-    if ( ! is_numeric( $number ) ) {
710
+    if (!is_numeric($number)) {
711 711
         return $number;
712 712
     }
713 713
 
714 714
     // Format the number.
715
-    $padd             = absint( (int) wpinv_get_option( 'invoice_number_padd', 5 ) );
716
-    $prefix           = sanitize_text_field( (string) wpinv_get_option( 'invoice_number_prefix', 'INV-' ) );
717
-    $prefix           = sanitize_text_field( apply_filters( 'getpaid_invoice_type_prefix', $prefix, $type ) );
718
-    $postfix          = sanitize_text_field( (string) wpinv_get_option( 'invoice_number_postfix' ) );
719
-    $postfix          = sanitize_text_field( apply_filters( 'getpaid_invoice_type_postfix', $postfix, $type ) );
720
-    $formatted_number = zeroise( absint( $number ), $padd );
715
+    $padd             = absint((int) wpinv_get_option('invoice_number_padd', 5));
716
+    $prefix           = sanitize_text_field((string) wpinv_get_option('invoice_number_prefix', 'INV-'));
717
+    $prefix           = sanitize_text_field(apply_filters('getpaid_invoice_type_prefix', $prefix, $type));
718
+    $postfix          = sanitize_text_field((string) wpinv_get_option('invoice_number_postfix'));
719
+    $postfix          = sanitize_text_field(apply_filters('getpaid_invoice_type_postfix', $postfix, $type));
720
+    $formatted_number = zeroise(absint($number), $padd);
721 721
 
722 722
     // Add the prefix and post fix.
723 723
     $formatted_number = $prefix . $formatted_number . $postfix;
724 724
 
725
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
725
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
726 726
 }
727 727
 
728 728
 /**
@@ -731,58 +731,58 @@  discard block
 block discarded – undo
731 731
  * @param string $type.
732 732
  * @return int|null|bool
733 733
  */
734
-function wpinv_get_next_invoice_number( $type = '' ) {
734
+function wpinv_get_next_invoice_number($type = '') {
735 735
 
736 736
     // Allow plugins to overide this.
737
-    $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type );
738
-    if ( null !== $check ) {
737
+    $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type);
738
+    if (null !== $check) {
739 739
         return $check;
740 740
     }
741 741
 
742 742
     // Ensure sequential invoice numbers is active.
743
-    if ( ! wpinv_sequential_number_active() ) {
743
+    if (!wpinv_sequential_number_active()) {
744 744
         return false;
745 745
     }
746 746
 
747 747
     // Retrieve the current number and the start number.
748
-    $number = (int) get_option( 'wpinv_last_invoice_number', 0 );
749
-    $start  = absint( (int) wpinv_get_option( 'invoice_sequence_start', 1 ) );
748
+    $number = (int) get_option('wpinv_last_invoice_number', 0);
749
+    $start  = absint((int) wpinv_get_option('invoice_sequence_start', 1));
750 750
 
751 751
     // Ensure that we are starting at a positive integer.
752
-    $start  = max( $start, 1 );
752
+    $start  = max($start, 1);
753 753
 
754 754
     // If this is the first invoice, use the start number.
755
-    $number = max( $start, $number );
755
+    $number = max($start, $number);
756 756
 
757 757
     // Format the invoice number.
758
-    $formatted_number = wpinv_format_invoice_number( $number, $type );
758
+    $formatted_number = wpinv_format_invoice_number($number, $type);
759 759
 
760 760
     // Ensure that this number is unique.
761
-    $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $formatted_number, 'number' );
761
+    $invoice_id = WPInv_Invoice::get_invoice_id_by_field($formatted_number, 'number');
762 762
 
763 763
     // We found a match. Nice.
764
-    if ( empty( $invoice_id ) ) {
765
-        update_option( 'wpinv_last_invoice_number', $number );
766
-        return apply_filters( 'wpinv_get_next_invoice_number', $number );
764
+    if (empty($invoice_id)) {
765
+        update_option('wpinv_last_invoice_number', $number);
766
+        return apply_filters('wpinv_get_next_invoice_number', $number);
767 767
     }
768 768
 
769
-    update_option( 'wpinv_last_invoice_number', $number + 1 );
770
-    return wpinv_get_next_invoice_number( $type );
769
+    update_option('wpinv_last_invoice_number', $number + 1);
770
+    return wpinv_get_next_invoice_number($type);
771 771
 
772 772
 }
773 773
 
774 774
 /**
775 775
  * The prefix used for invoice paths.
776 776
  */
777
-function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) {
778
-    return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type );
777
+function wpinv_post_name_prefix($post_type = 'wpi_invoice') {
778
+    return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type);
779 779
 }
780 780
 
781
-function wpinv_generate_post_name( $post_ID ) {
782
-    $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) );
783
-    $post_name = sanitize_title( $prefix . $post_ID );
781
+function wpinv_generate_post_name($post_ID) {
782
+    $prefix = wpinv_post_name_prefix(get_post_type($post_ID));
783
+    $post_name = sanitize_title($prefix . $post_ID);
784 784
 
785
-    return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix );
785
+    return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix);
786 786
 }
787 787
 
788 788
 /**
@@ -790,8 +790,8 @@  discard block
 block discarded – undo
790 790
  * 
791 791
  * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object.
792 792
  */
793
-function wpinv_is_invoice_viewed( $invoice ) {
794
-    $invoice = new WPInv_Invoice( $invoice );
793
+function wpinv_is_invoice_viewed($invoice) {
794
+    $invoice = new WPInv_Invoice($invoice);
795 795
     return (bool) $invoice->get_is_viewed();
796 796
 }
797 797
 
@@ -800,17 +800,17 @@  discard block
 block discarded – undo
800 800
  * 
801 801
  * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object.
802 802
  */
803
-function getpaid_maybe_mark_invoice_as_viewed( $invoice ) {
804
-    $invoice = new WPInv_Invoice( $invoice );
803
+function getpaid_maybe_mark_invoice_as_viewed($invoice) {
804
+    $invoice = new WPInv_Invoice($invoice);
805 805
 
806
-    if ( get_current_user_id() == $invoice->get_user_id() && ! $invoice->get_is_viewed() ) {
807
-        $invoice->set_is_viewed( true );
806
+    if (get_current_user_id() == $invoice->get_user_id() && !$invoice->get_is_viewed()) {
807
+        $invoice->set_is_viewed(true);
808 808
         $invoice->save();
809 809
     }
810 810
 
811 811
 }
812
-add_action( 'wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed' );
813
-add_action( 'wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed' );
812
+add_action('wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed');
813
+add_action('wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed');
814 814
 
815 815
 /**
816 816
  * Processes an invoice refund.
@@ -819,27 +819,27 @@  discard block
 block discarded – undo
819 819
  * @param array $status_transition
820 820
  * @todo: descrease customer/store earnings
821 821
  */
822
-function getpaid_maybe_process_refund( $invoice, $status_transition ) {
822
+function getpaid_maybe_process_refund($invoice, $status_transition) {
823 823
 
824
-    if ( empty( $status_transition['from'] ) || ! in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) {
824
+    if (empty($status_transition['from']) || !in_array($status_transition['from'], array('publish', 'wpi-processing', 'wpi-renewal'))) {
825 825
         return;
826 826
     }
827 827
 
828 828
     $discount_code = $invoice->get_discount_code();
829
-    if ( ! empty( $discount_code ) ) {
830
-        $discount = wpinv_get_discount_obj( $discount_code );
829
+    if (!empty($discount_code)) {
830
+        $discount = wpinv_get_discount_obj($discount_code);
831 831
 
832
-        if ( $discount->exists() ) {
832
+        if ($discount->exists()) {
833 833
             $discount->increase_usage( -1 );
834 834
         }
835 835
 
836 836
     }
837 837
 
838
-    do_action( 'wpinv_pre_refund_invoice', $invoice, $invoice->get_id() );
839
-    do_action( 'wpinv_refund_invoice', $invoice, $invoice->get_id() );
840
-    do_action( 'wpinv_post_refund_invoice', $invoice, $invoice->get_id() );
838
+    do_action('wpinv_pre_refund_invoice', $invoice, $invoice->get_id());
839
+    do_action('wpinv_refund_invoice', $invoice, $invoice->get_id());
840
+    do_action('wpinv_post_refund_invoice', $invoice, $invoice->get_id());
841 841
 }
842
-add_action( 'getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 2 );
842
+add_action('getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 2);
843 843
 
844 844
 
845 845
 /**
@@ -847,49 +847,49 @@  discard block
 block discarded – undo
847 847
  *
848 848
  * @param int $invoice_id
849 849
  */
850
-function getpaid_process_invoice_payment( $invoice_id ) {
850
+function getpaid_process_invoice_payment($invoice_id) {
851 851
 
852 852
     // Fetch the invoice.
853
-    $invoice = new WPInv_Invoice( $invoice_id );
853
+    $invoice = new WPInv_Invoice($invoice_id);
854 854
 
855 855
     // We only want to do this once.
856
-    if ( 1 ==  get_post_meta( $invoice->get_id(), 'wpinv_processed_payment', true ) ) {
856
+    if (1 == get_post_meta($invoice->get_id(), 'wpinv_processed_payment', true)) {
857 857
         return;
858 858
     }
859 859
 
860
-    update_post_meta( $invoice->get_id(), 'wpinv_processed_payment', 1 );
860
+    update_post_meta($invoice->get_id(), 'wpinv_processed_payment', 1);
861 861
 
862 862
     // Fires when processing a payment.
863
-    do_action( 'getpaid_process_payment', $invoice );
863
+    do_action('getpaid_process_payment', $invoice);
864 864
 
865 865
     // Fire an action for each invoice item.
866
-    foreach( $invoice->get_items() as $item ) {
867
-        do_action( 'getpaid_process_item_payment', $item, $invoice );
866
+    foreach ($invoice->get_items() as $item) {
867
+        do_action('getpaid_process_item_payment', $item, $invoice);
868 868
     }
869 869
 
870 870
     // Increase discount usage.
871 871
     $discount_code = $invoice->get_discount_code();
872
-    if ( ! empty( $discount_code ) && ! $invoice->is_renewal() ) {
873
-        $discount = wpinv_get_discount_obj( $discount_code );
872
+    if (!empty($discount_code) && !$invoice->is_renewal()) {
873
+        $discount = wpinv_get_discount_obj($discount_code);
874 874
 
875
-        if ( $discount->exists() ) {
875
+        if ($discount->exists()) {
876 876
             $discount->increase_usage();
877 877
         }
878 878
 
879 879
     }
880 880
 
881 881
     // Record reverse vat.
882
-    if ( 'invoice' == $invoice->get_type() && wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) {
882
+    if ('invoice' == $invoice->get_type() && wpinv_use_taxes() && !$invoice->get_disable_taxes()) {
883 883
 
884 884
         $taxes = $invoice->get_total_tax();
885
-        if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) {
886
-            $invoice->add_note( __( 'VAT was reverse charged', 'invoicing' ), false, false, true );
885
+        if (empty($taxes) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction($invoice->get_country())) {
886
+            $invoice->add_note(__('VAT was reverse charged', 'invoicing'), false, false, true);
887 887
         }
888 888
 
889 889
     }
890 890
 
891 891
 }
892
-add_action( 'getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment' );
892
+add_action('getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment');
893 893
 
894 894
 /**
895 895
  * Returns an array of invoice item columns
@@ -897,13 +897,13 @@  discard block
 block discarded – undo
897 897
  * @param int|WPInv_Invoice $invoice
898 898
  * @return array
899 899
  */
900
-function getpaid_invoice_item_columns( $invoice ) {
900
+function getpaid_invoice_item_columns($invoice) {
901 901
 
902 902
     // Prepare the invoice.
903
-    $invoice = new WPInv_Invoice( $invoice );
903
+    $invoice = new WPInv_Invoice($invoice);
904 904
 
905 905
     // Abort if there is no invoice.
906
-    if ( 0 == $invoice->get_id() ) {
906
+    if (0 == $invoice->get_id()) {
907 907
         return array();
908 908
     }
909 909
 
@@ -911,47 +911,47 @@  discard block
 block discarded – undo
911 911
     $columns = apply_filters(
912 912
         'getpaid_invoice_item_columns',
913 913
         array(
914
-            'name'     => __( 'Item', 'invoicing' ),
915
-            'price'    => __( 'Price', 'invoicing' ),
916
-            'quantity' => __( 'Quantity', 'invoicing' ),
917
-            'subtotal' => __( 'Subtotal', 'invoicing' ),
914
+            'name'     => __('Item', 'invoicing'),
915
+            'price'    => __('Price', 'invoicing'),
916
+            'quantity' => __('Quantity', 'invoicing'),
917
+            'subtotal' => __('Subtotal', 'invoicing'),
918 918
         ),
919 919
         $invoice
920 920
     );
921 921
 
922 922
     // Quantities.
923
-    if ( isset( $columns[ 'quantity' ] ) ) {
923
+    if (isset($columns['quantity'])) {
924 924
 
925
-        if ( 'hours' == $invoice->get_template() ) {
926
-            $columns[ 'quantity' ] = __( 'Hours', 'invoicing' );
925
+        if ('hours' == $invoice->get_template()) {
926
+            $columns['quantity'] = __('Hours', 'invoicing');
927 927
         }
928 928
 
929
-        if ( ! wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template() ) {
930
-            unset( $columns[ 'quantity' ] );
929
+        if (!wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template()) {
930
+            unset($columns['quantity']);
931 931
         }
932 932
 
933 933
     }
934 934
 
935 935
 
936 936
     // Price.
937
-    if ( isset( $columns[ 'price' ] ) ) {
937
+    if (isset($columns['price'])) {
938 938
 
939
-        if ( 'amount' == $invoice->get_template() ) {
940
-            $columns[ 'price' ] = __( 'Amount', 'invoicing' );
939
+        if ('amount' == $invoice->get_template()) {
940
+            $columns['price'] = __('Amount', 'invoicing');
941 941
         }
942 942
 
943
-        if ( 'hours' == $invoice->get_template() ) {
944
-            $columns[ 'price' ] = __( 'Rate', 'invoicing' );
943
+        if ('hours' == $invoice->get_template()) {
944
+            $columns['price'] = __('Rate', 'invoicing');
945 945
         }
946 946
 
947 947
     }
948 948
 
949 949
 
950 950
     // Sub total.
951
-    if ( isset( $columns[ 'subtotal' ] ) ) {
951
+    if (isset($columns['subtotal'])) {
952 952
 
953
-        if ( 'amount' == $invoice->get_template() ) {
954
-            unset( $columns[ 'subtotal' ] );
953
+        if ('amount' == $invoice->get_template()) {
954
+            unset($columns['subtotal']);
955 955
         }
956 956
 
957 957
     }
@@ -965,38 +965,38 @@  discard block
 block discarded – undo
965 965
  * @param int|WPInv_Invoice $invoice
966 966
  * @return array
967 967
  */
968
-function getpaid_invoice_totals_rows( $invoice ) {
968
+function getpaid_invoice_totals_rows($invoice) {
969 969
 
970 970
     // Prepare the invoice.
971
-    $invoice = new WPInv_Invoice( $invoice );
971
+    $invoice = new WPInv_Invoice($invoice);
972 972
 
973 973
     // Abort if there is no invoice.
974
-    if ( 0 == $invoice->get_id() ) {
974
+    if (0 == $invoice->get_id()) {
975 975
         return array();
976 976
     }
977 977
 
978 978
     $totals = apply_filters(
979 979
         'getpaid_invoice_totals_rows',
980 980
         array(
981
-            'subtotal' => __( 'Subtotal', 'invoicing' ),
982
-            'tax'      => __( 'Tax', 'invoicing' ),
983
-            'fee'      => __( 'Fee', 'invoicing' ),
984
-            'discount' => __( 'Discount', 'invoicing' ),
985
-            'total'    => __( 'Total', 'invoicing' ),
981
+            'subtotal' => __('Subtotal', 'invoicing'),
982
+            'tax'      => __('Tax', 'invoicing'),
983
+            'fee'      => __('Fee', 'invoicing'),
984
+            'discount' => __('Discount', 'invoicing'),
985
+            'total'    => __('Total', 'invoicing'),
986 986
         ),
987 987
         $invoice
988 988
     );
989 989
 
990
-    if ( ( $invoice->get_disable_taxes() || ! wpinv_use_taxes() ) && isset( $totals['tax'] ) ) {
991
-        unset( $totals['tax'] );
990
+    if (($invoice->get_disable_taxes() || !wpinv_use_taxes()) && isset($totals['tax'])) {
991
+        unset($totals['tax']);
992 992
     }
993 993
 
994
-    if ( 0 == $invoice->get_total_fees() && isset( $totals['fee'] ) ) {
995
-        unset( $totals['fee'] );
994
+    if (0 == $invoice->get_total_fees() && isset($totals['fee'])) {
995
+        unset($totals['fee']);
996 996
     }
997 997
 
998
-    if ( 0 == $invoice->get_total_discount() && isset( $totals['discount'] ) ) {
999
-        unset( $totals['discount'] );
998
+    if (0 == $invoice->get_total_discount() && isset($totals['discount'])) {
999
+        unset($totals['discount']);
1000 1000
     }
1001 1001
 
1002 1002
     return $totals;
@@ -1007,47 +1007,47 @@  discard block
 block discarded – undo
1007 1007
  * 
1008 1008
  * @param WPInv_Invoice $invoice
1009 1009
  */
1010
-function getpaid_new_invoice( $invoice ) {
1010
+function getpaid_new_invoice($invoice) {
1011 1011
 
1012
-    if ( ! $invoice->get_status() ) {
1012
+    if (!$invoice->get_status()) {
1013 1013
         return;
1014 1014
     }
1015 1015
 
1016 1016
     // Add an invoice created note.
1017 1017
     $invoice->add_note(
1018 1018
         sprintf(
1019
-            __( '%s created with the status "%s".', 'invoicing' ),
1020
-            ucfirst( $invoice->get_invoice_quote_type() ),
1021
-            wpinv_status_nicename( $invoice->get_status(), $invoice  )
1019
+            __('%s created with the status "%s".', 'invoicing'),
1020
+            ucfirst($invoice->get_invoice_quote_type()),
1021
+            wpinv_status_nicename($invoice->get_status(), $invoice)
1022 1022
         )
1023 1023
     );
1024 1024
 
1025 1025
 }
1026
-add_action( 'getpaid_new_invoice', 'getpaid_new_invoice' );
1026
+add_action('getpaid_new_invoice', 'getpaid_new_invoice');
1027 1027
 
1028 1028
 /**
1029 1029
  * This function updates invoice caches.
1030 1030
  * 
1031 1031
  * @param WPInv_Invoice $invoice
1032 1032
  */
1033
-function getpaid_update_invoice_caches( $invoice ) {
1033
+function getpaid_update_invoice_caches($invoice) {
1034 1034
 
1035 1035
     // Cache invoice number.
1036
-    wp_cache_set( $invoice->get_number(), $invoice->get_id(), "getpaid_invoice_numbers_to_invoice_ids" );
1036
+    wp_cache_set($invoice->get_number(), $invoice->get_id(), "getpaid_invoice_numbers_to_invoice_ids");
1037 1037
 
1038 1038
     // Cache invoice key.
1039
-    wp_cache_set( $invoice->get_key(), $invoice->get_id(), "getpaid_invoice_keys_to_invoice_ids" );
1039
+    wp_cache_set($invoice->get_key(), $invoice->get_id(), "getpaid_invoice_keys_to_invoice_ids");
1040 1040
 
1041 1041
     // (Maybe) cache transaction id.
1042 1042
     $transaction_id = $invoice->get_transaction_id();
1043 1043
 
1044
-    if ( ! empty( $transaction_id ) ) {
1045
-        wp_cache_set( $transaction_id, $invoice->get_id(), "getpaid_invoice_transaction_ids_to_invoice_ids" );
1044
+    if (!empty($transaction_id)) {
1045
+        wp_cache_set($transaction_id, $invoice->get_id(), "getpaid_invoice_transaction_ids_to_invoice_ids");
1046 1046
     }
1047 1047
 
1048 1048
 }
1049
-add_action( 'getpaid_new_invoice', 'getpaid_update_invoice_caches', 5 );
1050
-add_action( 'getpaid_update_invoice', 'getpaid_update_invoice_caches', 5 );
1049
+add_action('getpaid_new_invoice', 'getpaid_update_invoice_caches', 5);
1050
+add_action('getpaid_update_invoice', 'getpaid_update_invoice_caches', 5);
1051 1051
 
1052 1052
 /**
1053 1053
  * Duplicates an invoice.
@@ -1057,7 +1057,7 @@  discard block
 block discarded – undo
1057 1057
  * @param  WPInv_Invoice $old_invoice The invoice to duplicate
1058 1058
  * @return WPInv_Invoice The new invoice.
1059 1059
  */
1060
-function getpaid_duplicate_invoice( $old_invoice ) {
1060
+function getpaid_duplicate_invoice($old_invoice) {
1061 1061
 
1062 1062
     // Create the new invoice.
1063 1063
     $invoice = new WPInv_Invoice();
@@ -1118,127 +1118,127 @@  discard block
 block discarded – undo
1118 1118
  * @param WPInv_Invoice $invoice
1119 1119
  * @return array
1120 1120
  */
1121
-function getpaid_get_invoice_meta( $invoice ) {
1121
+function getpaid_get_invoice_meta($invoice) {
1122 1122
 
1123 1123
     // Load the invoice meta.
1124 1124
     $meta = array(
1125 1125
 
1126 1126
         'number' => array(
1127 1127
             'label' => sprintf(
1128
-                __( '%s Number', 'invoicing' ),
1129
-                ucfirst( $invoice->get_invoice_quote_type() )
1128
+                __('%s Number', 'invoicing'),
1129
+                ucfirst($invoice->get_invoice_quote_type())
1130 1130
             ),
1131
-            'value' => sanitize_text_field( $invoice->get_number() ),
1131
+            'value' => sanitize_text_field($invoice->get_number()),
1132 1132
         ),
1133 1133
 
1134 1134
         'status' => array(
1135 1135
             'label' => sprintf(
1136
-                __( '%s Status', 'invoicing' ),
1137
-                ucfirst( $invoice->get_invoice_quote_type() )
1136
+                __('%s Status', 'invoicing'),
1137
+                ucfirst($invoice->get_invoice_quote_type())
1138 1138
             ),
1139 1139
             'value' => $invoice->get_status_label_html(),
1140 1140
         ),
1141 1141
 
1142 1142
         'date' => array(
1143 1143
             'label' => sprintf(
1144
-                __( '%s Date', 'invoicing' ),
1145
-                ucfirst( $invoice->get_invoice_quote_type() )
1144
+                __('%s Date', 'invoicing'),
1145
+                ucfirst($invoice->get_invoice_quote_type())
1146 1146
             ),
1147
-            'value' => getpaid_format_date( $invoice->get_created_date() ),
1147
+            'value' => getpaid_format_date($invoice->get_created_date()),
1148 1148
         ),
1149 1149
 
1150 1150
         'date_paid' => array(
1151
-            'label' => __( 'Paid On', 'invoicing' ),
1152
-            'value' => getpaid_format_date( $invoice->get_completed_date() ),
1151
+            'label' => __('Paid On', 'invoicing'),
1152
+            'value' => getpaid_format_date($invoice->get_completed_date()),
1153 1153
         ),
1154 1154
 
1155 1155
         'gateway'   => array(
1156
-            'label' => __( 'Payment Method', 'invoicing' ),
1157
-            'value' => sanitize_text_field( $invoice->get_gateway_title() ),
1156
+            'label' => __('Payment Method', 'invoicing'),
1157
+            'value' => sanitize_text_field($invoice->get_gateway_title()),
1158 1158
         ),
1159 1159
 
1160 1160
         'transaction_id' => array(
1161
-            'label' => __( 'Transaction ID', 'invoicing' ),
1162
-            'value' => sanitize_text_field( $invoice->get_transaction_id() ),
1161
+            'label' => __('Transaction ID', 'invoicing'),
1162
+            'value' => sanitize_text_field($invoice->get_transaction_id()),
1163 1163
         ),
1164 1164
 
1165 1165
         'due_date'  => array(
1166
-            'label' => __( 'Due Date', 'invoicing' ),
1167
-            'value' => getpaid_format_date( $invoice->get_due_date() ),
1166
+            'label' => __('Due Date', 'invoicing'),
1167
+            'value' => getpaid_format_date($invoice->get_due_date()),
1168 1168
         ),
1169 1169
 
1170 1170
         'vat_number' => array(
1171
-            'label' => __( 'VAT Number', 'invoicing' ),
1172
-            'value' => sanitize_text_field( $invoice->get_vat_number() ),
1171
+            'label' => __('VAT Number', 'invoicing'),
1172
+            'value' => sanitize_text_field($invoice->get_vat_number()),
1173 1173
         ),
1174 1174
 
1175 1175
     );
1176 1176
 
1177 1177
     // If it is not paid, remove the date of payment.
1178
-    if ( ! $invoice->is_paid() ) {
1179
-        unset( $meta[ 'date_paid' ] );
1180
-        unset( $meta[ 'transaction_id' ] );
1178
+    if (!$invoice->is_paid()) {
1179
+        unset($meta['date_paid']);
1180
+        unset($meta['transaction_id']);
1181 1181
     }
1182 1182
 
1183
-    if ( ! $invoice->is_paid() || 'none' == $invoice->get_gateway() ) {
1184
-        unset( $meta[ 'gateway' ] );
1183
+    if (!$invoice->is_paid() || 'none' == $invoice->get_gateway()) {
1184
+        unset($meta['gateway']);
1185 1185
     }
1186 1186
 
1187 1187
     // Only display the due date if due dates are enabled.
1188
-    if ( ! $invoice->needs_payment() || ! wpinv_get_option( 'overdue_active' ) ) {
1189
-        unset( $meta[ 'due_date' ] );
1188
+    if (!$invoice->needs_payment() || !wpinv_get_option('overdue_active')) {
1189
+        unset($meta['due_date']);
1190 1190
     }
1191 1191
 
1192 1192
     // Only display the vat number if taxes are enabled.
1193
-    if ( ! wpinv_use_taxes() ) {
1194
-        unset( $meta[ 'vat_number' ] );
1193
+    if (!wpinv_use_taxes()) {
1194
+        unset($meta['vat_number']);
1195 1195
     }
1196 1196
 
1197
-    if ( $invoice->is_recurring() ) {
1197
+    if ($invoice->is_recurring()) {
1198 1198
 
1199 1199
         // Link to the parent invoice.
1200
-        if ( $invoice->is_renewal() ) {
1200
+        if ($invoice->is_renewal()) {
1201 1201
 
1202
-            $meta[ 'parent' ] = array(
1202
+            $meta['parent'] = array(
1203 1203
 
1204 1204
                 'label' => sprintf(
1205
-                    __( 'Parent %s', 'invoicing' ),
1206
-                    ucfirst( $invoice->get_invoice_quote_type() )
1205
+                    __('Parent %s', 'invoicing'),
1206
+                    ucfirst($invoice->get_invoice_quote_type())
1207 1207
                 ),
1208 1208
 
1209
-                'value' => wpinv_invoice_link( $invoice->get_parent_id() ),
1209
+                'value' => wpinv_invoice_link($invoice->get_parent_id()),
1210 1210
 
1211 1211
             );
1212 1212
 
1213 1213
         }
1214 1214
 
1215
-        $subscription = wpinv_get_subscription( $invoice );
1215
+        $subscription = wpinv_get_subscription($invoice);
1216 1216
 
1217 1217
         // Check is it one time payment
1218
-		$item = new WPInv_Item( $subscription->get_product_id() );
1218
+		$item = new WPInv_Item($subscription->get_product_id());
1219 1219
 		$is_one_time_payment = $item->is_one_time_recurring();
1220 1220
         
1221
-        if ( ! empty ( $subscription ) ) {
1221
+        if (!empty ($subscription)) {
1222 1222
 
1223 1223
             // Display the renewal date.
1224
-            if ( $subscription->is_active() && 'cancelled' != $subscription->get_status() && $is_one_time_payment != 1 ) {
1224
+            if ($subscription->is_active() && 'cancelled' != $subscription->get_status() && $is_one_time_payment != 1) {
1225 1225
 
1226
-                $meta[ 'renewal_date' ] = array(
1226
+                $meta['renewal_date'] = array(
1227 1227
 
1228
-                    'label' => __( 'Renews On', 'invoicing' ),
1229
-                    'value' => getpaid_format_date( $subscription->get_expiration() ),
1228
+                    'label' => __('Renews On', 'invoicing'),
1229
+                    'value' => getpaid_format_date($subscription->get_expiration()),
1230 1230
         
1231 1231
                 ); 
1232 1232
 
1233 1233
             }
1234 1234
 
1235
-            if ( $invoice->is_parent() && $is_one_time_payment != 1) {
1235
+            if ($invoice->is_parent() && $is_one_time_payment != 1) {
1236 1236
 
1237 1237
                 // Display the recurring amount.
1238
-                $meta[ 'recurring_total' ] = array(
1238
+                $meta['recurring_total'] = array(
1239 1239
 
1240
-                    'label' => __( 'Recurring Amount', 'invoicing' ),
1241
-                    'value' => wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ),
1240
+                    'label' => __('Recurring Amount', 'invoicing'),
1241
+                    'value' => wpinv_price($subscription->get_recurring_amount(), $invoice->get_currency()),
1242 1242
         
1243 1243
                 );
1244 1244
 
@@ -1248,15 +1248,15 @@  discard block
 block discarded – undo
1248 1248
     }
1249 1249
 
1250 1250
     // Add the invoice total to the meta.
1251
-    $meta[ 'invoice_total' ] = array(
1251
+    $meta['invoice_total'] = array(
1252 1252
 
1253
-        'label' => __( 'Total Amount', 'invoicing' ),
1254
-        'value' => wpinv_price( $invoice->get_total(), $invoice->get_currency() ),
1253
+        'label' => __('Total Amount', 'invoicing'),
1254
+        'value' => wpinv_price($invoice->get_total(), $invoice->get_currency()),
1255 1255
 
1256 1256
     );
1257 1257
 
1258 1258
     // Provide a way for third party plugins to filter the meta.
1259
-    $meta = apply_filters( 'getpaid_invoice_meta_data', $meta, $invoice );
1259
+    $meta = apply_filters('getpaid_invoice_meta_data', $meta, $invoice);
1260 1260
 
1261 1261
     return $meta;
1262 1262
 
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-item-details.php 2 patches
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  */
9 9
 
10 10
 if ( ! defined( 'ABSPATH' ) ) {
11
-	exit; // Exit if accessed directly
11
+    exit; // Exit if accessed directly
12 12
 }
13 13
 
14 14
 /**
@@ -17,10 +17,10 @@  discard block
 block discarded – undo
17 17
 class GetPaid_Meta_Box_Item_Details {
18 18
 
19 19
     /**
20
-	 * Output the metabox.
21
-	 *
22
-	 * @param WP_Post $post
23
-	 */
20
+     * Output the metabox.
21
+     *
22
+     * @param WP_Post $post
23
+     */
24 24
     public static function output( $post ) {
25 25
 
26 26
         // Prepare the item.
@@ -321,39 +321,39 @@  discard block
 block discarded – undo
321 321
     }
322 322
 
323 323
     /**
324
-	 * Save meta box data.
325
-	 *
326
-	 * @param int $post_id
327
-	 */
328
-	public static function save( $post_id ) {
324
+     * Save meta box data.
325
+     *
326
+     * @param int $post_id
327
+     */
328
+    public static function save( $post_id ) {
329 329
 
330 330
         // Prepare the item.
331 331
         $item = new WPInv_Item( $post_id );
332 332
         
333 333
         // Load new data.
334 334
         $item->set_props(
335
-			array(
336
-				'price'                => isset( $_POST['wpinv_item_price'] ) ? (float) $_POST['wpinv_item_price'] : null,
337
-				'vat_rule'             => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null,
338
-				'vat_class'            => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null,
339
-				'type'                 => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null,
340
-				'is_dynamic_pricing'   => isset( $_POST['wpinv_name_your_price'] ),
335
+            array(
336
+                'price'                => isset( $_POST['wpinv_item_price'] ) ? (float) $_POST['wpinv_item_price'] : null,
337
+                'vat_rule'             => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null,
338
+                'vat_class'            => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null,
339
+                'type'                 => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null,
340
+                'is_dynamic_pricing'   => isset( $_POST['wpinv_name_your_price'] ),
341 341
                 'minimum_price'        => isset( $_POST['wpinv_minimum_price'] ) ? (float) $_POST['wpinv_minimum_price'] : null,
342
-				'is_recurring'         => isset( $_POST['wpinv_is_recurring'] ),
342
+                'is_recurring'         => isset( $_POST['wpinv_is_recurring'] ),
343 343
                 'is_one_time_recurring' => isset( $_POST['wpinv_is_one_time_recurring'] ) ? (int) $_POST['wpinv_is_one_time_recurring']  : 0,
344
-				'recurring_period'     => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null,
345
-				'recurring_interval'   => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : null,
344
+                'recurring_period'     => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null,
345
+                'recurring_interval'   => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : null,
346 346
 
347
-				'recurring_limit'      => isset( $_POST['wpinv_recurring_limit'] ) ? ((isset( $_POST['wpinv_is_one_time_recurring'] )) ? 1 : (int) $_POST['wpinv_recurring_limit'] ) : null,
347
+                'recurring_limit'      => isset( $_POST['wpinv_recurring_limit'] ) ? ((isset( $_POST['wpinv_is_one_time_recurring'] )) ? 1 : (int) $_POST['wpinv_recurring_limit'] ) : null,
348 348
 
349
-				'is_free_trial'        => isset( $_POST['wpinv_trial_interval'] ) ? ((isset( $_POST['wpinv_is_one_time_recurring'] )) ? 0 : ( 0 != (int) $_POST['wpinv_trial_interval'] ) )  : null,
349
+                'is_free_trial'        => isset( $_POST['wpinv_trial_interval'] ) ? ((isset( $_POST['wpinv_is_one_time_recurring'] )) ? 0 : ( 0 != (int) $_POST['wpinv_trial_interval'] ) )  : null,
350 350
 
351
-				'trial_period'         => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null,
352
-				'trial_interval'       => isset( $_POST['wpinv_trial_interval'] )  ? ((isset( $_POST['wpinv_is_one_time_recurring'] )) ? 0 : (int) $_POST['wpinv_trial_interval'] ) : null,
353
-			)
351
+                'trial_period'         => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null,
352
+                'trial_interval'       => isset( $_POST['wpinv_trial_interval'] )  ? ((isset( $_POST['wpinv_is_one_time_recurring'] )) ? 0 : (int) $_POST['wpinv_trial_interval'] ) : null,
353
+            )
354 354
         );
355 355
 
356
-		$item->save();
357
-		do_action( 'getpaid_item_metabox_save', $post_id, $item );
358
-	}
356
+        $item->save();
357
+        do_action( 'getpaid_item_metabox_save', $post_id, $item );
358
+    }
359 359
 }
Please login to merge, or discard this patch.
Spacing   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  *
8 8
  */
9 9
 
10
-if ( ! defined( 'ABSPATH' ) ) {
10
+if (!defined('ABSPATH')) {
11 11
 	exit; // Exit if accessed directly
12 12
 }
13 13
 
@@ -21,27 +21,27 @@  discard block
 block discarded – undo
21 21
 	 *
22 22
 	 * @param WP_Post $post
23 23
 	 */
24
-    public static function output( $post ) {
24
+    public static function output($post) {
25 25
 
26 26
         // Prepare the item.
27
-        $item = new WPInv_Item( $post );
27
+        $item = new WPInv_Item($post);
28 28
 
29 29
         // Nonce field.
30
-        wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' );
30
+        wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce');
31 31
 
32 32
         // Set the currency position.
33 33
         $position = wpinv_currency_position();
34 34
 
35
-        if ( $position == 'left_space' ) {
35
+        if ($position == 'left_space') {
36 36
             $position = 'left';
37 37
         }
38 38
 
39
-        if ( $position == 'right_space' ) {
39
+        if ($position == 'right_space') {
40 40
             $position = 'right';
41 41
         }
42 42
 
43 43
         ?>
44
-        <input type="hidden" id="_wpi_current_type" value="<?php echo esc_attr( $item->get_type( 'edit' ) ); ?>" />
44
+        <input type="hidden" id="_wpi_current_type" value="<?php echo esc_attr($item->get_type('edit')); ?>" />
45 45
         <style>
46 46
             #poststuff .input-group-text,
47 47
             #poststuff .form-control {
@@ -55,21 +55,21 @@  discard block
 block discarded – undo
55 55
         </style>
56 56
         <div class='bsui' style='max-width: 600px;padding-top: 10px;'>
57 57
 
58
-            <?php do_action( 'wpinv_item_details_metabox_before_price', $item ); ?>
58
+            <?php do_action('wpinv_item_details_metabox_before_price', $item); ?>
59 59
             <div class="form-group row">
60
-                <label class="col-sm-3 col-form-label" for="wpinv_item_price"><span><?php _e( 'Item Price', 'invoicing' )?></span></label>
60
+                <label class="col-sm-3 col-form-label" for="wpinv_item_price"><span><?php _e('Item Price', 'invoicing')?></span></label>
61 61
                 <div class="col-sm-8">
62 62
                     <div class="row">
63 63
                         <div class="col-sm-4 getpaid-price-input">
64 64
                             <div class="input-group input-group-sm">
65
-                                <?php if( 'left' == $position ) : ?>
65
+                                <?php if ('left' == $position) : ?>
66 66
                                 <div class="input-group-prepend">
67 67
                                     <span class="input-group-text" id="wpinv_item_price_symbol"><?php echo wpinv_currency_symbol(); ?></span>
68 68
                                 </div>
69 69
                                 <?php endif; ?>
70
-                                <input type="text" name="wpinv_item_price" id="wpinv_item_price" value="<?php echo esc_attr( $item->get_price( 'edit' ) ); ?>" placeholder="<?php echo esc_attr( wpinv_sanitize_amount( 0 ) ); ?>" class="form-control">
70
+                                <input type="text" name="wpinv_item_price" id="wpinv_item_price" value="<?php echo esc_attr($item->get_price('edit')); ?>" placeholder="<?php echo esc_attr(wpinv_sanitize_amount(0)); ?>" class="form-control">
71 71
 
72
-                                <?php if( 'left' != $position ) : ?>
72
+                                <?php if ('left' != $position) : ?>
73 73
                                 <div class="input-group-append">
74 74
                                     <span class="input-group-text" id="wpinv_item_price_symbol"><?php echo wpinv_currency_symbol(); ?></span>
75 75
                                 </div>
@@ -83,25 +83,25 @@  discard block
 block discarded – undo
83 83
                                     array(
84 84
                                         'id'               => 'wpinv_recurring_interval',
85 85
                                         'name'             => 'wpinv_recurring_interval',
86
-                                        'label'            => __( 'Interval', 'invoicing' ),
87
-                                        'placeholder'      => __( 'Select Interval', 'invoicing' ),
88
-                                        'value'            => $item->get_recurring_interval( 'edit' ),
86
+                                        'label'            => __('Interval', 'invoicing'),
87
+                                        'placeholder'      => __('Select Interval', 'invoicing'),
88
+                                        'value'            => $item->get_recurring_interval('edit'),
89 89
                                         'select2'          => true,
90 90
                                         'data-allow-clear' => 'false',
91 91
                                         'options'          => array(
92
-                                            '1'  => __( 'every', 'invoicing' ),
93
-                                            '2'  => __( 'every 2nd', 'invoicing' ),
94
-                                            '3'  => __( 'every 3rd', 'invoicing' ),
95
-                                            '4'  => __( 'every 4th', 'invoicing' ),
96
-                                            '5'  => __( 'every 5th', 'invoicing' ),
97
-                                            '6'  => __( 'every 6th', 'invoicing' ),
98
-                                            '8'  => __( 'every 8th', 'invoicing' ),
99
-                                            '9'  => __( 'every 9th', 'invoicing' ),
100
-                                            '10' => __( 'every 10th', 'invoicing' ),
101
-                                            '11' => __( 'every 11th', 'invoicing' ),
102
-                                            '12' => __( 'every 12th', 'invoicing' ),
103
-                                            '13' => __( 'every 13th', 'invoicing' ),
104
-                                            '14' => __( 'every 14th', 'invoicing' ),
92
+                                            '1'  => __('every', 'invoicing'),
93
+                                            '2'  => __('every 2nd', 'invoicing'),
94
+                                            '3'  => __('every 3rd', 'invoicing'),
95
+                                            '4'  => __('every 4th', 'invoicing'),
96
+                                            '5'  => __('every 5th', 'invoicing'),
97
+                                            '6'  => __('every 6th', 'invoicing'),
98
+                                            '8'  => __('every 8th', 'invoicing'),
99
+                                            '9'  => __('every 9th', 'invoicing'),
100
+                                            '10' => __('every 10th', 'invoicing'),
101
+                                            '11' => __('every 11th', 'invoicing'),
102
+                                            '12' => __('every 12th', 'invoicing'),
103
+                                            '13' => __('every 13th', 'invoicing'),
104
+                                            '14' => __('every 14th', 'invoicing'),
105 105
                                         )
106 106
                                     )
107 107
                                 );
@@ -113,16 +113,16 @@  discard block
 block discarded – undo
113 113
                                     array(
114 114
                                         'id'               => 'wpinv_recurring_period',
115 115
                                         'name'             => 'wpinv_recurring_period',
116
-                                        'label'            => __( 'Period', 'invoicing' ),
117
-                                        'placeholder'      => __( 'Select Period', 'invoicing' ),
118
-                                        'value'            => $item->get_recurring_period( 'edit' ),
116
+                                        'label'            => __('Period', 'invoicing'),
117
+                                        'placeholder'      => __('Select Period', 'invoicing'),
118
+                                        'value'            => $item->get_recurring_period('edit'),
119 119
                                         'select2'          => true,
120 120
                                         'data-allow-clear' => 'false',
121 121
                                         'options'     => array(
122
-                                            'D'  => __( 'day', 'invoicing' ),
123
-                                            'W'  => __( 'week', 'invoicing' ),
124
-                                            'M'  => __( 'month', 'invoicing' ),
125
-                                            'Y'  => __( 'year', 'invoicing' ),
122
+                                            'D'  => __('day', 'invoicing'),
123
+                                            'W'  => __('week', 'invoicing'),
124
+                                            'M'  => __('month', 'invoicing'),
125
+                                            'Y'  => __('year', 'invoicing'),
126 126
                                         )
127 127
                                     )
128 128
                                 );
@@ -134,9 +134,9 @@  discard block
 block discarded – undo
134 134
                             <?php
135 135
 
136 136
                                 // Dynamic pricing.
137
-                                if( $item->supports_dynamic_pricing() ) {
137
+                                if ($item->supports_dynamic_pricing()) {
138 138
 
139
-                                    do_action( 'wpinv_item_details_metabox_before_dynamic_pricing_checkbox', $item );
139
+                                    do_action('wpinv_item_details_metabox_before_dynamic_pricing_checkbox', $item);
140 140
 
141 141
                                     // NYP toggle.
142 142
                                     echo aui()->input(
@@ -144,31 +144,31 @@  discard block
 block discarded – undo
144 144
                                             'id'          => 'wpinv_name_your_price',
145 145
                                             'name'        => 'wpinv_name_your_price',
146 146
                                             'type'        => 'checkbox',
147
-                                            'label'       => apply_filters( 'wpinv_name_your_price_toggle_text', __( 'Let customers name their price', 'invoicing' ) ),
147
+                                            'label'       => apply_filters('wpinv_name_your_price_toggle_text', __('Let customers name their price', 'invoicing')),
148 148
                                             'value'       => '1',
149 149
                                             'checked'     => $item->user_can_set_their_price(),
150 150
                                             'no_wrap'     => true,
151 151
                                         )
152 152
                                     );
153 153
 
154
-                                    do_action( 'wpinv_item_details_metabox_dynamic_pricing_checkbox', $item );
154
+                                    do_action('wpinv_item_details_metabox_dynamic_pricing_checkbox', $item);
155 155
 
156 156
                                 }
157 157
 
158 158
                                 // Subscriptions.
159
-                                do_action( 'wpinv_item_details_metabox_before_subscription_checkbox', $item );
159
+                                do_action('wpinv_item_details_metabox_before_subscription_checkbox', $item);
160 160
                                 echo aui()->input(
161 161
                                     array(
162 162
                                         'id'          => 'wpinv_is_recurring',
163 163
                                         'name'        => 'wpinv_is_recurring',
164 164
                                         'type'        => 'checkbox',
165
-                                        'label'       => apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Charge customers a recurring amount for this item', 'invoicing' ) ),
165
+                                        'label'       => apply_filters('wpinv_is_recurring_toggle_text', __('Charge customers a recurring amount for this item', 'invoicing')),
166 166
                                         'value'       => '1',
167 167
                                         'checked'     => $item->is_recurring(),
168 168
                                         'no_wrap'     => true,
169 169
                                     )
170 170
                                 );
171
-                                do_action( 'wpinv_item_details_metabox_subscription_checkbox', $item );
171
+                                do_action('wpinv_item_details_metabox_subscription_checkbox', $item);
172 172
 
173 173
                             ?>
174 174
                             <div class="wpinv_show_if_recurring">
@@ -178,30 +178,30 @@  discard block
 block discarded – undo
178 178
                     </div>
179 179
                 </div>
180 180
                 <div class="col-sm-1 pt-2 pl-0">
181
-                    <span class="wpi-help-tip dashicons dashicons-editor-help wpinv_show_if_recurring" title="<?php esc_attr_e( 'Set the subscription price, billing interval and period.', 'invoicing' ); ?>"></span>
181
+                    <span class="wpi-help-tip dashicons dashicons-editor-help wpinv_show_if_recurring" title="<?php esc_attr_e('Set the subscription price, billing interval and period.', 'invoicing'); ?>"></span>
182 182
                 </div>
183 183
             </div>
184
-            <?php do_action( 'wpinv_item_details_metabox_after_price', $item ); ?>
184
+            <?php do_action('wpinv_item_details_metabox_after_price', $item); ?>
185 185
 
186
-            <?php if( $item->supports_dynamic_pricing() ) : ?>
187
-                <?php do_action( 'wpinv_item_details_metabox_before_minimum_price', $item ); ?>
186
+            <?php if ($item->supports_dynamic_pricing()) : ?>
187
+                <?php do_action('wpinv_item_details_metabox_before_minimum_price', $item); ?>
188 188
                 <div class="wpinv_show_if_dynamic wpinv_minimum_price">
189 189
 
190 190
                     <div class="form-group row">
191 191
                         <label for="wpinv_minimum_price" class="col-sm-3 col-form-label">
192
-                            <?php _e( 'Minimum Price', 'invoicing' );?>
192
+                            <?php _e('Minimum Price', 'invoicing'); ?>
193 193
                         </label>
194 194
                         <div class="col-sm-8">
195 195
                             <div class="input-group input-group-sm">
196
-                                <?php if( 'left' == $position ) : ?>
196
+                                <?php if ('left' == $position) : ?>
197 197
                                     <div class="input-group-prepend">
198 198
                                         <span class="input-group-text" id="wpinv_item_minimum_price_symbol"><?php echo wpinv_currency_symbol(); ?></span>
199 199
                                     </div>
200 200
                                 <?php endif; ?>
201 201
 
202
-                                <input type="text" name="wpinv_minimum_price" id="wpinv_minimum_price" value="<?php echo esc_attr( $item->get_minimum_price( 'edit' ) ); ?>" placeholder="<?php echo esc_attr( wpinv_sanitize_amount( 0 ) ); ?>" class="form-control">
202
+                                <input type="text" name="wpinv_minimum_price" id="wpinv_minimum_price" value="<?php echo esc_attr($item->get_minimum_price('edit')); ?>" placeholder="<?php echo esc_attr(wpinv_sanitize_amount(0)); ?>" class="form-control">
203 203
 
204
-                                <?php if( 'left' != $position ) : ?>
204
+                                <?php if ('left' != $position) : ?>
205 205
                                     <div class="input-group-append">
206 206
                                         <span class="input-group-text" id="wpinv_item_minimum_price_symbol"><?php echo wpinv_currency_symbol(); ?></span>
207 207
                                     </div>
@@ -210,22 +210,22 @@  discard block
 block discarded – undo
210 210
                         </div>
211 211
 
212 212
                         <div class="col-sm-1 pt-2 pl-0">
213
-                            <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter the minimum amount that users are allowed to set', 'invoicing' ); ?>"></span>
213
+                            <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Enter the minimum amount that users are allowed to set', 'invoicing'); ?>"></span>
214 214
                         </div>
215 215
                     </div>
216 216
 
217 217
                 </div>
218
-                <?php do_action( 'wpinv_item_details_metabox_minimum_price', $item ); ?>
218
+                <?php do_action('wpinv_item_details_metabox_minimum_price', $item); ?>
219 219
             <?php endif; ?>
220 220
 
221 221
             <?php
222 222
             // one time Subscriptions.
223
-            do_action( 'wpinv_item_details_metabox_before_one_time_subscription_checkbox', $item );
223
+            do_action('wpinv_item_details_metabox_before_one_time_subscription_checkbox', $item);
224 224
             ?>
225 225
             <div class="wpinv_show_if_recurring wpinv_one_time_recurring">
226 226
                 <div class="form-group row">
227 227
                     <label for="wpinv_is_one_time_recurring" class="col-sm-3 col-form-label">
228
-                        <?php _e( 'One time only (non-recurring)?', 'invoicing' );?>
228
+                        <?php _e('One time only (non-recurring)?', 'invoicing'); ?>
229 229
                     </label> 
230 230
                     
231 231
                     <div class="col-sm-8">
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
                                     <input type="checkbox" value="1" <?php echo ($item->is_one_time_recurring()) ? 'checked' : ''; ?> class="form-control  custom-control-input"  name="wpinv_is_one_time_recurring" id="wpinv_is_one_time_recurring" /><label for="wpinv_is_one_time_recurring" class=" custom-control-label">Change customers a recurring amount for one time only.</label>
236 236
                                 </div>
237 237
                                 <div class="wpinv_show_if_recurring">
238
-                                    <em><span class="form-text text-muted"><?php echo apply_filters( 'wpinv_is_one_time_recurring_toggle_help_text', __( 'It will appear as a recurring payment, at the next renewal date it will complete the subscription without any deductions.', 'invoicing' ) ) ?></span></em>
238
+                                    <em><span class="form-text text-muted"><?php echo apply_filters('wpinv_is_one_time_recurring_toggle_help_text', __('It will appear as a recurring payment, at the next renewal date it will complete the subscription without any deductions.', 'invoicing')) ?></span></em>
239 239
                                 </div>
240 240
                             </div>
241 241
                         </div>
@@ -243,40 +243,40 @@  discard block
 block discarded – undo
243 243
                 </div>
244 244
             </div>
245 245
             <?php
246
-            do_action( 'wpinv_item_details_metabox_one_time_subscription_checkbox', $item );
246
+            do_action('wpinv_item_details_metabox_one_time_subscription_checkbox', $item);
247 247
             ?>
248 248
 
249
-            <?php do_action( 'wpinv_item_details_metabox_before_maximum_renewals', $item ); ?>
249
+            <?php do_action('wpinv_item_details_metabox_before_maximum_renewals', $item); ?>
250 250
             <div class="wpinv_show_if_recurring wpinv_maximum_renewals">
251 251
 
252 252
                 <div class="form-group row">
253 253
                     <label for="wpinv_recurring_limit" class="col-sm-3 col-form-label">
254
-                        <?php _e( 'Maximum Renewals', 'invoicing' );?>
254
+                        <?php _e('Maximum Renewals', 'invoicing'); ?>
255 255
                     </label>
256 256
                     <div class="col-sm-8">
257
-                        <input type="number" value="<?php echo esc_attr( $item->get_recurring_limit( 'edit' ) ); ?>" placeholder="0" name="wpinv_recurring_limit" id="wpinv_recurring_limit" style="width: 100%;" />
257
+                        <input type="number" value="<?php echo esc_attr($item->get_recurring_limit('edit')); ?>" placeholder="0" name="wpinv_recurring_limit" id="wpinv_recurring_limit" style="width: 100%;" />
258 258
                     </div>
259 259
                     <div class="col-sm-1 pt-2 pl-0">
260
-                        <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Leave empty if you want the subscription to renew until it is cancelled.', 'invoicing' ); ?>"></span>
260
+                        <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Leave empty if you want the subscription to renew until it is cancelled.', 'invoicing'); ?>"></span>
261 261
                     </div>
262 262
                 </div>
263 263
 
264 264
             </div>
265
-            <?php do_action( 'wpinv_item_details_metabox_maximum_renewals', $item ); ?>
265
+            <?php do_action('wpinv_item_details_metabox_maximum_renewals', $item); ?>
266 266
 
267
-            <?php do_action( 'wpinv_item_details_metabox_before_free_trial', $item ); ?>
267
+            <?php do_action('wpinv_item_details_metabox_before_free_trial', $item); ?>
268 268
             <div class="wpinv_show_if_recurring wpinv_free_trial">
269 269
 
270 270
                 <div class="form-group row">
271
-                    <label class="col-sm-3 col-form-label" for="wpinv_trial_interval"><?php _e( 'Free Trial', 'invoicing' )?></label>
271
+                    <label class="col-sm-3 col-form-label" for="wpinv_trial_interval"><?php _e('Free Trial', 'invoicing')?></label>
272 272
 
273 273
                     <div class="col-sm-8">
274 274
                         <div class="row">
275 275
                             <div class="col-sm-6">
276
-                                <?php $value = $item->has_free_trial() ? $item->get_trial_interval( 'edit' ) : 0;?>
276
+                                <?php $value = $item->has_free_trial() ? $item->get_trial_interval('edit') : 0; ?>
277 277
 
278 278
                                 <div>
279
-                                    <input type="number" name="wpinv_trial_interval" style="width: 100%;" placeholder="0" id="wpinv_trial_interval" value="<?php echo esc_attr( $value ); ?>" >
279
+                                    <input type="number" name="wpinv_trial_interval" style="width: 100%;" placeholder="0" id="wpinv_trial_interval" value="<?php echo esc_attr($value); ?>" >
280 280
                                 </div>
281 281
                             </div>
282 282
                             <div class="col-sm-6">
@@ -285,17 +285,17 @@  discard block
 block discarded – undo
285 285
                                         array(
286 286
                                             'id'               => 'wpinv_trial_period',
287 287
                                             'name'             => 'wpinv_trial_period',
288
-                                            'label'            => __( 'Trial Period', 'invoicing' ),
289
-                                            'placeholder'      => __( 'Trial Period', 'invoicing' ),
290
-                                            'value'            => $item->get_trial_period( 'edit' ),
288
+                                            'label'            => __('Trial Period', 'invoicing'),
289
+                                            'placeholder'      => __('Trial Period', 'invoicing'),
290
+                                            'value'            => $item->get_trial_period('edit'),
291 291
                                             'select2'          => true,
292 292
                                             'data-allow-clear' => 'false',
293 293
                                             'no_wrap'          => true,
294 294
                                             'options'          => array(
295
-                                                'D'  => __( 'day(s)', 'invoicing' ),
296
-                                                'W'  => __( 'week(s)', 'invoicing' ),
297
-                                                'M'  => __( 'month(s)', 'invoicing' ),
298
-                                                'Y'  => __( 'year(s)', 'invoicing' ),
295
+                                                'D'  => __('day(s)', 'invoicing'),
296
+                                                'W'  => __('week(s)', 'invoicing'),
297
+                                                'M'  => __('month(s)', 'invoicing'),
298
+                                                'Y'  => __('year(s)', 'invoicing'),
299 299
                                             )
300 300
                                         )
301 301
                                     );
@@ -306,15 +306,15 @@  discard block
 block discarded – undo
306 306
                     </div>
307 307
 
308 308
                     <div class="col-sm-1 pt-2 pl-0">
309
-                        <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'An optional period of time to wait before charging the first recurring payment.', 'invoicing' ); ?>"></span>
309
+                        <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('An optional period of time to wait before charging the first recurring payment.', 'invoicing'); ?>"></span>
310 310
                     </div>
311 311
 
312 312
                 </div>
313 313
 
314 314
             </div>
315
-            <?php do_action( 'wpinv_item_details_metabox__free_trial', $item ); ?>
315
+            <?php do_action('wpinv_item_details_metabox__free_trial', $item); ?>
316 316
 
317
-            <?php do_action( 'wpinv_item_details_metabox_item_details', $item ); ?>
317
+            <?php do_action('wpinv_item_details_metabox_item_details', $item); ?>
318 318
         </div>
319 319
         <?php
320 320
 
@@ -325,35 +325,35 @@  discard block
 block discarded – undo
325 325
 	 *
326 326
 	 * @param int $post_id
327 327
 	 */
328
-	public static function save( $post_id ) {
328
+	public static function save($post_id) {
329 329
 
330 330
         // Prepare the item.
331
-        $item = new WPInv_Item( $post_id );
331
+        $item = new WPInv_Item($post_id);
332 332
         
333 333
         // Load new data.
334 334
         $item->set_props(
335 335
 			array(
336
-				'price'                => isset( $_POST['wpinv_item_price'] ) ? (float) $_POST['wpinv_item_price'] : null,
337
-				'vat_rule'             => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null,
338
-				'vat_class'            => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null,
339
-				'type'                 => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null,
340
-				'is_dynamic_pricing'   => isset( $_POST['wpinv_name_your_price'] ),
341
-                'minimum_price'        => isset( $_POST['wpinv_minimum_price'] ) ? (float) $_POST['wpinv_minimum_price'] : null,
342
-				'is_recurring'         => isset( $_POST['wpinv_is_recurring'] ),
343
-                'is_one_time_recurring' => isset( $_POST['wpinv_is_one_time_recurring'] ) ? (int) $_POST['wpinv_is_one_time_recurring']  : 0,
344
-				'recurring_period'     => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null,
345
-				'recurring_interval'   => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : null,
346
-
347
-				'recurring_limit'      => isset( $_POST['wpinv_recurring_limit'] ) ? ((isset( $_POST['wpinv_is_one_time_recurring'] )) ? 1 : (int) $_POST['wpinv_recurring_limit'] ) : null,
348
-
349
-				'is_free_trial'        => isset( $_POST['wpinv_trial_interval'] ) ? ((isset( $_POST['wpinv_is_one_time_recurring'] )) ? 0 : ( 0 != (int) $_POST['wpinv_trial_interval'] ) )  : null,
350
-
351
-				'trial_period'         => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null,
352
-				'trial_interval'       => isset( $_POST['wpinv_trial_interval'] )  ? ((isset( $_POST['wpinv_is_one_time_recurring'] )) ? 0 : (int) $_POST['wpinv_trial_interval'] ) : null,
336
+				'price'                => isset($_POST['wpinv_item_price']) ? (float) $_POST['wpinv_item_price'] : null,
337
+				'vat_rule'             => isset($_POST['wpinv_vat_rules']) ? wpinv_clean($_POST['wpinv_vat_rules']) : null,
338
+				'vat_class'            => isset($_POST['wpinv_vat_class']) ? wpinv_clean($_POST['wpinv_vat_class']) : null,
339
+				'type'                 => isset($_POST['wpinv_item_type']) ? wpinv_clean($_POST['wpinv_item_type']) : null,
340
+				'is_dynamic_pricing'   => isset($_POST['wpinv_name_your_price']),
341
+                'minimum_price'        => isset($_POST['wpinv_minimum_price']) ? (float) $_POST['wpinv_minimum_price'] : null,
342
+				'is_recurring'         => isset($_POST['wpinv_is_recurring']),
343
+                'is_one_time_recurring' => isset($_POST['wpinv_is_one_time_recurring']) ? (int) $_POST['wpinv_is_one_time_recurring'] : 0,
344
+				'recurring_period'     => isset($_POST['wpinv_recurring_period']) ? wpinv_clean($_POST['wpinv_recurring_period']) : null,
345
+				'recurring_interval'   => isset($_POST['wpinv_recurring_interval']) ? (int) $_POST['wpinv_recurring_interval'] : null,
346
+
347
+				'recurring_limit'      => isset($_POST['wpinv_recurring_limit']) ? ((isset($_POST['wpinv_is_one_time_recurring'])) ? 1 : (int) $_POST['wpinv_recurring_limit']) : null,
348
+
349
+				'is_free_trial'        => isset($_POST['wpinv_trial_interval']) ? ((isset($_POST['wpinv_is_one_time_recurring'])) ? 0 : (0 != (int) $_POST['wpinv_trial_interval'])) : null,
350
+
351
+				'trial_period'         => isset($_POST['wpinv_trial_period']) ? wpinv_clean($_POST['wpinv_trial_period']) : null,
352
+				'trial_interval'       => isset($_POST['wpinv_trial_interval']) ? ((isset($_POST['wpinv_is_one_time_recurring'])) ? 0 : (int) $_POST['wpinv_trial_interval']) : null,
353 353
 			)
354 354
         );
355 355
 
356 356
 		$item->save();
357
-		do_action( 'getpaid_item_metabox_save', $post_id, $item );
357
+		do_action('getpaid_item_metabox_save', $post_id, $item);
358 358
 	}
359 359
 }
Please login to merge, or discard this patch.
includes/wpinv-subscription.php 2 patches
Indentation   +1010 added lines, -1010 removed lines patch added patch discarded remove patch
@@ -15,125 +15,125 @@  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
-	/**
66
-	 * Get the subscription if ID is passed, otherwise the subscription is new and empty.
67
-	 *
68
-	 * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
69
-	 * @param  bool $deprecated
70
-	 */
71
-	function __construct( $subscription = 0, $deprecated = false ) {
72
-
73
-		parent::__construct( $subscription );
74
-
75
-		if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
76
-			$this->set_id( $subscription );
77
-		} elseif ( $subscription instanceof self ) {
78
-			$this->set_id( $subscription->get_id() );
79
-		} elseif ( ! empty( $subscription->id ) ) {
80
-			$this->set_id( $subscription->id );
81
-		} elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
82
-			$this->set_id( $subscription_id );
83
-		} else {
84
-			$this->set_object_read( true );
85
-		}
86
-
87
-		// Load the datastore.
88
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
89
-
90
-		if ( $this->get_id() > 0 ) {
91
-			$this->data_store->read( $this );
92
-		}
93
-
94
-	}
95
-
96
-	/**
97
-	 * Given an invoice id, profile id, transaction id, it returns the subscription's id.
98
-	 *
99
-	 *
100
-	 * @static
101
-	 * @param string $value
102
-	 * @param string $field Either invoice_id, transaction_id or profile_id.
103
-	 * @since 1.0.19
104
-	 * @return int
105
-	 */
106
-	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
+    /**
66
+     * Get the subscription if ID is passed, otherwise the subscription is new and empty.
67
+     *
68
+     * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
69
+     * @param  bool $deprecated
70
+     */
71
+    function __construct( $subscription = 0, $deprecated = false ) {
72
+
73
+        parent::__construct( $subscription );
74
+
75
+        if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
76
+            $this->set_id( $subscription );
77
+        } elseif ( $subscription instanceof self ) {
78
+            $this->set_id( $subscription->get_id() );
79
+        } elseif ( ! empty( $subscription->id ) ) {
80
+            $this->set_id( $subscription->id );
81
+        } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
82
+            $this->set_id( $subscription_id );
83
+        } else {
84
+            $this->set_object_read( true );
85
+        }
86
+
87
+        // Load the datastore.
88
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
89
+
90
+        if ( $this->get_id() > 0 ) {
91
+            $this->data_store->read( $this );
92
+        }
93
+
94
+    }
95
+
96
+    /**
97
+     * Given an invoice id, profile id, transaction id, it returns the subscription's id.
98
+     *
99
+     *
100
+     * @static
101
+     * @param string $value
102
+     * @param string $field Either invoice_id, transaction_id or profile_id.
103
+     * @since 1.0.19
104
+     * @return int
105
+     */
106
+    public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
107 107
         global $wpdb;
108 108
 
109
-		// Trim the value.
110
-		$value = trim( $value );
109
+        // Trim the value.
110
+        $value = trim( $value );
111 111
 
112
-		if ( empty( $value ) ) {
113
-			return 0;
114
-		}
112
+        if ( empty( $value ) ) {
113
+            return 0;
114
+        }
115 115
 
116
-		if ( 'invoice_id' == $field ) {
117
-			$field = 'parent_payment_id';
118
-		}
116
+        if ( 'invoice_id' == $field ) {
117
+            $field = 'parent_payment_id';
118
+        }
119 119
 
120 120
         // Valid fields.
121 121
         $fields = array(
122
-			'parent_payment_id',
123
-			'transaction_id',
124
-			'profile_id'
125
-		);
126
-
127
-		// Ensure a field has been passed.
128
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
129
-			return 0;
130
-		}
131
-
132
-		// Maybe retrieve from the cache.
133
-		$subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
134
-		if ( ! empty( $subscription_id ) ) {
135
-			return $subscription_id;
136
-		}
122
+            'parent_payment_id',
123
+            'transaction_id',
124
+            'profile_id'
125
+        );
126
+
127
+        // Ensure a field has been passed.
128
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
129
+            return 0;
130
+        }
131
+
132
+        // Maybe retrieve from the cache.
133
+        $subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
134
+        if ( ! empty( $subscription_id ) ) {
135
+            return $subscription_id;
136
+        }
137 137
 
138 138
         // Fetch from the db.
139 139
         $table            = $wpdb->prefix . 'wpinv_subscriptions';
@@ -141,34 +141,34 @@  discard block
 block discarded – undo
141 141
             $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
142 142
         );
143 143
 
144
-		if ( empty( $subscription_id ) ) {
145
-			return 0;
146
-		}
144
+        if ( empty( $subscription_id ) ) {
145
+            return 0;
146
+        }
147 147
 
148
-		// Update the cache with our data.
149
-		wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
148
+        // Update the cache with our data.
149
+        wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
150 150
 
151
-		return $subscription_id;
152
-	}
151
+        return $subscription_id;
152
+    }
153 153
 
154
-	/**
154
+    /**
155 155
      * Clears the subscription's cache.
156 156
      */
157 157
     public function clear_cache() {
158
-		wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' );
159
-		wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' );
160
-		wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' );
161
-		wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' );
162
-	}
158
+        wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' );
159
+        wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' );
160
+        wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' );
161
+        wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' );
162
+    }
163 163
 
164
-	/**
164
+    /**
165 165
      * Checks if a subscription key is set.
166 166
      */
167 167
     public function _isset( $key ) {
168 168
         return isset( $this->data[$key] ) || method_exists( $this, "get_$key" );
169
-	}
169
+    }
170 170
 
171
-	/*
171
+    /*
172 172
 	|--------------------------------------------------------------------------
173 173
 	| CRUD methods
174 174
 	|--------------------------------------------------------------------------
@@ -177,545 +177,545 @@  discard block
 block discarded – undo
177 177
 	|
178 178
     */
179 179
 
180
-	/*
180
+    /*
181 181
 	|--------------------------------------------------------------------------
182 182
 	| Getters
183 183
 	|--------------------------------------------------------------------------
184 184
 	*/
185 185
 
186
-	/**
187
-	 * Get customer id.
188
-	 *
189
-	 * @since 1.0.19
190
-	 * @param  string $context View or edit context.
191
-	 * @return int
192
-	 */
193
-	public function get_customer_id( $context = 'view' ) {
194
-		return (int) $this->get_prop( 'customer_id', $context );
195
-	}
196
-
197
-	/**
198
-	 * Get customer information.
199
-	 *
200
-	 * @since 1.0.19
201
-	 * @param  string $context View or edit context.
202
-	 * @return WP_User|false WP_User object on success, false on failure.
203
-	 */
204
-	public function get_customer( $context = 'view' ) {
205
-		return get_userdata( $this->get_customer_id( $context ) );
206
-	}
207
-
208
-	/**
209
-	 * Get parent invoice id.
210
-	 *
211
-	 * @since 1.0.19
212
-	 * @param  string $context View or edit context.
213
-	 * @return int
214
-	 */
215
-	public function get_parent_invoice_id( $context = 'view' ) {
216
-		return (int) $this->get_prop( 'parent_payment_id', $context );
217
-	}
218
-
219
-	/**
220
-	 * Alias for self::get_parent_invoice_id().
221
-	 *
222
-	 * @since 1.0.19
223
-	 * @param  string $context View or edit context.
224
-	 * @return int
225
-	 */
186
+    /**
187
+     * Get customer id.
188
+     *
189
+     * @since 1.0.19
190
+     * @param  string $context View or edit context.
191
+     * @return int
192
+     */
193
+    public function get_customer_id( $context = 'view' ) {
194
+        return (int) $this->get_prop( 'customer_id', $context );
195
+    }
196
+
197
+    /**
198
+     * Get customer information.
199
+     *
200
+     * @since 1.0.19
201
+     * @param  string $context View or edit context.
202
+     * @return WP_User|false WP_User object on success, false on failure.
203
+     */
204
+    public function get_customer( $context = 'view' ) {
205
+        return get_userdata( $this->get_customer_id( $context ) );
206
+    }
207
+
208
+    /**
209
+     * Get parent invoice id.
210
+     *
211
+     * @since 1.0.19
212
+     * @param  string $context View or edit context.
213
+     * @return int
214
+     */
215
+    public function get_parent_invoice_id( $context = 'view' ) {
216
+        return (int) $this->get_prop( 'parent_payment_id', $context );
217
+    }
218
+
219
+    /**
220
+     * Alias for self::get_parent_invoice_id().
221
+     *
222
+     * @since 1.0.19
223
+     * @param  string $context View or edit context.
224
+     * @return int
225
+     */
226 226
     public function get_parent_payment_id( $context = 'view' ) {
227 227
         return $this->get_parent_invoice_id( $context );
228
-	}
228
+    }
229 229
 
230
-	/**
230
+    /**
231 231
      * Alias for self::get_parent_invoice_id().
232 232
      *
233
-     * @since  1.0.0
234
-     * @return int
233
+     * @since  1.0.0
234
+     * @return int
235
+     */
236
+    public function get_original_payment_id( $context = 'view' ) {
237
+        return $this->get_parent_invoice_id( $context );
238
+    }
239
+
240
+    /**
241
+     * Get parent invoice.
242
+     *
243
+     * @since 1.0.19
244
+     * @param  string $context View or edit context.
245
+     * @return WPInv_Invoice
246
+     */
247
+    public function get_parent_invoice( $context = 'view' ) {
248
+        return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
249
+    }
250
+
251
+    /**
252
+     * Alias for self::get_parent_invoice().
253
+     *
254
+     * @since 1.0.19
255
+     * @param  string $context View or edit context.
256
+     * @return WPInv_Invoice
257
+     */
258
+    public function get_parent_payment( $context = 'view' ) {
259
+        return $this->get_parent_invoice( $context );
260
+    }
261
+
262
+    /**
263
+     * Get subscription's product id.
264
+     *
265
+     * @since 1.0.19
266
+     * @param  string $context View or edit context.
267
+     * @return int
268
+     */
269
+    public function get_product_id( $context = 'view' ) {
270
+        return (int) $this->get_prop( 'product_id', $context );
271
+    }
272
+
273
+    /**
274
+     * Get the subscription product.
275
+     *
276
+     * @since 1.0.19
277
+     * @param  string $context View or edit context.
278
+     * @return WPInv_Item
279
+     */
280
+    public function get_product( $context = 'view' ) {
281
+        return new WPInv_Item( $this->get_product_id( $context ) );
282
+    }
283
+
284
+    /**
285
+     * Get parent invoice's gateway.
286
+     *
287
+     * Here for backwards compatibility.
288
+     *
289
+     * @since 1.0.19
290
+     * @param  string $context View or edit context.
291
+     * @return string
292
+     */
293
+    public function get_gateway( $context = 'view' ) {
294
+        return $this->get_parent_invoice( $context )->get_gateway();
295
+    }
296
+
297
+    /**
298
+     * Get the period of a renewal.
299
+     *
300
+     * @since 1.0.19
301
+     * @param  string $context View or edit context.
302
+     * @return string
303
+     */
304
+    public function get_period( $context = 'view' ) {
305
+        return $this->get_prop( 'period', $context );
306
+    }
307
+
308
+    /**
309
+     * Get number of periods each renewal is valid for.
310
+     *
311
+     * @since 1.0.19
312
+     * @param  string $context View or edit context.
313
+     * @return int
314
+     */
315
+    public function get_frequency( $context = 'view' ) {
316
+        return (int) $this->get_prop( 'frequency', $context );
317
+    }
318
+
319
+    /**
320
+     * Get the initial amount for the subscription.
321
+     *
322
+     * @since 1.0.19
323
+     * @param  string $context View or edit context.
324
+     * @return float
325
+     */
326
+    public function get_initial_amount( $context = 'view' ) {
327
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
328
+    }
329
+
330
+    /**
331
+     * Get the recurring amount for the subscription.
332
+     *
333
+     * @since 1.0.19
334
+     * @param  string $context View or edit context.
335
+     * @return float
336
+     */
337
+    public function get_recurring_amount( $context = 'view' ) {
338
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
339
+    }
340
+
341
+    /**
342
+     * Get number of times that this subscription can be renewed.
343
+     *
344
+     * @since 1.0.19
345
+     * @param  string $context View or edit context.
346
+     * @return int
347
+     */
348
+    public function get_bill_times( $context = 'view' ) {
349
+        return (int) $this->get_prop( 'bill_times', $context );
350
+    }
351
+
352
+    /**
353
+     * Get transaction id of this subscription's parent invoice.
354
+     *
355
+     * @since 1.0.19
356
+     * @param  string $context View or edit context.
357
+     * @return string
358
+     */
359
+    public function get_transaction_id( $context = 'view' ) {
360
+        return $this->get_prop( 'transaction_id', $context );
361
+    }
362
+
363
+    /**
364
+     * Get the date that the subscription was created.
365
+     *
366
+     * @since 1.0.19
367
+     * @param  string $context View or edit context.
368
+     * @return string
369
+     */
370
+    public function get_created( $context = 'view' ) {
371
+        return $this->get_prop( 'created', $context );
372
+    }
373
+
374
+    /**
375
+     * Alias for self::get_created().
376
+     *
377
+     * @since 1.0.19
378
+     * @param  string $context View or edit context.
379
+     * @return string
380
+     */
381
+    public function get_date_created( $context = 'view' ) {
382
+        return $this->get_created( $context );
383
+    }
384
+
385
+    /**
386
+     * Retrieves the creation date in a timestamp
387
+     *
388
+     * @since  1.0.0
389
+     * @return int
390
+     */
391
+    public function get_time_created() {
392
+        $created = $this->get_date_created();
393
+        return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
394
+    }
395
+
396
+    /**
397
+     * Get GMT date when the subscription was created.
398
+     *
399
+     * @since 1.0.19
400
+     * @param  string $context View or edit context.
401
+     * @return string
402
+     */
403
+    public function get_date_created_gmt( $context = 'view' ) {
404
+        $date = $this->get_date_created( $context );
405
+
406
+        if ( $date ) {
407
+            $date = get_gmt_from_date( $date );
408
+        }
409
+        return $date;
410
+    }
411
+
412
+    /**
413
+     * Get the date that the subscription will renew.
414
+     *
415
+     * @since 1.0.19
416
+     * @param  string $context View or edit context.
417
+     * @return string
418
+     */
419
+    public function get_next_renewal_date( $context = 'view' ) {
420
+        return $this->get_prop( 'expiration', $context );
421
+    }
422
+
423
+    /**
424
+     * Alias for self::get_next_renewal_date().
425
+     *
426
+     * @since 1.0.19
427
+     * @param  string $context View or edit context.
428
+     * @return string
429
+     */
430
+    public function get_expiration( $context = 'view' ) {
431
+        return $this->get_next_renewal_date( $context );
432
+    }
433
+
434
+    /**
435
+     * Retrieves the expiration date in a timestamp
436
+     *
437
+     * @since  1.0.0
438
+     * @return int
439
+     */
440
+    public function get_expiration_time() {
441
+        $expiration = $this->get_expiration();
442
+
443
+        if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
444
+            return current_time( 'timestamp' );
445
+        }
446
+
447
+        $expiration = strtotime( $expiration, current_time( 'timestamp' ) );
448
+        return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
449
+    }
450
+
451
+    /**
452
+     * Get GMT date when the subscription will renew.
453
+     *
454
+     * @since 1.0.19
455
+     * @param  string $context View or edit context.
456
+     * @return string
457
+     */
458
+    public function get_next_renewal_date_gmt( $context = 'view' ) {
459
+        $date = $this->get_next_renewal_date( $context );
460
+
461
+        if ( $date ) {
462
+            $date = get_gmt_from_date( $date );
463
+        }
464
+        return $date;
465
+    }
466
+
467
+    /**
468
+     * Get the subscription's trial period.
469
+     *
470
+     * @since 1.0.19
471
+     * @param  string $context View or edit context.
472
+     * @return string
473
+     */
474
+    public function get_trial_period( $context = 'view' ) {
475
+        return $this->get_prop( 'trial_period', $context );
476
+    }
477
+
478
+    /**
479
+     * Get the subscription's status.
480
+     *
481
+     * @since 1.0.19
482
+     * @param  string $context View or edit context.
483
+     * @return string
484
+     */
485
+    public function get_status( $context = 'view' ) {
486
+        return $this->get_prop( 'status', $context );
487
+    }
488
+
489
+    /**
490
+     * Get the subscription's profile id.
491
+     *
492
+     * @since 1.0.19
493
+     * @param  string $context View or edit context.
494
+     * @return string
495
+     */
496
+    public function get_profile_id( $context = 'view' ) {
497
+        return $this->get_prop( 'profile_id', $context );
498
+    }
499
+
500
+    /*
501
+	|--------------------------------------------------------------------------
502
+	| Setters
503
+	|--------------------------------------------------------------------------
504
+	*/
505
+
506
+    /**
507
+     * Set customer id.
508
+     *
509
+     * @since 1.0.19
510
+     * @param  int $value The customer's id.
511
+     */
512
+    public function set_customer_id( $value ) {
513
+        $this->set_prop( 'customer_id', (int) $value );
514
+    }
515
+
516
+    /**
517
+     * Set parent invoice id.
518
+     *
519
+     * @since 1.0.19
520
+     * @param  int $value The parent invoice id.
521
+     */
522
+    public function set_parent_invoice_id( $value ) {
523
+        $this->set_prop( 'parent_payment_id', (int) $value );
524
+    }
525
+
526
+    /**
527
+     * Alias for self::set_parent_invoice_id().
528
+     *
529
+     * @since 1.0.19
530
+     * @param  int $value The parent invoice id.
531
+     */
532
+    public function set_parent_payment_id( $value ) {
533
+        $this->set_parent_invoice_id( $value );
534
+    }
535
+
536
+    /**
537
+     * Alias for self::set_parent_invoice_id().
538
+     *
539
+     * @since 1.0.19
540
+     * @param  int $value The parent invoice id.
541
+     */
542
+    public function set_original_payment_id( $value ) {
543
+        $this->set_parent_invoice_id( $value );
544
+    }
545
+
546
+    /**
547
+     * Set subscription's product id.
548
+     *
549
+     * @since 1.0.19
550
+     * @param  int $value The subscription product id.
551
+     */
552
+    public function set_product_id( $value ) {
553
+        $this->set_prop( 'product_id', (int) $value );
554
+    }
555
+
556
+    /**
557
+     * Set the period of a renewal.
558
+     *
559
+     * @since 1.0.19
560
+     * @param  string $value The renewal period.
561
+     */
562
+    public function set_period( $value ) {
563
+        $this->set_prop( 'period', $value );
564
+    }
565
+
566
+    /**
567
+     * Set number of periods each renewal is valid for.
568
+     *
569
+     * @since 1.0.19
570
+     * @param  int $value The subscription frequency.
571
+     */
572
+    public function set_frequency( $value ) {
573
+        $value = empty( $value ) ? 1 : (int) $value;
574
+        $this->set_prop( 'frequency', absint( $value ) );
575
+    }
576
+
577
+    /**
578
+     * Set the initial amount for the subscription.
579
+     *
580
+     * @since 1.0.19
581
+     * @param  float $value The initial subcription amount.
582
+     */
583
+    public function set_initial_amount( $value ) {
584
+        $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
585
+    }
586
+
587
+    /**
588
+     * Set the recurring amount for the subscription.
589
+     *
590
+     * @since 1.0.19
591
+     * @param  float $value The recurring subcription amount.
592
+     */
593
+    public function set_recurring_amount( $value ) {
594
+        $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
595
+    }
596
+
597
+    /**
598
+     * Set number of times that this subscription can be renewed.
599
+     *
600
+     * @since 1.0.19
601
+     * @param  int $value Bill times.
602
+     */
603
+    public function set_bill_times( $value ) {
604
+        $this->set_prop( 'bill_times', (int) $value );
605
+    }
606
+
607
+    /**
608
+     * Get transaction id of this subscription's parent invoice.
609
+     *
610
+     * @since 1.0.19
611
+     * @param string $value Bill times.
235 612
      */
236
-    public function get_original_payment_id( $context = 'view' ) {
237
-        return $this->get_parent_invoice_id( $context );
613
+    public function set_transaction_id( $value ) {
614
+        $this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
238 615
     }
239 616
 
240
-	/**
241
-	 * Get parent invoice.
242
-	 *
243
-	 * @since 1.0.19
244
-	 * @param  string $context View or edit context.
245
-	 * @return WPInv_Invoice
246
-	 */
247
-	public function get_parent_invoice( $context = 'view' ) {
248
-		return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
249
-	}
250
-
251
-	/**
252
-	 * Alias for self::get_parent_invoice().
253
-	 *
254
-	 * @since 1.0.19
255
-	 * @param  string $context View or edit context.
256
-	 * @return WPInv_Invoice
257
-	 */
258
-    public function get_parent_payment( $context = 'view' ) {
259
-        return $this->get_parent_invoice( $context );
260
-	}
261
-
262
-	/**
263
-	 * Get subscription's product id.
264
-	 *
265
-	 * @since 1.0.19
266
-	 * @param  string $context View or edit context.
267
-	 * @return int
268
-	 */
269
-	public function get_product_id( $context = 'view' ) {
270
-		return (int) $this->get_prop( 'product_id', $context );
271
-	}
272
-
273
-	/**
274
-	 * Get the subscription product.
275
-	 *
276
-	 * @since 1.0.19
277
-	 * @param  string $context View or edit context.
278
-	 * @return WPInv_Item
279
-	 */
280
-	public function get_product( $context = 'view' ) {
281
-		return new WPInv_Item( $this->get_product_id( $context ) );
282
-	}
283
-
284
-	/**
285
-	 * Get parent invoice's gateway.
286
-	 *
287
-	 * Here for backwards compatibility.
288
-	 *
289
-	 * @since 1.0.19
290
-	 * @param  string $context View or edit context.
291
-	 * @return string
292
-	 */
293
-	public function get_gateway( $context = 'view' ) {
294
-		return $this->get_parent_invoice( $context )->get_gateway();
295
-	}
296
-
297
-	/**
298
-	 * Get the period of a renewal.
299
-	 *
300
-	 * @since 1.0.19
301
-	 * @param  string $context View or edit context.
302
-	 * @return string
303
-	 */
304
-	public function get_period( $context = 'view' ) {
305
-		return $this->get_prop( 'period', $context );
306
-	}
307
-
308
-	/**
309
-	 * Get number of periods each renewal is valid for.
310
-	 *
311
-	 * @since 1.0.19
312
-	 * @param  string $context View or edit context.
313
-	 * @return int
314
-	 */
315
-	public function get_frequency( $context = 'view' ) {
316
-		return (int) $this->get_prop( 'frequency', $context );
317
-	}
318
-
319
-	/**
320
-	 * Get the initial amount for the subscription.
321
-	 *
322
-	 * @since 1.0.19
323
-	 * @param  string $context View or edit context.
324
-	 * @return float
325
-	 */
326
-	public function get_initial_amount( $context = 'view' ) {
327
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
328
-	}
329
-
330
-	/**
331
-	 * Get the recurring amount for the subscription.
332
-	 *
333
-	 * @since 1.0.19
334
-	 * @param  string $context View or edit context.
335
-	 * @return float
336
-	 */
337
-	public function get_recurring_amount( $context = 'view' ) {
338
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
339
-	}
340
-
341
-	/**
342
-	 * Get number of times that this subscription can be renewed.
343
-	 *
344
-	 * @since 1.0.19
345
-	 * @param  string $context View or edit context.
346
-	 * @return int
347
-	 */
348
-	public function get_bill_times( $context = 'view' ) {
349
-		return (int) $this->get_prop( 'bill_times', $context );
350
-	}
351
-
352
-	/**
353
-	 * Get transaction id of this subscription's parent invoice.
354
-	 *
355
-	 * @since 1.0.19
356
-	 * @param  string $context View or edit context.
357
-	 * @return string
358
-	 */
359
-	public function get_transaction_id( $context = 'view' ) {
360
-		return $this->get_prop( 'transaction_id', $context );
361
-	}
362
-
363
-	/**
364
-	 * Get the date that the subscription was created.
365
-	 *
366
-	 * @since 1.0.19
367
-	 * @param  string $context View or edit context.
368
-	 * @return string
369
-	 */
370
-	public function get_created( $context = 'view' ) {
371
-		return $this->get_prop( 'created', $context );
372
-	}
373
-
374
-	/**
375
-	 * Alias for self::get_created().
376
-	 *
377
-	 * @since 1.0.19
378
-	 * @param  string $context View or edit context.
379
-	 * @return string
380
-	 */
381
-	public function get_date_created( $context = 'view' ) {
382
-		return $this->get_created( $context );
383
-	}
384
-
385
-	/**
386
-	 * Retrieves the creation date in a timestamp
387
-	 *
388
-	 * @since  1.0.0
389
-	 * @return int
390
-	 */
391
-	public function get_time_created() {
392
-		$created = $this->get_date_created();
393
-		return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
394
-	}
395
-
396
-	/**
397
-	 * Get GMT date when the subscription was created.
398
-	 *
399
-	 * @since 1.0.19
400
-	 * @param  string $context View or edit context.
401
-	 * @return string
402
-	 */
403
-	public function get_date_created_gmt( $context = 'view' ) {
404
-        $date = $this->get_date_created( $context );
617
+    /**
618
+     * Set date when this subscription started.
619
+     *
620
+     * @since 1.0.19
621
+     * @param string $value strtotime compliant date.
622
+     */
623
+    public function set_created( $value ) {
624
+        $date = strtotime( $value );
405 625
 
406
-        if ( $date ) {
407
-            $date = get_gmt_from_date( $date );
626
+        if ( $date && $value !== '0000-00-00 00:00:00' ) {
627
+            $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) );
628
+            return;
408 629
         }
409
-		return $date;
410
-	}
411
-
412
-	/**
413
-	 * Get the date that the subscription will renew.
414
-	 *
415
-	 * @since 1.0.19
416
-	 * @param  string $context View or edit context.
417
-	 * @return string
418
-	 */
419
-	public function get_next_renewal_date( $context = 'view' ) {
420
-		return $this->get_prop( 'expiration', $context );
421
-	}
422
-
423
-	/**
424
-	 * Alias for self::get_next_renewal_date().
425
-	 *
426
-	 * @since 1.0.19
427
-	 * @param  string $context View or edit context.
428
-	 * @return string
429
-	 */
430
-	public function get_expiration( $context = 'view' ) {
431
-		return $this->get_next_renewal_date( $context );
432
-	}
433
-
434
-	/**
435
-	 * Retrieves the expiration date in a timestamp
436
-	 *
437
-	 * @since  1.0.0
438
-	 * @return int
439
-	 */
440
-	public function get_expiration_time() {
441
-		$expiration = $this->get_expiration();
442
-
443
-		if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
444
-			return current_time( 'timestamp' );
445
-		}
446
-
447
-		$expiration = strtotime( $expiration, current_time( 'timestamp' ) );
448
-		return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
449
-	}
450
-
451
-	/**
452
-	 * Get GMT date when the subscription will renew.
453
-	 *
454
-	 * @since 1.0.19
455
-	 * @param  string $context View or edit context.
456
-	 * @return string
457
-	 */
458
-	public function get_next_renewal_date_gmt( $context = 'view' ) {
459
-        $date = $this->get_next_renewal_date( $context );
460 630
 
461
-        if ( $date ) {
462
-            $date = get_gmt_from_date( $date );
463
-        }
464
-		return $date;
465
-	}
466
-
467
-	/**
468
-	 * Get the subscription's trial period.
469
-	 *
470
-	 * @since 1.0.19
471
-	 * @param  string $context View or edit context.
472
-	 * @return string
473
-	 */
474
-	public function get_trial_period( $context = 'view' ) {
475
-		return $this->get_prop( 'trial_period', $context );
476
-	}
477
-
478
-	/**
479
-	 * Get the subscription's status.
480
-	 *
481
-	 * @since 1.0.19
482
-	 * @param  string $context View or edit context.
483
-	 * @return string
484
-	 */
485
-	public function get_status( $context = 'view' ) {
486
-		return $this->get_prop( 'status', $context );
487
-	}
488
-
489
-	/**
490
-	 * Get the subscription's profile id.
491
-	 *
492
-	 * @since 1.0.19
493
-	 * @param  string $context View or edit context.
494
-	 * @return string
495
-	 */
496
-	public function get_profile_id( $context = 'view' ) {
497
-		return $this->get_prop( 'profile_id', $context );
498
-	}
499
-
500
-	/*
501
-	|--------------------------------------------------------------------------
502
-	| Setters
503
-	|--------------------------------------------------------------------------
504
-	*/
631
+        $this->set_prop( 'created', '' );
505 632
 
506
-	/**
507
-	 * Set customer id.
508
-	 *
509
-	 * @since 1.0.19
510
-	 * @param  int $value The customer's id.
511
-	 */
512
-	public function set_customer_id( $value ) {
513
-		$this->set_prop( 'customer_id', (int) $value );
514
-	}
515
-
516
-	/**
517
-	 * Set parent invoice id.
518
-	 *
519
-	 * @since 1.0.19
520
-	 * @param  int $value The parent invoice id.
521
-	 */
522
-	public function set_parent_invoice_id( $value ) {
523
-		$this->set_prop( 'parent_payment_id', (int) $value );
524
-	}
525
-
526
-	/**
527
-	 * Alias for self::set_parent_invoice_id().
528
-	 *
529
-	 * @since 1.0.19
530
-	 * @param  int $value The parent invoice id.
531
-	 */
532
-    public function set_parent_payment_id( $value ) {
533
-        $this->set_parent_invoice_id( $value );
534
-	}
633
+    }
535 634
 
536
-	/**
537
-     * Alias for self::set_parent_invoice_id().
635
+    /**
636
+     * Alias for self::set_created().
538 637
      *
539 638
      * @since 1.0.19
540
-	 * @param  int $value The parent invoice id.
639
+     * @param string $value strtotime compliant date.
541 640
      */
542
-    public function set_original_payment_id( $value ) {
543
-        $this->set_parent_invoice_id( $value );
544
-	}
545
-
546
-	/**
547
-	 * Set subscription's product id.
548
-	 *
549
-	 * @since 1.0.19
550
-	 * @param  int $value The subscription product id.
551
-	 */
552
-	public function set_product_id( $value ) {
553
-		$this->set_prop( 'product_id', (int) $value );
554
-	}
555
-
556
-	/**
557
-	 * Set the period of a renewal.
558
-	 *
559
-	 * @since 1.0.19
560
-	 * @param  string $value The renewal period.
561
-	 */
562
-	public function set_period( $value ) {
563
-		$this->set_prop( 'period', $value );
564
-	}
565
-
566
-	/**
567
-	 * Set number of periods each renewal is valid for.
568
-	 *
569
-	 * @since 1.0.19
570
-	 * @param  int $value The subscription frequency.
571
-	 */
572
-	public function set_frequency( $value ) {
573
-		$value = empty( $value ) ? 1 : (int) $value;
574
-		$this->set_prop( 'frequency', absint( $value ) );
575
-	}
576
-
577
-	/**
578
-	 * Set the initial amount for the subscription.
579
-	 *
580
-	 * @since 1.0.19
581
-	 * @param  float $value The initial subcription amount.
582
-	 */
583
-	public function set_initial_amount( $value ) {
584
-		$this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
585
-	}
586
-
587
-	/**
588
-	 * Set the recurring amount for the subscription.
589
-	 *
590
-	 * @since 1.0.19
591
-	 * @param  float $value The recurring subcription amount.
592
-	 */
593
-	public function set_recurring_amount( $value ) {
594
-		$this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
595
-	}
596
-
597
-	/**
598
-	 * Set number of times that this subscription can be renewed.
599
-	 *
600
-	 * @since 1.0.19
601
-	 * @param  int $value Bill times.
602
-	 */
603
-	public function set_bill_times( $value ) {
604
-		$this->set_prop( 'bill_times', (int) $value );
605
-	}
606
-
607
-	/**
608
-	 * Get transaction id of this subscription's parent invoice.
609
-	 *
610
-	 * @since 1.0.19
611
-	 * @param string $value Bill times.
612
-	 */
613
-	public function set_transaction_id( $value ) {
614
-		$this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
615
-	}
616
-
617
-	/**
618
-	 * Set date when this subscription started.
619
-	 *
620
-	 * @since 1.0.19
621
-	 * @param string $value strtotime compliant date.
622
-	 */
623
-	public function set_created( $value ) {
641
+    public function set_date_created( $value ) {
642
+        $this->set_created( $value );
643
+    }
644
+
645
+    /**
646
+     * Set the date that the subscription will renew.
647
+     *
648
+     * @since 1.0.19
649
+     * @param string $value strtotime compliant date.
650
+     */
651
+    public function set_next_renewal_date( $value ) {
624 652
         $date = strtotime( $value );
625 653
 
626 654
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
627
-            $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) );
655
+            $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) );
628 656
             return;
629 657
         }
630 658
 
631
-		$this->set_prop( 'created', '' );
659
+        $this->set_prop( 'expiration', '' );
660
+
661
+    }
632 662
 
633
-	}
663
+    /**
664
+     * Alias for self::set_next_renewal_date().
665
+     *
666
+     * @since 1.0.19
667
+     * @param string $value strtotime compliant date.
668
+     */
669
+    public function set_expiration( $value ) {
670
+        $this->set_next_renewal_date( $value );
671
+    }
634 672
 
635
-	/**
636
-	 * Alias for self::set_created().
637
-	 *
638
-	 * @since 1.0.19
639
-	 * @param string $value strtotime compliant date.
640
-	 */
641
-	public function set_date_created( $value ) {
642
-		$this->set_created( $value );
673
+    /**
674
+     * Set the subscription's trial period.
675
+     *
676
+     * @since 1.0.19
677
+     * @param string $value trial period e.g 1 year.
678
+     */
679
+    public function set_trial_period( $value ) {
680
+        $this->set_prop( 'trial_period', $value );
643 681
     }
644 682
 
645
-	/**
646
-	 * Set the date that the subscription will renew.
647
-	 *
648
-	 * @since 1.0.19
649
-	 * @param string $value strtotime compliant date.
650
-	 */
651
-	public function set_next_renewal_date( $value ) {
652
-		$date = strtotime( $value );
683
+    /**
684
+     * Set the subscription's status.
685
+     *
686
+     * @since 1.0.19
687
+     * @param string $new_status    New subscription status.
688
+     */
689
+    public function set_status( $new_status ) {
653 690
 
654
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
655
-            $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) );
691
+        // Abort if this is not a valid status;
692
+        if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
656 693
             return;
657
-		}
658
-
659
-		$this->set_prop( 'expiration', '' );
660
-
661
-	}
662
-
663
-	/**
664
-	 * Alias for self::set_next_renewal_date().
665
-	 *
666
-	 * @since 1.0.19
667
-	 * @param string $value strtotime compliant date.
668
-	 */
669
-	public function set_expiration( $value ) {
670
-		$this->set_next_renewal_date( $value );
671
-    }
672
-
673
-	/**
674
-	 * Set the subscription's trial period.
675
-	 *
676
-	 * @since 1.0.19
677
-	 * @param string $value trial period e.g 1 year.
678
-	 */
679
-	public function set_trial_period( $value ) {
680
-		$this->set_prop( 'trial_period', $value );
681
-	}
682
-
683
-	/**
684
-	 * Set the subscription's status.
685
-	 *
686
-	 * @since 1.0.19
687
-	 * @param string $new_status    New subscription status.
688
-	 */
689
-	public function set_status( $new_status ) {
690
-
691
-		// Abort if this is not a valid status;
692
-		if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
693
-			return;
694
-		}
695
-
696
-		$old_status = $this->get_status();
697
-		$this->set_prop( 'status', $new_status );
698
-
699
-		if ( true === $this->object_read && $old_status !== $new_status ) {
700
-			$this->status_transition = array(
701
-				'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
702
-				'to'     => $new_status,
703
-			);
704
-		}
705
-
706
-	}
707
-
708
-	/**
709
-	 * Set the subscription's (remote) profile id.
710
-	 *
711
-	 * @since 1.0.19
712
-	 * @param  string $value the remote profile id.
713
-	 */
714
-	public function set_profile_id( $value ) {
715
-		$this->set_prop( 'profile_id', sanitize_text_field( $value ) );
716
-	}
717
-
718
-	/*
694
+        }
695
+
696
+        $old_status = $this->get_status();
697
+        $this->set_prop( 'status', $new_status );
698
+
699
+        if ( true === $this->object_read && $old_status !== $new_status ) {
700
+            $this->status_transition = array(
701
+                'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
702
+                'to'     => $new_status,
703
+            );
704
+        }
705
+
706
+    }
707
+
708
+    /**
709
+     * Set the subscription's (remote) profile id.
710
+     *
711
+     * @since 1.0.19
712
+     * @param  string $value the remote profile id.
713
+     */
714
+    public function set_profile_id( $value ) {
715
+        $this->set_prop( 'profile_id', sanitize_text_field( $value ) );
716
+    }
717
+
718
+    /*
719 719
 	|--------------------------------------------------------------------------
720 720
 	| Boolean methods
721 721
 	|--------------------------------------------------------------------------
@@ -724,55 +724,55 @@  discard block
 block discarded – undo
724 724
 	|
725 725
 	*/
726 726
 
727
-	/**
727
+    /**
728 728
      * Checks if the subscription has a given status.
729
-	 *
730
-	 * @param string|array String or array of strings to check for.
731
-	 * @return bool
729
+     *
730
+     * @param string|array String or array of strings to check for.
731
+     * @return bool
732 732
      */
733 733
     public function has_status( $status ) {
734 734
         return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) );
735
-	}
735
+    }
736 736
 
737
-	/**
737
+    /**
738 738
      * Checks if the subscription has a trial period.
739
-	 *
740
-	 * @return bool
739
+     *
740
+     * @return bool
741 741
      */
742 742
     public function has_trial_period() {
743
-		$period = $this->get_trial_period();
743
+        $period = $this->get_trial_period();
744 744
         return ! empty( $period );
745
-	}
746
-
747
-	/**
748
-	 * Is the subscription active?
749
-	 *
750
-	 * @return bool
751
-	 */
752
-	public function is_active() {
753
-		return $this->has_status( 'active trialling' ) && ! $this->is_expired();
754
-	}
755
-
756
-	/**
757
-	 * Is the subscription expired?
758
-	 *
759
-	 * @return bool
760
-	 */
761
-	public function is_expired() {
762
-		return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) );
763
-	}
764
-
765
-	/**
766
-	 * Is this the last renewals?
767
-	 *
768
-	 * @return bool
769
-	 */
770
-	public function is_last_renewal() {
771
-		$max_bills = $this->get_bill_times();
772
-		return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed();
773
-	}
774
-
775
-	/*
745
+    }
746
+
747
+    /**
748
+     * Is the subscription active?
749
+     *
750
+     * @return bool
751
+     */
752
+    public function is_active() {
753
+        return $this->has_status( 'active trialling' ) && ! $this->is_expired();
754
+    }
755
+
756
+    /**
757
+     * Is the subscription expired?
758
+     *
759
+     * @return bool
760
+     */
761
+    public function is_expired() {
762
+        return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) );
763
+    }
764
+
765
+    /**
766
+     * Is this the last renewals?
767
+     *
768
+     * @return bool
769
+     */
770
+    public function is_last_renewal() {
771
+        $max_bills = $this->get_bill_times();
772
+        return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed();
773
+    }
774
+
775
+    /*
776 776
 	|--------------------------------------------------------------------------
777 777
 	| Additional methods
778 778
 	|--------------------------------------------------------------------------
@@ -781,27 +781,27 @@  discard block
 block discarded – undo
781 781
 	|
782 782
 	*/
783 783
 
784
-	/**
785
-	 * Backwards compatibilty.
786
-	 */
787
-	public function create( $data = array() ) {
784
+    /**
785
+     * Backwards compatibilty.
786
+     */
787
+    public function create( $data = array() ) {
788 788
 
789
-		// Set the properties.
790
-		if ( is_array( $data ) ) {
791
-			$this->set_props( $data );
792
-		}
789
+        // Set the properties.
790
+        if ( is_array( $data ) ) {
791
+            $this->set_props( $data );
792
+        }
793 793
 
794
-		// Save the item.
795
-		return $this->save();
794
+        // Save the item.
795
+        return $this->save();
796 796
 
797
-	}
797
+    }
798 798
 
799
-	/**
800
-	 * Backwards compatibilty.
801
-	 */
802
-	public function update( $args = array() ) {
803
-		return $this->create( $args );
804
-	}
799
+    /**
800
+     * Backwards compatibilty.
801
+     */
802
+    public function update( $args = array() ) {
803
+        return $this->create( $args );
804
+    }
805 805
 
806 806
     /**
807 807
      * Retrieve renewal payments for a subscription
@@ -811,22 +811,22 @@  discard block
 block discarded – undo
811 811
      */
812 812
     public function get_child_payments( $hide_pending = true ) {
813 813
 
814
-		$statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' );
814
+        $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' );
815 815
 
816
-		if ( ! $hide_pending ) {
817
-			$statuses = array_keys( wpinv_get_invoice_statuses() );
818
-		}
816
+        if ( ! $hide_pending ) {
817
+            $statuses = array_keys( wpinv_get_invoice_statuses() );
818
+        }
819 819
 
820 820
         return get_posts(
821
-			array(
822
-            	'post_parent'    => $this->get_parent_payment_id(),
823
-            	'numberposts'    => -1,
824
-            	'post_status'    => $statuses,
825
-            	'orderby'        => 'ID',
826
-            	'order'          => 'ASC',
827
-            	'post_type'      => 'wpi_invoice'
828
-			)
829
-		);
821
+            array(
822
+                'post_parent'    => $this->get_parent_payment_id(),
823
+                'numberposts'    => -1,
824
+                'post_status'    => $statuses,
825
+                'orderby'        => 'ID',
826
+                'order'          => 'ASC',
827
+                'post_type'      => 'wpi_invoice'
828
+            )
829
+        );
830 830
     }
831 831
 
832 832
     /**
@@ -836,16 +836,16 @@  discard block
 block discarded – undo
836 836
      * @return int
837 837
      */
838 838
     public function get_total_payments() {
839
-		global $wpdb;
839
+        global $wpdb;
840 840
 
841
-		$count = (int) $wpdb->get_var(
842
-			$wpdb->prepare(
843
-				"SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
844
-				$this->get_parent_invoice_id()
845
-			)
846
-		);
841
+        $count = (int) $wpdb->get_var(
842
+            $wpdb->prepare(
843
+                "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
844
+                $this->get_parent_invoice_id()
845
+            )
846
+        );
847 847
 
848
-		// Maybe include parent invoice.
848
+        // Maybe include parent invoice.
849 849
         if ( $this->get_parent_payment()->is_paid() ) {
850 850
             $count++;
851 851
         }
@@ -874,65 +874,65 @@  discard block
 block discarded – undo
874 874
      *
875 875
      * @since  2.4
876 876
      * @param  array $args Array of values for the payment, including amount and transaction ID
877
-	 * @param  WPInv_Invoice $invoice If adding an existing invoice.
877
+     * @param  WPInv_Invoice $invoice If adding an existing invoice.
878 878
      * @return bool
879 879
      */
880 880
     public function add_payment( $args = array(), $invoice = false ) {
881 881
 
882
-		// Process each payment once.
882
+        // Process each payment once.
883 883
         if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) {
884 884
             return false;
885 885
         }
886 886
 		
887
-		// Check is it one time payment
888
-		$item = new WPInv_Item( $this->get_product_id() );
889
-		$is_one_time_payment = $item->is_one_time_recurring();
887
+        // Check is it one time payment
888
+        $item = new WPInv_Item( $this->get_product_id() );
889
+        $is_one_time_payment = $item->is_one_time_recurring();
890 890
         if ( $is_one_time_payment == 1 ) {
891 891
             $this->complete();
892
-			return true;
892
+            return true;
893 893
         } 
894 894
 
895
-		// Are we creating a new invoice?
896
-		if ( empty( $invoice ) ) {
897
-			$invoice = $this->create_payment();
895
+        // Are we creating a new invoice?
896
+        if ( empty( $invoice ) ) {
897
+            $invoice = $this->create_payment();
898 898
 
899
-			if ( empty( $invoice ) ) {
900
-				return false;
901
-			}
899
+            if ( empty( $invoice ) ) {
900
+                return false;
901
+            }
902 902
 
903
-		}
903
+        }
904 904
 
905
-		$invoice->set_status( 'wpi-renewal' );
905
+        $invoice->set_status( 'wpi-renewal' );
906 906
 
907
-		// Maybe set a transaction id.
908
-		if ( ! empty( $args['transaction_id'] ) ) {
909
-			$invoice->set_transaction_id( $args['transaction_id'] );
910
-		}
907
+        // Maybe set a transaction id.
908
+        if ( ! empty( $args['transaction_id'] ) ) {
909
+            $invoice->set_transaction_id( $args['transaction_id'] );
910
+        }
911 911
 
912
-		// Set the completed date.
913
-		$invoice->set_completed_date( current_time( 'mysql' ) );
912
+        // Set the completed date.
913
+        $invoice->set_completed_date( current_time( 'mysql' ) );
914 914
 
915
-		// And the gateway.
916
-		if ( ! empty( $args['gateway'] ) ) {
917
-			$invoice->set_gateway( $args['gateway'] );
918
-		}
915
+        // And the gateway.
916
+        if ( ! empty( $args['gateway'] ) ) {
917
+            $invoice->set_gateway( $args['gateway'] );
918
+        }
919 919
 
920
-		$invoice->save();
920
+        $invoice->save();
921 921
 
922
-		if ( ! $invoice->exists() ) {
923
-			return false;
924
-		}
922
+        if ( ! $invoice->exists() ) {
923
+            return false;
924
+        }
925 925
 
926
-		do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
927
-		do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
926
+        do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
927
+        do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
928 928
         do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() );
929 929
 
930 930
         update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id );
931 931
 
932 932
         return $invoice->get_id();
933
-	}
933
+    }
934 934
 
935
-	/**
935
+    /**
936 936
      * Creates a new invoice and returns it.
937 937
      *
938 938
      * @since  1.0.19
@@ -940,98 +940,98 @@  discard block
 block discarded – undo
940 940
      */
941 941
     public function create_payment() {
942 942
 
943
-		$parent_invoice = $this->get_parent_payment();
944
-
945
-		if ( ! $parent_invoice->exists() ) {
946
-			return false;
947
-		}
948
-
949
-		// Duplicate the parent invoice.
950
-		$invoice = getpaid_duplicate_invoice( $parent_invoice );
951
-		$invoice->set_parent_id( $parent_invoice->get_id() );
952
-		$invoice->recalculate_total();
953
-		$invoice->set_status( 'wpi-pending' );
954
-		$invoice->save();
955
-
956
-		return $invoice->exists() ? $invoice : false;
957
-    }
958
-
959
-	/**
960
-	 * Renews or completes a subscription
961
-	 *
962
-	 * @since  1.0.0
963
-	 * @return int The subscription's id
964
-	 */
965
-	public function renew() {
966
-
967
-		// Complete subscription if applicable
968
-		if ( $this->is_last_renewal() ) {
969
-			return $this->complete();
970
-		}
971
-
972
-		// Calculate new expiration
973
-		$frequency      = $this->get_frequency();
974
-		$period         = $this->get_period();
975
-		$new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
976
-
977
-		$this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) );
978
-		$this->set_status( 'active' );
979
-		$this->save();
980
-
981
-		do_action( 'getpaid_subscription_renewed', $this );
982
-
983
-		return $this->get_id();
984
-	}
985
-
986
-	/**
987
-	 * Marks a subscription as completed
988
-	 *
989
-	 * Subscription is completed when the number of payments matches the billing_times field
990
-	 *
991
-	 * @since  1.0.0
992
-	 * @return int|bool Subscription id or false if the subscription is cancelled.
993
-	 */
994
-	public function complete() {
995
-
996
-		// Only mark a subscription as complete if it's not already cancelled.
997
-		if ( $this->has_status( 'cancelled' ) ) {
998
-			return false;
999
-		}
1000
-
1001
-		$this->set_status( 'completed' );
1002
-		return $this->save();
1003
-
1004
-	}
1005
-
1006
-	/**
1007
-	 * Marks a subscription as expired
1008
-	 *
1009
-	 * @since  1.0.0
1010
-	 * @param  bool $check_expiration
1011
-	 * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1012
-	 */
1013
-	public function expire( $check_expiration = false ) {
1014
-
1015
-		if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1016
-			// Do not mark as expired since real expiration date is in the future
1017
-			return false;
1018
-		}
1019
-
1020
-		$this->set_status( 'expired' );
1021
-		return $this->save();
1022
-
1023
-	}
1024
-
1025
-	/**
1026
-	 * Marks a subscription as failing
1027
-	 *
1028
-	 * @since  2.4.2
1029
-	 * @return int Subscription id.
1030
-	 */
1031
-	public function failing() {
1032
-		$this->set_status( 'failing' );
1033
-		return $this->save();
1034
-	}
943
+        $parent_invoice = $this->get_parent_payment();
944
+
945
+        if ( ! $parent_invoice->exists() ) {
946
+            return false;
947
+        }
948
+
949
+        // Duplicate the parent invoice.
950
+        $invoice = getpaid_duplicate_invoice( $parent_invoice );
951
+        $invoice->set_parent_id( $parent_invoice->get_id() );
952
+        $invoice->recalculate_total();
953
+        $invoice->set_status( 'wpi-pending' );
954
+        $invoice->save();
955
+
956
+        return $invoice->exists() ? $invoice : false;
957
+    }
958
+
959
+    /**
960
+     * Renews or completes a subscription
961
+     *
962
+     * @since  1.0.0
963
+     * @return int The subscription's id
964
+     */
965
+    public function renew() {
966
+
967
+        // Complete subscription if applicable
968
+        if ( $this->is_last_renewal() ) {
969
+            return $this->complete();
970
+        }
971
+
972
+        // Calculate new expiration
973
+        $frequency      = $this->get_frequency();
974
+        $period         = $this->get_period();
975
+        $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
976
+
977
+        $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) );
978
+        $this->set_status( 'active' );
979
+        $this->save();
980
+
981
+        do_action( 'getpaid_subscription_renewed', $this );
982
+
983
+        return $this->get_id();
984
+    }
985
+
986
+    /**
987
+     * Marks a subscription as completed
988
+     *
989
+     * Subscription is completed when the number of payments matches the billing_times field
990
+     *
991
+     * @since  1.0.0
992
+     * @return int|bool Subscription id or false if the subscription is cancelled.
993
+     */
994
+    public function complete() {
995
+
996
+        // Only mark a subscription as complete if it's not already cancelled.
997
+        if ( $this->has_status( 'cancelled' ) ) {
998
+            return false;
999
+        }
1000
+
1001
+        $this->set_status( 'completed' );
1002
+        return $this->save();
1003
+
1004
+    }
1005
+
1006
+    /**
1007
+     * Marks a subscription as expired
1008
+     *
1009
+     * @since  1.0.0
1010
+     * @param  bool $check_expiration
1011
+     * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1012
+     */
1013
+    public function expire( $check_expiration = false ) {
1014
+
1015
+        if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1016
+            // Do not mark as expired since real expiration date is in the future
1017
+            return false;
1018
+        }
1019
+
1020
+        $this->set_status( 'expired' );
1021
+        return $this->save();
1022
+
1023
+    }
1024
+
1025
+    /**
1026
+     * Marks a subscription as failing
1027
+     *
1028
+     * @since  2.4.2
1029
+     * @return int Subscription id.
1030
+     */
1031
+    public function failing() {
1032
+        $this->set_status( 'failing' );
1033
+        return $this->save();
1034
+    }
1035 1035
 
1036 1036
     /**
1037 1037
      * Marks a subscription as cancelled
@@ -1040,19 +1040,19 @@  discard block
 block discarded – undo
1040 1040
      * @return int Subscription id.
1041 1041
      */
1042 1042
     public function cancel() {
1043
-		$this->set_status( 'cancelled' );
1044
-		return $this->save();
1043
+        $this->set_status( 'cancelled' );
1044
+        return $this->save();
1045 1045
     }
1046 1046
 
1047
-	/**
1048
-	 * Determines if a subscription can be cancelled both locally and with a payment processor.
1049
-	 *
1050
-	 * @since  1.0.0
1051
-	 * @return bool
1052
-	 */
1053
-	public function can_cancel() {
1054
-		return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1055
-	}
1047
+    /**
1048
+     * Determines if a subscription can be cancelled both locally and with a payment processor.
1049
+     *
1050
+     * @since  1.0.0
1051
+     * @return bool
1052
+     */
1053
+    public function can_cancel() {
1054
+        return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1055
+    }
1056 1056
 
1057 1057
     /**
1058 1058
      * Returns an array of subscription statuses that can be cancelled
@@ -1065,96 +1065,96 @@  discard block
 block discarded – undo
1065 1065
         return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) );
1066 1066
     }
1067 1067
 
1068
-	/**
1069
-	 * Retrieves the URL to cancel subscription
1070
-	 *
1071
-	 * @since  1.0.0
1072
-	 * @return string
1073
-	 */
1074
-	public function get_cancel_url() {
1075
-		$url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1076
-		return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1077
-	}
1078
-
1079
-	/**
1080
-	 * Retrieves the URL to view a subscription
1081
-	 *
1082
-	 * @since  1.0.19
1083
-	 * @return string
1084
-	 */
1085
-	public function get_view_url() {
1086
-
1087
-		$url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1088
-		$url = add_query_arg( 'subscription', $this->get_id(), $url );
1089
-
1090
-		return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1091
-	}
1092
-
1093
-	/**
1094
-	 * Determines if subscription can be manually renewed
1095
-	 *
1096
-	 * This method is filtered by payment gateways in order to return true on subscriptions
1097
-	 * that can be renewed manually
1098
-	 *
1099
-	 * @since  2.5
1100
-	 * @return bool
1101
-	 */
1102
-	public function can_renew() {
1103
-		return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1104
-	}
1105
-
1106
-	/**
1107
-	 * Retrieves the URL to renew a subscription
1108
-	 *
1109
-	 * @since  2.5
1110
-	 * @return string
1111
-	 */
1112
-	public function get_renew_url() {
1113
-		$url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' );
1114
-		return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1115
-	}
1116
-
1117
-	/**
1118
-	 * Determines if subscription can have their payment method updated
1119
-	 *
1120
-	 * @since  1.0.0
1121
-	 * @return bool
1122
-	 */
1123
-	public function can_update() {
1124
-		return apply_filters( 'wpinv_subscription_can_update', false, $this );
1125
-	}
1126
-
1127
-	/**
1128
-	 * Retrieves the URL to update subscription
1129
-	 *
1130
-	 * @since  1.0.0
1131
-	 * @return string
1132
-	 */
1133
-	public function get_update_url() {
1134
-		$url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) );
1135
-		return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1136
-	}
1137
-
1138
-	/**
1139
-	 * Retrieves the subscription status label
1140
-	 *
1141
-	 * @since  1.0.0
1142
-	 * @return string
1143
-	 */
1144
-	public function get_status_label() {
1145
-		return getpaid_get_subscription_status_label( $this->get_status() );
1146
-	}
1147
-
1148
-	/**
1149
-	 * Retrieves the subscription status class
1150
-	 *
1151
-	 * @since  1.0.19
1152
-	 * @return string
1153
-	 */
1154
-	public function get_status_class() {
1155
-		$statuses = getpaid_get_subscription_status_classes();
1156
-		return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark';
1157
-	}
1068
+    /**
1069
+     * Retrieves the URL to cancel subscription
1070
+     *
1071
+     * @since  1.0.0
1072
+     * @return string
1073
+     */
1074
+    public function get_cancel_url() {
1075
+        $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1076
+        return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1077
+    }
1078
+
1079
+    /**
1080
+     * Retrieves the URL to view a subscription
1081
+     *
1082
+     * @since  1.0.19
1083
+     * @return string
1084
+     */
1085
+    public function get_view_url() {
1086
+
1087
+        $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1088
+        $url = add_query_arg( 'subscription', $this->get_id(), $url );
1089
+
1090
+        return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1091
+    }
1092
+
1093
+    /**
1094
+     * Determines if subscription can be manually renewed
1095
+     *
1096
+     * This method is filtered by payment gateways in order to return true on subscriptions
1097
+     * that can be renewed manually
1098
+     *
1099
+     * @since  2.5
1100
+     * @return bool
1101
+     */
1102
+    public function can_renew() {
1103
+        return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1104
+    }
1105
+
1106
+    /**
1107
+     * Retrieves the URL to renew a subscription
1108
+     *
1109
+     * @since  2.5
1110
+     * @return string
1111
+     */
1112
+    public function get_renew_url() {
1113
+        $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' );
1114
+        return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1115
+    }
1116
+
1117
+    /**
1118
+     * Determines if subscription can have their payment method updated
1119
+     *
1120
+     * @since  1.0.0
1121
+     * @return bool
1122
+     */
1123
+    public function can_update() {
1124
+        return apply_filters( 'wpinv_subscription_can_update', false, $this );
1125
+    }
1126
+
1127
+    /**
1128
+     * Retrieves the URL to update subscription
1129
+     *
1130
+     * @since  1.0.0
1131
+     * @return string
1132
+     */
1133
+    public function get_update_url() {
1134
+        $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) );
1135
+        return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1136
+    }
1137
+
1138
+    /**
1139
+     * Retrieves the subscription status label
1140
+     *
1141
+     * @since  1.0.0
1142
+     * @return string
1143
+     */
1144
+    public function get_status_label() {
1145
+        return getpaid_get_subscription_status_label( $this->get_status() );
1146
+    }
1147
+
1148
+    /**
1149
+     * Retrieves the subscription status class
1150
+     *
1151
+     * @since  1.0.19
1152
+     * @return string
1153
+     */
1154
+    public function get_status_class() {
1155
+        $statuses = getpaid_get_subscription_status_classes();
1156
+        return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark';
1157
+    }
1158 1158
 
1159 1159
     /**
1160 1160
      * Retrieves the subscription status label
@@ -1164,11 +1164,11 @@  discard block
 block discarded – undo
1164 1164
      */
1165 1165
     public function get_status_label_html() {
1166 1166
 
1167
-		$status_label = sanitize_text_field( $this->get_status_label() );
1168
-		$class        = esc_attr( $this->get_status_class() );
1169
-		$status       = sanitize_html_class( $this->get_status() );
1167
+        $status_label = sanitize_text_field( $this->get_status_label() );
1168
+        $class        = esc_attr( $this->get_status_class() );
1169
+        $status       = sanitize_html_class( $this->get_status() );
1170 1170
 
1171
-		return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
1171
+        return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
1172 1172
     }
1173 1173
 
1174 1174
     /**
@@ -1179,75 +1179,75 @@  discard block
 block discarded – undo
1179 1179
      * @return bool
1180 1180
      */
1181 1181
     public function payment_exists( $txn_id = '' ) {
1182
-		$invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1182
+        $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1183 1183
         return ! empty( $invoice_id );
1184
-	}
1185
-
1186
-	/**
1187
-	 * Handle the status transition.
1188
-	 */
1189
-	protected function status_transition() {
1190
-		$status_transition = $this->status_transition;
1191
-
1192
-		// Reset status transition variable.
1193
-		$this->status_transition = false;
1194
-
1195
-		if ( $status_transition ) {
1196
-			try {
1197
-
1198
-				// Fire a hook for the status change.
1199
-				do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1200
-				do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1201
-
1202
-				if ( ! empty( $status_transition['from'] ) ) {
1203
-
1204
-					/* translators: 1: old subscription status 2: new subscription status */
1205
-					$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'] ) );
1206
-
1207
-					// Note the transition occurred.
1208
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1209
-
1210
-					// Fire another hook.
1211
-					do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1212
-					do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1213
-
1214
-				} else {
1215
-					/* translators: %s: new invoice status */
1216
-					$transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1217
-
1218
-					// Note the transition occurred.
1219
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1220
-
1221
-				}
1222
-			} catch ( Exception $e ) {
1223
-				$this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1224
-			}
1225
-		}
1226
-
1227
-	}
1228
-
1229
-	/**
1230
-	 * Save data to the database.
1231
-	 *
1232
-	 * @since 1.0.19
1233
-	 * @return int subscription ID
1234
-	 */
1235
-	public function save() {
1236
-		parent::save();
1237
-		$this->status_transition();
1238
-		return $this->get_id();
1239
-	}
1240
-
1241
-	/**
1242
-	 * Activates a subscription.
1243
-	 *
1244
-	 * @since 1.0.19
1245
-	 * @return int subscription ID
1246
-	 */
1247
-	public function activate() {
1248
-		$status = 'trialling' == $this->get_status() ? 'trialling' : 'active';
1249
-		$this->set_status( $status );
1250
-		return $this->save();
1251
-	}
1184
+    }
1185
+
1186
+    /**
1187
+     * Handle the status transition.
1188
+     */
1189
+    protected function status_transition() {
1190
+        $status_transition = $this->status_transition;
1191
+
1192
+        // Reset status transition variable.
1193
+        $this->status_transition = false;
1194
+
1195
+        if ( $status_transition ) {
1196
+            try {
1197
+
1198
+                // Fire a hook for the status change.
1199
+                do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1200
+                do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1201
+
1202
+                if ( ! empty( $status_transition['from'] ) ) {
1203
+
1204
+                    /* translators: 1: old subscription status 2: new subscription status */
1205
+                    $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'] ) );
1206
+
1207
+                    // Note the transition occurred.
1208
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1209
+
1210
+                    // Fire another hook.
1211
+                    do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1212
+                    do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1213
+
1214
+                } else {
1215
+                    /* translators: %s: new invoice status */
1216
+                    $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1217
+
1218
+                    // Note the transition occurred.
1219
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1220
+
1221
+                }
1222
+            } catch ( Exception $e ) {
1223
+                $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1224
+            }
1225
+        }
1226
+
1227
+    }
1228
+
1229
+    /**
1230
+     * Save data to the database.
1231
+     *
1232
+     * @since 1.0.19
1233
+     * @return int subscription ID
1234
+     */
1235
+    public function save() {
1236
+        parent::save();
1237
+        $this->status_transition();
1238
+        return $this->get_id();
1239
+    }
1240
+
1241
+    /**
1242
+     * Activates a subscription.
1243
+     *
1244
+     * @since 1.0.19
1245
+     * @return int subscription ID
1246
+     */
1247
+    public function activate() {
1248
+        $status = 'trialling' == $this->get_status() ? 'trialling' : 'active';
1249
+        $this->set_status( $status );
1250
+        return $this->save();
1251
+    }
1252 1252
 
1253 1253
 }
Please login to merge, or discard this patch.
Spacing   +220 added lines, -220 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
@@ -68,27 +68,27 @@  discard block
 block discarded – undo
68 68
 	 * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
69 69
 	 * @param  bool $deprecated
70 70
 	 */
71
-	function __construct( $subscription = 0, $deprecated = false ) {
71
+	function __construct($subscription = 0, $deprecated = false) {
72 72
 
73
-		parent::__construct( $subscription );
73
+		parent::__construct($subscription);
74 74
 
75
-		if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
76
-			$this->set_id( $subscription );
77
-		} elseif ( $subscription instanceof self ) {
78
-			$this->set_id( $subscription->get_id() );
79
-		} elseif ( ! empty( $subscription->id ) ) {
80
-			$this->set_id( $subscription->id );
81
-		} elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
82
-			$this->set_id( $subscription_id );
75
+		if (!$deprecated && !empty($subscription) && is_numeric($subscription)) {
76
+			$this->set_id($subscription);
77
+		} elseif ($subscription instanceof self) {
78
+			$this->set_id($subscription->get_id());
79
+		} elseif (!empty($subscription->id)) {
80
+			$this->set_id($subscription->id);
81
+		} elseif ($deprecated && $subscription_id = self::get_subscription_id_by_field($subscription, 'profile_id')) {
82
+			$this->set_id($subscription_id);
83 83
 		} else {
84
-			$this->set_object_read( true );
84
+			$this->set_object_read(true);
85 85
 		}
86 86
 
87 87
 		// Load the datastore.
88
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
88
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
89 89
 
90
-		if ( $this->get_id() > 0 ) {
91
-			$this->data_store->read( $this );
90
+		if ($this->get_id() > 0) {
91
+			$this->data_store->read($this);
92 92
 		}
93 93
 
94 94
 	}
@@ -103,17 +103,17 @@  discard block
 block discarded – undo
103 103
 	 * @since 1.0.19
104 104
 	 * @return int
105 105
 	 */
106
-	public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
106
+	public static function get_subscription_id_by_field($value, $field = 'profile_id') {
107 107
         global $wpdb;
108 108
 
109 109
 		// Trim the value.
110
-		$value = trim( $value );
110
+		$value = trim($value);
111 111
 
112
-		if ( empty( $value ) ) {
112
+		if (empty($value)) {
113 113
 			return 0;
114 114
 		}
115 115
 
116
-		if ( 'invoice_id' == $field ) {
116
+		if ('invoice_id' == $field) {
117 117
 			$field = 'parent_payment_id';
118 118
 		}
119 119
 
@@ -125,28 +125,28 @@  discard block
 block discarded – undo
125 125
 		);
126 126
 
127 127
 		// Ensure a field has been passed.
128
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
128
+		if (empty($field) || !in_array($field, $fields)) {
129 129
 			return 0;
130 130
 		}
131 131
 
132 132
 		// Maybe retrieve from the cache.
133
-		$subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
134
-		if ( ! empty( $subscription_id ) ) {
133
+		$subscription_id = wp_cache_get($value, "getpaid_subscription_{$field}s_to_subscription_ids");
134
+		if (!empty($subscription_id)) {
135 135
 			return $subscription_id;
136 136
 		}
137 137
 
138 138
         // Fetch from the db.
139 139
         $table            = $wpdb->prefix . 'wpinv_subscriptions';
140 140
         $subscription_id  = (int) $wpdb->get_var(
141
-            $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
141
+            $wpdb->prepare("SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value)
142 142
         );
143 143
 
144
-		if ( empty( $subscription_id ) ) {
144
+		if (empty($subscription_id)) {
145 145
 			return 0;
146 146
 		}
147 147
 
148 148
 		// Update the cache with our data.
149
-		wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
149
+		wp_cache_set($value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids");
150 150
 
151 151
 		return $subscription_id;
152 152
 	}
@@ -155,17 +155,17 @@  discard block
 block discarded – undo
155 155
      * Clears the subscription's cache.
156 156
      */
157 157
     public function clear_cache() {
158
-		wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' );
159
-		wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' );
160
-		wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' );
161
-		wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' );
158
+		wp_cache_delete($this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids');
159
+		wp_cache_delete($this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids');
160
+		wp_cache_delete($this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids');
161
+		wp_cache_delete($this->get_id(), 'getpaid_subscriptions');
162 162
 	}
163 163
 
164 164
 	/**
165 165
      * Checks if a subscription key is set.
166 166
      */
167
-    public function _isset( $key ) {
168
-        return isset( $this->data[$key] ) || method_exists( $this, "get_$key" );
167
+    public function _isset($key) {
168
+        return isset($this->data[$key]) || method_exists($this, "get_$key");
169 169
 	}
170 170
 
171 171
 	/*
@@ -190,8 +190,8 @@  discard block
 block discarded – undo
190 190
 	 * @param  string $context View or edit context.
191 191
 	 * @return int
192 192
 	 */
193
-	public function get_customer_id( $context = 'view' ) {
194
-		return (int) $this->get_prop( 'customer_id', $context );
193
+	public function get_customer_id($context = 'view') {
194
+		return (int) $this->get_prop('customer_id', $context);
195 195
 	}
196 196
 
197 197
 	/**
@@ -201,8 +201,8 @@  discard block
 block discarded – undo
201 201
 	 * @param  string $context View or edit context.
202 202
 	 * @return WP_User|false WP_User object on success, false on failure.
203 203
 	 */
204
-	public function get_customer( $context = 'view' ) {
205
-		return get_userdata( $this->get_customer_id( $context ) );
204
+	public function get_customer($context = 'view') {
205
+		return get_userdata($this->get_customer_id($context));
206 206
 	}
207 207
 
208 208
 	/**
@@ -212,8 +212,8 @@  discard block
 block discarded – undo
212 212
 	 * @param  string $context View or edit context.
213 213
 	 * @return int
214 214
 	 */
215
-	public function get_parent_invoice_id( $context = 'view' ) {
216
-		return (int) $this->get_prop( 'parent_payment_id', $context );
215
+	public function get_parent_invoice_id($context = 'view') {
216
+		return (int) $this->get_prop('parent_payment_id', $context);
217 217
 	}
218 218
 
219 219
 	/**
@@ -223,8 +223,8 @@  discard block
 block discarded – undo
223 223
 	 * @param  string $context View or edit context.
224 224
 	 * @return int
225 225
 	 */
226
-    public function get_parent_payment_id( $context = 'view' ) {
227
-        return $this->get_parent_invoice_id( $context );
226
+    public function get_parent_payment_id($context = 'view') {
227
+        return $this->get_parent_invoice_id($context);
228 228
 	}
229 229
 
230 230
 	/**
@@ -233,8 +233,8 @@  discard block
 block discarded – undo
233 233
      * @since  1.0.0
234 234
      * @return int
235 235
      */
236
-    public function get_original_payment_id( $context = 'view' ) {
237
-        return $this->get_parent_invoice_id( $context );
236
+    public function get_original_payment_id($context = 'view') {
237
+        return $this->get_parent_invoice_id($context);
238 238
     }
239 239
 
240 240
 	/**
@@ -244,8 +244,8 @@  discard block
 block discarded – undo
244 244
 	 * @param  string $context View or edit context.
245 245
 	 * @return WPInv_Invoice
246 246
 	 */
247
-	public function get_parent_invoice( $context = 'view' ) {
248
-		return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
247
+	public function get_parent_invoice($context = 'view') {
248
+		return new WPInv_Invoice($this->get_parent_invoice_id($context));
249 249
 	}
250 250
 
251 251
 	/**
@@ -255,8 +255,8 @@  discard block
 block discarded – undo
255 255
 	 * @param  string $context View or edit context.
256 256
 	 * @return WPInv_Invoice
257 257
 	 */
258
-    public function get_parent_payment( $context = 'view' ) {
259
-        return $this->get_parent_invoice( $context );
258
+    public function get_parent_payment($context = 'view') {
259
+        return $this->get_parent_invoice($context);
260 260
 	}
261 261
 
262 262
 	/**
@@ -266,8 +266,8 @@  discard block
 block discarded – undo
266 266
 	 * @param  string $context View or edit context.
267 267
 	 * @return int
268 268
 	 */
269
-	public function get_product_id( $context = 'view' ) {
270
-		return (int) $this->get_prop( 'product_id', $context );
269
+	public function get_product_id($context = 'view') {
270
+		return (int) $this->get_prop('product_id', $context);
271 271
 	}
272 272
 
273 273
 	/**
@@ -277,8 +277,8 @@  discard block
 block discarded – undo
277 277
 	 * @param  string $context View or edit context.
278 278
 	 * @return WPInv_Item
279 279
 	 */
280
-	public function get_product( $context = 'view' ) {
281
-		return new WPInv_Item( $this->get_product_id( $context ) );
280
+	public function get_product($context = 'view') {
281
+		return new WPInv_Item($this->get_product_id($context));
282 282
 	}
283 283
 
284 284
 	/**
@@ -290,8 +290,8 @@  discard block
 block discarded – undo
290 290
 	 * @param  string $context View or edit context.
291 291
 	 * @return string
292 292
 	 */
293
-	public function get_gateway( $context = 'view' ) {
294
-		return $this->get_parent_invoice( $context )->get_gateway();
293
+	public function get_gateway($context = 'view') {
294
+		return $this->get_parent_invoice($context)->get_gateway();
295 295
 	}
296 296
 
297 297
 	/**
@@ -301,8 +301,8 @@  discard block
 block discarded – undo
301 301
 	 * @param  string $context View or edit context.
302 302
 	 * @return string
303 303
 	 */
304
-	public function get_period( $context = 'view' ) {
305
-		return $this->get_prop( 'period', $context );
304
+	public function get_period($context = 'view') {
305
+		return $this->get_prop('period', $context);
306 306
 	}
307 307
 
308 308
 	/**
@@ -312,8 +312,8 @@  discard block
 block discarded – undo
312 312
 	 * @param  string $context View or edit context.
313 313
 	 * @return int
314 314
 	 */
315
-	public function get_frequency( $context = 'view' ) {
316
-		return (int) $this->get_prop( 'frequency', $context );
315
+	public function get_frequency($context = 'view') {
316
+		return (int) $this->get_prop('frequency', $context);
317 317
 	}
318 318
 
319 319
 	/**
@@ -323,8 +323,8 @@  discard block
 block discarded – undo
323 323
 	 * @param  string $context View or edit context.
324 324
 	 * @return float
325 325
 	 */
326
-	public function get_initial_amount( $context = 'view' ) {
327
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
326
+	public function get_initial_amount($context = 'view') {
327
+		return (float) wpinv_sanitize_amount($this->get_prop('initial_amount', $context));
328 328
 	}
329 329
 
330 330
 	/**
@@ -334,8 +334,8 @@  discard block
 block discarded – undo
334 334
 	 * @param  string $context View or edit context.
335 335
 	 * @return float
336 336
 	 */
337
-	public function get_recurring_amount( $context = 'view' ) {
338
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
337
+	public function get_recurring_amount($context = 'view') {
338
+		return (float) wpinv_sanitize_amount($this->get_prop('recurring_amount', $context));
339 339
 	}
340 340
 
341 341
 	/**
@@ -345,8 +345,8 @@  discard block
 block discarded – undo
345 345
 	 * @param  string $context View or edit context.
346 346
 	 * @return int
347 347
 	 */
348
-	public function get_bill_times( $context = 'view' ) {
349
-		return (int) $this->get_prop( 'bill_times', $context );
348
+	public function get_bill_times($context = 'view') {
349
+		return (int) $this->get_prop('bill_times', $context);
350 350
 	}
351 351
 
352 352
 	/**
@@ -356,8 +356,8 @@  discard block
 block discarded – undo
356 356
 	 * @param  string $context View or edit context.
357 357
 	 * @return string
358 358
 	 */
359
-	public function get_transaction_id( $context = 'view' ) {
360
-		return $this->get_prop( 'transaction_id', $context );
359
+	public function get_transaction_id($context = 'view') {
360
+		return $this->get_prop('transaction_id', $context);
361 361
 	}
362 362
 
363 363
 	/**
@@ -367,8 +367,8 @@  discard block
 block discarded – undo
367 367
 	 * @param  string $context View or edit context.
368 368
 	 * @return string
369 369
 	 */
370
-	public function get_created( $context = 'view' ) {
371
-		return $this->get_prop( 'created', $context );
370
+	public function get_created($context = 'view') {
371
+		return $this->get_prop('created', $context);
372 372
 	}
373 373
 
374 374
 	/**
@@ -378,8 +378,8 @@  discard block
 block discarded – undo
378 378
 	 * @param  string $context View or edit context.
379 379
 	 * @return string
380 380
 	 */
381
-	public function get_date_created( $context = 'view' ) {
382
-		return $this->get_created( $context );
381
+	public function get_date_created($context = 'view') {
382
+		return $this->get_created($context);
383 383
 	}
384 384
 
385 385
 	/**
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
 	 */
391 391
 	public function get_time_created() {
392 392
 		$created = $this->get_date_created();
393
-		return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
393
+		return empty($created) ? current_time('timestamp') : strtotime($created, current_time('timestamp'));
394 394
 	}
395 395
 
396 396
 	/**
@@ -400,11 +400,11 @@  discard block
 block discarded – undo
400 400
 	 * @param  string $context View or edit context.
401 401
 	 * @return string
402 402
 	 */
403
-	public function get_date_created_gmt( $context = 'view' ) {
404
-        $date = $this->get_date_created( $context );
403
+	public function get_date_created_gmt($context = 'view') {
404
+        $date = $this->get_date_created($context);
405 405
 
406
-        if ( $date ) {
407
-            $date = get_gmt_from_date( $date );
406
+        if ($date) {
407
+            $date = get_gmt_from_date($date);
408 408
         }
409 409
 		return $date;
410 410
 	}
@@ -416,8 +416,8 @@  discard block
 block discarded – undo
416 416
 	 * @param  string $context View or edit context.
417 417
 	 * @return string
418 418
 	 */
419
-	public function get_next_renewal_date( $context = 'view' ) {
420
-		return $this->get_prop( 'expiration', $context );
419
+	public function get_next_renewal_date($context = 'view') {
420
+		return $this->get_prop('expiration', $context);
421 421
 	}
422 422
 
423 423
 	/**
@@ -427,8 +427,8 @@  discard block
 block discarded – undo
427 427
 	 * @param  string $context View or edit context.
428 428
 	 * @return string
429 429
 	 */
430
-	public function get_expiration( $context = 'view' ) {
431
-		return $this->get_next_renewal_date( $context );
430
+	public function get_expiration($context = 'view') {
431
+		return $this->get_next_renewal_date($context);
432 432
 	}
433 433
 
434 434
 	/**
@@ -440,12 +440,12 @@  discard block
 block discarded – undo
440 440
 	public function get_expiration_time() {
441 441
 		$expiration = $this->get_expiration();
442 442
 
443
-		if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
444
-			return current_time( 'timestamp' );
443
+		if (empty($expiration) || '0000-00-00 00:00:00' == $expiration) {
444
+			return current_time('timestamp');
445 445
 		}
446 446
 
447
-		$expiration = strtotime( $expiration, current_time( 'timestamp' ) );
448
-		return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
447
+		$expiration = strtotime($expiration, current_time('timestamp'));
448
+		return $expiration < current_time('timestamp') ? current_time('timestamp') : $expiration;
449 449
 	}
450 450
 
451 451
 	/**
@@ -455,11 +455,11 @@  discard block
 block discarded – undo
455 455
 	 * @param  string $context View or edit context.
456 456
 	 * @return string
457 457
 	 */
458
-	public function get_next_renewal_date_gmt( $context = 'view' ) {
459
-        $date = $this->get_next_renewal_date( $context );
458
+	public function get_next_renewal_date_gmt($context = 'view') {
459
+        $date = $this->get_next_renewal_date($context);
460 460
 
461
-        if ( $date ) {
462
-            $date = get_gmt_from_date( $date );
461
+        if ($date) {
462
+            $date = get_gmt_from_date($date);
463 463
         }
464 464
 		return $date;
465 465
 	}
@@ -471,8 +471,8 @@  discard block
 block discarded – undo
471 471
 	 * @param  string $context View or edit context.
472 472
 	 * @return string
473 473
 	 */
474
-	public function get_trial_period( $context = 'view' ) {
475
-		return $this->get_prop( 'trial_period', $context );
474
+	public function get_trial_period($context = 'view') {
475
+		return $this->get_prop('trial_period', $context);
476 476
 	}
477 477
 
478 478
 	/**
@@ -482,8 +482,8 @@  discard block
 block discarded – undo
482 482
 	 * @param  string $context View or edit context.
483 483
 	 * @return string
484 484
 	 */
485
-	public function get_status( $context = 'view' ) {
486
-		return $this->get_prop( 'status', $context );
485
+	public function get_status($context = 'view') {
486
+		return $this->get_prop('status', $context);
487 487
 	}
488 488
 
489 489
 	/**
@@ -493,8 +493,8 @@  discard block
 block discarded – undo
493 493
 	 * @param  string $context View or edit context.
494 494
 	 * @return string
495 495
 	 */
496
-	public function get_profile_id( $context = 'view' ) {
497
-		return $this->get_prop( 'profile_id', $context );
496
+	public function get_profile_id($context = 'view') {
497
+		return $this->get_prop('profile_id', $context);
498 498
 	}
499 499
 
500 500
 	/*
@@ -509,8 +509,8 @@  discard block
 block discarded – undo
509 509
 	 * @since 1.0.19
510 510
 	 * @param  int $value The customer's id.
511 511
 	 */
512
-	public function set_customer_id( $value ) {
513
-		$this->set_prop( 'customer_id', (int) $value );
512
+	public function set_customer_id($value) {
513
+		$this->set_prop('customer_id', (int) $value);
514 514
 	}
515 515
 
516 516
 	/**
@@ -519,8 +519,8 @@  discard block
 block discarded – undo
519 519
 	 * @since 1.0.19
520 520
 	 * @param  int $value The parent invoice id.
521 521
 	 */
522
-	public function set_parent_invoice_id( $value ) {
523
-		$this->set_prop( 'parent_payment_id', (int) $value );
522
+	public function set_parent_invoice_id($value) {
523
+		$this->set_prop('parent_payment_id', (int) $value);
524 524
 	}
525 525
 
526 526
 	/**
@@ -529,8 +529,8 @@  discard block
 block discarded – undo
529 529
 	 * @since 1.0.19
530 530
 	 * @param  int $value The parent invoice id.
531 531
 	 */
532
-    public function set_parent_payment_id( $value ) {
533
-        $this->set_parent_invoice_id( $value );
532
+    public function set_parent_payment_id($value) {
533
+        $this->set_parent_invoice_id($value);
534 534
 	}
535 535
 
536 536
 	/**
@@ -539,8 +539,8 @@  discard block
 block discarded – undo
539 539
      * @since 1.0.19
540 540
 	 * @param  int $value The parent invoice id.
541 541
      */
542
-    public function set_original_payment_id( $value ) {
543
-        $this->set_parent_invoice_id( $value );
542
+    public function set_original_payment_id($value) {
543
+        $this->set_parent_invoice_id($value);
544 544
 	}
545 545
 
546 546
 	/**
@@ -549,8 +549,8 @@  discard block
 block discarded – undo
549 549
 	 * @since 1.0.19
550 550
 	 * @param  int $value The subscription product id.
551 551
 	 */
552
-	public function set_product_id( $value ) {
553
-		$this->set_prop( 'product_id', (int) $value );
552
+	public function set_product_id($value) {
553
+		$this->set_prop('product_id', (int) $value);
554 554
 	}
555 555
 
556 556
 	/**
@@ -559,8 +559,8 @@  discard block
 block discarded – undo
559 559
 	 * @since 1.0.19
560 560
 	 * @param  string $value The renewal period.
561 561
 	 */
562
-	public function set_period( $value ) {
563
-		$this->set_prop( 'period', $value );
562
+	public function set_period($value) {
563
+		$this->set_prop('period', $value);
564 564
 	}
565 565
 
566 566
 	/**
@@ -569,9 +569,9 @@  discard block
 block discarded – undo
569 569
 	 * @since 1.0.19
570 570
 	 * @param  int $value The subscription frequency.
571 571
 	 */
572
-	public function set_frequency( $value ) {
573
-		$value = empty( $value ) ? 1 : (int) $value;
574
-		$this->set_prop( 'frequency', absint( $value ) );
572
+	public function set_frequency($value) {
573
+		$value = empty($value) ? 1 : (int) $value;
574
+		$this->set_prop('frequency', absint($value));
575 575
 	}
576 576
 
577 577
 	/**
@@ -580,8 +580,8 @@  discard block
 block discarded – undo
580 580
 	 * @since 1.0.19
581 581
 	 * @param  float $value The initial subcription amount.
582 582
 	 */
583
-	public function set_initial_amount( $value ) {
584
-		$this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
583
+	public function set_initial_amount($value) {
584
+		$this->set_prop('initial_amount', wpinv_sanitize_amount($value));
585 585
 	}
586 586
 
587 587
 	/**
@@ -590,8 +590,8 @@  discard block
 block discarded – undo
590 590
 	 * @since 1.0.19
591 591
 	 * @param  float $value The recurring subcription amount.
592 592
 	 */
593
-	public function set_recurring_amount( $value ) {
594
-		$this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
593
+	public function set_recurring_amount($value) {
594
+		$this->set_prop('recurring_amount', wpinv_sanitize_amount($value));
595 595
 	}
596 596
 
597 597
 	/**
@@ -600,8 +600,8 @@  discard block
 block discarded – undo
600 600
 	 * @since 1.0.19
601 601
 	 * @param  int $value Bill times.
602 602
 	 */
603
-	public function set_bill_times( $value ) {
604
-		$this->set_prop( 'bill_times', (int) $value );
603
+	public function set_bill_times($value) {
604
+		$this->set_prop('bill_times', (int) $value);
605 605
 	}
606 606
 
607 607
 	/**
@@ -610,8 +610,8 @@  discard block
 block discarded – undo
610 610
 	 * @since 1.0.19
611 611
 	 * @param string $value Bill times.
612 612
 	 */
613
-	public function set_transaction_id( $value ) {
614
-		$this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
613
+	public function set_transaction_id($value) {
614
+		$this->set_prop('transaction_id', sanitize_text_field($value));
615 615
 	}
616 616
 
617 617
 	/**
@@ -620,15 +620,15 @@  discard block
 block discarded – undo
620 620
 	 * @since 1.0.19
621 621
 	 * @param string $value strtotime compliant date.
622 622
 	 */
623
-	public function set_created( $value ) {
624
-        $date = strtotime( $value );
623
+	public function set_created($value) {
624
+        $date = strtotime($value);
625 625
 
626
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
627
-            $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) );
626
+        if ($date && $value !== '0000-00-00 00:00:00') {
627
+            $this->set_prop('created', date('Y-m-d H:i:s', $date));
628 628
             return;
629 629
         }
630 630
 
631
-		$this->set_prop( 'created', '' );
631
+		$this->set_prop('created', '');
632 632
 
633 633
 	}
634 634
 
@@ -638,8 +638,8 @@  discard block
 block discarded – undo
638 638
 	 * @since 1.0.19
639 639
 	 * @param string $value strtotime compliant date.
640 640
 	 */
641
-	public function set_date_created( $value ) {
642
-		$this->set_created( $value );
641
+	public function set_date_created($value) {
642
+		$this->set_created($value);
643 643
     }
644 644
 
645 645
 	/**
@@ -648,15 +648,15 @@  discard block
 block discarded – undo
648 648
 	 * @since 1.0.19
649 649
 	 * @param string $value strtotime compliant date.
650 650
 	 */
651
-	public function set_next_renewal_date( $value ) {
652
-		$date = strtotime( $value );
651
+	public function set_next_renewal_date($value) {
652
+		$date = strtotime($value);
653 653
 
654
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
655
-            $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) );
654
+        if ($date && $value !== '0000-00-00 00:00:00') {
655
+            $this->set_prop('expiration', date('Y-m-d H:i:s', $date));
656 656
             return;
657 657
 		}
658 658
 
659
-		$this->set_prop( 'expiration', '' );
659
+		$this->set_prop('expiration', '');
660 660
 
661 661
 	}
662 662
 
@@ -666,8 +666,8 @@  discard block
 block discarded – undo
666 666
 	 * @since 1.0.19
667 667
 	 * @param string $value strtotime compliant date.
668 668
 	 */
669
-	public function set_expiration( $value ) {
670
-		$this->set_next_renewal_date( $value );
669
+	public function set_expiration($value) {
670
+		$this->set_next_renewal_date($value);
671 671
     }
672 672
 
673 673
 	/**
@@ -676,8 +676,8 @@  discard block
 block discarded – undo
676 676
 	 * @since 1.0.19
677 677
 	 * @param string $value trial period e.g 1 year.
678 678
 	 */
679
-	public function set_trial_period( $value ) {
680
-		$this->set_prop( 'trial_period', $value );
679
+	public function set_trial_period($value) {
680
+		$this->set_prop('trial_period', $value);
681 681
 	}
682 682
 
683 683
 	/**
@@ -686,19 +686,19 @@  discard block
 block discarded – undo
686 686
 	 * @since 1.0.19
687 687
 	 * @param string $new_status    New subscription status.
688 688
 	 */
689
-	public function set_status( $new_status ) {
689
+	public function set_status($new_status) {
690 690
 
691 691
 		// Abort if this is not a valid status;
692
-		if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
692
+		if (!array_key_exists($new_status, getpaid_get_subscription_statuses())) {
693 693
 			return;
694 694
 		}
695 695
 
696 696
 		$old_status = $this->get_status();
697
-		$this->set_prop( 'status', $new_status );
697
+		$this->set_prop('status', $new_status);
698 698
 
699
-		if ( true === $this->object_read && $old_status !== $new_status ) {
699
+		if (true === $this->object_read && $old_status !== $new_status) {
700 700
 			$this->status_transition = array(
701
-				'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
701
+				'from'   => !empty($this->status_transition['from']) ? $this->status_transition['from'] : $old_status,
702 702
 				'to'     => $new_status,
703 703
 			);
704 704
 		}
@@ -711,8 +711,8 @@  discard block
 block discarded – undo
711 711
 	 * @since 1.0.19
712 712
 	 * @param  string $value the remote profile id.
713 713
 	 */
714
-	public function set_profile_id( $value ) {
715
-		$this->set_prop( 'profile_id', sanitize_text_field( $value ) );
714
+	public function set_profile_id($value) {
715
+		$this->set_prop('profile_id', sanitize_text_field($value));
716 716
 	}
717 717
 
718 718
 	/*
@@ -730,8 +730,8 @@  discard block
 block discarded – undo
730 730
 	 * @param string|array String or array of strings to check for.
731 731
 	 * @return bool
732 732
      */
733
-    public function has_status( $status ) {
734
-        return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) );
733
+    public function has_status($status) {
734
+        return in_array($this->get_status(), wpinv_clean(wpinv_parse_list($status)));
735 735
 	}
736 736
 
737 737
 	/**
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
      */
742 742
     public function has_trial_period() {
743 743
 		$period = $this->get_trial_period();
744
-        return ! empty( $period );
744
+        return !empty($period);
745 745
 	}
746 746
 
747 747
 	/**
@@ -750,7 +750,7 @@  discard block
 block discarded – undo
750 750
 	 * @return bool
751 751
 	 */
752 752
 	public function is_active() {
753
-		return $this->has_status( 'active trialling' ) && ! $this->is_expired();
753
+		return $this->has_status('active trialling') && !$this->is_expired();
754 754
 	}
755 755
 
756 756
 	/**
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
 	 * @return bool
760 760
 	 */
761 761
 	public function is_expired() {
762
-		return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) );
762
+		return $this->has_status('expired') || ($this->has_status('active cancelled trialling') && $this->get_expiration_time() < current_time('mysql'));
763 763
 	}
764 764
 
765 765
 	/**
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
 	 */
770 770
 	public function is_last_renewal() {
771 771
 		$max_bills = $this->get_bill_times();
772
-		return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed();
772
+		return !empty($max_bills) && $max_bills <= $this->get_times_billed();
773 773
 	}
774 774
 
775 775
 	/*
@@ -784,11 +784,11 @@  discard block
 block discarded – undo
784 784
 	/**
785 785
 	 * Backwards compatibilty.
786 786
 	 */
787
-	public function create( $data = array() ) {
787
+	public function create($data = array()) {
788 788
 
789 789
 		// Set the properties.
790
-		if ( is_array( $data ) ) {
791
-			$this->set_props( $data );
790
+		if (is_array($data)) {
791
+			$this->set_props($data);
792 792
 		}
793 793
 
794 794
 		// Save the item.
@@ -799,8 +799,8 @@  discard block
 block discarded – undo
799 799
 	/**
800 800
 	 * Backwards compatibilty.
801 801
 	 */
802
-	public function update( $args = array() ) {
803
-		return $this->create( $args );
802
+	public function update($args = array()) {
803
+		return $this->create($args);
804 804
 	}
805 805
 
806 806
     /**
@@ -809,12 +809,12 @@  discard block
 block discarded – undo
809 809
      * @since  1.0.0
810 810
      * @return WP_Post[]
811 811
      */
812
-    public function get_child_payments( $hide_pending = true ) {
812
+    public function get_child_payments($hide_pending = true) {
813 813
 
814
-		$statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' );
814
+		$statuses = array('publish', 'wpi-processing', 'wpi-renewal');
815 815
 
816
-		if ( ! $hide_pending ) {
817
-			$statuses = array_keys( wpinv_get_invoice_statuses() );
816
+		if (!$hide_pending) {
817
+			$statuses = array_keys(wpinv_get_invoice_statuses());
818 818
 		}
819 819
 
820 820
         return get_posts(
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
 		);
847 847
 
848 848
 		// Maybe include parent invoice.
849
-        if ( $this->get_parent_payment()->is_paid() ) {
849
+        if ($this->get_parent_payment()->is_paid()) {
850 850
             $count++;
851 851
         }
852 852
 
@@ -862,7 +862,7 @@  discard block
 block discarded – undo
862 862
     public function get_times_billed() {
863 863
         $times_billed = $this->get_total_payments();
864 864
 
865
-        if ( (float) $this->get_initial_amount() == 0 && $times_billed > 0 ) {
865
+        if ((float) $this->get_initial_amount() == 0 && $times_billed > 0) {
866 866
             $times_billed--;
867 867
         }
868 868
 
@@ -877,57 +877,57 @@  discard block
 block discarded – undo
877 877
 	 * @param  WPInv_Invoice $invoice If adding an existing invoice.
878 878
      * @return bool
879 879
      */
880
-    public function add_payment( $args = array(), $invoice = false ) {
880
+    public function add_payment($args = array(), $invoice = false) {
881 881
 
882 882
 		// Process each payment once.
883
-        if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) {
883
+        if (!empty($args['transaction_id']) && $this->payment_exists($args['transaction_id'])) {
884 884
             return false;
885 885
         }
886 886
 		
887 887
 		// Check is it one time payment
888
-		$item = new WPInv_Item( $this->get_product_id() );
888
+		$item = new WPInv_Item($this->get_product_id());
889 889
 		$is_one_time_payment = $item->is_one_time_recurring();
890
-        if ( $is_one_time_payment == 1 ) {
890
+        if ($is_one_time_payment == 1) {
891 891
             $this->complete();
892 892
 			return true;
893 893
         } 
894 894
 
895 895
 		// Are we creating a new invoice?
896
-		if ( empty( $invoice ) ) {
896
+		if (empty($invoice)) {
897 897
 			$invoice = $this->create_payment();
898 898
 
899
-			if ( empty( $invoice ) ) {
899
+			if (empty($invoice)) {
900 900
 				return false;
901 901
 			}
902 902
 
903 903
 		}
904 904
 
905
-		$invoice->set_status( 'wpi-renewal' );
905
+		$invoice->set_status('wpi-renewal');
906 906
 
907 907
 		// Maybe set a transaction id.
908
-		if ( ! empty( $args['transaction_id'] ) ) {
909
-			$invoice->set_transaction_id( $args['transaction_id'] );
908
+		if (!empty($args['transaction_id'])) {
909
+			$invoice->set_transaction_id($args['transaction_id']);
910 910
 		}
911 911
 
912 912
 		// Set the completed date.
913
-		$invoice->set_completed_date( current_time( 'mysql' ) );
913
+		$invoice->set_completed_date(current_time('mysql'));
914 914
 
915 915
 		// And the gateway.
916
-		if ( ! empty( $args['gateway'] ) ) {
917
-			$invoice->set_gateway( $args['gateway'] );
916
+		if (!empty($args['gateway'])) {
917
+			$invoice->set_gateway($args['gateway']);
918 918
 		}
919 919
 
920 920
 		$invoice->save();
921 921
 
922
-		if ( ! $invoice->exists() ) {
922
+		if (!$invoice->exists()) {
923 923
 			return false;
924 924
 		}
925 925
 
926
-		do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
927
-		do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
928
-        do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() );
926
+		do_action('getpaid_after_create_subscription_renewal_invoice', $invoice, $this);
927
+		do_action('wpinv_recurring_add_subscription_payment', $invoice, $this);
928
+        do_action('wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id());
929 929
 
930
-        update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id );
930
+        update_post_meta($invoice->get_id(), '_wpinv_subscription_id', $this->id);
931 931
 
932 932
         return $invoice->get_id();
933 933
 	}
@@ -942,15 +942,15 @@  discard block
 block discarded – undo
942 942
 
943 943
 		$parent_invoice = $this->get_parent_payment();
944 944
 
945
-		if ( ! $parent_invoice->exists() ) {
945
+		if (!$parent_invoice->exists()) {
946 946
 			return false;
947 947
 		}
948 948
 
949 949
 		// Duplicate the parent invoice.
950
-		$invoice = getpaid_duplicate_invoice( $parent_invoice );
951
-		$invoice->set_parent_id( $parent_invoice->get_id() );
950
+		$invoice = getpaid_duplicate_invoice($parent_invoice);
951
+		$invoice->set_parent_id($parent_invoice->get_id());
952 952
 		$invoice->recalculate_total();
953
-		$invoice->set_status( 'wpi-pending' );
953
+		$invoice->set_status('wpi-pending');
954 954
 		$invoice->save();
955 955
 
956 956
 		return $invoice->exists() ? $invoice : false;
@@ -965,20 +965,20 @@  discard block
 block discarded – undo
965 965
 	public function renew() {
966 966
 
967 967
 		// Complete subscription if applicable
968
-		if ( $this->is_last_renewal() ) {
968
+		if ($this->is_last_renewal()) {
969 969
 			return $this->complete();
970 970
 		}
971 971
 
972 972
 		// Calculate new expiration
973 973
 		$frequency      = $this->get_frequency();
974 974
 		$period         = $this->get_period();
975
-		$new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
975
+		$new_expiration = strtotime("+ $frequency $period", $this->get_expiration_time());
976 976
 
977
-		$this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) );
978
-		$this->set_status( 'active' );
977
+		$this->set_expiration(date('Y-m-d H:i:s', $new_expiration));
978
+		$this->set_status('active');
979 979
 		$this->save();
980 980
 
981
-		do_action( 'getpaid_subscription_renewed', $this );
981
+		do_action('getpaid_subscription_renewed', $this);
982 982
 
983 983
 		return $this->get_id();
984 984
 	}
@@ -994,11 +994,11 @@  discard block
 block discarded – undo
994 994
 	public function complete() {
995 995
 
996 996
 		// Only mark a subscription as complete if it's not already cancelled.
997
-		if ( $this->has_status( 'cancelled' ) ) {
997
+		if ($this->has_status('cancelled')) {
998 998
 			return false;
999 999
 		}
1000 1000
 
1001
-		$this->set_status( 'completed' );
1001
+		$this->set_status('completed');
1002 1002
 		return $this->save();
1003 1003
 
1004 1004
 	}
@@ -1010,14 +1010,14 @@  discard block
 block discarded – undo
1010 1010
 	 * @param  bool $check_expiration
1011 1011
 	 * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1012 1012
 	 */
1013
-	public function expire( $check_expiration = false ) {
1013
+	public function expire($check_expiration = false) {
1014 1014
 
1015
-		if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1015
+		if ($check_expiration && $this->get_expiration_time() > current_time('timestamp')) {
1016 1016
 			// Do not mark as expired since real expiration date is in the future
1017 1017
 			return false;
1018 1018
 		}
1019 1019
 
1020
-		$this->set_status( 'expired' );
1020
+		$this->set_status('expired');
1021 1021
 		return $this->save();
1022 1022
 
1023 1023
 	}
@@ -1029,7 +1029,7 @@  discard block
 block discarded – undo
1029 1029
 	 * @return int Subscription id.
1030 1030
 	 */
1031 1031
 	public function failing() {
1032
-		$this->set_status( 'failing' );
1032
+		$this->set_status('failing');
1033 1033
 		return $this->save();
1034 1034
 	}
1035 1035
 
@@ -1040,7 +1040,7 @@  discard block
 block discarded – undo
1040 1040
      * @return int Subscription id.
1041 1041
      */
1042 1042
     public function cancel() {
1043
-		$this->set_status( 'cancelled' );
1043
+		$this->set_status('cancelled');
1044 1044
 		return $this->save();
1045 1045
     }
1046 1046
 
@@ -1051,7 +1051,7 @@  discard block
 block discarded – undo
1051 1051
 	 * @return bool
1052 1052
 	 */
1053 1053
 	public function can_cancel() {
1054
-		return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1054
+		return apply_filters('wpinv_subscription_can_cancel', $this->has_status($this->get_cancellable_statuses()), $this);
1055 1055
 	}
1056 1056
 
1057 1057
     /**
@@ -1062,7 +1062,7 @@  discard block
 block discarded – undo
1062 1062
      * @return      array
1063 1063
      */
1064 1064
     public function get_cancellable_statuses() {
1065
-        return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) );
1065
+        return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing'));
1066 1066
     }
1067 1067
 
1068 1068
 	/**
@@ -1072,8 +1072,8 @@  discard block
 block discarded – undo
1072 1072
 	 * @return string
1073 1073
 	 */
1074 1074
 	public function get_cancel_url() {
1075
-		$url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1076
-		return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1075
+		$url = getpaid_get_authenticated_action_url('subscription_cancel', $this->get_view_url());
1076
+		return apply_filters('wpinv_subscription_cancel_url', $url, $this);
1077 1077
 	}
1078 1078
 
1079 1079
 	/**
@@ -1084,10 +1084,10 @@  discard block
 block discarded – undo
1084 1084
 	 */
1085 1085
 	public function get_view_url() {
1086 1086
 
1087
-		$url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1088
-		$url = add_query_arg( 'subscription', $this->get_id(), $url );
1087
+		$url = getpaid_get_tab_url('gp-subscriptions', get_permalink((int) wpinv_get_option('invoice_subscription_page')));
1088
+		$url = add_query_arg('subscription', $this->get_id(), $url);
1089 1089
 
1090
-		return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1090
+		return apply_filters('getpaid_get_subscription_view_url', $url, $this);
1091 1091
 	}
1092 1092
 
1093 1093
 	/**
@@ -1100,7 +1100,7 @@  discard block
 block discarded – undo
1100 1100
 	 * @return bool
1101 1101
 	 */
1102 1102
 	public function can_renew() {
1103
-		return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1103
+		return apply_filters('wpinv_subscription_can_renew', true, $this);
1104 1104
 	}
1105 1105
 
1106 1106
 	/**
@@ -1110,8 +1110,8 @@  discard block
 block discarded – undo
1110 1110
 	 * @return string
1111 1111
 	 */
1112 1112
 	public function get_renew_url() {
1113
-		$url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' );
1114
-		return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1113
+		$url = wp_nonce_url(add_query_arg(array('getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id)), 'getpaid-nonce');
1114
+		return apply_filters('wpinv_subscription_renew_url', $url, $this);
1115 1115
 	}
1116 1116
 
1117 1117
 	/**
@@ -1121,7 +1121,7 @@  discard block
 block discarded – undo
1121 1121
 	 * @return bool
1122 1122
 	 */
1123 1123
 	public function can_update() {
1124
-		return apply_filters( 'wpinv_subscription_can_update', false, $this );
1124
+		return apply_filters('wpinv_subscription_can_update', false, $this);
1125 1125
 	}
1126 1126
 
1127 1127
 	/**
@@ -1131,8 +1131,8 @@  discard block
 block discarded – undo
1131 1131
 	 * @return string
1132 1132
 	 */
1133 1133
 	public function get_update_url() {
1134
-		$url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) );
1135
-		return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1134
+		$url = add_query_arg(array('action' => 'update', 'subscription_id' => $this->get_id()));
1135
+		return apply_filters('wpinv_subscription_update_url', $url, $this);
1136 1136
 	}
1137 1137
 
1138 1138
 	/**
@@ -1142,7 +1142,7 @@  discard block
 block discarded – undo
1142 1142
 	 * @return string
1143 1143
 	 */
1144 1144
 	public function get_status_label() {
1145
-		return getpaid_get_subscription_status_label( $this->get_status() );
1145
+		return getpaid_get_subscription_status_label($this->get_status());
1146 1146
 	}
1147 1147
 
1148 1148
 	/**
@@ -1153,7 +1153,7 @@  discard block
 block discarded – undo
1153 1153
 	 */
1154 1154
 	public function get_status_class() {
1155 1155
 		$statuses = getpaid_get_subscription_status_classes();
1156
-		return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark';
1156
+		return isset($statuses[$this->get_status()]) ? $statuses[$this->get_status()] : 'badge-dark';
1157 1157
 	}
1158 1158
 
1159 1159
     /**
@@ -1164,9 +1164,9 @@  discard block
 block discarded – undo
1164 1164
      */
1165 1165
     public function get_status_label_html() {
1166 1166
 
1167
-		$status_label = sanitize_text_field( $this->get_status_label() );
1168
-		$class        = esc_attr( $this->get_status_class() );
1169
-		$status       = sanitize_html_class( $this->get_status() );
1167
+		$status_label = sanitize_text_field($this->get_status_label());
1168
+		$class        = esc_attr($this->get_status_class());
1169
+		$status       = sanitize_html_class($this->get_status());
1170 1170
 
1171 1171
 		return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
1172 1172
     }
@@ -1178,9 +1178,9 @@  discard block
 block discarded – undo
1178 1178
      * @param  string $txn_id The transaction ID from the merchant processor
1179 1179
      * @return bool
1180 1180
      */
1181
-    public function payment_exists( $txn_id = '' ) {
1182
-		$invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1183
-        return ! empty( $invoice_id );
1181
+    public function payment_exists($txn_id = '') {
1182
+		$invoice_id = WPInv_Invoice::get_invoice_id_by_field($txn_id, 'transaction_id');
1183
+        return !empty($invoice_id);
1184 1184
 	}
1185 1185
 
1186 1186
 	/**
@@ -1192,35 +1192,35 @@  discard block
 block discarded – undo
1192 1192
 		// Reset status transition variable.
1193 1193
 		$this->status_transition = false;
1194 1194
 
1195
-		if ( $status_transition ) {
1195
+		if ($status_transition) {
1196 1196
 			try {
1197 1197
 
1198 1198
 				// Fire a hook for the status change.
1199
-				do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1200
-				do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1199
+				do_action('wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition);
1200
+				do_action('getpaid_subscription_' . $status_transition['to'], $this, $status_transition);
1201 1201
 
1202
-				if ( ! empty( $status_transition['from'] ) ) {
1202
+				if (!empty($status_transition['from'])) {
1203 1203
 
1204 1204
 					/* translators: 1: old subscription status 2: new subscription status */
1205
-					$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'] ) );
1205
+					$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']));
1206 1206
 
1207 1207
 					// Note the transition occurred.
1208
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1208
+					$this->get_parent_payment()->add_note($transition_note, false, false, true);
1209 1209
 
1210 1210
 					// Fire another hook.
1211
-					do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1212
-					do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1211
+					do_action('getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this);
1212
+					do_action('getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to']);
1213 1213
 
1214 1214
 				} else {
1215 1215
 					/* translators: %s: new invoice status */
1216
-					$transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1216
+					$transition_note = sprintf(__('Subscription status set to %s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['to']));
1217 1217
 
1218 1218
 					// Note the transition occurred.
1219
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1219
+					$this->get_parent_payment()->add_note($transition_note, false, false, true);
1220 1220
 
1221 1221
 				}
1222
-			} catch ( Exception $e ) {
1223
-				$this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1222
+			} catch (Exception $e) {
1223
+				$this->get_parent_payment()->add_note(__('Error during subscription status transition.', 'invoicing') . ' ' . $e->getMessage());
1224 1224
 			}
1225 1225
 		}
1226 1226
 
@@ -1246,7 +1246,7 @@  discard block
 block discarded – undo
1246 1246
 	 */
1247 1247
 	public function activate() {
1248 1248
 		$status = 'trialling' == $this->get_status() ? 'trialling' : 'active';
1249
-		$this->set_status( $status );
1249
+		$this->set_status($status);
1250 1250
 		return $this->save();
1251 1251
 	}
1252 1252
 
Please login to merge, or discard this patch.
includes/class-wpinv-item.php 2 patches
Indentation   +759 added lines, -759 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,30 +10,30 @@  discard block
 block discarded – undo
10 10
 class WPInv_Item  extends GetPaid_Data {
11 11
 
12 12
     /**
13
-	 * Which data store to load.
14
-	 *
15
-	 * @var string
16
-	 */
13
+     * Which data store to load.
14
+     *
15
+     * @var string
16
+     */
17 17
     protected $data_store_name = 'item';
18 18
 
19 19
     /**
20
-	 * This is the name of this object type.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	protected $object_type = 'item';
20
+     * This is the name of this object type.
21
+     *
22
+     * @var string
23
+     */
24
+    protected $object_type = 'item';
25 25
 
26 26
     /**
27
-	 * Item Data array. This is the core item data exposed in APIs.
28
-	 *
29
-	 * @since 1.0.19
30
-	 * @var array
31
-	 */
32
-	protected $data = array(
33
-		'parent_id'            => 0,
34
-		'status'               => 'draft',
35
-		'version'              => '',
36
-		'date_created'         => null,
27
+     * Item Data array. This is the core item data exposed in APIs.
28
+     *
29
+     * @since 1.0.19
30
+     * @var array
31
+     */
32
+    protected $data = array(
33
+        'parent_id'            => 0,
34
+        'status'               => 'draft',
35
+        'version'              => '',
36
+        'date_created'         => null,
37 37
         'date_modified'        => null,
38 38
         'name'                 => '',
39 39
         'description'          => '',
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
         'is_dynamic_pricing'   => null,
50 50
         'minimum_price'        => null,
51 51
         'is_recurring'         => null,
52
-		'is_one_time_recurring'=> null,
52
+        'is_one_time_recurring'=> null,
53 53
         'recurring_period'     => null,
54 54
         'recurring_interval'   => null,
55 55
         'recurring_limit'      => null,
@@ -59,13 +59,13 @@  discard block
 block discarded – undo
59 59
     );
60 60
 
61 61
     /**
62
-	 * Stores meta in cache for future reads.
63
-	 *
64
-	 * A group must be set to to enable caching.
65
-	 *
66
-	 * @var string
67
-	 */
68
-	protected $cache_group = 'getpaid_items';
62
+     * Stores meta in cache for future reads.
63
+     *
64
+     * A group must be set to to enable caching.
65
+     *
66
+     * @var string
67
+     */
68
+    protected $cache_group = 'getpaid_items';
69 69
 
70 70
     /**
71 71
      * Stores a reference to the original WP_Post object
@@ -75,37 +75,37 @@  discard block
 block discarded – undo
75 75
     protected $post = null;
76 76
 
77 77
     /**
78
-	 * Get the item if ID is passed, otherwise the item is new and empty.
79
-	 *
80
-	 * @param  int|object|WPInv_Item|WP_Post $item Item to read.
81
-	 */
82
-	public function __construct( $item = 0 ) {
83
-		parent::__construct( $item );
84
-
85
-		if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) {
86
-			$this->set_id( $item );
87
-		} elseif ( $item instanceof self ) {
88
-			$this->set_id( $item->get_id() );
89
-		} elseif ( ! empty( $item->ID ) ) {
90
-			$this->set_id( $item->ID );
91
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) {
92
-			$this->set_id( $item_id );
93
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) {
94
-			$this->set_id( $item_id );
95
-		} else {
96
-			$this->set_object_read( true );
97
-		}
78
+     * Get the item if ID is passed, otherwise the item is new and empty.
79
+     *
80
+     * @param  int|object|WPInv_Item|WP_Post $item Item to read.
81
+     */
82
+    public function __construct( $item = 0 ) {
83
+        parent::__construct( $item );
84
+
85
+        if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) {
86
+            $this->set_id( $item );
87
+        } elseif ( $item instanceof self ) {
88
+            $this->set_id( $item->get_id() );
89
+        } elseif ( ! empty( $item->ID ) ) {
90
+            $this->set_id( $item->ID );
91
+        } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) {
92
+            $this->set_id( $item_id );
93
+        } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) {
94
+            $this->set_id( $item_id );
95
+        } else {
96
+            $this->set_object_read( true );
97
+        }
98 98
 
99 99
         // Load the datastore.
100
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
100
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
101 101
 
102
-		if ( $this->get_id() > 0 ) {
102
+        if ( $this->get_id() > 0 ) {
103 103
             $this->post = get_post( $this->get_id() );
104 104
             $this->ID   = $this->get_id();
105
-			$this->data_store->read( $this );
105
+            $this->data_store->read( $this );
106 106
         }
107 107
 
108
-	}
108
+    }
109 109
 
110 110
     /*
111 111
 	|--------------------------------------------------------------------------
@@ -123,412 +123,412 @@  discard block
 block discarded – undo
123 123
     */
124 124
 
125 125
     /**
126
-	 * Get parent item ID.
127
-	 *
128
-	 * @since 1.0.19
129
-	 * @param  string $context View or edit context.
130
-	 * @return int
131
-	 */
132
-	public function get_parent_id( $context = 'view' ) {
133
-		return (int) $this->get_prop( 'parent_id', $context );
126
+     * Get parent item ID.
127
+     *
128
+     * @since 1.0.19
129
+     * @param  string $context View or edit context.
130
+     * @return int
131
+     */
132
+    public function get_parent_id( $context = 'view' ) {
133
+        return (int) $this->get_prop( 'parent_id', $context );
134 134
     }
135 135
 
136 136
     /**
137
-	 * Get item status.
138
-	 *
139
-	 * @since 1.0.19
140
-	 * @param  string $context View or edit context.
141
-	 * @return string
142
-	 */
143
-	public function get_status( $context = 'view' ) {
144
-		return $this->get_prop( 'status', $context );
137
+     * Get item status.
138
+     *
139
+     * @since 1.0.19
140
+     * @param  string $context View or edit context.
141
+     * @return string
142
+     */
143
+    public function get_status( $context = 'view' ) {
144
+        return $this->get_prop( 'status', $context );
145 145
     }
146 146
 
147 147
     /**
148
-	 * Get plugin version when the item was created.
149
-	 *
150
-	 * @since 1.0.19
151
-	 * @param  string $context View or edit context.
152
-	 * @return string
153
-	 */
154
-	public function get_version( $context = 'view' ) {
155
-		return $this->get_prop( 'version', $context );
148
+     * Get plugin version when the item was created.
149
+     *
150
+     * @since 1.0.19
151
+     * @param  string $context View or edit context.
152
+     * @return string
153
+     */
154
+    public function get_version( $context = 'view' ) {
155
+        return $this->get_prop( 'version', $context );
156 156
     }
157 157
 
158 158
     /**
159
-	 * Get date when the item was created.
160
-	 *
161
-	 * @since 1.0.19
162
-	 * @param  string $context View or edit context.
163
-	 * @return string
164
-	 */
165
-	public function get_date_created( $context = 'view' ) {
166
-		return $this->get_prop( 'date_created', $context );
159
+     * Get date when the item was created.
160
+     *
161
+     * @since 1.0.19
162
+     * @param  string $context View or edit context.
163
+     * @return string
164
+     */
165
+    public function get_date_created( $context = 'view' ) {
166
+        return $this->get_prop( 'date_created', $context );
167 167
     }
168 168
 
169 169
     /**
170
-	 * Get GMT date when the item was created.
171
-	 *
172
-	 * @since 1.0.19
173
-	 * @param  string $context View or edit context.
174
-	 * @return string
175
-	 */
176
-	public function get_date_created_gmt( $context = 'view' ) {
170
+     * Get GMT date when the item was created.
171
+     *
172
+     * @since 1.0.19
173
+     * @param  string $context View or edit context.
174
+     * @return string
175
+     */
176
+    public function get_date_created_gmt( $context = 'view' ) {
177 177
         $date = $this->get_date_created( $context );
178 178
 
179 179
         if ( $date ) {
180 180
             $date = get_gmt_from_date( $date );
181 181
         }
182
-		return $date;
182
+        return $date;
183 183
     }
184 184
 
185 185
     /**
186
-	 * Get date when the item was last modified.
187
-	 *
188
-	 * @since 1.0.19
189
-	 * @param  string $context View or edit context.
190
-	 * @return string
191
-	 */
192
-	public function get_date_modified( $context = 'view' ) {
193
-		return $this->get_prop( 'date_modified', $context );
186
+     * Get date when the item was last modified.
187
+     *
188
+     * @since 1.0.19
189
+     * @param  string $context View or edit context.
190
+     * @return string
191
+     */
192
+    public function get_date_modified( $context = 'view' ) {
193
+        return $this->get_prop( 'date_modified', $context );
194 194
     }
195 195
 
196 196
     /**
197
-	 * Get GMT date when the item was last modified.
198
-	 *
199
-	 * @since 1.0.19
200
-	 * @param  string $context View or edit context.
201
-	 * @return string
202
-	 */
203
-	public function get_date_modified_gmt( $context = 'view' ) {
197
+     * Get GMT date when the item was last modified.
198
+     *
199
+     * @since 1.0.19
200
+     * @param  string $context View or edit context.
201
+     * @return string
202
+     */
203
+    public function get_date_modified_gmt( $context = 'view' ) {
204 204
         $date = $this->get_date_modified( $context );
205 205
 
206 206
         if ( $date ) {
207 207
             $date = get_gmt_from_date( $date );
208 208
         }
209
-		return $date;
209
+        return $date;
210 210
     }
211 211
 
212 212
     /**
213
-	 * Get the item name.
214
-	 *
215
-	 * @since 1.0.19
216
-	 * @param  string $context View or edit context.
217
-	 * @return string
218
-	 */
219
-	public function get_name( $context = 'view' ) {
220
-		return $this->get_prop( 'name', $context );
213
+     * Get the item name.
214
+     *
215
+     * @since 1.0.19
216
+     * @param  string $context View or edit context.
217
+     * @return string
218
+     */
219
+    public function get_name( $context = 'view' ) {
220
+        return $this->get_prop( 'name', $context );
221 221
     }
222 222
 
223 223
     /**
224
-	 * Alias of self::get_name().
225
-	 *
226
-	 * @since 1.0.19
227
-	 * @param  string $context View or edit context.
228
-	 * @return string
229
-	 */
230
-	public function get_title( $context = 'view' ) {
231
-		return $this->get_name( $context );
224
+     * Alias of self::get_name().
225
+     *
226
+     * @since 1.0.19
227
+     * @param  string $context View or edit context.
228
+     * @return string
229
+     */
230
+    public function get_title( $context = 'view' ) {
231
+        return $this->get_name( $context );
232 232
     }
233 233
 
234 234
     /**
235
-	 * Get the item description.
236
-	 *
237
-	 * @since 1.0.19
238
-	 * @param  string $context View or edit context.
239
-	 * @return string
240
-	 */
241
-	public function get_description( $context = 'view' ) {
242
-		return $this->get_prop( 'description', $context );
235
+     * Get the item description.
236
+     *
237
+     * @since 1.0.19
238
+     * @param  string $context View or edit context.
239
+     * @return string
240
+     */
241
+    public function get_description( $context = 'view' ) {
242
+        return $this->get_prop( 'description', $context );
243 243
     }
244 244
 
245 245
     /**
246
-	 * Alias of self::get_description().
247
-	 *
248
-	 * @since 1.0.19
249
-	 * @param  string $context View or edit context.
250
-	 * @return string
251
-	 */
252
-	public function get_excerpt( $context = 'view' ) {
253
-		return $this->get_description( $context );
246
+     * Alias of self::get_description().
247
+     *
248
+     * @since 1.0.19
249
+     * @param  string $context View or edit context.
250
+     * @return string
251
+     */
252
+    public function get_excerpt( $context = 'view' ) {
253
+        return $this->get_description( $context );
254 254
     }
255 255
 
256 256
     /**
257
-	 * Alias of self::get_description().
258
-	 *
259
-	 * @since 1.0.19
260
-	 * @param  string $context View or edit context.
261
-	 * @return string
262
-	 */
263
-	public function get_summary( $context = 'view' ) {
264
-		return $this->get_description( $context );
257
+     * Alias of self::get_description().
258
+     *
259
+     * @since 1.0.19
260
+     * @param  string $context View or edit context.
261
+     * @return string
262
+     */
263
+    public function get_summary( $context = 'view' ) {
264
+        return $this->get_description( $context );
265 265
     }
266 266
 
267 267
     /**
268
-	 * Get the owner of the item.
269
-	 *
270
-	 * @since 1.0.19
271
-	 * @param  string $context View or edit context.
272
-	 * @return int
273
-	 */
274
-	public function get_author( $context = 'view' ) {
275
-		return (int) $this->get_prop( 'author', $context );
276
-	}
268
+     * Get the owner of the item.
269
+     *
270
+     * @since 1.0.19
271
+     * @param  string $context View or edit context.
272
+     * @return int
273
+     */
274
+    public function get_author( $context = 'view' ) {
275
+        return (int) $this->get_prop( 'author', $context );
276
+    }
277 277
 	
278
-	/**
279
-	 * Alias of self::get_author().
280
-	 *
281
-	 * @since 1.0.19
282
-	 * @param  string $context View or edit context.
283
-	 * @return int
284
-	 */
285
-	public function get_owner( $context = 'view' ) {
286
-		return $this->get_author( $context );
287
-    }
288
-
289
-    /**
290
-	 * Get the price of the item.
291
-	 *
292
-	 * @since 1.0.19
293
-	 * @param  string $context View or edit context.
294
-	 * @return float
295
-	 */
296
-	public function get_price( $context = 'view' ) {
278
+    /**
279
+     * Alias of self::get_author().
280
+     *
281
+     * @since 1.0.19
282
+     * @param  string $context View or edit context.
283
+     * @return int
284
+     */
285
+    public function get_owner( $context = 'view' ) {
286
+        return $this->get_author( $context );
287
+    }
288
+
289
+    /**
290
+     * Get the price of the item.
291
+     *
292
+     * @since 1.0.19
293
+     * @param  string $context View or edit context.
294
+     * @return float
295
+     */
296
+    public function get_price( $context = 'view' ) {
297 297
         return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) );
298
-	}
298
+    }
299 299
 	
300
-	/**
301
-	 * Get the inital price of the item.
302
-	 *
303
-	 * @since 1.0.19
304
-	 * @param  string $context View or edit context.
305
-	 * @return float
306
-	 */
307
-	public function get_initial_price( $context = 'view' ) {
300
+    /**
301
+     * Get the inital price of the item.
302
+     *
303
+     * @since 1.0.19
304
+     * @param  string $context View or edit context.
305
+     * @return float
306
+     */
307
+    public function get_initial_price( $context = 'view' ) {
308 308
 
309
-		$price = (float) $this->get_price( $context );
309
+        $price = (float) $this->get_price( $context );
310 310
 
311
-		if ( $this->has_free_trial() ) {
312
-			$price = 0;
313
-		}
311
+        if ( $this->has_free_trial() ) {
312
+            $price = 0;
313
+        }
314 314
 
315 315
         return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) );
316 316
     }
317 317
 
318 318
     /**
319
-	 * Returns a formated price.
320
-	 *
321
-	 * @since 1.0.19
322
-	 * @param  string $context View or edit context.
323
-	 * @return string
324
-	 */
319
+     * Returns a formated price.
320
+     *
321
+     * @since 1.0.19
322
+     * @param  string $context View or edit context.
323
+     * @return string
324
+     */
325 325
     public function get_the_price() {
326 326
         return wpinv_price( $this->get_price() );
327
-	}
328
-
329
-	/**
330
-	 * Returns the formated initial price.
331
-	 *
332
-	 * @since 1.0.19
333
-	 * @param  string $context View or edit context.
334
-	 * @return string
335
-	 */
327
+    }
328
+
329
+    /**
330
+     * Returns the formated initial price.
331
+     *
332
+     * @since 1.0.19
333
+     * @param  string $context View or edit context.
334
+     * @return string
335
+     */
336 336
     public function get_the_initial_price() {
337 337
         return wpinv_price( $this->get_initial_price() );
338 338
     }
339 339
 
340 340
     /**
341
-	 * Get the VAT rule of the item.
342
-	 *
343
-	 * @since 1.0.19
344
-	 * @param  string $context View or edit context.
345
-	 * @return string
346
-	 */
347
-	public function get_vat_rule( $context = 'view' ) {
341
+     * Get the VAT rule of the item.
342
+     *
343
+     * @since 1.0.19
344
+     * @param  string $context View or edit context.
345
+     * @return string
346
+     */
347
+    public function get_vat_rule( $context = 'view' ) {
348 348
         return $this->get_prop( 'vat_rule', $context );
349 349
     }
350 350
 
351 351
     /**
352
-	 * Get the VAT class of the item.
353
-	 *
354
-	 * @since 1.0.19
355
-	 * @param  string $context View or edit context.
356
-	 * @return string
357
-	 */
358
-	public function get_vat_class( $context = 'view' ) {
352
+     * Get the VAT class of the item.
353
+     *
354
+     * @since 1.0.19
355
+     * @param  string $context View or edit context.
356
+     * @return string
357
+     */
358
+    public function get_vat_class( $context = 'view' ) {
359 359
         return $this->get_prop( 'vat_class', $context );
360 360
     }
361 361
 
362 362
     /**
363
-	 * Get the type of the item.
364
-	 *
365
-	 * @since 1.0.19
366
-	 * @param  string $context View or edit context.
367
-	 * @return string
368
-	 */
369
-	public function get_type( $context = 'view' ) {
363
+     * Get the type of the item.
364
+     *
365
+     * @since 1.0.19
366
+     * @param  string $context View or edit context.
367
+     * @return string
368
+     */
369
+    public function get_type( $context = 'view' ) {
370 370
         return $this->get_prop( 'type', $context );
371 371
     }
372 372
 
373 373
     /**
374
-	 * Get the custom id of the item.
375
-	 *
376
-	 * @since 1.0.19
377
-	 * @param  string $context View or edit context.
378
-	 * @return string
379
-	 */
380
-	public function get_custom_id( $context = 'view' ) {
374
+     * Get the custom id of the item.
375
+     *
376
+     * @since 1.0.19
377
+     * @param  string $context View or edit context.
378
+     * @return string
379
+     */
380
+    public function get_custom_id( $context = 'view' ) {
381 381
         return $this->get_prop( 'custom_id', $context );
382 382
     }
383 383
 
384 384
     /**
385
-	 * Get the custom name of the item.
386
-	 *
387
-	 * @since 1.0.19
388
-	 * @param  string $context View or edit context.
389
-	 * @return string
390
-	 */
391
-	public function get_custom_name( $context = 'view' ) {
385
+     * Get the custom name of the item.
386
+     *
387
+     * @since 1.0.19
388
+     * @param  string $context View or edit context.
389
+     * @return string
390
+     */
391
+    public function get_custom_name( $context = 'view' ) {
392 392
         return $this->get_prop( 'custom_name', $context );
393 393
     }
394 394
 
395 395
     /**
396
-	 * Get the custom singular name of the item.
397
-	 *
398
-	 * @since 1.0.19
399
-	 * @param  string $context View or edit context.
400
-	 * @return string
401
-	 */
402
-	public function get_custom_singular_name( $context = 'view' ) {
396
+     * Get the custom singular name of the item.
397
+     *
398
+     * @since 1.0.19
399
+     * @param  string $context View or edit context.
400
+     * @return string
401
+     */
402
+    public function get_custom_singular_name( $context = 'view' ) {
403 403
         return $this->get_prop( 'custom_singular_name', $context );
404 404
     }
405 405
 
406 406
     /**
407
-	 * Checks if an item is editable..
408
-	 *
409
-	 * @since 1.0.19
410
-	 * @param  string $context View or edit context.
411
-	 * @return int
412
-	 */
413
-	public function get_is_editable( $context = 'view' ) {
407
+     * Checks if an item is editable..
408
+     *
409
+     * @since 1.0.19
410
+     * @param  string $context View or edit context.
411
+     * @return int
412
+     */
413
+    public function get_is_editable( $context = 'view' ) {
414 414
         return (int) $this->get_prop( 'is_editable', $context );
415 415
     }
416 416
 
417 417
     /**
418
-	 * Alias of self::get_is_editable().
419
-	 *
420
-	 * @since 1.0.19
421
-	 * @param  string $context View or edit context.
422
-	 * @return int
423
-	 */
424
-	public function get_editable( $context = 'view' ) {
425
-		return $this->get_is_editable( $context );
418
+     * Alias of self::get_is_editable().
419
+     *
420
+     * @since 1.0.19
421
+     * @param  string $context View or edit context.
422
+     * @return int
423
+     */
424
+    public function get_editable( $context = 'view' ) {
425
+        return $this->get_is_editable( $context );
426 426
     }
427 427
 
428 428
     /**
429
-	 * Checks if dynamic pricing is enabled.
430
-	 *
431
-	 * @since 1.0.19
432
-	 * @param  string $context View or edit context.
433
-	 * @return int
434
-	 */
435
-	public function get_is_dynamic_pricing( $context = 'view' ) {
429
+     * Checks if dynamic pricing is enabled.
430
+     *
431
+     * @since 1.0.19
432
+     * @param  string $context View or edit context.
433
+     * @return int
434
+     */
435
+    public function get_is_dynamic_pricing( $context = 'view' ) {
436 436
         return (int) $this->get_prop( 'is_dynamic_pricing', $context );
437 437
     }
438 438
 
439 439
     /**
440
-	 * Returns the minimum price if dynamic pricing is enabled.
441
-	 *
442
-	 * @since 1.0.19
443
-	 * @param  string $context View or edit context.
444
-	 * @return float
445
-	 */
446
-	public function get_minimum_price( $context = 'view' ) {
440
+     * Returns the minimum price if dynamic pricing is enabled.
441
+     *
442
+     * @since 1.0.19
443
+     * @param  string $context View or edit context.
444
+     * @return float
445
+     */
446
+    public function get_minimum_price( $context = 'view' ) {
447 447
         return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) );
448 448
     }
449 449
 
450 450
     /**
451
-	 * Checks if this is a recurring item.
452
-	 *
453
-	 * @since 1.0.19
454
-	 * @param  string $context View or edit context.
455
-	 * @return int
456
-	 */
457
-	public function get_is_recurring( $context = 'view' ) {
451
+     * Checks if this is a recurring item.
452
+     *
453
+     * @since 1.0.19
454
+     * @param  string $context View or edit context.
455
+     * @return int
456
+     */
457
+    public function get_is_recurring( $context = 'view' ) {
458 458
         return (int) $this->get_prop( 'is_recurring', $context );
459
-	}
460
-
461
-	/**
462
-	 * Checks if this is a one time recurring item.
463
-	 *
464
-	 * @since 1.0.19
465
-	 * @param  string $context View or edit context.
466
-	 * @return int
467
-	 */
468
-	public function get_is_one_time_recurring( $context = 'view' ) {
459
+    }
460
+
461
+    /**
462
+     * Checks if this is a one time recurring item.
463
+     *
464
+     * @since 1.0.19
465
+     * @param  string $context View or edit context.
466
+     * @return int
467
+     */
468
+    public function get_is_one_time_recurring( $context = 'view' ) {
469 469
         return (int) $this->get_prop( 'is_one_time_recurring', $context );
470
-	}
470
+    }
471 471
 	
472
-	/**
473
-	 * Get the recurring price of the item.
474
-	 *
475
-	 * @since 1.0.19
476
-	 * @param  string $context View or edit context.
477
-	 * @return float
478
-	 */
479
-	public function get_recurring_price( $context = 'view' ) {
480
-		$price = $this->get_price( $context );
472
+    /**
473
+     * Get the recurring price of the item.
474
+     *
475
+     * @since 1.0.19
476
+     * @param  string $context View or edit context.
477
+     * @return float
478
+     */
479
+    public function get_recurring_price( $context = 'view' ) {
480
+        $price = $this->get_price( $context );
481 481
         return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) );
482
-	}
483
-
484
-	/**
485
-	 * Get the formatted recurring price of the item.
486
-	 *
487
-	 * @since 1.0.19
488
-	 * @param  string $context View or edit context.
489
-	 * @return string
490
-	 */
482
+    }
483
+
484
+    /**
485
+     * Get the formatted recurring price of the item.
486
+     *
487
+     * @since 1.0.19
488
+     * @param  string $context View or edit context.
489
+     * @return string
490
+     */
491 491
     public function get_the_recurring_price() {
492 492
         return wpinv_price( $this->get_recurring_price() );
493
-	}
494
-
495
-	/**
496
-	 * Get the first renewal date (in timestamps) of the item.
497
-	 *
498
-	 * @since 1.0.19
499
-	 * @return int
500
-	 */
501
-	public function get_first_renewal_date() {
502
-
503
-		$periods = array(
504
-			'D' => 'days',
505
-			'W' => 'weeks',
506
-			'M' => 'months',
507
-			'Y' => 'years',
508
-		);
509
-
510
-		$period   = $this->get_recurring_period();
511
-		$interval = $this->get_recurring_interval();
512
-
513
-		if ( $this->has_free_trial() ) {
514
-			$period   = $this->get_trial_period();
515
-			$interval = $this->get_trial_interval();
516
-		}
517
-
518
-		$period       = $periods[ $period ];
519
-		$interval     = empty( $interval ) ? 1 : $interval;
520
-		$next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
493
+    }
494
+
495
+    /**
496
+     * Get the first renewal date (in timestamps) of the item.
497
+     *
498
+     * @since 1.0.19
499
+     * @return int
500
+     */
501
+    public function get_first_renewal_date() {
502
+
503
+        $periods = array(
504
+            'D' => 'days',
505
+            'W' => 'weeks',
506
+            'M' => 'months',
507
+            'Y' => 'years',
508
+        );
509
+
510
+        $period   = $this->get_recurring_period();
511
+        $interval = $this->get_recurring_interval();
512
+
513
+        if ( $this->has_free_trial() ) {
514
+            $period   = $this->get_trial_period();
515
+            $interval = $this->get_trial_interval();
516
+        }
517
+
518
+        $period       = $periods[ $period ];
519
+        $interval     = empty( $interval ) ? 1 : $interval;
520
+        $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
521 521
         return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this );
522 522
     }
523 523
 
524 524
     /**
525
-	 * Get the recurring period.
526
-	 *
527
-	 * @since 1.0.19
528
-	 * @param  bool $full Return abbreviation or in full.
529
-	 * @return string
530
-	 */
531
-	public function get_recurring_period( $full = false ) {
525
+     * Get the recurring period.
526
+     *
527
+     * @since 1.0.19
528
+     * @param  bool $full Return abbreviation or in full.
529
+     * @return string
530
+     */
531
+    public function get_recurring_period( $full = false ) {
532 532
         $period = $this->get_prop( 'recurring_period', 'view' );
533 533
 
534 534
         if ( $full && ! is_bool( $full ) ) {
@@ -539,63 +539,63 @@  discard block
 block discarded – undo
539 539
     }
540 540
 
541 541
     /**
542
-	 * Get the recurring interval.
543
-	 *
544
-	 * @since 1.0.19
545
-	 * @param  string $context View or edit context.
546
-	 * @return int
547
-	 */
548
-	public function get_recurring_interval( $context = 'view' ) {
549
-		$interval = absint( $this->get_prop( 'recurring_interval', $context ) );
542
+     * Get the recurring interval.
543
+     *
544
+     * @since 1.0.19
545
+     * @param  string $context View or edit context.
546
+     * @return int
547
+     */
548
+    public function get_recurring_interval( $context = 'view' ) {
549
+        $interval = absint( $this->get_prop( 'recurring_interval', $context ) );
550 550
 
551
-		if ( $interval < 1 ) {
552
-			$interval = 1;
553
-		}
551
+        if ( $interval < 1 ) {
552
+            $interval = 1;
553
+        }
554 554
 
555 555
         return $interval;
556 556
     }
557 557
 
558 558
     /**
559
-	 * Get the recurring limit.
560
-	 *
561
-	 * @since 1.0.19
562
-	 * @param  string $context View or edit context.
563
-	 * @return int
564
-	 */
565
-	public function get_recurring_limit( $context = 'view' ) {
559
+     * Get the recurring limit.
560
+     *
561
+     * @since 1.0.19
562
+     * @param  string $context View or edit context.
563
+     * @return int
564
+     */
565
+    public function get_recurring_limit( $context = 'view' ) {
566 566
         return (int) $this->get_prop( 'recurring_limit', $context );
567 567
     }
568 568
 
569 569
     /**
570
-	 * Checks if we have a free trial.
571
-	 *
572
-	 * @since 1.0.19
573
-	 * @param  string $context View or edit context.
574
-	 * @return int
575
-	 */
576
-	public function get_is_free_trial( $context = 'view' ) {
570
+     * Checks if we have a free trial.
571
+     *
572
+     * @since 1.0.19
573
+     * @param  string $context View or edit context.
574
+     * @return int
575
+     */
576
+    public function get_is_free_trial( $context = 'view' ) {
577 577
         return (int) $this->get_prop( 'is_free_trial', $context );
578 578
     }
579 579
 
580 580
     /**
581
-	 * Alias for self::get_is_free_trial().
582
-	 *
583
-	 * @since 1.0.19
584
-	 * @param  string $context View or edit context.
585
-	 * @return int
586
-	 */
587
-	public function get_free_trial( $context = 'view' ) {
581
+     * Alias for self::get_is_free_trial().
582
+     *
583
+     * @since 1.0.19
584
+     * @param  string $context View or edit context.
585
+     * @return int
586
+     */
587
+    public function get_free_trial( $context = 'view' ) {
588 588
         return $this->get_is_free_trial( $context );
589 589
     }
590 590
 
591 591
     /**
592
-	 * Get the trial period.
593
-	 *
594
-	 * @since 1.0.19
595
-	 * @param  bool $full Return abbreviation or in full.
596
-	 * @return string
597
-	 */
598
-	public function get_trial_period( $full = false ) {
592
+     * Get the trial period.
593
+     *
594
+     * @since 1.0.19
595
+     * @param  bool $full Return abbreviation or in full.
596
+     * @return string
597
+     */
598
+    public function get_trial_period( $full = false ) {
599 599
         $period = $this->get_prop( 'trial_period', 'view' );
600 600
 
601 601
         if ( $full && ! is_bool( $full ) ) {
@@ -606,104 +606,104 @@  discard block
 block discarded – undo
606 606
     }
607 607
 
608 608
     /**
609
-	 * Get the trial interval.
610
-	 *
611
-	 * @since 1.0.19
612
-	 * @param  string $context View or edit context.
613
-	 * @return int
614
-	 */
615
-	public function get_trial_interval( $context = 'view' ) {
609
+     * Get the trial interval.
610
+     *
611
+     * @since 1.0.19
612
+     * @param  string $context View or edit context.
613
+     * @return int
614
+     */
615
+    public function get_trial_interval( $context = 'view' ) {
616 616
         return (int) $this->get_prop( 'trial_interval', $context );
617
-	}
617
+    }
618 618
 	
619
-	/**
620
-	 * Get the item's edit url.
621
-	 *
622
-	 * @since 1.0.19
623
-	 * @return string
624
-	 */
625
-	public function get_edit_url() {
619
+    /**
620
+     * Get the item's edit url.
621
+     *
622
+     * @since 1.0.19
623
+     * @return string
624
+     */
625
+    public function get_edit_url() {
626 626
         return get_edit_post_link( $this->get_id() );
627
-	}
628
-
629
-	/**
630
-	 * Given an item's name/custom id, it returns its id.
631
-	 *
632
-	 *
633
-	 * @static
634
-	 * @param string $value The item name or custom id.
635
-	 * @param string $field Either name or custom_id.
636
-	 * @param string $type in case you need to search for a given type.
637
-	 * @since 1.0.15
638
-	 * @return int
639
-	 */
640
-	public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) {
641
-
642
-		// Trim the value.
643
-		$value = sanitize_text_field( $value );
644
-		if ( empty( $value ) ) {
645
-			return 0;
646
-		}
627
+    }
628
+
629
+    /**
630
+     * Given an item's name/custom id, it returns its id.
631
+     *
632
+     *
633
+     * @static
634
+     * @param string $value The item name or custom id.
635
+     * @param string $field Either name or custom_id.
636
+     * @param string $type in case you need to search for a given type.
637
+     * @since 1.0.15
638
+     * @return int
639
+     */
640
+    public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) {
641
+
642
+        // Trim the value.
643
+        $value = sanitize_text_field( $value );
644
+        if ( empty( $value ) ) {
645
+            return 0;
646
+        }
647 647
 
648 648
         // Valid fields.
649 649
         $fields = array( 'custom_id', 'name', 'slug' );
650 650
 
651
-		// Ensure a field has been passed.
652
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
653
-			return 0;
654
-		}
655
-
656
-		if ( $field == 'name' ) {
657
-			$field = 'slug';
658
-		}
659
-
660
-		// Maybe retrieve from the cache.
661
-		$item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" );
662
-		if ( ! empty( $item_id ) ) {
663
-			return $item_id;
664
-		}
665
-
666
-		// Fetch from the db.
667
-		$items = array();
668
-		if ( $field == 'slug' ) {
669
-			$items = get_posts(
670
-				array(
671
-					'post_type'      => 'wpi_item',
672
-					'name'           => $value,
673
-					'posts_per_page' => 1,
674
-					'post_status'    => 'any',
675
-				)
676
-			);
677
-		}
678
-
679
-		if ( $field =='custom_id' ) {
680
-			$items = get_posts(
681
-				array(
682
-					'post_type'      => 'wpi_item',
683
-					'posts_per_page' => 1,
684
-					'post_status'    => 'any',
685
-					'meta_query'     => array(
686
-						array(
687
-							'key'   => '_wpinv_type',
688
-                			'value' => $type,
689
-						),
690
-						array(
691
-							'key'   => '_wpinv_custom_id',
692
-                			'value' => $value,
693
-						)
694
-					)
695
-				)
696
-			);
697
-		}
698
-
699
-		if ( empty( $items ) ) {
700
-			return 0;
701
-		}
702
-
703
-		// Update the cache with our data
704
-		wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" );
705
-
706
-		return $items[0]->ID;
651
+        // Ensure a field has been passed.
652
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
653
+            return 0;
654
+        }
655
+
656
+        if ( $field == 'name' ) {
657
+            $field = 'slug';
658
+        }
659
+
660
+        // Maybe retrieve from the cache.
661
+        $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" );
662
+        if ( ! empty( $item_id ) ) {
663
+            return $item_id;
664
+        }
665
+
666
+        // Fetch from the db.
667
+        $items = array();
668
+        if ( $field == 'slug' ) {
669
+            $items = get_posts(
670
+                array(
671
+                    'post_type'      => 'wpi_item',
672
+                    'name'           => $value,
673
+                    'posts_per_page' => 1,
674
+                    'post_status'    => 'any',
675
+                )
676
+            );
677
+        }
678
+
679
+        if ( $field =='custom_id' ) {
680
+            $items = get_posts(
681
+                array(
682
+                    'post_type'      => 'wpi_item',
683
+                    'posts_per_page' => 1,
684
+                    'post_status'    => 'any',
685
+                    'meta_query'     => array(
686
+                        array(
687
+                            'key'   => '_wpinv_type',
688
+                            'value' => $type,
689
+                        ),
690
+                        array(
691
+                            'key'   => '_wpinv_custom_id',
692
+                            'value' => $value,
693
+                        )
694
+                    )
695
+                )
696
+            );
697
+        }
698
+
699
+        if ( empty( $items ) ) {
700
+            return 0;
701
+        }
702
+
703
+        // Update the cache with our data
704
+        wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" );
705
+
706
+        return $items[0]->ID;
707 707
     }
708 708
 
709 709
     /**
@@ -736,52 +736,52 @@  discard block
 block discarded – undo
736 736
     */
737 737
 
738 738
     /**
739
-	 * Set parent order ID.
740
-	 *
741
-	 * @since 1.0.19
742
-	 */
743
-	public function set_parent_id( $value ) {
744
-		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
745
-			return;
746
-		}
747
-		$this->set_prop( 'parent_id', absint( $value ) );
748
-	}
749
-
750
-    /**
751
-	 * Sets item status.
752
-	 *
753
-	 * @since 1.0.19
754
-	 * @param  string $status New status.
755
-	 * @return array details of change.
756
-	 */
757
-	public function set_status( $status ) {
739
+     * Set parent order ID.
740
+     *
741
+     * @since 1.0.19
742
+     */
743
+    public function set_parent_id( $value ) {
744
+        if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
745
+            return;
746
+        }
747
+        $this->set_prop( 'parent_id', absint( $value ) );
748
+    }
749
+
750
+    /**
751
+     * Sets item status.
752
+     *
753
+     * @since 1.0.19
754
+     * @param  string $status New status.
755
+     * @return array details of change.
756
+     */
757
+    public function set_status( $status ) {
758 758
         $old_status = $this->get_status();
759 759
 
760 760
         $this->set_prop( 'status', $status );
761 761
 
762
-		return array(
763
-			'from' => $old_status,
764
-			'to'   => $status,
765
-		);
762
+        return array(
763
+            'from' => $old_status,
764
+            'to'   => $status,
765
+        );
766 766
     }
767 767
 
768 768
     /**
769
-	 * Set plugin version when the item was created.
770
-	 *
771
-	 * @since 1.0.19
772
-	 */
773
-	public function set_version( $value ) {
774
-		$this->set_prop( 'version', $value );
769
+     * Set plugin version when the item was created.
770
+     *
771
+     * @since 1.0.19
772
+     */
773
+    public function set_version( $value ) {
774
+        $this->set_prop( 'version', $value );
775 775
     }
776 776
 
777 777
     /**
778
-	 * Set date when the item was created.
779
-	 *
780
-	 * @since 1.0.19
781
-	 * @param string $value Value to set.
778
+     * Set date when the item was created.
779
+     *
780
+     * @since 1.0.19
781
+     * @param string $value Value to set.
782 782
      * @return bool Whether or not the date was set.
783
-	 */
784
-	public function set_date_created( $value ) {
783
+     */
784
+    public function set_date_created( $value ) {
785 785
         $date = strtotime( $value );
786 786
 
787 787
         if ( $date ) {
@@ -794,13 +794,13 @@  discard block
 block discarded – undo
794 794
     }
795 795
 
796 796
     /**
797
-	 * Set date when the item was last modified.
798
-	 *
799
-	 * @since 1.0.19
800
-	 * @param string $value Value to set.
797
+     * Set date when the item was last modified.
798
+     *
799
+     * @since 1.0.19
800
+     * @param string $value Value to set.
801 801
      * @return bool Whether or not the date was set.
802
-	 */
803
-	public function set_date_modified( $value ) {
802
+     */
803
+    public function set_date_modified( $value ) {
804 804
         $date = strtotime( $value );
805 805
 
806 806
         if ( $date ) {
@@ -813,115 +813,115 @@  discard block
 block discarded – undo
813 813
     }
814 814
 
815 815
     /**
816
-	 * Set the item name.
817
-	 *
818
-	 * @since 1.0.19
819
-	 * @param  string $value New name.
820
-	 */
821
-	public function set_name( $value ) {
816
+     * Set the item name.
817
+     *
818
+     * @since 1.0.19
819
+     * @param  string $value New name.
820
+     */
821
+    public function set_name( $value ) {
822 822
         $name = sanitize_text_field( $value );
823
-		$this->set_prop( 'name', $name );
823
+        $this->set_prop( 'name', $name );
824 824
     }
825 825
 
826 826
     /**
827
-	 * Alias of self::set_name().
828
-	 *
829
-	 * @since 1.0.19
830
-	 * @param  string $value New name.
831
-	 */
832
-	public function set_title( $value ) {
833
-		$this->set_name( $value );
827
+     * Alias of self::set_name().
828
+     *
829
+     * @since 1.0.19
830
+     * @param  string $value New name.
831
+     */
832
+    public function set_title( $value ) {
833
+        $this->set_name( $value );
834 834
     }
835 835
 
836 836
     /**
837
-	 * Set the item description.
838
-	 *
839
-	 * @since 1.0.19
840
-	 * @param  string $value New description.
841
-	 */
842
-	public function set_description( $value ) {
843
-		$description = wp_kses_post( $value );
844
-		return $this->set_prop( 'description', $description );
837
+     * Set the item description.
838
+     *
839
+     * @since 1.0.19
840
+     * @param  string $value New description.
841
+     */
842
+    public function set_description( $value ) {
843
+        $description = wp_kses_post( $value );
844
+        return $this->set_prop( 'description', $description );
845 845
     }
846 846
 
847 847
     /**
848
-	 * Alias of self::set_description().
849
-	 *
850
-	 * @since 1.0.19
851
-	 * @param  string $value New description.
852
-	 */
853
-	public function set_excerpt( $value ) {
854
-		$this->set_description( $value );
848
+     * Alias of self::set_description().
849
+     *
850
+     * @since 1.0.19
851
+     * @param  string $value New description.
852
+     */
853
+    public function set_excerpt( $value ) {
854
+        $this->set_description( $value );
855 855
     }
856 856
 
857 857
     /**
858
-	 * Alias of self::set_description().
859
-	 *
860
-	 * @since 1.0.19
861
-	 * @param  string $value New description.
862
-	 */
863
-	public function set_summary( $value ) {
864
-		$this->set_description( $value );
858
+     * Alias of self::set_description().
859
+     *
860
+     * @since 1.0.19
861
+     * @param  string $value New description.
862
+     */
863
+    public function set_summary( $value ) {
864
+        $this->set_description( $value );
865 865
     }
866 866
 
867 867
     /**
868
-	 * Set the owner of the item.
869
-	 *
870
-	 * @since 1.0.19
871
-	 * @param  int $value New author.
872
-	 */
873
-	public function set_author( $value ) {
874
-		$this->set_prop( 'author', (int) $value );
875
-	}
868
+     * Set the owner of the item.
869
+     *
870
+     * @since 1.0.19
871
+     * @param  int $value New author.
872
+     */
873
+    public function set_author( $value ) {
874
+        $this->set_prop( 'author', (int) $value );
875
+    }
876 876
 	
877
-	/**
878
-	 * Alias of self::set_author().
879
-	 *
880
-	 * @since 1.0.19
881
-	 * @param  int $value New author.
882
-	 */
883
-	public function set_owner( $value ) {
884
-		$this->set_author( $value );
885
-    }
886
-
887
-    /**
888
-	 * Set the price of the item.
889
-	 *
890
-	 * @since 1.0.19
891
-	 * @param  float $value New price.
892
-	 */
893
-	public function set_price( $value ) {
877
+    /**
878
+     * Alias of self::set_author().
879
+     *
880
+     * @since 1.0.19
881
+     * @param  int $value New author.
882
+     */
883
+    public function set_owner( $value ) {
884
+        $this->set_author( $value );
885
+    }
886
+
887
+    /**
888
+     * Set the price of the item.
889
+     *
890
+     * @since 1.0.19
891
+     * @param  float $value New price.
892
+     */
893
+    public function set_price( $value ) {
894 894
         $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) );
895 895
     }
896 896
 
897 897
     /**
898
-	 * Set the VAT rule of the item.
899
-	 *
900
-	 * @since 1.0.19
901
-	 * @param  string $value new rule.
902
-	 */
903
-	public function set_vat_rule( $value ) {
898
+     * Set the VAT rule of the item.
899
+     *
900
+     * @since 1.0.19
901
+     * @param  string $value new rule.
902
+     */
903
+    public function set_vat_rule( $value ) {
904 904
         $this->set_prop( 'vat_rule', $value );
905 905
     }
906 906
 
907 907
     /**
908
-	 * Set the VAT class of the item.
909
-	 *
910
-	 * @since 1.0.19
911
-	 * @param  string $value new class.
912
-	 */
913
-	public function set_vat_class( $value ) {
908
+     * Set the VAT class of the item.
909
+     *
910
+     * @since 1.0.19
911
+     * @param  string $value new class.
912
+     */
913
+    public function set_vat_class( $value ) {
914 914
         $this->set_prop( 'vat_class', $value );
915 915
     }
916 916
 
917 917
     /**
918
-	 * Set the type of the item.
919
-	 *
920
-	 * @since 1.0.19
921
-	 * @param  string $value new item type.
922
-	 * @return string
923
-	 */
924
-	public function set_type( $value ) {
918
+     * Set the type of the item.
919
+     *
920
+     * @since 1.0.19
921
+     * @param  string $value new item type.
922
+     * @return string
923
+     */
924
+    public function set_type( $value ) {
925 925
 
926 926
         if ( empty( $value ) ) {
927 927
             $value = 'custom';
@@ -931,142 +931,142 @@  discard block
 block discarded – undo
931 931
     }
932 932
 
933 933
     /**
934
-	 * Set the custom id of the item.
935
-	 *
936
-	 * @since 1.0.19
937
-	 * @param  string $value new custom id.
938
-	 */
939
-	public function set_custom_id( $value ) {
934
+     * Set the custom id of the item.
935
+     *
936
+     * @since 1.0.19
937
+     * @param  string $value new custom id.
938
+     */
939
+    public function set_custom_id( $value ) {
940 940
         $this->set_prop( 'custom_id', $value );
941 941
     }
942 942
 
943 943
     /**
944
-	 * Set the custom name of the item.
945
-	 *
946
-	 * @since 1.0.19
947
-	 * @param  string $value new custom name.
948
-	 */
949
-	public function set_custom_name( $value ) {
944
+     * Set the custom name of the item.
945
+     *
946
+     * @since 1.0.19
947
+     * @param  string $value new custom name.
948
+     */
949
+    public function set_custom_name( $value ) {
950 950
         $this->set_prop( 'custom_name', $value );
951 951
     }
952 952
 
953 953
     /**
954
-	 * Set the custom singular name of the item.
955
-	 *
956
-	 * @since 1.0.19
957
-	 * @param  string $value new custom singular name.
958
-	 */
959
-	public function set_custom_singular_name( $value ) {
954
+     * Set the custom singular name of the item.
955
+     *
956
+     * @since 1.0.19
957
+     * @param  string $value new custom singular name.
958
+     */
959
+    public function set_custom_singular_name( $value ) {
960 960
         $this->set_prop( 'custom_singular_name', $value );
961 961
     }
962 962
 
963 963
     /**
964
-	 * Sets if an item is editable..
965
-	 *
966
-	 * @since 1.0.19
967
-	 * @param  int|bool $value whether or not the item is editable.
968
-	 */
969
-	public function set_is_editable( $value ) {
970
-		$this->set_prop( 'is_editable', (int) $value );
964
+     * Sets if an item is editable..
965
+     *
966
+     * @since 1.0.19
967
+     * @param  int|bool $value whether or not the item is editable.
968
+     */
969
+    public function set_is_editable( $value ) {
970
+        $this->set_prop( 'is_editable', (int) $value );
971 971
     }
972 972
 
973 973
     /**
974
-	 * Sets if dynamic pricing is enabled.
975
-	 *
976
-	 * @since 1.0.19
977
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
978
-	 */
979
-	public function set_is_dynamic_pricing( $value ) {
974
+     * Sets if dynamic pricing is enabled.
975
+     *
976
+     * @since 1.0.19
977
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
978
+     */
979
+    public function set_is_dynamic_pricing( $value ) {
980 980
         $this->set_prop( 'is_dynamic_pricing', (int) $value );
981 981
     }
982 982
 
983 983
     /**
984
-	 * Sets the minimum price if dynamic pricing is enabled.
985
-	 *
986
-	 * @since 1.0.19
987
-	 * @param  float $value minimum price.
988
-	 */
989
-	public function set_minimum_price( $value ) {
984
+     * Sets the minimum price if dynamic pricing is enabled.
985
+     *
986
+     * @since 1.0.19
987
+     * @param  float $value minimum price.
988
+     */
989
+    public function set_minimum_price( $value ) {
990 990
         $this->set_prop( 'minimum_price',  (float) wpinv_sanitize_amount( $value ) );
991 991
     }
992 992
 
993 993
     /**
994
-	 * Sets if this is a recurring item.
995
-	 *
996
-	 * @since 1.0.19
997
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
998
-	 */
999
-	public function set_is_recurring( $value ) {
994
+     * Sets if this is a recurring item.
995
+     *
996
+     * @since 1.0.19
997
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
998
+     */
999
+    public function set_is_recurring( $value ) {
1000 1000
         $this->set_prop( 'is_recurring', (int) $value );
1001 1001
     }
1002 1002
 
1003
-	/**
1004
-	 * Sets if this is a recurring item.
1005
-	 *
1006
-	 * @since 1.0.19
1007
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
1008
-	 */
1009
-	public function set_is_one_time_recurring( $value ) {
1003
+    /**
1004
+     * Sets if this is a recurring item.
1005
+     *
1006
+     * @since 1.0.19
1007
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
1008
+     */
1009
+    public function set_is_one_time_recurring( $value ) {
1010 1010
         $this->set_prop( 'is_one_time_recurring', (int) $value );
1011 1011
     }
1012 1012
 
1013 1013
     /**
1014
-	 * Set the recurring period.
1015
-	 *
1016
-	 * @since 1.0.19
1017
-	 * @param  string $value new period.
1018
-	 */
1019
-	public function set_recurring_period( $value ) {
1014
+     * Set the recurring period.
1015
+     *
1016
+     * @since 1.0.19
1017
+     * @param  string $value new period.
1018
+     */
1019
+    public function set_recurring_period( $value ) {
1020 1020
         $this->set_prop( 'recurring_period', $value );
1021 1021
     }
1022 1022
 
1023 1023
     /**
1024
-	 * Set the recurring interval.
1025
-	 *
1026
-	 * @since 1.0.19
1027
-	 * @param  int $value recurring interval.
1028
-	 */
1029
-	public function set_recurring_interval( $value ) {
1024
+     * Set the recurring interval.
1025
+     *
1026
+     * @since 1.0.19
1027
+     * @param  int $value recurring interval.
1028
+     */
1029
+    public function set_recurring_interval( $value ) {
1030 1030
         return $this->set_prop( 'recurring_interval', (int) $value );
1031 1031
     }
1032 1032
 
1033 1033
     /**
1034
-	 * Get the recurring limit.
1035
-	 * @since 1.0.19
1036
-	 * @param  int $value The recurring limit.
1037
-	 * @return int
1038
-	 */
1039
-	public function set_recurring_limit( $value ) {
1034
+     * Get the recurring limit.
1035
+     * @since 1.0.19
1036
+     * @param  int $value The recurring limit.
1037
+     * @return int
1038
+     */
1039
+    public function set_recurring_limit( $value ) {
1040 1040
         $this->set_prop( 'recurring_limit', (int) $value );
1041 1041
     }
1042 1042
 
1043 1043
     /**
1044
-	 * Checks if we have a free trial.
1045
-	 *
1046
-	 * @since 1.0.19
1047
-	 * @param  int|bool $value whether or not it has a free trial.
1048
-	 */
1049
-	public function set_is_free_trial( $value ) {
1044
+     * Checks if we have a free trial.
1045
+     *
1046
+     * @since 1.0.19
1047
+     * @param  int|bool $value whether or not it has a free trial.
1048
+     */
1049
+    public function set_is_free_trial( $value ) {
1050 1050
         $this->set_prop( 'is_free_trial', (int) $value );
1051 1051
     }
1052 1052
 
1053 1053
     /**
1054
-	 * Set the trial period.
1055
-	 *
1056
-	 * @since 1.0.19
1057
-	 * @param  string $value trial period.
1058
-	 */
1059
-	public function set_trial_period( $value ) {
1054
+     * Set the trial period.
1055
+     *
1056
+     * @since 1.0.19
1057
+     * @param  string $value trial period.
1058
+     */
1059
+    public function set_trial_period( $value ) {
1060 1060
         $this->set_prop( 'trial_period', $value );
1061 1061
     }
1062 1062
 
1063 1063
     /**
1064
-	 * Set the trial interval.
1065
-	 *
1066
-	 * @since 1.0.19
1067
-	 * @param  int $value trial interval.
1068
-	 */
1069
-	public function set_trial_interval( $value ) {
1064
+     * Set the trial interval.
1065
+     *
1066
+     * @since 1.0.19
1067
+     * @param  int $value trial interval.
1068
+     */
1069
+    public function set_trial_interval( $value ) {
1070 1070
         $this->set_prop( 'trial_interval', $value );
1071 1071
     }
1072 1072
 
@@ -1074,17 +1074,17 @@  discard block
 block discarded – undo
1074 1074
      * Create an item. For backwards compatibilty.
1075 1075
      * 
1076 1076
      * @deprecated
1077
-	 * @return int item id
1077
+     * @return int item id
1078 1078
      */
1079 1079
     public function create( $data = array() ) {
1080 1080
 
1081
-		// Set the properties.
1082
-		if ( is_array( $data ) ) {
1083
-			$this->set_props( $data );
1084
-		}
1081
+        // Set the properties.
1082
+        if ( is_array( $data ) ) {
1083
+            $this->set_props( $data );
1084
+        }
1085 1085
 
1086
-		// Save the item.
1087
-		return $this->save();
1086
+        // Save the item.
1087
+        return $this->save();
1088 1088
 
1089 1089
     }
1090 1090
 
@@ -1092,7 +1092,7 @@  discard block
 block discarded – undo
1092 1092
      * Updates an item. For backwards compatibilty.
1093 1093
      * 
1094 1094
      * @deprecated
1095
-	 * @return int item id
1095
+     * @return int item id
1096 1096
      */
1097 1097
     public function update( $data = array() ) {
1098 1098
         return $this->create( $data );
@@ -1108,103 +1108,103 @@  discard block
 block discarded – undo
1108 1108
 	*/
1109 1109
 
1110 1110
     /**
1111
-	 * Checks whether the item has enabled dynamic pricing.
1112
-	 *
1113
-	 * @since 1.0.19
1114
-	 * @return bool
1115
-	 */
1116
-	public function user_can_set_their_price() {
1111
+     * Checks whether the item has enabled dynamic pricing.
1112
+     *
1113
+     * @since 1.0.19
1114
+     * @return bool
1115
+     */
1116
+    public function user_can_set_their_price() {
1117 1117
         return (bool) $this->get_is_dynamic_pricing();
1118
-	}
1118
+    }
1119 1119
 	
1120
-	/**
1121
-	 * Checks whether the item is one time recurring.
1122
-	 *
1123
-	 * @since 1.0.19
1124
-	 * @return bool
1125
-	 */
1126
-	public function is_one_time_recurring() {
1120
+    /**
1121
+     * Checks whether the item is one time recurring.
1122
+     *
1123
+     * @since 1.0.19
1124
+     * @return bool
1125
+     */
1126
+    public function is_one_time_recurring() {
1127 1127
         return (bool) $this->get_is_one_time_recurring();
1128 1128
     }
1129 1129
 
1130
-	/**
1131
-	 * Checks whether the item is recurring.
1132
-	 *
1133
-	 * @since 1.0.19
1134
-	 * @return bool
1135
-	 */
1136
-	public function is_recurring() {
1130
+    /**
1131
+     * Checks whether the item is recurring.
1132
+     *
1133
+     * @since 1.0.19
1134
+     * @return bool
1135
+     */
1136
+    public function is_recurring() {
1137 1137
         return (bool) $this->get_is_recurring();
1138 1138
     } 
1139 1139
 
1140 1140
     /**
1141
-	 * Checks whether the item has a free trial.
1142
-	 *
1143
-	 * @since 1.0.19
1144
-	 * @return bool
1145
-	 */
1141
+     * Checks whether the item has a free trial.
1142
+     *
1143
+     * @since 1.0.19
1144
+     * @return bool
1145
+     */
1146 1146
     public function has_free_trial() {
1147 1147
         $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false;
1148 1148
         return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this );
1149 1149
     }
1150 1150
 
1151 1151
     /**
1152
-	 * Checks whether the item is free.
1153
-	 *
1154
-	 * @since 1.0.19
1155
-	 * @return bool
1156
-	 */
1152
+     * Checks whether the item is free.
1153
+     *
1154
+     * @since 1.0.19
1155
+     * @return bool
1156
+     */
1157 1157
     public function is_free() {
1158 1158
         $is_free   = $this->get_price() == 0;
1159 1159
         return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this );
1160 1160
     }
1161 1161
 
1162 1162
     /**
1163
-	 * Checks the item status against a passed in status.
1164
-	 *
1165
-	 * @param array|string $status Status to check.
1166
-	 * @return bool
1167
-	 */
1168
-	public function has_status( $status ) {
1169
-		$has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1170
-		return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1163
+     * Checks the item status against a passed in status.
1164
+     *
1165
+     * @param array|string $status Status to check.
1166
+     * @return bool
1167
+     */
1168
+    public function has_status( $status ) {
1169
+        $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1170
+        return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1171 1171
     }
1172 1172
 
1173 1173
     /**
1174
-	 * Checks the item type against a passed in types.
1175
-	 *
1176
-	 * @param array|string $type Type to check.
1177
-	 * @return bool
1178
-	 */
1179
-	public function is_type( $type ) {
1180
-		$is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1181
-		return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1182
-	}
1174
+     * Checks the item type against a passed in types.
1175
+     *
1176
+     * @param array|string $type Type to check.
1177
+     * @return bool
1178
+     */
1179
+    public function is_type( $type ) {
1180
+        $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1181
+        return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1182
+    }
1183 1183
 
1184 1184
     /**
1185
-	 * Checks whether the item is editable.
1186
-	 *
1187
-	 * @since 1.0.19
1188
-	 * @return bool
1189
-	 */
1185
+     * Checks whether the item is editable.
1186
+     *
1187
+     * @since 1.0.19
1188
+     * @return bool
1189
+     */
1190 1190
     public function is_editable() {
1191 1191
         $is_editable = $this->get_is_editable();
1192 1192
         return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this );
1193
-	}
1193
+    }
1194 1194
 
1195
-	/**
1196
-	 * Returns an array of cart fees.
1197
-	 */
1198
-	public function get_fees() {
1195
+    /**
1196
+     * Returns an array of cart fees.
1197
+     */
1198
+    public function get_fees() {
1199 1199
         return array();
1200 1200
     }
1201 1201
 
1202 1202
     /**
1203
-	 * Checks whether the item is purchasable.
1204
-	 *
1205
-	 * @since 1.0.19
1206
-	 * @return bool
1207
-	 */
1203
+     * Checks whether the item is purchasable.
1204
+     *
1205
+     * @since 1.0.19
1206
+     * @return bool
1207
+     */
1208 1208
     public function can_purchase() {
1209 1209
         $can_purchase = $this->exists();
1210 1210
 
@@ -1216,11 +1216,11 @@  discard block
 block discarded – undo
1216 1216
     }
1217 1217
 
1218 1218
     /**
1219
-	 * Checks whether the item supports dynamic pricing.
1220
-	 *
1221
-	 * @since 1.0.19
1222
-	 * @return bool
1223
-	 */
1219
+     * Checks whether the item supports dynamic pricing.
1220
+     *
1221
+     * @since 1.0.19
1222
+     * @return bool
1223
+     */
1224 1224
     public function supports_dynamic_pricing() {
1225 1225
         return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this );
1226 1226
     }
Please login to merge, or discard this patch.
Spacing   +215 added lines, -215 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
 
@@ -79,30 +79,30 @@  discard block
 block discarded – undo
79 79
 	 *
80 80
 	 * @param  int|object|WPInv_Item|WP_Post $item Item to read.
81 81
 	 */
82
-	public function __construct( $item = 0 ) {
83
-		parent::__construct( $item );
84
-
85
-		if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) {
86
-			$this->set_id( $item );
87
-		} elseif ( $item instanceof self ) {
88
-			$this->set_id( $item->get_id() );
89
-		} elseif ( ! empty( $item->ID ) ) {
90
-			$this->set_id( $item->ID );
91
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) {
92
-			$this->set_id( $item_id );
93
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) {
94
-			$this->set_id( $item_id );
82
+	public function __construct($item = 0) {
83
+		parent::__construct($item);
84
+
85
+		if (!empty($item) && is_numeric($item) && 'wpi_item' == get_post_type($item)) {
86
+			$this->set_id($item);
87
+		} elseif ($item instanceof self) {
88
+			$this->set_id($item->get_id());
89
+		} elseif (!empty($item->ID)) {
90
+			$this->set_id($item->ID);
91
+		} elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'custom_id')) {
92
+			$this->set_id($item_id);
93
+		} elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'name')) {
94
+			$this->set_id($item_id);
95 95
 		} else {
96
-			$this->set_object_read( true );
96
+			$this->set_object_read(true);
97 97
 		}
98 98
 
99 99
         // Load the datastore.
100
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
100
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
101 101
 
102
-		if ( $this->get_id() > 0 ) {
103
-            $this->post = get_post( $this->get_id() );
102
+		if ($this->get_id() > 0) {
103
+            $this->post = get_post($this->get_id());
104 104
             $this->ID   = $this->get_id();
105
-			$this->data_store->read( $this );
105
+			$this->data_store->read($this);
106 106
         }
107 107
 
108 108
 	}
@@ -129,8 +129,8 @@  discard block
 block discarded – undo
129 129
 	 * @param  string $context View or edit context.
130 130
 	 * @return int
131 131
 	 */
132
-	public function get_parent_id( $context = 'view' ) {
133
-		return (int) $this->get_prop( 'parent_id', $context );
132
+	public function get_parent_id($context = 'view') {
133
+		return (int) $this->get_prop('parent_id', $context);
134 134
     }
135 135
 
136 136
     /**
@@ -140,8 +140,8 @@  discard block
 block discarded – undo
140 140
 	 * @param  string $context View or edit context.
141 141
 	 * @return string
142 142
 	 */
143
-	public function get_status( $context = 'view' ) {
144
-		return $this->get_prop( 'status', $context );
143
+	public function get_status($context = 'view') {
144
+		return $this->get_prop('status', $context);
145 145
     }
146 146
 
147 147
     /**
@@ -151,8 +151,8 @@  discard block
 block discarded – undo
151 151
 	 * @param  string $context View or edit context.
152 152
 	 * @return string
153 153
 	 */
154
-	public function get_version( $context = 'view' ) {
155
-		return $this->get_prop( 'version', $context );
154
+	public function get_version($context = 'view') {
155
+		return $this->get_prop('version', $context);
156 156
     }
157 157
 
158 158
     /**
@@ -162,8 +162,8 @@  discard block
 block discarded – undo
162 162
 	 * @param  string $context View or edit context.
163 163
 	 * @return string
164 164
 	 */
165
-	public function get_date_created( $context = 'view' ) {
166
-		return $this->get_prop( 'date_created', $context );
165
+	public function get_date_created($context = 'view') {
166
+		return $this->get_prop('date_created', $context);
167 167
     }
168 168
 
169 169
     /**
@@ -173,11 +173,11 @@  discard block
 block discarded – undo
173 173
 	 * @param  string $context View or edit context.
174 174
 	 * @return string
175 175
 	 */
176
-	public function get_date_created_gmt( $context = 'view' ) {
177
-        $date = $this->get_date_created( $context );
176
+	public function get_date_created_gmt($context = 'view') {
177
+        $date = $this->get_date_created($context);
178 178
 
179
-        if ( $date ) {
180
-            $date = get_gmt_from_date( $date );
179
+        if ($date) {
180
+            $date = get_gmt_from_date($date);
181 181
         }
182 182
 		return $date;
183 183
     }
@@ -189,8 +189,8 @@  discard block
 block discarded – undo
189 189
 	 * @param  string $context View or edit context.
190 190
 	 * @return string
191 191
 	 */
192
-	public function get_date_modified( $context = 'view' ) {
193
-		return $this->get_prop( 'date_modified', $context );
192
+	public function get_date_modified($context = 'view') {
193
+		return $this->get_prop('date_modified', $context);
194 194
     }
195 195
 
196 196
     /**
@@ -200,11 +200,11 @@  discard block
 block discarded – undo
200 200
 	 * @param  string $context View or edit context.
201 201
 	 * @return string
202 202
 	 */
203
-	public function get_date_modified_gmt( $context = 'view' ) {
204
-        $date = $this->get_date_modified( $context );
203
+	public function get_date_modified_gmt($context = 'view') {
204
+        $date = $this->get_date_modified($context);
205 205
 
206
-        if ( $date ) {
207
-            $date = get_gmt_from_date( $date );
206
+        if ($date) {
207
+            $date = get_gmt_from_date($date);
208 208
         }
209 209
 		return $date;
210 210
     }
@@ -216,8 +216,8 @@  discard block
 block discarded – undo
216 216
 	 * @param  string $context View or edit context.
217 217
 	 * @return string
218 218
 	 */
219
-	public function get_name( $context = 'view' ) {
220
-		return $this->get_prop( 'name', $context );
219
+	public function get_name($context = 'view') {
220
+		return $this->get_prop('name', $context);
221 221
     }
222 222
 
223 223
     /**
@@ -227,8 +227,8 @@  discard block
 block discarded – undo
227 227
 	 * @param  string $context View or edit context.
228 228
 	 * @return string
229 229
 	 */
230
-	public function get_title( $context = 'view' ) {
231
-		return $this->get_name( $context );
230
+	public function get_title($context = 'view') {
231
+		return $this->get_name($context);
232 232
     }
233 233
 
234 234
     /**
@@ -238,8 +238,8 @@  discard block
 block discarded – undo
238 238
 	 * @param  string $context View or edit context.
239 239
 	 * @return string
240 240
 	 */
241
-	public function get_description( $context = 'view' ) {
242
-		return $this->get_prop( 'description', $context );
241
+	public function get_description($context = 'view') {
242
+		return $this->get_prop('description', $context);
243 243
     }
244 244
 
245 245
     /**
@@ -249,8 +249,8 @@  discard block
 block discarded – undo
249 249
 	 * @param  string $context View or edit context.
250 250
 	 * @return string
251 251
 	 */
252
-	public function get_excerpt( $context = 'view' ) {
253
-		return $this->get_description( $context );
252
+	public function get_excerpt($context = 'view') {
253
+		return $this->get_description($context);
254 254
     }
255 255
 
256 256
     /**
@@ -260,8 +260,8 @@  discard block
 block discarded – undo
260 260
 	 * @param  string $context View or edit context.
261 261
 	 * @return string
262 262
 	 */
263
-	public function get_summary( $context = 'view' ) {
264
-		return $this->get_description( $context );
263
+	public function get_summary($context = 'view') {
264
+		return $this->get_description($context);
265 265
     }
266 266
 
267 267
     /**
@@ -271,8 +271,8 @@  discard block
 block discarded – undo
271 271
 	 * @param  string $context View or edit context.
272 272
 	 * @return int
273 273
 	 */
274
-	public function get_author( $context = 'view' ) {
275
-		return (int) $this->get_prop( 'author', $context );
274
+	public function get_author($context = 'view') {
275
+		return (int) $this->get_prop('author', $context);
276 276
 	}
277 277
 	
278 278
 	/**
@@ -282,8 +282,8 @@  discard block
 block discarded – undo
282 282
 	 * @param  string $context View or edit context.
283 283
 	 * @return int
284 284
 	 */
285
-	public function get_owner( $context = 'view' ) {
286
-		return $this->get_author( $context );
285
+	public function get_owner($context = 'view') {
286
+		return $this->get_author($context);
287 287
     }
288 288
 
289 289
     /**
@@ -293,8 +293,8 @@  discard block
 block discarded – undo
293 293
 	 * @param  string $context View or edit context.
294 294
 	 * @return float
295 295
 	 */
296
-	public function get_price( $context = 'view' ) {
297
-        return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) );
296
+	public function get_price($context = 'view') {
297
+        return wpinv_sanitize_amount($this->get_prop('price', $context));
298 298
 	}
299 299
 	
300 300
 	/**
@@ -304,15 +304,15 @@  discard block
 block discarded – undo
304 304
 	 * @param  string $context View or edit context.
305 305
 	 * @return float
306 306
 	 */
307
-	public function get_initial_price( $context = 'view' ) {
307
+	public function get_initial_price($context = 'view') {
308 308
 
309
-		$price = (float) $this->get_price( $context );
309
+		$price = (float) $this->get_price($context);
310 310
 
311
-		if ( $this->has_free_trial() ) {
311
+		if ($this->has_free_trial()) {
312 312
 			$price = 0;
313 313
 		}
314 314
 
315
-        return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) );
315
+        return wpinv_sanitize_amount(apply_filters('wpinv_get_initial_item_price', $price, $this));
316 316
     }
317 317
 
318 318
     /**
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 	 * @return string
324 324
 	 */
325 325
     public function get_the_price() {
326
-        return wpinv_price( $this->get_price() );
326
+        return wpinv_price($this->get_price());
327 327
 	}
328 328
 
329 329
 	/**
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
 	 * @return string
335 335
 	 */
336 336
     public function get_the_initial_price() {
337
-        return wpinv_price( $this->get_initial_price() );
337
+        return wpinv_price($this->get_initial_price());
338 338
     }
339 339
 
340 340
     /**
@@ -344,8 +344,8 @@  discard block
 block discarded – undo
344 344
 	 * @param  string $context View or edit context.
345 345
 	 * @return string
346 346
 	 */
347
-	public function get_vat_rule( $context = 'view' ) {
348
-        return $this->get_prop( 'vat_rule', $context );
347
+	public function get_vat_rule($context = 'view') {
348
+        return $this->get_prop('vat_rule', $context);
349 349
     }
350 350
 
351 351
     /**
@@ -355,8 +355,8 @@  discard block
 block discarded – undo
355 355
 	 * @param  string $context View or edit context.
356 356
 	 * @return string
357 357
 	 */
358
-	public function get_vat_class( $context = 'view' ) {
359
-        return $this->get_prop( 'vat_class', $context );
358
+	public function get_vat_class($context = 'view') {
359
+        return $this->get_prop('vat_class', $context);
360 360
     }
361 361
 
362 362
     /**
@@ -366,8 +366,8 @@  discard block
 block discarded – undo
366 366
 	 * @param  string $context View or edit context.
367 367
 	 * @return string
368 368
 	 */
369
-	public function get_type( $context = 'view' ) {
370
-        return $this->get_prop( 'type', $context );
369
+	public function get_type($context = 'view') {
370
+        return $this->get_prop('type', $context);
371 371
     }
372 372
 
373 373
     /**
@@ -377,8 +377,8 @@  discard block
 block discarded – undo
377 377
 	 * @param  string $context View or edit context.
378 378
 	 * @return string
379 379
 	 */
380
-	public function get_custom_id( $context = 'view' ) {
381
-        return $this->get_prop( 'custom_id', $context );
380
+	public function get_custom_id($context = 'view') {
381
+        return $this->get_prop('custom_id', $context);
382 382
     }
383 383
 
384 384
     /**
@@ -388,8 +388,8 @@  discard block
 block discarded – undo
388 388
 	 * @param  string $context View or edit context.
389 389
 	 * @return string
390 390
 	 */
391
-	public function get_custom_name( $context = 'view' ) {
392
-        return $this->get_prop( 'custom_name', $context );
391
+	public function get_custom_name($context = 'view') {
392
+        return $this->get_prop('custom_name', $context);
393 393
     }
394 394
 
395 395
     /**
@@ -399,8 +399,8 @@  discard block
 block discarded – undo
399 399
 	 * @param  string $context View or edit context.
400 400
 	 * @return string
401 401
 	 */
402
-	public function get_custom_singular_name( $context = 'view' ) {
403
-        return $this->get_prop( 'custom_singular_name', $context );
402
+	public function get_custom_singular_name($context = 'view') {
403
+        return $this->get_prop('custom_singular_name', $context);
404 404
     }
405 405
 
406 406
     /**
@@ -410,8 +410,8 @@  discard block
 block discarded – undo
410 410
 	 * @param  string $context View or edit context.
411 411
 	 * @return int
412 412
 	 */
413
-	public function get_is_editable( $context = 'view' ) {
414
-        return (int) $this->get_prop( 'is_editable', $context );
413
+	public function get_is_editable($context = 'view') {
414
+        return (int) $this->get_prop('is_editable', $context);
415 415
     }
416 416
 
417 417
     /**
@@ -421,8 +421,8 @@  discard block
 block discarded – undo
421 421
 	 * @param  string $context View or edit context.
422 422
 	 * @return int
423 423
 	 */
424
-	public function get_editable( $context = 'view' ) {
425
-		return $this->get_is_editable( $context );
424
+	public function get_editable($context = 'view') {
425
+		return $this->get_is_editable($context);
426 426
     }
427 427
 
428 428
     /**
@@ -432,8 +432,8 @@  discard block
 block discarded – undo
432 432
 	 * @param  string $context View or edit context.
433 433
 	 * @return int
434 434
 	 */
435
-	public function get_is_dynamic_pricing( $context = 'view' ) {
436
-        return (int) $this->get_prop( 'is_dynamic_pricing', $context );
435
+	public function get_is_dynamic_pricing($context = 'view') {
436
+        return (int) $this->get_prop('is_dynamic_pricing', $context);
437 437
     }
438 438
 
439 439
     /**
@@ -443,8 +443,8 @@  discard block
 block discarded – undo
443 443
 	 * @param  string $context View or edit context.
444 444
 	 * @return float
445 445
 	 */
446
-	public function get_minimum_price( $context = 'view' ) {
447
-        return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) );
446
+	public function get_minimum_price($context = 'view') {
447
+        return wpinv_sanitize_amount($this->get_prop('minimum_price', $context));
448 448
     }
449 449
 
450 450
     /**
@@ -454,8 +454,8 @@  discard block
 block discarded – undo
454 454
 	 * @param  string $context View or edit context.
455 455
 	 * @return int
456 456
 	 */
457
-	public function get_is_recurring( $context = 'view' ) {
458
-        return (int) $this->get_prop( 'is_recurring', $context );
457
+	public function get_is_recurring($context = 'view') {
458
+        return (int) $this->get_prop('is_recurring', $context);
459 459
 	}
460 460
 
461 461
 	/**
@@ -465,8 +465,8 @@  discard block
 block discarded – undo
465 465
 	 * @param  string $context View or edit context.
466 466
 	 * @return int
467 467
 	 */
468
-	public function get_is_one_time_recurring( $context = 'view' ) {
469
-        return (int) $this->get_prop( 'is_one_time_recurring', $context );
468
+	public function get_is_one_time_recurring($context = 'view') {
469
+        return (int) $this->get_prop('is_one_time_recurring', $context);
470 470
 	}
471 471
 	
472 472
 	/**
@@ -476,9 +476,9 @@  discard block
 block discarded – undo
476 476
 	 * @param  string $context View or edit context.
477 477
 	 * @return float
478 478
 	 */
479
-	public function get_recurring_price( $context = 'view' ) {
480
-		$price = $this->get_price( $context );
481
-        return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) );
479
+	public function get_recurring_price($context = 'view') {
480
+		$price = $this->get_price($context);
481
+        return wpinv_sanitize_amount(apply_filters('wpinv_get_recurring_item_price', $price, $this->ID));
482 482
 	}
483 483
 
484 484
 	/**
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
 	 * @return string
490 490
 	 */
491 491
     public function get_the_recurring_price() {
492
-        return wpinv_price( $this->get_recurring_price() );
492
+        return wpinv_price($this->get_recurring_price());
493 493
 	}
494 494
 
495 495
 	/**
@@ -510,15 +510,15 @@  discard block
 block discarded – undo
510 510
 		$period   = $this->get_recurring_period();
511 511
 		$interval = $this->get_recurring_interval();
512 512
 
513
-		if ( $this->has_free_trial() ) {
513
+		if ($this->has_free_trial()) {
514 514
 			$period   = $this->get_trial_period();
515 515
 			$interval = $this->get_trial_interval();
516 516
 		}
517 517
 
518
-		$period       = $periods[ $period ];
519
-		$interval     = empty( $interval ) ? 1 : $interval;
520
-		$next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
521
-        return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this );
518
+		$period       = $periods[$period];
519
+		$interval     = empty($interval) ? 1 : $interval;
520
+		$next_renewal = strtotime("+$interval $period", current_time('timestamp'));
521
+        return apply_filters('wpinv_get_first_renewal_date', $next_renewal, $this);
522 522
     }
523 523
 
524 524
     /**
@@ -528,14 +528,14 @@  discard block
 block discarded – undo
528 528
 	 * @param  bool $full Return abbreviation or in full.
529 529
 	 * @return string
530 530
 	 */
531
-	public function get_recurring_period( $full = false ) {
532
-        $period = $this->get_prop( 'recurring_period', 'view' );
531
+	public function get_recurring_period($full = false) {
532
+        $period = $this->get_prop('recurring_period', 'view');
533 533
 
534
-        if ( $full && ! is_bool( $full ) ) {
534
+        if ($full && !is_bool($full)) {
535 535
             $full = false;
536 536
         }
537 537
 
538
-        return getpaid_sanitize_recurring_period( $period, $full );
538
+        return getpaid_sanitize_recurring_period($period, $full);
539 539
     }
540 540
 
541 541
     /**
@@ -545,10 +545,10 @@  discard block
 block discarded – undo
545 545
 	 * @param  string $context View or edit context.
546 546
 	 * @return int
547 547
 	 */
548
-	public function get_recurring_interval( $context = 'view' ) {
549
-		$interval = absint( $this->get_prop( 'recurring_interval', $context ) );
548
+	public function get_recurring_interval($context = 'view') {
549
+		$interval = absint($this->get_prop('recurring_interval', $context));
550 550
 
551
-		if ( $interval < 1 ) {
551
+		if ($interval < 1) {
552 552
 			$interval = 1;
553 553
 		}
554 554
 
@@ -562,8 +562,8 @@  discard block
 block discarded – undo
562 562
 	 * @param  string $context View or edit context.
563 563
 	 * @return int
564 564
 	 */
565
-	public function get_recurring_limit( $context = 'view' ) {
566
-        return (int) $this->get_prop( 'recurring_limit', $context );
565
+	public function get_recurring_limit($context = 'view') {
566
+        return (int) $this->get_prop('recurring_limit', $context);
567 567
     }
568 568
 
569 569
     /**
@@ -573,8 +573,8 @@  discard block
 block discarded – undo
573 573
 	 * @param  string $context View or edit context.
574 574
 	 * @return int
575 575
 	 */
576
-	public function get_is_free_trial( $context = 'view' ) {
577
-        return (int) $this->get_prop( 'is_free_trial', $context );
576
+	public function get_is_free_trial($context = 'view') {
577
+        return (int) $this->get_prop('is_free_trial', $context);
578 578
     }
579 579
 
580 580
     /**
@@ -584,8 +584,8 @@  discard block
 block discarded – undo
584 584
 	 * @param  string $context View or edit context.
585 585
 	 * @return int
586 586
 	 */
587
-	public function get_free_trial( $context = 'view' ) {
588
-        return $this->get_is_free_trial( $context );
587
+	public function get_free_trial($context = 'view') {
588
+        return $this->get_is_free_trial($context);
589 589
     }
590 590
 
591 591
     /**
@@ -595,14 +595,14 @@  discard block
 block discarded – undo
595 595
 	 * @param  bool $full Return abbreviation or in full.
596 596
 	 * @return string
597 597
 	 */
598
-	public function get_trial_period( $full = false ) {
599
-        $period = $this->get_prop( 'trial_period', 'view' );
598
+	public function get_trial_period($full = false) {
599
+        $period = $this->get_prop('trial_period', 'view');
600 600
 
601
-        if ( $full && ! is_bool( $full ) ) {
601
+        if ($full && !is_bool($full)) {
602 602
             $full = false;
603 603
         }
604 604
 
605
-        return getpaid_sanitize_recurring_period( $period, $full );
605
+        return getpaid_sanitize_recurring_period($period, $full);
606 606
     }
607 607
 
608 608
     /**
@@ -612,8 +612,8 @@  discard block
 block discarded – undo
612 612
 	 * @param  string $context View or edit context.
613 613
 	 * @return int
614 614
 	 */
615
-	public function get_trial_interval( $context = 'view' ) {
616
-        return (int) $this->get_prop( 'trial_interval', $context );
615
+	public function get_trial_interval($context = 'view') {
616
+        return (int) $this->get_prop('trial_interval', $context);
617 617
 	}
618 618
 	
619 619
 	/**
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
 	 * @return string
624 624
 	 */
625 625
 	public function get_edit_url() {
626
-        return get_edit_post_link( $this->get_id() );
626
+        return get_edit_post_link($this->get_id());
627 627
 	}
628 628
 
629 629
 	/**
@@ -637,35 +637,35 @@  discard block
 block discarded – undo
637 637
 	 * @since 1.0.15
638 638
 	 * @return int
639 639
 	 */
640
-	public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) {
640
+	public static function get_item_id_by_field($value, $field = 'custom_id', $type = '') {
641 641
 
642 642
 		// Trim the value.
643
-		$value = sanitize_text_field( $value );
644
-		if ( empty( $value ) ) {
643
+		$value = sanitize_text_field($value);
644
+		if (empty($value)) {
645 645
 			return 0;
646 646
 		}
647 647
 
648 648
         // Valid fields.
649
-        $fields = array( 'custom_id', 'name', 'slug' );
649
+        $fields = array('custom_id', 'name', 'slug');
650 650
 
651 651
 		// Ensure a field has been passed.
652
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
652
+		if (empty($field) || !in_array($field, $fields)) {
653 653
 			return 0;
654 654
 		}
655 655
 
656
-		if ( $field == 'name' ) {
656
+		if ($field == 'name') {
657 657
 			$field = 'slug';
658 658
 		}
659 659
 
660 660
 		// Maybe retrieve from the cache.
661
-		$item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" );
662
-		if ( ! empty( $item_id ) ) {
661
+		$item_id = wp_cache_get($value, "getpaid_{$type}_item_{$field}s_to_item_ids");
662
+		if (!empty($item_id)) {
663 663
 			return $item_id;
664 664
 		}
665 665
 
666 666
 		// Fetch from the db.
667 667
 		$items = array();
668
-		if ( $field == 'slug' ) {
668
+		if ($field == 'slug') {
669 669
 			$items = get_posts(
670 670
 				array(
671 671
 					'post_type'      => 'wpi_item',
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 			);
677 677
 		}
678 678
 
679
-		if ( $field =='custom_id' ) {
679
+		if ($field == 'custom_id') {
680 680
 			$items = get_posts(
681 681
 				array(
682 682
 					'post_type'      => 'wpi_item',
@@ -696,12 +696,12 @@  discard block
 block discarded – undo
696 696
 			);
697 697
 		}
698 698
 
699
-		if ( empty( $items ) ) {
699
+		if (empty($items)) {
700 700
 			return 0;
701 701
 		}
702 702
 
703 703
 		// Update the cache with our data
704
-		wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" );
704
+		wp_cache_set($value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids");
705 705
 
706 706
 		return $items[0]->ID;
707 707
     }
@@ -709,19 +709,19 @@  discard block
 block discarded – undo
709 709
     /**
710 710
      * Margic method for retrieving a property.
711 711
      */
712
-    public function __get( $key ) {
712
+    public function __get($key) {
713 713
 
714 714
         // Check if we have a helper method for that.
715
-        if ( method_exists( $this, 'get_' . $key ) ) {
716
-            return call_user_func( array( $this, 'get_' . $key ) );
715
+        if (method_exists($this, 'get_' . $key)) {
716
+            return call_user_func(array($this, 'get_' . $key));
717 717
         }
718 718
 
719 719
         // Check if the key is in the associated $post object.
720
-        if ( ! empty( $this->post ) && isset( $this->post->$key ) ) {
720
+        if (!empty($this->post) && isset($this->post->$key)) {
721 721
             return $this->post->$key;
722 722
         }
723 723
 
724
-        return $this->get_prop( $key );
724
+        return $this->get_prop($key);
725 725
 
726 726
     }
727 727
 
@@ -740,11 +740,11 @@  discard block
 block discarded – undo
740 740
 	 *
741 741
 	 * @since 1.0.19
742 742
 	 */
743
-	public function set_parent_id( $value ) {
744
-		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
743
+	public function set_parent_id($value) {
744
+		if ($value && ($value === $this->get_id() || !get_post($value))) {
745 745
 			return;
746 746
 		}
747
-		$this->set_prop( 'parent_id', absint( $value ) );
747
+		$this->set_prop('parent_id', absint($value));
748 748
 	}
749 749
 
750 750
     /**
@@ -754,10 +754,10 @@  discard block
 block discarded – undo
754 754
 	 * @param  string $status New status.
755 755
 	 * @return array details of change.
756 756
 	 */
757
-	public function set_status( $status ) {
757
+	public function set_status($status) {
758 758
         $old_status = $this->get_status();
759 759
 
760
-        $this->set_prop( 'status', $status );
760
+        $this->set_prop('status', $status);
761 761
 
762 762
 		return array(
763 763
 			'from' => $old_status,
@@ -770,8 +770,8 @@  discard block
 block discarded – undo
770 770
 	 *
771 771
 	 * @since 1.0.19
772 772
 	 */
773
-	public function set_version( $value ) {
774
-		$this->set_prop( 'version', $value );
773
+	public function set_version($value) {
774
+		$this->set_prop('version', $value);
775 775
     }
776 776
 
777 777
     /**
@@ -781,11 +781,11 @@  discard block
 block discarded – undo
781 781
 	 * @param string $value Value to set.
782 782
      * @return bool Whether or not the date was set.
783 783
 	 */
784
-	public function set_date_created( $value ) {
785
-        $date = strtotime( $value );
784
+	public function set_date_created($value) {
785
+        $date = strtotime($value);
786 786
 
787
-        if ( $date ) {
788
-            $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) );
787
+        if ($date) {
788
+            $this->set_prop('date_created', date('Y-m-d H:i:s', $date));
789 789
             return true;
790 790
         }
791 791
 
@@ -800,11 +800,11 @@  discard block
 block discarded – undo
800 800
 	 * @param string $value Value to set.
801 801
      * @return bool Whether or not the date was set.
802 802
 	 */
803
-	public function set_date_modified( $value ) {
804
-        $date = strtotime( $value );
803
+	public function set_date_modified($value) {
804
+        $date = strtotime($value);
805 805
 
806
-        if ( $date ) {
807
-            $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) );
806
+        if ($date) {
807
+            $this->set_prop('date_modified', date('Y-m-d H:i:s', $date));
808 808
             return true;
809 809
         }
810 810
 
@@ -818,9 +818,9 @@  discard block
 block discarded – undo
818 818
 	 * @since 1.0.19
819 819
 	 * @param  string $value New name.
820 820
 	 */
821
-	public function set_name( $value ) {
822
-        $name = sanitize_text_field( $value );
823
-		$this->set_prop( 'name', $name );
821
+	public function set_name($value) {
822
+        $name = sanitize_text_field($value);
823
+		$this->set_prop('name', $name);
824 824
     }
825 825
 
826 826
     /**
@@ -829,8 +829,8 @@  discard block
 block discarded – undo
829 829
 	 * @since 1.0.19
830 830
 	 * @param  string $value New name.
831 831
 	 */
832
-	public function set_title( $value ) {
833
-		$this->set_name( $value );
832
+	public function set_title($value) {
833
+		$this->set_name($value);
834 834
     }
835 835
 
836 836
     /**
@@ -839,9 +839,9 @@  discard block
 block discarded – undo
839 839
 	 * @since 1.0.19
840 840
 	 * @param  string $value New description.
841 841
 	 */
842
-	public function set_description( $value ) {
843
-		$description = wp_kses_post( $value );
844
-		return $this->set_prop( 'description', $description );
842
+	public function set_description($value) {
843
+		$description = wp_kses_post($value);
844
+		return $this->set_prop('description', $description);
845 845
     }
846 846
 
847 847
     /**
@@ -850,8 +850,8 @@  discard block
 block discarded – undo
850 850
 	 * @since 1.0.19
851 851
 	 * @param  string $value New description.
852 852
 	 */
853
-	public function set_excerpt( $value ) {
854
-		$this->set_description( $value );
853
+	public function set_excerpt($value) {
854
+		$this->set_description($value);
855 855
     }
856 856
 
857 857
     /**
@@ -860,8 +860,8 @@  discard block
 block discarded – undo
860 860
 	 * @since 1.0.19
861 861
 	 * @param  string $value New description.
862 862
 	 */
863
-	public function set_summary( $value ) {
864
-		$this->set_description( $value );
863
+	public function set_summary($value) {
864
+		$this->set_description($value);
865 865
     }
866 866
 
867 867
     /**
@@ -870,8 +870,8 @@  discard block
 block discarded – undo
870 870
 	 * @since 1.0.19
871 871
 	 * @param  int $value New author.
872 872
 	 */
873
-	public function set_author( $value ) {
874
-		$this->set_prop( 'author', (int) $value );
873
+	public function set_author($value) {
874
+		$this->set_prop('author', (int) $value);
875 875
 	}
876 876
 	
877 877
 	/**
@@ -880,8 +880,8 @@  discard block
 block discarded – undo
880 880
 	 * @since 1.0.19
881 881
 	 * @param  int $value New author.
882 882
 	 */
883
-	public function set_owner( $value ) {
884
-		$this->set_author( $value );
883
+	public function set_owner($value) {
884
+		$this->set_author($value);
885 885
     }
886 886
 
887 887
     /**
@@ -890,8 +890,8 @@  discard block
 block discarded – undo
890 890
 	 * @since 1.0.19
891 891
 	 * @param  float $value New price.
892 892
 	 */
893
-	public function set_price( $value ) {
894
-        $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) );
893
+	public function set_price($value) {
894
+        $this->set_prop('price', (float) wpinv_sanitize_amount($value));
895 895
     }
896 896
 
897 897
     /**
@@ -900,8 +900,8 @@  discard block
 block discarded – undo
900 900
 	 * @since 1.0.19
901 901
 	 * @param  string $value new rule.
902 902
 	 */
903
-	public function set_vat_rule( $value ) {
904
-        $this->set_prop( 'vat_rule', $value );
903
+	public function set_vat_rule($value) {
904
+        $this->set_prop('vat_rule', $value);
905 905
     }
906 906
 
907 907
     /**
@@ -910,8 +910,8 @@  discard block
 block discarded – undo
910 910
 	 * @since 1.0.19
911 911
 	 * @param  string $value new class.
912 912
 	 */
913
-	public function set_vat_class( $value ) {
914
-        $this->set_prop( 'vat_class', $value );
913
+	public function set_vat_class($value) {
914
+        $this->set_prop('vat_class', $value);
915 915
     }
916 916
 
917 917
     /**
@@ -921,13 +921,13 @@  discard block
 block discarded – undo
921 921
 	 * @param  string $value new item type.
922 922
 	 * @return string
923 923
 	 */
924
-	public function set_type( $value ) {
924
+	public function set_type($value) {
925 925
 
926
-        if ( empty( $value ) ) {
926
+        if (empty($value)) {
927 927
             $value = 'custom';
928 928
         }
929 929
 
930
-        $this->set_prop( 'type', $value );
930
+        $this->set_prop('type', $value);
931 931
     }
932 932
 
933 933
     /**
@@ -936,8 +936,8 @@  discard block
 block discarded – undo
936 936
 	 * @since 1.0.19
937 937
 	 * @param  string $value new custom id.
938 938
 	 */
939
-	public function set_custom_id( $value ) {
940
-        $this->set_prop( 'custom_id', $value );
939
+	public function set_custom_id($value) {
940
+        $this->set_prop('custom_id', $value);
941 941
     }
942 942
 
943 943
     /**
@@ -946,8 +946,8 @@  discard block
 block discarded – undo
946 946
 	 * @since 1.0.19
947 947
 	 * @param  string $value new custom name.
948 948
 	 */
949
-	public function set_custom_name( $value ) {
950
-        $this->set_prop( 'custom_name', $value );
949
+	public function set_custom_name($value) {
950
+        $this->set_prop('custom_name', $value);
951 951
     }
952 952
 
953 953
     /**
@@ -956,8 +956,8 @@  discard block
 block discarded – undo
956 956
 	 * @since 1.0.19
957 957
 	 * @param  string $value new custom singular name.
958 958
 	 */
959
-	public function set_custom_singular_name( $value ) {
960
-        $this->set_prop( 'custom_singular_name', $value );
959
+	public function set_custom_singular_name($value) {
960
+        $this->set_prop('custom_singular_name', $value);
961 961
     }
962 962
 
963 963
     /**
@@ -966,8 +966,8 @@  discard block
 block discarded – undo
966 966
 	 * @since 1.0.19
967 967
 	 * @param  int|bool $value whether or not the item is editable.
968 968
 	 */
969
-	public function set_is_editable( $value ) {
970
-		$this->set_prop( 'is_editable', (int) $value );
969
+	public function set_is_editable($value) {
970
+		$this->set_prop('is_editable', (int) $value);
971 971
     }
972 972
 
973 973
     /**
@@ -976,8 +976,8 @@  discard block
 block discarded – undo
976 976
 	 * @since 1.0.19
977 977
 	 * @param  int|bool $value whether or not dynamic pricing is allowed.
978 978
 	 */
979
-	public function set_is_dynamic_pricing( $value ) {
980
-        $this->set_prop( 'is_dynamic_pricing', (int) $value );
979
+	public function set_is_dynamic_pricing($value) {
980
+        $this->set_prop('is_dynamic_pricing', (int) $value);
981 981
     }
982 982
 
983 983
     /**
@@ -986,8 +986,8 @@  discard block
 block discarded – undo
986 986
 	 * @since 1.0.19
987 987
 	 * @param  float $value minimum price.
988 988
 	 */
989
-	public function set_minimum_price( $value ) {
990
-        $this->set_prop( 'minimum_price',  (float) wpinv_sanitize_amount( $value ) );
989
+	public function set_minimum_price($value) {
990
+        $this->set_prop('minimum_price', (float) wpinv_sanitize_amount($value));
991 991
     }
992 992
 
993 993
     /**
@@ -996,8 +996,8 @@  discard block
 block discarded – undo
996 996
 	 * @since 1.0.19
997 997
 	 * @param  int|bool $value whether or not dynamic pricing is allowed.
998 998
 	 */
999
-	public function set_is_recurring( $value ) {
1000
-        $this->set_prop( 'is_recurring', (int) $value );
999
+	public function set_is_recurring($value) {
1000
+        $this->set_prop('is_recurring', (int) $value);
1001 1001
     }
1002 1002
 
1003 1003
 	/**
@@ -1006,8 +1006,8 @@  discard block
 block discarded – undo
1006 1006
 	 * @since 1.0.19
1007 1007
 	 * @param  int|bool $value whether or not dynamic pricing is allowed.
1008 1008
 	 */
1009
-	public function set_is_one_time_recurring( $value ) {
1010
-        $this->set_prop( 'is_one_time_recurring', (int) $value );
1009
+	public function set_is_one_time_recurring($value) {
1010
+        $this->set_prop('is_one_time_recurring', (int) $value);
1011 1011
     }
1012 1012
 
1013 1013
     /**
@@ -1016,8 +1016,8 @@  discard block
 block discarded – undo
1016 1016
 	 * @since 1.0.19
1017 1017
 	 * @param  string $value new period.
1018 1018
 	 */
1019
-	public function set_recurring_period( $value ) {
1020
-        $this->set_prop( 'recurring_period', $value );
1019
+	public function set_recurring_period($value) {
1020
+        $this->set_prop('recurring_period', $value);
1021 1021
     }
1022 1022
 
1023 1023
     /**
@@ -1026,8 +1026,8 @@  discard block
 block discarded – undo
1026 1026
 	 * @since 1.0.19
1027 1027
 	 * @param  int $value recurring interval.
1028 1028
 	 */
1029
-	public function set_recurring_interval( $value ) {
1030
-        return $this->set_prop( 'recurring_interval', (int) $value );
1029
+	public function set_recurring_interval($value) {
1030
+        return $this->set_prop('recurring_interval', (int) $value);
1031 1031
     }
1032 1032
 
1033 1033
     /**
@@ -1036,8 +1036,8 @@  discard block
 block discarded – undo
1036 1036
 	 * @param  int $value The recurring limit.
1037 1037
 	 * @return int
1038 1038
 	 */
1039
-	public function set_recurring_limit( $value ) {
1040
-        $this->set_prop( 'recurring_limit', (int) $value );
1039
+	public function set_recurring_limit($value) {
1040
+        $this->set_prop('recurring_limit', (int) $value);
1041 1041
     }
1042 1042
 
1043 1043
     /**
@@ -1046,8 +1046,8 @@  discard block
 block discarded – undo
1046 1046
 	 * @since 1.0.19
1047 1047
 	 * @param  int|bool $value whether or not it has a free trial.
1048 1048
 	 */
1049
-	public function set_is_free_trial( $value ) {
1050
-        $this->set_prop( 'is_free_trial', (int) $value );
1049
+	public function set_is_free_trial($value) {
1050
+        $this->set_prop('is_free_trial', (int) $value);
1051 1051
     }
1052 1052
 
1053 1053
     /**
@@ -1056,8 +1056,8 @@  discard block
 block discarded – undo
1056 1056
 	 * @since 1.0.19
1057 1057
 	 * @param  string $value trial period.
1058 1058
 	 */
1059
-	public function set_trial_period( $value ) {
1060
-        $this->set_prop( 'trial_period', $value );
1059
+	public function set_trial_period($value) {
1060
+        $this->set_prop('trial_period', $value);
1061 1061
     }
1062 1062
 
1063 1063
     /**
@@ -1066,8 +1066,8 @@  discard block
 block discarded – undo
1066 1066
 	 * @since 1.0.19
1067 1067
 	 * @param  int $value trial interval.
1068 1068
 	 */
1069
-	public function set_trial_interval( $value ) {
1070
-        $this->set_prop( 'trial_interval', $value );
1069
+	public function set_trial_interval($value) {
1070
+        $this->set_prop('trial_interval', $value);
1071 1071
     }
1072 1072
 
1073 1073
     /**
@@ -1076,11 +1076,11 @@  discard block
 block discarded – undo
1076 1076
      * @deprecated
1077 1077
 	 * @return int item id
1078 1078
      */
1079
-    public function create( $data = array() ) {
1079
+    public function create($data = array()) {
1080 1080
 
1081 1081
 		// Set the properties.
1082
-		if ( is_array( $data ) ) {
1083
-			$this->set_props( $data );
1082
+		if (is_array($data)) {
1083
+			$this->set_props($data);
1084 1084
 		}
1085 1085
 
1086 1086
 		// Save the item.
@@ -1094,8 +1094,8 @@  discard block
 block discarded – undo
1094 1094
      * @deprecated
1095 1095
 	 * @return int item id
1096 1096
      */
1097
-    public function update( $data = array() ) {
1098
-        return $this->create( $data );
1097
+    public function update($data = array()) {
1098
+        return $this->create($data);
1099 1099
     }
1100 1100
 
1101 1101
     /*
@@ -1145,7 +1145,7 @@  discard block
 block discarded – undo
1145 1145
 	 */
1146 1146
     public function has_free_trial() {
1147 1147
         $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false;
1148
-        return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this );
1148
+        return (bool) apply_filters('wpinv_item_has_free_trial', $has_trial, $this->ID, $this);
1149 1149
     }
1150 1150
 
1151 1151
     /**
@@ -1155,8 +1155,8 @@  discard block
 block discarded – undo
1155 1155
 	 * @return bool
1156 1156
 	 */
1157 1157
     public function is_free() {
1158
-        $is_free   = $this->get_price() == 0;
1159
-        return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this );
1158
+        $is_free = $this->get_price() == 0;
1159
+        return (bool) apply_filters('wpinv_is_free_item', $is_free, $this->ID, $this);
1160 1160
     }
1161 1161
 
1162 1162
     /**
@@ -1165,9 +1165,9 @@  discard block
 block discarded – undo
1165 1165
 	 * @param array|string $status Status to check.
1166 1166
 	 * @return bool
1167 1167
 	 */
1168
-	public function has_status( $status ) {
1169
-		$has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1170
-		return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1168
+	public function has_status($status) {
1169
+		$has_status = (is_array($status) && in_array($this->get_status(), $status, true)) || $this->get_status() === $status;
1170
+		return (bool) apply_filters('getpaid_item_has_status', $has_status, $this, $status);
1171 1171
     }
1172 1172
 
1173 1173
     /**
@@ -1176,9 +1176,9 @@  discard block
 block discarded – undo
1176 1176
 	 * @param array|string $type Type to check.
1177 1177
 	 * @return bool
1178 1178
 	 */
1179
-	public function is_type( $type ) {
1180
-		$is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1181
-		return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1179
+	public function is_type($type) {
1180
+		$is_type = (is_array($type) && in_array($this->get_type(), $type, true)) || $this->get_type() === $type;
1181
+		return (bool) apply_filters('getpaid_item_is_type', $is_type, $this, $type);
1182 1182
 	}
1183 1183
 
1184 1184
     /**
@@ -1189,7 +1189,7 @@  discard block
 block discarded – undo
1189 1189
 	 */
1190 1190
     public function is_editable() {
1191 1191
         $is_editable = $this->get_is_editable();
1192
-        return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this );
1192
+        return (bool) apply_filters('wpinv_item_is_editable', $is_editable, $this->ID, $this);
1193 1193
 	}
1194 1194
 
1195 1195
 	/**
@@ -1208,11 +1208,11 @@  discard block
 block discarded – undo
1208 1208
     public function can_purchase() {
1209 1209
         $can_purchase = $this->exists();
1210 1210
 
1211
-        if ( ! current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) {
1211
+        if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') {
1212 1212
             $can_purchase = false;
1213 1213
         }
1214 1214
 
1215
-        return (bool) apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this );
1215
+        return (bool) apply_filters('wpinv_can_purchase_item', $can_purchase, $this);
1216 1216
     }
1217 1217
 
1218 1218
     /**
@@ -1222,6 +1222,6 @@  discard block
 block discarded – undo
1222 1222
 	 * @return bool
1223 1223
 	 */
1224 1224
     public function supports_dynamic_pricing() {
1225
-        return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this );
1225
+        return (bool) apply_filters('wpinv_item_supports_dynamic_pricing', true, $this);
1226 1226
     }
1227 1227
 }
Please login to merge, or discard this patch.
includes/data/item-schema.php 2 patches
Indentation   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -13,240 +13,240 @@
 block discarded – undo
13 13
 
14 14
 return array(
15 15
 
16
-	'id'              => array(
17
-		'description' => __( 'Unique identifier for the item.', 'invoicing' ),
18
-		'type'        => 'integer',
19
-		'context'     => array( 'view', 'edit', 'embed' ),
20
-		'readonly'    => true,
21
-	),
22
-
23
-	'parent_id'       => array(
24
-		'description' => __( 'Parent item ID.', 'invoicing' ),
25
-		'type'        => 'integer',
26
-		'context'     => array( 'view', 'edit', 'embed' ),
27
-		'default'     => 0,
28
-	),
29
-
30
-	'status'          => array(
31
-		'description' => __( 'A named status for the item.', 'invoicing' ),
32
-		'type'        => 'string',
33
-		'enum'        => array( 'draft', 'pending', 'publish' ),
34
-		'context'     => array( 'view', 'edit', 'embed' ),
35
-		'default'     => 'draft',
36
-	),
37
-
38
-	'version'         => array(
39
-		'description' => __( 'Plugin version when the item was created.', 'invoicing' ),
40
-		'type'        => 'string',
41
-		'context'     => array( 'view', 'edit' ),
42
-		'readonly'    => true,
43
-	),
44
-
45
-	'date_created'    => array(
46
-		'description' => __( "The date the item was created, in the site's timezone.", 'invoicing' ),
47
-		'type'        => 'string',
48
-		'context'     => array( 'view', 'edit', 'embed' ),
49
-	),
50
-
51
-	'date_created_gmt'    => array(
52
-		'description' => __( 'The GMT date the item was created.', 'invoicing' ),
53
-		'type'        => 'string',
54
-		'context'     => array( 'view', 'edit', 'embed' ),
55
-		'readonly'    => true,
56
-	),
57
-
58
-	'date_modified'   => array(
59
-		'description' => __( "The date the item was last modified, in the site's timezone.", 'invoicing' ),
60
-		'type'        => 'string',
61
-		'context'     => array( 'view', 'edit', 'embed' ),
62
-		'readonly'    => true,
63
-	),
64
-
65
-	'date_modified_gmt'    => array(
66
-		'description' => __( 'The GMT date the item was last modified.', 'invoicing' ),
67
-		'type'        => 'string',
68
-		'context'     => array( 'view', 'edit', 'embed' ),
69
-		'readonly'    => true,
70
-	),
71
-
72
-	'name'			  => array(
73
-		'description' => __( "The item's name.", 'invoicing' ),
74
-		'type'        => 'string',
75
-		'context'     => array( 'view', 'edit', 'embed' ),
76
-		'required'    => true,
77
-	),
78
-
79
-	'description'     => array(
80
-		'description' => __( "The item's description.", 'invoicing' ),
81
-		'type'        => 'string',
82
-		'context'     => array( 'view', 'edit', 'embed' ),
83
-	),
84
-
85
-	'owner'           => array(
86
-		'description' => __( 'The owner of the item (user id).', 'invoicing' ),
87
-		'type'        => 'integer',
88
-		'context'     => array( 'view', 'edit', 'embed' ),
89
-	),
90
-
91
-	'price'           => array(
92
-		'description' => __( 'The price of the item.', 'invoicing' ),
93
-		'type'        => 'number',
94
-		'context'     => array( 'view', 'edit', 'embed' ),
95
-		'required'    => true,
96
-	),
97
-
98
-	'the_price'       => array(
99
-		'description' => __( 'The formatted price of the item.', 'invoicing' ),
100
-		'type'        => 'string',
101
-		'context'     => array( 'view', 'edit', 'embed' ),
102
-		'readonly'    => true,
103
-	),
104
-
105
-	'type'       => array(
106
-		'description' => __( 'The item type.', 'invoicing' ),
107
-		'type'        => 'string',
108
-		'enum'        => wpinv_item_types(),
109
-		'default'     => 'custom',
110
-		'context'     => array( 'view', 'edit', 'embed' ),
111
-	),
112
-
113
-	'vat_rule'       => array(
114
-		'description' => __( 'VAT rule applied to the item.', 'invoicing' ),
115
-		'type'        => 'string',
116
-		'enum'        => array_keys( getpaid_get_tax_rules() ),
117
-		'context'     => array( 'view', 'edit', 'embed' ),
118
-	),
119
-
120
-	'vat_class'       => array(
121
-		'description' => __( 'VAT class for the item.', 'invoicing' ),
122
-		'type'        => 'string',
123
-		'context'     => array( 'view', 'edit', 'embed' ),
124
-		'enum'        => array_keys( getpaid_get_tax_classes() ),
125
-	),
126
-
127
-	'custom_id'       => array(
128
-		'description' => __( 'Custom id for the item.', 'invoicing' ),
129
-		'type'        => 'string',
130
-		'context'     => array( 'view', 'edit', 'embed' ),
131
-	),
16
+    'id'              => array(
17
+        'description' => __( 'Unique identifier for the item.', 'invoicing' ),
18
+        'type'        => 'integer',
19
+        'context'     => array( 'view', 'edit', 'embed' ),
20
+        'readonly'    => true,
21
+    ),
22
+
23
+    'parent_id'       => array(
24
+        'description' => __( 'Parent item ID.', 'invoicing' ),
25
+        'type'        => 'integer',
26
+        'context'     => array( 'view', 'edit', 'embed' ),
27
+        'default'     => 0,
28
+    ),
29
+
30
+    'status'          => array(
31
+        'description' => __( 'A named status for the item.', 'invoicing' ),
32
+        'type'        => 'string',
33
+        'enum'        => array( 'draft', 'pending', 'publish' ),
34
+        'context'     => array( 'view', 'edit', 'embed' ),
35
+        'default'     => 'draft',
36
+    ),
37
+
38
+    'version'         => array(
39
+        'description' => __( 'Plugin version when the item was created.', 'invoicing' ),
40
+        'type'        => 'string',
41
+        'context'     => array( 'view', 'edit' ),
42
+        'readonly'    => true,
43
+    ),
44
+
45
+    'date_created'    => array(
46
+        'description' => __( "The date the item was created, in the site's timezone.", 'invoicing' ),
47
+        'type'        => 'string',
48
+        'context'     => array( 'view', 'edit', 'embed' ),
49
+    ),
50
+
51
+    'date_created_gmt'    => array(
52
+        'description' => __( 'The GMT date the item was created.', 'invoicing' ),
53
+        'type'        => 'string',
54
+        'context'     => array( 'view', 'edit', 'embed' ),
55
+        'readonly'    => true,
56
+    ),
57
+
58
+    'date_modified'   => array(
59
+        'description' => __( "The date the item was last modified, in the site's timezone.", 'invoicing' ),
60
+        'type'        => 'string',
61
+        'context'     => array( 'view', 'edit', 'embed' ),
62
+        'readonly'    => true,
63
+    ),
64
+
65
+    'date_modified_gmt'    => array(
66
+        'description' => __( 'The GMT date the item was last modified.', 'invoicing' ),
67
+        'type'        => 'string',
68
+        'context'     => array( 'view', 'edit', 'embed' ),
69
+        'readonly'    => true,
70
+    ),
71
+
72
+    'name'			  => array(
73
+        'description' => __( "The item's name.", 'invoicing' ),
74
+        'type'        => 'string',
75
+        'context'     => array( 'view', 'edit', 'embed' ),
76
+        'required'    => true,
77
+    ),
78
+
79
+    'description'     => array(
80
+        'description' => __( "The item's description.", 'invoicing' ),
81
+        'type'        => 'string',
82
+        'context'     => array( 'view', 'edit', 'embed' ),
83
+    ),
84
+
85
+    'owner'           => array(
86
+        'description' => __( 'The owner of the item (user id).', 'invoicing' ),
87
+        'type'        => 'integer',
88
+        'context'     => array( 'view', 'edit', 'embed' ),
89
+    ),
90
+
91
+    'price'           => array(
92
+        'description' => __( 'The price of the item.', 'invoicing' ),
93
+        'type'        => 'number',
94
+        'context'     => array( 'view', 'edit', 'embed' ),
95
+        'required'    => true,
96
+    ),
97
+
98
+    'the_price'       => array(
99
+        'description' => __( 'The formatted price of the item.', 'invoicing' ),
100
+        'type'        => 'string',
101
+        'context'     => array( 'view', 'edit', 'embed' ),
102
+        'readonly'    => true,
103
+    ),
104
+
105
+    'type'       => array(
106
+        'description' => __( 'The item type.', 'invoicing' ),
107
+        'type'        => 'string',
108
+        'enum'        => wpinv_item_types(),
109
+        'default'     => 'custom',
110
+        'context'     => array( 'view', 'edit', 'embed' ),
111
+    ),
112
+
113
+    'vat_rule'       => array(
114
+        'description' => __( 'VAT rule applied to the item.', 'invoicing' ),
115
+        'type'        => 'string',
116
+        'enum'        => array_keys( getpaid_get_tax_rules() ),
117
+        'context'     => array( 'view', 'edit', 'embed' ),
118
+    ),
119
+
120
+    'vat_class'       => array(
121
+        'description' => __( 'VAT class for the item.', 'invoicing' ),
122
+        'type'        => 'string',
123
+        'context'     => array( 'view', 'edit', 'embed' ),
124
+        'enum'        => array_keys( getpaid_get_tax_classes() ),
125
+    ),
126
+
127
+    'custom_id'       => array(
128
+        'description' => __( 'Custom id for the item.', 'invoicing' ),
129
+        'type'        => 'string',
130
+        'context'     => array( 'view', 'edit', 'embed' ),
131
+    ),
132 132
 	
133
-	'custom_name'       => array(
134
-		'description' => __( 'Custom name for the item.', 'invoicing' ),
135
-		'type'        => 'string',
136
-		'context'     => array( 'view', 'edit', 'embed' ),
137
-	),
138
-
139
-	'custom_singular_name'       => array(
140
-		'description' => __( 'Custom singular name for the item.', 'invoicing' ),
141
-		'type'        => 'string',
142
-		'context'     => array( 'view', 'edit', 'embed' ),
143
-	),
144
-
145
-	'is_dynamic_pricing'     => array(
146
-		'description' => __( 'Whether or not customers can enter their own prices when checking out.', 'invoicing' ),
147
-		'type'        => 'integer',
148
-		'enum'        => array( 0, 1 ),
149
-		'context'     => array( 'view', 'edit', 'embed' ),
150
-	),
151
-
152
-	'minimum_price'   => array(
153
-		'description' => __( 'For dynamic prices, this is the minimum price that a user can set.', 'invoicing' ),
154
-		'type'        => 'number',
155
-		'context'     => array( 'view', 'edit', 'embed' ),
156
-	),
157
-
158
-	'is_one_time_recurring'        => array(
159
-		'description' => __( 'Whether or not this is a one time subscription item.', 'invoicing' ),
160
-		'type'        => 'integer',
161
-		'enum'        => array( 0, 1 ),
162
-		'context'     => array( 'view', 'edit', 'embed' ),
163
-	), 
164
-
165
-	'is_recurring'        => array(
166
-		'description' => __( 'Whether or not this is a subscription item.', 'invoicing' ),
167
-		'type'        => 'integer',
168
-		'enum'        => array( 0, 1 ),
169
-		'context'     => array( 'view', 'edit', 'embed' ),
170
-	),
171
-
172
-	'initial_price'   => array(
173
-		'description' => __( 'The initial price of the item.', 'invoicing' ),
174
-		'type'        => 'number',
175
-		'context'     => array( 'view', 'edit', 'embed' ),
176
-		'readonly'    => true,
177
-	),
178
-
179
-	'the_initial_price'       => array(
180
-		'description' => __( 'The formatted initial price of the item.', 'invoicing' ),
181
-		'type'        => 'string',
182
-		'context'     => array( 'view', 'edit', 'embed' ),
183
-		'readonly'    => true,
184
-	),
185
-
186
-	'recurring_price' => array(
187
-		'description' => __( 'The recurring price of the item.', 'invoicing' ),
188
-		'type'        => 'number',
189
-		'context'     => array( 'view', 'edit', 'embed' ),
190
-		'readonly'    => true,
191
-	),
192
-
193
-	'the_recurring_price'       => array(
194
-		'description' => __( 'The formatted recurring price of the item.', 'invoicing' ),
195
-		'type'        => 'string',
196
-		'context'     => array( 'view', 'edit', 'embed' ),
197
-		'readonly'    => true,
198
-	),
199
-
200
-	'recurring_period'        => array(
201
-		'description' => __( 'The recurring period for a recurring item.', 'invoicing' ),
202
-		'type'        => 'string',
203
-		'context'     => array( 'view', 'edit', 'embed' ),
204
-		'enum'        => array( 'D', 'W', 'M', 'Y' ),
205
-	),
206
-
207
-	'recurring_interval'        => array(
208
-		'description' => __( 'The recurring interval for a subscription item.', 'invoicing' ),
209
-		'type'        => 'integer',
210
-		'context'     => array( 'view', 'edit', 'embed' ),
211
-	),
212
-
213
-	'recurring_limit' => array(
214
-		'description' => __( 'The maximum number of renewals for a subscription item.', 'invoicing' ),
215
-		'type'        => 'integer',
216
-		'context'     => array( 'view', 'edit', 'embed' ),
217
-	),
218
-
219
-	'is_free_trial'   => array(
220
-		'description' => __( 'Whether the item has a free trial period.', 'invoicing' ),
221
-		'type'        => 'integer',
222
-		'enum'        => array( 0, 1 ),
223
-		'context'     => array( 'view', 'edit', 'embed' ),
224
-	),
225
-
226
-	'trial_period'    => array(
227
-		'description' => __( 'The trial period.', 'invoicing' ),
228
-		'type'        => 'string',
229
-		'context'     => array( 'view', 'edit', 'embed' ),
230
-		'enum'        => array( 'D', 'W', 'M', 'Y' ),
231
-	),
232
-
233
-	'trial_interval'  => array(
234
-		'description' => __( 'The trial interval.', 'invoicing' ),
235
-		'type'        => 'integer',
236
-		'context'     => array( 'view', 'edit', 'embed' ),
237
-	),
238
-
239
-	'first_renewal_date'       => array(
240
-		'description' => __( 'The first renewal date in case the item was to be bought today.', 'invoicing' ),
241
-		'type'        => 'string',
242
-		'context'     => array( 'view', 'edit', 'embed' ),
243
-		'readonly'    => true,
244
-	),
245
-
246
-	'edit_url'        => array(
247
-		'description' => __( 'The URL to edit an item.', 'invoicing' ),
248
-		'type'        => 'string',
249
-		'context'     => array( 'view', 'edit', 'embed' ),
250
-		'readonly'    => true,
251
-	),
133
+    'custom_name'       => array(
134
+        'description' => __( 'Custom name for the item.', 'invoicing' ),
135
+        'type'        => 'string',
136
+        'context'     => array( 'view', 'edit', 'embed' ),
137
+    ),
138
+
139
+    'custom_singular_name'       => array(
140
+        'description' => __( 'Custom singular name for the item.', 'invoicing' ),
141
+        'type'        => 'string',
142
+        'context'     => array( 'view', 'edit', 'embed' ),
143
+    ),
144
+
145
+    'is_dynamic_pricing'     => array(
146
+        'description' => __( 'Whether or not customers can enter their own prices when checking out.', 'invoicing' ),
147
+        'type'        => 'integer',
148
+        'enum'        => array( 0, 1 ),
149
+        'context'     => array( 'view', 'edit', 'embed' ),
150
+    ),
151
+
152
+    'minimum_price'   => array(
153
+        'description' => __( 'For dynamic prices, this is the minimum price that a user can set.', 'invoicing' ),
154
+        'type'        => 'number',
155
+        'context'     => array( 'view', 'edit', 'embed' ),
156
+    ),
157
+
158
+    'is_one_time_recurring'        => array(
159
+        'description' => __( 'Whether or not this is a one time subscription item.', 'invoicing' ),
160
+        'type'        => 'integer',
161
+        'enum'        => array( 0, 1 ),
162
+        'context'     => array( 'view', 'edit', 'embed' ),
163
+    ), 
164
+
165
+    'is_recurring'        => array(
166
+        'description' => __( 'Whether or not this is a subscription item.', 'invoicing' ),
167
+        'type'        => 'integer',
168
+        'enum'        => array( 0, 1 ),
169
+        'context'     => array( 'view', 'edit', 'embed' ),
170
+    ),
171
+
172
+    'initial_price'   => array(
173
+        'description' => __( 'The initial price of the item.', 'invoicing' ),
174
+        'type'        => 'number',
175
+        'context'     => array( 'view', 'edit', 'embed' ),
176
+        'readonly'    => true,
177
+    ),
178
+
179
+    'the_initial_price'       => array(
180
+        'description' => __( 'The formatted initial price of the item.', 'invoicing' ),
181
+        'type'        => 'string',
182
+        'context'     => array( 'view', 'edit', 'embed' ),
183
+        'readonly'    => true,
184
+    ),
185
+
186
+    'recurring_price' => array(
187
+        'description' => __( 'The recurring price of the item.', 'invoicing' ),
188
+        'type'        => 'number',
189
+        'context'     => array( 'view', 'edit', 'embed' ),
190
+        'readonly'    => true,
191
+    ),
192
+
193
+    'the_recurring_price'       => array(
194
+        'description' => __( 'The formatted recurring price of the item.', 'invoicing' ),
195
+        'type'        => 'string',
196
+        'context'     => array( 'view', 'edit', 'embed' ),
197
+        'readonly'    => true,
198
+    ),
199
+
200
+    'recurring_period'        => array(
201
+        'description' => __( 'The recurring period for a recurring item.', 'invoicing' ),
202
+        'type'        => 'string',
203
+        'context'     => array( 'view', 'edit', 'embed' ),
204
+        'enum'        => array( 'D', 'W', 'M', 'Y' ),
205
+    ),
206
+
207
+    'recurring_interval'        => array(
208
+        'description' => __( 'The recurring interval for a subscription item.', 'invoicing' ),
209
+        'type'        => 'integer',
210
+        'context'     => array( 'view', 'edit', 'embed' ),
211
+    ),
212
+
213
+    'recurring_limit' => array(
214
+        'description' => __( 'The maximum number of renewals for a subscription item.', 'invoicing' ),
215
+        'type'        => 'integer',
216
+        'context'     => array( 'view', 'edit', 'embed' ),
217
+    ),
218
+
219
+    'is_free_trial'   => array(
220
+        'description' => __( 'Whether the item has a free trial period.', 'invoicing' ),
221
+        'type'        => 'integer',
222
+        'enum'        => array( 0, 1 ),
223
+        'context'     => array( 'view', 'edit', 'embed' ),
224
+    ),
225
+
226
+    'trial_period'    => array(
227
+        'description' => __( 'The trial period.', 'invoicing' ),
228
+        'type'        => 'string',
229
+        'context'     => array( 'view', 'edit', 'embed' ),
230
+        'enum'        => array( 'D', 'W', 'M', 'Y' ),
231
+    ),
232
+
233
+    'trial_interval'  => array(
234
+        'description' => __( 'The trial interval.', 'invoicing' ),
235
+        'type'        => 'integer',
236
+        'context'     => array( 'view', 'edit', 'embed' ),
237
+    ),
238
+
239
+    'first_renewal_date'       => array(
240
+        'description' => __( 'The first renewal date in case the item was to be bought today.', 'invoicing' ),
241
+        'type'        => 'string',
242
+        'context'     => array( 'view', 'edit', 'embed' ),
243
+        'readonly'    => true,
244
+    ),
245
+
246
+    'edit_url'        => array(
247
+        'description' => __( 'The URL to edit an item.', 'invoicing' ),
248
+        'type'        => 'string',
249
+        'context'     => array( 'view', 'edit', 'embed' ),
250
+        'readonly'    => true,
251
+    ),
252 252
 );
Please login to merge, or discard this patch.
Spacing   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -9,244 +9,244 @@
 block discarded – undo
9 9
  * @version 1.0.19
10 10
  */
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 return array(
15 15
 
16 16
 	'id'              => array(
17
-		'description' => __( 'Unique identifier for the item.', 'invoicing' ),
17
+		'description' => __('Unique identifier for the item.', 'invoicing'),
18 18
 		'type'        => 'integer',
19
-		'context'     => array( 'view', 'edit', 'embed' ),
19
+		'context'     => array('view', 'edit', 'embed'),
20 20
 		'readonly'    => true,
21 21
 	),
22 22
 
23 23
 	'parent_id'       => array(
24
-		'description' => __( 'Parent item ID.', 'invoicing' ),
24
+		'description' => __('Parent item ID.', 'invoicing'),
25 25
 		'type'        => 'integer',
26
-		'context'     => array( 'view', 'edit', 'embed' ),
26
+		'context'     => array('view', 'edit', 'embed'),
27 27
 		'default'     => 0,
28 28
 	),
29 29
 
30 30
 	'status'          => array(
31
-		'description' => __( 'A named status for the item.', 'invoicing' ),
31
+		'description' => __('A named status for the item.', 'invoicing'),
32 32
 		'type'        => 'string',
33
-		'enum'        => array( 'draft', 'pending', 'publish' ),
34
-		'context'     => array( 'view', 'edit', 'embed' ),
33
+		'enum'        => array('draft', 'pending', 'publish'),
34
+		'context'     => array('view', 'edit', 'embed'),
35 35
 		'default'     => 'draft',
36 36
 	),
37 37
 
38 38
 	'version'         => array(
39
-		'description' => __( 'Plugin version when the item was created.', 'invoicing' ),
39
+		'description' => __('Plugin version when the item was created.', 'invoicing'),
40 40
 		'type'        => 'string',
41
-		'context'     => array( 'view', 'edit' ),
41
+		'context'     => array('view', 'edit'),
42 42
 		'readonly'    => true,
43 43
 	),
44 44
 
45 45
 	'date_created'    => array(
46
-		'description' => __( "The date the item was created, in the site's timezone.", 'invoicing' ),
46
+		'description' => __("The date the item was created, in the site's timezone.", 'invoicing'),
47 47
 		'type'        => 'string',
48
-		'context'     => array( 'view', 'edit', 'embed' ),
48
+		'context'     => array('view', 'edit', 'embed'),
49 49
 	),
50 50
 
51 51
 	'date_created_gmt'    => array(
52
-		'description' => __( 'The GMT date the item was created.', 'invoicing' ),
52
+		'description' => __('The GMT date the item was created.', 'invoicing'),
53 53
 		'type'        => 'string',
54
-		'context'     => array( 'view', 'edit', 'embed' ),
54
+		'context'     => array('view', 'edit', 'embed'),
55 55
 		'readonly'    => true,
56 56
 	),
57 57
 
58 58
 	'date_modified'   => array(
59
-		'description' => __( "The date the item was last modified, in the site's timezone.", 'invoicing' ),
59
+		'description' => __("The date the item was last modified, in the site's timezone.", 'invoicing'),
60 60
 		'type'        => 'string',
61
-		'context'     => array( 'view', 'edit', 'embed' ),
61
+		'context'     => array('view', 'edit', 'embed'),
62 62
 		'readonly'    => true,
63 63
 	),
64 64
 
65 65
 	'date_modified_gmt'    => array(
66
-		'description' => __( 'The GMT date the item was last modified.', 'invoicing' ),
66
+		'description' => __('The GMT date the item was last modified.', 'invoicing'),
67 67
 		'type'        => 'string',
68
-		'context'     => array( 'view', 'edit', 'embed' ),
68
+		'context'     => array('view', 'edit', 'embed'),
69 69
 		'readonly'    => true,
70 70
 	),
71 71
 
72 72
 	'name'			  => array(
73
-		'description' => __( "The item's name.", 'invoicing' ),
73
+		'description' => __("The item's name.", 'invoicing'),
74 74
 		'type'        => 'string',
75
-		'context'     => array( 'view', 'edit', 'embed' ),
75
+		'context'     => array('view', 'edit', 'embed'),
76 76
 		'required'    => true,
77 77
 	),
78 78
 
79 79
 	'description'     => array(
80
-		'description' => __( "The item's description.", 'invoicing' ),
80
+		'description' => __("The item's description.", 'invoicing'),
81 81
 		'type'        => 'string',
82
-		'context'     => array( 'view', 'edit', 'embed' ),
82
+		'context'     => array('view', 'edit', 'embed'),
83 83
 	),
84 84
 
85 85
 	'owner'           => array(
86
-		'description' => __( 'The owner of the item (user id).', 'invoicing' ),
86
+		'description' => __('The owner of the item (user id).', 'invoicing'),
87 87
 		'type'        => 'integer',
88
-		'context'     => array( 'view', 'edit', 'embed' ),
88
+		'context'     => array('view', 'edit', 'embed'),
89 89
 	),
90 90
 
91 91
 	'price'           => array(
92
-		'description' => __( 'The price of the item.', 'invoicing' ),
92
+		'description' => __('The price of the item.', 'invoicing'),
93 93
 		'type'        => 'number',
94
-		'context'     => array( 'view', 'edit', 'embed' ),
94
+		'context'     => array('view', 'edit', 'embed'),
95 95
 		'required'    => true,
96 96
 	),
97 97
 
98 98
 	'the_price'       => array(
99
-		'description' => __( 'The formatted price of the item.', 'invoicing' ),
99
+		'description' => __('The formatted price of the item.', 'invoicing'),
100 100
 		'type'        => 'string',
101
-		'context'     => array( 'view', 'edit', 'embed' ),
101
+		'context'     => array('view', 'edit', 'embed'),
102 102
 		'readonly'    => true,
103 103
 	),
104 104
 
105 105
 	'type'       => array(
106
-		'description' => __( 'The item type.', 'invoicing' ),
106
+		'description' => __('The item type.', 'invoicing'),
107 107
 		'type'        => 'string',
108 108
 		'enum'        => wpinv_item_types(),
109 109
 		'default'     => 'custom',
110
-		'context'     => array( 'view', 'edit', 'embed' ),
110
+		'context'     => array('view', 'edit', 'embed'),
111 111
 	),
112 112
 
113 113
 	'vat_rule'       => array(
114
-		'description' => __( 'VAT rule applied to the item.', 'invoicing' ),
114
+		'description' => __('VAT rule applied to the item.', 'invoicing'),
115 115
 		'type'        => 'string',
116
-		'enum'        => array_keys( getpaid_get_tax_rules() ),
117
-		'context'     => array( 'view', 'edit', 'embed' ),
116
+		'enum'        => array_keys(getpaid_get_tax_rules()),
117
+		'context'     => array('view', 'edit', 'embed'),
118 118
 	),
119 119
 
120 120
 	'vat_class'       => array(
121
-		'description' => __( 'VAT class for the item.', 'invoicing' ),
121
+		'description' => __('VAT class for the item.', 'invoicing'),
122 122
 		'type'        => 'string',
123
-		'context'     => array( 'view', 'edit', 'embed' ),
124
-		'enum'        => array_keys( getpaid_get_tax_classes() ),
123
+		'context'     => array('view', 'edit', 'embed'),
124
+		'enum'        => array_keys(getpaid_get_tax_classes()),
125 125
 	),
126 126
 
127 127
 	'custom_id'       => array(
128
-		'description' => __( 'Custom id for the item.', 'invoicing' ),
128
+		'description' => __('Custom id for the item.', 'invoicing'),
129 129
 		'type'        => 'string',
130
-		'context'     => array( 'view', 'edit', 'embed' ),
130
+		'context'     => array('view', 'edit', 'embed'),
131 131
 	),
132 132
 	
133 133
 	'custom_name'       => array(
134
-		'description' => __( 'Custom name for the item.', 'invoicing' ),
134
+		'description' => __('Custom name for the item.', 'invoicing'),
135 135
 		'type'        => 'string',
136
-		'context'     => array( 'view', 'edit', 'embed' ),
136
+		'context'     => array('view', 'edit', 'embed'),
137 137
 	),
138 138
 
139 139
 	'custom_singular_name'       => array(
140
-		'description' => __( 'Custom singular name for the item.', 'invoicing' ),
140
+		'description' => __('Custom singular name for the item.', 'invoicing'),
141 141
 		'type'        => 'string',
142
-		'context'     => array( 'view', 'edit', 'embed' ),
142
+		'context'     => array('view', 'edit', 'embed'),
143 143
 	),
144 144
 
145 145
 	'is_dynamic_pricing'     => array(
146
-		'description' => __( 'Whether or not customers can enter their own prices when checking out.', 'invoicing' ),
146
+		'description' => __('Whether or not customers can enter their own prices when checking out.', 'invoicing'),
147 147
 		'type'        => 'integer',
148
-		'enum'        => array( 0, 1 ),
149
-		'context'     => array( 'view', 'edit', 'embed' ),
148
+		'enum'        => array(0, 1),
149
+		'context'     => array('view', 'edit', 'embed'),
150 150
 	),
151 151
 
152 152
 	'minimum_price'   => array(
153
-		'description' => __( 'For dynamic prices, this is the minimum price that a user can set.', 'invoicing' ),
153
+		'description' => __('For dynamic prices, this is the minimum price that a user can set.', 'invoicing'),
154 154
 		'type'        => 'number',
155
-		'context'     => array( 'view', 'edit', 'embed' ),
155
+		'context'     => array('view', 'edit', 'embed'),
156 156
 	),
157 157
 
158 158
 	'is_one_time_recurring'        => array(
159
-		'description' => __( 'Whether or not this is a one time subscription item.', 'invoicing' ),
159
+		'description' => __('Whether or not this is a one time subscription item.', 'invoicing'),
160 160
 		'type'        => 'integer',
161
-		'enum'        => array( 0, 1 ),
162
-		'context'     => array( 'view', 'edit', 'embed' ),
161
+		'enum'        => array(0, 1),
162
+		'context'     => array('view', 'edit', 'embed'),
163 163
 	), 
164 164
 
165 165
 	'is_recurring'        => array(
166
-		'description' => __( 'Whether or not this is a subscription item.', 'invoicing' ),
166
+		'description' => __('Whether or not this is a subscription item.', 'invoicing'),
167 167
 		'type'        => 'integer',
168
-		'enum'        => array( 0, 1 ),
169
-		'context'     => array( 'view', 'edit', 'embed' ),
168
+		'enum'        => array(0, 1),
169
+		'context'     => array('view', 'edit', 'embed'),
170 170
 	),
171 171
 
172 172
 	'initial_price'   => array(
173
-		'description' => __( 'The initial price of the item.', 'invoicing' ),
173
+		'description' => __('The initial price of the item.', 'invoicing'),
174 174
 		'type'        => 'number',
175
-		'context'     => array( 'view', 'edit', 'embed' ),
175
+		'context'     => array('view', 'edit', 'embed'),
176 176
 		'readonly'    => true,
177 177
 	),
178 178
 
179 179
 	'the_initial_price'       => array(
180
-		'description' => __( 'The formatted initial price of the item.', 'invoicing' ),
180
+		'description' => __('The formatted initial price of the item.', 'invoicing'),
181 181
 		'type'        => 'string',
182
-		'context'     => array( 'view', 'edit', 'embed' ),
182
+		'context'     => array('view', 'edit', 'embed'),
183 183
 		'readonly'    => true,
184 184
 	),
185 185
 
186 186
 	'recurring_price' => array(
187
-		'description' => __( 'The recurring price of the item.', 'invoicing' ),
187
+		'description' => __('The recurring price of the item.', 'invoicing'),
188 188
 		'type'        => 'number',
189
-		'context'     => array( 'view', 'edit', 'embed' ),
189
+		'context'     => array('view', 'edit', 'embed'),
190 190
 		'readonly'    => true,
191 191
 	),
192 192
 
193 193
 	'the_recurring_price'       => array(
194
-		'description' => __( 'The formatted recurring price of the item.', 'invoicing' ),
194
+		'description' => __('The formatted recurring price of the item.', 'invoicing'),
195 195
 		'type'        => 'string',
196
-		'context'     => array( 'view', 'edit', 'embed' ),
196
+		'context'     => array('view', 'edit', 'embed'),
197 197
 		'readonly'    => true,
198 198
 	),
199 199
 
200 200
 	'recurring_period'        => array(
201
-		'description' => __( 'The recurring period for a recurring item.', 'invoicing' ),
201
+		'description' => __('The recurring period for a recurring item.', 'invoicing'),
202 202
 		'type'        => 'string',
203
-		'context'     => array( 'view', 'edit', 'embed' ),
204
-		'enum'        => array( 'D', 'W', 'M', 'Y' ),
203
+		'context'     => array('view', 'edit', 'embed'),
204
+		'enum'        => array('D', 'W', 'M', 'Y'),
205 205
 	),
206 206
 
207 207
 	'recurring_interval'        => array(
208
-		'description' => __( 'The recurring interval for a subscription item.', 'invoicing' ),
208
+		'description' => __('The recurring interval for a subscription item.', 'invoicing'),
209 209
 		'type'        => 'integer',
210
-		'context'     => array( 'view', 'edit', 'embed' ),
210
+		'context'     => array('view', 'edit', 'embed'),
211 211
 	),
212 212
 
213 213
 	'recurring_limit' => array(
214
-		'description' => __( 'The maximum number of renewals for a subscription item.', 'invoicing' ),
214
+		'description' => __('The maximum number of renewals for a subscription item.', 'invoicing'),
215 215
 		'type'        => 'integer',
216
-		'context'     => array( 'view', 'edit', 'embed' ),
216
+		'context'     => array('view', 'edit', 'embed'),
217 217
 	),
218 218
 
219 219
 	'is_free_trial'   => array(
220
-		'description' => __( 'Whether the item has a free trial period.', 'invoicing' ),
220
+		'description' => __('Whether the item has a free trial period.', 'invoicing'),
221 221
 		'type'        => 'integer',
222
-		'enum'        => array( 0, 1 ),
223
-		'context'     => array( 'view', 'edit', 'embed' ),
222
+		'enum'        => array(0, 1),
223
+		'context'     => array('view', 'edit', 'embed'),
224 224
 	),
225 225
 
226 226
 	'trial_period'    => array(
227
-		'description' => __( 'The trial period.', 'invoicing' ),
227
+		'description' => __('The trial period.', 'invoicing'),
228 228
 		'type'        => 'string',
229
-		'context'     => array( 'view', 'edit', 'embed' ),
230
-		'enum'        => array( 'D', 'W', 'M', 'Y' ),
229
+		'context'     => array('view', 'edit', 'embed'),
230
+		'enum'        => array('D', 'W', 'M', 'Y'),
231 231
 	),
232 232
 
233 233
 	'trial_interval'  => array(
234
-		'description' => __( 'The trial interval.', 'invoicing' ),
234
+		'description' => __('The trial interval.', 'invoicing'),
235 235
 		'type'        => 'integer',
236
-		'context'     => array( 'view', 'edit', 'embed' ),
236
+		'context'     => array('view', 'edit', 'embed'),
237 237
 	),
238 238
 
239 239
 	'first_renewal_date'       => array(
240
-		'description' => __( 'The first renewal date in case the item was to be bought today.', 'invoicing' ),
240
+		'description' => __('The first renewal date in case the item was to be bought today.', 'invoicing'),
241 241
 		'type'        => 'string',
242
-		'context'     => array( 'view', 'edit', 'embed' ),
242
+		'context'     => array('view', 'edit', 'embed'),
243 243
 		'readonly'    => true,
244 244
 	),
245 245
 
246 246
 	'edit_url'        => array(
247
-		'description' => __( 'The URL to edit an item.', 'invoicing' ),
247
+		'description' => __('The URL to edit an item.', 'invoicing'),
248 248
 		'type'        => 'string',
249
-		'context'     => array( 'view', 'edit', 'embed' ),
249
+		'context'     => array('view', 'edit', 'embed'),
250 250
 		'readonly'    => true,
251 251
 	),
252 252
 );
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-item-data-store.php 1 patch
Indentation   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 if ( ! defined( 'ABSPATH' ) ) {
7
-	exit;
7
+    exit;
8 8
 }
9 9
 
10 10
 /**
@@ -14,230 +14,230 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class GetPaid_Item_Data_Store extends GetPaid_Data_Store_WP {
16 16
 
17
-	/**
18
-	 * Data stored in meta keys, but not considered "meta" for an item.
19
-	 *
20
-	 * @since 1.0.19
21
-	 * @var array
22
-	 */
23
-	protected $internal_meta_keys = array(
24
-		'_wpinv_price',
25
-		'_wpinv_vat_rule',
26
-		'_wpinv_vat_class',
27
-		'_wpinv_type',
28
-		'_wpinv_custom_id',
29
-		'_wpinv_custom_name',
30
-		'_wpinv_custom_singular_name',
31
-		'_wpinv_editable',
32
-		'_wpinv_dynamic_pricing',
33
-		'_minimum_price',  
34
-		'_wpinv_is_recurring',
35
-		'_wpinv_is_one_time_recurring',
36
-		'_wpinv_recurring_period',
37
-		'_wpinv_recurring_interval',
38
-		'_wpinv_recurring_limit', 
39
-		'_wpinv_free_trial',
40
-		'_wpinv_trial_period',
41
-		'_wpinv_trial_interval'
42
-	);
43
-
44
-	/**
45
-	 * A map of meta keys to data props.
46
-	 *
47
-	 * @since 1.0.19
48
-	 *
49
-	 * @var array
50
-	 */
51
-	protected $meta_key_to_props = array(
52
-		'_wpinv_price'                => 'price',
53
-		'_wpinv_vat_rule'             => 'vat_rule',
54
-		'_wpinv_vat_class'            => 'vat_class',
55
-		'_wpinv_type'                 => 'type',
56
-		'_wpinv_custom_id'            => 'custom_id',
57
-		'_wpinv_custom_name'          => 'custom_name',
58
-		'_wpinv_custom_singular_name' => 'custom_singular_name',
59
-		'_wpinv_editable'             => 'is_editable',
60
-		'_wpinv_dynamic_pricing'      => 'is_dynamic_pricing',
61
-		'_minimum_price'              => 'minimum_price',
62
-		'_wpinv_custom_name'          => 'custom_name',
63
-		'_wpinv_is_recurring'         => 'is_recurring',
64
-		'_wpinv_is_one_time_recurring'=> 'is_one_time_recurring',
65
-		'_wpinv_recurring_period'     => 'recurring_period',
66
-		'_wpinv_recurring_interval'   => 'recurring_interval',
67
-		'_wpinv_recurring_limit'      => 'recurring_limit',
68
-		'_wpinv_free_trial'           => 'is_free_trial',
69
-		'_wpinv_trial_period'         => 'trial_period',
70
-		'_wpinv_trial_interval'       => 'trial_interval',
71
-		'_wpinv_version'              => 'version',
72
-	);
73
-
74
-	/*
17
+    /**
18
+     * Data stored in meta keys, but not considered "meta" for an item.
19
+     *
20
+     * @since 1.0.19
21
+     * @var array
22
+     */
23
+    protected $internal_meta_keys = array(
24
+        '_wpinv_price',
25
+        '_wpinv_vat_rule',
26
+        '_wpinv_vat_class',
27
+        '_wpinv_type',
28
+        '_wpinv_custom_id',
29
+        '_wpinv_custom_name',
30
+        '_wpinv_custom_singular_name',
31
+        '_wpinv_editable',
32
+        '_wpinv_dynamic_pricing',
33
+        '_minimum_price',  
34
+        '_wpinv_is_recurring',
35
+        '_wpinv_is_one_time_recurring',
36
+        '_wpinv_recurring_period',
37
+        '_wpinv_recurring_interval',
38
+        '_wpinv_recurring_limit', 
39
+        '_wpinv_free_trial',
40
+        '_wpinv_trial_period',
41
+        '_wpinv_trial_interval'
42
+    );
43
+
44
+    /**
45
+     * A map of meta keys to data props.
46
+     *
47
+     * @since 1.0.19
48
+     *
49
+     * @var array
50
+     */
51
+    protected $meta_key_to_props = array(
52
+        '_wpinv_price'                => 'price',
53
+        '_wpinv_vat_rule'             => 'vat_rule',
54
+        '_wpinv_vat_class'            => 'vat_class',
55
+        '_wpinv_type'                 => 'type',
56
+        '_wpinv_custom_id'            => 'custom_id',
57
+        '_wpinv_custom_name'          => 'custom_name',
58
+        '_wpinv_custom_singular_name' => 'custom_singular_name',
59
+        '_wpinv_editable'             => 'is_editable',
60
+        '_wpinv_dynamic_pricing'      => 'is_dynamic_pricing',
61
+        '_minimum_price'              => 'minimum_price',
62
+        '_wpinv_custom_name'          => 'custom_name',
63
+        '_wpinv_is_recurring'         => 'is_recurring',
64
+        '_wpinv_is_one_time_recurring'=> 'is_one_time_recurring',
65
+        '_wpinv_recurring_period'     => 'recurring_period',
66
+        '_wpinv_recurring_interval'   => 'recurring_interval',
67
+        '_wpinv_recurring_limit'      => 'recurring_limit',
68
+        '_wpinv_free_trial'           => 'is_free_trial',
69
+        '_wpinv_trial_period'         => 'trial_period',
70
+        '_wpinv_trial_interval'       => 'trial_interval',
71
+        '_wpinv_version'              => 'version',
72
+    );
73
+
74
+    /*
75 75
 	|--------------------------------------------------------------------------
76 76
 	| CRUD Methods
77 77
 	|--------------------------------------------------------------------------
78 78
 	*/
79 79
 
80
-	/**
81
-	 * Method to create a new item in the database.
82
-	 *
83
-	 * @param WPInv_Item $item Item object.
84
-	 */
85
-	public function create( &$item ) {
86
-		$item->set_version( WPINV_VERSION );
87
-		$item->set_date_created( current_time('mysql') );
88
-
89
-		// Create a new post.
90
-		$id = wp_insert_post(
91
-			apply_filters(
92
-				'getpaid_new_item_data',
93
-				array(
94
-					'post_date'     => $item->get_date_created( 'edit' ),
95
-					'post_type'     => 'wpi_item',
96
-					'post_status'   => $this->get_post_status( $item ),
97
-					'ping_status'   => 'closed',
98
-					'post_author'   => $item->get_author( 'edit' ),
99
-					'post_title'    => $item->get_name( 'edit' ),
100
-					'post_parent'   => 0,
101
-					'post_excerpt'  => $item->get_description( 'edit' ),
102
-				)
103
-			),
104
-			true
105
-		);
106
-
107
-		if ( $id && ! is_wp_error( $id ) ) {
108
-			$item->set_id( $id );
109
-			$this->update_post_meta( $item );
110
-			$item->save_meta_data();
111
-			$item->apply_changes();
112
-			$this->clear_caches( $item );
113
-			do_action( 'getpaid_new_item', $item );
114
-			return true;
115
-		}
116
-
117
-		if ( is_wp_error( $id ) ) {
118
-			$item->last_error = $id->get_error_message();
119
-		}
80
+    /**
81
+     * Method to create a new item in the database.
82
+     *
83
+     * @param WPInv_Item $item Item object.
84
+     */
85
+    public function create( &$item ) {
86
+        $item->set_version( WPINV_VERSION );
87
+        $item->set_date_created( current_time('mysql') );
88
+
89
+        // Create a new post.
90
+        $id = wp_insert_post(
91
+            apply_filters(
92
+                'getpaid_new_item_data',
93
+                array(
94
+                    'post_date'     => $item->get_date_created( 'edit' ),
95
+                    'post_type'     => 'wpi_item',
96
+                    'post_status'   => $this->get_post_status( $item ),
97
+                    'ping_status'   => 'closed',
98
+                    'post_author'   => $item->get_author( 'edit' ),
99
+                    'post_title'    => $item->get_name( 'edit' ),
100
+                    'post_parent'   => 0,
101
+                    'post_excerpt'  => $item->get_description( 'edit' ),
102
+                )
103
+            ),
104
+            true
105
+        );
106
+
107
+        if ( $id && ! is_wp_error( $id ) ) {
108
+            $item->set_id( $id );
109
+            $this->update_post_meta( $item );
110
+            $item->save_meta_data();
111
+            $item->apply_changes();
112
+            $this->clear_caches( $item );
113
+            do_action( 'getpaid_new_item', $item );
114
+            return true;
115
+        }
116
+
117
+        if ( is_wp_error( $id ) ) {
118
+            $item->last_error = $id->get_error_message();
119
+        }
120 120
 		
121
-		return false;
122
-	}
123
-
124
-	/**
125
-	 * Method to read an item from the database.
126
-	 *
127
-	 * @param WPInv_Item $item Item object.
128
-	 *
129
-	 */
130
-	public function read( &$item ) {
131
-
132
-		$item->set_defaults();
133
-		$item_object = get_post( $item->get_id() );
134
-
135
-		if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) {
136
-			$item->last_error = __( 'Invalid item.', 'invoicing' );
137
-			$item->set_id( 0 );
138
-			return false;
139
-		}
140
-
141
-		$item->set_props(
142
-			array(
143
-				'parent_id'     => $item_object->post_parent,
144
-				'date_created'  => 0 < $item_object->post_date ? $item_object->post_date : null,
145
-				'date_modified' => 0 < $item_object->post_modified ? $item_object->post_modified : null,
146
-				'status'        => $item_object->post_status,
147
-				'name'          => $item_object->post_title,
148
-				'description'   => $item_object->post_excerpt,
149
-				'author'        => $item_object->post_author,
150
-			)
151
-		);
152
-
153
-		$this->read_object_data( $item, $item_object );
154
-		$item->read_meta_data();
155
-		$item->set_object_read( true );
156
-		do_action( 'getpaid_read_item', $item );
157
-
158
-	}
159
-
160
-	/**
161
-	 * Method to update an item in the database.
162
-	 *
163
-	 * @param WPInv_Item $item Item object.
164
-	 */
165
-	public function update( &$item ) {
166
-		$item->save_meta_data();
167
-		$item->set_version( WPINV_VERSION );
168
-
169
-		if ( null === $item->get_date_created( 'edit' ) ) {
170
-			$item->set_date_created(  current_time('mysql') );
171
-		}
172
-
173
-		// Grab the current status so we can compare.
174
-		$previous_status = get_post_status( $item->get_id() );
175
-
176
-		$changes = $item->get_changes();
177
-
178
-		// Only update the post when the post data changes.
179
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'description', 'name', 'author' ), array_keys( $changes ) ) ) {
180
-			$post_data = array(
181
-				'post_date'         => $item->get_date_created( 'edit' ),
182
-				'post_status'       => $item->get_status( 'edit' ),
183
-				'post_parent'       => $item->get_parent_id( 'edit' ),
184
-				'post_excerpt'      => $item->get_description( 'edit' ),
185
-				'post_modified'     => $item->get_date_modified( 'edit' ),
186
-				'post_title'        => $item->get_name( 'edit' ),
187
-				'post_author'       => $item->get_author( 'edit' ),
188
-			);
189
-
190
-			/**
191
-			 * When updating this object, to prevent infinite loops, use $wpdb
192
-			 * to update data, since wp_update_post spawns more calls to the
193
-			 * save_post action.
194
-			 *
195
-			 * This ensures hooks are fired by either WP itself (admin screen save),
196
-			 * or an update purely from CRUD.
197
-			 */
198
-			if ( doing_action( 'save_post' ) ) {
199
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) );
200
-				clean_post_cache( $item->get_id() );
201
-			} else {
202
-				wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) );
203
-			}
204
-			$item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
205
-		}
206
-		$this->update_post_meta( $item );
207
-		$item->apply_changes();
208
-		$this->clear_caches( $item );
209
-
210
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
211
-		$new_status = $item->get_status( 'edit' );
212
-
213
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
214
-			do_action( 'getpaid_new_item', $item );
215
-		} else {
216
-			do_action( 'getpaid_update_item', $item );
217
-		}
218
-
219
-	}
220
-
221
-	/*
121
+        return false;
122
+    }
123
+
124
+    /**
125
+     * Method to read an item from the database.
126
+     *
127
+     * @param WPInv_Item $item Item object.
128
+     *
129
+     */
130
+    public function read( &$item ) {
131
+
132
+        $item->set_defaults();
133
+        $item_object = get_post( $item->get_id() );
134
+
135
+        if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) {
136
+            $item->last_error = __( 'Invalid item.', 'invoicing' );
137
+            $item->set_id( 0 );
138
+            return false;
139
+        }
140
+
141
+        $item->set_props(
142
+            array(
143
+                'parent_id'     => $item_object->post_parent,
144
+                'date_created'  => 0 < $item_object->post_date ? $item_object->post_date : null,
145
+                'date_modified' => 0 < $item_object->post_modified ? $item_object->post_modified : null,
146
+                'status'        => $item_object->post_status,
147
+                'name'          => $item_object->post_title,
148
+                'description'   => $item_object->post_excerpt,
149
+                'author'        => $item_object->post_author,
150
+            )
151
+        );
152
+
153
+        $this->read_object_data( $item, $item_object );
154
+        $item->read_meta_data();
155
+        $item->set_object_read( true );
156
+        do_action( 'getpaid_read_item', $item );
157
+
158
+    }
159
+
160
+    /**
161
+     * Method to update an item in the database.
162
+     *
163
+     * @param WPInv_Item $item Item object.
164
+     */
165
+    public function update( &$item ) {
166
+        $item->save_meta_data();
167
+        $item->set_version( WPINV_VERSION );
168
+
169
+        if ( null === $item->get_date_created( 'edit' ) ) {
170
+            $item->set_date_created(  current_time('mysql') );
171
+        }
172
+
173
+        // Grab the current status so we can compare.
174
+        $previous_status = get_post_status( $item->get_id() );
175
+
176
+        $changes = $item->get_changes();
177
+
178
+        // Only update the post when the post data changes.
179
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'description', 'name', 'author' ), array_keys( $changes ) ) ) {
180
+            $post_data = array(
181
+                'post_date'         => $item->get_date_created( 'edit' ),
182
+                'post_status'       => $item->get_status( 'edit' ),
183
+                'post_parent'       => $item->get_parent_id( 'edit' ),
184
+                'post_excerpt'      => $item->get_description( 'edit' ),
185
+                'post_modified'     => $item->get_date_modified( 'edit' ),
186
+                'post_title'        => $item->get_name( 'edit' ),
187
+                'post_author'       => $item->get_author( 'edit' ),
188
+            );
189
+
190
+            /**
191
+             * When updating this object, to prevent infinite loops, use $wpdb
192
+             * to update data, since wp_update_post spawns more calls to the
193
+             * save_post action.
194
+             *
195
+             * This ensures hooks are fired by either WP itself (admin screen save),
196
+             * or an update purely from CRUD.
197
+             */
198
+            if ( doing_action( 'save_post' ) ) {
199
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) );
200
+                clean_post_cache( $item->get_id() );
201
+            } else {
202
+                wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) );
203
+            }
204
+            $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
205
+        }
206
+        $this->update_post_meta( $item );
207
+        $item->apply_changes();
208
+        $this->clear_caches( $item );
209
+
210
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
211
+        $new_status = $item->get_status( 'edit' );
212
+
213
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
214
+            do_action( 'getpaid_new_item', $item );
215
+        } else {
216
+            do_action( 'getpaid_update_item', $item );
217
+        }
218
+
219
+    }
220
+
221
+    /*
222 222
 	|--------------------------------------------------------------------------
223 223
 	| Additional Methods
224 224
 	|--------------------------------------------------------------------------
225 225
 	*/
226 226
 
227
-	/**
228
-	 * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class.
229
-	 *
230
-	 * @param WPInv_Item $item WPInv_Item object.
231
-	 * @since 1.0.19
232
-	 */
233
-	protected function update_post_meta( &$item ) {
227
+    /**
228
+     * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class.
229
+     *
230
+     * @param WPInv_Item $item WPInv_Item object.
231
+     * @since 1.0.19
232
+     */
233
+    protected function update_post_meta( &$item ) {
234 234
 
235
-		// Ensure that we have a custom id.
235
+        // Ensure that we have a custom id.
236 236
         if ( ! $item->get_custom_id() ) {
237 237
             $item->set_custom_id( $item->get_id() );
238
-		}
238
+        }
239 239
 
240
-		parent::update_post_meta( $item );
241
-	}
240
+        parent::update_post_meta( $item );
241
+    }
242 242
 
243 243
 }
Please login to merge, or discard this patch.