Passed
Push — master ( abdd42...378b1c )
by Brian
20:25 queued 15:01
created
includes/data-stores/class-getpaid-data-store-wp.php 1 patch
Indentation   +338 added lines, -338 removed lines patch added patch discarded remove patch
@@ -14,346 +14,346 @@
 block discarded – undo
14 14
  */
15 15
 class GetPaid_Data_Store_WP {
16 16
 
17
-	/**
18
-	 * Meta type. This should match up with
19
-	 * the types available at https://developer.wordpress.org/reference/functions/add_metadata/.
20
-	 * WP defines 'post', 'user', 'comment', and 'term'.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	protected $meta_type = 'post';
25
-
26
-	/**
27
-	 * This only needs set if you are using a custom metadata type.
28
-	 *
29
-	 * @var string
30
-	 */
31
-	protected $object_id_field_for_meta = '';
32
-
33
-	/**
34
-	 * Data stored in meta keys, but not considered "meta" for an object.
35
-	 *
36
-	 * @since 1.0.19
37
-	 *
38
-	 * @var array
39
-	 */
40
-	protected $internal_meta_keys = array();
41
-
42
-	/**
43
-	 * Meta data which should exist in the DB, even if empty.
44
-	 *
45
-	 * @since 1.0.19
46
-	 *
47
-	 * @var array
48
-	 */
49
-	protected $must_exist_meta_keys = array();
50
-
51
-	/**
52
-	 * A map of meta keys to data props.
53
-	 *
54
-	 * @since 1.0.19
55
-	 *
56
-	 * @var array
57
-	 */
58
-	protected $meta_key_to_props = array();
59
-
60
-	/**
61
-	 * Returns an array of meta for an object.
62
-	 *
63
-	 * @since  1.0.19
64
-	 * @param  GetPaid_Data $object GetPaid_Data object.
65
-	 * @return array
66
-	 */
67
-	public function read_meta( &$object ) {
68
-		global $wpdb;
69
-		$db_info       = $this->get_db_info();
70
-		$raw_meta_data = $wpdb->get_results(
71
-			$wpdb->prepare(
72
-				"SELECT {$db_info['meta_id_field']} as meta_id, meta_key, meta_value
17
+    /**
18
+     * Meta type. This should match up with
19
+     * the types available at https://developer.wordpress.org/reference/functions/add_metadata/.
20
+     * WP defines 'post', 'user', 'comment', and 'term'.
21
+     *
22
+     * @var string
23
+     */
24
+    protected $meta_type = 'post';
25
+
26
+    /**
27
+     * This only needs set if you are using a custom metadata type.
28
+     *
29
+     * @var string
30
+     */
31
+    protected $object_id_field_for_meta = '';
32
+
33
+    /**
34
+     * Data stored in meta keys, but not considered "meta" for an object.
35
+     *
36
+     * @since 1.0.19
37
+     *
38
+     * @var array
39
+     */
40
+    protected $internal_meta_keys = array();
41
+
42
+    /**
43
+     * Meta data which should exist in the DB, even if empty.
44
+     *
45
+     * @since 1.0.19
46
+     *
47
+     * @var array
48
+     */
49
+    protected $must_exist_meta_keys = array();
50
+
51
+    /**
52
+     * A map of meta keys to data props.
53
+     *
54
+     * @since 1.0.19
55
+     *
56
+     * @var array
57
+     */
58
+    protected $meta_key_to_props = array();
59
+
60
+    /**
61
+     * Returns an array of meta for an object.
62
+     *
63
+     * @since  1.0.19
64
+     * @param  GetPaid_Data $object GetPaid_Data object.
65
+     * @return array
66
+     */
67
+    public function read_meta( &$object ) {
68
+        global $wpdb;
69
+        $db_info       = $this->get_db_info();
70
+        $raw_meta_data = $wpdb->get_results(
71
+            $wpdb->prepare(
72
+                "SELECT {$db_info['meta_id_field']} as meta_id, meta_key, meta_value
73 73
 				FROM {$db_info['table']}
74 74
 				WHERE {$db_info['object_id_field']} = %d
75 75
 				ORDER BY {$db_info['meta_id_field']}",
76
-				$object->get_id()
77
-			)
78
-		);
79
-
80
-		$this->internal_meta_keys = array_merge( array_map( array( $this, 'prefix_key' ), $object->get_data_keys() ), $this->internal_meta_keys );
81
-		$meta_data                = array_filter( $raw_meta_data, array( $this, 'exclude_internal_meta_keys' ) );
82
-		return apply_filters( "getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this );
83
-	}
84
-
85
-	/**
86
-	 * Deletes meta based on meta ID.
87
-	 *
88
-	 * @since  1.0.19
89
-	 * @param  GetPaid_Data  $object GetPaid_Data object.
90
-	 * @param  stdClass $meta (containing at least ->id).
91
-	 */
92
-	public function delete_meta( &$object, $meta ) {
93
-		delete_metadata_by_mid( $this->meta_type, $meta->id );
94
-	}
95
-
96
-	/**
97
-	 * Add new piece of meta.
98
-	 *
99
-	 * @since  1.0.19
100
-	 * @param  GetPaid_Data  $object GetPaid_Data object.
101
-	 * @param  stdClass $meta (containing ->key and ->value).
102
-	 * @return int meta ID
103
-	 */
104
-	public function add_meta( &$object, $meta ) {
105
-		return add_metadata( $this->meta_type, $object->get_id(), $meta->key, is_string( $meta->value ) ? wp_slash( $meta->value ) : $meta->value, false );
106
-	}
107
-
108
-	/**
109
-	 * Update meta.
110
-	 *
111
-	 * @since  1.0.19
112
-	 * @param  GetPaid_Data  $object GetPaid_Data object.
113
-	 * @param  stdClass $meta (containing ->id, ->key and ->value).
114
-	 */
115
-	public function update_meta( &$object, $meta ) {
116
-		update_metadata_by_mid( $this->meta_type, $meta->id, $meta->value, $meta->key );
117
-	}
118
-
119
-	/**
120
-	 * Table structure is slightly different between meta types, this function will return what we need to know.
121
-	 *
122
-	 * @since  1.0.19
123
-	 * @return array Array elements: table, object_id_field, meta_id_field
124
-	 */
125
-	protected function get_db_info() {
126
-		global $wpdb;
127
-
128
-		$meta_id_field = 'meta_id'; // users table calls this umeta_id so we need to track this as well.
129
-		$table         = $wpdb->prefix;
130
-
131
-		// If we are dealing with a type of metadata that is not a core type, the table should be prefixed.
132
-		if ( ! in_array( $this->meta_type, array( 'post', 'user', 'comment', 'term' ), true ) ) {
133
-			$table .= 'getpaid_';
134
-		}
135
-
136
-		$table          .= $this->meta_type . 'meta';
137
-		$object_id_field = $this->meta_type . '_id';
138
-
139
-		// Figure out our field names.
140
-		if ( 'user' === $this->meta_type ) {
141
-			$meta_id_field = 'umeta_id';
142
-			$table         = $wpdb->usermeta;
143
-		}
144
-
145
-		if ( ! empty( $this->object_id_field_for_meta ) ) {
146
-			$object_id_field = $this->object_id_field_for_meta;
147
-		}
148
-
149
-		return array(
150
-			'table'           => $table,
151
-			'object_id_field' => $object_id_field,
152
-			'meta_id_field'   => $meta_id_field,
153
-		);
154
-	}
155
-
156
-	/**
157
-	 * Internal meta keys we don't want exposed as part of meta_data. This is in
158
-	 * addition to all data props with _ prefix.
159
-	 *
160
-	 * @since 1.0.19
161
-	 *
162
-	 * @param string $key Prefix to be added to meta keys.
163
-	 * @return string
164
-	 */
165
-	protected function prefix_key( $key ) {
166
-		return '_' === substr( $key, 0, 1 ) ? $key : '_' . $key;
167
-	}
168
-
169
-	/**
170
-	 * Callback to remove unwanted meta data.
171
-	 *
172
-	 * @param object $meta Meta object to check if it should be excluded or not.
173
-	 * @return bool
174
-	 */
175
-	protected function exclude_internal_meta_keys( $meta ) {
176
-		return ! in_array( $meta->meta_key, $this->internal_meta_keys, true ) && 0 !== stripos( $meta->meta_key, 'wp_' );
177
-	}
178
-
179
-	/**
180
-	 * Gets a list of props and meta keys that need updated based on change state
181
-	 * or if they are present in the database or not.
182
-	 *
183
-	 * @param  GetPaid_Data $object         The GetPaid_Data object.
184
-	 * @param  array   $meta_key_to_props   A mapping of meta keys => prop names.
185
-	 * @param  string  $meta_type           The internal WP meta type (post, user, etc).
186
-	 * @return array                        A mapping of meta keys => prop names, filtered by ones that should be updated.
187
-	 */
188
-	protected function get_props_to_update( $object, $meta_key_to_props, $meta_type = 'post' ) {
189
-		$props_to_update = array();
190
-		$changed_props   = $object->get_changes();
191
-
192
-		// Props should be updated if they are a part of the $changed array or don't exist yet.
193
-		foreach ( $meta_key_to_props as $meta_key => $prop ) {
194
-			if ( array_key_exists( $prop, $changed_props ) || ! metadata_exists( $meta_type, $object->get_id(), $meta_key ) ) {
195
-				$props_to_update[ $meta_key ] = $prop;
196
-			}
197
-		}
198
-
199
-		return $props_to_update;
200
-	}
201
-
202
-	/**
203
-	 * Read object data.
204
-	 *
205
-	 * @param GetPaid_Data $object GetPaid_Data object.
206
-	 * @param WP_Post   $post_object Post object.
207
-	 * @since 1.0.19
208
-	 */
209
-	protected function read_object_data( &$object, $post_object ) {
210
-		$id    = $object->get_id();
211
-		$props = array();
212
-
213
-		foreach ( $this->meta_key_to_props as $meta_key => $prop ) {
214
-			$props[ $prop ] = get_post_meta( $id, $meta_key, true );
215
-		}
216
-
217
-		// Set object properties.
218
-		$object->set_props( $props );
219
-
220
-		// Gets extra data associated with the object if needed.
221
-		foreach ( $object->get_extra_data_keys() as $key ) {
222
-			$function = 'set_' . $key;
223
-			if ( is_callable( array( $object, $function ) ) ) {
224
-				$object->{$function}( get_post_meta( $object->get_id(), $key, true ) );
225
-			}
226
-		}
227
-	}
228
-
229
-	/**
230
-	 * Helper method that updates all the post meta for an object based on it's settings in the GetPaid_Data class.
231
-	 *
232
-	 * @param GetPaid_Data $object GetPaid_Data object.
233
-	 * @since 1.0.19
234
-	 */
235
-	protected function update_post_meta( &$object ) {
236
-
237
-		$updated_props   = array();
238
-		$props_to_update = $this->get_props_to_update( $object, $this->meta_key_to_props );
239
-		$object_type     = $object->get_object_type();
240
-
241
-		foreach ( $props_to_update as $meta_key => $prop ) {
242
-			$value = $object->{"get_$prop"}( 'edit' );
243
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
244
-
245
-			$updated = $this->update_or_delete_post_meta( $object, $meta_key, $value );
246
-
247
-			if ( $updated ) {
248
-				$updated_props[] = $prop;
249
-			}
250
-		}
251
-
252
-		do_action( "getpaid_{$object_type}_object_updated_props", $object, $updated_props );
253
-	}
254
-
255
-	/**
256
-	 * Update meta data in, or delete it from, the database.
257
-	 *
258
-	 * Avoids storing meta when it's either an empty string or empty array or null.
259
-	 * Other empty values such as numeric 0 should still be stored.
260
-	 * Data-stores can force meta to exist using `must_exist_meta_keys`.
261
-	 *
262
-	 * Note: WordPress `get_metadata` function returns an empty string when meta data does not exist.
263
-	 *
264
-	 * @param GetPaid_Data $object The GetPaid_Data object.
265
-	 * @param string  $meta_key Meta key to update.
266
-	 * @param mixed   $meta_value Value to save.
267
-	 *
268
-	 * @since 1.0.19 Added to prevent empty meta being stored unless required.
269
-	 *
270
-	 * @return bool True if updated/deleted.
271
-	 */
272
-	protected function update_or_delete_post_meta( $object, $meta_key, $meta_value ) {
273
-		if ( in_array( $meta_value, array( array(), '', null ), true ) && ! in_array( $meta_key, $this->must_exist_meta_keys, true ) ) {
274
-			$updated = delete_post_meta( $object->get_id(), $meta_key );
275
-		} else {
276
-			$updated = update_post_meta( $object->get_id(), $meta_key, $meta_value );
277
-		}
278
-
279
-		return (bool) $updated;
280
-	}
281
-
282
-	/**
283
-	 * Return list of internal meta keys.
284
-	 *
285
-	 * @since 1.0.19
286
-	 * @return array
287
-	 */
288
-	public function get_internal_meta_keys() {
289
-		return $this->internal_meta_keys;
290
-	}
291
-
292
-	/**
293
-	 * Clear any caches.
294
-	 *
295
-	 * @param GetPaid_Data $object GetPaid_Data object.
296
-	 * @since 1.0.19
297
-	 */
298
-	protected function clear_caches( &$object ) {
299
-		clean_post_cache( $object->get_id() );
300
-	}
301
-
302
-	/**
303
-	 * Method to delete a data object from the database.
304
-	 *
305
-	 * @param GetPaid_Data $object GetPaid_Data object.
306
-	 * @param array    $args Array of args to pass to the delete method.
307
-	 *
308
-	 * @return void
309
-	 */
310
-	public function delete( &$object, $args = array() ) {
311
-		$id          = $object->get_id();
312
-		$object_type = $object->get_object_type();
313
-
314
-		if ( 'invoice' == $object_type ) {
315
-			$object_type = $object->get_type();
316
-		}
317
-
318
-		$args        = wp_parse_args(
319
-			$args,
320
-			array(
321
-				'force_delete' => false,
322
-			)
323
-		);
324
-
325
-		if ( ! $id ) {
326
-			return;
327
-		}
328
-
329
-		if ( $args['force_delete'] ) {
330
-			wp_delete_post( $id, true );
331
-			$object->set_id( 0 );
332
-			do_action( "getpaid_delete_$object_type", $id );
333
-		} else {
334
-			wp_trash_post( $id );
335
-			$object->set_status( 'trash' );
336
-			do_action( "getpaid_trash_$object_type", $id );
337
-		}
338
-	}
339
-
340
-	/**
341
-	 * Get the status to save to the post object.
342
-	 *
343
-	 *
344
-	 * @since 1.0.19
345
-	 * @param  GetPaid_Data $object GetPaid_Data object.
346
-	 * @return string
347
-	 */
348
-	protected function get_post_status( $object ) {
349
-		$object_status = $object->get_status( 'edit' );
350
-		$object_type   = $object->get_object_type();
351
-
352
-		if ( ! $object_status ) {
353
-			$object_status = apply_filters( "getpaid_default_{$object_type}_status", 'draft' );
354
-		}
355
-
356
-		return $object_status;
357
-	}
76
+                $object->get_id()
77
+            )
78
+        );
79
+
80
+        $this->internal_meta_keys = array_merge( array_map( array( $this, 'prefix_key' ), $object->get_data_keys() ), $this->internal_meta_keys );
81
+        $meta_data                = array_filter( $raw_meta_data, array( $this, 'exclude_internal_meta_keys' ) );
82
+        return apply_filters( "getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this );
83
+    }
84
+
85
+    /**
86
+     * Deletes meta based on meta ID.
87
+     *
88
+     * @since  1.0.19
89
+     * @param  GetPaid_Data  $object GetPaid_Data object.
90
+     * @param  stdClass $meta (containing at least ->id).
91
+     */
92
+    public function delete_meta( &$object, $meta ) {
93
+        delete_metadata_by_mid( $this->meta_type, $meta->id );
94
+    }
95
+
96
+    /**
97
+     * Add new piece of meta.
98
+     *
99
+     * @since  1.0.19
100
+     * @param  GetPaid_Data  $object GetPaid_Data object.
101
+     * @param  stdClass $meta (containing ->key and ->value).
102
+     * @return int meta ID
103
+     */
104
+    public function add_meta( &$object, $meta ) {
105
+        return add_metadata( $this->meta_type, $object->get_id(), $meta->key, is_string( $meta->value ) ? wp_slash( $meta->value ) : $meta->value, false );
106
+    }
107
+
108
+    /**
109
+     * Update meta.
110
+     *
111
+     * @since  1.0.19
112
+     * @param  GetPaid_Data  $object GetPaid_Data object.
113
+     * @param  stdClass $meta (containing ->id, ->key and ->value).
114
+     */
115
+    public function update_meta( &$object, $meta ) {
116
+        update_metadata_by_mid( $this->meta_type, $meta->id, $meta->value, $meta->key );
117
+    }
118
+
119
+    /**
120
+     * Table structure is slightly different between meta types, this function will return what we need to know.
121
+     *
122
+     * @since  1.0.19
123
+     * @return array Array elements: table, object_id_field, meta_id_field
124
+     */
125
+    protected function get_db_info() {
126
+        global $wpdb;
127
+
128
+        $meta_id_field = 'meta_id'; // users table calls this umeta_id so we need to track this as well.
129
+        $table         = $wpdb->prefix;
130
+
131
+        // If we are dealing with a type of metadata that is not a core type, the table should be prefixed.
132
+        if ( ! in_array( $this->meta_type, array( 'post', 'user', 'comment', 'term' ), true ) ) {
133
+            $table .= 'getpaid_';
134
+        }
135
+
136
+        $table          .= $this->meta_type . 'meta';
137
+        $object_id_field = $this->meta_type . '_id';
138
+
139
+        // Figure out our field names.
140
+        if ( 'user' === $this->meta_type ) {
141
+            $meta_id_field = 'umeta_id';
142
+            $table         = $wpdb->usermeta;
143
+        }
144
+
145
+        if ( ! empty( $this->object_id_field_for_meta ) ) {
146
+            $object_id_field = $this->object_id_field_for_meta;
147
+        }
148
+
149
+        return array(
150
+            'table'           => $table,
151
+            'object_id_field' => $object_id_field,
152
+            'meta_id_field'   => $meta_id_field,
153
+        );
154
+    }
155
+
156
+    /**
157
+     * Internal meta keys we don't want exposed as part of meta_data. This is in
158
+     * addition to all data props with _ prefix.
159
+     *
160
+     * @since 1.0.19
161
+     *
162
+     * @param string $key Prefix to be added to meta keys.
163
+     * @return string
164
+     */
165
+    protected function prefix_key( $key ) {
166
+        return '_' === substr( $key, 0, 1 ) ? $key : '_' . $key;
167
+    }
168
+
169
+    /**
170
+     * Callback to remove unwanted meta data.
171
+     *
172
+     * @param object $meta Meta object to check if it should be excluded or not.
173
+     * @return bool
174
+     */
175
+    protected function exclude_internal_meta_keys( $meta ) {
176
+        return ! in_array( $meta->meta_key, $this->internal_meta_keys, true ) && 0 !== stripos( $meta->meta_key, 'wp_' );
177
+    }
178
+
179
+    /**
180
+     * Gets a list of props and meta keys that need updated based on change state
181
+     * or if they are present in the database or not.
182
+     *
183
+     * @param  GetPaid_Data $object         The GetPaid_Data object.
184
+     * @param  array   $meta_key_to_props   A mapping of meta keys => prop names.
185
+     * @param  string  $meta_type           The internal WP meta type (post, user, etc).
186
+     * @return array                        A mapping of meta keys => prop names, filtered by ones that should be updated.
187
+     */
188
+    protected function get_props_to_update( $object, $meta_key_to_props, $meta_type = 'post' ) {
189
+        $props_to_update = array();
190
+        $changed_props   = $object->get_changes();
191
+
192
+        // Props should be updated if they are a part of the $changed array or don't exist yet.
193
+        foreach ( $meta_key_to_props as $meta_key => $prop ) {
194
+            if ( array_key_exists( $prop, $changed_props ) || ! metadata_exists( $meta_type, $object->get_id(), $meta_key ) ) {
195
+                $props_to_update[ $meta_key ] = $prop;
196
+            }
197
+        }
198
+
199
+        return $props_to_update;
200
+    }
201
+
202
+    /**
203
+     * Read object data.
204
+     *
205
+     * @param GetPaid_Data $object GetPaid_Data object.
206
+     * @param WP_Post   $post_object Post object.
207
+     * @since 1.0.19
208
+     */
209
+    protected function read_object_data( &$object, $post_object ) {
210
+        $id    = $object->get_id();
211
+        $props = array();
212
+
213
+        foreach ( $this->meta_key_to_props as $meta_key => $prop ) {
214
+            $props[ $prop ] = get_post_meta( $id, $meta_key, true );
215
+        }
216
+
217
+        // Set object properties.
218
+        $object->set_props( $props );
219
+
220
+        // Gets extra data associated with the object if needed.
221
+        foreach ( $object->get_extra_data_keys() as $key ) {
222
+            $function = 'set_' . $key;
223
+            if ( is_callable( array( $object, $function ) ) ) {
224
+                $object->{$function}( get_post_meta( $object->get_id(), $key, true ) );
225
+            }
226
+        }
227
+    }
228
+
229
+    /**
230
+     * Helper method that updates all the post meta for an object based on it's settings in the GetPaid_Data class.
231
+     *
232
+     * @param GetPaid_Data $object GetPaid_Data object.
233
+     * @since 1.0.19
234
+     */
235
+    protected function update_post_meta( &$object ) {
236
+
237
+        $updated_props   = array();
238
+        $props_to_update = $this->get_props_to_update( $object, $this->meta_key_to_props );
239
+        $object_type     = $object->get_object_type();
240
+
241
+        foreach ( $props_to_update as $meta_key => $prop ) {
242
+            $value = $object->{"get_$prop"}( 'edit' );
243
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
244
+
245
+            $updated = $this->update_or_delete_post_meta( $object, $meta_key, $value );
246
+
247
+            if ( $updated ) {
248
+                $updated_props[] = $prop;
249
+            }
250
+        }
251
+
252
+        do_action( "getpaid_{$object_type}_object_updated_props", $object, $updated_props );
253
+    }
254
+
255
+    /**
256
+     * Update meta data in, or delete it from, the database.
257
+     *
258
+     * Avoids storing meta when it's either an empty string or empty array or null.
259
+     * Other empty values such as numeric 0 should still be stored.
260
+     * Data-stores can force meta to exist using `must_exist_meta_keys`.
261
+     *
262
+     * Note: WordPress `get_metadata` function returns an empty string when meta data does not exist.
263
+     *
264
+     * @param GetPaid_Data $object The GetPaid_Data object.
265
+     * @param string  $meta_key Meta key to update.
266
+     * @param mixed   $meta_value Value to save.
267
+     *
268
+     * @since 1.0.19 Added to prevent empty meta being stored unless required.
269
+     *
270
+     * @return bool True if updated/deleted.
271
+     */
272
+    protected function update_or_delete_post_meta( $object, $meta_key, $meta_value ) {
273
+        if ( in_array( $meta_value, array( array(), '', null ), true ) && ! in_array( $meta_key, $this->must_exist_meta_keys, true ) ) {
274
+            $updated = delete_post_meta( $object->get_id(), $meta_key );
275
+        } else {
276
+            $updated = update_post_meta( $object->get_id(), $meta_key, $meta_value );
277
+        }
278
+
279
+        return (bool) $updated;
280
+    }
281
+
282
+    /**
283
+     * Return list of internal meta keys.
284
+     *
285
+     * @since 1.0.19
286
+     * @return array
287
+     */
288
+    public function get_internal_meta_keys() {
289
+        return $this->internal_meta_keys;
290
+    }
291
+
292
+    /**
293
+     * Clear any caches.
294
+     *
295
+     * @param GetPaid_Data $object GetPaid_Data object.
296
+     * @since 1.0.19
297
+     */
298
+    protected function clear_caches( &$object ) {
299
+        clean_post_cache( $object->get_id() );
300
+    }
301
+
302
+    /**
303
+     * Method to delete a data object from the database.
304
+     *
305
+     * @param GetPaid_Data $object GetPaid_Data object.
306
+     * @param array    $args Array of args to pass to the delete method.
307
+     *
308
+     * @return void
309
+     */
310
+    public function delete( &$object, $args = array() ) {
311
+        $id          = $object->get_id();
312
+        $object_type = $object->get_object_type();
313
+
314
+        if ( 'invoice' == $object_type ) {
315
+            $object_type = $object->get_type();
316
+        }
317
+
318
+        $args        = wp_parse_args(
319
+            $args,
320
+            array(
321
+                'force_delete' => false,
322
+            )
323
+        );
324
+
325
+        if ( ! $id ) {
326
+            return;
327
+        }
328
+
329
+        if ( $args['force_delete'] ) {
330
+            wp_delete_post( $id, true );
331
+            $object->set_id( 0 );
332
+            do_action( "getpaid_delete_$object_type", $id );
333
+        } else {
334
+            wp_trash_post( $id );
335
+            $object->set_status( 'trash' );
336
+            do_action( "getpaid_trash_$object_type", $id );
337
+        }
338
+    }
339
+
340
+    /**
341
+     * Get the status to save to the post object.
342
+     *
343
+     *
344
+     * @since 1.0.19
345
+     * @param  GetPaid_Data $object GetPaid_Data object.
346
+     * @return string
347
+     */
348
+    protected function get_post_status( $object ) {
349
+        $object_status = $object->get_status( 'edit' );
350
+        $object_type   = $object->get_object_type();
351
+
352
+        if ( ! $object_status ) {
353
+            $object_status = apply_filters( "getpaid_default_{$object_type}_status", 'draft' );
354
+        }
355
+
356
+        return $object_status;
357
+    }
358 358
 
359 359
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-payment-form-data-store.php 1 patch
Indentation   +169 added lines, -169 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,179 +14,179 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class GetPaid_Payment_Form_Data_Store extends GetPaid_Data_Store_WP {
16 16
 
17
-	/**
18
-	 * Data stored in meta keys, but not considered "meta" for a form.
19
-	 *
20
-	 * @since 1.0.19
21
-	 * @var array
22
-	 */
23
-	protected $internal_meta_keys = array(
24
-		'wpinv_form_elements',
25
-		'wpinv_form_items',
26
-		'wpinv_form_earned',
27
-		'wpinv_form_refunded',
28
-		'wpinv_form_cancelled',
29
-		'wpinv_form_failed'
30
-	);
31
-
32
-	/**
33
-	 * A map of meta keys to data props.
34
-	 *
35
-	 * @since 1.0.19
36
-	 *
37
-	 * @var array
38
-	 */
39
-	protected $meta_key_to_props = array(
40
-		'wpinv_form_elements'  => 'elements',
41
-		'wpinv_form_items'     => 'items',
42
-		'wpinv_form_earned'    => 'earned',
43
-		'wpinv_form_refunded'  => 'refunded',
44
-		'wpinv_form_cancelled' => 'cancelled',
45
-		'wpinv_form_failed'    => 'failed',
46
-	);
47
-
48
-	/*
17
+    /**
18
+     * Data stored in meta keys, but not considered "meta" for a form.
19
+     *
20
+     * @since 1.0.19
21
+     * @var array
22
+     */
23
+    protected $internal_meta_keys = array(
24
+        'wpinv_form_elements',
25
+        'wpinv_form_items',
26
+        'wpinv_form_earned',
27
+        'wpinv_form_refunded',
28
+        'wpinv_form_cancelled',
29
+        'wpinv_form_failed'
30
+    );
31
+
32
+    /**
33
+     * A map of meta keys to data props.
34
+     *
35
+     * @since 1.0.19
36
+     *
37
+     * @var array
38
+     */
39
+    protected $meta_key_to_props = array(
40
+        'wpinv_form_elements'  => 'elements',
41
+        'wpinv_form_items'     => 'items',
42
+        'wpinv_form_earned'    => 'earned',
43
+        'wpinv_form_refunded'  => 'refunded',
44
+        'wpinv_form_cancelled' => 'cancelled',
45
+        'wpinv_form_failed'    => 'failed',
46
+    );
47
+
48
+    /*
49 49
 	|--------------------------------------------------------------------------
50 50
 	| CRUD Methods
51 51
 	|--------------------------------------------------------------------------
52 52
 	*/
53 53
 
54
-	/**
55
-	 * Method to create a new form in the database.
56
-	 *
57
-	 * @param GetPaid_Payment_Form $form Form object.
58
-	 */
59
-	public function create( &$form ) {
60
-		$form->set_version( WPINV_VERSION );
61
-		$form->set_date_created( current_time('mysql') );
62
-
63
-		// Create a new post.
64
-		$id = wp_insert_post(
65
-			apply_filters(
66
-				'getpaid_new_payment_form_data',
67
-				array(
68
-					'post_date'     => $form->get_date_created( 'edit' ),
69
-					'post_type'     => 'wpi_payment_form',
70
-					'post_status'   => $this->get_post_status( $form ),
71
-					'ping_status'   => 'closed',
72
-					'post_author'   => $form->get_author( 'edit' ),
73
-					'post_title'    => $form->get_name( 'edit' ),
74
-				)
75
-			),
76
-			true
77
-		);
78
-
79
-		if ( $id && ! is_wp_error( $id ) ) {
80
-			$form->set_id( $id );
81
-			$this->update_post_meta( $form );
82
-			$form->save_meta_data();
83
-			$form->apply_changes();
84
-			$this->clear_caches( $form );
85
-			do_action( 'getpaid_create_payment_form', $form->get_id(), $form );
86
-			return true;
87
-		}
88
-
89
-		if ( is_wp_error( $id ) ) {
90
-			$form->last_error = $id->get_error_message();
91
-		}
92
-
93
-		return false;
94
-	}
95
-
96
-	/**
97
-	 * Method to read a form from the database.
98
-	 *
99
-	 * @param GetPaid_Payment_Form $form Form object.
100
-	 *
101
-	 */
102
-	public function read( &$form ) {
103
-
104
-		$form->set_defaults();
105
-		$form_object = get_post( $form->get_id() );
106
-
107
-		if ( ! $form->get_id() || ! $form_object || $form_object->post_type != 'wpi_payment_form' ) {
108
-			$form->last_error = __( 'Invalid form.', 'invoicing' );
109
-			$form->set_id( 0 );
110
-			return false;
111
-		}
112
-
113
-		$form->set_props(
114
-			array(
115
-				'date_created'  => 0 < $form_object->post_date ? $form_object->post_date : null,
116
-				'date_modified' => 0 < $form_object->post_modified ? $form_object->post_modified : null,
117
-				'status'        => $form_object->post_status,
118
-				'name'          => $form_object->post_title,
119
-				'author'        => $form_object->post_author,
120
-			)
121
-		);
122
-
123
-		$this->read_object_data( $form, $form_object );
124
-		$form->read_meta_data();
125
-		$form->set_object_read( true );
126
-		do_action( 'getpaid_read_payment_form', $form->get_id(), $form );
127
-
128
-	}
129
-
130
-	/**
131
-	 * Method to update a form in the database.
132
-	 *
133
-	 * @param GetPaid_Payment_Form $form Form object.
134
-	 */
135
-	public function update( &$form ) {
136
-		$form->save_meta_data();
137
-		$form->set_version( WPINV_VERSION );
138
-
139
-		if ( null === $form->get_date_created( 'edit' ) ) {
140
-			$form->set_date_created(  current_time('mysql') );
141
-		}
142
-
143
-		// Grab the current status so we can compare.
144
-		$previous_status = get_post_status( $form->get_id() );
145
-
146
-		$changes = $form->get_changes();
147
-
148
-		// Only update the post when the post data changes.
149
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author' ), array_keys( $changes ) ) ) {
150
-			$post_data = array(
151
-				'post_date'         => $form->get_date_created( 'edit' ),
152
-				'post_status'       => $form->get_status( 'edit' ),
153
-				'post_title'        => $form->get_name( 'edit' ),
154
-				'post_author'       => $form->get_author( 'edit' ),
155
-				'post_modified'     => $form->get_date_modified( 'edit' ),
156
-			);
157
-
158
-			/**
159
-			 * When updating this object, to prevent infinite loops, use $wpdb
160
-			 * to update data, since wp_update_post spawns more calls to the
161
-			 * save_post action.
162
-			 *
163
-			 * This ensures hooks are fired by either WP itself (admin screen save),
164
-			 * or an update purely from CRUD.
165
-			 */
166
-			if ( doing_action( 'save_post' ) ) {
167
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $form->get_id() ) );
168
-				clean_post_cache( $form->get_id() );
169
-			} else {
170
-				wp_update_post( array_merge( array( 'ID' => $form->get_id() ), $post_data ) );
171
-			}
172
-			$form->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
173
-		}
174
-		$this->update_post_meta( $form );
175
-		$form->apply_changes();
176
-		$this->clear_caches( $form );
177
-
178
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
179
-		$new_status = $form->get_status( 'edit' );
180
-
181
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
182
-			do_action( 'getpaid_new_payment_form', $form->get_id(), $form );
183
-		} else {
184
-			do_action( 'getpaid_update_payment_form', $form->get_id(), $form );
185
-		}
186
-
187
-	}
188
-
189
-	/*
54
+    /**
55
+     * Method to create a new form in the database.
56
+     *
57
+     * @param GetPaid_Payment_Form $form Form object.
58
+     */
59
+    public function create( &$form ) {
60
+        $form->set_version( WPINV_VERSION );
61
+        $form->set_date_created( current_time('mysql') );
62
+
63
+        // Create a new post.
64
+        $id = wp_insert_post(
65
+            apply_filters(
66
+                'getpaid_new_payment_form_data',
67
+                array(
68
+                    'post_date'     => $form->get_date_created( 'edit' ),
69
+                    'post_type'     => 'wpi_payment_form',
70
+                    'post_status'   => $this->get_post_status( $form ),
71
+                    'ping_status'   => 'closed',
72
+                    'post_author'   => $form->get_author( 'edit' ),
73
+                    'post_title'    => $form->get_name( 'edit' ),
74
+                )
75
+            ),
76
+            true
77
+        );
78
+
79
+        if ( $id && ! is_wp_error( $id ) ) {
80
+            $form->set_id( $id );
81
+            $this->update_post_meta( $form );
82
+            $form->save_meta_data();
83
+            $form->apply_changes();
84
+            $this->clear_caches( $form );
85
+            do_action( 'getpaid_create_payment_form', $form->get_id(), $form );
86
+            return true;
87
+        }
88
+
89
+        if ( is_wp_error( $id ) ) {
90
+            $form->last_error = $id->get_error_message();
91
+        }
92
+
93
+        return false;
94
+    }
95
+
96
+    /**
97
+     * Method to read a form from the database.
98
+     *
99
+     * @param GetPaid_Payment_Form $form Form object.
100
+     *
101
+     */
102
+    public function read( &$form ) {
103
+
104
+        $form->set_defaults();
105
+        $form_object = get_post( $form->get_id() );
106
+
107
+        if ( ! $form->get_id() || ! $form_object || $form_object->post_type != 'wpi_payment_form' ) {
108
+            $form->last_error = __( 'Invalid form.', 'invoicing' );
109
+            $form->set_id( 0 );
110
+            return false;
111
+        }
112
+
113
+        $form->set_props(
114
+            array(
115
+                'date_created'  => 0 < $form_object->post_date ? $form_object->post_date : null,
116
+                'date_modified' => 0 < $form_object->post_modified ? $form_object->post_modified : null,
117
+                'status'        => $form_object->post_status,
118
+                'name'          => $form_object->post_title,
119
+                'author'        => $form_object->post_author,
120
+            )
121
+        );
122
+
123
+        $this->read_object_data( $form, $form_object );
124
+        $form->read_meta_data();
125
+        $form->set_object_read( true );
126
+        do_action( 'getpaid_read_payment_form', $form->get_id(), $form );
127
+
128
+    }
129
+
130
+    /**
131
+     * Method to update a form in the database.
132
+     *
133
+     * @param GetPaid_Payment_Form $form Form object.
134
+     */
135
+    public function update( &$form ) {
136
+        $form->save_meta_data();
137
+        $form->set_version( WPINV_VERSION );
138
+
139
+        if ( null === $form->get_date_created( 'edit' ) ) {
140
+            $form->set_date_created(  current_time('mysql') );
141
+        }
142
+
143
+        // Grab the current status so we can compare.
144
+        $previous_status = get_post_status( $form->get_id() );
145
+
146
+        $changes = $form->get_changes();
147
+
148
+        // Only update the post when the post data changes.
149
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author' ), array_keys( $changes ) ) ) {
150
+            $post_data = array(
151
+                'post_date'         => $form->get_date_created( 'edit' ),
152
+                'post_status'       => $form->get_status( 'edit' ),
153
+                'post_title'        => $form->get_name( 'edit' ),
154
+                'post_author'       => $form->get_author( 'edit' ),
155
+                'post_modified'     => $form->get_date_modified( 'edit' ),
156
+            );
157
+
158
+            /**
159
+             * When updating this object, to prevent infinite loops, use $wpdb
160
+             * to update data, since wp_update_post spawns more calls to the
161
+             * save_post action.
162
+             *
163
+             * This ensures hooks are fired by either WP itself (admin screen save),
164
+             * or an update purely from CRUD.
165
+             */
166
+            if ( doing_action( 'save_post' ) ) {
167
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $form->get_id() ) );
168
+                clean_post_cache( $form->get_id() );
169
+            } else {
170
+                wp_update_post( array_merge( array( 'ID' => $form->get_id() ), $post_data ) );
171
+            }
172
+            $form->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
173
+        }
174
+        $this->update_post_meta( $form );
175
+        $form->apply_changes();
176
+        $this->clear_caches( $form );
177
+
178
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
179
+        $new_status = $form->get_status( 'edit' );
180
+
181
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
182
+            do_action( 'getpaid_new_payment_form', $form->get_id(), $form );
183
+        } else {
184
+            do_action( 'getpaid_update_payment_form', $form->get_id(), $form );
185
+        }
186
+
187
+    }
188
+
189
+    /*
190 190
 	|--------------------------------------------------------------------------
191 191
 	| Additional Methods
192 192
 	|--------------------------------------------------------------------------
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-discount-data-store.php 1 patch
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit;
8
+    exit;
9 9
 }
10 10
 
11 11
 /**
@@ -15,196 +15,196 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Discount_Data_Store extends GetPaid_Data_Store_WP {
17 17
 
18
-	/**
19
-	 * Data stored in meta keys, but not considered "meta" for a discount.
20
-	 *
21
-	 * @since 1.0.19
22
-	 * @var array
23
-	 */
24
-	protected $internal_meta_keys = array(
25
-		'_wpi_discount_code',
26
-		'_wpi_discount_amount',
27
-		'_wpi_discount_start',
28
-		'_wpi_discount_expiration',
29
-		'_wpi_discount_type',
30
-		'_wpi_discount_uses',
31
-		'_wpi_discount_is_single_use',
32
-		'_wpi_discount_items',
33
-		'_wpi_discount_excluded_items',
34
-		'_wpi_discount_max_uses',
35
-		'_wpi_discount_is_recurring',
36
-		'_wpi_discount_min_total',
37
-		'_wpi_discount_max_total',
38
-	);
39
-
40
-	/**
41
-	 * A map of meta keys to data props.
42
-	 *
43
-	 * @since 1.0.19
44
-	 *
45
-	 * @var array
46
-	 */
47
-	protected $meta_key_to_props = array(
48
-		'_wpi_discount_code'           => 'code',
49
-		'_wpi_discount_amount'         => 'amount',
50
-		'_wpi_discount_start'          => 'start',
51
-		'_wpi_discount_expiration'     => 'expiration',
52
-		'_wpi_discount_type'           => 'type',
53
-		'_wpi_discount_uses'           => 'uses',
54
-		'_wpi_discount_is_single_use'  => 'is_single_use',
55
-		'_wpi_discount_items'          => 'items',
56
-		'_wpi_discount_excluded_items' => 'excluded_items',
57
-		'_wpi_discount_max_uses'       => 'max_uses',
58
-		'_wpi_discount_is_recurring'   => 'is_recurring',
59
-		'_wpi_discount_min_total'      => 'min_total',
60
-		'_wpi_discount_max_total'      => 'max_total',
61
-	);
62
-
63
-	/*
18
+    /**
19
+     * Data stored in meta keys, but not considered "meta" for a discount.
20
+     *
21
+     * @since 1.0.19
22
+     * @var array
23
+     */
24
+    protected $internal_meta_keys = array(
25
+        '_wpi_discount_code',
26
+        '_wpi_discount_amount',
27
+        '_wpi_discount_start',
28
+        '_wpi_discount_expiration',
29
+        '_wpi_discount_type',
30
+        '_wpi_discount_uses',
31
+        '_wpi_discount_is_single_use',
32
+        '_wpi_discount_items',
33
+        '_wpi_discount_excluded_items',
34
+        '_wpi_discount_max_uses',
35
+        '_wpi_discount_is_recurring',
36
+        '_wpi_discount_min_total',
37
+        '_wpi_discount_max_total',
38
+    );
39
+
40
+    /**
41
+     * A map of meta keys to data props.
42
+     *
43
+     * @since 1.0.19
44
+     *
45
+     * @var array
46
+     */
47
+    protected $meta_key_to_props = array(
48
+        '_wpi_discount_code'           => 'code',
49
+        '_wpi_discount_amount'         => 'amount',
50
+        '_wpi_discount_start'          => 'start',
51
+        '_wpi_discount_expiration'     => 'expiration',
52
+        '_wpi_discount_type'           => 'type',
53
+        '_wpi_discount_uses'           => 'uses',
54
+        '_wpi_discount_is_single_use'  => 'is_single_use',
55
+        '_wpi_discount_items'          => 'items',
56
+        '_wpi_discount_excluded_items' => 'excluded_items',
57
+        '_wpi_discount_max_uses'       => 'max_uses',
58
+        '_wpi_discount_is_recurring'   => 'is_recurring',
59
+        '_wpi_discount_min_total'      => 'min_total',
60
+        '_wpi_discount_max_total'      => 'max_total',
61
+    );
62
+
63
+    /*
64 64
 	|--------------------------------------------------------------------------
65 65
 	| CRUD Methods
66 66
 	|--------------------------------------------------------------------------
67 67
 	*/
68 68
 
69
-	/**
70
-	 * Method to create a new discount in the database.
71
-	 *
72
-	 * @param WPInv_Discount $discount Discount object.
73
-	 */
74
-	public function create( &$discount ) {
75
-		$discount->set_version( WPINV_VERSION );
76
-		$discount->set_date_created( current_time('mysql') );
77
-
78
-		// Create a new post.
79
-		$id = wp_insert_post(
80
-			apply_filters(
81
-				'getpaid_new_discount_data',
82
-				array(
83
-					'post_date'     => $discount->get_date_created( 'edit' ),
84
-					'post_type'     => 'wpi_discount',
85
-					'post_status'   => $this->get_post_status( $discount ),
86
-					'ping_status'   => 'closed',
87
-					'post_author'   => $discount->get_author( 'edit' ),
88
-					'post_title'    => $discount->get_name( 'edit' ),
89
-					'post_excerpt'  => $discount->get_description( 'edit' ),
90
-				)
91
-			),
92
-			true
93
-		);
94
-
95
-		if ( $id && ! is_wp_error( $id ) ) {
96
-			$discount->set_id( $id );
97
-			$this->update_post_meta( $discount );
98
-			$discount->save_meta_data();
99
-			$discount->apply_changes();
100
-			$this->clear_caches( $discount );
101
-			do_action( 'getpaid_new_discount', $discount->get_id(), $discount );
102
-			return true;
103
-		}
104
-
105
-		if ( is_wp_error( $id ) ) {
106
-			$discount->last_error = $id->get_error_message();
107
-		}
108
-
109
-		return false;
110
-	}
111
-
112
-	/**
113
-	 * Method to read a discount from the database.
114
-	 *
115
-	 * @param WPInv_Discount $discount Discount object.
116
-	 *
117
-	 */
118
-	public function read( &$discount ) {
119
-
120
-		$discount->set_defaults();
121
-		$discount_object = get_post( $discount->get_id() );
122
-
123
-		if ( ! $discount->get_id() || ! $discount_object || $discount_object->post_type != 'wpi_discount' ) {
124
-			$discount->last_error = __( 'Invalid discount.', 'invoicing' );
125
-			$discount->set_id( 0 );
126
-			return false;
127
-		}
128
-
129
-		$discount->set_props(
130
-			array(
131
-				'date_created'  => 0 < $discount_object->post_date ? $discount_object->post_date : null,
132
-				'date_modified' => 0 < $discount_object->post_modified ? $discount_object->post_modified : null,
133
-				'status'        => $discount_object->post_status,
134
-				'name'          => $discount_object->post_title,
135
-				'author'        => $discount_object->post_author,
136
-				'description'   => $discount_object->post_excerpt,
137
-			)
138
-		);
139
-
140
-		$this->read_object_data( $discount, $discount_object );
141
-		$discount->read_meta_data();
142
-		$discount->set_object_read( true );
143
-		do_action( 'getpaid_read_discount', $discount->get_id(), $discount );
144
-
145
-	}
146
-
147
-	/**
148
-	 * Method to update a discount in the database.
149
-	 *
150
-	 * @param WPInv_Discount $discount Discount object.
151
-	 */
152
-	public function update( &$discount ) {
153
-		$discount->save_meta_data();
154
-		$discount->set_version( WPINV_VERSION );
155
-
156
-		if ( null === $discount->get_date_created( 'edit' ) ) {
157
-			$discount->set_date_created(  current_time('mysql') );
158
-		}
159
-
160
-		// Grab the current status so we can compare.
161
-		$previous_status = get_post_status( $discount->get_id() );
162
-
163
-		$changes = $discount->get_changes();
164
-
165
-		// Only update the post when the post data changes.
166
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) {
167
-			$post_data = array(
168
-				'post_date'         => $discount->get_date_created( 'edit' ),
169
-				'post_status'       => $discount->get_status( 'edit' ),
170
-				'post_title'        => $discount->get_name( 'edit' ),
171
-				'post_author'       => $discount->get_author( 'edit' ),
172
-				'post_modified'     => $discount->get_date_modified( 'edit' ),
173
-				'post_excerpt'      => $discount->get_description( 'edit' ),
174
-			);
175
-
176
-			/**
177
-			 * When updating this object, to prevent infinite loops, use $wpdb
178
-			 * to update data, since wp_update_post spawns more calls to the
179
-			 * save_post action.
180
-			 *
181
-			 * This ensures hooks are fired by either WP itself (admin screen save),
182
-			 * or an update purely from CRUD.
183
-			 */
184
-			if ( doing_action( 'save_post' ) ) {
185
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) );
186
-				clean_post_cache( $discount->get_id() );
187
-			} else {
188
-				wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) );
189
-			}
190
-			$discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
191
-		}
192
-		$this->update_post_meta( $discount );
193
-		$discount->apply_changes();
194
-		$this->clear_caches( $discount );
195
-
196
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
197
-		$new_status = $discount->get_status( 'edit' );
198
-
199
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
200
-			do_action( 'getpaid_new_discount', $discount->get_id(), $discount );
201
-		} else {
202
-			do_action( 'getpaid_update_discount', $discount->get_id(), $discount );
203
-		}
204
-
205
-	}
206
-
207
-	/*
69
+    /**
70
+     * Method to create a new discount in the database.
71
+     *
72
+     * @param WPInv_Discount $discount Discount object.
73
+     */
74
+    public function create( &$discount ) {
75
+        $discount->set_version( WPINV_VERSION );
76
+        $discount->set_date_created( current_time('mysql') );
77
+
78
+        // Create a new post.
79
+        $id = wp_insert_post(
80
+            apply_filters(
81
+                'getpaid_new_discount_data',
82
+                array(
83
+                    'post_date'     => $discount->get_date_created( 'edit' ),
84
+                    'post_type'     => 'wpi_discount',
85
+                    'post_status'   => $this->get_post_status( $discount ),
86
+                    'ping_status'   => 'closed',
87
+                    'post_author'   => $discount->get_author( 'edit' ),
88
+                    'post_title'    => $discount->get_name( 'edit' ),
89
+                    'post_excerpt'  => $discount->get_description( 'edit' ),
90
+                )
91
+            ),
92
+            true
93
+        );
94
+
95
+        if ( $id && ! is_wp_error( $id ) ) {
96
+            $discount->set_id( $id );
97
+            $this->update_post_meta( $discount );
98
+            $discount->save_meta_data();
99
+            $discount->apply_changes();
100
+            $this->clear_caches( $discount );
101
+            do_action( 'getpaid_new_discount', $discount->get_id(), $discount );
102
+            return true;
103
+        }
104
+
105
+        if ( is_wp_error( $id ) ) {
106
+            $discount->last_error = $id->get_error_message();
107
+        }
108
+
109
+        return false;
110
+    }
111
+
112
+    /**
113
+     * Method to read a discount from the database.
114
+     *
115
+     * @param WPInv_Discount $discount Discount object.
116
+     *
117
+     */
118
+    public function read( &$discount ) {
119
+
120
+        $discount->set_defaults();
121
+        $discount_object = get_post( $discount->get_id() );
122
+
123
+        if ( ! $discount->get_id() || ! $discount_object || $discount_object->post_type != 'wpi_discount' ) {
124
+            $discount->last_error = __( 'Invalid discount.', 'invoicing' );
125
+            $discount->set_id( 0 );
126
+            return false;
127
+        }
128
+
129
+        $discount->set_props(
130
+            array(
131
+                'date_created'  => 0 < $discount_object->post_date ? $discount_object->post_date : null,
132
+                'date_modified' => 0 < $discount_object->post_modified ? $discount_object->post_modified : null,
133
+                'status'        => $discount_object->post_status,
134
+                'name'          => $discount_object->post_title,
135
+                'author'        => $discount_object->post_author,
136
+                'description'   => $discount_object->post_excerpt,
137
+            )
138
+        );
139
+
140
+        $this->read_object_data( $discount, $discount_object );
141
+        $discount->read_meta_data();
142
+        $discount->set_object_read( true );
143
+        do_action( 'getpaid_read_discount', $discount->get_id(), $discount );
144
+
145
+    }
146
+
147
+    /**
148
+     * Method to update a discount in the database.
149
+     *
150
+     * @param WPInv_Discount $discount Discount object.
151
+     */
152
+    public function update( &$discount ) {
153
+        $discount->save_meta_data();
154
+        $discount->set_version( WPINV_VERSION );
155
+
156
+        if ( null === $discount->get_date_created( 'edit' ) ) {
157
+            $discount->set_date_created(  current_time('mysql') );
158
+        }
159
+
160
+        // Grab the current status so we can compare.
161
+        $previous_status = get_post_status( $discount->get_id() );
162
+
163
+        $changes = $discount->get_changes();
164
+
165
+        // Only update the post when the post data changes.
166
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) {
167
+            $post_data = array(
168
+                'post_date'         => $discount->get_date_created( 'edit' ),
169
+                'post_status'       => $discount->get_status( 'edit' ),
170
+                'post_title'        => $discount->get_name( 'edit' ),
171
+                'post_author'       => $discount->get_author( 'edit' ),
172
+                'post_modified'     => $discount->get_date_modified( 'edit' ),
173
+                'post_excerpt'      => $discount->get_description( 'edit' ),
174
+            );
175
+
176
+            /**
177
+             * When updating this object, to prevent infinite loops, use $wpdb
178
+             * to update data, since wp_update_post spawns more calls to the
179
+             * save_post action.
180
+             *
181
+             * This ensures hooks are fired by either WP itself (admin screen save),
182
+             * or an update purely from CRUD.
183
+             */
184
+            if ( doing_action( 'save_post' ) ) {
185
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) );
186
+                clean_post_cache( $discount->get_id() );
187
+            } else {
188
+                wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) );
189
+            }
190
+            $discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
191
+        }
192
+        $this->update_post_meta( $discount );
193
+        $discount->apply_changes();
194
+        $this->clear_caches( $discount );
195
+
196
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
197
+        $new_status = $discount->get_status( 'edit' );
198
+
199
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
200
+            do_action( 'getpaid_new_discount', $discount->get_id(), $discount );
201
+        } else {
202
+            do_action( 'getpaid_update_discount', $discount->get_id(), $discount );
203
+        }
204
+
205
+    }
206
+
207
+    /*
208 208
 	|--------------------------------------------------------------------------
209 209
 	| Additional Methods
210 210
 	|--------------------------------------------------------------------------
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-item-data-store.php 1 patch
Indentation   +209 added lines, -209 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,228 +14,228 @@  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_recurring_period',
36
-		'_wpinv_recurring_interval',
37
-		'_wpinv_recurring_limit',
38
-		'_wpinv_free_trial',
39
-		'_wpinv_trial_period',
40
-		'_wpinv_trial_interval'
41
-	);
42
-
43
-	/**
44
-	 * A map of meta keys to data props.
45
-	 *
46
-	 * @since 1.0.19
47
-	 *
48
-	 * @var array
49
-	 */
50
-	protected $meta_key_to_props = array(
51
-		'_wpinv_price'                => 'price',
52
-		'_wpinv_vat_rule'             => 'vat_rule',
53
-		'_wpinv_vat_class'            => 'vat_class',
54
-		'_wpinv_type'                 => 'type',
55
-		'_wpinv_custom_id'            => 'custom_id',
56
-		'_wpinv_custom_name'          => 'custom_name',
57
-		'_wpinv_custom_singular_name' => 'custom_singular_name',
58
-		'_wpinv_editable'             => 'is_editable',
59
-		'_wpinv_dynamic_pricing'      => 'is_dynamic_pricing',
60
-		'_minimum_price'              => 'minimum_price',
61
-		'_wpinv_custom_name'          => 'custom_name',
62
-		'_wpinv_is_recurring'         => 'is_recurring',
63
-		'_wpinv_recurring_period'     => 'recurring_period',
64
-		'_wpinv_recurring_interval'   => 'recurring_interval',
65
-		'_wpinv_recurring_limit'      => 'recurring_limit',
66
-		'_wpinv_free_trial'           => 'is_free_trial',
67
-		'_wpinv_trial_period'         => 'trial_period',
68
-		'_wpinv_trial_interval'       => 'trial_interval',
69
-		'_wpinv_version'              => 'version',
70
-	);
71
-
72
-	/*
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_recurring_period',
36
+        '_wpinv_recurring_interval',
37
+        '_wpinv_recurring_limit',
38
+        '_wpinv_free_trial',
39
+        '_wpinv_trial_period',
40
+        '_wpinv_trial_interval'
41
+    );
42
+
43
+    /**
44
+     * A map of meta keys to data props.
45
+     *
46
+     * @since 1.0.19
47
+     *
48
+     * @var array
49
+     */
50
+    protected $meta_key_to_props = array(
51
+        '_wpinv_price'                => 'price',
52
+        '_wpinv_vat_rule'             => 'vat_rule',
53
+        '_wpinv_vat_class'            => 'vat_class',
54
+        '_wpinv_type'                 => 'type',
55
+        '_wpinv_custom_id'            => 'custom_id',
56
+        '_wpinv_custom_name'          => 'custom_name',
57
+        '_wpinv_custom_singular_name' => 'custom_singular_name',
58
+        '_wpinv_editable'             => 'is_editable',
59
+        '_wpinv_dynamic_pricing'      => 'is_dynamic_pricing',
60
+        '_minimum_price'              => 'minimum_price',
61
+        '_wpinv_custom_name'          => 'custom_name',
62
+        '_wpinv_is_recurring'         => 'is_recurring',
63
+        '_wpinv_recurring_period'     => 'recurring_period',
64
+        '_wpinv_recurring_interval'   => 'recurring_interval',
65
+        '_wpinv_recurring_limit'      => 'recurring_limit',
66
+        '_wpinv_free_trial'           => 'is_free_trial',
67
+        '_wpinv_trial_period'         => 'trial_period',
68
+        '_wpinv_trial_interval'       => 'trial_interval',
69
+        '_wpinv_version'              => 'version',
70
+    );
71
+
72
+    /*
73 73
 	|--------------------------------------------------------------------------
74 74
 	| CRUD Methods
75 75
 	|--------------------------------------------------------------------------
76 76
 	*/
77 77
 
78
-	/**
79
-	 * Method to create a new item in the database.
80
-	 *
81
-	 * @param WPInv_Item $item Item object.
82
-	 */
83
-	public function create( &$item ) {
84
-		$item->set_version( WPINV_VERSION );
85
-		$item->set_date_created( current_time('mysql') );
86
-
87
-		// Create a new post.
88
-		$id = wp_insert_post(
89
-			apply_filters(
90
-				'getpaid_new_item_data',
91
-				array(
92
-					'post_date'     => $item->get_date_created( 'edit' ),
93
-					'post_type'     => 'wpi_item',
94
-					'post_status'   => $this->get_post_status( $item ),
95
-					'ping_status'   => 'closed',
96
-					'post_author'   => $item->get_author( 'edit' ),
97
-					'post_title'    => $item->get_name( 'edit' ),
98
-					'post_parent'   => 0,
99
-					'post_excerpt'  => $item->get_description( 'edit' ),
100
-				)
101
-			),
102
-			true
103
-		);
104
-
105
-		if ( $id && ! is_wp_error( $id ) ) {
106
-			$item->set_id( $id );
107
-			$this->update_post_meta( $item );
108
-			$item->save_meta_data();
109
-			$item->apply_changes();
110
-			$this->clear_caches( $item );
111
-			do_action( 'getpaid_new_item', $item->get_id(), $item );
112
-			return true;
113
-		}
114
-
115
-		if ( is_wp_error( $id ) ) {
116
-			$item->last_error = $id->get_error_message();
117
-		}
78
+    /**
79
+     * Method to create a new item in the database.
80
+     *
81
+     * @param WPInv_Item $item Item object.
82
+     */
83
+    public function create( &$item ) {
84
+        $item->set_version( WPINV_VERSION );
85
+        $item->set_date_created( current_time('mysql') );
86
+
87
+        // Create a new post.
88
+        $id = wp_insert_post(
89
+            apply_filters(
90
+                'getpaid_new_item_data',
91
+                array(
92
+                    'post_date'     => $item->get_date_created( 'edit' ),
93
+                    'post_type'     => 'wpi_item',
94
+                    'post_status'   => $this->get_post_status( $item ),
95
+                    'ping_status'   => 'closed',
96
+                    'post_author'   => $item->get_author( 'edit' ),
97
+                    'post_title'    => $item->get_name( 'edit' ),
98
+                    'post_parent'   => 0,
99
+                    'post_excerpt'  => $item->get_description( 'edit' ),
100
+                )
101
+            ),
102
+            true
103
+        );
104
+
105
+        if ( $id && ! is_wp_error( $id ) ) {
106
+            $item->set_id( $id );
107
+            $this->update_post_meta( $item );
108
+            $item->save_meta_data();
109
+            $item->apply_changes();
110
+            $this->clear_caches( $item );
111
+            do_action( 'getpaid_new_item', $item->get_id(), $item );
112
+            return true;
113
+        }
114
+
115
+        if ( is_wp_error( $id ) ) {
116
+            $item->last_error = $id->get_error_message();
117
+        }
118 118
 		
119
-		return false;
120
-	}
121
-
122
-	/**
123
-	 * Method to read an item from the database.
124
-	 *
125
-	 * @param WPInv_Item $item Item object.
126
-	 *
127
-	 */
128
-	public function read( &$item ) {
129
-
130
-		$item->set_defaults();
131
-		$item_object = get_post( $item->get_id() );
132
-
133
-		if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) {
134
-			$item->last_error = __( 'Invalid item.', 'invoicing' );
135
-			$item->set_id( 0 );
136
-			return false;
137
-		}
138
-
139
-		$item->set_props(
140
-			array(
141
-				'parent_id'     => $item_object->post_parent,
142
-				'date_created'  => 0 < $item_object->post_date ? $item_object->post_date : null,
143
-				'date_modified' => 0 < $item_object->post_modified ? $item_object->post_modified : null,
144
-				'status'        => $item_object->post_status,
145
-				'name'          => $item_object->post_title,
146
-				'description'   => $item_object->post_excerpt,
147
-				'author'        => $item_object->post_author,
148
-			)
149
-		);
150
-
151
-		$this->read_object_data( $item, $item_object );
152
-		$item->read_meta_data();
153
-		$item->set_object_read( true );
154
-		do_action( 'getpaid_read_item', $item->get_id(), $item );
155
-
156
-	}
157
-
158
-	/**
159
-	 * Method to update an item in the database.
160
-	 *
161
-	 * @param WPInv_Item $item Item object.
162
-	 */
163
-	public function update( &$item ) {
164
-		$item->save_meta_data();
165
-		$item->set_version( WPINV_VERSION );
166
-
167
-		if ( null === $item->get_date_created( 'edit' ) ) {
168
-			$item->set_date_created(  current_time('mysql') );
169
-		}
170
-
171
-		// Grab the current status so we can compare.
172
-		$previous_status = get_post_status( $item->get_id() );
173
-
174
-		$changes = $item->get_changes();
175
-
176
-		// Only update the post when the post data changes.
177
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author' ), array_keys( $changes ) ) ) {
178
-			$post_data = array(
179
-				'post_date'         => $item->get_date_created( 'edit' ),
180
-				'post_status'       => $item->get_status( 'edit' ),
181
-				'post_parent'       => $item->get_parent_id( 'edit' ),
182
-				'post_excerpt'      => $item->get_description( 'edit' ),
183
-				'post_modified'     => $item->get_date_modified( 'edit' ),
184
-				'post_title'        => $item->get_name( 'edit' ),
185
-				'post_author'       => $item->get_author( 'edit' ),
186
-			);
187
-
188
-			/**
189
-			 * When updating this object, to prevent infinite loops, use $wpdb
190
-			 * to update data, since wp_update_post spawns more calls to the
191
-			 * save_post action.
192
-			 *
193
-			 * This ensures hooks are fired by either WP itself (admin screen save),
194
-			 * or an update purely from CRUD.
195
-			 */
196
-			if ( doing_action( 'save_post' ) ) {
197
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) );
198
-				clean_post_cache( $item->get_id() );
199
-			} else {
200
-				wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) );
201
-			}
202
-			$item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
203
-		}
204
-		$this->update_post_meta( $item );
205
-		$item->apply_changes();
206
-		$this->clear_caches( $item );
207
-
208
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
209
-		$new_status = $item->get_status( 'edit' );
210
-
211
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
212
-			do_action( 'getpaid_new_item', $item->get_id(), $item );
213
-		} else {
214
-			do_action( 'getpaid_update_item', $item->get_id(), $item );
215
-		}
216
-
217
-	}
218
-
219
-	/*
119
+        return false;
120
+    }
121
+
122
+    /**
123
+     * Method to read an item from the database.
124
+     *
125
+     * @param WPInv_Item $item Item object.
126
+     *
127
+     */
128
+    public function read( &$item ) {
129
+
130
+        $item->set_defaults();
131
+        $item_object = get_post( $item->get_id() );
132
+
133
+        if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) {
134
+            $item->last_error = __( 'Invalid item.', 'invoicing' );
135
+            $item->set_id( 0 );
136
+            return false;
137
+        }
138
+
139
+        $item->set_props(
140
+            array(
141
+                'parent_id'     => $item_object->post_parent,
142
+                'date_created'  => 0 < $item_object->post_date ? $item_object->post_date : null,
143
+                'date_modified' => 0 < $item_object->post_modified ? $item_object->post_modified : null,
144
+                'status'        => $item_object->post_status,
145
+                'name'          => $item_object->post_title,
146
+                'description'   => $item_object->post_excerpt,
147
+                'author'        => $item_object->post_author,
148
+            )
149
+        );
150
+
151
+        $this->read_object_data( $item, $item_object );
152
+        $item->read_meta_data();
153
+        $item->set_object_read( true );
154
+        do_action( 'getpaid_read_item', $item->get_id(), $item );
155
+
156
+    }
157
+
158
+    /**
159
+     * Method to update an item in the database.
160
+     *
161
+     * @param WPInv_Item $item Item object.
162
+     */
163
+    public function update( &$item ) {
164
+        $item->save_meta_data();
165
+        $item->set_version( WPINV_VERSION );
166
+
167
+        if ( null === $item->get_date_created( 'edit' ) ) {
168
+            $item->set_date_created(  current_time('mysql') );
169
+        }
170
+
171
+        // Grab the current status so we can compare.
172
+        $previous_status = get_post_status( $item->get_id() );
173
+
174
+        $changes = $item->get_changes();
175
+
176
+        // Only update the post when the post data changes.
177
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author' ), array_keys( $changes ) ) ) {
178
+            $post_data = array(
179
+                'post_date'         => $item->get_date_created( 'edit' ),
180
+                'post_status'       => $item->get_status( 'edit' ),
181
+                'post_parent'       => $item->get_parent_id( 'edit' ),
182
+                'post_excerpt'      => $item->get_description( 'edit' ),
183
+                'post_modified'     => $item->get_date_modified( 'edit' ),
184
+                'post_title'        => $item->get_name( 'edit' ),
185
+                'post_author'       => $item->get_author( 'edit' ),
186
+            );
187
+
188
+            /**
189
+             * When updating this object, to prevent infinite loops, use $wpdb
190
+             * to update data, since wp_update_post spawns more calls to the
191
+             * save_post action.
192
+             *
193
+             * This ensures hooks are fired by either WP itself (admin screen save),
194
+             * or an update purely from CRUD.
195
+             */
196
+            if ( doing_action( 'save_post' ) ) {
197
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) );
198
+                clean_post_cache( $item->get_id() );
199
+            } else {
200
+                wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) );
201
+            }
202
+            $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
203
+        }
204
+        $this->update_post_meta( $item );
205
+        $item->apply_changes();
206
+        $this->clear_caches( $item );
207
+
208
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
209
+        $new_status = $item->get_status( 'edit' );
210
+
211
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
212
+            do_action( 'getpaid_new_item', $item->get_id(), $item );
213
+        } else {
214
+            do_action( 'getpaid_update_item', $item->get_id(), $item );
215
+        }
216
+
217
+    }
218
+
219
+    /*
220 220
 	|--------------------------------------------------------------------------
221 221
 	| Additional Methods
222 222
 	|--------------------------------------------------------------------------
223 223
 	*/
224 224
 
225
-	/**
226
-	 * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class.
227
-	 *
228
-	 * @param WPInv_Item $item WPInv_Item object.
229
-	 * @since 1.0.19
230
-	 */
231
-	protected function update_post_meta( &$item ) {
225
+    /**
226
+     * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class.
227
+     *
228
+     * @param WPInv_Item $item WPInv_Item object.
229
+     * @since 1.0.19
230
+     */
231
+    protected function update_post_meta( &$item ) {
232 232
 
233
-		// Ensure that we have a custom id.
233
+        // Ensure that we have a custom id.
234 234
         if ( ! $item->get_custom_id() ) {
235 235
             $item->set_custom_id( $item->get_id() );
236
-		}
236
+        }
237 237
 
238
-		parent::update_post_meta( $item );
239
-	}
238
+        parent::update_post_meta( $item );
239
+    }
240 240
 
241 241
 }
Please login to merge, or discard this patch.
includes/class-wpinv-notes.php 1 patch
Indentation   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -12,118 +12,118 @@
 block discarded – undo
12 12
  */
13 13
 class WPInv_Notes {
14 14
 
15
-	/**
16
-	 * Class constructor.
17
-	 */
18
-	public function __construct() {
19
-
20
-		// Filter inovice notes.
21
-		add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
22
-		add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 );
23
-
24
-		// Fires after notes are loaded.
25
-		do_action( 'wpinv_notes_init', $this );
26
-	}
27
-
28
-	/**
29
-	 * Filters invoice notes query to only include our notes.
30
-	 *
31
-	 * @param WP_Comment_Query $query
32
-	 */
33
-	public function set_invoice_note_type( $query ) {
34
-		$post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
35
-
36
-		if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) {
37
-			$query->query_vars['type'] = 'wpinv_note';
38
-		} else {
39
-
40
-			if ( empty( $query->query_vars['type__not_in'] ) ) {
41
-				$query->query_vars['type__not_in'] = array();
42
-			}
43
-
44
-			$query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] );
45
-			$query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] );
46
-		}
47
-
48
-		return $query;
49
-	}
50
-
51
-	/**
52
-	 * Exclude notes from the comments feed.
53
-	 */
54
-	function wpinv_comment_feed_where( $where ){
55
-		return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' ";
56
-	}
57
-
58
-	/**
59
-	 * Returns an array of invoice notes.
60
-	 *
61
-	 * @param int $invoice_id The invoice ID whose notes to retrieve.
62
-	 * @param string $type Optional. Pass in customer to only return customer notes.
63
-	 * @return WP_Comment[]
64
-	 */
65
-	public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) {
66
-
67
-		// Default comment args.
68
-		$args = array(
69
-			'post_id'   => $invoice_id,
70
-			'orderby'   => 'comment_ID',
71
-			'order'     => 'ASC',
72
-		);
73
-
74
-		// Maybe only show customer comments.
75
-		if ( $type == 'customer' ) {
76
-			$args['meta_key']   = '_wpi_customer_note';
77
-			$args['meta_value'] = 1;
78
-		}
79
-
80
-		$args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
81
-
82
-		return get_comments( $args );
83
-	}
84
-
85
-	/**
86
-	 * Saves an invoice comment.
87
-	 * 
88
-	 * @param WPInv_Invoice $invoice The invoice to add the comment to.
89
-	 * @param string $note The note content.
90
-	 * @param string $note_author The name of the author of the note.
91
-	 * @param bool $for_customer Whether or not this comment is meant to be sent to the customer.
92
-	 * @return int|false The new note's ID on success, false on failure.
93
-	 */
94
-	function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ){
95
-
96
-		do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer );
97
-
98
-		/**
99
-		 * Insert the comment.
100
-		 */
101
-		$note_id = wp_insert_comment(
102
-			wp_filter_comment(
103
-				array(
104
-					'comment_post_ID'      => $invoice->get_id(),
105
-					'comment_content'      => $note,
106
-					'comment_agent'        => 'Invoicing',
107
-					'user_id'              => get_current_user_id(),
108
-					'comment_author'       => $note_author,
109
-					'comment_author_IP'    => wpinv_get_ip(),
110
-					'comment_author_email' => $author_email,
111
-					'comment_author_url'   => $invoice->get_view_url(),
112
-					'comment_type'         => 'wpinv_note',
113
-				)
114
-			)
115
-		);
116
-
117
-		do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer );
118
-
119
-		// Are we notifying the customer?
120
-		if ( empty( $note_id ) || empty( $for_customer ) ) {
121
-			return $note_id;
122
-		}
123
-
124
-		add_comment_meta( $note_id, '_wpi_customer_note', 1 );
125
-		do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $invoice->get_id(), 'user_note' => $note ) );
126
-		return $note_id;
127
-	}
15
+    /**
16
+     * Class constructor.
17
+     */
18
+    public function __construct() {
19
+
20
+        // Filter inovice notes.
21
+        add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
22
+        add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 );
23
+
24
+        // Fires after notes are loaded.
25
+        do_action( 'wpinv_notes_init', $this );
26
+    }
27
+
28
+    /**
29
+     * Filters invoice notes query to only include our notes.
30
+     *
31
+     * @param WP_Comment_Query $query
32
+     */
33
+    public function set_invoice_note_type( $query ) {
34
+        $post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
35
+
36
+        if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) {
37
+            $query->query_vars['type'] = 'wpinv_note';
38
+        } else {
39
+
40
+            if ( empty( $query->query_vars['type__not_in'] ) ) {
41
+                $query->query_vars['type__not_in'] = array();
42
+            }
43
+
44
+            $query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] );
45
+            $query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] );
46
+        }
47
+
48
+        return $query;
49
+    }
50
+
51
+    /**
52
+     * Exclude notes from the comments feed.
53
+     */
54
+    function wpinv_comment_feed_where( $where ){
55
+        return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' ";
56
+    }
57
+
58
+    /**
59
+     * Returns an array of invoice notes.
60
+     *
61
+     * @param int $invoice_id The invoice ID whose notes to retrieve.
62
+     * @param string $type Optional. Pass in customer to only return customer notes.
63
+     * @return WP_Comment[]
64
+     */
65
+    public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) {
66
+
67
+        // Default comment args.
68
+        $args = array(
69
+            'post_id'   => $invoice_id,
70
+            'orderby'   => 'comment_ID',
71
+            'order'     => 'ASC',
72
+        );
73
+
74
+        // Maybe only show customer comments.
75
+        if ( $type == 'customer' ) {
76
+            $args['meta_key']   = '_wpi_customer_note';
77
+            $args['meta_value'] = 1;
78
+        }
79
+
80
+        $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
81
+
82
+        return get_comments( $args );
83
+    }
84
+
85
+    /**
86
+     * Saves an invoice comment.
87
+     * 
88
+     * @param WPInv_Invoice $invoice The invoice to add the comment to.
89
+     * @param string $note The note content.
90
+     * @param string $note_author The name of the author of the note.
91
+     * @param bool $for_customer Whether or not this comment is meant to be sent to the customer.
92
+     * @return int|false The new note's ID on success, false on failure.
93
+     */
94
+    function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ){
95
+
96
+        do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer );
97
+
98
+        /**
99
+         * Insert the comment.
100
+         */
101
+        $note_id = wp_insert_comment(
102
+            wp_filter_comment(
103
+                array(
104
+                    'comment_post_ID'      => $invoice->get_id(),
105
+                    'comment_content'      => $note,
106
+                    'comment_agent'        => 'Invoicing',
107
+                    'user_id'              => get_current_user_id(),
108
+                    'comment_author'       => $note_author,
109
+                    'comment_author_IP'    => wpinv_get_ip(),
110
+                    'comment_author_email' => $author_email,
111
+                    'comment_author_url'   => $invoice->get_view_url(),
112
+                    'comment_type'         => 'wpinv_note',
113
+                )
114
+            )
115
+        );
116
+
117
+        do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer );
118
+
119
+        // Are we notifying the customer?
120
+        if ( empty( $note_id ) || empty( $for_customer ) ) {
121
+            return $note_id;
122
+        }
123
+
124
+        add_comment_meta( $note_id, '_wpi_customer_note', 1 );
125
+        do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $invoice->get_id(), 'user_note' => $note ) );
126
+        return $note_id;
127
+    }
128 128
 
129 129
 }
Please login to merge, or discard this patch.
includes/class-wpinv-item.php 1 patch
Indentation   +735 added lines, -735 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'          => '',
@@ -58,13 +58,13 @@  discard block
 block discarded – undo
58 58
     );
59 59
 
60 60
     /**
61
-	 * Stores meta in cache for future reads.
62
-	 *
63
-	 * A group must be set to to enable caching.
64
-	 *
65
-	 * @var string
66
-	 */
67
-	protected $cache_group = 'getpaid_items';
61
+     * Stores meta in cache for future reads.
62
+     *
63
+     * A group must be set to to enable caching.
64
+     *
65
+     * @var string
66
+     */
67
+    protected $cache_group = 'getpaid_items';
68 68
 
69 69
     /**
70 70
      * Stores a reference to the original WP_Post object
@@ -74,37 +74,37 @@  discard block
 block discarded – undo
74 74
     protected $post = null;
75 75
 
76 76
     /**
77
-	 * Get the item if ID is passed, otherwise the item is new and empty.
78
-	 *
79
-	 * @param  int|object|WPInv_Item|WP_Post $item Item to read.
80
-	 */
81
-	public function __construct( $item = 0 ) {
82
-		parent::__construct( $item );
83
-
84
-		if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) {
85
-			$this->set_id( $item );
86
-		} elseif ( $item instanceof self ) {
87
-			$this->set_id( $item->get_id() );
88
-		} elseif ( ! empty( $item->ID ) ) {
89
-			$this->set_id( $item->ID );
90
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) {
91
-			$this->set_id( $item_id );
92
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) {
93
-			$this->set_id( $item_id );
94
-		} else {
95
-			$this->set_object_read( true );
96
-		}
77
+     * Get the item if ID is passed, otherwise the item is new and empty.
78
+     *
79
+     * @param  int|object|WPInv_Item|WP_Post $item Item to read.
80
+     */
81
+    public function __construct( $item = 0 ) {
82
+        parent::__construct( $item );
83
+
84
+        if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) {
85
+            $this->set_id( $item );
86
+        } elseif ( $item instanceof self ) {
87
+            $this->set_id( $item->get_id() );
88
+        } elseif ( ! empty( $item->ID ) ) {
89
+            $this->set_id( $item->ID );
90
+        } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) {
91
+            $this->set_id( $item_id );
92
+        } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) {
93
+            $this->set_id( $item_id );
94
+        } else {
95
+            $this->set_object_read( true );
96
+        }
97 97
 
98 98
         // Load the datastore.
99
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
99
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
100 100
 
101
-		if ( $this->get_id() > 0 ) {
101
+        if ( $this->get_id() > 0 ) {
102 102
             $this->post = get_post( $this->get_id() );
103 103
             $this->ID   = $this->get_id();
104
-			$this->data_store->read( $this );
104
+            $this->data_store->read( $this );
105 105
         }
106 106
 
107
-	}
107
+    }
108 108
 
109 109
     /*
110 110
 	|--------------------------------------------------------------------------
@@ -122,401 +122,401 @@  discard block
 block discarded – undo
122 122
     */
123 123
 
124 124
     /**
125
-	 * Get parent item ID.
126
-	 *
127
-	 * @since 1.0.19
128
-	 * @param  string $context View or edit context.
129
-	 * @return int
130
-	 */
131
-	public function get_parent_id( $context = 'view' ) {
132
-		return (int) $this->get_prop( 'parent_id', $context );
125
+     * Get parent item ID.
126
+     *
127
+     * @since 1.0.19
128
+     * @param  string $context View or edit context.
129
+     * @return int
130
+     */
131
+    public function get_parent_id( $context = 'view' ) {
132
+        return (int) $this->get_prop( 'parent_id', $context );
133 133
     }
134 134
 
135 135
     /**
136
-	 * Get item status.
137
-	 *
138
-	 * @since 1.0.19
139
-	 * @param  string $context View or edit context.
140
-	 * @return string
141
-	 */
142
-	public function get_status( $context = 'view' ) {
143
-		return $this->get_prop( 'status', $context );
136
+     * Get item status.
137
+     *
138
+     * @since 1.0.19
139
+     * @param  string $context View or edit context.
140
+     * @return string
141
+     */
142
+    public function get_status( $context = 'view' ) {
143
+        return $this->get_prop( 'status', $context );
144 144
     }
145 145
 
146 146
     /**
147
-	 * Get plugin version when the item was created.
148
-	 *
149
-	 * @since 1.0.19
150
-	 * @param  string $context View or edit context.
151
-	 * @return string
152
-	 */
153
-	public function get_version( $context = 'view' ) {
154
-		return $this->get_prop( 'version', $context );
147
+     * Get plugin version when the item was created.
148
+     *
149
+     * @since 1.0.19
150
+     * @param  string $context View or edit context.
151
+     * @return string
152
+     */
153
+    public function get_version( $context = 'view' ) {
154
+        return $this->get_prop( 'version', $context );
155 155
     }
156 156
 
157 157
     /**
158
-	 * Get date when the item was created.
159
-	 *
160
-	 * @since 1.0.19
161
-	 * @param  string $context View or edit context.
162
-	 * @return string
163
-	 */
164
-	public function get_date_created( $context = 'view' ) {
165
-		return $this->get_prop( 'date_created', $context );
158
+     * Get date when the item was created.
159
+     *
160
+     * @since 1.0.19
161
+     * @param  string $context View or edit context.
162
+     * @return string
163
+     */
164
+    public function get_date_created( $context = 'view' ) {
165
+        return $this->get_prop( 'date_created', $context );
166 166
     }
167 167
 
168 168
     /**
169
-	 * Get GMT date when the item was created.
170
-	 *
171
-	 * @since 1.0.19
172
-	 * @param  string $context View or edit context.
173
-	 * @return string
174
-	 */
175
-	public function get_date_created_gmt( $context = 'view' ) {
169
+     * Get GMT date when the item was created.
170
+     *
171
+     * @since 1.0.19
172
+     * @param  string $context View or edit context.
173
+     * @return string
174
+     */
175
+    public function get_date_created_gmt( $context = 'view' ) {
176 176
         $date = $this->get_date_created( $context );
177 177
 
178 178
         if ( $date ) {
179 179
             $date = get_gmt_from_date( $date );
180 180
         }
181
-		return $date;
181
+        return $date;
182 182
     }
183 183
 
184 184
     /**
185
-	 * Get date when the item was last modified.
186
-	 *
187
-	 * @since 1.0.19
188
-	 * @param  string $context View or edit context.
189
-	 * @return string
190
-	 */
191
-	public function get_date_modified( $context = 'view' ) {
192
-		return $this->get_prop( 'date_modified', $context );
185
+     * Get date when the item was last modified.
186
+     *
187
+     * @since 1.0.19
188
+     * @param  string $context View or edit context.
189
+     * @return string
190
+     */
191
+    public function get_date_modified( $context = 'view' ) {
192
+        return $this->get_prop( 'date_modified', $context );
193 193
     }
194 194
 
195 195
     /**
196
-	 * Get GMT date when the item was last modified.
197
-	 *
198
-	 * @since 1.0.19
199
-	 * @param  string $context View or edit context.
200
-	 * @return string
201
-	 */
202
-	public function get_date_modified_gmt( $context = 'view' ) {
196
+     * Get GMT date when the item was last modified.
197
+     *
198
+     * @since 1.0.19
199
+     * @param  string $context View or edit context.
200
+     * @return string
201
+     */
202
+    public function get_date_modified_gmt( $context = 'view' ) {
203 203
         $date = $this->get_date_modified( $context );
204 204
 
205 205
         if ( $date ) {
206 206
             $date = get_gmt_from_date( $date );
207 207
         }
208
-		return $date;
208
+        return $date;
209 209
     }
210 210
 
211 211
     /**
212
-	 * Get the item name.
213
-	 *
214
-	 * @since 1.0.19
215
-	 * @param  string $context View or edit context.
216
-	 * @return string
217
-	 */
218
-	public function get_name( $context = 'view' ) {
219
-		return $this->get_prop( 'name', $context );
212
+     * Get the item name.
213
+     *
214
+     * @since 1.0.19
215
+     * @param  string $context View or edit context.
216
+     * @return string
217
+     */
218
+    public function get_name( $context = 'view' ) {
219
+        return $this->get_prop( 'name', $context );
220 220
     }
221 221
 
222 222
     /**
223
-	 * Alias of self::get_name().
224
-	 *
225
-	 * @since 1.0.19
226
-	 * @param  string $context View or edit context.
227
-	 * @return string
228
-	 */
229
-	public function get_title( $context = 'view' ) {
230
-		return $this->get_name( $context );
223
+     * Alias of self::get_name().
224
+     *
225
+     * @since 1.0.19
226
+     * @param  string $context View or edit context.
227
+     * @return string
228
+     */
229
+    public function get_title( $context = 'view' ) {
230
+        return $this->get_name( $context );
231 231
     }
232 232
 
233 233
     /**
234
-	 * Get the item description.
235
-	 *
236
-	 * @since 1.0.19
237
-	 * @param  string $context View or edit context.
238
-	 * @return string
239
-	 */
240
-	public function get_description( $context = 'view' ) {
241
-		return $this->get_prop( 'description', $context );
234
+     * Get the item description.
235
+     *
236
+     * @since 1.0.19
237
+     * @param  string $context View or edit context.
238
+     * @return string
239
+     */
240
+    public function get_description( $context = 'view' ) {
241
+        return $this->get_prop( 'description', $context );
242 242
     }
243 243
 
244 244
     /**
245
-	 * Alias of self::get_description().
246
-	 *
247
-	 * @since 1.0.19
248
-	 * @param  string $context View or edit context.
249
-	 * @return string
250
-	 */
251
-	public function get_excerpt( $context = 'view' ) {
252
-		return $this->get_description( $context );
245
+     * Alias of self::get_description().
246
+     *
247
+     * @since 1.0.19
248
+     * @param  string $context View or edit context.
249
+     * @return string
250
+     */
251
+    public function get_excerpt( $context = 'view' ) {
252
+        return $this->get_description( $context );
253 253
     }
254 254
 
255 255
     /**
256
-	 * Alias of self::get_description().
257
-	 *
258
-	 * @since 1.0.19
259
-	 * @param  string $context View or edit context.
260
-	 * @return string
261
-	 */
262
-	public function get_summary( $context = 'view' ) {
263
-		return $this->get_description( $context );
256
+     * Alias of self::get_description().
257
+     *
258
+     * @since 1.0.19
259
+     * @param  string $context View or edit context.
260
+     * @return string
261
+     */
262
+    public function get_summary( $context = 'view' ) {
263
+        return $this->get_description( $context );
264 264
     }
265 265
 
266 266
     /**
267
-	 * Get the owner of the item.
268
-	 *
269
-	 * @since 1.0.19
270
-	 * @param  string $context View or edit context.
271
-	 * @return int
272
-	 */
273
-	public function get_author( $context = 'view' ) {
274
-		return (int) $this->get_prop( 'author', $context );
275
-	}
267
+     * Get the owner of the item.
268
+     *
269
+     * @since 1.0.19
270
+     * @param  string $context View or edit context.
271
+     * @return int
272
+     */
273
+    public function get_author( $context = 'view' ) {
274
+        return (int) $this->get_prop( 'author', $context );
275
+    }
276 276
 	
277
-	/**
278
-	 * Alias of self::get_author().
279
-	 *
280
-	 * @since 1.0.19
281
-	 * @param  string $context View or edit context.
282
-	 * @return int
283
-	 */
284
-	public function get_owner( $context = 'view' ) {
285
-		return $this->get_author( $context );
286
-    }
287
-
288
-    /**
289
-	 * Get the price of the item.
290
-	 *
291
-	 * @since 1.0.19
292
-	 * @param  string $context View or edit context.
293
-	 * @return float
294
-	 */
295
-	public function get_price( $context = 'view' ) {
277
+    /**
278
+     * Alias of self::get_author().
279
+     *
280
+     * @since 1.0.19
281
+     * @param  string $context View or edit context.
282
+     * @return int
283
+     */
284
+    public function get_owner( $context = 'view' ) {
285
+        return $this->get_author( $context );
286
+    }
287
+
288
+    /**
289
+     * Get the price of the item.
290
+     *
291
+     * @since 1.0.19
292
+     * @param  string $context View or edit context.
293
+     * @return float
294
+     */
295
+    public function get_price( $context = 'view' ) {
296 296
         return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) );
297
-	}
297
+    }
298 298
 	
299
-	/**
300
-	 * Get the inital price of the item.
301
-	 *
302
-	 * @since 1.0.19
303
-	 * @param  string $context View or edit context.
304
-	 * @return float
305
-	 */
306
-	public function get_initial_price( $context = 'view' ) {
299
+    /**
300
+     * Get the inital price of the item.
301
+     *
302
+     * @since 1.0.19
303
+     * @param  string $context View or edit context.
304
+     * @return float
305
+     */
306
+    public function get_initial_price( $context = 'view' ) {
307 307
 
308
-		$price = (float) $this->get_price( $context );
308
+        $price = (float) $this->get_price( $context );
309 309
 
310
-		if ( $this->has_free_trial() ) {
311
-			$price = 0;
312
-		}
310
+        if ( $this->has_free_trial() ) {
311
+            $price = 0;
312
+        }
313 313
 
314 314
         return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) );
315 315
     }
316 316
 
317 317
     /**
318
-	 * Returns a formated price.
319
-	 *
320
-	 * @since 1.0.19
321
-	 * @param  string $context View or edit context.
322
-	 * @return string
323
-	 */
318
+     * Returns a formated price.
319
+     *
320
+     * @since 1.0.19
321
+     * @param  string $context View or edit context.
322
+     * @return string
323
+     */
324 324
     public function get_the_price() {
325 325
         return wpinv_price( wpinv_format_amount( $this->get_price() ) );
326
-	}
327
-
328
-	/**
329
-	 * Returns the formated initial price.
330
-	 *
331
-	 * @since 1.0.19
332
-	 * @param  string $context View or edit context.
333
-	 * @return string
334
-	 */
326
+    }
327
+
328
+    /**
329
+     * Returns the formated initial price.
330
+     *
331
+     * @since 1.0.19
332
+     * @param  string $context View or edit context.
333
+     * @return string
334
+     */
335 335
     public function get_the_initial_price() {
336 336
         return wpinv_price( wpinv_format_amount( $this->get_initial_price() ) );
337 337
     }
338 338
 
339 339
     /**
340
-	 * Get the VAT rule of the item.
341
-	 *
342
-	 * @since 1.0.19
343
-	 * @param  string $context View or edit context.
344
-	 * @return string
345
-	 */
346
-	public function get_vat_rule( $context = 'view' ) {
340
+     * Get the VAT rule of the item.
341
+     *
342
+     * @since 1.0.19
343
+     * @param  string $context View or edit context.
344
+     * @return string
345
+     */
346
+    public function get_vat_rule( $context = 'view' ) {
347 347
         return $this->get_prop( 'vat_rule', $context );
348 348
     }
349 349
 
350 350
     /**
351
-	 * Get the VAT class of the item.
352
-	 *
353
-	 * @since 1.0.19
354
-	 * @param  string $context View or edit context.
355
-	 * @return string
356
-	 */
357
-	public function get_vat_class( $context = 'view' ) {
351
+     * Get the VAT class of the item.
352
+     *
353
+     * @since 1.0.19
354
+     * @param  string $context View or edit context.
355
+     * @return string
356
+     */
357
+    public function get_vat_class( $context = 'view' ) {
358 358
         return $this->get_prop( 'vat_class', $context );
359 359
     }
360 360
 
361 361
     /**
362
-	 * Get the type of the item.
363
-	 *
364
-	 * @since 1.0.19
365
-	 * @param  string $context View or edit context.
366
-	 * @return string
367
-	 */
368
-	public function get_type( $context = 'view' ) {
362
+     * Get the type of the item.
363
+     *
364
+     * @since 1.0.19
365
+     * @param  string $context View or edit context.
366
+     * @return string
367
+     */
368
+    public function get_type( $context = 'view' ) {
369 369
         return $this->get_prop( 'type', $context );
370 370
     }
371 371
 
372 372
     /**
373
-	 * Get the custom id of the item.
374
-	 *
375
-	 * @since 1.0.19
376
-	 * @param  string $context View or edit context.
377
-	 * @return string
378
-	 */
379
-	public function get_custom_id( $context = 'view' ) {
373
+     * Get the custom id of the item.
374
+     *
375
+     * @since 1.0.19
376
+     * @param  string $context View or edit context.
377
+     * @return string
378
+     */
379
+    public function get_custom_id( $context = 'view' ) {
380 380
         return $this->get_prop( 'custom_id', $context );
381 381
     }
382 382
 
383 383
     /**
384
-	 * Get the custom name of the item.
385
-	 *
386
-	 * @since 1.0.19
387
-	 * @param  string $context View or edit context.
388
-	 * @return string
389
-	 */
390
-	public function get_custom_name( $context = 'view' ) {
384
+     * Get the custom name of the item.
385
+     *
386
+     * @since 1.0.19
387
+     * @param  string $context View or edit context.
388
+     * @return string
389
+     */
390
+    public function get_custom_name( $context = 'view' ) {
391 391
         return $this->get_prop( 'custom_name', $context );
392 392
     }
393 393
 
394 394
     /**
395
-	 * Get the custom singular name of the item.
396
-	 *
397
-	 * @since 1.0.19
398
-	 * @param  string $context View or edit context.
399
-	 * @return string
400
-	 */
401
-	public function get_custom_singular_name( $context = 'view' ) {
395
+     * Get the custom singular name of the item.
396
+     *
397
+     * @since 1.0.19
398
+     * @param  string $context View or edit context.
399
+     * @return string
400
+     */
401
+    public function get_custom_singular_name( $context = 'view' ) {
402 402
         return $this->get_prop( 'custom_singular_name', $context );
403 403
     }
404 404
 
405 405
     /**
406
-	 * Checks if an item is editable..
407
-	 *
408
-	 * @since 1.0.19
409
-	 * @param  string $context View or edit context.
410
-	 * @return int
411
-	 */
412
-	public function get_is_editable( $context = 'view' ) {
406
+     * Checks if an item is editable..
407
+     *
408
+     * @since 1.0.19
409
+     * @param  string $context View or edit context.
410
+     * @return int
411
+     */
412
+    public function get_is_editable( $context = 'view' ) {
413 413
         return (int) $this->get_prop( 'is_editable', $context );
414 414
     }
415 415
 
416 416
     /**
417
-	 * Alias of self::get_is_editable().
418
-	 *
419
-	 * @since 1.0.19
420
-	 * @param  string $context View or edit context.
421
-	 * @return int
422
-	 */
423
-	public function get_editable( $context = 'view' ) {
424
-		return $this->get_is_editable( $context );
417
+     * Alias of self::get_is_editable().
418
+     *
419
+     * @since 1.0.19
420
+     * @param  string $context View or edit context.
421
+     * @return int
422
+     */
423
+    public function get_editable( $context = 'view' ) {
424
+        return $this->get_is_editable( $context );
425 425
     }
426 426
 
427 427
     /**
428
-	 * Checks if dynamic pricing is enabled.
429
-	 *
430
-	 * @since 1.0.19
431
-	 * @param  string $context View or edit context.
432
-	 * @return int
433
-	 */
434
-	public function get_is_dynamic_pricing( $context = 'view' ) {
428
+     * Checks if dynamic pricing is enabled.
429
+     *
430
+     * @since 1.0.19
431
+     * @param  string $context View or edit context.
432
+     * @return int
433
+     */
434
+    public function get_is_dynamic_pricing( $context = 'view' ) {
435 435
         return (int) $this->get_prop( 'is_dynamic_pricing', $context );
436 436
     }
437 437
 
438 438
     /**
439
-	 * Returns the minimum price if dynamic pricing is enabled.
440
-	 *
441
-	 * @since 1.0.19
442
-	 * @param  string $context View or edit context.
443
-	 * @return float
444
-	 */
445
-	public function get_minimum_price( $context = 'view' ) {
439
+     * Returns the minimum price if dynamic pricing is enabled.
440
+     *
441
+     * @since 1.0.19
442
+     * @param  string $context View or edit context.
443
+     * @return float
444
+     */
445
+    public function get_minimum_price( $context = 'view' ) {
446 446
         return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) );
447 447
     }
448 448
 
449 449
     /**
450
-	 * Checks if this is a recurring item.
451
-	 *
452
-	 * @since 1.0.19
453
-	 * @param  string $context View or edit context.
454
-	 * @return int
455
-	 */
456
-	public function get_is_recurring( $context = 'view' ) {
450
+     * Checks if this is a recurring item.
451
+     *
452
+     * @since 1.0.19
453
+     * @param  string $context View or edit context.
454
+     * @return int
455
+     */
456
+    public function get_is_recurring( $context = 'view' ) {
457 457
         return (int) $this->get_prop( 'is_recurring', $context );
458
-	}
458
+    }
459 459
 	
460
-	/**
461
-	 * Get the recurring price of the item.
462
-	 *
463
-	 * @since 1.0.19
464
-	 * @param  string $context View or edit context.
465
-	 * @return float
466
-	 */
467
-	public function get_recurring_price( $context = 'view' ) {
468
-		$price = $this->get_price( $context );
460
+    /**
461
+     * Get the recurring price of the item.
462
+     *
463
+     * @since 1.0.19
464
+     * @param  string $context View or edit context.
465
+     * @return float
466
+     */
467
+    public function get_recurring_price( $context = 'view' ) {
468
+        $price = $this->get_price( $context );
469 469
         return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) );
470
-	}
471
-
472
-	/**
473
-	 * Get the formatted recurring price of the item.
474
-	 *
475
-	 * @since 1.0.19
476
-	 * @param  string $context View or edit context.
477
-	 * @return string
478
-	 */
470
+    }
471
+
472
+    /**
473
+     * Get the formatted recurring price of the item.
474
+     *
475
+     * @since 1.0.19
476
+     * @param  string $context View or edit context.
477
+     * @return string
478
+     */
479 479
     public function get_the_recurring_price() {
480 480
         return wpinv_price( wpinv_format_amount( $this->get_recurring_price() ) );
481
-	}
482
-
483
-	/**
484
-	 * Get the first renewal date (in timestamps) of the item.
485
-	 *
486
-	 * @since 1.0.19
487
-	 * @return int
488
-	 */
489
-	public function get_first_renewal_date() {
490
-
491
-		$periods = array(
492
-			'D' => 'days',
493
-			'W' => 'weeks',
494
-			'M' => 'months',
495
-			'Y' => 'years',
496
-		);
497
-
498
-		$period   = $this->get_recurring_period();
499
-		$interval = $this->get_recurring_interval();
500
-
501
-		if ( $this->has_free_trial() ) {
502
-			$period   = $this->get_trial_period();
503
-			$interval = $this->get_trial_interval();
504
-		}
505
-
506
-		$period       = $periods[ $period ];
507
-		$interval     = empty( $interval ) ? 1 : $interval;
508
-		$next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
481
+    }
482
+
483
+    /**
484
+     * Get the first renewal date (in timestamps) of the item.
485
+     *
486
+     * @since 1.0.19
487
+     * @return int
488
+     */
489
+    public function get_first_renewal_date() {
490
+
491
+        $periods = array(
492
+            'D' => 'days',
493
+            'W' => 'weeks',
494
+            'M' => 'months',
495
+            'Y' => 'years',
496
+        );
497
+
498
+        $period   = $this->get_recurring_period();
499
+        $interval = $this->get_recurring_interval();
500
+
501
+        if ( $this->has_free_trial() ) {
502
+            $period   = $this->get_trial_period();
503
+            $interval = $this->get_trial_interval();
504
+        }
505
+
506
+        $period       = $periods[ $period ];
507
+        $interval     = empty( $interval ) ? 1 : $interval;
508
+        $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
509 509
         return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this );
510 510
     }
511 511
 
512 512
     /**
513
-	 * Get the recurring period.
514
-	 *
515
-	 * @since 1.0.19
516
-	 * @param  bool $full Return abbreviation or in full.
517
-	 * @return string
518
-	 */
519
-	public function get_recurring_period( $full = false ) {
513
+     * Get the recurring period.
514
+     *
515
+     * @since 1.0.19
516
+     * @param  bool $full Return abbreviation or in full.
517
+     * @return string
518
+     */
519
+    public function get_recurring_period( $full = false ) {
520 520
         $period = $this->get_prop( 'recurring_period', 'view' );
521 521
 
522 522
         if ( $full && ! is_bool( $full ) ) {
@@ -527,63 +527,63 @@  discard block
 block discarded – undo
527 527
     }
528 528
 
529 529
     /**
530
-	 * Get the recurring interval.
531
-	 *
532
-	 * @since 1.0.19
533
-	 * @param  string $context View or edit context.
534
-	 * @return int
535
-	 */
536
-	public function get_recurring_interval( $context = 'view' ) {
537
-		$interval = absint( $this->get_prop( 'recurring_interval', $context ) );
530
+     * Get the recurring interval.
531
+     *
532
+     * @since 1.0.19
533
+     * @param  string $context View or edit context.
534
+     * @return int
535
+     */
536
+    public function get_recurring_interval( $context = 'view' ) {
537
+        $interval = absint( $this->get_prop( 'recurring_interval', $context ) );
538 538
 
539
-		if ( $interval < 1 ) {
540
-			$interval = 1;
541
-		}
539
+        if ( $interval < 1 ) {
540
+            $interval = 1;
541
+        }
542 542
 
543 543
         return $interval;
544 544
     }
545 545
 
546 546
     /**
547
-	 * Get the recurring limit.
548
-	 *
549
-	 * @since 1.0.19
550
-	 * @param  string $context View or edit context.
551
-	 * @return int
552
-	 */
553
-	public function get_recurring_limit( $context = 'view' ) {
547
+     * Get the recurring limit.
548
+     *
549
+     * @since 1.0.19
550
+     * @param  string $context View or edit context.
551
+     * @return int
552
+     */
553
+    public function get_recurring_limit( $context = 'view' ) {
554 554
         return (int) $this->get_prop( 'recurring_limit', $context );
555 555
     }
556 556
 
557 557
     /**
558
-	 * Checks if we have a free trial.
559
-	 *
560
-	 * @since 1.0.19
561
-	 * @param  string $context View or edit context.
562
-	 * @return int
563
-	 */
564
-	public function get_is_free_trial( $context = 'view' ) {
558
+     * Checks if we have a free trial.
559
+     *
560
+     * @since 1.0.19
561
+     * @param  string $context View or edit context.
562
+     * @return int
563
+     */
564
+    public function get_is_free_trial( $context = 'view' ) {
565 565
         return (int) $this->get_prop( 'is_free_trial', $context );
566 566
     }
567 567
 
568 568
     /**
569
-	 * Alias for self::get_is_free_trial().
570
-	 *
571
-	 * @since 1.0.19
572
-	 * @param  string $context View or edit context.
573
-	 * @return int
574
-	 */
575
-	public function get_free_trial( $context = 'view' ) {
569
+     * Alias for self::get_is_free_trial().
570
+     *
571
+     * @since 1.0.19
572
+     * @param  string $context View or edit context.
573
+     * @return int
574
+     */
575
+    public function get_free_trial( $context = 'view' ) {
576 576
         return $this->get_is_free_trial( $context );
577 577
     }
578 578
 
579 579
     /**
580
-	 * Get the trial period.
581
-	 *
582
-	 * @since 1.0.19
583
-	 * @param  bool $full Return abbreviation or in full.
584
-	 * @return string
585
-	 */
586
-	public function get_trial_period( $full = false ) {
580
+     * Get the trial period.
581
+     *
582
+     * @since 1.0.19
583
+     * @param  bool $full Return abbreviation or in full.
584
+     * @return string
585
+     */
586
+    public function get_trial_period( $full = false ) {
587 587
         $period = $this->get_prop( 'trial_period', 'view' );
588 588
 
589 589
         if ( $full && ! is_bool( $full ) ) {
@@ -594,104 +594,104 @@  discard block
 block discarded – undo
594 594
     }
595 595
 
596 596
     /**
597
-	 * Get the trial interval.
598
-	 *
599
-	 * @since 1.0.19
600
-	 * @param  string $context View or edit context.
601
-	 * @return int
602
-	 */
603
-	public function get_trial_interval( $context = 'view' ) {
597
+     * Get the trial interval.
598
+     *
599
+     * @since 1.0.19
600
+     * @param  string $context View or edit context.
601
+     * @return int
602
+     */
603
+    public function get_trial_interval( $context = 'view' ) {
604 604
         return (int) $this->get_prop( 'trial_interval', $context );
605
-	}
605
+    }
606 606
 	
607
-	/**
608
-	 * Get the item's edit url.
609
-	 *
610
-	 * @since 1.0.19
611
-	 * @return string
612
-	 */
613
-	public function get_edit_url() {
607
+    /**
608
+     * Get the item's edit url.
609
+     *
610
+     * @since 1.0.19
611
+     * @return string
612
+     */
613
+    public function get_edit_url() {
614 614
         return get_edit_post_link( $this->get_id() );
615
-	}
616
-
617
-	/**
618
-	 * Given an item's name/custom id, it returns its id.
619
-	 *
620
-	 *
621
-	 * @static
622
-	 * @param string $value The item name or custom id.
623
-	 * @param string $field Either name or custom_id.
624
-	 * @param string $type in case you need to search for a given type.
625
-	 * @since 1.0.15
626
-	 * @return int
627
-	 */
628
-	public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) {
629
-
630
-		// Trim the value.
631
-		$value = trim( $value );
632
-
633
-		if ( empty( $value ) ) {
634
-			return 0;
635
-		}
615
+    }
616
+
617
+    /**
618
+     * Given an item's name/custom id, it returns its id.
619
+     *
620
+     *
621
+     * @static
622
+     * @param string $value The item name or custom id.
623
+     * @param string $field Either name or custom_id.
624
+     * @param string $type in case you need to search for a given type.
625
+     * @since 1.0.15
626
+     * @return int
627
+     */
628
+    public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) {
629
+
630
+        // Trim the value.
631
+        $value = trim( $value );
632
+
633
+        if ( empty( $value ) ) {
634
+            return 0;
635
+        }
636 636
 
637 637
         // Valid fields.
638 638
         $fields = array( 'custom_id', 'name', 'slug' );
639 639
 
640
-		// Ensure a field has been passed.
641
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
642
-			return 0;
643
-		}
644
-
645
-		if ( $field == 'name' ) {
646
-			$field = 'slug';
647
-		} 
648
-
649
-		// Maybe retrieve from the cache.
650
-		$item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" );
651
-		if ( ! empty( $item_id ) ) {
652
-			return $item_id;
653
-		}
654
-
655
-		// Fetch from the db.
656
-		if ( $field =='slug' ) {
657
-			$items = get_posts(
658
-				array(
659
-					'post_type'      => 'wpi_item',
660
-					'name'           => $value,
661
-					'posts_per_page' => 1,
662
-					'post_status'    => 'any',
663
-				)
664
-			);
665
-		}
666
-
667
-		if ( $field =='custom_id' ) {
668
-			$items = get_posts(
669
-				array(
670
-					'post_type'      => 'wpi_item',
671
-					'posts_per_page' => 1,
672
-					'post_status'    => 'any',
673
-					'meta_query'     => array(
674
-						array(
675
-							'key'   => '_wpinv_type',
676
-                			'value' => $type,
677
-						),
678
-						array(
679
-							'key'   => '_wpinv_custom_id',
680
-                			'value' => $type,
681
-						)
682
-					)
683
-				)
684
-			);
685
-		}
686
-
687
-		if ( empty( $items ) ) {
688
-			return 0;
689
-		}
690
-
691
-		// Update the cache with our data
692
-		wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" );
693
-
694
-		return $items[0]->ID;
640
+        // Ensure a field has been passed.
641
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
642
+            return 0;
643
+        }
644
+
645
+        if ( $field == 'name' ) {
646
+            $field = 'slug';
647
+        } 
648
+
649
+        // Maybe retrieve from the cache.
650
+        $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" );
651
+        if ( ! empty( $item_id ) ) {
652
+            return $item_id;
653
+        }
654
+
655
+        // Fetch from the db.
656
+        if ( $field =='slug' ) {
657
+            $items = get_posts(
658
+                array(
659
+                    'post_type'      => 'wpi_item',
660
+                    'name'           => $value,
661
+                    'posts_per_page' => 1,
662
+                    'post_status'    => 'any',
663
+                )
664
+            );
665
+        }
666
+
667
+        if ( $field =='custom_id' ) {
668
+            $items = get_posts(
669
+                array(
670
+                    'post_type'      => 'wpi_item',
671
+                    'posts_per_page' => 1,
672
+                    'post_status'    => 'any',
673
+                    'meta_query'     => array(
674
+                        array(
675
+                            'key'   => '_wpinv_type',
676
+                            'value' => $type,
677
+                        ),
678
+                        array(
679
+                            'key'   => '_wpinv_custom_id',
680
+                            'value' => $type,
681
+                        )
682
+                    )
683
+                )
684
+            );
685
+        }
686
+
687
+        if ( empty( $items ) ) {
688
+            return 0;
689
+        }
690
+
691
+        // Update the cache with our data
692
+        wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" );
693
+
694
+        return $items[0]->ID;
695 695
     }
696 696
 
697 697
     /**
@@ -724,52 +724,52 @@  discard block
 block discarded – undo
724 724
     */
725 725
 
726 726
     /**
727
-	 * Set parent order ID.
728
-	 *
729
-	 * @since 1.0.19
730
-	 */
731
-	public function set_parent_id( $value ) {
732
-		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
733
-			return;
734
-		}
735
-		$this->set_prop( 'parent_id', absint( $value ) );
736
-	}
737
-
738
-    /**
739
-	 * Sets item status.
740
-	 *
741
-	 * @since 1.0.19
742
-	 * @param  string $status New status.
743
-	 * @return array details of change.
744
-	 */
745
-	public function set_status( $status ) {
727
+     * Set parent order ID.
728
+     *
729
+     * @since 1.0.19
730
+     */
731
+    public function set_parent_id( $value ) {
732
+        if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
733
+            return;
734
+        }
735
+        $this->set_prop( 'parent_id', absint( $value ) );
736
+    }
737
+
738
+    /**
739
+     * Sets item status.
740
+     *
741
+     * @since 1.0.19
742
+     * @param  string $status New status.
743
+     * @return array details of change.
744
+     */
745
+    public function set_status( $status ) {
746 746
         $old_status = $this->get_status();
747 747
 
748 748
         $this->set_prop( 'status', $status );
749 749
 
750
-		return array(
751
-			'from' => $old_status,
752
-			'to'   => $status,
753
-		);
750
+        return array(
751
+            'from' => $old_status,
752
+            'to'   => $status,
753
+        );
754 754
     }
755 755
 
756 756
     /**
757
-	 * Set plugin version when the item was created.
758
-	 *
759
-	 * @since 1.0.19
760
-	 */
761
-	public function set_version( $value ) {
762
-		$this->set_prop( 'version', $value );
757
+     * Set plugin version when the item was created.
758
+     *
759
+     * @since 1.0.19
760
+     */
761
+    public function set_version( $value ) {
762
+        $this->set_prop( 'version', $value );
763 763
     }
764 764
 
765 765
     /**
766
-	 * Set date when the item was created.
767
-	 *
768
-	 * @since 1.0.19
769
-	 * @param string $value Value to set.
766
+     * Set date when the item was created.
767
+     *
768
+     * @since 1.0.19
769
+     * @param string $value Value to set.
770 770
      * @return bool Whether or not the date was set.
771
-	 */
772
-	public function set_date_created( $value ) {
771
+     */
772
+    public function set_date_created( $value ) {
773 773
         $date = strtotime( $value );
774 774
 
775 775
         if ( $date ) {
@@ -782,13 +782,13 @@  discard block
 block discarded – undo
782 782
     }
783 783
 
784 784
     /**
785
-	 * Set date when the item was last modified.
786
-	 *
787
-	 * @since 1.0.19
788
-	 * @param string $value Value to set.
785
+     * Set date when the item was last modified.
786
+     *
787
+     * @since 1.0.19
788
+     * @param string $value Value to set.
789 789
      * @return bool Whether or not the date was set.
790
-	 */
791
-	public function set_date_modified( $value ) {
790
+     */
791
+    public function set_date_modified( $value ) {
792 792
         $date = strtotime( $value );
793 793
 
794 794
         if ( $date ) {
@@ -801,115 +801,115 @@  discard block
 block discarded – undo
801 801
     }
802 802
 
803 803
     /**
804
-	 * Set the item name.
805
-	 *
806
-	 * @since 1.0.19
807
-	 * @param  string $value New name.
808
-	 */
809
-	public function set_name( $value ) {
804
+     * Set the item name.
805
+     *
806
+     * @since 1.0.19
807
+     * @param  string $value New name.
808
+     */
809
+    public function set_name( $value ) {
810 810
         $name = sanitize_text_field( $value );
811
-		$this->set_prop( 'name', $name );
811
+        $this->set_prop( 'name', $name );
812 812
     }
813 813
 
814 814
     /**
815
-	 * Alias of self::set_name().
816
-	 *
817
-	 * @since 1.0.19
818
-	 * @param  string $value New name.
819
-	 */
820
-	public function set_title( $value ) {
821
-		$this->set_name( $value );
815
+     * Alias of self::set_name().
816
+     *
817
+     * @since 1.0.19
818
+     * @param  string $value New name.
819
+     */
820
+    public function set_title( $value ) {
821
+        $this->set_name( $value );
822 822
     }
823 823
 
824 824
     /**
825
-	 * Set the item description.
826
-	 *
827
-	 * @since 1.0.19
828
-	 * @param  string $value New description.
829
-	 */
830
-	public function set_description( $value ) {
825
+     * Set the item description.
826
+     *
827
+     * @since 1.0.19
828
+     * @param  string $value New description.
829
+     */
830
+    public function set_description( $value ) {
831 831
         $description = wp_kses_post( $value );
832
-		return $this->set_prop( 'description', $description );
832
+        return $this->set_prop( 'description', $description );
833 833
     }
834 834
 
835 835
     /**
836
-	 * Alias of self::set_description().
837
-	 *
838
-	 * @since 1.0.19
839
-	 * @param  string $value New description.
840
-	 */
841
-	public function set_excerpt( $value ) {
842
-		$this->set_description( $value );
836
+     * Alias of self::set_description().
837
+     *
838
+     * @since 1.0.19
839
+     * @param  string $value New description.
840
+     */
841
+    public function set_excerpt( $value ) {
842
+        $this->set_description( $value );
843 843
     }
844 844
 
845 845
     /**
846
-	 * Alias of self::set_description().
847
-	 *
848
-	 * @since 1.0.19
849
-	 * @param  string $value New description.
850
-	 */
851
-	public function set_summary( $value ) {
852
-		$this->set_description( $value );
846
+     * Alias of self::set_description().
847
+     *
848
+     * @since 1.0.19
849
+     * @param  string $value New description.
850
+     */
851
+    public function set_summary( $value ) {
852
+        $this->set_description( $value );
853 853
     }
854 854
 
855 855
     /**
856
-	 * Set the owner of the item.
857
-	 *
858
-	 * @since 1.0.19
859
-	 * @param  int $value New author.
860
-	 */
861
-	public function set_author( $value ) {
862
-		$this->set_prop( 'author', (int) $value );
863
-	}
856
+     * Set the owner of the item.
857
+     *
858
+     * @since 1.0.19
859
+     * @param  int $value New author.
860
+     */
861
+    public function set_author( $value ) {
862
+        $this->set_prop( 'author', (int) $value );
863
+    }
864 864
 	
865
-	/**
866
-	 * Alias of self::set_author().
867
-	 *
868
-	 * @since 1.0.19
869
-	 * @param  int $value New author.
870
-	 */
871
-	public function set_owner( $value ) {
872
-		$this->set_author( $value );
873
-    }
874
-
875
-    /**
876
-	 * Set the price of the item.
877
-	 *
878
-	 * @since 1.0.19
879
-	 * @param  float $value New price.
880
-	 */
881
-	public function set_price( $value ) {
865
+    /**
866
+     * Alias of self::set_author().
867
+     *
868
+     * @since 1.0.19
869
+     * @param  int $value New author.
870
+     */
871
+    public function set_owner( $value ) {
872
+        $this->set_author( $value );
873
+    }
874
+
875
+    /**
876
+     * Set the price of the item.
877
+     *
878
+     * @since 1.0.19
879
+     * @param  float $value New price.
880
+     */
881
+    public function set_price( $value ) {
882 882
         $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) );
883 883
     }
884 884
 
885 885
     /**
886
-	 * Set the VAT rule of the item.
887
-	 *
888
-	 * @since 1.0.19
889
-	 * @param  string $value new rule.
890
-	 */
891
-	public function set_vat_rule( $value ) {
886
+     * Set the VAT rule of the item.
887
+     *
888
+     * @since 1.0.19
889
+     * @param  string $value new rule.
890
+     */
891
+    public function set_vat_rule( $value ) {
892 892
         $this->set_prop( 'vat_rule', $value );
893 893
     }
894 894
 
895 895
     /**
896
-	 * Set the VAT class of the item.
897
-	 *
898
-	 * @since 1.0.19
899
-	 * @param  string $value new class.
900
-	 */
901
-	public function set_vat_class( $value ) {
896
+     * Set the VAT class of the item.
897
+     *
898
+     * @since 1.0.19
899
+     * @param  string $value new class.
900
+     */
901
+    public function set_vat_class( $value ) {
902 902
         $this->set_prop( 'vat_class', $value );
903 903
     }
904 904
 
905 905
     /**
906
-	 * Set the type of the item.
907
-	 *
908
-	 * @since 1.0.19
909
-	 * @param  string $value new item type.
910
-	 * @return string
911
-	 */
912
-	public function set_type( $value ) {
906
+     * Set the type of the item.
907
+     *
908
+     * @since 1.0.19
909
+     * @param  string $value new item type.
910
+     * @return string
911
+     */
912
+    public function set_type( $value ) {
913 913
 
914 914
         if ( empty( $value ) ) {
915 915
             $value = 'custom';
@@ -919,134 +919,134 @@  discard block
 block discarded – undo
919 919
     }
920 920
 
921 921
     /**
922
-	 * Set the custom id of the item.
923
-	 *
924
-	 * @since 1.0.19
925
-	 * @param  string $value new custom id.
926
-	 */
927
-	public function set_custom_id( $value ) {
922
+     * Set the custom id of the item.
923
+     *
924
+     * @since 1.0.19
925
+     * @param  string $value new custom id.
926
+     */
927
+    public function set_custom_id( $value ) {
928 928
         $this->set_prop( 'custom_id', $value );
929 929
     }
930 930
 
931 931
     /**
932
-	 * Set the custom name of the item.
933
-	 *
934
-	 * @since 1.0.19
935
-	 * @param  string $value new custom name.
936
-	 */
937
-	public function set_custom_name( $value ) {
932
+     * Set the custom name of the item.
933
+     *
934
+     * @since 1.0.19
935
+     * @param  string $value new custom name.
936
+     */
937
+    public function set_custom_name( $value ) {
938 938
         $this->set_prop( 'custom_name', $value );
939 939
     }
940 940
 
941 941
     /**
942
-	 * Set the custom singular name of the item.
943
-	 *
944
-	 * @since 1.0.19
945
-	 * @param  string $value new custom singular name.
946
-	 */
947
-	public function set_custom_singular_name( $value ) {
942
+     * Set the custom singular name of the item.
943
+     *
944
+     * @since 1.0.19
945
+     * @param  string $value new custom singular name.
946
+     */
947
+    public function set_custom_singular_name( $value ) {
948 948
         $this->set_prop( 'custom_singular_name', $value );
949 949
     }
950 950
 
951 951
     /**
952
-	 * Sets if an item is editable..
953
-	 *
954
-	 * @since 1.0.19
955
-	 * @param  int|bool $value whether or not the item is editable.
956
-	 */
957
-	public function set_is_editable( $value ) {
958
-		if ( is_numeric( $value ) ) {
959
-			$this->set_prop( 'is_editable', (int) $value );
960
-		}
952
+     * Sets if an item is editable..
953
+     *
954
+     * @since 1.0.19
955
+     * @param  int|bool $value whether or not the item is editable.
956
+     */
957
+    public function set_is_editable( $value ) {
958
+        if ( is_numeric( $value ) ) {
959
+            $this->set_prop( 'is_editable', (int) $value );
960
+        }
961 961
     }
962 962
 
963 963
     /**
964
-	 * Sets if dynamic pricing is enabled.
965
-	 *
966
-	 * @since 1.0.19
967
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
968
-	 */
969
-	public function set_is_dynamic_pricing( $value ) {
964
+     * Sets if dynamic pricing is enabled.
965
+     *
966
+     * @since 1.0.19
967
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
968
+     */
969
+    public function set_is_dynamic_pricing( $value ) {
970 970
         $this->set_prop( 'is_dynamic_pricing', (int) $value );
971 971
     }
972 972
 
973 973
     /**
974
-	 * Sets the minimum price if dynamic pricing is enabled.
975
-	 *
976
-	 * @since 1.0.19
977
-	 * @param  float $value minimum price.
978
-	 */
979
-	public function set_minimum_price( $value ) {
974
+     * Sets the minimum price if dynamic pricing is enabled.
975
+     *
976
+     * @since 1.0.19
977
+     * @param  float $value minimum price.
978
+     */
979
+    public function set_minimum_price( $value ) {
980 980
         $this->set_prop( 'minimum_price',  (float) wpinv_sanitize_amount( $value ) );
981 981
     }
982 982
 
983 983
     /**
984
-	 * Sets if this is a recurring item.
985
-	 *
986
-	 * @since 1.0.19
987
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
988
-	 */
989
-	public function set_is_recurring( $value ) {
984
+     * Sets if this is a recurring item.
985
+     *
986
+     * @since 1.0.19
987
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
988
+     */
989
+    public function set_is_recurring( $value ) {
990 990
         $this->set_prop( 'is_recurring', (int) $value );
991 991
     }
992 992
 
993 993
     /**
994
-	 * Set the recurring period.
995
-	 *
996
-	 * @since 1.0.19
997
-	 * @param  string $value new period.
998
-	 */
999
-	public function set_recurring_period( $value ) {
994
+     * Set the recurring period.
995
+     *
996
+     * @since 1.0.19
997
+     * @param  string $value new period.
998
+     */
999
+    public function set_recurring_period( $value ) {
1000 1000
         $this->set_prop( 'recurring_period', $value );
1001 1001
     }
1002 1002
 
1003 1003
     /**
1004
-	 * Set the recurring interval.
1005
-	 *
1006
-	 * @since 1.0.19
1007
-	 * @param  int $value recurring interval.
1008
-	 */
1009
-	public function set_recurring_interval( $value ) {
1004
+     * Set the recurring interval.
1005
+     *
1006
+     * @since 1.0.19
1007
+     * @param  int $value recurring interval.
1008
+     */
1009
+    public function set_recurring_interval( $value ) {
1010 1010
         return $this->set_prop( 'recurring_interval', (int) $value );
1011 1011
     }
1012 1012
 
1013 1013
     /**
1014
-	 * Get the recurring limit.
1015
-	 * @since 1.0.19
1016
-	 * @param  int $value The recurring limit.
1017
-	 * @return int
1018
-	 */
1019
-	public function set_recurring_limit( $value ) {
1014
+     * Get the recurring limit.
1015
+     * @since 1.0.19
1016
+     * @param  int $value The recurring limit.
1017
+     * @return int
1018
+     */
1019
+    public function set_recurring_limit( $value ) {
1020 1020
         $this->set_prop( 'recurring_limit', (int) $value );
1021 1021
     }
1022 1022
 
1023 1023
     /**
1024
-	 * Checks if we have a free trial.
1025
-	 *
1026
-	 * @since 1.0.19
1027
-	 * @param  int|bool $value whether or not it has a free trial.
1028
-	 */
1029
-	public function set_is_free_trial( $value ) {
1024
+     * Checks if we have a free trial.
1025
+     *
1026
+     * @since 1.0.19
1027
+     * @param  int|bool $value whether or not it has a free trial.
1028
+     */
1029
+    public function set_is_free_trial( $value ) {
1030 1030
         $this->set_prop( 'is_free_trial', (int) $value );
1031 1031
     }
1032 1032
 
1033 1033
     /**
1034
-	 * Set the trial period.
1035
-	 *
1036
-	 * @since 1.0.19
1037
-	 * @param  string $value trial period.
1038
-	 */
1039
-	public function set_trial_period( $value ) {
1034
+     * Set the trial period.
1035
+     *
1036
+     * @since 1.0.19
1037
+     * @param  string $value trial period.
1038
+     */
1039
+    public function set_trial_period( $value ) {
1040 1040
         $this->set_prop( 'trial_period', $value );
1041 1041
     }
1042 1042
 
1043 1043
     /**
1044
-	 * Set the trial interval.
1045
-	 *
1046
-	 * @since 1.0.19
1047
-	 * @param  int $value trial interval.
1048
-	 */
1049
-	public function set_trial_interval( $value ) {
1044
+     * Set the trial interval.
1045
+     *
1046
+     * @since 1.0.19
1047
+     * @param  int $value trial interval.
1048
+     */
1049
+    public function set_trial_interval( $value ) {
1050 1050
         $this->set_prop( 'trial_interval', $value );
1051 1051
     }
1052 1052
 
@@ -1054,17 +1054,17 @@  discard block
 block discarded – undo
1054 1054
      * Create an item. For backwards compatibilty.
1055 1055
      * 
1056 1056
      * @deprecated
1057
-	 * @return int item id
1057
+     * @return int item id
1058 1058
      */
1059 1059
     public function create( $data = array() ) {
1060 1060
 
1061
-		// Set the properties.
1062
-		if ( is_array( $data ) ) {
1063
-			$this->set_props( $data );
1064
-		}
1061
+        // Set the properties.
1062
+        if ( is_array( $data ) ) {
1063
+            $this->set_props( $data );
1064
+        }
1065 1065
 
1066
-		// Save the item.
1067
-		return $this->save();
1066
+        // Save the item.
1067
+        return $this->save();
1068 1068
 
1069 1069
     }
1070 1070
 
@@ -1072,7 +1072,7 @@  discard block
 block discarded – undo
1072 1072
      * Updates an item. For backwards compatibilty.
1073 1073
      * 
1074 1074
      * @deprecated
1075
-	 * @return int item id
1075
+     * @return int item id
1076 1076
      */
1077 1077
     public function update( $data = array() ) {
1078 1078
         return $this->create( $data );
@@ -1088,84 +1088,84 @@  discard block
 block discarded – undo
1088 1088
 	*/
1089 1089
 
1090 1090
     /**
1091
-	 * Checks whether the item has enabled dynamic pricing.
1092
-	 *
1093
-	 * @since 1.0.19
1094
-	 * @return bool
1095
-	 */
1096
-	public function user_can_set_their_price() {
1091
+     * Checks whether the item has enabled dynamic pricing.
1092
+     *
1093
+     * @since 1.0.19
1094
+     * @return bool
1095
+     */
1096
+    public function user_can_set_their_price() {
1097 1097
         return (bool) $this->get_is_dynamic_pricing();
1098
-	}
1098
+    }
1099 1099
 	
1100
-	/**
1101
-	 * Checks whether the item is recurring.
1102
-	 *
1103
-	 * @since 1.0.19
1104
-	 * @return bool
1105
-	 */
1106
-	public function is_recurring() {
1100
+    /**
1101
+     * Checks whether the item is recurring.
1102
+     *
1103
+     * @since 1.0.19
1104
+     * @return bool
1105
+     */
1106
+    public function is_recurring() {
1107 1107
         return (bool) $this->get_is_recurring();
1108 1108
     }
1109 1109
 
1110 1110
     /**
1111
-	 * Checks whether the item has a free trial.
1112
-	 *
1113
-	 * @since 1.0.19
1114
-	 * @return bool
1115
-	 */
1111
+     * Checks whether the item has a free trial.
1112
+     *
1113
+     * @since 1.0.19
1114
+     * @return bool
1115
+     */
1116 1116
     public function has_free_trial() {
1117 1117
         $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false;
1118 1118
         return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this );
1119 1119
     }
1120 1120
 
1121 1121
     /**
1122
-	 * Checks whether the item is free.
1123
-	 *
1124
-	 * @since 1.0.19
1125
-	 * @return bool
1126
-	 */
1122
+     * Checks whether the item is free.
1123
+     *
1124
+     * @since 1.0.19
1125
+     * @return bool
1126
+     */
1127 1127
     public function is_free() {
1128 1128
         $is_free   = $this->get_price() == 0;
1129 1129
         return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this );
1130 1130
     }
1131 1131
 
1132 1132
     /**
1133
-	 * Checks the item status against a passed in status.
1134
-	 *
1135
-	 * @param array|string $status Status to check.
1136
-	 * @return bool
1137
-	 */
1138
-	public function has_status( $status ) {
1139
-		$has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1140
-		return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1133
+     * Checks the item status against a passed in status.
1134
+     *
1135
+     * @param array|string $status Status to check.
1136
+     * @return bool
1137
+     */
1138
+    public function has_status( $status ) {
1139
+        $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1140
+        return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1141 1141
     }
1142 1142
 
1143 1143
     /**
1144
-	 * Checks the item type against a passed in types.
1145
-	 *
1146
-	 * @param array|string $type Type to check.
1147
-	 * @return bool
1148
-	 */
1149
-	public function is_type( $type ) {
1150
-		$is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1151
-		return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1152
-	}
1144
+     * Checks the item type against a passed in types.
1145
+     *
1146
+     * @param array|string $type Type to check.
1147
+     * @return bool
1148
+     */
1149
+    public function is_type( $type ) {
1150
+        $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1151
+        return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1152
+    }
1153 1153
 
1154 1154
     /**
1155
-	 * Checks whether the item is editable.
1156
-	 *
1157
-	 * @since 1.0.19
1158
-	 * @return bool
1159
-	 */
1155
+     * Checks whether the item is editable.
1156
+     *
1157
+     * @since 1.0.19
1158
+     * @return bool
1159
+     */
1160 1160
     public function is_editable() {
1161 1161
         $is_editable = $this->get_is_editable();
1162 1162
         return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this );
1163
-	}
1163
+    }
1164 1164
 
1165
-	/**
1166
-	 * Returns an array of cart fees.
1167
-	 */
1168
-	public function get_fees( $type = 'fee', $item_id = 0 ) {
1165
+    /**
1166
+     * Returns an array of cart fees.
1167
+     */
1168
+    public function get_fees( $type = 'fee', $item_id = 0 ) {
1169 1169
         
1170 1170
         $fees = getpaid_session()->get( 'wpi_cart_fees' );
1171 1171
 
@@ -1208,11 +1208,11 @@  discard block
 block discarded – undo
1208 1208
     }
1209 1209
 
1210 1210
     /**
1211
-	 * Checks whether the item is purchasable.
1212
-	 *
1213
-	 * @since 1.0.19
1214
-	 * @return bool
1215
-	 */
1211
+     * Checks whether the item is purchasable.
1212
+     *
1213
+     * @since 1.0.19
1214
+     * @return bool
1215
+     */
1216 1216
     public function can_purchase() {
1217 1217
         $can_purchase = null !== $this->get_id();
1218 1218
 
@@ -1224,11 +1224,11 @@  discard block
 block discarded – undo
1224 1224
     }
1225 1225
 
1226 1226
     /**
1227
-	 * Checks whether the item supports dynamic pricing.
1228
-	 *
1229
-	 * @since 1.0.19
1230
-	 * @return bool
1231
-	 */
1227
+     * Checks whether the item supports dynamic pricing.
1228
+     *
1229
+     * @since 1.0.19
1230
+     * @return bool
1231
+     */
1232 1232
     public function supports_dynamic_pricing() {
1233 1233
         return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this );
1234 1234
     }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-data.php 1 patch
Indentation   +857 added lines, -857 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  */
10 10
 
11 11
 if ( ! defined( 'ABSPATH' ) ) {
12
-	exit;
12
+    exit;
13 13
 }
14 14
 
15 15
 /**
@@ -21,356 +21,356 @@  discard block
 block discarded – undo
21 21
  */
22 22
 abstract class GetPaid_Data {
23 23
 
24
-	/**
25
-	 * ID for this object.
26
-	 *
27
-	 * @since 1.0.19
28
-	 * @var int
29
-	 */
30
-	protected $id = 0;
31
-
32
-	/**
33
-	 * Core data for this object. Name value pairs (name + default value).
34
-	 *
35
-	 * @since 1.0.19
36
-	 * @var array
37
-	 */
38
-	protected $data = array();
39
-
40
-	/**
41
-	 * Core data changes for this object.
42
-	 *
43
-	 * @since 1.0.19
44
-	 * @var array
45
-	 */
46
-	protected $changes = array();
47
-
48
-	/**
49
-	 * This is false until the object is read from the DB.
50
-	 *
51
-	 * @since 1.0.19
52
-	 * @var bool
53
-	 */
54
-	protected $object_read = false;
55
-
56
-	/**
57
-	 * This is the name of this object type.
58
-	 *
59
-	 * @since 1.0.19
60
-	 * @var string
61
-	 */
62
-	protected $object_type = 'data';
63
-
64
-	/**
65
-	 * Extra data for this object. Name value pairs (name + default value).
66
-	 * Used as a standard way for sub classes (like item types) to add
67
-	 * additional information to an inherited class.
68
-	 *
69
-	 * @since 1.0.19
70
-	 * @var array
71
-	 */
72
-	protected $extra_data = array();
73
-
74
-	/**
75
-	 * Set to _data on construct so we can track and reset data if needed.
76
-	 *
77
-	 * @since 1.0.19
78
-	 * @var array
79
-	 */
80
-	protected $default_data = array();
81
-
82
-	/**
83
-	 * Contains a reference to the data store for this class.
84
-	 *
85
-	 * @since 1.0.19
86
-	 * @var GetPaid_Data_Store
87
-	 */
88
-	protected $data_store;
89
-
90
-	/**
91
-	 * Stores meta in cache for future reads.
92
-	 * A group must be set to to enable caching.
93
-	 *
94
-	 * @since 1.0.19
95
-	 * @var string
96
-	 */
97
-	protected $cache_group = '';
98
-
99
-	/**
100
-	 * Stores the last error.
101
-	 *
102
-	 * @since 1.0.19
103
-	 * @var string
104
-	 */
105
-	public $last_error = '';
106
-
107
-	/**
108
-	 * Stores additional meta data.
109
-	 *
110
-	 * @since 1.0.19
111
-	 * @var array
112
-	 */
113
-	protected $meta_data = null;
114
-
115
-	/**
116
-	 * Default constructor.
117
-	 *
118
-	 * @param int|object|array $read ID to load from the DB (optional) or already queried data.
119
-	 */
120
-	public function __construct( $read = 0 ) {
121
-		$this->data         = array_merge( $this->data, $this->extra_data );
122
-		$this->default_data = $this->data;
123
-	}
124
-
125
-	/**
126
-	 * Only store the object ID to avoid serializing the data object instance.
127
-	 *
128
-	 * @return array
129
-	 */
130
-	public function __sleep() {
131
-		return array( 'id' );
132
-	}
133
-
134
-	/**
135
-	 * Re-run the constructor with the object ID.
136
-	 *
137
-	 * If the object no longer exists, remove the ID.
138
-	 */
139
-	public function __wakeup() {
140
-		$this->__construct( absint( $this->id ) );
141
-
142
-		if ( ! empty( $this->last_error ) ) {
143
-			$this->set_id( 0 );
144
-		}
145
-
146
-	}
147
-
148
-	/**
149
-	 * When the object is cloned, make sure meta is duplicated correctly.
150
-	 *
151
-	 * @since 1.0.19
152
-	 */
153
-	public function __clone() {
154
-		$this->maybe_read_meta_data();
155
-		if ( ! empty( $this->meta_data ) ) {
156
-			foreach ( $this->meta_data as $array_key => $meta ) {
157
-				$this->meta_data[ $array_key ] = clone $meta;
158
-				if ( ! empty( $meta->id ) ) {
159
-					$this->meta_data[ $array_key ]->id = null;
160
-				}
161
-			}
162
-		}
163
-	}
164
-
165
-	/**
166
-	 * Get the data store.
167
-	 *
168
-	 * @since  1.0.19
169
-	 * @return object
170
-	 */
171
-	public function get_data_store() {
172
-		return $this->data_store;
173
-	}
174
-
175
-	/**
176
-	 * Get the object type.
177
-	 *
178
-	 * @since  1.0.19
179
-	 * @return string
180
-	 */
181
-	public function get_object_type() {
182
-		return $this->object_type;
183
-	}
184
-
185
-	/**
186
-	 * Returns the unique ID for this object.
187
-	 *
188
-	 * @since  1.0.19
189
-	 * @return int
190
-	 */
191
-	public function get_id() {
192
-		return $this->id;
193
-	}
194
-
195
-	/**
196
-	 * Get form status.
197
-	 *
198
-	 * @since 1.0.19
199
-	 * @param  string $context View or edit context.
200
-	 * @return string
201
-	 */
202
-	public function get_status( $context = 'view' ) {
203
-		return $this->get_prop( 'status', $context );
204
-    }
205
-
206
-	/**
207
-	 * Delete an object, set the ID to 0, and return result.
208
-	 *
209
-	 * @since  1.0.19
210
-	 * @param  bool $force_delete Should the data be deleted permanently.
211
-	 * @return bool result
212
-	 */
213
-	public function delete( $force_delete = false ) {
214
-		if ( $this->data_store ) {
215
-			$this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
216
-			$this->set_id( 0 );
217
-			return true;
218
-		}
219
-		return false;
220
-	}
221
-
222
-	/**
223
-	 * Save should create or update based on object existence.
224
-	 *
225
-	 * @since  1.0.19
226
-	 * @return int
227
-	 */
228
-	public function save() {
229
-		if ( ! $this->data_store ) {
230
-			return $this->get_id();
231
-		}
232
-
233
-		/**
234
-		 * Trigger action before saving to the DB. Allows you to adjust object props before save.
235
-		 *
236
-		 * @param GetPaid_Data          $this The object being saved.
237
-		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
238
-		 */
239
-		do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
240
-
241
-		if ( $this->get_id() ) {
242
-			$this->data_store->update( $this );
243
-		} else {
244
-			$this->data_store->create( $this );
245
-		}
246
-
247
-		/**
248
-		 * Trigger action after saving to the DB.
249
-		 *
250
-		 * @param GetPaid_Data          $this The object being saved.
251
-		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
252
-		 */
253
-		do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
254
-
255
-		return $this->get_id();
256
-	}
257
-
258
-	/**
259
-	 * Change data to JSON format.
260
-	 *
261
-	 * @since  1.0.19
262
-	 * @return string Data in JSON format.
263
-	 */
264
-	public function __toString() {
265
-		return wp_json_encode( $this->get_data() );
266
-	}
267
-
268
-	/**
269
-	 * Returns all data for this object.
270
-	 *
271
-	 * @since  1.0.19
272
-	 * @return array
273
-	 */
274
-	public function get_data() {
275
-		return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
276
-	}
277
-
278
-	/**
279
-	 * Returns array of expected data keys for this object.
280
-	 *
281
-	 * @since   1.0.19
282
-	 * @return array
283
-	 */
284
-	public function get_data_keys() {
285
-		return array_keys( $this->data );
286
-	}
287
-
288
-	/**
289
-	 * Returns all "extra" data keys for an object (for sub objects like item types).
290
-	 *
291
-	 * @since  1.0.19
292
-	 * @return array
293
-	 */
294
-	public function get_extra_data_keys() {
295
-		return array_keys( $this->extra_data );
296
-	}
297
-
298
-	/**
299
-	 * Filter null meta values from array.
300
-	 *
301
-	 * @since  1.0.19
302
-	 * @param mixed $meta Meta value to check.
303
-	 * @return bool
304
-	 */
305
-	protected function filter_null_meta( $meta ) {
306
-		return ! is_null( $meta->value );
307
-	}
308
-
309
-	/**
310
-	 * Get All Meta Data.
311
-	 *
312
-	 * @since 1.0.19
313
-	 * @return array of objects.
314
-	 */
315
-	public function get_meta_data() {
316
-		$this->maybe_read_meta_data();
317
-		return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
318
-	}
319
-
320
-	/**
321
-	 * Check if the key is an internal one.
322
-	 *
323
-	 * @since  1.0.19
324
-	 * @param  string $key Key to check.
325
-	 * @return bool   true if it's an internal key, false otherwise
326
-	 */
327
-	protected function is_internal_meta_key( $key ) {
328
-		$internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
329
-
330
-		if ( ! $internal_meta_key ) {
331
-			return false;
332
-		}
333
-
334
-		$has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
335
-
336
-		if ( ! $has_setter_or_getter ) {
337
-			return false;
338
-		}
339
-
340
-		/* translators: %s: $key Key to check */
341
-		getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
342
-
343
-		return true;
344
-	}
345
-
346
-	/**
347
-	 * Magic method for setting data fields.
348
-	 *
349
-	 * This method does not update custom fields in the database.
350
-	 *
351
-	 * @since 1.0.19
352
-	 * @access public
353
-	 *
354
-	 */
355
-	public function __set( $key, $value ) {
356
-
357
-		if ( 'id' == strtolower( $key ) ) {
358
-			return $this->set_id( $value );
359
-		}
360
-
361
-		if ( method_exists( $this, "set_$key") ) {
362
-
363
-			/* translators: %s: $key Key to set */
364
-			getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
365
-
366
-			call_user_func( array( $this, "set_$key" ), $value );
367
-		} else {
368
-			$this->set_prop( $key, $value );
369
-		}
370
-
371
-	}
372
-
373
-	/**
24
+    /**
25
+     * ID for this object.
26
+     *
27
+     * @since 1.0.19
28
+     * @var int
29
+     */
30
+    protected $id = 0;
31
+
32
+    /**
33
+     * Core data for this object. Name value pairs (name + default value).
34
+     *
35
+     * @since 1.0.19
36
+     * @var array
37
+     */
38
+    protected $data = array();
39
+
40
+    /**
41
+     * Core data changes for this object.
42
+     *
43
+     * @since 1.0.19
44
+     * @var array
45
+     */
46
+    protected $changes = array();
47
+
48
+    /**
49
+     * This is false until the object is read from the DB.
50
+     *
51
+     * @since 1.0.19
52
+     * @var bool
53
+     */
54
+    protected $object_read = false;
55
+
56
+    /**
57
+     * This is the name of this object type.
58
+     *
59
+     * @since 1.0.19
60
+     * @var string
61
+     */
62
+    protected $object_type = 'data';
63
+
64
+    /**
65
+     * Extra data for this object. Name value pairs (name + default value).
66
+     * Used as a standard way for sub classes (like item types) to add
67
+     * additional information to an inherited class.
68
+     *
69
+     * @since 1.0.19
70
+     * @var array
71
+     */
72
+    protected $extra_data = array();
73
+
74
+    /**
75
+     * Set to _data on construct so we can track and reset data if needed.
76
+     *
77
+     * @since 1.0.19
78
+     * @var array
79
+     */
80
+    protected $default_data = array();
81
+
82
+    /**
83
+     * Contains a reference to the data store for this class.
84
+     *
85
+     * @since 1.0.19
86
+     * @var GetPaid_Data_Store
87
+     */
88
+    protected $data_store;
89
+
90
+    /**
91
+     * Stores meta in cache for future reads.
92
+     * A group must be set to to enable caching.
93
+     *
94
+     * @since 1.0.19
95
+     * @var string
96
+     */
97
+    protected $cache_group = '';
98
+
99
+    /**
100
+     * Stores the last error.
101
+     *
102
+     * @since 1.0.19
103
+     * @var string
104
+     */
105
+    public $last_error = '';
106
+
107
+    /**
108
+     * Stores additional meta data.
109
+     *
110
+     * @since 1.0.19
111
+     * @var array
112
+     */
113
+    protected $meta_data = null;
114
+
115
+    /**
116
+     * Default constructor.
117
+     *
118
+     * @param int|object|array $read ID to load from the DB (optional) or already queried data.
119
+     */
120
+    public function __construct( $read = 0 ) {
121
+        $this->data         = array_merge( $this->data, $this->extra_data );
122
+        $this->default_data = $this->data;
123
+    }
124
+
125
+    /**
126
+     * Only store the object ID to avoid serializing the data object instance.
127
+     *
128
+     * @return array
129
+     */
130
+    public function __sleep() {
131
+        return array( 'id' );
132
+    }
133
+
134
+    /**
135
+     * Re-run the constructor with the object ID.
136
+     *
137
+     * If the object no longer exists, remove the ID.
138
+     */
139
+    public function __wakeup() {
140
+        $this->__construct( absint( $this->id ) );
141
+
142
+        if ( ! empty( $this->last_error ) ) {
143
+            $this->set_id( 0 );
144
+        }
145
+
146
+    }
147
+
148
+    /**
149
+     * When the object is cloned, make sure meta is duplicated correctly.
150
+     *
151
+     * @since 1.0.19
152
+     */
153
+    public function __clone() {
154
+        $this->maybe_read_meta_data();
155
+        if ( ! empty( $this->meta_data ) ) {
156
+            foreach ( $this->meta_data as $array_key => $meta ) {
157
+                $this->meta_data[ $array_key ] = clone $meta;
158
+                if ( ! empty( $meta->id ) ) {
159
+                    $this->meta_data[ $array_key ]->id = null;
160
+                }
161
+            }
162
+        }
163
+    }
164
+
165
+    /**
166
+     * Get the data store.
167
+     *
168
+     * @since  1.0.19
169
+     * @return object
170
+     */
171
+    public function get_data_store() {
172
+        return $this->data_store;
173
+    }
174
+
175
+    /**
176
+     * Get the object type.
177
+     *
178
+     * @since  1.0.19
179
+     * @return string
180
+     */
181
+    public function get_object_type() {
182
+        return $this->object_type;
183
+    }
184
+
185
+    /**
186
+     * Returns the unique ID for this object.
187
+     *
188
+     * @since  1.0.19
189
+     * @return int
190
+     */
191
+    public function get_id() {
192
+        return $this->id;
193
+    }
194
+
195
+    /**
196
+     * Get form status.
197
+     *
198
+     * @since 1.0.19
199
+     * @param  string $context View or edit context.
200
+     * @return string
201
+     */
202
+    public function get_status( $context = 'view' ) {
203
+        return $this->get_prop( 'status', $context );
204
+    }
205
+
206
+    /**
207
+     * Delete an object, set the ID to 0, and return result.
208
+     *
209
+     * @since  1.0.19
210
+     * @param  bool $force_delete Should the data be deleted permanently.
211
+     * @return bool result
212
+     */
213
+    public function delete( $force_delete = false ) {
214
+        if ( $this->data_store ) {
215
+            $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
216
+            $this->set_id( 0 );
217
+            return true;
218
+        }
219
+        return false;
220
+    }
221
+
222
+    /**
223
+     * Save should create or update based on object existence.
224
+     *
225
+     * @since  1.0.19
226
+     * @return int
227
+     */
228
+    public function save() {
229
+        if ( ! $this->data_store ) {
230
+            return $this->get_id();
231
+        }
232
+
233
+        /**
234
+         * Trigger action before saving to the DB. Allows you to adjust object props before save.
235
+         *
236
+         * @param GetPaid_Data          $this The object being saved.
237
+         * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
238
+         */
239
+        do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
240
+
241
+        if ( $this->get_id() ) {
242
+            $this->data_store->update( $this );
243
+        } else {
244
+            $this->data_store->create( $this );
245
+        }
246
+
247
+        /**
248
+         * Trigger action after saving to the DB.
249
+         *
250
+         * @param GetPaid_Data          $this The object being saved.
251
+         * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
252
+         */
253
+        do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
254
+
255
+        return $this->get_id();
256
+    }
257
+
258
+    /**
259
+     * Change data to JSON format.
260
+     *
261
+     * @since  1.0.19
262
+     * @return string Data in JSON format.
263
+     */
264
+    public function __toString() {
265
+        return wp_json_encode( $this->get_data() );
266
+    }
267
+
268
+    /**
269
+     * Returns all data for this object.
270
+     *
271
+     * @since  1.0.19
272
+     * @return array
273
+     */
274
+    public function get_data() {
275
+        return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
276
+    }
277
+
278
+    /**
279
+     * Returns array of expected data keys for this object.
280
+     *
281
+     * @since   1.0.19
282
+     * @return array
283
+     */
284
+    public function get_data_keys() {
285
+        return array_keys( $this->data );
286
+    }
287
+
288
+    /**
289
+     * Returns all "extra" data keys for an object (for sub objects like item types).
290
+     *
291
+     * @since  1.0.19
292
+     * @return array
293
+     */
294
+    public function get_extra_data_keys() {
295
+        return array_keys( $this->extra_data );
296
+    }
297
+
298
+    /**
299
+     * Filter null meta values from array.
300
+     *
301
+     * @since  1.0.19
302
+     * @param mixed $meta Meta value to check.
303
+     * @return bool
304
+     */
305
+    protected function filter_null_meta( $meta ) {
306
+        return ! is_null( $meta->value );
307
+    }
308
+
309
+    /**
310
+     * Get All Meta Data.
311
+     *
312
+     * @since 1.0.19
313
+     * @return array of objects.
314
+     */
315
+    public function get_meta_data() {
316
+        $this->maybe_read_meta_data();
317
+        return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
318
+    }
319
+
320
+    /**
321
+     * Check if the key is an internal one.
322
+     *
323
+     * @since  1.0.19
324
+     * @param  string $key Key to check.
325
+     * @return bool   true if it's an internal key, false otherwise
326
+     */
327
+    protected function is_internal_meta_key( $key ) {
328
+        $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
329
+
330
+        if ( ! $internal_meta_key ) {
331
+            return false;
332
+        }
333
+
334
+        $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
335
+
336
+        if ( ! $has_setter_or_getter ) {
337
+            return false;
338
+        }
339
+
340
+        /* translators: %s: $key Key to check */
341
+        getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
342
+
343
+        return true;
344
+    }
345
+
346
+    /**
347
+     * Magic method for setting data fields.
348
+     *
349
+     * This method does not update custom fields in the database.
350
+     *
351
+     * @since 1.0.19
352
+     * @access public
353
+     *
354
+     */
355
+    public function __set( $key, $value ) {
356
+
357
+        if ( 'id' == strtolower( $key ) ) {
358
+            return $this->set_id( $value );
359
+        }
360
+
361
+        if ( method_exists( $this, "set_$key") ) {
362
+
363
+            /* translators: %s: $key Key to set */
364
+            getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
365
+
366
+            call_user_func( array( $this, "set_$key" ), $value );
367
+        } else {
368
+            $this->set_prop( $key, $value );
369
+        }
370
+
371
+    }
372
+
373
+    /**
374 374
      * Margic method for retrieving a property.
375 375
      */
376 376
     public function __get( $key ) {
@@ -378,10 +378,10 @@  discard block
 block discarded – undo
378 378
         // Check if we have a helper method for that.
379 379
         if ( method_exists( $this, 'get_' . $key ) ) {
380 380
 
381
-			if ( 'post_type' != $key ) {
382
-				/* translators: %s: $key Key to set */
383
-				getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
384
-			}
381
+            if ( 'post_type' != $key ) {
382
+                /* translators: %s: $key Key to set */
383
+                getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
384
+            }
385 385
 
386 386
             return call_user_func( array( $this, 'get_' . $key ) );
387 387
         }
@@ -391,509 +391,509 @@  discard block
 block discarded – undo
391 391
             return $this->post->$key;
392 392
         }
393 393
 
394
-		return $this->get_prop( $key );
395
-
396
-    }
397
-
398
-	/**
399
-	 * Get Meta Data by Key.
400
-	 *
401
-	 * @since  1.0.19
402
-	 * @param  string $key Meta Key.
403
-	 * @param  bool   $single return first found meta with key, or all with $key.
404
-	 * @param  string $context What the value is for. Valid values are view and edit.
405
-	 * @return mixed
406
-	 */
407
-	public function get_meta( $key = '', $single = true, $context = 'view' ) {
408
-
409
-		// Check if this is an internal meta key.
410
-		$_key = str_replace( '_wpinv', '', $key );
411
-		$_key = str_replace( 'wpinv', '', $_key );
412
-		if ( $this->is_internal_meta_key( $_key ) ) {
413
-			$function = 'get_' . $_key;
414
-
415
-			if ( is_callable( array( $this, $function ) ) ) {
416
-				return $this->{$function}();
417
-			}
418
-		}
419
-
420
-		// Read the meta data if not yet read.
421
-		$this->maybe_read_meta_data();
422
-		$meta_data  = $this->get_meta_data();
423
-		$array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
424
-		$value      = $single ? '' : array();
425
-
426
-		if ( ! empty( $array_keys ) ) {
427
-			// We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
428
-			if ( $single ) {
429
-				$value = $meta_data[ current( $array_keys ) ]->value;
430
-			} else {
431
-				$value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
432
-			}
433
-		}
434
-
435
-		if ( 'view' === $context ) {
436
-			$value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
437
-		}
438
-
439
-		return $value;
440
-	}
441
-
442
-	/**
443
-	 * See if meta data exists, since get_meta always returns a '' or array().
444
-	 *
445
-	 * @since  1.0.19
446
-	 * @param  string $key Meta Key.
447
-	 * @return boolean
448
-	 */
449
-	public function meta_exists( $key = '' ) {
450
-		$this->maybe_read_meta_data();
451
-		$array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
452
-		return in_array( $key, $array_keys, true );
453
-	}
454
-
455
-	/**
456
-	 * Set all meta data from array.
457
-	 *
458
-	 * @since 1.0.19
459
-	 * @param array $data Key/Value pairs.
460
-	 */
461
-	public function set_meta_data( $data ) {
462
-		if ( ! empty( $data ) && is_array( $data ) ) {
463
-			$this->maybe_read_meta_data();
464
-			foreach ( $data as $meta ) {
465
-				$meta = (array) $meta;
466
-				if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
467
-					$this->meta_data[] = new GetPaid_Meta_Data(
468
-						array(
469
-							'id'    => $meta['id'],
470
-							'key'   => $meta['key'],
471
-							'value' => $meta['value'],
472
-						)
473
-					);
474
-				}
475
-			}
476
-		}
477
-	}
478
-
479
-	/**
480
-	 * Add meta data.
481
-	 *
482
-	 * @since 1.0.19
483
-	 *
484
-	 * @param string       $key Meta key.
485
-	 * @param string|array $value Meta value.
486
-	 * @param bool         $unique Should this be a unique key?.
487
-	 */
488
-	public function add_meta_data( $key, $value, $unique = false ) {
489
-		if ( $this->is_internal_meta_key( $key ) ) {
490
-			$function = 'set_' . $key;
491
-
492
-			if ( is_callable( array( $this, $function ) ) ) {
493
-				return $this->{$function}( $value );
494
-			}
495
-		}
496
-
497
-		$this->maybe_read_meta_data();
498
-		if ( $unique ) {
499
-			$this->delete_meta_data( $key );
500
-		}
501
-		$this->meta_data[] = new GetPaid_Meta_Data(
502
-			array(
503
-				'key'   => $key,
504
-				'value' => $value,
505
-			)
506
-		);
507
-	}
508
-
509
-	/**
510
-	 * Update meta data by key or ID, if provided.
511
-	 *
512
-	 * @since  1.0.19
513
-	 *
514
-	 * @param  string       $key Meta key.
515
-	 * @param  string|array $value Meta value.
516
-	 * @param  int          $meta_id Meta ID.
517
-	 */
518
-	public function update_meta_data( $key, $value, $meta_id = 0 ) {
519
-		if ( $this->is_internal_meta_key( $key ) ) {
520
-			$function = 'set_' . $key;
521
-
522
-			if ( is_callable( array( $this, $function ) ) ) {
523
-				return $this->{$function}( $value );
524
-			}
525
-		}
526
-
527
-		$this->maybe_read_meta_data();
528
-
529
-		$array_key = false;
530
-
531
-		if ( $meta_id ) {
532
-			$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
533
-			$array_key  = $array_keys ? current( $array_keys ) : false;
534
-		} else {
535
-			// Find matches by key.
536
-			$matches = array();
537
-			foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
538
-				if ( $meta->key === $key ) {
539
-					$matches[] = $meta_data_array_key;
540
-				}
541
-			}
542
-
543
-			if ( ! empty( $matches ) ) {
544
-				// Set matches to null so only one key gets the new value.
545
-				foreach ( $matches as $meta_data_array_key ) {
546
-					$this->meta_data[ $meta_data_array_key ]->value = null;
547
-				}
548
-				$array_key = current( $matches );
549
-			}
550
-		}
551
-
552
-		if ( false !== $array_key ) {
553
-			$meta        = $this->meta_data[ $array_key ];
554
-			$meta->key   = $key;
555
-			$meta->value = $value;
556
-		} else {
557
-			$this->add_meta_data( $key, $value, true );
558
-		}
559
-	}
560
-
561
-	/**
562
-	 * Delete meta data.
563
-	 *
564
-	 * @since 1.0.19
565
-	 * @param string $key Meta key.
566
-	 */
567
-	public function delete_meta_data( $key ) {
568
-		$this->maybe_read_meta_data();
569
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
570
-
571
-		if ( $array_keys ) {
572
-			foreach ( $array_keys as $array_key ) {
573
-				$this->meta_data[ $array_key ]->value = null;
574
-			}
575
-		}
576
-	}
577
-
578
-	/**
579
-	 * Delete meta data.
580
-	 *
581
-	 * @since 1.0.19
582
-	 * @param int $mid Meta ID.
583
-	 */
584
-	public function delete_meta_data_by_mid( $mid ) {
585
-		$this->maybe_read_meta_data();
586
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
587
-
588
-		if ( $array_keys ) {
589
-			foreach ( $array_keys as $array_key ) {
590
-				$this->meta_data[ $array_key ]->value = null;
591
-			}
592
-		}
593
-	}
594
-
595
-	/**
596
-	 * Read meta data if null.
597
-	 *
598
-	 * @since 1.0.19
599
-	 */
600
-	protected function maybe_read_meta_data() {
601
-		if ( is_null( $this->meta_data ) ) {
602
-			$this->read_meta_data();
603
-		}
604
-	}
605
-
606
-	/**
607
-	 * Read Meta Data from the database. Ignore any internal properties.
608
-	 * Uses it's own caches because get_metadata does not provide meta_ids.
609
-	 *
610
-	 * @since 1.0.19
611
-	 * @param bool $force_read True to force a new DB read (and update cache).
612
-	 */
613
-	public function read_meta_data( $force_read = false ) {
614
-		$this->meta_data = array();
615
-		$cache_loaded    = false;
616
-
617
-		if ( ! $this->get_id() ) {
618
-			return;
619
-		}
620
-
621
-		if ( ! $this->data_store ) {
622
-			return;
623
-		}
624
-
625
-		if ( ! empty( $this->cache_group ) ) {
626
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
627
-		}
628
-
629
-		if ( ! $force_read ) {
630
-			if ( ! empty( $this->cache_group ) ) {
631
-				$cached_meta  = wp_cache_get( $cache_key, $this->cache_group );
632
-				$cache_loaded = ! empty( $cached_meta );
633
-			}
634
-		}
635
-
636
-		$raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this );
637
-		if ( $raw_meta_data ) {
638
-			foreach ( $raw_meta_data as $meta ) {
639
-				$this->meta_data[] = new GetPaid_Meta_Data(
640
-					array(
641
-						'id'    => (int) $meta->meta_id,
642
-						'key'   => $meta->meta_key,
643
-						'value' => maybe_unserialize( $meta->meta_value ),
644
-					)
645
-				);
646
-			}
647
-
648
-			if ( ! $cache_loaded && ! empty( $this->cache_group ) ) {
649
-				wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
650
-			}
651
-		}
652
-	}
653
-
654
-	/**
655
-	 * Update Meta Data in the database.
656
-	 *
657
-	 * @since 1.0.19
658
-	 */
659
-	public function save_meta_data() {
660
-		if ( ! $this->data_store || is_null( $this->meta_data ) ) {
661
-			return;
662
-		}
663
-		foreach ( $this->meta_data as $array_key => $meta ) {
664
-			if ( is_null( $meta->value ) ) {
665
-				if ( ! empty( $meta->id ) ) {
666
-					$this->data_store->delete_meta( $this, $meta );
667
-					unset( $this->meta_data[ $array_key ] );
668
-				}
669
-			} elseif ( empty( $meta->id ) ) {
670
-				$meta->id = $this->data_store->add_meta( $this, $meta );
671
-				$meta->apply_changes();
672
-			} else {
673
-				if ( $meta->get_changes() ) {
674
-					$this->data_store->update_meta( $this, $meta );
675
-					$meta->apply_changes();
676
-				}
677
-			}
678
-		}
679
-		if ( ! empty( $this->cache_group ) ) {
680
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
681
-			wp_cache_delete( $cache_key, $this->cache_group );
682
-		}
683
-	}
684
-
685
-	/**
686
-	 * Set ID.
687
-	 *
688
-	 * @since 1.0.19
689
-	 * @param int $id ID.
690
-	 */
691
-	public function set_id( $id ) {
692
-		$this->id = absint( $id );
693
-	}
694
-
695
-	/**
696
-	 * Sets item status.
697
-	 *
698
-	 * @since 1.0.19
699
-	 * @param string $status New status.
700
-	 * @return array details of change.
701
-	 */
702
-	public function set_status( $status ) {
394
+        return $this->get_prop( $key );
395
+
396
+    }
397
+
398
+    /**
399
+     * Get Meta Data by Key.
400
+     *
401
+     * @since  1.0.19
402
+     * @param  string $key Meta Key.
403
+     * @param  bool   $single return first found meta with key, or all with $key.
404
+     * @param  string $context What the value is for. Valid values are view and edit.
405
+     * @return mixed
406
+     */
407
+    public function get_meta( $key = '', $single = true, $context = 'view' ) {
408
+
409
+        // Check if this is an internal meta key.
410
+        $_key = str_replace( '_wpinv', '', $key );
411
+        $_key = str_replace( 'wpinv', '', $_key );
412
+        if ( $this->is_internal_meta_key( $_key ) ) {
413
+            $function = 'get_' . $_key;
414
+
415
+            if ( is_callable( array( $this, $function ) ) ) {
416
+                return $this->{$function}();
417
+            }
418
+        }
419
+
420
+        // Read the meta data if not yet read.
421
+        $this->maybe_read_meta_data();
422
+        $meta_data  = $this->get_meta_data();
423
+        $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
424
+        $value      = $single ? '' : array();
425
+
426
+        if ( ! empty( $array_keys ) ) {
427
+            // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
428
+            if ( $single ) {
429
+                $value = $meta_data[ current( $array_keys ) ]->value;
430
+            } else {
431
+                $value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
432
+            }
433
+        }
434
+
435
+        if ( 'view' === $context ) {
436
+            $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
437
+        }
438
+
439
+        return $value;
440
+    }
441
+
442
+    /**
443
+     * See if meta data exists, since get_meta always returns a '' or array().
444
+     *
445
+     * @since  1.0.19
446
+     * @param  string $key Meta Key.
447
+     * @return boolean
448
+     */
449
+    public function meta_exists( $key = '' ) {
450
+        $this->maybe_read_meta_data();
451
+        $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
452
+        return in_array( $key, $array_keys, true );
453
+    }
454
+
455
+    /**
456
+     * Set all meta data from array.
457
+     *
458
+     * @since 1.0.19
459
+     * @param array $data Key/Value pairs.
460
+     */
461
+    public function set_meta_data( $data ) {
462
+        if ( ! empty( $data ) && is_array( $data ) ) {
463
+            $this->maybe_read_meta_data();
464
+            foreach ( $data as $meta ) {
465
+                $meta = (array) $meta;
466
+                if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
467
+                    $this->meta_data[] = new GetPaid_Meta_Data(
468
+                        array(
469
+                            'id'    => $meta['id'],
470
+                            'key'   => $meta['key'],
471
+                            'value' => $meta['value'],
472
+                        )
473
+                    );
474
+                }
475
+            }
476
+        }
477
+    }
478
+
479
+    /**
480
+     * Add meta data.
481
+     *
482
+     * @since 1.0.19
483
+     *
484
+     * @param string       $key Meta key.
485
+     * @param string|array $value Meta value.
486
+     * @param bool         $unique Should this be a unique key?.
487
+     */
488
+    public function add_meta_data( $key, $value, $unique = false ) {
489
+        if ( $this->is_internal_meta_key( $key ) ) {
490
+            $function = 'set_' . $key;
491
+
492
+            if ( is_callable( array( $this, $function ) ) ) {
493
+                return $this->{$function}( $value );
494
+            }
495
+        }
496
+
497
+        $this->maybe_read_meta_data();
498
+        if ( $unique ) {
499
+            $this->delete_meta_data( $key );
500
+        }
501
+        $this->meta_data[] = new GetPaid_Meta_Data(
502
+            array(
503
+                'key'   => $key,
504
+                'value' => $value,
505
+            )
506
+        );
507
+    }
508
+
509
+    /**
510
+     * Update meta data by key or ID, if provided.
511
+     *
512
+     * @since  1.0.19
513
+     *
514
+     * @param  string       $key Meta key.
515
+     * @param  string|array $value Meta value.
516
+     * @param  int          $meta_id Meta ID.
517
+     */
518
+    public function update_meta_data( $key, $value, $meta_id = 0 ) {
519
+        if ( $this->is_internal_meta_key( $key ) ) {
520
+            $function = 'set_' . $key;
521
+
522
+            if ( is_callable( array( $this, $function ) ) ) {
523
+                return $this->{$function}( $value );
524
+            }
525
+        }
526
+
527
+        $this->maybe_read_meta_data();
528
+
529
+        $array_key = false;
530
+
531
+        if ( $meta_id ) {
532
+            $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
533
+            $array_key  = $array_keys ? current( $array_keys ) : false;
534
+        } else {
535
+            // Find matches by key.
536
+            $matches = array();
537
+            foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
538
+                if ( $meta->key === $key ) {
539
+                    $matches[] = $meta_data_array_key;
540
+                }
541
+            }
542
+
543
+            if ( ! empty( $matches ) ) {
544
+                // Set matches to null so only one key gets the new value.
545
+                foreach ( $matches as $meta_data_array_key ) {
546
+                    $this->meta_data[ $meta_data_array_key ]->value = null;
547
+                }
548
+                $array_key = current( $matches );
549
+            }
550
+        }
551
+
552
+        if ( false !== $array_key ) {
553
+            $meta        = $this->meta_data[ $array_key ];
554
+            $meta->key   = $key;
555
+            $meta->value = $value;
556
+        } else {
557
+            $this->add_meta_data( $key, $value, true );
558
+        }
559
+    }
560
+
561
+    /**
562
+     * Delete meta data.
563
+     *
564
+     * @since 1.0.19
565
+     * @param string $key Meta key.
566
+     */
567
+    public function delete_meta_data( $key ) {
568
+        $this->maybe_read_meta_data();
569
+        $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
570
+
571
+        if ( $array_keys ) {
572
+            foreach ( $array_keys as $array_key ) {
573
+                $this->meta_data[ $array_key ]->value = null;
574
+            }
575
+        }
576
+    }
577
+
578
+    /**
579
+     * Delete meta data.
580
+     *
581
+     * @since 1.0.19
582
+     * @param int $mid Meta ID.
583
+     */
584
+    public function delete_meta_data_by_mid( $mid ) {
585
+        $this->maybe_read_meta_data();
586
+        $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
587
+
588
+        if ( $array_keys ) {
589
+            foreach ( $array_keys as $array_key ) {
590
+                $this->meta_data[ $array_key ]->value = null;
591
+            }
592
+        }
593
+    }
594
+
595
+    /**
596
+     * Read meta data if null.
597
+     *
598
+     * @since 1.0.19
599
+     */
600
+    protected function maybe_read_meta_data() {
601
+        if ( is_null( $this->meta_data ) ) {
602
+            $this->read_meta_data();
603
+        }
604
+    }
605
+
606
+    /**
607
+     * Read Meta Data from the database. Ignore any internal properties.
608
+     * Uses it's own caches because get_metadata does not provide meta_ids.
609
+     *
610
+     * @since 1.0.19
611
+     * @param bool $force_read True to force a new DB read (and update cache).
612
+     */
613
+    public function read_meta_data( $force_read = false ) {
614
+        $this->meta_data = array();
615
+        $cache_loaded    = false;
616
+
617
+        if ( ! $this->get_id() ) {
618
+            return;
619
+        }
620
+
621
+        if ( ! $this->data_store ) {
622
+            return;
623
+        }
624
+
625
+        if ( ! empty( $this->cache_group ) ) {
626
+            $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
627
+        }
628
+
629
+        if ( ! $force_read ) {
630
+            if ( ! empty( $this->cache_group ) ) {
631
+                $cached_meta  = wp_cache_get( $cache_key, $this->cache_group );
632
+                $cache_loaded = ! empty( $cached_meta );
633
+            }
634
+        }
635
+
636
+        $raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this );
637
+        if ( $raw_meta_data ) {
638
+            foreach ( $raw_meta_data as $meta ) {
639
+                $this->meta_data[] = new GetPaid_Meta_Data(
640
+                    array(
641
+                        'id'    => (int) $meta->meta_id,
642
+                        'key'   => $meta->meta_key,
643
+                        'value' => maybe_unserialize( $meta->meta_value ),
644
+                    )
645
+                );
646
+            }
647
+
648
+            if ( ! $cache_loaded && ! empty( $this->cache_group ) ) {
649
+                wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
650
+            }
651
+        }
652
+    }
653
+
654
+    /**
655
+     * Update Meta Data in the database.
656
+     *
657
+     * @since 1.0.19
658
+     */
659
+    public function save_meta_data() {
660
+        if ( ! $this->data_store || is_null( $this->meta_data ) ) {
661
+            return;
662
+        }
663
+        foreach ( $this->meta_data as $array_key => $meta ) {
664
+            if ( is_null( $meta->value ) ) {
665
+                if ( ! empty( $meta->id ) ) {
666
+                    $this->data_store->delete_meta( $this, $meta );
667
+                    unset( $this->meta_data[ $array_key ] );
668
+                }
669
+            } elseif ( empty( $meta->id ) ) {
670
+                $meta->id = $this->data_store->add_meta( $this, $meta );
671
+                $meta->apply_changes();
672
+            } else {
673
+                if ( $meta->get_changes() ) {
674
+                    $this->data_store->update_meta( $this, $meta );
675
+                    $meta->apply_changes();
676
+                }
677
+            }
678
+        }
679
+        if ( ! empty( $this->cache_group ) ) {
680
+            $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
681
+            wp_cache_delete( $cache_key, $this->cache_group );
682
+        }
683
+    }
684
+
685
+    /**
686
+     * Set ID.
687
+     *
688
+     * @since 1.0.19
689
+     * @param int $id ID.
690
+     */
691
+    public function set_id( $id ) {
692
+        $this->id = absint( $id );
693
+    }
694
+
695
+    /**
696
+     * Sets item status.
697
+     *
698
+     * @since 1.0.19
699
+     * @param string $status New status.
700
+     * @return array details of change.
701
+     */
702
+    public function set_status( $status ) {
703 703
         $old_status = $this->get_status();
704 704
 
705
-		$this->set_prop( 'status', $status );
706
-
707
-		return array(
708
-			'from' => $old_status,
709
-			'to'   => $status,
710
-		);
711
-    }
712
-
713
-	/**
714
-	 * Set all props to default values.
715
-	 *
716
-	 * @since 1.0.19
717
-	 */
718
-	public function set_defaults() {
719
-		$this->data    = $this->default_data;
720
-		$this->changes = array();
721
-		$this->set_object_read( false );
722
-	}
723
-
724
-	/**
725
-	 * Set object read property.
726
-	 *
727
-	 * @since 1.0.19
728
-	 * @param boolean $read Should read?.
729
-	 */
730
-	public function set_object_read( $read = true ) {
731
-		$this->object_read = (bool) $read;
732
-	}
733
-
734
-	/**
735
-	 * Get object read property.
736
-	 *
737
-	 * @since  1.0.19
738
-	 * @return boolean
739
-	 */
740
-	public function get_object_read() {
741
-		return (bool) $this->object_read;
742
-	}
743
-
744
-	/**
745
-	 * Set a collection of props in one go, collect any errors, and return the result.
746
-	 * Only sets using public methods.
747
-	 *
748
-	 * @since  1.0.19
749
-	 *
750
-	 * @param array  $props Key value pairs to set. Key is the prop and should map to a setter function name.
751
-	 * @param string $context In what context to run this.
752
-	 *
753
-	 * @return bool|WP_Error
754
-	 */
755
-	public function set_props( $props, $context = 'set' ) {
756
-		$errors = false;
757
-
758
-		foreach ( $props as $prop => $value ) {
759
-			try {
760
-				/**
761
-				 * Checks if the prop being set is allowed, and the value is not null.
762
-				 */
763
-				if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
764
-					continue;
765
-				}
766
-				$setter = "set_$prop";
767
-
768
-				if ( is_callable( array( $this, $setter ) ) ) {
769
-					$this->{$setter}( $value );
770
-				}
771
-			} catch ( Exception $e ) {
772
-				if ( ! $errors ) {
773
-					$errors = new WP_Error();
774
-				}
775
-				$errors->add( $e->getCode(), $e->getMessage() );
776
-				$this->last_error = $e->getMessage();
777
-			}
778
-		}
779
-
780
-		return $errors && count( $errors->get_error_codes() ) ? $errors : true;
781
-	}
782
-
783
-	/**
784
-	 * Sets a prop for a setter method.
785
-	 *
786
-	 * This stores changes in a special array so we can track what needs saving
787
-	 * the the DB later.
788
-	 *
789
-	 * @since 1.0.19
790
-	 * @param string $prop Name of prop to set.
791
-	 * @param mixed  $value Value of the prop.
792
-	 */
793
-	protected function set_prop( $prop, $value ) {
794
-		if ( array_key_exists( $prop, $this->data ) ) {
795
-			if ( true === $this->object_read ) {
796
-				if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
797
-					$this->changes[ $prop ] = $value;
798
-				}
799
-			} else {
800
-				$this->data[ $prop ] = $value;
801
-			}
802
-		}
803
-	}
804
-
805
-	/**
806
-	 * Return data changes only.
807
-	 *
808
-	 * @since 1.0.19
809
-	 * @return array
810
-	 */
811
-	public function get_changes() {
812
-		return $this->changes;
813
-	}
814
-
815
-	/**
816
-	 * Merge changes with data and clear.
817
-	 *
818
-	 * @since 1.0.19
819
-	 */
820
-	public function apply_changes() {
821
-		$this->data    = array_replace_recursive( $this->data, $this->changes );
822
-		$this->changes = array();
823
-	}
824
-
825
-	/**
826
-	 * Prefix for action and filter hooks on data.
827
-	 *
828
-	 * @since  1.0.19
829
-	 * @return string
830
-	 */
831
-	protected function get_hook_prefix() {
832
-		return 'wpinv_get_' . $this->object_type . '_';
833
-	}
834
-
835
-	/**
836
-	 * Gets a prop for a getter method.
837
-	 *
838
-	 * Gets the value from either current pending changes, or the data itself.
839
-	 * Context controls what happens to the value before it's returned.
840
-	 *
841
-	 * @since  1.0.19
842
-	 * @param  string $prop Name of prop to get.
843
-	 * @param  string $context What the value is for. Valid values are view and edit.
844
-	 * @return mixed
845
-	 */
846
-	protected function get_prop( $prop, $context = 'view' ) {
847
-		$value = null;
848
-
849
-		if ( array_key_exists( $prop, $this->data ) ) {
850
-			$value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
851
-
852
-			if ( 'view' === $context ) {
853
-				$value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
854
-			}
855
-		}
856
-
857
-		return $value;
858
-	}
859
-
860
-	/**
861
-	 * Sets a date prop whilst handling formatting and datetime objects.
862
-	 *
863
-	 * @since 1.0.19
864
-	 * @param string         $prop Name of prop to set.
865
-	 * @param string|integer $value Value of the prop.
866
-	 */
867
-	protected function set_date_prop( $prop, $value ) {
868
-
869
-		if ( empty( $value ) ) {
870
-			$this->set_prop( $prop, null );
871
-			return;
872
-		}
873
-		$this->set_prop( $prop, $value );
874
-
875
-	}
876
-
877
-	/**
878
-	 * When invalid data is found, throw an exception unless reading from the DB.
879
-	 *
880
-	 * @since 1.0.19
881
-	 * @param string $code             Error code.
882
-	 * @param string $message          Error message.
883
-	 */
884
-	protected function error( $code, $message ) {
885
-		$this->last_error = $message;
886
-	}
887
-
888
-	/**
889
-	 * Checks if the object is saved in the database
890
-	 *
891
-	 * @since 1.0.19
892
-	 * @return bool
893
-	 */
894
-	public function exists() {
895
-		$id = $this->get_id();
896
-		return ! empty( $id );
897
-	}
705
+        $this->set_prop( 'status', $status );
706
+
707
+        return array(
708
+            'from' => $old_status,
709
+            'to'   => $status,
710
+        );
711
+    }
712
+
713
+    /**
714
+     * Set all props to default values.
715
+     *
716
+     * @since 1.0.19
717
+     */
718
+    public function set_defaults() {
719
+        $this->data    = $this->default_data;
720
+        $this->changes = array();
721
+        $this->set_object_read( false );
722
+    }
723
+
724
+    /**
725
+     * Set object read property.
726
+     *
727
+     * @since 1.0.19
728
+     * @param boolean $read Should read?.
729
+     */
730
+    public function set_object_read( $read = true ) {
731
+        $this->object_read = (bool) $read;
732
+    }
733
+
734
+    /**
735
+     * Get object read property.
736
+     *
737
+     * @since  1.0.19
738
+     * @return boolean
739
+     */
740
+    public function get_object_read() {
741
+        return (bool) $this->object_read;
742
+    }
743
+
744
+    /**
745
+     * Set a collection of props in one go, collect any errors, and return the result.
746
+     * Only sets using public methods.
747
+     *
748
+     * @since  1.0.19
749
+     *
750
+     * @param array  $props Key value pairs to set. Key is the prop and should map to a setter function name.
751
+     * @param string $context In what context to run this.
752
+     *
753
+     * @return bool|WP_Error
754
+     */
755
+    public function set_props( $props, $context = 'set' ) {
756
+        $errors = false;
757
+
758
+        foreach ( $props as $prop => $value ) {
759
+            try {
760
+                /**
761
+                 * Checks if the prop being set is allowed, and the value is not null.
762
+                 */
763
+                if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
764
+                    continue;
765
+                }
766
+                $setter = "set_$prop";
767
+
768
+                if ( is_callable( array( $this, $setter ) ) ) {
769
+                    $this->{$setter}( $value );
770
+                }
771
+            } catch ( Exception $e ) {
772
+                if ( ! $errors ) {
773
+                    $errors = new WP_Error();
774
+                }
775
+                $errors->add( $e->getCode(), $e->getMessage() );
776
+                $this->last_error = $e->getMessage();
777
+            }
778
+        }
779
+
780
+        return $errors && count( $errors->get_error_codes() ) ? $errors : true;
781
+    }
782
+
783
+    /**
784
+     * Sets a prop for a setter method.
785
+     *
786
+     * This stores changes in a special array so we can track what needs saving
787
+     * the the DB later.
788
+     *
789
+     * @since 1.0.19
790
+     * @param string $prop Name of prop to set.
791
+     * @param mixed  $value Value of the prop.
792
+     */
793
+    protected function set_prop( $prop, $value ) {
794
+        if ( array_key_exists( $prop, $this->data ) ) {
795
+            if ( true === $this->object_read ) {
796
+                if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
797
+                    $this->changes[ $prop ] = $value;
798
+                }
799
+            } else {
800
+                $this->data[ $prop ] = $value;
801
+            }
802
+        }
803
+    }
804
+
805
+    /**
806
+     * Return data changes only.
807
+     *
808
+     * @since 1.0.19
809
+     * @return array
810
+     */
811
+    public function get_changes() {
812
+        return $this->changes;
813
+    }
814
+
815
+    /**
816
+     * Merge changes with data and clear.
817
+     *
818
+     * @since 1.0.19
819
+     */
820
+    public function apply_changes() {
821
+        $this->data    = array_replace_recursive( $this->data, $this->changes );
822
+        $this->changes = array();
823
+    }
824
+
825
+    /**
826
+     * Prefix for action and filter hooks on data.
827
+     *
828
+     * @since  1.0.19
829
+     * @return string
830
+     */
831
+    protected function get_hook_prefix() {
832
+        return 'wpinv_get_' . $this->object_type . '_';
833
+    }
834
+
835
+    /**
836
+     * Gets a prop for a getter method.
837
+     *
838
+     * Gets the value from either current pending changes, or the data itself.
839
+     * Context controls what happens to the value before it's returned.
840
+     *
841
+     * @since  1.0.19
842
+     * @param  string $prop Name of prop to get.
843
+     * @param  string $context What the value is for. Valid values are view and edit.
844
+     * @return mixed
845
+     */
846
+    protected function get_prop( $prop, $context = 'view' ) {
847
+        $value = null;
848
+
849
+        if ( array_key_exists( $prop, $this->data ) ) {
850
+            $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
851
+
852
+            if ( 'view' === $context ) {
853
+                $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
854
+            }
855
+        }
856
+
857
+        return $value;
858
+    }
859
+
860
+    /**
861
+     * Sets a date prop whilst handling formatting and datetime objects.
862
+     *
863
+     * @since 1.0.19
864
+     * @param string         $prop Name of prop to set.
865
+     * @param string|integer $value Value of the prop.
866
+     */
867
+    protected function set_date_prop( $prop, $value ) {
868
+
869
+        if ( empty( $value ) ) {
870
+            $this->set_prop( $prop, null );
871
+            return;
872
+        }
873
+        $this->set_prop( $prop, $value );
874
+
875
+    }
876
+
877
+    /**
878
+     * When invalid data is found, throw an exception unless reading from the DB.
879
+     *
880
+     * @since 1.0.19
881
+     * @param string $code             Error code.
882
+     * @param string $message          Error message.
883
+     */
884
+    protected function error( $code, $message ) {
885
+        $this->last_error = $message;
886
+    }
887
+
888
+    /**
889
+     * Checks if the object is saved in the database
890
+     *
891
+     * @since 1.0.19
892
+     * @return bool
893
+     */
894
+    public function exists() {
895
+        $id = $this->get_id();
896
+        return ! empty( $id );
897
+    }
898 898
 
899 899
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-invoice-data-store.php 1 patch
Indentation   +441 added lines, -441 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit;
8
+    exit;
9 9
 }
10 10
 
11 11
 /**
@@ -15,510 +15,510 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Invoice_Data_Store extends GetPaid_Data_Store_WP {
17 17
 
18
-	/**
19
-	 * Data stored in meta keys, but not considered "meta" for a discount.
20
-	 *
21
-	 * @since 1.0.19
22
-	 * @var array
23
-	 */
24
-	protected $internal_meta_keys = array(
25
-		'_wpinv_subscr_profile_id',
26
-		'_wpinv_taxes',
27
-		'_wpinv_fees',
28
-		'_wpinv_discounts',
29
-		'_wpinv_submission_id',
30
-		'_wpinv_payment_form',
31
-		'_wpinv_is_viewed',
32
-		'wpinv_email_cc',
33
-		'wpinv_template'
34
-	);
35
-
36
-	/**
37
-	 * A map of meta keys to data props.
38
-	 *
39
-	 * @since 1.0.19
40
-	 *
41
-	 * @var array
42
-	 */
43
-	protected $meta_key_to_props = array(
44
-		'_wpinv_subscr_profile_id' => 'subscription_id',
45
-		'_wpinv_taxes'             => 'taxes',
46
-		'_wpinv_fees'              => 'fees',
47
-		'_wpinv_discounts'         => 'discounts',
48
-		'_wpinv_submission_id'     => 'submission_id',
49
-		'_wpinv_payment_form'      => 'payment_form',
50
-		'_wpinv_is_viewed'         => 'is_viewed',
51
-		'wpinv_email_cc'           => 'email_cc',
52
-		'wpinv_template'           => 'template',
53
-	);
54
-
55
-	/**
56
-	 * A map of database fields to data props.
57
-	 *
58
-	 * @since 1.0.19
59
-	 *
60
-	 * @var array
61
-	 */
62
-	protected $database_fields_to_props = array(
63
-		'post_id'            => 'id',
64
-		'number'             => 'number',
65
-		'currency'           => 'currency',
66
-		'key'                => 'key',
67
-		'type'               => 'type',
68
-		'mode'               => 'mode',
69
-		'user_ip'            => 'user_ip',
70
-		'first_name'         => 'first_name',
71
-		'last_name'          => 'last_name',
72
-		'address'            => 'address',
73
-		'city'               => 'city',
74
-		'state'              => 'state',
75
-		'country'            => 'country',
76
-		'zip'                => 'zip',
77
-		'zip'                => 'zip',
78
-		'adddress_confirmed' => 'address_confirmed',
79
-		'gateway'            => 'gateway',
80
-		'transaction_id'     => 'transaction_id',
81
-		'currency'           => 'currency',
82
-		'subtotal'           => 'subtotal',
83
-		'tax'                => 'total_tax',
84
-		'fees_total'         => 'total_fees',
85
-		'discount'           => 'total_discount',
86
-		'total'              => 'total',
87
-		'discount_code'      => 'discount_code',
88
-		'disable_taxes'      => 'disable_taxes',
89
-		'due_date'           => 'due_date',
90
-		'completed_date'     => 'completed_date',
91
-		'company'            => 'company',
92
-		'vat_number'         => 'vat_number',
93
-		'vat_rate'           => 'vat_rate',
94
-	);
95
-
96
-	/*
18
+    /**
19
+     * Data stored in meta keys, but not considered "meta" for a discount.
20
+     *
21
+     * @since 1.0.19
22
+     * @var array
23
+     */
24
+    protected $internal_meta_keys = array(
25
+        '_wpinv_subscr_profile_id',
26
+        '_wpinv_taxes',
27
+        '_wpinv_fees',
28
+        '_wpinv_discounts',
29
+        '_wpinv_submission_id',
30
+        '_wpinv_payment_form',
31
+        '_wpinv_is_viewed',
32
+        'wpinv_email_cc',
33
+        'wpinv_template'
34
+    );
35
+
36
+    /**
37
+     * A map of meta keys to data props.
38
+     *
39
+     * @since 1.0.19
40
+     *
41
+     * @var array
42
+     */
43
+    protected $meta_key_to_props = array(
44
+        '_wpinv_subscr_profile_id' => 'subscription_id',
45
+        '_wpinv_taxes'             => 'taxes',
46
+        '_wpinv_fees'              => 'fees',
47
+        '_wpinv_discounts'         => 'discounts',
48
+        '_wpinv_submission_id'     => 'submission_id',
49
+        '_wpinv_payment_form'      => 'payment_form',
50
+        '_wpinv_is_viewed'         => 'is_viewed',
51
+        'wpinv_email_cc'           => 'email_cc',
52
+        'wpinv_template'           => 'template',
53
+    );
54
+
55
+    /**
56
+     * A map of database fields to data props.
57
+     *
58
+     * @since 1.0.19
59
+     *
60
+     * @var array
61
+     */
62
+    protected $database_fields_to_props = array(
63
+        'post_id'            => 'id',
64
+        'number'             => 'number',
65
+        'currency'           => 'currency',
66
+        'key'                => 'key',
67
+        'type'               => 'type',
68
+        'mode'               => 'mode',
69
+        'user_ip'            => 'user_ip',
70
+        'first_name'         => 'first_name',
71
+        'last_name'          => 'last_name',
72
+        'address'            => 'address',
73
+        'city'               => 'city',
74
+        'state'              => 'state',
75
+        'country'            => 'country',
76
+        'zip'                => 'zip',
77
+        'zip'                => 'zip',
78
+        'adddress_confirmed' => 'address_confirmed',
79
+        'gateway'            => 'gateway',
80
+        'transaction_id'     => 'transaction_id',
81
+        'currency'           => 'currency',
82
+        'subtotal'           => 'subtotal',
83
+        'tax'                => 'total_tax',
84
+        'fees_total'         => 'total_fees',
85
+        'discount'           => 'total_discount',
86
+        'total'              => 'total',
87
+        'discount_code'      => 'discount_code',
88
+        'disable_taxes'      => 'disable_taxes',
89
+        'due_date'           => 'due_date',
90
+        'completed_date'     => 'completed_date',
91
+        'company'            => 'company',
92
+        'vat_number'         => 'vat_number',
93
+        'vat_rate'           => 'vat_rate',
94
+    );
95
+
96
+    /*
97 97
 	|--------------------------------------------------------------------------
98 98
 	| CRUD Methods
99 99
 	|--------------------------------------------------------------------------
100 100
 	*/
101
-	/**
102
-	 * Method to create a new invoice in the database.
103
-	 *
104
-	 * @param WPInv_Invoice $invoice Invoice object.
105
-	 */
106
-	public function create( &$invoice ) {
107
-		$invoice->set_version( WPINV_VERSION );
108
-		$invoice->set_date_created( current_time('mysql') );
109
-
110
-		// Create a new post.
111
-		$id = wp_insert_post(
112
-			apply_filters(
113
-				'getpaid_new_invoice_data',
114
-				array(
115
-					'post_date'     => $invoice->get_date_created( 'edit' ),
116
-					'post_type'     => $invoice->get_post_type( 'edit' ),
117
-					'post_status'   => $this->get_post_status( $invoice ),
118
-					'ping_status'   => 'closed',
119
-					'post_author'   => $invoice->get_user_id( 'edit' ),
120
-					'post_title'    => $invoice->get_title( 'edit' ),
121
-					'post_excerpt'  => $invoice->get_description( 'edit' ),
122
-					'post_parent'   => $invoice->get_parent_id( 'edit' ),
123
-					'post_name'     => $invoice->get_path( 'edit' ),
124
-				)
125
-			),
126
-			true
127
-		);
128
-
129
-		if ( $id && ! is_wp_error( $id ) ) {
130
-
131
-			// Update the new id and regenerate a title.
132
-			$invoice->set_id( $id );
133
-			wp_update_post( array( 'ID' => $invoice->get_id(), 'post_title' => $invoice->get_number( 'edit' ) ) );
134
-
135
-			// Ensure both the key and number are set.
136
-			$invoice->get_key();
137
-			$invoice->get_number();
138
-
139
-			// Save special fields and items.
140
-			$this->save_special_fields( $invoice );
141
-			$this->save_items( $invoice );
142
-
143
-			// Update meta data.
144
-			$this->update_post_meta( $invoice );
145
-			$invoice->save_meta_data();
146
-
147
-			// Apply changes.
148
-			$invoice->apply_changes();
149
-			$this->clear_caches( $invoice );
150
-
151
-			// Fires after a new invoice is created.
152
-			do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice );
153
-			return true;
154
-		}
155
-
156
-		if ( is_wp_error( $id ) ) {
157
-			$invoice->last_error = $id->get_error_message();
158
-		}
159
-
160
-		return false;
161
-	}
162
-
163
-	/**
164
-	 * Method to read an invoice from the database.
165
-	 *
166
-	 * @param WPInv_Invoice $invoice Invoice object.
167
-	 *
168
-	 */
169
-	public function read( &$invoice ) {
170
-
171
-		$invoice->set_defaults();
172
-		$invoice_object = get_post( $invoice->get_id() );
173
-
174
-		if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
175
-			$invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
176
-			$invoice->set_id( 0 );
177
-			return false;
178
-		}
179
-
180
-		$invoice->set_props(
181
-			array(
182
-				'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
183
-				'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
184
-				'status'        => $invoice_object->post_status,
185
-				'author'        => $invoice_object->post_author,
186
-				'description'   => $invoice_object->post_excerpt,
187
-				'parent_id'     => $invoice_object->post_parent,
188
-				'name'          => $invoice_object->post_title,
189
-				'path'          => $invoice_object->post_name,
190
-				'post_type'     => $invoice_object->post_type,
191
-			)
192
-		);
193
-
194
-		$invoice->set_type( $invoice_object->post_type );
195
-
196
-		$this->read_object_data( $invoice, $invoice_object );
197
-		$this->add_special_fields( $invoice );
198
-		$this->add_items( $invoice );
199
-		$invoice->read_meta_data();
200
-		$invoice->set_object_read( true );
201
-		do_action( 'getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice );
202
-
203
-	}
204
-
205
-	/**
206
-	 * Method to update an invoice in the database.
207
-	 *
208
-	 * @param WPInv_Invoice $invoice Invoice object.
209
-	 */
210
-	public function update( &$invoice ) {
211
-		$invoice->save_meta_data();
212
-		$invoice->set_version( WPINV_VERSION );
213
-
214
-		if ( null === $invoice->get_date_created( 'edit' ) ) {
215
-			$invoice->set_date_created(  current_time('mysql') );
216
-		}
217
-
218
-		// Ensure both the key and number are set.
219
-		$invoice->get_key();
220
-		$invoice->get_number();
221
-
222
-		// Grab the current status so we can compare.
223
-		$previous_status = get_post_status( $invoice->get_id() );
224
-
225
-		$changes = $invoice->get_changes();
226
-
227
-		// Only update the post when the post data changes.
228
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
229
-			$post_data = array(
230
-				'post_date'         => $invoice->get_date_created( 'edit' ),
231
-				'post_date_gmt'     => $invoice->get_date_created_gmt( 'edit' ),
232
-				'post_status'       => $invoice->get_status( 'edit' ),
233
-				'post_title'        => $invoice->get_name( 'edit' ),
234
-				'post_author'       => $invoice->get_user_id( 'edit' ),
235
-				'post_modified'     => $invoice->get_date_modified( 'edit' ),
236
-				'post_excerpt'      => $invoice->get_description( 'edit' ),
237
-				'post_parent'       => $invoice->get_parent_id( 'edit' ),
238
-				'post_name'         => $invoice->get_path( 'edit' ),
239
-				'post_type'         => $invoice->get_post_type( 'edit' ),
240
-			);
241
-
242
-			/**
243
-			 * When updating this object, to prevent infinite loops, use $wpdb
244
-			 * to update data, since wp_update_post spawns more calls to the
245
-			 * save_post action.
246
-			 *
247
-			 * This ensures hooks are fired by either WP itself (admin screen save),
248
-			 * or an update purely from CRUD.
249
-			 */
250
-			if ( doing_action( 'save_post' ) ) {
251
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
252
-				clean_post_cache( $invoice->get_id() );
253
-			} else {
254
-				wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
255
-			}
256
-			$invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
257
-		}
258
-
259
-		// Update meta data.
260
-		$this->update_post_meta( $invoice );
261
-
262
-		// Save special fields and items.
263
-		$this->save_special_fields( $invoice );
264
-		$this->save_items( $invoice );
265
-
266
-		// Apply the changes.
267
-		$invoice->apply_changes();
268
-
269
-		// Clear caches.
270
-		$this->clear_caches( $invoice );
271
-
272
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
273
-		$new_status = $invoice->get_status( 'edit' );
274
-
275
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
276
-			do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice );
277
-		} else {
278
-			do_action( 'getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice );
279
-		}
280
-
281
-	}
282
-
283
-	/*
101
+    /**
102
+     * Method to create a new invoice in the database.
103
+     *
104
+     * @param WPInv_Invoice $invoice Invoice object.
105
+     */
106
+    public function create( &$invoice ) {
107
+        $invoice->set_version( WPINV_VERSION );
108
+        $invoice->set_date_created( current_time('mysql') );
109
+
110
+        // Create a new post.
111
+        $id = wp_insert_post(
112
+            apply_filters(
113
+                'getpaid_new_invoice_data',
114
+                array(
115
+                    'post_date'     => $invoice->get_date_created( 'edit' ),
116
+                    'post_type'     => $invoice->get_post_type( 'edit' ),
117
+                    'post_status'   => $this->get_post_status( $invoice ),
118
+                    'ping_status'   => 'closed',
119
+                    'post_author'   => $invoice->get_user_id( 'edit' ),
120
+                    'post_title'    => $invoice->get_title( 'edit' ),
121
+                    'post_excerpt'  => $invoice->get_description( 'edit' ),
122
+                    'post_parent'   => $invoice->get_parent_id( 'edit' ),
123
+                    'post_name'     => $invoice->get_path( 'edit' ),
124
+                )
125
+            ),
126
+            true
127
+        );
128
+
129
+        if ( $id && ! is_wp_error( $id ) ) {
130
+
131
+            // Update the new id and regenerate a title.
132
+            $invoice->set_id( $id );
133
+            wp_update_post( array( 'ID' => $invoice->get_id(), 'post_title' => $invoice->get_number( 'edit' ) ) );
134
+
135
+            // Ensure both the key and number are set.
136
+            $invoice->get_key();
137
+            $invoice->get_number();
138
+
139
+            // Save special fields and items.
140
+            $this->save_special_fields( $invoice );
141
+            $this->save_items( $invoice );
142
+
143
+            // Update meta data.
144
+            $this->update_post_meta( $invoice );
145
+            $invoice->save_meta_data();
146
+
147
+            // Apply changes.
148
+            $invoice->apply_changes();
149
+            $this->clear_caches( $invoice );
150
+
151
+            // Fires after a new invoice is created.
152
+            do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice );
153
+            return true;
154
+        }
155
+
156
+        if ( is_wp_error( $id ) ) {
157
+            $invoice->last_error = $id->get_error_message();
158
+        }
159
+
160
+        return false;
161
+    }
162
+
163
+    /**
164
+     * Method to read an invoice from the database.
165
+     *
166
+     * @param WPInv_Invoice $invoice Invoice object.
167
+     *
168
+     */
169
+    public function read( &$invoice ) {
170
+
171
+        $invoice->set_defaults();
172
+        $invoice_object = get_post( $invoice->get_id() );
173
+
174
+        if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
175
+            $invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
176
+            $invoice->set_id( 0 );
177
+            return false;
178
+        }
179
+
180
+        $invoice->set_props(
181
+            array(
182
+                'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
183
+                'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
184
+                'status'        => $invoice_object->post_status,
185
+                'author'        => $invoice_object->post_author,
186
+                'description'   => $invoice_object->post_excerpt,
187
+                'parent_id'     => $invoice_object->post_parent,
188
+                'name'          => $invoice_object->post_title,
189
+                'path'          => $invoice_object->post_name,
190
+                'post_type'     => $invoice_object->post_type,
191
+            )
192
+        );
193
+
194
+        $invoice->set_type( $invoice_object->post_type );
195
+
196
+        $this->read_object_data( $invoice, $invoice_object );
197
+        $this->add_special_fields( $invoice );
198
+        $this->add_items( $invoice );
199
+        $invoice->read_meta_data();
200
+        $invoice->set_object_read( true );
201
+        do_action( 'getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice );
202
+
203
+    }
204
+
205
+    /**
206
+     * Method to update an invoice in the database.
207
+     *
208
+     * @param WPInv_Invoice $invoice Invoice object.
209
+     */
210
+    public function update( &$invoice ) {
211
+        $invoice->save_meta_data();
212
+        $invoice->set_version( WPINV_VERSION );
213
+
214
+        if ( null === $invoice->get_date_created( 'edit' ) ) {
215
+            $invoice->set_date_created(  current_time('mysql') );
216
+        }
217
+
218
+        // Ensure both the key and number are set.
219
+        $invoice->get_key();
220
+        $invoice->get_number();
221
+
222
+        // Grab the current status so we can compare.
223
+        $previous_status = get_post_status( $invoice->get_id() );
224
+
225
+        $changes = $invoice->get_changes();
226
+
227
+        // Only update the post when the post data changes.
228
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
229
+            $post_data = array(
230
+                'post_date'         => $invoice->get_date_created( 'edit' ),
231
+                'post_date_gmt'     => $invoice->get_date_created_gmt( 'edit' ),
232
+                'post_status'       => $invoice->get_status( 'edit' ),
233
+                'post_title'        => $invoice->get_name( 'edit' ),
234
+                'post_author'       => $invoice->get_user_id( 'edit' ),
235
+                'post_modified'     => $invoice->get_date_modified( 'edit' ),
236
+                'post_excerpt'      => $invoice->get_description( 'edit' ),
237
+                'post_parent'       => $invoice->get_parent_id( 'edit' ),
238
+                'post_name'         => $invoice->get_path( 'edit' ),
239
+                'post_type'         => $invoice->get_post_type( 'edit' ),
240
+            );
241
+
242
+            /**
243
+             * When updating this object, to prevent infinite loops, use $wpdb
244
+             * to update data, since wp_update_post spawns more calls to the
245
+             * save_post action.
246
+             *
247
+             * This ensures hooks are fired by either WP itself (admin screen save),
248
+             * or an update purely from CRUD.
249
+             */
250
+            if ( doing_action( 'save_post' ) ) {
251
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
252
+                clean_post_cache( $invoice->get_id() );
253
+            } else {
254
+                wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
255
+            }
256
+            $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
257
+        }
258
+
259
+        // Update meta data.
260
+        $this->update_post_meta( $invoice );
261
+
262
+        // Save special fields and items.
263
+        $this->save_special_fields( $invoice );
264
+        $this->save_items( $invoice );
265
+
266
+        // Apply the changes.
267
+        $invoice->apply_changes();
268
+
269
+        // Clear caches.
270
+        $this->clear_caches( $invoice );
271
+
272
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
273
+        $new_status = $invoice->get_status( 'edit' );
274
+
275
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
276
+            do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice );
277
+        } else {
278
+            do_action( 'getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice );
279
+        }
280
+
281
+    }
282
+
283
+    /*
284 284
 	|--------------------------------------------------------------------------
285 285
 	| Additional Methods
286 286
 	|--------------------------------------------------------------------------
287 287
 	*/
288 288
 
289
-	/**
289
+    /**
290 290
      * Retrieves special fields and adds to the invoice.
291
-	 *
292
-	 * @param WPInv_Invoice $invoice Invoice object.
291
+     *
292
+     * @param WPInv_Invoice $invoice Invoice object.
293 293
      */
294 294
     public function add_special_fields( &$invoice ) {
295
-		global $wpdb;
295
+        global $wpdb;
296 296
 
297
-		// Maybe retrieve from the cache.
298
-		$data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
297
+        // Maybe retrieve from the cache.
298
+        $data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
299 299
 
300
-		// If not found, retrieve from the db.
301
-		if ( false === $data ) {
302
-			$table =  $wpdb->prefix . 'getpaid_invoices';
300
+        // If not found, retrieve from the db.
301
+        if ( false === $data ) {
302
+            $table =  $wpdb->prefix . 'getpaid_invoices';
303 303
 
304
-			$data  = $wpdb->get_row(
305
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
306
-				ARRAY_A
307
-			);
304
+            $data  = $wpdb->get_row(
305
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
306
+                ARRAY_A
307
+            );
308 308
 
309
-			// Update the cache with our data
310
-			wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
309
+            // Update the cache with our data
310
+            wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
311 311
 
312
-		}
312
+        }
313 313
 
314
-		// Abort if the data does not exist.
315
-		if ( empty( $data ) ) {
316
-			$invoice->set_object_read( true );
317
-			$invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
318
-			return;
319
-		}
314
+        // Abort if the data does not exist.
315
+        if ( empty( $data ) ) {
316
+            $invoice->set_object_read( true );
317
+            $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
318
+            return;
319
+        }
320 320
 
321
-		$props = array();
321
+        $props = array();
322 322
 
323
-		foreach ( $this->database_fields_to_props as $db_field => $prop ) {
323
+        foreach ( $this->database_fields_to_props as $db_field => $prop ) {
324 324
 			
325
-			if ( $db_field == 'post_id' ) {
326
-				continue;
327
-			}
328
-
329
-			$props[ $prop ] = $data[ $db_field ];
330
-		}
331
-
332
-		$invoice->set_props( $props );
333
-
334
-	}
335
-
336
-	/**
337
-	 * Gets a list of special fields that need updated based on change state
338
-	 * or if they are present in the database or not.
339
-	 *
340
-	 * @param  WPInv_Invoice $invoice       The Invoice object.
341
-	 * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
342
-	 */
343
-	protected function get_special_fields_to_update( $invoice ) {
344
-		$fields_to_update = array();
345
-		$changed_props   = $invoice->get_changes();
346
-
347
-		// Props should be updated if they are a part of the $changed array or don't exist yet.
348
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
349
-			if ( array_key_exists( $prop, $changed_props ) ) {
350
-				$fields_to_update[ $database_field ] = $prop;
351
-			}
352
-		}
353
-
354
-		return $fields_to_update;
355
-	}
356
-
357
-	/**
358
-	 * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
359
-	 *
360
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
361
-	 * @since 1.0.19
362
-	 */
363
-	protected function update_special_fields( &$invoice ) {
364
-		global $wpdb;
365
-
366
-		$updated_props    = array();
367
-		$fields_to_update = $this->get_special_fields_to_update( $invoice );
368
-
369
-		foreach ( $fields_to_update as $database_field => $prop ) {
370
-			$value = $invoice->{"get_$prop"}( 'edit' );
371
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
372
-			$value = is_bool( $value ) ? ( int ) $value : $value;
373
-			$updated_props[ $database_field ] = maybe_serialize( $value );
374
-		}
375
-
376
-		if ( ! empty( $updated_props ) ) {
377
-
378
-			$table = $wpdb->prefix . 'getpaid_invoices';
379
-			$wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
380
-			wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
381
-			do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props );
382
-
383
-		}
384
-
385
-	}
386
-
387
-	/**
388
-	 * Helper method that inserts special fields to the database.
389
-	 *
390
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
391
-	 * @since 1.0.19
392
-	 */
393
-	protected function insert_special_fields( &$invoice ) {
394
-		global $wpdb;
395
-
396
-		$updated_props   = array();
397
-
398
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
399
-			$value = $invoice->{"get_$prop"}( 'edit' );
400
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
401
-			$value = is_bool( $value ) ? ( int ) $value : $value;
402
-			$updated_props[ $database_field ] = maybe_serialize( $value );
403
-		}
404
-
405
-		$table = $wpdb->prefix . 'getpaid_invoices';
406
-		$wpdb->insert( $table, $updated_props );
407
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
408
-		do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props );
409
-
410
-	}
411
-
412
-	/**
325
+            if ( $db_field == 'post_id' ) {
326
+                continue;
327
+            }
328
+
329
+            $props[ $prop ] = $data[ $db_field ];
330
+        }
331
+
332
+        $invoice->set_props( $props );
333
+
334
+    }
335
+
336
+    /**
337
+     * Gets a list of special fields that need updated based on change state
338
+     * or if they are present in the database or not.
339
+     *
340
+     * @param  WPInv_Invoice $invoice       The Invoice object.
341
+     * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
342
+     */
343
+    protected function get_special_fields_to_update( $invoice ) {
344
+        $fields_to_update = array();
345
+        $changed_props   = $invoice->get_changes();
346
+
347
+        // Props should be updated if they are a part of the $changed array or don't exist yet.
348
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
349
+            if ( array_key_exists( $prop, $changed_props ) ) {
350
+                $fields_to_update[ $database_field ] = $prop;
351
+            }
352
+        }
353
+
354
+        return $fields_to_update;
355
+    }
356
+
357
+    /**
358
+     * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
359
+     *
360
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
361
+     * @since 1.0.19
362
+     */
363
+    protected function update_special_fields( &$invoice ) {
364
+        global $wpdb;
365
+
366
+        $updated_props    = array();
367
+        $fields_to_update = $this->get_special_fields_to_update( $invoice );
368
+
369
+        foreach ( $fields_to_update as $database_field => $prop ) {
370
+            $value = $invoice->{"get_$prop"}( 'edit' );
371
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
372
+            $value = is_bool( $value ) ? ( int ) $value : $value;
373
+            $updated_props[ $database_field ] = maybe_serialize( $value );
374
+        }
375
+
376
+        if ( ! empty( $updated_props ) ) {
377
+
378
+            $table = $wpdb->prefix . 'getpaid_invoices';
379
+            $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
380
+            wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
381
+            do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props );
382
+
383
+        }
384
+
385
+    }
386
+
387
+    /**
388
+     * Helper method that inserts special fields to the database.
389
+     *
390
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
391
+     * @since 1.0.19
392
+     */
393
+    protected function insert_special_fields( &$invoice ) {
394
+        global $wpdb;
395
+
396
+        $updated_props   = array();
397
+
398
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
399
+            $value = $invoice->{"get_$prop"}( 'edit' );
400
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
401
+            $value = is_bool( $value ) ? ( int ) $value : $value;
402
+            $updated_props[ $database_field ] = maybe_serialize( $value );
403
+        }
404
+
405
+        $table = $wpdb->prefix . 'getpaid_invoices';
406
+        $wpdb->insert( $table, $updated_props );
407
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
408
+        do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props );
409
+
410
+    }
411
+
412
+    /**
413 413
      * Saves all special fields.
414
-	 *
415
-	 * @param WPInv_Invoice $invoice Invoice object.
414
+     *
415
+     * @param WPInv_Invoice $invoice Invoice object.
416 416
      */
417 417
     public function save_special_fields( $invoice ) {
418
-		global $wpdb;
418
+        global $wpdb;
419 419
 
420
-		// The invoices table.
421
-		$table = $wpdb->prefix . 'getpaid_invoices';
422
-		$id    = (int) $invoice->get_id();
420
+        // The invoices table.
421
+        $table = $wpdb->prefix . 'getpaid_invoices';
422
+        $id    = (int) $invoice->get_id();
423 423
 
424
-		if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
424
+        if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
425 425
 
426
-			$this->update_special_fields( $invoice );
426
+            $this->update_special_fields( $invoice );
427 427
 
428
-		} else {
428
+        } else {
429 429
 
430
-			$this->insert_special_fields( $invoice );
430
+            $this->insert_special_fields( $invoice );
431 431
 
432
-		}
432
+        }
433 433
 
434
-	}
434
+    }
435 435
 
436
-	/**
436
+    /**
437 437
      * Set's up cart details.
438
-	 *
439
-	 * @param WPInv_Invoice $invoice Invoice object.
438
+     *
439
+     * @param WPInv_Invoice $invoice Invoice object.
440 440
      */
441 441
     public function add_items( &$invoice ) {
442
-		global $wpdb;
442
+        global $wpdb;
443 443
 
444
-		// Maybe retrieve from the cache.
445
-		$items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
444
+        // Maybe retrieve from the cache.
445
+        $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
446 446
 
447
-		// If not found, retrieve from the db.
448
-		if ( false === $items ) {
449
-			$table =  $wpdb->prefix . 'getpaid_invoice_items';
447
+        // If not found, retrieve from the db.
448
+        if ( false === $items ) {
449
+            $table =  $wpdb->prefix . 'getpaid_invoice_items';
450 450
 
451
-			$items = $wpdb->get_results(
452
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
453
-			);
451
+            $items = $wpdb->get_results(
452
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
453
+            );
454 454
 
455
-			// Update the cache with our data
456
-			wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
455
+            // Update the cache with our data
456
+            wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
457 457
 
458
-		}
458
+        }
459 459
 
460
-		// Abort if no items found.
460
+        // Abort if no items found.
461 461
         if ( empty( $items ) ) {
462 462
             return;
463
-		}
463
+        }
464 464
 
465
-		foreach ( $items as $item_data ) {
466
-			$item = new GetPaid_Form_Item( $item_data->item_id );
465
+        foreach ( $items as $item_data ) {
466
+            $item = new GetPaid_Form_Item( $item_data->item_id );
467 467
 
468
-			// Set item data.
469
-			$item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
470
-			$item->item_discount = wpinv_sanitize_amount( $item_data->discount );
471
-			$item->set_name( $item_data->item_name );
472
-			$item->set_description( $item_data->item_description );
473
-			$item->set_price( $item_data->item_price );
474
-			$item->set_quantity( $item_data->quantity );
475
-			$item->set_item_meta( $item_data->meta );
468
+            // Set item data.
469
+            $item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
470
+            $item->item_discount = wpinv_sanitize_amount( $item_data->discount );
471
+            $item->set_name( $item_data->item_name );
472
+            $item->set_description( $item_data->item_description );
473
+            $item->set_price( $item_data->item_price );
474
+            $item->set_quantity( $item_data->quantity );
475
+            $item->set_item_meta( $item_data->meta );
476 476
 
477
-			$invoice->add_item( $item );
478
-		}
477
+            $invoice->add_item( $item );
478
+        }
479 479
 
480
-	}
480
+    }
481 481
 
482
-	/**
482
+    /**
483 483
      * Saves cart details.
484
-	 *
485
-	 * @param WPInv_Invoice $invoice Invoice object.
484
+     *
485
+     * @param WPInv_Invoice $invoice Invoice object.
486 486
      */
487 487
     public function save_items( $invoice ) {
488 488
 
489
-		// Delete previously existing items.
490
-		$this->delete_items( $invoice );
489
+        // Delete previously existing items.
490
+        $this->delete_items( $invoice );
491 491
 
492
-		$table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
492
+        $table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
493 493
 
494
-		foreach ( $invoice->get_cart_details() as $item_data ) {
495
-			$item_data = array_map( 'maybe_serialize', $item_data );
496
-			$GLOBALS['wpdb']->insert( $table, $item_data );
497
-		}
494
+        foreach ( $invoice->get_cart_details() as $item_data ) {
495
+            $item_data = array_map( 'maybe_serialize', $item_data );
496
+            $GLOBALS['wpdb']->insert( $table, $item_data );
497
+        }
498 498
 
499
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
500
-		do_action( "getpaid_invoice_save_items", $invoice );
499
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
500
+        do_action( "getpaid_invoice_save_items", $invoice );
501 501
 
502
-	}
502
+    }
503 503
 
504
-	/**
504
+    /**
505 505
      * Deletes an invoice's cart details from the database.
506
-	 *
507
-	 * @param WPInv_Invoice $invoice Invoice object.
506
+     *
507
+     * @param WPInv_Invoice $invoice Invoice object.
508 508
      */
509 509
     public function delete_items( $invoice ) {
510
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
511
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
512
-	}
510
+        $table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
511
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
512
+    }
513 513
 
514
-	/**
514
+    /**
515 515
      * Deletes an invoice's special fields from the database.
516
-	 *
517
-	 * @param WPInv_Invoice $invoice Invoice object.
516
+     *
517
+     * @param WPInv_Invoice $invoice Invoice object.
518 518
      */
519 519
     public function delete_special_fields( $invoice ) {
520
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
521
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
520
+        $table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
521
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
522 522
     }
523 523
 
524 524
 }
Please login to merge, or discard this patch.
includes/class-wpinv-invoice.php 1 patch
Indentation   +2236 added lines, -2236 removed lines patch added patch discarded remove patch
@@ -14,30 +14,30 @@  discard block
 block discarded – undo
14 14
 class WPInv_Invoice extends GetPaid_Data {
15 15
 
16 16
     /**
17
-	 * Which data store to load.
18
-	 *
19
-	 * @var string
20
-	 */
17
+     * Which data store to load.
18
+     *
19
+     * @var string
20
+     */
21 21
     protected $data_store_name = 'invoice';
22 22
 
23 23
     /**
24
-	 * This is the name of this object type.
25
-	 *
26
-	 * @var string
27
-	 */
24
+     * This is the name of this object type.
25
+     *
26
+     * @var string
27
+     */
28 28
     protected $object_type = 'invoice';
29 29
 
30 30
     /**
31
-	 * Item Data array. This is the core item data exposed in APIs.
32
-	 *
33
-	 * @since 1.0.19
34
-	 * @var array
35
-	 */
36
-	protected $data = array(
37
-		'parent_id'            => 0,
38
-		'status'               => 'wpi-pending',
39
-		'version'              => '',
40
-		'date_created'         => null,
31
+     * Item Data array. This is the core item data exposed in APIs.
32
+     *
33
+     * @since 1.0.19
34
+     * @var array
35
+     */
36
+    protected $data = array(
37
+        'parent_id'            => 0,
38
+        'status'               => 'wpi-pending',
39
+        'version'              => '',
40
+        'date_created'         => null,
41 41
         'date_modified'        => null,
42 42
         'due_date'             => null,
43 43
         'completed_date'       => null,
@@ -79,20 +79,20 @@  discard block
 block discarded – undo
79 79
         'transaction_id'       => '',
80 80
         'currency'             => '',
81 81
         'disable_taxes'        => false,
82
-		'subscription_id'      => null,
83
-		'is_viewed'            => false,
84
-		'email_cc'             => '',
85
-		'template'             => 'quantity', // hours, amount only
82
+        'subscription_id'      => null,
83
+        'is_viewed'            => false,
84
+        'email_cc'             => '',
85
+        'template'             => 'quantity', // hours, amount only
86 86
     );
87 87
 
88 88
     /**
89
-	 * Stores meta in cache for future reads.
90
-	 *
91
-	 * A group must be set to to enable caching.
92
-	 *
93
-	 * @var string
94
-	 */
95
-	protected $cache_group = 'getpaid_invoices';
89
+     * Stores meta in cache for future reads.
90
+     *
91
+     * A group must be set to to enable caching.
92
+     *
93
+     * @var string
94
+     */
95
+    protected $cache_group = 'getpaid_invoices';
96 96
 
97 97
     /**
98 98
      * Stores a reference to the original WP_Post object
@@ -106,104 +106,104 @@  discard block
 block discarded – undo
106 106
      *
107 107
      * @var int
108 108
      */
109
-	protected $recurring_item = null;
109
+    protected $recurring_item = null;
110 110
 
111
-	/**
111
+    /**
112 112
      * Stores an array of item totals.
113
-	 *
114
-	 * e.g $totals['discount'] = array(
115
-	 * 		'initial'   => 10,
116
-	 * 		'recurring' => 10,
117
-	 * )
113
+     *
114
+     * e.g $totals['discount'] = array(
115
+     * 		'initial'   => 10,
116
+     * 		'recurring' => 10,
117
+     * )
118 118
      *
119 119
      * @var array
120 120
      */
121
-	protected $totals = array();
121
+    protected $totals = array();
122 122
 
123
-	/**
124
-	 * Stores the status transition information.
125
-	 *
126
-	 * @since 1.0.19
127
-	 * @var bool
128
-	 */
129
-	protected $status_transition = false;
123
+    /**
124
+     * Stores the status transition information.
125
+     *
126
+     * @since 1.0.19
127
+     * @var bool
128
+     */
129
+    protected $status_transition = false;
130 130
 
131 131
     /**
132
-	 * Get the invoice if ID is passed, otherwise the invoice is new and empty.
133
-	 *
134
-	 * @param  int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read.
135
-	 */
132
+     * Get the invoice if ID is passed, otherwise the invoice is new and empty.
133
+     *
134
+     * @param  int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read.
135
+     */
136 136
     public function __construct( $invoice = false ) {
137 137
 
138 138
         parent::__construct( $invoice );
139 139
 
140
-		if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) {
141
-			$this->set_id( $invoice );
142
-		} elseif ( $invoice instanceof self ) {
143
-			$this->set_id( $invoice->get_id() );
144
-		} elseif ( ! empty( $invoice->ID ) ) {
145
-			$this->set_id( $invoice->ID );
146
-		} elseif ( is_array( $invoice ) ) {
147
-			$this->set_props( $invoice );
148
-
149
-			if ( isset( $invoice['ID'] ) ) {
150
-				$this->set_id( $invoice['ID'] );
151
-			}
152
-
153
-		} elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) {
154
-			$this->set_id( $invoice_id );
155
-		} elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) {
156
-			$this->set_id( $invoice_id );
157
-		} elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) {
158
-			$this->set_id( $invoice_id );
159
-		}else {
160
-			$this->set_object_read( true );
161
-		}
140
+        if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) {
141
+            $this->set_id( $invoice );
142
+        } elseif ( $invoice instanceof self ) {
143
+            $this->set_id( $invoice->get_id() );
144
+        } elseif ( ! empty( $invoice->ID ) ) {
145
+            $this->set_id( $invoice->ID );
146
+        } elseif ( is_array( $invoice ) ) {
147
+            $this->set_props( $invoice );
148
+
149
+            if ( isset( $invoice['ID'] ) ) {
150
+                $this->set_id( $invoice['ID'] );
151
+            }
152
+
153
+        } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) {
154
+            $this->set_id( $invoice_id );
155
+        } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) {
156
+            $this->set_id( $invoice_id );
157
+        } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) {
158
+            $this->set_id( $invoice_id );
159
+        }else {
160
+            $this->set_object_read( true );
161
+        }
162 162
 
163 163
         // Load the datastore.
164
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
164
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
165 165
 
166
-		if ( $this->get_id() > 0 ) {
166
+        if ( $this->get_id() > 0 ) {
167 167
             $this->post = get_post( $this->get_id() );
168 168
             $this->ID   = $this->get_id();
169
-			$this->data_store->read( $this );
169
+            $this->data_store->read( $this );
170 170
         }
171 171
 
172 172
     }
173 173
 
174 174
     /**
175
-	 * Given an invoice key/number, it returns its id.
176
-	 *
177
-	 *
178
-	 * @static
179
-	 * @param string $value The invoice key or number
180
-	 * @param string $field Either key, transaction_id or number.
181
-	 * @since 1.0.15
182
-	 * @return int
183
-	 */
184
-	public static function get_invoice_id_by_field( $value, $field = 'key' ) {
175
+     * Given an invoice key/number, it returns its id.
176
+     *
177
+     *
178
+     * @static
179
+     * @param string $value The invoice key or number
180
+     * @param string $field Either key, transaction_id or number.
181
+     * @since 1.0.15
182
+     * @return int
183
+     */
184
+    public static function get_invoice_id_by_field( $value, $field = 'key' ) {
185 185
         global $wpdb;
186 186
 
187
-		// Trim the value.
188
-		$value = trim( $value );
187
+        // Trim the value.
188
+        $value = trim( $value );
189 189
 
190
-		if ( empty( $value ) ) {
191
-			return 0;
192
-		}
190
+        if ( empty( $value ) ) {
191
+            return 0;
192
+        }
193 193
 
194 194
         // Valid fields.
195 195
         $fields = array( 'key', 'number', 'transaction_id' );
196 196
 
197
-		// Ensure a field has been passed.
198
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
199
-			return 0;
200
-		}
197
+        // Ensure a field has been passed.
198
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
199
+            return 0;
200
+        }
201 201
 
202
-		// Maybe retrieve from the cache.
203
-		$invoice_id   = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" );
204
-		if ( false !== $invoice_id ) {
205
-			return $invoice_id;
206
-		}
202
+        // Maybe retrieve from the cache.
203
+        $invoice_id   = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" );
204
+        if ( false !== $invoice_id ) {
205
+            return $invoice_id;
206
+        }
207 207
 
208 208
         // Fetch from the db.
209 209
         $table       = $wpdb->prefix . 'getpaid_invoices';
@@ -211,10 +211,10 @@  discard block
 block discarded – undo
211 211
             $wpdb->prepare( "SELECT `post_id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
212 212
         );
213 213
 
214
-		// Update the cache with our data
215
-		wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" );
214
+        // Update the cache with our data
215
+        wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" );
216 216
 
217
-		return $invoice_id;
217
+        return $invoice_id;
218 218
     }
219 219
 
220 220
     /**
@@ -240,80 +240,80 @@  discard block
 block discarded – undo
240 240
     */
241 241
 
242 242
     /**
243
-	 * Get parent invoice ID.
244
-	 *
245
-	 * @since 1.0.19
246
-	 * @param  string $context View or edit context.
247
-	 * @return int
248
-	 */
249
-	public function get_parent_id( $context = 'view' ) {
250
-		return (int) $this->get_prop( 'parent_id', $context );
243
+     * Get parent invoice ID.
244
+     *
245
+     * @since 1.0.19
246
+     * @param  string $context View or edit context.
247
+     * @return int
248
+     */
249
+    public function get_parent_id( $context = 'view' ) {
250
+        return (int) $this->get_prop( 'parent_id', $context );
251 251
     }
252 252
 
253 253
     /**
254
-	 * Get parent invoice.
255
-	 *
256
-	 * @since 1.0.19
257
-	 * @return WPInv_Invoice
258
-	 */
254
+     * Get parent invoice.
255
+     *
256
+     * @since 1.0.19
257
+     * @return WPInv_Invoice
258
+     */
259 259
     public function get_parent_payment() {
260 260
         return new WPInv_Invoice( $this->get_parent_id() );
261 261
     }
262 262
 
263 263
     /**
264
-	 * Alias for self::get_parent_payment().
265
-	 *
266
-	 * @since 1.0.19
267
-	 * @return WPInv_Invoice
268
-	 */
264
+     * Alias for self::get_parent_payment().
265
+     *
266
+     * @since 1.0.19
267
+     * @return WPInv_Invoice
268
+     */
269 269
     public function get_parent() {
270 270
         return $this->get_parent_payment();
271 271
     }
272 272
 
273 273
     /**
274
-	 * Get invoice status.
275
-	 *
276
-	 * @since 1.0.19
277
-	 * @param  string $context View or edit context.
278
-	 * @return string
279
-	 */
280
-	public function get_status( $context = 'view' ) {
281
-		return $this->get_prop( 'status', $context );
282
-	}
274
+     * Get invoice status.
275
+     *
276
+     * @since 1.0.19
277
+     * @param  string $context View or edit context.
278
+     * @return string
279
+     */
280
+    public function get_status( $context = 'view' ) {
281
+        return $this->get_prop( 'status', $context );
282
+    }
283 283
 	
284
-	/**
285
-	 * Retrieves an array of possible invoice statuses.
286
-	 *
287
-	 * @since 1.0.19
288
-	 * @return array
289
-	 */
290
-	public function get_all_statuses() {
291
-
292
-		$statuses = wpinv_get_invoice_statuses( true, true, $this );
293
-
294
-		// For backwards compatibility.
295
-		if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) {
284
+    /**
285
+     * Retrieves an array of possible invoice statuses.
286
+     *
287
+     * @since 1.0.19
288
+     * @return array
289
+     */
290
+    public function get_all_statuses() {
291
+
292
+        $statuses = wpinv_get_invoice_statuses( true, true, $this );
293
+
294
+        // For backwards compatibility.
295
+        if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) {
296 296
             $statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses();
297
-		}
297
+        }
298 298
 
299
-		return $statuses;
299
+        return $statuses;
300 300
     }
301 301
 
302 302
     /**
303
-	 * Get invoice status nice name.
304
-	 *
305
-	 * @since 1.0.19
306
-	 * @return string
307
-	 */
303
+     * Get invoice status nice name.
304
+     *
305
+     * @since 1.0.19
306
+     * @return string
307
+     */
308 308
     public function get_status_nicename() {
309
-		$statuses = $this->get_all_statuses();
309
+        $statuses = $this->get_all_statuses();
310 310
 
311 311
         $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status();
312 312
 
313 313
         return apply_filters( 'wpinv_get_invoice_status_nicename', $status, $this );
314 314
     }
315 315
 
316
-	/**
316
+    /**
317 317
      * Retrieves the invoice status label html
318 318
      *
319 319
      * @since  1.0.0
@@ -321,27 +321,27 @@  discard block
 block discarded – undo
321 321
      */
322 322
     public function get_status_label_html() {
323 323
 
324
-		$status_label = sanitize_text_field( $this->get_status_nicename() );
325
-		$status       = sanitize_html_class( $this->get_status() );
324
+        $status_label = sanitize_text_field( $this->get_status_nicename() );
325
+        $status       = sanitize_html_class( $this->get_status() );
326 326
 
327
-		return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded getpaid-invoice-status-$status'>$status_label</span></span>";
328
-	}
327
+        return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded getpaid-invoice-status-$status'>$status_label</span></span>";
328
+    }
329 329
 
330 330
     /**
331
-	 * Get plugin version when the invoice was created.
332
-	 *
333
-	 * @since 1.0.19
334
-	 * @param  string $context View or edit context.
335
-	 * @return string
336
-	 */
337
-	public function get_version( $context = 'view' ) {
338
-		return $this->get_prop( 'version', $context );
339
-	}
331
+     * Get plugin version when the invoice was created.
332
+     *
333
+     * @since 1.0.19
334
+     * @param  string $context View or edit context.
335
+     * @return string
336
+     */
337
+    public function get_version( $context = 'view' ) {
338
+        return $this->get_prop( 'version', $context );
339
+    }
340 340
 
341
-	/**
342
-	 * @deprecated
343
-	 */
344
-	public function get_invoice_date( $formatted = true ) {
341
+    /**
342
+     * @deprecated
343
+     */
344
+    public function get_invoice_date( $formatted = true ) {
345 345
         $date_completed = $this->get_date_completed();
346 346
         $invoice_date   = $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';
347 347
 
@@ -358,187 +358,187 @@  discard block
 block discarded – undo
358 358
     }
359 359
 
360 360
     /**
361
-	 * Get date when the invoice was created.
362
-	 *
363
-	 * @since 1.0.19
364
-	 * @param  string $context View or edit context.
365
-	 * @return string
366
-	 */
367
-	public function get_date_created( $context = 'view' ) {
368
-		return $this->get_prop( 'date_created', $context );
369
-	}
361
+     * Get date when the invoice was created.
362
+     *
363
+     * @since 1.0.19
364
+     * @param  string $context View or edit context.
365
+     * @return string
366
+     */
367
+    public function get_date_created( $context = 'view' ) {
368
+        return $this->get_prop( 'date_created', $context );
369
+    }
370 370
 	
371
-	/**
372
-	 * Alias for self::get_date_created().
373
-	 *
374
-	 * @since 1.0.19
375
-	 * @param  string $context View or edit context.
376
-	 * @return string
377
-	 */
378
-	public function get_created_date( $context = 'view' ) {
379
-		return $this->get_date_created( $context );
380
-    }
381
-
382
-    /**
383
-	 * Get GMT date when the invoice was created.
384
-	 *
385
-	 * @since 1.0.19
386
-	 * @param  string $context View or edit context.
387
-	 * @return string
388
-	 */
389
-	public function get_date_created_gmt( $context = 'view' ) {
371
+    /**
372
+     * Alias for self::get_date_created().
373
+     *
374
+     * @since 1.0.19
375
+     * @param  string $context View or edit context.
376
+     * @return string
377
+     */
378
+    public function get_created_date( $context = 'view' ) {
379
+        return $this->get_date_created( $context );
380
+    }
381
+
382
+    /**
383
+     * Get GMT date when the invoice was created.
384
+     *
385
+     * @since 1.0.19
386
+     * @param  string $context View or edit context.
387
+     * @return string
388
+     */
389
+    public function get_date_created_gmt( $context = 'view' ) {
390 390
         $date = $this->get_date_created( $context );
391 391
 
392 392
         if ( $date ) {
393 393
             $date = get_gmt_from_date( $date );
394 394
         }
395
-		return $date;
395
+        return $date;
396 396
     }
397 397
 
398 398
     /**
399
-	 * Get date when the invoice was last modified.
400
-	 *
401
-	 * @since 1.0.19
402
-	 * @param  string $context View or edit context.
403
-	 * @return string
404
-	 */
405
-	public function get_date_modified( $context = 'view' ) {
406
-		return $this->get_prop( 'date_modified', $context );
407
-	}
399
+     * Get date when the invoice was last modified.
400
+     *
401
+     * @since 1.0.19
402
+     * @param  string $context View or edit context.
403
+     * @return string
404
+     */
405
+    public function get_date_modified( $context = 'view' ) {
406
+        return $this->get_prop( 'date_modified', $context );
407
+    }
408 408
 
409
-	/**
410
-	 * Alias for self::get_date_modified().
411
-	 *
412
-	 * @since 1.0.19
413
-	 * @param  string $context View or edit context.
414
-	 * @return string
415
-	 */
416
-	public function get_modified_date( $context = 'view' ) {
417
-		return $this->get_date_modified( $context );
409
+    /**
410
+     * Alias for self::get_date_modified().
411
+     *
412
+     * @since 1.0.19
413
+     * @param  string $context View or edit context.
414
+     * @return string
415
+     */
416
+    public function get_modified_date( $context = 'view' ) {
417
+        return $this->get_date_modified( $context );
418 418
     }
419 419
 
420 420
     /**
421
-	 * Get GMT date when the invoice was last modified.
422
-	 *
423
-	 * @since 1.0.19
424
-	 * @param  string $context View or edit context.
425
-	 * @return string
426
-	 */
427
-	public function get_date_modified_gmt( $context = 'view' ) {
421
+     * Get GMT date when the invoice was last modified.
422
+     *
423
+     * @since 1.0.19
424
+     * @param  string $context View or edit context.
425
+     * @return string
426
+     */
427
+    public function get_date_modified_gmt( $context = 'view' ) {
428 428
         $date = $this->get_date_modified( $context );
429 429
 
430 430
         if ( $date ) {
431 431
             $date = get_gmt_from_date( $date );
432 432
         }
433
-		return $date;
433
+        return $date;
434 434
     }
435 435
 
436 436
     /**
437
-	 * Get the invoice due date.
438
-	 *
439
-	 * @since 1.0.19
440
-	 * @param  string $context View or edit context.
441
-	 * @return string
442
-	 */
443
-	public function get_due_date( $context = 'view' ) {
444
-		return $this->get_prop( 'due_date', $context );
437
+     * Get the invoice due date.
438
+     *
439
+     * @since 1.0.19
440
+     * @param  string $context View or edit context.
441
+     * @return string
442
+     */
443
+    public function get_due_date( $context = 'view' ) {
444
+        return $this->get_prop( 'due_date', $context );
445 445
     }
446 446
 
447 447
     /**
448
-	 * Alias for self::get_due_date().
449
-	 *
450
-	 * @since 1.0.19
451
-	 * @param  string $context View or edit context.
452
-	 * @return string
453
-	 */
454
-	public function get_date_due( $context = 'view' ) {
455
-		return $this->get_due_date( $context );
448
+     * Alias for self::get_due_date().
449
+     *
450
+     * @since 1.0.19
451
+     * @param  string $context View or edit context.
452
+     * @return string
453
+     */
454
+    public function get_date_due( $context = 'view' ) {
455
+        return $this->get_due_date( $context );
456 456
     }
457 457
 
458 458
     /**
459
-	 * Get the invoice GMT due date.
460
-	 *
461
-	 * @since 1.0.19
462
-	 * @param  string $context View or edit context.
463
-	 * @return string
464
-	 */
465
-	public function get_due_date_gmt( $context = 'view' ) {
459
+     * Get the invoice GMT due date.
460
+     *
461
+     * @since 1.0.19
462
+     * @param  string $context View or edit context.
463
+     * @return string
464
+     */
465
+    public function get_due_date_gmt( $context = 'view' ) {
466 466
         $date = $this->get_due_date( $context );
467 467
 
468 468
         if ( $date ) {
469 469
             $date = get_gmt_from_date( $date );
470 470
         }
471
-		return $date;
471
+        return $date;
472 472
     }
473 473
 
474 474
     /**
475
-	 * Alias for self::get_due_date_gmt().
476
-	 *
477
-	 * @since 1.0.19
478
-	 * @param  string $context View or edit context.
479
-	 * @return string
480
-	 */
481
-	public function get_gmt_date_due( $context = 'view' ) {
482
-		return $this->get_due_date_gmt( $context );
475
+     * Alias for self::get_due_date_gmt().
476
+     *
477
+     * @since 1.0.19
478
+     * @param  string $context View or edit context.
479
+     * @return string
480
+     */
481
+    public function get_gmt_date_due( $context = 'view' ) {
482
+        return $this->get_due_date_gmt( $context );
483 483
     }
484 484
 
485 485
     /**
486
-	 * Get date when the invoice was completed.
487
-	 *
488
-	 * @since 1.0.19
489
-	 * @param  string $context View or edit context.
490
-	 * @return string
491
-	 */
492
-	public function get_completed_date( $context = 'view' ) {
493
-		return $this->get_prop( 'completed_date', $context );
486
+     * Get date when the invoice was completed.
487
+     *
488
+     * @since 1.0.19
489
+     * @param  string $context View or edit context.
490
+     * @return string
491
+     */
492
+    public function get_completed_date( $context = 'view' ) {
493
+        return $this->get_prop( 'completed_date', $context );
494 494
     }
495 495
 
496 496
     /**
497
-	 * Alias for self::get_completed_date().
498
-	 *
499
-	 * @since 1.0.19
500
-	 * @param  string $context View or edit context.
501
-	 * @return string
502
-	 */
503
-	public function get_date_completed( $context = 'view' ) {
504
-		return $this->get_completed_date( $context );
497
+     * Alias for self::get_completed_date().
498
+     *
499
+     * @since 1.0.19
500
+     * @param  string $context View or edit context.
501
+     * @return string
502
+     */
503
+    public function get_date_completed( $context = 'view' ) {
504
+        return $this->get_completed_date( $context );
505 505
     }
506 506
 
507 507
     /**
508
-	 * Get GMT date when the invoice was was completed.
509
-	 *
510
-	 * @since 1.0.19
511
-	 * @param  string $context View or edit context.
512
-	 * @return string
513
-	 */
514
-	public function get_completed_date_gmt( $context = 'view' ) {
508
+     * Get GMT date when the invoice was was completed.
509
+     *
510
+     * @since 1.0.19
511
+     * @param  string $context View or edit context.
512
+     * @return string
513
+     */
514
+    public function get_completed_date_gmt( $context = 'view' ) {
515 515
         $date = $this->get_completed_date( $context );
516 516
 
517 517
         if ( $date ) {
518 518
             $date = get_gmt_from_date( $date );
519 519
         }
520
-		return $date;
520
+        return $date;
521 521
     }
522 522
 
523 523
     /**
524
-	 * Alias for self::get_completed_date_gmt().
525
-	 *
526
-	 * @since 1.0.19
527
-	 * @param  string $context View or edit context.
528
-	 * @return string
529
-	 */
530
-	public function get_gmt_completed_date( $context = 'view' ) {
531
-		return $this->get_completed_date_gmt( $context );
524
+     * Alias for self::get_completed_date_gmt().
525
+     *
526
+     * @since 1.0.19
527
+     * @param  string $context View or edit context.
528
+     * @return string
529
+     */
530
+    public function get_gmt_completed_date( $context = 'view' ) {
531
+        return $this->get_completed_date_gmt( $context );
532 532
     }
533 533
 
534 534
     /**
535
-	 * Get the invoice number.
536
-	 *
537
-	 * @since 1.0.19
538
-	 * @param  string $context View or edit context.
539
-	 * @return string
540
-	 */
541
-	public function get_number( $context = 'view' ) {
535
+     * Get the invoice number.
536
+     *
537
+     * @since 1.0.19
538
+     * @param  string $context View or edit context.
539
+     * @return string
540
+     */
541
+    public function get_number( $context = 'view' ) {
542 542
         $number = $this->get_prop( 'number', $context );
543 543
 
544 544
         if ( empty( $number ) ) {
@@ -546,17 +546,17 @@  discard block
 block discarded – undo
546 546
             $this->set_number( $number );
547 547
         }
548 548
 
549
-		return $number;
549
+        return $number;
550 550
     }
551 551
 
552 552
     /**
553
-	 * Get the invoice key.
554
-	 *
555
-	 * @since 1.0.19
556
-	 * @param  string $context View or edit context.
557
-	 * @return string
558
-	 */
559
-	public function get_key( $context = 'view' ) {
553
+     * Get the invoice key.
554
+     *
555
+     * @since 1.0.19
556
+     * @param  string $context View or edit context.
557
+     * @return string
558
+     */
559
+    public function get_key( $context = 'view' ) {
560 560
         $key = $this->get_prop( 'key', $context );
561 561
 
562 562
         if ( empty( $key ) ) {
@@ -564,24 +564,24 @@  discard block
 block discarded – undo
564 564
             $this->set_key( $key );
565 565
         }
566 566
 
567
-		return $key;
567
+        return $key;
568 568
     }
569 569
 
570 570
     /**
571
-	 * Get the invoice type.
572
-	 *
573
-	 * @since 1.0.19
574
-	 * @param  string $context View or edit context.
575
-	 * @return string
576
-	 */
577
-	public function get_type( $context = 'view' ) {
571
+     * Get the invoice type.
572
+     *
573
+     * @since 1.0.19
574
+     * @param  string $context View or edit context.
575
+     * @return string
576
+     */
577
+    public function get_type( $context = 'view' ) {
578 578
         return $this->get_prop( 'type', $context );
579
-	}
579
+    }
580 580
 
581
-	/**
582
-	 * @deprecated
583
-	 */
584
-	public function get_invoice_quote_type( $post_id ) {
581
+    /**
582
+     * @deprecated
583
+     */
584
+    public function get_invoice_quote_type( $post_id ) {
585 585
         if ( empty( $post_id ) ) {
586 586
             return '';
587 587
         }
@@ -598,35 +598,35 @@  discard block
 block discarded – undo
598 598
     }
599 599
 
600 600
     /**
601
-	 * Get the invoice post type.
602
-	 *
603
-	 * @since 1.0.19
604
-	 * @param  string $context View or edit context.
605
-	 * @return string
606
-	 */
607
-	public function get_post_type( $context = 'view' ) {
601
+     * Get the invoice post type.
602
+     *
603
+     * @since 1.0.19
604
+     * @param  string $context View or edit context.
605
+     * @return string
606
+     */
607
+    public function get_post_type( $context = 'view' ) {
608 608
         return $this->get_prop( 'post_type', $context );
609 609
     }
610 610
 
611 611
     /**
612
-	 * Get the invoice mode.
613
-	 *
614
-	 * @since 1.0.19
615
-	 * @param  string $context View or edit context.
616
-	 * @return string
617
-	 */
618
-	public function get_mode( $context = 'view' ) {
612
+     * Get the invoice mode.
613
+     *
614
+     * @since 1.0.19
615
+     * @param  string $context View or edit context.
616
+     * @return string
617
+     */
618
+    public function get_mode( $context = 'view' ) {
619 619
         return $this->get_prop( 'mode', $context );
620 620
     }
621 621
 
622 622
     /**
623
-	 * Get the invoice path.
624
-	 *
625
-	 * @since 1.0.19
626
-	 * @param  string $context View or edit context.
627
-	 * @return string
628
-	 */
629
-	public function get_path( $context = 'view' ) {
623
+     * Get the invoice path.
624
+     *
625
+     * @since 1.0.19
626
+     * @param  string $context View or edit context.
627
+     * @return string
628
+     */
629
+    public function get_path( $context = 'view' ) {
630 630
         $path = $this->get_prop( 'path', $context );
631 631
 
632 632
         if ( empty( $path ) ) {
@@ -634,71 +634,71 @@  discard block
 block discarded – undo
634 634
             $path   = sanitize_title( $prefix . $this->get_id() );
635 635
         }
636 636
 
637
-		return $path;
637
+        return $path;
638 638
     }
639 639
 
640 640
     /**
641
-	 * Get the invoice name/title.
642
-	 *
643
-	 * @since 1.0.19
644
-	 * @param  string $context View or edit context.
645
-	 * @return string
646
-	 */
647
-	public function get_name( $context = 'view' ) {
641
+     * Get the invoice name/title.
642
+     *
643
+     * @since 1.0.19
644
+     * @param  string $context View or edit context.
645
+     * @return string
646
+     */
647
+    public function get_name( $context = 'view' ) {
648 648
         return $this->get_prop( 'title', $context );
649 649
     }
650 650
 
651 651
     /**
652
-	 * Alias of self::get_name().
653
-	 *
654
-	 * @since 1.0.19
655
-	 * @param  string $context View or edit context.
656
-	 * @return string
657
-	 */
658
-	public function get_title( $context = 'view' ) {
659
-		return $this->get_name( $context );
652
+     * Alias of self::get_name().
653
+     *
654
+     * @since 1.0.19
655
+     * @param  string $context View or edit context.
656
+     * @return string
657
+     */
658
+    public function get_title( $context = 'view' ) {
659
+        return $this->get_name( $context );
660 660
     }
661 661
 
662 662
     /**
663
-	 * Get the invoice description.
664
-	 *
665
-	 * @since 1.0.19
666
-	 * @param  string $context View or edit context.
667
-	 * @return string
668
-	 */
669
-	public function get_description( $context = 'view' ) {
670
-		return $this->get_prop( 'description', $context );
663
+     * Get the invoice description.
664
+     *
665
+     * @since 1.0.19
666
+     * @param  string $context View or edit context.
667
+     * @return string
668
+     */
669
+    public function get_description( $context = 'view' ) {
670
+        return $this->get_prop( 'description', $context );
671 671
     }
672 672
 
673 673
     /**
674
-	 * Alias of self::get_description().
675
-	 *
676
-	 * @since 1.0.19
677
-	 * @param  string $context View or edit context.
678
-	 * @return string
679
-	 */
680
-	public function get_excerpt( $context = 'view' ) {
681
-		return $this->get_description( $context );
674
+     * Alias of self::get_description().
675
+     *
676
+     * @since 1.0.19
677
+     * @param  string $context View or edit context.
678
+     * @return string
679
+     */
680
+    public function get_excerpt( $context = 'view' ) {
681
+        return $this->get_description( $context );
682 682
     }
683 683
 
684 684
     /**
685
-	 * Alias of self::get_description().
686
-	 *
687
-	 * @since 1.0.19
688
-	 * @param  string $context View or edit context.
689
-	 * @return string
690
-	 */
691
-	public function get_summary( $context = 'view' ) {
692
-		return $this->get_description( $context );
685
+     * Alias of self::get_description().
686
+     *
687
+     * @since 1.0.19
688
+     * @param  string $context View or edit context.
689
+     * @return string
690
+     */
691
+    public function get_summary( $context = 'view' ) {
692
+        return $this->get_description( $context );
693 693
     }
694 694
 
695 695
     /**
696
-	 * Returns the user info.
697
-	 *
698
-	 * @since 1.0.19
696
+     * Returns the user info.
697
+     *
698
+     * @since 1.0.19
699 699
      * @param  string $context View or edit context.
700
-	 * @return array
701
-	 */
700
+     * @return array
701
+     */
702 702
     public function get_user_info( $context = 'view' ) {
703 703
 
704 704
         $user_info = array(
@@ -715,605 +715,605 @@  discard block
 block discarded – undo
715 715
             'company'    => $this->get_company( $context ),
716 716
             'vat_number' => $this->get_vat_number( $context ),
717 717
             'discount'   => $this->get_discount_code( $context ),
718
-		);
718
+        );
719 719
 
720
-		return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this );
720
+        return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this );
721 721
 
722 722
     }
723 723
 
724 724
     /**
725
-	 * Get the customer id.
726
-	 *
727
-	 * @since 1.0.19
728
-	 * @param  string $context View or edit context.
729
-	 * @return int
730
-	 */
731
-	public function get_author( $context = 'view' ) {
732
-		return (int) $this->get_prop( 'author', $context );
725
+     * Get the customer id.
726
+     *
727
+     * @since 1.0.19
728
+     * @param  string $context View or edit context.
729
+     * @return int
730
+     */
731
+    public function get_author( $context = 'view' ) {
732
+        return (int) $this->get_prop( 'author', $context );
733 733
     }
734 734
 
735 735
     /**
736
-	 * Alias of self::get_author().
737
-	 *
738
-	 * @since 1.0.19
739
-	 * @param  string $context View or edit context.
740
-	 * @return int
741
-	 */
742
-	public function get_user_id( $context = 'view' ) {
743
-		return $this->get_author( $context );
736
+     * Alias of self::get_author().
737
+     *
738
+     * @since 1.0.19
739
+     * @param  string $context View or edit context.
740
+     * @return int
741
+     */
742
+    public function get_user_id( $context = 'view' ) {
743
+        return $this->get_author( $context );
744 744
     }
745 745
 
746
-     /**
747
-	 * Alias of self::get_author().
748
-	 *
749
-	 * @since 1.0.19
750
-	 * @param  string $context View or edit context.
751
-	 * @return int
752
-	 */
753
-	public function get_customer_id( $context = 'view' ) {
754
-		return $this->get_author( $context );
746
+        /**
747
+         * Alias of self::get_author().
748
+         *
749
+         * @since 1.0.19
750
+         * @param  string $context View or edit context.
751
+         * @return int
752
+         */
753
+    public function get_customer_id( $context = 'view' ) {
754
+        return $this->get_author( $context );
755 755
     }
756 756
 
757 757
     /**
758
-	 * Get the customer's ip.
759
-	 *
760
-	 * @since 1.0.19
761
-	 * @param  string $context View or edit context.
762
-	 * @return string
763
-	 */
764
-	public function get_ip( $context = 'view' ) {
765
-		return $this->get_prop( 'user_ip', $context );
758
+     * Get the customer's ip.
759
+     *
760
+     * @since 1.0.19
761
+     * @param  string $context View or edit context.
762
+     * @return string
763
+     */
764
+    public function get_ip( $context = 'view' ) {
765
+        return $this->get_prop( 'user_ip', $context );
766 766
     }
767 767
 
768 768
     /**
769
-	 * Alias of self::get_ip().
770
-	 *
771
-	 * @since 1.0.19
772
-	 * @param  string $context View or edit context.
773
-	 * @return string
774
-	 */
775
-	public function get_user_ip( $context = 'view' ) {
776
-		return $this->get_ip( $context );
769
+     * Alias of self::get_ip().
770
+     *
771
+     * @since 1.0.19
772
+     * @param  string $context View or edit context.
773
+     * @return string
774
+     */
775
+    public function get_user_ip( $context = 'view' ) {
776
+        return $this->get_ip( $context );
777 777
     }
778 778
 
779
-     /**
780
-	 * Alias of self::get_ip().
781
-	 *
782
-	 * @since 1.0.19
783
-	 * @param  string $context View or edit context.
784
-	 * @return string
785
-	 */
786
-	public function get_customer_ip( $context = 'view' ) {
787
-		return $this->get_ip( $context );
779
+        /**
780
+         * Alias of self::get_ip().
781
+         *
782
+         * @since 1.0.19
783
+         * @param  string $context View or edit context.
784
+         * @return string
785
+         */
786
+    public function get_customer_ip( $context = 'view' ) {
787
+        return $this->get_ip( $context );
788 788
     }
789 789
 
790 790
     /**
791
-	 * Get the customer's first name.
792
-	 *
793
-	 * @since 1.0.19
794
-	 * @param  string $context View or edit context.
795
-	 * @return string
796
-	 */
797
-	public function get_first_name( $context = 'view' ) {
798
-		return $this->get_prop( 'first_name', $context );
791
+     * Get the customer's first name.
792
+     *
793
+     * @since 1.0.19
794
+     * @param  string $context View or edit context.
795
+     * @return string
796
+     */
797
+    public function get_first_name( $context = 'view' ) {
798
+        return $this->get_prop( 'first_name', $context );
799 799
     }
800 800
 
801 801
     /**
802
-	 * Alias of self::get_first_name().
803
-	 *
804
-	 * @since 1.0.19
805
-	 * @param  string $context View or edit context.
806
-	 * @return int
807
-	 */
808
-	public function get_user_first_name( $context = 'view' ) {
809
-		return $this->get_first_name( $context );
802
+     * Alias of self::get_first_name().
803
+     *
804
+     * @since 1.0.19
805
+     * @param  string $context View or edit context.
806
+     * @return int
807
+     */
808
+    public function get_user_first_name( $context = 'view' ) {
809
+        return $this->get_first_name( $context );
810 810
     }
811 811
 
812
-     /**
813
-	 * Alias of self::get_first_name().
814
-	 *
815
-	 * @since 1.0.19
816
-	 * @param  string $context View or edit context.
817
-	 * @return int
818
-	 */
819
-	public function get_customer_first_name( $context = 'view' ) {
820
-		return $this->get_first_name( $context );
812
+        /**
813
+         * Alias of self::get_first_name().
814
+         *
815
+         * @since 1.0.19
816
+         * @param  string $context View or edit context.
817
+         * @return int
818
+         */
819
+    public function get_customer_first_name( $context = 'view' ) {
820
+        return $this->get_first_name( $context );
821 821
     }
822 822
 
823 823
     /**
824
-	 * Get the customer's last name.
825
-	 *
826
-	 * @since 1.0.19
827
-	 * @param  string $context View or edit context.
828
-	 * @return string
829
-	 */
830
-	public function get_last_name( $context = 'view' ) {
831
-		return $this->get_prop( 'last_name', $context );
824
+     * Get the customer's last name.
825
+     *
826
+     * @since 1.0.19
827
+     * @param  string $context View or edit context.
828
+     * @return string
829
+     */
830
+    public function get_last_name( $context = 'view' ) {
831
+        return $this->get_prop( 'last_name', $context );
832 832
     }
833 833
 
834 834
     /**
835
-	 * Alias of self::get_last_name().
836
-	 *
837
-	 * @since 1.0.19
838
-	 * @param  string $context View or edit context.
839
-	 * @return int
840
-	 */
841
-	public function get_user_last_name( $context = 'view' ) {
842
-		return $this->get_last_name( $context );
835
+     * Alias of self::get_last_name().
836
+     *
837
+     * @since 1.0.19
838
+     * @param  string $context View or edit context.
839
+     * @return int
840
+     */
841
+    public function get_user_last_name( $context = 'view' ) {
842
+        return $this->get_last_name( $context );
843 843
     }
844 844
 
845 845
     /**
846
-	 * Alias of self::get_last_name().
847
-	 *
848
-	 * @since 1.0.19
849
-	 * @param  string $context View or edit context.
850
-	 * @return int
851
-	 */
852
-	public function get_customer_last_name( $context = 'view' ) {
853
-		return $this->get_last_name( $context );
846
+     * Alias of self::get_last_name().
847
+     *
848
+     * @since 1.0.19
849
+     * @param  string $context View or edit context.
850
+     * @return int
851
+     */
852
+    public function get_customer_last_name( $context = 'view' ) {
853
+        return $this->get_last_name( $context );
854 854
     }
855 855
 
856 856
     /**
857
-	 * Get the customer's full name.
858
-	 *
859
-	 * @since 1.0.19
860
-	 * @param  string $context View or edit context.
861
-	 * @return string
862
-	 */
863
-	public function get_full_name( $context = 'view' ) {
864
-		return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) );
857
+     * Get the customer's full name.
858
+     *
859
+     * @since 1.0.19
860
+     * @param  string $context View or edit context.
861
+     * @return string
862
+     */
863
+    public function get_full_name( $context = 'view' ) {
864
+        return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) );
865 865
     }
866 866
 
867 867
     /**
868
-	 * Alias of self::get_full_name().
869
-	 *
870
-	 * @since 1.0.19
871
-	 * @param  string $context View or edit context.
872
-	 * @return int
873
-	 */
874
-	public function get_user_full_name( $context = 'view' ) {
875
-		return $this->get_full_name( $context );
868
+     * Alias of self::get_full_name().
869
+     *
870
+     * @since 1.0.19
871
+     * @param  string $context View or edit context.
872
+     * @return int
873
+     */
874
+    public function get_user_full_name( $context = 'view' ) {
875
+        return $this->get_full_name( $context );
876 876
     }
877 877
 
878 878
     /**
879
-	 * Alias of self::get_full_name().
880
-	 *
881
-	 * @since 1.0.19
882
-	 * @param  string $context View or edit context.
883
-	 * @return int
884
-	 */
885
-	public function get_customer_full_name( $context = 'view' ) {
886
-		return $this->get_full_name( $context );
879
+     * Alias of self::get_full_name().
880
+     *
881
+     * @since 1.0.19
882
+     * @param  string $context View or edit context.
883
+     * @return int
884
+     */
885
+    public function get_customer_full_name( $context = 'view' ) {
886
+        return $this->get_full_name( $context );
887 887
     }
888 888
 
889 889
     /**
890
-	 * Get the customer's phone number.
891
-	 *
892
-	 * @since 1.0.19
893
-	 * @param  string $context View or edit context.
894
-	 * @return string
895
-	 */
896
-	public function get_phone( $context = 'view' ) {
897
-		return $this->get_prop( 'phone', $context );
890
+     * Get the customer's phone number.
891
+     *
892
+     * @since 1.0.19
893
+     * @param  string $context View or edit context.
894
+     * @return string
895
+     */
896
+    public function get_phone( $context = 'view' ) {
897
+        return $this->get_prop( 'phone', $context );
898 898
     }
899 899
 
900 900
     /**
901
-	 * Alias of self::get_phone().
902
-	 *
903
-	 * @since 1.0.19
904
-	 * @param  string $context View or edit context.
905
-	 * @return int
906
-	 */
907
-	public function get_phone_number( $context = 'view' ) {
908
-		return $this->get_phone( $context );
901
+     * Alias of self::get_phone().
902
+     *
903
+     * @since 1.0.19
904
+     * @param  string $context View or edit context.
905
+     * @return int
906
+     */
907
+    public function get_phone_number( $context = 'view' ) {
908
+        return $this->get_phone( $context );
909 909
     }
910 910
 
911 911
     /**
912
-	 * Alias of self::get_phone().
913
-	 *
914
-	 * @since 1.0.19
915
-	 * @param  string $context View or edit context.
916
-	 * @return int
917
-	 */
918
-	public function get_user_phone( $context = 'view' ) {
919
-		return $this->get_phone( $context );
912
+     * Alias of self::get_phone().
913
+     *
914
+     * @since 1.0.19
915
+     * @param  string $context View or edit context.
916
+     * @return int
917
+     */
918
+    public function get_user_phone( $context = 'view' ) {
919
+        return $this->get_phone( $context );
920 920
     }
921 921
 
922 922
     /**
923
-	 * Alias of self::get_phone().
924
-	 *
925
-	 * @since 1.0.19
926
-	 * @param  string $context View or edit context.
927
-	 * @return int
928
-	 */
929
-	public function get_customer_phone( $context = 'view' ) {
930
-		return $this->get_phone( $context );
923
+     * Alias of self::get_phone().
924
+     *
925
+     * @since 1.0.19
926
+     * @param  string $context View or edit context.
927
+     * @return int
928
+     */
929
+    public function get_customer_phone( $context = 'view' ) {
930
+        return $this->get_phone( $context );
931 931
     }
932 932
 
933 933
     /**
934
-	 * Get the customer's email address.
935
-	 *
936
-	 * @since 1.0.19
937
-	 * @param  string $context View or edit context.
938
-	 * @return string
939
-	 */
940
-	public function get_email( $context = 'view' ) {
941
-		return $this->get_prop( 'email', $context );
934
+     * Get the customer's email address.
935
+     *
936
+     * @since 1.0.19
937
+     * @param  string $context View or edit context.
938
+     * @return string
939
+     */
940
+    public function get_email( $context = 'view' ) {
941
+        return $this->get_prop( 'email', $context );
942 942
     }
943 943
 
944 944
     /**
945
-	 * Alias of self::get_email().
946
-	 *
947
-	 * @since 1.0.19
948
-	 * @param  string $context View or edit context.
949
-	 * @return string
950
-	 */
951
-	public function get_email_address( $context = 'view' ) {
952
-		return $this->get_email( $context );
945
+     * Alias of self::get_email().
946
+     *
947
+     * @since 1.0.19
948
+     * @param  string $context View or edit context.
949
+     * @return string
950
+     */
951
+    public function get_email_address( $context = 'view' ) {
952
+        return $this->get_email( $context );
953 953
     }
954 954
 
955 955
     /**
956
-	 * Alias of self::get_email().
957
-	 *
958
-	 * @since 1.0.19
959
-	 * @param  string $context View or edit context.
960
-	 * @return int
961
-	 */
962
-	public function get_user_email( $context = 'view' ) {
963
-		return $this->get_email( $context );
956
+     * Alias of self::get_email().
957
+     *
958
+     * @since 1.0.19
959
+     * @param  string $context View or edit context.
960
+     * @return int
961
+     */
962
+    public function get_user_email( $context = 'view' ) {
963
+        return $this->get_email( $context );
964 964
     }
965 965
 
966 966
     /**
967
-	 * Alias of self::get_email().
968
-	 *
969
-	 * @since 1.0.19
970
-	 * @param  string $context View or edit context.
971
-	 * @return int
972
-	 */
973
-	public function get_customer_email( $context = 'view' ) {
974
-		return $this->get_email( $context );
967
+     * Alias of self::get_email().
968
+     *
969
+     * @since 1.0.19
970
+     * @param  string $context View or edit context.
971
+     * @return int
972
+     */
973
+    public function get_customer_email( $context = 'view' ) {
974
+        return $this->get_email( $context );
975 975
     }
976 976
 
977 977
     /**
978
-	 * Get the customer's country.
979
-	 *
980
-	 * @since 1.0.19
981
-	 * @param  string $context View or edit context.
982
-	 * @return string
983
-	 */
984
-	public function get_country( $context = 'view' ) {
985
-		$country = $this->get_prop( 'country', $context );
986
-		return empty( $country ) ? wpinv_get_default_country() : $country;
978
+     * Get the customer's country.
979
+     *
980
+     * @since 1.0.19
981
+     * @param  string $context View or edit context.
982
+     * @return string
983
+     */
984
+    public function get_country( $context = 'view' ) {
985
+        $country = $this->get_prop( 'country', $context );
986
+        return empty( $country ) ? wpinv_get_default_country() : $country;
987 987
     }
988 988
 
989 989
     /**
990
-	 * Alias of self::get_country().
991
-	 *
992
-	 * @since 1.0.19
993
-	 * @param  string $context View or edit context.
994
-	 * @return int
995
-	 */
996
-	public function get_user_country( $context = 'view' ) {
997
-		return $this->get_country( $context );
990
+     * Alias of self::get_country().
991
+     *
992
+     * @since 1.0.19
993
+     * @param  string $context View or edit context.
994
+     * @return int
995
+     */
996
+    public function get_user_country( $context = 'view' ) {
997
+        return $this->get_country( $context );
998 998
     }
999 999
 
1000 1000
     /**
1001
-	 * Alias of self::get_country().
1002
-	 *
1003
-	 * @since 1.0.19
1004
-	 * @param  string $context View or edit context.
1005
-	 * @return int
1006
-	 */
1007
-	public function get_customer_country( $context = 'view' ) {
1008
-		return $this->get_country( $context );
1001
+     * Alias of self::get_country().
1002
+     *
1003
+     * @since 1.0.19
1004
+     * @param  string $context View or edit context.
1005
+     * @return int
1006
+     */
1007
+    public function get_customer_country( $context = 'view' ) {
1008
+        return $this->get_country( $context );
1009 1009
     }
1010 1010
 
1011 1011
     /**
1012
-	 * Get the customer's state.
1013
-	 *
1014
-	 * @since 1.0.19
1015
-	 * @param  string $context View or edit context.
1016
-	 * @return string
1017
-	 */
1018
-	public function get_state( $context = 'view' ) {
1019
-		$state = $this->get_prop( 'state', $context );
1020
-		return empty( $state ) ? wpinv_get_default_state() : $state;
1012
+     * Get the customer's state.
1013
+     *
1014
+     * @since 1.0.19
1015
+     * @param  string $context View or edit context.
1016
+     * @return string
1017
+     */
1018
+    public function get_state( $context = 'view' ) {
1019
+        $state = $this->get_prop( 'state', $context );
1020
+        return empty( $state ) ? wpinv_get_default_state() : $state;
1021 1021
     }
1022 1022
 
1023 1023
     /**
1024
-	 * Alias of self::get_state().
1025
-	 *
1026
-	 * @since 1.0.19
1027
-	 * @param  string $context View or edit context.
1028
-	 * @return int
1029
-	 */
1030
-	public function get_user_state( $context = 'view' ) {
1031
-		return $this->get_state( $context );
1032
-    }
1033
-
1024
+     * Alias of self::get_state().
1025
+     *
1026
+     * @since 1.0.19
1027
+     * @param  string $context View or edit context.
1028
+     * @return int
1029
+     */
1030
+    public function get_user_state( $context = 'view' ) {
1031
+        return $this->get_state( $context );
1032
+    }
1033
+
1034
+    /**
1035
+     * Alias of self::get_state().
1036
+     *
1037
+     * @since 1.0.19
1038
+     * @param  string $context View or edit context.
1039
+     * @return int
1040
+     */
1041
+    public function get_customer_state( $context = 'view' ) {
1042
+        return $this->get_state( $context );
1043
+    }
1044
+
1045
+    /**
1046
+     * Get the customer's city.
1047
+     *
1048
+     * @since 1.0.19
1049
+     * @param  string $context View or edit context.
1050
+     * @return string
1051
+     */
1052
+    public function get_city( $context = 'view' ) {
1053
+        return $this->get_prop( 'city', $context );
1054
+    }
1055
+
1056
+    /**
1057
+     * Alias of self::get_city().
1058
+     *
1059
+     * @since 1.0.19
1060
+     * @param  string $context View or edit context.
1061
+     * @return string
1062
+     */
1063
+    public function get_user_city( $context = 'view' ) {
1064
+        return $this->get_city( $context );
1065
+    }
1066
+
1034 1067
     /**
1035
-	 * Alias of self::get_state().
1036
-	 *
1037
-	 * @since 1.0.19
1038
-	 * @param  string $context View or edit context.
1039
-	 * @return int
1040
-	 */
1041
-	public function get_customer_state( $context = 'view' ) {
1042
-		return $this->get_state( $context );
1068
+     * Alias of self::get_city().
1069
+     *
1070
+     * @since 1.0.19
1071
+     * @param  string $context View or edit context.
1072
+     * @return string
1073
+     */
1074
+    public function get_customer_city( $context = 'view' ) {
1075
+        return $this->get_city( $context );
1043 1076
     }
1044 1077
 
1045 1078
     /**
1046
-	 * Get the customer's city.
1047
-	 *
1048
-	 * @since 1.0.19
1049
-	 * @param  string $context View or edit context.
1050
-	 * @return string
1051
-	 */
1052
-	public function get_city( $context = 'view' ) {
1053
-		return $this->get_prop( 'city', $context );
1079
+     * Get the customer's zip.
1080
+     *
1081
+     * @since 1.0.19
1082
+     * @param  string $context View or edit context.
1083
+     * @return string
1084
+     */
1085
+    public function get_zip( $context = 'view' ) {
1086
+        return $this->get_prop( 'zip', $context );
1054 1087
     }
1055 1088
 
1056 1089
     /**
1057
-	 * Alias of self::get_city().
1058
-	 *
1059
-	 * @since 1.0.19
1060
-	 * @param  string $context View or edit context.
1061
-	 * @return string
1062
-	 */
1063
-	public function get_user_city( $context = 'view' ) {
1064
-		return $this->get_city( $context );
1090
+     * Alias of self::get_zip().
1091
+     *
1092
+     * @since 1.0.19
1093
+     * @param  string $context View or edit context.
1094
+     * @return string
1095
+     */
1096
+    public function get_user_zip( $context = 'view' ) {
1097
+        return $this->get_zip( $context );
1065 1098
     }
1066 1099
 
1067 1100
     /**
1068
-	 * Alias of self::get_city().
1069
-	 *
1070
-	 * @since 1.0.19
1071
-	 * @param  string $context View or edit context.
1072
-	 * @return string
1073
-	 */
1074
-	public function get_customer_city( $context = 'view' ) {
1075
-		return $this->get_city( $context );
1101
+     * Alias of self::get_zip().
1102
+     *
1103
+     * @since 1.0.19
1104
+     * @param  string $context View or edit context.
1105
+     * @return string
1106
+     */
1107
+    public function get_customer_zip( $context = 'view' ) {
1108
+        return $this->get_zip( $context );
1076 1109
     }
1077 1110
 
1078 1111
     /**
1079
-	 * Get the customer's zip.
1080
-	 *
1081
-	 * @since 1.0.19
1082
-	 * @param  string $context View or edit context.
1083
-	 * @return string
1084
-	 */
1085
-	public function get_zip( $context = 'view' ) {
1086
-		return $this->get_prop( 'zip', $context );
1112
+     * Get the customer's company.
1113
+     *
1114
+     * @since 1.0.19
1115
+     * @param  string $context View or edit context.
1116
+     * @return string
1117
+     */
1118
+    public function get_company( $context = 'view' ) {
1119
+        return $this->get_prop( 'company', $context );
1087 1120
     }
1088 1121
 
1089 1122
     /**
1090
-	 * Alias of self::get_zip().
1091
-	 *
1092
-	 * @since 1.0.19
1093
-	 * @param  string $context View or edit context.
1094
-	 * @return string
1095
-	 */
1096
-	public function get_user_zip( $context = 'view' ) {
1097
-		return $this->get_zip( $context );
1123
+     * Alias of self::get_company().
1124
+     *
1125
+     * @since 1.0.19
1126
+     * @param  string $context View or edit context.
1127
+     * @return string
1128
+     */
1129
+    public function get_user_company( $context = 'view' ) {
1130
+        return $this->get_company( $context );
1098 1131
     }
1099 1132
 
1100 1133
     /**
1101
-	 * Alias of self::get_zip().
1102
-	 *
1103
-	 * @since 1.0.19
1104
-	 * @param  string $context View or edit context.
1105
-	 * @return string
1106
-	 */
1107
-	public function get_customer_zip( $context = 'view' ) {
1108
-		return $this->get_zip( $context );
1134
+     * Alias of self::get_company().
1135
+     *
1136
+     * @since 1.0.19
1137
+     * @param  string $context View or edit context.
1138
+     * @return string
1139
+     */
1140
+    public function get_customer_company( $context = 'view' ) {
1141
+        return $this->get_company( $context );
1109 1142
     }
1110 1143
 
1111 1144
     /**
1112
-	 * Get the customer's company.
1113
-	 *
1114
-	 * @since 1.0.19
1115
-	 * @param  string $context View or edit context.
1116
-	 * @return string
1117
-	 */
1118
-	public function get_company( $context = 'view' ) {
1119
-		return $this->get_prop( 'company', $context );
1145
+     * Get the customer's vat number.
1146
+     *
1147
+     * @since 1.0.19
1148
+     * @param  string $context View or edit context.
1149
+     * @return string
1150
+     */
1151
+    public function get_vat_number( $context = 'view' ) {
1152
+        return $this->get_prop( 'vat_number', $context );
1120 1153
     }
1121 1154
 
1122 1155
     /**
1123
-	 * Alias of self::get_company().
1124
-	 *
1125
-	 * @since 1.0.19
1126
-	 * @param  string $context View or edit context.
1127
-	 * @return string
1128
-	 */
1129
-	public function get_user_company( $context = 'view' ) {
1130
-		return $this->get_company( $context );
1156
+     * Alias of self::get_vat_number().
1157
+     *
1158
+     * @since 1.0.19
1159
+     * @param  string $context View or edit context.
1160
+     * @return string
1161
+     */
1162
+    public function get_user_vat_number( $context = 'view' ) {
1163
+        return $this->get_vat_number( $context );
1131 1164
     }
1132 1165
 
1133 1166
     /**
1134
-	 * Alias of self::get_company().
1135
-	 *
1136
-	 * @since 1.0.19
1137
-	 * @param  string $context View or edit context.
1138
-	 * @return string
1139
-	 */
1140
-	public function get_customer_company( $context = 'view' ) {
1141
-		return $this->get_company( $context );
1167
+     * Alias of self::get_vat_number().
1168
+     *
1169
+     * @since 1.0.19
1170
+     * @param  string $context View or edit context.
1171
+     * @return string
1172
+     */
1173
+    public function get_customer_vat_number( $context = 'view' ) {
1174
+        return $this->get_vat_number( $context );
1142 1175
     }
1143 1176
 
1144 1177
     /**
1145
-	 * Get the customer's vat number.
1146
-	 *
1147
-	 * @since 1.0.19
1148
-	 * @param  string $context View or edit context.
1149
-	 * @return string
1150
-	 */
1151
-	public function get_vat_number( $context = 'view' ) {
1152
-		return $this->get_prop( 'vat_number', $context );
1178
+     * Get the customer's vat rate.
1179
+     *
1180
+     * @since 1.0.19
1181
+     * @param  string $context View or edit context.
1182
+     * @return string
1183
+     */
1184
+    public function get_vat_rate( $context = 'view' ) {
1185
+        return $this->get_prop( 'vat_rate', $context );
1153 1186
     }
1154 1187
 
1155 1188
     /**
1156
-	 * Alias of self::get_vat_number().
1157
-	 *
1158
-	 * @since 1.0.19
1159
-	 * @param  string $context View or edit context.
1160
-	 * @return string
1161
-	 */
1162
-	public function get_user_vat_number( $context = 'view' ) {
1163
-		return $this->get_vat_number( $context );
1189
+     * Alias of self::get_vat_rate().
1190
+     *
1191
+     * @since 1.0.19
1192
+     * @param  string $context View or edit context.
1193
+     * @return string
1194
+     */
1195
+    public function get_user_vat_rate( $context = 'view' ) {
1196
+        return $this->get_vat_rate( $context );
1164 1197
     }
1165 1198
 
1166 1199
     /**
1167
-	 * Alias of self::get_vat_number().
1168
-	 *
1169
-	 * @since 1.0.19
1170
-	 * @param  string $context View or edit context.
1171
-	 * @return string
1172
-	 */
1173
-	public function get_customer_vat_number( $context = 'view' ) {
1174
-		return $this->get_vat_number( $context );
1200
+     * Alias of self::get_vat_rate().
1201
+     *
1202
+     * @since 1.0.19
1203
+     * @param  string $context View or edit context.
1204
+     * @return string
1205
+     */
1206
+    public function get_customer_vat_rate( $context = 'view' ) {
1207
+        return $this->get_vat_rate( $context );
1175 1208
     }
1176 1209
 
1177 1210
     /**
1178
-	 * Get the customer's vat rate.
1179
-	 *
1180
-	 * @since 1.0.19
1181
-	 * @param  string $context View or edit context.
1182
-	 * @return string
1183
-	 */
1184
-	public function get_vat_rate( $context = 'view' ) {
1185
-		return $this->get_prop( 'vat_rate', $context );
1211
+     * Get the customer's address.
1212
+     *
1213
+     * @since 1.0.19
1214
+     * @param  string $context View or edit context.
1215
+     * @return string
1216
+     */
1217
+    public function get_address( $context = 'view' ) {
1218
+        return $this->get_prop( 'address', $context );
1186 1219
     }
1187 1220
 
1188 1221
     /**
1189
-	 * Alias of self::get_vat_rate().
1190
-	 *
1191
-	 * @since 1.0.19
1192
-	 * @param  string $context View or edit context.
1193
-	 * @return string
1194
-	 */
1195
-	public function get_user_vat_rate( $context = 'view' ) {
1196
-		return $this->get_vat_rate( $context );
1222
+     * Alias of self::get_address().
1223
+     *
1224
+     * @since 1.0.19
1225
+     * @param  string $context View or edit context.
1226
+     * @return string
1227
+     */
1228
+    public function get_user_address( $context = 'view' ) {
1229
+        return $this->get_address( $context );
1197 1230
     }
1198 1231
 
1199 1232
     /**
1200
-	 * Alias of self::get_vat_rate().
1201
-	 *
1202
-	 * @since 1.0.19
1203
-	 * @param  string $context View or edit context.
1204
-	 * @return string
1205
-	 */
1206
-	public function get_customer_vat_rate( $context = 'view' ) {
1207
-		return $this->get_vat_rate( $context );
1233
+     * Alias of self::get_address().
1234
+     *
1235
+     * @since 1.0.19
1236
+     * @param  string $context View or edit context.
1237
+     * @return string
1238
+     */
1239
+    public function get_customer_address( $context = 'view' ) {
1240
+        return $this->get_address( $context );
1208 1241
     }
1209 1242
 
1210 1243
     /**
1211
-	 * Get the customer's address.
1212
-	 *
1213
-	 * @since 1.0.19
1214
-	 * @param  string $context View or edit context.
1215
-	 * @return string
1216
-	 */
1217
-	public function get_address( $context = 'view' ) {
1218
-		return $this->get_prop( 'address', $context );
1219
-    }
1220
-
1221
-    /**
1222
-	 * Alias of self::get_address().
1223
-	 *
1224
-	 * @since 1.0.19
1225
-	 * @param  string $context View or edit context.
1226
-	 * @return string
1227
-	 */
1228
-	public function get_user_address( $context = 'view' ) {
1229
-		return $this->get_address( $context );
1230
-    }
1231
-
1232
-    /**
1233
-	 * Alias of self::get_address().
1234
-	 *
1235
-	 * @since 1.0.19
1236
-	 * @param  string $context View or edit context.
1237
-	 * @return string
1238
-	 */
1239
-	public function get_customer_address( $context = 'view' ) {
1240
-		return $this->get_address( $context );
1241
-    }
1242
-
1243
-    /**
1244
-	 * Get whether the customer has viewed the invoice or not.
1245
-	 *
1246
-	 * @since 1.0.19
1247
-	 * @param  string $context View or edit context.
1248
-	 * @return bool
1249
-	 */
1250
-	public function get_is_viewed( $context = 'view' ) {
1251
-		return (bool) $this->get_prop( 'is_viewed', $context );
1252
-	}
1253
-
1254
-	/**
1255
-	 * Get other recipients for invoice communications.
1256
-	 *
1257
-	 * @since 1.0.19
1258
-	 * @param  string $context View or edit context.
1259
-	 * @return bool
1260
-	 */
1261
-	public function get_email_cc( $context = 'view' ) {
1262
-		return $this->get_prop( 'email_cc', $context );
1263
-	}
1264
-
1265
-	/**
1266
-	 * Get invoice template.
1267
-	 *
1268
-	 * @since 1.0.19
1269
-	 * @param  string $context View or edit context.
1270
-	 * @return bool
1271
-	 */
1272
-	public function get_template( $context = 'view' ) {
1273
-		return $this->get_prop( 'template', $context );
1274
-	}
1275
-
1276
-	/**
1277
-	 * Get whether the customer has confirmed their address.
1278
-	 *
1279
-	 * @since 1.0.19
1280
-	 * @param  string $context View or edit context.
1281
-	 * @return bool
1282
-	 */
1283
-	public function get_address_confirmed( $context = 'view' ) {
1284
-		return (bool) $this->get_prop( 'address_confirmed', $context );
1285
-    }
1286
-
1287
-    /**
1288
-	 * Alias of self::get_address_confirmed().
1289
-	 *
1290
-	 * @since 1.0.19
1291
-	 * @param  string $context View or edit context.
1292
-	 * @return bool
1293
-	 */
1294
-	public function get_user_address_confirmed( $context = 'view' ) {
1295
-		return $this->get_address_confirmed( $context );
1296
-    }
1297
-
1298
-    /**
1299
-	 * Alias of self::get_address().
1300
-	 *
1301
-	 * @since 1.0.19
1302
-	 * @param  string $context View or edit context.
1303
-	 * @return bool
1304
-	 */
1305
-	public function get_customer_address_confirmed( $context = 'view' ) {
1306
-		return $this->get_address_confirmed( $context );
1307
-    }
1308
-
1309
-    /**
1310
-	 * Get the invoice subtotal.
1311
-	 *
1312
-	 * @since 1.0.19
1313
-	 * @param  string $context View or edit context.
1314
-	 * @return float
1315
-	 */
1316
-	public function get_subtotal( $context = 'view' ) {
1244
+     * Get whether the customer has viewed the invoice or not.
1245
+     *
1246
+     * @since 1.0.19
1247
+     * @param  string $context View or edit context.
1248
+     * @return bool
1249
+     */
1250
+    public function get_is_viewed( $context = 'view' ) {
1251
+        return (bool) $this->get_prop( 'is_viewed', $context );
1252
+    }
1253
+
1254
+    /**
1255
+     * Get other recipients for invoice communications.
1256
+     *
1257
+     * @since 1.0.19
1258
+     * @param  string $context View or edit context.
1259
+     * @return bool
1260
+     */
1261
+    public function get_email_cc( $context = 'view' ) {
1262
+        return $this->get_prop( 'email_cc', $context );
1263
+    }
1264
+
1265
+    /**
1266
+     * Get invoice template.
1267
+     *
1268
+     * @since 1.0.19
1269
+     * @param  string $context View or edit context.
1270
+     * @return bool
1271
+     */
1272
+    public function get_template( $context = 'view' ) {
1273
+        return $this->get_prop( 'template', $context );
1274
+    }
1275
+
1276
+    /**
1277
+     * Get whether the customer has confirmed their address.
1278
+     *
1279
+     * @since 1.0.19
1280
+     * @param  string $context View or edit context.
1281
+     * @return bool
1282
+     */
1283
+    public function get_address_confirmed( $context = 'view' ) {
1284
+        return (bool) $this->get_prop( 'address_confirmed', $context );
1285
+    }
1286
+
1287
+    /**
1288
+     * Alias of self::get_address_confirmed().
1289
+     *
1290
+     * @since 1.0.19
1291
+     * @param  string $context View or edit context.
1292
+     * @return bool
1293
+     */
1294
+    public function get_user_address_confirmed( $context = 'view' ) {
1295
+        return $this->get_address_confirmed( $context );
1296
+    }
1297
+
1298
+    /**
1299
+     * Alias of self::get_address().
1300
+     *
1301
+     * @since 1.0.19
1302
+     * @param  string $context View or edit context.
1303
+     * @return bool
1304
+     */
1305
+    public function get_customer_address_confirmed( $context = 'view' ) {
1306
+        return $this->get_address_confirmed( $context );
1307
+    }
1308
+
1309
+    /**
1310
+     * Get the invoice subtotal.
1311
+     *
1312
+     * @since 1.0.19
1313
+     * @param  string $context View or edit context.
1314
+     * @return float
1315
+     */
1316
+    public function get_subtotal( $context = 'view' ) {
1317 1317
         $subtotal = (float) $this->get_prop( 'subtotal', $context );
1318 1318
 
1319 1319
         // Backwards compatibility.
@@ -1325,165 +1325,165 @@  discard block
 block discarded – undo
1325 1325
     }
1326 1326
 
1327 1327
     /**
1328
-	 * Get the invoice discount total.
1329
-	 *
1330
-	 * @since 1.0.19
1331
-	 * @param  string $context View or edit context.
1332
-	 * @return float
1333
-	 */
1334
-	public function get_total_discount( $context = 'view' ) {
1335
-		return (float) $this->get_prop( 'total_discount', $context );
1328
+     * Get the invoice discount total.
1329
+     *
1330
+     * @since 1.0.19
1331
+     * @param  string $context View or edit context.
1332
+     * @return float
1333
+     */
1334
+    public function get_total_discount( $context = 'view' ) {
1335
+        return (float) $this->get_prop( 'total_discount', $context );
1336 1336
     }
1337 1337
 
1338 1338
     /**
1339
-	 * Get the invoice tax total.
1340
-	 *
1341
-	 * @since 1.0.19
1342
-	 * @param  string $context View or edit context.
1343
-	 * @return float
1344
-	 */
1345
-	public function get_total_tax( $context = 'view' ) {
1346
-		return (float) $this->get_prop( 'total_tax', $context );
1347
-	}
1339
+     * Get the invoice tax total.
1340
+     *
1341
+     * @since 1.0.19
1342
+     * @param  string $context View or edit context.
1343
+     * @return float
1344
+     */
1345
+    public function get_total_tax( $context = 'view' ) {
1346
+        return (float) $this->get_prop( 'total_tax', $context );
1347
+    }
1348 1348
 
1349
-	/**
1350
-	 * @deprecated
1351
-	 */
1352
-	public function get_final_tax( $currency = false ) {
1353
-		$tax = $this->get_total_tax();
1349
+    /**
1350
+     * @deprecated
1351
+     */
1352
+    public function get_final_tax( $currency = false ) {
1353
+        $tax = $this->get_total_tax();
1354 1354
 
1355 1355
         if ( $currency ) {
1356
-			return wpinv_price( wpinv_format_amount( $tax, NULL, false ), $this->get_currency() );
1356
+            return wpinv_price( wpinv_format_amount( $tax, NULL, false ), $this->get_currency() );
1357 1357
         }
1358 1358
 
1359 1359
         return $tax;
1360 1360
     }
1361 1361
 
1362 1362
     /**
1363
-	 * Get the invoice fees total.
1364
-	 *
1365
-	 * @since 1.0.19
1366
-	 * @param  string $context View or edit context.
1367
-	 * @return float
1368
-	 */
1369
-	public function get_total_fees( $context = 'view' ) {
1370
-		return (float) $this->get_prop( 'total_fees', $context );
1363
+     * Get the invoice fees total.
1364
+     *
1365
+     * @since 1.0.19
1366
+     * @param  string $context View or edit context.
1367
+     * @return float
1368
+     */
1369
+    public function get_total_fees( $context = 'view' ) {
1370
+        return (float) $this->get_prop( 'total_fees', $context );
1371 1371
     }
1372 1372
 
1373 1373
     /**
1374
-	 * Alias for self::get_total_fees().
1375
-	 *
1376
-	 * @since 1.0.19
1377
-	 * @param  string $context View or edit context.
1378
-	 * @return float
1379
-	 */
1380
-	public function get_fees_total( $context = 'view' ) {
1381
-		return $this->get_total_fees( $context );
1374
+     * Alias for self::get_total_fees().
1375
+     *
1376
+     * @since 1.0.19
1377
+     * @param  string $context View or edit context.
1378
+     * @return float
1379
+     */
1380
+    public function get_fees_total( $context = 'view' ) {
1381
+        return $this->get_total_fees( $context );
1382 1382
     }
1383 1383
 
1384 1384
     /**
1385
-	 * Get the invoice total.
1386
-	 *
1387
-	 * @since 1.0.19
1385
+     * Get the invoice total.
1386
+     *
1387
+     * @since 1.0.19
1388 1388
      * @return float
1389
-	 */
1390
-	public function get_total() {
1391
-		$total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total();
1392
-		return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this  );
1393
-	}
1389
+     */
1390
+    public function get_total() {
1391
+        $total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total();
1392
+        return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this  );
1393
+    }
1394 1394
 	
1395
-	/**
1396
-	 * Get the invoice totals.
1397
-	 *
1398
-	 * @since 1.0.19
1395
+    /**
1396
+     * Get the invoice totals.
1397
+     *
1398
+     * @since 1.0.19
1399 1399
      * @return float
1400
-	 */
1401
-	public function get_totals() {
1402
-		return $this->totals;
1400
+     */
1401
+    public function get_totals() {
1402
+        return $this->totals;
1403 1403
     }
1404 1404
 
1405 1405
     /**
1406
-	 * Get the initial invoice total.
1407
-	 *
1408
-	 * @since 1.0.19
1406
+     * Get the initial invoice total.
1407
+     *
1408
+     * @since 1.0.19
1409 1409
      * @param  string $context View or edit context.
1410 1410
      * @return float
1411
-	 */
1411
+     */
1412 1412
     public function get_initial_total() {
1413 1413
 
1414
-		if ( empty( $this->totals ) ) {
1415
-			$this->recalculate_total();
1416
-		}
1414
+        if ( empty( $this->totals ) ) {
1415
+            $this->recalculate_total();
1416
+        }
1417 1417
 
1418
-		$tax      = $this->totals['tax']['initial'];
1419
-		$fee      = $this->totals['fee']['initial'];
1420
-		$discount = $this->totals['discount']['initial'];
1421
-		$subtotal = $this->totals['subtotal']['initial'];
1422
-		$total    = $tax + $fee - $discount + $subtotal;
1418
+        $tax      = $this->totals['tax']['initial'];
1419
+        $fee      = $this->totals['fee']['initial'];
1420
+        $discount = $this->totals['discount']['initial'];
1421
+        $subtotal = $this->totals['subtotal']['initial'];
1422
+        $total    = $tax + $fee - $discount + $subtotal;
1423 1423
 
1424
-		if ( 0 > $total ) {
1425
-			$total = 0;
1426
-		}
1424
+        if ( 0 > $total ) {
1425
+            $total = 0;
1426
+        }
1427 1427
 
1428 1428
         return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this );
1429
-	}
1429
+    }
1430 1430
 
1431
-	/**
1432
-	 * Get the recurring invoice total.
1433
-	 *
1434
-	 * @since 1.0.19
1431
+    /**
1432
+     * Get the recurring invoice total.
1433
+     *
1434
+     * @since 1.0.19
1435 1435
      * @param  string $context View or edit context.
1436 1436
      * @return float
1437
-	 */
1437
+     */
1438 1438
     public function get_recurring_total() {
1439 1439
 
1440
-		if ( empty( $this->totals ) ) {
1441
-			$this->recalculate_total();
1442
-		}
1440
+        if ( empty( $this->totals ) ) {
1441
+            $this->recalculate_total();
1442
+        }
1443 1443
 
1444
-		$tax      = $this->totals['tax']['recurring'];
1445
-		$fee      = $this->totals['fee']['recurring'];
1446
-		$discount = $this->totals['discount']['recurring'];
1447
-		$subtotal = $this->totals['subtotal']['recurring'];
1448
-		$total    = $tax + $fee - $discount + $subtotal;
1444
+        $tax      = $this->totals['tax']['recurring'];
1445
+        $fee      = $this->totals['fee']['recurring'];
1446
+        $discount = $this->totals['discount']['recurring'];
1447
+        $subtotal = $this->totals['subtotal']['recurring'];
1448
+        $total    = $tax + $fee - $discount + $subtotal;
1449 1449
 
1450
-		if ( 0 > $total ) {
1451
-			$total = 0;
1452
-		}
1450
+        if ( 0 > $total ) {
1451
+            $total = 0;
1452
+        }
1453 1453
 
1454 1454
         return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this );
1455
-	}
1455
+    }
1456 1456
 
1457
-	/**
1458
-	 * Returns recurring payment details.
1459
-	 *
1460
-	 * @since 1.0.19
1457
+    /**
1458
+     * Returns recurring payment details.
1459
+     *
1460
+     * @since 1.0.19
1461 1461
      * @param  string $field Optionally provide a field to return.
1462
-	 * @param string $currency Whether to include the currency.
1462
+     * @param string $currency Whether to include the currency.
1463 1463
      * @return float
1464
-	 */
1464
+     */
1465 1465
     public function get_recurring_details( $field = '', $currency = false ) {
1466 1466
 
1467
-		// Maybe recalculate totals.
1468
-		if ( empty( $this->totals ) ) {
1469
-			$this->recalculate_total();
1470
-		}
1467
+        // Maybe recalculate totals.
1468
+        if ( empty( $this->totals ) ) {
1469
+            $this->recalculate_total();
1470
+        }
1471 1471
 
1472
-		// Prepare recurring totals.
1472
+        // Prepare recurring totals.
1473 1473
         $data = apply_filters(
1474
-			'wpinv_get_invoice_recurring_details',
1475
-			array(
1476
-				'cart_details' => $this->get_cart_details(),
1477
-				'subtotal'     => $this->totals['subtotal']['recurring'],
1478
-				'discount'     => $this->totals['discount']['recurring'],
1479
-				'tax'          => $this->totals['tax']['recurring'],
1480
-				'fee'          => $this->totals['fee']['recurring'],
1481
-				'total'        => $this->get_recurring_total(),
1482
-			),
1483
-			$this,
1484
-			$field,
1485
-			$currency
1486
-		);
1474
+            'wpinv_get_invoice_recurring_details',
1475
+            array(
1476
+                'cart_details' => $this->get_cart_details(),
1477
+                'subtotal'     => $this->totals['subtotal']['recurring'],
1478
+                'discount'     => $this->totals['discount']['recurring'],
1479
+                'tax'          => $this->totals['tax']['recurring'],
1480
+                'fee'          => $this->totals['fee']['recurring'],
1481
+                'total'        => $this->get_recurring_total(),
1482
+            ),
1483
+            $this,
1484
+            $field,
1485
+            $currency
1486
+        );
1487 1487
 
1488 1488
         if ( isset( $data[$field] ) ) {
1489 1489
             return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
@@ -1493,145 +1493,145 @@  discard block
 block discarded – undo
1493 1493
     }
1494 1494
 
1495 1495
     /**
1496
-	 * Get the invoice fees.
1497
-	 *
1498
-	 * @since 1.0.19
1499
-	 * @param  string $context View or edit context.
1500
-	 * @return array
1501
-	 */
1502
-	public function get_fees( $context = 'view' ) {
1503
-		return wpinv_parse_list( $this->get_prop( 'fees', $context ) );
1496
+     * Get the invoice fees.
1497
+     *
1498
+     * @since 1.0.19
1499
+     * @param  string $context View or edit context.
1500
+     * @return array
1501
+     */
1502
+    public function get_fees( $context = 'view' ) {
1503
+        return wpinv_parse_list( $this->get_prop( 'fees', $context ) );
1504 1504
     }
1505 1505
 
1506 1506
     /**
1507
-	 * Get the invoice discounts.
1508
-	 *
1509
-	 * @since 1.0.19
1510
-	 * @param  string $context View or edit context.
1511
-	 * @return array
1512
-	 */
1513
-	public function get_discounts( $context = 'view' ) {
1514
-		return wpinv_parse_list( $this->get_prop( 'discounts', $context ) );
1507
+     * Get the invoice discounts.
1508
+     *
1509
+     * @since 1.0.19
1510
+     * @param  string $context View or edit context.
1511
+     * @return array
1512
+     */
1513
+    public function get_discounts( $context = 'view' ) {
1514
+        return wpinv_parse_list( $this->get_prop( 'discounts', $context ) );
1515 1515
     }
1516 1516
 
1517 1517
     /**
1518
-	 * Get the invoice taxes.
1519
-	 *
1520
-	 * @since 1.0.19
1521
-	 * @param  string $context View or edit context.
1522
-	 * @return array
1523
-	 */
1524
-	public function get_taxes( $context = 'view' ) {
1525
-		return wpinv_parse_list( $this->get_prop( 'taxes', $context ) );
1518
+     * Get the invoice taxes.
1519
+     *
1520
+     * @since 1.0.19
1521
+     * @param  string $context View or edit context.
1522
+     * @return array
1523
+     */
1524
+    public function get_taxes( $context = 'view' ) {
1525
+        return wpinv_parse_list( $this->get_prop( 'taxes', $context ) );
1526 1526
     }
1527 1527
 
1528 1528
     /**
1529
-	 * Get the invoice items.
1530
-	 *
1531
-	 * @since 1.0.19
1532
-	 * @param  string $context View or edit context.
1533
-	 * @return GetPaid_Form_Item[]
1534
-	 */
1535
-	public function get_items( $context = 'view' ) {
1529
+     * Get the invoice items.
1530
+     *
1531
+     * @since 1.0.19
1532
+     * @param  string $context View or edit context.
1533
+     * @return GetPaid_Form_Item[]
1534
+     */
1535
+    public function get_items( $context = 'view' ) {
1536 1536
         return $this->get_prop( 'items', $context );
1537 1537
     }
1538 1538
 
1539 1539
     /**
1540
-	 * Get the invoice's payment form.
1541
-	 *
1542
-	 * @since 1.0.19
1543
-	 * @param  string $context View or edit context.
1544
-	 * @return int
1545
-	 */
1546
-	public function get_payment_form( $context = 'view' ) {
1547
-		return intval( $this->get_prop( 'payment_form', $context ) );
1540
+     * Get the invoice's payment form.
1541
+     *
1542
+     * @since 1.0.19
1543
+     * @param  string $context View or edit context.
1544
+     * @return int
1545
+     */
1546
+    public function get_payment_form( $context = 'view' ) {
1547
+        return intval( $this->get_prop( 'payment_form', $context ) );
1548 1548
     }
1549 1549
 
1550 1550
     /**
1551
-	 * Get the invoice's submission id.
1552
-	 *
1553
-	 * @since 1.0.19
1554
-	 * @param  string $context View or edit context.
1555
-	 * @return string
1556
-	 */
1557
-	public function get_submission_id( $context = 'view' ) {
1558
-		return $this->get_prop( 'submission_id', $context );
1551
+     * Get the invoice's submission id.
1552
+     *
1553
+     * @since 1.0.19
1554
+     * @param  string $context View or edit context.
1555
+     * @return string
1556
+     */
1557
+    public function get_submission_id( $context = 'view' ) {
1558
+        return $this->get_prop( 'submission_id', $context );
1559 1559
     }
1560 1560
 
1561 1561
     /**
1562
-	 * Get the invoice's discount code.
1563
-	 *
1564
-	 * @since 1.0.19
1565
-	 * @param  string $context View or edit context.
1566
-	 * @return string
1567
-	 */
1568
-	public function get_discount_code( $context = 'view' ) {
1569
-		return $this->get_prop( 'discount_code', $context );
1562
+     * Get the invoice's discount code.
1563
+     *
1564
+     * @since 1.0.19
1565
+     * @param  string $context View or edit context.
1566
+     * @return string
1567
+     */
1568
+    public function get_discount_code( $context = 'view' ) {
1569
+        return $this->get_prop( 'discount_code', $context );
1570 1570
     }
1571 1571
 
1572 1572
     /**
1573
-	 * Get the invoice's gateway.
1574
-	 *
1575
-	 * @since 1.0.19
1576
-	 * @param  string $context View or edit context.
1577
-	 * @return string
1578
-	 */
1579
-	public function get_gateway( $context = 'view' ) {
1580
-		return $this->get_prop( 'gateway', $context );
1573
+     * Get the invoice's gateway.
1574
+     *
1575
+     * @since 1.0.19
1576
+     * @param  string $context View or edit context.
1577
+     * @return string
1578
+     */
1579
+    public function get_gateway( $context = 'view' ) {
1580
+        return $this->get_prop( 'gateway', $context );
1581 1581
     }
1582 1582
 
1583 1583
     /**
1584
-	 * Get the invoice's gateway display title.
1585
-	 *
1586
-	 * @since 1.0.19
1587
-	 * @return string
1588
-	 */
1584
+     * Get the invoice's gateway display title.
1585
+     *
1586
+     * @since 1.0.19
1587
+     * @return string
1588
+     */
1589 1589
     public function get_gateway_title() {
1590 1590
         $title =  wpinv_get_gateway_checkout_label( $this->get_gateway() );
1591 1591
         return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this );
1592 1592
     }
1593 1593
 
1594 1594
     /**
1595
-	 * Get the invoice's transaction id.
1596
-	 *
1597
-	 * @since 1.0.19
1598
-	 * @param  string $context View or edit context.
1599
-	 * @return string
1600
-	 */
1601
-	public function get_transaction_id( $context = 'view' ) {
1602
-		return $this->get_prop( 'transaction_id', $context );
1595
+     * Get the invoice's transaction id.
1596
+     *
1597
+     * @since 1.0.19
1598
+     * @param  string $context View or edit context.
1599
+     * @return string
1600
+     */
1601
+    public function get_transaction_id( $context = 'view' ) {
1602
+        return $this->get_prop( 'transaction_id', $context );
1603 1603
     }
1604 1604
 
1605 1605
     /**
1606
-	 * Get the invoice's currency.
1607
-	 *
1608
-	 * @since 1.0.19
1609
-	 * @param  string $context View or edit context.
1610
-	 * @return string
1611
-	 */
1612
-	public function get_currency( $context = 'view' ) {
1606
+     * Get the invoice's currency.
1607
+     *
1608
+     * @since 1.0.19
1609
+     * @param  string $context View or edit context.
1610
+     * @return string
1611
+     */
1612
+    public function get_currency( $context = 'view' ) {
1613 1613
         $currency = $this->get_prop( 'currency', $context );
1614 1614
         return empty( $currency ) ? wpinv_get_currency() : $currency;
1615 1615
     }
1616 1616
 
1617 1617
     /**
1618
-	 * Checks if we are charging taxes for this invoice.
1619
-	 *
1620
-	 * @since 1.0.19
1621
-	 * @param  string $context View or edit context.
1622
-	 * @return bool
1623
-	 */
1624
-	public function get_disable_taxes( $context = 'view' ) {
1618
+     * Checks if we are charging taxes for this invoice.
1619
+     *
1620
+     * @since 1.0.19
1621
+     * @param  string $context View or edit context.
1622
+     * @return bool
1623
+     */
1624
+    public function get_disable_taxes( $context = 'view' ) {
1625 1625
         return (bool) $this->get_prop( 'disable_taxes', $context );
1626 1626
     }
1627 1627
 
1628 1628
     /**
1629
-	 * Retrieves the remote subscription id for an invoice.
1630
-	 *
1631
-	 * @since 1.0.19
1632
-	 * @param  string $context View or edit context.
1633
-	 * @return int
1634
-	 */
1629
+     * Retrieves the remote subscription id for an invoice.
1630
+     *
1631
+     * @since 1.0.19
1632
+     * @param  string $context View or edit context.
1633
+     * @return int
1634
+     */
1635 1635
     public function get_subscription_id( $context = 'view' ) {
1636 1636
         $subscription_id = $this->get_prop( 'subscription_id', $context );
1637 1637
 
@@ -1644,12 +1644,12 @@  discard block
 block discarded – undo
1644 1644
     }
1645 1645
 
1646 1646
     /**
1647
-	 * Retrieves the payment meta for an invoice.
1648
-	 *
1649
-	 * @since 1.0.19
1650
-	 * @param  string $context View or edit context.
1651
-	 * @return array
1652
-	 */
1647
+     * Retrieves the payment meta for an invoice.
1648
+     *
1649
+     * @since 1.0.19
1650
+     * @param  string $context View or edit context.
1651
+     * @return array
1652
+     */
1653 1653
     public function get_payment_meta( $context = 'view' ) {
1654 1654
 
1655 1655
         return array(
@@ -1669,11 +1669,11 @@  discard block
 block discarded – undo
1669 1669
     }
1670 1670
 
1671 1671
     /**
1672
-	 * Retrieves the cart details for an invoice.
1673
-	 *
1674
-	 * @since 1.0.19
1675
-	 * @return array
1676
-	 */
1672
+     * Retrieves the cart details for an invoice.
1673
+     *
1674
+     * @since 1.0.19
1675
+     * @return array
1676
+     */
1677 1677
     public function get_cart_details() {
1678 1678
         $items        = $this->get_items();
1679 1679
         $cart_details = array();
@@ -1683,16 +1683,16 @@  discard block
 block discarded – undo
1683 1683
         }
1684 1684
 
1685 1685
         return $cart_details;
1686
-	}
1686
+    }
1687 1687
 
1688
-	/**
1689
-	 * Retrieves the recurring item.
1690
-	 *
1691
-	 * @return null|GetPaid_Form_Item|int
1692
-	 */
1693
-	public function get_recurring( $object = false ) {
1688
+    /**
1689
+     * Retrieves the recurring item.
1690
+     *
1691
+     * @return null|GetPaid_Form_Item|int
1692
+     */
1693
+    public function get_recurring( $object = false ) {
1694 1694
 
1695
-		// Are we returning an object?
1695
+        // Are we returning an object?
1696 1696
         if ( $object ) {
1697 1697
             return $this->get_item( $this->recurring_item );
1698 1698
         }
@@ -1700,100 +1700,100 @@  discard block
 block discarded – undo
1700 1700
         return $this->recurring_item;
1701 1701
     }
1702 1702
 
1703
-	/**
1704
-	 * Retrieves the subscription name.
1705
-	 *
1706
-	 * @since 1.0.19
1707
-	 * @return string
1708
-	 */
1709
-	public function get_subscription_name() {
1703
+    /**
1704
+     * Retrieves the subscription name.
1705
+     *
1706
+     * @since 1.0.19
1707
+     * @return string
1708
+     */
1709
+    public function get_subscription_name() {
1710 1710
 
1711
-		// Retrieve the recurring name
1711
+        // Retrieve the recurring name
1712 1712
         $item = $this->get_recurring( true );
1713 1713
 
1714
-		// Abort if it does not exist.
1714
+        // Abort if it does not exist.
1715 1715
         if ( empty( $item ) ) {
1716 1716
             return '';
1717 1717
         }
1718 1718
 
1719
-		// Return the item name.
1719
+        // Return the item name.
1720 1720
         return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this );
1721
-	}
1722
-
1723
-	/**
1724
-	 * Retrieves the view url.
1725
-	 *
1726
-	 * @since 1.0.19
1727
-	 * @return string
1728
-	 */
1729
-	public function get_view_url() {
1721
+    }
1722
+
1723
+    /**
1724
+     * Retrieves the view url.
1725
+     *
1726
+     * @since 1.0.19
1727
+     * @return string
1728
+     */
1729
+    public function get_view_url() {
1730 1730
         $invoice_url = get_permalink( $this->get_id() );
1731
-		$invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
1731
+        $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
1732 1732
         return apply_filters( 'wpinv_get_view_url', $invoice_url, $this );
1733
-	}
1733
+    }
1734 1734
 
1735
-	/**
1736
-	 * Retrieves the payment url.
1737
-	 *
1738
-	 * @since 1.0.19
1739
-	 * @return string
1740
-	 */
1741
-	public function get_checkout_payment_url( $deprecated = false, $secret = false ) {
1735
+    /**
1736
+     * Retrieves the payment url.
1737
+     *
1738
+     * @since 1.0.19
1739
+     * @return string
1740
+     */
1741
+    public function get_checkout_payment_url( $deprecated = false, $secret = false ) {
1742 1742
 
1743
-		// Retrieve the checkout url.
1743
+        // Retrieve the checkout url.
1744 1744
         $pay_url = wpinv_get_checkout_uri();
1745 1745
 
1746
-		// Maybe force ssl.
1746
+        // Maybe force ssl.
1747 1747
         if ( is_ssl() ) {
1748 1748
             $pay_url = str_replace( 'http:', 'https:', $pay_url );
1749 1749
         }
1750 1750
 
1751
-		// Add the invoice key.
1752
-		$pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url );
1751
+        // Add the invoice key.
1752
+        $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url );
1753 1753
 
1754
-		// (Maybe?) add a secret
1754
+        // (Maybe?) add a secret
1755 1755
         if ( $secret ) {
1756 1756
             $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url );
1757 1757
         }
1758 1758
 
1759 1759
         return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret );
1760
-	}
1760
+    }
1761 1761
 	
1762
-	/**
1763
-	 * Retrieves the receipt url.
1764
-	 *
1765
-	 * @since 1.0.19
1766
-	 * @return string
1767
-	 */
1768
-	public function get_receipt_url() {
1769
-
1770
-		// Retrieve the checkout url.
1762
+    /**
1763
+     * Retrieves the receipt url.
1764
+     *
1765
+     * @since 1.0.19
1766
+     * @return string
1767
+     */
1768
+    public function get_receipt_url() {
1769
+
1770
+        // Retrieve the checkout url.
1771 1771
         $receipt_url = wpinv_get_success_page_uri();
1772 1772
 
1773
-		// Maybe force ssl.
1773
+        // Maybe force ssl.
1774 1774
         if ( is_ssl() ) {
1775 1775
             $receipt_url = str_replace( 'http:', 'https:', $receipt_url );
1776 1776
         }
1777 1777
 
1778
-		// Add the invoice key.
1779
-		$receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url );
1778
+        // Add the invoice key.
1779
+        $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url );
1780 1780
 
1781 1781
         return apply_filters( 'getpaid_get_invoice_receipt_url', $receipt_url, $this );
1782 1782
     }
1783 1783
 
1784 1784
     /**
1785
-	 * Magic method for accessing invoice properties.
1786
-	 *
1787
-	 * @since 1.0.15
1788
-	 * @access public
1789
-	 *
1790
-	 * @param string $key Discount data to retrieve
1791
-	 * @param  string $context View or edit context.
1792
-	 * @return mixed Value of the given invoice property (if set).
1793
-	 */
1794
-	public function get( $key, $context = 'view' ) {
1785
+     * Magic method for accessing invoice properties.
1786
+     *
1787
+     * @since 1.0.15
1788
+     * @access public
1789
+     *
1790
+     * @param string $key Discount data to retrieve
1791
+     * @param  string $context View or edit context.
1792
+     * @return mixed Value of the given invoice property (if set).
1793
+     */
1794
+    public function get( $key, $context = 'view' ) {
1795 1795
         return $this->get_prop( $key, $context );
1796
-	}
1796
+    }
1797 1797
 
1798 1798
     /*
1799 1799
 	|--------------------------------------------------------------------------
@@ -1806,130 +1806,130 @@  discard block
 block discarded – undo
1806 1806
     */
1807 1807
 
1808 1808
     /**
1809
-	 * Magic method for setting invoice properties.
1810
-	 *
1811
-	 * @since 1.0.19
1812
-	 * @access public
1813
-	 *
1814
-	 * @param string $key Discount data to retrieve
1815
-	 * @param  mixed $value new value.
1816
-	 * @return mixed Value of the given invoice property (if set).
1817
-	 */
1818
-	public function set( $key, $value ) {
1809
+     * Magic method for setting invoice properties.
1810
+     *
1811
+     * @since 1.0.19
1812
+     * @access public
1813
+     *
1814
+     * @param string $key Discount data to retrieve
1815
+     * @param  mixed $value new value.
1816
+     * @return mixed Value of the given invoice property (if set).
1817
+     */
1818
+    public function set( $key, $value ) {
1819 1819
 
1820 1820
         $setter = "set_$key";
1821 1821
         if ( is_callable( array( $this, $setter ) ) ) {
1822 1822
             $this->{$setter}( $value );
1823 1823
         }
1824 1824
 
1825
-	}
1825
+    }
1826 1826
 
1827
-	/**
1828
-	 * Sets item status.
1829
-	 *
1830
-	 * @since 1.0.19
1831
-	 * @param string $new_status    New status.
1832
-	 * @param string $note          Optional note to add.
1833
-	 * @param bool   $manual_update Is this a manual status change?.
1834
-	 * @return array details of change.
1835
-	 */
1836
-	public function set_status( $new_status, $note = '', $manual_update = false ) {
1837
-		$old_status = $this->get_status();
1827
+    /**
1828
+     * Sets item status.
1829
+     *
1830
+     * @since 1.0.19
1831
+     * @param string $new_status    New status.
1832
+     * @param string $note          Optional note to add.
1833
+     * @param bool   $manual_update Is this a manual status change?.
1834
+     * @return array details of change.
1835
+     */
1836
+    public function set_status( $new_status, $note = '', $manual_update = false ) {
1837
+        $old_status = $this->get_status();
1838 1838
 
1839
-		$statuses = $this->get_all_statuses();
1839
+        $statuses = $this->get_all_statuses();
1840 1840
 
1841
-		if ( isset( $statuses[ 'draft' ] ) ) {
1842
-			unset( $statuses[ 'draft' ] );
1843
-		}
1841
+        if ( isset( $statuses[ 'draft' ] ) ) {
1842
+            unset( $statuses[ 'draft' ] );
1843
+        }
1844 1844
 
1845
-		$this->set_prop( 'status', $new_status );
1845
+        $this->set_prop( 'status', $new_status );
1846 1846
 
1847
-		// If setting the status, ensure it's set to a valid status.
1848
-		if ( true === $this->object_read ) {
1847
+        // If setting the status, ensure it's set to a valid status.
1848
+        if ( true === $this->object_read ) {
1849 1849
 
1850
-			// Only allow valid new status.
1851
-			if ( ! array_key_exists( $new_status, $statuses ) ) {
1852
-				$new_status = 'wpi-pending';
1853
-			}
1850
+            // Only allow valid new status.
1851
+            if ( ! array_key_exists( $new_status, $statuses ) ) {
1852
+                $new_status = 'wpi-pending';
1853
+            }
1854 1854
 
1855
-			// If the old status is set but unknown (e.g. draft) assume its pending for action usage.
1856
-			if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) {
1857
-				$old_status = 'wpi-pending';
1858
-			}
1855
+            // If the old status is set but unknown (e.g. draft) assume its pending for action usage.
1856
+            if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) {
1857
+                $old_status = 'wpi-pending';
1858
+            }
1859 1859
 
1860
-			// Paid - Renewal (i.e when duplicating a parent invoice )
1861
-			if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) {
1862
-				$old_status = 'wpi-pending';
1863
-			}
1860
+            // Paid - Renewal (i.e when duplicating a parent invoice )
1861
+            if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) {
1862
+                $old_status = 'wpi-pending';
1863
+            }
1864 1864
 
1865
-		}
1865
+        }
1866 1866
 
1867
-		if ( true === $this->object_read && $old_status !== $new_status ) {
1868
-			$this->status_transition = array(
1869
-				'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
1870
-				'to'     => $new_status,
1871
-				'note'   => $note,
1872
-				'manual' => (bool) $manual_update,
1873
-			);
1867
+        if ( true === $this->object_read && $old_status !== $new_status ) {
1868
+            $this->status_transition = array(
1869
+                'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
1870
+                'to'     => $new_status,
1871
+                'note'   => $note,
1872
+                'manual' => (bool) $manual_update,
1873
+            );
1874 1874
 
1875
-			if ( $manual_update ) {
1876
-				do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status );
1877
-			}
1875
+            if ( $manual_update ) {
1876
+                do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status );
1877
+            }
1878 1878
 
1879
-			$this->maybe_set_date_paid();
1879
+            $this->maybe_set_date_paid();
1880 1880
 
1881
-		}
1881
+        }
1882 1882
 
1883
-		return array(
1884
-			'from' => $old_status,
1885
-			'to'   => $new_status,
1886
-		);
1887
-	}
1883
+        return array(
1884
+            'from' => $old_status,
1885
+            'to'   => $new_status,
1886
+        );
1887
+    }
1888 1888
 
1889
-	/**
1890
-	 * Maybe set date paid.
1891
-	 *
1892
-	 * Sets the date paid variable when transitioning to the payment complete
1893
-	 * order status.
1894
-	 *
1895
-	 * @since 1.0.19
1896
-	 */
1897
-	public function maybe_set_date_paid() {
1889
+    /**
1890
+     * Maybe set date paid.
1891
+     *
1892
+     * Sets the date paid variable when transitioning to the payment complete
1893
+     * order status.
1894
+     *
1895
+     * @since 1.0.19
1896
+     */
1897
+    public function maybe_set_date_paid() {
1898 1898
 
1899
-		if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) {
1900
-			$this->set_date_completed( current_time( 'mysql' ) );
1901
-		}
1902
-	}
1899
+        if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) {
1900
+            $this->set_date_completed( current_time( 'mysql' ) );
1901
+        }
1902
+    }
1903 1903
 
1904 1904
     /**
1905
-	 * Set parent invoice ID.
1906
-	 *
1907
-	 * @since 1.0.19
1908
-	 */
1909
-	public function set_parent_id( $value ) {
1910
-		if ( $value && ( $value === $this->get_id() ) ) {
1911
-			return;
1912
-		}
1913
-		$this->set_prop( 'parent_id', absint( $value ) );
1905
+     * Set parent invoice ID.
1906
+     *
1907
+     * @since 1.0.19
1908
+     */
1909
+    public function set_parent_id( $value ) {
1910
+        if ( $value && ( $value === $this->get_id() ) ) {
1911
+            return;
1912
+        }
1913
+        $this->set_prop( 'parent_id', absint( $value ) );
1914 1914
     }
1915 1915
 
1916 1916
     /**
1917
-	 * Set plugin version when the invoice was created.
1918
-	 *
1919
-	 * @since 1.0.19
1920
-	 */
1921
-	public function set_version( $value ) {
1922
-		$this->set_prop( 'version', $value );
1917
+     * Set plugin version when the invoice was created.
1918
+     *
1919
+     * @since 1.0.19
1920
+     */
1921
+    public function set_version( $value ) {
1922
+        $this->set_prop( 'version', $value );
1923 1923
     }
1924
-
1925
-    /**
1926
-	 * Set date when the invoice was created.
1927
-	 *
1928
-	 * @since 1.0.19
1929
-	 * @param string $value Value to set.
1924
+
1925
+    /**
1926
+     * Set date when the invoice was created.
1927
+     *
1928
+     * @since 1.0.19
1929
+     * @param string $value Value to set.
1930 1930
      * @return bool Whether or not the date was set.
1931
-	 */
1932
-	public function set_date_created( $value ) {
1931
+     */
1932
+    public function set_date_created( $value ) {
1933 1933
         $date = strtotime( $value );
1934 1934
 
1935 1935
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -1942,13 +1942,13 @@  discard block
 block discarded – undo
1942 1942
     }
1943 1943
 
1944 1944
     /**
1945
-	 * Set date invoice due date.
1946
-	 *
1947
-	 * @since 1.0.19
1948
-	 * @param string $value Value to set.
1945
+     * Set date invoice due date.
1946
+     *
1947
+     * @since 1.0.19
1948
+     * @param string $value Value to set.
1949 1949
      * @return bool Whether or not the date was set.
1950
-	 */
1951
-	public function set_due_date( $value ) {
1950
+     */
1951
+    public function set_due_date( $value ) {
1952 1952
         $date = strtotime( $value );
1953 1953
 
1954 1954
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -1956,29 +1956,29 @@  discard block
 block discarded – undo
1956 1956
             return true;
1957 1957
         }
1958 1958
 
1959
-		$this->set_prop( 'due_date', '' );
1959
+        $this->set_prop( 'due_date', '' );
1960 1960
         return false;
1961 1961
 
1962 1962
     }
1963 1963
 
1964 1964
     /**
1965
-	 * Alias of self::set_due_date().
1966
-	 *
1967
-	 * @since 1.0.19
1968
-	 * @param  string $value New name.
1969
-	 */
1970
-	public function set_date_due( $value ) {
1971
-		$this->set_due_date( $value );
1965
+     * Alias of self::set_due_date().
1966
+     *
1967
+     * @since 1.0.19
1968
+     * @param  string $value New name.
1969
+     */
1970
+    public function set_date_due( $value ) {
1971
+        $this->set_due_date( $value );
1972 1972
     }
1973 1973
 
1974 1974
     /**
1975
-	 * Set date invoice was completed.
1976
-	 *
1977
-	 * @since 1.0.19
1978
-	 * @param string $value Value to set.
1975
+     * Set date invoice was completed.
1976
+     *
1977
+     * @since 1.0.19
1978
+     * @param string $value Value to set.
1979 1979
      * @return bool Whether or not the date was set.
1980
-	 */
1981
-	public function set_completed_date( $value ) {
1980
+     */
1981
+    public function set_completed_date( $value ) {
1982 1982
         $date = strtotime( $value );
1983 1983
 
1984 1984
         if ( $date && $value !== '0000-00-00 00:00:00'  ) {
@@ -1986,29 +1986,29 @@  discard block
 block discarded – undo
1986 1986
             return true;
1987 1987
         }
1988 1988
 
1989
-		$this->set_prop( 'completed_date', '' );
1989
+        $this->set_prop( 'completed_date', '' );
1990 1990
         return false;
1991 1991
 
1992 1992
     }
1993 1993
 
1994 1994
     /**
1995
-	 * Alias of self::set_completed_date().
1996
-	 *
1997
-	 * @since 1.0.19
1998
-	 * @param  string $value New name.
1999
-	 */
2000
-	public function set_date_completed( $value ) {
2001
-		$this->set_completed_date( $value );
1995
+     * Alias of self::set_completed_date().
1996
+     *
1997
+     * @since 1.0.19
1998
+     * @param  string $value New name.
1999
+     */
2000
+    public function set_date_completed( $value ) {
2001
+        $this->set_completed_date( $value );
2002 2002
     }
2003 2003
 
2004 2004
     /**
2005
-	 * Set date when the invoice was last modified.
2006
-	 *
2007
-	 * @since 1.0.19
2008
-	 * @param string $value Value to set.
2005
+     * Set date when the invoice was last modified.
2006
+     *
2007
+     * @since 1.0.19
2008
+     * @param string $value Value to set.
2009 2009
      * @return bool Whether or not the date was set.
2010
-	 */
2011
-	public function set_date_modified( $value ) {
2010
+     */
2011
+    public function set_date_modified( $value ) {
2012 2012
         $date = strtotime( $value );
2013 2013
 
2014 2014
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -2016,706 +2016,706 @@  discard block
 block discarded – undo
2016 2016
             return true;
2017 2017
         }
2018 2018
 
2019
-		$this->set_prop( 'date_modified', '' );
2019
+        $this->set_prop( 'date_modified', '' );
2020 2020
         return false;
2021 2021
 
2022 2022
     }
2023 2023
 
2024 2024
     /**
2025
-	 * Set the invoice number.
2026
-	 *
2027
-	 * @since 1.0.19
2028
-	 * @param  string $value New number.
2029
-	 */
2030
-	public function set_number( $value ) {
2025
+     * Set the invoice number.
2026
+     *
2027
+     * @since 1.0.19
2028
+     * @param  string $value New number.
2029
+     */
2030
+    public function set_number( $value ) {
2031 2031
         $number = sanitize_text_field( $value );
2032
-		$this->set_prop( 'number', $number );
2032
+        $this->set_prop( 'number', $number );
2033 2033
     }
2034 2034
 
2035 2035
     /**
2036
-	 * Set the invoice type.
2037
-	 *
2038
-	 * @since 1.0.19
2039
-	 * @param  string $value Type.
2040
-	 */
2041
-	public function set_type( $value ) {
2036
+     * Set the invoice type.
2037
+     *
2038
+     * @since 1.0.19
2039
+     * @param  string $value Type.
2040
+     */
2041
+    public function set_type( $value ) {
2042 2042
         $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) );
2043
-		$this->set_prop( 'type', $type );
2044
-	}
2043
+        $this->set_prop( 'type', $type );
2044
+    }
2045 2045
 
2046 2046
     /**
2047
-	 * Set the invoice post type.
2048
-	 *
2049
-	 * @since 1.0.19
2050
-	 * @param  string $value Post type.
2051
-	 */
2052
-	public function set_post_type( $value ) {
2047
+     * Set the invoice post type.
2048
+     *
2049
+     * @since 1.0.19
2050
+     * @param  string $value Post type.
2051
+     */
2052
+    public function set_post_type( $value ) {
2053 2053
         if ( getpaid_is_invoice_post_type( $value ) ) {
2054
-			$this->set_type( $value );
2054
+            $this->set_type( $value );
2055 2055
             $this->set_prop( 'post_type', $value );
2056 2056
         }
2057 2057
     }
2058 2058
 
2059 2059
     /**
2060
-	 * Set the invoice key.
2061
-	 *
2062
-	 * @since 1.0.19
2063
-	 * @param  string $value New key.
2064
-	 */
2065
-	public function set_key( $value ) {
2060
+     * Set the invoice key.
2061
+     *
2062
+     * @since 1.0.19
2063
+     * @param  string $value New key.
2064
+     */
2065
+    public function set_key( $value ) {
2066 2066
         $key = sanitize_text_field( $value );
2067
-		$this->set_prop( 'key', $key );
2067
+        $this->set_prop( 'key', $key );
2068 2068
     }
2069 2069
 
2070 2070
     /**
2071
-	 * Set the invoice mode.
2072
-	 *
2073
-	 * @since 1.0.19
2074
-	 * @param  string $value mode.
2075
-	 */
2076
-	public function set_mode( $value ) {
2071
+     * Set the invoice mode.
2072
+     *
2073
+     * @since 1.0.19
2074
+     * @param  string $value mode.
2075
+     */
2076
+    public function set_mode( $value ) {
2077 2077
         if ( ! in_array( $value, array( 'live', 'test' ) ) ) {
2078 2078
             $this->set_prop( 'value', $value );
2079 2079
         }
2080 2080
     }
2081 2081
 
2082 2082
     /**
2083
-	 * Set the invoice path.
2084
-	 *
2085
-	 * @since 1.0.19
2086
-	 * @param  string $value path.
2087
-	 */
2088
-	public function set_path( $value ) {
2083
+     * Set the invoice path.
2084
+     *
2085
+     * @since 1.0.19
2086
+     * @param  string $value path.
2087
+     */
2088
+    public function set_path( $value ) {
2089 2089
         $this->set_prop( 'path', $value );
2090 2090
     }
2091 2091
 
2092 2092
     /**
2093
-	 * Set the invoice name.
2094
-	 *
2095
-	 * @since 1.0.19
2096
-	 * @param  string $value New name.
2097
-	 */
2098
-	public function set_name( $value ) {
2093
+     * Set the invoice name.
2094
+     *
2095
+     * @since 1.0.19
2096
+     * @param  string $value New name.
2097
+     */
2098
+    public function set_name( $value ) {
2099 2099
         $name = sanitize_text_field( $value );
2100
-		$this->set_prop( 'name', $name );
2100
+        $this->set_prop( 'name', $name );
2101 2101
     }
2102 2102
 
2103 2103
     /**
2104
-	 * Alias of self::set_name().
2105
-	 *
2106
-	 * @since 1.0.19
2107
-	 * @param  string $value New name.
2108
-	 */
2109
-	public function set_title( $value ) {
2110
-		$this->set_name( $value );
2104
+     * Alias of self::set_name().
2105
+     *
2106
+     * @since 1.0.19
2107
+     * @param  string $value New name.
2108
+     */
2109
+    public function set_title( $value ) {
2110
+        $this->set_name( $value );
2111 2111
     }
2112 2112
 
2113 2113
     /**
2114
-	 * Set the invoice description.
2115
-	 *
2116
-	 * @since 1.0.19
2117
-	 * @param  string $value New description.
2118
-	 */
2119
-	public function set_description( $value ) {
2114
+     * Set the invoice description.
2115
+     *
2116
+     * @since 1.0.19
2117
+     * @param  string $value New description.
2118
+     */
2119
+    public function set_description( $value ) {
2120 2120
         $description = wp_kses_post( $value );
2121
-		return $this->set_prop( 'description', $description );
2121
+        return $this->set_prop( 'description', $description );
2122 2122
     }
2123 2123
 
2124 2124
     /**
2125
-	 * Alias of self::set_description().
2126
-	 *
2127
-	 * @since 1.0.19
2128
-	 * @param  string $value New description.
2129
-	 */
2130
-	public function set_excerpt( $value ) {
2131
-		$this->set_description( $value );
2125
+     * Alias of self::set_description().
2126
+     *
2127
+     * @since 1.0.19
2128
+     * @param  string $value New description.
2129
+     */
2130
+    public function set_excerpt( $value ) {
2131
+        $this->set_description( $value );
2132 2132
     }
2133 2133
 
2134 2134
     /**
2135
-	 * Alias of self::set_description().
2136
-	 *
2137
-	 * @since 1.0.19
2138
-	 * @param  string $value New description.
2139
-	 */
2140
-	public function set_summary( $value ) {
2141
-		$this->set_description( $value );
2135
+     * Alias of self::set_description().
2136
+     *
2137
+     * @since 1.0.19
2138
+     * @param  string $value New description.
2139
+     */
2140
+    public function set_summary( $value ) {
2141
+        $this->set_description( $value );
2142 2142
     }
2143 2143
 
2144 2144
     /**
2145
-	 * Set the receiver of the invoice.
2146
-	 *
2147
-	 * @since 1.0.19
2148
-	 * @param  int $value New author.
2149
-	 */
2150
-	public function set_author( $value ) {
2151
-		$user = get_user_by( 'id', (int) $value );
2145
+     * Set the receiver of the invoice.
2146
+     *
2147
+     * @since 1.0.19
2148
+     * @param  int $value New author.
2149
+     */
2150
+    public function set_author( $value ) {
2151
+        $user = get_user_by( 'id', (int) $value );
2152 2152
 
2153
-		if ( $user && $user->ID ) {
2154
-			$this->set_prop( 'author', $user->ID );
2155
-			$this->set_prop( 'email', $user->user_email );
2156
-		}
2153
+        if ( $user && $user->ID ) {
2154
+            $this->set_prop( 'author', $user->ID );
2155
+            $this->set_prop( 'email', $user->user_email );
2156
+        }
2157 2157
 		
2158 2158
     }
2159 2159
 
2160 2160
     /**
2161
-	 * Alias of self::set_author().
2162
-	 *
2163
-	 * @since 1.0.19
2164
-	 * @param  int $value New user id.
2165
-	 */
2166
-	public function set_user_id( $value ) {
2167
-		$this->set_author( $value );
2161
+     * Alias of self::set_author().
2162
+     *
2163
+     * @since 1.0.19
2164
+     * @param  int $value New user id.
2165
+     */
2166
+    public function set_user_id( $value ) {
2167
+        $this->set_author( $value );
2168 2168
     }
2169 2169
 
2170 2170
     /**
2171
-	 * Alias of self::set_author().
2172
-	 *
2173
-	 * @since 1.0.19
2174
-	 * @param  int $value New user id.
2175
-	 */
2176
-	public function set_customer_id( $value ) {
2177
-		$this->set_author( $value );
2171
+     * Alias of self::set_author().
2172
+     *
2173
+     * @since 1.0.19
2174
+     * @param  int $value New user id.
2175
+     */
2176
+    public function set_customer_id( $value ) {
2177
+        $this->set_author( $value );
2178 2178
     }
2179 2179
 
2180 2180
     /**
2181
-	 * Set the customer's ip.
2182
-	 *
2183
-	 * @since 1.0.19
2184
-	 * @param  string $value ip address.
2185
-	 */
2186
-	public function set_ip( $value ) {
2187
-		$this->set_prop( 'ip', $value );
2181
+     * Set the customer's ip.
2182
+     *
2183
+     * @since 1.0.19
2184
+     * @param  string $value ip address.
2185
+     */
2186
+    public function set_ip( $value ) {
2187
+        $this->set_prop( 'ip', $value );
2188 2188
     }
2189 2189
 
2190 2190
     /**
2191
-	 * Alias of self::set_ip().
2192
-	 *
2193
-	 * @since 1.0.19
2194
-	 * @param  string $value ip address.
2195
-	 */
2196
-	public function set_user_ip( $value ) {
2197
-		$this->set_ip( $value );
2191
+     * Alias of self::set_ip().
2192
+     *
2193
+     * @since 1.0.19
2194
+     * @param  string $value ip address.
2195
+     */
2196
+    public function set_user_ip( $value ) {
2197
+        $this->set_ip( $value );
2198 2198
     }
2199 2199
 
2200 2200
     /**
2201
-	 * Set the customer's first name.
2202
-	 *
2203
-	 * @since 1.0.19
2204
-	 * @param  string $value first name.
2205
-	 */
2206
-	public function set_first_name( $value ) {
2207
-		$this->set_prop( 'first_name', $value );
2201
+     * Set the customer's first name.
2202
+     *
2203
+     * @since 1.0.19
2204
+     * @param  string $value first name.
2205
+     */
2206
+    public function set_first_name( $value ) {
2207
+        $this->set_prop( 'first_name', $value );
2208 2208
     }
2209 2209
 
2210 2210
     /**
2211
-	 * Alias of self::set_first_name().
2212
-	 *
2213
-	 * @since 1.0.19
2214
-	 * @param  string $value first name.
2215
-	 */
2216
-	public function set_user_first_name( $value ) {
2217
-		$this->set_first_name( $value );
2211
+     * Alias of self::set_first_name().
2212
+     *
2213
+     * @since 1.0.19
2214
+     * @param  string $value first name.
2215
+     */
2216
+    public function set_user_first_name( $value ) {
2217
+        $this->set_first_name( $value );
2218 2218
     }
2219 2219
 
2220 2220
     /**
2221
-	 * Alias of self::set_first_name().
2222
-	 *
2223
-	 * @since 1.0.19
2224
-	 * @param  string $value first name.
2225
-	 */
2226
-	public function set_customer_first_name( $value ) {
2227
-		$this->set_first_name( $value );
2221
+     * Alias of self::set_first_name().
2222
+     *
2223
+     * @since 1.0.19
2224
+     * @param  string $value first name.
2225
+     */
2226
+    public function set_customer_first_name( $value ) {
2227
+        $this->set_first_name( $value );
2228 2228
     }
2229 2229
 
2230 2230
     /**
2231
-	 * Set the customer's last name.
2232
-	 *
2233
-	 * @since 1.0.19
2234
-	 * @param  string $value last name.
2235
-	 */
2236
-	public function set_last_name( $value ) {
2237
-		$this->set_prop( 'last_name', $value );
2231
+     * Set the customer's last name.
2232
+     *
2233
+     * @since 1.0.19
2234
+     * @param  string $value last name.
2235
+     */
2236
+    public function set_last_name( $value ) {
2237
+        $this->set_prop( 'last_name', $value );
2238 2238
     }
2239 2239
 
2240 2240
     /**
2241
-	 * Alias of self::set_last_name().
2242
-	 *
2243
-	 * @since 1.0.19
2244
-	 * @param  string $value last name.
2245
-	 */
2246
-	public function set_user_last_name( $value ) {
2247
-		$this->set_last_name( $value );
2241
+     * Alias of self::set_last_name().
2242
+     *
2243
+     * @since 1.0.19
2244
+     * @param  string $value last name.
2245
+     */
2246
+    public function set_user_last_name( $value ) {
2247
+        $this->set_last_name( $value );
2248 2248
     }
2249 2249
 
2250 2250
     /**
2251
-	 * Alias of self::set_last_name().
2252
-	 *
2253
-	 * @since 1.0.19
2254
-	 * @param  string $value last name.
2255
-	 */
2256
-	public function set_customer_last_name( $value ) {
2257
-		$this->set_last_name( $value );
2251
+     * Alias of self::set_last_name().
2252
+     *
2253
+     * @since 1.0.19
2254
+     * @param  string $value last name.
2255
+     */
2256
+    public function set_customer_last_name( $value ) {
2257
+        $this->set_last_name( $value );
2258 2258
     }
2259 2259
 
2260 2260
     /**
2261
-	 * Set the customer's phone number.
2262
-	 *
2263
-	 * @since 1.0.19
2264
-	 * @param  string $value phone.
2265
-	 */
2266
-	public function set_phone( $value ) {
2267
-		$this->set_prop( 'phone', $value );
2261
+     * Set the customer's phone number.
2262
+     *
2263
+     * @since 1.0.19
2264
+     * @param  string $value phone.
2265
+     */
2266
+    public function set_phone( $value ) {
2267
+        $this->set_prop( 'phone', $value );
2268 2268
     }
2269 2269
 
2270 2270
     /**
2271
-	 * Alias of self::set_phone().
2272
-	 *
2273
-	 * @since 1.0.19
2274
-	 * @param  string $value phone.
2275
-	 */
2276
-	public function set_user_phone( $value ) {
2277
-		$this->set_phone( $value );
2271
+     * Alias of self::set_phone().
2272
+     *
2273
+     * @since 1.0.19
2274
+     * @param  string $value phone.
2275
+     */
2276
+    public function set_user_phone( $value ) {
2277
+        $this->set_phone( $value );
2278
+    }
2279
+
2280
+    /**
2281
+     * Alias of self::set_phone().
2282
+     *
2283
+     * @since 1.0.19
2284
+     * @param  string $value phone.
2285
+     */
2286
+    public function set_customer_phone( $value ) {
2287
+        $this->set_phone( $value );
2288
+    }
2289
+
2290
+    /**
2291
+     * Alias of self::set_phone().
2292
+     *
2293
+     * @since 1.0.19
2294
+     * @param  string $value phone.
2295
+     */
2296
+    public function set_phone_number( $value ) {
2297
+        $this->set_phone( $value );
2278 2298
     }
2279 2299
 
2280 2300
     /**
2281
-	 * Alias of self::set_phone().
2282
-	 *
2283
-	 * @since 1.0.19
2284
-	 * @param  string $value phone.
2285
-	 */
2286
-	public function set_customer_phone( $value ) {
2287
-		$this->set_phone( $value );
2301
+     * Set the customer's email address.
2302
+     *
2303
+     * @since 1.0.19
2304
+     * @param  string $value email address.
2305
+     */
2306
+    public function set_email( $value ) {
2307
+        $this->set_prop( 'email', $value );
2288 2308
     }
2289 2309
 
2290 2310
     /**
2291
-	 * Alias of self::set_phone().
2292
-	 *
2293
-	 * @since 1.0.19
2294
-	 * @param  string $value phone.
2295
-	 */
2296
-	public function set_phone_number( $value ) {
2297
-		$this->set_phone( $value );
2311
+     * Alias of self::set_email().
2312
+     *
2313
+     * @since 1.0.19
2314
+     * @param  string $value email address.
2315
+     */
2316
+    public function set_user_email( $value ) {
2317
+        $this->set_email( $value );
2298 2318
     }
2299 2319
 
2300 2320
     /**
2301
-	 * Set the customer's email address.
2302
-	 *
2303
-	 * @since 1.0.19
2304
-	 * @param  string $value email address.
2305
-	 */
2306
-	public function set_email( $value ) {
2307
-		$this->set_prop( 'email', $value );
2321
+     * Alias of self::set_email().
2322
+     *
2323
+     * @since 1.0.19
2324
+     * @param  string $value email address.
2325
+     */
2326
+    public function set_email_address( $value ) {
2327
+        $this->set_email( $value );
2328
+    }
2329
+
2330
+    /**
2331
+     * Alias of self::set_email().
2332
+     *
2333
+     * @since 1.0.19
2334
+     * @param  string $value email address.
2335
+     */
2336
+    public function set_customer_email( $value ) {
2337
+        $this->set_email( $value );
2308 2338
     }
2309 2339
 
2310 2340
     /**
2311
-	 * Alias of self::set_email().
2312
-	 *
2313
-	 * @since 1.0.19
2314
-	 * @param  string $value email address.
2315
-	 */
2316
-	public function set_user_email( $value ) {
2317
-		$this->set_email( $value );
2341
+     * Set the customer's country.
2342
+     *
2343
+     * @since 1.0.19
2344
+     * @param  string $value country.
2345
+     */
2346
+    public function set_country( $value ) {
2347
+        $this->set_prop( 'country', $value );
2318 2348
     }
2319 2349
 
2320 2350
     /**
2321
-	 * Alias of self::set_email().
2322
-	 *
2323
-	 * @since 1.0.19
2324
-	 * @param  string $value email address.
2325
-	 */
2326
-	public function set_email_address( $value ) {
2327
-		$this->set_email( $value );
2351
+     * Alias of self::set_country().
2352
+     *
2353
+     * @since 1.0.19
2354
+     * @param  string $value country.
2355
+     */
2356
+    public function set_user_country( $value ) {
2357
+        $this->set_country( $value );
2328 2358
     }
2329 2359
 
2330 2360
     /**
2331
-	 * Alias of self::set_email().
2332
-	 *
2333
-	 * @since 1.0.19
2334
-	 * @param  string $value email address.
2335
-	 */
2336
-	public function set_customer_email( $value ) {
2337
-		$this->set_email( $value );
2361
+     * Alias of self::set_country().
2362
+     *
2363
+     * @since 1.0.19
2364
+     * @param  string $value country.
2365
+     */
2366
+    public function set_customer_country( $value ) {
2367
+        $this->set_country( $value );
2338 2368
     }
2339 2369
 
2340 2370
     /**
2341
-	 * Set the customer's country.
2342
-	 *
2343
-	 * @since 1.0.19
2344
-	 * @param  string $value country.
2345
-	 */
2346
-	public function set_country( $value ) {
2347
-		$this->set_prop( 'country', $value );
2371
+     * Set the customer's state.
2372
+     *
2373
+     * @since 1.0.19
2374
+     * @param  string $value state.
2375
+     */
2376
+    public function set_state( $value ) {
2377
+        $this->set_prop( 'state', $value );
2348 2378
     }
2349 2379
 
2350 2380
     /**
2351
-	 * Alias of self::set_country().
2352
-	 *
2353
-	 * @since 1.0.19
2354
-	 * @param  string $value country.
2355
-	 */
2356
-	public function set_user_country( $value ) {
2357
-		$this->set_country( $value );
2381
+     * Alias of self::set_state().
2382
+     *
2383
+     * @since 1.0.19
2384
+     * @param  string $value state.
2385
+     */
2386
+    public function set_user_state( $value ) {
2387
+        $this->set_state( $value );
2358 2388
     }
2359 2389
 
2360 2390
     /**
2361
-	 * Alias of self::set_country().
2362
-	 *
2363
-	 * @since 1.0.19
2364
-	 * @param  string $value country.
2365
-	 */
2366
-	public function set_customer_country( $value ) {
2367
-		$this->set_country( $value );
2391
+     * Alias of self::set_state().
2392
+     *
2393
+     * @since 1.0.19
2394
+     * @param  string $value state.
2395
+     */
2396
+    public function set_customer_state( $value ) {
2397
+        $this->set_state( $value );
2368 2398
     }
2369 2399
 
2370 2400
     /**
2371
-	 * Set the customer's state.
2372
-	 *
2373
-	 * @since 1.0.19
2374
-	 * @param  string $value state.
2375
-	 */
2376
-	public function set_state( $value ) {
2377
-		$this->set_prop( 'state', $value );
2401
+     * Set the customer's city.
2402
+     *
2403
+     * @since 1.0.19
2404
+     * @param  string $value city.
2405
+     */
2406
+    public function set_city( $value ) {
2407
+        $this->set_prop( 'city', $value );
2378 2408
     }
2379 2409
 
2380 2410
     /**
2381
-	 * Alias of self::set_state().
2382
-	 *
2383
-	 * @since 1.0.19
2384
-	 * @param  string $value state.
2385
-	 */
2386
-	public function set_user_state( $value ) {
2387
-		$this->set_state( $value );
2411
+     * Alias of self::set_city().
2412
+     *
2413
+     * @since 1.0.19
2414
+     * @param  string $value city.
2415
+     */
2416
+    public function set_user_city( $value ) {
2417
+        $this->set_city( $value );
2388 2418
     }
2389 2419
 
2390 2420
     /**
2391
-	 * Alias of self::set_state().
2392
-	 *
2393
-	 * @since 1.0.19
2394
-	 * @param  string $value state.
2395
-	 */
2396
-	public function set_customer_state( $value ) {
2397
-		$this->set_state( $value );
2421
+     * Alias of self::set_city().
2422
+     *
2423
+     * @since 1.0.19
2424
+     * @param  string $value city.
2425
+     */
2426
+    public function set_customer_city( $value ) {
2427
+        $this->set_city( $value );
2398 2428
     }
2399 2429
 
2400 2430
     /**
2401
-	 * Set the customer's city.
2402
-	 *
2403
-	 * @since 1.0.19
2404
-	 * @param  string $value city.
2405
-	 */
2406
-	public function set_city( $value ) {
2407
-		$this->set_prop( 'city', $value );
2431
+     * Set the customer's zip code.
2432
+     *
2433
+     * @since 1.0.19
2434
+     * @param  string $value zip.
2435
+     */
2436
+    public function set_zip( $value ) {
2437
+        $this->set_prop( 'zip', $value );
2408 2438
     }
2409 2439
 
2410 2440
     /**
2411
-	 * Alias of self::set_city().
2412
-	 *
2413
-	 * @since 1.0.19
2414
-	 * @param  string $value city.
2415
-	 */
2416
-	public function set_user_city( $value ) {
2417
-		$this->set_city( $value );
2441
+     * Alias of self::set_zip().
2442
+     *
2443
+     * @since 1.0.19
2444
+     * @param  string $value zip.
2445
+     */
2446
+    public function set_user_zip( $value ) {
2447
+        $this->set_zip( $value );
2418 2448
     }
2419 2449
 
2420 2450
     /**
2421
-	 * Alias of self::set_city().
2422
-	 *
2423
-	 * @since 1.0.19
2424
-	 * @param  string $value city.
2425
-	 */
2426
-	public function set_customer_city( $value ) {
2427
-		$this->set_city( $value );
2451
+     * Alias of self::set_zip().
2452
+     *
2453
+     * @since 1.0.19
2454
+     * @param  string $value zip.
2455
+     */
2456
+    public function set_customer_zip( $value ) {
2457
+        $this->set_zip( $value );
2428 2458
     }
2429 2459
 
2430 2460
     /**
2431
-	 * Set the customer's zip code.
2432
-	 *
2433
-	 * @since 1.0.19
2434
-	 * @param  string $value zip.
2435
-	 */
2436
-	public function set_zip( $value ) {
2437
-		$this->set_prop( 'zip', $value );
2461
+     * Set the customer's company.
2462
+     *
2463
+     * @since 1.0.19
2464
+     * @param  string $value company.
2465
+     */
2466
+    public function set_company( $value ) {
2467
+        $this->set_prop( 'company', $value );
2438 2468
     }
2439 2469
 
2440 2470
     /**
2441
-	 * Alias of self::set_zip().
2442
-	 *
2443
-	 * @since 1.0.19
2444
-	 * @param  string $value zip.
2445
-	 */
2446
-	public function set_user_zip( $value ) {
2447
-		$this->set_zip( $value );
2471
+     * Alias of self::set_company().
2472
+     *
2473
+     * @since 1.0.19
2474
+     * @param  string $value company.
2475
+     */
2476
+    public function set_user_company( $value ) {
2477
+        $this->set_company( $value );
2448 2478
     }
2449 2479
 
2450 2480
     /**
2451
-	 * Alias of self::set_zip().
2452
-	 *
2453
-	 * @since 1.0.19
2454
-	 * @param  string $value zip.
2455
-	 */
2456
-	public function set_customer_zip( $value ) {
2457
-		$this->set_zip( $value );
2481
+     * Alias of self::set_company().
2482
+     *
2483
+     * @since 1.0.19
2484
+     * @param  string $value company.
2485
+     */
2486
+    public function set_customer_company( $value ) {
2487
+        $this->set_company( $value );
2458 2488
     }
2459 2489
 
2460 2490
     /**
2461
-	 * Set the customer's company.
2462
-	 *
2463
-	 * @since 1.0.19
2464
-	 * @param  string $value company.
2465
-	 */
2466
-	public function set_company( $value ) {
2467
-		$this->set_prop( 'company', $value );
2491
+     * Set the customer's var number.
2492
+     *
2493
+     * @since 1.0.19
2494
+     * @param  string $value var number.
2495
+     */
2496
+    public function set_vat_number( $value ) {
2497
+        $this->set_prop( 'vat_number', $value );
2468 2498
     }
2469 2499
 
2470 2500
     /**
2471
-	 * Alias of self::set_company().
2472
-	 *
2473
-	 * @since 1.0.19
2474
-	 * @param  string $value company.
2475
-	 */
2476
-	public function set_user_company( $value ) {
2477
-		$this->set_company( $value );
2501
+     * Alias of self::set_vat_number().
2502
+     *
2503
+     * @since 1.0.19
2504
+     * @param  string $value var number.
2505
+     */
2506
+    public function set_user_vat_number( $value ) {
2507
+        $this->set_vat_number( $value );
2478 2508
     }
2479 2509
 
2480 2510
     /**
2481
-	 * Alias of self::set_company().
2482
-	 *
2483
-	 * @since 1.0.19
2484
-	 * @param  string $value company.
2485
-	 */
2486
-	public function set_customer_company( $value ) {
2487
-		$this->set_company( $value );
2511
+     * Alias of self::set_vat_number().
2512
+     *
2513
+     * @since 1.0.19
2514
+     * @param  string $value var number.
2515
+     */
2516
+    public function set_customer_vat_number( $value ) {
2517
+        $this->set_vat_number( $value );
2488 2518
     }
2489 2519
 
2490 2520
     /**
2491
-	 * Set the customer's var number.
2492
-	 *
2493
-	 * @since 1.0.19
2494
-	 * @param  string $value var number.
2495
-	 */
2496
-	public function set_vat_number( $value ) {
2497
-		$this->set_prop( 'vat_number', $value );
2521
+     * Set the customer's vat rate.
2522
+     *
2523
+     * @since 1.0.19
2524
+     * @param  string $value var rate.
2525
+     */
2526
+    public function set_vat_rate( $value ) {
2527
+        $this->set_prop( 'vat_rate', $value );
2498 2528
     }
2499 2529
 
2500 2530
     /**
2501
-	 * Alias of self::set_vat_number().
2502
-	 *
2503
-	 * @since 1.0.19
2504
-	 * @param  string $value var number.
2505
-	 */
2506
-	public function set_user_vat_number( $value ) {
2507
-		$this->set_vat_number( $value );
2531
+     * Alias of self::set_vat_rate().
2532
+     *
2533
+     * @since 1.0.19
2534
+     * @param  string $value var number.
2535
+     */
2536
+    public function set_user_vat_rate( $value ) {
2537
+        $this->set_vat_rate( $value );
2508 2538
     }
2509 2539
 
2510 2540
     /**
2511
-	 * Alias of self::set_vat_number().
2512
-	 *
2513
-	 * @since 1.0.19
2514
-	 * @param  string $value var number.
2515
-	 */
2516
-	public function set_customer_vat_number( $value ) {
2517
-		$this->set_vat_number( $value );
2541
+     * Alias of self::set_vat_rate().
2542
+     *
2543
+     * @since 1.0.19
2544
+     * @param  string $value var number.
2545
+     */
2546
+    public function set_customer_vat_rate( $value ) {
2547
+        $this->set_vat_rate( $value );
2518 2548
     }
2519 2549
 
2520 2550
     /**
2521
-	 * Set the customer's vat rate.
2522
-	 *
2523
-	 * @since 1.0.19
2524
-	 * @param  string $value var rate.
2525
-	 */
2526
-	public function set_vat_rate( $value ) {
2527
-		$this->set_prop( 'vat_rate', $value );
2551
+     * Set the customer's address.
2552
+     *
2553
+     * @since 1.0.19
2554
+     * @param  string $value address.
2555
+     */
2556
+    public function set_address( $value ) {
2557
+        $this->set_prop( 'address', $value );
2528 2558
     }
2529 2559
 
2530 2560
     /**
2531
-	 * Alias of self::set_vat_rate().
2532
-	 *
2533
-	 * @since 1.0.19
2534
-	 * @param  string $value var number.
2535
-	 */
2536
-	public function set_user_vat_rate( $value ) {
2537
-		$this->set_vat_rate( $value );
2561
+     * Alias of self::set_address().
2562
+     *
2563
+     * @since 1.0.19
2564
+     * @param  string $value address.
2565
+     */
2566
+    public function set_user_address( $value ) {
2567
+        $this->set_address( $value );
2538 2568
     }
2539 2569
 
2540 2570
     /**
2541
-	 * Alias of self::set_vat_rate().
2542
-	 *
2543
-	 * @since 1.0.19
2544
-	 * @param  string $value var number.
2545
-	 */
2546
-	public function set_customer_vat_rate( $value ) {
2547
-		$this->set_vat_rate( $value );
2571
+     * Alias of self::set_address().
2572
+     *
2573
+     * @since 1.0.19
2574
+     * @param  string $value address.
2575
+     */
2576
+    public function set_customer_address( $value ) {
2577
+        $this->set_address( $value );
2548 2578
     }
2549 2579
 
2550 2580
     /**
2551
-	 * Set the customer's address.
2552
-	 *
2553
-	 * @since 1.0.19
2554
-	 * @param  string $value address.
2555
-	 */
2556
-	public function set_address( $value ) {
2557
-		$this->set_prop( 'address', $value );
2581
+     * Set whether the customer has viewed the invoice or not.
2582
+     *
2583
+     * @since 1.0.19
2584
+     * @param  int|bool $value confirmed.
2585
+     */
2586
+    public function set_is_viewed( $value ) {
2587
+        $this->set_prop( 'is_viewed', $value );
2558 2588
     }
2559 2589
 
2560 2590
     /**
2561
-	 * Alias of self::set_address().
2562
-	 *
2563
-	 * @since 1.0.19
2564
-	 * @param  string $value address.
2565
-	 */
2566
-	public function set_user_address( $value ) {
2567
-		$this->set_address( $value );
2591
+     * Set extra email recipients.
2592
+     *
2593
+     * @since 1.0.19
2594
+     * @param  string $value email recipients.
2595
+     */
2596
+    public function set_email_cc( $value ) {
2597
+        $this->set_prop( 'email_cc', $value );
2568 2598
     }
2569 2599
 
2570 2600
     /**
2571
-	 * Alias of self::set_address().
2572
-	 *
2573
-	 * @since 1.0.19
2574
-	 * @param  string $value address.
2575
-	 */
2576
-	public function set_customer_address( $value ) {
2577
-		$this->set_address( $value );
2601
+     * Set the invoice template.
2602
+     *
2603
+     * @since 1.0.19
2604
+     * @param  string $value email recipients.
2605
+     */
2606
+    public function set_template( $value ) {
2607
+        if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) {
2608
+            $this->set_prop( 'template', $value );
2609
+        }
2578 2610
     }
2579 2611
 
2580 2612
     /**
2581
-	 * Set whether the customer has viewed the invoice or not.
2582
-	 *
2583
-	 * @since 1.0.19
2584
-	 * @param  int|bool $value confirmed.
2585
-	 */
2586
-	public function set_is_viewed( $value ) {
2587
-		$this->set_prop( 'is_viewed', $value );
2588
-	}
2589
-
2590
-	/**
2591
-	 * Set extra email recipients.
2592
-	 *
2593
-	 * @since 1.0.19
2594
-	 * @param  string $value email recipients.
2595
-	 */
2596
-	public function set_email_cc( $value ) {
2597
-		$this->set_prop( 'email_cc', $value );
2598
-	}
2599
-
2600
-	/**
2601
-	 * Set the invoice template.
2602
-	 *
2603
-	 * @since 1.0.19
2604
-	 * @param  string $value email recipients.
2605
-	 */
2606
-	public function set_template( $value ) {
2607
-		if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) {
2608
-			$this->set_prop( 'template', $value );
2609
-		}
2610
-	}
2611
-
2612
-	/**
2613
-	 * Set the customer's address confirmed status.
2614
-	 *
2615
-	 * @since 1.0.19
2616
-	 * @param  int|bool $value confirmed.
2617
-	 */
2618
-	public function set_address_confirmed( $value ) {
2619
-		$this->set_prop( 'address_confirmed', $value );
2613
+     * Set the customer's address confirmed status.
2614
+     *
2615
+     * @since 1.0.19
2616
+     * @param  int|bool $value confirmed.
2617
+     */
2618
+    public function set_address_confirmed( $value ) {
2619
+        $this->set_prop( 'address_confirmed', $value );
2620 2620
     }
2621 2621
 
2622 2622
     /**
2623
-	 * Alias of self::set_address_confirmed().
2624
-	 *
2625
-	 * @since 1.0.19
2626
-	 * @param  int|bool $value confirmed.
2627
-	 */
2628
-	public function set_user_address_confirmed( $value ) {
2629
-		$this->set_address_confirmed( $value );
2623
+     * Alias of self::set_address_confirmed().
2624
+     *
2625
+     * @since 1.0.19
2626
+     * @param  int|bool $value confirmed.
2627
+     */
2628
+    public function set_user_address_confirmed( $value ) {
2629
+        $this->set_address_confirmed( $value );
2630 2630
     }
2631 2631
 
2632 2632
     /**
2633
-	 * Alias of self::set_address_confirmed().
2634
-	 *
2635
-	 * @since 1.0.19
2636
-	 * @param  int|bool $value confirmed.
2637
-	 */
2638
-	public function set_customer_address_confirmed( $value ) {
2639
-		$this->set_address_confirmed( $value );
2633
+     * Alias of self::set_address_confirmed().
2634
+     *
2635
+     * @since 1.0.19
2636
+     * @param  int|bool $value confirmed.
2637
+     */
2638
+    public function set_customer_address_confirmed( $value ) {
2639
+        $this->set_address_confirmed( $value );
2640 2640
     }
2641 2641
 
2642 2642
     /**
2643
-	 * Set the invoice sub total.
2644
-	 *
2645
-	 * @since 1.0.19
2646
-	 * @param  float $value sub total.
2647
-	 */
2648
-	public function set_subtotal( $value ) {
2649
-		$this->set_prop( 'subtotal', $value );
2643
+     * Set the invoice sub total.
2644
+     *
2645
+     * @since 1.0.19
2646
+     * @param  float $value sub total.
2647
+     */
2648
+    public function set_subtotal( $value ) {
2649
+        $this->set_prop( 'subtotal', $value );
2650 2650
     }
2651 2651
 
2652 2652
     /**
2653
-	 * Set the invoice discount amount.
2654
-	 *
2655
-	 * @since 1.0.19
2656
-	 * @param  float $value discount total.
2657
-	 */
2658
-	public function set_total_discount( $value ) {
2659
-		$this->set_prop( 'total_discount', $value );
2653
+     * Set the invoice discount amount.
2654
+     *
2655
+     * @since 1.0.19
2656
+     * @param  float $value discount total.
2657
+     */
2658
+    public function set_total_discount( $value ) {
2659
+        $this->set_prop( 'total_discount', $value );
2660 2660
     }
2661 2661
 
2662 2662
     /**
2663
-	 * Alias of self::set_total_discount().
2664
-	 *
2665
-	 * @since 1.0.19
2666
-	 * @param  float $value discount total.
2667
-	 */
2668
-	public function set_discount( $value ) {
2669
-		$this->set_total_discount( $value );
2663
+     * Alias of self::set_total_discount().
2664
+     *
2665
+     * @since 1.0.19
2666
+     * @param  float $value discount total.
2667
+     */
2668
+    public function set_discount( $value ) {
2669
+        $this->set_total_discount( $value );
2670 2670
     }
2671 2671
 
2672 2672
     /**
2673
-	 * Set the invoice tax amount.
2674
-	 *
2675
-	 * @since 1.0.19
2676
-	 * @param  float $value tax total.
2677
-	 */
2678
-	public function set_total_tax( $value ) {
2679
-		$this->set_prop( 'total_tax', $value );
2673
+     * Set the invoice tax amount.
2674
+     *
2675
+     * @since 1.0.19
2676
+     * @param  float $value tax total.
2677
+     */
2678
+    public function set_total_tax( $value ) {
2679
+        $this->set_prop( 'total_tax', $value );
2680 2680
     }
2681 2681
 
2682 2682
     /**
2683
-	 * Alias of self::set_total_tax().
2684
-	 *
2685
-	 * @since 1.0.19
2686
-	 * @param  float $value tax total.
2687
-	 */
2688
-	public function set_tax_total( $value ) {
2689
-		$this->set_total_tax( $value );
2683
+     * Alias of self::set_total_tax().
2684
+     *
2685
+     * @since 1.0.19
2686
+     * @param  float $value tax total.
2687
+     */
2688
+    public function set_tax_total( $value ) {
2689
+        $this->set_total_tax( $value );
2690 2690
     }
2691 2691
 
2692 2692
     /**
2693
-	 * Set the invoice fees amount.
2694
-	 *
2695
-	 * @since 1.0.19
2696
-	 * @param  float $value fees total.
2697
-	 */
2698
-	public function set_total_fees( $value ) {
2699
-		$this->set_prop( 'total_fees', $value );
2693
+     * Set the invoice fees amount.
2694
+     *
2695
+     * @since 1.0.19
2696
+     * @param  float $value fees total.
2697
+     */
2698
+    public function set_total_fees( $value ) {
2699
+        $this->set_prop( 'total_fees', $value );
2700 2700
     }
2701 2701
 
2702 2702
     /**
2703
-	 * Alias of self::set_total_fees().
2704
-	 *
2705
-	 * @since 1.0.19
2706
-	 * @param  float $value fees total.
2707
-	 */
2708
-	public function set_fees_total( $value ) {
2709
-		$this->set_total_fees( $value );
2703
+     * Alias of self::set_total_fees().
2704
+     *
2705
+     * @since 1.0.19
2706
+     * @param  float $value fees total.
2707
+     */
2708
+    public function set_fees_total( $value ) {
2709
+        $this->set_total_fees( $value );
2710 2710
     }
2711 2711
 
2712 2712
     /**
2713
-	 * Set the invoice fees.
2714
-	 *
2715
-	 * @since 1.0.19
2716
-	 * @param  array $value fees.
2717
-	 */
2718
-	public function set_fees( $value ) {
2713
+     * Set the invoice fees.
2714
+     *
2715
+     * @since 1.0.19
2716
+     * @param  array $value fees.
2717
+     */
2718
+    public function set_fees( $value ) {
2719 2719
 
2720 2720
         $this->set_prop( 'fees', array() );
2721 2721
 
@@ -2733,23 +2733,23 @@  discard block
 block discarded – undo
2733 2733
     }
2734 2734
 
2735 2735
     /**
2736
-	 * Set the invoice taxes.
2737
-	 *
2738
-	 * @since 1.0.19
2739
-	 * @param  array $value taxes.
2740
-	 */
2741
-	public function set_taxes( $value ) {
2742
-		$this->set_prop( 'taxes', $value );
2736
+     * Set the invoice taxes.
2737
+     *
2738
+     * @since 1.0.19
2739
+     * @param  array $value taxes.
2740
+     */
2741
+    public function set_taxes( $value ) {
2742
+        $this->set_prop( 'taxes', $value );
2743 2743
     }
2744 2744
 
2745 2745
     /**
2746
-	 * Set the invoice discounts.
2747
-	 *
2748
-	 * @since 1.0.19
2749
-	 * @param  array $value discounts.
2750
-	 */
2751
-	public function set_discounts( $value ) {
2752
-		$this->set_prop( 'discounts', array() );
2746
+     * Set the invoice discounts.
2747
+     *
2748
+     * @since 1.0.19
2749
+     * @param  array $value discounts.
2750
+     */
2751
+    public function set_discounts( $value ) {
2752
+        $this->set_prop( 'discounts', array() );
2753 2753
 
2754 2754
         // Ensure that we have an array.
2755 2755
         if ( ! is_array( $value ) ) {
@@ -2764,12 +2764,12 @@  discard block
 block discarded – undo
2764 2764
     }
2765 2765
 
2766 2766
     /**
2767
-	 * Set the invoice items.
2768
-	 *
2769
-	 * @since 1.0.19
2770
-	 * @param  GetPaid_Form_Item[] $value items.
2771
-	 */
2772
-	public function set_items( $value ) {
2767
+     * Set the invoice items.
2768
+     *
2769
+     * @since 1.0.19
2770
+     * @param  GetPaid_Form_Item[] $value items.
2771
+     */
2772
+    public function set_items( $value ) {
2773 2773
 
2774 2774
         // Remove existing items.
2775 2775
         $this->set_prop( 'items', array() );
@@ -2786,85 +2786,85 @@  discard block
 block discarded – undo
2786 2786
     }
2787 2787
 
2788 2788
     /**
2789
-	 * Set the payment form.
2790
-	 *
2791
-	 * @since 1.0.19
2792
-	 * @param  int $value payment form.
2793
-	 */
2794
-	public function set_payment_form( $value ) {
2795
-		$this->set_prop( 'payment_form', $value );
2789
+     * Set the payment form.
2790
+     *
2791
+     * @since 1.0.19
2792
+     * @param  int $value payment form.
2793
+     */
2794
+    public function set_payment_form( $value ) {
2795
+        $this->set_prop( 'payment_form', $value );
2796 2796
     }
2797 2797
 
2798 2798
     /**
2799
-	 * Set the submission id.
2800
-	 *
2801
-	 * @since 1.0.19
2802
-	 * @param  string $value submission id.
2803
-	 */
2804
-	public function set_submission_id( $value ) {
2805
-		$this->set_prop( 'submission_id', $value );
2799
+     * Set the submission id.
2800
+     *
2801
+     * @since 1.0.19
2802
+     * @param  string $value submission id.
2803
+     */
2804
+    public function set_submission_id( $value ) {
2805
+        $this->set_prop( 'submission_id', $value );
2806 2806
     }
2807 2807
 
2808 2808
     /**
2809
-	 * Set the discount code.
2810
-	 *
2811
-	 * @since 1.0.19
2812
-	 * @param  string $value discount code.
2813
-	 */
2814
-	public function set_discount_code( $value ) {
2815
-		$this->set_prop( 'discount_code', $value );
2809
+     * Set the discount code.
2810
+     *
2811
+     * @since 1.0.19
2812
+     * @param  string $value discount code.
2813
+     */
2814
+    public function set_discount_code( $value ) {
2815
+        $this->set_prop( 'discount_code', $value );
2816 2816
     }
2817 2817
 
2818 2818
     /**
2819
-	 * Set the gateway.
2820
-	 *
2821
-	 * @since 1.0.19
2822
-	 * @param  string $value gateway.
2823
-	 */
2824
-	public function set_gateway( $value ) {
2825
-		$this->set_prop( 'gateway', $value );
2819
+     * Set the gateway.
2820
+     *
2821
+     * @since 1.0.19
2822
+     * @param  string $value gateway.
2823
+     */
2824
+    public function set_gateway( $value ) {
2825
+        $this->set_prop( 'gateway', $value );
2826 2826
     }
2827 2827
 
2828 2828
     /**
2829
-	 * Set the transaction id.
2830
-	 *
2831
-	 * @since 1.0.19
2832
-	 * @param  string $value transaction id.
2833
-	 */
2834
-	public function set_transaction_id( $value ) {
2835
-		if ( ! empty( $value ) ) {
2836
-			$this->set_prop( 'transaction_id', $value );
2837
-		}
2829
+     * Set the transaction id.
2830
+     *
2831
+     * @since 1.0.19
2832
+     * @param  string $value transaction id.
2833
+     */
2834
+    public function set_transaction_id( $value ) {
2835
+        if ( ! empty( $value ) ) {
2836
+            $this->set_prop( 'transaction_id', $value );
2837
+        }
2838 2838
     }
2839 2839
 
2840 2840
     /**
2841
-	 * Set the currency id.
2842
-	 *
2843
-	 * @since 1.0.19
2844
-	 * @param  string $value currency id.
2845
-	 */
2846
-	public function set_currency( $value ) {
2847
-		$this->set_prop( 'currency', $value );
2841
+     * Set the currency id.
2842
+     *
2843
+     * @since 1.0.19
2844
+     * @param  string $value currency id.
2845
+     */
2846
+    public function set_currency( $value ) {
2847
+        $this->set_prop( 'currency', $value );
2848 2848
     }
2849 2849
 
2850
-	/**
2851
-	 * Set whether to disable taxes.
2852
-	 *
2853
-	 * @since 1.0.19
2854
-	 * @param  bool $value value.
2855
-	 */
2856
-	public function set_disable_taxes( $value ) {
2857
-		$this->set_prop( 'disable_taxes', (bool) $value );
2858
-	}
2850
+    /**
2851
+     * Set whether to disable taxes.
2852
+     *
2853
+     * @since 1.0.19
2854
+     * @param  bool $value value.
2855
+     */
2856
+    public function set_disable_taxes( $value ) {
2857
+        $this->set_prop( 'disable_taxes', (bool) $value );
2858
+    }
2859 2859
 
2860 2860
     /**
2861
-	 * Set the subscription id.
2862
-	 *
2863
-	 * @since 1.0.19
2864
-	 * @param  string $value subscription id.
2865
-	 */
2866
-	public function set_subscription_id( $value ) {
2867
-		$this->set_prop( 'subscription_id', $value );
2861
+     * Set the subscription id.
2862
+     *
2863
+     * @since 1.0.19
2864
+     * @param  string $value subscription id.
2865
+     */
2866
+    public function set_subscription_id( $value ) {
2867
+        $this->set_prop( 'subscription_id', $value );
2868 2868
     }
2869 2869
 
2870 2870
     /*
@@ -2903,12 +2903,12 @@  discard block
 block discarded – undo
2903 2903
      */
2904 2904
     public function is_taxable() {
2905 2905
         return ! $this->get_disable_taxes();
2906
-	}
2906
+    }
2907 2907
 
2908
-	/**
2909
-	 * @deprecated
2910
-	 */
2911
-	public function has_vat() {
2908
+    /**
2909
+     * @deprecated
2910
+     */
2911
+    public function has_vat() {
2912 2912
         global $wpinv_euvat, $wpi_country;
2913 2913
 
2914 2914
         $requires_vat = false;
@@ -2919,17 +2919,17 @@  discard block
 block discarded – undo
2919 2919
         }
2920 2920
 
2921 2921
         return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2922
-	}
2922
+    }
2923 2923
 
2924
-	/**
2925
-	 * Checks to see if the invoice requires payment.
2926
-	 */
2927
-	public function is_free() {
2924
+    /**
2925
+     * Checks to see if the invoice requires payment.
2926
+     */
2927
+    public function is_free() {
2928 2928
         $is_free = ( (float) wpinv_round_amount( $this->get_initial_total() ) == 0 );
2929 2929
 
2930
-		if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) {
2931
-			$is_free = false;
2932
-		}
2930
+        if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) {
2931
+            $is_free = false;
2932
+        }
2933 2933
 
2934 2934
         return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
2935 2935
     }
@@ -2940,46 +2940,46 @@  discard block
 block discarded – undo
2940 2940
     public function is_paid() {
2941 2941
         $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) );
2942 2942
         return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this );
2943
-	}
2943
+    }
2944 2944
 
2945
-	/**
2945
+    /**
2946 2946
      * Checks if the invoice needs payment.
2947 2947
      */
2948
-	public function needs_payment() {
2949
-		$needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free();
2948
+    public function needs_payment() {
2949
+        $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free();
2950 2950
         return apply_filters( 'wpinv_needs_payment', $needs_payment, $this );
2951 2951
     }
2952 2952
 
2953
-	/**
2953
+    /**
2954 2954
      * Checks if the invoice is refunded.
2955 2955
      */
2956
-	public function is_refunded() {
2956
+    public function is_refunded() {
2957 2957
         $is_refunded = $this->has_status( 'wpi-refunded' );
2958 2958
         return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this );
2959
-	}
2959
+    }
2960 2960
 
2961
-	/**
2961
+    /**
2962 2962
      * Checks if the invoice is held.
2963 2963
      */
2964
-	public function is_held() {
2964
+    public function is_held() {
2965 2965
         $is_held = $this->has_status( 'wpi-onhold' );
2966 2966
         return apply_filters( 'wpinv_invoice_is_held', $is_held, $this );
2967
-	}
2967
+    }
2968 2968
 
2969
-	/**
2969
+    /**
2970 2970
      * Checks if the invoice is due.
2971 2971
      */
2972
-	public function is_due() {
2973
-		$due_date = $this->get_due_date();
2974
-		return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date );
2975
-	}
2972
+    public function is_due() {
2973
+        $due_date = $this->get_due_date();
2974
+        return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date );
2975
+    }
2976 2976
 
2977
-	/**
2977
+    /**
2978 2978
      * Checks if the invoice is draft.
2979 2979
      */
2980
-	public function is_draft() {
2980
+    public function is_draft() {
2981 2981
         return $this->has_status( 'draft, auto-draft' );
2982
-	}
2982
+    }
2983 2983
 
2984 2984
     /**
2985 2985
      * Checks if the invoice has a given status.
@@ -2987,9 +2987,9 @@  discard block
 block discarded – undo
2987 2987
     public function has_status( $status ) {
2988 2988
         $status = wpinv_parse_list( $status );
2989 2989
         return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status );
2990
-	}
2990
+    }
2991 2991
 
2992
-	/**
2992
+    /**
2993 2993
      * Checks if the invoice is of a given type.
2994 2994
      */
2995 2995
     public function is_type( $type ) {
@@ -3012,25 +3012,25 @@  discard block
 block discarded – undo
3012 3012
      */
3013 3013
     public function has_free_trial() {
3014 3014
         return $this->is_recurring() && 0 == $this->get_initial_total();
3015
-	}
3015
+    }
3016 3016
 
3017
-	/**
3017
+    /**
3018 3018
      * @deprecated
3019 3019
      */
3020 3020
     public function is_free_trial() {
3021 3021
         $this->has_free_trial();
3022 3022
     }
3023 3023
 
3024
-	/**
3024
+    /**
3025 3025
      * Check if the initial payment if 0.
3026 3026
      *
3027 3027
      */
3028
-	public function is_initial_free() {
3028
+    public function is_initial_free() {
3029 3029
         $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 );
3030 3030
         return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this );
3031 3031
     }
3032 3032
 	
3033
-	/**
3033
+    /**
3034 3034
      * Check if the recurring item has a free trial.
3035 3035
      *
3036 3036
      */
@@ -3043,21 +3043,21 @@  discard block
 block discarded – undo
3043 3043
 
3044 3044
         $item = $this->get_recurring( true );
3045 3045
         return $item->has_free_trial();
3046
-	}
3046
+    }
3047 3047
 
3048
-	/**
3048
+    /**
3049 3049
      * Check if the free trial is a result of a discount.
3050 3050
      */
3051 3051
     public function is_free_trial_from_discount() {
3052
-		return $this->has_free_trial() && ! $this->item_has_free_trial();
3053
-	}
3052
+        return $this->has_free_trial() && ! $this->item_has_free_trial();
3053
+    }
3054 3054
 	
3055
-	/**
3055
+    /**
3056 3056
      * @deprecated
3057 3057
      */
3058 3058
     public function discount_first_payment_only() {
3059 3059
 
3060
-		$discount_code = $this->get_discount_code();
3060
+        $discount_code = $this->get_discount_code();
3061 3061
         if ( empty( $this->discount_code ) || ! $this->is_recurring() ) {
3062 3062
             return true;
3063 3063
         }
@@ -3088,28 +3088,28 @@  discard block
 block discarded – undo
3088 3088
      */
3089 3089
     public function add_item( $item ) {
3090 3090
 
3091
-		if ( is_array( $item ) ) {
3092
-			$item = $this->process_array_item( $item );
3093
-		}
3091
+        if ( is_array( $item ) ) {
3092
+            $item = $this->process_array_item( $item );
3093
+        }
3094 3094
 
3095
-		if ( is_numeric( $item ) ) {
3096
-			$item = new GetPaid_Form_Item( $item );
3097
-		}
3095
+        if ( is_numeric( $item ) ) {
3096
+            $item = new GetPaid_Form_Item( $item );
3097
+        }
3098 3098
 
3099 3099
         // Make sure that it is available for purchase.
3100
-		if ( $item->get_id() > 0 && ! $item->can_purchase() ) {
3101
-			return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) );
3100
+        if ( $item->get_id() > 0 && ! $item->can_purchase() ) {
3101
+            return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) );
3102 3102
         }
3103 3103
 
3104 3104
         // Do we have a recurring item?
3105
-		if ( $item->is_recurring() ) {
3105
+        if ( $item->is_recurring() ) {
3106 3106
 
3107
-			// An invoice can only contain one recurring item.
3108
-			if ( ! empty( $this->recurring_item  && $this->recurring_item != (int) $item->get_id() ) ) {
3109
-				return new WP_Error( 'recurring_item', __( 'An invoice can only contain one recurring item', 'invoicing' ) );
3110
-			}
3107
+            // An invoice can only contain one recurring item.
3108
+            if ( ! empty( $this->recurring_item  && $this->recurring_item != (int) $item->get_id() ) ) {
3109
+                return new WP_Error( 'recurring_item', __( 'An invoice can only contain one recurring item', 'invoicing' ) );
3110
+            }
3111 3111
 
3112
-			$this->recurring_item = $item->get_id();
3112
+            $this->recurring_item = $item->get_id();
3113 3113
         }
3114 3114
 
3115 3115
         // Invoice id.
@@ -3120,60 +3120,60 @@  discard block
 block discarded – undo
3120 3120
         $items[ (int) $item->get_id() ] = $item;
3121 3121
 
3122 3122
         $this->set_prop( 'items', $items );
3123
-		return true;
3124
-	}
3123
+        return true;
3124
+    }
3125 3125
 	
3126
-	/**
3127
-	 * Converts an array to an item.
3128
-	 *
3129
-	 * @since 1.0.19
3130
-	 * @return GetPaid_Form_Item
3131
-	 */
3132
-	protected function process_array_item( $array ) {
3133
-
3134
-		$item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0;
3135
-		$item    = new GetPaid_Form_Item( $item_id );
3136
-
3137
-		// Set item data.
3138
-		foreach( array( 'name', 'price', 'description' ) as $key ) {
3139
-			if ( isset( $array[ "item_$key" ] ) ) {
3140
-				$method = "set_$key";
3141
-				$item->$method( $array[ "item_$key" ] );
3142
-			}
3143
-		}
3144
-
3145
-		if ( isset( $array['quantity'] ) ) {
3146
-			$item->set_quantity( $array['quantity'] );
3147
-		}
3148
-
3149
-		// Set item meta.
3150
-		if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) {
3151
-			$item->set_item_meta( $array['meta'] );
3152
-		}
3153
-
3154
-		return $item;
3155
-
3156
-	}
3157
-
3158
-    /**
3159
-	 * Retrieves a specific item.
3160
-	 *
3161
-	 * @since 1.0.19
3162
-	 */
3163
-	public function get_item( $item_id ) {
3164
-		$items   = $this->get_items();
3165
-		$item_id = (int) $item_id;
3166
-		return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null;
3167
-    }
3168
-
3169
-    /**
3170
-	 * Removes a specific item.
3171
-	 *
3172
-	 * @since 1.0.19
3173
-	 */
3174
-	public function remove_item( $item_id ) {
3175
-		$items   = $this->get_items();
3176
-		$item_id = (int) $item_id;
3126
+    /**
3127
+     * Converts an array to an item.
3128
+     *
3129
+     * @since 1.0.19
3130
+     * @return GetPaid_Form_Item
3131
+     */
3132
+    protected function process_array_item( $array ) {
3133
+
3134
+        $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0;
3135
+        $item    = new GetPaid_Form_Item( $item_id );
3136
+
3137
+        // Set item data.
3138
+        foreach( array( 'name', 'price', 'description' ) as $key ) {
3139
+            if ( isset( $array[ "item_$key" ] ) ) {
3140
+                $method = "set_$key";
3141
+                $item->$method( $array[ "item_$key" ] );
3142
+            }
3143
+        }
3144
+
3145
+        if ( isset( $array['quantity'] ) ) {
3146
+            $item->set_quantity( $array['quantity'] );
3147
+        }
3148
+
3149
+        // Set item meta.
3150
+        if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) {
3151
+            $item->set_item_meta( $array['meta'] );
3152
+        }
3153
+
3154
+        return $item;
3155
+
3156
+    }
3157
+
3158
+    /**
3159
+     * Retrieves a specific item.
3160
+     *
3161
+     * @since 1.0.19
3162
+     */
3163
+    public function get_item( $item_id ) {
3164
+        $items   = $this->get_items();
3165
+        $item_id = (int) $item_id;
3166
+        return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null;
3167
+    }
3168
+
3169
+    /**
3170
+     * Removes a specific item.
3171
+     *
3172
+     * @since 1.0.19
3173
+     */
3174
+    public function remove_item( $item_id ) {
3175
+        $items   = $this->get_items();
3176
+        $item_id = (int) $item_id;
3177 3177
 
3178 3178
         if ( $item_id == $this->recurring_item ) {
3179 3179
             $this->recurring_item = null;
@@ -3200,38 +3200,38 @@  discard block
 block discarded – undo
3200 3200
         if ( isset( $fees[ $fee ] ) && isset( $fees[ $fee ]['amount'] ) ) {
3201 3201
 
3202 3202
             $amount = $fees[ $fee ]['amount'] += $amount;
3203
-			$fees[ $fee ] = array(
3204
-				'amount'    => $amount,
3203
+            $fees[ $fee ] = array(
3204
+                'amount'    => $amount,
3205 3205
                 'recurring' => (bool) $recurring,
3206 3206
             );
3207 3207
 
3208
-		} else {
3209
-			$fees[ $fee ] = array(
3208
+        } else {
3209
+            $fees[ $fee ] = array(
3210 3210
                 'amount'    => $amount,
3211 3211
                 'recurring' => (bool) $recurring,
3212 3212
             );
3213
-		}
3213
+        }
3214 3214
 
3215 3215
         $this->set_prop( 'fees', $fee );
3216 3216
 
3217 3217
     }
3218 3218
 
3219 3219
     /**
3220
-	 * Retrieves a specific fee.
3221
-	 *
3222
-	 * @since 1.0.19
3223
-	 */
3224
-	public function get_fee( $fee ) {
3220
+     * Retrieves a specific fee.
3221
+     *
3222
+     * @since 1.0.19
3223
+     */
3224
+    public function get_fee( $fee ) {
3225 3225
         $fees = $this->get_fees();
3226
-		return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null;
3226
+        return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null;
3227 3227
     }
3228 3228
 
3229 3229
     /**
3230
-	 * Removes a specific fee.
3231
-	 *
3232
-	 * @since 1.0.19
3233
-	 */
3234
-	public function remove_fee( $fee ) {
3230
+     * Removes a specific fee.
3231
+     *
3232
+     * @since 1.0.19
3233
+     */
3234
+    public function remove_fee( $fee ) {
3235 3235
         $fees = $this->get_fees();
3236 3236
         if ( isset( $fees[ $fee ] ) ) {
3237 3237
             unset( $fees[ $fee ] );
@@ -3254,44 +3254,44 @@  discard block
 block discarded – undo
3254 3254
         if ( isset( $discounts[ $discount ] ) && isset( $discounts[ $discount ]['amount'] ) ) {
3255 3255
 
3256 3256
             $amount = $discounts[ $discount ]['amount'] += $amount;
3257
-			$discounts[ $discount ] = array(
3257
+            $discounts[ $discount ] = array(
3258 3258
                 'amount'    => $amount,
3259 3259
                 'recurring' => (bool) $recurring,
3260 3260
             );
3261 3261
 
3262
-		} else {
3263
-			$discounts[ $discount ] = array(
3262
+        } else {
3263
+            $discounts[ $discount ] = array(
3264 3264
                 'amount'    => $amount,
3265 3265
                 'recurring' => (bool) $recurring,
3266 3266
             );
3267
-		}
3267
+        }
3268 3268
 
3269 3269
         $this->set_prop( 'discounts', $discount );
3270 3270
 
3271 3271
     }
3272 3272
 
3273 3273
     /**
3274
-	 * Retrieves a specific discount.
3275
-	 *
3276
-	 * @since 1.0.19
3277
-	 */
3278
-	public function get_discount( $discount = false ) {
3274
+     * Retrieves a specific discount.
3275
+     *
3276
+     * @since 1.0.19
3277
+     */
3278
+    public function get_discount( $discount = false ) {
3279 3279
 
3280
-		// Backwards compatibilty.
3281
-		if ( empty( $discount ) ) {
3282
-			return $this->get_total_discount();
3283
-		}
3280
+        // Backwards compatibilty.
3281
+        if ( empty( $discount ) ) {
3282
+            return $this->get_total_discount();
3283
+        }
3284 3284
 
3285 3285
         $discounts = $this->get_discounts();
3286
-		return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null;
3286
+        return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null;
3287 3287
     }
3288 3288
 
3289 3289
     /**
3290
-	 * Removes a specific discount.
3291
-	 *
3292
-	 * @since 1.0.19
3293
-	 */
3294
-	public function remove_discount( $discount ) {
3290
+     * Removes a specific discount.
3291
+     *
3292
+     * @since 1.0.19
3293
+     */
3294
+    public function remove_discount( $discount ) {
3295 3295
         $discounts = $this->get_discounts();
3296 3296
         if ( isset( $discounts[ $discount ] ) ) {
3297 3297
             unset( $discounts[ $discount ] );
@@ -3317,44 +3317,44 @@  discard block
 block discarded – undo
3317 3317
         if ( isset( $taxes[ $tax ] ) && isset( $taxes[ $tax ]['amount'] ) ) {
3318 3318
 
3319 3319
             $amount = $taxes[ $tax ]['amount'] += $amount;
3320
-			$taxes[ $tax ] = array(
3320
+            $taxes[ $tax ] = array(
3321 3321
                 'amount'    => $amount,
3322 3322
                 'recurring' => (bool) $recurring,
3323 3323
             );
3324 3324
 
3325
-		} else {
3326
-			$taxes[ $tax ] = array(
3325
+        } else {
3326
+            $taxes[ $tax ] = array(
3327 3327
                 'amount'    => $amount,
3328 3328
                 'recurring' => (bool) $recurring,
3329 3329
             );
3330
-		}
3330
+        }
3331 3331
 
3332 3332
         $this->set_prop( 'taxes', $tax );
3333 3333
 
3334 3334
     }
3335 3335
 
3336 3336
     /**
3337
-	 * Retrieves a specific tax.
3338
-	 *
3339
-	 * @since 1.0.19
3340
-	 */
3341
-	public function get_tax( $tax = null ) {
3337
+     * Retrieves a specific tax.
3338
+     *
3339
+     * @since 1.0.19
3340
+     */
3341
+    public function get_tax( $tax = null ) {
3342 3342
 
3343
-		// Backwards compatility.
3344
-		if ( empty( $tax ) ) {
3345
-			return $this->get_total_tax();
3346
-		}
3343
+        // Backwards compatility.
3344
+        if ( empty( $tax ) ) {
3345
+            return $this->get_total_tax();
3346
+        }
3347 3347
 
3348 3348
         $taxes = $this->get_taxes();
3349
-		return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null;
3349
+        return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null;
3350 3350
     }
3351 3351
 
3352 3352
     /**
3353
-	 * Removes a specific tax.
3354
-	 *
3355
-	 * @since 1.0.19
3356
-	 */
3357
-	public function remove_tax( $tax ) {
3353
+     * Removes a specific tax.
3354
+     *
3355
+     * @since 1.0.19
3356
+     */
3357
+    public function remove_tax( $tax ) {
3358 3358
         $taxes = $this->get_discounts();
3359 3359
         if ( isset( $taxes[ $tax ] ) ) {
3360 3360
             unset( $taxes[ $tax ] );
@@ -3363,160 +3363,160 @@  discard block
 block discarded – undo
3363 3363
     }
3364 3364
 
3365 3365
     /**
3366
-	 * Recalculates the invoice subtotal.
3367
-	 *
3368
-	 * @since 1.0.19
3369
-	 * @return float The recalculated subtotal
3370
-	 */
3371
-	public function recalculate_subtotal() {
3366
+     * Recalculates the invoice subtotal.
3367
+     *
3368
+     * @since 1.0.19
3369
+     * @return float The recalculated subtotal
3370
+     */
3371
+    public function recalculate_subtotal() {
3372 3372
         $items     = $this->get_items();
3373
-		$subtotal  = 0;
3374
-		$recurring = 0;
3373
+        $subtotal  = 0;
3374
+        $recurring = 0;
3375 3375
 
3376 3376
         foreach ( $items as $item ) {
3377
-			$subtotal  += $item->get_sub_total();
3378
-			$recurring += $item->get_recurring_sub_total();
3377
+            $subtotal  += $item->get_sub_total();
3378
+            $recurring += $item->get_recurring_sub_total();
3379 3379
         }
3380 3380
 
3381
-		if ( $this->is_renewal() ) {
3382
-			$this->set_subtotal( $recurring );
3383
-		} else {
3384
-			$this->set_subtotal( $subtotal );
3385
-		}
3381
+        if ( $this->is_renewal() ) {
3382
+            $this->set_subtotal( $recurring );
3383
+        } else {
3384
+            $this->set_subtotal( $subtotal );
3385
+        }
3386 3386
 
3387
-		$this->totals['subtotal'] = array(
3388
-			'initial'   => $subtotal,
3389
-			'recurring' => $recurring,
3390
-		);
3387
+        $this->totals['subtotal'] = array(
3388
+            'initial'   => $subtotal,
3389
+            'recurring' => $recurring,
3390
+        );
3391 3391
 
3392 3392
         return $this->is_renewal() ? $recurring : $subtotal;
3393 3393
     }
3394 3394
 
3395 3395
     /**
3396
-	 * Recalculates the invoice discount total.
3397
-	 *
3398
-	 * @since 1.0.19
3399
-	 * @return float The recalculated discount
3400
-	 */
3401
-	public function recalculate_total_discount() {
3396
+     * Recalculates the invoice discount total.
3397
+     *
3398
+     * @since 1.0.19
3399
+     * @return float The recalculated discount
3400
+     */
3401
+    public function recalculate_total_discount() {
3402 3402
         $discounts = $this->get_discounts();
3403
-		$discount  = 0;
3404
-		$recurring = 0;
3403
+        $discount  = 0;
3404
+        $recurring = 0;
3405 3405
 
3406 3406
         foreach ( $discounts as $data ) {
3407 3407
 
3408
-			if ( $data['recurring'] ) {
3409
-				$recurring += $data['amount'];
3410
-			} else {
3411
-				$discount += $data['amount'];
3412
-			}
3408
+            if ( $data['recurring'] ) {
3409
+                $recurring += $data['amount'];
3410
+            } else {
3411
+                $discount += $data['amount'];
3412
+            }
3413 3413
 
3414
-		}
3414
+        }
3415 3415
 
3416
-		if ( $this->is_renewal() ) {
3417
-			$this->set_total_discount( $recurring );
3418
-		} else {
3419
-			$this->set_total_discount( $discount );
3420
-		}
3416
+        if ( $this->is_renewal() ) {
3417
+            $this->set_total_discount( $recurring );
3418
+        } else {
3419
+            $this->set_total_discount( $discount );
3420
+        }
3421 3421
 
3422
-		$this->totals['discount'] = array(
3423
-			'initial'   => $discount,
3424
-			'recurring' => $recurring,
3425
-		);
3422
+        $this->totals['discount'] = array(
3423
+            'initial'   => $discount,
3424
+            'recurring' => $recurring,
3425
+        );
3426 3426
 
3427
-		return $this->is_renewal() ? $recurring : $discount;
3427
+        return $this->is_renewal() ? $recurring : $discount;
3428 3428
 
3429 3429
     }
3430 3430
 
3431 3431
     /**
3432
-	 * Recalculates the invoice tax total.
3433
-	 *
3434
-	 * @since 1.0.19
3435
-	 * @return float The recalculated tax
3436
-	 */
3437
-	public function recalculate_total_tax() {
3432
+     * Recalculates the invoice tax total.
3433
+     *
3434
+     * @since 1.0.19
3435
+     * @return float The recalculated tax
3436
+     */
3437
+    public function recalculate_total_tax() {
3438 3438
         $taxes     = $this->get_taxes();
3439
-		$tax       = 0;
3440
-		$recurring = 0;
3439
+        $tax       = 0;
3440
+        $recurring = 0;
3441 3441
 
3442 3442
         foreach ( $taxes as $data ) {
3443 3443
 
3444
-			if ( $data['recurring'] ) {
3445
-				$recurring += $data['amount'];
3446
-			} else {
3447
-				$tax += $data['amount'];
3448
-			}
3444
+            if ( $data['recurring'] ) {
3445
+                $recurring += $data['amount'];
3446
+            } else {
3447
+                $tax += $data['amount'];
3448
+            }
3449 3449
 
3450
-		}
3450
+        }
3451 3451
 
3452
-		if ( $this->is_renewal() ) {
3453
-			$this->set_total_tax( $recurring );
3454
-		} else {
3455
-			$this->set_total_tax( $tax );
3456
-		}
3452
+        if ( $this->is_renewal() ) {
3453
+            $this->set_total_tax( $recurring );
3454
+        } else {
3455
+            $this->set_total_tax( $tax );
3456
+        }
3457 3457
 
3458
-		$this->totals['tax'] = array(
3459
-			'initial'   => $tax,
3460
-			'recurring' => $recurring,
3461
-		);
3458
+        $this->totals['tax'] = array(
3459
+            'initial'   => $tax,
3460
+            'recurring' => $recurring,
3461
+        );
3462 3462
 
3463
-		return $this->is_renewal() ? $recurring : $tax;
3463
+        return $this->is_renewal() ? $recurring : $tax;
3464 3464
 
3465 3465
     }
3466 3466
 
3467 3467
     /**
3468
-	 * Recalculates the invoice fees total.
3469
-	 *
3470
-	 * @since 1.0.19
3471
-	 * @return float The recalculated fee
3472
-	 */
3473
-	public function recalculate_total_fees() {
3474
-		$fees      = $this->get_fees();
3475
-		$fee       = 0;
3476
-		$recurring = 0;
3468
+     * Recalculates the invoice fees total.
3469
+     *
3470
+     * @since 1.0.19
3471
+     * @return float The recalculated fee
3472
+     */
3473
+    public function recalculate_total_fees() {
3474
+        $fees      = $this->get_fees();
3475
+        $fee       = 0;
3476
+        $recurring = 0;
3477 3477
 
3478 3478
         foreach ( $fees as $data ) {
3479 3479
 
3480
-			if ( $data['recurring'] ) {
3481
-				$recurring += $data['amount'];
3482
-			} else {
3483
-				$fee += $data['amount'];
3484
-			}
3480
+            if ( $data['recurring'] ) {
3481
+                $recurring += $data['amount'];
3482
+            } else {
3483
+                $fee += $data['amount'];
3484
+            }
3485 3485
 
3486
-		}
3486
+        }
3487 3487
 
3488 3488
         if ( $this->is_renewal() ) {
3489
-			$this->set_total_fees( $recurring );
3490
-		} else {
3491
-			$this->set_total_fees( $fee );
3492
-		}
3489
+            $this->set_total_fees( $recurring );
3490
+        } else {
3491
+            $this->set_total_fees( $fee );
3492
+        }
3493 3493
 
3494
-		$this->totals['fee'] = array(
3495
-			'initial'   => $fee,
3496
-			'recurring' => $recurring,
3497
-		);
3494
+        $this->totals['fee'] = array(
3495
+            'initial'   => $fee,
3496
+            'recurring' => $recurring,
3497
+        );
3498 3498
 
3499 3499
         $this->set_total_fees( $fee );
3500 3500
         return $this->is_renewal() ? $recurring : $fee;
3501 3501
     }
3502 3502
 
3503 3503
     /**
3504
-	 * Recalculates the invoice total.
3505
-	 *
3506
-	 * @since 1.0.19
3504
+     * Recalculates the invoice total.
3505
+     *
3506
+     * @since 1.0.19
3507 3507
      * @return float The invoice total
3508
-	 */
3509
-	public function recalculate_total() {
3508
+     */
3509
+    public function recalculate_total() {
3510 3510
         $this->recalculate_subtotal();
3511 3511
         $this->recalculate_total_fees();
3512 3512
         $this->recalculate_total_discount();
3513 3513
         $this->recalculate_total_tax();
3514
-		return $this->get_total();
3515
-	}
3514
+        return $this->get_total();
3515
+    }
3516 3516
 
3517
-	/**
3518
-	 * @deprecated
3519
-	 */
3517
+    /**
3518
+     * @deprecated
3519
+     */
3520 3520
     public function recalculate_totals( $temp = false ) {
3521 3521
         $this->update_items( $temp );
3522 3522
         $this->save( true );
@@ -3534,7 +3534,7 @@  discard block
 block discarded – undo
3534 3534
      * Adds a note to an invoice.
3535 3535
      *
3536 3536
      * @param string $note The note being added.
3537
-	 * @return int|false The new note's ID on success, false on failure.
3537
+     * @return int|false The new note's ID on success, false on failure.
3538 3538
      *
3539 3539
      */
3540 3540
     public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
@@ -3544,23 +3544,23 @@  discard block
 block discarded – undo
3544 3544
             return false;
3545 3545
         }
3546 3546
 
3547
-		// If this is an admin comment or it has been added by the user.
3548
-		if ( is_user_logged_in() && ( wpinv_current_user_can_manage_invoicing() || $added_by_user ) ) {
3549
-			$user         = get_user_by( 'id', get_current_user_id() );
3547
+        // If this is an admin comment or it has been added by the user.
3548
+        if ( is_user_logged_in() && ( wpinv_current_user_can_manage_invoicing() || $added_by_user ) ) {
3549
+            $user         = get_user_by( 'id', get_current_user_id() );
3550 3550
             $author       = $user->display_name;
3551 3551
             $author_email = $user->user_email;
3552
-		} 
3552
+        } 
3553 3553
 
3554
-		if ( $system ) {
3555
-			$author       = 'System';
3554
+        if ( $system ) {
3555
+            $author       = 'System';
3556 3556
             $author_email = '[email protected]';
3557
-		}
3557
+        }
3558 3558
 
3559
-		return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type );
3559
+        return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type );
3560 3560
 
3561
-	}
3561
+    }
3562 3562
 
3563
-	/**
3563
+    /**
3564 3564
      * Generates a unique key for the invoice.
3565 3565
      */
3566 3566
     public function generate_key( $string = '' ) {
@@ -3580,106 +3580,106 @@  discard block
 block discarded – undo
3580 3580
             $number = wpinv_get_next_invoice_number( $this->post_type );
3581 3581
         }
3582 3582
 
3583
-		$number = wpinv_format_invoice_number( $number, $this->post_type );
3583
+        $number = wpinv_format_invoice_number( $number, $this->post_type );
3584 3584
 
3585
-		return $number;
3586
-	}
3585
+        return $number;
3586
+    }
3587 3587
 
3588
-	/**
3589
-	 * Handle the status transition.
3590
-	 */
3591
-	protected function status_transition() {
3592
-		$status_transition = $this->status_transition;
3588
+    /**
3589
+     * Handle the status transition.
3590
+     */
3591
+    protected function status_transition() {
3592
+        $status_transition = $this->status_transition;
3593 3593
 
3594
-		// Reset status transition variable.
3595
-		$this->status_transition = false;
3594
+        // Reset status transition variable.
3595
+        $this->status_transition = false;
3596 3596
 
3597
-		if ( $status_transition ) {
3598
-			try {
3597
+        if ( $status_transition ) {
3598
+            try {
3599 3599
 
3600
-				// Fire a hook for the status change.
3601
-				do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
3600
+                // Fire a hook for the status change.
3601
+                do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
3602 3602
 
3603
-				// @deprecated this is deprecated and will be removed in the future.
3604
-				do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3603
+                // @deprecated this is deprecated and will be removed in the future.
3604
+                do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3605 3605
 
3606
-				if ( ! empty( $status_transition['from'] ) ) {
3606
+                if ( ! empty( $status_transition['from'] ) ) {
3607 3607
 
3608
-					/* translators: 1: old invoice status 2: new invoice status */
3609
-					$transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'] ), wpinv_status_nicename( $status_transition['to'] ) );
3608
+                    /* translators: 1: old invoice status 2: new invoice status */
3609
+                    $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'] ), wpinv_status_nicename( $status_transition['to'] ) );
3610 3610
 
3611
-					// Fire another hook.
3612
-					do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
3613
-					do_action( 'getpaid_invoice_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );
3611
+                    // Fire another hook.
3612
+                    do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
3613
+                    do_action( 'getpaid_invoice_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );
3614 3614
 
3615
-					// @deprecated this is deprecated and will be removed in the future.
3616
-					do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3615
+                    // @deprecated this is deprecated and will be removed in the future.
3616
+                    do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3617 3617
 
3618
-					// Note the transition occurred.
3619
-					$this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3618
+                    // Note the transition occurred.
3619
+                    $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3620 3620
 
3621
-					// Work out if this was for a payment, and trigger a payment_status hook instead.
3622
-					if (
3623
-						in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded' ), true )
3624
-						&& in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3625
-					) {
3626
-						do_action( 'getpaid_invoice_payment_status_changed', $this->get_id(), $this, $status_transition );
3627
-					}
3628
-				} else {
3629
-					/* translators: %s: new invoice status */
3630
-					$transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'] ) );
3621
+                    // Work out if this was for a payment, and trigger a payment_status hook instead.
3622
+                    if (
3623
+                        in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded' ), true )
3624
+                        && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3625
+                    ) {
3626
+                        do_action( 'getpaid_invoice_payment_status_changed', $this->get_id(), $this, $status_transition );
3627
+                    }
3628
+                } else {
3629
+                    /* translators: %s: new invoice status */
3630
+                    $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'] ) );
3631 3631
 
3632
-					// Note the transition occurred.
3633
-					$this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3632
+                    // Note the transition occurred.
3633
+                    $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3634 3634
 
3635
-				}
3636
-			} catch ( Exception $e ) {
3637
-				$this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
3638
-			}
3639
-		}
3640
-	}
3635
+                }
3636
+            } catch ( Exception $e ) {
3637
+                $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
3638
+            }
3639
+        }
3640
+    }
3641 3641
 
3642
-	/**
3643
-	 * Updates an invoice status.
3644
-	 */
3645
-	public function update_status( $new_status = false, $note = '', $manual = false ) {
3642
+    /**
3643
+     * Updates an invoice status.
3644
+     */
3645
+    public function update_status( $new_status = false, $note = '', $manual = false ) {
3646 3646
 
3647
-		// Fires before updating a status.
3648
-		do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) );
3647
+        // Fires before updating a status.
3648
+        do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) );
3649 3649
 
3650
-		// Update the status.
3651
-		$this->set_status( $new_status, $note, $manual );
3650
+        // Update the status.
3651
+        $this->set_status( $new_status, $note, $manual );
3652 3652
 
3653
-		// Save the order.
3654
-		return $this->save();
3653
+        // Save the order.
3654
+        return $this->save();
3655 3655
 
3656
-	}
3656
+    }
3657 3657
 
3658
-	/**
3659
-	 * @deprecated
3660
-	 */
3661
-	public function refresh_item_ids() {
3658
+    /**
3659
+     * @deprecated
3660
+     */
3661
+    public function refresh_item_ids() {
3662 3662
         $item_ids = implode( ',', array_unique( array_keys( $this->get_items() ) ) );
3663 3663
         update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids );
3664
-	}
3664
+    }
3665 3665
 
3666
-	/**
3667
-	 * @deprecated
3668
-	 */
3669
-	public function update_items( $temp = false ) {
3666
+    /**
3667
+     * @deprecated
3668
+     */
3669
+    public function update_items( $temp = false ) {
3670 3670
 
3671
-		$this->set_items( $this->get_items() );
3671
+        $this->set_items( $this->get_items() );
3672 3672
 
3673
-		if ( ! $temp ) {
3674
-			$this->save();
3675
-		}
3673
+        if ( ! $temp ) {
3674
+            $this->save();
3675
+        }
3676 3676
 
3677 3677
         return $this;
3678
-	}
3678
+    }
3679 3679
 
3680
-	/**
3681
-	 * @deprecated
3682
-	 */
3680
+    /**
3681
+     * @deprecated
3682
+     */
3683 3683
     public function validate_discount() {
3684 3684
 
3685 3685
         $discount_code = $this->get_discount_code();
@@ -3695,86 +3695,86 @@  discard block
 block discarded – undo
3695 3695
 
3696 3696
     }
3697 3697
 
3698
-	/**
3699
-	 * Refunds an invoice.
3700
-	 */
3698
+    /**
3699
+     * Refunds an invoice.
3700
+     */
3701 3701
     public function refund() {
3702
-		$this->set_status( 'wpi-refunded' );
3702
+        $this->set_status( 'wpi-refunded' );
3703 3703
         $this->save();
3704
-	}
3704
+    }
3705 3705
 
3706
-	/**
3707
-	 * Marks an invoice as paid.
3708
-	 * 
3709
-	 * @param string $transaction_id
3710
-	 */
3706
+    /**
3707
+     * Marks an invoice as paid.
3708
+     * 
3709
+     * @param string $transaction_id
3710
+     */
3711 3711
     public function mark_paid( $transaction_id = null, $note = '' ) {
3712 3712
 
3713
-		// Set the transaction id.
3714
-		if ( empty( $transaction_id ) ) {
3715
-			$transaction_id = $this->generate_key('trans_');
3716
-		}
3713
+        // Set the transaction id.
3714
+        if ( empty( $transaction_id ) ) {
3715
+            $transaction_id = $this->generate_key('trans_');
3716
+        }
3717 3717
 
3718
-		if ( ! $this->get_transaction_id() ) {
3719
-			$this->set_transaction_id( $transaction_id );
3720
-		}
3718
+        if ( ! $this->get_transaction_id() ) {
3719
+            $this->set_transaction_id( $transaction_id );
3720
+        }
3721 3721
 
3722
-		if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) {
3723
-			return $this->save();
3724
-		}
3722
+        if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) {
3723
+            return $this->save();
3724
+        }
3725 3725
 
3726
-		// Set the completed date.
3727
-		$this->set_date_completed( current_time( 'mysql' ) );
3726
+        // Set the completed date.
3727
+        $this->set_date_completed( current_time( 'mysql' ) );
3728 3728
 
3729
-		// Set the new status.
3730
-		if ( $this->is_renewal() ) {
3729
+        // Set the new status.
3730
+        if ( $this->is_renewal() ) {
3731 3731
 
3732
-			$_note = sprintf(
3733
-				__( 'Renewed via %s', 'invoicing' ),
3734
-				$this->get_gateway_title() . empty( $note ) ? '' : " ($note)"
3735
-			);
3732
+            $_note = sprintf(
3733
+                __( 'Renewed via %s', 'invoicing' ),
3734
+                $this->get_gateway_title() . empty( $note ) ? '' : " ($note)"
3735
+            );
3736 3736
 
3737
-			if ( 'none' == $this->get_gateway() ) {
3738
-				$_note = $note;
3739
-			}
3737
+            if ( 'none' == $this->get_gateway() ) {
3738
+                $_note = $note;
3739
+            }
3740 3740
 
3741
-			$this->set_status( 'wpi-renewal', $_note );
3741
+            $this->set_status( 'wpi-renewal', $_note );
3742 3742
 
3743
-		} else {
3743
+        } else {
3744 3744
 
3745
-			$_note = sprintf(
3746
-				__( 'Paid via %s', 'invoicing' ),
3747
-				$this->get_gateway_title() . empty( $note ) ? '' : " ($note)"
3748
-			);
3745
+            $_note = sprintf(
3746
+                __( 'Paid via %s', 'invoicing' ),
3747
+                $this->get_gateway_title() . empty( $note ) ? '' : " ($note)"
3748
+            );
3749 3749
 
3750
-			if ( 'none' == $this->get_gateway() ) {
3751
-				$_note = $note;
3752
-			}
3750
+            if ( 'none' == $this->get_gateway() ) {
3751
+                $_note = $note;
3752
+            }
3753 3753
 
3754
-			$this->set_status( 'publish',$_note );
3754
+            $this->set_status( 'publish',$_note );
3755 3755
 
3756
-		}
3756
+        }
3757 3757
 
3758
-		// Set checkout mode.
3759
-		$mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live';
3760
-		$this->set_mode( $mode );
3758
+        // Set checkout mode.
3759
+        $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live';
3760
+        $this->set_mode( $mode );
3761 3761
 
3762
-		// Save the invoice.
3762
+        // Save the invoice.
3763 3763
         $this->save();
3764
-	}
3765
-
3766
-
3767
-	/**
3768
-	 * Save data to the database.
3769
-	 *
3770
-	 * @since 1.0.19
3771
-	 * @return int invoice ID
3772
-	 */
3773
-	public function save() {
3774
-		$this->maybe_set_date_paid();
3775
-		parent::save();
3776
-		$this->status_transition();
3777
-		return $this->get_id();
3778
-	}
3764
+    }
3765
+
3766
+
3767
+    /**
3768
+     * Save data to the database.
3769
+     *
3770
+     * @since 1.0.19
3771
+     * @return int invoice ID
3772
+     */
3773
+    public function save() {
3774
+        $this->maybe_set_date_paid();
3775
+        parent::save();
3776
+        $this->status_transition();
3777
+        return $this->get_id();
3778
+    }
3779 3779
 
3780 3780
 }
Please login to merge, or discard this patch.