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