Passed
Pull Request — master (#371)
by Brian
88:26
created

WPInv_Item::set_custom_id()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 2
rs 10
1
<?php
2
if ( ! defined( 'ABSPATH' ) ) {
3
	exit;
4
}
5
6
/**
7
 * Item Class
8
 *
9
 */
10
class WPInv_Item  extends GetPaid_Data {
11
12
    /**
13
     * Object id.
14
     * 
15
     * Here for backwards compatibility and should not be accessed directly.
16
     */
17
    public $ID = 0;
18
19
    /**
20
	 * Which data store to load.
21
	 *
22
	 * @var string
23
	 */
24
    protected $data_store_name = 'item';
25
26
    /**
27
	 * This is the name of this object type.
28
	 *
29
	 * @var string
30
	 */
31
	protected $object_type = 'item';
32
33
    /**
34
	 * Item Data array. This is the core item data exposed in APIs.
35
	 *
36
	 * @since 1.0.19
37
	 * @var array
38
	 */
39
	protected $data = array(
40
		'parent_id'            => 0,
41
		'status'               => 'draft',
42
		'version'              => '',
43
		'date_created'         => null,
44
        'date_modified'        => null,
45
        'name'                 => '',
46
        'description'          => '',
47
        'author'               => 1,
48
        'price'                => 0,
49
        'vat_rule'             => null,
50
        'vat_class'            => null,
51
        'type'                 => 'custom',
52
        'custom_id'            => null,
53
        'custom_name'          => null,
54
        'custom_singular_name' => null,
55
        'is_editable'          => 1,
56
        'is_dynamic_pricing'   => null,
57
        'minimum_price'        => null,
58
        'is_recurring'         => null,
59
        'recurring_period'     => null,
60
        'recurring_interval'   => null,
61
        'recurring_limit'      => null,
62
        'is_free_trial'        => null,
63
        'trial_period'         => null,
64
        'signup_fee'           => null,
65
        'trial_interval'       => null,
66
    );
67
68
    /**
69
	 * Stores meta in cache for future reads.
70
	 *
71
	 * A group must be set to to enable caching.
72
	 *
73
	 * @var string
74
	 */
75
	protected $cache_group = 'getpaid_items';
76
77
    /**
78
     * Stores a reference to the original WP_Post object
79
     * 
80
     * @var WP_Post
81
     */
82
    protected $post = null; 
83
84
    /**
85
	 * Get the item if ID is passed, otherwise the item is new and empty.
86
	 *
87
	 * @param  int|object|WPInv_Item|WP_Post $item Item to read.
88
	 */
89
	public function __construct( $item = 0 ) {
90
		parent::__construct( $item );
91
92
		if ( is_numeric( $item ) && $item > 0 ) {
93
			$this->set_id( $item );
94
		} elseif ( $item instanceof self ) {
95
			$this->set_id( $item->get_id() );
96
		} elseif ( ! empty( $item->ID ) ) {
97
			$this->set_id( $item->ID );
98
		} else {
99
			$this->set_object_read( true );
100
		}
101
102
        // Load the datastore.
103
		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
104
105
		if ( $this->get_id() > 0 ) {
106
            $this->post = get_post( $this->get_id() );
107
			$this->data_store->read( $this );
108
		}
109
	}
110
111
    /*
112
	|--------------------------------------------------------------------------
113
	| CRUD methods
114
	|--------------------------------------------------------------------------
115
	|
116
	| Methods which create, read, update and delete items from the database.
117
	|
118
    */
119
120
    /*
121
	|--------------------------------------------------------------------------
122
	| Getters
123
	|--------------------------------------------------------------------------
124
    */
125
126
    /**
127
	 * Get parent item ID.
128
	 *
129
	 * @since 1.0.19
130
	 * @param  string $context View or edit context.
131
	 * @return int
132
	 */
133
	public function get_parent_id( $context = 'view' ) {
134
		return (int) $this->get_prop( 'parent_id', $context );
135
    }
136
137
    /**
138
	 * Get item status.
139
	 *
140
	 * @since 1.0.19
141
	 * @param  string $context View or edit context.
142
	 * @return string
143
	 */
144
	public function get_status( $context = 'view' ) {
145
		return $this->get_prop( 'status', $context );
146
    }
147
148
    /**
149
	 * Get plugin version when the item was created.
150
	 *
151
	 * @since 1.0.19
152
	 * @param  string $context View or edit context.
153
	 * @return string
154
	 */
155
	public function get_version( $context = 'view' ) {
156
		return $this->get_prop( 'version', $context );
157
    }
158
159
    /**
160
	 * Get date when the item was created.
161
	 *
162
	 * @since 1.0.19
163
	 * @param  string $context View or edit context.
164
	 * @return string
165
	 */
166
	public function get_date_created( $context = 'view' ) {
167
		return $this->get_prop( 'date_created', $context );
168
    }
169
170
    /**
171
	 * Get GMT date when the item was created.
172
	 *
173
	 * @since 1.0.19
174
	 * @param  string $context View or edit context.
175
	 * @return string
176
	 */
177
	public function get_date_created_gmt( $context = 'view' ) {
178
        $date = $this->get_date_created( $context );
179
180
        if ( $date ) {
181
            $date = get_gmt_from_date( $date );
182
        }
183
		return $date;
184
    }
185
186
    /**
187
	 * Get date when the item was last modified.
188
	 *
189
	 * @since 1.0.19
190
	 * @param  string $context View or edit context.
191
	 * @return string
192
	 */
193
	public function get_date_modified( $context = 'view' ) {
194
		return $this->get_prop( 'date_modified', $context );
195
    }
196
197
    /**
198
	 * Get GMT date when the item was last modified.
199
	 *
200
	 * @since 1.0.19
201
	 * @param  string $context View or edit context.
202
	 * @return string
203
	 */
204
	public function get_date_modified_gmt( $context = 'view' ) {
205
        $date = $this->get_date_modified( $context );
206
207
        if ( $date ) {
208
            $date = get_gmt_from_date( $date );
209
        }
210
		return $date;
211
    }
212
213
    /**
214
	 * Get the item name.
215
	 *
216
	 * @since 1.0.19
217
	 * @param  string $context View or edit context.
218
	 * @return string
219
	 */
220
	public function get_name( $context = 'view' ) {
221
		return $this->get_prop( 'name', $context );
222
    }
223
224
    /**
225
	 * Alias of self::get_name().
226
	 *
227
	 * @since 1.0.19
228
	 * @param  string $context View or edit context.
229
	 * @return string
230
	 */
231
	public function get_title( $context = 'view' ) {
232
		return $this->get_name( $context );
233
    }
234
235
    /**
236
	 * Get the item description.
237
	 *
238
	 * @since 1.0.19
239
	 * @param  string $context View or edit context.
240
	 * @return string
241
	 */
242
	public function get_description( $context = 'view' ) {
243
		return $this->get_prop( 'description', $context );
244
    }
245
246
    /**
247
	 * Alias of self::get_description().
248
	 *
249
	 * @since 1.0.19
250
	 * @param  string $context View or edit context.
251
	 * @return string
252
	 */
253
	public function get_excerpt( $context = 'view' ) {
254
		return $this->get_description( $context );
255
    }
256
257
    /**
258
	 * Alias of self::get_description().
259
	 *
260
	 * @since 1.0.19
261
	 * @param  string $context View or edit context.
262
	 * @return string
263
	 */
264
	public function get_summary( $context = 'view' ) {
265
		return $this->get_description( $context );
266
    }
267
268
    /**
269
	 * Get the owner of the item.
270
	 *
271
	 * @since 1.0.19
272
	 * @param  string $context View or edit context.
273
	 * @return string
274
	 */
275
	public function get_author( $context = 'view' ) {
276
		return (int) $this->get_prop( 'author', $context );
277
    }
278
279
    /**
280
	 * Get the price of the item.
281
	 *
282
	 * @since 1.0.19
283
	 * @param  string $context View or edit context.
284
	 * @return string
285
	 */
286
	public function get_price( $context = 'view' ) {
287
        return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) );
288
    }
289
290
    /**
291
	 * Returns a formated price.
292
	 *
293
	 * @since 1.0.19
294
	 * @param  string $context View or edit context.
295
	 * @return string
296
	 */
297
    public function get_the_price() {
298
        $item_price = wpinv_price( wpinv_format_amount( $this->get_price() ) );
299
300
        return apply_filters( 'wpinv_get_the_item_price', $item_price, $this->ID );
301
    }
302
303
    /**
304
	 * Get the VAT rule of the item.
305
	 *
306
	 * @since 1.0.19
307
	 * @param  string $context View or edit context.
308
	 * @return string
309
	 */
310
	public function get_vat_rule( $context = 'view' ) {
311
        return $this->get_prop( 'vat_rule', $context );
312
    }
313
314
    /**
315
	 * Get the VAT class of the item.
316
	 *
317
	 * @since 1.0.19
318
	 * @param  string $context View or edit context.
319
	 * @return string
320
	 */
321
	public function get_vat_class( $context = 'view' ) {
322
        return $this->get_prop( 'vat_class', $context );
323
    }
324
325
    /**
326
	 * Get the type of the item.
327
	 *
328
	 * @since 1.0.19
329
	 * @param  string $context View or edit context.
330
	 * @return string
331
	 */
332
	public function get_type( $context = 'view' ) {
333
        return $this->get_prop( 'type', $context );
334
    }
335
336
    /**
337
	 * Get the custom id of the item.
338
	 *
339
	 * @since 1.0.19
340
	 * @param  string $context View or edit context.
341
	 * @return string
342
	 */
343
	public function get_custom_id( $context = 'view' ) {
344
        return $this->get_prop( 'custom_id', $context );
345
    }
346
347
    /**
348
	 * Get the custom name of the item.
349
	 *
350
	 * @since 1.0.19
351
	 * @param  string $context View or edit context.
352
	 * @return string
353
	 */
354
	public function get_custom_name( $context = 'view' ) {
355
        return $this->get_prop( 'custom_name', $context );
356
    }
357
358
    /**
359
	 * Get the custom singular name of the item.
360
	 *
361
	 * @since 1.0.19
362
	 * @param  string $context View or edit context.
363
	 * @return string
364
	 */
365
	public function get_custom_singular_name( $context = 'view' ) {
366
        return $this->get_prop( 'custom_singular_name', $context );
367
    }
368
369
    /**
370
	 * Checks if an item is editable..
371
	 *
372
	 * @since 1.0.19
373
	 * @param  string $context View or edit context.
374
	 * @return string
375
	 */
376
	public function get_is_editable( $context = 'view' ) {
377
        return $this->get_prop( 'is_editable', $context );
378
    }
379
380
    /**
381
	 * Alias of self::get_is_editable().
382
	 *
383
	 * @since 1.0.19
384
	 * @param  string $context View or edit context.
385
	 * @return string
386
	 */
387
	public function get_editable( $context = 'view' ) {
388
		return $this->get_is_editable( $context );
389
    }
390
391
    /**
392
	 * Checks if dynamic pricing is enabled.
393
	 *
394
	 * @since 1.0.19
395
	 * @param  string $context View or edit context.
396
	 * @return string
397
	 */
398
	public function get_is_dynamic_pricing( $context = 'view' ) {
399
        return $this->get_prop( 'is_dynamic_pricing', $context );
400
    }
401
402
    /**
403
	 * Returns the minimum price if dynamic pricing is enabled.
404
	 *
405
	 * @since 1.0.19
406
	 * @param  string $context View or edit context.
407
	 * @return string
408
	 */
409
	public function get_minimum_price( $context = 'view' ) {
410
        return $this->get_prop( 'minimum_price', $context );
411
    }
412
413
    /**
414
	 * Checks if this is a recurring item.
415
	 *
416
	 * @since 1.0.19
417
	 * @param  string $context View or edit context.
418
	 * @return string
419
	 */
420
	public function get_is_recurring( $context = 'view' ) {
421
        return $this->get_prop( 'is_recurring', $context );
422
    }
423
424
    /**
425
	 * Get the recurring period.
426
	 *
427
	 * @since 1.0.19
428
	 * @param  bool $full Return abbreviation or in full.
429
	 * @return string
430
	 */
431
	public function get_recurring_period( $full = false ) {
432
        $period = $this->get_prop( 'recurring_period', 'view' );
433
434
        if ( $full && ! is_bool( $full ) ) {
0 ignored issues
show
introduced by
The condition is_bool($full) is always true.
Loading history...
435
            $full = false;
436
        }
437
438
        return getpaid_sanitize_recurring_period( $period, $full );
439
    }
440
441
    /**
442
	 * Get the recurring interval.
443
	 *
444
	 * @since 1.0.19
445
	 * @param  string $context View or edit context.
446
	 * @return int
447
	 */
448
	public function get_recurring_interval( $context = 'view' ) {
449
        return (int) $this->get_prop( 'recurring_interval', $context );
450
    }
451
452
    /**
453
	 * Get the recurring limit.
454
	 *
455
	 * @since 1.0.19
456
	 * @param  string $context View or edit context.
457
	 * @return int
458
	 */
459
	public function get_recurring_limit( $context = 'view' ) {
460
        return (int) $this->get_prop( 'recurring_limit', $context );
461
    }
462
463
    /**
464
	 * Checks if we have a free trial.
465
	 *
466
	 * @since 1.0.19
467
	 * @param  string $context View or edit context.
468
	 * @return string
469
	 */
470
	public function get_is_free_trial( $context = 'view' ) {
471
        return $this->get_prop( 'is_free_trial', $context );
472
    }
473
474
    /**
475
	 * Alias for self::get_is_free_trial().
476
	 *
477
	 * @since 1.0.19
478
	 * @param  string $context View or edit context.
479
	 * @return string
480
	 */
481
	public function get_free_trial( $context = 'view' ) {
482
        return $this->get_is_free_trial( $context );
483
    }
484
485
    /**
486
	 * Get the trial period.
487
	 *
488
	 * @since 1.0.19
489
	 * @param  bool $full Return abbreviation or in full.
490
	 * @return string
491
	 */
492
	public function get_trial_period( $full = false ) {
493
        $period = $this->get_prop( 'trial_period', 'view' );
494
495
        if ( $full && ! is_bool( $full ) ) {
0 ignored issues
show
introduced by
The condition is_bool($full) is always true.
Loading history...
496
            $full = false;
497
        }
498
499
        return getpaid_sanitize_recurring_period( $period, $full );
500
    }
501
502
    /**
503
	 * Get the trial interval.
504
	 *
505
	 * @since 1.0.19
506
	 * @param  string $context View or edit context.
507
	 * @return string
508
	 */
509
	public function get_trial_interval( $context = 'view' ) {
510
        return (int) $this->get_prop( 'trial_interval', $context );
511
    }
512
513
    /**
514
	 * Get the sign up fee.
515
	 *
516
	 * @since 1.0.19
517
	 * @param  string $context View or edit context.
518
	 * @return float
519
	 */
520
	public function get_signup_fee( $context = 'view' ) {
521
        return $this->get_prop( 'signup_fee', $context );
522
    }
523
524
    /**
525
     * Margic method for retrieving a property.
526
     */
527
    public function __get( $key ) {
528
529
        // Check if we have a helper method for that.
530
        if ( method_exists( $this, 'get_' . $key ) ) {
531
            return call_user_func( array( $this, 'get_' . $key ) );
532
        }
533
        
534
        // Check if the key is in the associated $post object.
535
        if ( ! empty( $this->post ) && isset( $this->post->$key ) ) {
536
            return $this->post->$key;
537
        }
538
539
        return $this->get_prop( $key );
540
541
    }
542
543
    /*
544
	|--------------------------------------------------------------------------
545
	| Setters
546
	|--------------------------------------------------------------------------
547
	|
548
	| Functions for setting order data. These should not update anything in the
549
	| database itself and should only change what is stored in the class
550
	| object.
551
    */
552
    
553
    /**
554
	 * Set parent order ID.
555
	 *
556
	 * @since 1.0.19
557
	 */
558
	public function set_parent_id( $value ) {
559
		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
560
			return;
561
		}
562
		$this->set_prop( 'parent_id', absint( $value ) );
563
	}
564
565
    /**
566
	 * Sets item status.
567
	 *
568
	 * @since 1.0.19
569
	 * @param  string $status New status.
570
	 * @return array details of change.
571
	 */
572
	public function set_status( $status ) {
573
        $old_status = $this->get_status();
574
        
575
        $this->set_prop( 'status', $status );
576
577
		return array(
578
			'from' => $old_status,
579
			'to'   => $status,
580
		);
581
    }
582
583
    /**
584
	 * Set plugin version when the item was created.
585
	 *
586
	 * @since 1.0.19
587
	 * @param string $value Value to set.
588
	 */
589
	public function set_version( $value ) {
590
		return $this->set_prop( 'version', $value );
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->set_prop('version', $value) targeting GetPaid_Data::set_prop() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
591
    }
592
593
    /**
594
	 * Set date when the item was created.
595
	 *
596
	 * @since 1.0.19
597
	 * @param string $value Value to set.
598
	 */
599
	public function set_date_created( $value ) {
600
		return $this->set_prop( 'date_created', $value );
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->set_prop('date_created', $value) targeting GetPaid_Data::set_prop() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
601
    }
602
603
    /**
604
	 * Set date when the item was last modified.
605
	 *
606
	 * @since 1.0.19
607
	 * @param string $value Value to set.
608
	 */
609
	public function set_date_modified( $value ) {
610
		return $this->set_prop( 'date_modified', $value );
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->set_prop('date_modified', $value) targeting GetPaid_Data::set_prop() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
611
    }
612
613
    /**
614
	 * Set the item name.
615
	 *
616
	 * @since 1.0.19
617
	 * @param  string $value New name.
618
	 * @return string
619
	 */
620
	public function set_name( $value ) {
621
		return $this->set_prop( 'name', $value );
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->set_prop('name', $value) targeting GetPaid_Data::set_prop() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
622
    }
623
624
    /**
625
	 * Alias of self::set_name().
626
	 *
627
	 * @since 1.0.19
628
	 * @param  string $value New name.
629
	 * @return string
630
	 */
631
	public function set_title( $value ) {
632
		return $this->set_name( $value );
633
    }
634
635
    /**
636
	 * Set the item description.
637
	 *
638
	 * @since 1.0.19
639
	 * @param  string $value New description.
640
	 * @return string
641
	 */
642
	public function set_description( $value ) {
643
		return $this->set_prop( 'description', $value );
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->set_prop('description', $value) targeting GetPaid_Data::set_prop() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
644
    }
645
646
    /**
647
	 * Alias of self::set_description().
648
	 *
649
	 * @since 1.0.19
650
	 * @param  string $value New description.
651
	 * @return string
652
	 */
653
	public function set_excerpt( $value ) {
654
		return $this->set_description( $value );
655
    }
656
657
    /**
658
	 * Alias of self::get_description().
659
	 *
660
	 * @since 1.0.19
661
	 * @param  string $value New description.
662
	 */
663
	public function set_summary( $value ) {
664
		return $this->set_description( $value );
665
    }
666
667
    /**
668
	 * Set the owner of the item.
669
	 *
670
	 * @since 1.0.19
671
	 * @param  int $value New author.
672
	 */
673
	public function set_author( $value ) {
674
		$this->set_prop( 'author', (int) $value );
675
    }
676
677
    /**
678
	 * Set the price of the item.
679
	 *
680
	 * @since 1.0.19
681
	 * @param  float $value New price.
682
	 * @return string
683
	 */
684
	public function set_price( $value ) {
685
        $this->set_prop( 'price', wpinv_sanitize_amount( $value ) );
686
    }
687
688
    /**
689
	 * Set the VAT rule of the item.
690
	 *
691
	 * @since 1.0.19
692
	 * @param  string $value new rule.
693
	 */
694
	public function set_vat_rule( $value ) {
695
        $this->set_prop( 'price', $value );
696
    }
697
698
    /**
699
	 * Set the VAT class of the item.
700
	 *
701
	 * @since 1.0.19
702
	 * @param  string $value new class.
703
	 */
704
	public function set_vat_class( $value ) {
705
        $this->set_prop( 'vat_class', $value );
706
    }
707
708
    /**
709
	 * Set the type of the item.
710
	 *
711
	 * @since 1.0.19
712
	 * @param  string $value new item type.
713
	 * @return string
714
	 */
715
	public function set_type( $value ) {
716
717
        if ( empty( $value ) ) {
718
            $value = 'custom';
719
        }
720
721
        $this->set_prop( 'type', $value );
722
    }
723
724
    /**
725
	 * Set the custom id of the item.
726
	 *
727
	 * @since 1.0.19
728
	 * @param  string $value new custom id.
729
	 */
730
	public function set_custom_id( $value ) {
731
        $this->set_prop( 'custom_id', $value );
732
    }
733
734
    /**
735
	 * Set the custom name of the item.
736
	 *
737
	 * @since 1.0.19
738
	 * @param  string $value new custom id.
739
	 */
740
	public function set_custom_name( $value ) {
741
        $this->set_prop( 'custom_name', $value );
742
    }
743
744
    /**
745
	 * Set the custom singular name of the item.
746
	 *
747
	 * @since 1.0.19
748
	 * @param  string $value new custom id.
749
	 */
750
	public function set_custom_singular_name( $value ) {
751
        $this->set_prop( 'custom_singular_name', $value );
752
    }
753
754
    /**
755
	 * Sets if an item is editable..
756
	 *
757
	 * @since 1.0.19
758
	 * @param  bool $value whether or not the item is editable.
759
	 */
760
	public function set_is_editable( $value ) {
761
        $this->set_prop( 'is_editable', (int) $value );
762
    }
763
764
    /**
765
	 * Sets if dynamic pricing is enabled.
766
	 *
767
	 * @since 1.0.19
768
	 * @param  bool $value whether or not dynamic pricing is allowed.
769
	 */
770
	public function set_is_dynamic_pricing( $value ) {
771
        $this->get_prop( 'is_dynamic_pricing', (int) $value );
772
    }
773
774
    /**
775
	 * Sets the minimum price if dynamic pricing is enabled.
776
	 *
777
	 * @since 1.0.19
778
	 * @param  float $value minimum price.
779
	 */
780
	public function set_minimum_price( $value ) {
781
        $this->set_prop( 'minimum_price',  wpinv_sanitize_amount( $value ) );
782
    }
783
784
    /**
785
	 * Sets if this is a recurring item.
786
	 *
787
	 * @since 1.0.19
788
	 * @param  bool $value whether or not dynamic pricing is allowed.
789
	 */
790
	public function set_is_recurring( $value ) {
791
        $this->set_prop( 'is_recurring', (int) $value );
792
    }
793
794
    /**
795
	 * Set the recurring period.
796
	 *
797
	 * @since 1.0.19
798
	 * @param  string $value new period.
799
	 */
800
	public function set_recurring_period( $value ) {
801
        $this->set_prop( 'recurring_period', $value );
802
    }
803
804
    /**
805
	 * Set the recurring interval.
806
	 *
807
	 * @since 1.0.19
808
	 * @param  int $value recurring interval.
809
	 */
810
	public function set_recurring_interval( $value ) {
811
        return $this->set_prop( 'recurring_interval', (int) $value );
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->set_prop('recurri...interval', (int)$value) targeting GetPaid_Data::set_prop() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
812
    }
813
814
    /**
815
	 * Get the recurring limit.
816
	 * @since 1.0.19
817
	 * @param  int $value The recurring limit.
818
	 * @return int
819
	 */
820
	public function set_recurring_limit( $value ) {
821
        $this->get_prop( 'recurring_limit', (int) $value );
822
    }
823
824
    /**
825
	 * Checks if we have a free trial.
826
	 *
827
	 * @since 1.0.19
828
	 * @param  bool $value whether or not it has a free trial.
829
	 */
830
	public function set_is_free_trial( $value ) {
831
        $this->set_prop( 'is_free_trial', (int) $value );
832
    }
833
834
    /**
835
	 * Set the trial period.
836
	 *
837
	 * @since 1.0.19
838
	 * @param  string $value trial period.
839
	 */
840
	public function set_trial_period( $value ) {
841
        $this->set_prop( 'trial_period', $value );
842
    }
843
844
    /**
845
	 * Set the trial interval.
846
	 *
847
	 * @since 1.0.19
848
	 * @param  int $value trial interval.
849
	 */
850
	public function Set_trial_interval( $value ) {
851
        $this->set_prop( 'trial_interval', $value );
852
    }
853
854
    /**
855
	 * Set the sign up fee.
856
	 *
857
	 * @since 1.0.19
858
	 * @param  float $value The signup fee.
859
	 */
860
	public function set_signup_fee( $value ) {
861
        $this->set_prop( 'signup_fee', $value );
862
    }
863
864
    /**
865
     * Create an item. For backwards compatibilty.
866
     * 
867
     * @deprecated
868
     */
869
    public function create( $data = array(), $wp_error = false ) {
870
        $this->save();
871
    }
872
873
    /**
874
     * Updates an item. For backwards compatibilty.
875
     * 
876
     * @deprecated
877
     */
878
    public function update( $data = array(), $wp_error = false ) {
879
        $this->save();
880
    }
881
882
    /*
883
	|--------------------------------------------------------------------------
884
	| Conditionals
885
	|--------------------------------------------------------------------------
886
	|
887
	| Checks if a condition is true or false.
888
	|
889
	*/
890
891
    /**
892
	 * Checks whether the item is recurring.
893
	 *
894
	 * @since 1.0.19
895
	 * @return bool
896
	 */
897
	public function is_recurring() {
898
        (bool) $this->get_is_recurring();
899
    }
900
901
    /**
902
	 * Checks whether the item has a free trial.
903
	 *
904
	 * @since 1.0.19
905
	 * @return bool
906
	 */
907
    public function has_free_trial() {
908
        $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false;
909
910
        return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this );
911
    }
912
913
    /**
914
	 * Checks whether the item has a sign up fee.
915
	 *
916
	 * @since 1.0.19
917
	 * @return bool
918
	 */
919
    public function has_signup_fee() {
920
        $has_signup_fee = $this->is_recurring() && $this->get_signup_fee() > 0 ? true : false;
921
922
        return (bool) apply_filters( 'wpinv_item_has_signup_fee', $has_signup_fee, $this->ID, $this );
923
    }
924
925
    /**
926
	 * Checks whether the item is free.
927
	 *
928
	 * @since 1.0.19
929
	 * @return bool
930
	 */
931
    public function is_free() {
932
        $price   = (float) $this->get_price();
933
        $is_free = $price == 0;
934
935
        return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID );
936
937
    }
938
939
    /**
940
	 * Checks the item status against a passed in status.
941
	 *
942
	 * @param array|string $status Status to check.
943
	 * @return bool
944
	 */
945
	public function has_status( $status ) {
946
		return apply_filters( 'getpaid_item_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status, $this, $status );
947
    }
948
    
949
    /**
950
	 * Checks the item type against a passed in types.
951
	 *
952
	 * @param array|string $type Type to check.
953
	 * @return bool
954
	 */
955
	public function is_type( $type ) {
956
		return apply_filters( 'getpaid_item_is_type', ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type, $this, $type );
957
	}
958
959
    /**
960
	 * Checks whether the item is editable.
961
	 *
962
	 * @since 1.0.19
963
	 * @return bool
964
	 */
965
    public function is_editable() {
966
        $is_editable = (int) $this->get_is_editable();
967
        return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID );
968
    }
969
970
971
    /**
972
	 * Checks whether the item is purchasable.
973
	 *
974
	 * @since 1.0.19
975
	 * @return bool
976
	 */
977
    public function can_purchase() {
978
        $can_purchase = null != $this->get_id();
979
980
        if ( ! current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) {
0 ignored issues
show
Bug Best Practice introduced by
The property post_status does not exist on WPInv_Item. Since you implemented __get, consider adding a @property annotation.
Loading history...
981
            $can_purchase = false;
982
        }
983
984
        return (bool) apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this );
985
    }
986
987
    /**
988
	 * Checks whether the item supports dynamic pricing.
989
	 *
990
	 * @since 1.0.19
991
	 * @return bool
992
	 */
993
    public function supports_dynamic_pricing() {
994
        return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this );
995
    }
996
}
997