Passed
Pull Request — master (#410)
by Brian
04:58
created
includes/data-stores/class-getpaid-data-store-wp.php 2 patches
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
-			do_action( "getpaid_delete_$object_type", $object );
331
-			wp_delete_post( $id, true );
332
-			$object->set_id( 0 );
333
-		} else {
334
-			do_action( "getpaid_trash_$object_type", $object );
335
-			wp_trash_post( $id );
336
-			$object->set_status( 'trash' );
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
+            do_action( "getpaid_delete_$object_type", $object );
331
+            wp_delete_post( $id, true );
332
+            $object->set_id( 0 );
333
+        } else {
334
+            do_action( "getpaid_trash_$object_type", $object );
335
+            wp_trash_post( $id );
336
+            $object->set_status( 'trash' );
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.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * @version 1.0.19
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * GetPaid_Data_Store_WP class.
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	 * @param  GetPaid_Data $object GetPaid_Data object.
65 65
 	 * @return array
66 66
 	 */
67
-	public function read_meta( &$object ) {
67
+	public function read_meta(&$object) {
68 68
 		global $wpdb;
69 69
 		$db_info       = $this->get_db_info();
70 70
 		$raw_meta_data = $wpdb->get_results(
@@ -77,9 +77,9 @@  discard block
 block discarded – undo
77 77
 			)
78 78
 		);
79 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 );
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 83
 	}
84 84
 
85 85
 	/**
@@ -89,8 +89,8 @@  discard block
 block discarded – undo
89 89
 	 * @param  GetPaid_Data  $object GetPaid_Data object.
90 90
 	 * @param  stdClass $meta (containing at least ->id).
91 91
 	 */
92
-	public function delete_meta( &$object, $meta ) {
93
-		delete_metadata_by_mid( $this->meta_type, $meta->id );
92
+	public function delete_meta(&$object, $meta) {
93
+		delete_metadata_by_mid($this->meta_type, $meta->id);
94 94
 	}
95 95
 
96 96
 	/**
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
 	 * @param  stdClass $meta (containing ->key and ->value).
102 102
 	 * @return int meta ID
103 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 );
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 106
 	}
107 107
 
108 108
 	/**
@@ -112,8 +112,8 @@  discard block
 block discarded – undo
112 112
 	 * @param  GetPaid_Data  $object GetPaid_Data object.
113 113
 	 * @param  stdClass $meta (containing ->id, ->key and ->value).
114 114
 	 */
115
-	public function update_meta( &$object, $meta ) {
116
-		update_metadata_by_mid( $this->meta_type, $meta->id, $meta->value, $meta->key );
115
+	public function update_meta(&$object, $meta) {
116
+		update_metadata_by_mid($this->meta_type, $meta->id, $meta->value, $meta->key);
117 117
 	}
118 118
 
119 119
 	/**
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 		$table         = $wpdb->prefix;
130 130
 
131 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 ) ) {
132
+		if (!in_array($this->meta_type, array('post', 'user', 'comment', 'term'), true)) {
133 133
 			$table .= 'getpaid_';
134 134
 		}
135 135
 
@@ -137,12 +137,12 @@  discard block
 block discarded – undo
137 137
 		$object_id_field = $this->meta_type . '_id';
138 138
 
139 139
 		// Figure out our field names.
140
-		if ( 'user' === $this->meta_type ) {
140
+		if ('user' === $this->meta_type) {
141 141
 			$meta_id_field = 'umeta_id';
142 142
 			$table         = $wpdb->usermeta;
143 143
 		}
144 144
 
145
-		if ( ! empty( $this->object_id_field_for_meta ) ) {
145
+		if (!empty($this->object_id_field_for_meta)) {
146 146
 			$object_id_field = $this->object_id_field_for_meta;
147 147
 		}
148 148
 
@@ -162,8 +162,8 @@  discard block
 block discarded – undo
162 162
 	 * @param string $key Prefix to be added to meta keys.
163 163
 	 * @return string
164 164
 	 */
165
-	protected function prefix_key( $key ) {
166
-		return '_' === substr( $key, 0, 1 ) ? $key : '_' . $key;
165
+	protected function prefix_key($key) {
166
+		return '_' === substr($key, 0, 1) ? $key : '_' . $key;
167 167
 	}
168 168
 
169 169
 	/**
@@ -172,8 +172,8 @@  discard block
 block discarded – undo
172 172
 	 * @param object $meta Meta object to check if it should be excluded or not.
173 173
 	 * @return bool
174 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_' );
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 177
 	}
178 178
 
179 179
 	/**
@@ -185,14 +185,14 @@  discard block
 block discarded – undo
185 185
 	 * @param  string  $meta_type           The internal WP meta type (post, user, etc).
186 186
 	 * @return array                        A mapping of meta keys => prop names, filtered by ones that should be updated.
187 187
 	 */
188
-	protected function get_props_to_update( $object, $meta_key_to_props, $meta_type = 'post' ) {
188
+	protected function get_props_to_update($object, $meta_key_to_props, $meta_type = 'post') {
189 189
 		$props_to_update = array();
190 190
 		$changed_props   = $object->get_changes();
191 191
 
192 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;
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 196
 			}
197 197
 		}
198 198
 
@@ -206,22 +206,22 @@  discard block
 block discarded – undo
206 206
 	 * @param WP_Post   $post_object Post object.
207 207
 	 * @since 1.0.19
208 208
 	 */
209
-	protected function read_object_data( &$object, $post_object ) {
209
+	protected function read_object_data(&$object, $post_object) {
210 210
 		$id    = $object->get_id();
211 211
 		$props = array();
212 212
 
213
-		foreach ( $this->meta_key_to_props as $meta_key => $prop ) {
214
-			$props[ $prop ] = get_post_meta( $id, $meta_key, true );
213
+		foreach ($this->meta_key_to_props as $meta_key => $prop) {
214
+			$props[$prop] = get_post_meta($id, $meta_key, true);
215 215
 		}
216 216
 
217 217
 		// Set object properties.
218
-		$object->set_props( $props );
218
+		$object->set_props($props);
219 219
 
220 220
 		// Gets extra data associated with the object if needed.
221
-		foreach ( $object->get_extra_data_keys() as $key ) {
221
+		foreach ($object->get_extra_data_keys() as $key) {
222 222
 			$function = 'set_' . $key;
223
-			if ( is_callable( array( $object, $function ) ) ) {
224
-				$object->{$function}( get_post_meta( $object->get_id(), $key, true ) );
223
+			if (is_callable(array($object, $function))) {
224
+				$object->{$function}(get_post_meta($object->get_id(), $key, true));
225 225
 			}
226 226
 		}
227 227
 	}
@@ -232,24 +232,24 @@  discard block
 block discarded – undo
232 232
 	 * @param GetPaid_Data $object GetPaid_Data object.
233 233
 	 * @since 1.0.19
234 234
 	 */
235
-	protected function update_post_meta( &$object ) {
235
+	protected function update_post_meta(&$object) {
236 236
 
237 237
 		$updated_props   = array();
238
-		$props_to_update = $this->get_props_to_update( $object, $this->meta_key_to_props );
238
+		$props_to_update = $this->get_props_to_update($object, $this->meta_key_to_props);
239 239
 		$object_type     = $object->get_object_type();
240 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;
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 244
 
245
-			$updated = $this->update_or_delete_post_meta( $object, $meta_key, $value );
245
+			$updated = $this->update_or_delete_post_meta($object, $meta_key, $value);
246 246
 
247
-			if ( $updated ) {
247
+			if ($updated) {
248 248
 				$updated_props[] = $prop;
249 249
 			}
250 250
 		}
251 251
 
252
-		do_action( "getpaid_{$object_type}_object_updated_props", $object, $updated_props );
252
+		do_action("getpaid_{$object_type}_object_updated_props", $object, $updated_props);
253 253
 	}
254 254
 
255 255
 	/**
@@ -269,11 +269,11 @@  discard block
 block discarded – undo
269 269
 	 *
270 270
 	 * @return bool True if updated/deleted.
271 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 );
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 275
 		} else {
276
-			$updated = update_post_meta( $object->get_id(), $meta_key, $meta_value );
276
+			$updated = update_post_meta($object->get_id(), $meta_key, $meta_value);
277 277
 		}
278 278
 
279 279
 		return (bool) $updated;
@@ -295,8 +295,8 @@  discard block
 block discarded – undo
295 295
 	 * @param GetPaid_Data $object GetPaid_Data object.
296 296
 	 * @since 1.0.19
297 297
 	 */
298
-	protected function clear_caches( &$object ) {
299
-		clean_post_cache( $object->get_id() );
298
+	protected function clear_caches(&$object) {
299
+		clean_post_cache($object->get_id());
300 300
 	}
301 301
 
302 302
 	/**
@@ -307,33 +307,33 @@  discard block
 block discarded – undo
307 307
 	 *
308 308
 	 * @return void
309 309
 	 */
310
-	public function delete( &$object, $args = array() ) {
310
+	public function delete(&$object, $args = array()) {
311 311
 		$id          = $object->get_id();
312 312
 		$object_type = $object->get_object_type();
313 313
 
314
-		if ( 'invoice' == $object_type ) {
314
+		if ('invoice' == $object_type) {
315 315
 			$object_type = $object->get_type();
316 316
 		}
317 317
 
318
-		$args        = wp_parse_args(
318
+		$args = wp_parse_args(
319 319
 			$args,
320 320
 			array(
321 321
 				'force_delete' => false,
322 322
 			)
323 323
 		);
324 324
 
325
-		if ( ! $id ) {
325
+		if (!$id) {
326 326
 			return;
327 327
 		}
328 328
 
329
-		if ( $args['force_delete'] ) {
330
-			do_action( "getpaid_delete_$object_type", $object );
331
-			wp_delete_post( $id, true );
332
-			$object->set_id( 0 );
329
+		if ($args['force_delete']) {
330
+			do_action("getpaid_delete_$object_type", $object);
331
+			wp_delete_post($id, true);
332
+			$object->set_id(0);
333 333
 		} else {
334
-			do_action( "getpaid_trash_$object_type", $object );
335
-			wp_trash_post( $id );
336
-			$object->set_status( 'trash' );
334
+			do_action("getpaid_trash_$object_type", $object);
335
+			wp_trash_post($id);
336
+			$object->set_status('trash');
337 337
 		}
338 338
 	}
339 339
 
@@ -345,12 +345,12 @@  discard block
 block discarded – undo
345 345
 	 * @param  GetPaid_Data $object GetPaid_Data object.
346 346
 	 * @return string
347 347
 	 */
348
-	protected function get_post_status( $object ) {
349
-		$object_status = $object->get_status( 'edit' );
348
+	protected function get_post_status($object) {
349
+		$object_status = $object->get_status('edit');
350 350
 		$object_type   = $object->get_object_type();
351 351
 
352
-		if ( ! $object_status ) {
353
-			$object_status = apply_filters( "getpaid_default_{$object_type}_status", 'draft' );
352
+		if (!$object_status) {
353
+			$object_status = apply_filters("getpaid_default_{$object_type}_status", 'draft');
354 354
 		}
355 355
 
356 356
 		return $object_status;
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-subscription-data-store.php 2 patches
Indentation   +180 added lines, -180 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_Subscription_Data_Store {
17 17
 
18
-	/**
19
-	 * A map of database fields to data types.
20
-	 *
21
-	 * @since 1.0.19
22
-	 * @var array
23
-	 */
24
-	protected $database_fields_to_data_type = array(
25
-		'id'                => '%d',
26
-		'customer_id'       => '%d',
27
-		'frequency'         => '%d',
28
-		'period'            => '%s',
29
-		'initial_amount'    => '%s',
30
-		'recurring_amount'  => '%s',
31
-		'bill_times'        => '%d',
32
-		'transaction_id'    => '%s',
33
-		'parent_payment_id' => '%d',
34
-		'product_id'        => '%d',
35
-		'created'           => '%s',
36
-		'expiration'        => '%s',
37
-		'trial_period'      => '%s',
38
-		'status'            => '%s',
39
-		'profile_id'        => '%s',
40
-	);
41
-
42
-	/*
18
+    /**
19
+     * A map of database fields to data types.
20
+     *
21
+     * @since 1.0.19
22
+     * @var array
23
+     */
24
+    protected $database_fields_to_data_type = array(
25
+        'id'                => '%d',
26
+        'customer_id'       => '%d',
27
+        'frequency'         => '%d',
28
+        'period'            => '%s',
29
+        'initial_amount'    => '%s',
30
+        'recurring_amount'  => '%s',
31
+        'bill_times'        => '%d',
32
+        'transaction_id'    => '%s',
33
+        'parent_payment_id' => '%d',
34
+        'product_id'        => '%d',
35
+        'created'           => '%s',
36
+        'expiration'        => '%s',
37
+        'trial_period'      => '%s',
38
+        'status'            => '%s',
39
+        'profile_id'        => '%s',
40
+    );
41
+
42
+    /*
43 43
 	|--------------------------------------------------------------------------
44 44
 	| CRUD Methods
45 45
 	|--------------------------------------------------------------------------
46 46
 	*/
47 47
 
48
-	/**
49
-	 * Method to create a new subscription in the database.
50
-	 *
51
-	 * @param WPInv_Subscription $subscription Subscription object.
52
-	 */
53
-	public function create( &$subscription ) {
54
-		global $wpdb;
55
-
56
-		$values  = array();
57
-		$formats = array();
58
-
59
-		$fields = $this->database_fields_to_data_type;
60
-		unset( $fields['id'] );
61
-
62
-		foreach ( $fields as $key => $format ) {
63
-			$method       = "get_$key";
64
-			$values[$key] = $subscription->$method( 'edit' );
65
-			$formats[]    = $format;
66
-		}
67
-
68
-		$result = $wpdb->insert( $wpdb->prefix . 'wpinv_subscriptions', $fields, $formats );
69
-
70
-		if ( $result ) {
71
-			$subscription->set_id( $wpdb->insert_id );
72
-			$subscription->apply_changes();
73
-			$subscription->clear_cache();
74
-			update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id() );
75
-			do_action( 'getpaid_new_subscription', $subscription );
76
-			return true;
77
-		}
78
-
79
-		return false;
80
-	}
81
-
82
-	/**
83
-	 * Method to read a subscription from the database.
84
-	 *
85
-	 * @param WPInv_Subscription $subscription Subscription object.
86
-	 *
87
-	 */
88
-	public function read( &$subscription ) {
89
-		global $wpdb;
90
-
91
-		$subscription->set_defaults();
92
-
93
-		if ( ! $subscription->get_id() ) {
94
-			$subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
95
-			$subscription->set_id( 0 );
96
-			return false;
97
-		}
98
-
99
-		// Maybe retrieve from the cache.
100
-		$raw_subscription = wp_cache_get( $subscription->get_id(), 'getpaid_subscriptions' );
101
-
102
-		// If not found, retrieve from the db.
103
-		if ( false === $raw_subscription ) {
104
-
105
-			$raw_subscription = $wpdb->get_row(
106
-				$wpdb->prepare(
107
-					"SELECT * FROM {$wpdb->prefix}wpinv_subscriptions WHERE id = %d",
108
-					$subscription->get_id()
109
-				)
110
-			);
111
-
112
-			// Update the cache with our data
113
-			wp_cache_set( $subscription->get_id(), $raw_subscription, 'getpaid_subscriptions' );
114
-
115
-		}
116
-
117
-		if ( ! $raw_subscription ) {
118
-			$subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
119
-			return false;
120
-		}
121
-
122
-		foreach ( array_keys( $this->database_fields_to_data_type ) as $key ) {
123
-			$method     = "set_$key";
124
-			$subscription->$method( $raw_subscription->$key );
125
-		}
126
-
127
-		$subscription->set_object_read( true );
128
-		do_action( 'getpaid_read_subscription', $subscription );
129
-
130
-	}
131
-
132
-	/**
133
-	 * Method to update a subscription in the database.
134
-	 *
135
-	 * @param WPInv_Subscription $subscription Subscription object.
136
-	 */
137
-	public function update( &$subscription ) {
138
-		global $wpdb;
139
-
140
-		$changes = $subscription->get_changes();
141
-		$values  = array();
142
-		$format  = array();
143
-
144
-		foreach ( $this->database_fields_to_data_type as $key => $format ) {
145
-			if ( array_key_exists( $key, $changes ) ) {
146
-				$method       = "get_$key";
147
-				$values[$key] = $subscription->$method( 'edit' );
148
-				$formats[]    = $format;
149
-			}
150
-		}
151
-
152
-		if ( empty( $values ) ) {
153
-			return;
154
-		}
155
-
156
-		$wpdb->update(
157
-			$wpdb->prefix . 'wpinv_subscriptions',
158
-			$values,
159
-			array(
160
-				'id' => $subscription->get_id(),
161
-			),
162
-			$formats,
163
-			'%d'
164
-		);
165
-
166
-		// Apply the changes.
167
-		$subscription->apply_changes();
168
-
169
-		// Delete cache.
170
-		$subscription->clear_cache();
171
-
172
-		update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id', $subscription->get_profile_id() );
173
-
174
-		// Fire a hook.
175
-		do_action( 'getpaid_update_subscription', $subscription );
176
-
177
-	}
178
-
179
-	/**
180
-	 * Method to delete a subscription from the database.
181
-	 *
182
-	 * @param WPInv_Subscription $subscription
183
-	 */
184
-	public function delete( &$subscription ) {
185
-		global $wpdb;
186
-
187
-		$wpdb->query(
188
-			$wpdb->prepare(
189
-				"DELETE FROM {$wpdb->prefix}getpaid_subscriptions
48
+    /**
49
+     * Method to create a new subscription in the database.
50
+     *
51
+     * @param WPInv_Subscription $subscription Subscription object.
52
+     */
53
+    public function create( &$subscription ) {
54
+        global $wpdb;
55
+
56
+        $values  = array();
57
+        $formats = array();
58
+
59
+        $fields = $this->database_fields_to_data_type;
60
+        unset( $fields['id'] );
61
+
62
+        foreach ( $fields as $key => $format ) {
63
+            $method       = "get_$key";
64
+            $values[$key] = $subscription->$method( 'edit' );
65
+            $formats[]    = $format;
66
+        }
67
+
68
+        $result = $wpdb->insert( $wpdb->prefix . 'wpinv_subscriptions', $fields, $formats );
69
+
70
+        if ( $result ) {
71
+            $subscription->set_id( $wpdb->insert_id );
72
+            $subscription->apply_changes();
73
+            $subscription->clear_cache();
74
+            update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id() );
75
+            do_action( 'getpaid_new_subscription', $subscription );
76
+            return true;
77
+        }
78
+
79
+        return false;
80
+    }
81
+
82
+    /**
83
+     * Method to read a subscription from the database.
84
+     *
85
+     * @param WPInv_Subscription $subscription Subscription object.
86
+     *
87
+     */
88
+    public function read( &$subscription ) {
89
+        global $wpdb;
90
+
91
+        $subscription->set_defaults();
92
+
93
+        if ( ! $subscription->get_id() ) {
94
+            $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
95
+            $subscription->set_id( 0 );
96
+            return false;
97
+        }
98
+
99
+        // Maybe retrieve from the cache.
100
+        $raw_subscription = wp_cache_get( $subscription->get_id(), 'getpaid_subscriptions' );
101
+
102
+        // If not found, retrieve from the db.
103
+        if ( false === $raw_subscription ) {
104
+
105
+            $raw_subscription = $wpdb->get_row(
106
+                $wpdb->prepare(
107
+                    "SELECT * FROM {$wpdb->prefix}wpinv_subscriptions WHERE id = %d",
108
+                    $subscription->get_id()
109
+                )
110
+            );
111
+
112
+            // Update the cache with our data
113
+            wp_cache_set( $subscription->get_id(), $raw_subscription, 'getpaid_subscriptions' );
114
+
115
+        }
116
+
117
+        if ( ! $raw_subscription ) {
118
+            $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
119
+            return false;
120
+        }
121
+
122
+        foreach ( array_keys( $this->database_fields_to_data_type ) as $key ) {
123
+            $method     = "set_$key";
124
+            $subscription->$method( $raw_subscription->$key );
125
+        }
126
+
127
+        $subscription->set_object_read( true );
128
+        do_action( 'getpaid_read_subscription', $subscription );
129
+
130
+    }
131
+
132
+    /**
133
+     * Method to update a subscription in the database.
134
+     *
135
+     * @param WPInv_Subscription $subscription Subscription object.
136
+     */
137
+    public function update( &$subscription ) {
138
+        global $wpdb;
139
+
140
+        $changes = $subscription->get_changes();
141
+        $values  = array();
142
+        $format  = array();
143
+
144
+        foreach ( $this->database_fields_to_data_type as $key => $format ) {
145
+            if ( array_key_exists( $key, $changes ) ) {
146
+                $method       = "get_$key";
147
+                $values[$key] = $subscription->$method( 'edit' );
148
+                $formats[]    = $format;
149
+            }
150
+        }
151
+
152
+        if ( empty( $values ) ) {
153
+            return;
154
+        }
155
+
156
+        $wpdb->update(
157
+            $wpdb->prefix . 'wpinv_subscriptions',
158
+            $values,
159
+            array(
160
+                'id' => $subscription->get_id(),
161
+            ),
162
+            $formats,
163
+            '%d'
164
+        );
165
+
166
+        // Apply the changes.
167
+        $subscription->apply_changes();
168
+
169
+        // Delete cache.
170
+        $subscription->clear_cache();
171
+
172
+        update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id', $subscription->get_profile_id() );
173
+
174
+        // Fire a hook.
175
+        do_action( 'getpaid_update_subscription', $subscription );
176
+
177
+    }
178
+
179
+    /**
180
+     * Method to delete a subscription from the database.
181
+     *
182
+     * @param WPInv_Subscription $subscription
183
+     */
184
+    public function delete( &$subscription ) {
185
+        global $wpdb;
186
+
187
+        $wpdb->query(
188
+            $wpdb->prepare(
189
+                "DELETE FROM {$wpdb->prefix}getpaid_subscriptions
190 190
 				WHERE id = %d",
191
-				$subscription->get_id()
192
-			)
193
-		);
191
+                $subscription->get_id()
192
+            )
193
+        );
194 194
 
195
-		delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id' );
196
-		delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id' );
195
+        delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id' );
196
+        delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id' );
197 197
 
198
-		// Delete cache.
199
-		$subscription->clear_cache();
198
+        // Delete cache.
199
+        $subscription->clear_cache();
200 200
 
201
-		// Fire a hook.
202
-		do_action( 'getpaid_delete_subscription', $subscription );
201
+        // Fire a hook.
202
+        do_action( 'getpaid_delete_subscription', $subscription );
203 203
 
204
-		$subscription->set_id( 0 );
205
-	}
204
+        $subscription->set_id( 0 );
205
+    }
206 206
 
207
-	/*
207
+    /*
208 208
 	|--------------------------------------------------------------------------
209 209
 	| Additional Methods
210 210
 	|--------------------------------------------------------------------------
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * GetPaid_Subscription_Data_Store class file.
5 5
  *
6 6
  */
7
-if ( ! defined( 'ABSPATH' ) ) {
7
+if (!defined('ABSPATH')) {
8 8
 	exit;
9 9
 }
10 10
 
@@ -50,29 +50,29 @@  discard block
 block discarded – undo
50 50
 	 *
51 51
 	 * @param WPInv_Subscription $subscription Subscription object.
52 52
 	 */
53
-	public function create( &$subscription ) {
53
+	public function create(&$subscription) {
54 54
 		global $wpdb;
55 55
 
56 56
 		$values  = array();
57 57
 		$formats = array();
58 58
 
59 59
 		$fields = $this->database_fields_to_data_type;
60
-		unset( $fields['id'] );
60
+		unset($fields['id']);
61 61
 
62
-		foreach ( $fields as $key => $format ) {
62
+		foreach ($fields as $key => $format) {
63 63
 			$method       = "get_$key";
64
-			$values[$key] = $subscription->$method( 'edit' );
64
+			$values[$key] = $subscription->$method('edit');
65 65
 			$formats[]    = $format;
66 66
 		}
67 67
 
68
-		$result = $wpdb->insert( $wpdb->prefix . 'wpinv_subscriptions', $fields, $formats );
68
+		$result = $wpdb->insert($wpdb->prefix . 'wpinv_subscriptions', $fields, $formats);
69 69
 
70
-		if ( $result ) {
71
-			$subscription->set_id( $wpdb->insert_id );
70
+		if ($result) {
71
+			$subscription->set_id($wpdb->insert_id);
72 72
 			$subscription->apply_changes();
73 73
 			$subscription->clear_cache();
74
-			update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id() );
75
-			do_action( 'getpaid_new_subscription', $subscription );
74
+			update_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id());
75
+			do_action('getpaid_new_subscription', $subscription);
76 76
 			return true;
77 77
 		}
78 78
 
@@ -85,22 +85,22 @@  discard block
 block discarded – undo
85 85
 	 * @param WPInv_Subscription $subscription Subscription object.
86 86
 	 *
87 87
 	 */
88
-	public function read( &$subscription ) {
88
+	public function read(&$subscription) {
89 89
 		global $wpdb;
90 90
 
91 91
 		$subscription->set_defaults();
92 92
 
93
-		if ( ! $subscription->get_id() ) {
94
-			$subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
95
-			$subscription->set_id( 0 );
93
+		if (!$subscription->get_id()) {
94
+			$subscription->last_error = __('Invalid subscription ID.', 'invoicing');
95
+			$subscription->set_id(0);
96 96
 			return false;
97 97
 		}
98 98
 
99 99
 		// Maybe retrieve from the cache.
100
-		$raw_subscription = wp_cache_get( $subscription->get_id(), 'getpaid_subscriptions' );
100
+		$raw_subscription = wp_cache_get($subscription->get_id(), 'getpaid_subscriptions');
101 101
 
102 102
 		// If not found, retrieve from the db.
103
-		if ( false === $raw_subscription ) {
103
+		if (false === $raw_subscription) {
104 104
 
105 105
 			$raw_subscription = $wpdb->get_row(
106 106
 				$wpdb->prepare(
@@ -110,22 +110,22 @@  discard block
 block discarded – undo
110 110
 			);
111 111
 
112 112
 			// Update the cache with our data
113
-			wp_cache_set( $subscription->get_id(), $raw_subscription, 'getpaid_subscriptions' );
113
+			wp_cache_set($subscription->get_id(), $raw_subscription, 'getpaid_subscriptions');
114 114
 
115 115
 		}
116 116
 
117
-		if ( ! $raw_subscription ) {
118
-			$subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
117
+		if (!$raw_subscription) {
118
+			$subscription->last_error = __('Invalid subscription ID.', 'invoicing');
119 119
 			return false;
120 120
 		}
121 121
 
122
-		foreach ( array_keys( $this->database_fields_to_data_type ) as $key ) {
123
-			$method     = "set_$key";
124
-			$subscription->$method( $raw_subscription->$key );
122
+		foreach (array_keys($this->database_fields_to_data_type) as $key) {
123
+			$method = "set_$key";
124
+			$subscription->$method($raw_subscription->$key);
125 125
 		}
126 126
 
127
-		$subscription->set_object_read( true );
128
-		do_action( 'getpaid_read_subscription', $subscription );
127
+		$subscription->set_object_read(true);
128
+		do_action('getpaid_read_subscription', $subscription);
129 129
 
130 130
 	}
131 131
 
@@ -134,22 +134,22 @@  discard block
 block discarded – undo
134 134
 	 *
135 135
 	 * @param WPInv_Subscription $subscription Subscription object.
136 136
 	 */
137
-	public function update( &$subscription ) {
137
+	public function update(&$subscription) {
138 138
 		global $wpdb;
139 139
 
140 140
 		$changes = $subscription->get_changes();
141 141
 		$values  = array();
142 142
 		$format  = array();
143 143
 
144
-		foreach ( $this->database_fields_to_data_type as $key => $format ) {
145
-			if ( array_key_exists( $key, $changes ) ) {
144
+		foreach ($this->database_fields_to_data_type as $key => $format) {
145
+			if (array_key_exists($key, $changes)) {
146 146
 				$method       = "get_$key";
147
-				$values[$key] = $subscription->$method( 'edit' );
147
+				$values[$key] = $subscription->$method('edit');
148 148
 				$formats[]    = $format;
149 149
 			}
150 150
 		}
151 151
 
152
-		if ( empty( $values ) ) {
152
+		if (empty($values)) {
153 153
 			return;
154 154
 		}
155 155
 
@@ -169,10 +169,10 @@  discard block
 block discarded – undo
169 169
 		// Delete cache.
170 170
 		$subscription->clear_cache();
171 171
 
172
-		update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id', $subscription->get_profile_id() );
172
+		update_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id', $subscription->get_profile_id());
173 173
 
174 174
 		// Fire a hook.
175
-		do_action( 'getpaid_update_subscription', $subscription );
175
+		do_action('getpaid_update_subscription', $subscription);
176 176
 
177 177
 	}
178 178
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 	 *
182 182
 	 * @param WPInv_Subscription $subscription
183 183
 	 */
184
-	public function delete( &$subscription ) {
184
+	public function delete(&$subscription) {
185 185
 		global $wpdb;
186 186
 
187 187
 		$wpdb->query(
@@ -192,16 +192,16 @@  discard block
 block discarded – undo
192 192
 			)
193 193
 		);
194 194
 
195
-		delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id' );
196
-		delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id' );
195
+		delete_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id');
196
+		delete_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscription_id');
197 197
 
198 198
 		// Delete cache.
199 199
 		$subscription->clear_cache();
200 200
 
201 201
 		// Fire a hook.
202
-		do_action( 'getpaid_delete_subscription', $subscription );
202
+		do_action('getpaid_delete_subscription', $subscription);
203 203
 
204
-		$subscription->set_id( 0 );
204
+		$subscription->set_id(0);
205 205
 	}
206 206
 
207 207
 	/*
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-invoice-data-store.php 2 patches
Indentation   +443 added lines, -443 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,512 +15,512 @@  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_subscription_id',
27
-		'_wpinv_taxes',
28
-		'_wpinv_fees',
29
-		'_wpinv_discounts',
30
-		'_wpinv_submission_id',
31
-		'_wpinv_payment_form',
32
-		'_wpinv_is_viewed',
33
-		'wpinv_email_cc',
34
-		'wpinv_template'
35
-	);
36
-
37
-	/**
38
-	 * A map of meta keys to data props.
39
-	 *
40
-	 * @since 1.0.19
41
-	 *
42
-	 * @var array
43
-	 */
44
-	protected $meta_key_to_props = array(
45
-		'_wpinv_subscr_profile_id' => 'remote_subscription_id',
46
-		'_wpinv_subscription_id'   => 'subscription_id',
47
-		'_wpinv_taxes'             => 'taxes',
48
-		'_wpinv_fees'              => 'fees',
49
-		'_wpinv_discounts'         => 'discounts',
50
-		'_wpinv_submission_id'     => 'submission_id',
51
-		'_wpinv_payment_form'      => 'payment_form',
52
-		'_wpinv_is_viewed'         => 'is_viewed',
53
-		'wpinv_email_cc'           => 'email_cc',
54
-		'wpinv_template'           => 'template',
55
-	);
56
-
57
-	/**
58
-	 * A map of database fields to data props.
59
-	 *
60
-	 * @since 1.0.19
61
-	 *
62
-	 * @var array
63
-	 */
64
-	protected $database_fields_to_props = array(
65
-		'post_id'            => 'id',
66
-		'number'             => 'number',
67
-		'currency'           => 'currency',
68
-		'key'                => 'key',
69
-		'type'               => 'type',
70
-		'mode'               => 'mode',
71
-		'user_ip'            => 'user_ip',
72
-		'first_name'         => 'first_name',
73
-		'last_name'          => 'last_name',
74
-		'address'            => 'address',
75
-		'city'               => 'city',
76
-		'state'              => 'state',
77
-		'country'            => 'country',
78
-		'zip'                => 'zip',
79
-		'zip'                => 'zip',
80
-		'adddress_confirmed' => 'address_confirmed',
81
-		'gateway'            => 'gateway',
82
-		'transaction_id'     => 'transaction_id',
83
-		'currency'           => 'currency',
84
-		'subtotal'           => 'subtotal',
85
-		'tax'                => 'total_tax',
86
-		'fees_total'         => 'total_fees',
87
-		'discount'           => 'total_discount',
88
-		'total'              => 'total',
89
-		'discount_code'      => 'discount_code',
90
-		'disable_taxes'      => 'disable_taxes',
91
-		'due_date'           => 'due_date',
92
-		'completed_date'     => 'completed_date',
93
-		'company'            => 'company',
94
-		'vat_number'         => 'vat_number',
95
-		'vat_rate'           => 'vat_rate',
96
-	);
97
-
98
-	/*
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_subscription_id',
27
+        '_wpinv_taxes',
28
+        '_wpinv_fees',
29
+        '_wpinv_discounts',
30
+        '_wpinv_submission_id',
31
+        '_wpinv_payment_form',
32
+        '_wpinv_is_viewed',
33
+        'wpinv_email_cc',
34
+        'wpinv_template'
35
+    );
36
+
37
+    /**
38
+     * A map of meta keys to data props.
39
+     *
40
+     * @since 1.0.19
41
+     *
42
+     * @var array
43
+     */
44
+    protected $meta_key_to_props = array(
45
+        '_wpinv_subscr_profile_id' => 'remote_subscription_id',
46
+        '_wpinv_subscription_id'   => 'subscription_id',
47
+        '_wpinv_taxes'             => 'taxes',
48
+        '_wpinv_fees'              => 'fees',
49
+        '_wpinv_discounts'         => 'discounts',
50
+        '_wpinv_submission_id'     => 'submission_id',
51
+        '_wpinv_payment_form'      => 'payment_form',
52
+        '_wpinv_is_viewed'         => 'is_viewed',
53
+        'wpinv_email_cc'           => 'email_cc',
54
+        'wpinv_template'           => 'template',
55
+    );
56
+
57
+    /**
58
+     * A map of database fields to data props.
59
+     *
60
+     * @since 1.0.19
61
+     *
62
+     * @var array
63
+     */
64
+    protected $database_fields_to_props = array(
65
+        'post_id'            => 'id',
66
+        'number'             => 'number',
67
+        'currency'           => 'currency',
68
+        'key'                => 'key',
69
+        'type'               => 'type',
70
+        'mode'               => 'mode',
71
+        'user_ip'            => 'user_ip',
72
+        'first_name'         => 'first_name',
73
+        'last_name'          => 'last_name',
74
+        'address'            => 'address',
75
+        'city'               => 'city',
76
+        'state'              => 'state',
77
+        'country'            => 'country',
78
+        'zip'                => 'zip',
79
+        'zip'                => 'zip',
80
+        'adddress_confirmed' => 'address_confirmed',
81
+        'gateway'            => 'gateway',
82
+        'transaction_id'     => 'transaction_id',
83
+        'currency'           => 'currency',
84
+        'subtotal'           => 'subtotal',
85
+        'tax'                => 'total_tax',
86
+        'fees_total'         => 'total_fees',
87
+        'discount'           => 'total_discount',
88
+        'total'              => 'total',
89
+        'discount_code'      => 'discount_code',
90
+        'disable_taxes'      => 'disable_taxes',
91
+        'due_date'           => 'due_date',
92
+        'completed_date'     => 'completed_date',
93
+        'company'            => 'company',
94
+        'vat_number'         => 'vat_number',
95
+        'vat_rate'           => 'vat_rate',
96
+    );
97
+
98
+    /*
99 99
 	|--------------------------------------------------------------------------
100 100
 	| CRUD Methods
101 101
 	|--------------------------------------------------------------------------
102 102
 	*/
103
-	/**
104
-	 * Method to create a new invoice in the database.
105
-	 *
106
-	 * @param WPInv_Invoice $invoice Invoice object.
107
-	 */
108
-	public function create( &$invoice ) {
109
-		$invoice->set_version( WPINV_VERSION );
110
-		$invoice->set_date_created( current_time('mysql') );
111
-
112
-		// Create a new post.
113
-		$id = wp_insert_post(
114
-			apply_filters(
115
-				'getpaid_new_invoice_data',
116
-				array(
117
-					'post_date'     => $invoice->get_date_created( 'edit' ),
118
-					'post_type'     => $invoice->get_post_type( 'edit' ),
119
-					'post_status'   => $this->get_post_status( $invoice ),
120
-					'ping_status'   => 'closed',
121
-					'post_author'   => $invoice->get_user_id( 'edit' ),
122
-					'post_title'    => $invoice->get_title( 'edit' ),
123
-					'post_excerpt'  => $invoice->get_description( 'edit' ),
124
-					'post_parent'   => $invoice->get_parent_id( 'edit' ),
125
-					'post_name'     => $invoice->get_path( 'edit' ),
126
-				)
127
-			),
128
-			true
129
-		);
130
-
131
-		if ( $id && ! is_wp_error( $id ) ) {
132
-
133
-			// Update the new id and regenerate a title.
134
-			$invoice->set_id( $id );
135
-			wp_update_post( array( 'ID' => $invoice->get_id(), 'post_title' => $invoice->get_number( 'edit' ) ) );
136
-
137
-			// Ensure both the key and number are set.
138
-			$invoice->get_key();
139
-			$invoice->get_number();
140
-
141
-			// Save special fields and items.
142
-			$this->save_special_fields( $invoice );
143
-			$this->save_items( $invoice );
144
-
145
-			// Update meta data.
146
-			$this->update_post_meta( $invoice );
147
-			$invoice->save_meta_data();
148
-
149
-			// Apply changes.
150
-			$invoice->apply_changes();
151
-			$this->clear_caches( $invoice );
152
-
153
-			// Fires after a new invoice is created.
154
-			do_action( 'getpaid_new_' . $invoice->get_type(), $invoice );
155
-			return true;
156
-		}
157
-
158
-		if ( is_wp_error( $id ) ) {
159
-			$invoice->last_error = $id->get_error_message();
160
-		}
161
-
162
-		return false;
163
-	}
164
-
165
-	/**
166
-	 * Method to read an invoice from the database.
167
-	 *
168
-	 * @param WPInv_Invoice $invoice Invoice object.
169
-	 *
170
-	 */
171
-	public function read( &$invoice ) {
172
-
173
-		$invoice->set_defaults();
174
-		$invoice_object = get_post( $invoice->get_id() );
175
-
176
-		if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
177
-			$invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
178
-			$invoice->set_id( 0 );
179
-			return false;
180
-		}
181
-
182
-		$invoice->set_props(
183
-			array(
184
-				'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
185
-				'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
186
-				'status'        => $invoice_object->post_status,
187
-				'author'        => $invoice_object->post_author,
188
-				'description'   => $invoice_object->post_excerpt,
189
-				'parent_id'     => $invoice_object->post_parent,
190
-				'name'          => $invoice_object->post_title,
191
-				'path'          => $invoice_object->post_name,
192
-				'post_type'     => $invoice_object->post_type,
193
-			)
194
-		);
195
-
196
-		$invoice->set_type( $invoice_object->post_type );
197
-
198
-		$this->read_object_data( $invoice, $invoice_object );
199
-		$this->add_special_fields( $invoice );
200
-		$this->add_items( $invoice );
201
-		$invoice->read_meta_data();
202
-		$invoice->set_object_read( true );
203
-		do_action( 'getpaid_read_' . $invoice->get_type(), $invoice );
204
-
205
-	}
206
-
207
-	/**
208
-	 * Method to update an invoice in the database.
209
-	 *
210
-	 * @param WPInv_Invoice $invoice Invoice object.
211
-	 */
212
-	public function update( &$invoice ) {
213
-		$invoice->save_meta_data();
214
-		$invoice->set_version( WPINV_VERSION );
215
-
216
-		if ( null === $invoice->get_date_created( 'edit' ) ) {
217
-			$invoice->set_date_created(  current_time('mysql') );
218
-		}
219
-
220
-		// Ensure both the key and number are set.
221
-		$invoice->get_key();
222
-		$invoice->get_number();
223
-
224
-		// Grab the current status so we can compare.
225
-		$previous_status = get_post_status( $invoice->get_id() );
226
-
227
-		$changes = $invoice->get_changes();
228
-
229
-		// Only update the post when the post data changes.
230
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
231
-			$post_data = array(
232
-				'post_date'         => $invoice->get_date_created( 'edit' ),
233
-				'post_date_gmt'     => $invoice->get_date_created_gmt( 'edit' ),
234
-				'post_status'       => $invoice->get_status( 'edit' ),
235
-				'post_title'        => $invoice->get_name( 'edit' ),
236
-				'post_author'       => $invoice->get_user_id( 'edit' ),
237
-				'post_modified'     => $invoice->get_date_modified( 'edit' ),
238
-				'post_excerpt'      => $invoice->get_description( 'edit' ),
239
-				'post_parent'       => $invoice->get_parent_id( 'edit' ),
240
-				'post_name'         => $invoice->get_path( 'edit' ),
241
-				'post_type'         => $invoice->get_post_type( 'edit' ),
242
-			);
243
-
244
-			/**
245
-			 * When updating this object, to prevent infinite loops, use $wpdb
246
-			 * to update data, since wp_update_post spawns more calls to the
247
-			 * save_post action.
248
-			 *
249
-			 * This ensures hooks are fired by either WP itself (admin screen save),
250
-			 * or an update purely from CRUD.
251
-			 */
252
-			if ( doing_action( 'save_post' ) ) {
253
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
254
-				clean_post_cache( $invoice->get_id() );
255
-			} else {
256
-				wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
257
-			}
258
-			$invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
259
-		}
260
-
261
-		// Update meta data.
262
-		$this->update_post_meta( $invoice );
263
-
264
-		// Save special fields and items.
265
-		$this->save_special_fields( $invoice );
266
-		$this->save_items( $invoice );
267
-
268
-		// Apply the changes.
269
-		$invoice->apply_changes();
270
-
271
-		// Clear caches.
272
-		$this->clear_caches( $invoice );
273
-
274
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
275
-		$new_status = $invoice->get_status( 'edit' );
276
-
277
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
278
-			do_action( 'getpaid_new_' . $invoice->get_type(), $invoice );
279
-		} else {
280
-			do_action( 'getpaid_update_' . $invoice->get_type(), $invoice );
281
-		}
282
-
283
-	}
284
-
285
-	/*
103
+    /**
104
+     * Method to create a new invoice in the database.
105
+     *
106
+     * @param WPInv_Invoice $invoice Invoice object.
107
+     */
108
+    public function create( &$invoice ) {
109
+        $invoice->set_version( WPINV_VERSION );
110
+        $invoice->set_date_created( current_time('mysql') );
111
+
112
+        // Create a new post.
113
+        $id = wp_insert_post(
114
+            apply_filters(
115
+                'getpaid_new_invoice_data',
116
+                array(
117
+                    'post_date'     => $invoice->get_date_created( 'edit' ),
118
+                    'post_type'     => $invoice->get_post_type( 'edit' ),
119
+                    'post_status'   => $this->get_post_status( $invoice ),
120
+                    'ping_status'   => 'closed',
121
+                    'post_author'   => $invoice->get_user_id( 'edit' ),
122
+                    'post_title'    => $invoice->get_title( 'edit' ),
123
+                    'post_excerpt'  => $invoice->get_description( 'edit' ),
124
+                    'post_parent'   => $invoice->get_parent_id( 'edit' ),
125
+                    'post_name'     => $invoice->get_path( 'edit' ),
126
+                )
127
+            ),
128
+            true
129
+        );
130
+
131
+        if ( $id && ! is_wp_error( $id ) ) {
132
+
133
+            // Update the new id and regenerate a title.
134
+            $invoice->set_id( $id );
135
+            wp_update_post( array( 'ID' => $invoice->get_id(), 'post_title' => $invoice->get_number( 'edit' ) ) );
136
+
137
+            // Ensure both the key and number are set.
138
+            $invoice->get_key();
139
+            $invoice->get_number();
140
+
141
+            // Save special fields and items.
142
+            $this->save_special_fields( $invoice );
143
+            $this->save_items( $invoice );
144
+
145
+            // Update meta data.
146
+            $this->update_post_meta( $invoice );
147
+            $invoice->save_meta_data();
148
+
149
+            // Apply changes.
150
+            $invoice->apply_changes();
151
+            $this->clear_caches( $invoice );
152
+
153
+            // Fires after a new invoice is created.
154
+            do_action( 'getpaid_new_' . $invoice->get_type(), $invoice );
155
+            return true;
156
+        }
157
+
158
+        if ( is_wp_error( $id ) ) {
159
+            $invoice->last_error = $id->get_error_message();
160
+        }
161
+
162
+        return false;
163
+    }
164
+
165
+    /**
166
+     * Method to read an invoice from the database.
167
+     *
168
+     * @param WPInv_Invoice $invoice Invoice object.
169
+     *
170
+     */
171
+    public function read( &$invoice ) {
172
+
173
+        $invoice->set_defaults();
174
+        $invoice_object = get_post( $invoice->get_id() );
175
+
176
+        if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
177
+            $invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
178
+            $invoice->set_id( 0 );
179
+            return false;
180
+        }
181
+
182
+        $invoice->set_props(
183
+            array(
184
+                'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
185
+                'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
186
+                'status'        => $invoice_object->post_status,
187
+                'author'        => $invoice_object->post_author,
188
+                'description'   => $invoice_object->post_excerpt,
189
+                'parent_id'     => $invoice_object->post_parent,
190
+                'name'          => $invoice_object->post_title,
191
+                'path'          => $invoice_object->post_name,
192
+                'post_type'     => $invoice_object->post_type,
193
+            )
194
+        );
195
+
196
+        $invoice->set_type( $invoice_object->post_type );
197
+
198
+        $this->read_object_data( $invoice, $invoice_object );
199
+        $this->add_special_fields( $invoice );
200
+        $this->add_items( $invoice );
201
+        $invoice->read_meta_data();
202
+        $invoice->set_object_read( true );
203
+        do_action( 'getpaid_read_' . $invoice->get_type(), $invoice );
204
+
205
+    }
206
+
207
+    /**
208
+     * Method to update an invoice in the database.
209
+     *
210
+     * @param WPInv_Invoice $invoice Invoice object.
211
+     */
212
+    public function update( &$invoice ) {
213
+        $invoice->save_meta_data();
214
+        $invoice->set_version( WPINV_VERSION );
215
+
216
+        if ( null === $invoice->get_date_created( 'edit' ) ) {
217
+            $invoice->set_date_created(  current_time('mysql') );
218
+        }
219
+
220
+        // Ensure both the key and number are set.
221
+        $invoice->get_key();
222
+        $invoice->get_number();
223
+
224
+        // Grab the current status so we can compare.
225
+        $previous_status = get_post_status( $invoice->get_id() );
226
+
227
+        $changes = $invoice->get_changes();
228
+
229
+        // Only update the post when the post data changes.
230
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
231
+            $post_data = array(
232
+                'post_date'         => $invoice->get_date_created( 'edit' ),
233
+                'post_date_gmt'     => $invoice->get_date_created_gmt( 'edit' ),
234
+                'post_status'       => $invoice->get_status( 'edit' ),
235
+                'post_title'        => $invoice->get_name( 'edit' ),
236
+                'post_author'       => $invoice->get_user_id( 'edit' ),
237
+                'post_modified'     => $invoice->get_date_modified( 'edit' ),
238
+                'post_excerpt'      => $invoice->get_description( 'edit' ),
239
+                'post_parent'       => $invoice->get_parent_id( 'edit' ),
240
+                'post_name'         => $invoice->get_path( 'edit' ),
241
+                'post_type'         => $invoice->get_post_type( 'edit' ),
242
+            );
243
+
244
+            /**
245
+             * When updating this object, to prevent infinite loops, use $wpdb
246
+             * to update data, since wp_update_post spawns more calls to the
247
+             * save_post action.
248
+             *
249
+             * This ensures hooks are fired by either WP itself (admin screen save),
250
+             * or an update purely from CRUD.
251
+             */
252
+            if ( doing_action( 'save_post' ) ) {
253
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
254
+                clean_post_cache( $invoice->get_id() );
255
+            } else {
256
+                wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
257
+            }
258
+            $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
259
+        }
260
+
261
+        // Update meta data.
262
+        $this->update_post_meta( $invoice );
263
+
264
+        // Save special fields and items.
265
+        $this->save_special_fields( $invoice );
266
+        $this->save_items( $invoice );
267
+
268
+        // Apply the changes.
269
+        $invoice->apply_changes();
270
+
271
+        // Clear caches.
272
+        $this->clear_caches( $invoice );
273
+
274
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
275
+        $new_status = $invoice->get_status( 'edit' );
276
+
277
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
278
+            do_action( 'getpaid_new_' . $invoice->get_type(), $invoice );
279
+        } else {
280
+            do_action( 'getpaid_update_' . $invoice->get_type(), $invoice );
281
+        }
282
+
283
+    }
284
+
285
+    /*
286 286
 	|--------------------------------------------------------------------------
287 287
 	| Additional Methods
288 288
 	|--------------------------------------------------------------------------
289 289
 	*/
290 290
 
291
-	/**
291
+    /**
292 292
      * Retrieves special fields and adds to the invoice.
293
-	 *
294
-	 * @param WPInv_Invoice $invoice Invoice object.
293
+     *
294
+     * @param WPInv_Invoice $invoice Invoice object.
295 295
      */
296 296
     public function add_special_fields( &$invoice ) {
297
-		global $wpdb;
297
+        global $wpdb;
298 298
 
299
-		// Maybe retrieve from the cache.
300
-		$data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
299
+        // Maybe retrieve from the cache.
300
+        $data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
301 301
 
302
-		// If not found, retrieve from the db.
303
-		if ( false === $data ) {
304
-			$table =  $wpdb->prefix . 'getpaid_invoices';
302
+        // If not found, retrieve from the db.
303
+        if ( false === $data ) {
304
+            $table =  $wpdb->prefix . 'getpaid_invoices';
305 305
 
306
-			$data  = $wpdb->get_row(
307
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
308
-				ARRAY_A
309
-			);
306
+            $data  = $wpdb->get_row(
307
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
308
+                ARRAY_A
309
+            );
310 310
 
311
-			// Update the cache with our data
312
-			wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
311
+            // Update the cache with our data
312
+            wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
313 313
 
314
-		}
314
+        }
315 315
 
316
-		// Abort if the data does not exist.
317
-		if ( empty( $data ) ) {
318
-			$invoice->set_object_read( true );
319
-			$invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
320
-			return;
321
-		}
316
+        // Abort if the data does not exist.
317
+        if ( empty( $data ) ) {
318
+            $invoice->set_object_read( true );
319
+            $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
320
+            return;
321
+        }
322 322
 
323
-		$props = array();
323
+        $props = array();
324 324
 
325
-		foreach ( $this->database_fields_to_props as $db_field => $prop ) {
325
+        foreach ( $this->database_fields_to_props as $db_field => $prop ) {
326 326
 			
327
-			if ( $db_field == 'post_id' ) {
328
-				continue;
329
-			}
330
-
331
-			$props[ $prop ] = $data[ $db_field ];
332
-		}
333
-
334
-		$invoice->set_props( $props );
335
-
336
-	}
337
-
338
-	/**
339
-	 * Gets a list of special fields that need updated based on change state
340
-	 * or if they are present in the database or not.
341
-	 *
342
-	 * @param  WPInv_Invoice $invoice       The Invoice object.
343
-	 * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
344
-	 */
345
-	protected function get_special_fields_to_update( $invoice ) {
346
-		$fields_to_update = array();
347
-		$changed_props   = $invoice->get_changes();
348
-
349
-		// Props should be updated if they are a part of the $changed array or don't exist yet.
350
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
351
-			if ( array_key_exists( $prop, $changed_props ) ) {
352
-				$fields_to_update[ $database_field ] = $prop;
353
-			}
354
-		}
355
-
356
-		return $fields_to_update;
357
-	}
358
-
359
-	/**
360
-	 * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
361
-	 *
362
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
363
-	 * @since 1.0.19
364
-	 */
365
-	protected function update_special_fields( &$invoice ) {
366
-		global $wpdb;
367
-
368
-		$updated_props    = array();
369
-		$fields_to_update = $this->get_special_fields_to_update( $invoice );
370
-
371
-		foreach ( $fields_to_update as $database_field => $prop ) {
372
-			$value = $invoice->{"get_$prop"}( 'edit' );
373
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
374
-			$value = is_bool( $value ) ? ( int ) $value : $value;
375
-			$updated_props[ $database_field ] = maybe_serialize( $value );
376
-		}
377
-
378
-		if ( ! empty( $updated_props ) ) {
379
-
380
-			$table = $wpdb->prefix . 'getpaid_invoices';
381
-			$wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
382
-			wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
383
-			do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props );
384
-
385
-		}
386
-
387
-	}
388
-
389
-	/**
390
-	 * Helper method that inserts special fields to the database.
391
-	 *
392
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
393
-	 * @since 1.0.19
394
-	 */
395
-	protected function insert_special_fields( &$invoice ) {
396
-		global $wpdb;
397
-
398
-		$updated_props   = array();
399
-
400
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
401
-			$value = $invoice->{"get_$prop"}( 'edit' );
402
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
403
-			$value = is_bool( $value ) ? ( int ) $value : $value;
404
-			$updated_props[ $database_field ] = maybe_serialize( $value );
405
-		}
406
-
407
-		$table = $wpdb->prefix . 'getpaid_invoices';
408
-		$wpdb->insert( $table, $updated_props );
409
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
410
-		do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props );
411
-
412
-	}
413
-
414
-	/**
327
+            if ( $db_field == 'post_id' ) {
328
+                continue;
329
+            }
330
+
331
+            $props[ $prop ] = $data[ $db_field ];
332
+        }
333
+
334
+        $invoice->set_props( $props );
335
+
336
+    }
337
+
338
+    /**
339
+     * Gets a list of special fields that need updated based on change state
340
+     * or if they are present in the database or not.
341
+     *
342
+     * @param  WPInv_Invoice $invoice       The Invoice object.
343
+     * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
344
+     */
345
+    protected function get_special_fields_to_update( $invoice ) {
346
+        $fields_to_update = array();
347
+        $changed_props   = $invoice->get_changes();
348
+
349
+        // Props should be updated if they are a part of the $changed array or don't exist yet.
350
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
351
+            if ( array_key_exists( $prop, $changed_props ) ) {
352
+                $fields_to_update[ $database_field ] = $prop;
353
+            }
354
+        }
355
+
356
+        return $fields_to_update;
357
+    }
358
+
359
+    /**
360
+     * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
361
+     *
362
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
363
+     * @since 1.0.19
364
+     */
365
+    protected function update_special_fields( &$invoice ) {
366
+        global $wpdb;
367
+
368
+        $updated_props    = array();
369
+        $fields_to_update = $this->get_special_fields_to_update( $invoice );
370
+
371
+        foreach ( $fields_to_update as $database_field => $prop ) {
372
+            $value = $invoice->{"get_$prop"}( 'edit' );
373
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
374
+            $value = is_bool( $value ) ? ( int ) $value : $value;
375
+            $updated_props[ $database_field ] = maybe_serialize( $value );
376
+        }
377
+
378
+        if ( ! empty( $updated_props ) ) {
379
+
380
+            $table = $wpdb->prefix . 'getpaid_invoices';
381
+            $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
382
+            wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
383
+            do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props );
384
+
385
+        }
386
+
387
+    }
388
+
389
+    /**
390
+     * Helper method that inserts special fields to the database.
391
+     *
392
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
393
+     * @since 1.0.19
394
+     */
395
+    protected function insert_special_fields( &$invoice ) {
396
+        global $wpdb;
397
+
398
+        $updated_props   = array();
399
+
400
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
401
+            $value = $invoice->{"get_$prop"}( 'edit' );
402
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
403
+            $value = is_bool( $value ) ? ( int ) $value : $value;
404
+            $updated_props[ $database_field ] = maybe_serialize( $value );
405
+        }
406
+
407
+        $table = $wpdb->prefix . 'getpaid_invoices';
408
+        $wpdb->insert( $table, $updated_props );
409
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
410
+        do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props );
411
+
412
+    }
413
+
414
+    /**
415 415
      * Saves all special fields.
416
-	 *
417
-	 * @param WPInv_Invoice $invoice Invoice object.
416
+     *
417
+     * @param WPInv_Invoice $invoice Invoice object.
418 418
      */
419 419
     public function save_special_fields( $invoice ) {
420
-		global $wpdb;
420
+        global $wpdb;
421 421
 
422
-		// The invoices table.
423
-		$table = $wpdb->prefix . 'getpaid_invoices';
424
-		$id    = (int) $invoice->get_id();
422
+        // The invoices table.
423
+        $table = $wpdb->prefix . 'getpaid_invoices';
424
+        $id    = (int) $invoice->get_id();
425 425
 
426
-		if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
426
+        if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
427 427
 
428
-			$this->update_special_fields( $invoice );
428
+            $this->update_special_fields( $invoice );
429 429
 
430
-		} else {
430
+        } else {
431 431
 
432
-			$this->insert_special_fields( $invoice );
432
+            $this->insert_special_fields( $invoice );
433 433
 
434
-		}
434
+        }
435 435
 
436
-	}
436
+    }
437 437
 
438
-	/**
438
+    /**
439 439
      * Set's up cart details.
440
-	 *
441
-	 * @param WPInv_Invoice $invoice Invoice object.
440
+     *
441
+     * @param WPInv_Invoice $invoice Invoice object.
442 442
      */
443 443
     public function add_items( &$invoice ) {
444
-		global $wpdb;
444
+        global $wpdb;
445 445
 
446
-		// Maybe retrieve from the cache.
447
-		$items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
446
+        // Maybe retrieve from the cache.
447
+        $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
448 448
 
449
-		// If not found, retrieve from the db.
450
-		if ( false === $items ) {
451
-			$table =  $wpdb->prefix . 'getpaid_invoice_items';
449
+        // If not found, retrieve from the db.
450
+        if ( false === $items ) {
451
+            $table =  $wpdb->prefix . 'getpaid_invoice_items';
452 452
 
453
-			$items = $wpdb->get_results(
454
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
455
-			);
453
+            $items = $wpdb->get_results(
454
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
455
+            );
456 456
 
457
-			// Update the cache with our data
458
-			wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
457
+            // Update the cache with our data
458
+            wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
459 459
 
460
-		}
460
+        }
461 461
 
462
-		// Abort if no items found.
462
+        // Abort if no items found.
463 463
         if ( empty( $items ) ) {
464 464
             return;
465
-		}
465
+        }
466 466
 
467
-		foreach ( $items as $item_data ) {
468
-			$item = new GetPaid_Form_Item( $item_data->item_id );
467
+        foreach ( $items as $item_data ) {
468
+            $item = new GetPaid_Form_Item( $item_data->item_id );
469 469
 
470
-			// Set item data.
471
-			$item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
472
-			$item->item_discount = wpinv_sanitize_amount( $item_data->discount );
473
-			$item->set_name( $item_data->item_name );
474
-			$item->set_description( $item_data->item_description );
475
-			$item->set_price( $item_data->item_price );
476
-			$item->set_quantity( $item_data->quantity );
477
-			$item->set_item_meta( $item_data->meta );
470
+            // Set item data.
471
+            $item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
472
+            $item->item_discount = wpinv_sanitize_amount( $item_data->discount );
473
+            $item->set_name( $item_data->item_name );
474
+            $item->set_description( $item_data->item_description );
475
+            $item->set_price( $item_data->item_price );
476
+            $item->set_quantity( $item_data->quantity );
477
+            $item->set_item_meta( $item_data->meta );
478 478
 
479
-			$invoice->add_item( $item );
480
-		}
479
+            $invoice->add_item( $item );
480
+        }
481 481
 
482
-	}
482
+    }
483 483
 
484
-	/**
484
+    /**
485 485
      * Saves cart details.
486
-	 *
487
-	 * @param WPInv_Invoice $invoice Invoice object.
486
+     *
487
+     * @param WPInv_Invoice $invoice Invoice object.
488 488
      */
489 489
     public function save_items( $invoice ) {
490 490
 
491
-		// Delete previously existing items.
492
-		$this->delete_items( $invoice );
491
+        // Delete previously existing items.
492
+        $this->delete_items( $invoice );
493 493
 
494
-		$table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
494
+        $table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
495 495
 
496
-		foreach ( $invoice->get_cart_details() as $item_data ) {
497
-			$item_data = array_map( 'maybe_serialize', $item_data );
498
-			$GLOBALS['wpdb']->insert( $table, $item_data );
499
-		}
496
+        foreach ( $invoice->get_cart_details() as $item_data ) {
497
+            $item_data = array_map( 'maybe_serialize', $item_data );
498
+            $GLOBALS['wpdb']->insert( $table, $item_data );
499
+        }
500 500
 
501
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
502
-		do_action( "getpaid_invoice_save_items", $invoice );
501
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
502
+        do_action( "getpaid_invoice_save_items", $invoice );
503 503
 
504
-	}
504
+    }
505 505
 
506
-	/**
506
+    /**
507 507
      * Deletes an invoice's cart details from the database.
508
-	 *
509
-	 * @param WPInv_Invoice $invoice Invoice object.
508
+     *
509
+     * @param WPInv_Invoice $invoice Invoice object.
510 510
      */
511 511
     public function delete_items( $invoice ) {
512
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
513
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
514
-	}
512
+        $table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
513
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
514
+    }
515 515
 
516
-	/**
516
+    /**
517 517
      * Deletes an invoice's special fields from the database.
518
-	 *
519
-	 * @param WPInv_Invoice $invoice Invoice object.
518
+     *
519
+     * @param WPInv_Invoice $invoice Invoice object.
520 520
      */
521 521
     public function delete_special_fields( $invoice ) {
522
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
523
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
522
+        $table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
523
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
524 524
     }
525 525
 
526 526
 }
Please login to merge, or discard this patch.
Spacing   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * GetPaid_Invoice_Data_Store class file.
5 5
  *
6 6
  */
7
-if ( ! defined( 'ABSPATH' ) ) {
7
+if (!defined('ABSPATH')) {
8 8
 	exit;
9 9
 }
10 10
 
@@ -105,57 +105,57 @@  discard block
 block discarded – undo
105 105
 	 *
106 106
 	 * @param WPInv_Invoice $invoice Invoice object.
107 107
 	 */
108
-	public function create( &$invoice ) {
109
-		$invoice->set_version( WPINV_VERSION );
110
-		$invoice->set_date_created( current_time('mysql') );
108
+	public function create(&$invoice) {
109
+		$invoice->set_version(WPINV_VERSION);
110
+		$invoice->set_date_created(current_time('mysql'));
111 111
 
112 112
 		// Create a new post.
113 113
 		$id = wp_insert_post(
114 114
 			apply_filters(
115 115
 				'getpaid_new_invoice_data',
116 116
 				array(
117
-					'post_date'     => $invoice->get_date_created( 'edit' ),
118
-					'post_type'     => $invoice->get_post_type( 'edit' ),
119
-					'post_status'   => $this->get_post_status( $invoice ),
117
+					'post_date'     => $invoice->get_date_created('edit'),
118
+					'post_type'     => $invoice->get_post_type('edit'),
119
+					'post_status'   => $this->get_post_status($invoice),
120 120
 					'ping_status'   => 'closed',
121
-					'post_author'   => $invoice->get_user_id( 'edit' ),
122
-					'post_title'    => $invoice->get_title( 'edit' ),
123
-					'post_excerpt'  => $invoice->get_description( 'edit' ),
124
-					'post_parent'   => $invoice->get_parent_id( 'edit' ),
125
-					'post_name'     => $invoice->get_path( 'edit' ),
121
+					'post_author'   => $invoice->get_user_id('edit'),
122
+					'post_title'    => $invoice->get_title('edit'),
123
+					'post_excerpt'  => $invoice->get_description('edit'),
124
+					'post_parent'   => $invoice->get_parent_id('edit'),
125
+					'post_name'     => $invoice->get_path('edit'),
126 126
 				)
127 127
 			),
128 128
 			true
129 129
 		);
130 130
 
131
-		if ( $id && ! is_wp_error( $id ) ) {
131
+		if ($id && !is_wp_error($id)) {
132 132
 
133 133
 			// Update the new id and regenerate a title.
134
-			$invoice->set_id( $id );
135
-			wp_update_post( array( 'ID' => $invoice->get_id(), 'post_title' => $invoice->get_number( 'edit' ) ) );
134
+			$invoice->set_id($id);
135
+			wp_update_post(array('ID' => $invoice->get_id(), 'post_title' => $invoice->get_number('edit')));
136 136
 
137 137
 			// Ensure both the key and number are set.
138 138
 			$invoice->get_key();
139 139
 			$invoice->get_number();
140 140
 
141 141
 			// Save special fields and items.
142
-			$this->save_special_fields( $invoice );
143
-			$this->save_items( $invoice );
142
+			$this->save_special_fields($invoice);
143
+			$this->save_items($invoice);
144 144
 
145 145
 			// Update meta data.
146
-			$this->update_post_meta( $invoice );
146
+			$this->update_post_meta($invoice);
147 147
 			$invoice->save_meta_data();
148 148
 
149 149
 			// Apply changes.
150 150
 			$invoice->apply_changes();
151
-			$this->clear_caches( $invoice );
151
+			$this->clear_caches($invoice);
152 152
 
153 153
 			// Fires after a new invoice is created.
154
-			do_action( 'getpaid_new_' . $invoice->get_type(), $invoice );
154
+			do_action('getpaid_new_' . $invoice->get_type(), $invoice);
155 155
 			return true;
156 156
 		}
157 157
 
158
-		if ( is_wp_error( $id ) ) {
158
+		if (is_wp_error($id)) {
159 159
 			$invoice->last_error = $id->get_error_message();
160 160
 		}
161 161
 
@@ -168,14 +168,14 @@  discard block
 block discarded – undo
168 168
 	 * @param WPInv_Invoice $invoice Invoice object.
169 169
 	 *
170 170
 	 */
171
-	public function read( &$invoice ) {
171
+	public function read(&$invoice) {
172 172
 
173 173
 		$invoice->set_defaults();
174
-		$invoice_object = get_post( $invoice->get_id() );
174
+		$invoice_object = get_post($invoice->get_id());
175 175
 
176
-		if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
177
-			$invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
178
-			$invoice->set_id( 0 );
176
+		if (!$invoice->get_id() || !$invoice_object || !getpaid_is_invoice_post_type($invoice_object->post_type)) {
177
+			$invoice->last_error = __('Invalid invoice.', 'invoicing');
178
+			$invoice->set_id(0);
179 179
 			return false;
180 180
 		}
181 181
 
@@ -193,14 +193,14 @@  discard block
 block discarded – undo
193 193
 			)
194 194
 		);
195 195
 
196
-		$invoice->set_type( $invoice_object->post_type );
196
+		$invoice->set_type($invoice_object->post_type);
197 197
 
198
-		$this->read_object_data( $invoice, $invoice_object );
199
-		$this->add_special_fields( $invoice );
200
-		$this->add_items( $invoice );
198
+		$this->read_object_data($invoice, $invoice_object);
199
+		$this->add_special_fields($invoice);
200
+		$this->add_items($invoice);
201 201
 		$invoice->read_meta_data();
202
-		$invoice->set_object_read( true );
203
-		do_action( 'getpaid_read_' . $invoice->get_type(), $invoice );
202
+		$invoice->set_object_read(true);
203
+		do_action('getpaid_read_' . $invoice->get_type(), $invoice);
204 204
 
205 205
 	}
206 206
 
@@ -209,12 +209,12 @@  discard block
 block discarded – undo
209 209
 	 *
210 210
 	 * @param WPInv_Invoice $invoice Invoice object.
211 211
 	 */
212
-	public function update( &$invoice ) {
212
+	public function update(&$invoice) {
213 213
 		$invoice->save_meta_data();
214
-		$invoice->set_version( WPINV_VERSION );
214
+		$invoice->set_version(WPINV_VERSION);
215 215
 
216
-		if ( null === $invoice->get_date_created( 'edit' ) ) {
217
-			$invoice->set_date_created(  current_time('mysql') );
216
+		if (null === $invoice->get_date_created('edit')) {
217
+			$invoice->set_date_created(current_time('mysql'));
218 218
 		}
219 219
 
220 220
 		// Ensure both the key and number are set.
@@ -222,23 +222,23 @@  discard block
 block discarded – undo
222 222
 		$invoice->get_number();
223 223
 
224 224
 		// Grab the current status so we can compare.
225
-		$previous_status = get_post_status( $invoice->get_id() );
225
+		$previous_status = get_post_status($invoice->get_id());
226 226
 
227 227
 		$changes = $invoice->get_changes();
228 228
 
229 229
 		// Only update the post when the post data changes.
230
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
230
+		if (array_intersect(array('date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path'), array_keys($changes))) {
231 231
 			$post_data = array(
232
-				'post_date'         => $invoice->get_date_created( 'edit' ),
233
-				'post_date_gmt'     => $invoice->get_date_created_gmt( 'edit' ),
234
-				'post_status'       => $invoice->get_status( 'edit' ),
235
-				'post_title'        => $invoice->get_name( 'edit' ),
236
-				'post_author'       => $invoice->get_user_id( 'edit' ),
237
-				'post_modified'     => $invoice->get_date_modified( 'edit' ),
238
-				'post_excerpt'      => $invoice->get_description( 'edit' ),
239
-				'post_parent'       => $invoice->get_parent_id( 'edit' ),
240
-				'post_name'         => $invoice->get_path( 'edit' ),
241
-				'post_type'         => $invoice->get_post_type( 'edit' ),
232
+				'post_date'         => $invoice->get_date_created('edit'),
233
+				'post_date_gmt'     => $invoice->get_date_created_gmt('edit'),
234
+				'post_status'       => $invoice->get_status('edit'),
235
+				'post_title'        => $invoice->get_name('edit'),
236
+				'post_author'       => $invoice->get_user_id('edit'),
237
+				'post_modified'     => $invoice->get_date_modified('edit'),
238
+				'post_excerpt'      => $invoice->get_description('edit'),
239
+				'post_parent'       => $invoice->get_parent_id('edit'),
240
+				'post_name'         => $invoice->get_path('edit'),
241
+				'post_type'         => $invoice->get_post_type('edit'),
242 242
 			);
243 243
 
244 244
 			/**
@@ -249,35 +249,35 @@  discard block
 block discarded – undo
249 249
 			 * This ensures hooks are fired by either WP itself (admin screen save),
250 250
 			 * or an update purely from CRUD.
251 251
 			 */
252
-			if ( doing_action( 'save_post' ) ) {
253
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
254
-				clean_post_cache( $invoice->get_id() );
252
+			if (doing_action('save_post')) {
253
+				$GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $invoice->get_id()));
254
+				clean_post_cache($invoice->get_id());
255 255
 			} else {
256
-				wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
256
+				wp_update_post(array_merge(array('ID' => $invoice->get_id()), $post_data));
257 257
 			}
258
-			$invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
258
+			$invoice->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
259 259
 		}
260 260
 
261 261
 		// Update meta data.
262
-		$this->update_post_meta( $invoice );
262
+		$this->update_post_meta($invoice);
263 263
 
264 264
 		// Save special fields and items.
265
-		$this->save_special_fields( $invoice );
266
-		$this->save_items( $invoice );
265
+		$this->save_special_fields($invoice);
266
+		$this->save_items($invoice);
267 267
 
268 268
 		// Apply the changes.
269 269
 		$invoice->apply_changes();
270 270
 
271 271
 		// Clear caches.
272
-		$this->clear_caches( $invoice );
272
+		$this->clear_caches($invoice);
273 273
 
274 274
 		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
275
-		$new_status = $invoice->get_status( 'edit' );
275
+		$new_status = $invoice->get_status('edit');
276 276
 
277
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
278
-			do_action( 'getpaid_new_' . $invoice->get_type(), $invoice );
277
+		if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) {
278
+			do_action('getpaid_new_' . $invoice->get_type(), $invoice);
279 279
 		} else {
280
-			do_action( 'getpaid_update_' . $invoice->get_type(), $invoice );
280
+			do_action('getpaid_update_' . $invoice->get_type(), $invoice);
281 281
 		}
282 282
 
283 283
 	}
@@ -293,45 +293,45 @@  discard block
 block discarded – undo
293 293
 	 *
294 294
 	 * @param WPInv_Invoice $invoice Invoice object.
295 295
      */
296
-    public function add_special_fields( &$invoice ) {
296
+    public function add_special_fields(&$invoice) {
297 297
 		global $wpdb;
298 298
 
299 299
 		// Maybe retrieve from the cache.
300
-		$data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
300
+		$data = wp_cache_get($invoice->get_id(), 'getpaid_invoice_special_fields');
301 301
 
302 302
 		// If not found, retrieve from the db.
303
-		if ( false === $data ) {
304
-			$table =  $wpdb->prefix . 'getpaid_invoices';
303
+		if (false === $data) {
304
+			$table = $wpdb->prefix . 'getpaid_invoices';
305 305
 
306 306
 			$data  = $wpdb->get_row(
307
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
307
+				$wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id()),
308 308
 				ARRAY_A
309 309
 			);
310 310
 
311 311
 			// Update the cache with our data
312
-			wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
312
+			wp_cache_set($invoice->get_id(), $data, 'getpaid_invoice_special_fields');
313 313
 
314 314
 		}
315 315
 
316 316
 		// Abort if the data does not exist.
317
-		if ( empty( $data ) ) {
318
-			$invoice->set_object_read( true );
319
-			$invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
317
+		if (empty($data)) {
318
+			$invoice->set_object_read(true);
319
+			$invoice->set_props(wpinv_get_user_address($invoice->get_user_id()));
320 320
 			return;
321 321
 		}
322 322
 
323 323
 		$props = array();
324 324
 
325
-		foreach ( $this->database_fields_to_props as $db_field => $prop ) {
325
+		foreach ($this->database_fields_to_props as $db_field => $prop) {
326 326
 			
327
-			if ( $db_field == 'post_id' ) {
327
+			if ($db_field == 'post_id') {
328 328
 				continue;
329 329
 			}
330 330
 
331
-			$props[ $prop ] = $data[ $db_field ];
331
+			$props[$prop] = $data[$db_field];
332 332
 		}
333 333
 
334
-		$invoice->set_props( $props );
334
+		$invoice->set_props($props);
335 335
 
336 336
 	}
337 337
 
@@ -342,14 +342,14 @@  discard block
 block discarded – undo
342 342
 	 * @param  WPInv_Invoice $invoice       The Invoice object.
343 343
 	 * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
344 344
 	 */
345
-	protected function get_special_fields_to_update( $invoice ) {
345
+	protected function get_special_fields_to_update($invoice) {
346 346
 		$fields_to_update = array();
347
-		$changed_props   = $invoice->get_changes();
347
+		$changed_props = $invoice->get_changes();
348 348
 
349 349
 		// Props should be updated if they are a part of the $changed array or don't exist yet.
350
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
351
-			if ( array_key_exists( $prop, $changed_props ) ) {
352
-				$fields_to_update[ $database_field ] = $prop;
350
+		foreach ($this->database_fields_to_props as $database_field => $prop) {
351
+			if (array_key_exists($prop, $changed_props)) {
352
+				$fields_to_update[$database_field] = $prop;
353 353
 			}
354 354
 		}
355 355
 
@@ -362,25 +362,25 @@  discard block
 block discarded – undo
362 362
 	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
363 363
 	 * @since 1.0.19
364 364
 	 */
365
-	protected function update_special_fields( &$invoice ) {
365
+	protected function update_special_fields(&$invoice) {
366 366
 		global $wpdb;
367 367
 
368 368
 		$updated_props    = array();
369
-		$fields_to_update = $this->get_special_fields_to_update( $invoice );
369
+		$fields_to_update = $this->get_special_fields_to_update($invoice);
370 370
 
371
-		foreach ( $fields_to_update as $database_field => $prop ) {
372
-			$value = $invoice->{"get_$prop"}( 'edit' );
373
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
374
-			$value = is_bool( $value ) ? ( int ) $value : $value;
375
-			$updated_props[ $database_field ] = maybe_serialize( $value );
371
+		foreach ($fields_to_update as $database_field => $prop) {
372
+			$value = $invoice->{"get_$prop"}('edit');
373
+			$value = is_string($value) ? wp_slash($value) : $value;
374
+			$value = is_bool($value) ? (int) $value : $value;
375
+			$updated_props[$database_field] = maybe_serialize($value);
376 376
 		}
377 377
 
378
-		if ( ! empty( $updated_props ) ) {
378
+		if (!empty($updated_props)) {
379 379
 
380 380
 			$table = $wpdb->prefix . 'getpaid_invoices';
381
-			$wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
382
-			wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
383
-			do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props );
381
+			$wpdb->update($table, $updated_props, array('post_id' => $invoice->get_id()));
382
+			wp_cache_delete($invoice->get_id(), 'getpaid_invoice_special_fields');
383
+			do_action("getpaid_invoice_update_database_fields", $invoice, $updated_props);
384 384
 
385 385
 		}
386 386
 
@@ -392,22 +392,22 @@  discard block
 block discarded – undo
392 392
 	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
393 393
 	 * @since 1.0.19
394 394
 	 */
395
-	protected function insert_special_fields( &$invoice ) {
395
+	protected function insert_special_fields(&$invoice) {
396 396
 		global $wpdb;
397 397
 
398
-		$updated_props   = array();
398
+		$updated_props = array();
399 399
 
400
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
401
-			$value = $invoice->{"get_$prop"}( 'edit' );
402
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
403
-			$value = is_bool( $value ) ? ( int ) $value : $value;
404
-			$updated_props[ $database_field ] = maybe_serialize( $value );
400
+		foreach ($this->database_fields_to_props as $database_field => $prop) {
401
+			$value = $invoice->{"get_$prop"}('edit');
402
+			$value = is_string($value) ? wp_slash($value) : $value;
403
+			$value = is_bool($value) ? (int) $value : $value;
404
+			$updated_props[$database_field] = maybe_serialize($value);
405 405
 		}
406 406
 
407 407
 		$table = $wpdb->prefix . 'getpaid_invoices';
408
-		$wpdb->insert( $table, $updated_props );
409
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
410
-		do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props );
408
+		$wpdb->insert($table, $updated_props);
409
+		wp_cache_delete($invoice->get_id(), 'getpaid_invoice_special_fields');
410
+		do_action("getpaid_invoice_insert_database_fields", $invoice, $updated_props);
411 411
 
412 412
 	}
413 413
 
@@ -416,20 +416,20 @@  discard block
 block discarded – undo
416 416
 	 *
417 417
 	 * @param WPInv_Invoice $invoice Invoice object.
418 418
      */
419
-    public function save_special_fields( $invoice ) {
419
+    public function save_special_fields($invoice) {
420 420
 		global $wpdb;
421 421
 
422 422
 		// The invoices table.
423 423
 		$table = $wpdb->prefix . 'getpaid_invoices';
424 424
 		$id    = (int) $invoice->get_id();
425 425
 
426
-		if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
426
+		if ($wpdb->get_var("SELECT `post_id` FROM $table WHERE `post_id`= $id")) {
427 427
 
428
-			$this->update_special_fields( $invoice );
428
+			$this->update_special_fields($invoice);
429 429
 
430 430
 		} else {
431 431
 
432
-			$this->insert_special_fields( $invoice );
432
+			$this->insert_special_fields($invoice);
433 433
 
434 434
 		}
435 435
 
@@ -440,43 +440,43 @@  discard block
 block discarded – undo
440 440
 	 *
441 441
 	 * @param WPInv_Invoice $invoice Invoice object.
442 442
      */
443
-    public function add_items( &$invoice ) {
443
+    public function add_items(&$invoice) {
444 444
 		global $wpdb;
445 445
 
446 446
 		// Maybe retrieve from the cache.
447
-		$items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
447
+		$items = wp_cache_get($invoice->get_id(), 'getpaid_invoice_cart_details');
448 448
 
449 449
 		// If not found, retrieve from the db.
450
-		if ( false === $items ) {
451
-			$table =  $wpdb->prefix . 'getpaid_invoice_items';
450
+		if (false === $items) {
451
+			$table = $wpdb->prefix . 'getpaid_invoice_items';
452 452
 
453 453
 			$items = $wpdb->get_results(
454
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
454
+				$wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id())
455 455
 			);
456 456
 
457 457
 			// Update the cache with our data
458
-			wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
458
+			wp_cache_set($invoice->get_id(), $items, 'getpaid_invoice_cart_details');
459 459
 
460 460
 		}
461 461
 
462 462
 		// Abort if no items found.
463
-        if ( empty( $items ) ) {
463
+        if (empty($items)) {
464 464
             return;
465 465
 		}
466 466
 
467
-		foreach ( $items as $item_data ) {
468
-			$item = new GetPaid_Form_Item( $item_data->item_id );
467
+		foreach ($items as $item_data) {
468
+			$item = new GetPaid_Form_Item($item_data->item_id);
469 469
 
470 470
 			// Set item data.
471
-			$item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
472
-			$item->item_discount = wpinv_sanitize_amount( $item_data->discount );
473
-			$item->set_name( $item_data->item_name );
474
-			$item->set_description( $item_data->item_description );
475
-			$item->set_price( $item_data->item_price );
476
-			$item->set_quantity( $item_data->quantity );
477
-			$item->set_item_meta( $item_data->meta );
478
-
479
-			$invoice->add_item( $item );
471
+			$item->item_tax      = wpinv_sanitize_amount($item_data->tax);
472
+			$item->item_discount = wpinv_sanitize_amount($item_data->discount);
473
+			$item->set_name($item_data->item_name);
474
+			$item->set_description($item_data->item_description);
475
+			$item->set_price($item_data->item_price);
476
+			$item->set_quantity($item_data->quantity);
477
+			$item->set_item_meta($item_data->meta);
478
+
479
+			$invoice->add_item($item);
480 480
 		}
481 481
 
482 482
 	}
@@ -486,20 +486,20 @@  discard block
 block discarded – undo
486 486
 	 *
487 487
 	 * @param WPInv_Invoice $invoice Invoice object.
488 488
      */
489
-    public function save_items( $invoice ) {
489
+    public function save_items($invoice) {
490 490
 
491 491
 		// Delete previously existing items.
492
-		$this->delete_items( $invoice );
492
+		$this->delete_items($invoice);
493 493
 
494
-		$table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
494
+		$table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
495 495
 
496
-		foreach ( $invoice->get_cart_details() as $item_data ) {
497
-			$item_data = array_map( 'maybe_serialize', $item_data );
498
-			$GLOBALS['wpdb']->insert( $table, $item_data );
496
+		foreach ($invoice->get_cart_details() as $item_data) {
497
+			$item_data = array_map('maybe_serialize', $item_data);
498
+			$GLOBALS['wpdb']->insert($table, $item_data);
499 499
 		}
500 500
 
501
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
502
-		do_action( "getpaid_invoice_save_items", $invoice );
501
+		wp_cache_delete($invoice->get_id(), 'getpaid_invoice_cart_details');
502
+		do_action("getpaid_invoice_save_items", $invoice);
503 503
 
504 504
 	}
505 505
 
@@ -508,9 +508,9 @@  discard block
 block discarded – undo
508 508
 	 *
509 509
 	 * @param WPInv_Invoice $invoice Invoice object.
510 510
      */
511
-    public function delete_items( $invoice ) {
512
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
513
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
511
+    public function delete_items($invoice) {
512
+		$table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
513
+		return $GLOBALS['wpdb']->delete($table, array('post_id' => $invoice->get_id()));
514 514
 	}
515 515
 
516 516
 	/**
@@ -518,9 +518,9 @@  discard block
 block discarded – undo
518 518
 	 *
519 519
 	 * @param WPInv_Invoice $invoice Invoice object.
520 520
      */
521
-    public function delete_special_fields( $invoice ) {
522
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
523
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
521
+    public function delete_special_fields($invoice) {
522
+		$table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
523
+		return $GLOBALS['wpdb']->delete($table, array('post_id' => $invoice->get_id()));
524 524
     }
525 525
 
526 526
 }
Please login to merge, or discard this patch.
includes/class-wpinv-reports.php 1 patch
Spacing   +335 added lines, -335 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit; // Exit if accessed directly
4 4
 }
5 5
 
@@ -21,79 +21,79 @@  discard block
 block discarded – undo
21 21
     public function init() {
22 22
         global $wp_filesystem;
23 23
 
24
-        if ( empty( $wp_filesystem ) ) {
25
-            require_once( ABSPATH . '/wp-admin/includes/file.php' );
24
+        if (empty($wp_filesystem)) {
25
+            require_once(ABSPATH . '/wp-admin/includes/file.php');
26 26
             WP_Filesystem();
27 27
             global $wp_filesystem;
28 28
         }
29 29
         $this->wp_filesystem    = $wp_filesystem;
30 30
 
31 31
         $this->export_dir       = $this->export_location();
32
-        $this->export_url       = $this->export_location( true );
32
+        $this->export_url       = $this->export_location(true);
33 33
         $this->export           = 'invoicing';
34 34
         $this->filetype         = 'csv';
35 35
         $this->per_page         = 20;
36 36
 
37
-        do_action( 'wpinv_class_reports_init', $this );
37
+        do_action('wpinv_class_reports_init', $this);
38 38
     }
39 39
 
40 40
     public function includes() {
41
-        do_action( 'wpinv_class_reports_includes', $this );
41
+        do_action('wpinv_class_reports_includes', $this);
42 42
     }
43 43
 
44 44
     public function actions() {
45
-        if ( is_admin() ) {
46
-            add_action( 'admin_menu', array( $this, 'add_submenu' ), 20 );
47
-            add_action( 'wpinv_reports_tab_reports', array( $this, 'reports' ) );
48
-            add_action( 'wpinv_reports_tab_export', array( $this, 'export' ) );
49
-            add_action( 'wp_ajax_wpinv_ajax_export', array( $this, 'ajax_export' ) );
50
-            add_action( 'wp_ajax_wpinv_ajax_discount_use_export', array( $this, 'discount_use_export' ) );
45
+        if (is_admin()) {
46
+            add_action('admin_menu', array($this, 'add_submenu'), 20);
47
+            add_action('wpinv_reports_tab_reports', array($this, 'reports'));
48
+            add_action('wpinv_reports_tab_export', array($this, 'export'));
49
+            add_action('wp_ajax_wpinv_ajax_export', array($this, 'ajax_export'));
50
+            add_action('wp_ajax_wpinv_ajax_discount_use_export', array($this, 'discount_use_export'));
51 51
 
52 52
             // Export Invoices.
53
-            add_action( 'wpinv_export_set_params_invoices', array( $this, 'set_invoices_export' ) );
54
-            add_filter( 'wpinv_export_get_columns_invoices', array( $this, 'get_invoices_columns' ) );
55
-            add_filter( 'wpinv_export_get_data_invoices', array( $this, 'get_invoices_data' ) );
56
-            add_filter( 'wpinv_get_export_status_invoices', array( $this, 'invoices_export_status' ) );
53
+            add_action('wpinv_export_set_params_invoices', array($this, 'set_invoices_export'));
54
+            add_filter('wpinv_export_get_columns_invoices', array($this, 'get_invoices_columns'));
55
+            add_filter('wpinv_export_get_data_invoices', array($this, 'get_invoices_data'));
56
+            add_filter('wpinv_get_export_status_invoices', array($this, 'invoices_export_status'));
57 57
 
58 58
             // Reports.
59
-            add_action( 'wpinv_reports_view_earnings', array( $this, 'earnings_report' ) );
60
-            add_action( 'wpinv_reports_view_gateways', array( $this, 'gateways_report' ) );
61
-            add_action( 'wpinv_reports_view_items', array( $this, 'items_report' ) );
62
-            add_action( 'wpinv_reports_view_taxes', array( $this, 'tax_report' ) );
59
+            add_action('wpinv_reports_view_earnings', array($this, 'earnings_report'));
60
+            add_action('wpinv_reports_view_gateways', array($this, 'gateways_report'));
61
+            add_action('wpinv_reports_view_items', array($this, 'items_report'));
62
+            add_action('wpinv_reports_view_taxes', array($this, 'tax_report'));
63 63
         }
64
-        do_action( 'wpinv_class_reports_actions', $this );
64
+        do_action('wpinv_class_reports_actions', $this);
65 65
     }
66 66
 
67 67
     public function add_submenu() {
68 68
         global $wpi_reports_page;
69
-        $wpi_reports_page = add_submenu_page( 'wpinv', __( 'Reports', 'invoicing' ), __( 'Reports', 'invoicing' ), wpinv_get_capability(), 'wpinv-reports', array( $this, 'reports_page' ) );
69
+        $wpi_reports_page = add_submenu_page('wpinv', __('Reports', 'invoicing'), __('Reports', 'invoicing'), wpinv_get_capability(), 'wpinv-reports', array($this, 'reports_page'));
70 70
     }
71 71
 
72 72
     public function reports_page() {
73 73
 
74
-        if ( !wp_script_is( 'postbox', 'enqueued' ) ) {
75
-            wp_enqueue_script( 'postbox' );
74
+        if (!wp_script_is('postbox', 'enqueued')) {
75
+            wp_enqueue_script('postbox');
76 76
         }
77 77
 
78
-        if ( !wp_script_is( 'jquery-ui-datepicker', 'enqueued' ) ) {
79
-            wp_enqueue_script( 'jquery-ui-datepicker' );
78
+        if (!wp_script_is('jquery-ui-datepicker', 'enqueued')) {
79
+            wp_enqueue_script('jquery-ui-datepicker');
80 80
         }
81 81
 
82
-        $current_page = admin_url( 'admin.php?page=wpinv-reports' );
83
-        $active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports';
82
+        $current_page = admin_url('admin.php?page=wpinv-reports');
83
+        $active_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'reports';
84 84
         ?>
85 85
         <div class="wrap wpi-reports-wrap">
86
-            <h1><?php echo esc_html( __( 'Reports', 'invoicing' ) ); ?></h1>
86
+            <h1><?php echo esc_html(__('Reports', 'invoicing')); ?></h1>
87 87
             <h2 class="nav-tab-wrapper wp-clearfix">
88
-                <a href="<?php echo add_query_arg( array( 'tab' => 'reports', 'settings-updated' => false ), $current_page ); ?>" class="nav-tab <?php echo $active_tab == 'reports' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Reports', 'invoicing' ); ?></a>
89
-                <a href="<?php echo add_query_arg( array( 'tab' => 'export', 'settings-updated' => false ), $current_page ); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Export', 'invoicing' ); ?></a>
90
-                <?php do_action( 'wpinv_reports_page_tabs' ); ;?>
88
+                <a href="<?php echo add_query_arg(array('tab' => 'reports', 'settings-updated' => false), $current_page); ?>" class="nav-tab <?php echo $active_tab == 'reports' ? 'nav-tab-active' : ''; ?>"><?php _e('Reports', 'invoicing'); ?></a>
89
+                <a href="<?php echo add_query_arg(array('tab' => 'export', 'settings-updated' => false), $current_page); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e('Export', 'invoicing'); ?></a>
90
+                <?php do_action('wpinv_reports_page_tabs'); ;?>
91 91
             </h2>
92
-            <div class="wpi-reports-content wpi-reports-<?php echo esc_attr( $active_tab ); ?>">
92
+            <div class="wpi-reports-content wpi-reports-<?php echo esc_attr($active_tab); ?>">
93 93
             <?php
94
-                do_action( 'wpinv_reports_page_top' );
95
-                do_action( 'wpinv_reports_tab_' . $active_tab );
96
-                do_action( 'wpinv_reports_page_bottom' );
94
+                do_action('wpinv_reports_page_top');
95
+                do_action('wpinv_reports_tab_' . $active_tab);
96
+                do_action('wpinv_reports_page_bottom');
97 97
             ?>
98 98
             </div>
99 99
         </div>
@@ -106,139 +106,139 @@  discard block
 block discarded – undo
106 106
     public function reports() {
107 107
 
108 108
         $views = array(
109
-            'earnings'   => __( 'Earnings', 'invoicing' ),
110
-            'items'      => __( 'Items', 'invoicing' ),
111
-            'gateways'   => __( 'Payment Methods', 'invoicing' ),
112
-            'taxes'      => __( 'Taxes', 'invoicing' ),
109
+            'earnings'   => __('Earnings', 'invoicing'),
110
+            'items'      => __('Items', 'invoicing'),
111
+            'gateways'   => __('Payment Methods', 'invoicing'),
112
+            'taxes'      => __('Taxes', 'invoicing'),
113 113
         );
114 114
 
115
-        $views   = apply_filters( 'wpinv_report_views', $views );
115
+        $views   = apply_filters('wpinv_report_views', $views);
116 116
         $current = 'earnings';
117 117
 
118
-        if ( isset( $_GET['view'] ) && array_key_exists( $_GET['view'], $views ) )
118
+        if (isset($_GET['view']) && array_key_exists($_GET['view'], $views))
119 119
 		$current = $_GET['view'];
120 120
 
121 121
         ?>
122 122
 	        <form id="wpinv-reports-filter" method="get" class="tablenav">
123 123
 		        <select id="wpinv-reports-view" name="view">
124
-			        <option value="-1" disabled><?php _e( 'Report Type', 'invoicing' ); ?></option>
125
-			            <?php foreach ( $views as $view_id => $label ) : ?>
126
-				            <option value="<?php echo esc_attr( $view_id ); ?>" <?php selected( $view_id, $current ); ?>><?php echo $label; ?></option>
124
+			        <option value="-1" disabled><?php _e('Report Type', 'invoicing'); ?></option>
125
+			            <?php foreach ($views as $view_id => $label) : ?>
126
+				            <option value="<?php echo esc_attr($view_id); ?>" <?php selected($view_id, $current); ?>><?php echo $label; ?></option>
127 127
 			            <?php endforeach; ?>
128 128
 		        </select>
129 129
 
130
-		        <?php do_action( 'wpinv_report_view_actions' ); ?>
130
+		        <?php do_action('wpinv_report_view_actions'); ?>
131 131
 
132 132
 		        <input type="hidden" name="page" value="wpinv-reports"/>
133
-		        <?php submit_button( __( 'Show', 'invoicing' ), 'secondary', 'submit', false ); ?>
133
+		        <?php submit_button(__('Show', 'invoicing'), 'secondary', 'submit', false); ?>
134 134
 	        </form>
135 135
         <?php
136 136
 
137
-	    do_action( 'wpinv_reports_view_' . $current );
137
+	    do_action('wpinv_reports_view_' . $current);
138 138
 
139 139
     }
140 140
 
141 141
     public function export() {
142
-        $statuses = wpinv_get_invoice_statuses( true );
143
-        $statuses = array_merge( array( 'any' => __( 'All Statuses', 'invoicing' ) ), $statuses );
142
+        $statuses = wpinv_get_invoice_statuses(true);
143
+        $statuses = array_merge(array('any' => __('All Statuses', 'invoicing')), $statuses);
144 144
         ?>
145 145
         <div class="metabox-holder">
146 146
             <div id="post-body">
147 147
                 <div id="post-body-content">
148
-                    <?php do_action( 'wpinv_reports_tab_export_content_top' ); ?>
148
+                    <?php do_action('wpinv_reports_tab_export_content_top'); ?>
149 149
 
150 150
                     <div class="postbox wpi-export-invoices">
151
-                        <h2 class="hndle ui-sortabled-handle"><span><?php _e( 'Invoices','invoicing' ); ?></span></h2>
151
+                        <h2 class="hndle ui-sortabled-handle"><span><?php _e('Invoices', 'invoicing'); ?></span></h2>
152 152
                         <div class="inside">
153
-                            <p><?php _e( 'Download a CSV of all payment invoices.', 'invoicing' ); ?></p>
153
+                            <p><?php _e('Download a CSV of all payment invoices.', 'invoicing'); ?></p>
154 154
                             <form id="wpi-export-invoices" class="wpi-export-form" method="post">
155
-                                <?php echo wpinv_html_date_field( array(
155
+                                <?php echo wpinv_html_date_field(array(
156 156
                                     'id' => 'wpi_export_from_date',
157 157
                                     'name' => 'from_date',
158 158
                                     'data' => array(
159 159
                                         'dateFormat' => 'yy-mm-dd'
160 160
                                     ),
161
-                                    'placeholder' => __( 'From date', 'invoicing' ) )
161
+                                    'placeholder' => __('From date', 'invoicing') )
162 162
                                 ); ?>
163
-                                <?php echo wpinv_html_date_field( array(
163
+                                <?php echo wpinv_html_date_field(array(
164 164
                                     'id' => 'wpi_export_to_date',
165 165
                                     'name' => 'to_date',
166 166
                                     'data' => array(
167 167
                                         'dateFormat' => 'yy-mm-dd'
168 168
                                     ),
169
-                                    'placeholder' => __( 'To date', 'invoicing' ) )
169
+                                    'placeholder' => __('To date', 'invoicing') )
170 170
                                 ); ?>
171 171
                                 <span id="wpinv-status-wrap">
172
-                                <?php echo wpinv_html_select( array(
172
+                                <?php echo wpinv_html_select(array(
173 173
                                     'options'          => $statuses,
174 174
                                     'name'             => 'status',
175 175
                                     'id'               => 'wpi_export_status',
176 176
                                     'show_option_all'  => false,
177 177
                                     'show_option_none' => false,
178 178
                                     'class'            => 'wpi_select2',
179
-                                ) ); ?>
180
-                                <?php wp_nonce_field( 'wpi_ajax_export', 'wpi_ajax_export' ); ?>
179
+                                )); ?>
180
+                                <?php wp_nonce_field('wpi_ajax_export', 'wpi_ajax_export'); ?>
181 181
                                 </span>
182 182
                                 <span id="wpinv-submit-wrap">
183 183
                                     <input type="hidden" value="invoices" name="export" />
184
-                                    <input type="submit" value="<?php _e( 'Generate CSV', 'invoicing' ); ?>" class="button-primary" />
184
+                                    <input type="submit" value="<?php _e('Generate CSV', 'invoicing'); ?>" class="button-primary" />
185 185
                                 </span>
186 186
                             </form>
187 187
                         </div>
188 188
                     </div>
189 189
 
190 190
                     <div class="postbox wpi-export-discount-uses">
191
-                        <h2 class="hndle ui-sortabled-handle"><span><?php _e( 'Discount Use','invoicing' ); ?></span></h2>
191
+                        <h2 class="hndle ui-sortabled-handle"><span><?php _e('Discount Use', 'invoicing'); ?></span></h2>
192 192
                         <div class="inside">
193
-                            <p><?php _e( 'Download a CSV of discount uses.', 'invoicing' ); ?></p>
194
-                            <a class="button-primary" href="<?php echo esc_url( wp_nonce_url( admin_url( 'admin-ajax.php?action=wpinv_ajax_discount_use_export' ), 'wpi_discount_ajax_export', 'wpi_discount_ajax_export' ) ); ?>"><?php _e( 'Generate CSV', 'invoicing' ); ?></a>
193
+                            <p><?php _e('Download a CSV of discount uses.', 'invoicing'); ?></p>
194
+                            <a class="button-primary" href="<?php echo esc_url(wp_nonce_url(admin_url('admin-ajax.php?action=wpinv_ajax_discount_use_export'), 'wpi_discount_ajax_export', 'wpi_discount_ajax_export')); ?>"><?php _e('Generate CSV', 'invoicing'); ?></a>
195 195
                         </div>
196 196
                     </div>
197 197
 
198
-                    <?php do_action( 'wpinv_reports_tab_export_content_bottom' ); ?>
198
+                    <?php do_action('wpinv_reports_tab_export_content_bottom'); ?>
199 199
                 </div>
200 200
             </div>
201 201
         </div>
202 202
         <?php
203 203
     }
204 204
 
205
-    public function export_location( $relative = false ) {
205
+    public function export_location($relative = false) {
206 206
         $upload_dir         = wp_upload_dir();
207
-        $export_location    = $relative ? trailingslashit( $upload_dir['baseurl'] ) . 'cache' : trailingslashit( $upload_dir['basedir'] ) . 'cache';
208
-        $export_location    = apply_filters( 'wpinv_export_location', $export_location, $relative );
207
+        $export_location    = $relative ? trailingslashit($upload_dir['baseurl']) . 'cache' : trailingslashit($upload_dir['basedir']) . 'cache';
208
+        $export_location    = apply_filters('wpinv_export_location', $export_location, $relative);
209 209
 
210
-        return trailingslashit( $export_location );
210
+        return trailingslashit($export_location);
211 211
     }
212 212
 
213 213
     public function check_export_location() {
214 214
         try {
215
-            if ( empty( $this->wp_filesystem ) ) {
216
-                return __( 'Filesystem ERROR: Could not access filesystem.', 'invoicing' );
215
+            if (empty($this->wp_filesystem)) {
216
+                return __('Filesystem ERROR: Could not access filesystem.', 'invoicing');
217 217
             }
218 218
 
219
-            if ( is_wp_error( $this->wp_filesystem ) ) {
220
-                return __( 'Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing' );
219
+            if (is_wp_error($this->wp_filesystem)) {
220
+                return __('Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing');
221 221
             }
222 222
 
223
-            $is_dir         = $this->wp_filesystem->is_dir( $this->export_dir );
224
-            $is_writeable   = $is_dir && is_writeable( $this->export_dir );
223
+            $is_dir         = $this->wp_filesystem->is_dir($this->export_dir);
224
+            $is_writeable   = $is_dir && is_writeable($this->export_dir);
225 225
 
226
-            if ( $is_dir && $is_writeable ) {
226
+            if ($is_dir && $is_writeable) {
227 227
                return true;
228
-            } else if ( $is_dir && !$is_writeable ) {
229
-               if ( !$this->wp_filesystem->chmod( $this->export_dir, FS_CHMOD_DIR ) ) {
230
-                   return wp_sprintf( __( 'Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing' ), $this->export_dir );
228
+            } else if ($is_dir && !$is_writeable) {
229
+               if (!$this->wp_filesystem->chmod($this->export_dir, FS_CHMOD_DIR)) {
230
+                   return wp_sprintf(__('Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing'), $this->export_dir);
231 231
                }
232 232
 
233 233
                return true;
234 234
             } else {
235
-                if ( !$this->wp_filesystem->mkdir( $this->export_dir, FS_CHMOD_DIR ) ) {
236
-                    return wp_sprintf( __( 'Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing' ), $this->export_dir );
235
+                if (!$this->wp_filesystem->mkdir($this->export_dir, FS_CHMOD_DIR)) {
236
+                    return wp_sprintf(__('Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing'), $this->export_dir);
237 237
                 }
238 238
 
239 239
                 return true;
240 240
             }
241
-        } catch ( Exception $e ) {
241
+        } catch (Exception $e) {
242 242
             return $e->getMessage();
243 243
         }
244 244
     }
@@ -246,59 +246,59 @@  discard block
 block discarded – undo
246 246
     public function ajax_export() {
247 247
         $response               = array();
248 248
         $response['success']    = false;
249
-        $response['msg']        = __( 'Invalid export request found.', 'invoicing' );
249
+        $response['msg']        = __('Invalid export request found.', 'invoicing');
250 250
 
251
-        if ( empty( $_POST['data'] ) || ! wpinv_current_user_can_manage_invoicing() ) {
252
-            wp_send_json( $response );
251
+        if (empty($_POST['data']) || !wpinv_current_user_can_manage_invoicing()) {
252
+            wp_send_json($response);
253 253
         }
254 254
 
255
-        parse_str( $_POST['data'], $data );
255
+        parse_str($_POST['data'], $data);
256 256
 
257
-        $data['step']   = !empty( $_POST['step'] ) ? absint( $_POST['step'] ) : 1;
257
+        $data['step'] = !empty($_POST['step']) ? absint($_POST['step']) : 1;
258 258
 
259
-        $_REQUEST = (array)$data;
260
-        if ( !( !empty( $_REQUEST['wpi_ajax_export'] ) && wp_verify_nonce( $_REQUEST['wpi_ajax_export'], 'wpi_ajax_export' ) ) ) {
261
-            $response['msg']    = __( 'Security check failed.', 'invoicing' );
262
-            wp_send_json( $response );
259
+        $_REQUEST = (array) $data;
260
+        if (!(!empty($_REQUEST['wpi_ajax_export']) && wp_verify_nonce($_REQUEST['wpi_ajax_export'], 'wpi_ajax_export'))) {
261
+            $response['msg'] = __('Security check failed.', 'invoicing');
262
+            wp_send_json($response);
263 263
         }
264 264
 
265
-        if ( ( $error = $this->check_export_location( true ) ) !== true ) {
266
-            $response['msg'] = __( 'Filesystem ERROR: ' . $error, 'invoicing' );
267
-            wp_send_json( $response );
265
+        if (($error = $this->check_export_location(true)) !== true) {
266
+            $response['msg'] = __('Filesystem ERROR: ' . $error, 'invoicing');
267
+            wp_send_json($response);
268 268
         }
269 269
 
270
-        $this->set_export_params( $_REQUEST );
270
+        $this->set_export_params($_REQUEST);
271 271
 
272 272
         $return = $this->process_export_step();
273 273
         $done   = $this->get_export_status();
274 274
 
275
-        if ( $return ) {
275
+        if ($return) {
276 276
             $this->step += 1;
277 277
 
278 278
             $response['success']    = true;
279 279
             $response['msg']        = '';
280 280
 
281
-            if ( $done >= 100 ) {
281
+            if ($done >= 100) {
282 282
                 $this->step     = 'done';
283
-                $new_filename   = 'wpi-' . $this->export . '-' . date( 'y-m-d-H-i' ) . '.' . $this->filetype;
283
+                $new_filename   = 'wpi-' . $this->export . '-' . date('y-m-d-H-i') . '.' . $this->filetype;
284 284
                 $new_file       = $this->export_dir . $new_filename;
285 285
 
286
-                if ( file_exists( $this->file ) ) {
287
-                    $this->wp_filesystem->move( $this->file, $new_file, true );
286
+                if (file_exists($this->file)) {
287
+                    $this->wp_filesystem->move($this->file, $new_file, true);
288 288
                 }
289 289
 
290
-                if ( file_exists( $new_file ) ) {
291
-                    $response['data']['file'] = array( 'u' => $this->export_url . $new_filename, 's' => size_format( filesize( $new_file ), 2 ) );
290
+                if (file_exists($new_file)) {
291
+                    $response['data']['file'] = array('u' => $this->export_url . $new_filename, 's' => size_format(filesize($new_file), 2));
292 292
                 }
293 293
             }
294 294
 
295 295
             $response['data']['step']   = $this->step;
296 296
             $response['data']['done']   = $done;
297 297
         } else {
298
-            $response['msg']    = __( 'No data found for export.', 'invoicing' );
298
+            $response['msg'] = __('No data found for export.', 'invoicing');
299 299
         }
300 300
 
301
-        wp_send_json( $response );
301
+        wp_send_json($response);
302 302
     }
303 303
 
304 304
     /**
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
      */
307 307
     public function discount_use_export() {
308 308
 
309
-        if ( ! wp_verify_nonce( $_GET['wpi_discount_ajax_export'], 'wpi_discount_ajax_export' ) || ! wpinv_current_user_can_manage_invoicing() ) {
309
+        if (!wp_verify_nonce($_GET['wpi_discount_ajax_export'], 'wpi_discount_ajax_export') || !wpinv_current_user_can_manage_invoicing()) {
310 310
             wp_die( -1, 403 );
311 311
         }
312 312
 
@@ -316,115 +316,115 @@  discard block
 block discarded – undo
316 316
             'posts_per_page' => -1,
317 317
         );
318 318
 
319
-        $discounts = get_posts( $args );
319
+        $discounts = get_posts($args);
320 320
 
321
-        if ( empty( $discounts ) ) {
322
-            die ( __( 'You have not set up any discounts', 'invoicing' ) );
321
+        if (empty($discounts)) {
322
+            die (__('You have not set up any discounts', 'invoicing'));
323 323
         }
324 324
 
325
-        $output  = fopen( 'php://output', 'w' ) or die( 'Unsupported server' );
325
+        $output = fopen('php://output', 'w') or die('Unsupported server');
326 326
 
327 327
         // Let the browser know what content we're streaming and how it should save the content.
328 328
 		$name = time();
329
-		header( "Content-Type:application/csv" );
330
-        header( "Content-Disposition:attachment;filename=noptin-subscribers-$name.csv" );
329
+		header("Content-Type:application/csv");
330
+        header("Content-Disposition:attachment;filename=noptin-subscribers-$name.csv");
331 331
 
332 332
         // Output the csv column headers.
333 333
 		fputcsv(
334 334
             $output,
335 335
             array(
336
-                __( 'Discount Id', 'invoicing' ),
337
-                __( 'Discount Code', 'invoicing' ),
338
-                __( 'Discount Type', 'invoicing' ),
339
-                __( 'Discount Amount', 'invoicing' ),
340
-                __( 'Uses', 'invoicing' ),
336
+                __('Discount Id', 'invoicing'),
337
+                __('Discount Code', 'invoicing'),
338
+                __('Discount Type', 'invoicing'),
339
+                __('Discount Amount', 'invoicing'),
340
+                __('Uses', 'invoicing'),
341 341
             )
342 342
         );
343 343
 
344
-        foreach ( $discounts as $discount ) {
344
+        foreach ($discounts as $discount) {
345 345
 
346 346
             $discount = (int) $discount;
347 347
             $row      = array(
348 348
                 $discount,
349
-                get_post_meta( $discount, '_wpi_discount_code', true ),
350
-                get_post_meta( $discount, '_wpi_discount_type', true ),
351
-                get_post_meta( $discount, '_wpi_discount_amount', true ),
352
-                (int) get_post_meta( $discount, '_wpi_discount_uses', true )
349
+                get_post_meta($discount, '_wpi_discount_code', true),
350
+                get_post_meta($discount, '_wpi_discount_type', true),
351
+                get_post_meta($discount, '_wpi_discount_amount', true),
352
+                (int) get_post_meta($discount, '_wpi_discount_uses', true)
353 353
             );
354
-            fputcsv( $output, $row );
354
+            fputcsv($output, $row);
355 355
         }
356 356
 
357
-        fclose( $output );
357
+        fclose($output);
358 358
         exit;
359 359
 
360 360
     }
361 361
 
362
-    public function set_export_params( $request ) {
362
+    public function set_export_params($request) {
363 363
         $this->empty    = false;
364
-        $this->step     = !empty( $request['step'] ) ? absint( $request['step'] ) : 1;
365
-        $this->export   = !empty( $request['export'] ) ? $request['export'] : $this->export;
364
+        $this->step     = !empty($request['step']) ? absint($request['step']) : 1;
365
+        $this->export   = !empty($request['export']) ? $request['export'] : $this->export;
366 366
         $this->filename = 'wpi-' . $this->export . '-' . $request['wpi_ajax_export'] . '.' . $this->filetype;
367 367
         $this->file     = $this->export_dir . $this->filename;
368 368
 
369
-        do_action( 'wpinv_export_set_params_' . $this->export, $request );
369
+        do_action('wpinv_export_set_params_' . $this->export, $request);
370 370
     }
371 371
 
372 372
     public function get_columns() {
373 373
         $columns = array();
374 374
 
375
-        return apply_filters( 'wpinv_export_get_columns_' . $this->export, $columns );
375
+        return apply_filters('wpinv_export_get_columns_' . $this->export, $columns);
376 376
     }
377 377
 
378 378
     protected function get_export_file() {
379 379
         $file = '';
380 380
 
381
-        if ( $this->wp_filesystem->exists( $this->file ) ) {
382
-            $file = $this->wp_filesystem->get_contents( $this->file );
381
+        if ($this->wp_filesystem->exists($this->file)) {
382
+            $file = $this->wp_filesystem->get_contents($this->file);
383 383
         } else {
384
-            $this->wp_filesystem->put_contents( $this->file, '' );
384
+            $this->wp_filesystem->put_contents($this->file, '');
385 385
         }
386 386
 
387 387
         return $file;
388 388
     }
389 389
 
390
-    protected function attach_export_data( $data = '' ) {
391
-        $filedata   = $this->get_export_file();
392
-        $filedata   .= $data;
390
+    protected function attach_export_data($data = '') {
391
+        $filedata = $this->get_export_file();
392
+        $filedata .= $data;
393 393
 
394
-        $this->wp_filesystem->put_contents( $this->file, $filedata );
394
+        $this->wp_filesystem->put_contents($this->file, $filedata);
395 395
 
396
-        $rows       = file( $this->file, FILE_SKIP_EMPTY_LINES );
396
+        $rows       = file($this->file, FILE_SKIP_EMPTY_LINES);
397 397
         $columns    = $this->get_columns();
398
-        $columns    = empty( $columns ) ? 0 : 1;
398
+        $columns    = empty($columns) ? 0 : 1;
399 399
 
400
-        $this->empty = count( $rows ) == $columns ? true : false;
400
+        $this->empty = count($rows) == $columns ? true : false;
401 401
     }
402 402
 
403 403
     public function print_columns() {
404 404
         $column_data    = '';
405 405
         $columns        = $this->get_columns();
406 406
         $i              = 1;
407
-        foreach( $columns as $key => $column ) {
408
-            $column_data .= '"' . addslashes( $column ) . '"';
409
-            $column_data .= $i == count( $columns ) ? '' : ',';
407
+        foreach ($columns as $key => $column) {
408
+            $column_data .= '"' . addslashes($column) . '"';
409
+            $column_data .= $i == count($columns) ? '' : ',';
410 410
             $i++;
411 411
         }
412 412
         $column_data .= "\r\n";
413 413
 
414
-        $this->attach_export_data( $column_data );
414
+        $this->attach_export_data($column_data);
415 415
 
416 416
         return $column_data;
417 417
     }
418 418
 
419 419
     public function process_export_step() {
420
-        if ( $this->step < 2 ) {
421
-            /** @scrutinizer ignore-unhandled */ @unlink( $this->file );
420
+        if ($this->step < 2) {
421
+            /** @scrutinizer ignore-unhandled */ @unlink($this->file);
422 422
             $this->print_columns();
423 423
         }
424 424
 
425 425
         $return = $this->print_rows();
426 426
 
427
-        if ( $return ) {
427
+        if ($return) {
428 428
             return true;
429 429
         } else {
430 430
             return false;
@@ -433,14 +433,14 @@  discard block
 block discarded – undo
433 433
 
434 434
     public function get_export_status() {
435 435
         $status = 100;
436
-        return apply_filters( 'wpinv_get_export_status_' . $this->export, $status );
436
+        return apply_filters('wpinv_get_export_status_' . $this->export, $status);
437 437
     }
438 438
 
439 439
     public function get_export_data() {
440 440
         $data = array();
441 441
 
442
-        $data = apply_filters( 'wpinv_export_get_data', $data );
443
-        $data = apply_filters( 'wpinv_export_get_data_' . $this->export, $data );
442
+        $data = apply_filters('wpinv_export_get_data', $data);
443
+        $data = apply_filters('wpinv_export_get_data_' . $this->export, $data);
444 444
 
445 445
         return $data;
446 446
     }
@@ -450,20 +450,20 @@  discard block
 block discarded – undo
450 450
         $data       = $this->get_export_data();
451 451
         $columns    = $this->get_columns();
452 452
 
453
-        if ( $data ) {
454
-            foreach ( $data as $row ) {
453
+        if ($data) {
454
+            foreach ($data as $row) {
455 455
                 $i = 1;
456
-                foreach ( $row as $key => $column ) {
457
-                    if ( array_key_exists( $key, $columns ) ) {
458
-                        $row_data .= '"' . addslashes( preg_replace( "/\"/","'", $column ) ) . '"';
459
-                        $row_data .= $i == count( $columns ) ? '' : ',';
456
+                foreach ($row as $key => $column) {
457
+                    if (array_key_exists($key, $columns)) {
458
+                        $row_data .= '"' . addslashes(preg_replace("/\"/", "'", $column)) . '"';
459
+                        $row_data .= $i == count($columns) ? '' : ',';
460 460
                         $i++;
461 461
                     }
462 462
                 }
463 463
                 $row_data .= "\r\n";
464 464
             }
465 465
 
466
-            $this->attach_export_data( $row_data );
466
+            $this->attach_export_data($row_data);
467 467
 
468 468
             return $row_data;
469 469
         }
@@ -472,48 +472,48 @@  discard block
 block discarded – undo
472 472
     }
473 473
 
474 474
     // Export Invoices.
475
-    public function set_invoices_export( $request ) {
476
-        $this->from_date    = isset( $request['from_date'] ) ? sanitize_text_field( $request['from_date'] ) : '';
477
-        $this->to_date      = isset( $request['to_date'] ) ? sanitize_text_field( $request['to_date'] ) : '';
478
-        $this->status       = isset( $request['status'] ) ? sanitize_text_field( $request['status'] ) : 'publish';
475
+    public function set_invoices_export($request) {
476
+        $this->from_date    = isset($request['from_date']) ? sanitize_text_field($request['from_date']) : '';
477
+        $this->to_date      = isset($request['to_date']) ? sanitize_text_field($request['to_date']) : '';
478
+        $this->status       = isset($request['status']) ? sanitize_text_field($request['status']) : 'publish';
479 479
     }
480 480
 
481
-    public function get_invoices_columns( $columns = array() ) {
481
+    public function get_invoices_columns($columns = array()) {
482 482
         $columns = array(
483
-            'id'            => __( 'ID',   'invoicing' ),
484
-            'number'        => __( 'Number',   'invoicing' ),
485
-            'date'          => __( 'Date', 'invoicing' ),
486
-            'due_date'      => __( 'Due Date', 'invoicing' ),
487
-            'completed_date'=> __( 'Payment Done Date', 'invoicing' ),
488
-            'amount'        => __( 'Amount', 'invoicing' ),
489
-            'currency'      => __( 'Currency', 'invoicing' ),
490
-            'items'        => __( 'Items', 'invoicing' ),
491
-            'status_nicename'  => __( 'Status Nicename', 'invoicing' ),
492
-            'status'        => __( 'Status', 'invoicing' ),
493
-            'tax'           => __( 'Tax', 'invoicing' ),
494
-            'discount'      => __( 'Discount', 'invoicing' ),
495
-            'user_id'       => __( 'User ID', 'invoicing' ),
496
-            'email'         => __( 'Email', 'invoicing' ),
497
-            'first_name'    => __( 'First Name', 'invoicing' ),
498
-            'last_name'     => __( 'Last Name', 'invoicing' ),
499
-            'address'       => __( 'Address', 'invoicing' ),
500
-            'city'          => __( 'City', 'invoicing' ),
501
-            'state'         => __( 'State', 'invoicing' ),
502
-            'country'       => __( 'Country', 'invoicing' ),
503
-            'zip'           => __( 'Zipcode', 'invoicing' ),
504
-            'phone'         => __( 'Phone', 'invoicing' ),
505
-            'company'       => __( 'Company', 'invoicing' ),
506
-            'vat_number'    => __( 'Vat Number', 'invoicing' ),
507
-            'ip'            => __( 'IP', 'invoicing' ),
508
-            'gateway'       => __( 'Gateway', 'invoicing' ),
509
-            'gateway_nicename'       => __( 'Gateway Nicename', 'invoicing' ),
510
-            'transaction_id'=> __( 'Transaction ID', 'invoicing' ),
483
+            'id'            => __('ID', 'invoicing'),
484
+            'number'        => __('Number', 'invoicing'),
485
+            'date'          => __('Date', 'invoicing'),
486
+            'due_date'      => __('Due Date', 'invoicing'),
487
+            'completed_date'=> __('Payment Done Date', 'invoicing'),
488
+            'amount'        => __('Amount', 'invoicing'),
489
+            'currency'      => __('Currency', 'invoicing'),
490
+            'items'        => __('Items', 'invoicing'),
491
+            'status_nicename'  => __('Status Nicename', 'invoicing'),
492
+            'status'        => __('Status', 'invoicing'),
493
+            'tax'           => __('Tax', 'invoicing'),
494
+            'discount'      => __('Discount', 'invoicing'),
495
+            'user_id'       => __('User ID', 'invoicing'),
496
+            'email'         => __('Email', 'invoicing'),
497
+            'first_name'    => __('First Name', 'invoicing'),
498
+            'last_name'     => __('Last Name', 'invoicing'),
499
+            'address'       => __('Address', 'invoicing'),
500
+            'city'          => __('City', 'invoicing'),
501
+            'state'         => __('State', 'invoicing'),
502
+            'country'       => __('Country', 'invoicing'),
503
+            'zip'           => __('Zipcode', 'invoicing'),
504
+            'phone'         => __('Phone', 'invoicing'),
505
+            'company'       => __('Company', 'invoicing'),
506
+            'vat_number'    => __('Vat Number', 'invoicing'),
507
+            'ip'            => __('IP', 'invoicing'),
508
+            'gateway'       => __('Gateway', 'invoicing'),
509
+            'gateway_nicename'       => __('Gateway Nicename', 'invoicing'),
510
+            'transaction_id'=> __('Transaction ID', 'invoicing'),
511 511
         );
512 512
 
513 513
         return $columns;
514 514
     }
515 515
 
516
-    public function get_invoices_data( $response = array() ) {
516
+    public function get_invoices_data($response = array()) {
517 517
         $args = array(
518 518
             'limit'    => $this->per_page,
519 519
             'page'     => $this->step,
@@ -521,42 +521,42 @@  discard block
 block discarded – undo
521 521
             'orderby'  => 'date',
522 522
         );
523 523
 
524
-        if ( $this->status != 'any' ) {
524
+        if ($this->status != 'any') {
525 525
             $args['status'] = $this->status;
526 526
         } else {
527
-            $args['status'] = array_keys( wpinv_get_invoice_statuses( true ) );
527
+            $args['status'] = array_keys(wpinv_get_invoice_statuses(true));
528 528
         }
529 529
 
530
-        if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) {
530
+        if (!empty($this->from_date) || !empty($this->to_date)) {
531 531
             $args['date_query'] = array(
532 532
                 array(
533
-                    'after'     => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ),
534
-                    'before'    => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ),
533
+                    'after'     => date('Y-n-d 00:00:00', strtotime($this->from_date)),
534
+                    'before'    => date('Y-n-d 23:59:59', strtotime($this->to_date)),
535 535
                     'inclusive' => true
536 536
                 )
537 537
             );
538 538
         }
539 539
 
540
-        $invoices = wpinv_get_invoices( $args );
540
+        $invoices = wpinv_get_invoices($args);
541 541
 
542 542
         $data = array();
543 543
 
544
-        if ( !empty( $invoices ) ) {
545
-            foreach ( $invoices as $invoice ) {
544
+        if (!empty($invoices)) {
545
+            foreach ($invoices as $invoice) {
546 546
                 $items = $this->get_invoice_items($invoice);
547 547
                 $row = array(
548 548
                     'id'            => $invoice->ID,
549 549
                     'number'        => $invoice->get_number(),
550
-                    'date'          => $invoice->get_invoice_date( false ),
551
-                    'due_date'      => $invoice->get_due_date( false ),
550
+                    'date'          => $invoice->get_invoice_date(false),
551
+                    'due_date'      => $invoice->get_due_date(false),
552 552
                     'completed_date'=> $invoice->get_completed_date(),
553
-                    'amount'        => wpinv_round_amount( $invoice->get_total() ),
553
+                    'amount'        => wpinv_round_amount($invoice->get_total()),
554 554
                     'currency'      => $invoice->get_currency(),
555 555
                     'items'         => $items,
556
-                    'status_nicename' => $invoice->get_status( true ),
556
+                    'status_nicename' => $invoice->get_status(true),
557 557
                     'status'        => $invoice->get_status(),
558
-                    'tax'           => $invoice->get_tax() > 0 ? wpinv_round_amount( $invoice->get_tax() ) : '',
559
-                    'discount'      => $invoice->get_discount() > 0 ? wpinv_round_amount( $invoice->get_discount() ) : '',
558
+                    'tax'           => $invoice->get_tax() > 0 ? wpinv_round_amount($invoice->get_tax()) : '',
559
+                    'discount'      => $invoice->get_discount() > 0 ? wpinv_round_amount($invoice->get_discount()) : '',
560 560
                     'user_id'       => $invoice->get_user_id(),
561 561
                     'email'         => $invoice->get_email(),
562 562
                     'first_name'    => $invoice->get_first_name(),
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
                     'transaction_id'=> $invoice->gateway ? $invoice->get_transaction_id() : '',
576 576
                 );
577 577
 
578
-                $data[] = apply_filters( 'wpinv_export_invoice_row', $row, $invoice );
578
+                $data[] = apply_filters('wpinv_export_invoice_row', $row, $invoice);
579 579
             }
580 580
 
581 581
             return $data;
@@ -591,44 +591,44 @@  discard block
 block discarded – undo
591 591
             'return'   => 'ids',
592 592
         );
593 593
 
594
-        if ( $this->status != 'any' ) {
594
+        if ($this->status != 'any') {
595 595
             $args['status'] = $this->status;
596 596
         } else {
597
-            $args['status'] = array_keys( wpinv_get_invoice_statuses( true ) );
597
+            $args['status'] = array_keys(wpinv_get_invoice_statuses(true));
598 598
         }
599 599
 
600
-        if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) {
600
+        if (!empty($this->from_date) || !empty($this->to_date)) {
601 601
             $args['date_query'] = array(
602 602
                 array(
603
-                    'after'     => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ),
604
-                    'before'    => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ),
603
+                    'after'     => date('Y-n-d 00:00:00', strtotime($this->from_date)),
604
+                    'before'    => date('Y-n-d 23:59:59', strtotime($this->to_date)),
605 605
                     'inclusive' => true
606 606
                 )
607 607
             );
608 608
         }
609 609
 
610
-        $invoices   = wpinv_get_invoices( $args );
611
-        $total      = !empty( $invoices ) ? count( $invoices ) : 0;
610
+        $invoices   = wpinv_get_invoices($args);
611
+        $total      = !empty($invoices) ? count($invoices) : 0;
612 612
         $status     = 100;
613 613
 
614
-        if ( $total > 0 ) {
615
-            $status = ( ( $this->per_page * $this->step ) / $total ) * 100;
614
+        if ($total > 0) {
615
+            $status = (($this->per_page * $this->step) / $total) * 100;
616 616
         }
617 617
 
618
-        if ( $status > 100 ) {
618
+        if ($status > 100) {
619 619
             $status = 100;
620 620
         }
621 621
 
622 622
         return $status;
623 623
     }
624 624
 
625
-    public function get_invoice_items($invoice){
626
-        if(!$invoice){
625
+    public function get_invoice_items($invoice) {
626
+        if (!$invoice) {
627 627
             return '';
628 628
         }
629 629
 
630 630
         $cart_details = $invoice->get_cart_details();
631
-        if(!empty($cart_details)){
631
+        if (!empty($cart_details)) {
632 632
             $cart_details = maybe_serialize($cart_details);
633 633
         } else {
634 634
             $cart_details = '';
@@ -640,14 +640,14 @@  discard block
 block discarded – undo
640 640
     /**
641 641
      * Returns the periods filter.
642 642
      */
643
-    public function period_filter( $args = array() ) {
643
+    public function period_filter($args = array()) {
644 644
 
645 645
         ob_start();
646 646
 
647 647
         echo '<form id="wpinv-graphs-filter" method="get" style="margin-bottom: 10px;" class="tablenav">';
648 648
         echo '<input type="hidden" name="page" value="wpinv-reports">';
649 649
 
650
-        foreach ( $args as $key => $val ) {
650
+        foreach ($args as $key => $val) {
651 651
             $key = esc_attr($key);
652 652
             $val = esc_attr($val);
653 653
             echo "<input type='hidden' name='$key' value='$val'>";
@@ -656,21 +656,21 @@  discard block
 block discarded – undo
656 656
         echo '<select id="wpinv-graphs-date-options" name="range" style="min-width: 200px;" onChange="this.form.submit()">';
657 657
 
658 658
         $ranges = array(
659
-            'today'        => __( 'Today', 'invoicing' ),
660
-            'yesterday'    => __( 'Yesterday', 'invoicing' ),
661
-            'this_week'    => __( 'This Week', 'invoicing' ),
662
-            'last_week'    => __( 'Last Week', 'invoicing' ),
663
-            '7_days_ago'   => __( 'Last 7 Days', 'invoicing' ),
664
-            '30_days_ago'  => __( 'Last 30 Days', 'invoicing' ),
665
-            'this_month'   => __( 'This Month', 'invoicing' ),
666
-            'this_year'    => __( 'This Year', 'invoicing' ),
667
-            'last_year'    => __( 'Last Year', 'invoicing' ),
659
+            'today'        => __('Today', 'invoicing'),
660
+            'yesterday'    => __('Yesterday', 'invoicing'),
661
+            'this_week'    => __('This Week', 'invoicing'),
662
+            'last_week'    => __('Last Week', 'invoicing'),
663
+            '7_days_ago'   => __('Last 7 Days', 'invoicing'),
664
+            '30_days_ago'  => __('Last 30 Days', 'invoicing'),
665
+            'this_month'   => __('This Month', 'invoicing'),
666
+            'this_year'    => __('This Year', 'invoicing'),
667
+            'last_year'    => __('Last Year', 'invoicing'),
668 668
         );
669 669
 
670
-        $range = isset( $_GET['range'] ) && isset( $ranges[ $_GET['range'] ] ) ? $_GET['range'] : '7_days_ago';
670
+        $range = isset($_GET['range']) && isset($ranges[$_GET['range']]) ? $_GET['range'] : '7_days_ago';
671 671
 
672
-        foreach ( $ranges as $val => $label ) {
673
-            $selected = selected( $range, $val, false );
672
+        foreach ($ranges as $val => $label) {
673
+            $selected = selected($range, $val, false);
674 674
             echo "<option value='$val' $selected>$label</option>";
675 675
         }
676 676
 
@@ -682,28 +682,28 @@  discard block
 block discarded – undo
682 682
     /**
683 683
      * Returns the the current date range.
684 684
      */
685
-    public function get_sql_clauses( $range ) {
685
+    public function get_sql_clauses($range) {
686 686
 
687 687
         $date     = 'CAST(meta.completed_date AS DATE)';
688 688
         $datetime = 'meta.completed_date';
689 689
 
690 690
         // Prepare durations.
691
-        $today                = current_time( 'Y-m-d' );
692
-        $yesterday            = date( 'Y-m-d', strtotime( '-1 day', current_time( 'timestamp' ) ) );
693
-        $sunday               = date( 'Y-m-d', strtotime( 'sunday this week', current_time( 'timestamp' ) ) );
694
-        $monday               = date( 'Y-m-d', strtotime( 'monday this week', current_time( 'timestamp' ) ) );
695
-        $last_sunday          = date( 'Y-m-d', strtotime( 'sunday last week', current_time( 'timestamp' ) ) );
696
-        $last_monday          = date( 'Y-m-d', strtotime( 'monday last week', current_time( 'timestamp' ) ) );
697
-        $seven_days_ago       = date( 'Y-m-d', strtotime( '-7 days', current_time( 'timestamp' ) ) );
698
-        $thirty_days_ago      = date( 'Y-m-d', strtotime( '-30 days', current_time( 'timestamp' ) ) );
699
-        $first_day_month  	  = date( 'Y-m-1', current_time( 'timestamp' ) );
700
-        $last_day_month  	  = date( 'Y-m-t', current_time( 'timestamp' ) );
701
-		$first_day_last_month = date( 'Y-m-d', strtotime( 'first day of last month', current_time( 'timestamp' ) ) );
702
-        $last_day_last_month  = date( 'Y-m-d', strtotime( 'last day of last month', current_time( 'timestamp' ) ) );
703
-        $first_day_year  	  = date( 'Y-1-1', current_time( 'timestamp' ) );
704
-        $last_day_year  	  = date( 'Y-12-31', current_time( 'timestamp' ) );
705
-		$first_day_last_year  = date( 'Y-m-d', strtotime( 'first day of last year', current_time( 'timestamp' ) ) );
706
-		$last_day_last_year   = date( 'Y-m-d', strtotime( 'last day of last year', current_time( 'timestamp' ) ) );
691
+        $today                = current_time('Y-m-d');
692
+        $yesterday            = date('Y-m-d', strtotime('-1 day', current_time('timestamp')));
693
+        $sunday               = date('Y-m-d', strtotime('sunday this week', current_time('timestamp')));
694
+        $monday               = date('Y-m-d', strtotime('monday this week', current_time('timestamp')));
695
+        $last_sunday          = date('Y-m-d', strtotime('sunday last week', current_time('timestamp')));
696
+        $last_monday          = date('Y-m-d', strtotime('monday last week', current_time('timestamp')));
697
+        $seven_days_ago       = date('Y-m-d', strtotime('-7 days', current_time('timestamp')));
698
+        $thirty_days_ago      = date('Y-m-d', strtotime('-30 days', current_time('timestamp')));
699
+        $first_day_month = date('Y-m-1', current_time('timestamp'));
700
+        $last_day_month  	  = date('Y-m-t', current_time('timestamp'));
701
+		$first_day_last_month = date('Y-m-d', strtotime('first day of last month', current_time('timestamp')));
702
+        $last_day_last_month = date('Y-m-d', strtotime('last day of last month', current_time('timestamp')));
703
+        $first_day_year  	  = date('Y-1-1', current_time('timestamp'));
704
+        $last_day_year = date('Y-12-31', current_time('timestamp'));
705
+		$first_day_last_year  = date('Y-m-d', strtotime('first day of last year', current_time('timestamp')));
706
+		$last_day_last_year   = date('Y-m-d', strtotime('last day of last year', current_time('timestamp')));
707 707
 
708 708
         $ranges = array(
709 709
 
@@ -759,21 +759,21 @@  discard block
 block discarded – undo
759 759
 
760 760
         );
761 761
 
762
-        if ( ! isset( $ranges[ $range ] ) ) {
762
+        if (!isset($ranges[$range])) {
763 763
             return $ranges['7_days_ago'];
764 764
         }
765
-        return $ranges[ $range ];
765
+        return $ranges[$range];
766 766
 
767 767
     }
768 768
 
769 769
     /**
770 770
      * Returns the the current date ranges results.
771 771
      */
772
-    public function get_report_results( $range ) {
772
+    public function get_report_results($range) {
773 773
         global $wpdb;
774 774
 
775 775
         $table   = $wpdb->prefix . 'getpaid_invoices';
776
-        $clauses = $this->get_sql_clauses( $range );
776
+        $clauses = $this->get_sql_clauses($range);
777 777
         $sql     = "SELECT
778 778
                 {$clauses[0]} AS completed_date,
779 779
                 SUM( meta.total ) AS total,
@@ -789,30 +789,30 @@  discard block
 block discarded – undo
789 789
             GROUP BY {$clauses[0]}
790 790
         ";
791 791
 
792
-        return $wpdb->get_results( $sql );
792
+        return $wpdb->get_results($sql);
793 793
     }
794 794
 
795 795
     /**
796 796
      * Fill nulls.
797 797
      */
798
-    public function fill_nulls( $data, $range ) {
798
+    public function fill_nulls($data, $range) {
799 799
 
800 800
         $return = array();
801 801
         $time   = current_time('timestamp');
802 802
 
803
-        switch ( $range ) {
803
+        switch ($range) {
804 804
             case 'today' :
805 805
             case 'yesterday' :
806
-                $hour  = 0;
806
+                $hour = 0;
807 807
 
808
-                while ( $hour < 23 ) {
808
+                while ($hour < 23) {
809 809
                     $amount = 0;
810
-                    if ( isset( $data[$hour] ) ) {
811
-                        $amount = floatval( $data[$hour] );
810
+                    if (isset($data[$hour])) {
811
+                        $amount = floatval($data[$hour]);
812 812
                     }
813 813
 
814
-                    $time = strtotime( "$range $hour:00:00" ) * 1000;
815
-                    $return[] = array( $time, $amount );
814
+                    $time = strtotime("$range $hour:00:00") * 1000;
815
+                    $return[] = array($time, $amount);
816 816
                     $hour++;
817 817
                 }
818 818
 
@@ -820,24 +820,24 @@  discard block
 block discarded – undo
820 820
 
821 821
             case 'this_month' :
822 822
             case 'last_month' :
823
-                $_range = str_replace( '_', ' ', $range );
824
-                $month  = date( 'n', strtotime( $_range, $time ) );
825
-                $year   = date( 'Y', strtotime( $_range, $time ) );
823
+                $_range = str_replace('_', ' ', $range);
824
+                $month  = date('n', strtotime($_range, $time));
825
+                $year   = date('Y', strtotime($_range, $time));
826 826
                 $days   = cal_days_in_month(
827
-                    defined( 'CAL_GREGORIAN' ) ? CAL_GREGORIAN : 1,
827
+                    defined('CAL_GREGORIAN') ? CAL_GREGORIAN : 1,
828 828
                     $month,
829 829
                     $year
830 830
                 );
831 831
 
832 832
                 $day = 1;
833
-                while ( $days != $day ) {
833
+                while ($days != $day) {
834 834
                     $amount = 0;
835
-                    if ( isset( $data[$day] ) ) {
836
-                        $amount = floatval( $data[$day] );
835
+                    if (isset($data[$day])) {
836
+                        $amount = floatval($data[$day]);
837 837
                     }
838 838
 
839
-                    $time = strtotime( "$year-$month-$day" ) * 1000;
840
-                    $return[] = array( $time, $amount );
839
+                    $time = strtotime("$year-$month-$day") * 1000;
840
+                    $return[] = array($time, $amount);
841 841
                     $day++;
842 842
                 }
843 843
 
@@ -845,52 +845,52 @@  discard block
 block discarded – undo
845 845
 
846 846
             case 'this_week' :
847 847
             case 'last_week' :
848
-                $_range = str_replace( '_', ' ', $range );
849
-                $days   = array( 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday' );
848
+                $_range = str_replace('_', ' ', $range);
849
+                $days   = array('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday');
850 850
 
851
-                foreach ( $days as $day ) {
851
+                foreach ($days as $day) {
852 852
 
853 853
                     $amount = 0;
854
-                    if ( isset( $data[ ucfirst( $day ) ] ) ) {
855
-                        $amount = floatval( $data[ ucfirst( $day ) ] );
854
+                    if (isset($data[ucfirst($day)])) {
855
+                        $amount = floatval($data[ucfirst($day)]);
856 856
                     }
857 857
 
858
-                    $time = strtotime( "$_range $day" ) * 1000;
859
-                    $return[] = array( $time, $amount );
858
+                    $time = strtotime("$_range $day") * 1000;
859
+                    $return[] = array($time, $amount);
860 860
                 }
861 861
 
862 862
                 break;
863 863
 
864 864
             case 'this_year' :
865 865
             case 'last_year' :
866
-                $_range = str_replace( '_', ' ', $range );
867
-                $year   = date( 'Y', strtotime( $_range, $time ) );
868
-                $months = array( '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12' );
866
+                $_range = str_replace('_', ' ', $range);
867
+                $year   = date('Y', strtotime($_range, $time));
868
+                $months = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12');
869 869
 
870
-                foreach ( $months as $month ) {
870
+                foreach ($months as $month) {
871 871
 
872 872
                     $amount = 0;
873
-                    if ( isset( $data[$month] ) ) {
874
-                        $amount = floatval( $data[$month] );
873
+                    if (isset($data[$month])) {
874
+                        $amount = floatval($data[$month]);
875 875
                     }
876 876
 
877
-                    $_time     = strtotime("$year-$month-01") * 1000;
878
-                    $return[] = array( $_time, $amount );
877
+                    $_time = strtotime("$year-$month-01") * 1000;
878
+                    $return[] = array($_time, $amount);
879 879
                 }
880 880
 
881 881
                 break;
882 882
             case '30_days_ago' :
883 883
                 $days = 30;
884 884
 
885
-                while ( $days > 1 ) {
885
+                while ($days > 1) {
886 886
                     $amount = 0;
887
-                    $date   = date( 'j', strtotime( "-$days days", $time ) );
888
-                    if ( isset( $data[$date] ) ) {
889
-                        $amount = floatval( $data[$date] );
887
+                    $date   = date('j', strtotime("-$days days", $time));
888
+                    if (isset($data[$date])) {
889
+                        $amount = floatval($data[$date]);
890 890
                     }
891 891
 
892
-                    $_time = strtotime( "-$days days", $time ) * 1000;
893
-                    $return[] = array( $_time, $amount );
892
+                    $_time = strtotime("-$days days", $time) * 1000;
893
+                    $return[] = array($_time, $amount);
894 894
                     $days--;
895 895
                 }
896 896
 
@@ -899,15 +899,15 @@  discard block
 block discarded – undo
899 899
             default:
900 900
                 $days = 7;
901 901
 
902
-                while ( $days > 1 ) {
902
+                while ($days > 1) {
903 903
                     $amount = 0;
904
-                    $date   = date( 'j', strtotime( "-$days days", $time ) );
905
-                    if ( isset( $data[$date] ) ) {
906
-                        $amount = floatval( $data[$date] );
904
+                    $date   = date('j', strtotime("-$days days", $time));
905
+                    if (isset($data[$date])) {
906
+                        $amount = floatval($data[$date]);
907 907
                     }
908 908
 
909
-                    $_time = strtotime( "-$days days", $time ) * 1000;
910
-                    $return[] = array( $_time, $amount );
909
+                    $_time = strtotime("-$days days", $time) * 1000;
910
+                    $return[] = array($_time, $amount);
911 911
                     $days--;
912 912
                 }
913 913
 
@@ -922,33 +922,33 @@  discard block
 block discarded – undo
922 922
      * Retrieves the stats.
923 923
      */
924 924
     public function get_stats() {
925
-        $range     = isset( $_GET['range'] ) ? $_GET['range'] : '7_days_ago';
926
-        $results   = $this->get_report_results( $range );
927
-        $earnings  = wp_list_pluck( $results, 'total', 'completed_date' );
928
-        $taxes     = wp_list_pluck( $results, 'tax', 'completed_date' );
929
-        $discounts = wp_list_pluck( $results, 'discount', 'completed_date' );
930
-        $fees      = wp_list_pluck( $results, 'fees_total', 'completed_date' );
925
+        $range     = isset($_GET['range']) ? $_GET['range'] : '7_days_ago';
926
+        $results   = $this->get_report_results($range);
927
+        $earnings  = wp_list_pluck($results, 'total', 'completed_date');
928
+        $taxes     = wp_list_pluck($results, 'tax', 'completed_date');
929
+        $discounts = wp_list_pluck($results, 'discount', 'completed_date');
930
+        $fees      = wp_list_pluck($results, 'fees_total', 'completed_date');
931 931
 
932 932
         return array(
933 933
 
934 934
             array(
935
-                'label' => __( 'Earnings', 'invoicing' ),
936
-                'data'  => $this->fill_nulls( $earnings, $range ),
935
+                'label' => __('Earnings', 'invoicing'),
936
+                'data'  => $this->fill_nulls($earnings, $range),
937 937
             ),
938 938
 
939 939
             array(
940
-                'label' => __( 'Taxes', 'invoicing' ),
941
-                'data'  => $this->fill_nulls( $taxes, $range ),
940
+                'label' => __('Taxes', 'invoicing'),
941
+                'data'  => $this->fill_nulls($taxes, $range),
942 942
             ),
943 943
 
944 944
             array(
945
-                'label' => __( 'Discounts', 'invoicing' ),
946
-                'data'  => $this->fill_nulls( $discounts, $range ),
945
+                'label' => __('Discounts', 'invoicing'),
946
+                'data'  => $this->fill_nulls($discounts, $range),
947 947
             ),
948 948
 
949 949
             array(
950
-                'label' => __( 'Fees', 'invoicing' ),
951
-                'data'  => $this->fill_nulls( $fees, $range ),
950
+                'label' => __('Fees', 'invoicing'),
951
+                'data'  => $this->fill_nulls($fees, $range),
952 952
             )
953 953
         );
954 954
 
@@ -958,34 +958,34 @@  discard block
 block discarded – undo
958 958
      * Retrieves the time format for stats.
959 959
      */
960 960
     public function get_time_format() {
961
-        $range    = isset( $_GET['range'] ) ? $_GET['range'] : '7_days_ago';
961
+        $range = isset($_GET['range']) ? $_GET['range'] : '7_days_ago';
962 962
 
963
-        switch ( $range ) {
963
+        switch ($range) {
964 964
             case 'today' :
965 965
             case 'yesterday' :
966
-                return array( 'hour', '%h %p' );
966
+                return array('hour', '%h %p');
967 967
                 break;
968 968
 
969 969
             case 'this_month' :
970 970
             case 'last_month' :
971
-                return array( 'day', '%b %d' );
971
+                return array('day', '%b %d');
972 972
                 break;
973 973
 
974 974
             case 'this_week' :
975 975
             case 'last_week' :
976
-                return array( 'day', '%b %d' );
976
+                return array('day', '%b %d');
977 977
                 break;
978 978
 
979 979
             case 'this_year' :
980 980
             case 'last_year' :
981
-                return array( 'month', '%b' );
981
+                return array('month', '%b');
982 982
                 break;
983 983
             case '30_days_ago' :
984
-                return array( 'day', '%b %d' );
984
+                return array('day', '%b %d');
985 985
                 break;
986 986
 
987 987
             default:
988
-                return array( 'day', '%b %d' );
988
+                return array('day', '%b %d');
989 989
                 break;
990 990
 
991 991
         }
@@ -996,11 +996,11 @@  discard block
 block discarded – undo
996 996
      */
997 997
     public function earnings_report() {
998 998
 
999
-        $data        = wp_json_encode( $this->get_stats() );
999
+        $data        = wp_json_encode($this->get_stats());
1000 1000
         $time_format = $this->get_time_format();
1001 1001
         echo '
1002 1002
             <div class="wpinv-report-container">
1003
-                <h3><span>' . __( 'Earnings Over Time', 'invoicing' ) .'</span></h3>
1003
+                <h3><span>' . __('Earnings Over Time', 'invoicing') . '</span></h3>
1004 1004
                 ' . $this->period_filter() . '
1005 1005
                 <div id="wpinv_report_graph" style="height: 450px;"></div>
1006 1006
             </div>
@@ -1009,12 +1009,12 @@  discard block
 block discarded – undo
1009 1009
                 jQuery(document).ready( function() {
1010 1010
                     jQuery.plot(
1011 1011
                         jQuery("#wpinv_report_graph"),
1012
-                        ' . $data .',
1012
+                        ' . $data . ',
1013 1013
                         {
1014 1014
                             xaxis:{
1015 1015
                                 mode: "time",
1016
-                                timeformat: "' . $time_format[1] .'",
1017
-                                minTickSize: [0.5, "' . $time_format[0] .'"]
1016
+                                timeformat: "' . $time_format[1] . '",
1017
+                                minTickSize: [0.5, "' . $time_format[0] . '"]
1018 1018
                             },
1019 1019
 
1020 1020
                             yaxis: {
@@ -1042,7 +1042,7 @@  discard block
 block discarded – undo
1042 1042
      * Displays the gateways report.
1043 1043
      */
1044 1044
     public function gateways_report() {
1045
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-gateways-report-table.php' );
1045
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-gateways-report-table.php');
1046 1046
 
1047 1047
         $table = new WPInv_Gateways_Report_Table();
1048 1048
         $table->prepare_items();
@@ -1053,12 +1053,12 @@  discard block
 block discarded – undo
1053 1053
      * Displays the items report.
1054 1054
      */
1055 1055
     public function items_report() {
1056
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-items-report-table.php' );
1056
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-items-report-table.php');
1057 1057
 
1058 1058
         $table = new WPInv_Items_Report_Table();
1059 1059
         $table->prepare_items();
1060 1060
         $table->display();
1061
-        echo __( '* Items with no sales not shown.', 'invoicing' );
1061
+        echo __('* Items with no sales not shown.', 'invoicing');
1062 1062
     }
1063 1063
 
1064 1064
     /**
@@ -1068,27 +1068,27 @@  discard block
 block discarded – undo
1068 1068
      */
1069 1069
     public function tax_report() {
1070 1070
 
1071
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-taxes-report-table.php' );
1071
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-taxes-report-table.php');
1072 1072
         $table = new WPInv_Taxes_Reports_Table();
1073 1073
         $table->prepare_items();
1074
-        $year = isset( $_GET['year'] ) ? absint( $_GET['year'] ) : date( 'Y' );
1074
+        $year = isset($_GET['year']) ? absint($_GET['year']) : date('Y');
1075 1075
         ?>
1076 1076
 
1077 1077
         <div class="metabox-holder" style="padding-top: 0;">
1078 1078
             <div class="postbox">
1079
-                <h3><span><?php _e('Tax Report','invoicing' ); ?></span></h3>
1079
+                <h3><span><?php _e('Tax Report', 'invoicing'); ?></span></h3>
1080 1080
                 <div class="inside">
1081
-                    <p><?php _e( 'This report shows the total amount collected in sales tax for the given year.', 'invoicing' ); ?></p>
1081
+                    <p><?php _e('This report shows the total amount collected in sales tax for the given year.', 'invoicing'); ?></p>
1082 1082
                     <form method="get">
1083
-                        <span><?php echo $year; ?></span>: <strong><?php echo wpinv_sales_tax_for_year( $year ); ?></strong>&nbsp;&mdash;&nbsp;
1083
+                        <span><?php echo $year; ?></span>: <strong><?php echo wpinv_sales_tax_for_year($year); ?></strong>&nbsp;&mdash;&nbsp;
1084 1084
                         <select name="year">
1085
-                            <?php for ( $i = 2014; $i <= date( 'Y' ); $i++ ) : ?>
1086
-                            <option value="<?php echo $i; ?>"<?php selected( $year, $i ); ?>><?php echo $i; ?></option>
1085
+                            <?php for ($i = 2014; $i <= date('Y'); $i++) : ?>
1086
+                            <option value="<?php echo $i; ?>"<?php selected($year, $i); ?>><?php echo $i; ?></option>
1087 1087
                             <?php endfor; ?>
1088 1088
                         </select>
1089 1089
                         <input type="hidden" name="view" value="taxes" />
1090 1090
                         <input type="hidden" name="page" value="wpinv-reports"/>
1091
-                        <?php submit_button( __( 'Submit', 'invoicing' ), 'secondary', 'submit', false ); ?>
1091
+                        <?php submit_button(__('Submit', 'invoicing'), 'secondary', 'submit', false); ?>
1092 1092
                     </form>
1093 1093
                 </div><!-- .inside -->
1094 1094
             </div><!-- .postbox -->
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-authorize-net-gateway.php 1 patch
Spacing   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Authorize.net Payment Gateway class.
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @var array
26 26
 	 */
27
-    protected $supports = array( 'subscription', 'sandbox', 'tokens' );
27
+    protected $supports = array('subscription', 'sandbox', 'tokens');
28 28
 
29 29
     /**
30 30
 	 * Payment method order.
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 *
53 53
 	 * @var array
54 54
 	 */
55
-	public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
55
+	public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD');
56 56
 
57 57
     /**
58 58
 	 * URL to view a transaction.
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public function __construct() {
68 68
 
69
-        $this->title                = __( 'Credit Card / Debit Card', 'invoicing' );
70
-        $this->method_title         = __( 'Authorize.Net', 'invoicing' );
71
-        $this->notify_url           = wpinv_get_ipn_url( $this->id );
69
+        $this->title                = __('Credit Card / Debit Card', 'invoicing');
70
+        $this->method_title         = __('Authorize.Net', 'invoicing');
71
+        $this->notify_url           = wpinv_get_ipn_url($this->id);
72 72
 
73
-        add_filter( 'wpinv_renew_authorizenet_subscription_profile', array( $this, 'renew_subscription' ) );
74
-        add_filter( 'wpinv_gateway_description', array( $this, 'sandbox_notice' ), 10, 2 );
73
+        add_filter('wpinv_renew_authorizenet_subscription_profile', array($this, 'renew_subscription'));
74
+        add_filter('wpinv_gateway_description', array($this, 'sandbox_notice'), 10, 2);
75 75
         parent::__construct();
76 76
     }
77 77
 
@@ -81,13 +81,13 @@  discard block
 block discarded – undo
81 81
 	 * @param int $invoice_id 0 or invoice id.
82 82
 	 * @param GetPaid_Payment_Form $form Current payment form.
83 83
 	 */
84
-    public function payment_fields( $invoice_id, $form ) {
84
+    public function payment_fields($invoice_id, $form) {
85 85
 
86 86
         // Let the user select a payment method.
87 87
         echo $this->saved_payment_methods();
88 88
 
89 89
         // Show the credit card entry form.
90
-        echo $this->new_payment_method_entry( $this->get_cc_form( true ) );
90
+        echo $this->new_payment_method_entry($this->get_cc_form(true));
91 91
     }
92 92
 
93 93
     /**
@@ -100,64 +100,64 @@  discard block
 block discarded – undo
100 100
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
101 101
 	 * @return string|WP_Error Payment profile id.
102 102
 	 */
103
-	public function create_customer_profile( $invoice, $submission_data, $save = true ) {
103
+	public function create_customer_profile($invoice, $submission_data, $save = true) {
104 104
 
105 105
         // Remove non-digits from the number
106
-        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
106
+        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']);
107 107
 
108 108
         // Generate args.
109 109
         $args = array(
110 110
             'createCustomerProfileRequest' => array(
111 111
                 'merchantAuthentication'   => $this->get_auth_params(),
112 112
                 'profile'                  => array(
113
-                    'merchantCustomerId'   => getpaid_limit_length( $invoice->get_user_id(), 20 ),
114
-                    'description'          => getpaid_limit_length( $invoice->get_full_name(), 255 ),
115
-                    'email'                => getpaid_limit_length( $invoice->get_email(), 255 ),
113
+                    'merchantCustomerId'   => getpaid_limit_length($invoice->get_user_id(), 20),
114
+                    'description'          => getpaid_limit_length($invoice->get_full_name(), 255),
115
+                    'email'                => getpaid_limit_length($invoice->get_email(), 255),
116 116
                     'paymentProfiles'      => array(
117 117
                         'customerType'     => 'individual',
118 118
 
119 119
                         // Billing information.
120 120
                         'billTo'           => array(
121
-                            'firstName'    => getpaid_limit_length( $invoice->get_first_name(), 50 ),
122
-                            'lastName'     => getpaid_limit_length( $invoice->get_last_name(), 50 ),
123
-                            'address'      => getpaid_limit_length( $invoice->get_last_name(), 60 ),
124
-                            'city'         => getpaid_limit_length( $invoice->get_city(), 40 ),
125
-                            'state'        => getpaid_limit_length( $invoice->get_state(), 40 ),
126
-                            'zip'          => getpaid_limit_length( $invoice->get_zip(), 20 ),
127
-                            'country'      => getpaid_limit_length( $invoice->get_country(), 60 ),
121
+                            'firstName'    => getpaid_limit_length($invoice->get_first_name(), 50),
122
+                            'lastName'     => getpaid_limit_length($invoice->get_last_name(), 50),
123
+                            'address'      => getpaid_limit_length($invoice->get_last_name(), 60),
124
+                            'city'         => getpaid_limit_length($invoice->get_city(), 40),
125
+                            'state'        => getpaid_limit_length($invoice->get_state(), 40),
126
+                            'zip'          => getpaid_limit_length($invoice->get_zip(), 20),
127
+                            'country'      => getpaid_limit_length($invoice->get_country(), 60),
128 128
                         ),
129 129
 
130 130
                         // Payment information.
131
-                        'payment'          => $this->get_payment_information( $submission_data['authorizenet'] ),
131
+                        'payment'          => $this->get_payment_information($submission_data['authorizenet']),
132 132
                     )
133 133
                 ),
134
-                'validationMode'           => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', 
134
+                'validationMode'           => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', 
135 135
             )
136 136
         );
137 137
 
138
-        $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice );
138
+        $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice);
139 139
 
140
-        if ( is_wp_error( $response ) ) {
140
+        if (is_wp_error($response)) {
141 141
             return $response;
142 142
         }
143 143
 
144
-        update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId );
144
+        update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId);
145 145
 
146 146
         // Save the payment token.
147
-        if ( $save ) {
147
+        if ($save) {
148 148
             $this->save_token(
149 149
                 array(
150 150
                     'id'      => $response->customerPaymentProfileIdList[0],
151
-                    'name'    => $this->get_card_name( $submission_data['authorizenet']['cc_number'] ) . '&middot;&middot;&middot;&middot;' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
151
+                    'name'    => $this->get_card_name($submission_data['authorizenet']['cc_number']) . '&middot;&middot;&middot;&middot;' . substr($submission_data['authorizenet']['cc_number'], -4),
152 152
                     'default' => true,
153
-                    'type'    => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live',
153
+                    'type'    => $this->is_sandbox($invoice) ? 'sandbox' : 'live',
154 154
                 )
155 155
             );
156 156
         }
157 157
 
158 158
         // Add a note about the validation response.
159 159
         $invoice->add_note(
160
-            sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ),
160
+            sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]),
161 161
             false,
162 162
             false,
163 163
             true
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 	 * @return string|WP_Error Profile id.
175 175
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile
176 176
 	 */
177
-	public function get_customer_profile( $profile_id ) {
177
+	public function get_customer_profile($profile_id) {
178 178
 
179 179
         // Generate args.
180 180
         $args = array(
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
             )
185 185
         );
186 186
 
187
-        return $this->post( $args, false );
187
+        return $this->post($args, false);
188 188
 
189 189
     }
190 190
 
@@ -199,10 +199,10 @@  discard block
 block discarded – undo
199 199
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
200 200
 	 * @return string|WP_Error Profile id.
201 201
 	 */
202
-	public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
202
+	public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) {
203 203
 
204 204
         // Remove non-digits from the number
205
-        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
205
+        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']);
206 206
 
207 207
         // Generate args.
208 208
         $args = array(
@@ -213,34 +213,34 @@  discard block
 block discarded – undo
213 213
 
214 214
                     // Billing information.
215 215
                     'billTo'           => array(
216
-                        'firstName'    => getpaid_limit_length( $invoice->get_first_name(), 50 ),
217
-                        'lastName'     => getpaid_limit_length( $invoice->get_last_name(), 50 ),
218
-                        'address'      => getpaid_limit_length( $invoice->get_last_name(), 60 ),
219
-                        'city'         => getpaid_limit_length( $invoice->get_city(), 40 ),
220
-                        'state'        => getpaid_limit_length( $invoice->get_state(), 40 ),
221
-                        'zip'          => getpaid_limit_length( $invoice->get_zip(), 20 ),
222
-                        'country'      => getpaid_limit_length( $invoice->get_country(), 60 ),
216
+                        'firstName'    => getpaid_limit_length($invoice->get_first_name(), 50),
217
+                        'lastName'     => getpaid_limit_length($invoice->get_last_name(), 50),
218
+                        'address'      => getpaid_limit_length($invoice->get_last_name(), 60),
219
+                        'city'         => getpaid_limit_length($invoice->get_city(), 40),
220
+                        'state'        => getpaid_limit_length($invoice->get_state(), 40),
221
+                        'zip'          => getpaid_limit_length($invoice->get_zip(), 20),
222
+                        'country'      => getpaid_limit_length($invoice->get_country(), 60),
223 223
                     ),
224 224
 
225 225
                     // Payment information.
226
-                    'payment'          => $this->get_payment_information( $submission_data['authorizenet'] )
226
+                    'payment'          => $this->get_payment_information($submission_data['authorizenet'])
227 227
                 ),
228
-                'validationMode'       => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', 
228
+                'validationMode'       => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', 
229 229
             )
230 230
         );
231 231
 
232
-        $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice );
232
+        $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice);
233 233
 
234
-        if ( is_wp_error( $response ) ) {
234
+        if (is_wp_error($response)) {
235 235
             return $response;
236 236
         }
237 237
 
238 238
         // Save the payment token.
239
-        if ( $save ) {
239
+        if ($save) {
240 240
             $this->save_token(
241 241
                 array(
242 242
                     'id'      => $response->customerPaymentProfileId,
243
-                    'name'    => $this->get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' &middot;&middot;&middot;&middot; ' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
243
+                    'name'    => $this->get_card_name($submission_data['authorizenet']['cc_number']) . ' &middot;&middot;&middot;&middot; ' . substr($submission_data['authorizenet']['cc_number'], -4),
244 244
                     'default' => true
245 245
                 )
246 246
             );
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 
249 249
         // Add a note about the validation response.
250 250
         $invoice->add_note(
251
-            sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ),
251
+            sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse),
252 252
             false,
253 253
             false,
254 254
             true
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 	 * @return string|WP_Error Profile id.
268 268
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile
269 269
 	 */
270
-	public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
270
+	public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) {
271 271
 
272 272
         // Generate args.
273 273
         $args = array(
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
             )
279 279
         );
280 280
 
281
-        return $this->post( $args, false );
281
+        return $this->post($args, false);
282 282
 
283 283
     }
284 284
 
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
      * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile
292 292
 	 * @return WP_Error|object
293 293
 	 */
294
-	public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
294
+	public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) {
295 295
 
296 296
         // Generate args.
297 297
         $args = array(
@@ -311,24 +311,24 @@  discard block
 block discarded – undo
311 311
                         )
312 312
                     ),
313 313
                     'order'                    => array(
314
-                        'invoiceNumber'        => getpaid_limit_length( $invoice->get_number(), 20 ),
314
+                        'invoiceNumber'        => getpaid_limit_length($invoice->get_number(), 20),
315 315
                     ),
316
-                    'lineItems'                => array( 'lineItem' => $this->get_line_items( $invoice ) ),
316
+                    'lineItems'                => array('lineItem' => $this->get_line_items($invoice)),
317 317
                     'tax'                      => array(
318 318
                         'amount'               => $invoice->get_total_tax(),
319 319
                         'name'                 => getpaid_tax()->get_vat_name(),
320 320
                     ),
321
-                    'poNumber'                 => getpaid_limit_length( $invoice->get_number(), 25 ),
321
+                    'poNumber'                 => getpaid_limit_length($invoice->get_number(), 25),
322 322
                     'customer'                 => array(
323
-                        'id'                   => getpaid_limit_length( $invoice->get_user_id(), 25 ),
324
-                        'email'                => getpaid_limit_length( $invoice->get_email(), 25 ),
323
+                        'id'                   => getpaid_limit_length($invoice->get_user_id(), 25),
324
+                        'email'                => getpaid_limit_length($invoice->get_email(), 25),
325 325
                     ),
326 326
                     'customerIP'               => $invoice->get_ip(),
327 327
                 )
328 328
             )
329 329
         );
330
-log_noptin_message( $args );
331
-        return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice );
330
+log_noptin_message($args);
331
+        return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice);
332 332
 
333 333
     }
334 334
 
@@ -338,43 +338,43 @@  discard block
 block discarded – undo
338 338
      * @param stdClass $result Api response.
339 339
 	 * @param WPInv_Invoice $invoice Invoice.
340 340
 	 */
341
-	public function process_charge_response( $result, $invoice ) {
341
+	public function process_charge_response($result, $invoice) {
342 342
 
343 343
         wpinv_clear_errors();
344 344
 
345
-        switch ( (int) $result->transactionResponse->responseCode ) {
345
+        switch ((int) $result->transactionResponse->responseCode) {
346 346
 
347 347
             case 1:
348 348
             case 4:
349 349
 
350
-                if ( ! empty( $result->transactionResponse->transId ) ) {
351
-                    $invoice->set_transaction_id( $result->transactionResponse->transId );
350
+                if (!empty($result->transactionResponse->transId)) {
351
+                    $invoice->set_transaction_id($result->transactionResponse->transId);
352 352
                 }
353 353
 
354
-                if ( 1 == (int) $result->transactionResponse->responseCode ) {
354
+                if (1 == (int) $result->transactionResponse->responseCode) {
355 355
                     $invoice->mark_paid();
356 356
                 } else {
357
-                    $invoice->set_status( 'wpi-onhold' );
357
+                    $invoice->set_status('wpi-onhold');
358 358
                     $invoice->add_note( 
359 359
                         sprintf(
360
-                            __( 'Held for review: %s', 'invoicing' ),
360
+                            __('Held for review: %s', 'invoicing'),
361 361
                             $result->transactionResponse->messages->message[0]->description
362 362
                         )
363 363
                     );
364 364
                 }
365 365
 
366
-                $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
366
+                $invoice->add_note(sprintf(__('Authentication code: %s (%s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true);
367 367
                 $invoice->save();
368 368
 
369 369
                 return;
370 370
 
371 371
             case 2:
372 372
             case 3:
373
-                wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) );
373
+                wpinv_set_error('card_declined', __('Credit card declined.', 'invoicing'));
374 374
 
375
-                if ( ! empty( $result->transactionResponse->errors ) ) {
375
+                if (!empty($result->transactionResponse->errors)) {
376 376
                     $errors = (object) $result->transactionResponse->errors;
377
-                    wpinv_set_error( $errors->error[0]->errorCode, $errors->error[0]->errorText );
377
+                    wpinv_set_error($errors->error[0]->errorCode, $errors->error[0]->errorText);
378 378
                 }
379 379
 
380 380
                 return;
@@ -390,10 +390,10 @@  discard block
 block discarded – undo
390 390
 	 * @param array $card Card details.
391 391
 	 * @return array
392 392
 	 */
393
-	public function get_payment_information( $card ) {
393
+	public function get_payment_information($card) {
394 394
         return array(
395 395
 
396
-            'creditCard'         => array (
396
+            'creditCard'         => array(
397 397
                 'cardNumber'     => $card['cc_number'],
398 398
                 'expirationDate' => $card['cc_expire_year'] . '-' . $card['cc_expire_month'],
399 399
                 'cardCode'       => $card['cc_cvv2'],
@@ -409,30 +409,30 @@  discard block
 block discarded – undo
409 409
 	 * @param string $card_number Card number.
410 410
 	 * @return string
411 411
 	 */
412
-	public function get_card_name( $card_number ) {
412
+	public function get_card_name($card_number) {
413 413
 
414
-        switch( $card_number ) {
414
+        switch ($card_number) {
415 415
 
416
-            case( preg_match ( '/^4/', $card_number ) >= 1 ):
417
-                return __( 'Visa', 'invoicing' );
416
+            case(preg_match('/^4/', $card_number) >= 1):
417
+                return __('Visa', 'invoicing');
418 418
 
419
-            case( preg_match ( '/^5[1-5]/', $card_number ) >= 1 ):
420
-                return __( 'Mastercard', 'invoicing' );
419
+            case(preg_match('/^5[1-5]/', $card_number) >= 1):
420
+                return __('Mastercard', 'invoicing');
421 421
 
422
-            case( preg_match ( '/^3[47]/', $card_number ) >= 1 ):
423
-                return __( 'Amex', 'invoicing' );
422
+            case(preg_match('/^3[47]/', $card_number) >= 1):
423
+                return __('Amex', 'invoicing');
424 424
 
425
-            case( preg_match ( '/^3(?:0[0-5]|[68])/', $card_number ) >= 1 ):
426
-                return __( 'Diners Club', 'invoicing' );
425
+            case(preg_match('/^3(?:0[0-5]|[68])/', $card_number) >= 1):
426
+                return __('Diners Club', 'invoicing');
427 427
 
428
-            case( preg_match ( '/^6(?:011|5)/', $card_number ) >= 1 ):
429
-                return __( 'Discover', 'invoicing' );
428
+            case(preg_match('/^6(?:011|5)/', $card_number) >= 1):
429
+                return __('Discover', 'invoicing');
430 430
 
431
-            case( preg_match ( '/^(?:2131|1800|35\d{3})/', $card_number ) >= 1 ):
432
-                return __( 'JCB', 'invoicing' );
431
+            case(preg_match('/^(?:2131|1800|35\d{3})/', $card_number) >= 1):
432
+                return __('JCB', 'invoicing');
433 433
 
434 434
             default:
435
-            return __( 'Card', 'invoicing' );
435
+            return __('Card', 'invoicing');
436 436
                 break;
437 437
         }
438 438
 
@@ -445,8 +445,8 @@  discard block
 block discarded – undo
445 445
 	 * @param WPInv_Invoice $invoice Invoice.
446 446
 	 * @return string
447 447
 	 */
448
-	public function get_customer_profile_meta_name( $invoice ) {
449
-        return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
448
+	public function get_customer_profile_meta_name($invoice) {
449
+        return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
450 450
     }
451 451
 
452 452
     /**
@@ -456,8 +456,8 @@  discard block
 block discarded – undo
456 456
 	 * @param WPInv_Invoice $invoice Invoice.
457 457
 	 * @return string
458 458
 	 */
459
-	public function get_api_url( $invoice ) {
460
-        return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api';
459
+	public function get_api_url($invoice) {
460
+        return $this->is_sandbox($invoice) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api';
461 461
     }
462 462
 
463 463
     /**
@@ -469,8 +469,8 @@  discard block
 block discarded – undo
469 469
 	public function get_auth_params() {
470 470
 
471 471
         return array(
472
-            'name'           => $this->get_option( 'login_id' ),
473
-            'transactionKey' => $this->get_option( 'transaction_key' ),
472
+            'name'           => $this->get_option('login_id'),
473
+            'transactionKey' => $this->get_option('transaction_key'),
474 474
         );
475 475
 
476 476
     }
@@ -483,34 +483,34 @@  discard block
 block discarded – undo
483 483
      * @param WPInv_Invoice $invoice
484 484
 	 * @return WP_Error|string The payment profile id
485 485
 	 */
486
-	public function validate_submission_data( $submission_data, $invoice ) {
486
+	public function validate_submission_data($submission_data, $invoice) {
487 487
 
488 488
         // Validate authentication details.
489 489
         $auth = $this->get_auth_params();
490 490
 
491
-        if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) {
492
-            return new WP_Error( 'invalid_settings', __( 'This gateway has not been set up.', 'invoicing') );
491
+        if (empty($auth['name']) || empty($auth['transactionKey'])) {
492
+            return new WP_Error('invalid_settings', __('This gateway has not been set up.', 'invoicing'));
493 493
         }
494 494
 
495 495
         // Validate the payment method.
496
-        if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) {
497
-            return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing') );
496
+        if (empty($submission_data['getpaid-authorizenet-payment-method'])) {
497
+            return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing'));
498 498
         }
499 499
 
500 500
         // Are we adding a new payment method?
501
-        if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) {
501
+        if ('new' != $submission_data['getpaid-authorizenet-payment-method']) {
502 502
             return $submission_data['getpaid-authorizenet-payment-method'];
503 503
         }
504 504
 
505 505
         // Retrieve the customer profile id.
506
-        $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
506
+        $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
507 507
 
508 508
         // Create payment method.
509
-        if ( empty( $profile_id ) ) {
510
-            return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
509
+        if (empty($profile_id)) {
510
+            return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
511 511
         }
512 512
 
513
-        return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
513
+        return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
514 514
 
515 515
     }
516 516
 
@@ -521,15 +521,15 @@  discard block
 block discarded – undo
521 521
 	 * @param WPInv_Invoice $invoice Invoice.
522 522
 	 * @return array
523 523
 	 */
524
-	public function get_line_items( $invoice ) {
524
+	public function get_line_items($invoice) {
525 525
         $items = array();
526 526
 
527
-        foreach ( $invoice->get_items() as $item ) {
527
+        foreach ($invoice->get_items() as $item) {
528 528
 
529 529
             $items[] = array(
530
-                'itemId'      => getpaid_limit_length( $item->get_id(), 31 ),
531
-                'name'        => getpaid_limit_length( $item->get_raw_name(), 31 ),
532
-                'description' => getpaid_limit_length( $item->get_description(), 255 ),
530
+                'itemId'      => getpaid_limit_length($item->get_id(), 31),
531
+                'name'        => getpaid_limit_length($item->get_raw_name(), 31),
532
+                'description' => getpaid_limit_length($item->get_description(), 255),
533 533
                 'quantity'    => (int) $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(),
534 534
                 'unitPrice'   => (float) $item->get_price(),
535 535
                 'taxable'     => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(),
@@ -548,40 +548,40 @@  discard block
 block discarded – undo
548 548
      * @param WPInv_Invoice $invoice Invoice.
549 549
 	 * @return stdClass|WP_Error
550 550
 	 */
551
-    public function post( $post, $invoice ){
551
+    public function post($post, $invoice) {
552 552
 
553
-        $url      = $this->get_api_url( $invoice );
553
+        $url      = $this->get_api_url($invoice);
554 554
         $response = wp_remote_post(
555 555
             $url,
556 556
             array(
557 557
                 'headers'          => array(
558 558
                     'Content-Type' => 'application/json; charset=utf-8'
559 559
                 ),
560
-                'body'             => json_encode( $post ),
560
+                'body'             => json_encode($post),
561 561
                 'method'           => 'POST'
562 562
             )
563 563
         );
564 564
 
565
-        if ( is_wp_error( $response ) ) {
565
+        if (is_wp_error($response)) {
566 566
             return $response;
567 567
         }
568 568
 
569
-        $response = wp_unslash( wp_remote_retrieve_body( $response ) );
569
+        $response = wp_unslash(wp_remote_retrieve_body($response));
570 570
         $response = preg_replace('/\xEF\xBB\xBF/', '', $response); // https://community.developer.authorize.net/t5/Integration-and-Testing/JSON-issues/td-p/48851
571
-        $response = json_decode( $response );
571
+        $response = json_decode($response);
572 572
 
573
-        if ( empty( $response ) ) {
574
-            return new WP_Error( 'invalid_reponse', __( 'Invalid response', 'invoicing' ) );
573
+        if (empty($response)) {
574
+            return new WP_Error('invalid_reponse', __('Invalid response', 'invoicing'));
575 575
         }
576 576
 
577
-        if ( $response->messages->resultCode == 'Error' ) {
577
+        if ($response->messages->resultCode == 'Error') {
578 578
 
579
-            if ( ! empty( $response->transactionResponse ) && ! empty( $response->transactionResponse->errors ) ) {
579
+            if (!empty($response->transactionResponse) && !empty($response->transactionResponse->errors)) {
580 580
                 $error = $response->transactionResponse->errors[0];
581
-                return new WP_Error( $error->errorCode, $error->errorText );
581
+                return new WP_Error($error->errorCode, $error->errorText);
582 582
             }
583 583
 
584
-            return new WP_Error( $response->messages->message[0]->code, $response->messages->message[0]->text );
584
+            return new WP_Error($response->messages->message[0]->code, $response->messages->message[0]->text);
585 585
         }
586 586
 
587 587
         return $response;
@@ -597,49 +597,49 @@  discard block
 block discarded – undo
597 597
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
598 598
 	 * @return array
599 599
 	 */
600
-	public function process_payment( $invoice, $submission_data, $submission ) {
600
+	public function process_payment($invoice, $submission_data, $submission) {
601 601
 
602 602
         // Validate the submitted data.
603
-        $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
603
+        $payment_profile_id = $this->validate_submission_data($submission_data, $invoice);
604 604
 
605 605
         // Do we have an error?
606
-        if ( is_wp_error( $payment_profile_id ) ) {
607
-            wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() );
606
+        if (is_wp_error($payment_profile_id)) {
607
+            wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message());
608 608
             wpinv_send_back_to_checkout();
609 609
         }
610 610
 
611 611
         // Save the payment method to the order.
612
-        update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id );
612
+        update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id);
613 613
 
614 614
         // Check if this is a subscription or not.
615
-        if ( $invoice->is_recurring() && $subscription = wpinv_get_subscription( $invoice ) ) {
616
-            $this->process_subscription( $invoice, $subscription );
615
+        if ($invoice->is_recurring() && $subscription = wpinv_get_subscription($invoice)) {
616
+            $this->process_subscription($invoice, $subscription);
617 617
         }
618 618
 
619 619
         // If it is free, send to the success page.
620
-        if ( ! $invoice->needs_payment() ) {
620
+        if (!$invoice->needs_payment()) {
621 621
             $invoice->mark_paid();
622
-            wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
622
+            wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
623 623
         }
624 624
 
625 625
         // Charge the payment profile.
626
-        $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
627
-        $result           = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
626
+        $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
627
+        $result           = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice);
628 628
 
629 629
         // Do we have an error?
630
-        if ( is_wp_error( $result ) ) {
631
-            wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
630
+        if (is_wp_error($result)) {
631
+            wpinv_set_error($result->get_error_code(), $result->get_error_message());
632 632
             wpinv_send_back_to_checkout();
633 633
         }
634 634
 
635 635
         // Process the response.
636
-        $this->process_charge_response( $result, $invoice );
636
+        $this->process_charge_response($result, $invoice);
637 637
 
638
-        if ( wpinv_get_errors() ) {
638
+        if (wpinv_get_errors()) {
639 639
             wpinv_send_back_to_checkout();
640 640
         }
641 641
 
642
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
642
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
643 643
 
644 644
         exit;
645 645
 
@@ -651,40 +651,40 @@  discard block
 block discarded – undo
651 651
      * @param WPInv_Invoice $invoice Invoice.
652 652
      * @param WPInv_Subscription $subscription Subscription.
653 653
 	 */
654
-	public function process_subscription( $invoice, $subscription ) {
654
+	public function process_subscription($invoice, $subscription) {
655 655
 
656 656
         // Check if there is an initial amount to charge.
657
-        if ( (float) $invoice->get_total() > 0 ) {
657
+        if ((float) $invoice->get_total() > 0) {
658 658
 
659 659
             // Retrieve the payment method.
660
-            $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
661
-            $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
662
-            $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
660
+            $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
661
+            $customer_profile   = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
662
+            $result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice);
663 663
 
664 664
             // Do we have an error?
665
-            if ( is_wp_error( $result ) ) {
666
-                wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
665
+            if (is_wp_error($result)) {
666
+                wpinv_set_error($result->get_error_code(), $result->get_error_message());
667 667
                 wpinv_send_back_to_checkout();
668 668
             }
669 669
 
670 670
             // Process the response.
671
-            $this->process_charge_response( $result, $invoice );
671
+            $this->process_charge_response($result, $invoice);
672 672
 
673
-            if ( wpinv_get_errors() ) {
673
+            if (wpinv_get_errors()) {
674 674
                 wpinv_send_back_to_checkout();
675 675
             }
676 676
 
677 677
         }
678 678
 
679 679
         // Recalculate the new subscription expiry.
680
-        $duration = strtotime( $subscription->expiration ) - strtotime( $subscription->created );
681
-        $expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
680
+        $duration = strtotime($subscription->expiration) - strtotime($subscription->created);
681
+        $expiry   = date('Y-m-d H:i:s', (current_time('timestamp') + $duration));
682 682
 
683 683
         // Schedule an action to run when the subscription expires.
684 684
         $action_id = as_schedule_single_action(
685
-            strtotime( $expiry ),
685
+            strtotime($expiry),
686 686
             'wpinv_renew_authorizenet_subscription_profile',
687
-            array( $invoice->get_id() ),
687
+            array($invoice->get_id()),
688 688
             'invoicing'
689 689
         );
690 690
 
@@ -693,12 +693,12 @@  discard block
 block discarded – undo
693 693
             array(
694 694
                 'profile_id' => $action_id,
695 695
                 'status'     => 'trialling' == $subscription->status ? 'trialling' : 'active',
696
-                'created'    => current_time( 'mysql' ),
696
+                'created'    => current_time('mysql'),
697 697
                 'expiration' => $expiry,
698 698
             )
699 699
         );
700 700
 
701
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
701
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
702 702
 
703 703
     }
704 704
 
@@ -707,45 +707,45 @@  discard block
 block discarded – undo
707 707
 	 *
708 708
      * @param int $invoice Invoice id.
709 709
 	 */
710
-	public function renew_subscription( $invoice ) {
710
+	public function renew_subscription($invoice) {
711 711
 
712 712
         // Retrieve the subscription.
713
-        $subscription = wpinv_get_subscription( $invoice );
714
-        if ( empty( $subscription ) ) {
713
+        $subscription = wpinv_get_subscription($invoice);
714
+        if (empty($subscription)) {
715 715
             return;
716 716
         }
717 717
 
718 718
         // Abort if it is canceled or complete.
719
-        if ( $subscription->status == 'completed' || $subscription->status == 'cancelled' ) {
719
+        if ($subscription->status == 'completed' || $subscription->status == 'cancelled') {
720 720
             return;
721 721
         }
722 722
 
723 723
         // Retrieve the invoice.
724
-        $invoice = new WPInv_Invoice( $invoice );
724
+        $invoice = new WPInv_Invoice($invoice);
725 725
 
726 726
         // If we have not maxed out on bill times...
727 727
         $times_billed = $subscription->get_times_billed();
728 728
         $max_bills    = $subscription->bill_times;
729 729
 
730
-        if ( empty( $max_bills ) || $max_bills > $times_billed ) {
730
+        if (empty($max_bills) || $max_bills > $times_billed) {
731 731
 
732 732
             $new_invoice = $subscription->create_payment();
733 733
 
734
-            if ( empty( $new_invoice ) ) {
735
-                $invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
734
+            if (empty($new_invoice)) {
735
+                $invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false);
736 736
                 $subscription->failing();
737 737
                 return;
738 738
             }
739 739
 
740 740
             // retrieve the payment method.
741
-            $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
742
-            $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
743
-            $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
741
+            $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
742
+            $customer_profile   = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
743
+            $result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice);
744 744
 
745 745
             // Do we have an error?
746
-            if ( is_wp_error( $result ) ) {
746
+            if (is_wp_error($result)) {
747 747
                 $invoice->add_note(
748
-                    sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
748
+                    sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()),
749 749
                     true,
750 750
                     false,
751 751
                     true
@@ -755,12 +755,12 @@  discard block
 block discarded – undo
755 755
             }
756 756
 
757 757
             // Process the response.
758
-            $this->process_charge_response( $result, $new_invoice );
758
+            $this->process_charge_response($result, $new_invoice);
759 759
 
760
-            if ( wpinv_get_errors() ) {
760
+            if (wpinv_get_errors()) {
761 761
 
762 762
                 $invoice->add_note(
763
-                    sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
763
+                    sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()),
764 764
                     true,
765 765
                     false,
766 766
                     true
@@ -782,17 +782,17 @@  discard block
 block discarded – undo
782 782
             // Renew/Complete the subscription.
783 783
             $subscription->renew();
784 784
 
785
-            if ( 'completed' != $subscription->status ) {
785
+            if ('completed' != $subscription->status) {
786 786
 
787 787
                 // Schedule an action to run when the subscription expires.
788 788
                 $action_id = as_schedule_single_action(
789
-                    strtotime( $subscription->expiration ),
789
+                    strtotime($subscription->expiration),
790 790
                     'wpinv_renew_authorizenet_subscription_profile',
791
-                    array( $invoice->get_id() ),
791
+                    array($invoice->get_id()),
792 792
                     'invoicing'
793 793
                 );
794 794
     
795
-                $subscription->update( array( 'profile_id' => $action_id, ) );
795
+                $subscription->update(array('profile_id' => $action_id,));
796 796
     
797 797
             }
798 798
 
@@ -806,9 +806,9 @@  discard block
 block discarded – undo
806 806
 	 * @param WPInv_Subscription $subscription Subscription.
807 807
      * @param WPInv_Invoice $invoice Invoice.
808 808
 	 */
809
-	public function cancel_subscription( $subscription, $invoice ) {
809
+	public function cancel_subscription($subscription, $invoice) {
810 810
 
811
-        if ( as_unschedule_action( 'wpinv_renew_authorizenet_subscription_profile', array( $invoice->get_id() ), 'invoicing' ) ) {
811
+        if (as_unschedule_action('wpinv_renew_authorizenet_subscription_profile', array($invoice->get_id()), 'invoicing')) {
812 812
             return;
813 813
         }
814 814
 
@@ -835,45 +835,45 @@  discard block
 block discarded – undo
835 835
         $this->maybe_process_old_ipn();
836 836
 
837 837
         // Validate the IPN.
838
-        if ( empty( $_POST ) || ! $this->validate_ipn() ) {
839
-		    wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 500 ) );
838
+        if (empty($_POST) || !$this->validate_ipn()) {
839
+		    wp_die('Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array('response' => 500));
840 840
         }
841 841
 
842 842
         // Event type.
843
-        $posted = json_decode( file_get_contents('php://input') );
844
-        if ( empty( $posted ) ) {
845
-            wp_die( 'Invalid JSON', 'Authorize.NET IPN', array( 'response' => 500 ) );
843
+        $posted = json_decode(file_get_contents('php://input'));
844
+        if (empty($posted)) {
845
+            wp_die('Invalid JSON', 'Authorize.NET IPN', array('response' => 500));
846 846
         }
847 847
 
848 848
         // Process the IPN.
849
-        $posted = (object) wp_unslash( $posted );
849
+        $posted = (object) wp_unslash($posted);
850 850
 
851 851
         // Process refunds.
852
-        if ( 'net.authorize.payment.refund.created' == $posted->eventType ) {
853
-            $invoice = new WPInv_Invoice( $posted->payload->merchantReferenceId );
852
+        if ('net.authorize.payment.refund.created' == $posted->eventType) {
853
+            $invoice = new WPInv_Invoice($posted->payload->merchantReferenceId);
854 854
 
855
-            if ( $invoice->get_id() && $posted->payload->id == $invoice->get_transaction_id() ) {
855
+            if ($invoice->get_id() && $posted->payload->id == $invoice->get_transaction_id()) {
856 856
                 $invoice->refund();
857 857
             }
858 858
 
859 859
         }
860 860
 
861 861
         // Held funds approved.
862
-        if ( 'net.authorize.payment.fraud.approved' == $posted->eventType ) {
863
-            $invoice = new WPInv_Invoice( $posted->payload->id );
862
+        if ('net.authorize.payment.fraud.approved' == $posted->eventType) {
863
+            $invoice = new WPInv_Invoice($posted->payload->id);
864 864
 
865
-            if ( $invoice->get_id() && $posted->payload->id == $invoice->get_transaction_id() ) {
866
-                $invoice->mark_paid( false, __( 'Payment released', 'invoicing' ));
865
+            if ($invoice->get_id() && $posted->payload->id == $invoice->get_transaction_id()) {
866
+                $invoice->mark_paid(false, __('Payment released', 'invoicing'));
867 867
             }
868 868
 
869 869
         }
870 870
 
871 871
         // Held funds declined.
872
-        if ( 'net.authorize.payment.fraud.declined' == $posted->eventType ) {
873
-            $invoice = new WPInv_Invoice( $posted->payload->id );
872
+        if ('net.authorize.payment.fraud.declined' == $posted->eventType) {
873
+            $invoice = new WPInv_Invoice($posted->payload->id);
874 874
 
875
-            if ( $invoice->get_id() && $posted->payload->id == $invoice->get_transaction_id() ) {
876
-                $invoice->set_status( 'wpi-failed', __( 'Payment desclined', 'invoicing' ) );
875
+            if ($invoice->get_id() && $posted->payload->id == $invoice->get_transaction_id()) {
876
+                $invoice->set_status('wpi-failed', __('Payment desclined', 'invoicing'));
877 877
                 $invoice->save();
878 878
             }
879 879
 
@@ -891,41 +891,41 @@  discard block
 block discarded – undo
891 891
 	public function maybe_process_old_ipn() {
892 892
 
893 893
         // Ensure that we are using the old subscriptions.
894
-        if ( empty( $_POST['x_subscription_id'] ) ) {
894
+        if (empty($_POST['x_subscription_id'])) {
895 895
             return;
896 896
         }
897 897
 
898 898
         // Check validity.
899
-        $signature = $this->get_option( 'signature_key' );
900
-        if ( ! empty( $signature ) ) {
901
-            $login_id  = $this->get_option( 'login_id' );
899
+        $signature = $this->get_option('signature_key');
900
+        if (!empty($signature)) {
901
+            $login_id  = $this->get_option('login_id');
902 902
             $trans_id  = $_POST['x_trans_id'];
903 903
             $amount    = $_POST['x_amount'];
904
-            $hash      = hash_hmac ( 'sha512', "^$login_id^$trans_id^$amount^", hex2bin( $signature ) );
904
+            $hash      = hash_hmac('sha512', "^$login_id^$trans_id^$amount^", hex2bin($signature));
905 905
 
906
-            if ( ! hash_equals( $hash, $_POST['x_SHA2_Hash'] ) ) {
906
+            if (!hash_equals($hash, $_POST['x_SHA2_Hash'])) {
907 907
                 exit;
908 908
             }
909 909
 
910 910
         }
911 911
 
912 912
         // Fetch the associated subscription.
913
-        $subscription_id = WPInv_Subscription::get_subscription_id_by_field( $_POST['x_subscription_id'] );
914
-        $subscription    = new WPInv_Subscription( $subscription_id );
913
+        $subscription_id = WPInv_Subscription::get_subscription_id_by_field($_POST['x_subscription_id']);
914
+        $subscription    = new WPInv_Subscription($subscription_id);
915 915
 
916 916
         // Abort if it is missing or completed.
917
-        if ( ! $subscription->get_id() || $subscription->has_status( 'completed' ) ) {
917
+        if (!$subscription->get_id() || $subscription->has_status('completed')) {
918 918
             return;
919 919
         }
920 920
 
921 921
         // Payment status.
922
-        if ( 1 == $_POST['x_response_code'] ) {
922
+        if (1 == $_POST['x_response_code']) {
923 923
 
924 924
             $invoice = $subscription->create_payment();
925
-            $invoice->set_transaction_id( sanitize_text_field( $_POST['x_trans_id'] ) );
926
-            $invoice->set_status( 'wpi-renewal' );
925
+            $invoice->set_transaction_id(sanitize_text_field($_POST['x_trans_id']));
926
+            $invoice->set_status('wpi-renewal');
927 927
             $invoice->save();
928
-            $subscription->add_payment( array(), $invoice );
928
+            $subscription->add_payment(array(), $invoice);
929 929
             $subscription->renew();
930 930
 
931 931
         } else {
@@ -941,28 +941,28 @@  discard block
 block discarded – undo
941 941
 	 */
942 942
 	public function validate_ipn() {
943 943
 
944
-        wpinv_error_log( 'Validating Authorize.NET IPN response' );
944
+        wpinv_error_log('Validating Authorize.NET IPN response');
945 945
 
946
-        if ( empty( $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) {
946
+        if (empty($_SERVER['HTTP_X_ANET_SIGNATURE'])) {
947 947
             return false;
948 948
         }
949 949
 
950
-        $signature = $this->get_option( 'signature_key' );
950
+        $signature = $this->get_option('signature_key');
951 951
 
952
-        if ( empty( $signature ) ) {
953
-            wpinv_error_log( 'Error: You have not set a signature key' );
952
+        if (empty($signature)) {
953
+            wpinv_error_log('Error: You have not set a signature key');
954 954
             return false;
955 955
         }
956 956
 
957
-        $hash  = hash_hmac ( 'sha512', file_get_contents('php://input'), hex2bin( $signature ) );
957
+        $hash = hash_hmac('sha512', file_get_contents('php://input'), hex2bin($signature));
958 958
 
959
-        if ( hash_equals( $hash, $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) {
960
-            wpinv_error_log( 'Successfully validated the IPN' );
959
+        if (hash_equals($hash, $_SERVER['HTTP_X_ANET_SIGNATURE'])) {
960
+            wpinv_error_log('Successfully validated the IPN');
961 961
             return true;
962 962
         }
963 963
 
964
-        wpinv_error_log( 'IPN hash is not valid' );
965
-        wpinv_error_log(  $_SERVER['HTTP_X_ANET_SIGNATURE']  );
964
+        wpinv_error_log('IPN hash is not valid');
965
+        wpinv_error_log($_SERVER['HTTP_X_ANET_SIGNATURE']);
966 966
         return false;
967 967
 
968 968
     }
@@ -970,11 +970,11 @@  discard block
 block discarded – undo
970 970
     /**
971 971
      * Displays a notice on the checkout page if sandbox is enabled.
972 972
      */
973
-    public function sandbox_notice( $description, $gateway ) {
973
+    public function sandbox_notice($description, $gateway) {
974 974
 
975
-        if ( $this->id == $gateway && wpinv_is_test_mode( $this->id ) ) {
975
+        if ($this->id == $gateway && wpinv_is_test_mode($this->id)) {
976 976
             $description .= '<br>' . sprintf(
977
-                __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing' ),
977
+                __('SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing'),
978 978
                 '<a href="https://developer.authorize.net/hello_world/testing_guide.html">',
979 979
                 '</a>'
980 980
             );
@@ -988,42 +988,42 @@  discard block
 block discarded – undo
988 988
 	 * 
989 989
 	 * @param array $admin_settings
990 990
 	 */
991
-	public function admin_settings( $admin_settings ) {
991
+	public function admin_settings($admin_settings) {
992 992
 
993 993
         $currencies = sprintf(
994
-            __( 'Supported Currencies: %s', 'invoicing' ),
995
-            implode( ', ', $this->currencies )
994
+            __('Supported Currencies: %s', 'invoicing'),
995
+            implode(', ', $this->currencies)
996 996
         );
997 997
 
998 998
         $admin_settings['authorizenet_active']['desc'] .= $admin_settings['authorizenet_active']['desc'] . " ($currencies)";
999
-        $admin_settings['authorizenet_desc']['std']     = __( 'Pay securely using your credit or debit card.', 'invoicing' );
999
+        $admin_settings['authorizenet_desc']['std']     = __('Pay securely using your credit or debit card.', 'invoicing');
1000 1000
 
1001 1001
         $admin_settings['authorizenet_login_id'] = array(
1002 1002
             'type' => 'text',
1003 1003
             'id'   => 'authorizenet_login_id',
1004
-            'name' => __( 'API Login ID', 'invoicing' ),
1005
-            'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __( 'How do I obtain my API Login ID and Transaction Key?', 'invoicing' ) . '</em></a>',
1004
+            'name' => __('API Login ID', 'invoicing'),
1005
+            'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __('How do I obtain my API Login ID and Transaction Key?', 'invoicing') . '</em></a>',
1006 1006
         );
1007 1007
 
1008 1008
         $admin_settings['authorizenet_transaction_key'] = array(
1009 1009
             'type' => 'text',
1010 1010
             'id'   => 'authorizenet_transaction_key',
1011
-            'name' => __( 'Transaction Key', 'invoicing' ),
1011
+            'name' => __('Transaction Key', 'invoicing'),
1012 1012
         );
1013 1013
 
1014 1014
         $admin_settings['authorizenet_signature_key'] = array(
1015 1015
             'type' => 'text',
1016 1016
             'id'   => 'authorizenet_signature_key',
1017
-            'name' => __( 'Signature Key', 'invoicing' ),
1018
-            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
1017
+            'name' => __('Signature Key', 'invoicing'),
1018
+            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
1019 1019
         );
1020 1020
 
1021 1021
         $admin_settings['authorizenet_ipn_url'] = array(
1022 1022
             'type'     => 'ipn_url',
1023 1023
             'id'       => 'authorizenet_ipn_url',
1024
-            'name'     => __( 'Webhook URL', 'invoicing' ),
1024
+            'name'     => __('Webhook URL', 'invoicing'),
1025 1025
             'std'      => $this->notify_url,
1026
-            'desc'     => __( 'Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing' ) . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
1026
+            'desc'     => __('Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing') . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
1027 1027
             'custom'   => 'authorizenet',
1028 1028
             'readonly' => true,
1029 1029
         );
Please login to merge, or discard this patch.
includes/error-functions.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
  
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Returns the errors as html
@@ -14,27 +14,27 @@  discard block
 block discarded – undo
14 14
  * @param clear whether or not to clear the errors.
15 15
  * @since  1.0.19
16 16
  */
17
-function getpaid_get_errors_html( $clear = true ) {
17
+function getpaid_get_errors_html($clear = true) {
18 18
 
19 19
     $errors = '';
20
-    foreach ( wpinv_get_errors() as $error ) {
21
-        $type     = 'error';
20
+    foreach (wpinv_get_errors() as $error) {
21
+        $type = 'error';
22 22
 
23
-        if ( is_array( $error ) ) {
23
+        if (is_array($error)) {
24 24
             $type  = $error['type'];
25 25
             $error = $error['text'];
26 26
         }
27 27
 
28 28
         $errors .= aui()->alert(
29 29
             array(
30
-                'content'     => wp_kses_post( $error ),
30
+                'content'     => wp_kses_post($error),
31 31
                 'type'        => $type,
32 32
             )
33 33
         );
34 34
 
35 35
     }
36 36
 
37
-    if ( $clear ){
37
+    if ($clear) {
38 38
         wpinv_clear_errors();
39 39
     }
40 40
 
@@ -55,8 +55,8 @@  discard block
 block discarded – undo
55 55
  * @return array
56 56
  */
57 57
 function wpinv_get_errors() {
58
-    $errors = getpaid_session()->get( 'wpinv_errors' );
59
-    return is_array( $errors ) ? $errors : array();
58
+    $errors = getpaid_session()->get('wpinv_errors');
59
+    return is_array($errors) ? $errors : array();
60 60
 }
61 61
 
62 62
 /**
@@ -66,15 +66,15 @@  discard block
 block discarded – undo
66 66
  * @param string $error_message The error message.
67 67
  * @param string $type Either error, info, warning, primary, dark, light or success.
68 68
  */
69
-function wpinv_set_error( $error_id, $error_message, $type = 'error' ) {
69
+function wpinv_set_error($error_id, $error_message, $type = 'error') {
70 70
 
71 71
     $errors              = wpinv_get_errors();
72
-    $errors[ $error_id ] = array(
72
+    $errors[$error_id] = array(
73 73
         'type' =>  $type,
74 74
         'text' =>  $error_message,
75 75
     );
76 76
 
77
-    getpaid()->session->set( 'wpinv_errors', $errors );
77
+    getpaid()->session->set('wpinv_errors', $errors);
78 78
 }
79 79
 
80 80
 /**
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
  * 
83 83
  */
84 84
 function wpinv_has_errors() {
85
-    return count( wpinv_get_errors() ) > 0;
85
+    return count(wpinv_get_errors()) > 0;
86 86
 }
87 87
 
88 88
 /**
@@ -90,21 +90,21 @@  discard block
 block discarded – undo
90 90
  * 
91 91
  */
92 92
 function wpinv_clear_errors() {
93
-    getpaid_session()->set( 'wpinv_errors', null );
93
+    getpaid_session()->set('wpinv_errors', null);
94 94
 }
95 95
 
96 96
 /**
97 97
  * Clears a single error.
98 98
  * 
99 99
  */
100
-function wpinv_unset_error( $error_id ) {
100
+function wpinv_unset_error($error_id) {
101 101
     $errors = wpinv_get_errors();
102 102
 
103
-    if ( isset( $errors[ $error_id ] ) ) {
104
-        unset( $errors[ $error_id ] );
103
+    if (isset($errors[$error_id])) {
104
+        unset($errors[$error_id]);
105 105
     }
106 106
 
107
-    getpaid_session()->set( 'wpinv_errors', $errors );
107
+    getpaid_session()->set('wpinv_errors', $errors);
108 108
 }
109 109
 
110 110
 /**
@@ -115,15 +115,15 @@  discard block
 block discarded – undo
115 115
  * @param string $message Message to log.
116 116
  * @param string $version Version the message was added in.
117 117
  */
118
-function getpaid_doing_it_wrong( $function, $message, $version ) {
118
+function getpaid_doing_it_wrong($function, $message, $version) {
119 119
 
120 120
 	$message .= ' Backtrace: ' . wp_debug_backtrace_summary();
121 121
 
122
-	if ( is_ajax() || defined( 'REST_REQUEST' ) ) {
123
-		do_action( 'doing_it_wrong_run', $function, $message, $version );
124
-		error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." );
122
+	if (is_ajax() || defined('REST_REQUEST')) {
123
+		do_action('doing_it_wrong_run', $function, $message, $version);
124
+		error_log("{$function} was called incorrectly. {$message}. This message was added in version {$version}.");
125 125
 	} else {
126
-		_doing_it_wrong( $function, $message, $version );
126
+		_doing_it_wrong($function, $message, $version);
127 127
 	}
128 128
 
129 129
 }
Please login to merge, or discard this patch.
includes/class-wpinv-notes.php 2 patches
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -12,119 +12,119 @@
 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
-		do_action( 'getpaid_new_customer_note', $invoice, $note );
127
-		return $note_id;
128
-	}
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
+        do_action( 'getpaid_new_customer_note', $invoice, $note );
127
+        return $note_id;
128
+    }
129 129
 
130 130
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Handles invoice notes.
@@ -18,11 +18,11 @@  discard block
 block discarded – undo
18 18
 	public function __construct() {
19 19
 
20 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 );
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 23
 
24 24
 		// Fires after notes are loaded.
25
-		do_action( 'wpinv_notes_init', $this );
25
+		do_action('wpinv_notes_init', $this);
26 26
 	}
27 27
 
28 28
 	/**
@@ -30,19 +30,19 @@  discard block
 block discarded – undo
30 30
 	 *
31 31
 	 * @param WP_Comment_Query $query
32 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'];
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 35
 
36
-		if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) {
36
+		if ($post_id && getpaid_is_invoice_post_type(get_post_type($post_id))) {
37 37
 			$query->query_vars['type'] = 'wpinv_note';
38 38
 		} else {
39 39
 
40
-			if ( empty( $query->query_vars['type__not_in'] ) ) {
40
+			if (empty($query->query_vars['type__not_in'])) {
41 41
 				$query->query_vars['type__not_in'] = array();
42 42
 			}
43 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'] );
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 46
 		}
47 47
 
48 48
 		return $query;
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
 	/**
52 52
 	 * Exclude notes from the comments feed.
53 53
 	 */
54
-	function wpinv_comment_feed_where( $where ){
55
-		return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' ";
54
+	function wpinv_comment_feed_where($where) {
55
+		return $where . ($where ? ' AND ' : '') . " comment_type != 'wpinv_note' ";
56 56
 	}
57 57
 
58 58
 	/**
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 * @param string $type Optional. Pass in customer to only return customer notes.
63 63
 	 * @return WP_Comment[]
64 64
 	 */
65
-	public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) {
65
+	public function get_invoice_notes($invoice_id = 0, $type = 'all') {
66 66
 
67 67
 		// Default comment args.
68 68
 		$args = array(
@@ -72,14 +72,14 @@  discard block
 block discarded – undo
72 72
 		);
73 73
 
74 74
 		// Maybe only show customer comments.
75
-		if ( $type == 'customer' ) {
75
+		if ($type == 'customer') {
76 76
 			$args['meta_key']   = '_wpi_customer_note';
77 77
 			$args['meta_value'] = 1;
78 78
 		}
79 79
 
80
-		$args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
80
+		$args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type);
81 81
 
82
-		return get_comments( $args );
82
+		return get_comments($args);
83 83
 	}
84 84
 
85 85
 	/**
@@ -91,9 +91,9 @@  discard block
 block discarded – undo
91 91
 	 * @param bool $for_customer Whether or not this comment is meant to be sent to the customer.
92 92
 	 * @return int|false The new note's ID on success, false on failure.
93 93
 	 */
94
-	function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ){
94
+	function add_invoice_note($invoice, $note, $note_author, $author_email, $for_customer = false) {
95 95
 
96
-		do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer );
96
+		do_action('wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer);
97 97
 
98 98
 		/**
99 99
 		 * Insert the comment.
@@ -114,16 +114,16 @@  discard block
 block discarded – undo
114 114
 			)
115 115
 		);
116 116
 
117
-		do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer );
117
+		do_action('wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer);
118 118
 
119 119
 		// Are we notifying the customer?
120
-		if ( empty( $note_id ) || empty( $for_customer ) ) {
120
+		if (empty($note_id) || empty($for_customer)) {
121 121
 			return $note_id;
122 122
 		}
123 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
-		do_action( 'getpaid_new_customer_note', $invoice, $note );
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
+		do_action('getpaid_new_customer_note', $invoice, $note);
127 127
 		return $note_id;
128 128
 	}
129 129
 
Please login to merge, or discard this patch.
includes/class-wpinv-item.php 2 patches
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 = sanitize_text_field( $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 = sanitize_text_field( $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.
Spacing   +229 added lines, -229 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -78,30 +78,30 @@  discard block
 block discarded – undo
78 78
 	 *
79 79
 	 * @param  int|object|WPInv_Item|WP_Post $item Item to read.
80 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 );
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 94
 		} else {
95
-			$this->set_object_read( true );
95
+			$this->set_object_read(true);
96 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 ) {
102
-            $this->post = get_post( $this->get_id() );
101
+		if ($this->get_id() > 0) {
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
 	}
@@ -128,8 +128,8 @@  discard block
 block discarded – undo
128 128
 	 * @param  string $context View or edit context.
129 129
 	 * @return int
130 130
 	 */
131
-	public function get_parent_id( $context = 'view' ) {
132
-		return (int) $this->get_prop( 'parent_id', $context );
131
+	public function get_parent_id($context = 'view') {
132
+		return (int) $this->get_prop('parent_id', $context);
133 133
     }
134 134
 
135 135
     /**
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
 	 * @param  string $context View or edit context.
140 140
 	 * @return string
141 141
 	 */
142
-	public function get_status( $context = 'view' ) {
143
-		return $this->get_prop( 'status', $context );
142
+	public function get_status($context = 'view') {
143
+		return $this->get_prop('status', $context);
144 144
     }
145 145
 
146 146
     /**
@@ -150,8 +150,8 @@  discard block
 block discarded – undo
150 150
 	 * @param  string $context View or edit context.
151 151
 	 * @return string
152 152
 	 */
153
-	public function get_version( $context = 'view' ) {
154
-		return $this->get_prop( 'version', $context );
153
+	public function get_version($context = 'view') {
154
+		return $this->get_prop('version', $context);
155 155
     }
156 156
 
157 157
     /**
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
 	 * @param  string $context View or edit context.
162 162
 	 * @return string
163 163
 	 */
164
-	public function get_date_created( $context = 'view' ) {
165
-		return $this->get_prop( 'date_created', $context );
164
+	public function get_date_created($context = 'view') {
165
+		return $this->get_prop('date_created', $context);
166 166
     }
167 167
 
168 168
     /**
@@ -172,11 +172,11 @@  discard block
 block discarded – undo
172 172
 	 * @param  string $context View or edit context.
173 173
 	 * @return string
174 174
 	 */
175
-	public function get_date_created_gmt( $context = 'view' ) {
176
-        $date = $this->get_date_created( $context );
175
+	public function get_date_created_gmt($context = 'view') {
176
+        $date = $this->get_date_created($context);
177 177
 
178
-        if ( $date ) {
179
-            $date = get_gmt_from_date( $date );
178
+        if ($date) {
179
+            $date = get_gmt_from_date($date);
180 180
         }
181 181
 		return $date;
182 182
     }
@@ -188,8 +188,8 @@  discard block
 block discarded – undo
188 188
 	 * @param  string $context View or edit context.
189 189
 	 * @return string
190 190
 	 */
191
-	public function get_date_modified( $context = 'view' ) {
192
-		return $this->get_prop( 'date_modified', $context );
191
+	public function get_date_modified($context = 'view') {
192
+		return $this->get_prop('date_modified', $context);
193 193
     }
194 194
 
195 195
     /**
@@ -199,11 +199,11 @@  discard block
 block discarded – undo
199 199
 	 * @param  string $context View or edit context.
200 200
 	 * @return string
201 201
 	 */
202
-	public function get_date_modified_gmt( $context = 'view' ) {
203
-        $date = $this->get_date_modified( $context );
202
+	public function get_date_modified_gmt($context = 'view') {
203
+        $date = $this->get_date_modified($context);
204 204
 
205
-        if ( $date ) {
206
-            $date = get_gmt_from_date( $date );
205
+        if ($date) {
206
+            $date = get_gmt_from_date($date);
207 207
         }
208 208
 		return $date;
209 209
     }
@@ -215,8 +215,8 @@  discard block
 block discarded – undo
215 215
 	 * @param  string $context View or edit context.
216 216
 	 * @return string
217 217
 	 */
218
-	public function get_name( $context = 'view' ) {
219
-		return $this->get_prop( 'name', $context );
218
+	public function get_name($context = 'view') {
219
+		return $this->get_prop('name', $context);
220 220
     }
221 221
 
222 222
     /**
@@ -226,8 +226,8 @@  discard block
 block discarded – undo
226 226
 	 * @param  string $context View or edit context.
227 227
 	 * @return string
228 228
 	 */
229
-	public function get_title( $context = 'view' ) {
230
-		return $this->get_name( $context );
229
+	public function get_title($context = 'view') {
230
+		return $this->get_name($context);
231 231
     }
232 232
 
233 233
     /**
@@ -237,8 +237,8 @@  discard block
 block discarded – undo
237 237
 	 * @param  string $context View or edit context.
238 238
 	 * @return string
239 239
 	 */
240
-	public function get_description( $context = 'view' ) {
241
-		return $this->get_prop( 'description', $context );
240
+	public function get_description($context = 'view') {
241
+		return $this->get_prop('description', $context);
242 242
     }
243 243
 
244 244
     /**
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
 	 * @param  string $context View or edit context.
249 249
 	 * @return string
250 250
 	 */
251
-	public function get_excerpt( $context = 'view' ) {
252
-		return $this->get_description( $context );
251
+	public function get_excerpt($context = 'view') {
252
+		return $this->get_description($context);
253 253
     }
254 254
 
255 255
     /**
@@ -259,8 +259,8 @@  discard block
 block discarded – undo
259 259
 	 * @param  string $context View or edit context.
260 260
 	 * @return string
261 261
 	 */
262
-	public function get_summary( $context = 'view' ) {
263
-		return $this->get_description( $context );
262
+	public function get_summary($context = 'view') {
263
+		return $this->get_description($context);
264 264
     }
265 265
 
266 266
     /**
@@ -270,8 +270,8 @@  discard block
 block discarded – undo
270 270
 	 * @param  string $context View or edit context.
271 271
 	 * @return int
272 272
 	 */
273
-	public function get_author( $context = 'view' ) {
274
-		return (int) $this->get_prop( 'author', $context );
273
+	public function get_author($context = 'view') {
274
+		return (int) $this->get_prop('author', $context);
275 275
 	}
276 276
 	
277 277
 	/**
@@ -281,8 +281,8 @@  discard block
 block discarded – undo
281 281
 	 * @param  string $context View or edit context.
282 282
 	 * @return int
283 283
 	 */
284
-	public function get_owner( $context = 'view' ) {
285
-		return $this->get_author( $context );
284
+	public function get_owner($context = 'view') {
285
+		return $this->get_author($context);
286 286
     }
287 287
 
288 288
     /**
@@ -292,8 +292,8 @@  discard block
 block discarded – undo
292 292
 	 * @param  string $context View or edit context.
293 293
 	 * @return float
294 294
 	 */
295
-	public function get_price( $context = 'view' ) {
296
-        return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) );
295
+	public function get_price($context = 'view') {
296
+        return wpinv_sanitize_amount($this->get_prop('price', $context));
297 297
 	}
298 298
 	
299 299
 	/**
@@ -303,15 +303,15 @@  discard block
 block discarded – undo
303 303
 	 * @param  string $context View or edit context.
304 304
 	 * @return float
305 305
 	 */
306
-	public function get_initial_price( $context = 'view' ) {
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() ) {
310
+		if ($this->has_free_trial()) {
311 311
 			$price = 0;
312 312
 		}
313 313
 
314
-        return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) );
314
+        return wpinv_sanitize_amount(apply_filters('wpinv_get_initial_item_price', $price, $this));
315 315
     }
316 316
 
317 317
     /**
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 	 * @return string
323 323
 	 */
324 324
     public function get_the_price() {
325
-        return wpinv_price( wpinv_format_amount( $this->get_price() ) );
325
+        return wpinv_price(wpinv_format_amount($this->get_price()));
326 326
 	}
327 327
 
328 328
 	/**
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 	 * @return string
334 334
 	 */
335 335
     public function get_the_initial_price() {
336
-        return wpinv_price( wpinv_format_amount( $this->get_initial_price() ) );
336
+        return wpinv_price(wpinv_format_amount($this->get_initial_price()));
337 337
     }
338 338
 
339 339
     /**
@@ -343,8 +343,8 @@  discard block
 block discarded – undo
343 343
 	 * @param  string $context View or edit context.
344 344
 	 * @return string
345 345
 	 */
346
-	public function get_vat_rule( $context = 'view' ) {
347
-        return $this->get_prop( 'vat_rule', $context );
346
+	public function get_vat_rule($context = 'view') {
347
+        return $this->get_prop('vat_rule', $context);
348 348
     }
349 349
 
350 350
     /**
@@ -354,8 +354,8 @@  discard block
 block discarded – undo
354 354
 	 * @param  string $context View or edit context.
355 355
 	 * @return string
356 356
 	 */
357
-	public function get_vat_class( $context = 'view' ) {
358
-        return $this->get_prop( 'vat_class', $context );
357
+	public function get_vat_class($context = 'view') {
358
+        return $this->get_prop('vat_class', $context);
359 359
     }
360 360
 
361 361
     /**
@@ -365,8 +365,8 @@  discard block
 block discarded – undo
365 365
 	 * @param  string $context View or edit context.
366 366
 	 * @return string
367 367
 	 */
368
-	public function get_type( $context = 'view' ) {
369
-        return $this->get_prop( 'type', $context );
368
+	public function get_type($context = 'view') {
369
+        return $this->get_prop('type', $context);
370 370
     }
371 371
 
372 372
     /**
@@ -376,8 +376,8 @@  discard block
 block discarded – undo
376 376
 	 * @param  string $context View or edit context.
377 377
 	 * @return string
378 378
 	 */
379
-	public function get_custom_id( $context = 'view' ) {
380
-        return $this->get_prop( 'custom_id', $context );
379
+	public function get_custom_id($context = 'view') {
380
+        return $this->get_prop('custom_id', $context);
381 381
     }
382 382
 
383 383
     /**
@@ -387,8 +387,8 @@  discard block
 block discarded – undo
387 387
 	 * @param  string $context View or edit context.
388 388
 	 * @return string
389 389
 	 */
390
-	public function get_custom_name( $context = 'view' ) {
391
-        return $this->get_prop( 'custom_name', $context );
390
+	public function get_custom_name($context = 'view') {
391
+        return $this->get_prop('custom_name', $context);
392 392
     }
393 393
 
394 394
     /**
@@ -398,8 +398,8 @@  discard block
 block discarded – undo
398 398
 	 * @param  string $context View or edit context.
399 399
 	 * @return string
400 400
 	 */
401
-	public function get_custom_singular_name( $context = 'view' ) {
402
-        return $this->get_prop( 'custom_singular_name', $context );
401
+	public function get_custom_singular_name($context = 'view') {
402
+        return $this->get_prop('custom_singular_name', $context);
403 403
     }
404 404
 
405 405
     /**
@@ -409,8 +409,8 @@  discard block
 block discarded – undo
409 409
 	 * @param  string $context View or edit context.
410 410
 	 * @return int
411 411
 	 */
412
-	public function get_is_editable( $context = 'view' ) {
413
-        return (int) $this->get_prop( 'is_editable', $context );
412
+	public function get_is_editable($context = 'view') {
413
+        return (int) $this->get_prop('is_editable', $context);
414 414
     }
415 415
 
416 416
     /**
@@ -420,8 +420,8 @@  discard block
 block discarded – undo
420 420
 	 * @param  string $context View or edit context.
421 421
 	 * @return int
422 422
 	 */
423
-	public function get_editable( $context = 'view' ) {
424
-		return $this->get_is_editable( $context );
423
+	public function get_editable($context = 'view') {
424
+		return $this->get_is_editable($context);
425 425
     }
426 426
 
427 427
     /**
@@ -431,8 +431,8 @@  discard block
 block discarded – undo
431 431
 	 * @param  string $context View or edit context.
432 432
 	 * @return int
433 433
 	 */
434
-	public function get_is_dynamic_pricing( $context = 'view' ) {
435
-        return (int) $this->get_prop( 'is_dynamic_pricing', $context );
434
+	public function get_is_dynamic_pricing($context = 'view') {
435
+        return (int) $this->get_prop('is_dynamic_pricing', $context);
436 436
     }
437 437
 
438 438
     /**
@@ -442,8 +442,8 @@  discard block
 block discarded – undo
442 442
 	 * @param  string $context View or edit context.
443 443
 	 * @return float
444 444
 	 */
445
-	public function get_minimum_price( $context = 'view' ) {
446
-        return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) );
445
+	public function get_minimum_price($context = 'view') {
446
+        return wpinv_sanitize_amount($this->get_prop('minimum_price', $context));
447 447
     }
448 448
 
449 449
     /**
@@ -453,8 +453,8 @@  discard block
 block discarded – undo
453 453
 	 * @param  string $context View or edit context.
454 454
 	 * @return int
455 455
 	 */
456
-	public function get_is_recurring( $context = 'view' ) {
457
-        return (int) $this->get_prop( 'is_recurring', $context );
456
+	public function get_is_recurring($context = 'view') {
457
+        return (int) $this->get_prop('is_recurring', $context);
458 458
 	}
459 459
 	
460 460
 	/**
@@ -464,9 +464,9 @@  discard block
 block discarded – undo
464 464
 	 * @param  string $context View or edit context.
465 465
 	 * @return float
466 466
 	 */
467
-	public function get_recurring_price( $context = 'view' ) {
468
-		$price = $this->get_price( $context );
469
-        return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) );
467
+	public function get_recurring_price($context = 'view') {
468
+		$price = $this->get_price($context);
469
+        return wpinv_sanitize_amount(apply_filters('wpinv_get_recurring_item_price', $price, $this->ID));
470 470
 	}
471 471
 
472 472
 	/**
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
 	 * @return string
478 478
 	 */
479 479
     public function get_the_recurring_price() {
480
-        return wpinv_price( wpinv_format_amount( $this->get_recurring_price() ) );
480
+        return wpinv_price(wpinv_format_amount($this->get_recurring_price()));
481 481
 	}
482 482
 
483 483
 	/**
@@ -498,15 +498,15 @@  discard block
 block discarded – undo
498 498
 		$period   = $this->get_recurring_period();
499 499
 		$interval = $this->get_recurring_interval();
500 500
 
501
-		if ( $this->has_free_trial() ) {
501
+		if ($this->has_free_trial()) {
502 502
 			$period   = $this->get_trial_period();
503 503
 			$interval = $this->get_trial_interval();
504 504
 		}
505 505
 
506
-		$period       = $periods[ $period ];
507
-		$interval     = empty( $interval ) ? 1 : $interval;
508
-		$next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
509
-        return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this );
506
+		$period       = $periods[$period];
507
+		$interval     = empty($interval) ? 1 : $interval;
508
+		$next_renewal = strtotime("+$interval $period", current_time('timestamp'));
509
+        return apply_filters('wpinv_get_first_renewal_date', $next_renewal, $this);
510 510
     }
511 511
 
512 512
     /**
@@ -516,14 +516,14 @@  discard block
 block discarded – undo
516 516
 	 * @param  bool $full Return abbreviation or in full.
517 517
 	 * @return string
518 518
 	 */
519
-	public function get_recurring_period( $full = false ) {
520
-        $period = $this->get_prop( 'recurring_period', 'view' );
519
+	public function get_recurring_period($full = false) {
520
+        $period = $this->get_prop('recurring_period', 'view');
521 521
 
522
-        if ( $full && ! is_bool( $full ) ) {
522
+        if ($full && !is_bool($full)) {
523 523
             $full = false;
524 524
         }
525 525
 
526
-        return getpaid_sanitize_recurring_period( $period, $full );
526
+        return getpaid_sanitize_recurring_period($period, $full);
527 527
     }
528 528
 
529 529
     /**
@@ -533,10 +533,10 @@  discard block
 block discarded – undo
533 533
 	 * @param  string $context View or edit context.
534 534
 	 * @return int
535 535
 	 */
536
-	public function get_recurring_interval( $context = 'view' ) {
537
-		$interval = absint( $this->get_prop( 'recurring_interval', $context ) );
536
+	public function get_recurring_interval($context = 'view') {
537
+		$interval = absint($this->get_prop('recurring_interval', $context));
538 538
 
539
-		if ( $interval < 1 ) {
539
+		if ($interval < 1) {
540 540
 			$interval = 1;
541 541
 		}
542 542
 
@@ -550,8 +550,8 @@  discard block
 block discarded – undo
550 550
 	 * @param  string $context View or edit context.
551 551
 	 * @return int
552 552
 	 */
553
-	public function get_recurring_limit( $context = 'view' ) {
554
-        return (int) $this->get_prop( 'recurring_limit', $context );
553
+	public function get_recurring_limit($context = 'view') {
554
+        return (int) $this->get_prop('recurring_limit', $context);
555 555
     }
556 556
 
557 557
     /**
@@ -561,8 +561,8 @@  discard block
 block discarded – undo
561 561
 	 * @param  string $context View or edit context.
562 562
 	 * @return int
563 563
 	 */
564
-	public function get_is_free_trial( $context = 'view' ) {
565
-        return (int) $this->get_prop( 'is_free_trial', $context );
564
+	public function get_is_free_trial($context = 'view') {
565
+        return (int) $this->get_prop('is_free_trial', $context);
566 566
     }
567 567
 
568 568
     /**
@@ -572,8 +572,8 @@  discard block
 block discarded – undo
572 572
 	 * @param  string $context View or edit context.
573 573
 	 * @return int
574 574
 	 */
575
-	public function get_free_trial( $context = 'view' ) {
576
-        return $this->get_is_free_trial( $context );
575
+	public function get_free_trial($context = 'view') {
576
+        return $this->get_is_free_trial($context);
577 577
     }
578 578
 
579 579
     /**
@@ -583,14 +583,14 @@  discard block
 block discarded – undo
583 583
 	 * @param  bool $full Return abbreviation or in full.
584 584
 	 * @return string
585 585
 	 */
586
-	public function get_trial_period( $full = false ) {
587
-        $period = $this->get_prop( 'trial_period', 'view' );
586
+	public function get_trial_period($full = false) {
587
+        $period = $this->get_prop('trial_period', 'view');
588 588
 
589
-        if ( $full && ! is_bool( $full ) ) {
589
+        if ($full && !is_bool($full)) {
590 590
             $full = false;
591 591
         }
592 592
 
593
-        return getpaid_sanitize_recurring_period( $period, $full );
593
+        return getpaid_sanitize_recurring_period($period, $full);
594 594
     }
595 595
 
596 596
     /**
@@ -600,8 +600,8 @@  discard block
 block discarded – undo
600 600
 	 * @param  string $context View or edit context.
601 601
 	 * @return int
602 602
 	 */
603
-	public function get_trial_interval( $context = 'view' ) {
604
-        return (int) $this->get_prop( 'trial_interval', $context );
603
+	public function get_trial_interval($context = 'view') {
604
+        return (int) $this->get_prop('trial_interval', $context);
605 605
 	}
606 606
 	
607 607
 	/**
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
 	 * @return string
612 612
 	 */
613 613
 	public function get_edit_url() {
614
-        return get_edit_post_link( $this->get_id() );
614
+        return get_edit_post_link($this->get_id());
615 615
 	}
616 616
 
617 617
 	/**
@@ -625,35 +625,35 @@  discard block
 block discarded – undo
625 625
 	 * @since 1.0.15
626 626
 	 * @return int
627 627
 	 */
628
-	public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) {
628
+	public static function get_item_id_by_field($value, $field = 'custom_id', $type = '') {
629 629
 
630 630
 		// Trim the value.
631
-		$value = sanitize_text_field( $value );
631
+		$value = sanitize_text_field($value);
632 632
 
633
-		if ( empty( $value ) ) {
633
+		if (empty($value)) {
634 634
 			return 0;
635 635
 		}
636 636
 
637 637
         // Valid fields.
638
-        $fields = array( 'custom_id', 'name', 'slug' );
638
+        $fields = array('custom_id', 'name', 'slug');
639 639
 
640 640
 		// Ensure a field has been passed.
641
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
641
+		if (empty($field) || !in_array($field, $fields)) {
642 642
 			return 0;
643 643
 		}
644 644
 
645
-		if ( $field == 'name' ) {
645
+		if ($field == 'name') {
646 646
 			$field = 'slug';
647 647
 		} 
648 648
 
649 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 ) ) {
650
+		$item_id = wp_cache_get($value, "getpaid_{$type}_item_{$field}s_to_item_ids");
651
+		if (!empty($item_id)) {
652 652
 			return $item_id;
653 653
 		}
654 654
 
655 655
 		// Fetch from the db.
656
-		if ( $field =='slug' ) {
656
+		if ($field == 'slug') {
657 657
 			$items = get_posts(
658 658
 				array(
659 659
 					'post_type'      => 'wpi_item',
@@ -664,7 +664,7 @@  discard block
 block discarded – undo
664 664
 			);
665 665
 		}
666 666
 
667
-		if ( $field =='custom_id' ) {
667
+		if ($field == 'custom_id') {
668 668
 			$items = get_posts(
669 669
 				array(
670 670
 					'post_type'      => 'wpi_item',
@@ -684,12 +684,12 @@  discard block
 block discarded – undo
684 684
 			);
685 685
 		}
686 686
 
687
-		if ( empty( $items ) ) {
687
+		if (empty($items)) {
688 688
 			return 0;
689 689
 		}
690 690
 
691 691
 		// Update the cache with our data
692
-		wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" );
692
+		wp_cache_set($value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids");
693 693
 
694 694
 		return $items[0]->ID;
695 695
     }
@@ -697,19 +697,19 @@  discard block
 block discarded – undo
697 697
     /**
698 698
      * Margic method for retrieving a property.
699 699
      */
700
-    public function __get( $key ) {
700
+    public function __get($key) {
701 701
 
702 702
         // Check if we have a helper method for that.
703
-        if ( method_exists( $this, 'get_' . $key ) ) {
704
-            return call_user_func( array( $this, 'get_' . $key ) );
703
+        if (method_exists($this, 'get_' . $key)) {
704
+            return call_user_func(array($this, 'get_' . $key));
705 705
         }
706 706
 
707 707
         // Check if the key is in the associated $post object.
708
-        if ( ! empty( $this->post ) && isset( $this->post->$key ) ) {
708
+        if (!empty($this->post) && isset($this->post->$key)) {
709 709
             return $this->post->$key;
710 710
         }
711 711
 
712
-        return $this->get_prop( $key );
712
+        return $this->get_prop($key);
713 713
 
714 714
     }
715 715
 
@@ -728,11 +728,11 @@  discard block
 block discarded – undo
728 728
 	 *
729 729
 	 * @since 1.0.19
730 730
 	 */
731
-	public function set_parent_id( $value ) {
732
-		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
731
+	public function set_parent_id($value) {
732
+		if ($value && ($value === $this->get_id() || !get_post($value))) {
733 733
 			return;
734 734
 		}
735
-		$this->set_prop( 'parent_id', absint( $value ) );
735
+		$this->set_prop('parent_id', absint($value));
736 736
 	}
737 737
 
738 738
     /**
@@ -742,10 +742,10 @@  discard block
 block discarded – undo
742 742
 	 * @param  string $status New status.
743 743
 	 * @return array details of change.
744 744
 	 */
745
-	public function set_status( $status ) {
745
+	public function set_status($status) {
746 746
         $old_status = $this->get_status();
747 747
 
748
-        $this->set_prop( 'status', $status );
748
+        $this->set_prop('status', $status);
749 749
 
750 750
 		return array(
751 751
 			'from' => $old_status,
@@ -758,8 +758,8 @@  discard block
 block discarded – undo
758 758
 	 *
759 759
 	 * @since 1.0.19
760 760
 	 */
761
-	public function set_version( $value ) {
762
-		$this->set_prop( 'version', $value );
761
+	public function set_version($value) {
762
+		$this->set_prop('version', $value);
763 763
     }
764 764
 
765 765
     /**
@@ -769,11 +769,11 @@  discard block
 block discarded – undo
769 769
 	 * @param string $value Value to set.
770 770
      * @return bool Whether or not the date was set.
771 771
 	 */
772
-	public function set_date_created( $value ) {
773
-        $date = strtotime( $value );
772
+	public function set_date_created($value) {
773
+        $date = strtotime($value);
774 774
 
775
-        if ( $date ) {
776
-            $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) );
775
+        if ($date) {
776
+            $this->set_prop('date_created', date('Y-m-d H:i:s', $date));
777 777
             return true;
778 778
         }
779 779
 
@@ -788,11 +788,11 @@  discard block
 block discarded – undo
788 788
 	 * @param string $value Value to set.
789 789
      * @return bool Whether or not the date was set.
790 790
 	 */
791
-	public function set_date_modified( $value ) {
792
-        $date = strtotime( $value );
791
+	public function set_date_modified($value) {
792
+        $date = strtotime($value);
793 793
 
794
-        if ( $date ) {
795
-            $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) );
794
+        if ($date) {
795
+            $this->set_prop('date_modified', date('Y-m-d H:i:s', $date));
796 796
             return true;
797 797
         }
798 798
 
@@ -806,9 +806,9 @@  discard block
 block discarded – undo
806 806
 	 * @since 1.0.19
807 807
 	 * @param  string $value New name.
808 808
 	 */
809
-	public function set_name( $value ) {
810
-        $name = sanitize_text_field( $value );
811
-		$this->set_prop( 'name', $name );
809
+	public function set_name($value) {
810
+        $name = sanitize_text_field($value);
811
+		$this->set_prop('name', $name);
812 812
     }
813 813
 
814 814
     /**
@@ -817,8 +817,8 @@  discard block
 block discarded – undo
817 817
 	 * @since 1.0.19
818 818
 	 * @param  string $value New name.
819 819
 	 */
820
-	public function set_title( $value ) {
821
-		$this->set_name( $value );
820
+	public function set_title($value) {
821
+		$this->set_name($value);
822 822
     }
823 823
 
824 824
     /**
@@ -827,9 +827,9 @@  discard block
 block discarded – undo
827 827
 	 * @since 1.0.19
828 828
 	 * @param  string $value New description.
829 829
 	 */
830
-	public function set_description( $value ) {
831
-        $description = wp_kses_post( $value );
832
-		return $this->set_prop( 'description', $description );
830
+	public function set_description($value) {
831
+        $description = wp_kses_post($value);
832
+		return $this->set_prop('description', $description);
833 833
     }
834 834
 
835 835
     /**
@@ -838,8 +838,8 @@  discard block
 block discarded – undo
838 838
 	 * @since 1.0.19
839 839
 	 * @param  string $value New description.
840 840
 	 */
841
-	public function set_excerpt( $value ) {
842
-		$this->set_description( $value );
841
+	public function set_excerpt($value) {
842
+		$this->set_description($value);
843 843
     }
844 844
 
845 845
     /**
@@ -848,8 +848,8 @@  discard block
 block discarded – undo
848 848
 	 * @since 1.0.19
849 849
 	 * @param  string $value New description.
850 850
 	 */
851
-	public function set_summary( $value ) {
852
-		$this->set_description( $value );
851
+	public function set_summary($value) {
852
+		$this->set_description($value);
853 853
     }
854 854
 
855 855
     /**
@@ -858,8 +858,8 @@  discard block
 block discarded – undo
858 858
 	 * @since 1.0.19
859 859
 	 * @param  int $value New author.
860 860
 	 */
861
-	public function set_author( $value ) {
862
-		$this->set_prop( 'author', (int) $value );
861
+	public function set_author($value) {
862
+		$this->set_prop('author', (int) $value);
863 863
 	}
864 864
 	
865 865
 	/**
@@ -868,8 +868,8 @@  discard block
 block discarded – undo
868 868
 	 * @since 1.0.19
869 869
 	 * @param  int $value New author.
870 870
 	 */
871
-	public function set_owner( $value ) {
872
-		$this->set_author( $value );
871
+	public function set_owner($value) {
872
+		$this->set_author($value);
873 873
     }
874 874
 
875 875
     /**
@@ -878,8 +878,8 @@  discard block
 block discarded – undo
878 878
 	 * @since 1.0.19
879 879
 	 * @param  float $value New price.
880 880
 	 */
881
-	public function set_price( $value ) {
882
-        $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) );
881
+	public function set_price($value) {
882
+        $this->set_prop('price', (float) wpinv_sanitize_amount($value));
883 883
     }
884 884
 
885 885
     /**
@@ -888,8 +888,8 @@  discard block
 block discarded – undo
888 888
 	 * @since 1.0.19
889 889
 	 * @param  string $value new rule.
890 890
 	 */
891
-	public function set_vat_rule( $value ) {
892
-        $this->set_prop( 'vat_rule', $value );
891
+	public function set_vat_rule($value) {
892
+        $this->set_prop('vat_rule', $value);
893 893
     }
894 894
 
895 895
     /**
@@ -898,8 +898,8 @@  discard block
 block discarded – undo
898 898
 	 * @since 1.0.19
899 899
 	 * @param  string $value new class.
900 900
 	 */
901
-	public function set_vat_class( $value ) {
902
-        $this->set_prop( 'vat_class', $value );
901
+	public function set_vat_class($value) {
902
+        $this->set_prop('vat_class', $value);
903 903
     }
904 904
 
905 905
     /**
@@ -909,13 +909,13 @@  discard block
 block discarded – undo
909 909
 	 * @param  string $value new item type.
910 910
 	 * @return string
911 911
 	 */
912
-	public function set_type( $value ) {
912
+	public function set_type($value) {
913 913
 
914
-        if ( empty( $value ) ) {
914
+        if (empty($value)) {
915 915
             $value = 'custom';
916 916
         }
917 917
 
918
-        $this->set_prop( 'type', $value );
918
+        $this->set_prop('type', $value);
919 919
     }
920 920
 
921 921
     /**
@@ -924,8 +924,8 @@  discard block
 block discarded – undo
924 924
 	 * @since 1.0.19
925 925
 	 * @param  string $value new custom id.
926 926
 	 */
927
-	public function set_custom_id( $value ) {
928
-        $this->set_prop( 'custom_id', $value );
927
+	public function set_custom_id($value) {
928
+        $this->set_prop('custom_id', $value);
929 929
     }
930 930
 
931 931
     /**
@@ -934,8 +934,8 @@  discard block
 block discarded – undo
934 934
 	 * @since 1.0.19
935 935
 	 * @param  string $value new custom name.
936 936
 	 */
937
-	public function set_custom_name( $value ) {
938
-        $this->set_prop( 'custom_name', $value );
937
+	public function set_custom_name($value) {
938
+        $this->set_prop('custom_name', $value);
939 939
     }
940 940
 
941 941
     /**
@@ -944,8 +944,8 @@  discard block
 block discarded – undo
944 944
 	 * @since 1.0.19
945 945
 	 * @param  string $value new custom singular name.
946 946
 	 */
947
-	public function set_custom_singular_name( $value ) {
948
-        $this->set_prop( 'custom_singular_name', $value );
947
+	public function set_custom_singular_name($value) {
948
+        $this->set_prop('custom_singular_name', $value);
949 949
     }
950 950
 
951 951
     /**
@@ -954,9 +954,9 @@  discard block
 block discarded – undo
954 954
 	 * @since 1.0.19
955 955
 	 * @param  int|bool $value whether or not the item is editable.
956 956
 	 */
957
-	public function set_is_editable( $value ) {
958
-		if ( is_numeric( $value ) ) {
959
-			$this->set_prop( 'is_editable', (int) $value );
957
+	public function set_is_editable($value) {
958
+		if (is_numeric($value)) {
959
+			$this->set_prop('is_editable', (int) $value);
960 960
 		}
961 961
     }
962 962
 
@@ -966,8 +966,8 @@  discard block
 block discarded – undo
966 966
 	 * @since 1.0.19
967 967
 	 * @param  int|bool $value whether or not dynamic pricing is allowed.
968 968
 	 */
969
-	public function set_is_dynamic_pricing( $value ) {
970
-        $this->set_prop( 'is_dynamic_pricing', (int) $value );
969
+	public function set_is_dynamic_pricing($value) {
970
+        $this->set_prop('is_dynamic_pricing', (int) $value);
971 971
     }
972 972
 
973 973
     /**
@@ -976,8 +976,8 @@  discard block
 block discarded – undo
976 976
 	 * @since 1.0.19
977 977
 	 * @param  float $value minimum price.
978 978
 	 */
979
-	public function set_minimum_price( $value ) {
980
-        $this->set_prop( 'minimum_price',  (float) wpinv_sanitize_amount( $value ) );
979
+	public function set_minimum_price($value) {
980
+        $this->set_prop('minimum_price', (float) wpinv_sanitize_amount($value));
981 981
     }
982 982
 
983 983
     /**
@@ -986,8 +986,8 @@  discard block
 block discarded – undo
986 986
 	 * @since 1.0.19
987 987
 	 * @param  int|bool $value whether or not dynamic pricing is allowed.
988 988
 	 */
989
-	public function set_is_recurring( $value ) {
990
-        $this->set_prop( 'is_recurring', (int) $value );
989
+	public function set_is_recurring($value) {
990
+        $this->set_prop('is_recurring', (int) $value);
991 991
     }
992 992
 
993 993
     /**
@@ -996,8 +996,8 @@  discard block
 block discarded – undo
996 996
 	 * @since 1.0.19
997 997
 	 * @param  string $value new period.
998 998
 	 */
999
-	public function set_recurring_period( $value ) {
1000
-        $this->set_prop( 'recurring_period', $value );
999
+	public function set_recurring_period($value) {
1000
+        $this->set_prop('recurring_period', $value);
1001 1001
     }
1002 1002
 
1003 1003
     /**
@@ -1006,8 +1006,8 @@  discard block
 block discarded – undo
1006 1006
 	 * @since 1.0.19
1007 1007
 	 * @param  int $value recurring interval.
1008 1008
 	 */
1009
-	public function set_recurring_interval( $value ) {
1010
-        return $this->set_prop( 'recurring_interval', (int) $value );
1009
+	public function set_recurring_interval($value) {
1010
+        return $this->set_prop('recurring_interval', (int) $value);
1011 1011
     }
1012 1012
 
1013 1013
     /**
@@ -1016,8 +1016,8 @@  discard block
 block discarded – undo
1016 1016
 	 * @param  int $value The recurring limit.
1017 1017
 	 * @return int
1018 1018
 	 */
1019
-	public function set_recurring_limit( $value ) {
1020
-        $this->set_prop( 'recurring_limit', (int) $value );
1019
+	public function set_recurring_limit($value) {
1020
+        $this->set_prop('recurring_limit', (int) $value);
1021 1021
     }
1022 1022
 
1023 1023
     /**
@@ -1026,8 +1026,8 @@  discard block
 block discarded – undo
1026 1026
 	 * @since 1.0.19
1027 1027
 	 * @param  int|bool $value whether or not it has a free trial.
1028 1028
 	 */
1029
-	public function set_is_free_trial( $value ) {
1030
-        $this->set_prop( 'is_free_trial', (int) $value );
1029
+	public function set_is_free_trial($value) {
1030
+        $this->set_prop('is_free_trial', (int) $value);
1031 1031
     }
1032 1032
 
1033 1033
     /**
@@ -1036,8 +1036,8 @@  discard block
 block discarded – undo
1036 1036
 	 * @since 1.0.19
1037 1037
 	 * @param  string $value trial period.
1038 1038
 	 */
1039
-	public function set_trial_period( $value ) {
1040
-        $this->set_prop( 'trial_period', $value );
1039
+	public function set_trial_period($value) {
1040
+        $this->set_prop('trial_period', $value);
1041 1041
     }
1042 1042
 
1043 1043
     /**
@@ -1046,8 +1046,8 @@  discard block
 block discarded – undo
1046 1046
 	 * @since 1.0.19
1047 1047
 	 * @param  int $value trial interval.
1048 1048
 	 */
1049
-	public function set_trial_interval( $value ) {
1050
-        $this->set_prop( 'trial_interval', $value );
1049
+	public function set_trial_interval($value) {
1050
+        $this->set_prop('trial_interval', $value);
1051 1051
     }
1052 1052
 
1053 1053
     /**
@@ -1056,11 +1056,11 @@  discard block
 block discarded – undo
1056 1056
      * @deprecated
1057 1057
 	 * @return int item id
1058 1058
      */
1059
-    public function create( $data = array() ) {
1059
+    public function create($data = array()) {
1060 1060
 
1061 1061
 		// Set the properties.
1062
-		if ( is_array( $data ) ) {
1063
-			$this->set_props( $data );
1062
+		if (is_array($data)) {
1063
+			$this->set_props($data);
1064 1064
 		}
1065 1065
 
1066 1066
 		// Save the item.
@@ -1074,8 +1074,8 @@  discard block
 block discarded – undo
1074 1074
      * @deprecated
1075 1075
 	 * @return int item id
1076 1076
      */
1077
-    public function update( $data = array() ) {
1078
-        return $this->create( $data );
1077
+    public function update($data = array()) {
1078
+        return $this->create($data);
1079 1079
     }
1080 1080
 
1081 1081
     /*
@@ -1115,7 +1115,7 @@  discard block
 block discarded – undo
1115 1115
 	 */
1116 1116
     public function has_free_trial() {
1117 1117
         $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false;
1118
-        return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this );
1118
+        return (bool) apply_filters('wpinv_item_has_free_trial', $has_trial, $this->ID, $this);
1119 1119
     }
1120 1120
 
1121 1121
     /**
@@ -1125,8 +1125,8 @@  discard block
 block discarded – undo
1125 1125
 	 * @return bool
1126 1126
 	 */
1127 1127
     public function is_free() {
1128
-        $is_free   = $this->get_price() == 0;
1129
-        return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this );
1128
+        $is_free = $this->get_price() == 0;
1129
+        return (bool) apply_filters('wpinv_is_free_item', $is_free, $this->ID, $this);
1130 1130
     }
1131 1131
 
1132 1132
     /**
@@ -1135,9 +1135,9 @@  discard block
 block discarded – undo
1135 1135
 	 * @param array|string $status Status to check.
1136 1136
 	 * @return bool
1137 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 );
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
     /**
@@ -1146,9 +1146,9 @@  discard block
 block discarded – undo
1146 1146
 	 * @param array|string $type Type to check.
1147 1147
 	 * @return bool
1148 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 );
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 1152
 	}
1153 1153
 
1154 1154
     /**
@@ -1159,52 +1159,52 @@  discard block
 block discarded – undo
1159 1159
 	 */
1160 1160
     public function is_editable() {
1161 1161
         $is_editable = $this->get_is_editable();
1162
-        return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this );
1162
+        return (bool) apply_filters('wpinv_item_is_editable', $is_editable, $this->ID, $this);
1163 1163
 	}
1164 1164
 
1165 1165
 	/**
1166 1166
 	 * Returns an array of cart fees.
1167 1167
 	 */
1168
-	public function get_fees( $type = 'fee', $item_id = 0 ) {
1168
+	public function get_fees($type = 'fee', $item_id = 0) {
1169 1169
         
1170
-        $fees = getpaid_session()->get( 'wpi_cart_fees' );
1170
+        $fees = getpaid_session()->get('wpi_cart_fees');
1171 1171
 
1172
-        if ( ! wpinv_get_cart_contents() ) {
1172
+        if (!wpinv_get_cart_contents()) {
1173 1173
             // We can only get item type fees when the cart is empty
1174 1174
             $type = 'custom';
1175 1175
         }
1176 1176
 
1177
-        if ( ! empty( $fees ) && ! empty( $type ) && 'all' !== $type ) {
1178
-            foreach( $fees as $key => $fee ) {
1179
-                if( ! empty( $fee['type'] ) && $type != $fee['type'] ) {
1180
-                    unset( $fees[ $key ] );
1177
+        if (!empty($fees) && !empty($type) && 'all' !== $type) {
1178
+            foreach ($fees as $key => $fee) {
1179
+                if (!empty($fee['type']) && $type != $fee['type']) {
1180
+                    unset($fees[$key]);
1181 1181
                 }
1182 1182
             }
1183 1183
         }
1184 1184
 
1185
-        if ( ! empty( $fees ) && ! empty( $item_id ) ) {
1185
+        if (!empty($fees) && !empty($item_id)) {
1186 1186
             // Remove fees that don't belong to the specified Item
1187
-            foreach ( $fees as $key => $fee ) {
1188
-                if ( (int) $item_id !== (int)$fee['custom_id'] ) {
1189
-                    unset( $fees[ $key ] );
1187
+            foreach ($fees as $key => $fee) {
1188
+                if ((int) $item_id !== (int) $fee['custom_id']) {
1189
+                    unset($fees[$key]);
1190 1190
                 }
1191 1191
             }
1192 1192
         }
1193 1193
 
1194
-        if ( ! empty( $fees ) ) {
1194
+        if (!empty($fees)) {
1195 1195
             // Remove fees that belong to a specific item but are not in the cart
1196
-            foreach( $fees as $key => $fee ) {
1197
-                if( empty( $fee['custom_id'] ) ) {
1196
+            foreach ($fees as $key => $fee) {
1197
+                if (empty($fee['custom_id'])) {
1198 1198
                     continue;
1199 1199
                 }
1200 1200
 
1201
-                if ( !wpinv_item_in_cart( $fee['custom_id'] ) ) {
1202
-                    unset( $fees[ $key ] );
1201
+                if (!wpinv_item_in_cart($fee['custom_id'])) {
1202
+                    unset($fees[$key]);
1203 1203
                 }
1204 1204
             }
1205 1205
         }
1206 1206
 
1207
-        return ! empty( $fees ) ? $fees : array();
1207
+        return !empty($fees) ? $fees : array();
1208 1208
     }
1209 1209
 
1210 1210
     /**
@@ -1216,11 +1216,11 @@  discard block
 block discarded – undo
1216 1216
     public function can_purchase() {
1217 1217
         $can_purchase = null !== $this->get_id();
1218 1218
 
1219
-        if ( ! current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) {
1219
+        if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') {
1220 1220
             $can_purchase = false;
1221 1221
         }
1222 1222
 
1223
-        return (bool) apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this );
1223
+        return (bool) apply_filters('wpinv_can_purchase_item', $can_purchase, $this);
1224 1224
     }
1225 1225
 
1226 1226
     /**
@@ -1230,6 +1230,6 @@  discard block
 block discarded – undo
1230 1230
 	 * @return bool
1231 1231
 	 */
1232 1232
     public function supports_dynamic_pricing() {
1233
-        return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this );
1233
+        return (bool) apply_filters('wpinv_item_supports_dynamic_pricing', true, $this);
1234 1234
     }
1235 1235
 }
Please login to merge, or discard this patch.
includes/class-wpinv-privacy-exporters.php 1 patch
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Personal data exporters.
4 4
  */
5 5
 
6
-defined( 'ABSPATH' ) || exit;
6
+defined('ABSPATH') || exit;
7 7
 
8 8
 /**
9 9
  * WPInv_Privacy_Exporters Class.
@@ -17,38 +17,38 @@  discard block
 block discarded – undo
17 17
      * @param int    $page  Page.
18 18
      * @return array An array of invoice data in name value pairs
19 19
      */
20
-    public static function customer_invoice_data_exporter( $email_address, $page ) {
20
+    public static function customer_invoice_data_exporter($email_address, $page) {
21 21
         $done           = false;
22 22
         $page           = (int) $page;
23 23
         $data_to_export = array();
24 24
 
25
-        $user           = get_user_by( 'email', $email_address );
26
-        if ( ! $user instanceof WP_User ) {
25
+        $user           = get_user_by('email', $email_address);
26
+        if (!$user instanceof WP_User) {
27 27
             return array(
28 28
                 'data' => $data_to_export,
29 29
                 'done' => true,
30 30
             );
31 31
         }
32 32
 
33
-        $args    = array(
33
+        $args = array(
34 34
             'limit'    => 30,
35 35
             'page'     => $page,
36 36
             'user'     => $user->ID,
37 37
         );
38 38
 
39
-        $invoices = wpinv_get_invoices( $args );
39
+        $invoices = wpinv_get_invoices($args);
40 40
 
41
-        if ( 0 < count( $invoices ) ) {
42
-            foreach ( $invoices as $invoice ) {
41
+        if (0 < count($invoices)) {
42
+            foreach ($invoices as $invoice) {
43 43
                 $data_to_export[] = array(
44 44
                     'group_id'          => 'customer_invoices',
45
-                    'group_label'       => __( 'Invoicing Data', 'invoicing' ),
46
-                    'group_description' => __( 'Customer invoicing data.', 'invoicing' ),
45
+                    'group_label'       => __('Invoicing Data', 'invoicing'),
46
+                    'group_description' => __('Customer invoicing data.', 'invoicing'),
47 47
                     'item_id'           => "wpinv-{$invoice->ID}",
48
-                    'data'              => self::get_customer_invoice_data( $invoice ),
48
+                    'data'              => self::get_customer_invoice_data($invoice),
49 49
                 );
50 50
             }
51
-            $done = 30 > count( $invoices );
51
+            $done = 30 > count($invoices);
52 52
         } else {
53 53
             $done = true;
54 54
         }
@@ -66,59 +66,59 @@  discard block
 block discarded – undo
66 66
      * @param WPInv_Invoice $invoice invoice object.
67 67
      * @return array
68 68
      */
69
-    public static function get_customer_invoice_data( $invoice ) {
69
+    public static function get_customer_invoice_data($invoice) {
70 70
         $personal_data = array();
71 71
 
72 72
         $props_to_export = array(
73
-            'number'               => __( 'Invoice Number', 'invoicing' ),
74
-            'created_date'         => __( 'Invoice Date', 'invoicing' ),
75
-            'status'               => __( 'Invoice Status', 'invoicing' ),
76
-            'total'                => __( 'Invoice Total', 'invoicing' ),
77
-            'items'                => __( 'Invoice Items', 'invoicing' ),
78
-            'first_name'           => __( 'First Name', 'invoicing' ),
79
-            'last_name'            => __( 'Last Name', 'invoicing' ),
80
-            'email'                => __( 'Email Address', 'invoicing' ),
81
-            '_wpinv_company'       => __( 'Company', 'invoicing' ),
82
-            'phone'                => __( 'Phone Number', 'invoicing' ),
83
-            'address'              => __( 'Address', 'invoicing' ),
84
-            '_wpinv_city'          => __( 'City', 'invoicing' ),
85
-            '_wpinv_country'       => __( 'Country', 'invoicing' ),
86
-            '_wpinv_state'         => __( 'State', 'invoicing' ),
87
-            '_wpinv_zip'           => __( 'Zip Code', 'invoicing' ),
73
+            'number'               => __('Invoice Number', 'invoicing'),
74
+            'created_date'         => __('Invoice Date', 'invoicing'),
75
+            'status'               => __('Invoice Status', 'invoicing'),
76
+            'total'                => __('Invoice Total', 'invoicing'),
77
+            'items'                => __('Invoice Items', 'invoicing'),
78
+            'first_name'           => __('First Name', 'invoicing'),
79
+            'last_name'            => __('Last Name', 'invoicing'),
80
+            'email'                => __('Email Address', 'invoicing'),
81
+            '_wpinv_company'       => __('Company', 'invoicing'),
82
+            'phone'                => __('Phone Number', 'invoicing'),
83
+            'address'              => __('Address', 'invoicing'),
84
+            '_wpinv_city'          => __('City', 'invoicing'),
85
+            '_wpinv_country'       => __('Country', 'invoicing'),
86
+            '_wpinv_state'         => __('State', 'invoicing'),
87
+            '_wpinv_zip'           => __('Zip Code', 'invoicing'),
88 88
         );
89 89
 
90
-        $subscription = wpinv_get_subscription( $invoice );
90
+        $subscription = wpinv_get_subscription($invoice);
91 91
         $period = $initial_amt = $bill_times = $billed = $renewal_date = '';
92 92
 
93
-        if ( $invoice->is_recurring() && !empty( $subscription ) ) {
94
-            $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->get_period(),$subscription->get_frequency() );
95
-            $period = wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $subscription->get_parent_payment()->get_currency() ) . ' / ' . $frequency;
96
-            $initial_amt = wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $subscription->get_parent_payment()->get_currency() );
97
-            $bill_times = $subscription->get_times_billed() . ' / ' . ( ( $subscription->get_bill_times() == 0 ) ? __( 'Until Cancelled', 'invoicing' ) : $subscription->get_bill_times() );
98
-            $renewal_date = ! empty( $subscription->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $subscription->expiration ) ) : __( 'N/A', 'invoicing' );
99
-
100
-            $props_to_export['period'] = __( 'Billing Cycle', 'invoicing' );
101
-            $props_to_export['initial_amount'] = __( 'Initial Amount', 'invoicing' );
102
-            $props_to_export['bill_times'] = __( 'Times Billed', 'invoicing' );
103
-            $props_to_export['renewal_date'] = __( 'Renewal Date', 'invoicing' );
93
+        if ($invoice->is_recurring() && !empty($subscription)) {
94
+            $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($subscription->get_period(), $subscription->get_frequency());
95
+            $period = wpinv_price(wpinv_format_amount($subscription->get_recurring_amount()), $subscription->get_parent_payment()->get_currency()) . ' / ' . $frequency;
96
+            $initial_amt = wpinv_price(wpinv_format_amount($subscription->get_initial_amount()), $subscription->get_parent_payment()->get_currency());
97
+            $bill_times = $subscription->get_times_billed() . ' / ' . (($subscription->get_bill_times() == 0) ? __('Until Cancelled', 'invoicing') : $subscription->get_bill_times());
98
+            $renewal_date = !empty($subscription->expiration) ? date_i18n(get_option('date_format'), strtotime($subscription->expiration)) : __('N/A', 'invoicing');
99
+
100
+            $props_to_export['period'] = __('Billing Cycle', 'invoicing');
101
+            $props_to_export['initial_amount'] = __('Initial Amount', 'invoicing');
102
+            $props_to_export['bill_times'] = __('Times Billed', 'invoicing');
103
+            $props_to_export['renewal_date'] = __('Renewal Date', 'invoicing');
104 104
         }
105 105
 
106
-        $props_to_export['ip'] = __( 'IP Address', 'invoicing' );
107
-        $props_to_export['view_url'] = __( 'Invoice Link', 'invoicing' );
106
+        $props_to_export['ip'] = __('IP Address', 'invoicing');
107
+        $props_to_export['view_url'] = __('Invoice Link', 'invoicing');
108 108
 
109
-        $props_to_export = apply_filters( 'wpinv_privacy_export_invoice_personal_data_props', $props_to_export, $invoice, $subscription);
109
+        $props_to_export = apply_filters('wpinv_privacy_export_invoice_personal_data_props', $props_to_export, $invoice, $subscription);
110 110
 
111
-        foreach ( $props_to_export as $prop => $name ) {
111
+        foreach ($props_to_export as $prop => $name) {
112 112
             $value = '';
113 113
 
114
-            switch ( $prop ) {
114
+            switch ($prop) {
115 115
                 case 'items':
116 116
                     $item_names = array();
117
-                    foreach ( $invoice->get_cart_details() as $key => $cart_item ) {
118
-                        $item_quantity  = $cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1;
117
+                    foreach ($invoice->get_cart_details() as $key => $cart_item) {
118
+                        $item_quantity = $cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1;
119 119
                         $item_names[] = $cart_item['name'] . ' x ' . $item_quantity;
120 120
                     }
121
-                    $value = implode( ', ', $item_names );
121
+                    $value = implode(', ', $item_names);
122 122
                     break;
123 123
                 case 'status':
124 124
                     $value = $invoice->get_status(true);
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
                     $value = $renewal_date;
140 140
                     break;
141 141
                 default:
142
-                    if ( is_callable( array( $invoice, 'get_' . $prop ) ) ) {
142
+                    if (is_callable(array($invoice, 'get_' . $prop))) {
143 143
                         $value = $invoice->{"get_$prop"}();
144 144
                     } else {
145 145
                         $value = $invoice->get_meta($prop);
@@ -147,9 +147,9 @@  discard block
 block discarded – undo
147 147
                     break;
148 148
             }
149 149
 
150
-            $value = apply_filters( 'wpi_privacy_export_invoice_personal_data_prop', $value, $prop, $invoice );
150
+            $value = apply_filters('wpi_privacy_export_invoice_personal_data_prop', $value, $prop, $invoice);
151 151
 
152
-            if ( $value ) {
152
+            if ($value) {
153 153
                 $personal_data[] = array(
154 154
                     'name'  => $name,
155 155
                     'value' => $value,
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 
159 159
         }
160 160
 
161
-        $personal_data = apply_filters( 'wpinv_privacy_export_invoice_personal_data', $personal_data, $invoice );
161
+        $personal_data = apply_filters('wpinv_privacy_export_invoice_personal_data', $personal_data, $invoice);
162 162
 
163 163
         return $personal_data;
164 164
 
Please login to merge, or discard this patch.