Passed
Push — master ( 18145d...828cff )
by Brian
05:08
created
templates/payment-forms/elements/price_input.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -7,30 +7,30 @@
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Set the currency position.
13 13
 $position = wpinv_currency_position();
14 14
 
15
-if ( $position == 'left_space' ) {
15
+if ($position == 'left_space') {
16 16
     $position = 'left';
17 17
 }
18 18
 
19
-if ( $position == 'right_space' ) {
19
+if ($position == 'right_space') {
20 20
     $position = 'right';
21 21
 }
22 22
 
23 23
 echo aui()->input(
24 24
     array(
25
-        'name'              => esc_attr( $id ),
26
-        'id'                => esc_attr( $id ) . uniqid( '_' ),
27
-        'placeholder'       => empty( $placeholder ) ? wpinv_format_amount(0) : wpinv_format_amount( $placeholder ),
28
-        'value'             => empty( $value ) ? wpinv_format_amount(0) : wpinv_format_amount( $value ),
29
-        'label'             => empty( $label ) ? '' : wp_kses_post( $label ),
25
+        'name'              => esc_attr($id),
26
+        'id'                => esc_attr($id) . uniqid('_'),
27
+        'placeholder'       => empty($placeholder) ? wpinv_format_amount(0) : wpinv_format_amount($placeholder),
28
+        'value'             => empty($value) ? wpinv_format_amount(0) : wpinv_format_amount($value),
29
+        'label'             => empty($label) ? '' : wp_kses_post($label),
30 30
         'label_type'        => 'vertical',
31
-        'help_text'         => empty( $description ) ? '' : wp_kses_post( $description ),
32
-        'input_group_right' => $position == 'right' ? wpinv_currency_symbol( $form->get_currency() ) : '',
33
-        'input_group_left'  => $position == 'left' ? wpinv_currency_symbol( $form->get_currency() ) : '',
31
+        'help_text'         => empty($description) ? '' : wp_kses_post($description),
32
+        'input_group_right' => $position == 'right' ? wpinv_currency_symbol($form->get_currency()) : '',
33
+        'input_group_left'  => $position == 'left' ? wpinv_currency_symbol($form->get_currency()) : '',
34 34
         'class'             => 'getpaid-refresh-on-change',
35 35
     )
36 36
 );
Please login to merge, or discard this patch.
includes/admin/class-wpinv-subscriptions-list-table.php 1 patch
Spacing   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -3,9 +3,9 @@  discard block
 block discarded – undo
3 3
  * Displays a list of all subscriptions rules
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) exit;
6
+if (!defined('ABSPATH')) exit;
7 7
 
8
-if ( ! class_exists( 'WP_List_Table' ) ) {
8
+if (!class_exists('WP_List_Table')) {
9 9
 	include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
10 10
 }
11 11
 
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 
79 79
 		$this->prepare_query();
80 80
 
81
-		$this->base_url = remove_query_arg( 'status' );
81
+		$this->base_url = remove_query_arg('status');
82 82
 
83 83
 	}
84 84
 
@@ -91,21 +91,21 @@  discard block
 block discarded – undo
91 91
 		$query = array(
92 92
 			'number'  => $this->per_page,
93 93
 			'paged'   => $this->get_paged(),
94
-			'status'  => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all',
95
-			'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id',
96
-			'order'   => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC',
94
+			'status'  => (isset($_GET['status']) && array_key_exists($_GET['status'], getpaid_get_subscription_statuses())) ? $_GET['status'] : 'all',
95
+			'orderby' => (isset($_GET['orderby'])) ? $_GET['orderby'] : 'id',
96
+			'order'   => (isset($_GET['order'])) ? $_GET['order'] : 'DESC',
97 97
 		);
98 98
 
99 99
 		// Prepare class properties.
100
-		$this->query               = new GetPaid_Subscriptions_Query( $query );
100
+		$this->query               = new GetPaid_Subscriptions_Query($query);
101 101
 		$this->total_count         = $this->query->get_total();
102 102
 		$this->current_total_count = $this->query->get_total();
103 103
 		$this->items               = $this->query->get_results();
104
-		$this->status_counts       = getpaid_get_subscription_status_counts( $query );
104
+		$this->status_counts       = getpaid_get_subscription_status_counts($query);
105 105
 
106
-		if ( 'all' != $query['status'] ) {
107
-			unset( $query['status'] );
108
-			$this->total_count   = getpaid_get_subscriptions( $query, 'count' );
106
+		if ('all' != $query['status']) {
107
+			unset($query['status']);
108
+			$this->total_count = getpaid_get_subscriptions($query, 'count');
109 109
 		}
110 110
 
111 111
 	}
@@ -122,26 +122,26 @@  discard block
 block discarded – undo
122 122
 	 */
123 123
 	public function get_views() {
124 124
 
125
-		$current  = isset( $_GET['status'] ) ? $_GET['status'] : 'all';
125
+		$current  = isset($_GET['status']) ? $_GET['status'] : 'all';
126 126
 		$views    = array(
127 127
 
128 128
 			'all' => sprintf(
129 129
 				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
130
-				esc_url( add_query_arg( 'status', false, $this->base_url ) ),
130
+				esc_url(add_query_arg('status', false, $this->base_url)),
131 131
 				$current === 'all' ? ' class="current"' : '',
132
-				__('All','invoicing' ),
132
+				__('All', 'invoicing'),
133 133
 				$this->total_count
134 134
 			)
135 135
 
136 136
 		);
137 137
 
138
-		foreach ( array_filter( $this->status_counts ) as $status => $count ) {
138
+		foreach (array_filter($this->status_counts) as $status => $count) {
139 139
 
140
-			$views[ $status ] = sprintf(
140
+			$views[$status] = sprintf(
141 141
 				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
142
-				esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ),
142
+				esc_url(add_query_arg('status', urlencode($status), $this->base_url)),
143 143
 				$current === $status ? ' class="current"' : '',
144
-				sanitize_text_field( getpaid_get_subscription_status_label( $status ) ),
144
+				sanitize_text_field(getpaid_get_subscription_status_label($status)),
145 145
 				$count
146 146
 			);
147 147
 
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
 	 * @since       1.0.0
159 159
 	 * @return      string
160 160
 	 */
161
-	public function column_default( $item, $column_name ) {
162
-		return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name );
161
+	public function column_default($item, $column_name) {
162
+		return apply_filters("getpaid_subscriptions_table_column_$column_name", $item->$column_name);
163 163
 	}
164 164
 
165 165
 	/**
@@ -168,8 +168,8 @@  discard block
 block discarded – undo
168 168
 	 * @param WPInv_Subscription $item
169 169
 	 * @return string
170 170
 	 */
171
-	public function column_cb( $item ) {
172
-		return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) );
171
+	public function column_cb($item) {
172
+		return sprintf('<input type="checkbox" name="id[]" value="%s" />', esc_html($item->get_id()));
173 173
 	}
174 174
 
175 175
 	/**
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 	 * @since       1.0.0
180 180
 	 * @return      string
181 181
 	 */
182
-	public function column_status( $item ) {
182
+	public function column_status($item) {
183 183
 		return $item->get_status_label_html();
184 184
 	}
185 185
 
@@ -190,46 +190,46 @@  discard block
 block discarded – undo
190 190
 	 * @since       1.0.0
191 191
 	 * @return      string
192 192
 	 */
193
-	public function column_subscription( $item ) {
193
+	public function column_subscription($item) {
194 194
 
195
-		$username = __( '(Missing User)', 'invoicing' );
195
+		$username = __('(Missing User)', 'invoicing');
196 196
 
197
-		$user = get_userdata( $item->get_customer_id() );
198
-		if ( $user ) {
197
+		$user = get_userdata($item->get_customer_id());
198
+		if ($user) {
199 199
 
200 200
 			$username = sprintf(
201 201
 				'<a href="user-edit.php?user_id=%s">%s</a>',
202
-				absint( $user->ID ),
203
-				! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
202
+				absint($user->ID),
203
+				!empty($user->display_name) ? sanitize_text_field($user->display_name) : sanitize_email($user->user_email)
204 204
 			);
205 205
 
206 206
 		}
207 207
 
208 208
 		// translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name
209 209
 		$column_content = sprintf(
210
-			_x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ),
211
-			'<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">',
212
-			'<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>',
210
+			_x('%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing'),
211
+			'<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . absint($item->get_id()))) . '">',
212
+			'<strong>' . esc_attr($item->get_id()) . '</strong>', '</a>',
213 213
 			$username
214 214
 		);
215 215
 
216 216
 		$row_actions = array();
217 217
 
218 218
 		// View subscription.
219
-		$view_url    = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ));
220
-		$row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>';
219
+		$view_url    = esc_url(add_query_arg('id', $item->get_id(), admin_url('admin.php?page=wpinv-subscriptions')));
220
+		$row_actions['view'] = '<a href="' . $view_url . '">' . __('View Subscription', 'invoicing') . '</a>';
221 221
 
222 222
 		// View invoice.
223
-		$invoice = get_post( $item->get_parent_invoice_id() );
223
+		$invoice = get_post($item->get_parent_invoice_id());
224 224
 
225
-		if ( ! empty( $invoice ) ) {
226
-			$view_url    = get_edit_post_link( $invoice );
227
-			$row_actions['invoice'] = '<a href="' . $view_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>';
225
+		if (!empty($invoice)) {
226
+			$view_url = get_edit_post_link($invoice);
227
+			$row_actions['invoice'] = '<a href="' . $view_url . '">' . __('View Invoice', 'invoicing') . '</a>';
228 228
 		}
229 229
 
230
-		$row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) );
230
+		$row_actions = $this->row_actions(apply_filters('getpaid_subscription_table_row_actions', $row_actions, $item));
231 231
 
232
-		return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions;
232
+		return "<strong>$column_content</strong>" . $this->column_amount($item) . $row_actions;
233 233
 	}
234 234
 
235 235
 	/**
@@ -239,8 +239,8 @@  discard block
 block discarded – undo
239 239
 	 * @since       1.0.0
240 240
 	 * @return      string
241 241
 	 */
242
-	public function column_renewal_date( $item ) {
243
-		return getpaid_format_date_value( $item->get_expiration() );
242
+	public function column_renewal_date($item) {
243
+		return getpaid_format_date_value($item->get_expiration());
244 244
 	}
245 245
 
246 246
 	/**
@@ -250,8 +250,8 @@  discard block
 block discarded – undo
250 250
 	 * @since       1.0.0
251 251
 	 * @return      string
252 252
 	 */
253
-	public function column_start_date( $item ) {
254
-		return getpaid_format_date_value( $item->get_date_created() );
253
+	public function column_start_date($item) {
254
+		return getpaid_format_date_value($item->get_date_created());
255 255
 	}
256 256
 
257 257
 	/**
@@ -261,8 +261,8 @@  discard block
 block discarded – undo
261 261
 	 * @since       1.0.19
262 262
 	 * @return      string
263 263
 	 */
264
-	public function column_amount( $item ) {
265
-		$amount = getpaid_get_formatted_subscription_amount( $item );
264
+	public function column_amount($item) {
265
+		$amount = getpaid_get_formatted_subscription_amount($item);
266 266
 		return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>";
267 267
 	}
268 268
 
@@ -273,9 +273,9 @@  discard block
 block discarded – undo
273 273
 	 * @since       1.0.0
274 274
 	 * @return      string
275 275
 	 */
276
-	public function column_renewals( $item ) {
276
+	public function column_renewals($item) {
277 277
 		$max_bills = $item->get_bill_times();
278
-		return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
278
+		return $item->get_times_billed() . ' / ' . (empty($max_bills) ? "&infin;" : $max_bills);
279 279
 	}
280 280
 
281 281
 	/**
@@ -285,16 +285,16 @@  discard block
 block discarded – undo
285 285
 	 * @since       1.0.0
286 286
 	 * @return      string
287 287
 	 */
288
-	public function column_item( $item ) {
289
-		$_item = get_post( $item->get_product_id() );
288
+	public function column_item($item) {
289
+		$_item = get_post($item->get_product_id());
290 290
 
291
-		if ( ! empty( $_item ) ) {
292
-			$link = get_edit_post_link( $_item );
293
-			$link = esc_url( $link );
294
-			$name = esc_html( get_the_title( $_item ) );
291
+		if (!empty($_item)) {
292
+			$link = get_edit_post_link($_item);
293
+			$link = esc_url($link);
294
+			$name = esc_html(get_the_title($_item));
295 295
 			return "<a href='$link'>$name</a>";
296 296
 		} else {
297
-			return sprintf( __( 'Item #%s', 'invoicing' ), $item->get_product_id() );
297
+			return sprintf(__('Item #%s', 'invoicing'), $item->get_product_id());
298 298
 		}
299 299
 
300 300
 	}
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
 	 * @return      int
306 306
 	 */
307 307
 	public function get_paged() {
308
-		return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
308
+		return isset($_GET['paged']) ? absint($_GET['paged']) : 1;
309 309
 	}
310 310
 
311 311
 	/**
@@ -318,13 +318,13 @@  discard block
 block discarded – undo
318 318
 		$hidden   = array();
319 319
 		$sortable = $this->get_sortable_columns();
320 320
 
321
-		$this->_column_headers = array( $columns, $hidden, $sortable );
321
+		$this->_column_headers = array($columns, $hidden, $sortable);
322 322
 
323 323
 		$this->set_pagination_args(
324 324
 			array(
325 325
 			'total_items' => $this->current_total_count,
326 326
 			'per_page'    => $this->per_page,
327
-			'total_pages' => ceil( $this->current_total_count / $this->per_page )
327
+			'total_pages' => ceil($this->current_total_count / $this->per_page)
328 328
 			)
329 329
 		);
330 330
 	}
@@ -334,18 +334,18 @@  discard block
 block discarded – undo
334 334
 	 *
335 335
 	 * @return array
336 336
 	 */
337
-	public function get_columns(){
337
+	public function get_columns() {
338 338
 		$columns = array(
339 339
 			'cb'                => '<input type="checkbox" />',
340
-			'subscription'      => __( 'Subscription', 'invoicing' ),
341
-			'start_date'        => __( 'Start Date', 'invoicing' ),
342
-			'renewal_date'      => __( 'Next Payment', 'invoicing' ),
343
-			'renewals'          => __( 'Payments', 'invoicing' ),
344
-			'item'              => __( 'Item', 'invoicing' ),
345
-			'status'            => __( 'Status', 'invoicing' ),
340
+			'subscription'      => __('Subscription', 'invoicing'),
341
+			'start_date'        => __('Start Date', 'invoicing'),
342
+			'renewal_date'      => __('Next Payment', 'invoicing'),
343
+			'renewals'          => __('Payments', 'invoicing'),
344
+			'item'              => __('Item', 'invoicing'),
345
+			'status'            => __('Status', 'invoicing'),
346 346
 		);
347 347
 
348
-		return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns );
348
+		return apply_filters('manage_getpaid_subscriptions_table_columns', $columns);
349 349
 	}
350 350
 
351 351
 	/**
@@ -355,15 +355,15 @@  discard block
 block discarded – undo
355 355
 	 */
356 356
 	public function get_sortable_columns() {
357 357
 		$sortable = array(
358
-			'subscription' => array( 'id', true ),
359
-			'start_date'   => array( 'created', true ),
360
-			'renewal_date' => array( 'expiration', true ),
361
-			'renewals'     => array( 'bill_times', true ),
362
-			'item'         => array( 'product_id', true ),
363
-			'status'       => array( 'status', true ),
358
+			'subscription' => array('id', true),
359
+			'start_date'   => array('created', true),
360
+			'renewal_date' => array('expiration', true),
361
+			'renewals'     => array('bill_times', true),
362
+			'item'         => array('product_id', true),
363
+			'status'       => array('status', true),
364 364
 		);
365 365
 
366
-		return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable );
366
+		return apply_filters('manage_getpaid_subscriptions_sortable_table_columns', $sortable);
367 367
 	}
368 368
 
369 369
 	/**
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
 	 * @return bool
373 373
 	 */
374 374
 	public function has_items() {
375
-		return ! empty( $this->current_total_count );
375
+		return !empty($this->current_total_count);
376 376
 	}
377 377
 
378 378
 	/**
Please login to merge, or discard this patch.
includes/admin/class-getpaid-post-types-admin.php 1 patch
Spacing   +193 added lines, -193 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
  * Post types Admin Class
@@ -21,68 +21,68 @@  discard block
 block discarded – undo
21 21
 		GetPaid_Metaboxes::init();
22 22
 
23 23
 		// Filter the post updated messages.
24
-		add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
24
+		add_filter('post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages');
25 25
 
26 26
 		// Filter post actions.
27
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
27
+		add_filter('post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2);
28 28
 
29 29
 		// Invoice table columns.
30
-		add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
31
-		add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
30
+		add_filter('manage_wpi_invoice_posts_columns', array(__CLASS__, 'invoice_columns'), 100);
31
+		add_action('manage_wpi_invoice_posts_custom_column', array(__CLASS__, 'display_invoice_columns'), 10, 2);
32 32
 
33 33
 		// Items table columns.
34
-		add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
35
-		add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
36
-		add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
37
-		add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
38
-		add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
39
-		add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
34
+		add_filter('manage_wpi_item_posts_columns', array(__CLASS__, 'item_columns'), 100);
35
+		add_filter('manage_edit-wpi_item_sortable_columns', array(__CLASS__, 'sortable_item_columns'), 20);
36
+		add_action('manage_wpi_item_posts_custom_column', array(__CLASS__, 'display_item_columns'), 10, 2);
37
+		add_action('restrict_manage_posts', array(__CLASS__, 'add_item_filters'), 100);
38
+		add_action('parse_query', array(__CLASS__, 'filter_item_query'), 100);
39
+		add_action('request', array(__CLASS__, 'reorder_items'), 100);
40 40
 
41 41
 		// Payment forms columns.
42
-		add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
43
-		add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
44
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
42
+		add_filter('manage_wpi_payment_form_posts_columns', array(__CLASS__, 'payment_form_columns'), 100);
43
+		add_action('manage_wpi_payment_form_posts_custom_column', array(__CLASS__, 'display_payment_form_columns'), 10, 2);
44
+		add_filter('display_post_states', array(__CLASS__, 'filter_payment_form_state'), 10, 2);
45 45
 
46 46
 		// Discount table columns.
47
-		add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
47
+		add_filter('manage_wpi_discount_posts_columns', array(__CLASS__, 'discount_columns'), 100);
48 48
 
49 49
 		// Deleting posts.
50
-		add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
51
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
50
+		add_action('delete_post', array(__CLASS__, 'delete_post'));
51
+		add_filter('display_post_states', array(__CLASS__, 'filter_discount_state'), 10, 2);
52 52
 	}
53 53
 
54 54
 	/**
55 55
 	 * Post updated messages.
56 56
 	 */
57
-	public static function post_updated_messages( $messages ) {
57
+	public static function post_updated_messages($messages) {
58 58
 		global $post;
59 59
 
60 60
 		$messages['wpi_discount'] = array(
61 61
 			0   => '',
62
-			1   => __( 'Discount updated.', 'invoicing' ),
63
-			2   => __( 'Custom field updated.', 'invoicing' ),
64
-			3   => __( 'Custom field deleted.', 'invoicing' ),
65
-			4   => __( 'Discount updated.', 'invoicing' ),
66
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
67
-			6   => __( 'Discount updated.', 'invoicing' ),
68
-			7   => __( 'Discount saved.', 'invoicing' ),
69
-			8   => __( 'Discount submitted.', 'invoicing' ),
70
-			9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
71
-			10  => __( 'Discount draft updated.', 'invoicing' ),
62
+			1   => __('Discount updated.', 'invoicing'),
63
+			2   => __('Custom field updated.', 'invoicing'),
64
+			3   => __('Custom field deleted.', 'invoicing'),
65
+			4   => __('Discount updated.', 'invoicing'),
66
+			5   => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
67
+			6   => __('Discount updated.', 'invoicing'),
68
+			7   => __('Discount saved.', 'invoicing'),
69
+			8   => __('Discount submitted.', 'invoicing'),
70
+			9   => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))),
71
+			10  => __('Discount draft updated.', 'invoicing'),
72 72
 		);
73 73
 
74 74
 		$messages['wpi_payment_form'] = array(
75 75
 			0   => '',
76
-			1   => __( 'Payment Form updated.', 'invoicing' ),
77
-			2   => __( 'Custom field updated.', 'invoicing' ),
78
-			3   => __( 'Custom field deleted.', 'invoicing' ),
79
-			4   => __( 'Payment Form updated.', 'invoicing' ),
80
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
81
-			6   => __( 'Payment Form updated.', 'invoicing' ),
82
-			7   => __( 'Payment Form saved.', 'invoicing' ),
83
-			8   => __( 'Payment Form submitted.', 'invoicing' ),
84
-			9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
85
-			10  => __( 'Payment Form draft updated.', 'invoicing' ),
76
+			1   => __('Payment Form updated.', 'invoicing'),
77
+			2   => __('Custom field updated.', 'invoicing'),
78
+			3   => __('Custom field deleted.', 'invoicing'),
79
+			4   => __('Payment Form updated.', 'invoicing'),
80
+			5   => isset($_GET['revision']) ? wp_sprintf(__('Payment Form restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
81
+			6   => __('Payment Form updated.', 'invoicing'),
82
+			7   => __('Payment Form saved.', 'invoicing'),
83
+			8   => __('Payment Form submitted.', 'invoicing'),
84
+			9   => wp_sprintf(__('Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))),
85
+			10  => __('Payment Form draft updated.', 'invoicing'),
86 86
 		);
87 87
 
88 88
 		return $messages;
@@ -92,14 +92,14 @@  discard block
 block discarded – undo
92 92
 	/**
93 93
 	 * Post row actions.
94 94
 	 */
95
-	public static function post_row_actions( $actions, $post ) {
95
+	public static function post_row_actions($actions, $post) {
96 96
 
97
-		$post = get_post( $post );
97
+		$post = get_post($post);
98 98
 
99 99
 		// We do not want to edit the default payment form.
100
-		if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) {
101
-			unset( $actions['trash'] );
102
-			unset( $actions['inline hide-if-no-js'] );
100
+		if ('wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form()) {
101
+			unset($actions['trash']);
102
+			unset($actions['inline hide-if-no-js']);
103 103
 		}
104 104
 
105 105
 		return $actions;
@@ -108,51 +108,51 @@  discard block
 block discarded – undo
108 108
 	/**
109 109
 	 * Returns an array of invoice table columns.
110 110
 	 */
111
-	public static function invoice_columns( $columns ) {
111
+	public static function invoice_columns($columns) {
112 112
 
113 113
 		$columns = array(
114 114
 			'cb'                => $columns['cb'],
115
-			'number'            => __( 'Invoice', 'invoicing' ),
116
-			'customer'          => __( 'Customer', 'invoicing' ),
117
-			'invoice_date'      => __( 'Date', 'invoicing' ),
118
-			'amount'            => __( 'Amount', 'invoicing' ),
119
-			'recurring'         => __( 'Recurring', 'invoicing' ),
120
-			'status'            => __( 'Status', 'invoicing' ),
121
-			'wpi_actions'       => __( 'Actions', 'invoicing' ),
115
+			'number'            => __('Invoice', 'invoicing'),
116
+			'customer'          => __('Customer', 'invoicing'),
117
+			'invoice_date'      => __('Date', 'invoicing'),
118
+			'amount'            => __('Amount', 'invoicing'),
119
+			'recurring'         => __('Recurring', 'invoicing'),
120
+			'status'            => __('Status', 'invoicing'),
121
+			'wpi_actions'       => __('Actions', 'invoicing'),
122 122
 		);
123 123
 
124
-		return apply_filters( 'wpi_invoice_table_columns', $columns );
124
+		return apply_filters('wpi_invoice_table_columns', $columns);
125 125
 	}
126 126
 
127 127
 	/**
128 128
 	 * Displays invoice table columns.
129 129
 	 */
130
-	public static function display_invoice_columns( $column_name, $post_id ) {
130
+	public static function display_invoice_columns($column_name, $post_id) {
131 131
 
132
-		$invoice = new WPInv_Invoice( $post_id );
132
+		$invoice = new WPInv_Invoice($post_id);
133 133
 
134
-		switch ( $column_name ) {
134
+		switch ($column_name) {
135 135
 
136 136
 			case 'invoice_date' :
137
-				$date_time = esc_attr( $invoice->get_created_date() );
138
-				$date      = getpaid_format_date_value( $date_time );
137
+				$date_time = esc_attr($invoice->get_created_date());
138
+				$date      = getpaid_format_date_value($date_time);
139 139
 				echo "<span title='$date_time'>$date</span>";
140 140
 				break;
141 141
 
142 142
 			case 'amount' :
143 143
 
144 144
 				$amount = $invoice->get_total();
145
-				$formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() );
145
+				$formated_amount = wpinv_price(wpinv_format_amount($amount), $invoice->get_currency());
146 146
 
147
-				if ( $invoice->is_refunded() ) {
148
-					$refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() );
147
+				if ($invoice->is_refunded()) {
148
+					$refunded_amount = wpinv_price(wpinv_format_amount(0), $invoice->get_currency());
149 149
 					echo "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>";
150 150
 				} else {
151 151
 
152 152
 					$discount = $invoice->get_total_discount();
153 153
 
154
-					if ( ! empty( $discount ) ) {
155
-						$new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() );
154
+					if (!empty($discount)) {
155
+						$new_amount = wpinv_price(wpinv_format_amount($amount + $discount), $invoice->get_currency());
156 156
 						echo "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>";
157 157
 					} else {
158 158
 						echo $formated_amount;
@@ -163,13 +163,13 @@  discard block
 block discarded – undo
163 163
 				break;
164 164
 
165 165
 			case 'status' :
166
-				$status       = sanitize_text_field( $invoice->get_status() );
167
-				$status_label = sanitize_text_field( $invoice->get_status_nicename() );
166
+				$status       = sanitize_text_field($invoice->get_status());
167
+				$status_label = sanitize_text_field($invoice->get_status_nicename());
168 168
 
169 169
 				// If it is paid, show the gateway title.
170
-				if ( $invoice->is_paid() ) {
171
-					$gateway = sanitize_text_field( $invoice->get_gateway_title() );
172
-					$gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
170
+				if ($invoice->is_paid()) {
171
+					$gateway = sanitize_text_field($invoice->get_gateway_title());
172
+					$gateway = wp_sprintf(esc_attr__('Paid via %s', 'invoicing'), $gateway);
173 173
 
174 174
 					echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
175 175
 				} else {
@@ -177,22 +177,22 @@  discard block
 block discarded – undo
177 177
 				}
178 178
 
179 179
 				// If it is not paid, display the overdue and view status.
180
-				if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
180
+				if (!$invoice->is_paid() && !$invoice->is_refunded()) {
181 181
 
182 182
 					// Invoice view status.
183
-					if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
184
-						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
183
+					if (wpinv_is_invoice_viewed($invoice->get_id())) {
184
+						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="' . esc_attr__('Viewed by Customer', 'invoicing') . '"></i>';
185 185
 					} else {
186
-						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
186
+						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__('Not Viewed by Customer', 'invoicing') . '"></i>';
187 187
 					}
188 188
 
189 189
 					// Display the overview status.
190
-					if ( wpinv_get_option( 'overdue_active' ) ) {
190
+					if (wpinv_get_option('overdue_active')) {
191 191
 						$due_date = $invoice->get_due_date();
192
-						$fomatted = getpaid_format_date( $due_date );
192
+						$fomatted = getpaid_format_date($due_date);
193 193
 
194
-						if ( ! empty( $fomatted ) ) {
195
-							$date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted );
194
+						if (!empty($fomatted)) {
195
+							$date = wp_sprintf(__('Due %s', 'invoicing'), $fomatted);
196 196
 							echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>";
197 197
 						}
198 198
 					}
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 
204 204
 			case 'recurring':
205 205
 
206
-				if ( $invoice->is_recurring() ) {
206
+				if ($invoice->is_recurring()) {
207 207
 					echo '<i class="fa fa-check" style="color:#43850a;"></i>';
208 208
 				} else {
209 209
 					echo '<i class="fa fa-times" style="color:#616161;"></i>';
@@ -212,9 +212,9 @@  discard block
 block discarded – undo
212 212
 
213 213
 			case 'number' :
214 214
 
215
-				$edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
216
-				$invoice_number  = sanitize_text_field( $invoice->get_number() );
217
-				$invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
215
+				$edit_link       = esc_url(get_edit_post_link($invoice->get_id()));
216
+				$invoice_number  = sanitize_text_field($invoice->get_number());
217
+				$invoice_details = esc_attr__('View Invoice Details', 'invoicing');
218 218
 
219 219
 				echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
220 220
 
@@ -224,13 +224,13 @@  discard block
 block discarded – undo
224 224
 	
225 225
 				$customer_name = $invoice->get_user_full_name();
226 226
 	
227
-				if ( empty( $customer_name ) ) {
227
+				if (empty($customer_name)) {
228 228
 					$customer_name = $invoice->get_email();
229 229
 				}
230 230
 	
231
-				if ( ! empty( $customer_name ) ) {
232
-					$customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
233
-					$view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
231
+				if (!empty($customer_name)) {
232
+					$customer_details = esc_attr__('View Customer Details', 'invoicing');
233
+					$view_link        = esc_url(add_query_arg('user_id', $invoice->get_user_id(), admin_url('user-edit.php')));
234 234
 					echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
235 235
 				} else {
236 236
 					echo '<div>&mdash;</div>';
@@ -240,12 +240,12 @@  discard block
 block discarded – undo
240 240
 
241 241
 			case 'wpi_actions' :
242 242
 
243
-				if ( $invoice->is_draft() ) {
243
+				if ($invoice->is_draft()) {
244 244
 					return;
245 245
 				}
246 246
 
247
-				$url    = esc_url( $invoice->get_view_url() );
248
-				$print  = esc_attr__( 'Print invoice', 'invoicing' );
247
+				$url    = esc_url($invoice->get_view_url());
248
+				$print  = esc_attr__('Print invoice', 'invoicing');
249 249
 				echo "&nbsp;<a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>";
250 250
 
251 251
 				$url    = esc_url(
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 					)
262 262
 				);
263 263
 
264
-				$send   = esc_attr__( 'Send invoice to customer', 'invoicing' );
264
+				$send = esc_attr__('Send invoice to customer', 'invoicing');
265 265
 				echo "&nbsp;&nbsp;<a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>";
266 266
 
267 267
 				break;
@@ -272,50 +272,50 @@  discard block
 block discarded – undo
272 272
 	/**
273 273
 	 * Returns an array of payment forms table columns.
274 274
 	 */
275
-	public static function payment_form_columns( $columns ) {
275
+	public static function payment_form_columns($columns) {
276 276
 
277 277
 		$columns = array(
278 278
 			'cb'                => $columns['cb'],
279
-			'title'             => __( 'Name', 'invoicing' ),
280
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
281
-			'earnings'          => __( 'Revenue', 'invoicing' ),
282
-			'refunds'           => __( 'Refunded', 'invoicing' ),
283
-			'items'             => __( 'Items', 'invoicing' ),
284
-			'date'              => __( 'Date', 'invoicing' ),
279
+			'title'             => __('Name', 'invoicing'),
280
+			'shortcode'         => __('Shortcode', 'invoicing'),
281
+			'earnings'          => __('Revenue', 'invoicing'),
282
+			'refunds'           => __('Refunded', 'invoicing'),
283
+			'items'             => __('Items', 'invoicing'),
284
+			'date'              => __('Date', 'invoicing'),
285 285
 		);
286 286
 
287
-		return apply_filters( 'wpi_payment_form_table_columns', $columns );
287
+		return apply_filters('wpi_payment_form_table_columns', $columns);
288 288
 
289 289
 	}
290 290
 
291 291
 	/**
292 292
 	 * Displays payment form table columns.
293 293
 	 */
294
-	public static function display_payment_form_columns( $column_name, $post_id ) {
294
+	public static function display_payment_form_columns($column_name, $post_id) {
295 295
 
296 296
 		// Retrieve the payment form.
297
-		$form = new GetPaid_Payment_Form( $post_id );
297
+		$form = new GetPaid_Payment_Form($post_id);
298 298
 
299
-		switch ( $column_name ) {
299
+		switch ($column_name) {
300 300
 
301 301
 			case 'earnings' :
302
-				echo wpinv_price( wpinv_format_amount( $form->get_earned() ) );
302
+				echo wpinv_price(wpinv_format_amount($form->get_earned()));
303 303
 				break;
304 304
 
305 305
 			case 'refunds' :
306
-				echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
306
+				echo wpinv_price(wpinv_format_amount($form->get_refunded()));
307 307
 				break;
308 308
 
309 309
 			case 'refunds' :
310
-				echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
310
+				echo wpinv_price(wpinv_format_amount($form->get_refunded()));
311 311
 				break;
312 312
 
313 313
 			case 'shortcode' :
314 314
 
315
-				if ( $form->is_default() ) {
315
+				if ($form->is_default()) {
316 316
 					echo '&mdash;';
317 317
 				} else {
318
-					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
318
+					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr($form->get_id()) . ']" style="width: 100%;" readonly/>';
319 319
 				}
320 320
 
321 321
 				break;
@@ -324,29 +324,29 @@  discard block
 block discarded – undo
324 324
 
325 325
 				$items = $form->get_items();
326 326
 
327
-				if ( $form->is_default() || empty( $items ) ) {
327
+				if ($form->is_default() || empty($items)) {
328 328
 					echo '&mdash;';
329 329
 					return;
330 330
 				}
331 331
 
332 332
 				$_items = array();
333 333
 
334
-				foreach ( $items as $item ) {
334
+				foreach ($items as $item) {
335 335
 					$url = $item->get_edit_url();
336 336
 
337
-					if ( empty( $url ) ) {
338
-						$_items[] = sanitize_text_field( $item->get_name() );
337
+					if (empty($url)) {
338
+						$_items[] = sanitize_text_field($item->get_name());
339 339
 					} else {
340 340
 						$_items[] = sprintf(
341 341
 							'<a href="%s">%s</a>',
342
-							esc_url( $url ),
343
-							sanitize_text_field( $item->get_name() )
342
+							esc_url($url),
343
+							sanitize_text_field($item->get_name())
344 344
 						);
345 345
 					}
346 346
 
347 347
 				}
348 348
 
349
-				echo implode( '<br>', $_items );
349
+				echo implode('<br>', $_items);
350 350
 
351 351
 				break;
352 352
 
@@ -357,10 +357,10 @@  discard block
 block discarded – undo
357 357
 	/**
358 358
 	 * Filters post states.
359 359
 	 */
360
-	public static function filter_payment_form_state( $post_states, $post ) {
360
+	public static function filter_payment_form_state($post_states, $post) {
361 361
 
362
-		if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
363
-			$post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
362
+		if ('wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID) {
363
+			$post_states['default_form'] = __('Default Payment Form', 'invoicing');
364 364
 		}
365 365
 	
366 366
 		return $post_states;
@@ -370,35 +370,35 @@  discard block
 block discarded – undo
370 370
 	/**
371 371
 	 * Returns an array of coupon table columns.
372 372
 	 */
373
-	public static function discount_columns( $columns ) {
373
+	public static function discount_columns($columns) {
374 374
 
375 375
 		$columns = array(
376 376
 			'cb'                => $columns['cb'],
377
-			'title'             => __( 'Name', 'invoicing' ),
378
-			'code'              => __( 'Code', 'invoicing' ),
379
-			'amount'            => __( 'Amount', 'invoicing' ),
380
-			'usage'             => __( 'Usage / Limit', 'invoicing' ),
381
-			'start_date'        => __( 'Start Date', 'invoicing' ),
382
-			'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
377
+			'title'             => __('Name', 'invoicing'),
378
+			'code'              => __('Code', 'invoicing'),
379
+			'amount'            => __('Amount', 'invoicing'),
380
+			'usage'             => __('Usage / Limit', 'invoicing'),
381
+			'start_date'        => __('Start Date', 'invoicing'),
382
+			'expiry_date'       => __('Expiry Date', 'invoicing'),
383 383
 		);
384 384
 
385
-		return apply_filters( 'wpi_discount_table_columns', $columns );
385
+		return apply_filters('wpi_discount_table_columns', $columns);
386 386
 	}
387 387
 
388 388
 	/**
389 389
 	 * Filters post states.
390 390
 	 */
391
-	public static function filter_discount_state( $post_states, $post ) {
391
+	public static function filter_discount_state($post_states, $post) {
392 392
 
393
-		if ( 'wpi_discount' == $post->post_type ) {
393
+		if ('wpi_discount' == $post->post_type) {
394 394
 
395
-			$discount = new WPInv_Discount( $post );
395
+			$discount = new WPInv_Discount($post);
396 396
 
397 397
 			$status = $discount->is_expired() ? 'expired' : $discount->get_status();
398 398
 
399
-			if ( $status != 'publish' ) {
399
+			if ($status != 'publish') {
400 400
 				return array(
401
-					'discount_status' => wpinv_discount_status( $status ),
401
+					'discount_status' => wpinv_discount_status($status),
402 402
 				);
403 403
 			}
404 404
 
@@ -413,34 +413,34 @@  discard block
 block discarded – undo
413 413
 	/**
414 414
 	 * Returns an array of items table columns.
415 415
 	 */
416
-	public static function item_columns( $columns ) {
416
+	public static function item_columns($columns) {
417 417
 		global $wpinv_euvat;
418 418
 
419 419
 		$columns = array(
420 420
 			'cb'                => $columns['cb'],
421
-			'title'             => __( 'Name', 'invoicing' ),
422
-			'price'             => __( 'Price', 'invoicing' ),
423
-			'vat_rule'          => __( 'VAT rule', 'invoicing' ),
424
-			'vat_class'         => __( 'VAT class', 'invoicing' ),
425
-			'type'              => __( 'Type', 'invoicing' ),
426
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
421
+			'title'             => __('Name', 'invoicing'),
422
+			'price'             => __('Price', 'invoicing'),
423
+			'vat_rule'          => __('VAT rule', 'invoicing'),
424
+			'vat_class'         => __('VAT class', 'invoicing'),
425
+			'type'              => __('Type', 'invoicing'),
426
+			'shortcode'         => __('Shortcode', 'invoicing'),
427 427
 		);
428 428
 
429
-		if ( ! $wpinv_euvat->allow_vat_rules() ) {
430
-			unset( $columns['vat_rule'] );
429
+		if (!$wpinv_euvat->allow_vat_rules()) {
430
+			unset($columns['vat_rule']);
431 431
 		}
432 432
 
433
-		if ( ! $wpinv_euvat->allow_vat_classes() ) {
434
-			unset( $columns['vat_class'] );
433
+		if (!$wpinv_euvat->allow_vat_classes()) {
434
+			unset($columns['vat_class']);
435 435
 		}
436 436
 
437
-		return apply_filters( 'wpi_item_table_columns', $columns );
437
+		return apply_filters('wpi_item_table_columns', $columns);
438 438
 	}
439 439
 
440 440
 	/**
441 441
 	 * Returns an array of sortable items table columns.
442 442
 	 */
443
-	public static function sortable_item_columns( $columns ) {
443
+	public static function sortable_item_columns($columns) {
444 444
 
445 445
 		return array_merge(
446 446
 			$columns,
@@ -457,50 +457,50 @@  discard block
 block discarded – undo
457 457
 	/**
458 458
 	 * Displays items table columns.
459 459
 	 */
460
-	public static function display_item_columns( $column_name, $post_id ) {
460
+	public static function display_item_columns($column_name, $post_id) {
461 461
 		global $wpinv_euvat;
462 462
 
463
-		$item = new WPInv_Item( $post_id );
463
+		$item = new WPInv_Item($post_id);
464 464
 
465
-		switch ( $column_name ) {
465
+		switch ($column_name) {
466 466
 
467 467
 			case 'price' :
468 468
 
469
-				if ( ! $item->is_recurring() ) {
469
+				if (!$item->is_recurring()) {
470 470
 					echo $item->get_the_price();
471 471
 					break;
472 472
 				}
473 473
 
474 474
 				$price = wp_sprintf(
475
-					__( '%s / %s', 'invoicing' ),
475
+					__('%s / %s', 'invoicing'),
476 476
 					$item->get_the_price(),
477
-					getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
477
+					getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), '')
478 478
 				);
479 479
 
480
-				if ( $item->get_the_price() == $item->get_the_initial_price() ) {
480
+				if ($item->get_the_price() == $item->get_the_initial_price()) {
481 481
 					echo $price;
482 482
 					break;
483 483
 				}
484 484
 
485 485
 				echo $item->get_the_initial_price();
486 486
 
487
-				echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
487
+				echo '<span class="meta">' . wp_sprintf(__('then %s', 'invoicing'), $price) . '</span>';
488 488
 				break;
489 489
 
490 490
 			case 'vat_rule' :
491
-				echo $wpinv_euvat->item_rule_label( $item->get_id() );
491
+				echo $wpinv_euvat->item_rule_label($item->get_id());
492 492
 				break;
493 493
 
494 494
 			case 'vat_class' :
495
-				echo $wpinv_euvat->item_class_label( $item->get_id() );
495
+				echo $wpinv_euvat->item_class_label($item->get_id());
496 496
 				break;
497 497
 
498 498
 			case 'shortcode' :
499
-				echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
499
+				echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr($item->get_id()) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
500 500
 				break;
501 501
 
502 502
 			case 'type' :
503
-				echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
503
+				echo wpinv_item_type($item->get_id()) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
504 504
 				break;
505 505
 
506 506
 		}
@@ -510,22 +510,22 @@  discard block
 block discarded – undo
510 510
 	/**
511 511
 	 * Lets users filter items using taxes.
512 512
 	 */
513
-	public static function add_item_filters( $post_type ) {
513
+	public static function add_item_filters($post_type) {
514 514
 		$wpinv_euvat = getpaid_tax();
515 515
 
516 516
 		// Abort if we're not dealing with items.
517
-		if ( $post_type != 'wpi_item' ) {
517
+		if ($post_type != 'wpi_item') {
518 518
 			return;
519 519
 		}
520 520
 
521 521
 		// Filter by vat rules.
522
-		if ( $wpinv_euvat->allow_vat_rules() ) {
522
+		if ($wpinv_euvat->allow_vat_rules()) {
523 523
 	
524 524
 			// Sanitize selected vat rule.
525 525
 			$vat_rule   = '';
526 526
 			$vat_rules  = $wpinv_euvat->get_rules();
527
-			if ( isset( $_GET['vat_rule'] ) ) {
528
-				$vat_rule   =  $_GET['vat_rule'];
527
+			if (isset($_GET['vat_rule'])) {
528
+				$vat_rule = $_GET['vat_rule'];
529 529
 			}
530 530
 
531 531
 			// Filter by VAT rule.
@@ -533,13 +533,13 @@  discard block
 block discarded – undo
533 533
 				array(
534 534
 					'options'          => array_merge(
535 535
 						array(
536
-							'' => __( 'All VAT rules', 'invoicing' )
536
+							'' => __('All VAT rules', 'invoicing')
537 537
 						),
538 538
 						$vat_rules
539 539
 					),
540 540
 					'name'             => 'vat_rule',
541 541
 					'id'               => 'vat_rule',
542
-					'selected'         => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '',
542
+					'selected'         => in_array($vat_rule, array_keys($vat_rules)) ? $vat_rule : '',
543 543
 					'show_option_all'  => false,
544 544
 					'show_option_none' => false,
545 545
 					'class'            => 'gdmbx2-text-medium',
@@ -550,26 +550,26 @@  discard block
 block discarded – undo
550 550
 		}
551 551
 
552 552
 		// Filter by vat class.
553
-		if ( $wpinv_euvat->allow_vat_classes() ) {
553
+		if ($wpinv_euvat->allow_vat_classes()) {
554 554
 	
555 555
 			// Sanitize selected vat rule.
556 556
 			$vat_class   = '';
557 557
 			$vat_classes = $wpinv_euvat->get_all_classes();
558
-			if ( isset( $_GET['vat_class'] ) ) {
559
-				$vat_class   =  $_GET['vat_class'];
558
+			if (isset($_GET['vat_class'])) {
559
+				$vat_class = $_GET['vat_class'];
560 560
 			}
561 561
 
562 562
 			echo wpinv_html_select(
563 563
 				array(
564 564
 					'options'          => array_merge(
565 565
 						array(
566
-							'' => __( 'All VAT classes', 'invoicing' )
566
+							'' => __('All VAT classes', 'invoicing')
567 567
 						),
568 568
 						$vat_classes
569 569
 					),
570 570
 					'name'             => 'vat_class',
571 571
 					'id'               => 'vat_class',
572
-					'selected'         => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '',
572
+					'selected'         => in_array($vat_class, array_keys($vat_classes)) ? $vat_class : '',
573 573
 					'show_option_all'  => false,
574 574
 					'show_option_none' => false,
575 575
 					'class'            => 'gdmbx2-text-medium',
@@ -579,22 +579,22 @@  discard block
 block discarded – undo
579 579
 		}
580 580
 
581 581
 		// Filter by item type.
582
-		$type   = '';
583
-		if ( isset( $_GET['type'] ) ) {
584
-			$type   =  $_GET['type'];
582
+		$type = '';
583
+		if (isset($_GET['type'])) {
584
+			$type = $_GET['type'];
585 585
 		}
586 586
 
587 587
 		echo wpinv_html_select(
588 588
 			array(
589 589
 				'options'          => array_merge(
590 590
 					array(
591
-						'' => __( 'All item types', 'invoicing' )
591
+						'' => __('All item types', 'invoicing')
592 592
 					),
593 593
 					wpinv_get_item_types()
594 594
 				),
595 595
 				'name'             => 'type',
596 596
 				'id'               => 'type',
597
-				'selected'         => in_array( $type, wpinv_item_types() ) ? $type : '',
597
+				'selected'         => in_array($type, wpinv_item_types()) ? $type : '',
598 598
 				'show_option_all'  => false,
599 599
 				'show_option_none' => false,
600 600
 				'class'            => 'gdmbx2-text-medium',
@@ -606,45 +606,45 @@  discard block
 block discarded – undo
606 606
 	/**
607 607
 	 * Filters the item query.
608 608
 	 */
609
-	public static function filter_item_query( $query ) {
609
+	public static function filter_item_query($query) {
610 610
 
611 611
 		// modify the query only if it admin and main query.
612
-		if ( ! ( is_admin() && $query->is_main_query() ) ){ 
612
+		if (!(is_admin() && $query->is_main_query())) { 
613 613
 			return $query;
614 614
 		}
615 615
 
616 616
 		// we want to modify the query for our items.
617
-		if ( 'wpi_item' != $query->query['post_type'] ){
617
+		if ('wpi_item' != $query->query['post_type']) {
618 618
 			return $query;
619 619
 		}
620 620
 
621
-		if ( empty( $query->query_vars['meta_query'] ) ) {
621
+		if (empty($query->query_vars['meta_query'])) {
622 622
 			$query->query_vars['meta_query'] = array();
623 623
 		}
624 624
 
625 625
 		// Filter vat rule type
626
-        if ( ! empty( $_GET['vat_rule'] ) ) {
626
+        if (!empty($_GET['vat_rule'])) {
627 627
             $query->query_vars['meta_query'][] = array(
628 628
                 'key'     => '_wpinv_vat_rule',
629
-                'value'   => sanitize_text_field( $_GET['vat_rule'] ),
629
+                'value'   => sanitize_text_field($_GET['vat_rule']),
630 630
                 'compare' => '='
631 631
             );
632 632
         }
633 633
 
634 634
         // Filter vat class
635
-        if ( ! empty( $_GET['vat_class'] ) ) {
635
+        if (!empty($_GET['vat_class'])) {
636 636
             $query->query_vars['meta_query'][] = array(
637 637
                 'key'     => '_wpinv_vat_class',
638
-                'value'   => sanitize_text_field( $_GET['vat_class'] ),
638
+                'value'   => sanitize_text_field($_GET['vat_class']),
639 639
                 'compare' => '='
640 640
             );
641 641
         }
642 642
 
643 643
         // Filter item type
644
-        if ( ! empty( $_GET['type'] ) ) {
644
+        if (!empty($_GET['type'])) {
645 645
             $query->query_vars['meta_query'][] = array(
646 646
                 'key'     => '_wpinv_type',
647
-                'value'   => sanitize_text_field( $_GET['type'] ),
647
+                'value'   => sanitize_text_field($_GET['type']),
648 648
                 'compare' => '='
649 649
             );
650 650
 		}
@@ -654,15 +654,15 @@  discard block
 block discarded – undo
654 654
 	/**
655 655
 	 * Reorders items.
656 656
 	 */
657
-	public static function reorder_items( $vars ) {
657
+	public static function reorder_items($vars) {
658 658
 		global $typenow;
659 659
 
660
-		if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
660
+		if ('wpi_item' !== $typenow || empty($vars['orderby'])) {
661 661
 			return $vars;
662 662
 		}
663 663
 
664 664
 		// By item type.
665
-		if ( 'type' == $vars['orderby'] ) {
665
+		if ('type' == $vars['orderby']) {
666 666
 			return array_merge(
667 667
 				$vars,
668 668
 				array(
@@ -673,7 +673,7 @@  discard block
 block discarded – undo
673 673
 		}
674 674
 
675 675
 		// By vat class.
676
-		if ( 'vat_class' == $vars['orderby'] ) {
676
+		if ('vat_class' == $vars['orderby']) {
677 677
 			return array_merge(
678 678
 				$vars,
679 679
 				array(
@@ -684,7 +684,7 @@  discard block
 block discarded – undo
684 684
 		}
685 685
 
686 686
 		// By vat rule.
687
-		if ( 'vat_rule' == $vars['orderby'] ) {
687
+		if ('vat_rule' == $vars['orderby']) {
688 688
 			return array_merge(
689 689
 				$vars,
690 690
 				array(
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
 		}
696 696
 
697 697
 		// By price.
698
-		if ( 'price' == $vars['orderby'] ) {
698
+		if ('price' == $vars['orderby']) {
699 699
 			return array_merge(
700 700
 				$vars,
701 701
 				array(
@@ -712,27 +712,27 @@  discard block
 block discarded – undo
712 712
 	/**
713 713
 	 * Fired when deleting a post.
714 714
 	 */
715
-	public static function delete_post( $post_id ) {
715
+	public static function delete_post($post_id) {
716 716
 
717
-		switch ( get_post_type( $post_id ) ) {
717
+		switch (get_post_type($post_id)) {
718 718
 
719 719
 			case 'wpi_item' :
720
-				do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
720
+				do_action("getpaid_before_delete_item", new WPInv_Item($post_id));
721 721
 				break;
722 722
 
723 723
 			case 'wpi_payment_form' :
724
-				do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
724
+				do_action("getpaid_before_delete_payment_form", new GetPaid_Payment_Form($post_id));
725 725
 				break;
726 726
 
727 727
 			case 'wpi_discount' :
728
-				do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
728
+				do_action("getpaid_before_delete_discount", new WPInv_Discount($post_id));
729 729
 				break;
730 730
 
731 731
 			case 'wpi_invoice' :
732
-				$invoice = new WPInv_Invoice( $post_id );
733
-				do_action( "getpaid_before_delete_invoice", $invoice );
734
-				$invoice->get_data_store()->delete_items( $invoice );
735
-				$invoice->get_data_store()->delete_special_fields( $invoice );
732
+				$invoice = new WPInv_Invoice($post_id);
733
+				do_action("getpaid_before_delete_invoice", $invoice);
734
+				$invoice->get_data_store()->delete_items($invoice);
735
+				$invoice->get_data_store()->delete_special_fields($invoice);
736 736
 				break;
737 737
 		}
738 738
 	}
Please login to merge, or discard this patch.
includes/wpinv-helper-functions.php 1 patch
Spacing   +235 added lines, -235 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
  * Are we supporting item quantities?
@@ -21,25 +21,25 @@  discard block
 block discarded – undo
21 21
 function wpinv_get_ip() {
22 22
     $ip = $_SERVER['REMOTE_ADDR'];
23 23
 
24
-    if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
24
+    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
25 25
         //Check ip from share internet.
26 26
         $ip = $_SERVER['HTTP_CLIENT_IP'];
27
-    } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
27
+    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
28 28
         //Check ip is pass from proxy.
29 29
         $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
30 30
     }
31 31
 
32
-    return apply_filters( 'wpinv_get_ip', $ip );
32
+    return apply_filters('wpinv_get_ip', $ip);
33 33
 }
34 34
 
35 35
 function wpinv_get_user_agent() {
36
-    if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
37
-        $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
36
+    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
37
+        $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
38 38
     } else {
39 39
         $user_agent = '';
40 40
     }
41 41
 
42
-    return apply_filters( 'wpinv_get_user_agent', $user_agent );
42
+    return apply_filters('wpinv_get_user_agent', $user_agent);
43 43
 }
44 44
 
45 45
 /**
@@ -47,27 +47,27 @@  discard block
 block discarded – undo
47 47
  * 
48 48
  * @param string $amount The amount to sanitize.
49 49
  */
50
-function wpinv_sanitize_amount( $amount ) {
50
+function wpinv_sanitize_amount($amount) {
51 51
 
52 52
     // Format decimals.
53
-    $amount = str_replace( wpinv_decimal_separator(), '.', $amount );
53
+    $amount = str_replace(wpinv_decimal_separator(), '.', $amount);
54 54
 
55 55
     // Remove thousands.
56
-    $amount = str_replace( wpinv_thousands_separator(), '', $amount );
56
+    $amount = str_replace(wpinv_thousands_separator(), '', $amount);
57 57
 
58 58
     // Cast the remaining to a float.
59
-    return (float) preg_replace( '/[^0-9\.\-]/', '', $amount );
59
+    return (float) preg_replace('/[^0-9\.\-]/', '', $amount);
60 60
 
61 61
 }
62 62
 
63
-function wpinv_round_amount( $amount, $decimals = NULL ) {
64
-    if ( $decimals === NULL ) {
63
+function wpinv_round_amount($amount, $decimals = NULL) {
64
+    if ($decimals === NULL) {
65 65
         $decimals = wpinv_decimals();
66 66
     }
67 67
     
68
-    $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) );
68
+    $amount = round((double) $amount, wpinv_currency_decimal_filter(absint($decimals)));
69 69
 
70
-    return apply_filters( 'wpinv_round_amount', $amount, $decimals );
70
+    return apply_filters('wpinv_round_amount', $amount, $decimals);
71 71
 }
72 72
 
73 73
 /**
@@ -76,32 +76,32 @@  discard block
 block discarded – undo
76 76
  * @since 1.0.19
77 77
  * @return array
78 78
  */
79
-function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) {
79
+function wpinv_get_invoice_statuses($draft = false, $trashed = false, $invoice = false) {
80 80
 	$invoice_statuses = array(
81
-		'wpi-pending'    => _x( 'Pending payment', 'Invoice status', 'invoicing' ),
82
-        'publish'        => _x( 'Paid', 'Invoice status', 'invoicing' ),
83
-        'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ),
84
-		'wpi-onhold'     => _x( 'On hold', 'Invoice status', 'invoicing' ),
85
-		'wpi-cancelled'  => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
86
-		'wpi-refunded'   => _x( 'Refunded', 'Invoice status', 'invoicing' ),
87
-        'wpi-failed'     => _x( 'Failed', 'Invoice status', 'invoicing' ),
88
-        'wpi-renewal'    => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ),
81
+		'wpi-pending'    => _x('Pending payment', 'Invoice status', 'invoicing'),
82
+        'publish'        => _x('Paid', 'Invoice status', 'invoicing'),
83
+        'wpi-processing' => _x('Processing', 'Invoice status', 'invoicing'),
84
+		'wpi-onhold'     => _x('On hold', 'Invoice status', 'invoicing'),
85
+		'wpi-cancelled'  => _x('Cancelled', 'Invoice status', 'invoicing'),
86
+		'wpi-refunded'   => _x('Refunded', 'Invoice status', 'invoicing'),
87
+        'wpi-failed'     => _x('Failed', 'Invoice status', 'invoicing'),
88
+        'wpi-renewal'    => _x('Renewal Payment', 'Invoice status', 'invoicing'),
89 89
     );
90 90
 
91
-    if ( $draft ) {
92
-        $invoice_statuses['draft'] = __( 'Draft', 'invoicing' );
91
+    if ($draft) {
92
+        $invoice_statuses['draft'] = __('Draft', 'invoicing');
93 93
     }
94 94
 
95
-    if ( $trashed ) {
96
-        $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
95
+    if ($trashed) {
96
+        $invoice_statuses['trash'] = __('Trash', 'invoicing');
97 97
     }
98 98
 
99
-	return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
99
+	return apply_filters('wpinv_statuses', $invoice_statuses, $invoice);
100 100
 }
101 101
 
102
-function wpinv_status_nicename( $status ) {
103
-    $statuses = wpinv_get_invoice_statuses( true, true );
104
-    $status   = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' );
102
+function wpinv_status_nicename($status) {
103
+    $statuses = wpinv_get_invoice_statuses(true, true);
104
+    $status   = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing');
105 105
 
106 106
     return $status;
107 107
 }
@@ -111,13 +111,13 @@  discard block
 block discarded – undo
111 111
  * 
112 112
  * @param string $current
113 113
  */
114
-function wpinv_get_currency( $current = '' ) {
114
+function wpinv_get_currency($current = '') {
115 115
 
116
-    if ( empty( $current ) ) {
117
-        $current = apply_filters( 'wpinv_currency', wpinv_get_option( 'currency', 'USD' ) );
116
+    if (empty($current)) {
117
+        $current = apply_filters('wpinv_currency', wpinv_get_option('currency', 'USD'));
118 118
     }
119 119
 
120
-    return trim( strtoupper( $current ) );
120
+    return trim(strtoupper($current));
121 121
 }
122 122
 
123 123
 /**
@@ -125,25 +125,25 @@  discard block
 block discarded – undo
125 125
  * 
126 126
  * @param string|null $currency The currency code. Defaults to the default currency.
127 127
  */
128
-function wpinv_currency_symbol( $currency = null ) {
128
+function wpinv_currency_symbol($currency = null) {
129 129
 
130 130
     // Prepare the currency.
131
-    $currency = empty( $currency ) ? wpinv_get_currency() : wpinv_clean( $currency );
131
+    $currency = empty($currency) ? wpinv_get_currency() : wpinv_clean($currency);
132 132
 
133 133
     // Fetch all symbols.
134 134
     $symbols = wpinv_get_currency_symbols();
135 135
 
136 136
     // Fetch this currencies symbol.
137
-    $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : $currency;
137
+    $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency;
138 138
 
139 139
     // Filter the symbol.
140
-    return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
140
+    return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency);
141 141
 }
142 142
 
143 143
 function wpinv_currency_position() {
144
-    $position = wpinv_get_option( 'currency_position', 'left' );
144
+    $position = wpinv_get_option('currency_position', 'left');
145 145
     
146
-    return apply_filters( 'wpinv_currency_position', $position );
146
+    return apply_filters('wpinv_currency_position', $position);
147 147
 }
148 148
 
149 149
 /**
@@ -151,13 +151,13 @@  discard block
 block discarded – undo
151 151
  * 
152 152
  * @param $string|null $current
153 153
  */
154
-function wpinv_thousands_separator( $current = null ) {
154
+function wpinv_thousands_separator($current = null) {
155 155
 
156
-    if ( null == $current ) {
157
-        $current = wpinv_get_option( 'thousands_separator', '.' );
156
+    if (null == $current) {
157
+        $current = wpinv_get_option('thousands_separator', '.');
158 158
     }
159 159
 
160
-    return trim( $current );
160
+    return trim($current);
161 161
 }
162 162
 
163 163
 /**
@@ -165,13 +165,13 @@  discard block
 block discarded – undo
165 165
  * 
166 166
  * @param $string|null $current
167 167
  */
168
-function wpinv_decimal_separator( $current = null ) {
168
+function wpinv_decimal_separator($current = null) {
169 169
 
170
-    if ( null == $current ) {
171
-        $current = wpinv_get_option( 'decimal_separator', '.' );
170
+    if (null == $current) {
171
+        $current = wpinv_get_option('decimal_separator', '.');
172 172
     }
173 173
     
174
-    return trim( $current );
174
+    return trim($current);
175 175
 }
176 176
 
177 177
 /**
@@ -179,27 +179,27 @@  discard block
 block discarded – undo
179 179
  * 
180 180
  * @param $string|null $current
181 181
  */
182
-function wpinv_decimals( $current = null ) {
182
+function wpinv_decimals($current = null) {
183 183
 
184
-    if ( null == $current ) {
185
-        $current = wpinv_get_option( 'decimals', 2 );
184
+    if (null == $current) {
185
+        $current = wpinv_get_option('decimals', 2);
186 186
     }
187 187
     
188
-    return absint( $current );
188
+    return absint($current);
189 189
 }
190 190
 
191 191
 /**
192 192
  * Retrieves a list of all supported currencies.
193 193
  */
194 194
 function wpinv_get_currencies() {
195
-    return apply_filters( 'wpinv_currencies', wpinv_get_data( 'currencies' ) );
195
+    return apply_filters('wpinv_currencies', wpinv_get_data('currencies'));
196 196
 }
197 197
 
198 198
 /**
199 199
  * Retrieves a list of all currency symbols.
200 200
  */
201 201
 function wpinv_get_currency_symbols() {
202
-    return apply_filters( 'wpinv_currency_symbols', wpinv_get_data( 'currency-symbols' ) );
202
+    return apply_filters('wpinv_currency_symbols', wpinv_get_data('currency-symbols'));
203 203
 }
204 204
 
205 205
 /**
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 	$currency_pos = wpinv_currency_position();
212 212
 	$format       = '%1$s%2$s';
213 213
 
214
-	switch ( $currency_pos ) {
214
+	switch ($currency_pos) {
215 215
 		case 'left':
216 216
 			$format = '%1$s%2$s';
217 217
 			break;
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 			break;
227 227
 	}
228 228
 
229
-	return apply_filters( 'getpaid_price_format', $format, $currency_pos );
229
+	return apply_filters('getpaid_price_format', $format, $currency_pos);
230 230
 }
231 231
 
232 232
 /**
@@ -236,25 +236,25 @@  discard block
 block discarded – undo
236 236
  * @param  string $currency Currency.
237 237
  * @return string
238 238
  */
239
-function wpinv_price( $amount = 0, $currency = '' ) {
239
+function wpinv_price($amount = 0, $currency = '') {
240 240
 
241 241
     // Backwards compatibility.
242
-    $amount             = floatval( wpinv_sanitize_amount( $amount ) );
242
+    $amount             = floatval(wpinv_sanitize_amount($amount));
243 243
 
244 244
     // Prepare variables.
245
-    $currency           = wpinv_get_currency( $currency );
245
+    $currency           = wpinv_get_currency($currency);
246 246
     $amount             = (float) $amount;
247 247
     $unformatted_amount = $amount;
248 248
     $negative           = $amount < 0;
249
-    $amount             = apply_filters( 'getpaid_raw_amount', floatval( $negative ? $amount * -1 : $amount ) );
250
-    $amount             = wpinv_format_amount( $amount );
249
+    $amount             = apply_filters('getpaid_raw_amount', floatval($negative ? $amount * -1 : $amount));
250
+    $amount             = wpinv_format_amount($amount);
251 251
 
252 252
     // Format the amount.
253 253
     $format             = getpaid_get_price_format();
254
-    $formatted_amount   = ( $negative ? '-' : '' ) . sprintf( $format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol( $currency ) . '</span>', $amount );
254
+    $formatted_amount   = ($negative ? '-' : '') . sprintf($format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol($currency) . '</span>', $amount);
255 255
 
256 256
     // Filter the formatting.
257
-    return apply_filters( 'wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount );
257
+    return apply_filters('wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount);
258 258
 }
259 259
 
260 260
 /**
@@ -265,33 +265,33 @@  discard block
 block discarded – undo
265 265
  * @param  bool     $calculate Whether or not to apply separators.
266 266
  * @return string
267 267
  */
268
-function wpinv_format_amount( $amount, $decimals = null, $calculate = false ) {
268
+function wpinv_format_amount($amount, $decimals = null, $calculate = false) {
269 269
     $thousands_sep = wpinv_thousands_separator();
270 270
     $decimal_sep   = wpinv_decimal_separator();
271
-    $decimals      = wpinv_decimals( $decimals );
271
+    $decimals      = wpinv_decimals($decimals);
272 272
 
273 273
     // Format decimals.
274
-    $amount = str_replace( $decimal_sep, '.', $amount );
274
+    $amount = str_replace($decimal_sep, '.', $amount);
275 275
 
276 276
     // Remove thousands.
277
-    $amount = str_replace( $thousands_sep, '', $amount );
277
+    $amount = str_replace($thousands_sep, '', $amount);
278 278
 
279 279
     // Cast the remaining to a float.
280
-    $amount = floatval( $amount );
280
+    $amount = floatval($amount);
281 281
 
282
-    if ( $calculate ) {
282
+    if ($calculate) {
283 283
         return $amount;
284 284
     }
285 285
 
286 286
     // Fomart the amount.
287
-    return number_format( $amount, $decimals, $decimal_sep, $thousands_sep );
287
+    return number_format($amount, $decimals, $decimal_sep, $thousands_sep);
288 288
 }
289 289
 
290
-function wpinv_sanitize_key( $key ) {
290
+function wpinv_sanitize_key($key) {
291 291
     $raw_key = $key;
292
-    $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
292
+    $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key);
293 293
 
294
-    return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
294
+    return apply_filters('wpinv_sanitize_key', $key, $raw_key);
295 295
 }
296 296
 
297 297
 /**
@@ -299,8 +299,8 @@  discard block
 block discarded – undo
299 299
  * 
300 300
  * @param $str the file whose extension should be retrieved.
301 301
  */
302
-function wpinv_get_file_extension( $str ) {
303
-    $filetype = wp_check_filetype( $str );
302
+function wpinv_get_file_extension($str) {
303
+    $filetype = wp_check_filetype($str);
304 304
     return $filetype['ext'];
305 305
 }
306 306
 
@@ -309,16 +309,16 @@  discard block
 block discarded – undo
309 309
  * 
310 310
  * @param string $string
311 311
  */
312
-function wpinv_string_is_image_url( $string ) {
313
-    $extension = strtolower( wpinv_get_file_extension( $string ) );
314
-    return in_array( $extension, array( 'jpeg', 'jpg', 'png', 'gif', 'ico' ), true );
312
+function wpinv_string_is_image_url($string) {
313
+    $extension = strtolower(wpinv_get_file_extension($string));
314
+    return in_array($extension, array('jpeg', 'jpg', 'png', 'gif', 'ico'), true);
315 315
 }
316 316
 
317 317
 /**
318 318
  * Returns the current URL.
319 319
  */
320 320
 function wpinv_get_current_page_url() {
321
-    return ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
321
+    return (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
322 322
 }
323 323
 
324 324
 /**
@@ -328,46 +328,46 @@  discard block
 block discarded – undo
328 328
  * @param string $name  Constant name.
329 329
  * @param mixed  $value Value.
330 330
  */
331
-function getpaid_maybe_define_constant( $name, $value ) {
332
-	if ( ! defined( $name ) ) {
333
-		define( $name, $value );
331
+function getpaid_maybe_define_constant($name, $value) {
332
+	if (!defined($name)) {
333
+		define($name, $value);
334 334
 	}
335 335
 }
336 336
 
337 337
 function wpinv_get_php_arg_separator_output() {
338
-	return ini_get( 'arg_separator.output' );
338
+	return ini_get('arg_separator.output');
339 339
 }
340 340
 
341
-function wpinv_rgb_from_hex( $color ) {
342
-    $color = str_replace( '#', '', $color );
341
+function wpinv_rgb_from_hex($color) {
342
+    $color = str_replace('#', '', $color);
343 343
 
344 344
     // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
345
-    $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
346
-    if ( empty( $color ) ) {
345
+    $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
346
+    if (empty($color)) {
347 347
         return NULL;
348 348
     }
349 349
 
350
-    $color = str_split( $color );
350
+    $color = str_split($color);
351 351
 
352 352
     $rgb      = array();
353
-    $rgb['R'] = hexdec( $color[0] . $color[1] );
354
-    $rgb['G'] = hexdec( $color[2] . $color[3] );
355
-    $rgb['B'] = hexdec( $color[4] . $color[5] );
353
+    $rgb['R'] = hexdec($color[0] . $color[1]);
354
+    $rgb['G'] = hexdec($color[2] . $color[3]);
355
+    $rgb['B'] = hexdec($color[4] . $color[5]);
356 356
 
357 357
     return $rgb;
358 358
 }
359 359
 
360
-function wpinv_hex_darker( $color, $factor = 30 ) {
361
-    $base  = wpinv_rgb_from_hex( $color );
360
+function wpinv_hex_darker($color, $factor = 30) {
361
+    $base  = wpinv_rgb_from_hex($color);
362 362
     $color = '#';
363 363
 
364
-    foreach ( $base as $k => $v ) {
364
+    foreach ($base as $k => $v) {
365 365
         $amount      = $v / 100;
366
-        $amount      = round( $amount * $factor );
366
+        $amount      = round($amount * $factor);
367 367
         $new_decimal = $v - $amount;
368 368
 
369
-        $new_hex_component = dechex( $new_decimal );
370
-        if ( strlen( $new_hex_component ) < 2 ) {
369
+        $new_hex_component = dechex($new_decimal);
370
+        if (strlen($new_hex_component) < 2) {
371 371
             $new_hex_component = "0" . $new_hex_component;
372 372
         }
373 373
         $color .= $new_hex_component;
@@ -376,18 +376,18 @@  discard block
 block discarded – undo
376 376
     return $color;
377 377
 }
378 378
 
379
-function wpinv_hex_lighter( $color, $factor = 30 ) {
380
-    $base  = wpinv_rgb_from_hex( $color );
379
+function wpinv_hex_lighter($color, $factor = 30) {
380
+    $base  = wpinv_rgb_from_hex($color);
381 381
     $color = '#';
382 382
 
383
-    foreach ( $base as $k => $v ) {
383
+    foreach ($base as $k => $v) {
384 384
         $amount      = 255 - $v;
385 385
         $amount      = $amount / 100;
386
-        $amount      = round( $amount * $factor );
386
+        $amount      = round($amount * $factor);
387 387
         $new_decimal = $v + $amount;
388 388
 
389
-        $new_hex_component = dechex( $new_decimal );
390
-        if ( strlen( $new_hex_component ) < 2 ) {
389
+        $new_hex_component = dechex($new_decimal);
390
+        if (strlen($new_hex_component) < 2) {
391 391
             $new_hex_component = "0" . $new_hex_component;
392 392
         }
393 393
         $color .= $new_hex_component;
@@ -396,22 +396,22 @@  discard block
 block discarded – undo
396 396
     return $color;
397 397
 }
398 398
 
399
-function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
400
-    $hex = str_replace( '#', '', $color );
399
+function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
400
+    $hex = str_replace('#', '', $color);
401 401
 
402
-    $c_r = hexdec( substr( $hex, 0, 2 ) );
403
-    $c_g = hexdec( substr( $hex, 2, 2 ) );
404
-    $c_b = hexdec( substr( $hex, 4, 2 ) );
402
+    $c_r = hexdec(substr($hex, 0, 2));
403
+    $c_g = hexdec(substr($hex, 2, 2));
404
+    $c_b = hexdec(substr($hex, 4, 2));
405 405
 
406
-    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
406
+    $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
407 407
 
408 408
     return $brightness > 155 ? $dark : $light;
409 409
 }
410 410
 
411
-function wpinv_format_hex( $hex ) {
412
-    $hex = trim( str_replace( '#', '', $hex ) );
411
+function wpinv_format_hex($hex) {
412
+    $hex = trim(str_replace('#', '', $hex));
413 413
 
414
-    if ( strlen( $hex ) == 3 ) {
414
+    if (strlen($hex) == 3) {
415 415
         $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
416 416
     }
417 417
 
@@ -431,12 +431,12 @@  discard block
 block discarded – undo
431 431
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
432 432
  * @return string
433 433
  */
434
-function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) {
435
-    if ( function_exists( 'mb_strimwidth' ) ) {
436
-        return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding );
434
+function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') {
435
+    if (function_exists('mb_strimwidth')) {
436
+        return mb_strimwidth($str, $start, $width, $trimmaker, $encoding);
437 437
     }
438 438
     
439
-    return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker;
439
+    return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker;
440 440
 }
441 441
 
442 442
 /**
@@ -448,28 +448,28 @@  discard block
 block discarded – undo
448 448
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
449 449
  * @return int Returns the number of characters in string.
450 450
  */
451
-function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) {
452
-    if ( function_exists( 'mb_strlen' ) ) {
453
-        return mb_strlen( $str, $encoding );
451
+function wpinv_utf8_strlen($str, $encoding = 'UTF-8') {
452
+    if (function_exists('mb_strlen')) {
453
+        return mb_strlen($str, $encoding);
454 454
     }
455 455
         
456
-    return strlen( $str );
456
+    return strlen($str);
457 457
 }
458 458
 
459
-function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
460
-    if ( function_exists( 'mb_strtolower' ) ) {
461
-        return mb_strtolower( $str, $encoding );
459
+function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') {
460
+    if (function_exists('mb_strtolower')) {
461
+        return mb_strtolower($str, $encoding);
462 462
     }
463 463
     
464
-    return strtolower( $str );
464
+    return strtolower($str);
465 465
 }
466 466
 
467
-function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
468
-    if ( function_exists( 'mb_strtoupper' ) ) {
469
-        return mb_strtoupper( $str, $encoding );
467
+function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') {
468
+    if (function_exists('mb_strtoupper')) {
469
+        return mb_strtoupper($str, $encoding);
470 470
     }
471 471
     
472
-    return strtoupper( $str );
472
+    return strtoupper($str);
473 473
 }
474 474
 
475 475
 /**
@@ -483,12 +483,12 @@  discard block
 block discarded – undo
483 483
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
484 484
  * @return int Returns the position of the first occurrence of search in the string.
485 485
  */
486
-function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
487
-    if ( function_exists( 'mb_strpos' ) ) {
488
-        return mb_strpos( $str, $find, $offset, $encoding );
486
+function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
487
+    if (function_exists('mb_strpos')) {
488
+        return mb_strpos($str, $find, $offset, $encoding);
489 489
     }
490 490
         
491
-    return strpos( $str, $find, $offset );
491
+    return strpos($str, $find, $offset);
492 492
 }
493 493
 
494 494
 /**
@@ -502,12 +502,12 @@  discard block
 block discarded – undo
502 502
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
503 503
  * @return int Returns the position of the last occurrence of search.
504 504
  */
505
-function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
506
-    if ( function_exists( 'mb_strrpos' ) ) {
507
-        return mb_strrpos( $str, $find, $offset, $encoding );
505
+function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
506
+    if (function_exists('mb_strrpos')) {
507
+        return mb_strrpos($str, $find, $offset, $encoding);
508 508
     }
509 509
         
510
-    return strrpos( $str, $find, $offset );
510
+    return strrpos($str, $find, $offset);
511 511
 }
512 512
 
513 513
 /**
@@ -522,16 +522,16 @@  discard block
 block discarded – undo
522 522
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
523 523
  * @return string
524 524
  */
525
-function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) {
526
-    if ( function_exists( 'mb_substr' ) ) {
527
-        if ( $length === null ) {
528
-            return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding );
525
+function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') {
526
+    if (function_exists('mb_substr')) {
527
+        if ($length === null) {
528
+            return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding);
529 529
         } else {
530
-            return mb_substr( $str, $start, $length, $encoding );
530
+            return mb_substr($str, $start, $length, $encoding);
531 531
         }
532 532
     }
533 533
         
534
-    return substr( $str, $start, $length );
534
+    return substr($str, $start, $length);
535 535
 }
536 536
 
537 537
 /**
@@ -543,48 +543,48 @@  discard block
 block discarded – undo
543 543
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
544 544
  * @return string The width of string.
545 545
  */
546
-function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
547
-    if ( function_exists( 'mb_strwidth' ) ) {
548
-        return mb_strwidth( $str, $encoding );
546
+function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') {
547
+    if (function_exists('mb_strwidth')) {
548
+        return mb_strwidth($str, $encoding);
549 549
     }
550 550
     
551
-    return wpinv_utf8_strlen( $str, $encoding );
551
+    return wpinv_utf8_strlen($str, $encoding);
552 552
 }
553 553
 
554
-function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) {
555
-    if ( function_exists( 'mb_strlen' ) ) {
556
-        $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding );
554
+function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') {
555
+    if (function_exists('mb_strlen')) {
556
+        $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding);
557 557
         $str_end = "";
558 558
         
559
-        if ( $lower_str_end ) {
560
-            $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding );
559
+        if ($lower_str_end) {
560
+            $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding);
561 561
         } else {
562
-            $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding );
562
+            $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding);
563 563
         }
564 564
 
565 565
         return $first_letter . $str_end;
566 566
     }
567 567
     
568
-    return ucfirst( $str );
568
+    return ucfirst($str);
569 569
 }
570 570
 
571
-function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) {
572
-    if ( function_exists( 'mb_convert_case' ) ) {
573
-        return mb_convert_case( $str, MB_CASE_TITLE, $encoding );
571
+function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') {
572
+    if (function_exists('mb_convert_case')) {
573
+        return mb_convert_case($str, MB_CASE_TITLE, $encoding);
574 574
     }
575 575
     
576
-    return ucwords( $str );
576
+    return ucwords($str);
577 577
 }
578 578
 
579
-function wpinv_period_in_days( $period, $unit ) {
580
-    $period = absint( $period );
579
+function wpinv_period_in_days($period, $unit) {
580
+    $period = absint($period);
581 581
     
582
-    if ( $period > 0 ) {
583
-        if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) {
582
+    if ($period > 0) {
583
+        if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) {
584 584
             $period = $period * 7;
585
-        } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) {
585
+        } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) {
586 586
             $period = $period * 30;
587
-        } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) {
587
+        } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) {
588 588
             $period = $period * 365;
589 589
         }
590 590
     }
@@ -592,14 +592,14 @@  discard block
 block discarded – undo
592 592
     return $period;
593 593
 }
594 594
 
595
-function wpinv_cal_days_in_month( $calendar, $month, $year ) {
596
-    if ( function_exists( 'cal_days_in_month' ) ) {
597
-        return cal_days_in_month( $calendar, $month, $year );
595
+function wpinv_cal_days_in_month($calendar, $month, $year) {
596
+    if (function_exists('cal_days_in_month')) {
597
+        return cal_days_in_month($calendar, $month, $year);
598 598
     }
599 599
 
600 600
     // Fallback in case the calendar extension is not loaded in PHP
601 601
     // Only supports Gregorian calendar
602
-    return date( 't', mktime( 0, 0, 0, $month, 1, $year ) );
602
+    return date('t', mktime(0, 0, 0, $month, 1, $year));
603 603
 }
604 604
 
605 605
 /**
@@ -610,11 +610,11 @@  discard block
 block discarded – undo
610 610
  *
611 611
  * @return string
612 612
  */
613
-function wpi_help_tip( $tip, $allow_html = false ) {
614
-    if ( $allow_html ) {
615
-        $tip = wpi_sanitize_tooltip( $tip );
613
+function wpi_help_tip($tip, $allow_html = false) {
614
+    if ($allow_html) {
615
+        $tip = wpi_sanitize_tooltip($tip);
616 616
     } else {
617
-        $tip = esc_attr( $tip );
617
+        $tip = esc_attr($tip);
618 618
     }
619 619
 
620 620
     return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
@@ -628,8 +628,8 @@  discard block
 block discarded – undo
628 628
  * @param string $var
629 629
  * @return string
630 630
  */
631
-function wpi_sanitize_tooltip( $var ) {
632
-    return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
631
+function wpi_sanitize_tooltip($var) {
632
+    return htmlspecialchars(wp_kses(html_entity_decode($var), array(
633 633
         'br'     => array(),
634 634
         'em'     => array(),
635 635
         'strong' => array(),
@@ -639,7 +639,7 @@  discard block
 block discarded – undo
639 639
         'li'     => array(),
640 640
         'ol'     => array(),
641 641
         'p'      => array(),
642
-    ) ) );
642
+    )));
643 643
 }
644 644
 
645 645
 /**
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
  */
650 650
 function wpinv_get_screen_ids() {
651 651
 
652
-    $screen_id = sanitize_title( __( 'Invoicing', 'invoicing' ) );
652
+    $screen_id = sanitize_title(__('Invoicing', 'invoicing'));
653 653
 
654 654
     $screen_ids = array(
655 655
         'toplevel_page_' . $screen_id,
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
         'invoicing_page_wpi-addons',
668 668
     );
669 669
 
670
-    return apply_filters( 'wpinv_screen_ids', $screen_ids );
670
+    return apply_filters('wpinv_screen_ids', $screen_ids);
671 671
 }
672 672
 
673 673
 /**
@@ -678,14 +678,14 @@  discard block
 block discarded – undo
678 678
  * @param array|string $list List of values.
679 679
  * @return array Sanitized array of values.
680 680
  */
681
-function wpinv_parse_list( $list ) {
681
+function wpinv_parse_list($list) {
682 682
 
683
-    if ( empty( $list ) ) {
683
+    if (empty($list)) {
684 684
         $list = array();
685 685
     }
686 686
 
687
-	if ( ! is_array( $list ) ) {
688
-		return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
687
+	if (!is_array($list)) {
688
+		return preg_split('/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY);
689 689
 	}
690 690
 
691 691
 	return $list;
@@ -699,16 +699,16 @@  discard block
 block discarded – undo
699 699
  * @param string $key Type of data to fetch.
700 700
  * @return mixed Fetched data.
701 701
  */
702
-function wpinv_get_data( $key ) {
702
+function wpinv_get_data($key) {
703 703
 
704 704
     // Try fetching it from the cache.
705
-    $data = wp_cache_get( "wpinv-data-$key", 'wpinv' );
706
-    if( $data ) {
705
+    $data = wp_cache_get("wpinv-data-$key", 'wpinv');
706
+    if ($data) {
707 707
         return $data;
708 708
     }
709 709
 
710
-    $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" );
711
-	wp_cache_set( "wpinv-data-$key", $data, 'wpinv' );
710
+    $data = apply_filters("wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php");
711
+	wp_cache_set("wpinv-data-$key", $data, 'wpinv');
712 712
 
713 713
 	return $data;
714 714
 }
@@ -722,10 +722,10 @@  discard block
 block discarded – undo
722 722
  * @param bool $first_empty Whether or not the first item in the list should be empty
723 723
  * @return mixed Fetched data.
724 724
  */
725
-function wpinv_maybe_add_empty_option( $options, $first_empty ) {
725
+function wpinv_maybe_add_empty_option($options, $first_empty) {
726 726
 
727
-    if ( ! empty( $options ) && $first_empty ) {
728
-        return array_merge( array( '' => '' ), $options );
727
+    if (!empty($options) && $first_empty) {
728
+        return array_merge(array('' => ''), $options);
729 729
     }
730 730
     return $options;
731 731
 
@@ -737,21 +737,21 @@  discard block
 block discarded – undo
737 737
  * @param mixed $var Data to sanitize.
738 738
  * @return string|array
739 739
  */
740
-function wpinv_clean( $var ) {
740
+function wpinv_clean($var) {
741 741
 
742
-	if ( is_array( $var ) ) {
743
-		return array_map( 'wpinv_clean', $var );
742
+	if (is_array($var)) {
743
+		return array_map('wpinv_clean', $var);
744 744
     }
745 745
 
746
-    if ( is_object( $var ) ) {
747
-		$object_vars = get_object_vars( $var );
748
-		foreach ( $object_vars as $property_name => $property_value ) {
749
-			$var->$property_name = wpinv_clean( $property_value );
746
+    if (is_object($var)) {
747
+		$object_vars = get_object_vars($var);
748
+		foreach ($object_vars as $property_name => $property_value) {
749
+			$var->$property_name = wpinv_clean($property_value);
750 750
         }
751 751
         return $var;
752 752
 	}
753 753
     
754
-    return is_string( $var ) ? sanitize_text_field( $var ) : $var;
754
+    return is_string($var) ? sanitize_text_field($var) : $var;
755 755
 }
756 756
 
757 757
 /**
@@ -760,43 +760,43 @@  discard block
 block discarded – undo
760 760
  * @param string $str Data to convert.
761 761
  * @return string|array
762 762
  */
763
-function getpaid_convert_price_string_to_options( $str ) {
763
+function getpaid_convert_price_string_to_options($str) {
764 764
 
765
-	$raw_options = array_map( 'trim', explode( ',', $str ) );
766
-    $options     = array();
765
+	$raw_options = array_map('trim', explode(',', $str));
766
+    $options = array();
767 767
 
768
-    foreach ( $raw_options as $option ) {
768
+    foreach ($raw_options as $option) {
769 769
 
770
-        if ( '' == $option ) {
770
+        if ('' == $option) {
771 771
             continue;
772 772
         }
773 773
 
774
-        $option = array_map( 'trim', explode( '|', $option ) );
774
+        $option = array_map('trim', explode('|', $option));
775 775
 
776 776
         $price = null;
777 777
         $label = null;
778 778
 
779
-        if ( isset( $option[0] ) && '' !=  $option[0] ) {
780
-            $label  = $option[0];
779
+        if (isset($option[0]) && '' != $option[0]) {
780
+            $label = $option[0];
781 781
         }
782 782
 
783
-        if ( isset( $option[1] ) && '' !=  $option[1] ) {
783
+        if (isset($option[1]) && '' != $option[1]) {
784 784
             $price = $option[1];
785 785
         }
786 786
 
787
-        if ( ! isset( $price ) ) {
787
+        if (!isset($price)) {
788 788
             $price = $label;
789 789
         }
790 790
 
791
-        if ( ! isset( $price ) || ! is_numeric( $price ) ) {
791
+        if (!isset($price) || !is_numeric($price)) {
792 792
             continue;
793 793
         }
794 794
 
795
-        if ( ! isset( $label ) ) {
795
+        if (!isset($label)) {
796 796
             $label = $price;
797 797
         }
798 798
 
799
-        $options[ $price ] = $label;
799
+        $options[$price] = $label;
800 800
     }
801 801
 
802 802
     return $options;
@@ -805,22 +805,22 @@  discard block
 block discarded – undo
805 805
 /**
806 806
  * Returns the help tip.
807 807
  */
808
-function getpaid_get_help_tip( $tip, $additional_classes = '' ) {
809
-    $additional_classes = sanitize_html_class( $additional_classes );
810
-    $tip                = esc_attr__( $tip );
808
+function getpaid_get_help_tip($tip, $additional_classes = '') {
809
+    $additional_classes = sanitize_html_class($additional_classes);
810
+    $tip                = esc_attr__($tip);
811 811
     return "<span class='wpi-help-tip dashicons dashicons-editor-help $additional_classes' title='$tip'></span>";
812 812
 }
813 813
 
814 814
 /**
815 815
  * Formats a date
816 816
  */
817
-function getpaid_format_date( $date ) {
817
+function getpaid_format_date($date) {
818 818
 
819
-    if ( empty( $date ) || $date == '0000-00-00 00:00:00' ) {
819
+    if (empty($date) || $date == '0000-00-00 00:00:00') {
820 820
         return '';
821 821
     }
822 822
 
823
-    return date_i18n( getpaid_date_format(), strtotime( $date ) );
823
+    return date_i18n(getpaid_date_format(), strtotime($date));
824 824
 
825 825
 }
826 826
 
@@ -829,9 +829,9 @@  discard block
 block discarded – undo
829 829
  *
830 830
  * @return string
831 831
  */
832
-function getpaid_format_date_value( $date, $default = "&mdash;" ) {
833
-    $date = getpaid_format_date( $date );
834
-    return empty( $date ) ? $default : $date;
832
+function getpaid_format_date_value($date, $default = "&mdash;") {
833
+    $date = getpaid_format_date($date);
834
+    return empty($date) ? $default : $date;
835 835
 }
836 836
 
837 837
 /**
@@ -840,7 +840,7 @@  discard block
 block discarded – undo
840 840
  * @return string
841 841
  */
842 842
 function getpaid_date_format() {
843
-	return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) );
843
+	return apply_filters('getpaid_date_format', get_option('date_format'));
844 844
 }
845 845
 
846 846
 /**
@@ -849,7 +849,7 @@  discard block
 block discarded – undo
849 849
  * @return string
850 850
  */
851 851
 function getpaid_time_format() {
852
-	return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) );
852
+	return apply_filters('getpaid_time_format', get_option('time_format'));
853 853
 }
854 854
 
855 855
 /**
@@ -859,16 +859,16 @@  discard block
 block discarded – undo
859 859
  * @param  integer $limit Limit size in characters.
860 860
  * @return string
861 861
  */
862
-function getpaid_limit_length( $string, $limit ) {
862
+function getpaid_limit_length($string, $limit) {
863 863
     $str_limit = $limit - 3;
864 864
 
865
-	if ( function_exists( 'mb_strimwidth' ) ) {
866
-		if ( mb_strlen( $string ) > $limit ) {
867
-			$string = mb_strimwidth( $string, 0, $str_limit ) . '...';
865
+	if (function_exists('mb_strimwidth')) {
866
+		if (mb_strlen($string) > $limit) {
867
+			$string = mb_strimwidth($string, 0, $str_limit) . '...';
868 868
 		}
869 869
 	} else {
870
-		if ( strlen( $string ) > $limit ) {
871
-			$string = substr( $string, 0, $str_limit ) . '...';
870
+		if (strlen($string) > $limit) {
871
+			$string = substr($string, 0, $str_limit) . '...';
872 872
 		}
873 873
 	}
874 874
     return $string;
@@ -882,7 +882,7 @@  discard block
 block discarded – undo
882 882
  * @since 1.0.19
883 883
  */
884 884
 function getpaid_api() {
885
-    return getpaid()->get( 'api' );
885
+    return getpaid()->get('api');
886 886
 }
887 887
 
888 888
 /**
@@ -892,7 +892,7 @@  discard block
 block discarded – undo
892 892
  * @since 1.0.19
893 893
  */
894 894
 function getpaid_post_types() {
895
-    return getpaid()->get( 'post_types' );
895
+    return getpaid()->get('post_types');
896 896
 }
897 897
 
898 898
 /**
@@ -902,7 +902,7 @@  discard block
 block discarded – undo
902 902
  * @since 1.0.19
903 903
  */
904 904
 function getpaid_session() {
905
-    return getpaid()->get( 'session' );
905
+    return getpaid()->get('session');
906 906
 }
907 907
 
908 908
 /**
@@ -912,7 +912,7 @@  discard block
 block discarded – undo
912 912
  * @since 1.0.19
913 913
  */
914 914
 function getpaid_notes() {
915
-    return getpaid()->get( 'notes' );
915
+    return getpaid()->get('notes');
916 916
 }
917 917
 
918 918
 /**
@@ -921,7 +921,7 @@  discard block
 block discarded – undo
921 921
  * @return GetPaid_Admin
922 922
  */
923 923
 function getpaid_admin() {
924
-    return getpaid()->get( 'admin' );
924
+    return getpaid()->get('admin');
925 925
 }
926 926
 
927 927
 /**
@@ -931,6 +931,6 @@  discard block
 block discarded – undo
931 931
  * @param string $base the base url
932 932
  * @return string
933 933
  */
934
-function getpaid_get_authenticated_action_url( $action, $base = false ) {
935
-    return wp_nonce_url( add_query_arg( 'getpaid-action', $action, $base ), 'getpaid-nonce', 'getpaid-nonce' );
934
+function getpaid_get_authenticated_action_url($action, $base = false) {
935
+    return wp_nonce_url(add_query_arg('getpaid-action', $action, $base), 'getpaid-nonce', 'getpaid-nonce');
936 936
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-checkout.php 1 patch
Spacing   +82 added lines, -82 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
  * Main Checkout Class.
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 * 
23 23
 	 * @param GetPaid_Payment_Form_Submission $submission
24 24
 	 */
25
-	public function __construct( $submission ) {
25
+	public function __construct($submission) {
26 26
 		$this->payment_form_submission = $submission;
27 27
 	}
28 28
 
@@ -38,15 +38,15 @@  discard block
 block discarded – undo
38 38
 		// Prepare the invoice.
39 39
 		$items      = $this->get_submission_items();
40 40
 		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
42
-		$prepared   = $this->prepare_submission_data_for_saving( $invoice );
41
+		$invoice    = $this->process_submission_invoice($invoice, $items);
42
+		$prepared   = $this->prepare_submission_data_for_saving($invoice);
43 43
 
44 44
 		// Save the invoice.
45 45
 		$invoice->recalculate_total();
46 46
         $invoice->save();
47 47
 
48 48
 		// Send to the gateway.
49
-		$this->post_process_submission( $invoice, $prepared );
49
+		$this->post_process_submission($invoice, $prepared);
50 50
 	}
51 51
 
52 52
 	/**
@@ -59,34 +59,34 @@  discard block
 block discarded – undo
59 59
 		$data       = $submission->get_data();
60 60
 
61 61
 		// Do we have an error?
62
-        if ( ! empty( $submission->last_error ) ) {
63
-			wp_send_json_error( $submission->last_error );
62
+        if (!empty($submission->last_error)) {
63
+			wp_send_json_error($submission->last_error);
64 64
         }
65 65
 
66 66
 		// We need a billing email.
67
-        if ( ! $submission->has_billing_email() ) {
68
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
67
+        if (!$submission->has_billing_email()) {
68
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
69 69
 		}
70 70
 
71 71
 		// Non-recurring gateways should not be allowed to process recurring invoices.
72
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
73
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
72
+		if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) {
73
+			wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing'));
74 74
 		}
75 75
 
76 76
 		// Ensure the gateway is active.
77
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
78
-			wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
77
+		if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) {
78
+			wpinv_set_error('invalid_gateway', __('The selected payment gateway is not active', 'invoicing'));
79 79
 		}
80 80
 
81 81
 		// Clear any existing errors.
82 82
 		wpinv_clear_errors();
83 83
 
84 84
 		// Allow themes and plugins to hook to errors
85
-		do_action( 'getpaid_checkout_error_checks', $submission );
85
+		do_action('getpaid_checkout_error_checks', $submission);
86 86
 
87 87
 		// Do we have any errors?
88
-        if ( wpinv_get_errors() ) {
89
-            wp_send_json_error( getpaid_get_errors_html() );
88
+        if (wpinv_get_errors()) {
89
+            wp_send_json_error(getpaid_get_errors_html());
90 90
 		}
91 91
 
92 92
 	}
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
 		$items = $this->payment_form_submission->get_items();
102 102
 
103 103
         // Ensure that we have items.
104
-        if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
105
-            wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
104
+        if (empty($items) && !$this->payment_form_submission->has_fees()) {
105
+            wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing'));
106 106
 		}
107 107
 
108 108
 		return $items;
@@ -116,17 +116,17 @@  discard block
 block discarded – undo
116 116
 	protected function get_submission_invoice() {
117 117
 		$submission = $this->payment_form_submission;
118 118
 
119
-		if ( ! $submission->has_invoice() ) {
119
+		if (!$submission->has_invoice()) {
120 120
 			$invoice = new WPInv_Invoice();
121
-			$invoice->created_via( 'payment_form' );
121
+			$invoice->created_via('payment_form');
122 122
 			return $invoice;
123 123
         }
124 124
 
125 125
 		$invoice = $submission->get_invoice();
126 126
 
127 127
 		// Make sure that it is neither paid or refunded.
128
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
129
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
128
+		if ($invoice->is_paid() || $invoice->is_refunded()) {
129
+			wp_send_json_error(__('This invoice has already been paid for.', 'invoicing'));
130 130
 		}
131 131
 
132 132
 		return $invoice;
@@ -139,26 +139,26 @@  discard block
 block discarded – undo
139 139
 	 * @param GetPaid_Form_Item[] $items
140 140
 	 * @return WPInv_Invoice
141 141
 	 */
142
-	protected function process_submission_invoice( $invoice, $items ) {
142
+	protected function process_submission_invoice($invoice, $items) {
143 143
 
144 144
 		$submission = $this->payment_form_submission;
145 145
 		$data       = $submission->get_data();
146 146
 
147 147
 		// Set-up the invoice details.
148
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
149
-		$invoice->set_user_id( $this->get_submission_customer() );
150
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
151
-        $invoice->set_items( $items );
152
-        $invoice->set_fees( $submission->get_fees() );
153
-        $invoice->set_taxes( $submission->get_taxes() );
154
-		$invoice->set_discounts( $submission->get_discounts() );
155
-		$invoice->set_gateway( $data['wpi-gateway'] );
156
-
157
-		if ( $submission->has_discount_code() ) {
158
-            $invoice->set_discount_code( $submission->get_discount_code() );
148
+		$invoice->set_email(sanitize_email($submission->get_billing_email()));
149
+		$invoice->set_user_id($this->get_submission_customer());
150
+		$invoice->set_payment_form(absint($submission->get_payment_form()->get_id()));
151
+        $invoice->set_items($items);
152
+        $invoice->set_fees($submission->get_fees());
153
+        $invoice->set_taxes($submission->get_taxes());
154
+		$invoice->set_discounts($submission->get_discounts());
155
+		$invoice->set_gateway($data['wpi-gateway']);
156
+
157
+		if ($submission->has_discount_code()) {
158
+            $invoice->set_discount_code($submission->get_discount_code());
159 159
 		}
160 160
 
161
-		getpaid_maybe_add_default_address( $invoice );
161
+		getpaid_maybe_add_default_address($invoice);
162 162
 		return $invoice;
163 163
 	}
164 164
 
@@ -171,26 +171,26 @@  discard block
 block discarded – undo
171 171
 		$submission = $this->payment_form_submission;
172 172
 
173 173
 		// If this is an existing invoice...
174
-		if ( $submission->has_invoice() ) {
174
+		if ($submission->has_invoice()) {
175 175
 			return $submission->get_invoice()->get_user_id();
176 176
 		}
177 177
 
178 178
 		// (Maybe) create the user.
179 179
         $user = get_current_user_id();
180 180
 
181
-        if ( empty( $user ) ) {
182
-            $user = get_user_by( 'email', $submission->get_billing_email() );
181
+        if (empty($user)) {
182
+            $user = get_user_by('email', $submission->get_billing_email());
183 183
         }
184 184
 
185
-        if ( empty( $user ) ) {
186
-            $user = wpinv_create_user( $submission->get_billing_email() );
185
+        if (empty($user)) {
186
+            $user = wpinv_create_user($submission->get_billing_email());
187 187
         }
188 188
 
189
-        if ( is_wp_error( $user ) ) {
190
-            wp_send_json_error( $user->get_error_message() );
189
+        if (is_wp_error($user)) {
190
+            wp_send_json_error($user->get_error_message());
191 191
         }
192 192
 
193
-        if ( is_numeric( $user ) ) {
193
+        if (is_numeric($user)) {
194 194
             return $user;
195 195
 		}
196 196
 
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
      *
204 204
 	 * @param WPInv_Invoice $invoice
205 205
      */
206
-    public function prepare_submission_data_for_saving( &$invoice ) {
206
+    public function prepare_submission_data_for_saving(&$invoice) {
207 207
 
208 208
 		$submission = $this->payment_form_submission;
209 209
 
@@ -214,49 +214,49 @@  discard block
 block discarded – undo
214 214
 		$data = $submission->get_data();
215 215
 		
216 216
 		// Loop throught the submitted details.
217
-        foreach ( $submission->get_payment_form()->get_elements() as $field ) {
217
+        foreach ($submission->get_payment_form()->get_elements() as $field) {
218 218
 
219 219
 			// Skip premade fields.
220
-            if ( ! empty( $field['premade'] ) ) {
220
+            if (!empty($field['premade'])) {
221 221
                 continue;
222 222
             }
223 223
 
224 224
             // If it is required and not set, abort.
225
-            if ( ! $submission->is_required_field_set( $field ) ) {
226
-                wp_send_json_error( __( 'Some required fields are not set.', 'invoicing' ) );
225
+            if (!$submission->is_required_field_set($field)) {
226
+                wp_send_json_error(__('Some required fields are not set.', 'invoicing'));
227 227
             }
228 228
 
229 229
             // Handle address fields.
230
-            if ( $field['type'] == 'address' ) {
230
+            if ($field['type'] == 'address') {
231 231
 
232
-                foreach ( $field['fields'] as $address_field ) {
232
+                foreach ($field['fields'] as $address_field) {
233 233
 
234 234
                     // skip if it is not visible.
235
-                    if ( empty( $address_field['visible'] ) ) {
235
+                    if (empty($address_field['visible'])) {
236 236
                         continue;
237 237
                     }
238 238
 
239 239
                     // If it is required and not set, abort
240
-                    if ( ! empty( $address_field['required'] ) && empty( $data[ $address_field['name'] ] ) ) {
241
-                        wp_send_json_error( __( 'Some required fields are not set.', 'invoicing' ) );
240
+                    if (!empty($address_field['required']) && empty($data[$address_field['name']])) {
241
+                        wp_send_json_error(__('Some required fields are not set.', 'invoicing'));
242 242
                     }
243 243
 
244
-                    if ( isset( $data[ $address_field['name'] ] ) ) {
245
-                        $name   = str_replace( 'wpinv_', '', $address_field['name'] );
244
+                    if (isset($data[$address_field['name']])) {
245
+                        $name   = str_replace('wpinv_', '', $address_field['name']);
246 246
                         $method = "set_$name";
247
-                        $invoice->$method( wpinv_clean( $data[ $address_field['name'] ] ) );
247
+                        $invoice->$method(wpinv_clean($data[$address_field['name']]));
248 248
                     }
249 249
 
250 250
                 }
251 251
 
252
-            } else if ( isset( $data[ $field['id'] ] ) ) {
252
+            } else if (isset($data[$field['id']])) {
253 253
                 $label = $field['id'];
254 254
 
255
-                if ( isset( $field['label'] ) ) {
255
+                if (isset($field['label'])) {
256 256
                     $label = $field['label'];
257 257
                 }
258 258
 
259
-                $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] );
259
+                $prepared[wpinv_clean($label)] = wpinv_clean($data[$field['id']]);
260 260
             }
261 261
 
262 262
 		}
@@ -271,22 +271,22 @@  discard block
 block discarded – undo
271 271
 	 * @param WPInv_Invoice $invoice
272 272
 	 * @param array $prepared_payment_form_data
273 273
 	 */
274
-	protected function post_process_submission( $invoice, $prepared_payment_form_data ) {
274
+	protected function post_process_submission($invoice, $prepared_payment_form_data) {
275 275
 
276 276
 		// Ensure the invoice exists.
277
-        if ( ! $invoice->exists() ) {
278
-            wp_send_json_error( __( 'An error occured while saving your invoice.', 'invoicing' ) );
277
+        if (!$invoice->exists()) {
278
+            wp_send_json_error(__('An error occured while saving your invoice.', 'invoicing'));
279 279
         }
280 280
 
281 281
         // Save payment form data.
282
-        if ( ! empty( $prepared_payment_form_data ) ) {
283
-            update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data );
282
+        if (!empty($prepared_payment_form_data)) {
283
+            update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data);
284 284
 		}
285 285
 
286 286
 		// Backwards compatibility.
287
-        add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
287
+        add_filter('wp_redirect', array($this, 'send_redirect_response'));
288 288
 
289
-		$this->process_payment( $invoice );
289
+		$this->process_payment($invoice);
290 290
 
291 291
         // If we are here, there was an error.
292 292
 		wpinv_send_back_to_checkout();
@@ -298,44 +298,44 @@  discard block
 block discarded – undo
298 298
 	 *
299 299
 	 * @param WPInv_Invoice $invoice
300 300
 	 */
301
-	protected function process_payment( $invoice ) {
301
+	protected function process_payment($invoice) {
302 302
 
303 303
 		$submission = $this->payment_form_submission;
304 304
 
305 305
 		// No need to send free invoices to the gateway.
306
-		if ( $invoice->is_free() ) {
307
-			$invoice->set_gateway( 'none' );
308
-			$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
306
+		if ($invoice->is_free()) {
307
+			$invoice->set_gateway('none');
308
+			$invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true);
309 309
 			$invoice->mark_paid();
310
-			wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
310
+			wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
311 311
 		}
312 312
 
313 313
 		// Clear any checkout errors.
314 314
 		wpinv_clear_errors();
315 315
 
316 316
 		// Fires before sending to the gateway.
317
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
317
+		do_action('getpaid_checkout_before_gateway', $invoice, $submission);
318 318
 
319 319
 		// Allow the sumission data to be modified before it is sent to the gateway.
320 320
 		$submission_data    = $submission->get_data();
321
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
322
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
321
+		$submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice);
322
+		$submission_data    = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice);
323 323
 
324 324
 		// Validate the currency.
325
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
326
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) );
325
+		if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) {
326
+			wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support the invoice currency', 'invoicing'));
327 327
 		}
328 328
 
329 329
 		// Check to see if we have any errors.
330
-		if ( wpinv_get_errors() ) {
330
+		if (wpinv_get_errors()) {
331 331
 			wpinv_send_back_to_checkout();
332 332
 		}
333 333
 
334 334
 		// Send info to the gateway for payment processing
335
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
335
+		do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission);
336 336
 
337 337
 		// Backwards compatibility.
338
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
338
+		wpinv_send_to_gateway($submission_gateway, $invoice);
339 339
 
340 340
 	}
341 341
 
@@ -343,9 +343,9 @@  discard block
 block discarded – undo
343 343
      * Sends a redrect response to payment details.
344 344
      *
345 345
      */
346
-    public function send_redirect_response( $url ) {
347
-        $url = urlencode( $url );
348
-        wp_send_json_success( $url );
346
+    public function send_redirect_response($url) {
347
+        $url = urlencode($url);
348
+        wp_send_json_success($url);
349 349
     }
350 350
 
351 351
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission.php 1 patch
Spacing   +106 added lines, -106 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
 
@@ -134,8 +134,8 @@  discard block
 block discarded – undo
134 134
 		$this->state   = wpinv_get_default_state();
135 135
 
136 136
 		// Do we have an actual submission?
137
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
138
-			$this->load_data( $_POST );
137
+		if (isset($_POST['getpaid_payment_form_submission'])) {
138
+			$this->load_data($_POST);
139 139
 		}
140 140
 
141 141
 	}
@@ -145,19 +145,19 @@  discard block
 block discarded – undo
145 145
 	 *
146 146
 	 * @param array $data
147 147
 	 */
148
-	public function load_data( $data ) {
148
+	public function load_data($data) {
149 149
 
150 150
 		// Remove slashes from the submitted data...
151
-		$data       = wp_unslash( $data );
151
+		$data       = wp_unslash($data);
152 152
 
153 153
 		// Allow plugins to filter the data.
154
-		$data       = apply_filters( 'getpaid_submission_data', $data, $this );
154
+		$data       = apply_filters('getpaid_submission_data', $data, $this);
155 155
 
156 156
 		// Cache it...
157 157
 		$this->data = $data;
158 158
 
159 159
 		// Then generate a unique id from the data.
160
-		$this->id   = md5( wp_json_encode( $data ) );
160
+		$this->id   = md5(wp_json_encode($data));
161 161
 
162 162
 		// Finally, process the submission.
163 163
 		try {
@@ -167,26 +167,26 @@  discard block
 block discarded – undo
167 167
 			$processors = apply_filters(
168 168
 				'getpaid_payment_form_submission_processors',
169 169
 				array(
170
-					array( $this, 'process_payment_form' ),
171
-					array( $this, 'process_invoice' ),
172
-					array( $this, 'process_fees' ),
173
-					array( $this, 'process_items' ),
174
-					array( $this, 'process_taxes' ),
175
-					array( $this, 'process_discount' ),
170
+					array($this, 'process_payment_form'),
171
+					array($this, 'process_invoice'),
172
+					array($this, 'process_fees'),
173
+					array($this, 'process_items'),
174
+					array($this, 'process_taxes'),
175
+					array($this, 'process_discount'),
176 176
 				),
177 177
 				$this		
178 178
 			);
179 179
 
180
-			foreach ( $processors as $processor ) {
181
-				call_user_func_array( $processor, array( &$this ) );
180
+			foreach ($processors as $processor) {
181
+				call_user_func_array($processor, array(&$this));
182 182
 			}
183 183
 
184
-		} catch ( Exception $e ) {
184
+		} catch (Exception $e) {
185 185
 			$this->last_error = $e->getMessage();
186 186
 		}
187 187
 
188 188
 		// Fired when we are done processing a submission.
189
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
189
+		do_action_ref_array('getpaid_process_submission', array(&$this));
190 190
 
191 191
 	}
192 192
 
@@ -207,18 +207,18 @@  discard block
 block discarded – undo
207 207
 	public function process_payment_form() {
208 208
 
209 209
 		// Every submission needs an active payment form.
210
-		if ( empty( $this->data['form_id'] ) ) {
211
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
210
+		if (empty($this->data['form_id'])) {
211
+			throw new Exception(__('Missing payment form', 'invoicing'));
212 212
 		}
213 213
 
214 214
 		// Fetch the payment form.
215
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
215
+		$this->payment_form = new GetPaid_Payment_Form($this->data['form_id']);
216 216
 
217
-		if ( ! $this->payment_form->is_active() ) {
218
-			throw new Exception( __( 'Payment form not active', 'invoicing' ) );
217
+		if (!$this->payment_form->is_active()) {
218
+			throw new Exception(__('Payment form not active', 'invoicing'));
219 219
 		}
220 220
 
221
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
221
+		do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this));
222 222
 	}
223 223
 
224 224
     /**
@@ -248,30 +248,30 @@  discard block
 block discarded – undo
248 248
 	public function process_invoice() {
249 249
 
250 250
 		// Abort if there is no invoice.
251
-		if ( empty( $this->data['invoice_id'] ) ) {
251
+		if (empty($this->data['invoice_id'])) {
252 252
 			return;
253 253
 		}
254 254
 
255 255
 		// If the submission is for an existing invoice, ensure that it exists
256 256
 		// and that it is not paid for.
257
-		$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
257
+		$invoice = wpinv_get_invoice($this->data['invoice_id']);
258 258
 
259
-        if ( empty( $invoice ) ) {
260
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
259
+        if (empty($invoice)) {
260
+			throw new Exception(__('Invalid invoice', 'invoicing'));
261 261
 		}
262 262
 
263
-		if ( $invoice->is_paid() ) {
264
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
263
+		if ($invoice->is_paid()) {
264
+			throw new Exception(__('This invoice is already paid for.', 'invoicing'));
265 265
 		}
266 266
 
267
-		$this->payment_form->set_items( $invoice->get_items() );
267
+		$this->payment_form->set_items($invoice->get_items());
268 268
 		$this->payment_form->invoice = $invoice;
269 269
 
270 270
 		$this->country = $invoice->get_country();
271 271
 		$this->state   = $invoice->get_state();
272 272
 		$this->invoice = $invoice;
273 273
 
274
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
274
+		do_action_ref_array('getpaid_submissions_process_invoice', array(&$this));
275 275
 	}
276 276
 
277 277
 	/**
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
 	 * @return bool
292 292
 	 */
293 293
 	public function has_invoice() {
294
-		return ! empty( $this->invoice );
294
+		return !empty($this->invoice);
295 295
 	}
296 296
 
297 297
 	/*
@@ -310,13 +310,13 @@  discard block
 block discarded – undo
310 310
 	 */
311 311
 	public function process_items() {
312 312
 
313
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
313
+		$processor = new GetPaid_Payment_Form_Submission_Items($this);
314 314
 
315
-		foreach ( $processor->items as $item ) {
316
-			$this->add_item( $item );
315
+		foreach ($processor->items as $item) {
316
+			$this->add_item($item);
317 317
 		}
318 318
 
319
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
319
+		do_action_ref_array('getpaid_submissions_process_items', array(&$this));
320 320
 	}
321 321
 
322 322
 	/**
@@ -325,18 +325,18 @@  discard block
 block discarded – undo
325 325
 	 * @since 1.0.19
326 326
 	 * @param GetPaid_Form_Item $item
327 327
 	 */
328
-	public function add_item( $item ) {
328
+	public function add_item($item) {
329 329
 
330 330
 		// Make sure that it is available for purchase.
331
-		if ( ! $item->can_purchase() ) {
331
+		if (!$item->can_purchase()) {
332 332
 			return;
333 333
 		}
334 334
 
335 335
 		// Each submission can only contain one recurring item.
336
-		if ( $item->is_recurring() ) {
336
+		if ($item->is_recurring()) {
337 337
 
338
-			if ( $this->has_recurring != 0 ) {
339
-				throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) );
338
+			if ($this->has_recurring != 0) {
339
+				throw new Exception(__('You can only buy one recurring item at a time.', 'invoicing'));
340 340
 			}
341 341
 
342 342
 			$this->has_recurring = $item->get_id();
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 		}
345 345
 
346 346
 		// Update the items and totals.
347
-		$this->items[ $item->get_id() ]         = $item;
347
+		$this->items[$item->get_id()]         = $item;
348 348
 		$this->totals['subtotal']['initial']   += $item->get_sub_total();
349 349
 		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
350 350
 
@@ -358,17 +358,17 @@  discard block
 block discarded – undo
358 358
 	 *
359 359
 	 * @since 1.0.19
360 360
 	 */
361
-	public function remove_item( $item_id ) {
361
+	public function remove_item($item_id) {
362 362
 
363
-		if ( isset( $this->items[ $item_id ] ) ) {
364
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
365
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
363
+		if (isset($this->items[$item_id])) {
364
+			$this->totals['subtotal']['initial']   -= $this->items[$item_id]->get_sub_total();
365
+			$this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total();
366 366
 
367
-			if ( $this->items[ $item_id ]->is_recurring() ) {
367
+			if ($this->items[$item_id]->is_recurring()) {
368 368
 				$this->has_recurring = 0;
369 369
 			}
370 370
 
371
-			unset( $this->items[ $item_id ] );
371
+			unset($this->items[$item_id]);
372 372
 		}
373 373
 		
374 374
 	}
@@ -418,26 +418,26 @@  discard block
 block discarded – undo
418 418
 	public function process_taxes() {
419 419
 
420 420
 		// Abort if we're not using taxes.
421
-		if ( ! $this->use_taxes() ) {
421
+		if (!$this->use_taxes()) {
422 422
 			return;
423 423
 		}
424 424
 
425 425
 		// If a custom country && state has been passed in, use it to calculate taxes.
426
-		if ( ! empty( $this->data['wpinv_country'] ) ) {
426
+		if (!empty($this->data['wpinv_country'])) {
427 427
 			$this->country = $this->data['wpinv_country'];
428 428
 		}
429 429
 
430
-		if ( ! empty( $this->data['wpinv_state'] ) ) {
430
+		if (!empty($this->data['wpinv_state'])) {
431 431
 			$this->country = $this->data['wpinv_state'];
432 432
 		}
433 433
 
434
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
434
+		$processor = new GetPaid_Payment_Form_Submission_Taxes($this);
435 435
 
436
-		foreach ( $processor->taxes as $tax ) {
437
-			$this->add_tax( $tax );
436
+		foreach ($processor->taxes as $tax) {
437
+			$this->add_tax($tax);
438 438
 		}
439 439
 
440
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
440
+		do_action_ref_array('getpaid_submissions_process_taxes', array(&$this));
441 441
 	}
442 442
 
443 443
 	/**
@@ -446,10 +446,10 @@  discard block
 block discarded – undo
446 446
 	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
447 447
 	 * @since 1.0.19
448 448
 	 */
449
-	public function add_tax( $tax ) {
450
-		$this->taxes[ $tax['name'] ]         = $tax;
451
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
452
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
449
+	public function add_tax($tax) {
450
+		$this->taxes[$tax['name']]         = $tax;
451
+		$this->totals['taxes']['initial']   += wpinv_sanitize_amount($tax['initial_tax']);
452
+		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']);
453 453
 	}
454 454
 
455 455
 	/**
@@ -457,12 +457,12 @@  discard block
 block discarded – undo
457 457
 	 *
458 458
 	 * @since 1.0.19
459 459
 	 */
460
-	public function remove_tax( $tax_name ) {
460
+	public function remove_tax($tax_name) {
461 461
 
462
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
463
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
464
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
465
-			unset( $this->taxes[ $tax_name ] );
462
+		if (isset($this->taxes[$tax_name])) {
463
+			$this->totals['taxes']['initial']   -= $this->taxes[$tax_name]['initial_tax'];
464
+			$this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax'];
465
+			unset($this->taxes[$tax_name]);
466 466
 		}
467 467
 
468 468
 	}
@@ -476,11 +476,11 @@  discard block
 block discarded – undo
476 476
 
477 477
 		$use_taxes = wpinv_use_taxes();
478 478
 
479
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
479
+		if ($this->has_invoice() && !$this->invoice->is_taxable()) {
480 480
 			$use_taxes = false;
481 481
 		}
482 482
 
483
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
483
+		return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this);
484 484
 
485 485
 	}
486 486
 
@@ -529,13 +529,13 @@  discard block
 block discarded – undo
529 529
 
530 530
 		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
531 531
 		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
532
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
532
+		$processor        = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total);
533 533
 
534
-		foreach ( $processor->discounts as $discount ) {
535
-			$this->add_discount( $discount );
534
+		foreach ($processor->discounts as $discount) {
535
+			$this->add_discount($discount);
536 536
 		}
537 537
 
538
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
538
+		do_action_ref_array('getpaid_submissions_process_discounts', array(&$this));
539 539
 	}
540 540
 
541 541
 	/**
@@ -544,10 +544,10 @@  discard block
 block discarded – undo
544 544
 	 * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
545 545
 	 * @since 1.0.19
546 546
 	 */
547
-	public function add_discount( $discount ) {
548
-		$this->discounts[ $discount['name'] ]   = $discount;
549
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
550
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
547
+	public function add_discount($discount) {
548
+		$this->discounts[$discount['name']]   = $discount;
549
+		$this->totals['discount']['initial']   += wpinv_sanitize_amount($discount['initial_discount']);
550
+		$this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']);
551 551
 	}
552 552
 
553 553
 	/**
@@ -555,12 +555,12 @@  discard block
 block discarded – undo
555 555
 	 *
556 556
 	 * @since 1.0.19
557 557
 	 */
558
-	public function remove_discount( $name ) {
558
+	public function remove_discount($name) {
559 559
 
560
-		if ( isset( $this->discounts[ $name ] ) ) {
561
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
562
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
563
-			unset( $this->discounts[ $name ] );
560
+		if (isset($this->discounts[$name])) {
561
+			$this->totals['discount']['initial']   -= $this->discounts[$name]['initial_discount'];
562
+			$this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount'];
563
+			unset($this->discounts[$name]);
564 564
 		}
565 565
 
566 566
 	}
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
 	 * @return bool
573 573
 	 */
574 574
 	public function has_discount_code() {
575
-		return ! empty( $this->discounts['discount_code'] );
575
+		return !empty($this->discounts['discount_code']);
576 576
 	}
577 577
 
578 578
 	/**
@@ -629,13 +629,13 @@  discard block
 block discarded – undo
629 629
 	 */
630 630
 	public function process_fees() {
631 631
 
632
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
632
+		$fees_processor = new GetPaid_Payment_Form_Submission_Fees($this);
633 633
 
634
-		foreach ( $fees_processor->fees as $fee ) {
635
-			$this->add_fee( $fee );
634
+		foreach ($fees_processor->fees as $fee) {
635
+			$this->add_fee($fee);
636 636
 		}
637 637
 
638
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
638
+		do_action_ref_array('getpaid_submissions_process_fees', array(&$this));
639 639
 	}
640 640
 
641 641
 	/**
@@ -644,11 +644,11 @@  discard block
 block discarded – undo
644 644
 	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
645 645
 	 * @since 1.0.19
646 646
 	 */
647
-	public function add_fee( $fee ) {
647
+	public function add_fee($fee) {
648 648
 
649
-		$this->fees[ $fee['name'] ]         = $fee;
650
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
651
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
649
+		$this->fees[$fee['name']]         = $fee;
650
+		$this->totals['fees']['initial']   += wpinv_sanitize_amount($fee['initial_fee']);
651
+		$this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']);
652 652
 
653 653
 	}
654 654
 
@@ -657,12 +657,12 @@  discard block
 block discarded – undo
657 657
 	 *
658 658
 	 * @since 1.0.19
659 659
 	 */
660
-	public function remove_fee( $name ) {
660
+	public function remove_fee($name) {
661 661
 
662
-		if ( isset( $this->fees[ $name ] ) ) {
663
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
664
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
665
-			unset( $this->fees[ $name ] );
662
+		if (isset($this->fees[$name])) {
663
+			$this->totals['fees']['initial']   -= $this->fees[$name]['initial_fee'];
664
+			$this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee'];
665
+			unset($this->fees[$name]);
666 666
 		}
667 667
 
668 668
 	}
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
 	 * @since 1.0.19
702 702
 	 */
703 703
 	public function has_fees() {
704
-		return count( $this->fees ) !== 0;
704
+		return count($this->fees) !== 0;
705 705
 	}
706 706
 
707 707
 	/*
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
 	 */
720 720
 	public function get_total() {
721 721
 		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
722
-		return max( $total, 0 );
722
+		return max($total, 0);
723 723
 	}
724 724
 
725 725
 	/**
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
 	 */
730 730
 	public function get_recurring_total() {
731 731
 		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
732
-		return max( $total, 0 );
732
+		return max($total, 0);
733 733
 	}
734 734
 
735 735
 	/**
@@ -741,12 +741,12 @@  discard block
 block discarded – undo
741 741
 		$initial   = $this->get_total();
742 742
 		$recurring = $this->get_recurring_total();
743 743
 
744
-		if ( $this->has_recurring == 0 ) {
744
+		if ($this->has_recurring == 0) {
745 745
 			$recurring = 0;
746 746
 		}
747 747
 
748 748
 		$collect = $initial > 0 || $recurring > 0;
749
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
749
+		return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this);
750 750
 	}
751 751
 
752 752
 	/**
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
 	 * @since 1.0.19
756 756
 	 */
757 757
 	public function get_billing_email() {
758
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
758
+		return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this);
759 759
 	}
760 760
 
761 761
 	/**
@@ -765,7 +765,7 @@  discard block
 block discarded – undo
765 765
 	 */
766 766
 	public function has_billing_email() {
767 767
 		$billing_email = $this->get_billing_email();
768
-		return ! empty( $billing_email ) && is_email( $billing_email );
768
+		return !empty($billing_email) && is_email($billing_email);
769 769
 	}
770 770
 
771 771
 	/**
@@ -795,8 +795,8 @@  discard block
 block discarded – undo
795 795
 	 * @since 1.0.19
796 796
 	 * @return mixed
797 797
 	 */
798
-	public function get_field( $field ) {
799
-		return isset( $this->data[ $field ] ) ? $this->data[ $field ] : '';
798
+	public function get_field($field) {
799
+		return isset($this->data[$field]) ? $this->data[$field] : '';
800 800
 	}
801 801
 
802 802
 	/**
@@ -804,8 +804,8 @@  discard block
 block discarded – undo
804 804
 	 *
805 805
 	 * @since 1.0.19
806 806
 	 */
807
-	public function is_required_field_set( $field ) {
808
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
807
+	public function is_required_field_set($field) {
808
+		return empty($field['required']) || !empty($this->data[$field['id']]);
809 809
 	}
810 810
 
811 811
 	/**
@@ -813,8 +813,8 @@  discard block
 block discarded – undo
813 813
 	 *
814 814
 	 * @since 1.0.19
815 815
 	 */
816
-	public function format_amount( $amount ) {
817
-		return wpinv_price( $amount, $this->get_currency() );
816
+	public function format_amount($amount) {
817
+		return wpinv_price($amount, $this->get_currency());
818 818
 	}
819 819
 
820 820
 }
Please login to merge, or discard this patch.
includes/class-getpaid-daily-maintenance.php 1 patch
Spacing   +21 added lines, -21 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
  * Daily maintenance class.
@@ -15,18 +15,18 @@  discard block
 block discarded – undo
15 15
 	/**
16 16
 	 * Class constructor.
17 17
 	 */
18
-	public function __construct(){
18
+	public function __construct() {
19 19
 
20 20
 		// Clear deprecated events.
21
-		add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) );
21
+		add_action('wp', array($this, 'maybe_clear_deprecated_events'));
22 22
 
23 23
 		// (Maybe) schedule a cron that runs daily.
24
-		add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) );
24
+		add_action('wp', array($this, 'maybe_create_scheduled_event'));
25 25
 
26 26
 		// Fired everyday at 7 a.m (this might vary for sites with few visitors)
27
-		add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) );
28
-		add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) );
29
-		add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) );
27
+		add_action('getpaid_daily_maintenance', array($this, 'log_cron_run'));
28
+		add_action('getpaid_daily_maintenance', array($this, 'backwards_compat'));
29
+		add_action('getpaid_daily_maintenance', array($this, 'maybe_expire_subscriptions'));
30 30
 
31 31
 	}
32 32
 
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
 	 */
37 37
 	public function maybe_create_scheduled_event() {
38 38
 
39
-		if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) {
40
-			$timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) );
41
-			wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' );
39
+		if (!wp_next_scheduled('getpaid_daily_maintenance')) {
40
+			$timestamp = strtotime('tomorrow 07:00:00', current_time('timestamp'));
41
+			wp_schedule_event($timestamp, 'daily', 'getpaid_daily_maintenance');
42 42
 		}
43 43
 
44 44
 	}
@@ -49,10 +49,10 @@  discard block
 block discarded – undo
49 49
 	 */
50 50
 	public function maybe_clear_deprecated_events() {
51 51
 
52
-		if ( ! get_option( 'wpinv_cleared_old_events' ) ) {
53
-			wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' );
54
-			wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' );
55
-			update_option( 'wpinv_cleared_old_events', 1 );
52
+		if (!get_option('wpinv_cleared_old_events')) {
53
+			wp_clear_scheduled_hook('wpinv_register_schedule_event_twicedaily');
54
+			wp_clear_scheduled_hook('wpinv_register_schedule_event_daily');
55
+			update_option('wpinv_cleared_old_events', 1);
56 56
 		}
57 57
 
58 58
 	}
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 *
63 63
 	 */
64 64
 	public function backwards_compat() {
65
-		do_action( 'wpinv_register_schedule_event_daily' );
65
+		do_action('wpinv_register_schedule_event_daily');
66 66
 	}
67 67
 
68 68
 	/**
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	public function maybe_expire_subscriptions() {
73 73
 
74 74
 		// Fetch expired subscriptions (skips those that expire today).
75
-		$args  = array(
75
+		$args = array(
76 76
 			'number'             => -1,
77 77
 			'count_total'        => false,
78 78
 			'status'             => 'trialling active failing cancelled',
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
 			),
83 83
 		);
84 84
 
85
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
85
+		$subscriptions = new GetPaid_Subscriptions_Query($args);
86 86
 
87
-		foreach ( $subscriptions->get_results() as $subscription ) {
88
-			if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) {
89
-				$subscription->set_status( 'expired' );
87
+		foreach ($subscriptions->get_results() as $subscription) {
88
+			if (apply_filters('getpaid_daily_maintenance_should_expire_subscription', true, $subscription)) {
89
+				$subscription->set_status('expired');
90 90
 				$subscription->save();
91 91
 			}
92 92
 		}
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 	 *
99 99
 	 */
100 100
 	public function log_cron_run() {
101
-		wpinv_error_log( 'GetPaid Daily Cron' );
101
+		wpinv_error_log('GetPaid Daily Cron');
102 102
 	}
103 103
 
104 104
 }
Please login to merge, or discard this patch.
includes/class-wpinv-discount.php 1 patch
Spacing   +289 added lines, -289 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * @since   1.0.15
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * Discount class.
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  * @since 1.0.15
14 14
  *
15 15
  */
16
-class WPInv_Discount extends GetPaid_Data  {
16
+class WPInv_Discount extends GetPaid_Data {
17 17
 
18 18
 	/**
19 19
 	 * Which data store to load.
@@ -79,35 +79,35 @@  discard block
 block discarded – undo
79 79
 	 *
80 80
 	 * @param int|array|string|WPInv_Discount|WP_Post $discount discount data, object, ID or code.
81 81
 	 */
82
-	public function __construct( $discount = 0 ) {
83
-		parent::__construct( $discount );
82
+	public function __construct($discount = 0) {
83
+		parent::__construct($discount);
84 84
 
85
-		if ( is_numeric( $discount ) && 'wpi_discount' === get_post_type( $discount ) ) {
86
-			$this->set_id( $discount );
87
-		} elseif ( $discount instanceof self ) {
88
-			$this->set_id( $discount->get_id() );
89
-		} elseif ( ! empty( $discount->ID ) ) {
90
-			$this->set_id( $discount->ID );
91
-		} elseif ( is_array( $discount ) ) {
92
-			$this->set_props( $discount );
85
+		if (is_numeric($discount) && 'wpi_discount' === get_post_type($discount)) {
86
+			$this->set_id($discount);
87
+		} elseif ($discount instanceof self) {
88
+			$this->set_id($discount->get_id());
89
+		} elseif (!empty($discount->ID)) {
90
+			$this->set_id($discount->ID);
91
+		} elseif (is_array($discount)) {
92
+			$this->set_props($discount);
93 93
 
94
-			if ( isset( $discount['ID'] ) ) {
95
-				$this->set_id( $discount['ID'] );
94
+			if (isset($discount['ID'])) {
95
+				$this->set_id($discount['ID']);
96 96
 			}
97 97
 
98
-		} elseif ( is_scalar( $discount ) && $discount = self::get_discount_id_by_code( $discount ) ) {
99
-			$this->set_id( $discount );
98
+		} elseif (is_scalar($discount) && $discount = self::get_discount_id_by_code($discount)) {
99
+			$this->set_id($discount);
100 100
 		} else {
101
-			$this->set_object_read( true );
101
+			$this->set_object_read(true);
102 102
 		}
103 103
 
104 104
         // Load the datastore.
105
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
105
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
106 106
 
107
-		if ( $this->get_id() > 0 ) {
108
-            $this->post = get_post( $this->get_id() );
107
+		if ($this->get_id() > 0) {
108
+            $this->post = get_post($this->get_id());
109 109
             $this->ID   = $this->get_id();
110
-			$this->data_store->read( $this );
110
+			$this->data_store->read($this);
111 111
         }
112 112
 
113 113
 	}
@@ -123,50 +123,50 @@  discard block
 block discarded – undo
123 123
 	 * @since 1.0.15
124 124
 	 * @return array|bool array of discount details on success. False otherwise.
125 125
 	 */
126
-	public static function get_data_by( $field, $value ) {
126
+	public static function get_data_by($field, $value) {
127 127
 
128
-		if ( 'id' == strtolower( $field ) ) {
128
+		if ('id' == strtolower($field)) {
129 129
 			// Make sure the value is numeric to avoid casting objects, for example,
130 130
 			// to int 1.
131
-			if ( ! is_numeric( $value ) )
131
+			if (!is_numeric($value))
132 132
 				return false;
133
-			$value = intval( $value );
134
-			if ( $value < 1 )
133
+			$value = intval($value);
134
+			if ($value < 1)
135 135
 				return false;
136 136
 		}
137 137
 
138
-		if ( ! $value || ! is_string( $field ) ) {
138
+		if (!$value || !is_string($field)) {
139 139
 			return false;
140 140
 		}
141 141
 
142
-		$field = trim( $field );
142
+		$field = trim($field);
143 143
 
144 144
 		// prepare query args
145
-		switch ( strtolower( $field ) ) {
145
+		switch (strtolower($field)) {
146 146
 			case 'id':
147 147
 				$discount_id = $value;
148
-				$args		 = array( 'include' => array( $value ) );
148
+				$args = array('include' => array($value));
149 149
 				break;
150 150
 			case 'discount_code':
151 151
 			case 'code':
152
-				$value       = trim( $value );
153
-				$discount_id = wp_cache_get( $value, 'WPInv_Discount_Codes' );
154
-				$args		 = array( 'meta_key' => '_wpi_discount_code', 'meta_value' => $value );
152
+				$value       = trim($value);
153
+				$discount_id = wp_cache_get($value, 'WPInv_Discount_Codes');
154
+				$args = array('meta_key' => '_wpi_discount_code', 'meta_value' => $value);
155 155
 				break;
156 156
 			case 'name':
157 157
 				$discount_id = 0;
158
-				$args		 = array( 'name' => trim( $value ) );
158
+				$args		 = array('name' => trim($value));
159 159
 				break;
160 160
 			default:
161
-				$args		 = apply_filters( "wpinv_discount_get_data_by_{$field}_args", null, $value );
162
-				if ( ! is_array( $args ) ) {
163
-					return apply_filters( "wpinv_discount_get_data_by_$field", false, $value );
161
+				$args		 = apply_filters("wpinv_discount_get_data_by_{$field}_args", null, $value);
162
+				if (!is_array($args)) {
163
+					return apply_filters("wpinv_discount_get_data_by_$field", false, $value);
164 164
 				}
165 165
 
166 166
 		}
167 167
 
168 168
 		// Check if there is a cached value.
169
-		if ( ! empty( $discount_id ) && $discount = wp_cache_get( (int) $discount_id, 'WPInv_Discounts' ) ) {
169
+		if (!empty($discount_id) && $discount = wp_cache_get((int) $discount_id, 'WPInv_Discounts')) {
170 170
 			return $discount;
171 171
 		}
172 172
 
@@ -175,13 +175,13 @@  discard block
 block discarded – undo
175 175
 			array(
176 176
 				'post_type'      => 'wpi_discount',
177 177
 				'posts_per_page' => 1,
178
-				'post_status'    => array( 'publish', 'pending', 'draft', 'expired' )
178
+				'post_status'    => array('publish', 'pending', 'draft', 'expired')
179 179
 			)
180 180
 		);
181 181
 
182
-		$discount = get_posts( $args );
182
+		$discount = get_posts($args);
183 183
 
184
-		if( empty( $discount ) ) {
184
+		if (empty($discount)) {
185 185
 			return false;
186 186
 		}
187 187
 
@@ -190,30 +190,30 @@  discard block
 block discarded – undo
190 190
 		// Prepare the return data.
191 191
 		$return = array(
192 192
             'ID'                          => $discount->ID,
193
-            'code'                        => get_post_meta( $discount->ID, '_wpi_discount_code', true ),
194
-            'amount'                      => get_post_meta( $discount->ID, '_wpi_discount_amount', true ),
193
+            'code'                        => get_post_meta($discount->ID, '_wpi_discount_code', true),
194
+            'amount'                      => get_post_meta($discount->ID, '_wpi_discount_amount', true),
195 195
             'date_created'                => $discount->post_date,
196 196
 			'date_modified'               => $discount->post_modified,
197 197
 			'status'               		  => $discount->post_status,
198
-			'start'                  	  => get_post_meta( $discount->ID, '_wpi_discount_start', true ),
199
-            'expiration'                  => get_post_meta( $discount->ID, '_wpi_discount_expiration', true ),
200
-            'type'               		  => get_post_meta( $discount->ID, '_wpi_discount_type', true ),
198
+			'start'                  	  => get_post_meta($discount->ID, '_wpi_discount_start', true),
199
+            'expiration'                  => get_post_meta($discount->ID, '_wpi_discount_expiration', true),
200
+            'type'               		  => get_post_meta($discount->ID, '_wpi_discount_type', true),
201 201
             'description'                 => $discount->post_excerpt,
202
-            'uses'                 		  => get_post_meta( $discount->ID, '_wpi_discount_uses', true ),
203
-            'is_single_use'               => get_post_meta( $discount->ID, '_wpi_discount_is_single_use', true ),
204
-            'items'              	      => get_post_meta( $discount->ID, '_wpi_discount_items', true ),
205
-            'excluded_items'              => get_post_meta( $discount->ID, '_wpi_discount_excluded_items', true ),
206
-            'max_uses'                    => get_post_meta( $discount->ID, '_wpi_discount_max_uses', true ),
207
-            'is_recurring'                => get_post_meta( $discount->ID, '_wpi_discount_is_recurring', true ),
208
-            'min_total'                   => get_post_meta( $discount->ID, '_wpi_discount_min_total', true ),
209
-            'max_total'                   => get_post_meta( $discount->ID, '_wpi_discount_max_total', true ),
202
+            'uses'                 		  => get_post_meta($discount->ID, '_wpi_discount_uses', true),
203
+            'is_single_use'               => get_post_meta($discount->ID, '_wpi_discount_is_single_use', true),
204
+            'items'              	      => get_post_meta($discount->ID, '_wpi_discount_items', true),
205
+            'excluded_items'              => get_post_meta($discount->ID, '_wpi_discount_excluded_items', true),
206
+            'max_uses'                    => get_post_meta($discount->ID, '_wpi_discount_max_uses', true),
207
+            'is_recurring'                => get_post_meta($discount->ID, '_wpi_discount_is_recurring', true),
208
+            'min_total'                   => get_post_meta($discount->ID, '_wpi_discount_min_total', true),
209
+            'max_total'                   => get_post_meta($discount->ID, '_wpi_discount_max_total', true),
210 210
         );
211 211
 
212
-		$return = apply_filters( 'wpinv_discount_properties', $return );
212
+		$return = apply_filters('wpinv_discount_properties', $return);
213 213
 
214 214
 		// Update the cache with our data
215
-		wp_cache_add( $discount->ID, $return, 'WPInv_Discounts' );
216
-		wp_cache_add( $return['code'], $discount->ID, 'WPInv_Discount_Codes' );
215
+		wp_cache_add($discount->ID, $return, 'WPInv_Discounts');
216
+		wp_cache_add($return['code'], $discount->ID, 'WPInv_Discount_Codes');
217 217
 
218 218
 		return $return;
219 219
 	}
@@ -227,19 +227,19 @@  discard block
 block discarded – undo
227 227
 	 * @since 1.0.15
228 228
 	 * @return int
229 229
 	 */
230
-	public static function get_discount_id_by_code( $discount_code ) {
230
+	public static function get_discount_id_by_code($discount_code) {
231 231
 
232 232
 		// Trim the code.
233
-		$discount_code = trim( $discount_code );
233
+		$discount_code = trim($discount_code);
234 234
 
235 235
 		// Ensure a value has been passed.
236
-		if ( empty( $discount_code ) ) {
236
+		if (empty($discount_code)) {
237 237
 			return 0;
238 238
 		}
239 239
 
240 240
 		// Maybe retrieve from the cache.
241
-		$discount_id   = wp_cache_get( $discount_code, 'getpaid_discount_codes' );
242
-		if ( ! empty( $discount_id ) ) {
241
+		$discount_id = wp_cache_get($discount_code, 'getpaid_discount_codes');
242
+		if (!empty($discount_id)) {
243 243
 			return $discount_id;
244 244
 		}
245 245
 
@@ -250,19 +250,19 @@  discard block
 block discarded – undo
250 250
 				'meta_value'     => $discount_code,
251 251
 				'post_type'      => 'wpi_discount',
252 252
 				'posts_per_page' => 1,
253
-				'post_status'    => array( 'publish', 'pending', 'draft', 'expired' ),
253
+				'post_status'    => array('publish', 'pending', 'draft', 'expired'),
254 254
 				'fields'         => 'ids',
255 255
 			)
256 256
 		);
257 257
 
258
-		if ( empty( $discounts ) ) {
258
+		if (empty($discounts)) {
259 259
 			return 0;
260 260
 		}
261 261
 
262 262
 		$discount_id = $discounts[0];
263 263
 
264 264
 		// Update the cache with our data
265
-		wp_cache_add( get_post_meta( $discount_id, '_wpi_discount_code', true ), $discount_id, 'getpaid_discount_codes' );
265
+		wp_cache_add(get_post_meta($discount_id, '_wpi_discount_code', true), $discount_id, 'getpaid_discount_codes');
266 266
 
267 267
 		return $discount_id;
268 268
 	}
@@ -275,8 +275,8 @@  discard block
 block discarded – undo
275 275
 	 *
276 276
 	 * @return bool Whether the given discount field is set.
277 277
 	 */
278
-	public function __isset( $key ){
279
-		return isset( $this->data[$key] ) || method_exists( $this, "get_$key");
278
+	public function __isset($key) {
279
+		return isset($this->data[$key]) || method_exists($this, "get_$key");
280 280
 	}
281 281
 
282 282
 	/*
@@ -301,8 +301,8 @@  discard block
 block discarded – undo
301 301
 	 * @param  string $context View or edit context.
302 302
 	 * @return string
303 303
 	 */
304
-	public function get_status( $context = 'view' ) {
305
-		return $this->get_prop( 'status', $context );
304
+	public function get_status($context = 'view') {
305
+		return $this->get_prop('status', $context);
306 306
     }
307 307
 
308 308
     /**
@@ -312,8 +312,8 @@  discard block
 block discarded – undo
312 312
 	 * @param  string $context View or edit context.
313 313
 	 * @return string
314 314
 	 */
315
-	public function get_version( $context = 'view' ) {
316
-		return $this->get_prop( 'version', $context );
315
+	public function get_version($context = 'view') {
316
+		return $this->get_prop('version', $context);
317 317
     }
318 318
 
319 319
     /**
@@ -323,8 +323,8 @@  discard block
 block discarded – undo
323 323
 	 * @param  string $context View or edit context.
324 324
 	 * @return string
325 325
 	 */
326
-	public function get_date_created( $context = 'view' ) {
327
-		return $this->get_prop( 'date_created', $context );
326
+	public function get_date_created($context = 'view') {
327
+		return $this->get_prop('date_created', $context);
328 328
     }
329 329
 
330 330
     /**
@@ -334,11 +334,11 @@  discard block
 block discarded – undo
334 334
 	 * @param  string $context View or edit context.
335 335
 	 * @return string
336 336
 	 */
337
-	public function get_date_created_gmt( $context = 'view' ) {
338
-        $date = $this->get_date_created( $context );
337
+	public function get_date_created_gmt($context = 'view') {
338
+        $date = $this->get_date_created($context);
339 339
 
340
-        if ( $date ) {
341
-            $date = get_gmt_from_date( $date );
340
+        if ($date) {
341
+            $date = get_gmt_from_date($date);
342 342
         }
343 343
 		return $date;
344 344
     }
@@ -350,8 +350,8 @@  discard block
 block discarded – undo
350 350
 	 * @param  string $context View or edit context.
351 351
 	 * @return string
352 352
 	 */
353
-	public function get_date_modified( $context = 'view' ) {
354
-		return $this->get_prop( 'date_modified', $context );
353
+	public function get_date_modified($context = 'view') {
354
+		return $this->get_prop('date_modified', $context);
355 355
     }
356 356
 
357 357
     /**
@@ -361,11 +361,11 @@  discard block
 block discarded – undo
361 361
 	 * @param  string $context View or edit context.
362 362
 	 * @return string
363 363
 	 */
364
-	public function get_date_modified_gmt( $context = 'view' ) {
365
-        $date = $this->get_date_modified( $context );
364
+	public function get_date_modified_gmt($context = 'view') {
365
+        $date = $this->get_date_modified($context);
366 366
 
367
-        if ( $date ) {
368
-            $date = get_gmt_from_date( $date );
367
+        if ($date) {
368
+            $date = get_gmt_from_date($date);
369 369
         }
370 370
 		return $date;
371 371
     }
@@ -377,8 +377,8 @@  discard block
 block discarded – undo
377 377
 	 * @param  string $context View or edit context.
378 378
 	 * @return string
379 379
 	 */
380
-	public function get_name( $context = 'view' ) {
381
-		return $this->get_prop( 'name', $context );
380
+	public function get_name($context = 'view') {
381
+		return $this->get_prop('name', $context);
382 382
     }
383 383
 
384 384
     /**
@@ -388,8 +388,8 @@  discard block
 block discarded – undo
388 388
 	 * @param  string $context View or edit context.
389 389
 	 * @return string
390 390
 	 */
391
-	public function get_title( $context = 'view' ) {
392
-		return $this->get_name( $context );
391
+	public function get_title($context = 'view') {
392
+		return $this->get_name($context);
393 393
     }
394 394
 
395 395
     /**
@@ -399,8 +399,8 @@  discard block
 block discarded – undo
399 399
 	 * @param  string $context View or edit context.
400 400
 	 * @return string
401 401
 	 */
402
-	public function get_description( $context = 'view' ) {
403
-		return $this->get_prop( 'description', $context );
402
+	public function get_description($context = 'view') {
403
+		return $this->get_prop('description', $context);
404 404
     }
405 405
 
406 406
     /**
@@ -410,8 +410,8 @@  discard block
 block discarded – undo
410 410
 	 * @param  string $context View or edit context.
411 411
 	 * @return string
412 412
 	 */
413
-	public function get_excerpt( $context = 'view' ) {
414
-		return $this->get_description( $context );
413
+	public function get_excerpt($context = 'view') {
414
+		return $this->get_description($context);
415 415
     }
416 416
 
417 417
     /**
@@ -421,8 +421,8 @@  discard block
 block discarded – undo
421 421
 	 * @param  string $context View or edit context.
422 422
 	 * @return string
423 423
 	 */
424
-	public function get_summary( $context = 'view' ) {
425
-		return $this->get_description( $context );
424
+	public function get_summary($context = 'view') {
425
+		return $this->get_description($context);
426 426
     }
427 427
 
428 428
     /**
@@ -432,8 +432,8 @@  discard block
 block discarded – undo
432 432
 	 * @param  string $context View or edit context.
433 433
 	 * @return string
434 434
 	 */
435
-	public function get_author( $context = 'view' ) {
436
-		return (int) $this->get_prop( 'author', $context );
435
+	public function get_author($context = 'view') {
436
+		return (int) $this->get_prop('author', $context);
437 437
 	}
438 438
 	
439 439
 	/**
@@ -443,8 +443,8 @@  discard block
 block discarded – undo
443 443
 	 * @param  string $context View or edit context.
444 444
 	 * @return string
445 445
 	 */
446
-	public function get_code( $context = 'view' ) {
447
-		return $this->get_prop( 'code', $context );
446
+	public function get_code($context = 'view') {
447
+		return $this->get_prop('code', $context);
448 448
 	}
449 449
 	
450 450
 	/**
@@ -454,8 +454,8 @@  discard block
 block discarded – undo
454 454
 	 * @param  string $context View or edit context.
455 455
 	 * @return string
456 456
 	 */
457
-	public function get_coupon_code( $context = 'view' ) {
458
-		return $this->get_code( $context );
457
+	public function get_coupon_code($context = 'view') {
458
+		return $this->get_code($context);
459 459
 	}
460 460
 	
461 461
 	/**
@@ -465,8 +465,8 @@  discard block
 block discarded – undo
465 465
 	 * @param  string $context View or edit context.
466 466
 	 * @return string
467 467
 	 */
468
-	public function get_discount_code( $context = 'view' ) {
469
-		return $this->get_code( $context );
468
+	public function get_discount_code($context = 'view') {
469
+		return $this->get_code($context);
470 470
 	}
471 471
 	
472 472
 	/**
@@ -476,8 +476,8 @@  discard block
 block discarded – undo
476 476
 	 * @param  string $context View or edit context.
477 477
 	 * @return float
478 478
 	 */
479
-	public function get_amount( $context = 'view' ) {
480
-		return $this->get_prop( 'amount', $context );
479
+	public function get_amount($context = 'view') {
480
+		return $this->get_prop('amount', $context);
481 481
 	}
482 482
 
483 483
 	/**
@@ -488,13 +488,13 @@  discard block
 block discarded – undo
488 488
 	 */
489 489
 	public function get_formatted_amount() {
490 490
 
491
-		if ( $this->is_type( 'flat' ) ) {
492
-			$rate = wpinv_price( wpinv_format_amount( $this->get_amount() ) );
491
+		if ($this->is_type('flat')) {
492
+			$rate = wpinv_price(wpinv_format_amount($this->get_amount()));
493 493
 		} else {
494 494
 			$rate = $this->get_amount() . '%';
495 495
 		}
496 496
 
497
-		return apply_filters( 'wpinv_format_discount_rate', $rate, $this->get_type(), $this->get_amount() );
497
+		return apply_filters('wpinv_format_discount_rate', $rate, $this->get_type(), $this->get_amount());
498 498
 	}
499 499
 	
500 500
 	/**
@@ -504,8 +504,8 @@  discard block
 block discarded – undo
504 504
 	 * @param  string $context View or edit context.
505 505
 	 * @return string
506 506
 	 */
507
-	public function get_start( $context = 'view' ) {
508
-		return $this->get_prop( 'start', $context );
507
+	public function get_start($context = 'view') {
508
+		return $this->get_prop('start', $context);
509 509
 	}
510 510
 	
511 511
 	/**
@@ -515,8 +515,8 @@  discard block
 block discarded – undo
515 515
 	 * @param  string $context View or edit context.
516 516
 	 * @return string
517 517
 	 */
518
-	public function get_start_date( $context = 'view' ) {
519
-		return $this->get_start( $context );
518
+	public function get_start_date($context = 'view') {
519
+		return $this->get_start($context);
520 520
 	}
521 521
 	
522 522
 	/**
@@ -526,8 +526,8 @@  discard block
 block discarded – undo
526 526
 	 * @param  string $context View or edit context.
527 527
 	 * @return string
528 528
 	 */
529
-	public function get_expiration( $context = 'view' ) {
530
-		return $this->get_prop( 'expiration', $context );
529
+	public function get_expiration($context = 'view') {
530
+		return $this->get_prop('expiration', $context);
531 531
 	}
532 532
 	
533 533
 	/**
@@ -537,8 +537,8 @@  discard block
 block discarded – undo
537 537
 	 * @param  string $context View or edit context.
538 538
 	 * @return string
539 539
 	 */
540
-	public function get_expiration_date( $context = 'view' ) {
541
-		return $this->get_expiration( $context );
540
+	public function get_expiration_date($context = 'view') {
541
+		return $this->get_expiration($context);
542 542
 	}
543 543
 
544 544
 	/**
@@ -548,8 +548,8 @@  discard block
 block discarded – undo
548 548
 	 * @param  string $context View or edit context.
549 549
 	 * @return string
550 550
 	 */
551
-	public function get_end_date( $context = 'view' ) {
552
-		return $this->get_expiration( $context );
551
+	public function get_end_date($context = 'view') {
552
+		return $this->get_expiration($context);
553 553
 	}
554 554
 	
555 555
 	/**
@@ -559,8 +559,8 @@  discard block
 block discarded – undo
559 559
 	 * @param  string $context View or edit context.
560 560
 	 * @return string
561 561
 	 */
562
-	public function get_type( $context = 'view' ) {
563
-		return $this->get_prop( 'type', $context );
562
+	public function get_type($context = 'view') {
563
+		return $this->get_prop('type', $context);
564 564
 	}
565 565
 
566 566
 	/**
@@ -570,8 +570,8 @@  discard block
 block discarded – undo
570 570
 	 * @param  string $context View or edit context.
571 571
 	 * @return int
572 572
 	 */
573
-	public function get_uses( $context = 'view' ) {
574
-		return (int) $this->get_prop( 'uses', $context );
573
+	public function get_uses($context = 'view') {
574
+		return (int) $this->get_prop('uses', $context);
575 575
 	}
576 576
 
577 577
 	/**
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
 	 */
583 583
 	public function get_usage() {
584 584
 
585
-		if ( ! $this->has_limit() ) {
585
+		if (!$this->has_limit()) {
586 586
 			return $this->get_uses() . ' / ' . ' &infin;';
587 587
 		}
588 588
 
@@ -597,9 +597,9 @@  discard block
 block discarded – undo
597 597
 	 * @param  string $context View or edit context.
598 598
 	 * @return int
599 599
 	 */
600
-	public function get_max_uses( $context = 'view' ) {
601
-		$max_uses = $this->get_prop( 'max_uses', $context );
602
-		return empty( $max_uses ) ? null : $max_uses;
600
+	public function get_max_uses($context = 'view') {
601
+		$max_uses = $this->get_prop('max_uses', $context);
602
+		return empty($max_uses) ? null : $max_uses;
603 603
 	}
604 604
 
605 605
 	/**
@@ -609,8 +609,8 @@  discard block
 block discarded – undo
609 609
 	 * @param  string $context View or edit context.
610 610
 	 * @return bool
611 611
 	 */
612
-	public function get_is_single_use( $context = 'view' ) {
613
-		return $this->get_prop( 'is_single_use', $context );
612
+	public function get_is_single_use($context = 'view') {
613
+		return $this->get_prop('is_single_use', $context);
614 614
 	}
615 615
 
616 616
 	/**
@@ -620,8 +620,8 @@  discard block
 block discarded – undo
620 620
 	 * @param  string $context View or edit context.
621 621
 	 * @return array
622 622
 	 */
623
-	public function get_items( $context = 'view' ) {
624
-		return wpinv_parse_list( $this->get_prop( 'items', $context ) );
623
+	public function get_items($context = 'view') {
624
+		return wpinv_parse_list($this->get_prop('items', $context));
625 625
 	}
626 626
 
627 627
 	/**
@@ -631,8 +631,8 @@  discard block
 block discarded – undo
631 631
 	 * @param  string $context View or edit context.
632 632
 	 * @return array
633 633
 	 */
634
-	public function get_allowed_items( $context = 'view' ) {
635
-		return $this->get_items( $context );
634
+	public function get_allowed_items($context = 'view') {
635
+		return $this->get_items($context);
636 636
 	}
637 637
 
638 638
 	/**
@@ -642,8 +642,8 @@  discard block
 block discarded – undo
642 642
 	 * @param  string $context View or edit context.
643 643
 	 * @return array
644 644
 	 */
645
-	public function get_excluded_items( $context = 'view' ) {
646
-		return wpinv_parse_list( $this->get_prop( 'excluded_items', $context ) );
645
+	public function get_excluded_items($context = 'view') {
646
+		return wpinv_parse_list($this->get_prop('excluded_items', $context));
647 647
 	}
648 648
 
649 649
 	/**
@@ -653,8 +653,8 @@  discard block
 block discarded – undo
653 653
 	 * @param  string $context View or edit context.
654 654
 	 * @return int|string|bool
655 655
 	 */
656
-	public function get_is_recurring( $context = 'view' ) {
657
-		return $this->get_prop( 'is_recurring', $context );
656
+	public function get_is_recurring($context = 'view') {
657
+		return $this->get_prop('is_recurring', $context);
658 658
 	}
659 659
 
660 660
 	/**
@@ -664,9 +664,9 @@  discard block
 block discarded – undo
664 664
 	 * @param  string $context View or edit context.
665 665
 	 * @return float
666 666
 	 */
667
-	public function get_min_total( $context = 'view' ) {
668
-		$minimum = $this->get_prop( 'min_total', $context );
669
-		return empty( $minimum ) ? null : $minimum;
667
+	public function get_min_total($context = 'view') {
668
+		$minimum = $this->get_prop('min_total', $context);
669
+		return empty($minimum) ? null : $minimum;
670 670
 	}
671 671
 
672 672
 	/**
@@ -676,8 +676,8 @@  discard block
 block discarded – undo
676 676
 	 * @param  string $context View or edit context.
677 677
 	 * @return float
678 678
 	 */
679
-	public function get_minimum_total( $context = 'view' ) {
680
-		return $this->get_min_total( $context );
679
+	public function get_minimum_total($context = 'view') {
680
+		return $this->get_min_total($context);
681 681
 	}
682 682
 
683 683
 	/**
@@ -687,9 +687,9 @@  discard block
 block discarded – undo
687 687
 	 * @param  string $context View or edit context.
688 688
 	 * @return float
689 689
 	 */
690
-	public function get_max_total( $context = 'view' ) {
691
-		$maximum = $this->get_prop( 'max_total', $context );
692
-		return empty( $maximum ) ? null : $maximum;
690
+	public function get_max_total($context = 'view') {
691
+		$maximum = $this->get_prop('max_total', $context);
692
+		return empty($maximum) ? null : $maximum;
693 693
 	}
694 694
 
695 695
 	/**
@@ -699,8 +699,8 @@  discard block
 block discarded – undo
699 699
 	 * @param  string $context View or edit context.
700 700
 	 * @return float
701 701
 	 */
702
-	public function get_maximum_total( $context = 'view' ) {
703
-		return $this->get_max_total( $context );
702
+	public function get_maximum_total($context = 'view') {
703
+		return $this->get_max_total($context);
704 704
 	}
705 705
 
706 706
 	/**
@@ -713,8 +713,8 @@  discard block
 block discarded – undo
713 713
 	 * @param  string $context View or edit context.
714 714
 	 * @return mixed Value of the given discount property (if set).
715 715
 	 */
716
-	public function get( $key, $context = 'view' ) {
717
-        return $this->get_prop( $key, $context );
716
+	public function get($key, $context = 'view') {
717
+        return $this->get_prop($key, $context);
718 718
 	}
719 719
 
720 720
 	/*
@@ -734,10 +734,10 @@  discard block
 block discarded – undo
734 734
 	 * @param  string $status New status.
735 735
 	 * @return array details of change.
736 736
 	 */
737
-	public function set_status( $status ) {
737
+	public function set_status($status) {
738 738
         $old_status = $this->get_status();
739 739
 
740
-        $this->set_prop( 'status', $status );
740
+        $this->set_prop('status', $status);
741 741
 
742 742
 		return array(
743 743
 			'from' => $old_status,
@@ -750,8 +750,8 @@  discard block
 block discarded – undo
750 750
 	 *
751 751
 	 * @since 1.0.19
752 752
 	 */
753
-	public function set_version( $value ) {
754
-		$this->set_prop( 'version', $value );
753
+	public function set_version($value) {
754
+		$this->set_prop('version', $value);
755 755
     }
756 756
 
757 757
     /**
@@ -761,11 +761,11 @@  discard block
 block discarded – undo
761 761
 	 * @param string $value Value to set.
762 762
      * @return bool Whether or not the date was set.
763 763
 	 */
764
-	public function set_date_created( $value ) {
765
-        $date = strtotime( $value );
764
+	public function set_date_created($value) {
765
+        $date = strtotime($value);
766 766
 
767
-        if ( $date ) {
768
-            $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) );
767
+        if ($date) {
768
+            $this->set_prop('date_created', date('Y-m-d H:i:s', $date));
769 769
             return true;
770 770
         }
771 771
 
@@ -780,11 +780,11 @@  discard block
 block discarded – undo
780 780
 	 * @param string $value Value to set.
781 781
      * @return bool Whether or not the date was set.
782 782
 	 */
783
-	public function set_date_modified( $value ) {
784
-        $date = strtotime( $value );
783
+	public function set_date_modified($value) {
784
+        $date = strtotime($value);
785 785
 
786
-        if ( $date ) {
787
-            $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) );
786
+        if ($date) {
787
+            $this->set_prop('date_modified', date('Y-m-d H:i:s', $date));
788 788
             return true;
789 789
         }
790 790
 
@@ -798,9 +798,9 @@  discard block
 block discarded – undo
798 798
 	 * @since 1.0.19
799 799
 	 * @param  string $value New name.
800 800
 	 */
801
-	public function set_name( $value ) {
802
-        $name = sanitize_text_field( $value );
803
-		$this->set_prop( 'name', $name );
801
+	public function set_name($value) {
802
+        $name = sanitize_text_field($value);
803
+		$this->set_prop('name', $name);
804 804
     }
805 805
 
806 806
     /**
@@ -809,8 +809,8 @@  discard block
 block discarded – undo
809 809
 	 * @since 1.0.19
810 810
 	 * @param  string $value New name.
811 811
 	 */
812
-	public function set_title( $value ) {
813
-		$this->set_name( $value );
812
+	public function set_title($value) {
813
+		$this->set_name($value);
814 814
     }
815 815
 
816 816
     /**
@@ -819,9 +819,9 @@  discard block
 block discarded – undo
819 819
 	 * @since 1.0.19
820 820
 	 * @param  string $value New description.
821 821
 	 */
822
-	public function set_description( $value ) {
823
-        $description = wp_kses_post( $value );
824
-		return $this->set_prop( 'description', $description );
822
+	public function set_description($value) {
823
+        $description = wp_kses_post($value);
824
+		return $this->set_prop('description', $description);
825 825
     }
826 826
 
827 827
     /**
@@ -830,8 +830,8 @@  discard block
 block discarded – undo
830 830
 	 * @since 1.0.19
831 831
 	 * @param  string $value New description.
832 832
 	 */
833
-	public function set_excerpt( $value ) {
834
-		$this->set_description( $value );
833
+	public function set_excerpt($value) {
834
+		$this->set_description($value);
835 835
     }
836 836
 
837 837
     /**
@@ -840,8 +840,8 @@  discard block
 block discarded – undo
840 840
 	 * @since 1.0.19
841 841
 	 * @param  string $value New description.
842 842
 	 */
843
-	public function set_summary( $value ) {
844
-		$this->set_description( $value );
843
+	public function set_summary($value) {
844
+		$this->set_description($value);
845 845
     }
846 846
 
847 847
     /**
@@ -850,8 +850,8 @@  discard block
 block discarded – undo
850 850
 	 * @since 1.0.19
851 851
 	 * @param  int $value New author.
852 852
 	 */
853
-	public function set_author( $value ) {
854
-		$this->set_prop( 'author', (int) $value );
853
+	public function set_author($value) {
854
+		$this->set_prop('author', (int) $value);
855 855
 	}
856 856
 	
857 857
 	/**
@@ -860,9 +860,9 @@  discard block
 block discarded – undo
860 860
 	 * @since 1.0.19
861 861
 	 * @param string $value New discount code.
862 862
 	 */
863
-	public function set_code( $value ) {
864
-		$code = sanitize_text_field( $value );
865
-		$this->set_prop( 'code', $code );
863
+	public function set_code($value) {
864
+		$code = sanitize_text_field($value);
865
+		$this->set_prop('code', $code);
866 866
 	}
867 867
 	
868 868
 	/**
@@ -871,8 +871,8 @@  discard block
 block discarded – undo
871 871
 	 * @since 1.0.19
872 872
 	 * @param string $value New discount code.
873 873
 	 */
874
-	public function set_coupon_code( $value ) {
875
-		$this->set_code( $value );
874
+	public function set_coupon_code($value) {
875
+		$this->set_code($value);
876 876
 	}
877 877
 	
878 878
 	/**
@@ -881,8 +881,8 @@  discard block
 block discarded – undo
881 881
 	 * @since 1.0.19
882 882
 	 * @param string $value New discount code.
883 883
 	 */
884
-	public function set_discount_code( $value ) {
885
-		$this->set_code( $value );
884
+	public function set_discount_code($value) {
885
+		$this->set_code($value);
886 886
 	}
887 887
 	
888 888
 	/**
@@ -891,9 +891,9 @@  discard block
 block discarded – undo
891 891
 	 * @since 1.0.19
892 892
 	 * @param float $value New discount code.
893 893
 	 */
894
-	public function set_amount( $value ) {
895
-		$amount = floatval( wpinv_sanitize_amount( $value ) );
896
-		$this->set_prop( 'amount', $amount );
894
+	public function set_amount($value) {
895
+		$amount = floatval(wpinv_sanitize_amount($value));
896
+		$this->set_prop('amount', $amount);
897 897
 	}
898 898
 
899 899
 	/**
@@ -902,15 +902,15 @@  discard block
 block discarded – undo
902 902
 	 * @since 1.0.19
903 903
 	 * @param float $value New start date.
904 904
 	 */
905
-	public function set_start( $value ) {
906
-		$date = strtotime( $value );
905
+	public function set_start($value) {
906
+		$date = strtotime($value);
907 907
 
908
-        if ( $date ) {
909
-            $this->set_prop( 'start', date( 'Y-m-d H:i', $date ) );
908
+        if ($date) {
909
+            $this->set_prop('start', date('Y-m-d H:i', $date));
910 910
             return true;
911 911
 		}
912 912
 		
913
-		$this->set_prop( 'start', '' );
913
+		$this->set_prop('start', '');
914 914
 
915 915
         return false;
916 916
 	}
@@ -921,8 +921,8 @@  discard block
 block discarded – undo
921 921
 	 * @since 1.0.19
922 922
 	 * @param string $value New start date.
923 923
 	 */
924
-	public function set_start_date( $value ) {
925
-		$this->set_start( $value );
924
+	public function set_start_date($value) {
925
+		$this->set_start($value);
926 926
 	}
927 927
 
928 928
 	/**
@@ -931,15 +931,15 @@  discard block
 block discarded – undo
931 931
 	 * @since 1.0.19
932 932
 	 * @param float $value New expiration date.
933 933
 	 */
934
-	public function set_expiration( $value ) {
935
-		$date = strtotime( $value );
934
+	public function set_expiration($value) {
935
+		$date = strtotime($value);
936 936
 
937
-        if ( $date ) {
938
-            $this->set_prop( 'expiration', date( 'Y-m-d H:i', $date ) );
937
+        if ($date) {
938
+            $this->set_prop('expiration', date('Y-m-d H:i', $date));
939 939
             return true;
940 940
         }
941 941
 
942
-		$this->set_prop( 'expiration', '' );
942
+		$this->set_prop('expiration', '');
943 943
         return false;
944 944
 	}
945 945
 
@@ -949,8 +949,8 @@  discard block
 block discarded – undo
949 949
 	 * @since 1.0.19
950 950
 	 * @param string $value New expiration date.
951 951
 	 */
952
-	public function set_expiration_date( $value ) {
953
-		$this->set_expiration( $value );
952
+	public function set_expiration_date($value) {
953
+		$this->set_expiration($value);
954 954
 	}
955 955
 
956 956
 	/**
@@ -959,8 +959,8 @@  discard block
 block discarded – undo
959 959
 	 * @since 1.0.19
960 960
 	 * @param string $value New expiration date.
961 961
 	 */
962
-	public function set_end_date( $value ) {
963
-		$this->set_expiration( $value );
962
+	public function set_end_date($value) {
963
+		$this->set_expiration($value);
964 964
 	}
965 965
 
966 966
 	/**
@@ -969,9 +969,9 @@  discard block
 block discarded – undo
969 969
 	 * @since 1.0.19
970 970
 	 * @param string $value New discount type.
971 971
 	 */
972
-	public function set_type( $value ) {
973
-		if ( $value && array_key_exists( sanitize_text_field( $value ), wpinv_get_discount_types() ) ) {
974
-			$this->set_prop( 'type', sanitize_text_field( $value ) );
972
+	public function set_type($value) {
973
+		if ($value && array_key_exists(sanitize_text_field($value), wpinv_get_discount_types())) {
974
+			$this->set_prop('type', sanitize_text_field($value));
975 975
 		}
976 976
 	}
977 977
 
@@ -981,15 +981,15 @@  discard block
 block discarded – undo
981 981
 	 * @since 1.0.19
982 982
 	 * @param int $value usage count.
983 983
 	 */
984
-	public function set_uses( $value ) {
984
+	public function set_uses($value) {
985 985
 
986 986
 		$value = (int) $value;
987 987
 
988
-		if ( $value < 0 ) {
988
+		if ($value < 0) {
989 989
 			$value = 0;
990 990
 		}
991 991
 
992
-		$this->set_prop( 'uses', (int) $value );
992
+		$this->set_prop('uses', (int) $value);
993 993
 	}
994 994
 
995 995
 	/**
@@ -998,8 +998,8 @@  discard block
 block discarded – undo
998 998
 	 * @since 1.0.19
999 999
 	 * @param int $value maximum usage count.
1000 1000
 	 */
1001
-	public function set_max_uses( $value ) {
1002
-		$this->set_prop( 'max_uses', absint( $value ) );
1001
+	public function set_max_uses($value) {
1002
+		$this->set_prop('max_uses', absint($value));
1003 1003
 	}
1004 1004
 
1005 1005
 	/**
@@ -1008,8 +1008,8 @@  discard block
 block discarded – undo
1008 1008
 	 * @since 1.0.19
1009 1009
 	 * @param int|bool $value is single use.
1010 1010
 	 */
1011
-	public function set_is_single_use( $value ) {
1012
-		$this->set_prop( 'is_single_use', (bool) $value );
1011
+	public function set_is_single_use($value) {
1012
+		$this->set_prop('is_single_use', (bool) $value);
1013 1013
 	}
1014 1014
 
1015 1015
 	/**
@@ -1018,8 +1018,8 @@  discard block
 block discarded – undo
1018 1018
 	 * @since 1.0.19
1019 1019
 	 * @param array $value items.
1020 1020
 	 */
1021
-	public function set_items( $value ) {
1022
-		$this->set_prop( 'items', wpinv_parse_list( $value ) );
1021
+	public function set_items($value) {
1022
+		$this->set_prop('items', wpinv_parse_list($value));
1023 1023
 	}
1024 1024
 
1025 1025
 	/**
@@ -1028,8 +1028,8 @@  discard block
 block discarded – undo
1028 1028
 	 * @since 1.0.19
1029 1029
 	 * @param array $value items.
1030 1030
 	 */
1031
-	public function set_allowed_items( $value ) {
1032
-		$this->set_items( $value );
1031
+	public function set_allowed_items($value) {
1032
+		$this->set_items($value);
1033 1033
 	}
1034 1034
 
1035 1035
 	/**
@@ -1038,8 +1038,8 @@  discard block
 block discarded – undo
1038 1038
 	 * @since 1.0.19
1039 1039
 	 * @param array $value items.
1040 1040
 	 */
1041
-	public function set_excluded_items( $value ) {
1042
-		$this->set_prop( 'excluded_items', wpinv_parse_list( $value ) );
1041
+	public function set_excluded_items($value) {
1042
+		$this->set_prop('excluded_items', wpinv_parse_list($value));
1043 1043
 	}
1044 1044
 
1045 1045
 	/**
@@ -1048,8 +1048,8 @@  discard block
 block discarded – undo
1048 1048
 	 * @since 1.0.19
1049 1049
 	 * @param int|bool $value is recurring.
1050 1050
 	 */
1051
-	public function set_is_recurring( $value ) {
1052
-		$this->set_prop( 'is_recurring', (bool) $value );
1051
+	public function set_is_recurring($value) {
1052
+		$this->set_prop('is_recurring', (bool) $value);
1053 1053
 	}
1054 1054
 
1055 1055
 	/**
@@ -1058,8 +1058,8 @@  discard block
 block discarded – undo
1058 1058
 	 * @since 1.0.19
1059 1059
 	 * @param float $value minimum total.
1060 1060
 	 */
1061
-	public function set_min_total( $value ) {
1062
-		$this->set_prop( 'min_total', (float) wpinv_sanitize_amount( $value ) );
1061
+	public function set_min_total($value) {
1062
+		$this->set_prop('min_total', (float) wpinv_sanitize_amount($value));
1063 1063
 	}
1064 1064
 
1065 1065
 	/**
@@ -1068,8 +1068,8 @@  discard block
 block discarded – undo
1068 1068
 	 * @since 1.0.19
1069 1069
 	 * @param float $value minimum total.
1070 1070
 	 */
1071
-	public function set_minimum_total( $value ) {
1072
-		$this->set_min_total( $value );
1071
+	public function set_minimum_total($value) {
1072
+		$this->set_min_total($value);
1073 1073
 	}
1074 1074
 
1075 1075
 	/**
@@ -1078,8 +1078,8 @@  discard block
 block discarded – undo
1078 1078
 	 * @since 1.0.19
1079 1079
 	 * @param float $value maximum total.
1080 1080
 	 */
1081
-	public function set_max_total( $value ) {
1082
-		$this->set_prop( 'max_total', (float) wpinv_sanitize_amount( $value ) );
1081
+	public function set_max_total($value) {
1082
+		$this->set_prop('max_total', (float) wpinv_sanitize_amount($value));
1083 1083
 	}
1084 1084
 
1085 1085
 	/**
@@ -1088,23 +1088,23 @@  discard block
 block discarded – undo
1088 1088
 	 * @since 1.0.19
1089 1089
 	 * @param float $value maximum total.
1090 1090
 	 */
1091
-	public function set_maximum_total( $value ) {
1092
-		$this->set_max_total( $value );
1091
+	public function set_maximum_total($value) {
1092
+		$this->set_max_total($value);
1093 1093
 	}
1094 1094
 
1095 1095
 	/**
1096 1096
 	 * @deprecated
1097 1097
 	 */
1098
-	public function refresh(){}
1098
+	public function refresh() {}
1099 1099
 
1100 1100
 	/**
1101 1101
 	 * @deprecated
1102 1102
 	 *
1103 1103
 	 */
1104
-	public function update_status( $status = 'publish' ){
1104
+	public function update_status($status = 'publish') {
1105 1105
 
1106
-		if ( $this->exists() && $this->get_status() != $status ) {
1107
-			$this->set_status( $status );
1106
+		if ($this->exists() && $this->get_status() != $status) {
1107
+			$this->set_status($status);
1108 1108
 			$this->save();
1109 1109
 		}
1110 1110
 
@@ -1124,9 +1124,9 @@  discard block
 block discarded – undo
1124 1124
 	 *
1125 1125
 	 * @since 1.0.15
1126 1126
 	 */
1127
-	public function exists(){
1127
+	public function exists() {
1128 1128
 		$id = $this->get_id();
1129
-		return ! empty( $id );
1129
+		return !empty($id);
1130 1130
 	}
1131 1131
 
1132 1132
 	/**
@@ -1137,7 +1137,7 @@  discard block
 block discarded – undo
1137 1137
 	 * @since 1.0.15
1138 1138
 	 * @return bool
1139 1139
 	 */
1140
-	public function is_type( $type ) {
1140
+	public function is_type($type) {
1141 1141
 		return $this->get_type() == $type;
1142 1142
 	}
1143 1143
 
@@ -1159,7 +1159,7 @@  discard block
 block discarded – undo
1159 1159
 	 */
1160 1160
 	public function has_limit() {
1161 1161
 		$limit = $this->get_max_uses();
1162
-		return ! empty( $limit );
1162
+		return !empty($limit);
1163 1163
 	}
1164 1164
 
1165 1165
 	/**
@@ -1180,13 +1180,13 @@  discard block
 block discarded – undo
1180 1180
 	 */
1181 1181
 	public function has_exceeded_limit() {
1182 1182
 
1183
-		if ( ! $this->has_limit() || ! $this->has_uses() ) {
1184
-			$exceeded = false ;
1183
+		if (!$this->has_limit() || !$this->has_uses()) {
1184
+			$exceeded = false;
1185 1185
 		} else {
1186
-			$exceeded = ! ( (int) $this->get_max_uses() < $this->get_uses() );
1186
+			$exceeded = !((int) $this->get_max_uses() < $this->get_uses());
1187 1187
 		}
1188 1188
 
1189
-		return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->get_id(), $this, $this->get_code() );
1189
+		return apply_filters('wpinv_is_discount_maxed_out', $exceeded, $this->get_id(), $this, $this->get_code());
1190 1190
 	}
1191 1191
 
1192 1192
 	/**
@@ -1197,7 +1197,7 @@  discard block
 block discarded – undo
1197 1197
 	 */
1198 1198
 	public function has_expiration_date() {
1199 1199
 		$date = $this->get_expiration_date();
1200
-		return ! empty( $date );
1200
+		return !empty($date);
1201 1201
 	}
1202 1202
 
1203 1203
 	/**
@@ -1207,8 +1207,8 @@  discard block
 block discarded – undo
1207 1207
 	 * @return bool
1208 1208
 	 */
1209 1209
 	public function is_expired() {
1210
-		$expired = $this->has_expiration_date() ? current_time( 'timestamp' ) > strtotime( $this->get_expiration_date() ) : false;
1211
-		return apply_filters( 'wpinv_is_discount_expired', $expired, $this->get_id(), $this, $this->get_code() );
1210
+		$expired = $this->has_expiration_date() ? current_time('timestamp') > strtotime($this->get_expiration_date()) : false;
1211
+		return apply_filters('wpinv_is_discount_expired', $expired, $this->get_id(), $this, $this->get_code());
1212 1212
 	}
1213 1213
 
1214 1214
 	/**
@@ -1219,7 +1219,7 @@  discard block
 block discarded – undo
1219 1219
 	 */
1220 1220
 	public function has_start_date() {
1221 1221
 		$date = $this->get_start_date();
1222
-		return ! empty( $date );
1222
+		return !empty($date);
1223 1223
 	}
1224 1224
 
1225 1225
 	/**
@@ -1229,8 +1229,8 @@  discard block
 block discarded – undo
1229 1229
 	 * @return bool
1230 1230
 	 */
1231 1231
 	public function has_started() {
1232
-		$started = $this->has_start_date() ? true : current_time( 'timestamp' ) > strtotime( $this->get_start_date() );
1233
-		return apply_filters( 'wpinv_is_discount_started', $started, $this->get_id(), $this, $this->get_code() );
1232
+		$started = $this->has_start_date() ? true : current_time('timestamp') > strtotime($this->get_start_date());
1233
+		return apply_filters('wpinv_is_discount_started', $started, $this->get_id(), $this, $this->get_code());
1234 1234
 	}
1235 1235
 
1236 1236
 	/**
@@ -1241,7 +1241,7 @@  discard block
 block discarded – undo
1241 1241
 	 */
1242 1242
 	public function has_allowed_items() {
1243 1243
 		$allowed_items = $this->get_allowed_items();
1244
-		return ! empty( $allowed_items );
1244
+		return !empty($allowed_items);
1245 1245
 	}
1246 1246
 
1247 1247
 	/**
@@ -1252,7 +1252,7 @@  discard block
 block discarded – undo
1252 1252
 	 */
1253 1253
 	public function has_excluded_items() {
1254 1254
 		$excluded_items = $this->get_excluded_items();
1255
-		return ! empty( $excluded_items );
1255
+		return !empty($excluded_items);
1256 1256
 	}
1257 1257
 
1258 1258
 	/**
@@ -1262,17 +1262,17 @@  discard block
 block discarded – undo
1262 1262
 	 * @since 1.0.15
1263 1263
 	 * @return boolean
1264 1264
 	 */
1265
-	public function is_valid_for_items( $item_ids ) {
1265
+	public function is_valid_for_items($item_ids) {
1266 1266
 
1267
-		$item_ids = wp_parse_id_list( $item_ids );
1268
-		$included = array_intersect( $item_ids, $this->get_allowed_items() );
1269
-		$excluded = array_intersect( $item_ids, $this->get_excluded_items() );
1267
+		$item_ids = wp_parse_id_list($item_ids);
1268
+		$included = array_intersect($item_ids, $this->get_allowed_items());
1269
+		$excluded = array_intersect($item_ids, $this->get_excluded_items());
1270 1270
 
1271
-		if ( $this->has_excluded_items() && ! empty( $excluded ) ) {
1271
+		if ($this->has_excluded_items() && !empty($excluded)) {
1272 1272
 			return false;
1273 1273
 		}
1274 1274
 
1275
-		if ( $this->has_allowed_items() && empty( $included ) ) {
1275
+		if ($this->has_allowed_items() && empty($included)) {
1276 1276
 			return false;
1277 1277
 		}
1278 1278
 
@@ -1286,8 +1286,8 @@  discard block
 block discarded – undo
1286 1286
 	 * @since 1.0.15
1287 1287
 	 * @return boolean
1288 1288
 	 */
1289
-	public function is_valid_for_amount( $amount ) {
1290
-		return $this->is_minimum_amount_met( $amount ) && $this->is_maximum_amount_met( $amount );
1289
+	public function is_valid_for_amount($amount) {
1290
+		return $this->is_minimum_amount_met($amount) && $this->is_maximum_amount_met($amount);
1291 1291
 	}
1292 1292
 
1293 1293
 	/**
@@ -1298,7 +1298,7 @@  discard block
 block discarded – undo
1298 1298
 	 */
1299 1299
 	public function has_minimum_amount() {
1300 1300
 		$minimum = $this->get_minimum_total();
1301
-		return ! empty( $minimum );
1301
+		return !empty($minimum);
1302 1302
 	}
1303 1303
 
1304 1304
 	/**
@@ -1308,10 +1308,10 @@  discard block
 block discarded – undo
1308 1308
 	 * @since 1.0.15
1309 1309
 	 * @return boolean
1310 1310
 	 */
1311
-	public function is_minimum_amount_met( $amount ) {
1312
-		$amount = floatval( wpinv_sanitize_amount( $amount ) );
1313
-		$min_met= ! ( $this->has_minimum_amount() && $amount < floatval( wpinv_sanitize_amount( $this->get_minimum_total() ) ) );
1314
-		return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->get_id(), $this, $this->get_code(), $amount );
1311
+	public function is_minimum_amount_met($amount) {
1312
+		$amount = floatval(wpinv_sanitize_amount($amount));
1313
+		$min_met = !($this->has_minimum_amount() && $amount < floatval(wpinv_sanitize_amount($this->get_minimum_total())));
1314
+		return apply_filters('wpinv_is_discount_min_met', $min_met, $this->get_id(), $this, $this->get_code(), $amount);
1315 1315
 	}
1316 1316
 
1317 1317
 	/**
@@ -1322,7 +1322,7 @@  discard block
 block discarded – undo
1322 1322
 	 */
1323 1323
 	public function has_maximum_amount() {
1324 1324
 		$maximum = $this->get_maximum_total();
1325
-		return ! empty( $maximum );
1325
+		return !empty($maximum);
1326 1326
 	}
1327 1327
 
1328 1328
 	/**
@@ -1332,10 +1332,10 @@  discard block
 block discarded – undo
1332 1332
 	 * @since 1.0.15
1333 1333
 	 * @return boolean
1334 1334
 	 */
1335
-	public function is_maximum_amount_met( $amount ) {
1336
-		$amount = floatval( wpinv_sanitize_amount( $amount ) );
1337
-		$max_met= ! ( $this->has_maximum_amount() && $amount > floatval( wpinv_sanitize_amount( $this->get_maximum_total() ) ) );
1338
-		return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->get_id(), $this, $this->get_code(), $amount );
1335
+	public function is_maximum_amount_met($amount) {
1336
+		$amount = floatval(wpinv_sanitize_amount($amount));
1337
+		$max_met = !($this->has_maximum_amount() && $amount > floatval(wpinv_sanitize_amount($this->get_maximum_total())));
1338
+		return apply_filters('wpinv_is_discount_max_met', $max_met, $this->get_id(), $this, $this->get_code(), $amount);
1339 1339
 	}
1340 1340
 
1341 1341
 	/**
@@ -1346,7 +1346,7 @@  discard block
 block discarded – undo
1346 1346
 	 */
1347 1347
 	public function is_recurring() {
1348 1348
 		$recurring = $this->get_is_recurring();
1349
-		return ! empty( $recurring );
1349
+		return !empty($recurring);
1350 1350
 	}
1351 1351
 
1352 1352
 	/**
@@ -1357,7 +1357,7 @@  discard block
 block discarded – undo
1357 1357
 	 */
1358 1358
 	public function is_single_use() {
1359 1359
 		$usage = $this->get_is_single_use();
1360
-		return ! empty( $usage );
1360
+		return !empty($usage);
1361 1361
 	}
1362 1362
 
1363 1363
 	/**
@@ -1367,37 +1367,37 @@  discard block
 block discarded – undo
1367 1367
 	 * @since 1.0.15
1368 1368
 	 * @return boolean
1369 1369
 	 */
1370
-	public function is_valid_for_user( $user ) {
1370
+	public function is_valid_for_user($user) {
1371 1371
 
1372 1372
 		// Ensure that the discount is single use.
1373
-		if ( empty( $user ) || ! $this->is_single_use() ) {
1373
+		if (empty($user) || !$this->is_single_use()) {
1374 1374
 			return true;
1375 1375
 		}
1376 1376
 
1377 1377
 		// Prepare the user id.
1378 1378
 		$user_id = 0;
1379
-        if ( is_numeric( $user ) ) {
1380
-            $user_id = absint( $user );
1381
-        } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) {
1379
+        if (is_numeric($user)) {
1380
+            $user_id = absint($user);
1381
+        } else if (is_email($user) && $user_data = get_user_by('email', $user)) {
1382 1382
             $user_id = $user_data->ID;
1383
-        } else if ( $user_data = get_user_by( 'login', $user ) ) {
1383
+        } else if ($user_data = get_user_by('login', $user)) {
1384 1384
             $user_id = $user_data->ID;
1385 1385
         }
1386 1386
 
1387 1387
 		// Ensure that we have a user.
1388
-		if ( empty( $user_id ) ) {
1388
+		if (empty($user_id)) {
1389 1389
 			return true;
1390 1390
 		}
1391 1391
 
1392 1392
 		// Get all payments with matching user id.
1393
-        $payments = wpinv_get_invoices( array( 'user' => $user_id, 'limit' => false, 'paginate' => false ) );
1394
-		$code     = strtolower( $this->get_code() );
1393
+        $payments = wpinv_get_invoices(array('user' => $user_id, 'limit' => false, 'paginate' => false));
1394
+		$code = strtolower($this->get_code());
1395 1395
 
1396 1396
 		// For each payment...
1397
-		foreach ( $payments as $payment ) {
1397
+		foreach ($payments as $payment) {
1398 1398
 
1399 1399
 			// Only check for paid invoices.
1400
-			if ( $payment->is_paid() && strtolower( $payment->get_discount_code() ) == $code ) {
1400
+			if ($payment->is_paid() && strtolower($payment->get_discount_code()) == $code) {
1401 1401
 				return false;
1402 1402
 			}
1403 1403
 
@@ -1423,24 +1423,24 @@  discard block
 block discarded – undo
1423 1423
 	 * @param int $by The number of usages to increas by.
1424 1424
 	 * @return int
1425 1425
 	 */
1426
-	public function increase_usage( $by = 1 ) {
1426
+	public function increase_usage($by = 1) {
1427 1427
 
1428 1428
 		// Abort if zero.
1429
-		if ( empty( $by ) ) {
1429
+		if (empty($by)) {
1430 1430
 			return;
1431 1431
 		}
1432 1432
 
1433 1433
 		// Increase the usage.
1434
-		$this->set_uses( $this->get_uses() + (int) $by );
1434
+		$this->set_uses($this->get_uses() + (int) $by);
1435 1435
 
1436 1436
 		// Save the discount.
1437 1437
 		$this->save();
1438 1438
 
1439 1439
 		// Fire relevant hooks.
1440
-		if( (int) $by > 0 ) {
1441
-			do_action( 'wpinv_discount_increase_use_count', $this->get_uses(), $this->get_id(), $this->get_code(),  absint( $by ) );
1440
+		if ((int) $by > 0) {
1441
+			do_action('wpinv_discount_increase_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint($by));
1442 1442
 		} else {
1443
-			do_action( 'wpinv_discount_decrease_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint( $by ) );
1443
+			do_action('wpinv_discount_decrease_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint($by));
1444 1444
 		}
1445 1445
 
1446 1446
 		// Return the number of times the discount has been used.
@@ -1464,7 +1464,7 @@  discard block
 block discarded – undo
1464 1464
 	 * @param float $amount
1465 1465
 	 * @return float
1466 1466
 	 */
1467
-	public function get_discounted_amount( $amount ) {
1467
+	public function get_discounted_amount($amount) {
1468 1468
 
1469 1469
 		// Convert amount to float.
1470 1470
 		$amount = (float) $amount;
@@ -1472,29 +1472,29 @@  discard block
 block discarded – undo
1472 1472
 		// Get discount amount.
1473 1473
 		$discount_amount = $this->get_amount();
1474 1474
 
1475
-		if ( empty( $discount_amount ) ) {
1475
+		if (empty($discount_amount)) {
1476 1476
 			return 0;
1477 1477
 		}
1478 1478
 
1479 1479
 		// Format the amount.
1480
-		$discount_amount = floatval( wpinv_sanitize_amount( $discount_amount ) );
1480
+		$discount_amount = floatval(wpinv_sanitize_amount($discount_amount));
1481 1481
 		
1482 1482
 		// If this is a percentage discount.
1483
-		if ( $this->is_type( 'percent' ) ) {
1484
-            $discount_amount = $amount * ( $discount_amount / 100 );
1483
+		if ($this->is_type('percent')) {
1484
+            $discount_amount = $amount * ($discount_amount / 100);
1485 1485
 		}
1486 1486
 
1487 1487
 		// Discount can not be less than zero...
1488
-		if ( $discount_amount < 0 ) {
1488
+		if ($discount_amount < 0) {
1489 1489
 			$discount_amount = 0;
1490 1490
 		}
1491 1491
 
1492 1492
 		// ... or more than the amount.
1493
-		if ( $discount_amount > $amount ) {
1493
+		if ($discount_amount > $amount) {
1494 1494
 			$discount_amount = $amount;
1495 1495
 		}
1496 1496
 
1497
-		return apply_filters( 'wpinv_discount_total_discount_amount', $discount_amount, $amount, $this );
1497
+		return apply_filters('wpinv_discount_total_discount_amount', $discount_amount, $amount, $this);
1498 1498
 	}
1499 1499
 
1500 1500
 }
Please login to merge, or discard this patch.
includes/wpinv-item-functions.php 1 patch
Spacing   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
  
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Retrieves an item by it's ID.
@@ -14,9 +14,9 @@  discard block
 block discarded – undo
14 14
  * @param int the item ID to retrieve.
15 15
  * @return WPInv_Item|false
16 16
  */
17
-function wpinv_get_item_by_id( $id ) {
18
-    $item = wpinv_get_item( $id );
19
-    return empty( $item ) || $id != $item->get_id() ? false : $item;
17
+function wpinv_get_item_by_id($id) {
18
+    $item = wpinv_get_item($id);
19
+    return empty($item) || $id != $item->get_id() ? false : $item;
20 20
 }
21 21
 
22 22
 /**
@@ -24,14 +24,14 @@  discard block
 block discarded – undo
24 24
  * 
25 25
  * @return WPInv_Item|false
26 26
  */
27
-function wpinv_get_item_by( $field = '', $value = '', $type = '' ) {
27
+function wpinv_get_item_by($field = '', $value = '', $type = '') {
28 28
 
29
-    if ( 'id' == strtolower( $field ) ) {
30
-        return wpinv_get_item_by_id( $field );
29
+    if ('id' == strtolower($field)) {
30
+        return wpinv_get_item_by_id($field);
31 31
     }
32 32
 
33
-    $id = WPInv_Item::get_item_id_by_field( $value, strtolower( $field ), $type );
34
-    return $id ? wpinv_get_item( $id ) : false;
33
+    $id = WPInv_Item::get_item_id_by_field($value, strtolower($field), $type);
34
+    return $id ? wpinv_get_item($id) : false;
35 35
 
36 36
 }
37 37
 
@@ -41,22 +41,22 @@  discard block
 block discarded – undo
41 41
  * @param int|WPInv_Item the item to retrieve.
42 42
  * @return WPInv_Item|false
43 43
  */
44
-function wpinv_get_item( $item = 0 ) {
44
+function wpinv_get_item($item = 0) {
45 45
     
46
-    if ( empty( $item ) ) {
46
+    if (empty($item)) {
47 47
         return false;
48 48
     }
49 49
 
50
-    $item = new WPInv_Item( $item );
50
+    $item = new WPInv_Item($item);
51 51
     return $item->get_id() ? $item : false;
52 52
 
53 53
 }
54 54
 
55
-function wpinv_get_all_items( $args = array() ) {
55
+function wpinv_get_all_items($args = array()) {
56 56
 
57
-    $args = wp_parse_args( $args, array(
58
-        'status'         => array( 'publish' ),
59
-        'limit'          => get_option( 'posts_per_page' ),
57
+    $args = wp_parse_args($args, array(
58
+        'status'         => array('publish'),
59
+        'limit'          => get_option('posts_per_page'),
60 60
         'page'           => 1,
61 61
         'exclude'        => array(),
62 62
         'orderby'        => 'date',
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
         'meta_query'     => array(),
66 66
         'return'         => 'objects',
67 67
         'paginate'       => false,
68
-    ) );
68
+    ));
69 69
 
70 70
     $wp_query_args = array(
71 71
         'post_type'      => 'wpi_item',
@@ -75,26 +75,26 @@  discard block
 block discarded – undo
75 75
         'fields'         => 'ids',
76 76
         'orderby'        => $args['orderby'],
77 77
         'order'          => $args['order'],
78
-        'paged'          => absint( $args['page'] ),
78
+        'paged'          => absint($args['page']),
79 79
     );
80 80
 
81
-    if ( ! empty( $args['exclude'] ) ) {
82
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
81
+    if (!empty($args['exclude'])) {
82
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
83 83
     }
84 84
 
85
-    if ( ! $args['paginate' ] ) {
85
+    if (!$args['paginate']) {
86 86
         $wp_query_args['no_found_rows'] = true;
87 87
     }
88 88
 
89
-    if ( ! empty( $args['search'] ) ) {
89
+    if (!empty($args['search'])) {
90 90
         $wp_query_args['s'] = $args['search'];
91 91
     }
92 92
 
93
-    if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) {
94
-        $types = wpinv_parse_list( $args['type'] );
93
+    if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) {
94
+        $types = wpinv_parse_list($args['type']);
95 95
         $wp_query_args['meta_query'][] = array(
96 96
             'key'     => '_wpinv_type',
97
-            'value'   => implode( ',', $types ),
97
+            'value'   => implode(',', $types),
98 98
             'compare' => 'IN',
99 99
         );
100 100
     }
@@ -102,17 +102,17 @@  discard block
 block discarded – undo
102 102
     $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args);
103 103
 
104 104
     // Get results.
105
-    $items = new WP_Query( $wp_query_args );
105
+    $items = new WP_Query($wp_query_args);
106 106
 
107
-    if ( 'objects' === $args['return'] ) {
108
-        $return = array_map( 'wpinv_get_item_by_id', $items->posts );
109
-    } elseif ( 'self' === $args['return'] ) {
107
+    if ('objects' === $args['return']) {
108
+        $return = array_map('wpinv_get_item_by_id', $items->posts);
109
+    } elseif ('self' === $args['return']) {
110 110
         return $items;
111 111
     } else {
112 112
         $return = $items->posts;
113 113
     }
114 114
 
115
-    if ( $args['paginate' ] ) {
115
+    if ($args['paginate']) {
116 116
         return (object) array(
117 117
             'items'      => $return,
118 118
             'total'         => $items->found_posts,
@@ -124,12 +124,12 @@  discard block
 block discarded – undo
124 124
 
125 125
 }
126 126
 
127
-function wpinv_is_free_item( $item_id = 0 ) {
128
-    if( empty( $item_id ) ) {
127
+function wpinv_is_free_item($item_id = 0) {
128
+    if (empty($item_id)) {
129 129
         return false;
130 130
     }
131 131
 
132
-    $item = new WPInv_Item( $item_id );
132
+    $item = new WPInv_Item($item_id);
133 133
     
134 134
     return $item->is_free();
135 135
 }
@@ -139,21 +139,21 @@  discard block
 block discarded – undo
139 139
  * 
140 140
  * @param WP_Post|WPInv_Item|Int $item The item to check for.
141 141
  */
142
-function wpinv_item_is_editable( $item = 0 ) {
142
+function wpinv_item_is_editable($item = 0) {
143 143
 
144 144
     // Fetch the item.
145
-    $item = new WPInv_Item( $item );
145
+    $item = new WPInv_Item($item);
146 146
 
147 147
     // Check if it is editable.
148 148
     return $item->is_editable();
149 149
 }
150 150
 
151
-function wpinv_get_item_price( $item_id = 0 ) {
152
-    if( empty( $item_id ) ) {
151
+function wpinv_get_item_price($item_id = 0) {
152
+    if (empty($item_id)) {
153 153
         return false;
154 154
     }
155 155
 
156
-    $item = new WPInv_Item( $item_id );
156
+    $item = new WPInv_Item($item_id);
157 157
     
158 158
     return $item->get_price();
159 159
 }
@@ -163,266 +163,266 @@  discard block
 block discarded – undo
163 163
  *
164 164
  * @param WPInv_Item|int $item
165 165
  */
166
-function wpinv_is_recurring_item( $item = 0 ) {
167
-    $item = new WPInv_Item( $item ); 
166
+function wpinv_is_recurring_item($item = 0) {
167
+    $item = new WPInv_Item($item); 
168 168
     return $item->is_recurring();
169 169
 }
170 170
 
171
-function wpinv_item_price( $item_id = 0 ) {
172
-    if( empty( $item_id ) ) {
171
+function wpinv_item_price($item_id = 0) {
172
+    if (empty($item_id)) {
173 173
         return false;
174 174
     }
175 175
 
176
-    $price = wpinv_get_item_price( $item_id );
177
-    $price = wpinv_price( wpinv_format_amount( $price ) );
176
+    $price = wpinv_get_item_price($item_id);
177
+    $price = wpinv_price(wpinv_format_amount($price));
178 178
     
179
-    return apply_filters( 'wpinv_item_price', $price, $item_id );
179
+    return apply_filters('wpinv_item_price', $price, $item_id);
180 180
 }
181 181
 
182
-function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) {
183
-    if ( is_null( $amount_override ) ) {
184
-        $original_price = get_post_meta( $item_id, '_wpinv_price', true );
182
+function wpinv_get_item_final_price($item_id = 0, $amount_override = null) {
183
+    if (is_null($amount_override)) {
184
+        $original_price = get_post_meta($item_id, '_wpinv_price', true);
185 185
     } else {
186 186
         $original_price = $amount_override;
187 187
     }
188 188
     
189 189
     $price = $original_price;
190 190
 
191
-    return apply_filters( 'wpinv_get_item_final_price', $price, $item_id );
191
+    return apply_filters('wpinv_get_item_final_price', $price, $item_id);
192 192
 }
193 193
 
194
-function wpinv_item_custom_singular_name( $item_id ) {
195
-    if( empty( $item_id ) ) {
194
+function wpinv_item_custom_singular_name($item_id) {
195
+    if (empty($item_id)) {
196 196
         return false;
197 197
     }
198 198
 
199
-    $item = new WPInv_Item( $item_id );
199
+    $item = new WPInv_Item($item_id);
200 200
     
201 201
     return $item->get_custom_singular_name();
202 202
 }
203 203
 
204 204
 function wpinv_get_item_types() {
205 205
     $item_types = array(
206
-            'custom'    => __( 'Standard', 'invoicing' ),
207
-            'fee'       => __( 'Fee', 'invoicing' ),
206
+            'custom'    => __('Standard', 'invoicing'),
207
+            'fee'       => __('Fee', 'invoicing'),
208 208
         );
209
-    return apply_filters( 'wpinv_get_item_types', $item_types );
209
+    return apply_filters('wpinv_get_item_types', $item_types);
210 210
 }
211 211
 
212 212
 function wpinv_item_types() {
213 213
     $item_types = wpinv_get_item_types();
214 214
     
215
-    return ( !empty( $item_types ) ? array_keys( $item_types ) : array() );
215
+    return (!empty($item_types) ? array_keys($item_types) : array());
216 216
 }
217 217
 
218
-function wpinv_get_item_type( $item_id ) {
219
-    if( empty( $item_id ) ) {
218
+function wpinv_get_item_type($item_id) {
219
+    if (empty($item_id)) {
220 220
         return false;
221 221
     }
222 222
 
223
-    $item = new WPInv_Item( $item_id );
223
+    $item = new WPInv_Item($item_id);
224 224
     
225 225
     return $item->get_type();
226 226
 }
227 227
 
228
-function wpinv_item_type( $item_id ) {
228
+function wpinv_item_type($item_id) {
229 229
     $item_types = wpinv_get_item_types();
230 230
     
231
-    $item_type = wpinv_get_item_type( $item_id );
231
+    $item_type = wpinv_get_item_type($item_id);
232 232
     
233
-    if ( empty( $item_type ) ) {
233
+    if (empty($item_type)) {
234 234
         $item_type = '-';
235 235
     }
236 236
     
237
-    $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' );
237
+    $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing');
238 238
 
239
-    return apply_filters( 'wpinv_item_type', $item_type, $item_id );
239
+    return apply_filters('wpinv_item_type', $item_type, $item_id);
240 240
 }
241 241
 
242
-function wpinv_get_random_item( $post_ids = true ) {
243
-    wpinv_get_random_items( 1, $post_ids );
242
+function wpinv_get_random_item($post_ids = true) {
243
+    wpinv_get_random_items(1, $post_ids);
244 244
 }
245 245
 
246
-function wpinv_get_random_items( $num = 3, $post_ids = true ) {
247
-    if ( $post_ids ) {
248
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' );
246
+function wpinv_get_random_items($num = 3, $post_ids = true) {
247
+    if ($post_ids) {
248
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids');
249 249
     } else {
250
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num );
250
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num);
251 251
     }
252 252
     
253
-    $args  = apply_filters( 'wpinv_get_random_items', $args );
253
+    $args = apply_filters('wpinv_get_random_items', $args);
254 254
     
255
-    return get_posts( $args );
255
+    return get_posts($args);
256 256
 }
257 257
 
258
-function wpinv_get_item_token( $url = '' ) {
258
+function wpinv_get_item_token($url = '') {
259 259
     $args    = array();
260
-    $hash    = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' );
261
-    $secret  = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) );
260
+    $hash    = apply_filters('wpinv_get_url_token_algorithm', 'sha256');
261
+    $secret  = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt()));
262 262
 
263
-    $parts   = parse_url( $url );
263
+    $parts   = parse_url($url);
264 264
     $options = array();
265 265
 
266
-    if ( isset( $parts['query'] ) ) {
267
-        wp_parse_str( $parts['query'], $query_args );
266
+    if (isset($parts['query'])) {
267
+        wp_parse_str($parts['query'], $query_args);
268 268
 
269
-        if ( ! empty( $query_args['o'] ) ) {
270
-            $options = explode( ':', rawurldecode( $query_args['o'] ) );
269
+        if (!empty($query_args['o'])) {
270
+            $options = explode(':', rawurldecode($query_args['o']));
271 271
 
272
-            if ( in_array( 'ip', $options ) ) {
272
+            if (in_array('ip', $options)) {
273 273
                 $args['ip'] = wpinv_get_ip();
274 274
             }
275 275
 
276
-            if ( in_array( 'ua', $options ) ) {
276
+            if (in_array('ua', $options)) {
277 277
                 $ua = wpinv_get_user_agent();
278
-                $args['user_agent'] = rawurlencode( $ua );
278
+                $args['user_agent'] = rawurlencode($ua);
279 279
             }
280 280
         }
281 281
     }
282 282
 
283
-    $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options );
283
+    $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options);
284 284
 
285 285
     $args['secret'] = $secret;
286 286
     $args['token']  = false;
287 287
 
288
-    $url   = add_query_arg( $args, $url );
289
-    $parts = parse_url( $url );
288
+    $url   = add_query_arg($args, $url);
289
+    $parts = parse_url($url);
290 290
 
291
-    if ( ! isset( $parts['path'] ) ) {
291
+    if (!isset($parts['path'])) {
292 292
         $parts['path'] = '';
293 293
     }
294 294
 
295
-    $token = md5( $parts['path'] . '?' . $parts['query'] );
295
+    $token = md5($parts['path'] . '?' . $parts['query']);
296 296
 
297 297
     return $token;
298 298
 }
299 299
 
300
-function wpinv_validate_url_token( $url = '' ) {
300
+function wpinv_validate_url_token($url = '') {
301 301
     $ret   = false;
302
-    $parts = parse_url( $url );
302
+    $parts = parse_url($url);
303 303
 
304
-    if ( isset( $parts['query'] ) ) {
305
-        wp_parse_str( $parts['query'], $query_args );
304
+    if (isset($parts['query'])) {
305
+        wp_parse_str($parts['query'], $query_args);
306 306
 
307
-        $allowed = apply_filters( 'wpinv_url_token_allowed_params', array(
307
+        $allowed = apply_filters('wpinv_url_token_allowed_params', array(
308 308
             'item',
309 309
             'ttl',
310 310
             'token'
311
-        ) );
311
+        ));
312 312
 
313 313
         $remove = array();
314 314
 
315
-        foreach( $query_args as $key => $value ) {
316
-            if( false === in_array( $key, $allowed ) ) {
315
+        foreach ($query_args as $key => $value) {
316
+            if (false === in_array($key, $allowed)) {
317 317
                 $remove[] = $key;
318 318
             }
319 319
         }
320 320
 
321
-        if( ! empty( $remove ) ) {
322
-            $url = remove_query_arg( $remove, $url );
321
+        if (!empty($remove)) {
322
+            $url = remove_query_arg($remove, $url);
323 323
         }
324 324
 
325
-        if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) {
326
-            wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
325
+        if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) {
326
+            wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403));
327 327
         }
328 328
 
329
-        if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) {
329
+        if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) {
330 330
             $ret = true;
331 331
         }
332 332
 
333 333
     }
334 334
 
335
-    return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args );
335
+    return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args);
336 336
 }
337 337
 
338
-function wpinv_item_in_cart( $item_id = 0, $options = array() ) {
338
+function wpinv_item_in_cart($item_id = 0, $options = array()) {
339 339
     $cart_items = wpinv_get_cart_contents();
340 340
 
341 341
     $ret = false;
342 342
 
343
-    if ( is_array( $cart_items ) ) {
344
-        foreach ( $cart_items as $item ) {
345
-            if ( $item['id'] == $item_id ) {
343
+    if (is_array($cart_items)) {
344
+        foreach ($cart_items as $item) {
345
+            if ($item['id'] == $item_id) {
346 346
                 $ret = true;
347 347
                 break;
348 348
             }
349 349
         }
350 350
     }
351 351
 
352
-    return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options );
352
+    return (bool) apply_filters('wpinv_item_in_cart', $ret, $item_id, $options);
353 353
 }
354 354
 
355
-function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) {
355
+function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) {
356 356
     $tax = 0;
357
-    if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) {
358
-        $country = !empty( $_POST['country'] ) ? $_POST['country'] : false;
359
-        $state   = isset( $_POST['state'] ) ? $_POST['state'] : '';
357
+    if (!wpinv_item_is_tax_exclusive($item_id)) {
358
+        $country = !empty($_POST['country']) ? $_POST['country'] : false;
359
+        $state   = isset($_POST['state']) ? $_POST['state'] : '';
360 360
 
361
-        $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id );
361
+        $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id);
362 362
     }
363 363
 
364
-    return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options );
364
+    return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options);
365 365
 }
366 366
 
367
-function wpinv_cart_item_price( $item, $currency = '' ) {
367
+function wpinv_cart_item_price($item, $currency = '') {
368 368
 
369
-    if( empty( $currency ) ) {
369
+    if (empty($currency)) {
370 370
         $currency = wpinv_get_currency();
371 371
     }
372 372
 
373
-    $item_id    = isset( $item['id'] ) ? $item['id'] : 0;
374
-    $price      = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0;
375
-    $tax        = wpinv_price( wpinv_format_amount( $item['tax'] ) );
373
+    $item_id    = isset($item['id']) ? $item['id'] : 0;
374
+    $price      = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0;
375
+    $tax        = wpinv_price(wpinv_format_amount($item['tax']));
376 376
     
377
-    if ( !wpinv_is_free_item( $item_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) {
378
-        if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) {
377
+    if (!wpinv_is_free_item($item_id) && !wpinv_item_is_tax_exclusive($item_id)) {
378
+        if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) {
379 379
             $price += $tax;
380 380
         }
381 381
         
382
-        if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) {
382
+        if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) {
383 383
             $price -= $tax;
384 384
         }        
385 385
     }
386 386
 
387
-    $price = wpinv_price( wpinv_format_amount( $price ), $currency );
387
+    $price = wpinv_price(wpinv_format_amount($price), $currency);
388 388
 
389
-    return apply_filters( 'wpinv_cart_item_price_label', $price, $item );
389
+    return apply_filters('wpinv_cart_item_price_label', $price, $item);
390 390
 }
391 391
 
392
-function wpinv_cart_item_subtotal( $item, $currency = '' ) {
392
+function wpinv_cart_item_subtotal($item, $currency = '') {
393 393
 
394
-    if( empty( $currency ) ) {
394
+    if (empty($currency)) {
395 395
         $currency = wpinv_get_currency();
396 396
     }
397 397
 
398
-    $subtotal   = isset( $item['subtotal'] ) ? $item['subtotal'] : 0;
399
-    $subtotal   = wpinv_price( wpinv_format_amount( $subtotal ), $currency );
398
+    $subtotal   = isset($item['subtotal']) ? $item['subtotal'] : 0;
399
+    $subtotal   = wpinv_price(wpinv_format_amount($subtotal), $currency);
400 400
 
401
-    return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item );
401
+    return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item);
402 402
 }
403 403
 
404
-function wpinv_cart_item_tax( $item, $currency = '' ) {
404
+function wpinv_cart_item_tax($item, $currency = '') {
405 405
     $tax        = '';
406 406
     $tax_rate   = '';
407 407
 
408
-    if( empty( $currency ) ) {
408
+    if (empty($currency)) {
409 409
         $currency = wpinv_get_currency();
410 410
     }
411 411
     
412
-    if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) {
413
-        $tax      = wpinv_price( wpinv_format_amount( $item['tax'] ), $currency );
414
-        $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100;
415
-        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
412
+    if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) {
413
+        $tax      = wpinv_price(wpinv_format_amount($item['tax']), $currency);
414
+        $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100;
415
+        $tax_rate = $tax_rate > 0 ? (float) wpinv_round_amount($tax_rate, 4) : '';
416 416
         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : '';
417 417
     }
418 418
     
419
-    $tax        = $tax . $tax_rate;
419
+    $tax = $tax . $tax_rate;
420 420
     
421
-    if ( $tax === '' ) {
421
+    if ($tax === '') {
422 422
         $tax = 0; // Zero tax
423 423
     }
424 424
 
425
-    return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item );
425
+    return apply_filters('wpinv_cart_item_tax_label', $tax, $item);
426 426
 }
427 427
 
428 428
 /**
@@ -431,13 +431,13 @@  discard block
 block discarded – undo
431 431
  * @param WPInv_Item|int $item
432 432
  * @param bool $html
433 433
  */
434
-function wpinv_get_item_suffix( $item, $html = true ) {
434
+function wpinv_get_item_suffix($item, $html = true) {
435 435
 
436
-    $item   = new WPInv_Item( $item );
437
-    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '';
438
-    $suffix = $html ? $suffix : strip_tags( $suffix );
436
+    $item   = new WPInv_Item($item);
437
+    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '';
438
+    $suffix = $html ? $suffix : strip_tags($suffix);
439 439
 
440
-    return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html );
440
+    return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html);
441 441
 }
442 442
 
443 443
 /**
@@ -446,9 +446,9 @@  discard block
 block discarded – undo
446 446
  * @param WPInv_Item|int $item
447 447
  * @param bool $force_delete
448 448
  */
449
-function wpinv_remove_item( $item = 0, $force_delete = false ) {
450
-    $item = new WPInv_Item( $item );
451
-    $item->delete( $force_delete );
449
+function wpinv_remove_item($item = 0, $force_delete = false) {
450
+    $item = new WPInv_Item($item);
451
+    $item->delete($force_delete);
452 452
 }
453 453
 
454 454
 /**
@@ -487,45 +487,45 @@  discard block
 block discarded – undo
487 487
  * @param bool $wp_error whether or not to return a WP_Error on failure.
488 488
  * @return bool|WP_Error|WPInv_Item
489 489
  */
490
-function wpinv_create_item( $args = array(), $wp_error = false ) {
490
+function wpinv_create_item($args = array(), $wp_error = false) {
491 491
 
492 492
     // Prepare the item.
493
-    if ( ! empty( $args['custom_id'] ) && empty( $args['ID'] ) ) {
494
-        $type = empty( $args['type'] ) ? 'custom' : $args['type'];
495
-        $item = wpinv_get_item_by( 'custom_id', $args['custom_id'], $type );
493
+    if (!empty($args['custom_id']) && empty($args['ID'])) {
494
+        $type = empty($args['type']) ? 'custom' : $args['type'];
495
+        $item = wpinv_get_item_by('custom_id', $args['custom_id'], $type);
496 496
 
497
-        if ( ! empty( $item ) ) {
497
+        if (!empty($item)) {
498 498
             $args['ID'] = $item->get_id();
499 499
         }
500 500
 
501 501
     }
502 502
 
503 503
     // Do we have an item?
504
-    if ( ! empty( $args['ID'] ) ) {
505
-        $item = new WPInv_Item( $args['ID'] );
504
+    if (!empty($args['ID'])) {
505
+        $item = new WPInv_Item($args['ID']);
506 506
     } else {
507 507
         $item = new WPInv_Item();
508 508
     }
509 509
 
510 510
     // Do we have an error?
511
-    if ( ! empty( $item->last_error ) ) {
512
-        return $wp_error ? new WP_Error( 'invalid_item', $item->last_error ) : false;
511
+    if (!empty($item->last_error)) {
512
+        return $wp_error ? new WP_Error('invalid_item', $item->last_error) : false;
513 513
     }
514 514
 
515 515
     // Update item props.
516
-    $item->set_props( $args );
516
+    $item->set_props($args);
517 517
 
518 518
     // Save the item.
519 519
     $item->save();
520 520
 
521 521
     // Do we have an error?
522
-    if ( ! empty( $item->last_error ) ) {
523
-        return $wp_error ? new WP_Error( 'not_saved', $item->last_error ) : false;
522
+    if (!empty($item->last_error)) {
523
+        return $wp_error ? new WP_Error('not_saved', $item->last_error) : false;
524 524
     }
525 525
 
526 526
     // Was the item saved?
527
-    if ( ! $item->get_id() ) {
528
-        return $wp_error ? new WP_Error( 'not_saved', __( 'An error occured while saving the item', 'invoicing' ) ) : false;
527
+    if (!$item->get_id()) {
528
+        return $wp_error ? new WP_Error('not_saved', __('An error occured while saving the item', 'invoicing')) : false;
529 529
     }
530 530
 
531 531
     return $item;
@@ -537,14 +537,14 @@  discard block
 block discarded – undo
537 537
  * 
538 538
  * @see wpinv_create_item()
539 539
  */
540
-function wpinv_update_item( $args = array(), $wp_error = false ) {
541
-    return wpinv_create_item( $args, $wp_error );
540
+function wpinv_update_item($args = array(), $wp_error = false) {
541
+    return wpinv_create_item($args, $wp_error);
542 542
 }
543 543
 
544 544
 /**
545 545
  * Sanitizes a recurring period
546 546
  */
547
-function getpaid_sanitize_recurring_period( $period, $full = false ) {
547
+function getpaid_sanitize_recurring_period($period, $full = false) {
548 548
 
549 549
     $periods = array(
550 550
         'D' => 'day',
@@ -553,11 +553,11 @@  discard block
 block discarded – undo
553 553
         'Y' => 'year',
554 554
     );
555 555
 
556
-    if ( ! isset( $periods[ $period ] ) ) {
556
+    if (!isset($periods[$period])) {
557 557
         $period = 'D';
558 558
     }
559 559
 
560
-    return $full ? $periods[ $period ] : $period;
560
+    return $full ? $periods[$period] : $period;
561 561
 
562 562
 }
563 563
 
@@ -566,34 +566,34 @@  discard block
 block discarded – undo
566 566
  * 
567 567
  * @param WPInv_Item|GetPaid_Form_Item $item
568 568
  */
569
-function getpaid_item_recurring_price_help_text( $item, $currency = '' ) {
569
+function getpaid_item_recurring_price_help_text($item, $currency = '') {
570 570
 
571 571
     // Abort if it is not recurring.
572
-    if ( ! $item->is_recurring() ) {
572
+    if (!$item->is_recurring()) {
573 573
         return '';
574 574
     }
575 575
 
576
-    $initial_price   = wpinv_price( $item->get_initial_price(), $currency );
577
-    $recurring_price = wpinv_price( $item->get_recurring_price(), $currency );
578
-    $period          = getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' );
576
+    $initial_price   = wpinv_price($item->get_initial_price(), $currency);
577
+    $recurring_price = wpinv_price($item->get_recurring_price(), $currency);
578
+    $period          = getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), '');
579 579
     $initial_class   = 'getpaid-item-initial-price';
580 580
     $recurring_class = 'getpaid-item-recurring-price';
581 581
 
582
-    if ( $item instanceof GetPaid_Form_Item ) {
583
-        $initial_price   = wpinv_price( $item->get_sub_total(), $currency );
584
-        $recurring_price = wpinv_price( $item->get_recurring_sub_total(), $currency );
582
+    if ($item instanceof GetPaid_Form_Item) {
583
+        $initial_price   = wpinv_price($item->get_sub_total(), $currency);
584
+        $recurring_price = wpinv_price($item->get_recurring_sub_total(), $currency);
585 585
     }
586 586
 
587 587
     // For free trial items.
588
-    if ( $item->has_free_trial() ) {
589
-        $trial_period = getpaid_get_subscription_period_label( $item->get_trial_period(), $item->get_trial_interval() );
588
+    if ($item->has_free_trial()) {
589
+        $trial_period = getpaid_get_subscription_period_label($item->get_trial_period(), $item->get_trial_interval());
590 590
 
591
-        if ( 0 == $item->get_initial_price() ) {
591
+        if (0 == $item->get_initial_price()) {
592 592
 
593 593
             return sprintf(
594 594
 
595 595
                 // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period
596
-                _x( 'Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing' ),
596
+                _x('Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing'),
597 597
                 $trial_period,
598 598
                 "<span class='$recurring_class'>$recurring_price</span>",
599 599
                 $period
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
         return sprintf(
606 606
 
607 607
             // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period
608
-            _x( '%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing' ),
608
+            _x('%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing'),
609 609
             "<span class='$initial_class'>$initial_price</span>",
610 610
             $trial_period,
611 611
             "<span class='$recurring_class'>$recurring_price</span>",
@@ -615,12 +615,12 @@  discard block
 block discarded – undo
615 615
 
616 616
     }
617 617
 
618
-    if ( $initial_price == $recurring_price ) {
618
+    if ($initial_price == $recurring_price) {
619 619
 
620 620
         return sprintf(
621 621
 
622 622
             // translators: $1: is the recurring price, $2: is the susbcription period
623
-            _x( '%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing' ),
623
+            _x('%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing'),
624 624
             "<span class='$recurring_class'>$recurring_price</span>",
625 625
             $period
626 626
 
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
     return sprintf(
632 632
 
633 633
         // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period
634
-        _x( 'Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing' ),
634
+        _x('Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing'),
635 635
         "<span class='$initial_class'>$initial_price</span>",
636 636
         "<span class='$recurring_class'>$recurring_price</span>",
637 637
         $period
Please login to merge, or discard this patch.