Passed
Push — master ( bb5579...999429 )
by Brian
04:56
created
includes/wpinv-item-functions.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -411,9 +411,9 @@
 block discarded – undo
411 411
     $bill_times      = $item->get_recurring_limit();
412 412
 
413 413
     if ( ! empty( $bill_times ) ) {
414
-		$bill_times = $item->get_recurring_interval() * $bill_times;
415
-		$bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times );
416
-	}
414
+        $bill_times = $item->get_recurring_interval() * $bill_times;
415
+        $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times );
416
+    }
417 417
 
418 418
     if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) {
419 419
         $initial_price   = wpinv_price( $item->get_sub_total(), $currency );
Please login to merge, or discard this patch.
Spacing   +131 added lines, -131 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 an item by it's ID.
@@ -14,9 +14,9 @@  discard block
 block discarded – undo
14 14
  * @param int the item ID to retrieve.
15 15
  * @return WPInv_Item|false
16 16
  */
17
-function wpinv_get_item_by_id( $id ) {
18
-    $item = wpinv_get_item( $id );
19
-    return empty( $item ) || $id != $item->get_id() ? false : $item;
17
+function wpinv_get_item_by_id($id) {
18
+    $item = wpinv_get_item($id);
19
+    return empty($item) || $id != $item->get_id() ? false : $item;
20 20
 }
21 21
 
22 22
 /**
@@ -24,14 +24,14 @@  discard block
 block discarded – undo
24 24
  *
25 25
  * @return WPInv_Item|false
26 26
  */
27
-function wpinv_get_item_by( $field = '', $value = '', $type = '' ) {
27
+function wpinv_get_item_by($field = '', $value = '', $type = '') {
28 28
 
29
-    if ( 'id' == strtolower( $field ) ) {
30
-        return wpinv_get_item_by_id( $field );
29
+    if ('id' == strtolower($field)) {
30
+        return wpinv_get_item_by_id($field);
31 31
     }
32 32
 
33
-    $id = WPInv_Item::get_item_id_by_field( $value, strtolower( $field ), $type );
34
-    return empty( $id ) ? false : wpinv_get_item( $id );
33
+    $id = WPInv_Item::get_item_id_by_field($value, strtolower($field), $type);
34
+    return empty($id) ? false : wpinv_get_item($id);
35 35
 
36 36
 }
37 37
 
@@ -41,22 +41,22 @@  discard block
 block discarded – undo
41 41
  * @param int|WPInv_Item the item to retrieve.
42 42
  * @return WPInv_Item|false
43 43
  */
44
-function wpinv_get_item( $item = 0 ) {
44
+function wpinv_get_item($item = 0) {
45 45
 
46
-    if ( empty( $item ) ) {
46
+    if (empty($item)) {
47 47
         return false;
48 48
     }
49 49
 
50
-    $item = new WPInv_Item( $item );
50
+    $item = new WPInv_Item($item);
51 51
     return $item->exists() ? $item : false;
52 52
 
53 53
 }
54 54
 
55
-function wpinv_get_all_items( $args = array() ) {
55
+function wpinv_get_all_items($args = array()) {
56 56
 
57
-    $args = wp_parse_args( $args, array(
58
-        'status'         => array( 'publish' ),
59
-        'limit'          => get_option( 'posts_per_page' ),
57
+    $args = wp_parse_args($args, array(
58
+        'status'         => array('publish'),
59
+        'limit'          => get_option('posts_per_page'),
60 60
         'page'           => 1,
61 61
         'exclude'        => array(),
62 62
         'orderby'        => 'date',
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
         'meta_query'     => array(),
66 66
         'return'         => 'objects',
67 67
         'paginate'       => false,
68
-    ) );
68
+    ));
69 69
 
70 70
     $wp_query_args = array(
71 71
         'post_type'      => 'wpi_item',
@@ -75,26 +75,26 @@  discard block
 block discarded – undo
75 75
         'fields'         => 'ids',
76 76
         'orderby'        => $args['orderby'],
77 77
         'order'          => $args['order'],
78
-        'paged'          => absint( $args['page'] ),
78
+        'paged'          => absint($args['page']),
79 79
     );
80 80
 
81
-    if ( ! empty( $args['exclude'] ) ) {
82
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
81
+    if (!empty($args['exclude'])) {
82
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
83 83
     }
84 84
 
85
-    if ( ! $args['paginate' ] ) {
85
+    if (!$args['paginate']) {
86 86
         $wp_query_args['no_found_rows'] = true;
87 87
     }
88 88
 
89
-    if ( ! empty( $args['search'] ) ) {
89
+    if (!empty($args['search'])) {
90 90
         $wp_query_args['s'] = $args['search'];
91 91
     }
92 92
 
93
-    if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) {
94
-        $types = wpinv_parse_list( $args['type'] );
93
+    if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) {
94
+        $types = wpinv_parse_list($args['type']);
95 95
         $wp_query_args['meta_query'][] = array(
96 96
             'key'     => '_wpinv_type',
97
-            'value'   => implode( ',', $types ),
97
+            'value'   => implode(',', $types),
98 98
             'compare' => 'IN',
99 99
         );
100 100
     }
@@ -102,17 +102,17 @@  discard block
 block discarded – undo
102 102
     $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args);
103 103
 
104 104
     // Get results.
105
-    $items = new WP_Query( $wp_query_args );
105
+    $items = new WP_Query($wp_query_args);
106 106
 
107
-    if ( 'objects' === $args['return'] ) {
108
-        $return = array_map( 'wpinv_get_item_by_id', $items->posts );
109
-    } elseif ( 'self' === $args['return'] ) {
107
+    if ('objects' === $args['return']) {
108
+        $return = array_map('wpinv_get_item_by_id', $items->posts);
109
+    } elseif ('self' === $args['return']) {
110 110
         return $items;
111 111
     } else {
112 112
         $return = $items->posts;
113 113
     }
114 114
 
115
-    if ( $args['paginate' ] ) {
115
+    if ($args['paginate']) {
116 116
         return (object) array(
117 117
             'items'      => $return,
118 118
             'total'         => $items->found_posts,
@@ -124,12 +124,12 @@  discard block
 block discarded – undo
124 124
 
125 125
 }
126 126
 
127
-function wpinv_is_free_item( $item_id = 0 ) {
128
-    if( empty( $item_id ) ) {
127
+function wpinv_is_free_item($item_id = 0) {
128
+    if (empty($item_id)) {
129 129
         return false;
130 130
     }
131 131
 
132
-    $item = new WPInv_Item( $item_id );
132
+    $item = new WPInv_Item($item_id);
133 133
 
134 134
     return $item->is_free();
135 135
 }
@@ -139,21 +139,21 @@  discard block
 block discarded – undo
139 139
  *
140 140
  * @param WP_Post|WPInv_Item|Int $item The item to check for.
141 141
  */
142
-function wpinv_item_is_editable( $item = 0 ) {
142
+function wpinv_item_is_editable($item = 0) {
143 143
 
144 144
     // Fetch the item.
145
-    $item = new WPInv_Item( $item );
145
+    $item = new WPInv_Item($item);
146 146
 
147 147
     // Check if it is editable.
148 148
     return $item->is_editable();
149 149
 }
150 150
 
151
-function wpinv_get_item_price( $item_id = 0 ) {
152
-    if( empty( $item_id ) ) {
151
+function wpinv_get_item_price($item_id = 0) {
152
+    if (empty($item_id)) {
153 153
         return false;
154 154
     }
155 155
 
156
-    $item = new WPInv_Item( $item_id );
156
+    $item = new WPInv_Item($item_id);
157 157
 
158 158
     return $item->get_price();
159 159
 }
@@ -163,96 +163,96 @@  discard block
 block discarded – undo
163 163
  *
164 164
  * @param WPInv_Item|int $item
165 165
  */
166
-function wpinv_is_recurring_item( $item = 0 ) {
167
-    $item = new WPInv_Item( $item );
166
+function wpinv_is_recurring_item($item = 0) {
167
+    $item = new WPInv_Item($item);
168 168
     return $item->is_recurring();
169 169
 }
170 170
 
171
-function wpinv_item_price( $item_id = 0 ) {
172
-    if( empty( $item_id ) ) {
171
+function wpinv_item_price($item_id = 0) {
172
+    if (empty($item_id)) {
173 173
         return false;
174 174
     }
175 175
 
176
-    $price = wpinv_get_item_price( $item_id );
177
-    $price = wpinv_price( $price );
176
+    $price = wpinv_get_item_price($item_id);
177
+    $price = wpinv_price($price);
178 178
 
179
-    return apply_filters( 'wpinv_item_price', $price, $item_id );
179
+    return apply_filters('wpinv_item_price', $price, $item_id);
180 180
 }
181 181
 
182
-function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) {
183
-    if ( is_null( $amount_override ) ) {
184
-        $original_price = get_post_meta( $item_id, '_wpinv_price', true );
182
+function wpinv_get_item_final_price($item_id = 0, $amount_override = null) {
183
+    if (is_null($amount_override)) {
184
+        $original_price = get_post_meta($item_id, '_wpinv_price', true);
185 185
     } else {
186 186
         $original_price = $amount_override;
187 187
     }
188 188
 
189 189
     $price = $original_price;
190 190
 
191
-    return apply_filters( 'wpinv_get_item_final_price', $price, $item_id );
191
+    return apply_filters('wpinv_get_item_final_price', $price, $item_id);
192 192
 }
193 193
 
194
-function wpinv_item_custom_singular_name( $item_id ) {
195
-    if( empty( $item_id ) ) {
194
+function wpinv_item_custom_singular_name($item_id) {
195
+    if (empty($item_id)) {
196 196
         return false;
197 197
     }
198 198
 
199
-    $item = new WPInv_Item( $item_id );
199
+    $item = new WPInv_Item($item_id);
200 200
 
201 201
     return $item->get_custom_singular_name();
202 202
 }
203 203
 
204 204
 function wpinv_get_item_types() {
205 205
     $item_types = array(
206
-            'custom'    => __( 'Standard', 'invoicing' ),
207
-            'fee'       => __( 'Fee', 'invoicing' ),
206
+            'custom'    => __('Standard', 'invoicing'),
207
+            'fee'       => __('Fee', 'invoicing'),
208 208
         );
209
-    return apply_filters( 'wpinv_get_item_types', $item_types );
209
+    return apply_filters('wpinv_get_item_types', $item_types);
210 210
 }
211 211
 
212 212
 function wpinv_item_types() {
213 213
     $item_types = wpinv_get_item_types();
214 214
 
215
-    return ( !empty( $item_types ) ? array_keys( $item_types ) : array() );
215
+    return (!empty($item_types) ? array_keys($item_types) : array());
216 216
 }
217 217
 
218
-function wpinv_get_item_type( $item_id ) {
219
-    if( empty( $item_id ) ) {
218
+function wpinv_get_item_type($item_id) {
219
+    if (empty($item_id)) {
220 220
         return false;
221 221
     }
222 222
 
223
-    $item = new WPInv_Item( $item_id );
223
+    $item = new WPInv_Item($item_id);
224 224
 
225 225
     return $item->get_type();
226 226
 }
227 227
 
228
-function wpinv_item_type( $item_id ) {
228
+function wpinv_item_type($item_id) {
229 229
     $item_types = wpinv_get_item_types();
230 230
 
231
-    $item_type = wpinv_get_item_type( $item_id );
231
+    $item_type = wpinv_get_item_type($item_id);
232 232
 
233
-    if ( empty( $item_type ) ) {
233
+    if (empty($item_type)) {
234 234
         $item_type = '-';
235 235
     }
236 236
 
237
-    $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' );
237
+    $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing');
238 238
 
239
-    return apply_filters( 'wpinv_item_type', $item_type, $item_id );
239
+    return apply_filters('wpinv_item_type', $item_type, $item_id);
240 240
 }
241 241
 
242
-function wpinv_get_random_item( $post_ids = true ) {
243
-    wpinv_get_random_items( 1, $post_ids );
242
+function wpinv_get_random_item($post_ids = true) {
243
+    wpinv_get_random_items(1, $post_ids);
244 244
 }
245 245
 
246
-function wpinv_get_random_items( $num = 3, $post_ids = true ) {
247
-    if ( $post_ids ) {
248
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' );
246
+function wpinv_get_random_items($num = 3, $post_ids = true) {
247
+    if ($post_ids) {
248
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids');
249 249
     } else {
250
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num );
250
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num);
251 251
     }
252 252
 
253
-    $args  = apply_filters( 'wpinv_get_random_items', $args );
253
+    $args = apply_filters('wpinv_get_random_items', $args);
254 254
 
255
-    return get_posts( $args );
255
+    return get_posts($args);
256 256
 }
257 257
 
258 258
 /**
@@ -261,13 +261,13 @@  discard block
 block discarded – undo
261 261
  * @param WPInv_Item|int $item
262 262
  * @param bool $html
263 263
  */
264
-function wpinv_get_item_suffix( $item, $html = true ) {
264
+function wpinv_get_item_suffix($item, $html = true) {
265 265
 
266
-    $item   = new WPInv_Item( $item );
267
-    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '';
268
-    $suffix = $html ? $suffix : strip_tags( $suffix );
266
+    $item   = new WPInv_Item($item);
267
+    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '';
268
+    $suffix = $html ? $suffix : strip_tags($suffix);
269 269
 
270
-    return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html );
270
+    return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html);
271 271
 }
272 272
 
273 273
 /**
@@ -276,9 +276,9 @@  discard block
 block discarded – undo
276 276
  * @param WPInv_Item|int $item
277 277
  * @param bool $force_delete
278 278
  */
279
-function wpinv_remove_item( $item = 0, $force_delete = false ) {
280
-    $item = new WPInv_Item( $item );
281
-    $item->delete( $force_delete );
279
+function wpinv_remove_item($item = 0, $force_delete = false) {
280
+    $item = new WPInv_Item($item);
281
+    $item->delete($force_delete);
282 282
 }
283 283
 
284 284
 /**
@@ -317,45 +317,45 @@  discard block
 block discarded – undo
317 317
  * @param bool $wp_error whether or not to return a WP_Error on failure.
318 318
  * @return bool|WP_Error|WPInv_Item
319 319
  */
320
-function wpinv_create_item( $args = array(), $wp_error = false ) {
320
+function wpinv_create_item($args = array(), $wp_error = false) {
321 321
 
322 322
     // Prepare the item.
323
-    if ( ! empty( $args['custom_id'] ) && empty( $args['ID'] ) ) {
324
-        $type = empty( $args['type'] ) ? 'custom' : $args['type'];
325
-        $item = wpinv_get_item_by( 'custom_id', $args['custom_id'], $type );
323
+    if (!empty($args['custom_id']) && empty($args['ID'])) {
324
+        $type = empty($args['type']) ? 'custom' : $args['type'];
325
+        $item = wpinv_get_item_by('custom_id', $args['custom_id'], $type);
326 326
 
327
-        if ( ! empty( $item ) ) {
327
+        if (!empty($item)) {
328 328
             $args['ID'] = $item->get_id();
329 329
         }
330 330
 
331 331
     }
332 332
 
333 333
     // Do we have an item?
334
-    if ( ! empty( $args['ID'] ) ) {
335
-        $item = new WPInv_Item( $args['ID'] );
334
+    if (!empty($args['ID'])) {
335
+        $item = new WPInv_Item($args['ID']);
336 336
     } else {
337 337
         $item = new WPInv_Item();
338 338
     }
339 339
 
340 340
     // Do we have an error?
341
-    if ( ! empty( $item->last_error ) ) {
342
-        return $wp_error ? new WP_Error( 'invalid_item', $item->last_error ) : false;
341
+    if (!empty($item->last_error)) {
342
+        return $wp_error ? new WP_Error('invalid_item', $item->last_error) : false;
343 343
     }
344 344
 
345 345
     // Update item props.
346
-    $item->set_props( $args );
346
+    $item->set_props($args);
347 347
 
348 348
     // Save the item.
349 349
     $item->save();
350 350
 
351 351
     // Do we have an error?
352
-    if ( ! empty( $item->last_error ) ) {
353
-        return $wp_error ? new WP_Error( 'not_saved', $item->last_error ) : false;
352
+    if (!empty($item->last_error)) {
353
+        return $wp_error ? new WP_Error('not_saved', $item->last_error) : false;
354 354
     }
355 355
 
356 356
     // Was the item saved?
357
-    if ( ! $item->get_id() ) {
358
-        return $wp_error ? new WP_Error( 'not_saved', __( 'An error occured while saving the item', 'invoicing' ) ) : false;
357
+    if (!$item->get_id()) {
358
+        return $wp_error ? new WP_Error('not_saved', __('An error occured while saving the item', 'invoicing')) : false;
359 359
     }
360 360
 
361 361
     return $item;
@@ -367,14 +367,14 @@  discard block
 block discarded – undo
367 367
  *
368 368
  * @see wpinv_create_item()
369 369
  */
370
-function wpinv_update_item( $args = array(), $wp_error = false ) {
371
-    return wpinv_create_item( $args, $wp_error );
370
+function wpinv_update_item($args = array(), $wp_error = false) {
371
+    return wpinv_create_item($args, $wp_error);
372 372
 }
373 373
 
374 374
 /**
375 375
  * Sanitizes a recurring period
376 376
  */
377
-function getpaid_sanitize_recurring_period( $period, $full = false ) {
377
+function getpaid_sanitize_recurring_period($period, $full = false) {
378 378
 
379 379
     $periods = array(
380 380
         'D' => 'day',
@@ -383,11 +383,11 @@  discard block
 block discarded – undo
383 383
         'Y' => 'year',
384 384
     );
385 385
 
386
-    if ( ! isset( $periods[ $period ] ) ) {
386
+    if (!isset($periods[$period])) {
387 387
         $period = 'D';
388 388
     }
389 389
 
390
-    return $full ? $periods[ $period ] : $period;
390
+    return $full ? $periods[$period] : $period;
391 391
 
392 392
 }
393 393
 
@@ -396,46 +396,46 @@  discard block
 block discarded – undo
396 396
  *
397 397
  * @param WPInv_Item|GetPaid_Form_Item $item
398 398
  */
399
-function getpaid_item_recurring_price_help_text( $item, $currency = '', $_initial_price = false, $_recurring_price = false ) {
399
+function getpaid_item_recurring_price_help_text($item, $currency = '', $_initial_price = false, $_recurring_price = false) {
400 400
 
401 401
     // Abort if it is not recurring.
402
-    if ( ! $item->is_recurring() ) {
402
+    if (!$item->is_recurring()) {
403 403
         return '';
404 404
     }
405 405
 
406
-    $initial_price   = false === $_initial_price ? wpinv_price( $item->get_initial_price(), $currency ) : $_initial_price;
407
-    $recurring_price = false === $_recurring_price ? wpinv_price( $item->get_recurring_price(), $currency ) : $_recurring_price;
408
-    $period          = getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' );
406
+    $initial_price   = false === $_initial_price ? wpinv_price($item->get_initial_price(), $currency) : $_initial_price;
407
+    $recurring_price = false === $_recurring_price ? wpinv_price($item->get_recurring_price(), $currency) : $_recurring_price;
408
+    $period          = getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), '');
409 409
     $initial_class   = 'getpaid-item-initial-price';
410 410
     $recurring_class = 'getpaid-item-recurring-price';
411 411
     $bill_times      = $item->get_recurring_limit();
412 412
 
413
-    if ( ! empty( $bill_times ) ) {
413
+    if (!empty($bill_times)) {
414 414
 		$bill_times = $item->get_recurring_interval() * $bill_times;
415
-		$bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times );
415
+		$bill_times = getpaid_get_subscription_period_label($item->get_recurring_period(), $bill_times);
416 416
 	}
417 417
 
418
-    if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) {
419
-        $initial_price   = wpinv_price( $item->get_sub_total(), $currency );
420
-        $recurring_price = wpinv_price( $item->get_recurring_sub_total(), $currency );
418
+    if ($item instanceof GetPaid_Form_Item && false === $_initial_price) {
419
+        $initial_price   = wpinv_price($item->get_sub_total(), $currency);
420
+        $recurring_price = wpinv_price($item->get_recurring_sub_total(), $currency);
421 421
     }
422 422
 
423
-    if ( wpinv_price( 0, $currency ) == $initial_price && wpinv_price( 0, $currency ) == $recurring_price ) {
424
-        return __( 'Free forever', 'invoicing' );
423
+    if (wpinv_price(0, $currency) == $initial_price && wpinv_price(0, $currency) == $recurring_price) {
424
+        return __('Free forever', 'invoicing');
425 425
     }
426 426
 
427 427
     // For free trial items.
428
-    if ( $item->has_free_trial() ) {
429
-        $trial_period = getpaid_get_subscription_period_label( $item->get_trial_period(), $item->get_trial_interval() );
428
+    if ($item->has_free_trial()) {
429
+        $trial_period = getpaid_get_subscription_period_label($item->get_trial_period(), $item->get_trial_interval());
430 430
 
431
-        if ( wpinv_price( 0, $currency ) == $initial_price ) {
431
+        if (wpinv_price(0, $currency) == $initial_price) {
432 432
 
433
-            if ( empty( $bill_times ) ) {
433
+            if (empty($bill_times)) {
434 434
 
435 435
                 return sprintf(
436 436
 
437 437
                     // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period
438
-                    _x( 'Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing' ),
438
+                    _x('Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing'),
439 439
                     "<span class='getpaid-item-trial-period'>$trial_period</span>",
440 440
                     "<span class='$recurring_class'>$recurring_price</span>",
441 441
                     "<span class='getpaid-item-recurring-period'>$period</span>"
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
             return sprintf(
448 448
 
449 449
                 // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period, $4: is the bill times
450
-                _x( 'Free for %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year for 4 years)', 'invoicing' ),
450
+                _x('Free for %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year for 4 years)', 'invoicing'),
451 451
                 "<span class='getpaid-item-trial-period'>$trial_period</span>",
452 452
                 "<span class='$recurring_class'>$recurring_price</span>",
453 453
                 "<span class='getpaid-item-recurring-period'>$period</span>",
@@ -457,12 +457,12 @@  discard block
 block discarded – undo
457 457
 
458 458
         }
459 459
 
460
-        if ( empty( $bill_times ) ) {
460
+        if (empty($bill_times)) {
461 461
 
462 462
             return sprintf(
463 463
 
464 464
                 // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period
465
-                _x( '%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing' ),
465
+                _x('%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing'),
466 466
                 "<span class='$initial_class'>$initial_price</span>",
467 467
                 "<span class='getpaid-item-trial-period'>$trial_period</span>",
468 468
                 "<span class='$recurring_class'>$recurring_price</span>",
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
         return sprintf(
476 476
 
477 477
             // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period, $4: is the susbcription bill times
478
-            _x( '%1$s for %2$s then %3$s / %4$s for %5$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year for 5 years)', 'invoicing' ),
478
+            _x('%1$s for %2$s then %3$s / %4$s for %5$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year for 5 years)', 'invoicing'),
479 479
             "<span class='$initial_class'>$initial_price</span>",
480 480
             "<span class='getpaid-item-trial-period'>$trial_period</span>",
481 481
             "<span class='$recurring_class'>$recurring_price</span>",
@@ -486,14 +486,14 @@  discard block
 block discarded – undo
486 486
 
487 487
     }
488 488
 
489
-    if ( $initial_price == $recurring_price ) {
489
+    if ($initial_price == $recurring_price) {
490 490
 
491
-        if ( empty( $bill_times ) ) {
491
+        if (empty($bill_times)) {
492 492
 
493 493
             return sprintf(
494 494
 
495 495
                 // translators: $1: is the recurring price, $2: is the susbcription period
496
-                _x( '%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing' ),
496
+                _x('%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing'),
497 497
                 "<span class='$recurring_class'>$recurring_price</span>",
498 498
                 "<span class='getpaid-item-recurring-period'>$period</span>"
499 499
 
@@ -504,7 +504,7 @@  discard block
 block discarded – undo
504 504
         return sprintf(
505 505
 
506 506
             // translators: $1: is the recurring price, $2: is the susbcription period, $3: is the susbcription bill times
507
-            _x( '%1$s / %2$s for %3$s', 'Item subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
507
+            _x('%1$s / %2$s for %3$s', 'Item subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing'),
508 508
             "<span class='$recurring_class'>$recurring_price</span>",
509 509
             "<span class='getpaid-item-recurring-period'>$period</span>",
510 510
             "<span class='getpaid-item-recurring-bill-times'>$bill_times</span>"
@@ -513,14 +513,14 @@  discard block
 block discarded – undo
513 513
 
514 514
     }
515 515
 
516
-    if ( $initial_price == wpinv_price( 0, $currency ) ) {
516
+    if ($initial_price == wpinv_price(0, $currency)) {
517 517
 
518
-        if ( empty( $bill_times ) ) {
518
+        if (empty($bill_times)) {
519 519
 
520 520
             return sprintf(
521 521
 
522 522
                 // translators: $1: is the recurring period, $2: is the recurring price
523
-                _x( 'Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing' ),
523
+                _x('Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing'),
524 524
                 "<span class='getpaid-item-recurring-period'>$period</span>",
525 525
                 "<span class='$recurring_class'>$recurring_price</span>"
526 526
 
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
         return sprintf(
532 532
 
533 533
             // translators: $1: is the recurring period, $2: is the recurring price, $3: is the bill times
534
-            _x( 'Free for %1$s then %2$s / %1$s for %3$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months for 12 months)', 'invoicing' ),
534
+            _x('Free for %1$s then %2$s / %1$s for %3$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months for 12 months)', 'invoicing'),
535 535
             "<span class='getpaid-item-recurring-period'>$period</span>",
536 536
             "<span class='$recurring_class'>$recurring_price</span>",
537 537
             "<span class='getpaid-item-recurring-bill-times'>$bill_times</span>"
@@ -540,12 +540,12 @@  discard block
 block discarded – undo
540 540
 
541 541
     }
542 542
 
543
-    if ( empty( $bill_times ) ) {
543
+    if (empty($bill_times)) {
544 544
 
545 545
         return sprintf(
546 546
 
547 547
             // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period
548
-            _x( 'Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing' ),
548
+            _x('Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing'),
549 549
             "<span class='$initial_class'>$initial_price</span>",
550 550
             "<span class='$recurring_class'>$recurring_price</span>",
551 551
             "<span class='getpaid-item-recurring-period'>$period</span>"
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
     return sprintf(
558 558
 
559 559
         // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period, $4: is the susbcription bill times
560
-        _x( 'Initial payment of %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year for 4 years)', 'invoicing' ),
560
+        _x('Initial payment of %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year for 4 years)', 'invoicing'),
561 561
         "<span class='$initial_class'>$initial_price</span>",
562 562
         "<span class='$recurring_class'>$recurring_price</span>",
563 563
         "<span class='getpaid-item-recurring-period'>$period</span>",
Please login to merge, or discard this patch.
includes/subscription-functions.php 2 patches
Indentation   +181 added lines, -181 removed lines patch added patch discarded remove patch
@@ -17,28 +17,28 @@  discard block
 block discarded – undo
17 17
  */
18 18
 function getpaid_get_subscriptions( $args = array(), $return = 'results' ) {
19 19
 
20
-	// Do not retrieve all fields if we just want the count.
21
-	if ( 'count' == $return ) {
22
-		$args['fields'] = 'id';
23
-		$args['number'] = 1;
24
-	}
20
+    // Do not retrieve all fields if we just want the count.
21
+    if ( 'count' == $return ) {
22
+        $args['fields'] = 'id';
23
+        $args['number'] = 1;
24
+    }
25 25
 
26
-	// Do not count all matches if we just want the results.
27
-	if ( 'results' == $return ) {
28
-		$args['count_total'] = false;
29
-	}
26
+    // Do not count all matches if we just want the results.
27
+    if ( 'results' == $return ) {
28
+        $args['count_total'] = false;
29
+    }
30 30
 
31
-	$query = new GetPaid_Subscriptions_Query( $args );
31
+    $query = new GetPaid_Subscriptions_Query( $args );
32 32
 
33
-	if ( 'results' == $return ) {
34
-		return $query->get_results();
35
-	}
33
+    if ( 'results' == $return ) {
34
+        return $query->get_results();
35
+    }
36 36
 
37
-	if ( 'count' == $return ) {
38
-		return $query->get_total();
39
-	}
37
+    if ( 'count' == $return ) {
38
+        return $query->get_total();
39
+    }
40 40
 
41
-	return $query;
41
+    return $query;
42 42
 }
43 43
 
44 44
 /**
@@ -48,18 +48,18 @@  discard block
 block discarded – undo
48 48
  */
49 49
 function getpaid_get_subscription_statuses() {
50 50
 
51
-	return apply_filters(
52
-		'getpaid_get_subscription_statuses',
53
-		array(
54
-			'pending'    => __( 'Pending', 'invoicing' ),
55
-			'trialling'  => __( 'Trialing', 'invoicing' ),
56
-			'active'     => __( 'Active', 'invoicing' ),
57
-			'failing'    => __( 'Failing', 'invoicing' ),
58
-			'expired'    => __( 'Expired', 'invoicing' ),
59
-			'completed'  => __( 'Complete', 'invoicing' ),
60
-			'cancelled'  => __( 'Cancelled', 'invoicing' ),
61
-		)
62
-	);
51
+    return apply_filters(
52
+        'getpaid_get_subscription_statuses',
53
+        array(
54
+            'pending'    => __( 'Pending', 'invoicing' ),
55
+            'trialling'  => __( 'Trialing', 'invoicing' ),
56
+            'active'     => __( 'Active', 'invoicing' ),
57
+            'failing'    => __( 'Failing', 'invoicing' ),
58
+            'expired'    => __( 'Expired', 'invoicing' ),
59
+            'completed'  => __( 'Complete', 'invoicing' ),
60
+            'cancelled'  => __( 'Cancelled', 'invoicing' ),
61
+        )
62
+    );
63 63
 
64 64
 }
65 65
 
@@ -69,8 +69,8 @@  discard block
 block discarded – undo
69 69
  * @return string
70 70
  */
71 71
 function getpaid_get_subscription_status_label( $status ) {
72
-	$statuses = getpaid_get_subscription_statuses();
73
-	return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
72
+    $statuses = getpaid_get_subscription_statuses();
73
+    return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
74 74
 }
75 75
 
76 76
 /**
@@ -80,18 +80,18 @@  discard block
 block discarded – undo
80 80
  */
81 81
 function getpaid_get_subscription_status_classes() {
82 82
 
83
-	return apply_filters(
84
-		'getpaid_get_subscription_status_classes',
85
-		array(
86
-			'pending'    => 'badge-dark',
87
-			'trialling'  => 'badge-info',
88
-			'active'     => 'badge-success',
89
-			'failing'    => 'badge-warning',
90
-			'expired'    => 'badge-danger',
91
-			'completed'  => 'badge-primary',
92
-			'cancelled'  => 'badge-secondary',
93
-		)
94
-	);
83
+    return apply_filters(
84
+        'getpaid_get_subscription_status_classes',
85
+        array(
86
+            'pending'    => 'badge-dark',
87
+            'trialling'  => 'badge-info',
88
+            'active'     => 'badge-success',
89
+            'failing'    => 'badge-warning',
90
+            'expired'    => 'badge-danger',
91
+            'completed'  => 'badge-primary',
92
+            'cancelled'  => 'badge-secondary',
93
+        )
94
+    );
95 95
 
96 96
 }
97 97
 
@@ -102,15 +102,15 @@  discard block
 block discarded – undo
102 102
  */
103 103
 function getpaid_get_subscription_status_counts( $args = array() ) {
104 104
 
105
-	$statuses = array_keys( getpaid_get_subscription_statuses() );
106
-	$counts   = array();
105
+    $statuses = array_keys( getpaid_get_subscription_statuses() );
106
+    $counts   = array();
107 107
 
108
-	foreach ( $statuses as $status ) {
109
-		$_args             = wp_parse_args( "status=$status", $args );
110
-		$counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
111
-	}
108
+    foreach ( $statuses as $status ) {
109
+        $_args             = wp_parse_args( "status=$status", $args );
110
+        $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
111
+    }
112 112
 
113
-	return $counts;
113
+    return $counts;
114 114
 
115 115
 }
116 116
 
@@ -121,32 +121,32 @@  discard block
 block discarded – undo
121 121
  */
122 122
 function getpaid_get_subscription_periods() {
123 123
 
124
-	return apply_filters(
125
-		'getpaid_get_subscription_periods',
126
-		array(
124
+    return apply_filters(
125
+        'getpaid_get_subscription_periods',
126
+        array(
127 127
 
128
-			'day'   => array(
129
-				'singular' => __( '%s day', 'invoicing' ),
130
-				'plural'   => __( '%d days', 'invoicing' ),
131
-			),
128
+            'day'   => array(
129
+                'singular' => __( '%s day', 'invoicing' ),
130
+                'plural'   => __( '%d days', 'invoicing' ),
131
+            ),
132 132
 
133
-			'week'   => array(
134
-				'singular' => __( '%s week', 'invoicing' ),
135
-				'plural'   => __( '%d weeks', 'invoicing' ),
136
-			),
133
+            'week'   => array(
134
+                'singular' => __( '%s week', 'invoicing' ),
135
+                'plural'   => __( '%d weeks', 'invoicing' ),
136
+            ),
137 137
 
138
-			'month'   => array(
139
-				'singular' => __( '%s month', 'invoicing' ),
140
-				'plural'   => __( '%d months', 'invoicing' ),
141
-			),
138
+            'month'   => array(
139
+                'singular' => __( '%s month', 'invoicing' ),
140
+                'plural'   => __( '%d months', 'invoicing' ),
141
+            ),
142 142
 
143
-			'year'   => array(
144
-				'singular' => __( '%s year', 'invoicing' ),
145
-				'plural'   => __( '%d years', 'invoicing' ),
146
-			),
143
+            'year'   => array(
144
+                'singular' => __( '%s year', 'invoicing' ),
145
+                'plural'   => __( '%d years', 'invoicing' ),
146
+            ),
147 147
 
148
-		)
149
-	);
148
+        )
149
+    );
150 150
 
151 151
 }
152 152
 
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
  * @return int
158 158
  */
159 159
 function getpaid_get_subscription_trial_period_interval( $trial_period ) {
160
-	return (int) preg_replace( '/[^0-9]/', '', $trial_period );
160
+    return (int) preg_replace( '/[^0-9]/', '', $trial_period );
161 161
 }
162 162
 
163 163
 /**
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
  * @return string
168 168
  */
169 169
 function getpaid_get_subscription_trial_period_period( $trial_period ) {
170
-	return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
170
+    return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
171 171
 }
172 172
 
173 173
 /**
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
  * @return string
179 179
  */
180 180
 function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) {
181
-	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label(  $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
182
-	return strtolower( sanitize_text_field( $label ) );
181
+    $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label(  $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
182
+    return strtolower( sanitize_text_field( $label ) );
183 183
 }
184 184
 
185 185
 /**
@@ -190,22 +190,22 @@  discard block
 block discarded – undo
190 190
  */
191 191
 function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) {
192 192
 
193
-	$periods = getpaid_get_subscription_periods();
194
-	$period  = strtolower( $period );
193
+    $periods = getpaid_get_subscription_periods();
194
+    $period  = strtolower( $period );
195 195
 
196
-	if ( isset( $periods[ $period ] ) ) {
197
-		return sprintf( $periods[ $period ]['singular'], $singular_prefix );
198
-	}
196
+    if ( isset( $periods[ $period ] ) ) {
197
+        return sprintf( $periods[ $period ]['singular'], $singular_prefix );
198
+    }
199 199
 
200
-	// Backwards compatibility.
201
-	foreach ( $periods as $key => $data ) {
202
-		if ( strpos( $key, $period ) === 0 ) {
203
-			return sprintf( $data['singular'], $singular_prefix );
204
-		}
205
-	}
200
+    // Backwards compatibility.
201
+    foreach ( $periods as $key => $data ) {
202
+        if ( strpos( $key, $period ) === 0 ) {
203
+            return sprintf( $data['singular'], $singular_prefix );
204
+        }
205
+    }
206 206
 
207
-	// Invalid string.
208
-	return '';
207
+    // Invalid string.
208
+    return '';
209 209
 }
210 210
 
211 211
 /**
@@ -217,22 +217,22 @@  discard block
 block discarded – undo
217 217
  */
218 218
 function getpaid_get_plural_subscription_period_label( $period, $interval ) {
219 219
 
220
-	$periods = getpaid_get_subscription_periods();
221
-	$period  = strtolower( $period );
220
+    $periods = getpaid_get_subscription_periods();
221
+    $period  = strtolower( $period );
222 222
 
223
-	if ( isset( $periods[ $period ] ) ) {
224
-		return sprintf( $periods[ $period ]['plural'], $interval );
225
-	}
223
+    if ( isset( $periods[ $period ] ) ) {
224
+        return sprintf( $periods[ $period ]['plural'], $interval );
225
+    }
226 226
 
227
-	// Backwards compatibility.
228
-	foreach ( $periods as $key => $data ) {
229
-		if ( strpos( $key, $period ) === 0 ) {
230
-			return sprintf( $data['plural'], $interval );
231
-		}
232
-	}
227
+    // Backwards compatibility.
228
+    foreach ( $periods as $key => $data ) {
229
+        if ( strpos( $key, $period ) === 0 ) {
230
+            return sprintf( $data['plural'], $interval );
231
+        }
232
+    }
233 233
 
234
-	// Invalid string.
235
-	return '';
234
+    // Invalid string.
235
+    return '';
236 236
 }
237 237
 
238 238
 /**
@@ -243,101 +243,101 @@  discard block
 block discarded – undo
243 243
  */
244 244
 function getpaid_get_formatted_subscription_amount( $subscription ) {
245 245
 
246
-	$initial    = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
247
-	$recurring  = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
248
-	$period     = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
249
-	$bill_times = $subscription->get_bill_times();
246
+    $initial    = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
247
+    $recurring  = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
248
+    $period     = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
249
+    $bill_times = $subscription->get_bill_times();
250 250
 
251
-	if ( ! empty( $bill_times ) ) {
252
-		$bill_times = $subscription->get_frequency() * $bill_times;
253
-		$bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times );
254
-	}
251
+    if ( ! empty( $bill_times ) ) {
252
+        $bill_times = $subscription->get_frequency() * $bill_times;
253
+        $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times );
254
+    }
255 255
 
256
-	// Trial periods.
257
-	if ( $subscription->has_trial_period() ) {
256
+    // Trial periods.
257
+    if ( $subscription->has_trial_period() ) {
258 258
 
259
-		$trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
260
-		$trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
259
+        $trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
260
+        $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
261 261
 
262
-		if ( empty( $bill_times ) ) {
262
+        if ( empty( $bill_times ) ) {
263 263
 
264
-			return sprintf(
264
+            return sprintf(
265 265
 
266
-				// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
267
-				_x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
268
-				$initial,
269
-				getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
270
-				$recurring,
271
-				$period
266
+                // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
267
+                _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
268
+                $initial,
269
+                getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
270
+                $recurring,
271
+                $period
272 272
 	
273
-			);
273
+            );
274 274
 
275
-		}
275
+        }
276 276
 
277
-		return sprintf(
277
+        return sprintf(
278 278
 
279
-			// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times
280
-			_x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ),
281
-			$initial,
282
-			getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
283
-			$recurring,
284
-			$period,
285
-			$bill_times
286
-		);
279
+            // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times
280
+            _x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ),
281
+            $initial,
282
+            getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
283
+            $recurring,
284
+            $period,
285
+            $bill_times
286
+        );
287 287
 
288
-	}
288
+    }
289 289
 
290
-	if ( $initial != $recurring ) {
290
+    if ( $initial != $recurring ) {
291 291
 
292
-		if ( empty( $bill_times ) ) {
292
+        if ( empty( $bill_times ) ) {
293 293
 
294
-			return sprintf(
294
+            return sprintf(
295 295
 
296
-				// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
297
-				_x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
298
-				$initial,
299
-				$recurring,
300
-				$period
296
+                // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
297
+                _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
298
+                $initial,
299
+                $recurring,
300
+                $period
301 301
 	
302
-			);
302
+            );
303 303
 
304
-		}
304
+        }
305 305
 
306
-		return sprintf(
306
+        return sprintf(
307 307
 
308
-			// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times
309
-			_x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ),
310
-			$initial,
311
-			$recurring,
312
-			$period,
313
-			$bill_times
308
+            // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times
309
+            _x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ),
310
+            $initial,
311
+            $recurring,
312
+            $period,
313
+            $bill_times
314 314
 
315
-		);
315
+        );
316 316
 
317
-	}
317
+    }
318 318
 
319
-	if ( empty( $bill_times ) ) {
319
+    if ( empty( $bill_times ) ) {
320 320
 
321
-		return sprintf(
321
+        return sprintf(
322 322
 
323
-			// translators: $1: is the recurring amount, $2: is the recurring period
324
-			_x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
325
-			$initial,
326
-			$period
323
+            // translators: $1: is the recurring amount, $2: is the recurring period
324
+            _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
325
+            $initial,
326
+            $period
327 327
 	
328
-		);
328
+        );
329 329
 
330
-	}
330
+    }
331 331
 
332
-	return sprintf(
332
+    return sprintf(
333 333
 
334
-		// translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period
335
-		_x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
336
-		$bill_times,
337
-		$initial,
338
-		$period
334
+        // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period
335
+        _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
336
+        $bill_times,
337
+        $initial,
338
+        $period
339 339
 
340
-	);
340
+    );
341 341
 
342 342
 }
343 343
 
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
  * @return WPInv_Subscription|bool
349 349
  */
350 350
 function getpaid_get_invoice_subscription( $invoice ) {
351
-	return getpaid_subscriptions()->get_invoice_subscription( $invoice );
351
+    return getpaid_subscriptions()->get_invoice_subscription( $invoice );
352 352
 }
353 353
 
354 354
 /**
@@ -357,10 +357,10 @@  discard block
 block discarded – undo
357 357
  * @param WPInv_Invoice $invoice
358 358
  */
359 359
 function getpaid_activate_invoice_subscription( $invoice ) {
360
-	$subscription = getpaid_get_invoice_subscription( $invoice );
361
-	if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
362
-		$subscription->activate();
363
-	}
360
+    $subscription = getpaid_get_invoice_subscription( $invoice );
361
+    if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
362
+        $subscription->activate();
363
+    }
364 364
 }
365 365
 
366 366
 /**
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
  * @return WPInv_Subscriptions
370 370
  */
371 371
 function getpaid_subscriptions() {
372
-	return getpaid()->get( 'subscriptions' );
372
+    return getpaid()->get( 'subscriptions' );
373 373
 }
374 374
 
375 375
 /**
@@ -387,14 +387,14 @@  discard block
 block discarded – undo
387 387
         return false;
388 388
     }
389 389
 
390
-	// Fetch the invoiec subscription.
391
-	$subscription = getpaid_get_subscriptions(
392
-		array(
393
-			'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(),
394
-			'number'     => 1,
395
-		)
396
-	);
390
+    // Fetch the invoiec subscription.
391
+    $subscription = getpaid_get_subscriptions(
392
+        array(
393
+            'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(),
394
+            'number'     => 1,
395
+        )
396
+    );
397 397
 
398
-	return empty( $subscription ) ? false : $subscription[0];
398
+    return empty( $subscription ) ? false : $subscription[0];
399 399
 
400 400
 }
Please login to merge, or discard this patch.
Spacing   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -15,26 +15,26 @@  discard block
 block discarded – undo
15 15
  *
16 16
  * @return int|array|WPInv_Subscription[]|GetPaid_Subscriptions_Query
17 17
  */
18
-function getpaid_get_subscriptions( $args = array(), $return = 'results' ) {
18
+function getpaid_get_subscriptions($args = array(), $return = 'results') {
19 19
 
20 20
 	// Do not retrieve all fields if we just want the count.
21
-	if ( 'count' == $return ) {
21
+	if ('count' == $return) {
22 22
 		$args['fields'] = 'id';
23 23
 		$args['number'] = 1;
24 24
 	}
25 25
 
26 26
 	// Do not count all matches if we just want the results.
27
-	if ( 'results' == $return ) {
27
+	if ('results' == $return) {
28 28
 		$args['count_total'] = false;
29 29
 	}
30 30
 
31
-	$query = new GetPaid_Subscriptions_Query( $args );
31
+	$query = new GetPaid_Subscriptions_Query($args);
32 32
 
33
-	if ( 'results' == $return ) {
33
+	if ('results' == $return) {
34 34
 		return $query->get_results();
35 35
 	}
36 36
 
37
-	if ( 'count' == $return ) {
37
+	if ('count' == $return) {
38 38
 		return $query->get_total();
39 39
 	}
40 40
 
@@ -51,13 +51,13 @@  discard block
 block discarded – undo
51 51
 	return apply_filters(
52 52
 		'getpaid_get_subscription_statuses',
53 53
 		array(
54
-			'pending'    => __( 'Pending', 'invoicing' ),
55
-			'trialling'  => __( 'Trialing', 'invoicing' ),
56
-			'active'     => __( 'Active', 'invoicing' ),
57
-			'failing'    => __( 'Failing', 'invoicing' ),
58
-			'expired'    => __( 'Expired', 'invoicing' ),
59
-			'completed'  => __( 'Complete', 'invoicing' ),
60
-			'cancelled'  => __( 'Cancelled', 'invoicing' ),
54
+			'pending'    => __('Pending', 'invoicing'),
55
+			'trialling'  => __('Trialing', 'invoicing'),
56
+			'active'     => __('Active', 'invoicing'),
57
+			'failing'    => __('Failing', 'invoicing'),
58
+			'expired'    => __('Expired', 'invoicing'),
59
+			'completed'  => __('Complete', 'invoicing'),
60
+			'cancelled'  => __('Cancelled', 'invoicing'),
61 61
 		)
62 62
 	);
63 63
 
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
  *
69 69
  * @return string
70 70
  */
71
-function getpaid_get_subscription_status_label( $status ) {
71
+function getpaid_get_subscription_status_label($status) {
72 72
 	$statuses = getpaid_get_subscription_statuses();
73
-	return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
73
+	return isset($statuses[$status]) ? $statuses[$status] : ucfirst(sanitize_text_field($status));
74 74
 }
75 75
 
76 76
 /**
@@ -100,14 +100,14 @@  discard block
 block discarded – undo
100 100
  *
101 101
  * @return array
102 102
  */
103
-function getpaid_get_subscription_status_counts( $args = array() ) {
103
+function getpaid_get_subscription_status_counts($args = array()) {
104 104
 
105
-	$statuses = array_keys( getpaid_get_subscription_statuses() );
105
+	$statuses = array_keys(getpaid_get_subscription_statuses());
106 106
 	$counts   = array();
107 107
 
108
-	foreach ( $statuses as $status ) {
109
-		$_args             = wp_parse_args( "status=$status", $args );
110
-		$counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
108
+	foreach ($statuses as $status) {
109
+		$_args             = wp_parse_args("status=$status", $args);
110
+		$counts[$status] = getpaid_get_subscriptions($_args, 'count');
111 111
 	}
112 112
 
113 113
 	return $counts;
@@ -126,23 +126,23 @@  discard block
 block discarded – undo
126 126
 		array(
127 127
 
128 128
 			'day'   => array(
129
-				'singular' => __( '%s day', 'invoicing' ),
130
-				'plural'   => __( '%d days', 'invoicing' ),
129
+				'singular' => __('%s day', 'invoicing'),
130
+				'plural'   => __('%d days', 'invoicing'),
131 131
 			),
132 132
 
133 133
 			'week'   => array(
134
-				'singular' => __( '%s week', 'invoicing' ),
135
-				'plural'   => __( '%d weeks', 'invoicing' ),
134
+				'singular' => __('%s week', 'invoicing'),
135
+				'plural'   => __('%d weeks', 'invoicing'),
136 136
 			),
137 137
 
138 138
 			'month'   => array(
139
-				'singular' => __( '%s month', 'invoicing' ),
140
-				'plural'   => __( '%d months', 'invoicing' ),
139
+				'singular' => __('%s month', 'invoicing'),
140
+				'plural'   => __('%d months', 'invoicing'),
141 141
 			),
142 142
 
143 143
 			'year'   => array(
144
-				'singular' => __( '%s year', 'invoicing' ),
145
-				'plural'   => __( '%d years', 'invoicing' ),
144
+				'singular' => __('%s year', 'invoicing'),
145
+				'plural'   => __('%d years', 'invoicing'),
146 146
 			),
147 147
 
148 148
 		)
@@ -156,8 +156,8 @@  discard block
 block discarded – undo
156 156
  * @param string $trial_period
157 157
  * @return int
158 158
  */
159
-function getpaid_get_subscription_trial_period_interval( $trial_period ) {
160
-	return (int) preg_replace( '/[^0-9]/', '', $trial_period );
159
+function getpaid_get_subscription_trial_period_interval($trial_period) {
160
+	return (int) preg_replace('/[^0-9]/', '', $trial_period);
161 161
 }
162 162
 
163 163
 /**
@@ -166,8 +166,8 @@  discard block
 block discarded – undo
166 166
  * @param string $trial_period
167 167
  * @return string
168 168
  */
169
-function getpaid_get_subscription_trial_period_period( $trial_period ) {
170
-	return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
169
+function getpaid_get_subscription_trial_period_period($trial_period) {
170
+	return preg_replace('/[^a-z]/', '', strtolower($trial_period));
171 171
 }
172 172
 
173 173
 /**
@@ -177,9 +177,9 @@  discard block
 block discarded – undo
177 177
  * @param int $interval
178 178
  * @return string
179 179
  */
180
-function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) {
181
-	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label(  $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
182
-	return strtolower( sanitize_text_field( $label ) );
180
+function getpaid_get_subscription_period_label($period, $interval = 1, $singular_prefix = '1') {
181
+	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label($period, $interval) : getpaid_get_singular_subscription_period_label($period, $singular_prefix);
182
+	return strtolower(sanitize_text_field($label));
183 183
 }
184 184
 
185 185
 /**
@@ -188,19 +188,19 @@  discard block
 block discarded – undo
188 188
  * @param string $period
189 189
  * @return string
190 190
  */
191
-function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) {
191
+function getpaid_get_singular_subscription_period_label($period, $singular_prefix = '1') {
192 192
 
193 193
 	$periods = getpaid_get_subscription_periods();
194
-	$period  = strtolower( $period );
194
+	$period  = strtolower($period);
195 195
 
196
-	if ( isset( $periods[ $period ] ) ) {
197
-		return sprintf( $periods[ $period ]['singular'], $singular_prefix );
196
+	if (isset($periods[$period])) {
197
+		return sprintf($periods[$period]['singular'], $singular_prefix);
198 198
 	}
199 199
 
200 200
 	// Backwards compatibility.
201
-	foreach ( $periods as $key => $data ) {
202
-		if ( strpos( $key, $period ) === 0 ) {
203
-			return sprintf( $data['singular'], $singular_prefix );
201
+	foreach ($periods as $key => $data) {
202
+		if (strpos($key, $period) === 0) {
203
+			return sprintf($data['singular'], $singular_prefix);
204 204
 		}
205 205
 	}
206 206
 
@@ -215,19 +215,19 @@  discard block
 block discarded – undo
215 215
  * @param int $interval
216 216
  * @return string
217 217
  */
218
-function getpaid_get_plural_subscription_period_label( $period, $interval ) {
218
+function getpaid_get_plural_subscription_period_label($period, $interval) {
219 219
 
220 220
 	$periods = getpaid_get_subscription_periods();
221
-	$period  = strtolower( $period );
221
+	$period  = strtolower($period);
222 222
 
223
-	if ( isset( $periods[ $period ] ) ) {
224
-		return sprintf( $periods[ $period ]['plural'], $interval );
223
+	if (isset($periods[$period])) {
224
+		return sprintf($periods[$period]['plural'], $interval);
225 225
 	}
226 226
 
227 227
 	// Backwards compatibility.
228
-	foreach ( $periods as $key => $data ) {
229
-		if ( strpos( $key, $period ) === 0 ) {
230
-			return sprintf( $data['plural'], $interval );
228
+	foreach ($periods as $key => $data) {
229
+		if (strpos($key, $period) === 0) {
230
+			return sprintf($data['plural'], $interval);
231 231
 		}
232 232
 	}
233 233
 
@@ -241,32 +241,32 @@  discard block
 block discarded – undo
241 241
  * @param WPInv_Subscription $subscription
242 242
  * @return string
243 243
  */
244
-function getpaid_get_formatted_subscription_amount( $subscription ) {
244
+function getpaid_get_formatted_subscription_amount($subscription) {
245 245
 
246
-	$initial    = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
247
-	$recurring  = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
248
-	$period     = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
246
+	$initial    = wpinv_price($subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency());
247
+	$recurring  = wpinv_price($subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency());
248
+	$period     = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), '');
249 249
 	$bill_times = $subscription->get_bill_times();
250 250
 
251
-	if ( ! empty( $bill_times ) ) {
251
+	if (!empty($bill_times)) {
252 252
 		$bill_times = $subscription->get_frequency() * $bill_times;
253
-		$bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times );
253
+		$bill_times = getpaid_get_subscription_period_label($subscription->get_period(), $bill_times);
254 254
 	}
255 255
 
256 256
 	// Trial periods.
257
-	if ( $subscription->has_trial_period() ) {
257
+	if ($subscription->has_trial_period()) {
258 258
 
259
-		$trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
260
-		$trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
259
+		$trial_period   = getpaid_get_subscription_trial_period_period($subscription->get_trial_period());
260
+		$trial_interval = getpaid_get_subscription_trial_period_interval($subscription->get_trial_period());
261 261
 
262
-		if ( empty( $bill_times ) ) {
262
+		if (empty($bill_times)) {
263 263
 
264 264
 			return sprintf(
265 265
 
266 266
 				// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
267
-				_x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
267
+				_x('%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing'),
268 268
 				$initial,
269
-				getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
269
+				getpaid_get_subscription_period_label($trial_period, $trial_interval),
270 270
 				$recurring,
271 271
 				$period
272 272
 	
@@ -277,9 +277,9 @@  discard block
 block discarded – undo
277 277
 		return sprintf(
278 278
 
279 279
 			// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times
280
-			_x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ),
280
+			_x('%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing'),
281 281
 			$initial,
282
-			getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
282
+			getpaid_get_subscription_period_label($trial_period, $trial_interval),
283 283
 			$recurring,
284 284
 			$period,
285 285
 			$bill_times
@@ -287,14 +287,14 @@  discard block
 block discarded – undo
287 287
 
288 288
 	}
289 289
 
290
-	if ( $initial != $recurring ) {
290
+	if ($initial != $recurring) {
291 291
 
292
-		if ( empty( $bill_times ) ) {
292
+		if (empty($bill_times)) {
293 293
 
294 294
 			return sprintf(
295 295
 
296 296
 				// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
297
-				_x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
297
+				_x('Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing'),
298 298
 				$initial,
299 299
 				$recurring,
300 300
 				$period
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
 		return sprintf(
307 307
 
308 308
 			// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times
309
-			_x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ),
309
+			_x('Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing'),
310 310
 			$initial,
311 311
 			$recurring,
312 312
 			$period,
@@ -316,12 +316,12 @@  discard block
 block discarded – undo
316 316
 
317 317
 	}
318 318
 
319
-	if ( empty( $bill_times ) ) {
319
+	if (empty($bill_times)) {
320 320
 
321 321
 		return sprintf(
322 322
 
323 323
 			// translators: $1: is the recurring amount, $2: is the recurring period
324
-			_x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
324
+			_x('%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing'),
325 325
 			$initial,
326 326
 			$period
327 327
 	
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 	return sprintf(
333 333
 
334 334
 		// translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period
335
-		_x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
335
+		_x('%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing'),
336 336
 		$bill_times,
337 337
 		$initial,
338 338
 		$period
@@ -347,8 +347,8 @@  discard block
 block discarded – undo
347 347
  * @param WPInv_Invoice $invoice
348 348
  * @return WPInv_Subscription|bool
349 349
  */
350
-function getpaid_get_invoice_subscription( $invoice ) {
351
-	return getpaid_subscriptions()->get_invoice_subscription( $invoice );
350
+function getpaid_get_invoice_subscription($invoice) {
351
+	return getpaid_subscriptions()->get_invoice_subscription($invoice);
352 352
 }
353 353
 
354 354
 /**
@@ -356,9 +356,9 @@  discard block
 block discarded – undo
356 356
  *
357 357
  * @param WPInv_Invoice $invoice
358 358
  */
359
-function getpaid_activate_invoice_subscription( $invoice ) {
360
-	$subscription = getpaid_get_invoice_subscription( $invoice );
361
-	if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
359
+function getpaid_activate_invoice_subscription($invoice) {
360
+	$subscription = getpaid_get_invoice_subscription($invoice);
361
+	if (is_a($subscription, 'WPInv_Subscription')) {
362 362
 		$subscription->activate();
363 363
 	}
364 364
 }
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
  * @return WPInv_Subscriptions
370 370
  */
371 371
 function getpaid_subscriptions() {
372
-	return getpaid()->get( 'subscriptions' );
372
+	return getpaid()->get('subscriptions');
373 373
 }
374 374
 
375 375
 /**
@@ -377,13 +377,13 @@  discard block
 block discarded – undo
377 377
  *
378 378
  * @return WPInv_Subscription|bool
379 379
  */
380
-function wpinv_get_subscription( $invoice ) {
380
+function wpinv_get_subscription($invoice) {
381 381
 
382 382
     // Retrieve the invoice.
383
-    $invoice = new WPInv_Invoice( $invoice );
383
+    $invoice = new WPInv_Invoice($invoice);
384 384
 
385 385
     // Ensure it is a recurring invoice.
386
-    if ( ! $invoice->is_recurring() ) {
386
+    if (!$invoice->is_recurring()) {
387 387
         return false;
388 388
     }
389 389
 
@@ -395,6 +395,6 @@  discard block
 block discarded – undo
395 395
 		)
396 396
 	);
397 397
 
398
-	return empty( $subscription ) ? false : $subscription[0];
398
+	return empty($subscription) ? false : $subscription[0];
399 399
 
400 400
 }
Please login to merge, or discard this patch.