Passed
Push — master ( 330418...c4952f )
by Brian
05:45 queued 27s
created
templates/payment-forms/embed.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -1,32 +1,32 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-	// Is the request set up correctly?
4
-	if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
5
-		return aui()->alert(
6
-			array(
7
-				'type'    => 'warning',
8
-				'content' => __( 'No payment form or item selected', 'invoicing' ),
9
-			)
10
-		);
11
-		wp_die( __( 'No payment form or item selected', 'invoicing' ), 400 );
12
-	}
13
-
14
-	// Payment form or button?
15
-	if ( ! empty( $_GET['form'] ) ) {
16
-
17
-		$shortcode = sprintf(
18
-			'[getpaid form=%s]',
19
-			(int) $_GET['form']
20
-		);
21
-
22
-	} else {
23
-
24
-		$shortcode = sprintf(
25
-			'[getpaid item=%s]',
26
-			esc_attr( urldecode( $_GET['item'] ) )
27
-		);
28
-
29
-	}
3
+    // Is the request set up correctly?
4
+    if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
5
+        return aui()->alert(
6
+            array(
7
+                'type'    => 'warning',
8
+                'content' => __( 'No payment form or item selected', 'invoicing' ),
9
+            )
10
+        );
11
+        wp_die( __( 'No payment form or item selected', 'invoicing' ), 400 );
12
+    }
13
+
14
+    // Payment form or button?
15
+    if ( ! empty( $_GET['form'] ) ) {
16
+
17
+        $shortcode = sprintf(
18
+            '[getpaid form=%s]',
19
+            (int) $_GET['form']
20
+        );
21
+
22
+    } else {
23
+
24
+        $shortcode = sprintf(
25
+            '[getpaid item=%s]',
26
+            esc_attr( urldecode( $_GET['item'] ) )
27
+        );
28
+
29
+    }
30 30
 
31 31
 ?>
32 32
 
@@ -44,12 +44,12 @@  discard block
 block discarded – undo
44 44
 
45 45
         <title>GetPaid</title>
46 46
 		<?php
47
-			wp_enqueue_scripts();
48
-			wp_print_styles();
49
-			wp_print_head_scripts();
50
-			wp_custom_css_cb();
51
-			wpinv_get_template( 'frontend-head.php' );
52
-		?>
47
+            wp_enqueue_scripts();
48
+            wp_print_styles();
49
+            wp_print_head_scripts();
50
+            wp_custom_css_cb();
51
+            wpinv_get_template( 'frontend-head.php' );
52
+        ?>
53 53
 
54 54
 		<style type="text/css">
55 55
 			.body{ 
@@ -83,11 +83,11 @@  discard block
 block discarded – undo
83 83
 	<body class="body page-template-default page">
84 84
 		<div id="getpaid-form-embed" class="container my-5 page type-page status-publish hentry post post-content">
85 85
 			<?php
86
-				do_action( 'getpaid_payment_form_embed_top' );
87
-				echo do_shortcode( $shortcode );
88
-				do_action( 'getpaid_payment_form_embed_bottom' );
89
-				wpinv_get_template( 'frontend-footer.php' );
90
-			?>
86
+                do_action( 'getpaid_payment_form_embed_top' );
87
+                echo do_shortcode( $shortcode );
88
+                do_action( 'getpaid_payment_form_embed_bottom' );
89
+                wpinv_get_template( 'frontend-footer.php' );
90
+            ?>
91 91
 		</div>
92 92
 		<?php wp_footer(); ?>
93 93
 	</body>
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,18 +1,18 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 	// Is the request set up correctly?
4
-	if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
4
+	if (empty($_GET['form']) && empty($_GET['item'])) {
5 5
 		return aui()->alert(
6 6
 			array(
7 7
 				'type'    => 'warning',
8
-				'content' => __( 'No payment form or item selected', 'invoicing' ),
8
+				'content' => __('No payment form or item selected', 'invoicing'),
9 9
 			)
10 10
 		);
11
-		wp_die( __( 'No payment form or item selected', 'invoicing' ), 400 );
11
+		wp_die(__('No payment form or item selected', 'invoicing'), 400);
12 12
 	}
13 13
 
14 14
 	// Payment form or button?
15
-	if ( ! empty( $_GET['form'] ) ) {
15
+	if (!empty($_GET['form'])) {
16 16
 
17 17
 		$shortcode = sprintf(
18 18
 			'[getpaid form=%s]',
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 
24 24
 		$shortcode = sprintf(
25 25
 			'[getpaid item=%s]',
26
-			esc_attr( urldecode( $_GET['item'] ) )
26
+			esc_attr(urldecode($_GET['item']))
27 27
 		);
28 28
 
29 29
 	}
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 
36 36
 	<head>
37 37
 
38
-		<meta charset="<?php bloginfo( 'charset' ); ?>">
38
+		<meta charset="<?php bloginfo('charset'); ?>">
39 39
         <meta name="viewport" content="width=device-width, initial-scale=1.0" >
40 40
 
41 41
         <meta name="robots" content="noindex,nofollow">
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 			wp_print_styles();
49 49
 			wp_print_head_scripts();
50 50
 			wp_custom_css_cb();
51
-			wpinv_get_template( 'frontend-head.php' );
51
+			wpinv_get_template('frontend-head.php');
52 52
 		?>
53 53
 
54 54
 		<style type="text/css">
@@ -83,10 +83,10 @@  discard block
 block discarded – undo
83 83
 	<body class="body page-template-default page">
84 84
 		<div id="getpaid-form-embed" class="container my-5 page type-page status-publish hentry post post-content">
85 85
 			<?php
86
-				do_action( 'getpaid_payment_form_embed_top' );
87
-				echo do_shortcode( $shortcode );
88
-				do_action( 'getpaid_payment_form_embed_bottom' );
89
-				wpinv_get_template( 'frontend-footer.php' );
86
+				do_action('getpaid_payment_form_embed_top');
87
+				echo do_shortcode($shortcode);
88
+				do_action('getpaid_payment_form_embed_bottom');
89
+				wpinv_get_template('frontend-footer.php');
90 90
 			?>
91 91
 		</div>
92 92
 		<?php wp_footer(); ?>
Please login to merge, or discard this patch.
widgets/subscriptions.php 2 patches
Indentation   +346 added lines, -346 removed lines patch added patch discarded remove patch
@@ -14,144 +14,144 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class WPInv_Subscriptions_Widget extends WP_Super_Duper {
16 16
 
17
-	/**
18
-	 * Register the widget with WordPress.
19
-	 *
20
-	 */
21
-	public function __construct() {
22
-
23
-		$options = array(
24
-			'textdomain'    => 'invoicing',
25
-			'block-icon'    => 'controls-repeat',
26
-			'block-category'=> 'widgets',
27
-			'block-keywords'=> "['invoicing','subscriptions', 'getpaid']",
28
-			'class_name'     => __CLASS__,
29
-			'base_id'       => 'wpinv_subscriptions',
30
-			'name'          => __( 'GetPaid > Subscriptions', 'invoicing' ),
31
-			'widget_ops'    => array(
32
-				'classname'   => 'getpaid-subscriptions bsui',
33
-				'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ),
34
-			),
35
-			'arguments'     => array(
36
-				'title'  => array(
37
-					'title'       => __( 'Widget title', 'invoicing' ),
38
-					'desc'        => __( 'Enter widget title.', 'invoicing' ),
39
-					'type'        => 'text',
40
-					'desc_tip'    => true,
41
-					'default'     => '',
42
-					'advanced'    => false
43
-				),
44
-			)
45
-
46
-		);
47
-
48
-
49
-		parent::__construct( $options );
50
-	}
51
-
52
-	/**
53
-	 * Retrieves current user's subscriptions.
54
-	 *
55
-	 * @return GetPaid_Subscriptions_Query
56
-	 */
57
-	public function get_subscriptions() {
58
-
59
-		// Prepare license args.
60
-		$args  = array(
61
-			'customer_in' => get_current_user_id(),
62
-			'paged'       => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1,
63
-		);
64
-
65
-		return new GetPaid_Subscriptions_Query( $args );
66
-
67
-	}
68
-
69
-	/**
70
-	 * The Super block output function.
71
-	 *
72
-	 * @param array $args
73
-	 * @param array $widget_args
74
-	 * @param string $content
75
-	 *
76
-	 * @return mixed|string|bool
77
-	 */
78
-	public function output( $args = array(), $widget_args = array(), $content = '' ) {
79
-
80
-		// Ensure that the user is logged in.
81
-		if ( ! is_user_logged_in() ) {
82
-
83
-			return aui()->alert(
84
-				array(
85
-					'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ),
86
-					'type'    => 'error',
87
-				)
88
-			);
89
-
90
-		}
91
-
92
-		// Are we displaying a single subscription?
93
-		if ( isset( $_GET['subscription'] ) ) {
94
-			return $this->display_single_subscription( intval( $_GET['subscription'] ) );
95
-		}
96
-
97
-		// Retrieve the user's subscriptions.
98
-		$subscriptions = $this->get_subscriptions();
99
-
100
-		// Start the output buffer.
101
-		ob_start();
102
-
103
-		// Backwards compatibility.
104
-		do_action( 'wpinv_before_user_subscriptions' );
105
-
106
-		// Display errors and notices.
107
-		wpinv_print_errors();
108
-
109
-		do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions );
110
-
111
-		// Print the table header.
112
-		$this->print_table_header();
113
-
114
-		// Print table body.
115
-		$this->print_table_body( $subscriptions->get_results() );
116
-
117
-		// Print table footer.
118
-		$this->print_table_footer();
119
-
120
-		// Print the navigation.
121
-		$this->print_navigation( $subscriptions->get_total() );
122
-
123
-		// Backwards compatibility.
124
-		do_action( 'wpinv_after_user_subscriptions' );
125
-
126
-		// Return the output.
127
-		return ob_get_clean();
128
-
129
-	}
130
-
131
-	/**
132
-	 * Retrieves the subscription columns.
133
-	 *
134
-	 * @return array
135
-	 */
136
-	public function get_subscriptions_table_columns() {
17
+    /**
18
+     * Register the widget with WordPress.
19
+     *
20
+     */
21
+    public function __construct() {
22
+
23
+        $options = array(
24
+            'textdomain'    => 'invoicing',
25
+            'block-icon'    => 'controls-repeat',
26
+            'block-category'=> 'widgets',
27
+            'block-keywords'=> "['invoicing','subscriptions', 'getpaid']",
28
+            'class_name'     => __CLASS__,
29
+            'base_id'       => 'wpinv_subscriptions',
30
+            'name'          => __( 'GetPaid > Subscriptions', 'invoicing' ),
31
+            'widget_ops'    => array(
32
+                'classname'   => 'getpaid-subscriptions bsui',
33
+                'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ),
34
+            ),
35
+            'arguments'     => array(
36
+                'title'  => array(
37
+                    'title'       => __( 'Widget title', 'invoicing' ),
38
+                    'desc'        => __( 'Enter widget title.', 'invoicing' ),
39
+                    'type'        => 'text',
40
+                    'desc_tip'    => true,
41
+                    'default'     => '',
42
+                    'advanced'    => false
43
+                ),
44
+            )
45
+
46
+        );
47
+
48
+
49
+        parent::__construct( $options );
50
+    }
51
+
52
+    /**
53
+     * Retrieves current user's subscriptions.
54
+     *
55
+     * @return GetPaid_Subscriptions_Query
56
+     */
57
+    public function get_subscriptions() {
58
+
59
+        // Prepare license args.
60
+        $args  = array(
61
+            'customer_in' => get_current_user_id(),
62
+            'paged'       => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1,
63
+        );
64
+
65
+        return new GetPaid_Subscriptions_Query( $args );
66
+
67
+    }
68
+
69
+    /**
70
+     * The Super block output function.
71
+     *
72
+     * @param array $args
73
+     * @param array $widget_args
74
+     * @param string $content
75
+     *
76
+     * @return mixed|string|bool
77
+     */
78
+    public function output( $args = array(), $widget_args = array(), $content = '' ) {
79
+
80
+        // Ensure that the user is logged in.
81
+        if ( ! is_user_logged_in() ) {
82
+
83
+            return aui()->alert(
84
+                array(
85
+                    'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ),
86
+                    'type'    => 'error',
87
+                )
88
+            );
89
+
90
+        }
91
+
92
+        // Are we displaying a single subscription?
93
+        if ( isset( $_GET['subscription'] ) ) {
94
+            return $this->display_single_subscription( intval( $_GET['subscription'] ) );
95
+        }
96
+
97
+        // Retrieve the user's subscriptions.
98
+        $subscriptions = $this->get_subscriptions();
99
+
100
+        // Start the output buffer.
101
+        ob_start();
102
+
103
+        // Backwards compatibility.
104
+        do_action( 'wpinv_before_user_subscriptions' );
105
+
106
+        // Display errors and notices.
107
+        wpinv_print_errors();
108
+
109
+        do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions );
110
+
111
+        // Print the table header.
112
+        $this->print_table_header();
113
+
114
+        // Print table body.
115
+        $this->print_table_body( $subscriptions->get_results() );
116
+
117
+        // Print table footer.
118
+        $this->print_table_footer();
119
+
120
+        // Print the navigation.
121
+        $this->print_navigation( $subscriptions->get_total() );
122
+
123
+        // Backwards compatibility.
124
+        do_action( 'wpinv_after_user_subscriptions' );
125
+
126
+        // Return the output.
127
+        return ob_get_clean();
128
+
129
+    }
130
+
131
+    /**
132
+     * Retrieves the subscription columns.
133
+     *
134
+     * @return array
135
+     */
136
+    public function get_subscriptions_table_columns() {
137 137
 
138
-		$columns = array(
139
-			'subscription'   => __( 'Subscription', 'invoicing' ),
140
-			'amount'         => __( 'Amount', 'invoicing' ),
141
-			'renewal-date'   => __( 'Next payment', 'invoicing' ),
142
-			'status'         => __( 'Status', 'invoicing' ),
143
-		);
138
+        $columns = array(
139
+            'subscription'   => __( 'Subscription', 'invoicing' ),
140
+            'amount'         => __( 'Amount', 'invoicing' ),
141
+            'renewal-date'   => __( 'Next payment', 'invoicing' ),
142
+            'status'         => __( 'Status', 'invoicing' ),
143
+        );
144 144
 
145
-		return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns );
146
-	}
145
+        return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns );
146
+    }
147 147
 
148
-	/**
149
-	 * Displays the table header.
150
-	 *
151
-	 */
152
-	public function print_table_header() {
148
+    /**
149
+     * Displays the table header.
150
+     *
151
+     */
152
+    public function print_table_header() {
153 153
 
154
-		?>
154
+        ?>
155 155
 
156 156
 			<table class="table table-bordered table-striped">
157 157
 
@@ -167,121 +167,121 @@  discard block
 block discarded – undo
167 167
 
168 168
 		<?php
169 169
 
170
-	}
170
+    }
171 171
 
172
-	/**
173
-	 * Displays the table body.
174
-	 *
175
-	 * @param WPInv_Subscription[] $subscriptions
176
-	 */
177
-	public function print_table_body( $subscriptions ) {
172
+    /**
173
+     * Displays the table body.
174
+     *
175
+     * @param WPInv_Subscription[] $subscriptions
176
+     */
177
+    public function print_table_body( $subscriptions ) {
178 178
 
179
-		if ( empty( $subscriptions ) ) {
180
-			$this->print_table_body_no_subscriptions();
181
-		} else {
182
-			$this->print_table_body_subscriptions( $subscriptions );
183
-		}
179
+        if ( empty( $subscriptions ) ) {
180
+            $this->print_table_body_no_subscriptions();
181
+        } else {
182
+            $this->print_table_body_subscriptions( $subscriptions );
183
+        }
184 184
 
185
-	}
185
+    }
186 186
 
187
-	/**
188
-	 * Displays the table body if no subscriptions were found.
189
-	 *
190
-	 */
191
-	public function print_table_body_no_subscriptions() {
187
+    /**
188
+     * Displays the table body if no subscriptions were found.
189
+     *
190
+     */
191
+    public function print_table_body_no_subscriptions() {
192 192
 
193
-		?>
193
+        ?>
194 194
 		<tbody>
195 195
 
196 196
 			<tr>
197 197
 				<td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>">
198 198
 
199 199
 					<?php
200
-						echo aui()->alert(
201
-							array(
202
-								'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ),
203
-								'type'    => 'warning',
204
-							)
205
-						);
206
-					?>
200
+                        echo aui()->alert(
201
+                            array(
202
+                                'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ),
203
+                                'type'    => 'warning',
204
+                            )
205
+                        );
206
+                    ?>
207 207
 
208 208
 				</td>
209 209
 			</tr>
210 210
 
211 211
 		</tbody>
212 212
 		<?php
213
-	}
213
+    }
214 214
 
215
-	/**
216
-	 * Displays the table body if subscriptions were found.
217
-	 *
218
-	 * @param WPInv_Subscription[] $subscriptions
219
-	 */
220
-	public function print_table_body_subscriptions( $subscriptions ) {
215
+    /**
216
+     * Displays the table body if subscriptions were found.
217
+     *
218
+     * @param WPInv_Subscription[] $subscriptions
219
+     */
220
+    public function print_table_body_subscriptions( $subscriptions ) {
221 221
 
222
-		?>
222
+        ?>
223 223
 		<tbody>
224 224
 
225 225
 			<?php foreach ( $subscriptions as $subscription ) : ?>
226 226
 				<tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>">
227 227
 					<?php
228
-						wpinv_get_template(
229
-							'subscriptions/subscriptions-table-row.php',
230
-							array(
231
-								'subscription' => $subscription,
232
-								'widget'       => $this
233
-							)
234
-						);
235
-					?>
228
+                        wpinv_get_template(
229
+                            'subscriptions/subscriptions-table-row.php',
230
+                            array(
231
+                                'subscription' => $subscription,
232
+                                'widget'       => $this
233
+                            )
234
+                        );
235
+                    ?>
236 236
 				</tr>
237 237
 			<?php endforeach; ?>
238 238
 
239 239
 		</tbody>
240 240
 		<?php
241
-	}
242
-
243
-	/**
244
-	 * Adds row actions to a column
245
-	 *
246
-	 * @param string $content column content
247
-	 * @param WPInv_Subscription $subscription
248
-	 * @since       1.0.0
249
-	 * @return      string
250
-	 */
251
-	public function add_row_actions( $content, $subscription ) {
252
-
253
-		// Prepare row actions.
254
-		$actions = array();
255
-
256
-		// View subscription action.
257
-		$view_url        = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
258
-		$view_url        = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) );
259
-		$actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>';
260
-
261
-		// Filter the actions.
262
-		$actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription );
263
-
264
-		$sanitized  = array();
265
-		foreach ( $actions as $key => $action ) {
266
-			$key         = sanitize_html_class( $key );
267
-			$action      = wp_kses_post( $action );
268
-			$sanitized[] = "<span class='$key'>$action</span>";
269
-		}
270
-
271
-		$row_actions  = "<small class='form-text getpaid-subscription-item-actions'>";
272
-		$row_actions .= implode( ' | ', $sanitized );
273
-		$row_actions .= '</small>';
274
-
275
-		return $content . $row_actions;
276
-	}
277
-
278
-	/**
279
-	 * Displays the table footer.
280
-	 *
281
-	 */
282
-	public function print_table_footer() {
283
-
284
-		?>
241
+    }
242
+
243
+    /**
244
+     * Adds row actions to a column
245
+     *
246
+     * @param string $content column content
247
+     * @param WPInv_Subscription $subscription
248
+     * @since       1.0.0
249
+     * @return      string
250
+     */
251
+    public function add_row_actions( $content, $subscription ) {
252
+
253
+        // Prepare row actions.
254
+        $actions = array();
255
+
256
+        // View subscription action.
257
+        $view_url        = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
258
+        $view_url        = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) );
259
+        $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>';
260
+
261
+        // Filter the actions.
262
+        $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription );
263
+
264
+        $sanitized  = array();
265
+        foreach ( $actions as $key => $action ) {
266
+            $key         = sanitize_html_class( $key );
267
+            $action      = wp_kses_post( $action );
268
+            $sanitized[] = "<span class='$key'>$action</span>";
269
+        }
270
+
271
+        $row_actions  = "<small class='form-text getpaid-subscription-item-actions'>";
272
+        $row_actions .= implode( ' | ', $sanitized );
273
+        $row_actions .= '</small>';
274
+
275
+        return $content . $row_actions;
276
+    }
277
+
278
+    /**
279
+     * Displays the table footer.
280
+     *
281
+     */
282
+    public function print_table_footer() {
283
+
284
+        ?>
285 285
 
286 286
 				<tfoot>
287 287
 					<tr>
@@ -296,143 +296,143 @@  discard block
 block discarded – undo
296 296
 			</table>
297 297
 		<?php
298 298
 
299
-	}
299
+    }
300 300
 
301
-	/**
302
-	 * Displays the navigation.
303
-	 *
304
-	 * @param int $total
305
-	 */
306
-	public function print_navigation( $total ) {
301
+    /**
302
+     * Displays the navigation.
303
+     *
304
+     * @param int $total
305
+     */
306
+    public function print_navigation( $total ) {
307 307
 
308
-		if ( $total < 1 ) {
308
+        if ( $total < 1 ) {
309 309
 
310
-			// Out-of-bounds, run the query again without LIMIT for total count.
311
-			$args  = array(
312
-				'customer_in' => get_current_user_id(),
313
-				'fields'      => 'id',
314
-			);
310
+            // Out-of-bounds, run the query again without LIMIT for total count.
311
+            $args  = array(
312
+                'customer_in' => get_current_user_id(),
313
+                'fields'      => 'id',
314
+            );
315 315
 
316
-			$count_query = new GetPaid_Subscriptions_Query( $args );
317
-			$total       = $count_query->get_total();
318
-		}
316
+            $count_query = new GetPaid_Subscriptions_Query( $args );
317
+            $total       = $count_query->get_total();
318
+        }
319 319
 
320
-		// Abort if we do not have pages.
321
-		if ( 2 > $total ) {
322
-			return;
323
-		}
320
+        // Abort if we do not have pages.
321
+        if ( 2 > $total ) {
322
+            return;
323
+        }
324 324
 
325
-		?>
325
+        ?>
326 326
 
327 327
 		<div class="getpaid-subscriptions-pagination">
328 328
 			<?php
329
-				$big = 999999;
330
-
331
-				echo getpaid_paginate_links(
332
-					array(
333
-						'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
334
-						'format'  => '?paged=%#%',
335
-						'total'   => (int) ceil( $total / 10 ),
336
-					)
337
-				);
338
-			?>
329
+                $big = 999999;
330
+
331
+                echo getpaid_paginate_links(
332
+                    array(
333
+                        'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
334
+                        'format'  => '?paged=%#%',
335
+                        'total'   => (int) ceil( $total / 10 ),
336
+                    )
337
+                );
338
+            ?>
339 339
 		</div>
340 340
 
341 341
 		<?php
342
-	}
343
-
344
-	/**
345
-	 * Returns a single subscription's columns.
346
-	 *
347
-	 * @param WPInv_Subscription $subscription
348
-	 *
349
-	 * @return array
350
-	 */
351
-	public function get_single_subscription_columns( $subscription ) {
352
-
353
-		// Prepare subscription detail columns.
354
-		$subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() );
355
-		$items_count        = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] );
356
-		$fields             = apply_filters(
357
-			'getpaid_single_subscription_details_fields',
358
-			array(
359
-				'status'           => __( 'Status', 'invoicing' ),
360
-				'initial_amount'   => __( 'Initial amount', 'invoicing' ),
361
-				'recurring_amount' => __( 'Recurring amount', 'invoicing' ),
362
-				'start_date'       => __( 'Start date', 'invoicing' ),
363
-				'expiry_date'      => __( 'Next payment', 'invoicing' ),
364
-				'payments'         => __( 'Payments', 'invoicing' ),
365
-				'item'             => _n( 'Item', 'Items', $items_count, 'invoicing' ),
366
-			),
367
-			$subscription
368
-		);
369
-
370
-		if ( isset( $fields['expiry_date'] ) ) {
371
-
372
-			if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) {
373
-				$fields['expiry_date'] = __( 'End date', 'invoicing' );
374
-			}
375
-
376
-			if ( 'pending' == $subscription->get_status() ) {
377
-				unset( $fields['expiry_date'] );
378
-			}
379
-
380
-		}
381
-
382
-		if ( isset( $fields['start_date'] ) && 'pending' == $subscription->get_status() ) {
383
-			unset( $fields['start_date'] );
384
-		}
385
-
386
-		if ( $subscription->get_initial_amount() == $subscription->get_recurring_amount() ) {
387
-			unset( $fields['initial_amount'] );
388
-		}
389
-
390
-		return $fields;
391
-	}
392
-
393
-	/**
394
-	 * Displays a single subscription.
395
-	 *
396
-	 * @param string $subscription
397
-	 *
398
-	 * @return string
399
-	 */
400
-	public function display_single_subscription( $subscription ) {
401
-
402
-		// Fetch the subscription.
403
-		$subscription = new WPInv_Subscription( (int) $subscription );
404
-
405
-		if ( ! $subscription->exists() ) {
406
-
407
-			return aui()->alert(
408
-				array(
409
-					'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ),
410
-					'type'    => 'error',
411
-				)
412
-			);
413
-
414
-		}
415
-
416
-		// Ensure that the user owns this subscription key.
417
-		if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) {
418
-
419
-			return aui()->alert(
420
-				array(
421
-					'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ),
422
-					'type'    => 'error',
423
-				)
424
-			);
425
-
426
-		}
427
-
428
-		return wpinv_get_template_html(
429
-			'subscriptions/subscription-details.php',
430
-			array(
431
-				'subscription' => $subscription,
432
-				'widget'       => $this
433
-			)
434
-		);
435
-
436
-	}
342
+    }
343
+
344
+    /**
345
+     * Returns a single subscription's columns.
346
+     *
347
+     * @param WPInv_Subscription $subscription
348
+     *
349
+     * @return array
350
+     */
351
+    public function get_single_subscription_columns( $subscription ) {
352
+
353
+        // Prepare subscription detail columns.
354
+        $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() );
355
+        $items_count        = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] );
356
+        $fields             = apply_filters(
357
+            'getpaid_single_subscription_details_fields',
358
+            array(
359
+                'status'           => __( 'Status', 'invoicing' ),
360
+                'initial_amount'   => __( 'Initial amount', 'invoicing' ),
361
+                'recurring_amount' => __( 'Recurring amount', 'invoicing' ),
362
+                'start_date'       => __( 'Start date', 'invoicing' ),
363
+                'expiry_date'      => __( 'Next payment', 'invoicing' ),
364
+                'payments'         => __( 'Payments', 'invoicing' ),
365
+                'item'             => _n( 'Item', 'Items', $items_count, 'invoicing' ),
366
+            ),
367
+            $subscription
368
+        );
369
+
370
+        if ( isset( $fields['expiry_date'] ) ) {
371
+
372
+            if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) {
373
+                $fields['expiry_date'] = __( 'End date', 'invoicing' );
374
+            }
375
+
376
+            if ( 'pending' == $subscription->get_status() ) {
377
+                unset( $fields['expiry_date'] );
378
+            }
379
+
380
+        }
381
+
382
+        if ( isset( $fields['start_date'] ) && 'pending' == $subscription->get_status() ) {
383
+            unset( $fields['start_date'] );
384
+        }
385
+
386
+        if ( $subscription->get_initial_amount() == $subscription->get_recurring_amount() ) {
387
+            unset( $fields['initial_amount'] );
388
+        }
389
+
390
+        return $fields;
391
+    }
392
+
393
+    /**
394
+     * Displays a single subscription.
395
+     *
396
+     * @param string $subscription
397
+     *
398
+     * @return string
399
+     */
400
+    public function display_single_subscription( $subscription ) {
401
+
402
+        // Fetch the subscription.
403
+        $subscription = new WPInv_Subscription( (int) $subscription );
404
+
405
+        if ( ! $subscription->exists() ) {
406
+
407
+            return aui()->alert(
408
+                array(
409
+                    'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ),
410
+                    'type'    => 'error',
411
+                )
412
+            );
413
+
414
+        }
415
+
416
+        // Ensure that the user owns this subscription key.
417
+        if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) {
418
+
419
+            return aui()->alert(
420
+                array(
421
+                    'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ),
422
+                    'type'    => 'error',
423
+                )
424
+            );
425
+
426
+        }
427
+
428
+        return wpinv_get_template_html(
429
+            'subscriptions/subscription-details.php',
430
+            array(
431
+                'subscription' => $subscription,
432
+                'widget'       => $this
433
+            )
434
+        );
435
+
436
+    }
437 437
 
438 438
 }
Please login to merge, or discard this patch.
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * @version 1.0.0
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * Contains the subscriptions widget.
@@ -27,15 +27,15 @@  discard block
 block discarded – undo
27 27
 			'block-keywords'=> "['invoicing','subscriptions', 'getpaid']",
28 28
 			'class_name'     => __CLASS__,
29 29
 			'base_id'       => 'wpinv_subscriptions',
30
-			'name'          => __( 'GetPaid > Subscriptions', 'invoicing' ),
30
+			'name'          => __('GetPaid > Subscriptions', 'invoicing'),
31 31
 			'widget_ops'    => array(
32 32
 				'classname'   => 'getpaid-subscriptions bsui',
33
-				'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ),
33
+				'description' => esc_html__("Displays the current user's subscriptions.", 'invoicing'),
34 34
 			),
35 35
 			'arguments'     => array(
36 36
 				'title'  => array(
37
-					'title'       => __( 'Widget title', 'invoicing' ),
38
-					'desc'        => __( 'Enter widget title.', 'invoicing' ),
37
+					'title'       => __('Widget title', 'invoicing'),
38
+					'desc'        => __('Enter widget title.', 'invoicing'),
39 39
 					'type'        => 'text',
40 40
 					'desc_tip'    => true,
41 41
 					'default'     => '',
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 		);
47 47
 
48 48
 
49
-		parent::__construct( $options );
49
+		parent::__construct($options);
50 50
 	}
51 51
 
52 52
 	/**
@@ -57,12 +57,12 @@  discard block
 block discarded – undo
57 57
 	public function get_subscriptions() {
58 58
 
59 59
 		// Prepare license args.
60
-		$args  = array(
60
+		$args = array(
61 61
 			'customer_in' => get_current_user_id(),
62
-			'paged'       => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1,
62
+			'paged'       => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1,
63 63
 		);
64 64
 
65
-		return new GetPaid_Subscriptions_Query( $args );
65
+		return new GetPaid_Subscriptions_Query($args);
66 66
 
67 67
 	}
68 68
 
@@ -75,14 +75,14 @@  discard block
 block discarded – undo
75 75
 	 *
76 76
 	 * @return mixed|string|bool
77 77
 	 */
78
-	public function output( $args = array(), $widget_args = array(), $content = '' ) {
78
+	public function output($args = array(), $widget_args = array(), $content = '') {
79 79
 
80 80
 		// Ensure that the user is logged in.
81
-		if ( ! is_user_logged_in() ) {
81
+		if (!is_user_logged_in()) {
82 82
 
83 83
 			return aui()->alert(
84 84
 				array(
85
-					'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ),
85
+					'content' => wp_kses_post(__('You need to log-in or create an account to view this section.', 'invoicing')),
86 86
 					'type'    => 'error',
87 87
 				)
88 88
 			);
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
 		}
91 91
 
92 92
 		// Are we displaying a single subscription?
93
-		if ( isset( $_GET['subscription'] ) ) {
94
-			return $this->display_single_subscription( intval( $_GET['subscription'] ) );
93
+		if (isset($_GET['subscription'])) {
94
+			return $this->display_single_subscription(intval($_GET['subscription']));
95 95
 		}
96 96
 
97 97
 		// Retrieve the user's subscriptions.
@@ -101,27 +101,27 @@  discard block
 block discarded – undo
101 101
 		ob_start();
102 102
 
103 103
 		// Backwards compatibility.
104
-		do_action( 'wpinv_before_user_subscriptions' );
104
+		do_action('wpinv_before_user_subscriptions');
105 105
 
106 106
 		// Display errors and notices.
107 107
 		wpinv_print_errors();
108 108
 
109
-		do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions );
109
+		do_action('getpaid_license_manager_before_subscriptions', $subscriptions);
110 110
 
111 111
 		// Print the table header.
112 112
 		$this->print_table_header();
113 113
 
114 114
 		// Print table body.
115
-		$this->print_table_body( $subscriptions->get_results() );
115
+		$this->print_table_body($subscriptions->get_results());
116 116
 
117 117
 		// Print table footer.
118 118
 		$this->print_table_footer();
119 119
 
120 120
 		// Print the navigation.
121
-		$this->print_navigation( $subscriptions->get_total() );
121
+		$this->print_navigation($subscriptions->get_total());
122 122
 
123 123
 		// Backwards compatibility.
124
-		do_action( 'wpinv_after_user_subscriptions' );
124
+		do_action('wpinv_after_user_subscriptions');
125 125
 
126 126
 		// Return the output.
127 127
 		return ob_get_clean();
@@ -136,13 +136,13 @@  discard block
 block discarded – undo
136 136
 	public function get_subscriptions_table_columns() {
137 137
 
138 138
 		$columns = array(
139
-			'subscription'   => __( 'Subscription', 'invoicing' ),
140
-			'amount'         => __( 'Amount', 'invoicing' ),
141
-			'renewal-date'   => __( 'Next payment', 'invoicing' ),
142
-			'status'         => __( 'Status', 'invoicing' ),
139
+			'subscription'   => __('Subscription', 'invoicing'),
140
+			'amount'         => __('Amount', 'invoicing'),
141
+			'renewal-date'   => __('Next payment', 'invoicing'),
142
+			'status'         => __('Status', 'invoicing'),
143 143
 		);
144 144
 
145
-		return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns );
145
+		return apply_filters('getpaid_frontend_subscriptions_table_columns', $columns);
146 146
 	}
147 147
 
148 148
 	/**
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
 
158 158
 				<thead>
159 159
 					<tr>
160
-						<?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?>
161
-							<th scope="col" class="font-weight-bold getpaid-subscriptions-table-<?php echo sanitize_html_class( $key ); ?>">
162
-								<?php echo esc_html( $label ); ?>
160
+						<?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?>
161
+							<th scope="col" class="font-weight-bold getpaid-subscriptions-table-<?php echo sanitize_html_class($key); ?>">
162
+								<?php echo esc_html($label); ?>
163 163
 							</th>
164 164
 						<?php endforeach; ?>
165 165
 					</tr>
@@ -174,12 +174,12 @@  discard block
 block discarded – undo
174 174
 	 *
175 175
 	 * @param WPInv_Subscription[] $subscriptions
176 176
 	 */
177
-	public function print_table_body( $subscriptions ) {
177
+	public function print_table_body($subscriptions) {
178 178
 
179
-		if ( empty( $subscriptions ) ) {
179
+		if (empty($subscriptions)) {
180 180
 			$this->print_table_body_no_subscriptions();
181 181
 		} else {
182
-			$this->print_table_body_subscriptions( $subscriptions );
182
+			$this->print_table_body_subscriptions($subscriptions);
183 183
 		}
184 184
 
185 185
 	}
@@ -194,12 +194,12 @@  discard block
 block discarded – undo
194 194
 		<tbody>
195 195
 
196 196
 			<tr>
197
-				<td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>">
197
+				<td colspan="<?php echo count($this->get_subscriptions_table_columns()); ?>">
198 198
 
199 199
 					<?php
200 200
 						echo aui()->alert(
201 201
 							array(
202
-								'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ),
202
+								'content' => wp_kses_post(__('No subscriptions found.', 'invoicing')),
203 203
 								'type'    => 'warning',
204 204
 							)
205 205
 						);
@@ -217,12 +217,12 @@  discard block
 block discarded – undo
217 217
 	 *
218 218
 	 * @param WPInv_Subscription[] $subscriptions
219 219
 	 */
220
-	public function print_table_body_subscriptions( $subscriptions ) {
220
+	public function print_table_body_subscriptions($subscriptions) {
221 221
 
222 222
 		?>
223 223
 		<tbody>
224 224
 
225
-			<?php foreach ( $subscriptions as $subscription ) : ?>
225
+			<?php foreach ($subscriptions as $subscription) : ?>
226 226
 				<tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>">
227 227
 					<?php
228 228
 						wpinv_get_template(
@@ -248,28 +248,28 @@  discard block
 block discarded – undo
248 248
 	 * @since       1.0.0
249 249
 	 * @return      string
250 250
 	 */
251
-	public function add_row_actions( $content, $subscription ) {
251
+	public function add_row_actions($content, $subscription) {
252 252
 
253 253
 		// Prepare row actions.
254 254
 		$actions = array();
255 255
 
256 256
 		// View subscription action.
257
-		$view_url        = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
258
-		$view_url        = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) );
259
-		$actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>';
257
+		$view_url        = getpaid_get_tab_url('gp-subscriptions', get_permalink((int) wpinv_get_option('invoice_subscription_page')));
258
+		$view_url        = esc_url(add_query_arg('subscription', (int) $subscription->get_id(), $view_url));
259
+		$actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __('Manage Subscription', 'invoicing') . '</a>';
260 260
 
261 261
 		// Filter the actions.
262
-		$actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription );
262
+		$actions = apply_filters('getpaid_subscriptions_table_subscription_actions', $actions, $subscription);
263 263
 
264
-		$sanitized  = array();
265
-		foreach ( $actions as $key => $action ) {
266
-			$key         = sanitize_html_class( $key );
267
-			$action      = wp_kses_post( $action );
264
+		$sanitized = array();
265
+		foreach ($actions as $key => $action) {
266
+			$key         = sanitize_html_class($key);
267
+			$action      = wp_kses_post($action);
268 268
 			$sanitized[] = "<span class='$key'>$action</span>";
269 269
 		}
270 270
 
271 271
 		$row_actions  = "<small class='form-text getpaid-subscription-item-actions'>";
272
-		$row_actions .= implode( ' | ', $sanitized );
272
+		$row_actions .= implode(' | ', $sanitized);
273 273
 		$row_actions .= '</small>';
274 274
 
275 275
 		return $content . $row_actions;
@@ -285,9 +285,9 @@  discard block
 block discarded – undo
285 285
 
286 286
 				<tfoot>
287 287
 					<tr>
288
-						<?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?>
289
-							<th class="font-weight-bold getpaid-subscriptions-<?php echo sanitize_html_class( $key ); ?>">
290
-								<?php echo esc_html( $label ); ?>
288
+						<?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?>
289
+							<th class="font-weight-bold getpaid-subscriptions-<?php echo sanitize_html_class($key); ?>">
290
+								<?php echo esc_html($label); ?>
291 291
 							</th>
292 292
 						<?php endforeach; ?>
293 293
 					</tr>
@@ -303,22 +303,22 @@  discard block
 block discarded – undo
303 303
 	 *
304 304
 	 * @param int $total
305 305
 	 */
306
-	public function print_navigation( $total ) {
306
+	public function print_navigation($total) {
307 307
 
308
-		if ( $total < 1 ) {
308
+		if ($total < 1) {
309 309
 
310 310
 			// Out-of-bounds, run the query again without LIMIT for total count.
311
-			$args  = array(
311
+			$args = array(
312 312
 				'customer_in' => get_current_user_id(),
313 313
 				'fields'      => 'id',
314 314
 			);
315 315
 
316
-			$count_query = new GetPaid_Subscriptions_Query( $args );
316
+			$count_query = new GetPaid_Subscriptions_Query($args);
317 317
 			$total       = $count_query->get_total();
318 318
 		}
319 319
 
320 320
 		// Abort if we do not have pages.
321
-		if ( 2 > $total ) {
321
+		if (2 > $total) {
322 322
 			return;
323 323
 		}
324 324
 
@@ -330,9 +330,9 @@  discard block
 block discarded – undo
330 330
 
331 331
 				echo getpaid_paginate_links(
332 332
 					array(
333
-						'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
333
+						'base'    => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
334 334
 						'format'  => '?paged=%#%',
335
-						'total'   => (int) ceil( $total / 10 ),
335
+						'total'   => (int) ceil($total / 10),
336 336
 					)
337 337
 				);
338 338
 			?>
@@ -348,43 +348,43 @@  discard block
 block discarded – undo
348 348
 	 *
349 349
 	 * @return array
350 350
 	 */
351
-	public function get_single_subscription_columns( $subscription ) {
351
+	public function get_single_subscription_columns($subscription) {
352 352
 
353 353
 		// Prepare subscription detail columns.
354
-		$subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() );
355
-		$items_count        = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] );
354
+		$subscription_group = getpaid_get_invoice_subscription_group($subscription->get_parent_invoice_id(), $subscription->get_id());
355
+		$items_count        = empty($subscription_group) ? 1 : count($subscription_group['items']);
356 356
 		$fields             = apply_filters(
357 357
 			'getpaid_single_subscription_details_fields',
358 358
 			array(
359
-				'status'           => __( 'Status', 'invoicing' ),
360
-				'initial_amount'   => __( 'Initial amount', 'invoicing' ),
361
-				'recurring_amount' => __( 'Recurring amount', 'invoicing' ),
362
-				'start_date'       => __( 'Start date', 'invoicing' ),
363
-				'expiry_date'      => __( 'Next payment', 'invoicing' ),
364
-				'payments'         => __( 'Payments', 'invoicing' ),
365
-				'item'             => _n( 'Item', 'Items', $items_count, 'invoicing' ),
359
+				'status'           => __('Status', 'invoicing'),
360
+				'initial_amount'   => __('Initial amount', 'invoicing'),
361
+				'recurring_amount' => __('Recurring amount', 'invoicing'),
362
+				'start_date'       => __('Start date', 'invoicing'),
363
+				'expiry_date'      => __('Next payment', 'invoicing'),
364
+				'payments'         => __('Payments', 'invoicing'),
365
+				'item'             => _n('Item', 'Items', $items_count, 'invoicing'),
366 366
 			),
367 367
 			$subscription
368 368
 		);
369 369
 
370
-		if ( isset( $fields['expiry_date'] ) ) {
370
+		if (isset($fields['expiry_date'])) {
371 371
 
372
-			if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) {
373
-				$fields['expiry_date'] = __( 'End date', 'invoicing' );
372
+			if (!$subscription->is_active() || $subscription->is_last_renewal()) {
373
+				$fields['expiry_date'] = __('End date', 'invoicing');
374 374
 			}
375 375
 
376
-			if ( 'pending' == $subscription->get_status() ) {
377
-				unset( $fields['expiry_date'] );
376
+			if ('pending' == $subscription->get_status()) {
377
+				unset($fields['expiry_date']);
378 378
 			}
379 379
 
380 380
 		}
381 381
 
382
-		if ( isset( $fields['start_date'] ) && 'pending' == $subscription->get_status() ) {
383
-			unset( $fields['start_date'] );
382
+		if (isset($fields['start_date']) && 'pending' == $subscription->get_status()) {
383
+			unset($fields['start_date']);
384 384
 		}
385 385
 
386
-		if ( $subscription->get_initial_amount() == $subscription->get_recurring_amount() ) {
387
-			unset( $fields['initial_amount'] );
386
+		if ($subscription->get_initial_amount() == $subscription->get_recurring_amount()) {
387
+			unset($fields['initial_amount']);
388 388
 		}
389 389
 
390 390
 		return $fields;
@@ -397,16 +397,16 @@  discard block
 block discarded – undo
397 397
 	 *
398 398
 	 * @return string
399 399
 	 */
400
-	public function display_single_subscription( $subscription ) {
400
+	public function display_single_subscription($subscription) {
401 401
 
402 402
 		// Fetch the subscription.
403
-		$subscription = new WPInv_Subscription( (int) $subscription );
403
+		$subscription = new WPInv_Subscription((int) $subscription);
404 404
 
405
-		if ( ! $subscription->exists() ) {
405
+		if (!$subscription->exists()) {
406 406
 
407 407
 			return aui()->alert(
408 408
 				array(
409
-					'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ),
409
+					'content' => wp_kses_post(__('Subscription not found.', 'invoicing')),
410 410
 					'type'    => 'error',
411 411
 				)
412 412
 			);
@@ -414,11 +414,11 @@  discard block
 block discarded – undo
414 414
 		}
415 415
 
416 416
 		// Ensure that the user owns this subscription key.
417
-		if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) {
417
+		if (get_current_user_id() != $subscription->get_customer_id() && !wpinv_current_user_can_manage_invoicing()) {
418 418
 
419 419
 			return aui()->alert(
420 420
 				array(
421
-					'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ),
421
+					'content' => wp_kses_post(__('You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing')),
422 422
 					'type'    => 'error',
423 423
 				)
424 424
 			);
Please login to merge, or discard this patch.
includes/reports/class-getpaid-reports-report.php 2 patches
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -12,88 +12,88 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Reports_Report {
14 14
 
15
-	/**
16
-	 * @var array
17
-	 */
18
-	public $views;
15
+    /**
16
+     * @var array
17
+     */
18
+    public $views;
19 19
 
20
-	/**
21
-	 * Class constructor.
22
-	 *
23
-	 */
24
-	public function __construct() {
20
+    /**
21
+     * Class constructor.
22
+     *
23
+     */
24
+    public function __construct() {
25 25
 
26
-		$this->views        = array(
26
+        $this->views        = array(
27 27
 
28 28
             'items'     => array(
29
-				'label' => __( 'Items', 'invoicing' ),
30
-				'class' => 'GetPaid_Reports_Report_Items',
31
-			),
29
+                'label' => __( 'Items', 'invoicing' ),
30
+                'class' => 'GetPaid_Reports_Report_Items',
31
+            ),
32 32
 
33
-			'gateways'  => array(
34
-				'label' => __( 'Payment Methods', 'invoicing' ),
35
-				'class' => 'GetPaid_Reports_Report_Gateways',
36
-			),
33
+            'gateways'  => array(
34
+                'label' => __( 'Payment Methods', 'invoicing' ),
35
+                'class' => 'GetPaid_Reports_Report_Gateways',
36
+            ),
37 37
 
38
-			'discounts'  => array(
39
-				'label' => __( 'Discount Codes', 'invoicing' ),
40
-				'class' => 'GetPaid_Reports_Report_Discounts',
41
-			),
38
+            'discounts'  => array(
39
+                'label' => __( 'Discount Codes', 'invoicing' ),
40
+                'class' => 'GetPaid_Reports_Report_Discounts',
41
+            ),
42 42
 
43 43
         );
44 44
 
45
-		$this->views        = apply_filters( 'wpinv_report_views', $this->views );
46
-
47
-	}
48
-
49
-	/**
50
-	 * Retrieves the current range.
51
-	 *
52
-	 */
53
-	public function get_range() {
54
-		$valid_ranges = $this->get_periods();
55
-
56
-		if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) {
57
-			return sanitize_key( $_GET['date_range'] );
58
-		}
59
-
60
-		return '7_days';
61
-	}
62
-
63
-	/**
64
-	 * Returns an array of date ranges.
65
-	 *
66
-	 * @return array
67
-	 */
68
-	public function get_periods() {
69
-
70
-		$periods = array(
71
-			'today'        => __( 'Today', 'invoicing' ),
72
-			'yesterday'    => __( 'Yesterday', 'invoicing' ),
73
-			'week'         => __( 'This week', 'invoicing' ),
74
-			'last_week'    => __( 'Last week', 'invoicing' ),
75
-			'7_days'       => __( 'Last 7 days', 'invoicing' ),
76
-			'month'        => __( 'This month', 'invoicing' ),
77
-			'last_month'   => __( 'Last month', 'invoicing' ),
78
-			'30_days'      => __( 'Last 30 days', 'invoicing' ),
79
-			'quarter'      => __( 'This Quarter', 'invoicing' ),
80
-			'last_quarter' => __( 'Last Quarter', 'invoicing' ),
81
-			'year'         => __( 'This year', 'invoicing' ),
82
-			'last_year'    => __( 'Last Year', 'invoicing' ),
83
-			'custom'       => __( 'Custom Date Range', 'invoicing' ),
84
-		);
85
-
86
-		return apply_filters( 'getpaid_earning_periods', $periods );
87
-	}
88
-
89
-	/**
90
-	 * Displays the range selector.
91
-	 *
92
-	 */
93
-	public function display_range_selector() {
94
-
95
-		$range = $this->get_range();
96
-		?>
45
+        $this->views        = apply_filters( 'wpinv_report_views', $this->views );
46
+
47
+    }
48
+
49
+    /**
50
+     * Retrieves the current range.
51
+     *
52
+     */
53
+    public function get_range() {
54
+        $valid_ranges = $this->get_periods();
55
+
56
+        if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) {
57
+            return sanitize_key( $_GET['date_range'] );
58
+        }
59
+
60
+        return '7_days';
61
+    }
62
+
63
+    /**
64
+     * Returns an array of date ranges.
65
+     *
66
+     * @return array
67
+     */
68
+    public function get_periods() {
69
+
70
+        $periods = array(
71
+            'today'        => __( 'Today', 'invoicing' ),
72
+            'yesterday'    => __( 'Yesterday', 'invoicing' ),
73
+            'week'         => __( 'This week', 'invoicing' ),
74
+            'last_week'    => __( 'Last week', 'invoicing' ),
75
+            '7_days'       => __( 'Last 7 days', 'invoicing' ),
76
+            'month'        => __( 'This month', 'invoicing' ),
77
+            'last_month'   => __( 'Last month', 'invoicing' ),
78
+            '30_days'      => __( 'Last 30 days', 'invoicing' ),
79
+            'quarter'      => __( 'This Quarter', 'invoicing' ),
80
+            'last_quarter' => __( 'Last Quarter', 'invoicing' ),
81
+            'year'         => __( 'This year', 'invoicing' ),
82
+            'last_year'    => __( 'Last Year', 'invoicing' ),
83
+            'custom'       => __( 'Custom Date Range', 'invoicing' ),
84
+        );
85
+
86
+        return apply_filters( 'getpaid_earning_periods', $periods );
87
+    }
88
+
89
+    /**
90
+     * Displays the range selector.
91
+     *
92
+     */
93
+    public function display_range_selector() {
94
+
95
+        $range = $this->get_range();
96
+        ?>
97 97
 
98 98
 			<form method="get" class="getpaid-filter-earnings float-right">
99 99
 				<?php getpaid_hidden_field( 'page', isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : 'wpinv-reports' );  ?>
@@ -115,14 +115,14 @@  discard block
 block discarded – undo
115 115
 			</form>
116 116
 
117 117
 		<?php
118
-	}
118
+    }
119 119
 
120
-	/**
121
-	 * Displays the reports tab.
122
-	 *
123
-	 */
124
-	public function display() {
125
-		?>
120
+    /**
121
+     * Displays the reports tab.
122
+     *
123
+     */
124
+    public function display() {
125
+        ?>
126 126
 
127 127
 		<div class="mt-4">
128 128
 
@@ -202,16 +202,16 @@  discard block
 block discarded – undo
202 202
 
203 203
 		<?php
204 204
 
205
-	}
205
+    }
206 206
 
207
-	/**
208
-	 * Displays the left side.
209
-	 *
210
-	 */
211
-	public function display_left() {
212
-		$graphs = wpinv_get_report_graphs();
207
+    /**
208
+     * Displays the left side.
209
+     *
210
+     */
211
+    public function display_left() {
212
+        $graphs = wpinv_get_report_graphs();
213 213
 
214
-		?>
214
+        ?>
215 215
 
216 216
 			<?php foreach ( $graphs as $key => $graph ) : ?>
217 217
 				<div class="row mb-4">
@@ -230,35 +230,35 @@  discard block
 block discarded – undo
230 230
 
231 231
 		<?php
232 232
 
233
-	}
234
-
235
-	/**
236
-	 * Retrieves the download url.
237
-	 *
238
-	 */
239
-	public function get_download_url( $graph, $file_type ) {
240
-
241
-		return wp_nonce_url(
242
-			add_query_arg(
243
-				array(
244
-					'getpaid-admin-action' => 'download_graph',
245
-					'file_type'            => urlencode( $file_type ),
246
-					'graph'                => urlencode( $graph ),
247
-				)
248
-			),
249
-			'getpaid-nonce',
250
-			'getpaid-nonce'
251
-		);
233
+    }
234
+
235
+    /**
236
+     * Retrieves the download url.
237
+     *
238
+     */
239
+    public function get_download_url( $graph, $file_type ) {
240
+
241
+        return wp_nonce_url(
242
+            add_query_arg(
243
+                array(
244
+                    'getpaid-admin-action' => 'download_graph',
245
+                    'file_type'            => urlencode( $file_type ),
246
+                    'graph'                => urlencode( $graph ),
247
+                )
248
+            ),
249
+            'getpaid-nonce',
250
+            'getpaid-nonce'
251
+        );
252 252
 
253
-	}
253
+    }
254 254
 
255
-	/**
256
-	 * Displays the right side.
257
-	 *
258
-	 */
259
-	public function display_right() {
255
+    /**
256
+     * Displays the right side.
257
+     *
258
+     */
259
+    public function display_right() {
260 260
 
261
-		?>
261
+        ?>
262 262
 
263 263
 			<?php foreach ( $this->views as $key => $view ) : ?>
264 264
 				<div class="row mb-4">
@@ -287,10 +287,10 @@  discard block
 block discarded – undo
287 287
 							</div>
288 288
 							<div class="card-body">
289 289
 								<?php
290
-									$class = $view['class'];
291
-									$class = new $class();
292
-									$class->display_stats();
293
-								?>
290
+                                    $class = $view['class'];
291
+                                    $class = new $class();
292
+                                    $class->display_stats();
293
+                                ?>
294 294
 							</div>
295 295
 						</div>
296 296
 					</div>
@@ -299,68 +299,68 @@  discard block
 block discarded – undo
299 299
 
300 300
 		<?php
301 301
 
302
-		do_action( 'getpaid_reports_display_right', $this );
303
-	}
304
-
305
-	/**
306
-	 * Returns a list of report cards.
307
-	 *
308
-	 */
309
-	public function get_cards() {
310
-
311
-		$cards = array(
312
-			'total_sales' => array(
313
-				'description' => __( 'Gross sales in the period.', 'invoicing' ),
314
-				'label'       => __( 'Gross Revenue', 'invoicing' ),
315
-			),
316
-			'net_sales' => array(
317
-				'description' => __( 'Net sales in the period.', 'invoicing' ),
318
-				'label'       => __( 'Net Revenue', 'invoicing' ),
319
-			),
320
-			'average_sales' => array(
321
-				'description' => __( 'Average net daily/monthly sales.', 'invoicing' ),
322
-				'label'       => __( 'Avg. Net Sales', 'invoicing' ),
323
-			),
324
-			'average_total_sales' => array(
325
-				'description' => __( 'Average gross daily/monthly sales.', 'invoicing' ),
326
-				'label'       => __( 'Avg. Gross Sales', 'invoicing' ),
327
-			),
328
-			'total_invoices'  => array(
329
-				'description' => __( 'Number of paid invoices.', 'invoicing' ),
330
-				'label'       => __( 'Paid Invoices', 'invoicing' ),
331
-			),
332
-			'total_items' => array(
333
-				'description' => __( 'Number of items purchased.', 'invoicing' ),
334
-				'label'       => __( 'Purchased Items', 'invoicing' ),
335
-			),
336
-			'refunded_items' => array(
337
-				'description' => __( 'Number of items refunded.', 'invoicing' ),
338
-				'label'       => __( 'Refunded Items', 'invoicing' ),
339
-			),
340
-			'total_tax' => array(
341
-				'description' => __( 'Total charged for taxes.', 'invoicing' ),
342
-				'label'       => __( 'Tax', 'invoicing' ),
343
-			),
344
-			'total_refunded_tax' => array(
345
-				'description' => __( 'Total refunded for taxes.', 'invoicing' ),
346
-				'label'       => __( 'Refunded Tax', 'invoicing' ),
347
-			),
348
-			'total_fees' => array(
349
-				'description' => __( 'Total fees charged.', 'invoicing' ),
350
-				'label'       => __( 'Fees', 'invoicing' ),
351
-			),
352
-			'total_refunds' => array(
353
-				'description' => __( 'Total of refunded invoices.', 'invoicing' ),
354
-				'label'       => __( 'Refunded', 'invoicing' ),
355
-			),
356
-			'total_discount'  => array(
357
-				'description' => __( 'Total of discounts used.', 'invoicing' ),
358
-				'label'       => __( 'Discounted', 'invoicing' ),
359
-			),
360
-		);
361
-
362
-		return apply_filters( 'wpinv_report_cards', $cards );
363
-	}
302
+        do_action( 'getpaid_reports_display_right', $this );
303
+    }
304
+
305
+    /**
306
+     * Returns a list of report cards.
307
+     *
308
+     */
309
+    public function get_cards() {
310
+
311
+        $cards = array(
312
+            'total_sales' => array(
313
+                'description' => __( 'Gross sales in the period.', 'invoicing' ),
314
+                'label'       => __( 'Gross Revenue', 'invoicing' ),
315
+            ),
316
+            'net_sales' => array(
317
+                'description' => __( 'Net sales in the period.', 'invoicing' ),
318
+                'label'       => __( 'Net Revenue', 'invoicing' ),
319
+            ),
320
+            'average_sales' => array(
321
+                'description' => __( 'Average net daily/monthly sales.', 'invoicing' ),
322
+                'label'       => __( 'Avg. Net Sales', 'invoicing' ),
323
+            ),
324
+            'average_total_sales' => array(
325
+                'description' => __( 'Average gross daily/monthly sales.', 'invoicing' ),
326
+                'label'       => __( 'Avg. Gross Sales', 'invoicing' ),
327
+            ),
328
+            'total_invoices'  => array(
329
+                'description' => __( 'Number of paid invoices.', 'invoicing' ),
330
+                'label'       => __( 'Paid Invoices', 'invoicing' ),
331
+            ),
332
+            'total_items' => array(
333
+                'description' => __( 'Number of items purchased.', 'invoicing' ),
334
+                'label'       => __( 'Purchased Items', 'invoicing' ),
335
+            ),
336
+            'refunded_items' => array(
337
+                'description' => __( 'Number of items refunded.', 'invoicing' ),
338
+                'label'       => __( 'Refunded Items', 'invoicing' ),
339
+            ),
340
+            'total_tax' => array(
341
+                'description' => __( 'Total charged for taxes.', 'invoicing' ),
342
+                'label'       => __( 'Tax', 'invoicing' ),
343
+            ),
344
+            'total_refunded_tax' => array(
345
+                'description' => __( 'Total refunded for taxes.', 'invoicing' ),
346
+                'label'       => __( 'Refunded Tax', 'invoicing' ),
347
+            ),
348
+            'total_fees' => array(
349
+                'description' => __( 'Total fees charged.', 'invoicing' ),
350
+                'label'       => __( 'Fees', 'invoicing' ),
351
+            ),
352
+            'total_refunds' => array(
353
+                'description' => __( 'Total of refunded invoices.', 'invoicing' ),
354
+                'label'       => __( 'Refunded', 'invoicing' ),
355
+            ),
356
+            'total_discount'  => array(
357
+                'description' => __( 'Total of discounts used.', 'invoicing' ),
358
+                'label'       => __( 'Discounted', 'invoicing' ),
359
+            ),
360
+        );
361
+
362
+        return apply_filters( 'wpinv_report_cards', $cards );
363
+    }
364 364
 
365 365
 	
366 366
 
Please login to merge, or discard this patch.
Spacing   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * GetPaid_Reports_Report Class.
@@ -23,26 +23,26 @@  discard block
 block discarded – undo
23 23
 	 */
24 24
 	public function __construct() {
25 25
 
26
-		$this->views        = array(
26
+		$this->views = array(
27 27
 
28 28
             'items'     => array(
29
-				'label' => __( 'Items', 'invoicing' ),
29
+				'label' => __('Items', 'invoicing'),
30 30
 				'class' => 'GetPaid_Reports_Report_Items',
31 31
 			),
32 32
 
33 33
 			'gateways'  => array(
34
-				'label' => __( 'Payment Methods', 'invoicing' ),
34
+				'label' => __('Payment Methods', 'invoicing'),
35 35
 				'class' => 'GetPaid_Reports_Report_Gateways',
36 36
 			),
37 37
 
38 38
 			'discounts'  => array(
39
-				'label' => __( 'Discount Codes', 'invoicing' ),
39
+				'label' => __('Discount Codes', 'invoicing'),
40 40
 				'class' => 'GetPaid_Reports_Report_Discounts',
41 41
 			),
42 42
 
43 43
         );
44 44
 
45
-		$this->views        = apply_filters( 'wpinv_report_views', $this->views );
45
+		$this->views = apply_filters('wpinv_report_views', $this->views);
46 46
 
47 47
 	}
48 48
 
@@ -53,8 +53,8 @@  discard block
 block discarded – undo
53 53
 	public function get_range() {
54 54
 		$valid_ranges = $this->get_periods();
55 55
 
56
-		if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) {
57
-			return sanitize_key( $_GET['date_range'] );
56
+		if (isset($_GET['date_range']) && array_key_exists($_GET['date_range'], $valid_ranges)) {
57
+			return sanitize_key($_GET['date_range']);
58 58
 		}
59 59
 
60 60
 		return '7_days';
@@ -68,22 +68,22 @@  discard block
 block discarded – undo
68 68
 	public function get_periods() {
69 69
 
70 70
 		$periods = array(
71
-			'today'        => __( 'Today', 'invoicing' ),
72
-			'yesterday'    => __( 'Yesterday', 'invoicing' ),
73
-			'week'         => __( 'This week', 'invoicing' ),
74
-			'last_week'    => __( 'Last week', 'invoicing' ),
75
-			'7_days'       => __( 'Last 7 days', 'invoicing' ),
76
-			'month'        => __( 'This month', 'invoicing' ),
77
-			'last_month'   => __( 'Last month', 'invoicing' ),
78
-			'30_days'      => __( 'Last 30 days', 'invoicing' ),
79
-			'quarter'      => __( 'This Quarter', 'invoicing' ),
80
-			'last_quarter' => __( 'Last Quarter', 'invoicing' ),
81
-			'year'         => __( 'This year', 'invoicing' ),
82
-			'last_year'    => __( 'Last Year', 'invoicing' ),
83
-			'custom'       => __( 'Custom Date Range', 'invoicing' ),
71
+			'today'        => __('Today', 'invoicing'),
72
+			'yesterday'    => __('Yesterday', 'invoicing'),
73
+			'week'         => __('This week', 'invoicing'),
74
+			'last_week'    => __('Last week', 'invoicing'),
75
+			'7_days'       => __('Last 7 days', 'invoicing'),
76
+			'month'        => __('This month', 'invoicing'),
77
+			'last_month'   => __('Last month', 'invoicing'),
78
+			'30_days'      => __('Last 30 days', 'invoicing'),
79
+			'quarter'      => __('This Quarter', 'invoicing'),
80
+			'last_quarter' => __('Last Quarter', 'invoicing'),
81
+			'year'         => __('This year', 'invoicing'),
82
+			'last_year'    => __('Last Year', 'invoicing'),
83
+			'custom'       => __('Custom Date Range', 'invoicing'),
84 84
 		);
85 85
 
86
-		return apply_filters( 'getpaid_earning_periods', $periods );
86
+		return apply_filters('getpaid_earning_periods', $periods);
87 87
 	}
88 88
 
89 89
 	/**
@@ -96,21 +96,21 @@  discard block
 block discarded – undo
96 96
 		?>
97 97
 
98 98
 			<form method="get" class="getpaid-filter-earnings float-right">
99
-				<?php getpaid_hidden_field( 'page', isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : 'wpinv-reports' );  ?>
100
-				<?php getpaid_hidden_field( 'tab', 'reports' );  ?>
99
+				<?php getpaid_hidden_field('page', isset($_GET['page']) ? sanitize_text_field($_GET['page']) : 'wpinv-reports'); ?>
100
+				<?php getpaid_hidden_field('tab', 'reports'); ?>
101 101
 				<select name='date_range'>
102
-					<?php foreach( $this->get_periods() as $key => $label ) :?>
103
-						<option value="<?php echo esc_attr( $key ); ?>" <?php selected( $key, $range ); ?>><?php echo esc_html( $label ); ?></option>
104
-					<?php endforeach;?>
102
+					<?php foreach ($this->get_periods() as $key => $label) :?>
103
+						<option value="<?php echo esc_attr($key); ?>" <?php selected($key, $range); ?>><?php echo esc_html($label); ?></option>
104
+					<?php endforeach; ?>
105 105
 				</select>
106 106
 				<span class="getpaid-date-range-picker <?php echo 'custom' == $range ? '' : 'd-none'; ?>">
107 107
 					<input type="text" name="from" class="getpaid-from align-middle" />
108
-						<?php _e( 'to', 'invoicing' ); ?>
108
+						<?php _e('to', 'invoicing'); ?>
109 109
 					<input type="text" name="to" class="getpaid-to align-middle" />
110 110
 				</span>
111 111
 				<button type="submit" class="button button-primary">
112 112
 					<i class="fa fa-chevron-right fa-lg"></i>
113
-					<span class="screen-reader-text"><?php _e( 'View Reports', 'invoicing' ); ?></span>
113
+					<span class="screen-reader-text"><?php _e('View Reports', 'invoicing'); ?></span>
114 114
 				</button>
115 115
 			</form>
116 116
 
@@ -159,17 +159,17 @@  discard block
 block discarded – undo
159 159
 
160 160
 				<div class="col-12 col-md-4">
161 161
 					<div class="row getpaid-report-cards">
162
-						<?php foreach( $this->get_cards() as $key => $card ) : ?>
162
+						<?php foreach ($this->get_cards() as $key => $card) : ?>
163 163
 							<div class="col-12 mb-4">
164 164
 
165
-								<!-- <?php echo esc_html(  $card['label']  ); ?> Card -->
166
-								<div class="card p-0 m-0 shadow-none <?php echo sanitize_html_class( $key ); ?>">
165
+								<!-- <?php echo esc_html($card['label']); ?> Card -->
166
+								<div class="card p-0 m-0 shadow-none <?php echo sanitize_html_class($key); ?>">
167 167
 
168 168
 									<div class="card-body">
169 169
 
170 170
 										<p class="getpaid-current text-uppercase small mb-2">
171
-											<strong><?php echo esc_html( $card['label']  ); ?></strong>
172
-											<span title="<?php echo esc_attr( $card['description'] ); ?>" class="wpi-help-tip dashicons dashicons-editor-help text-muted" style="margin-top: -2px;"></span>
171
+											<strong><?php echo esc_html($card['label']); ?></strong>
172
+											<span title="<?php echo esc_attr($card['description']); ?>" class="wpi-help-tip dashicons dashicons-editor-help text-muted" style="margin-top: -2px;"></span>
173 173
 										</p>
174 174
 										<h5 class="font-weight-bold mb-0">
175 175
 											<span class="getpaid-report-card-value">
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 
181 181
 										<hr>
182 182
 
183
-										<p class="getpaid-previous text-uppercase text-muted small mb-2"><strong><?php _e( 'Previous Period', 'invoicing' ); ?></strong></p>
183
+										<p class="getpaid-previous text-uppercase text-muted small mb-2"><strong><?php _e('Previous Period', 'invoicing'); ?></strong></p>
184 184
 										<h5 class="getpaid-report-card-previous-value font-weight-bold text-muted mb-0">
185 185
 											<span class="spinner is-active float-none"></span>
186 186
 										</h5>
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 									</div>
189 189
 
190 190
 								</div>
191
-								<!-- <?php echo esc_html( $card['label'] ); ?> Card -->
191
+								<!-- <?php echo esc_html($card['label']); ?> Card -->
192 192
 
193 193
 							</div>
194 194
 						<?php endforeach; ?>
@@ -213,15 +213,15 @@  discard block
 block discarded – undo
213 213
 
214 214
 		?>
215 215
 
216
-			<?php foreach ( $graphs as $key => $graph ) : ?>
216
+			<?php foreach ($graphs as $key => $graph) : ?>
217 217
 				<div class="row mb-4">
218 218
 					<div class="col-12">
219 219
 						<div class="card m-0 p-0 single-report-card" style="max-width:100%">
220 220
 							<div class="card-header">
221
-								<strong><?php echo esc_html( $graph ); ?></strong>
221
+								<strong><?php echo esc_html($graph); ?></strong>
222 222
 							</div>
223 223
 							<div class="card-body">
224
-								<canvas id="getpaid-chartjs-<?php echo esc_attr( $key ); ?>"></canvas>
224
+								<canvas id="getpaid-chartjs-<?php echo esc_attr($key); ?>"></canvas>
225 225
 							</div>
226 226
 						</div>
227 227
 					</div>
@@ -236,14 +236,14 @@  discard block
 block discarded – undo
236 236
 	 * Retrieves the download url.
237 237
 	 *
238 238
 	 */
239
-	public function get_download_url( $graph, $file_type ) {
239
+	public function get_download_url($graph, $file_type) {
240 240
 
241 241
 		return wp_nonce_url(
242 242
 			add_query_arg(
243 243
 				array(
244 244
 					'getpaid-admin-action' => 'download_graph',
245
-					'file_type'            => urlencode( $file_type ),
246
-					'graph'                => urlencode( $graph ),
245
+					'file_type'            => urlencode($file_type),
246
+					'graph'                => urlencode($graph),
247 247
 				)
248 248
 			),
249 249
 			'getpaid-nonce',
@@ -260,27 +260,27 @@  discard block
 block discarded – undo
260 260
 
261 261
 		?>
262 262
 
263
-			<?php foreach ( $this->views as $key => $view ) : ?>
263
+			<?php foreach ($this->views as $key => $view) : ?>
264 264
 				<div class="row mb-4">
265 265
 					<div class="col-12">
266 266
 						<div class="card m-0 p-0" style="max-width:100%">
267 267
 							<div class="card-header">
268 268
 								<div class="row">
269
-									<div class="<?php echo empty( $view['disable-downloads'] ) ? 'col-9' : 'col-12'; ?>">
270
-										<strong><?php echo esc_html( $view['label'] ); ?></strong>
269
+									<div class="<?php echo empty($view['disable-downloads']) ? 'col-9' : 'col-12'; ?>">
270
+										<strong><?php echo esc_html($view['label']); ?></strong>
271 271
 									</div>
272
-									<div class="<?php echo empty( $view['disable-downloads'] ) ? 'col-3' : 'd-none'; ?>">
273
-										<a title="<?php esc_attr_e( 'Download JSON', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'json' ) ); ?>">
272
+									<div class="<?php echo empty($view['disable-downloads']) ? 'col-3' : 'd-none'; ?>">
273
+										<a title="<?php esc_attr_e('Download JSON', 'invoicing'); ?>" href="<?php echo esc_url($this->get_download_url($key, 'json')); ?>">
274 274
 											<i class="fa fa-download text-dark" style="font-size: 16px" aria-hidden="true"></i>
275
-											<span class="screen-reader-text"><?php _e( 'Download JSON', 'invoicing' ); ?></span>
275
+											<span class="screen-reader-text"><?php _e('Download JSON', 'invoicing'); ?></span>
276 276
 										</a>
277
-										<a title="<?php esc_attr_e( 'Download CSV', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'csv' ) ); ?>">
277
+										<a title="<?php esc_attr_e('Download CSV', 'invoicing'); ?>" href="<?php echo esc_url($this->get_download_url($key, 'csv')); ?>">
278 278
 											<i class="fa fa-file-csv text-dark" style="font-size: 16px" aria-hidden="true"></i>
279
-											<span class="screen-reader-text"><?php _e( 'Download CSV', 'invoicing' ); ?></span>
279
+											<span class="screen-reader-text"><?php _e('Download CSV', 'invoicing'); ?></span>
280 280
 										</a>
281
-										<a title="<?php esc_attr_e( 'Download XML', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'xml' ) ); ?>">
281
+										<a title="<?php esc_attr_e('Download XML', 'invoicing'); ?>" href="<?php echo esc_url($this->get_download_url($key, 'xml')); ?>">
282 282
 											<i class="fa fa-file-code text-dark" style="font-size: 16px" aria-hidden="true"></i>
283
-											<span class="screen-reader-text"><?php _e( 'Download XML', 'invoicing' ); ?></span>
283
+											<span class="screen-reader-text"><?php _e('Download XML', 'invoicing'); ?></span>
284 284
 										</a>
285 285
 									</div>
286 286
 								</div>
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 
300 300
 		<?php
301 301
 
302
-		do_action( 'getpaid_reports_display_right', $this );
302
+		do_action('getpaid_reports_display_right', $this);
303 303
 	}
304 304
 
305 305
 	/**
@@ -310,56 +310,56 @@  discard block
 block discarded – undo
310 310
 
311 311
 		$cards = array(
312 312
 			'total_sales' => array(
313
-				'description' => __( 'Gross sales in the period.', 'invoicing' ),
314
-				'label'       => __( 'Gross Revenue', 'invoicing' ),
313
+				'description' => __('Gross sales in the period.', 'invoicing'),
314
+				'label'       => __('Gross Revenue', 'invoicing'),
315 315
 			),
316 316
 			'net_sales' => array(
317
-				'description' => __( 'Net sales in the period.', 'invoicing' ),
318
-				'label'       => __( 'Net Revenue', 'invoicing' ),
317
+				'description' => __('Net sales in the period.', 'invoicing'),
318
+				'label'       => __('Net Revenue', 'invoicing'),
319 319
 			),
320 320
 			'average_sales' => array(
321
-				'description' => __( 'Average net daily/monthly sales.', 'invoicing' ),
322
-				'label'       => __( 'Avg. Net Sales', 'invoicing' ),
321
+				'description' => __('Average net daily/monthly sales.', 'invoicing'),
322
+				'label'       => __('Avg. Net Sales', 'invoicing'),
323 323
 			),
324 324
 			'average_total_sales' => array(
325
-				'description' => __( 'Average gross daily/monthly sales.', 'invoicing' ),
326
-				'label'       => __( 'Avg. Gross Sales', 'invoicing' ),
325
+				'description' => __('Average gross daily/monthly sales.', 'invoicing'),
326
+				'label'       => __('Avg. Gross Sales', 'invoicing'),
327 327
 			),
328 328
 			'total_invoices'  => array(
329
-				'description' => __( 'Number of paid invoices.', 'invoicing' ),
330
-				'label'       => __( 'Paid Invoices', 'invoicing' ),
329
+				'description' => __('Number of paid invoices.', 'invoicing'),
330
+				'label'       => __('Paid Invoices', 'invoicing'),
331 331
 			),
332 332
 			'total_items' => array(
333
-				'description' => __( 'Number of items purchased.', 'invoicing' ),
334
-				'label'       => __( 'Purchased Items', 'invoicing' ),
333
+				'description' => __('Number of items purchased.', 'invoicing'),
334
+				'label'       => __('Purchased Items', 'invoicing'),
335 335
 			),
336 336
 			'refunded_items' => array(
337
-				'description' => __( 'Number of items refunded.', 'invoicing' ),
338
-				'label'       => __( 'Refunded Items', 'invoicing' ),
337
+				'description' => __('Number of items refunded.', 'invoicing'),
338
+				'label'       => __('Refunded Items', 'invoicing'),
339 339
 			),
340 340
 			'total_tax' => array(
341
-				'description' => __( 'Total charged for taxes.', 'invoicing' ),
342
-				'label'       => __( 'Tax', 'invoicing' ),
341
+				'description' => __('Total charged for taxes.', 'invoicing'),
342
+				'label'       => __('Tax', 'invoicing'),
343 343
 			),
344 344
 			'total_refunded_tax' => array(
345
-				'description' => __( 'Total refunded for taxes.', 'invoicing' ),
346
-				'label'       => __( 'Refunded Tax', 'invoicing' ),
345
+				'description' => __('Total refunded for taxes.', 'invoicing'),
346
+				'label'       => __('Refunded Tax', 'invoicing'),
347 347
 			),
348 348
 			'total_fees' => array(
349
-				'description' => __( 'Total fees charged.', 'invoicing' ),
350
-				'label'       => __( 'Fees', 'invoicing' ),
349
+				'description' => __('Total fees charged.', 'invoicing'),
350
+				'label'       => __('Fees', 'invoicing'),
351 351
 			),
352 352
 			'total_refunds' => array(
353
-				'description' => __( 'Total of refunded invoices.', 'invoicing' ),
354
-				'label'       => __( 'Refunded', 'invoicing' ),
353
+				'description' => __('Total of refunded invoices.', 'invoicing'),
354
+				'label'       => __('Refunded', 'invoicing'),
355 355
 			),
356 356
 			'total_discount'  => array(
357
-				'description' => __( 'Total of discounts used.', 'invoicing' ),
358
-				'label'       => __( 'Discounted', 'invoicing' ),
357
+				'description' => __('Total of discounts used.', 'invoicing'),
358
+				'label'       => __('Discounted', 'invoicing'),
359 359
 			),
360 360
 		);
361 361
 
362
-		return apply_filters( 'wpinv_report_cards', $cards );
362
+		return apply_filters('wpinv_report_cards', $cards);
363 363
 	}
364 364
 
365 365
 	
Please login to merge, or discard this patch.
includes/wpinv-address-functions.php 2 patches
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -13,9 +13,9 @@  discard block
 block discarded – undo
13 13
 
14 14
 
15 15
 function wpinv_get_default_country() {
16
-	$country = wpinv_get_option( 'default_country', 'UK' );
16
+    $country = wpinv_get_option( 'default_country', 'UK' );
17 17
 
18
-	return apply_filters( 'wpinv_default_country', $country );
18
+    return apply_filters( 'wpinv_default_country', $country );
19 19
 }
20 20
 
21 21
 /**
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
  */
37 37
 function wpinv_sanitize_country( $country ) {
38 38
 
39
-	// Enure the country is specified
39
+    // Enure the country is specified
40 40
     if ( empty( $country ) ) {
41 41
         $country = wpinv_get_default_country();
42 42
     }
@@ -66,9 +66,9 @@  discard block
 block discarded – undo
66 66
 }
67 67
 
68 68
 function wpinv_get_default_state() {
69
-	$state = wpinv_get_option( 'default_state', '' );
69
+    $state = wpinv_get_option( 'default_state', '' );
70 70
 
71
-	return apply_filters( 'wpinv_default_state', $state );
71
+    return apply_filters( 'wpinv_default_state', $state );
72 72
 }
73 73
 
74 74
 function wpinv_state_name( $state_code = '', $country_code = '' ) {
@@ -308,11 +308,11 @@  discard block
 block discarded – undo
308 308
 
309 309
     $country = wpinv_sanitize_country( $country );
310 310
     
311
-	foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) {
312
-		if ( false !== array_search( $country, $countries, true ) ) {
313
-			return $continent_code;
314
-		}
315
-	}
311
+    foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) {
312
+        if ( false !== array_search( $country, $countries, true ) ) {
313
+            return $continent_code;
314
+        }
315
+    }
316 316
 
317 317
     return '';
318 318
     
@@ -604,33 +604,33 @@  discard block
 block discarded – undo
604 604
 }
605 605
 
606 606
 function wpinv_get_states_field() {
607
-	if( empty( $_POST['country'] ) ) {
608
-		$_POST['country'] = wpinv_get_default_country();
609
-	}
610
-	$states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
607
+    if( empty( $_POST['country'] ) ) {
608
+        $_POST['country'] = wpinv_get_default_country();
609
+    }
610
+    $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
611 611
 
612
-	if( !empty( $states ) ) {
613
-		$sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
612
+    if( !empty( $states ) ) {
613
+        $sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
614 614
 
615 615
         $class  = isset( $_POST['class'] ) ? esc_attr( sanitize_text_field( $_POST['class'] ) ) : '';
616 616
         $class .= " $sanitized_field_name getpaid_js_field-state custom-select wpinv-select wpi_select2";
617 617
 
618 618
         $args  = array(
619
-			'name'    => $sanitized_field_name,
620
-			'id'      => $sanitized_field_name,
621
-			'class'   => implode( ' ', array_unique( explode( ' ', $class ) ) ),
622
-			'options' => array_merge( array( '' => '' ), $states ),
623
-			'show_option_all'  => false,
624
-			'show_option_none' => false
625
-		);
626
-
627
-		$response = wpinv_html_select( $args );
628
-
629
-	} else {
630
-		$response = 'nostates';
631
-	}
619
+            'name'    => $sanitized_field_name,
620
+            'id'      => $sanitized_field_name,
621
+            'class'   => implode( ' ', array_unique( explode( ' ', $class ) ) ),
622
+            'options' => array_merge( array( '' => '' ), $states ),
623
+            'show_option_all'  => false,
624
+            'show_option_none' => false
625
+        );
626
+
627
+        $response = wpinv_html_select( $args );
628
+
629
+    } else {
630
+        $response = 'nostates';
631
+    }
632 632
 
633
-	return $response;
633
+    return $response;
634 634
 }
635 635
 
636 636
 function wpinv_default_billing_country( $country = '', $user_id = 0 ) {
@@ -648,46 +648,46 @@  discard block
 block discarded – undo
648 648
  */
649 649
 function wpinv_get_address_formats() {
650 650
 
651
-		return apply_filters( 'wpinv_localisation_address_formats',
652
-			array(
653
-				'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}",
654
-				'AU'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}",
655
-				'AT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
656
-				'BE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
657
-				'CA'      => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{state_code}}&nbsp;&nbsp;{{zip}}\n{{country}}",
658
-				'CH'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
659
-				'CL'      => "{{company}}\n{{name}}\n{{address}}\n{{state}}\n{{zip}} {{city}}\n{{country}}",
660
-				'CN'      => "{{country}} {{zip}}\n{{state}}, {{city}}, {{address}}\n{{company}}\n{{name}}",
661
-				'CZ'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
662
-				'DE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
663
-				'EE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
664
-				'FI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
665
-				'DK'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
666
-				'FR'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city_upper}}\n{{country}}",
667
-				'HK'      => "{{company}}\n{{first_name}} {{last_name_upper}}\n{{address}}\n{{city_upper}}\n{{state_upper}}\n{{country}}",
668
-				'HU'      => "{{name}}\n{{company}}\n{{city}}\n{{address}}\n{{zip}}\n{{country}}",
669
-				'IN'      => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{zip}}\n{{state}}, {{country}}",
670
-				'IS'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
671
-				'IT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}}\n{{city}}\n{{state_upper}}\n{{country}}",
672
-				'JP'      => "{{zip}}\n{{state}} {{city}} {{address}}\n{{company}}\n{{last_name}} {{first_name}}\n{{country}}",
673
-				'TW'      => "{{company}}\n{{last_name}} {{first_name}}\n{{address}}\n{{state}}, {{city}} {{zip}}\n{{country}}",
674
-				'LI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
675
-				'NL'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
676
-				'NZ'      => "{{name}}\n{{company}}\n{{address}}\n{{city}} {{zip}}\n{{country}}",
677
-				'NO'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
678
-				'PL'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
679
-				'PT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
680
-				'SK'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
681
-				'RS'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
682
-				'SI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
683
-				'ES'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{state}}\n{{country}}",
684
-				'SE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
685
-				'TR'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}} {{state}}\n{{country}}",
686
-				'UG'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}, {{country}}",
687
-				'US'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}, {{state_code}} {{zip}}\n{{country}}",
688
-				'VN'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{country}}",
689
-			)
690
-		);
651
+        return apply_filters( 'wpinv_localisation_address_formats',
652
+            array(
653
+                'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}",
654
+                'AU'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}",
655
+                'AT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
656
+                'BE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
657
+                'CA'      => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{state_code}}&nbsp;&nbsp;{{zip}}\n{{country}}",
658
+                'CH'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
659
+                'CL'      => "{{company}}\n{{name}}\n{{address}}\n{{state}}\n{{zip}} {{city}}\n{{country}}",
660
+                'CN'      => "{{country}} {{zip}}\n{{state}}, {{city}}, {{address}}\n{{company}}\n{{name}}",
661
+                'CZ'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
662
+                'DE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
663
+                'EE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
664
+                'FI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
665
+                'DK'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
666
+                'FR'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city_upper}}\n{{country}}",
667
+                'HK'      => "{{company}}\n{{first_name}} {{last_name_upper}}\n{{address}}\n{{city_upper}}\n{{state_upper}}\n{{country}}",
668
+                'HU'      => "{{name}}\n{{company}}\n{{city}}\n{{address}}\n{{zip}}\n{{country}}",
669
+                'IN'      => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{zip}}\n{{state}}, {{country}}",
670
+                'IS'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
671
+                'IT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}}\n{{city}}\n{{state_upper}}\n{{country}}",
672
+                'JP'      => "{{zip}}\n{{state}} {{city}} {{address}}\n{{company}}\n{{last_name}} {{first_name}}\n{{country}}",
673
+                'TW'      => "{{company}}\n{{last_name}} {{first_name}}\n{{address}}\n{{state}}, {{city}} {{zip}}\n{{country}}",
674
+                'LI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
675
+                'NL'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
676
+                'NZ'      => "{{name}}\n{{company}}\n{{address}}\n{{city}} {{zip}}\n{{country}}",
677
+                'NO'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
678
+                'PL'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
679
+                'PT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
680
+                'SK'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
681
+                'RS'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
682
+                'SI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
683
+                'ES'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{state}}\n{{country}}",
684
+                'SE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
685
+                'TR'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}} {{state}}\n{{country}}",
686
+                'UG'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}, {{country}}",
687
+                'US'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}, {{state_code}} {{zip}}\n{{country}}",
688
+                'VN'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{country}}",
689
+            )
690
+        );
691 691
 }
692 692
 
693 693
 /**
@@ -704,21 +704,21 @@  discard block
 block discarded – undo
704 704
     }
705 705
 
706 706
     // Get all formats.
707
-	$formats = wpinv_get_address_formats();
707
+    $formats = wpinv_get_address_formats();
708 708
 
709
-	// Get format for the specified country.
710
-	$format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];
709
+    // Get format for the specified country.
710
+    $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];
711 711
     
712 712
     /**
713
-	 * Filters the address format to use on Invoices.
713
+     * Filters the address format to use on Invoices.
714 714
      * 
715 715
      * New lines will be replaced by a `br` element. Double new lines will be replaced by a paragraph. HTML tags are allowed.
716
-	 *
717
-	 * @since 1.0.13
718
-	 *
719
-	 * @param string $format  The address format to use.
716
+     *
717
+     * @since 1.0.13
718
+     *
719
+     * @param string $format  The address format to use.
720 720
      * @param string $country The country who's address format is being retrieved.
721
-	 */
721
+     */
722 722
     return apply_filters( 'wpinv_get_full_address_format', $format, $country );
723 723
 }
724 724
 
@@ -739,8 +739,8 @@  discard block
 block discarded – undo
739 739
         'country'           => '',
740 740
         'zip'               => '',
741 741
         'first_name'        => '',
742
-		'last_name'         => '',
743
-		'company'           => '',
742
+        'last_name'         => '',
743
+        'company'           => '',
744 744
     );
745 745
 
746 746
     $args    = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' );
@@ -761,14 +761,14 @@  discard block
 block discarded – undo
761 761
     $args['country_code']= $country;
762 762
 
763 763
     /**
764
-	 * Filters the address format replacements to use on Invoices.
764
+     * Filters the address format replacements to use on Invoices.
765 765
      * 
766
-	 *
767
-	 * @since 1.0.13
768
-	 *
769
-	 * @param array $replacements  The address replacements to use.
766
+     *
767
+     * @since 1.0.13
768
+     *
769
+     * @param array $replacements  The address replacements to use.
770 770
      * @param array $billing_details  The billing details to use.
771
-	 */
771
+     */
772 772
     $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details );
773 773
 
774 774
     $return = array();
@@ -791,5 +791,5 @@  discard block
 block discarded – undo
791 791
  * @return string
792 792
  */
793 793
 function wpinv_trim_formatted_address_line( $line ) {
794
-	return trim( $line, ', ' );
794
+    return trim( $line, ', ' );
795 795
 }
796 796
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 
15 15
 function wpinv_get_default_country() {
16
-	$country = wpinv_get_option( 'default_country', 'UK' );
16
+	$country = wpinv_get_option('default_country', 'UK');
17 17
 
18
-	return apply_filters( 'wpinv_default_country', $country );
18
+	return apply_filters('wpinv_default_country', $country);
19 19
 }
20 20
 
21 21
 /**
@@ -23,8 +23,8 @@  discard block
 block discarded – undo
23 23
  *
24 24
  * @return string
25 25
  */
26
-function getpaid_get_ip_country( $ip_address = '' ) {
27
-    $country = GetPaid_Geolocation::geolocate_ip( $ip_address, true );
26
+function getpaid_get_ip_country($ip_address = '') {
27
+    $country = GetPaid_Geolocation::geolocate_ip($ip_address, true);
28 28
     return $country['country'];
29 29
 }
30 30
 
@@ -34,59 +34,59 @@  discard block
 block discarded – undo
34 34
  * @param string $country The country code to sanitize
35 35
  * @return array
36 36
  */
37
-function wpinv_sanitize_country( $country ) {
37
+function wpinv_sanitize_country($country) {
38 38
 
39 39
 	// Enure the country is specified
40
-    if ( empty( $country ) ) {
40
+    if (empty($country)) {
41 41
         $country = wpinv_get_default_country();
42 42
     }
43
-    return trim( wpinv_utf8_strtoupper( $country ) );
43
+    return trim(wpinv_utf8_strtoupper($country));
44 44
 
45 45
 }
46 46
 
47
-function wpinv_is_base_country( $country ) {
47
+function wpinv_is_base_country($country) {
48 48
     $base_country = wpinv_get_default_country();
49 49
     
50
-    if ( $base_country === 'UK' ) {
50
+    if ($base_country === 'UK') {
51 51
         $base_country = 'GB';
52 52
     }
53
-    if ( $country == 'UK' ) {
53
+    if ($country == 'UK') {
54 54
         $country = 'GB';
55 55
     }
56 56
 
57
-    return ( $country && $country === $base_country ) ? true : false;
57
+    return ($country && $country === $base_country) ? true : false;
58 58
 }
59 59
 
60
-function wpinv_country_name( $country_code = '' ) { 
60
+function wpinv_country_name($country_code = '') { 
61 61
     $countries = wpinv_get_country_list();
62 62
     $country_code = $country_code == 'UK' ? 'GB' : $country_code;
63
-    $country = isset( $countries[$country_code] ) ? $countries[$country_code] : $country_code;
63
+    $country = isset($countries[$country_code]) ? $countries[$country_code] : $country_code;
64 64
 
65
-    return apply_filters( 'wpinv_country_name', $country, $country_code );
65
+    return apply_filters('wpinv_country_name', $country, $country_code);
66 66
 }
67 67
 
68 68
 function wpinv_get_default_state() {
69
-	$state = wpinv_get_option( 'default_state', '' );
69
+	$state = wpinv_get_option('default_state', '');
70 70
 
71
-	return apply_filters( 'wpinv_default_state', $state );
71
+	return apply_filters('wpinv_default_state', $state);
72 72
 }
73 73
 
74
-function wpinv_state_name( $state_code = '', $country_code = '' ) {
74
+function wpinv_state_name($state_code = '', $country_code = '') {
75 75
     $state = $state_code;
76 76
     
77
-    if ( !empty( $country_code ) ) {
78
-        $states = wpinv_get_country_states( $country_code );
77
+    if (!empty($country_code)) {
78
+        $states = wpinv_get_country_states($country_code);
79 79
         
80
-        $state = !empty( $states ) && isset( $states[$state_code] ) ? $states[$state_code] : $state;
80
+        $state = !empty($states) && isset($states[$state_code]) ? $states[$state_code] : $state;
81 81
     }
82 82
 
83
-    return apply_filters( 'wpinv_state_name', $state, $state_code, $country_code );
83
+    return apply_filters('wpinv_state_name', $state, $state_code, $country_code);
84 84
 }
85 85
 
86 86
 function wpinv_store_address() {
87
-    $address = wpinv_get_option( 'store_address', '' );
87
+    $address = wpinv_get_option('store_address', '');
88 88
 
89
-    return apply_filters( 'wpinv_store_address', $address );
89
+    return apply_filters('wpinv_store_address', $address);
90 90
 }
91 91
 
92 92
 /**
@@ -94,24 +94,24 @@  discard block
 block discarded – undo
94 94
  *
95 95
  * @param WPInv_Invoice $invoice
96 96
  */
97
-function getpaid_maybe_add_default_address( &$invoice ) {
97
+function getpaid_maybe_add_default_address(&$invoice) {
98 98
 
99 99
     $user_id = $invoice->get_user_id();
100 100
 
101 101
     // Abort if the invoice belongs to no one.
102
-    if ( empty( $user_id ) ) {
102
+    if (empty($user_id)) {
103 103
         return;
104 104
     }
105 105
 
106 106
     // Fill in defaults whenever necessary.
107
-    foreach ( wpinv_get_user_address( $user_id ) as $key => $value ) {
107
+    foreach (wpinv_get_user_address($user_id) as $key => $value) {
108 108
 
109
-        if ( is_callable( $invoice, "get_$key" ) ) {
110
-            $current = call_user_func( array( $invoice, "get_$key" ) );
109
+        if (is_callable($invoice, "get_$key")) {
110
+            $current = call_user_func(array($invoice, "get_$key"));
111 111
 
112
-            if ( empty( $current ) ) {
112
+            if (empty($current)) {
113 113
                 $method = "set_$key";
114
-                $invoice->$method( $value );
114
+                $invoice->$method($value);
115 115
             }
116 116
 
117 117
         }
@@ -130,22 +130,22 @@  discard block
 block discarded – undo
130 130
     $address_fields = apply_filters(
131 131
         'getpaid_user_address_fields',
132 132
         array(
133
-            'first_name' => __( 'First Name', 'invoicing' ),
134
-            'last_name'  => __( 'Last Name', 'invoicing' ),
135
-            'address'    => __( 'Address', 'invoicing' ),
136
-            'city'       => __( 'City', 'invoicing' ),
137
-            'country'    => __( 'Country', 'invoicing' ),
138
-            'state'      => __( 'State', 'invoicing' ),
139
-            'zip'        => __( 'Zip/Postal Code', 'invoicing' ),
140
-            'phone'      => __( 'Phone Number', 'invoicing' ),
141
-            'company'    => __( 'Company', 'invoicing' ),
142
-            'company_id'    => __( 'Company ID', 'invoicing' ),
143
-            'vat_number' => __( 'VAT Number', 'invoicing' ),
133
+            'first_name' => __('First Name', 'invoicing'),
134
+            'last_name'  => __('Last Name', 'invoicing'),
135
+            'address'    => __('Address', 'invoicing'),
136
+            'city'       => __('City', 'invoicing'),
137
+            'country'    => __('Country', 'invoicing'),
138
+            'state'      => __('State', 'invoicing'),
139
+            'zip'        => __('Zip/Postal Code', 'invoicing'),
140
+            'phone'      => __('Phone Number', 'invoicing'),
141
+            'company'    => __('Company', 'invoicing'),
142
+            'company_id'    => __('Company ID', 'invoicing'),
143
+            'vat_number' => __('VAT Number', 'invoicing'),
144 144
         )
145 145
     );
146 146
 
147
-    if ( ! wpinv_use_taxes() && isset( $address_fields['vat_number'] ) ) {
148
-        unset( $address_fields['vat_number'] );
147
+    if (!wpinv_use_taxes() && isset($address_fields['vat_number'])) {
148
+        unset($address_fields['vat_number']);
149 149
     }
150 150
 
151 151
     return $address_fields;
@@ -156,8 +156,8 @@  discard block
 block discarded – undo
156 156
  * 
157 157
  * @return bool
158 158
  */
159
-function getpaid_is_address_field_whitelisted( $key ) {
160
-    return array_key_exists( $key, getpaid_user_address_fields() );
159
+function getpaid_is_address_field_whitelisted($key) {
160
+    return array_key_exists($key, getpaid_user_address_fields());
161 161
 }
162 162
 
163 163
 /**
@@ -167,24 +167,24 @@  discard block
 block discarded – undo
167 167
  *
168 168
  * @param WPInv_Invoice $invoice
169 169
  */
170
-function getpaid_save_invoice_user_address( $invoice ) {
170
+function getpaid_save_invoice_user_address($invoice) {
171 171
 
172 172
     // Retrieve the invoice.
173
-    $invoice = wpinv_get_invoice( $invoice );
173
+    $invoice = wpinv_get_invoice($invoice);
174 174
 
175 175
     // Abort if it does not exist.
176
-    if ( empty( $invoice ) || $invoice->is_renewal() ) {
176
+    if (empty($invoice) || $invoice->is_renewal()) {
177 177
         return;
178 178
     }
179 179
 
180
-    foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
180
+    foreach (array_keys(getpaid_user_address_fields()) as $field) {
181 181
 
182
-        if ( is_callable( array( $invoice, "get_$field" ) ) ) {
183
-            $value = call_user_func( array( $invoice, "get_$field" ) );
182
+        if (is_callable(array($invoice, "get_$field"))) {
183
+            $value = call_user_func(array($invoice, "get_$field"));
184 184
 
185 185
             // Only save if it is not empty.
186
-            if ( ! empty( $value ) ) {
187
-                update_user_meta( $invoice->get_user_id(), '_wpinv_' . $field, $value );
186
+            if (!empty($value)) {
187
+                update_user_meta($invoice->get_user_id(), '_wpinv_' . $field, $value);
188 188
             }
189 189
 
190 190
         }
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
     }
193 193
 
194 194
 }
195
-add_action( 'getpaid_checkout_invoice_updated', 'getpaid_save_invoice_user_address' );
195
+add_action('getpaid_checkout_invoice_updated', 'getpaid_save_invoice_user_address');
196 196
 
197 197
 /**
198 198
  * Retrieves a saved user address.
@@ -201,14 +201,14 @@  discard block
 block discarded – undo
201 201
  * @param bool $with_default Whether or not we should use the default country and state.
202 202
  * @return array
203 203
  */
204
-function wpinv_get_user_address( $user_id = 0, $with_default = true ) {
204
+function wpinv_get_user_address($user_id = 0, $with_default = true) {
205 205
 
206 206
     // Prepare the user id.
207
-    $user_id   = empty( $user_id ) ? get_current_user_id() : $user_id;
208
-    $user_info = get_userdata( $user_id );
207
+    $user_id   = empty($user_id) ? get_current_user_id() : $user_id;
208
+    $user_info = get_userdata($user_id);
209 209
 
210 210
     // Abort if non exists.
211
-    if ( empty( $user_info ) ) {
211
+    if (empty($user_info)) {
212 212
         return array();
213 213
     }
214 214
 
@@ -218,13 +218,13 @@  discard block
 block discarded – undo
218 218
         'email'   => $user_info->user_email,
219 219
     );
220 220
 
221
-    foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
222
-        $address[$field] = getpaid_get_user_address_field( $user_id, $field );
221
+    foreach (array_keys(getpaid_user_address_fields()) as $field) {
222
+        $address[$field] = getpaid_get_user_address_field($user_id, $field);
223 223
     }
224 224
 
225
-    $address = array_filter( $address );
225
+    $address = array_filter($address);
226 226
 
227
-    if ( ! $with_default ) {
227
+    if (!$with_default) {
228 228
         return $address;
229 229
     }
230 230
 
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
         'country'    => wpinv_get_default_country(),
236 236
     );
237 237
 
238
-    return getpaid_array_merge_if_empty( $address, $defaults );
238
+    return getpaid_array_merge_if_empty($address, $defaults);
239 239
 
240 240
 }
241 241
 
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
  * @param string $field The field to use.
247 247
  * @return string|null
248 248
  */
249
-function getpaid_get_user_address_field( $user_id, $field ) {
249
+function getpaid_get_user_address_field($user_id, $field) {
250 250
 
251 251
     $prefixes = array(
252 252
         '_wpinv_',
@@ -254,15 +254,15 @@  discard block
 block discarded – undo
254 254
         ''
255 255
     );
256 256
 
257
-    foreach ( $prefixes as $prefix ) {
257
+    foreach ($prefixes as $prefix) {
258 258
 
259 259
         // Meta table.
260
-        $value = get_user_meta( $user_id, $prefix . $field, true );
260
+        $value = get_user_meta($user_id, $prefix . $field, true);
261 261
         
262 262
         // UWP table.
263
-        $value = ( empty( $value ) && function_exists( 'uwp_get_usermeta' ) ) ? uwp_get_usermeta( $user_id, $prefix . $field ) : $value;
263
+        $value = (empty($value) && function_exists('uwp_get_usermeta')) ? uwp_get_usermeta($user_id, $prefix . $field) : $value;
264 264
 
265
-        if ( ! empty( $value ) ) {
265
+        if (!empty($value)) {
266 266
             return $value;
267 267
         }
268 268
 
@@ -279,16 +279,16 @@  discard block
 block discarded – undo
279 279
  * @param string $return What to return.
280 280
  * @return array
281 281
  */
282
-function wpinv_get_continents( $return = 'all' ) {
282
+function wpinv_get_continents($return = 'all') {
283 283
 
284
-    $continents = wpinv_get_data( 'continents' );
284
+    $continents = wpinv_get_data('continents');
285 285
 
286
-    switch( $return ) {
286
+    switch ($return) {
287 287
         case 'name' :
288
-            return wp_list_pluck( $continents, 'name' );
288
+            return wp_list_pluck($continents, 'name');
289 289
             break;
290 290
         case 'countries' :
291
-            return wp_list_pluck( $continents, 'countries' );
291
+            return wp_list_pluck($continents, 'countries');
292 292
             break;
293 293
         default :
294 294
             return $continents;
@@ -304,12 +304,12 @@  discard block
 block discarded – undo
304 304
  * @param string $country Country code. If no code is specified, defaults to the default country.
305 305
  * @return string
306 306
  */
307
-function wpinv_get_continent_code_for_country( $country = false ) {
307
+function wpinv_get_continent_code_for_country($country = false) {
308 308
 
309
-    $country = wpinv_sanitize_country( $country );
309
+    $country = wpinv_sanitize_country($country);
310 310
     
311
-	foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) {
312
-		if ( false !== array_search( $country, $countries, true ) ) {
311
+	foreach (wpinv_get_continents('countries') as $continent_code => $countries) {
312
+		if (false !== array_search($country, $countries, true)) {
313 313
 			return $continent_code;
314 314
 		}
315 315
 	}
@@ -325,13 +325,13 @@  discard block
 block discarded – undo
325 325
  * @param string $country Country code. If no code is specified, defaults to the default country.
326 326
  * @return array
327 327
  */
328
-function wpinv_get_country_calling_code( $country = null) {
328
+function wpinv_get_country_calling_code($country = null) {
329 329
 
330
-    $country = wpinv_sanitize_country( $country );
331
-    $codes   = wpinv_get_data( 'phone-codes' );
332
-    $code    = isset( $codes[ $country ] ) ? $codes[ $country ] : '';
330
+    $country = wpinv_sanitize_country($country);
331
+    $codes   = wpinv_get_data('phone-codes');
332
+    $code    = isset($codes[$country]) ? $codes[$country] : '';
333 333
 
334
-    if ( is_array( $code ) ) {
334
+    if (is_array($code)) {
335 335
         return $code[0];
336 336
     }
337 337
     return $code;
@@ -344,8 +344,8 @@  discard block
 block discarded – undo
344 344
  * @param bool $first_empty Whether or not the first item in the list should be empty
345 345
  * @return array
346 346
  */
347
-function wpinv_get_country_list( $first_empty = false ) {
348
-    return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty );
347
+function wpinv_get_country_list($first_empty = false) {
348
+    return wpinv_maybe_add_empty_option(apply_filters('wpinv_countries', wpinv_get_data('countries')), $first_empty);
349 349
 }
350 350
 
351 351
 /**
@@ -355,22 +355,22 @@  discard block
 block discarded – undo
355 355
  * @param bool $first_empty Whether or not the first item in the list should be empty
356 356
  * @return array
357 357
  */
358
-function wpinv_get_country_states( $country = null, $first_empty = false ) {
358
+function wpinv_get_country_states($country = null, $first_empty = false) {
359 359
     
360 360
     // Prepare the country.
361
-    $country = wpinv_sanitize_country( $country );
361
+    $country = wpinv_sanitize_country($country);
362 362
 
363 363
     // Fetch all states.
364
-    $all_states = wpinv_get_data( 'states' );
364
+    $all_states = wpinv_get_data('states');
365 365
 
366 366
     // Fetch the specified country's states.
367
-    $states     = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array() ;
368
-    $states     = apply_filters( "wpinv_{$country}_states", $states );
369
-    $states     = apply_filters( 'wpinv_country_states', $states, $country );
367
+    $states     = isset($all_states[$country]) ? $all_states[$country] : array();
368
+    $states     = apply_filters("wpinv_{$country}_states", $states);
369
+    $states     = apply_filters('wpinv_country_states', $states, $country);
370 370
 
371
-    asort( $states );
371
+    asort($states);
372 372
      
373
-    return wpinv_maybe_add_empty_option( $states, $first_empty );
373
+    return wpinv_maybe_add_empty_option($states, $first_empty);
374 374
 }
375 375
 
376 376
 /**
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
  * @return array
381 381
  */
382 382
 function wpinv_get_us_states_list() {
383
-    return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) );
383
+    return apply_filters('wpinv_usa_states', wpinv_get_country_states('US'));
384 384
 }
385 385
 
386 386
 /**
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
  * @return array
391 391
  */
392 392
 function wpinv_get_canada_states_list() {
393
-    return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) );
393
+    return apply_filters('wpinv_canada_provinces', wpinv_get_country_states('CA'));
394 394
 }
395 395
 
396 396
 /**
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
  * @return array
401 401
  */
402 402
 function wpinv_get_australia_states_list() {
403
-    return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) );
403
+    return apply_filters('wpinv_australia_states', wpinv_get_country_states('AU'));
404 404
 }
405 405
 
406 406
 /**
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
  * @return array
411 411
  */
412 412
 function wpinv_get_bangladesh_states_list() {
413
-    return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) );
413
+    return apply_filters('wpinv_bangladesh_states', wpinv_get_country_states('BD'));
414 414
 }
415 415
 
416 416
 /**
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
  * @return array
421 421
  */
422 422
 function wpinv_get_brazil_states_list() {
423
-    return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) );
423
+    return apply_filters('wpinv_brazil_states', wpinv_get_country_states('BR'));
424 424
 }
425 425
 
426 426
 /**
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
  * @return array
431 431
  */
432 432
 function wpinv_get_bulgaria_states_list() {
433
-    return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) );
433
+    return apply_filters('wpinv_bulgaria_states', wpinv_get_country_states('BG'));
434 434
 }
435 435
 
436 436
 /**
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
  * @return array
441 441
  */
442 442
 function wpinv_get_hong_kong_states_list() {
443
-    return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) );
443
+    return apply_filters('wpinv_hong_kong_states', wpinv_get_country_states('HK'));
444 444
 }
445 445
 
446 446
 /**
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
  * @return array
451 451
  */
452 452
 function wpinv_get_hungary_states_list() {
453
-    return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) );
453
+    return apply_filters('wpinv_hungary_states', wpinv_get_country_states('HU'));
454 454
 }
455 455
 
456 456
 /**
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
  * @return array
461 461
  */
462 462
 function wpinv_get_japan_states_list() {
463
-    return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) );
463
+    return apply_filters('wpinv_japan_states', wpinv_get_country_states('JP'));
464 464
 }
465 465
 
466 466
 /**
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
  * @return array
471 471
  */
472 472
 function wpinv_get_china_states_list() {
473
-    return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) );
473
+    return apply_filters('wpinv_china_states', wpinv_get_country_states('CN'));
474 474
 }
475 475
 
476 476
 /**
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
  * @return array
481 481
  */
482 482
 function wpinv_get_new_zealand_states_list() {
483
-    return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) );
483
+    return apply_filters('wpinv_new_zealand_states', wpinv_get_country_states('NZ'));
484 484
 }
485 485
 
486 486
 /**
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
  * @return array
491 491
  */
492 492
 function wpinv_get_peru_states_list() {
493
-    return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) );
493
+    return apply_filters('wpinv_peru_states', wpinv_get_country_states('PE'));
494 494
 }
495 495
 
496 496
 /**
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
  * @return array
501 501
  */
502 502
 function wpinv_get_indonesia_states_list() {
503
-    return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) );
503
+    return apply_filters('wpinv_indonesia_states', wpinv_get_country_states('ID'));
504 504
 }
505 505
 
506 506
 /**
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
  * @return array
511 511
  */
512 512
 function wpinv_get_india_states_list() {
513
-    return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) );
513
+    return apply_filters('wpinv_india_states', wpinv_get_country_states('IN'));
514 514
 }
515 515
 
516 516
 /**
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
  * @return array
521 521
  */
522 522
 function wpinv_get_iran_states_list() {
523
-    return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) );
523
+    return apply_filters('wpinv_iran_states', wpinv_get_country_states('IR'));
524 524
 }
525 525
 
526 526
 /**
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
  * @return array
531 531
  */
532 532
 function wpinv_get_italy_states_list() {
533
-    return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) );
533
+    return apply_filters('wpinv_italy_states', wpinv_get_country_states('IT'));
534 534
 }
535 535
 
536 536
 /**
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
  * @return array
541 541
  */
542 542
 function wpinv_get_malaysia_states_list() {
543
-    return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) );
543
+    return apply_filters('wpinv_malaysia_states', wpinv_get_country_states('MY'));
544 544
 }
545 545
 
546 546
 /**
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
  * @return array
551 551
  */
552 552
 function wpinv_get_mexico_states_list() {
553
-    return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) );
553
+    return apply_filters('wpinv_mexico_states', wpinv_get_country_states('MX'));
554 554
 }
555 555
 
556 556
 /**
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
  * @return array
561 561
  */
562 562
 function wpinv_get_nepal_states_list() {
563
-    return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) );
563
+    return apply_filters('wpinv_nepal_states', wpinv_get_country_states('NP'));
564 564
 }
565 565
 
566 566
 /**
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
  * @return array
571 571
  */
572 572
 function wpinv_get_south_africa_states_list() {
573
-    return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) );
573
+    return apply_filters('wpinv_south_africa_states', wpinv_get_country_states('ZA'));
574 574
 }
575 575
 
576 576
 /**
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
  * @return array
581 581
  */
582 582
 function wpinv_get_thailand_states_list() {
583
-    return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) );
583
+    return apply_filters('wpinv_thailand_states', wpinv_get_country_states('TH'));
584 584
 }
585 585
 
586 586
 /**
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
  * @return array
591 591
  */
592 592
 function wpinv_get_turkey_states_list() {
593
-    return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) );
593
+    return apply_filters('wpinv_turkey_states', wpinv_get_country_states('TR'));
594 594
 }
595 595
 
596 596
 /**
@@ -600,31 +600,31 @@  discard block
 block discarded – undo
600 600
  * @return array
601 601
  */
602 602
 function wpinv_get_spain_states_list() {
603
-    return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) );
603
+    return apply_filters('wpinv_spain_states', wpinv_get_country_states('ES'));
604 604
 }
605 605
 
606 606
 function wpinv_get_states_field() {
607
-	if( empty( $_POST['country'] ) ) {
607
+	if (empty($_POST['country'])) {
608 608
 		$_POST['country'] = wpinv_get_default_country();
609 609
 	}
610
-	$states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
610
+	$states = wpinv_get_country_states(sanitize_text_field($_POST['country']));
611 611
 
612
-	if( !empty( $states ) ) {
613
-		$sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
612
+	if (!empty($states)) {
613
+		$sanitized_field_name = sanitize_text_field($_POST['field_name']);
614 614
 
615
-        $class  = isset( $_POST['class'] ) ? esc_attr( sanitize_text_field( $_POST['class'] ) ) : '';
615
+        $class  = isset($_POST['class']) ? esc_attr(sanitize_text_field($_POST['class'])) : '';
616 616
         $class .= " $sanitized_field_name getpaid_js_field-state custom-select wpinv-select wpi_select2";
617 617
 
618
-        $args  = array(
618
+        $args = array(
619 619
 			'name'    => $sanitized_field_name,
620 620
 			'id'      => $sanitized_field_name,
621
-			'class'   => implode( ' ', array_unique( explode( ' ', $class ) ) ),
622
-			'options' => array_merge( array( '' => '' ), $states ),
621
+			'class'   => implode(' ', array_unique(explode(' ', $class))),
622
+			'options' => array_merge(array('' => ''), $states),
623 623
 			'show_option_all'  => false,
624 624
 			'show_option_none' => false
625 625
 		);
626 626
 
627
-		$response = wpinv_html_select( $args );
627
+		$response = wpinv_html_select($args);
628 628
 
629 629
 	} else {
630 630
 		$response = 'nostates';
@@ -633,10 +633,10 @@  discard block
 block discarded – undo
633 633
 	return $response;
634 634
 }
635 635
 
636
-function wpinv_default_billing_country( $country = '', $user_id = 0 ) {
637
-    $country = !empty( $country ) ? $country : wpinv_get_default_country();
636
+function wpinv_default_billing_country($country = '', $user_id = 0) {
637
+    $country = !empty($country) ? $country : wpinv_get_default_country();
638 638
     
639
-    return apply_filters( 'wpinv_default_billing_country', $country, $user_id );
639
+    return apply_filters('wpinv_default_billing_country', $country, $user_id);
640 640
 }
641 641
 
642 642
 /**
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
  */
649 649
 function wpinv_get_address_formats() {
650 650
 
651
-		return apply_filters( 'wpinv_localisation_address_formats',
651
+		return apply_filters('wpinv_localisation_address_formats',
652 652
 			array(
653 653
 				'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}",
654 654
 				'AU'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}",
@@ -697,9 +697,9 @@  discard block
 block discarded – undo
697 697
  * @see `wpinv_get_invoice_address_replacements`
698 698
  * @return string
699 699
  */
700
-function wpinv_get_full_address_format( $country = false) {
700
+function wpinv_get_full_address_format($country = false) {
701 701
 
702
-    if( empty( $country ) ) {
702
+    if (empty($country)) {
703 703
         $country = wpinv_get_default_country();
704 704
     }
705 705
 
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
 	$formats = wpinv_get_address_formats();
708 708
 
709 709
 	// Get format for the specified country.
710
-	$format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];
710
+	$format = ($country && isset($formats[$country])) ? $formats[$country] : $formats['default'];
711 711
     
712 712
     /**
713 713
 	 * Filters the address format to use on Invoices.
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
 	 * @param string $format  The address format to use.
720 720
      * @param string $country The country who's address format is being retrieved.
721 721
 	 */
722
-    return apply_filters( 'wpinv_get_full_address_format', $format, $country );
722
+    return apply_filters('wpinv_get_full_address_format', $format, $country);
723 723
 }
724 724
 
725 725
 /**
@@ -730,7 +730,7 @@  discard block
 block discarded – undo
730 730
  * @param array $billing_details customer's billing details
731 731
  * @return array
732 732
  */
733
-function wpinv_get_invoice_address_replacements( $billing_details ) {
733
+function wpinv_get_invoice_address_replacements($billing_details) {
734 734
 
735 735
     $default_args = array(
736 736
         'address'           => '',
@@ -743,22 +743,22 @@  discard block
 block discarded – undo
743 743
 		'company'           => '',
744 744
     );
745 745
 
746
-    $args    = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' );
746
+    $args    = map_deep(wp_parse_args($billing_details, $default_args), 'trim');
747 747
     $state   = $args['state'];
748 748
     $country = $args['country'];
749 749
 
750 750
     // Handle full country name.
751
-    $full_country = empty( $country ) ? $country : wpinv_country_name( $country );
751
+    $full_country = empty($country) ? $country : wpinv_country_name($country);
752 752
 
753 753
     // Handle full state name.
754
-    $full_state   = ( $country && $state ) ?  wpinv_state_name( $state, $country ) : $state;
754
+    $full_state   = ($country && $state) ?  wpinv_state_name($state, $country) : $state;
755 755
 
756 756
     $args['postcode']    = $args['zip'];
757 757
     $args['name']        = $args['first_name'] . ' ' . $args['last_name'];
758 758
     $args['state']       = $full_state;
759 759
     $args['state_code']  = $state;
760 760
     $args['country']     = $full_country;
761
-    $args['country_code']= $country;
761
+    $args['country_code'] = $country;
762 762
 
763 763
     /**
764 764
 	 * Filters the address format replacements to use on Invoices.
@@ -769,14 +769,14 @@  discard block
 block discarded – undo
769 769
 	 * @param array $replacements  The address replacements to use.
770 770
      * @param array $billing_details  The billing details to use.
771 771
 	 */
772
-    $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details );
772
+    $replacements = apply_filters('wpinv_get_invoice_address_replacements', $args, $billing_details);
773 773
 
774 774
     $return = array();
775 775
 
776
-    foreach( $replacements as $key => $value ) {
777
-        $value  = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : '';
776
+    foreach ($replacements as $key => $value) {
777
+        $value = is_scalar($value) ? trim(sanitize_text_field($value)) : '';
778 778
         $return['{{' . $key . '}}'] = $value;
779
-        $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper( $value );
779
+        $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper($value);
780 780
     }
781 781
 
782 782
     return $return;
@@ -790,6 +790,6 @@  discard block
 block discarded – undo
790 790
  * @since 1.0.14
791 791
  * @return string
792 792
  */
793
-function wpinv_trim_formatted_address_line( $line ) {
794
-	return trim( $line, ', ' );
793
+function wpinv_trim_formatted_address_line($line) {
794
+	return trim($line, ', ');
795 795
 }
796 796
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-getpaid-invoice-notification-emails.php 2 patches
Indentation   +454 added lines, -454 removed lines patch added patch discarded remove patch
@@ -12,491 +12,491 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Invoice_Notification_Emails {
14 14
 
15
-	/**
16
-	 * The array of invoice email actions.
17
-	 *
18
-	 * @param array
19
-	 */
20
-	public $invoice_actions;
21
-
22
-	/**
23
-	 * Class constructor
24
-	 *
25
-	 */
26
-	public function __construct() {
27
-
28
-		$this->invoice_actions = apply_filters(
29
-			'getpaid_notification_email_invoice_triggers',
30
-			array(
31
-				'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
-				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
-				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
-				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
-				'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
-				'getpaid_invoice_status_publish'        => 'completed_invoice',
37
-				'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
-				'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
-				'getpaid_new_customer_note'             => 'user_note',
40
-				'getpaid_daily_maintenance'             => 'overdue',
41
-			)
42
-		);
43
-
44
-		$this->init_hooks();
45
-
46
-	}
47
-
48
-	/**
49
-	 * Registers email hooks.
50
-	 */
51
-	public function init_hooks() {
52
-
53
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
-
56
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
57
-			$this->init_email_type_hook( $hook, $email_type );
58
-		}
59
-	}
60
-
61
-	/**
62
-	 * Registers an email hook for an invoice action.
63
-	 * 
64
-	 * @param string $hook
65
-	 * @param string|array $email_type
66
-	 */
67
-	public function init_email_type_hook( $hook, $email_type ) {
68
-
69
-		$email_type = wpinv_parse_list( $email_type );
70
-
71
-		foreach ( $email_type as $type ) {
72
-
73
-			$email = new GetPaid_Notification_Email( $type );
74
-
75
-			// Abort if it is not active.
76
-			if ( ! $email->is_active() ) {
77
-				continue;
78
-			}
79
-
80
-			if ( method_exists( $this, $type ) ) {
81
-				add_action( $hook, array( $this, $type ), 100, 2 );
82
-				continue;
83
-			}
84
-
85
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
-		}
87
-
88
-	}
89
-
90
-	/**
91
-	 * Filters invoice merge tags.
92
-	 *
93
-	 * @param array $merge_tags
94
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
-	 */
96
-	public function invoice_merge_tags( $merge_tags, $object ) {
97
-
98
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
-			return array_merge(
100
-				$merge_tags,
101
-				$this->get_invoice_merge_tags( $object )
102
-			);
103
-		}
104
-
105
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
-			return array_merge(
107
-				$merge_tags,
108
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
109
-			);
110
-		}
111
-
112
-		return $merge_tags;
113
-
114
-	}
115
-
116
-	/**
117
-	 * Generates invoice merge tags.
118
-	 *
119
-	 * @param WPInv_Invoice $invoice
120
-	 * @return array
121
-	 */
122
-	public function get_invoice_merge_tags( $invoice ) {
123
-
124
-		// Abort if it does not exist.
125
-		if ( ! $invoice->get_id() ) {
126
-			return array();
127
-		}
128
-
129
-		$merge_tags = array(
130
-			'{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
-			'{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
-			'{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
-			'{email}'               => sanitize_email( $invoice->get_email() ),
135
-			'{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
-			'{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
-			'{invoice_total}'       => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
-			'{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
-			'{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
-			'{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
-			'{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
-			'{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
-			'{invoice_quote}'       => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
-			'{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
-			'{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
-			'{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
-			'{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
-		);
149
-
150
-		$payment_form_data = $invoice->get_meta( 'payment_form_data', true );
151
-
152
-		if ( is_array( $payment_form_data ) ) {
153
-
154
-			foreach ( $payment_form_data as $label => $value ) {
155
-
156
-				$label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
-				$value = is_array( $value ) ? implode( ', ', $value ) : $value;
158
-
159
-				if ( is_scalar ( $value ) ) {
160
-					$merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
161
-				}
162
-
163
-			}
164
-
165
-		}
166
-
167
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
168
-	}
169
-
170
-	/**
171
-	 * Helper function to send an email.
172
-	 *
173
-	 * @param WPInv_Invoice $invoice
174
-	 * @param GetPaid_Notification_Email $email
175
-	 * @param string $type
176
-	 * @param string|array $recipients
177
-	 * @param array $extra_args Extra template args.
178
-	 */
179
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
180
-
181
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
182
-
183
-		$skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
184
-		if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
185
-			return;
186
-		}
187
-
188
-		$mailer     = new GetPaid_Notification_Email_Sender();
189
-		$merge_tags = $email->get_merge_tags();
190
-
191
-		$result = $mailer->send(
192
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
193
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
194
-			$email->get_content( $merge_tags, $extra_args ),
195
-			$email->get_attachments()
196
-		);
197
-
198
-		// Maybe send a copy to the admin.
199
-		if ( $email->include_admin_bcc() ) {
200
-			$mailer->send(
201
-				wpinv_get_admin_email(),
202
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
203
-				$email->get_content( $merge_tags ),
204
-				$email->get_attachments()
205
-			);
206
-		}
207
-
208
-		if ( $result ) {
209
-			$invoice->add_system_note(
210
-				sprintf(
211
-					__( 'Successfully sent %s notification email to %s.', 'invoicing' ),
212
-					sanitize_key( $type ),
213
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
214
-				)
215
-			);
216
-		} else {
217
-			$invoice->add_system_note(
218
-				sprintf(
219
-					__( 'Failed sending %s notification email to %s.', 'invoicing' ),
220
-					sanitize_key( $type ),
221
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
222
-				)
223
-			);	
224
-		}
225
-
226
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
227
-
228
-		return $result;
229
-	}
230
-
231
-	/**
232
-	 * Also send emails to any cc users.
233
-	 *
234
-	 * @param array $recipients
235
-	 * @param GetPaid_Notification_Email $email
236
-	 */
237
-	public function filter_email_recipients( $recipients, $email ) {
238
-
239
-		if ( ! $email->is_admin_email() ) {
240
-			$cc   = $email->object->get_email_cc();
241
-			$cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true );
242
-
243
-			if ( ! empty( $cc ) ) {
244
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
245
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
246
-			}
247
-
248
-			if ( ! empty( $cc_2 ) ) {
249
-				$cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) );
250
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) );
251
-			}
252
-
253
-		}
254
-
255
-		return $recipients;
256
-
257
-	}
258
-
259
-	/**
260
-	 * Sends a new invoice notification.
261
-	 *
262
-	 * @param WPInv_Invoice $invoice
263
-	 */
264
-	public function new_invoice( $invoice ) {
265
-
266
-		// Only send this email for invoices created via the admin page.
267
-		if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
268
-			return;
269
-		}
270
-
271
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
272
-		$recipient = wpinv_get_admin_email();
273
-
274
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
275
-
276
-	}
277
-
278
-	/**
279
-	 * Sends a cancelled invoice notification.
280
-	 *
281
-	 * @param WPInv_Invoice $invoice
282
-	 */
283
-	public function cancelled_invoice( $invoice ) {
284
-
285
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
286
-		$recipient = $invoice->get_email();
287
-
288
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
289
-	}
290
-
291
-	/**
292
-	 * Sends a failed invoice notification.
293
-	 *
294
-	 * @param WPInv_Invoice $invoice
295
-	 */
296
-	public function failed_invoice( $invoice ) {
297
-
298
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
299
-		$recipient = wpinv_get_admin_email();
300
-
301
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
302
-
303
-	}
304
-
305
-	/**
306
-	 * Sends a notification whenever an invoice is put on hold.
307
-	 *
308
-	 * @param WPInv_Invoice $invoice
309
-	 */
310
-	public function onhold_invoice( $invoice ) {
311
-
312
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
313
-		$recipient = $invoice->get_email();
314
-
315
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
15
+    /**
16
+     * The array of invoice email actions.
17
+     *
18
+     * @param array
19
+     */
20
+    public $invoice_actions;
21
+
22
+    /**
23
+     * Class constructor
24
+     *
25
+     */
26
+    public function __construct() {
27
+
28
+        $this->invoice_actions = apply_filters(
29
+            'getpaid_notification_email_invoice_triggers',
30
+            array(
31
+                'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
+                'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
+                'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
+                'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
+                'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
+                'getpaid_invoice_status_publish'        => 'completed_invoice',
37
+                'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
+                'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
+                'getpaid_new_customer_note'             => 'user_note',
40
+                'getpaid_daily_maintenance'             => 'overdue',
41
+            )
42
+        );
43
+
44
+        $this->init_hooks();
45
+
46
+    }
47
+
48
+    /**
49
+     * Registers email hooks.
50
+     */
51
+    public function init_hooks() {
52
+
53
+        add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
+        add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
+
56
+        foreach ( $this->invoice_actions as $hook => $email_type ) {
57
+            $this->init_email_type_hook( $hook, $email_type );
58
+        }
59
+    }
60
+
61
+    /**
62
+     * Registers an email hook for an invoice action.
63
+     * 
64
+     * @param string $hook
65
+     * @param string|array $email_type
66
+     */
67
+    public function init_email_type_hook( $hook, $email_type ) {
68
+
69
+        $email_type = wpinv_parse_list( $email_type );
70
+
71
+        foreach ( $email_type as $type ) {
72
+
73
+            $email = new GetPaid_Notification_Email( $type );
74
+
75
+            // Abort if it is not active.
76
+            if ( ! $email->is_active() ) {
77
+                continue;
78
+            }
79
+
80
+            if ( method_exists( $this, $type ) ) {
81
+                add_action( $hook, array( $this, $type ), 100, 2 );
82
+                continue;
83
+            }
84
+
85
+            do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
+        }
87
+
88
+    }
89
+
90
+    /**
91
+     * Filters invoice merge tags.
92
+     *
93
+     * @param array $merge_tags
94
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
+     */
96
+    public function invoice_merge_tags( $merge_tags, $object ) {
97
+
98
+        if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
+            return array_merge(
100
+                $merge_tags,
101
+                $this->get_invoice_merge_tags( $object )
102
+            );
103
+        }
104
+
105
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
+            return array_merge(
107
+                $merge_tags,
108
+                $this->get_invoice_merge_tags( $object->get_parent_payment() )
109
+            );
110
+        }
111
+
112
+        return $merge_tags;
113
+
114
+    }
115
+
116
+    /**
117
+     * Generates invoice merge tags.
118
+     *
119
+     * @param WPInv_Invoice $invoice
120
+     * @return array
121
+     */
122
+    public function get_invoice_merge_tags( $invoice ) {
123
+
124
+        // Abort if it does not exist.
125
+        if ( ! $invoice->get_id() ) {
126
+            return array();
127
+        }
128
+
129
+        $merge_tags = array(
130
+            '{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
+            '{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
+            '{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
+            '{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
+            '{email}'               => sanitize_email( $invoice->get_email() ),
135
+            '{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
+            '{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
+            '{invoice_total}'       => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
+            '{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
+            '{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
+            '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
+            '{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
+            '{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
+            '{invoice_quote}'       => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
+            '{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
+            '{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
+            '{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
+            '{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
+        );
149
+
150
+        $payment_form_data = $invoice->get_meta( 'payment_form_data', true );
151
+
152
+        if ( is_array( $payment_form_data ) ) {
153
+
154
+            foreach ( $payment_form_data as $label => $value ) {
155
+
156
+                $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
+                $value = is_array( $value ) ? implode( ', ', $value ) : $value;
158
+
159
+                if ( is_scalar ( $value ) ) {
160
+                    $merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
161
+                }
162
+
163
+            }
164
+
165
+        }
166
+
167
+        return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
168
+    }
169
+
170
+    /**
171
+     * Helper function to send an email.
172
+     *
173
+     * @param WPInv_Invoice $invoice
174
+     * @param GetPaid_Notification_Email $email
175
+     * @param string $type
176
+     * @param string|array $recipients
177
+     * @param array $extra_args Extra template args.
178
+     */
179
+    public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
180
+
181
+        do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
182
+
183
+        $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
184
+        if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
185
+            return;
186
+        }
187
+
188
+        $mailer     = new GetPaid_Notification_Email_Sender();
189
+        $merge_tags = $email->get_merge_tags();
190
+
191
+        $result = $mailer->send(
192
+            apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
193
+            $email->add_merge_tags( $email->get_subject(), $merge_tags ),
194
+            $email->get_content( $merge_tags, $extra_args ),
195
+            $email->get_attachments()
196
+        );
197
+
198
+        // Maybe send a copy to the admin.
199
+        if ( $email->include_admin_bcc() ) {
200
+            $mailer->send(
201
+                wpinv_get_admin_email(),
202
+                $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
203
+                $email->get_content( $merge_tags ),
204
+                $email->get_attachments()
205
+            );
206
+        }
207
+
208
+        if ( $result ) {
209
+            $invoice->add_system_note(
210
+                sprintf(
211
+                    __( 'Successfully sent %s notification email to %s.', 'invoicing' ),
212
+                    sanitize_key( $type ),
213
+                    $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
214
+                )
215
+            );
216
+        } else {
217
+            $invoice->add_system_note(
218
+                sprintf(
219
+                    __( 'Failed sending %s notification email to %s.', 'invoicing' ),
220
+                    sanitize_key( $type ),
221
+                    $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
222
+                )
223
+            );	
224
+        }
225
+
226
+        do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
227
+
228
+        return $result;
229
+    }
230
+
231
+    /**
232
+     * Also send emails to any cc users.
233
+     *
234
+     * @param array $recipients
235
+     * @param GetPaid_Notification_Email $email
236
+     */
237
+    public function filter_email_recipients( $recipients, $email ) {
238
+
239
+        if ( ! $email->is_admin_email() ) {
240
+            $cc   = $email->object->get_email_cc();
241
+            $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true );
242
+
243
+            if ( ! empty( $cc ) ) {
244
+                $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
245
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
246
+            }
247
+
248
+            if ( ! empty( $cc_2 ) ) {
249
+                $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) );
250
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) );
251
+            }
252
+
253
+        }
254
+
255
+        return $recipients;
256
+
257
+    }
258
+
259
+    /**
260
+     * Sends a new invoice notification.
261
+     *
262
+     * @param WPInv_Invoice $invoice
263
+     */
264
+    public function new_invoice( $invoice ) {
265
+
266
+        // Only send this email for invoices created via the admin page.
267
+        if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
268
+            return;
269
+        }
270
+
271
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
272
+        $recipient = wpinv_get_admin_email();
273
+
274
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
275
+
276
+    }
277
+
278
+    /**
279
+     * Sends a cancelled invoice notification.
280
+     *
281
+     * @param WPInv_Invoice $invoice
282
+     */
283
+    public function cancelled_invoice( $invoice ) {
284
+
285
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
286
+        $recipient = $invoice->get_email();
287
+
288
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
289
+    }
290
+
291
+    /**
292
+     * Sends a failed invoice notification.
293
+     *
294
+     * @param WPInv_Invoice $invoice
295
+     */
296
+    public function failed_invoice( $invoice ) {
297
+
298
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
299
+        $recipient = wpinv_get_admin_email();
300
+
301
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
302
+
303
+    }
304
+
305
+    /**
306
+     * Sends a notification whenever an invoice is put on hold.
307
+     *
308
+     * @param WPInv_Invoice $invoice
309
+     */
310
+    public function onhold_invoice( $invoice ) {
311
+
312
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
313
+        $recipient = $invoice->get_email();
314
+
315
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
316 316
 
317
-	}
317
+    }
318 318
 
319
-	/**
320
-	 * Sends a notification whenever an invoice is marked as processing payment.
321
-	 *
322
-	 * @param WPInv_Invoice $invoice
323
-	 */
324
-	public function processing_invoice( $invoice ) {
319
+    /**
320
+     * Sends a notification whenever an invoice is marked as processing payment.
321
+     *
322
+     * @param WPInv_Invoice $invoice
323
+     */
324
+    public function processing_invoice( $invoice ) {
325 325
 
326
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
327
-		$recipient = $invoice->get_email();
328
-
329
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
330
-
331
-	}
332
-
333
-	/**
334
-	 * Sends a notification whenever an invoice is paid.
335
-	 *
336
-	 * @param WPInv_Invoice $invoice
337
-	 */
338
-	public function completed_invoice( $invoice ) {
326
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
327
+        $recipient = $invoice->get_email();
328
+
329
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
330
+
331
+    }
332
+
333
+    /**
334
+     * Sends a notification whenever an invoice is paid.
335
+     *
336
+     * @param WPInv_Invoice $invoice
337
+     */
338
+    public function completed_invoice( $invoice ) {
339 339
 
340
-		// (Maybe) abort if it is a renewal invoice.
341
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
342
-			return;
343
-		}
340
+        // (Maybe) abort if it is a renewal invoice.
341
+        if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
342
+            return;
343
+        }
344 344
 
345
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
346
-		$recipient = $invoice->get_email();
345
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
346
+        $recipient = $invoice->get_email();
347 347
 
348
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
348
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
349 349
 
350
-	}
350
+    }
351 351
 
352
-	/**
353
-	 * Sends a notification whenever an invoice is refunded.
354
-	 *
355
-	 * @param WPInv_Invoice $invoice
356
-	 */
357
-	public function refunded_invoice( $invoice ) {
352
+    /**
353
+     * Sends a notification whenever an invoice is refunded.
354
+     *
355
+     * @param WPInv_Invoice $invoice
356
+     */
357
+    public function refunded_invoice( $invoice ) {
358 358
 
359
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
360
-		$recipient = $invoice->get_email();
361
-
362
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
359
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
360
+        $recipient = $invoice->get_email();
361
+
362
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
363 363
 
364
-	}
364
+    }
365 365
 
366
-	/**
367
-	 * Notifies a user about new invoices
368
-	 *
369
-	 * @param WPInv_Invoice $invoice
370
-	 * @param bool $force
371
-	 */
372
-	public function user_invoice( $invoice, $force = false ) {
366
+    /**
367
+     * Notifies a user about new invoices
368
+     *
369
+     * @param WPInv_Invoice $invoice
370
+     * @param bool $force
371
+     */
372
+    public function user_invoice( $invoice, $force = false ) {
373 373
 
374
-		if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
375
-			return;
376
-		}
377
-
378
-		// Only send this email for invoices created via the admin page.
379
-		if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
380
-			return;
381
-		}
374
+        if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
375
+            return;
376
+        }
377
+
378
+        // Only send this email for invoices created via the admin page.
379
+        if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
380
+            return;
381
+        }
382 382
 
383
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
384
-		$recipient = $invoice->get_email();
385
-
386
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
383
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
384
+        $recipient = $invoice->get_email();
385
+
386
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
387 387
 
388
-	}
389
-
390
-	/**
391
-	 * Checks if an invoice is a payment form invoice.
392
-	 *
393
-	 * @param int $invoice
394
-	 * @return bool
395
-	 */
396
-	public function is_payment_form_invoice( $invoice ) {
397
-		$is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' === get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' === get_post_meta( $invoice, 'wpinv_created_via', true ) );
398
-		return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
399
-	}
388
+    }
389
+
390
+    /**
391
+     * Checks if an invoice is a payment form invoice.
392
+     *
393
+     * @param int $invoice
394
+     * @return bool
395
+     */
396
+    public function is_payment_form_invoice( $invoice ) {
397
+        $is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' === get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' === get_post_meta( $invoice, 'wpinv_created_via', true ) );
398
+        return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
399
+    }
400 400
 
401
-	/**
402
-	 * Notifies admin about new invoice notes
403
-	 *
404
-	 * @param WPInv_Invoice $invoice
405
-	 * @param string $note
406
-	 */
407
-	public function user_note( $invoice, $note ) {
408
-
409
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
410
-		$recipient = $invoice->get_email();
401
+    /**
402
+     * Notifies admin about new invoice notes
403
+     *
404
+     * @param WPInv_Invoice $invoice
405
+     * @param string $note
406
+     */
407
+    public function user_note( $invoice, $note ) {
408
+
409
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
410
+        $recipient = $invoice->get_email();
411 411
 
412
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
413
-
414
-	}
415
-
416
-	/**
417
-	 * (Force) Sends overdue notices.
418
-	 *
419
-	 * @param WPInv_Invoice $invoice
420
-	 */
421
-	public function force_send_overdue_notice( $invoice ) {
422
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
423
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
424
-	}
425
-
426
-	/**
427
-	 * Sends overdue notices.
428
-	 *
429
-	 * @TODO: Create an invoices query class.
430
-	 */
431
-	public function overdue() {
432
-		global $wpdb;
433
-
434
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
435
-
436
-		// Fetch reminder days.
437
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
438
-
439
-		// Abort if non is set.
440
-		if ( empty( $reminder_days ) ) {
441
-			return;
442
-		}
443
-
444
-		// Retrieve date query.
445
-		$date_query = $this->get_date_query( $reminder_days );
446
-
447
-		// Invoices table.
448
-		$table = $wpdb->prefix . 'getpaid_invoices';
449
-
450
-		// Fetch invoices.
451
-		$invoices  = $wpdb->get_col(
452
-			"SELECT posts.ID FROM $wpdb->posts as posts
412
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
413
+
414
+    }
415
+
416
+    /**
417
+     * (Force) Sends overdue notices.
418
+     *
419
+     * @param WPInv_Invoice $invoice
420
+     */
421
+    public function force_send_overdue_notice( $invoice ) {
422
+        $email = new GetPaid_Notification_Email( 'overdue', $invoice );
423
+        return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
424
+    }
425
+
426
+    /**
427
+     * Sends overdue notices.
428
+     *
429
+     * @TODO: Create an invoices query class.
430
+     */
431
+    public function overdue() {
432
+        global $wpdb;
433
+
434
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
435
+
436
+        // Fetch reminder days.
437
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
438
+
439
+        // Abort if non is set.
440
+        if ( empty( $reminder_days ) ) {
441
+            return;
442
+        }
443
+
444
+        // Retrieve date query.
445
+        $date_query = $this->get_date_query( $reminder_days );
446
+
447
+        // Invoices table.
448
+        $table = $wpdb->prefix . 'getpaid_invoices';
449
+
450
+        // Fetch invoices.
451
+        $invoices  = $wpdb->get_col(
452
+            "SELECT posts.ID FROM $wpdb->posts as posts
453 453
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
454 454
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
455 455
 
456
-		foreach ( $invoices as $invoice ) {
456
+        foreach ( $invoices as $invoice ) {
457 457
 
458
-			// Only send this email for invoices created via the admin page.
459
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
460
-				$invoice       = new WPInv_Invoice( $invoice );
461
-				$email->object = $invoice;
458
+            // Only send this email for invoices created via the admin page.
459
+            if ( ! $this->is_payment_form_invoice( $invoice ) ) {
460
+                $invoice       = new WPInv_Invoice( $invoice );
461
+                $email->object = $invoice;
462 462
 
463
-				if ( $invoice->needs_payment() ) {
464
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
465
-				}
463
+                if ( $invoice->needs_payment() ) {
464
+                    $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
465
+                }
466 466
 
467
-			}
467
+            }
468 468
 
469
-		}
469
+        }
470 470
 
471
-	}
471
+    }
472 472
 
473
-	/**
474
-	 * Calculates the date query for an invoices query
475
-	 *
476
-	 * @param array $reminder_days
477
-	 * @return string
478
-	 */
479
-	public function get_date_query( $reminder_days ) {
473
+    /**
474
+     * Calculates the date query for an invoices query
475
+     *
476
+     * @param array $reminder_days
477
+     * @return string
478
+     */
479
+    public function get_date_query( $reminder_days ) {
480 480
 
481
-		$date_query = array(
482
-			'relation'  => 'OR'
483
-		);
481
+        $date_query = array(
482
+            'relation'  => 'OR'
483
+        );
484 484
 
485
-		foreach ( $reminder_days as $days ) {
486
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
485
+        foreach ( $reminder_days as $days ) {
486
+            $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
487 487
 
488
-			$date_query[] = array(
489
-				'year'  => $date['year'],
490
-				'month' => $date['month'],
491
-				'day'   => $date['day'],
492
-			);
488
+            $date_query[] = array(
489
+                'year'  => $date['year'],
490
+                'month' => $date['month'],
491
+                'day'   => $date['day'],
492
+            );
493 493
 
494
-		}
494
+        }
495 495
 
496
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
496
+        $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
497 497
 
498
-		return $date_query->get_sql();
498
+        return $date_query->get_sql();
499 499
 
500
-	}
500
+    }
501 501
 
502 502
 }
Please login to merge, or discard this patch.
Spacing   +125 added lines, -125 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
  * This class handles invoice notificaiton emails.
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 		$this->invoice_actions = apply_filters(
29 29
 			'getpaid_notification_email_invoice_triggers',
30 30
 			array(
31
-				'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
31
+				'getpaid_new_invoice'                   => array('new_invoice', 'user_invoice'),
32 32
 				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33 33
 				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34 34
 				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
@@ -50,11 +50,11 @@  discard block
 block discarded – undo
50 50
 	 */
51 51
 	public function init_hooks() {
52 52
 
53
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
53
+		add_filter('getpaid_get_email_merge_tags', array($this, 'invoice_merge_tags'), 10, 2);
54
+		add_filter('getpaid_invoice_email_recipients', array($this, 'filter_email_recipients'), 10, 2);
55 55
 
56
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
57
-			$this->init_email_type_hook( $hook, $email_type );
56
+		foreach ($this->invoice_actions as $hook => $email_type) {
57
+			$this->init_email_type_hook($hook, $email_type);
58 58
 		}
59 59
 	}
60 60
 
@@ -64,25 +64,25 @@  discard block
 block discarded – undo
64 64
 	 * @param string $hook
65 65
 	 * @param string|array $email_type
66 66
 	 */
67
-	public function init_email_type_hook( $hook, $email_type ) {
67
+	public function init_email_type_hook($hook, $email_type) {
68 68
 
69
-		$email_type = wpinv_parse_list( $email_type );
69
+		$email_type = wpinv_parse_list($email_type);
70 70
 
71
-		foreach ( $email_type as $type ) {
71
+		foreach ($email_type as $type) {
72 72
 
73
-			$email = new GetPaid_Notification_Email( $type );
73
+			$email = new GetPaid_Notification_Email($type);
74 74
 
75 75
 			// Abort if it is not active.
76
-			if ( ! $email->is_active() ) {
76
+			if (!$email->is_active()) {
77 77
 				continue;
78 78
 			}
79 79
 
80
-			if ( method_exists( $this, $type ) ) {
81
-				add_action( $hook, array( $this, $type ), 100, 2 );
80
+			if (method_exists($this, $type)) {
81
+				add_action($hook, array($this, $type), 100, 2);
82 82
 				continue;
83 83
 			}
84 84
 
85
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
85
+			do_action('getpaid_invoice_init_email_type_hook', $type, $hook);
86 86
 		}
87 87
 
88 88
 	}
@@ -93,19 +93,19 @@  discard block
 block discarded – undo
93 93
 	 * @param array $merge_tags
94 94
 	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95 95
 	 */
96
-	public function invoice_merge_tags( $merge_tags, $object ) {
96
+	public function invoice_merge_tags($merge_tags, $object) {
97 97
 
98
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
98
+		if (is_a($object, 'WPInv_Invoice')) {
99 99
 			return array_merge(
100 100
 				$merge_tags,
101
-				$this->get_invoice_merge_tags( $object )
101
+				$this->get_invoice_merge_tags($object)
102 102
 			);
103 103
 		}
104 104
 
105
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
105
+		if (is_a($object, 'WPInv_Subscription')) {
106 106
 			return array_merge(
107 107
 				$merge_tags,
108
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
108
+				$this->get_invoice_merge_tags($object->get_parent_payment())
109 109
 			);
110 110
 		}
111 111
 
@@ -119,52 +119,52 @@  discard block
 block discarded – undo
119 119
 	 * @param WPInv_Invoice $invoice
120 120
 	 * @return array
121 121
 	 */
122
-	public function get_invoice_merge_tags( $invoice ) {
122
+	public function get_invoice_merge_tags($invoice) {
123 123
 
124 124
 		// Abort if it does not exist.
125
-		if ( ! $invoice->get_id() ) {
125
+		if (!$invoice->get_id()) {
126 126
 			return array();
127 127
 		}
128 128
 
129 129
 		$merge_tags = array(
130
-			'{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
-			'{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
-			'{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
-			'{email}'               => sanitize_email( $invoice->get_email() ),
135
-			'{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
-			'{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
-			'{invoice_total}'       => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
-			'{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
-			'{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
-			'{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
-			'{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
-			'{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
-			'{invoice_quote}'       => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
-			'{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
-			'{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
-			'{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
-			'{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
130
+			'{name}'                => sanitize_text_field($invoice->get_user_full_name()),
131
+			'{full_name}'           => sanitize_text_field($invoice->get_user_full_name()),
132
+			'{first_name}'          => sanitize_text_field($invoice->get_first_name()),
133
+			'{last_name}'           => sanitize_text_field($invoice->get_last_name()),
134
+			'{email}'               => sanitize_email($invoice->get_email()),
135
+			'{invoice_number}'      => sanitize_text_field($invoice->get_number()),
136
+			'{invoice_currency}'    => sanitize_text_field($invoice->get_currency()),
137
+			'{invoice_total}'       => sanitize_text_field(wpinv_price($invoice->get_total(), $invoice->get_currency())),
138
+			'{invoice_link}'        => esc_url($invoice->get_view_url()),
139
+			'{invoice_pay_link}'    => esc_url($invoice->get_checkout_payment_url()),
140
+			'{invoice_receipt_link}'=> esc_url($invoice->get_receipt_url()),
141
+			'{invoice_date}'        => getpaid_format_date_value($invoice->get_date_created()),
142
+			'{invoice_due_date}'    => getpaid_format_date_value($invoice->get_due_date(), __('on receipt', 'invoicing')),
143
+			'{invoice_quote}'       => sanitize_text_field(strtolower($invoice->get_label())),
144
+			'{invoice_label}'       => sanitize_text_field(ucfirst($invoice->get_label())),
145
+			'{invoice_description}' => wp_kses_post($invoice->get_description()),
146
+			'{subscription_name}'   => wp_kses_post($invoice->get_subscription_name()),
147
+			'{is_was}'              => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'),
148 148
 		);
149 149
 
150
-		$payment_form_data = $invoice->get_meta( 'payment_form_data', true );
150
+		$payment_form_data = $invoice->get_meta('payment_form_data', true);
151 151
 
152
-		if ( is_array( $payment_form_data ) ) {
152
+		if (is_array($payment_form_data)) {
153 153
 
154
-			foreach ( $payment_form_data as $label => $value ) {
154
+			foreach ($payment_form_data as $label => $value) {
155 155
 
156
-				$label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
-				$value = is_array( $value ) ? implode( ', ', $value ) : $value;
156
+				$label = preg_replace('/[^a-z0-9]+/', '_', strtolower($label));
157
+				$value = is_array($value) ? implode(', ', $value) : $value;
158 158
 
159
-				if ( is_scalar ( $value ) ) {
160
-					$merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
159
+				if (is_scalar($value)) {
160
+					$merge_tags["{{$label}}"] = wp_kses_post($value);
161 161
 				}
162 162
 
163 163
 			}
164 164
 
165 165
 		}
166 166
 
167
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
167
+		return apply_filters('getpaid_invoice_email_merge_tags', $merge_tags, $invoice);
168 168
 	}
169 169
 
170 170
 	/**
@@ -176,12 +176,12 @@  discard block
 block discarded – undo
176 176
 	 * @param string|array $recipients
177 177
 	 * @param array $extra_args Extra template args.
178 178
 	 */
179
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
179
+	public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) {
180 180
 
181
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
181
+		do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email);
182 182
 
183
-		$skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
184
-		if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
183
+		$skip = $invoice->is_free() && wpinv_get_option('skip_email_free_invoice');
184
+		if (apply_filters('getpaid_skip_invoice_email', $skip, $type, $invoice)) {
185 185
 			return;
186 186
 		}
187 187
 
@@ -189,41 +189,41 @@  discard block
 block discarded – undo
189 189
 		$merge_tags = $email->get_merge_tags();
190 190
 
191 191
 		$result = $mailer->send(
192
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
193
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
194
-			$email->get_content( $merge_tags, $extra_args ),
192
+			apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email),
193
+			$email->add_merge_tags($email->get_subject(), $merge_tags),
194
+			$email->get_content($merge_tags, $extra_args),
195 195
 			$email->get_attachments()
196 196
 		);
197 197
 
198 198
 		// Maybe send a copy to the admin.
199
-		if ( $email->include_admin_bcc() ) {
199
+		if ($email->include_admin_bcc()) {
200 200
 			$mailer->send(
201 201
 				wpinv_get_admin_email(),
202
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
203
-				$email->get_content( $merge_tags ),
202
+				$email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags),
203
+				$email->get_content($merge_tags),
204 204
 				$email->get_attachments()
205 205
 			);
206 206
 		}
207 207
 
208
-		if ( $result ) {
208
+		if ($result) {
209 209
 			$invoice->add_system_note(
210 210
 				sprintf(
211
-					__( 'Successfully sent %s notification email to %s.', 'invoicing' ),
212
-					sanitize_key( $type ),
213
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
211
+					__('Successfully sent %s notification email to %s.', 'invoicing'),
212
+					sanitize_key($type),
213
+					$email->is_admin_email() ? __('admin') : __('the customer')
214 214
 				)
215 215
 			);
216 216
 		} else {
217 217
 			$invoice->add_system_note(
218 218
 				sprintf(
219
-					__( 'Failed sending %s notification email to %s.', 'invoicing' ),
220
-					sanitize_key( $type ),
221
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
219
+					__('Failed sending %s notification email to %s.', 'invoicing'),
220
+					sanitize_key($type),
221
+					$email->is_admin_email() ? __('admin') : __('the customer')
222 222
 				)
223 223
 			);	
224 224
 		}
225 225
 
226
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
226
+		do_action('getpaid_after_send_invoice_notification', $type, $invoice, $email);
227 227
 
228 228
 		return $result;
229 229
 	}
@@ -234,20 +234,20 @@  discard block
 block discarded – undo
234 234
 	 * @param array $recipients
235 235
 	 * @param GetPaid_Notification_Email $email
236 236
 	 */
237
-	public function filter_email_recipients( $recipients, $email ) {
237
+	public function filter_email_recipients($recipients, $email) {
238 238
 
239
-		if ( ! $email->is_admin_email() ) {
239
+		if (!$email->is_admin_email()) {
240 240
 			$cc   = $email->object->get_email_cc();
241
-			$cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true );
241
+			$cc_2 = get_user_meta($email->object->get_user_id(), '_wpinv_email_cc', true);
242 242
 
243
-			if ( ! empty( $cc ) ) {
244
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
245
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
243
+			if (!empty($cc)) {
244
+				$cc = array_map('sanitize_email', wpinv_parse_list($cc));
245
+				$recipients = array_filter(array_unique(array_merge($recipients, $cc)));
246 246
 			}
247 247
 
248
-			if ( ! empty( $cc_2 ) ) {
249
-				$cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) );
250
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) );
248
+			if (!empty($cc_2)) {
249
+				$cc_2 = array_map('sanitize_email', wpinv_parse_list($cc_2));
250
+				$recipients = array_filter(array_unique(array_merge($recipients, $cc_2)));
251 251
 			}
252 252
 
253 253
 		}
@@ -261,17 +261,17 @@  discard block
 block discarded – undo
261 261
 	 *
262 262
 	 * @param WPInv_Invoice $invoice
263 263
 	 */
264
-	public function new_invoice( $invoice ) {
264
+	public function new_invoice($invoice) {
265 265
 
266 266
 		// Only send this email for invoices created via the admin page.
267
-		if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
267
+		if (!$invoice->is_type('invoice') || $invoice->is_paid() || $this->is_payment_form_invoice($invoice->get_id())) {
268 268
 			return;
269 269
 		}
270 270
 
271
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
271
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
272 272
 		$recipient = wpinv_get_admin_email();
273 273
 
274
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
274
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
275 275
 
276 276
 	}
277 277
 
@@ -280,12 +280,12 @@  discard block
 block discarded – undo
280 280
 	 *
281 281
 	 * @param WPInv_Invoice $invoice
282 282
 	 */
283
-	public function cancelled_invoice( $invoice ) {
283
+	public function cancelled_invoice($invoice) {
284 284
 
285
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
285
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
286 286
 		$recipient = $invoice->get_email();
287 287
 
288
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
288
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
289 289
 	}
290 290
 
291 291
 	/**
@@ -293,12 +293,12 @@  discard block
 block discarded – undo
293 293
 	 *
294 294
 	 * @param WPInv_Invoice $invoice
295 295
 	 */
296
-	public function failed_invoice( $invoice ) {
296
+	public function failed_invoice($invoice) {
297 297
 
298
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
298
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
299 299
 		$recipient = wpinv_get_admin_email();
300 300
 
301
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
301
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
302 302
 
303 303
 	}
304 304
 
@@ -307,12 +307,12 @@  discard block
 block discarded – undo
307 307
 	 *
308 308
 	 * @param WPInv_Invoice $invoice
309 309
 	 */
310
-	public function onhold_invoice( $invoice ) {
310
+	public function onhold_invoice($invoice) {
311 311
 
312
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
312
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
313 313
 		$recipient = $invoice->get_email();
314 314
 
315
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
315
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
316 316
 
317 317
 	}
318 318
 
@@ -321,12 +321,12 @@  discard block
 block discarded – undo
321 321
 	 *
322 322
 	 * @param WPInv_Invoice $invoice
323 323
 	 */
324
-	public function processing_invoice( $invoice ) {
324
+	public function processing_invoice($invoice) {
325 325
 
326
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
326
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
327 327
 		$recipient = $invoice->get_email();
328 328
 
329
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
329
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
330 330
 
331 331
 	}
332 332
 
@@ -335,17 +335,17 @@  discard block
 block discarded – undo
335 335
 	 *
336 336
 	 * @param WPInv_Invoice $invoice
337 337
 	 */
338
-	public function completed_invoice( $invoice ) {
338
+	public function completed_invoice($invoice) {
339 339
 
340 340
 		// (Maybe) abort if it is a renewal invoice.
341
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
341
+		if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) {
342 342
 			return;
343 343
 		}
344 344
 
345
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
345
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
346 346
 		$recipient = $invoice->get_email();
347 347
 
348
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
348
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
349 349
 
350 350
 	}
351 351
 
@@ -354,12 +354,12 @@  discard block
 block discarded – undo
354 354
 	 *
355 355
 	 * @param WPInv_Invoice $invoice
356 356
 	 */
357
-	public function refunded_invoice( $invoice ) {
357
+	public function refunded_invoice($invoice) {
358 358
 
359
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
359
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
360 360
 		$recipient = $invoice->get_email();
361 361
 
362
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
362
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
363 363
 
364 364
 	}
365 365
 
@@ -369,21 +369,21 @@  discard block
 block discarded – undo
369 369
 	 * @param WPInv_Invoice $invoice
370 370
 	 * @param bool $force
371 371
 	 */
372
-	public function user_invoice( $invoice, $force = false ) {
372
+	public function user_invoice($invoice, $force = false) {
373 373
 
374
-		if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
374
+		if (!$force && !empty($GLOBALS['wpinv_skip_invoice_notification'])) {
375 375
 			return;
376 376
 		}
377 377
 
378 378
 		// Only send this email for invoices created via the admin page.
379
-		if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
379
+		if (!$invoice->is_type('invoice') || (empty($force) && $invoice->is_paid()) || (empty($force) && $this->is_payment_form_invoice($invoice->get_id()))) {
380 380
 			return;
381 381
 		}
382 382
 
383
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
383
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
384 384
 		$recipient = $invoice->get_email();
385 385
 
386
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
386
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
387 387
 
388 388
 	}
389 389
 
@@ -393,9 +393,9 @@  discard block
 block discarded – undo
393 393
 	 * @param int $invoice
394 394
 	 * @return bool
395 395
 	 */
396
-	public function is_payment_form_invoice( $invoice ) {
397
-		$is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' === get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' === get_post_meta( $invoice, 'wpinv_created_via', true ) );
398
-		return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
396
+	public function is_payment_form_invoice($invoice) {
397
+		$is_payment_form_invoice = empty($_GET['getpaid-admin-action']) && ('payment_form' === get_post_meta($invoice, 'wpinv_created_via', true) || 'geodirectory' === get_post_meta($invoice, 'wpinv_created_via', true));
398
+		return apply_filters('getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice);
399 399
 	}
400 400
 
401 401
 	/**
@@ -404,12 +404,12 @@  discard block
 block discarded – undo
404 404
 	 * @param WPInv_Invoice $invoice
405 405
 	 * @param string $note
406 406
 	 */
407
-	public function user_note( $invoice, $note ) {
407
+	public function user_note($invoice, $note) {
408 408
 
409
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
409
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
410 410
 		$recipient = $invoice->get_email();
411 411
 
412
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
412
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note));
413 413
 
414 414
 	}
415 415
 
@@ -418,9 +418,9 @@  discard block
 block discarded – undo
418 418
 	 *
419 419
 	 * @param WPInv_Invoice $invoice
420 420
 	 */
421
-	public function force_send_overdue_notice( $invoice ) {
422
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
423
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
421
+	public function force_send_overdue_notice($invoice) {
422
+		$email = new GetPaid_Notification_Email('overdue', $invoice);
423
+		return $this->send_email($invoice, $email, 'overdue', $invoice->get_email());
424 424
 	}
425 425
 
426 426
 	/**
@@ -431,37 +431,37 @@  discard block
 block discarded – undo
431 431
 	public function overdue() {
432 432
 		global $wpdb;
433 433
 
434
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
434
+		$email = new GetPaid_Notification_Email(__FUNCTION__);
435 435
 
436 436
 		// Fetch reminder days.
437
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
437
+		$reminder_days = array_unique(wp_parse_id_list($email->get_option('days')));
438 438
 
439 439
 		// Abort if non is set.
440
-		if ( empty( $reminder_days ) ) {
440
+		if (empty($reminder_days)) {
441 441
 			return;
442 442
 		}
443 443
 
444 444
 		// Retrieve date query.
445
-		$date_query = $this->get_date_query( $reminder_days );
445
+		$date_query = $this->get_date_query($reminder_days);
446 446
 
447 447
 		// Invoices table.
448 448
 		$table = $wpdb->prefix . 'getpaid_invoices';
449 449
 
450 450
 		// Fetch invoices.
451
-		$invoices  = $wpdb->get_col(
451
+		$invoices = $wpdb->get_col(
452 452
 			"SELECT posts.ID FROM $wpdb->posts as posts
453 453
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
454 454
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
455 455
 
456
-		foreach ( $invoices as $invoice ) {
456
+		foreach ($invoices as $invoice) {
457 457
 
458 458
 			// Only send this email for invoices created via the admin page.
459
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
460
-				$invoice       = new WPInv_Invoice( $invoice );
459
+			if (!$this->is_payment_form_invoice($invoice)) {
460
+				$invoice       = new WPInv_Invoice($invoice);
461 461
 				$email->object = $invoice;
462 462
 
463
-				if ( $invoice->needs_payment() ) {
464
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
463
+				if ($invoice->needs_payment()) {
464
+					$this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email());
465 465
 				}
466 466
 
467 467
 			}
@@ -476,14 +476,14 @@  discard block
 block discarded – undo
476 476
 	 * @param array $reminder_days
477 477
 	 * @return string
478 478
 	 */
479
-	public function get_date_query( $reminder_days ) {
479
+	public function get_date_query($reminder_days) {
480 480
 
481 481
 		$date_query = array(
482 482
 			'relation'  => 'OR'
483 483
 		);
484 484
 
485
-		foreach ( $reminder_days as $days ) {
486
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
485
+		foreach ($reminder_days as $days) {
486
+			$date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp'))));
487 487
 
488 488
 			$date_query[] = array(
489 489
 				'year'  => $date['year'],
@@ -493,7 +493,7 @@  discard block
 block discarded – undo
493 493
 
494 494
 		}
495 495
 
496
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
496
+		$date_query = new WP_Date_Query($date_query, 'invoices.due_date');
497 497
 
498 498
 		return $date_query->get_sql();
499 499
 
Please login to merge, or discard this patch.
includes/admin/class-getpaid-metaboxes.php 2 patches
Indentation   +240 added lines, -240 removed lines patch added patch discarded remove patch
@@ -12,276 +12,276 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Metaboxes {
14 14
 
15
-	/**
16
-	 * Only save metaboxes once.
17
-	 *
18
-	 * @var boolean
19
-	 */
20
-	private static $saved_meta_boxes = false;
21
-
22 15
     /**
23
-	 * Hook in methods.
24
-	 */
25
-	public static function init() {
26
-
27
-		// Register metaboxes.
28
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
29
-
30
-		// Remove metaboxes.
31
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
32
-
33
-		// Rename metaboxes.
34
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
35
-
36
-		// Save metaboxes.
37
-		add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
-	}
39
-
40
-	/**
41
-	 * Register core metaboxes.
42
-	 */
43
-	public static function add_meta_boxes( $post_type, $post ) {
44
-
45
-		// For invoices...
46
-		self::add_invoice_meta_boxes( $post_type, $post );
47
-
48
-		// For payment forms.
49
-		self::add_payment_form_meta_boxes( $post_type, $post );
50
-
51
-		// For invoice items.
52
-		self::add_item_meta_boxes( $post_type );
53
-
54
-		// For invoice discounts.
55
-		if ( $post_type == 'wpi_discount' ) {
56
-			add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
57
-		}
58
-
59
-	}
16
+     * Only save metaboxes once.
17
+     *
18
+     * @var boolean
19
+     */
20
+    private static $saved_meta_boxes = false;
60 21
 
61
-	/**
62
-	 * Register core metaboxes.
63
-	 */
64
-	protected static function add_payment_form_meta_boxes( $post_type, $post ) {
22
+    /**
23
+     * Hook in methods.
24
+     */
25
+    public static function init() {
65 26
 
66
-		// For payment forms.
67
-		if ( $post_type == 'wpi_payment_form' ) {
27
+        // Register metaboxes.
28
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
68 29
 
69
-			// Design payment form.
70
-			add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
30
+        // Remove metaboxes.
31
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
71 32
 
72
-			// Payment form information.
73
-			if ( $post->ID != wpinv_get_default_payment_form() ) {
74
-				add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
75
-			}
33
+        // Rename metaboxes.
34
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
76 35
 
77
-		}
36
+        // Save metaboxes.
37
+        add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
+    }
78 39
 
79
-	}
40
+    /**
41
+     * Register core metaboxes.
42
+     */
43
+    public static function add_meta_boxes( $post_type, $post ) {
80 44
 
81
-	/**
82
-	 * Register core metaboxes.
83
-	 */
84
-	protected static function add_item_meta_boxes( $post_type ) {
45
+        // For invoices...
46
+        self::add_invoice_meta_boxes( $post_type, $post );
85 47
 
86
-		if ( $post_type == 'wpi_item' ) {
48
+        // For payment forms.
49
+        self::add_payment_form_meta_boxes( $post_type, $post );
87 50
 
88
-			// Item details.
89
-			add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
51
+        // For invoice items.
52
+        self::add_item_meta_boxes( $post_type );
90 53
 
91
-			// If taxes are enabled, register the tax metabox.
92
-			if ( wpinv_use_taxes() ) {
93
-				add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
94
-			}
54
+        // For invoice discounts.
55
+        if ( $post_type == 'wpi_discount' ) {
56
+            add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
57
+        }
95 58
 
96
-			// Item info.
97
-			add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
59
+    }
98 60
 
99
-		}
61
+    /**
62
+     * Register core metaboxes.
63
+     */
64
+    protected static function add_payment_form_meta_boxes( $post_type, $post ) {
100 65
 
101
-	}
66
+        // For payment forms.
67
+        if ( $post_type == 'wpi_payment_form' ) {
102 68
 
103
-	/**
104
-	 * Register invoice metaboxes.
105
-	 */
106
-	protected static function add_invoice_meta_boxes( $post_type, $post ) {
69
+            // Design payment form.
70
+            add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
107 71
 
108
-		// For invoices...
109
-		if ( getpaid_is_invoice_post_type( $post_type ) ) {
110
-			$invoice = new WPInv_Invoice( $post );
72
+            // Payment form information.
73
+            if ( $post->ID != wpinv_get_default_payment_form() ) {
74
+                add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
75
+            }
111 76
 
112
-			// Resend invoice.
113
-			if ( ! $invoice->is_draft() ) {
77
+        }
114 78
 
115
-				add_meta_box(
116
-					'wpinv-mb-resend-invoice',
117
-					sprintf(
118
-						__( 'Resend %s', 'invoicing' ),
119
-						ucfirst( $invoice->get_invoice_quote_type() )
120
-					),
121
-					'GetPaid_Meta_Box_Resend_Invoice::output',
122
-					$post_type,
123
-					'side',
124
-					'low'
125
-				);
79
+    }
126 80
 
127
-			}
81
+    /**
82
+     * Register core metaboxes.
83
+     */
84
+    protected static function add_item_meta_boxes( $post_type ) {
128 85
 
129
-			// Subscriptions.
130
-			$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
131
-			if ( ! empty( $subscriptions ) ) {
86
+        if ( $post_type == 'wpi_item' ) {
132 87
 
133
-				if ( is_array( $subscriptions ) ) {
134
-					add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' );
135
-				} else {
136
-					add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
137
-				}
88
+            // Item details.
89
+            add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
138 90
 
139
-				if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) {
140
-					add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
141
-				}
91
+            // If taxes are enabled, register the tax metabox.
92
+            if ( wpinv_use_taxes() ) {
93
+                add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
94
+            }
142 95
 
143
-			}
96
+            // Item info.
97
+            add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
144 98
 
145
-			// Invoice details.
146
-			add_meta_box(
147
-				'wpinv-details',
148
-				sprintf(
149
-					__( '%s Details', 'invoicing' ),
150
-					ucfirst( $invoice->get_invoice_quote_type() )
151
-				),
152
-				'GetPaid_Meta_Box_Invoice_Details::output',
153
-				$post_type,
154
-				'side'
155
-			);
99
+        }
156 100
 
157
-			// Payment details.
158
-			add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
101
+    }
159 102
 
160
-			// Billing details.
161
-			add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
103
+    /**
104
+     * Register invoice metaboxes.
105
+     */
106
+    protected static function add_invoice_meta_boxes( $post_type, $post ) {
107
+
108
+        // For invoices...
109
+        if ( getpaid_is_invoice_post_type( $post_type ) ) {
110
+            $invoice = new WPInv_Invoice( $post );
111
+
112
+            // Resend invoice.
113
+            if ( ! $invoice->is_draft() ) {
114
+
115
+                add_meta_box(
116
+                    'wpinv-mb-resend-invoice',
117
+                    sprintf(
118
+                        __( 'Resend %s', 'invoicing' ),
119
+                        ucfirst( $invoice->get_invoice_quote_type() )
120
+                    ),
121
+                    'GetPaid_Meta_Box_Resend_Invoice::output',
122
+                    $post_type,
123
+                    'side',
124
+                    'low'
125
+                );
126
+
127
+            }
128
+
129
+            // Subscriptions.
130
+            $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
131
+            if ( ! empty( $subscriptions ) ) {
132
+
133
+                if ( is_array( $subscriptions ) ) {
134
+                    add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' );
135
+                } else {
136
+                    add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
137
+                }
138
+
139
+                if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) {
140
+                    add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
141
+                }
142
+
143
+            }
144
+
145
+            // Invoice details.
146
+            add_meta_box(
147
+                'wpinv-details',
148
+                sprintf(
149
+                    __( '%s Details', 'invoicing' ),
150
+                    ucfirst( $invoice->get_invoice_quote_type() )
151
+                ),
152
+                'GetPaid_Meta_Box_Invoice_Details::output',
153
+                $post_type,
154
+                'side'
155
+            );
156
+
157
+            // Payment details.
158
+            add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
159
+
160
+            // Billing details.
161
+            add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
162 162
 			
163
-			// Invoice items.
164
-			add_meta_box(
165
-				'wpinv-items',
166
-				sprintf(
167
-					__( '%s Items', 'invoicing' ),
168
-					ucfirst( $invoice->get_invoice_quote_type() )
169
-				),
170
-				'GetPaid_Meta_Box_Invoice_Items::output',
171
-				$post_type,
172
-				'normal',
173
-				'high'
174
-			);
163
+            // Invoice items.
164
+            add_meta_box(
165
+                'wpinv-items',
166
+                sprintf(
167
+                    __( '%s Items', 'invoicing' ),
168
+                    ucfirst( $invoice->get_invoice_quote_type() )
169
+                ),
170
+                'GetPaid_Meta_Box_Invoice_Items::output',
171
+                $post_type,
172
+                'normal',
173
+                'high'
174
+            );
175 175
 			
176
-			// Invoice notes.
177
-			add_meta_box(
178
-				'wpinv-notes',
179
-				sprintf(
180
-					__( '%s Notes', 'invoicing' ),
181
-					ucfirst( $invoice->get_invoice_quote_type() )
182
-				),
183
-				'WPInv_Meta_Box_Notes::output',
184
-				$post_type,
185
-				'side',
186
-				'low'
187
-			);
188
-
189
-			// Shipping Address.
190
-			if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) {
191
-				add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
192
-			}
193
-
194
-			// Payment form information.
195
-			if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) {
196
-				add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
197
-			}
198
-
199
-		}
200
-
201
-	}
202
-
203
-	/**
204
-	 * Remove some metaboxes.
205
-	 */
206
-	public static function remove_meta_boxes() {
207
-		remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
208
-	}
209
-
210
-	/**
211
-	 * Rename other metaboxes.
212
-	 */
213
-	public static function rename_meta_boxes() {
176
+            // Invoice notes.
177
+            add_meta_box(
178
+                'wpinv-notes',
179
+                sprintf(
180
+                    __( '%s Notes', 'invoicing' ),
181
+                    ucfirst( $invoice->get_invoice_quote_type() )
182
+                ),
183
+                'WPInv_Meta_Box_Notes::output',
184
+                $post_type,
185
+                'side',
186
+                'low'
187
+            );
188
+
189
+            // Shipping Address.
190
+            if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) {
191
+                add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
192
+            }
193
+
194
+            // Payment form information.
195
+            if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) {
196
+                add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
197
+            }
198
+
199
+        }
200
+
201
+    }
202
+
203
+    /**
204
+     * Remove some metaboxes.
205
+     */
206
+    public static function remove_meta_boxes() {
207
+        remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
208
+    }
209
+
210
+    /**
211
+     * Rename other metaboxes.
212
+     */
213
+    public static function rename_meta_boxes() {
214 214
 		
215
-	}
216
-
217
-	/**
218
-	 * Check if we're saving, then trigger an action based on the post type.
219
-	 *
220
-	 * @param  int    $post_id Post ID.
221
-	 * @param  object $post Post object.
222
-	 */
223
-	public static function save_meta_boxes( $post_id, $post ) {
224
-		$post_id = absint( $post_id );
225
-		$data    = wp_kses_post_deep( wp_unslash( $_POST ) );
226
-
227
-		// Do not save for ajax requests.
228
-		if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
229
-			return;
230
-		}
231
-
232
-		// $post_id and $post are required
233
-		if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
234
-			return;
235
-		}
236
-
237
-		// Dont' save meta boxes for revisions or autosaves.
238
-		if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
239
-			return;
240
-		}
241
-
242
-		// Check the nonce.
243
-		if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
244
-			return;
245
-		}
246
-
247
-		// Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
248
-		if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
249
-			return;
250
-		}
251
-
252
-		// Check user has permission to edit.
253
-		if ( ! current_user_can( 'edit_post', $post_id ) ) {
254
-			return;
255
-		}
256
-
257
-		if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
258
-
259
-			// We need this save event to run once to avoid potential endless loops.
260
-			self::$saved_meta_boxes = true;
261
-
262
-			return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
263
-
264
-		}
265
-
266
-		// Ensure this is our post type.
267
-		$post_types_map = array(
268
-			'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
269
-			'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
270
-			'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
271
-		);
272
-
273
-		// Is this our post type?
274
-		if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
275
-			return;
276
-		}
277
-
278
-		// We need this save event to run once to avoid potential endless loops.
279
-		self::$saved_meta_boxes = true;
215
+    }
216
+
217
+    /**
218
+     * Check if we're saving, then trigger an action based on the post type.
219
+     *
220
+     * @param  int    $post_id Post ID.
221
+     * @param  object $post Post object.
222
+     */
223
+    public static function save_meta_boxes( $post_id, $post ) {
224
+        $post_id = absint( $post_id );
225
+        $data    = wp_kses_post_deep( wp_unslash( $_POST ) );
226
+
227
+        // Do not save for ajax requests.
228
+        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
229
+            return;
230
+        }
231
+
232
+        // $post_id and $post are required
233
+        if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
234
+            return;
235
+        }
236
+
237
+        // Dont' save meta boxes for revisions or autosaves.
238
+        if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
239
+            return;
240
+        }
241
+
242
+        // Check the nonce.
243
+        if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
244
+            return;
245
+        }
246
+
247
+        // Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
248
+        if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
249
+            return;
250
+        }
251
+
252
+        // Check user has permission to edit.
253
+        if ( ! current_user_can( 'edit_post', $post_id ) ) {
254
+            return;
255
+        }
256
+
257
+        if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
258
+
259
+            // We need this save event to run once to avoid potential endless loops.
260
+            self::$saved_meta_boxes = true;
261
+
262
+            return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
263
+
264
+        }
265
+
266
+        // Ensure this is our post type.
267
+        $post_types_map = array(
268
+            'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
269
+            'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
270
+            'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
271
+        );
272
+
273
+        // Is this our post type?
274
+        if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
275
+            return;
276
+        }
277
+
278
+        // We need this save event to run once to avoid potential endless loops.
279
+        self::$saved_meta_boxes = true;
280 280
 		
281
-		// Save the post.
282
-		$class = $post_types_map[ $post->post_type ];
283
-		$class::save( $post_id, wp_kses_post_deep( $_POST ), $post );
281
+        // Save the post.
282
+        $class = $post_types_map[ $post->post_type ];
283
+        $class::save( $post_id, wp_kses_post_deep( $_POST ), $post );
284 284
 
285
-	}
285
+    }
286 286
 
287 287
 }
Please login to merge, or discard this patch.
Spacing   +62 added lines, -62 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
  * Metaboxes Admin Class
@@ -25,35 +25,35 @@  discard block
 block discarded – undo
25 25
 	public static function init() {
26 26
 
27 27
 		// Register metaboxes.
28
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
28
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2);
29 29
 
30 30
 		// Remove metaboxes.
31
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
31
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30);
32 32
 
33 33
 		// Rename metaboxes.
34
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
34
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45);
35 35
 
36 36
 		// Save metaboxes.
37
-		add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
37
+		add_action('save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2);
38 38
 	}
39 39
 
40 40
 	/**
41 41
 	 * Register core metaboxes.
42 42
 	 */
43
-	public static function add_meta_boxes( $post_type, $post ) {
43
+	public static function add_meta_boxes($post_type, $post) {
44 44
 
45 45
 		// For invoices...
46
-		self::add_invoice_meta_boxes( $post_type, $post );
46
+		self::add_invoice_meta_boxes($post_type, $post);
47 47
 
48 48
 		// For payment forms.
49
-		self::add_payment_form_meta_boxes( $post_type, $post );
49
+		self::add_payment_form_meta_boxes($post_type, $post);
50 50
 
51 51
 		// For invoice items.
52
-		self::add_item_meta_boxes( $post_type );
52
+		self::add_item_meta_boxes($post_type);
53 53
 
54 54
 		// For invoice discounts.
55
-		if ( $post_type == 'wpi_discount' ) {
56
-			add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
55
+		if ($post_type == 'wpi_discount') {
56
+			add_meta_box('wpinv_discount_details', __('Discount Details', 'invoicing'), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high');
57 57
 		}
58 58
 
59 59
 	}
@@ -61,17 +61,17 @@  discard block
 block discarded – undo
61 61
 	/**
62 62
 	 * Register core metaboxes.
63 63
 	 */
64
-	protected static function add_payment_form_meta_boxes( $post_type, $post ) {
64
+	protected static function add_payment_form_meta_boxes($post_type, $post) {
65 65
 
66 66
 		// For payment forms.
67
-		if ( $post_type == 'wpi_payment_form' ) {
67
+		if ($post_type == 'wpi_payment_form') {
68 68
 
69 69
 			// Design payment form.
70
-			add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
70
+			add_meta_box('wpinv-payment-form-design', __('Payment Form', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal');
71 71
 
72 72
 			// Payment form information.
73
-			if ( $post->ID != wpinv_get_default_payment_form() ) {
74
-				add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
73
+			if ($post->ID != wpinv_get_default_payment_form()) {
74
+				add_meta_box('wpinv-payment-form-info', __('Details', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side');
75 75
 			}
76 76
 
77 77
 		}
@@ -81,20 +81,20 @@  discard block
 block discarded – undo
81 81
 	/**
82 82
 	 * Register core metaboxes.
83 83
 	 */
84
-	protected static function add_item_meta_boxes( $post_type ) {
84
+	protected static function add_item_meta_boxes($post_type) {
85 85
 
86
-		if ( $post_type == 'wpi_item' ) {
86
+		if ($post_type == 'wpi_item') {
87 87
 
88 88
 			// Item details.
89
-			add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
89
+			add_meta_box('wpinv_item_details', __('Item Details', 'invoicing'), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high');
90 90
 
91 91
 			// If taxes are enabled, register the tax metabox.
92
-			if ( wpinv_use_taxes() ) {
93
-				add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
92
+			if (wpinv_use_taxes()) {
93
+				add_meta_box('wpinv_item_vat', __('Tax', 'invoicing'), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high');
94 94
 			}
95 95
 
96 96
 			// Item info.
97
-			add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
97
+			add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core');
98 98
 
99 99
 		}
100 100
 
@@ -103,20 +103,20 @@  discard block
 block discarded – undo
103 103
 	/**
104 104
 	 * Register invoice metaboxes.
105 105
 	 */
106
-	protected static function add_invoice_meta_boxes( $post_type, $post ) {
106
+	protected static function add_invoice_meta_boxes($post_type, $post) {
107 107
 
108 108
 		// For invoices...
109
-		if ( getpaid_is_invoice_post_type( $post_type ) ) {
110
-			$invoice = new WPInv_Invoice( $post );
109
+		if (getpaid_is_invoice_post_type($post_type)) {
110
+			$invoice = new WPInv_Invoice($post);
111 111
 
112 112
 			// Resend invoice.
113
-			if ( ! $invoice->is_draft() ) {
113
+			if (!$invoice->is_draft()) {
114 114
 
115 115
 				add_meta_box(
116 116
 					'wpinv-mb-resend-invoice',
117 117
 					sprintf(
118
-						__( 'Resend %s', 'invoicing' ),
119
-						ucfirst( $invoice->get_invoice_quote_type() )
118
+						__('Resend %s', 'invoicing'),
119
+						ucfirst($invoice->get_invoice_quote_type())
120 120
 					),
121 121
 					'GetPaid_Meta_Box_Resend_Invoice::output',
122 122
 					$post_type,
@@ -127,17 +127,17 @@  discard block
 block discarded – undo
127 127
 			}
128 128
 
129 129
 			// Subscriptions.
130
-			$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
131
-			if ( ! empty( $subscriptions ) ) {
130
+			$subscriptions = getpaid_get_invoice_subscriptions($invoice);
131
+			if (!empty($subscriptions)) {
132 132
 
133
-				if ( is_array( $subscriptions ) ) {
134
-					add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' );
133
+				if (is_array($subscriptions)) {
134
+					add_meta_box('wpinv-mb-subscriptions', __('Related Subscriptions', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced');
135 135
 				} else {
136
-					add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
136
+					add_meta_box('wpinv-mb-subscriptions', __('Subscription Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced');
137 137
 				}
138 138
 
139
-				if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) {
140
-					add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
139
+				if (getpaid_count_subscription_invoices($invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id()) > 1) {
140
+					add_meta_box('wpinv-mb-subscription-invoices', __('Related Payments', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced');
141 141
 				}
142 142
 
143 143
 			}
@@ -146,8 +146,8 @@  discard block
 block discarded – undo
146 146
 			add_meta_box(
147 147
 				'wpinv-details',
148 148
 				sprintf(
149
-					__( '%s Details', 'invoicing' ),
150
-					ucfirst( $invoice->get_invoice_quote_type() )
149
+					__('%s Details', 'invoicing'),
150
+					ucfirst($invoice->get_invoice_quote_type())
151 151
 				),
152 152
 				'GetPaid_Meta_Box_Invoice_Details::output',
153 153
 				$post_type,
@@ -155,17 +155,17 @@  discard block
 block discarded – undo
155 155
 			);
156 156
 
157 157
 			// Payment details.
158
-			add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
158
+			add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default');
159 159
 
160 160
 			// Billing details.
161
-			add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
161
+			add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high');
162 162
 			
163 163
 			// Invoice items.
164 164
 			add_meta_box(
165 165
 				'wpinv-items',
166 166
 				sprintf(
167
-					__( '%s Items', 'invoicing' ),
168
-					ucfirst( $invoice->get_invoice_quote_type() )
167
+					__('%s Items', 'invoicing'),
168
+					ucfirst($invoice->get_invoice_quote_type())
169 169
 				),
170 170
 				'GetPaid_Meta_Box_Invoice_Items::output',
171 171
 				$post_type,
@@ -177,8 +177,8 @@  discard block
 block discarded – undo
177 177
 			add_meta_box(
178 178
 				'wpinv-notes',
179 179
 				sprintf(
180
-					__( '%s Notes', 'invoicing' ),
181
-					ucfirst( $invoice->get_invoice_quote_type() )
180
+					__('%s Notes', 'invoicing'),
181
+					ucfirst($invoice->get_invoice_quote_type())
182 182
 				),
183 183
 				'WPInv_Meta_Box_Notes::output',
184 184
 				$post_type,
@@ -187,13 +187,13 @@  discard block
 block discarded – undo
187 187
 			);
188 188
 
189 189
 			// Shipping Address.
190
-			if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) {
191
-				add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
190
+			if (get_post_meta($invoice->get_id(), 'shipping_address', true)) {
191
+				add_meta_box('wpinv-invoice-shipping-details', __('Shipping Address', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high');
192 192
 			}
193 193
 
194 194
 			// Payment form information.
195
-			if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) {
196
-				add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
195
+			if (get_post_meta($invoice->get_id(), 'payment_form_data', true)) {
196
+				add_meta_box('wpinv-invoice-payment-form-details', __('Payment Form Details', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high');
197 197
 			}
198 198
 
199 199
 		}
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 	 * Remove some metaboxes.
205 205
 	 */
206 206
 	public static function remove_meta_boxes() {
207
-		remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
207
+		remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal');
208 208
 	}
209 209
 
210 210
 	/**
@@ -220,46 +220,46 @@  discard block
 block discarded – undo
220 220
 	 * @param  int    $post_id Post ID.
221 221
 	 * @param  object $post Post object.
222 222
 	 */
223
-	public static function save_meta_boxes( $post_id, $post ) {
224
-		$post_id = absint( $post_id );
225
-		$data    = wp_kses_post_deep( wp_unslash( $_POST ) );
223
+	public static function save_meta_boxes($post_id, $post) {
224
+		$post_id = absint($post_id);
225
+		$data    = wp_kses_post_deep(wp_unslash($_POST));
226 226
 
227 227
 		// Do not save for ajax requests.
228
-		if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
228
+		if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
229 229
 			return;
230 230
 		}
231 231
 
232 232
 		// $post_id and $post are required
233
-		if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
233
+		if (empty($post_id) || empty($post) || self::$saved_meta_boxes) {
234 234
 			return;
235 235
 		}
236 236
 
237 237
 		// Dont' save meta boxes for revisions or autosaves.
238
-		if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
238
+		if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
239 239
 			return;
240 240
 		}
241 241
 
242 242
 		// Check the nonce.
243
-		if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
243
+		if (empty($data['getpaid_meta_nonce']) || !wp_verify_nonce($data['getpaid_meta_nonce'], 'getpaid_meta_nonce')) {
244 244
 			return;
245 245
 		}
246 246
 
247 247
 		// Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
248
-		if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
248
+		if (empty($data['post_ID']) || absint($data['post_ID']) !== $post_id) {
249 249
 			return;
250 250
 		}
251 251
 
252 252
 		// Check user has permission to edit.
253
-		if ( ! current_user_can( 'edit_post', $post_id ) ) {
253
+		if (!current_user_can('edit_post', $post_id)) {
254 254
 			return;
255 255
 		}
256 256
 
257
-		if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
257
+		if (getpaid_is_invoice_post_type($post->post_type)) {
258 258
 
259 259
 			// We need this save event to run once to avoid potential endless loops.
260 260
 			self::$saved_meta_boxes = true;
261 261
 
262
-			return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
262
+			return GetPaid_Meta_Box_Invoice_Address::save($post_id);
263 263
 
264 264
 		}
265 265
 
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 		);
272 272
 
273 273
 		// Is this our post type?
274
-		if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
274
+		if (!isset($post_types_map[$post->post_type])) {
275 275
 			return;
276 276
 		}
277 277
 
@@ -279,8 +279,8 @@  discard block
 block discarded – undo
279 279
 		self::$saved_meta_boxes = true;
280 280
 		
281 281
 		// Save the post.
282
-		$class = $post_types_map[ $post->post_type ];
283
-		$class::save( $post_id, wp_kses_post_deep( $_POST ), $post );
282
+		$class = $post_types_map[$post->post_type];
283
+		$class::save($post_id, wp_kses_post_deep($_POST), $post);
284 284
 
285 285
 	}
286 286
 
Please login to merge, or discard this patch.
includes/admin/class-getpaid-post-types-admin.php 2 patches
Indentation   +730 added lines, -730 removed lines patch added patch discarded remove patch
@@ -13,732 +13,732 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Post_Types_Admin {
14 14
 
15 15
     /**
16
-	 * Hook in methods.
17
-	 */
18
-	public static function init() {
19
-
20
-		// Init metaboxes.
21
-		GetPaid_Metaboxes::init();
22
-
23
-		// Filter the post updated messages.
24
-		add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
25
-
26
-		// Filter post actions.
27
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
28
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 );
29
-
30
-		// Invoice table columns.
31
-		add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
32
-		add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
33
-		add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) );
34
-		add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 );
35
-
36
-		// Items table columns.
37
-		add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
38
-		add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
39
-		add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
40
-		add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
41
-		add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
42
-		add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
43
-
44
-		// Payment forms columns.
45
-		add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
46
-		add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
47
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
48
-
49
-		// Discount table columns.
50
-		add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
51
-		add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 );
52
-
53
-		// Deleting posts.
54
-		add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
55
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
56
-
57
-		add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 );
58
-	}
59
-
60
-	/**
61
-	 * Post updated messages.
62
-	 */
63
-	public static function post_updated_messages( $messages ) {
64
-		global $post;
65
-
66
-		$messages['wpi_discount'] = array(
67
-			0   => '',
68
-			1   => __( 'Discount updated.', 'invoicing' ),
69
-			2   => __( 'Custom field updated.', 'invoicing' ),
70
-			3   => __( 'Custom field deleted.', 'invoicing' ),
71
-			4   => __( 'Discount updated.', 'invoicing' ),
72
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
73
-			6   => __( 'Discount updated.', 'invoicing' ),
74
-			7   => __( 'Discount saved.', 'invoicing' ),
75
-			8   => __( 'Discount submitted.', 'invoicing' ),
76
-			9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
77
-			10  => __( 'Discount draft updated.', 'invoicing' ),
78
-		);
79
-
80
-		$messages['wpi_payment_form'] = array(
81
-			0   => '',
82
-			1   => __( 'Payment Form updated.', 'invoicing' ),
83
-			2   => __( 'Custom field updated.', 'invoicing' ),
84
-			3   => __( 'Custom field deleted.', 'invoicing' ),
85
-			4   => __( 'Payment Form updated.', 'invoicing' ),
86
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
87
-			6   => __( 'Payment Form updated.', 'invoicing' ),
88
-			7   => __( 'Payment Form saved.', 'invoicing' ),
89
-			8   => __( 'Payment Form submitted.', 'invoicing' ),
90
-			9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
91
-			10  => __( 'Payment Form draft updated.', 'invoicing' ),
92
-		);
93
-
94
-		return $messages;
95
-
96
-	}
97
-
98
-	/**
99
-	 * Post row actions.
100
-	 */
101
-	public static function post_row_actions( $actions, $post ) {
102
-
103
-		$post = get_post( $post );
104
-
105
-		// We do not want to edit the default payment form.
106
-		if ( 'wpi_payment_form' == $post->post_type ) {
107
-
108
-			if ( $post->ID == wpinv_get_default_payment_form() ) {
109
-				unset( $actions['trash'] );
110
-				unset( $actions['inline hide-if-no-js'] );
111
-			}
112
-
113
-			$actions['duplicate'] =  sprintf(
114
-				'<a href="%1$s">%2$s</a>',
115
-				esc_url(
116
-					wp_nonce_url(
117
-						add_query_arg(
118
-							array(
119
-								'getpaid-admin-action' => 'duplicate_form',
120
-								'form_id'              => $post->ID
121
-							)
122
-						),
123
-						'getpaid-nonce',
124
-						'getpaid-nonce'
125
-					)
126
-				),
127
-				esc_html( __( 'Duplicate', 'invoicing' ) )
128
-			);
129
-
130
-		}
131
-
132
-		// Link to item payment form.
133
-		if ( 'wpi_item' == $post->post_type ) {
134
-
135
-			if ( in_array( get_post_meta( $post->ID, '_wpinv_type', true ), array( '', 'fee', 'custom' ) ) ) {
136
-
137
-				$actions['buy'] =  sprintf(
138
-					'<a href="%1$s">%2$s</a>',
139
-					esc_url( getpaid_embed_url( false, $post->ID . '|0' ) ),
140
-					esc_html( __( 'Buy', 'invoicing' ) )
141
-				);
142
-
143
-			}
144
-
145
-		}
146
-
147
-		return $actions;
148
-	}
149
-
150
-	/**
16
+     * Hook in methods.
17
+     */
18
+    public static function init() {
19
+
20
+        // Init metaboxes.
21
+        GetPaid_Metaboxes::init();
22
+
23
+        // Filter the post updated messages.
24
+        add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
25
+
26
+        // Filter post actions.
27
+        add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
28
+        add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 );
29
+
30
+        // Invoice table columns.
31
+        add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
32
+        add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
33
+        add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) );
34
+        add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 );
35
+
36
+        // Items table columns.
37
+        add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
38
+        add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
39
+        add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
40
+        add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
41
+        add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
42
+        add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
43
+
44
+        // Payment forms columns.
45
+        add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
46
+        add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
47
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
48
+
49
+        // Discount table columns.
50
+        add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
51
+        add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 );
52
+
53
+        // Deleting posts.
54
+        add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
55
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
56
+
57
+        add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 );
58
+    }
59
+
60
+    /**
61
+     * Post updated messages.
62
+     */
63
+    public static function post_updated_messages( $messages ) {
64
+        global $post;
65
+
66
+        $messages['wpi_discount'] = array(
67
+            0   => '',
68
+            1   => __( 'Discount updated.', 'invoicing' ),
69
+            2   => __( 'Custom field updated.', 'invoicing' ),
70
+            3   => __( 'Custom field deleted.', 'invoicing' ),
71
+            4   => __( 'Discount updated.', 'invoicing' ),
72
+            5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
73
+            6   => __( 'Discount updated.', 'invoicing' ),
74
+            7   => __( 'Discount saved.', 'invoicing' ),
75
+            8   => __( 'Discount submitted.', 'invoicing' ),
76
+            9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
77
+            10  => __( 'Discount draft updated.', 'invoicing' ),
78
+        );
79
+
80
+        $messages['wpi_payment_form'] = array(
81
+            0   => '',
82
+            1   => __( 'Payment Form updated.', 'invoicing' ),
83
+            2   => __( 'Custom field updated.', 'invoicing' ),
84
+            3   => __( 'Custom field deleted.', 'invoicing' ),
85
+            4   => __( 'Payment Form updated.', 'invoicing' ),
86
+            5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
87
+            6   => __( 'Payment Form updated.', 'invoicing' ),
88
+            7   => __( 'Payment Form saved.', 'invoicing' ),
89
+            8   => __( 'Payment Form submitted.', 'invoicing' ),
90
+            9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
91
+            10  => __( 'Payment Form draft updated.', 'invoicing' ),
92
+        );
93
+
94
+        return $messages;
95
+
96
+    }
97
+
98
+    /**
99
+     * Post row actions.
100
+     */
101
+    public static function post_row_actions( $actions, $post ) {
102
+
103
+        $post = get_post( $post );
104
+
105
+        // We do not want to edit the default payment form.
106
+        if ( 'wpi_payment_form' == $post->post_type ) {
107
+
108
+            if ( $post->ID == wpinv_get_default_payment_form() ) {
109
+                unset( $actions['trash'] );
110
+                unset( $actions['inline hide-if-no-js'] );
111
+            }
112
+
113
+            $actions['duplicate'] =  sprintf(
114
+                '<a href="%1$s">%2$s</a>',
115
+                esc_url(
116
+                    wp_nonce_url(
117
+                        add_query_arg(
118
+                            array(
119
+                                'getpaid-admin-action' => 'duplicate_form',
120
+                                'form_id'              => $post->ID
121
+                            )
122
+                        ),
123
+                        'getpaid-nonce',
124
+                        'getpaid-nonce'
125
+                    )
126
+                ),
127
+                esc_html( __( 'Duplicate', 'invoicing' ) )
128
+            );
129
+
130
+        }
131
+
132
+        // Link to item payment form.
133
+        if ( 'wpi_item' == $post->post_type ) {
134
+
135
+            if ( in_array( get_post_meta( $post->ID, '_wpinv_type', true ), array( '', 'fee', 'custom' ) ) ) {
136
+
137
+                $actions['buy'] =  sprintf(
138
+                    '<a href="%1$s">%2$s</a>',
139
+                    esc_url( getpaid_embed_url( false, $post->ID . '|0' ) ),
140
+                    esc_html( __( 'Buy', 'invoicing' ) )
141
+                );
142
+
143
+            }
144
+
145
+        }
146
+
147
+        return $actions;
148
+    }
149
+
150
+    /**
151 151
      * Remove bulk edit option from admin side quote listing
152 152
      *
153 153
      * @since    1.0.0
154 154
      * @param array $actions post actions
155
-	 * @param WP_Post $post
155
+     * @param WP_Post $post
156 156
      * @return array $actions actions without edit option
157 157
      */
158 158
     public static function filter_invoice_row_actions( $actions, $post ) {
159 159
 
160 160
         if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
161 161
 
162
-			$actions = array();
163
-			$invoice = new WPInv_Invoice( $post );
164
-
165
-			$actions['edit'] =  sprintf(
166
-				'<a href="%1$s">%2$s</a>',
167
-				esc_url( get_edit_post_link( $invoice->get_id() ) ),
168
-				esc_html( __( 'Edit', 'invoicing' ) )
169
-			);
170
-
171
-			if ( ! $invoice->is_draft() ) {
172
-
173
-				$actions['view'] =  sprintf(
174
-					'<a href="%1$s">%2$s</a>',
175
-					esc_url( $invoice->get_view_url() ),
176
-					sprintf(
177
-						esc_html( __( 'View %s', 'invoicing' ) ),
178
-						getpaid_get_post_type_label( $invoice->get_post_type(), false )
179
-					)
180
-				);
181
-
182
-				$actions['send'] =  sprintf(
183
-					'<a href="%1$s">%2$s</a>',
184
-					esc_url(
185
-						wp_nonce_url(
186
-							add_query_arg(
187
-								array(
188
-									'getpaid-admin-action' => 'send_invoice',
189
-									'invoice_id'           => $invoice->get_id()
190
-								)
191
-							),
192
-							'getpaid-nonce',
193
-							'getpaid-nonce'
194
-						)
195
-					),
196
-					esc_html( __( 'Send to Customer', 'invoicing' ) )
197
-				);
198
-
199
-			}
200
-
201
-			$actions['duplicate'] =  sprintf(
202
-				'<a href="%1$s">%2$s</a>',
203
-				esc_url(
204
-					wp_nonce_url(
205
-						add_query_arg(
206
-							array(
207
-								'getpaid-admin-action' => 'duplicate_invoice',
208
-								'invoice_id'           => $post->ID
209
-							)
210
-						),
211
-						'getpaid-nonce',
212
-						'getpaid-nonce'
213
-					)
214
-				),
215
-				esc_html( __( 'Duplicate', 'invoicing' ) )
216
-			);
162
+            $actions = array();
163
+            $invoice = new WPInv_Invoice( $post );
164
+
165
+            $actions['edit'] =  sprintf(
166
+                '<a href="%1$s">%2$s</a>',
167
+                esc_url( get_edit_post_link( $invoice->get_id() ) ),
168
+                esc_html( __( 'Edit', 'invoicing' ) )
169
+            );
170
+
171
+            if ( ! $invoice->is_draft() ) {
172
+
173
+                $actions['view'] =  sprintf(
174
+                    '<a href="%1$s">%2$s</a>',
175
+                    esc_url( $invoice->get_view_url() ),
176
+                    sprintf(
177
+                        esc_html( __( 'View %s', 'invoicing' ) ),
178
+                        getpaid_get_post_type_label( $invoice->get_post_type(), false )
179
+                    )
180
+                );
181
+
182
+                $actions['send'] =  sprintf(
183
+                    '<a href="%1$s">%2$s</a>',
184
+                    esc_url(
185
+                        wp_nonce_url(
186
+                            add_query_arg(
187
+                                array(
188
+                                    'getpaid-admin-action' => 'send_invoice',
189
+                                    'invoice_id'           => $invoice->get_id()
190
+                                )
191
+                            ),
192
+                            'getpaid-nonce',
193
+                            'getpaid-nonce'
194
+                        )
195
+                    ),
196
+                    esc_html( __( 'Send to Customer', 'invoicing' ) )
197
+                );
198
+
199
+            }
200
+
201
+            $actions['duplicate'] =  sprintf(
202
+                '<a href="%1$s">%2$s</a>',
203
+                esc_url(
204
+                    wp_nonce_url(
205
+                        add_query_arg(
206
+                            array(
207
+                                'getpaid-admin-action' => 'duplicate_invoice',
208
+                                'invoice_id'           => $post->ID
209
+                            )
210
+                        ),
211
+                        'getpaid-nonce',
212
+                        'getpaid-nonce'
213
+                    )
214
+                ),
215
+                esc_html( __( 'Duplicate', 'invoicing' ) )
216
+            );
217 217
 
218 218
         }
219 219
 
220 220
         return $actions;
221
-	}
222
-
223
-	/**
224
-	 * Returns an array of invoice table columns.
225
-	 */
226
-	public static function invoice_columns( $columns ) {
227
-
228
-		$columns = array(
229
-			'cb'                => $columns['cb'],
230
-			'number'            => __( 'Invoice', 'invoicing' ),
231
-			'customer'          => __( 'Customer', 'invoicing' ),
232
-			'invoice_date'      => __( 'Created', 'invoicing' ),
233
-			'payment_date'      => __( 'Completed', 'invoicing' ),
234
-			'amount'            => __( 'Amount', 'invoicing' ),
235
-			'recurring'         => __( 'Recurring', 'invoicing' ),
236
-			'status'            => __( 'Status', 'invoicing' ),
237
-		);
238
-
239
-		return apply_filters( 'wpi_invoice_table_columns', $columns );
240
-	}
241
-
242
-	/**
243
-	 * Displays invoice table columns.
244
-	 */
245
-	public static function display_invoice_columns( $column_name, $post_id ) {
246
-
247
-		$invoice = new WPInv_Invoice( $post_id );
248
-
249
-		switch ( $column_name ) {
250
-
251
-			case 'invoice_date' :
252
-				$date_time = esc_attr( $invoice->get_created_date() );
253
-				$date      = esc_html( getpaid_format_date_value( $date_time, "&mdash;", true ) );
254
-				echo "<span title='$date_time'>$date</span>";
255
-				break;
256
-
257
-			case 'payment_date' :
258
-
259
-				if ( $invoice->is_paid() ) {
260
-					$date_time = esc_attr( $invoice->get_completed_date() );
261
-					$date      = esc_html( getpaid_format_date_value( $date_time, "&mdash;", true ) );
262
-					echo "<span title='$date_time'>$date</span>";
263
-				} else {
264
-					echo "&mdash;";
265
-				}
221
+    }
222
+
223
+    /**
224
+     * Returns an array of invoice table columns.
225
+     */
226
+    public static function invoice_columns( $columns ) {
227
+
228
+        $columns = array(
229
+            'cb'                => $columns['cb'],
230
+            'number'            => __( 'Invoice', 'invoicing' ),
231
+            'customer'          => __( 'Customer', 'invoicing' ),
232
+            'invoice_date'      => __( 'Created', 'invoicing' ),
233
+            'payment_date'      => __( 'Completed', 'invoicing' ),
234
+            'amount'            => __( 'Amount', 'invoicing' ),
235
+            'recurring'         => __( 'Recurring', 'invoicing' ),
236
+            'status'            => __( 'Status', 'invoicing' ),
237
+        );
238
+
239
+        return apply_filters( 'wpi_invoice_table_columns', $columns );
240
+    }
241
+
242
+    /**
243
+     * Displays invoice table columns.
244
+     */
245
+    public static function display_invoice_columns( $column_name, $post_id ) {
246
+
247
+        $invoice = new WPInv_Invoice( $post_id );
248
+
249
+        switch ( $column_name ) {
250
+
251
+            case 'invoice_date' :
252
+                $date_time = esc_attr( $invoice->get_created_date() );
253
+                $date      = esc_html( getpaid_format_date_value( $date_time, "&mdash;", true ) );
254
+                echo "<span title='$date_time'>$date</span>";
255
+                break;
256
+
257
+            case 'payment_date' :
258
+
259
+                if ( $invoice->is_paid() ) {
260
+                    $date_time = esc_attr( $invoice->get_completed_date() );
261
+                    $date      = esc_html( getpaid_format_date_value( $date_time, "&mdash;", true ) );
262
+                    echo "<span title='$date_time'>$date</span>";
263
+                } else {
264
+                    echo "&mdash;";
265
+                }
266 266
 				
267
-				break;
267
+                break;
268 268
 
269
-			case 'amount' :
269
+            case 'amount' :
270 270
 
271
-				$amount = $invoice->get_total();
272
-				$formated_amount = wp_kses_post( wpinv_price( $amount, $invoice->get_currency() ) );
271
+                $amount = $invoice->get_total();
272
+                $formated_amount = wp_kses_post( wpinv_price( $amount, $invoice->get_currency() ) );
273 273
 
274
-				if ( $invoice->is_refunded() ) {
275
-					$refunded_amount = wp_kses_post( wpinv_price( 0, $invoice->get_currency() ) );
276
-					echo "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>";
277
-				} else {
274
+                if ( $invoice->is_refunded() ) {
275
+                    $refunded_amount = wp_kses_post( wpinv_price( 0, $invoice->get_currency() ) );
276
+                    echo "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>";
277
+                } else {
278 278
 
279
-					$discount = $invoice->get_total_discount();
279
+                    $discount = $invoice->get_total_discount();
280 280
 
281
-					if ( ! empty( $discount ) ) {
282
-						$new_amount = wp_kses_post( wpinv_price( $amount + $discount, $invoice->get_currency() ) );
283
-						echo "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>";
284
-					} else {
285
-						echo $formated_amount;
286
-					}
281
+                    if ( ! empty( $discount ) ) {
282
+                        $new_amount = wp_kses_post( wpinv_price( $amount + $discount, $invoice->get_currency() ) );
283
+                        echo "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>";
284
+                    } else {
285
+                        echo $formated_amount;
286
+                    }
287 287
 
288
-				}
288
+                }
289 289
 
290
-				break;
290
+                break;
291 291
 
292
-			case 'status' :
293
-				$status       = esc_html( $invoice->get_status() );
294
-				$status_label = esc_html( $invoice->get_status_nicename() );
292
+            case 'status' :
293
+                $status       = esc_html( $invoice->get_status() );
294
+                $status_label = esc_html( $invoice->get_status_nicename() );
295 295
 
296
-				// If it is paid, show the gateway title.
297
-				if ( $invoice->is_paid() ) {
298
-					$gateway = esc_html( $invoice->get_gateway_title() );
299
-					$gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), esc_html( $gateway ) );
296
+                // If it is paid, show the gateway title.
297
+                if ( $invoice->is_paid() ) {
298
+                    $gateway = esc_html( $invoice->get_gateway_title() );
299
+                    $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), esc_html( $gateway ) );
300 300
 
301
-					echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
302
-				} else {
303
-					echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>";
304
-				}
301
+                    echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
302
+                } else {
303
+                    echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>";
304
+                }
305 305
 
306
-				// If it is not paid, display the overdue and view status.
307
-				if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
306
+                // If it is not paid, display the overdue and view status.
307
+                if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
308 308
 
309
-					// Invoice view status.
310
-					if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
311
-						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
312
-					} else {
313
-						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
314
-					}
309
+                    // Invoice view status.
310
+                    if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
311
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
312
+                    } else {
313
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
314
+                    }
315 315
 
316
-					// Display the overview status.
317
-					if ( wpinv_get_option( 'overdue_active' ) ) {
318
-						$due_date = $invoice->get_due_date();
319
-						$fomatted = getpaid_format_date( $due_date );
316
+                    // Display the overview status.
317
+                    if ( wpinv_get_option( 'overdue_active' ) ) {
318
+                        $due_date = $invoice->get_due_date();
319
+                        $fomatted = getpaid_format_date( $due_date );
320 320
 
321
-						if ( ! empty( $fomatted ) ) {
322
-							$date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted );
323
-							echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>";
324
-						}
325
-					}
321
+                        if ( ! empty( $fomatted ) ) {
322
+                            $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted );
323
+                            echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>";
324
+                        }
325
+                    }
326 326
 
327
-				}
327
+                }
328 328
 
329
-				break;
329
+                break;
330 330
 
331
-			case 'recurring':
331
+            case 'recurring':
332 332
 
333
-				if ( $invoice->is_recurring() ) {
334
-					echo '<i class="fa fa-check" style="color:#43850a;"></i>';
335
-				} else {
336
-					echo '<i class="fa fa-times" style="color:#616161;"></i>';
337
-				}
338
-				break;
333
+                if ( $invoice->is_recurring() ) {
334
+                    echo '<i class="fa fa-check" style="color:#43850a;"></i>';
335
+                } else {
336
+                    echo '<i class="fa fa-times" style="color:#616161;"></i>';
337
+                }
338
+                break;
339 339
 
340
-			case 'number' :
340
+            case 'number' :
341 341
 
342
-				$edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
343
-				$invoice_number  = esc_html( $invoice->get_number() );
344
-				$invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
342
+                $edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
343
+                $invoice_number  = esc_html( $invoice->get_number() );
344
+                $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
345 345
 
346
-				echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
346
+                echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
347 347
 
348
-				break;
348
+                break;
349 349
 
350
-			case 'customer' :
350
+            case 'customer' :
351 351
 	
352
-				$customer_name = $invoice->get_user_full_name();
352
+                $customer_name = $invoice->get_user_full_name();
353 353
 	
354
-				if ( empty( $customer_name ) ) {
355
-					$customer_name = $invoice->get_email();
356
-				}
354
+                if ( empty( $customer_name ) ) {
355
+                    $customer_name = $invoice->get_email();
356
+                }
357 357
 	
358
-				if ( ! empty( $customer_name ) ) {
359
-					$customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
360
-					$view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
361
-					echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
362
-				} else {
363
-					echo '<div>&mdash;</div>';
364
-				}
358
+                if ( ! empty( $customer_name ) ) {
359
+                    $customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
360
+                    $view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
361
+                    echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
362
+                } else {
363
+                    echo '<div>&mdash;</div>';
364
+                }
365 365
 
366
-				break;
366
+                break;
367 367
 
368
-		}
368
+        }
369 369
 
370
-	}
370
+    }
371 371
 
372
-	/**
373
-	 * Displays invoice bulk actions.
374
-	 */
375
-	public static function invoice_bulk_actions( $actions ) {
376
-		$actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' );
377
-		return $actions;
378
-	}
372
+    /**
373
+     * Displays invoice bulk actions.
374
+     */
375
+    public static function invoice_bulk_actions( $actions ) {
376
+        $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' );
377
+        return $actions;
378
+    }
379 379
 
380
-	/**
381
-	 * Processes invoice bulk actions.
382
-	 */
383
-	public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) {
380
+    /**
381
+     * Processes invoice bulk actions.
382
+     */
383
+    public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) {
384 384
 
385
-		if ( $action == 'resend-invoice' ) {
386
-			foreach ( $post_ids as $post_id ) {
387
-				getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true );
388
-			}
389
-		}
385
+        if ( $action == 'resend-invoice' ) {
386
+            foreach ( $post_ids as $post_id ) {
387
+                getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true );
388
+            }
389
+        }
390 390
 
391
-		return $redirect_url;
391
+        return $redirect_url;
392 392
 
393
-	}
393
+    }
394 394
 
395
-	/**
396
-	 * Returns an array of payment forms table columns.
397
-	 */
398
-	public static function payment_form_columns( $columns ) {
395
+    /**
396
+     * Returns an array of payment forms table columns.
397
+     */
398
+    public static function payment_form_columns( $columns ) {
399 399
 
400
-		$columns = array(
401
-			'cb'                => $columns['cb'],
402
-			'title'             => __( 'Name', 'invoicing' ),
403
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
404
-			'earnings'          => __( 'Revenue', 'invoicing' ),
405
-			'refunds'           => __( 'Refunded', 'invoicing' ),
406
-			'items'             => __( 'Items', 'invoicing' ),
407
-			'date'              => __( 'Date', 'invoicing' ),
408
-		);
400
+        $columns = array(
401
+            'cb'                => $columns['cb'],
402
+            'title'             => __( 'Name', 'invoicing' ),
403
+            'shortcode'         => __( 'Shortcode', 'invoicing' ),
404
+            'earnings'          => __( 'Revenue', 'invoicing' ),
405
+            'refunds'           => __( 'Refunded', 'invoicing' ),
406
+            'items'             => __( 'Items', 'invoicing' ),
407
+            'date'              => __( 'Date', 'invoicing' ),
408
+        );
409 409
 
410
-		return apply_filters( 'wpi_payment_form_table_columns', $columns );
410
+        return apply_filters( 'wpi_payment_form_table_columns', $columns );
411 411
 
412
-	}
412
+    }
413 413
 
414
-	/**
415
-	 * Displays payment form table columns.
416
-	 */
417
-	public static function display_payment_form_columns( $column_name, $post_id ) {
414
+    /**
415
+     * Displays payment form table columns.
416
+     */
417
+    public static function display_payment_form_columns( $column_name, $post_id ) {
418 418
 
419
-		// Retrieve the payment form.
420
-		$form = new GetPaid_Payment_Form( $post_id );
419
+        // Retrieve the payment form.
420
+        $form = new GetPaid_Payment_Form( $post_id );
421 421
 
422
-		switch ( $column_name ) {
422
+        switch ( $column_name ) {
423 423
 
424
-			case 'earnings' :
425
-				echo wpinv_price( $form->get_earned() );
426
-				break;
424
+            case 'earnings' :
425
+                echo wpinv_price( $form->get_earned() );
426
+                break;
427 427
 
428
-			case 'refunds' :
429
-				echo wpinv_price( $form->get_refunded() );
430
-				break;
428
+            case 'refunds' :
429
+                echo wpinv_price( $form->get_refunded() );
430
+                break;
431 431
 
432
-			case 'refunds' :
433
-				echo wpinv_price( $form->get_refunded() );
434
-				break;
432
+            case 'refunds' :
433
+                echo wpinv_price( $form->get_refunded() );
434
+                break;
435 435
 
436
-			case 'shortcode' :
436
+            case 'shortcode' :
437 437
 
438
-				if ( $form->is_default() ) {
439
-					echo '&mdash;';
440
-				} else {
441
-					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
442
-				}
438
+                if ( $form->is_default() ) {
439
+                    echo '&mdash;';
440
+                } else {
441
+                    echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
442
+                }
443 443
 
444
-				break;
444
+                break;
445 445
 
446
-			case 'items' :
446
+            case 'items' :
447 447
 
448
-				$items = $form->get_items();
448
+                $items = $form->get_items();
449 449
 
450
-				if ( $form->is_default() || empty( $items ) ) {
451
-					echo '&mdash;';
452
-					return;
453
-				}
450
+                if ( $form->is_default() || empty( $items ) ) {
451
+                    echo '&mdash;';
452
+                    return;
453
+                }
454 454
 
455
-				$_items = array();
455
+                $_items = array();
456 456
 
457
-				foreach ( $items as $item ) {
458
-					$url = $item->get_edit_url();
457
+                foreach ( $items as $item ) {
458
+                    $url = $item->get_edit_url();
459 459
 
460
-					if ( empty( $url ) ) {
461
-						$_items[] = esc_html( $item->get_name() );
462
-					} else {
463
-						$_items[] = sprintf(
464
-							'<a href="%s">%s</a>',
465
-							esc_url( $url ),
466
-							esc_html( $item->get_name() )
467
-						);
468
-					}
460
+                    if ( empty( $url ) ) {
461
+                        $_items[] = esc_html( $item->get_name() );
462
+                    } else {
463
+                        $_items[] = sprintf(
464
+                            '<a href="%s">%s</a>',
465
+                            esc_url( $url ),
466
+                            esc_html( $item->get_name() )
467
+                        );
468
+                    }
469 469
 
470
-				}
470
+                }
471 471
 
472
-				echo implode( '<br>', $_items );
472
+                echo implode( '<br>', $_items );
473 473
 
474
-				break;
474
+                break;
475 475
 
476
-		}
476
+        }
477 477
 
478
-	}
478
+    }
479 479
 
480
-	/**
481
-	 * Filters post states.
482
-	 */
483
-	public static function filter_payment_form_state( $post_states, $post ) {
480
+    /**
481
+     * Filters post states.
482
+     */
483
+    public static function filter_payment_form_state( $post_states, $post ) {
484 484
 
485
-		if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
486
-			$post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
487
-		}
485
+        if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
486
+            $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
487
+        }
488 488
 	
489
-		return $post_states;
490
-
491
-	}
492
-
493
-	/**
494
-	 * Returns an array of coupon table columns.
495
-	 */
496
-	public static function discount_columns( $columns ) {
497
-
498
-		$columns = array(
499
-			'cb'                => $columns['cb'],
500
-			'title'             => __( 'Name', 'invoicing' ),
501
-			'code'              => __( 'Code', 'invoicing' ),
502
-			'amount'            => __( 'Amount', 'invoicing' ),
503
-			'usage'             => __( 'Usage / Limit', 'invoicing' ),
504
-			'start_date'        => __( 'Start Date', 'invoicing' ),
505
-			'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
506
-		);
507
-
508
-		return apply_filters( 'wpi_discount_table_columns', $columns );
509
-	}
510
-
511
-	/**
512
-	 * Filters post states.
513
-	 */
514
-	public static function filter_discount_state( $post_states, $post ) {
515
-
516
-		if ( 'wpi_discount' == $post->post_type ) {
517
-
518
-			$discount = new WPInv_Discount( $post );
519
-
520
-			$status = $discount->is_expired() ? 'expired' : $discount->get_status();
521
-
522
-			if ( $status != 'publish' ) {
523
-				return array(
524
-					'discount_status' => wpinv_discount_status( $status ),
525
-				);
526
-			}
527
-
528
-			return array();
529
-
530
-		}
531
-
532
-		return $post_states;
533
-
534
-	}
535
-
536
-	/**
537
-	 * Returns an array of items table columns.
538
-	 */
539
-	public static function item_columns( $columns ) {
540
-
541
-		$columns = array(
542
-			'cb'                => $columns['cb'],
543
-			'title'             => __( 'Name', 'invoicing' ),
544
-			'price'             => __( 'Price', 'invoicing' ),
545
-			'vat_rule'          => __( 'VAT rule', 'invoicing' ),
546
-			'vat_class'         => __( 'VAT class', 'invoicing' ),
547
-			'type'              => __( 'Type', 'invoicing' ),
548
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
549
-		);
550
-
551
-		if ( ! wpinv_use_taxes() ) {
552
-			unset( $columns['vat_rule'] );
553
-			unset( $columns['vat_class'] );
554
-		}
555
-
556
-		return apply_filters( 'wpi_item_table_columns', $columns );
557
-	}
558
-
559
-	/**
560
-	 * Returns an array of sortable items table columns.
561
-	 */
562
-	public static function sortable_item_columns( $columns ) {
563
-
564
-		return array_merge(
565
-			$columns,
566
-			array(
567
-				'price'     => 'price',
568
-				'vat_rule'  => 'vat_rule',
569
-				'vat_class' => 'vat_class',
570
-				'type'      => 'type',
571
-			)
572
-		);
573
-
574
-	}
575
-
576
-	/**
577
-	 * Displays items table columns.
578
-	 */
579
-	public static function display_item_columns( $column_name, $post_id ) {
489
+        return $post_states;
490
+
491
+    }
492
+
493
+    /**
494
+     * Returns an array of coupon table columns.
495
+     */
496
+    public static function discount_columns( $columns ) {
497
+
498
+        $columns = array(
499
+            'cb'                => $columns['cb'],
500
+            'title'             => __( 'Name', 'invoicing' ),
501
+            'code'              => __( 'Code', 'invoicing' ),
502
+            'amount'            => __( 'Amount', 'invoicing' ),
503
+            'usage'             => __( 'Usage / Limit', 'invoicing' ),
504
+            'start_date'        => __( 'Start Date', 'invoicing' ),
505
+            'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
506
+        );
507
+
508
+        return apply_filters( 'wpi_discount_table_columns', $columns );
509
+    }
510
+
511
+    /**
512
+     * Filters post states.
513
+     */
514
+    public static function filter_discount_state( $post_states, $post ) {
515
+
516
+        if ( 'wpi_discount' == $post->post_type ) {
517
+
518
+            $discount = new WPInv_Discount( $post );
519
+
520
+            $status = $discount->is_expired() ? 'expired' : $discount->get_status();
521
+
522
+            if ( $status != 'publish' ) {
523
+                return array(
524
+                    'discount_status' => wpinv_discount_status( $status ),
525
+                );
526
+            }
527
+
528
+            return array();
529
+
530
+        }
531
+
532
+        return $post_states;
533
+
534
+    }
535
+
536
+    /**
537
+     * Returns an array of items table columns.
538
+     */
539
+    public static function item_columns( $columns ) {
540
+
541
+        $columns = array(
542
+            'cb'                => $columns['cb'],
543
+            'title'             => __( 'Name', 'invoicing' ),
544
+            'price'             => __( 'Price', 'invoicing' ),
545
+            'vat_rule'          => __( 'VAT rule', 'invoicing' ),
546
+            'vat_class'         => __( 'VAT class', 'invoicing' ),
547
+            'type'              => __( 'Type', 'invoicing' ),
548
+            'shortcode'         => __( 'Shortcode', 'invoicing' ),
549
+        );
550
+
551
+        if ( ! wpinv_use_taxes() ) {
552
+            unset( $columns['vat_rule'] );
553
+            unset( $columns['vat_class'] );
554
+        }
555
+
556
+        return apply_filters( 'wpi_item_table_columns', $columns );
557
+    }
558
+
559
+    /**
560
+     * Returns an array of sortable items table columns.
561
+     */
562
+    public static function sortable_item_columns( $columns ) {
563
+
564
+        return array_merge(
565
+            $columns,
566
+            array(
567
+                'price'     => 'price',
568
+                'vat_rule'  => 'vat_rule',
569
+                'vat_class' => 'vat_class',
570
+                'type'      => 'type',
571
+            )
572
+        );
573
+
574
+    }
575
+
576
+    /**
577
+     * Displays items table columns.
578
+     */
579
+    public static function display_item_columns( $column_name, $post_id ) {
580 580
  
581
-		$item = new WPInv_Item( $post_id );
581
+        $item = new WPInv_Item( $post_id );
582 582
 
583
-		switch ( $column_name ) {
583
+        switch ( $column_name ) {
584 584
 
585
-			case 'price' :
585
+            case 'price' :
586 586
 
587
-				if ( ! $item->is_recurring() ) {
588
-					echo $item->get_the_price();
589
-					break;
590
-				}
587
+                if ( ! $item->is_recurring() ) {
588
+                    echo $item->get_the_price();
589
+                    break;
590
+                }
591 591
 
592
-				$price = wp_sprintf(
593
-					__( '%s / %s', 'invoicing' ),
594
-					$item->get_the_price(),
595
-					getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
596
-				);
592
+                $price = wp_sprintf(
593
+                    __( '%s / %s', 'invoicing' ),
594
+                    $item->get_the_price(),
595
+                    getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
596
+                );
597 597
 
598
-				if ( $item->get_the_price() == $item->get_the_initial_price() ) {
599
-					echo $price;
600
-					break;
601
-				}
598
+                if ( $item->get_the_price() == $item->get_the_initial_price() ) {
599
+                    echo $price;
600
+                    break;
601
+                }
602 602
 
603
-				echo $item->get_the_initial_price();
603
+                echo $item->get_the_initial_price();
604 604
 
605
-				echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
606
-				break;
605
+                echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
606
+                break;
607 607
 
608
-			case 'vat_rule' :
609
-				echo getpaid_get_tax_rule_label( $item->get_vat_rule() );
610
-				break;
608
+            case 'vat_rule' :
609
+                echo getpaid_get_tax_rule_label( $item->get_vat_rule() );
610
+                break;
611 611
 
612
-			case 'vat_class' :
613
-				echo getpaid_get_tax_class_label( $item->get_vat_class() );
614
-				break;
612
+            case 'vat_class' :
613
+                echo getpaid_get_tax_class_label( $item->get_vat_class() );
614
+                break;
615 615
 
616
-			case 'shortcode' :
616
+            case 'shortcode' :
617 617
 
618
-				if ( $item->is_type( array( '', 'fee', 'custom' ) ) ) {
619
-					echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
620
-				} else {
621
-					echo "&mdash;";
622
-				}
618
+                if ( $item->is_type( array( '', 'fee', 'custom' ) ) ) {
619
+                    echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
620
+                } else {
621
+                    echo "&mdash;";
622
+                }
623 623
 				
624
-				break;
624
+                break;
625 625
 
626
-			case 'type' :
627
-				echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
628
-				break;
626
+            case 'type' :
627
+                echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
628
+                break;
629 629
 
630
-		}
630
+        }
631 631
 
632
-	}
632
+    }
633 633
 
634
-	/**
635
-	 * Lets users filter items using taxes.
636
-	 */
637
-	public static function add_item_filters( $post_type ) {
634
+    /**
635
+     * Lets users filter items using taxes.
636
+     */
637
+    public static function add_item_filters( $post_type ) {
638 638
 
639
-		// Abort if we're not dealing with items.
640
-		if ( $post_type != 'wpi_item' ) {
641
-			return;
642
-		}
639
+        // Abort if we're not dealing with items.
640
+        if ( $post_type != 'wpi_item' ) {
641
+            return;
642
+        }
643 643
 
644
-		// Filter by vat rules.
645
-		if ( wpinv_use_taxes() ) {
644
+        // Filter by vat rules.
645
+        if ( wpinv_use_taxes() ) {
646 646
 	
647
-			// Sanitize selected vat rule.
648
-			$vat_rule   = '';
649
-			$vat_rules  = getpaid_get_tax_rules();
650
-			if ( isset( $_GET['vat_rule'] ) ) {
651
-				$vat_rule   =  sanitize_text_field( $_GET['vat_rule'] );
652
-			}
653
-
654
-			// Filter by VAT rule.
655
-			echo wpinv_html_select(
656
-				array(
657
-					'options'          => array_merge(
658
-						array(
659
-							'' => __( 'All VAT rules', 'invoicing' )
660
-						),
661
-						$vat_rules
662
-					),
663
-					'name'             => 'vat_rule',
664
-					'id'               => 'vat_rule',
665
-					'selected'         => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '',
666
-					'show_option_all'  => false,
667
-					'show_option_none' => false,
668
-				)
669
-			);
670
-
671
-			// Filter by VAT class.
647
+            // Sanitize selected vat rule.
648
+            $vat_rule   = '';
649
+            $vat_rules  = getpaid_get_tax_rules();
650
+            if ( isset( $_GET['vat_rule'] ) ) {
651
+                $vat_rule   =  sanitize_text_field( $_GET['vat_rule'] );
652
+            }
653
+
654
+            // Filter by VAT rule.
655
+            echo wpinv_html_select(
656
+                array(
657
+                    'options'          => array_merge(
658
+                        array(
659
+                            '' => __( 'All VAT rules', 'invoicing' )
660
+                        ),
661
+                        $vat_rules
662
+                    ),
663
+                    'name'             => 'vat_rule',
664
+                    'id'               => 'vat_rule',
665
+                    'selected'         => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '',
666
+                    'show_option_all'  => false,
667
+                    'show_option_none' => false,
668
+                )
669
+            );
670
+
671
+            // Filter by VAT class.
672 672
 	
673
-			// Sanitize selected vat rule.
674
-			$vat_class   = '';
675
-			$vat_classes = getpaid_get_tax_classes();
676
-			if ( isset( $_GET['vat_class'] ) ) {
677
-				$vat_class   = sanitize_text_field( $_GET['vat_class'] );
678
-			}
679
-
680
-			echo wpinv_html_select(
681
-				array(
682
-					'options'          => array_merge(
683
-						array(
684
-							'' => __( 'All VAT classes', 'invoicing' )
685
-						),
686
-						$vat_classes
687
-					),
688
-					'name'             => 'vat_class',
689
-					'id'               => 'vat_class',
690
-					'selected'         => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '',
691
-					'show_option_all'  => false,
692
-					'show_option_none' => false,
693
-				)
694
-			);
695
-
696
-		}
697
-
698
-		// Filter by item type.
699
-		$type   = '';
700
-		if ( isset( $_GET['type'] ) ) {
701
-			$type   = sanitize_text_field( $_GET['type'] );
702
-		}
703
-
704
-		echo wpinv_html_select(
705
-			array(
706
-				'options'          => array_merge(
707
-					array(
708
-						'' => __( 'All item types', 'invoicing' )
709
-					),
710
-					wpinv_get_item_types()
711
-				),
712
-				'name'             => 'type',
713
-				'id'               => 'type',
714
-				'selected'         => in_array( $type, wpinv_item_types() ) ? $type : '',
715
-				'show_option_all'  => false,
716
-				'show_option_none' => false,
717
-			)
718
-		);
719
-
720
-	}
721
-
722
-	/**
723
-	 * Filters the item query.
724
-	 */
725
-	public static function filter_item_query( $query ) {
726
-
727
-		// modify the query only if it admin and main query.
728
-		if ( ! ( is_admin() && $query->is_main_query() ) ){ 
729
-			return $query;
730
-		}
731
-
732
-		// we want to modify the query for our items.
733
-		if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){
734
-			return $query;
735
-		}
736
-
737
-		if ( empty( $query->query_vars['meta_query'] ) ) {
738
-			$query->query_vars['meta_query'] = array();
739
-		}
740
-
741
-		// Filter vat rule type
673
+            // Sanitize selected vat rule.
674
+            $vat_class   = '';
675
+            $vat_classes = getpaid_get_tax_classes();
676
+            if ( isset( $_GET['vat_class'] ) ) {
677
+                $vat_class   = sanitize_text_field( $_GET['vat_class'] );
678
+            }
679
+
680
+            echo wpinv_html_select(
681
+                array(
682
+                    'options'          => array_merge(
683
+                        array(
684
+                            '' => __( 'All VAT classes', 'invoicing' )
685
+                        ),
686
+                        $vat_classes
687
+                    ),
688
+                    'name'             => 'vat_class',
689
+                    'id'               => 'vat_class',
690
+                    'selected'         => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '',
691
+                    'show_option_all'  => false,
692
+                    'show_option_none' => false,
693
+                )
694
+            );
695
+
696
+        }
697
+
698
+        // Filter by item type.
699
+        $type   = '';
700
+        if ( isset( $_GET['type'] ) ) {
701
+            $type   = sanitize_text_field( $_GET['type'] );
702
+        }
703
+
704
+        echo wpinv_html_select(
705
+            array(
706
+                'options'          => array_merge(
707
+                    array(
708
+                        '' => __( 'All item types', 'invoicing' )
709
+                    ),
710
+                    wpinv_get_item_types()
711
+                ),
712
+                'name'             => 'type',
713
+                'id'               => 'type',
714
+                'selected'         => in_array( $type, wpinv_item_types() ) ? $type : '',
715
+                'show_option_all'  => false,
716
+                'show_option_none' => false,
717
+            )
718
+        );
719
+
720
+    }
721
+
722
+    /**
723
+     * Filters the item query.
724
+     */
725
+    public static function filter_item_query( $query ) {
726
+
727
+        // modify the query only if it admin and main query.
728
+        if ( ! ( is_admin() && $query->is_main_query() ) ){ 
729
+            return $query;
730
+        }
731
+
732
+        // we want to modify the query for our items.
733
+        if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){
734
+            return $query;
735
+        }
736
+
737
+        if ( empty( $query->query_vars['meta_query'] ) ) {
738
+            $query->query_vars['meta_query'] = array();
739
+        }
740
+
741
+        // Filter vat rule type
742 742
         if ( ! empty( $_GET['vat_rule'] ) ) {
743 743
             $query->query_vars['meta_query'][] = array(
744 744
                 'key'     => '_wpinv_vat_rule',
@@ -763,97 +763,97 @@  discard block
 block discarded – undo
763 763
                 'value'   => sanitize_text_field( $_GET['type'] ),
764 764
                 'compare' => '='
765 765
             );
766
-		}
767
-
768
-	}
769
-
770
-	/**
771
-	 * Reorders items.
772
-	 */
773
-	public static function reorder_items( $vars ) {
774
-		global $typenow;
775
-
776
-		if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
777
-			return $vars;
778
-		}
779
-
780
-		// By item type.
781
-		if ( 'type' == $vars['orderby'] ) {
782
-			return array_merge(
783
-				$vars,
784
-				array(
785
-					'meta_key' => '_wpinv_type',
786
-					'orderby'  => 'meta_value'
787
-				)
788
-			);
789
-		}
790
-
791
-		// By vat class.
792
-		if ( 'vat_class' == $vars['orderby'] ) {
793
-			return array_merge(
794
-				$vars,
795
-				array(
796
-					'meta_key' => '_wpinv_vat_class',
797
-					'orderby'  => 'meta_value'
798
-				)
799
-			);
800
-		}
801
-
802
-		// By vat rule.
803
-		if ( 'vat_rule' == $vars['orderby'] ) {
804
-			return array_merge(
805
-				$vars,
806
-				array(
807
-					'meta_key' => '_wpinv_vat_rule',
808
-					'orderby'  => 'meta_value'
809
-				)
810
-			);
811
-		}
812
-
813
-		// By price.
814
-		if ( 'price' == $vars['orderby'] ) {
815
-			return array_merge(
816
-				$vars,
817
-				array(
818
-					'meta_key' => '_wpinv_price',
819
-					'orderby'  => 'meta_value_num'
820
-				)
821
-			);
822
-		}
823
-
824
-		return $vars;
825
-
826
-	}
827
-
828
-	/**
829
-	 * Fired when deleting a post.
830
-	 */
831
-	public static function delete_post( $post_id ) {
832
-
833
-		switch ( get_post_type( $post_id ) ) {
834
-
835
-			case 'wpi_item' :
836
-				do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
837
-				break;
838
-
839
-			case 'wpi_payment_form' :
840
-				do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
841
-				break;
842
-
843
-			case 'wpi_discount' :
844
-				do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
845
-				break;
846
-
847
-			case 'wpi_invoice' :
848
-				$invoice = new WPInv_Invoice( $post_id );
849
-				do_action( "getpaid_before_delete_invoice", $invoice );
850
-				$invoice->get_data_store()->delete_items( $invoice );
851
-				$invoice->get_data_store()->delete_special_fields( $invoice );
852
-				break;
853
-		}
854
-	}
855
-
856
-	/**
766
+        }
767
+
768
+    }
769
+
770
+    /**
771
+     * Reorders items.
772
+     */
773
+    public static function reorder_items( $vars ) {
774
+        global $typenow;
775
+
776
+        if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
777
+            return $vars;
778
+        }
779
+
780
+        // By item type.
781
+        if ( 'type' == $vars['orderby'] ) {
782
+            return array_merge(
783
+                $vars,
784
+                array(
785
+                    'meta_key' => '_wpinv_type',
786
+                    'orderby'  => 'meta_value'
787
+                )
788
+            );
789
+        }
790
+
791
+        // By vat class.
792
+        if ( 'vat_class' == $vars['orderby'] ) {
793
+            return array_merge(
794
+                $vars,
795
+                array(
796
+                    'meta_key' => '_wpinv_vat_class',
797
+                    'orderby'  => 'meta_value'
798
+                )
799
+            );
800
+        }
801
+
802
+        // By vat rule.
803
+        if ( 'vat_rule' == $vars['orderby'] ) {
804
+            return array_merge(
805
+                $vars,
806
+                array(
807
+                    'meta_key' => '_wpinv_vat_rule',
808
+                    'orderby'  => 'meta_value'
809
+                )
810
+            );
811
+        }
812
+
813
+        // By price.
814
+        if ( 'price' == $vars['orderby'] ) {
815
+            return array_merge(
816
+                $vars,
817
+                array(
818
+                    'meta_key' => '_wpinv_price',
819
+                    'orderby'  => 'meta_value_num'
820
+                )
821
+            );
822
+        }
823
+
824
+        return $vars;
825
+
826
+    }
827
+
828
+    /**
829
+     * Fired when deleting a post.
830
+     */
831
+    public static function delete_post( $post_id ) {
832
+
833
+        switch ( get_post_type( $post_id ) ) {
834
+
835
+            case 'wpi_item' :
836
+                do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
837
+                break;
838
+
839
+            case 'wpi_payment_form' :
840
+                do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
841
+                break;
842
+
843
+            case 'wpi_discount' :
844
+                do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
845
+                break;
846
+
847
+            case 'wpi_invoice' :
848
+                $invoice = new WPInv_Invoice( $post_id );
849
+                do_action( "getpaid_before_delete_invoice", $invoice );
850
+                $invoice->get_data_store()->delete_items( $invoice );
851
+                $invoice->get_data_store()->delete_special_fields( $invoice );
852
+                break;
853
+        }
854
+    }
855
+
856
+    /**
857 857
      * Add a post display state for special GetPaid pages in the page list table.
858 858
      *
859 859
      * @param array   $post_states An array of post display states.
@@ -867,22 +867,22 @@  discard block
 block discarded – undo
867 867
             $post_states['getpaid_success_page'] = __( 'GetPaid Receipt Page', 'invoicing' );
868 868
         }
869 869
 
870
-		foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) {
870
+        foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) {
871 871
 
872
-			if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) {
873
-				$post_states["getpaid_{$post_type}_history_page"] = sprintf(
874
-					__( 'GetPaid %s History Page', 'invoicing' ),
875
-					$label
876
-				);
877
-			}
872
+            if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) {
873
+                $post_states["getpaid_{$post_type}_history_page"] = sprintf(
874
+                    __( 'GetPaid %s History Page', 'invoicing' ),
875
+                    $label
876
+                );
877
+            }
878 878
 
879
-		}
879
+        }
880 880
 		
881
-		if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) {
881
+        if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) {
882 882
             $post_states['getpaid_invoice_subscription_page'] = __( 'GetPaid Subscription Page', 'invoicing' );
883 883
         }
884 884
 
885
-		if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) {
885
+        if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) {
886 886
             $post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' );
887 887
         }
888 888
 
Please login to merge, or discard this patch.
Spacing   +235 added lines, -235 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,74 +21,74 @@  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 );
28
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 );
27
+		add_filter('post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2);
28
+		add_filter('post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2);
29 29
 
30 30
 		// Invoice table columns.
31
-		add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
32
-		add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
33
-		add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) );
34
-		add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 );
31
+		add_filter('manage_wpi_invoice_posts_columns', array(__CLASS__, 'invoice_columns'), 100);
32
+		add_action('manage_wpi_invoice_posts_custom_column', array(__CLASS__, 'display_invoice_columns'), 10, 2);
33
+		add_filter('bulk_actions-edit-wpi_invoice', array(__CLASS__, 'invoice_bulk_actions'));
34
+		add_filter('handle_bulk_actions-edit-wpi_invoice', array(__CLASS__, 'handle_invoice_bulk_actions'), 10, 3);
35 35
 
36 36
 		// Items table columns.
37
-		add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
38
-		add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
39
-		add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
40
-		add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
41
-		add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
42
-		add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
37
+		add_filter('manage_wpi_item_posts_columns', array(__CLASS__, 'item_columns'), 100);
38
+		add_filter('manage_edit-wpi_item_sortable_columns', array(__CLASS__, 'sortable_item_columns'), 20);
39
+		add_action('manage_wpi_item_posts_custom_column', array(__CLASS__, 'display_item_columns'), 10, 2);
40
+		add_action('restrict_manage_posts', array(__CLASS__, 'add_item_filters'), 100);
41
+		add_action('parse_query', array(__CLASS__, 'filter_item_query'), 100);
42
+		add_action('request', array(__CLASS__, 'reorder_items'), 100);
43 43
 
44 44
 		// Payment forms columns.
45
-		add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
46
-		add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
47
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
45
+		add_filter('manage_wpi_payment_form_posts_columns', array(__CLASS__, 'payment_form_columns'), 100);
46
+		add_action('manage_wpi_payment_form_posts_custom_column', array(__CLASS__, 'display_payment_form_columns'), 10, 2);
47
+		add_filter('display_post_states', array(__CLASS__, 'filter_payment_form_state'), 10, 2);
48 48
 
49 49
 		// Discount table columns.
50
-		add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
51
-		add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 );
50
+		add_filter('manage_wpi_discount_posts_columns', array(__CLASS__, 'discount_columns'), 100);
51
+		add_filter('bulk_actions-edit-wpi_discount', '__return_empty_array', 100);
52 52
 
53 53
 		// Deleting posts.
54
-		add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
55
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
54
+		add_action('delete_post', array(__CLASS__, 'delete_post'));
55
+		add_filter('display_post_states', array(__CLASS__, 'filter_discount_state'), 10, 2);
56 56
 
57
-		add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 );
57
+		add_filter('display_post_states', array(__CLASS__, 'add_display_post_states'), 10, 2);
58 58
 	}
59 59
 
60 60
 	/**
61 61
 	 * Post updated messages.
62 62
 	 */
63
-	public static function post_updated_messages( $messages ) {
63
+	public static function post_updated_messages($messages) {
64 64
 		global $post;
65 65
 
66 66
 		$messages['wpi_discount'] = array(
67 67
 			0   => '',
68
-			1   => __( 'Discount updated.', 'invoicing' ),
69
-			2   => __( 'Custom field updated.', 'invoicing' ),
70
-			3   => __( 'Custom field deleted.', 'invoicing' ),
71
-			4   => __( 'Discount updated.', 'invoicing' ),
72
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
73
-			6   => __( 'Discount updated.', 'invoicing' ),
74
-			7   => __( 'Discount saved.', 'invoicing' ),
75
-			8   => __( 'Discount submitted.', 'invoicing' ),
76
-			9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
77
-			10  => __( 'Discount draft updated.', 'invoicing' ),
68
+			1   => __('Discount updated.', 'invoicing'),
69
+			2   => __('Custom field updated.', 'invoicing'),
70
+			3   => __('Custom field deleted.', 'invoicing'),
71
+			4   => __('Discount updated.', 'invoicing'),
72
+			5   => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
73
+			6   => __('Discount updated.', 'invoicing'),
74
+			7   => __('Discount saved.', 'invoicing'),
75
+			8   => __('Discount submitted.', 'invoicing'),
76
+			9   => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))),
77
+			10  => __('Discount draft updated.', 'invoicing'),
78 78
 		);
79 79
 
80 80
 		$messages['wpi_payment_form'] = array(
81 81
 			0   => '',
82
-			1   => __( 'Payment Form updated.', 'invoicing' ),
83
-			2   => __( 'Custom field updated.', 'invoicing' ),
84
-			3   => __( 'Custom field deleted.', 'invoicing' ),
85
-			4   => __( 'Payment Form updated.', 'invoicing' ),
86
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
87
-			6   => __( 'Payment Form updated.', 'invoicing' ),
88
-			7   => __( 'Payment Form saved.', 'invoicing' ),
89
-			8   => __( 'Payment Form submitted.', 'invoicing' ),
90
-			9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
91
-			10  => __( 'Payment Form draft updated.', 'invoicing' ),
82
+			1   => __('Payment Form updated.', 'invoicing'),
83
+			2   => __('Custom field updated.', 'invoicing'),
84
+			3   => __('Custom field deleted.', 'invoicing'),
85
+			4   => __('Payment Form updated.', 'invoicing'),
86
+			5   => isset($_GET['revision']) ? wp_sprintf(__('Payment Form restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
87
+			6   => __('Payment Form updated.', 'invoicing'),
88
+			7   => __('Payment Form saved.', 'invoicing'),
89
+			8   => __('Payment Form submitted.', 'invoicing'),
90
+			9   => wp_sprintf(__('Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))),
91
+			10  => __('Payment Form draft updated.', 'invoicing'),
92 92
 		);
93 93
 
94 94
 		return $messages;
@@ -98,19 +98,19 @@  discard block
 block discarded – undo
98 98
 	/**
99 99
 	 * Post row actions.
100 100
 	 */
101
-	public static function post_row_actions( $actions, $post ) {
101
+	public static function post_row_actions($actions, $post) {
102 102
 
103
-		$post = get_post( $post );
103
+		$post = get_post($post);
104 104
 
105 105
 		// We do not want to edit the default payment form.
106
-		if ( 'wpi_payment_form' == $post->post_type ) {
106
+		if ('wpi_payment_form' == $post->post_type) {
107 107
 
108
-			if ( $post->ID == wpinv_get_default_payment_form() ) {
109
-				unset( $actions['trash'] );
110
-				unset( $actions['inline hide-if-no-js'] );
108
+			if ($post->ID == wpinv_get_default_payment_form()) {
109
+				unset($actions['trash']);
110
+				unset($actions['inline hide-if-no-js']);
111 111
 			}
112 112
 
113
-			$actions['duplicate'] =  sprintf(
113
+			$actions['duplicate'] = sprintf(
114 114
 				'<a href="%1$s">%2$s</a>',
115 115
 				esc_url(
116 116
 					wp_nonce_url(
@@ -124,20 +124,20 @@  discard block
 block discarded – undo
124 124
 						'getpaid-nonce'
125 125
 					)
126 126
 				),
127
-				esc_html( __( 'Duplicate', 'invoicing' ) )
127
+				esc_html(__('Duplicate', 'invoicing'))
128 128
 			);
129 129
 
130 130
 		}
131 131
 
132 132
 		// Link to item payment form.
133
-		if ( 'wpi_item' == $post->post_type ) {
133
+		if ('wpi_item' == $post->post_type) {
134 134
 
135
-			if ( in_array( get_post_meta( $post->ID, '_wpinv_type', true ), array( '', 'fee', 'custom' ) ) ) {
135
+			if (in_array(get_post_meta($post->ID, '_wpinv_type', true), array('', 'fee', 'custom'))) {
136 136
 
137
-				$actions['buy'] =  sprintf(
137
+				$actions['buy'] = sprintf(
138 138
 					'<a href="%1$s">%2$s</a>',
139
-					esc_url( getpaid_embed_url( false, $post->ID . '|0' ) ),
140
-					esc_html( __( 'Buy', 'invoicing' ) )
139
+					esc_url(getpaid_embed_url(false, $post->ID . '|0')),
140
+					esc_html(__('Buy', 'invoicing'))
141 141
 				);
142 142
 
143 143
 			}
@@ -155,31 +155,31 @@  discard block
 block discarded – undo
155 155
 	 * @param WP_Post $post
156 156
      * @return array $actions actions without edit option
157 157
      */
158
-    public static function filter_invoice_row_actions( $actions, $post ) {
158
+    public static function filter_invoice_row_actions($actions, $post) {
159 159
 
160
-        if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
160
+        if (getpaid_is_invoice_post_type($post->post_type)) {
161 161
 
162 162
 			$actions = array();
163
-			$invoice = new WPInv_Invoice( $post );
163
+			$invoice = new WPInv_Invoice($post);
164 164
 
165
-			$actions['edit'] =  sprintf(
165
+			$actions['edit'] = sprintf(
166 166
 				'<a href="%1$s">%2$s</a>',
167
-				esc_url( get_edit_post_link( $invoice->get_id() ) ),
168
-				esc_html( __( 'Edit', 'invoicing' ) )
167
+				esc_url(get_edit_post_link($invoice->get_id())),
168
+				esc_html(__('Edit', 'invoicing'))
169 169
 			);
170 170
 
171
-			if ( ! $invoice->is_draft() ) {
171
+			if (!$invoice->is_draft()) {
172 172
 
173
-				$actions['view'] =  sprintf(
173
+				$actions['view'] = sprintf(
174 174
 					'<a href="%1$s">%2$s</a>',
175
-					esc_url( $invoice->get_view_url() ),
175
+					esc_url($invoice->get_view_url()),
176 176
 					sprintf(
177
-						esc_html( __( 'View %s', 'invoicing' ) ),
178
-						getpaid_get_post_type_label( $invoice->get_post_type(), false )
177
+						esc_html(__('View %s', 'invoicing')),
178
+						getpaid_get_post_type_label($invoice->get_post_type(), false)
179 179
 					)
180 180
 				);
181 181
 
182
-				$actions['send'] =  sprintf(
182
+				$actions['send'] = sprintf(
183 183
 					'<a href="%1$s">%2$s</a>',
184 184
 					esc_url(
185 185
 						wp_nonce_url(
@@ -193,12 +193,12 @@  discard block
 block discarded – undo
193 193
 							'getpaid-nonce'
194 194
 						)
195 195
 					),
196
-					esc_html( __( 'Send to Customer', 'invoicing' ) )
196
+					esc_html(__('Send to Customer', 'invoicing'))
197 197
 				);
198 198
 
199 199
 			}
200 200
 
201
-			$actions['duplicate'] =  sprintf(
201
+			$actions['duplicate'] = sprintf(
202 202
 				'<a href="%1$s">%2$s</a>',
203 203
 				esc_url(
204 204
 					wp_nonce_url(
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 						'getpaid-nonce'
213 213
 					)
214 214
 				),
215
-				esc_html( __( 'Duplicate', 'invoicing' ) )
215
+				esc_html(__('Duplicate', 'invoicing'))
216 216
 			);
217 217
 
218 218
         }
@@ -223,42 +223,42 @@  discard block
 block discarded – undo
223 223
 	/**
224 224
 	 * Returns an array of invoice table columns.
225 225
 	 */
226
-	public static function invoice_columns( $columns ) {
226
+	public static function invoice_columns($columns) {
227 227
 
228 228
 		$columns = array(
229 229
 			'cb'                => $columns['cb'],
230
-			'number'            => __( 'Invoice', 'invoicing' ),
231
-			'customer'          => __( 'Customer', 'invoicing' ),
232
-			'invoice_date'      => __( 'Created', 'invoicing' ),
233
-			'payment_date'      => __( 'Completed', 'invoicing' ),
234
-			'amount'            => __( 'Amount', 'invoicing' ),
235
-			'recurring'         => __( 'Recurring', 'invoicing' ),
236
-			'status'            => __( 'Status', 'invoicing' ),
230
+			'number'            => __('Invoice', 'invoicing'),
231
+			'customer'          => __('Customer', 'invoicing'),
232
+			'invoice_date'      => __('Created', 'invoicing'),
233
+			'payment_date'      => __('Completed', 'invoicing'),
234
+			'amount'            => __('Amount', 'invoicing'),
235
+			'recurring'         => __('Recurring', 'invoicing'),
236
+			'status'            => __('Status', 'invoicing'),
237 237
 		);
238 238
 
239
-		return apply_filters( 'wpi_invoice_table_columns', $columns );
239
+		return apply_filters('wpi_invoice_table_columns', $columns);
240 240
 	}
241 241
 
242 242
 	/**
243 243
 	 * Displays invoice table columns.
244 244
 	 */
245
-	public static function display_invoice_columns( $column_name, $post_id ) {
245
+	public static function display_invoice_columns($column_name, $post_id) {
246 246
 
247
-		$invoice = new WPInv_Invoice( $post_id );
247
+		$invoice = new WPInv_Invoice($post_id);
248 248
 
249
-		switch ( $column_name ) {
249
+		switch ($column_name) {
250 250
 
251 251
 			case 'invoice_date' :
252
-				$date_time = esc_attr( $invoice->get_created_date() );
253
-				$date      = esc_html( getpaid_format_date_value( $date_time, "&mdash;", true ) );
252
+				$date_time = esc_attr($invoice->get_created_date());
253
+				$date      = esc_html(getpaid_format_date_value($date_time, "&mdash;", true));
254 254
 				echo "<span title='$date_time'>$date</span>";
255 255
 				break;
256 256
 
257 257
 			case 'payment_date' :
258 258
 
259
-				if ( $invoice->is_paid() ) {
260
-					$date_time = esc_attr( $invoice->get_completed_date() );
261
-					$date      = esc_html( getpaid_format_date_value( $date_time, "&mdash;", true ) );
259
+				if ($invoice->is_paid()) {
260
+					$date_time = esc_attr($invoice->get_completed_date());
261
+					$date      = esc_html(getpaid_format_date_value($date_time, "&mdash;", true));
262 262
 					echo "<span title='$date_time'>$date</span>";
263 263
 				} else {
264 264
 					echo "&mdash;";
@@ -269,17 +269,17 @@  discard block
 block discarded – undo
269 269
 			case 'amount' :
270 270
 
271 271
 				$amount = $invoice->get_total();
272
-				$formated_amount = wp_kses_post( wpinv_price( $amount, $invoice->get_currency() ) );
272
+				$formated_amount = wp_kses_post(wpinv_price($amount, $invoice->get_currency()));
273 273
 
274
-				if ( $invoice->is_refunded() ) {
275
-					$refunded_amount = wp_kses_post( wpinv_price( 0, $invoice->get_currency() ) );
274
+				if ($invoice->is_refunded()) {
275
+					$refunded_amount = wp_kses_post(wpinv_price(0, $invoice->get_currency()));
276 276
 					echo "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>";
277 277
 				} else {
278 278
 
279 279
 					$discount = $invoice->get_total_discount();
280 280
 
281
-					if ( ! empty( $discount ) ) {
282
-						$new_amount = wp_kses_post( wpinv_price( $amount + $discount, $invoice->get_currency() ) );
281
+					if (!empty($discount)) {
282
+						$new_amount = wp_kses_post(wpinv_price($amount + $discount, $invoice->get_currency()));
283 283
 						echo "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>";
284 284
 					} else {
285 285
 						echo $formated_amount;
@@ -290,13 +290,13 @@  discard block
 block discarded – undo
290 290
 				break;
291 291
 
292 292
 			case 'status' :
293
-				$status       = esc_html( $invoice->get_status() );
294
-				$status_label = esc_html( $invoice->get_status_nicename() );
293
+				$status       = esc_html($invoice->get_status());
294
+				$status_label = esc_html($invoice->get_status_nicename());
295 295
 
296 296
 				// If it is paid, show the gateway title.
297
-				if ( $invoice->is_paid() ) {
298
-					$gateway = esc_html( $invoice->get_gateway_title() );
299
-					$gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), esc_html( $gateway ) );
297
+				if ($invoice->is_paid()) {
298
+					$gateway = esc_html($invoice->get_gateway_title());
299
+					$gateway = wp_sprintf(esc_attr__('Paid via %s', 'invoicing'), esc_html($gateway));
300 300
 
301 301
 					echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
302 302
 				} else {
@@ -304,22 +304,22 @@  discard block
 block discarded – undo
304 304
 				}
305 305
 
306 306
 				// If it is not paid, display the overdue and view status.
307
-				if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
307
+				if (!$invoice->is_paid() && !$invoice->is_refunded()) {
308 308
 
309 309
 					// Invoice view status.
310
-					if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
311
-						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
310
+					if (wpinv_is_invoice_viewed($invoice->get_id())) {
311
+						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="' . esc_attr__('Viewed by Customer', 'invoicing') . '"></i>';
312 312
 					} else {
313
-						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
313
+						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__('Not Viewed by Customer', 'invoicing') . '"></i>';
314 314
 					}
315 315
 
316 316
 					// Display the overview status.
317
-					if ( wpinv_get_option( 'overdue_active' ) ) {
317
+					if (wpinv_get_option('overdue_active')) {
318 318
 						$due_date = $invoice->get_due_date();
319
-						$fomatted = getpaid_format_date( $due_date );
319
+						$fomatted = getpaid_format_date($due_date);
320 320
 
321
-						if ( ! empty( $fomatted ) ) {
322
-							$date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted );
321
+						if (!empty($fomatted)) {
322
+							$date = wp_sprintf(__('Due %s', 'invoicing'), $fomatted);
323 323
 							echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>";
324 324
 						}
325 325
 					}
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 
331 331
 			case 'recurring':
332 332
 
333
-				if ( $invoice->is_recurring() ) {
333
+				if ($invoice->is_recurring()) {
334 334
 					echo '<i class="fa fa-check" style="color:#43850a;"></i>';
335 335
 				} else {
336 336
 					echo '<i class="fa fa-times" style="color:#616161;"></i>';
@@ -339,9 +339,9 @@  discard block
 block discarded – undo
339 339
 
340 340
 			case 'number' :
341 341
 
342
-				$edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
343
-				$invoice_number  = esc_html( $invoice->get_number() );
344
-				$invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
342
+				$edit_link       = esc_url(get_edit_post_link($invoice->get_id()));
343
+				$invoice_number  = esc_html($invoice->get_number());
344
+				$invoice_details = esc_attr__('View Invoice Details', 'invoicing');
345 345
 
346 346
 				echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
347 347
 
@@ -351,13 +351,13 @@  discard block
 block discarded – undo
351 351
 	
352 352
 				$customer_name = $invoice->get_user_full_name();
353 353
 	
354
-				if ( empty( $customer_name ) ) {
354
+				if (empty($customer_name)) {
355 355
 					$customer_name = $invoice->get_email();
356 356
 				}
357 357
 	
358
-				if ( ! empty( $customer_name ) ) {
359
-					$customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
360
-					$view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
358
+				if (!empty($customer_name)) {
359
+					$customer_details = esc_attr__('View Customer Details', 'invoicing');
360
+					$view_link        = esc_url(add_query_arg('user_id', $invoice->get_user_id(), admin_url('user-edit.php')));
361 361
 					echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
362 362
 				} else {
363 363
 					echo '<div>&mdash;</div>';
@@ -372,19 +372,19 @@  discard block
 block discarded – undo
372 372
 	/**
373 373
 	 * Displays invoice bulk actions.
374 374
 	 */
375
-	public static function invoice_bulk_actions( $actions ) {
376
-		$actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' );
375
+	public static function invoice_bulk_actions($actions) {
376
+		$actions['resend-invoice'] = __('Send to Customer', 'invoicing');
377 377
 		return $actions;
378 378
 	}
379 379
 
380 380
 	/**
381 381
 	 * Processes invoice bulk actions.
382 382
 	 */
383
-	public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) {
383
+	public static function handle_invoice_bulk_actions($redirect_url, $action, $post_ids) {
384 384
 
385
-		if ( $action == 'resend-invoice' ) {
386
-			foreach ( $post_ids as $post_id ) {
387
-				getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true );
385
+		if ($action == 'resend-invoice') {
386
+			foreach ($post_ids as $post_id) {
387
+				getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($post_id), true);
388 388
 			}
389 389
 		}
390 390
 
@@ -395,50 +395,50 @@  discard block
 block discarded – undo
395 395
 	/**
396 396
 	 * Returns an array of payment forms table columns.
397 397
 	 */
398
-	public static function payment_form_columns( $columns ) {
398
+	public static function payment_form_columns($columns) {
399 399
 
400 400
 		$columns = array(
401 401
 			'cb'                => $columns['cb'],
402
-			'title'             => __( 'Name', 'invoicing' ),
403
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
404
-			'earnings'          => __( 'Revenue', 'invoicing' ),
405
-			'refunds'           => __( 'Refunded', 'invoicing' ),
406
-			'items'             => __( 'Items', 'invoicing' ),
407
-			'date'              => __( 'Date', 'invoicing' ),
402
+			'title'             => __('Name', 'invoicing'),
403
+			'shortcode'         => __('Shortcode', 'invoicing'),
404
+			'earnings'          => __('Revenue', 'invoicing'),
405
+			'refunds'           => __('Refunded', 'invoicing'),
406
+			'items'             => __('Items', 'invoicing'),
407
+			'date'              => __('Date', 'invoicing'),
408 408
 		);
409 409
 
410
-		return apply_filters( 'wpi_payment_form_table_columns', $columns );
410
+		return apply_filters('wpi_payment_form_table_columns', $columns);
411 411
 
412 412
 	}
413 413
 
414 414
 	/**
415 415
 	 * Displays payment form table columns.
416 416
 	 */
417
-	public static function display_payment_form_columns( $column_name, $post_id ) {
417
+	public static function display_payment_form_columns($column_name, $post_id) {
418 418
 
419 419
 		// Retrieve the payment form.
420
-		$form = new GetPaid_Payment_Form( $post_id );
420
+		$form = new GetPaid_Payment_Form($post_id);
421 421
 
422
-		switch ( $column_name ) {
422
+		switch ($column_name) {
423 423
 
424 424
 			case 'earnings' :
425
-				echo wpinv_price( $form->get_earned() );
425
+				echo wpinv_price($form->get_earned());
426 426
 				break;
427 427
 
428 428
 			case 'refunds' :
429
-				echo wpinv_price( $form->get_refunded() );
429
+				echo wpinv_price($form->get_refunded());
430 430
 				break;
431 431
 
432 432
 			case 'refunds' :
433
-				echo wpinv_price( $form->get_refunded() );
433
+				echo wpinv_price($form->get_refunded());
434 434
 				break;
435 435
 
436 436
 			case 'shortcode' :
437 437
 
438
-				if ( $form->is_default() ) {
438
+				if ($form->is_default()) {
439 439
 					echo '&mdash;';
440 440
 				} else {
441
-					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
441
+					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr($form->get_id()) . ']" style="width: 100%;" readonly/>';
442 442
 				}
443 443
 
444 444
 				break;
@@ -447,29 +447,29 @@  discard block
 block discarded – undo
447 447
 
448 448
 				$items = $form->get_items();
449 449
 
450
-				if ( $form->is_default() || empty( $items ) ) {
450
+				if ($form->is_default() || empty($items)) {
451 451
 					echo '&mdash;';
452 452
 					return;
453 453
 				}
454 454
 
455 455
 				$_items = array();
456 456
 
457
-				foreach ( $items as $item ) {
457
+				foreach ($items as $item) {
458 458
 					$url = $item->get_edit_url();
459 459
 
460
-					if ( empty( $url ) ) {
461
-						$_items[] = esc_html( $item->get_name() );
460
+					if (empty($url)) {
461
+						$_items[] = esc_html($item->get_name());
462 462
 					} else {
463 463
 						$_items[] = sprintf(
464 464
 							'<a href="%s">%s</a>',
465
-							esc_url( $url ),
466
-							esc_html( $item->get_name() )
465
+							esc_url($url),
466
+							esc_html($item->get_name())
467 467
 						);
468 468
 					}
469 469
 
470 470
 				}
471 471
 
472
-				echo implode( '<br>', $_items );
472
+				echo implode('<br>', $_items);
473 473
 
474 474
 				break;
475 475
 
@@ -480,10 +480,10 @@  discard block
 block discarded – undo
480 480
 	/**
481 481
 	 * Filters post states.
482 482
 	 */
483
-	public static function filter_payment_form_state( $post_states, $post ) {
483
+	public static function filter_payment_form_state($post_states, $post) {
484 484
 
485
-		if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
486
-			$post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
485
+		if ('wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID) {
486
+			$post_states['default_form'] = __('Default Payment Form', 'invoicing');
487 487
 		}
488 488
 	
489 489
 		return $post_states;
@@ -493,35 +493,35 @@  discard block
 block discarded – undo
493 493
 	/**
494 494
 	 * Returns an array of coupon table columns.
495 495
 	 */
496
-	public static function discount_columns( $columns ) {
496
+	public static function discount_columns($columns) {
497 497
 
498 498
 		$columns = array(
499 499
 			'cb'                => $columns['cb'],
500
-			'title'             => __( 'Name', 'invoicing' ),
501
-			'code'              => __( 'Code', 'invoicing' ),
502
-			'amount'            => __( 'Amount', 'invoicing' ),
503
-			'usage'             => __( 'Usage / Limit', 'invoicing' ),
504
-			'start_date'        => __( 'Start Date', 'invoicing' ),
505
-			'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
500
+			'title'             => __('Name', 'invoicing'),
501
+			'code'              => __('Code', 'invoicing'),
502
+			'amount'            => __('Amount', 'invoicing'),
503
+			'usage'             => __('Usage / Limit', 'invoicing'),
504
+			'start_date'        => __('Start Date', 'invoicing'),
505
+			'expiry_date'       => __('Expiry Date', 'invoicing'),
506 506
 		);
507 507
 
508
-		return apply_filters( 'wpi_discount_table_columns', $columns );
508
+		return apply_filters('wpi_discount_table_columns', $columns);
509 509
 	}
510 510
 
511 511
 	/**
512 512
 	 * Filters post states.
513 513
 	 */
514
-	public static function filter_discount_state( $post_states, $post ) {
514
+	public static function filter_discount_state($post_states, $post) {
515 515
 
516
-		if ( 'wpi_discount' == $post->post_type ) {
516
+		if ('wpi_discount' == $post->post_type) {
517 517
 
518
-			$discount = new WPInv_Discount( $post );
518
+			$discount = new WPInv_Discount($post);
519 519
 
520 520
 			$status = $discount->is_expired() ? 'expired' : $discount->get_status();
521 521
 
522
-			if ( $status != 'publish' ) {
522
+			if ($status != 'publish') {
523 523
 				return array(
524
-					'discount_status' => wpinv_discount_status( $status ),
524
+					'discount_status' => wpinv_discount_status($status),
525 525
 				);
526 526
 			}
527 527
 
@@ -536,30 +536,30 @@  discard block
 block discarded – undo
536 536
 	/**
537 537
 	 * Returns an array of items table columns.
538 538
 	 */
539
-	public static function item_columns( $columns ) {
539
+	public static function item_columns($columns) {
540 540
 
541 541
 		$columns = array(
542 542
 			'cb'                => $columns['cb'],
543
-			'title'             => __( 'Name', 'invoicing' ),
544
-			'price'             => __( 'Price', 'invoicing' ),
545
-			'vat_rule'          => __( 'VAT rule', 'invoicing' ),
546
-			'vat_class'         => __( 'VAT class', 'invoicing' ),
547
-			'type'              => __( 'Type', 'invoicing' ),
548
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
543
+			'title'             => __('Name', 'invoicing'),
544
+			'price'             => __('Price', 'invoicing'),
545
+			'vat_rule'          => __('VAT rule', 'invoicing'),
546
+			'vat_class'         => __('VAT class', 'invoicing'),
547
+			'type'              => __('Type', 'invoicing'),
548
+			'shortcode'         => __('Shortcode', 'invoicing'),
549 549
 		);
550 550
 
551
-		if ( ! wpinv_use_taxes() ) {
552
-			unset( $columns['vat_rule'] );
553
-			unset( $columns['vat_class'] );
551
+		if (!wpinv_use_taxes()) {
552
+			unset($columns['vat_rule']);
553
+			unset($columns['vat_class']);
554 554
 		}
555 555
 
556
-		return apply_filters( 'wpi_item_table_columns', $columns );
556
+		return apply_filters('wpi_item_table_columns', $columns);
557 557
 	}
558 558
 
559 559
 	/**
560 560
 	 * Returns an array of sortable items table columns.
561 561
 	 */
562
-	public static function sortable_item_columns( $columns ) {
562
+	public static function sortable_item_columns($columns) {
563 563
 
564 564
 		return array_merge(
565 565
 			$columns,
@@ -576,47 +576,47 @@  discard block
 block discarded – undo
576 576
 	/**
577 577
 	 * Displays items table columns.
578 578
 	 */
579
-	public static function display_item_columns( $column_name, $post_id ) {
579
+	public static function display_item_columns($column_name, $post_id) {
580 580
  
581
-		$item = new WPInv_Item( $post_id );
581
+		$item = new WPInv_Item($post_id);
582 582
 
583
-		switch ( $column_name ) {
583
+		switch ($column_name) {
584 584
 
585 585
 			case 'price' :
586 586
 
587
-				if ( ! $item->is_recurring() ) {
587
+				if (!$item->is_recurring()) {
588 588
 					echo $item->get_the_price();
589 589
 					break;
590 590
 				}
591 591
 
592 592
 				$price = wp_sprintf(
593
-					__( '%s / %s', 'invoicing' ),
593
+					__('%s / %s', 'invoicing'),
594 594
 					$item->get_the_price(),
595
-					getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
595
+					getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), '')
596 596
 				);
597 597
 
598
-				if ( $item->get_the_price() == $item->get_the_initial_price() ) {
598
+				if ($item->get_the_price() == $item->get_the_initial_price()) {
599 599
 					echo $price;
600 600
 					break;
601 601
 				}
602 602
 
603 603
 				echo $item->get_the_initial_price();
604 604
 
605
-				echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
605
+				echo '<span class="meta">' . wp_sprintf(__('then %s', 'invoicing'), $price) . '</span>';
606 606
 				break;
607 607
 
608 608
 			case 'vat_rule' :
609
-				echo getpaid_get_tax_rule_label( $item->get_vat_rule() );
609
+				echo getpaid_get_tax_rule_label($item->get_vat_rule());
610 610
 				break;
611 611
 
612 612
 			case 'vat_class' :
613
-				echo getpaid_get_tax_class_label( $item->get_vat_class() );
613
+				echo getpaid_get_tax_class_label($item->get_vat_class());
614 614
 				break;
615 615
 
616 616
 			case 'shortcode' :
617 617
 
618
-				if ( $item->is_type( array( '', 'fee', 'custom' ) ) ) {
619
-					echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
618
+				if ($item->is_type(array('', 'fee', 'custom'))) {
619
+					echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr($item->get_id()) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
620 620
 				} else {
621 621
 					echo "&mdash;";
622 622
 				}
@@ -624,7 +624,7 @@  discard block
 block discarded – undo
624 624
 				break;
625 625
 
626 626
 			case 'type' :
627
-				echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
627
+				echo wpinv_item_type($item->get_id()) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
628 628
 				break;
629 629
 
630 630
 		}
@@ -634,21 +634,21 @@  discard block
 block discarded – undo
634 634
 	/**
635 635
 	 * Lets users filter items using taxes.
636 636
 	 */
637
-	public static function add_item_filters( $post_type ) {
637
+	public static function add_item_filters($post_type) {
638 638
 
639 639
 		// Abort if we're not dealing with items.
640
-		if ( $post_type != 'wpi_item' ) {
640
+		if ($post_type != 'wpi_item') {
641 641
 			return;
642 642
 		}
643 643
 
644 644
 		// Filter by vat rules.
645
-		if ( wpinv_use_taxes() ) {
645
+		if (wpinv_use_taxes()) {
646 646
 	
647 647
 			// Sanitize selected vat rule.
648 648
 			$vat_rule   = '';
649 649
 			$vat_rules  = getpaid_get_tax_rules();
650
-			if ( isset( $_GET['vat_rule'] ) ) {
651
-				$vat_rule   =  sanitize_text_field( $_GET['vat_rule'] );
650
+			if (isset($_GET['vat_rule'])) {
651
+				$vat_rule = sanitize_text_field($_GET['vat_rule']);
652 652
 			}
653 653
 
654 654
 			// Filter by VAT rule.
@@ -656,13 +656,13 @@  discard block
 block discarded – undo
656 656
 				array(
657 657
 					'options'          => array_merge(
658 658
 						array(
659
-							'' => __( 'All VAT rules', 'invoicing' )
659
+							'' => __('All VAT rules', 'invoicing')
660 660
 						),
661 661
 						$vat_rules
662 662
 					),
663 663
 					'name'             => 'vat_rule',
664 664
 					'id'               => 'vat_rule',
665
-					'selected'         => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '',
665
+					'selected'         => in_array($vat_rule, array_keys($vat_rules)) ? $vat_rule : '',
666 666
 					'show_option_all'  => false,
667 667
 					'show_option_none' => false,
668 668
 				)
@@ -673,21 +673,21 @@  discard block
 block discarded – undo
673 673
 			// Sanitize selected vat rule.
674 674
 			$vat_class   = '';
675 675
 			$vat_classes = getpaid_get_tax_classes();
676
-			if ( isset( $_GET['vat_class'] ) ) {
677
-				$vat_class   = sanitize_text_field( $_GET['vat_class'] );
676
+			if (isset($_GET['vat_class'])) {
677
+				$vat_class = sanitize_text_field($_GET['vat_class']);
678 678
 			}
679 679
 
680 680
 			echo wpinv_html_select(
681 681
 				array(
682 682
 					'options'          => array_merge(
683 683
 						array(
684
-							'' => __( 'All VAT classes', 'invoicing' )
684
+							'' => __('All VAT classes', 'invoicing')
685 685
 						),
686 686
 						$vat_classes
687 687
 					),
688 688
 					'name'             => 'vat_class',
689 689
 					'id'               => 'vat_class',
690
-					'selected'         => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '',
690
+					'selected'         => in_array($vat_class, array_keys($vat_classes)) ? $vat_class : '',
691 691
 					'show_option_all'  => false,
692 692
 					'show_option_none' => false,
693 693
 				)
@@ -696,22 +696,22 @@  discard block
 block discarded – undo
696 696
 		}
697 697
 
698 698
 		// Filter by item type.
699
-		$type   = '';
700
-		if ( isset( $_GET['type'] ) ) {
701
-			$type   = sanitize_text_field( $_GET['type'] );
699
+		$type = '';
700
+		if (isset($_GET['type'])) {
701
+			$type = sanitize_text_field($_GET['type']);
702 702
 		}
703 703
 
704 704
 		echo wpinv_html_select(
705 705
 			array(
706 706
 				'options'          => array_merge(
707 707
 					array(
708
-						'' => __( 'All item types', 'invoicing' )
708
+						'' => __('All item types', 'invoicing')
709 709
 					),
710 710
 					wpinv_get_item_types()
711 711
 				),
712 712
 				'name'             => 'type',
713 713
 				'id'               => 'type',
714
-				'selected'         => in_array( $type, wpinv_item_types() ) ? $type : '',
714
+				'selected'         => in_array($type, wpinv_item_types()) ? $type : '',
715 715
 				'show_option_all'  => false,
716 716
 				'show_option_none' => false,
717 717
 			)
@@ -722,45 +722,45 @@  discard block
 block discarded – undo
722 722
 	/**
723 723
 	 * Filters the item query.
724 724
 	 */
725
-	public static function filter_item_query( $query ) {
725
+	public static function filter_item_query($query) {
726 726
 
727 727
 		// modify the query only if it admin and main query.
728
-		if ( ! ( is_admin() && $query->is_main_query() ) ){ 
728
+		if (!(is_admin() && $query->is_main_query())) { 
729 729
 			return $query;
730 730
 		}
731 731
 
732 732
 		// we want to modify the query for our items.
733
-		if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){
733
+		if (empty($query->query['post_type']) || 'wpi_item' != $query->query['post_type']) {
734 734
 			return $query;
735 735
 		}
736 736
 
737
-		if ( empty( $query->query_vars['meta_query'] ) ) {
737
+		if (empty($query->query_vars['meta_query'])) {
738 738
 			$query->query_vars['meta_query'] = array();
739 739
 		}
740 740
 
741 741
 		// Filter vat rule type
742
-        if ( ! empty( $_GET['vat_rule'] ) ) {
742
+        if (!empty($_GET['vat_rule'])) {
743 743
             $query->query_vars['meta_query'][] = array(
744 744
                 'key'     => '_wpinv_vat_rule',
745
-                'value'   => sanitize_text_field( $_GET['vat_rule'] ),
745
+                'value'   => sanitize_text_field($_GET['vat_rule']),
746 746
                 'compare' => '='
747 747
             );
748 748
         }
749 749
 
750 750
         // Filter vat class
751
-        if ( ! empty( $_GET['vat_class'] ) ) {
751
+        if (!empty($_GET['vat_class'])) {
752 752
             $query->query_vars['meta_query'][] = array(
753 753
                 'key'     => '_wpinv_vat_class',
754
-                'value'   => sanitize_text_field( $_GET['vat_class'] ),
754
+                'value'   => sanitize_text_field($_GET['vat_class']),
755 755
                 'compare' => '='
756 756
             );
757 757
         }
758 758
 
759 759
         // Filter item type
760
-        if ( ! empty( $_GET['type'] ) ) {
760
+        if (!empty($_GET['type'])) {
761 761
             $query->query_vars['meta_query'][] = array(
762 762
                 'key'     => '_wpinv_type',
763
-                'value'   => sanitize_text_field( $_GET['type'] ),
763
+                'value'   => sanitize_text_field($_GET['type']),
764 764
                 'compare' => '='
765 765
             );
766 766
 		}
@@ -770,15 +770,15 @@  discard block
 block discarded – undo
770 770
 	/**
771 771
 	 * Reorders items.
772 772
 	 */
773
-	public static function reorder_items( $vars ) {
773
+	public static function reorder_items($vars) {
774 774
 		global $typenow;
775 775
 
776
-		if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
776
+		if ('wpi_item' !== $typenow || empty($vars['orderby'])) {
777 777
 			return $vars;
778 778
 		}
779 779
 
780 780
 		// By item type.
781
-		if ( 'type' == $vars['orderby'] ) {
781
+		if ('type' == $vars['orderby']) {
782 782
 			return array_merge(
783 783
 				$vars,
784 784
 				array(
@@ -789,7 +789,7 @@  discard block
 block discarded – undo
789 789
 		}
790 790
 
791 791
 		// By vat class.
792
-		if ( 'vat_class' == $vars['orderby'] ) {
792
+		if ('vat_class' == $vars['orderby']) {
793 793
 			return array_merge(
794 794
 				$vars,
795 795
 				array(
@@ -800,7 +800,7 @@  discard block
 block discarded – undo
800 800
 		}
801 801
 
802 802
 		// By vat rule.
803
-		if ( 'vat_rule' == $vars['orderby'] ) {
803
+		if ('vat_rule' == $vars['orderby']) {
804 804
 			return array_merge(
805 805
 				$vars,
806 806
 				array(
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
 		}
812 812
 
813 813
 		// By price.
814
-		if ( 'price' == $vars['orderby'] ) {
814
+		if ('price' == $vars['orderby']) {
815 815
 			return array_merge(
816 816
 				$vars,
817 817
 				array(
@@ -828,27 +828,27 @@  discard block
 block discarded – undo
828 828
 	/**
829 829
 	 * Fired when deleting a post.
830 830
 	 */
831
-	public static function delete_post( $post_id ) {
831
+	public static function delete_post($post_id) {
832 832
 
833
-		switch ( get_post_type( $post_id ) ) {
833
+		switch (get_post_type($post_id)) {
834 834
 
835 835
 			case 'wpi_item' :
836
-				do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
836
+				do_action("getpaid_before_delete_item", new WPInv_Item($post_id));
837 837
 				break;
838 838
 
839 839
 			case 'wpi_payment_form' :
840
-				do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
840
+				do_action("getpaid_before_delete_payment_form", new GetPaid_Payment_Form($post_id));
841 841
 				break;
842 842
 
843 843
 			case 'wpi_discount' :
844
-				do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
844
+				do_action("getpaid_before_delete_discount", new WPInv_Discount($post_id));
845 845
 				break;
846 846
 
847 847
 			case 'wpi_invoice' :
848
-				$invoice = new WPInv_Invoice( $post_id );
849
-				do_action( "getpaid_before_delete_invoice", $invoice );
850
-				$invoice->get_data_store()->delete_items( $invoice );
851
-				$invoice->get_data_store()->delete_special_fields( $invoice );
848
+				$invoice = new WPInv_Invoice($post_id);
849
+				do_action("getpaid_before_delete_invoice", $invoice);
850
+				$invoice->get_data_store()->delete_items($invoice);
851
+				$invoice->get_data_store()->delete_special_fields($invoice);
852 852
 				break;
853 853
 		}
854 854
 	}
@@ -861,29 +861,29 @@  discard block
 block discarded – undo
861 861
      *
862 862
      * @return mixed
863 863
      */
864
-    public static function add_display_post_states( $post_states, $post ) {
864
+    public static function add_display_post_states($post_states, $post) {
865 865
 
866
-        if ( wpinv_get_option( 'success_page', 0 ) == $post->ID ) {
867
-            $post_states['getpaid_success_page'] = __( 'GetPaid Receipt Page', 'invoicing' );
866
+        if (wpinv_get_option('success_page', 0) == $post->ID) {
867
+            $post_states['getpaid_success_page'] = __('GetPaid Receipt Page', 'invoicing');
868 868
         }
869 869
 
870
-		foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) {
870
+		foreach (getpaid_get_invoice_post_types() as $post_type => $label) {
871 871
 
872
-			if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) {
872
+			if (wpinv_get_option("{$post_type}_history_page", 0) == $post->ID) {
873 873
 				$post_states["getpaid_{$post_type}_history_page"] = sprintf(
874
-					__( 'GetPaid %s History Page', 'invoicing' ),
874
+					__('GetPaid %s History Page', 'invoicing'),
875 875
 					$label
876 876
 				);
877 877
 			}
878 878
 
879 879
 		}
880 880
 		
881
-		if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) {
882
-            $post_states['getpaid_invoice_subscription_page'] = __( 'GetPaid Subscription Page', 'invoicing' );
881
+		if (wpinv_get_option('invoice_subscription_page', 0) == $post->ID) {
882
+            $post_states['getpaid_invoice_subscription_page'] = __('GetPaid Subscription Page', 'invoicing');
883 883
         }
884 884
 
885
-		if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) {
886
-            $post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' );
885
+		if (wpinv_get_option('checkout_page', 0) == $post->ID) {
886
+            $post_states['getpaid_checkout_page'] = __('GetPaid Checkout Page', 'invoicing');
887 887
         }
888 888
 
889 889
         return $post_states;
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission.php 2 patches
Indentation   +859 added lines, -859 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,200 +10,200 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Payment_Form_Submission {
11 11
 
12 12
     /**
13
-	 * Submission ID
14
-	 *
15
-	 * @var string
16
-	 */
17
-	public $id = null;
18
-
19
-	/**
20
-	 * The raw submission data.
21
-	 *
22
-	 * @var array
23
-	 */
24
-	protected $data = null;
25
-
26
-	/**
27
-	 * Submission totals
28
-	 *
29
-	 * @var array
30
-	 */
31
-	protected $totals = array(
32
-
33
-		'subtotal'      => array(
34
-			'initial'   => 0,
35
-			'recurring' => 0,
36
-		),
37
-
38
-		'discount'      => array(
39
-			'initial'   => 0,
40
-			'recurring' => 0,
41
-		),
42
-
43
-		'fees'          => array(
44
-			'initial'   => 0,
45
-			'recurring' => 0,
46
-		),
47
-
48
-		'taxes'         => array(
49
-			'initial'   => 0,
50
-			'recurring' => 0,
51
-		),
52
-
53
-		'shipping'         => array(
54
-			'initial'   => 0,
55
-			'recurring' => 0,
56
-		),
57
-
58
-	);
59
-
60
-	/**
61
-	 * Sets the associated payment form.
62
-	 *
63
-	 * @var GetPaid_Payment_Form
64
-	 */
13
+     * Submission ID
14
+     *
15
+     * @var string
16
+     */
17
+    public $id = null;
18
+
19
+    /**
20
+     * The raw submission data.
21
+     *
22
+     * @var array
23
+     */
24
+    protected $data = null;
25
+
26
+    /**
27
+     * Submission totals
28
+     *
29
+     * @var array
30
+     */
31
+    protected $totals = array(
32
+
33
+        'subtotal'      => array(
34
+            'initial'   => 0,
35
+            'recurring' => 0,
36
+        ),
37
+
38
+        'discount'      => array(
39
+            'initial'   => 0,
40
+            'recurring' => 0,
41
+        ),
42
+
43
+        'fees'          => array(
44
+            'initial'   => 0,
45
+            'recurring' => 0,
46
+        ),
47
+
48
+        'taxes'         => array(
49
+            'initial'   => 0,
50
+            'recurring' => 0,
51
+        ),
52
+
53
+        'shipping'         => array(
54
+            'initial'   => 0,
55
+            'recurring' => 0,
56
+        ),
57
+
58
+    );
59
+
60
+    /**
61
+     * Sets the associated payment form.
62
+     *
63
+     * @var GetPaid_Payment_Form
64
+     */
65 65
     protected $payment_form = null;
66 66
 
67 67
     /**
68
-	 * The country for the submission.
69
-	 *
70
-	 * @var string
71
-	 */
72
-	public $country = null;
73
-
74
-    /**
75
-	 * The state for the submission.
76
-	 *
77
-	 * @since 1.0.19
78
-	 * @var string
79
-	 */
80
-	public $state = null;
81
-
82
-	/**
83
-	 * The invoice associated with the submission.
84
-	 *
85
-	 * @var WPInv_Invoice
86
-	 */
87
-	protected $invoice = null;
88
-
89
-	/**
90
-	 * The recurring item for the submission.
91
-	 *
92
-	 * @var int
93
-	 */
94
-	public $has_recurring = 0;
95
-
96
-	/**
97
-	 * An array of fees for the submission.
98
-	 *
99
-	 * @var array
100
-	 */
101
-	protected $fees = array();
102
-
103
-	/**
104
-	 * An array of discounts for the submission.
105
-	 *
106
-	 * @var array
107
-	 */
108
-	protected $discounts = array();
109
-
110
-	/**
111
-	 * An array of taxes for the submission.
112
-	 *
113
-	 * @var array
114
-	 */
115
-	protected $taxes = array();
116
-
117
-	/**
118
-	 * An array of items for the submission.
119
-	 *
120
-	 * @var GetPaid_Form_Item[]
121
-	 */
122
-	protected $items = array();
123
-
124
-	/**
125
-	 * The last error.
126
-	 *
127
-	 * @var string
128
-	 */
129
-	public $last_error = null;
130
-
131
-	/**
132
-	 * The last error code.
133
-	 *
134
-	 * @var string
135
-	 */
136
-	public $last_error_code = null;
137
-
138
-    /**
139
-	 * Class constructor.
140
-	 *
141
-	 */
142
-	public function __construct() {
143
-
144
-		// Set the state and country to the default state and country.
145
-		$this->country = wpinv_default_billing_country();
146
-		$this->state   = wpinv_get_default_state();
147
-
148
-		// Do we have an actual submission?
149
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
150
-			$this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) );
151
-		}
152
-
153
-	}
154
-
155
-	/**
156
-	 * Loads submission data.
157
-	 *
158
-	 * @param array $data
159
-	 */
160
-	public function load_data( $data ) {
161
-
162
-		// Allow plugins to filter the data.
163
-		$data       = apply_filters( 'getpaid_submission_data', $data, $this );
164
-
165
-		// Cache it...
166
-		$this->data = $data;
167
-
168
-		// Then generate a unique id from the data.
169
-		$this->id   = md5( wp_json_encode( $data ) );
170
-
171
-		// Finally, process the submission.
172
-		try {
173
-
174
-			// Each process is passed an instance of the class (with reference)
175
-			// and should throw an Exception whenever it encounters one.
176
-			$processors = apply_filters(
177
-				'getpaid_payment_form_submission_processors',
178
-				array(
179
-					array( $this, 'process_payment_form' ),
180
-					array( $this, 'process_invoice' ),
181
-					array( $this, 'process_fees' ),
182
-					array( $this, 'process_items' ),
183
-					array( $this, 'process_discount' ),
184
-					array( $this, 'process_taxes' ),
185
-				),
186
-				$this		
187
-			);
188
-
189
-			foreach ( $processors as $processor ) {
190
-				call_user_func_array( $processor, array( &$this ) );
191
-			}
192
-
193
-		} catch( GetPaid_Payment_Exception $e ) {
194
-			$this->last_error      = $e->getMessage();
195
-			$this->last_error_code = $e->getErrorCode();
196
-		} catch ( Exception $e ) {
197
-			$this->last_error      = $e->getMessage();
198
-			$this->last_error_code = $e->getCode();
199
-		}
200
-
201
-		// Fired when we are done processing a submission.
202
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
203
-
204
-	}
205
-
206
-	/*
68
+     * The country for the submission.
69
+     *
70
+     * @var string
71
+     */
72
+    public $country = null;
73
+
74
+    /**
75
+     * The state for the submission.
76
+     *
77
+     * @since 1.0.19
78
+     * @var string
79
+     */
80
+    public $state = null;
81
+
82
+    /**
83
+     * The invoice associated with the submission.
84
+     *
85
+     * @var WPInv_Invoice
86
+     */
87
+    protected $invoice = null;
88
+
89
+    /**
90
+     * The recurring item for the submission.
91
+     *
92
+     * @var int
93
+     */
94
+    public $has_recurring = 0;
95
+
96
+    /**
97
+     * An array of fees for the submission.
98
+     *
99
+     * @var array
100
+     */
101
+    protected $fees = array();
102
+
103
+    /**
104
+     * An array of discounts for the submission.
105
+     *
106
+     * @var array
107
+     */
108
+    protected $discounts = array();
109
+
110
+    /**
111
+     * An array of taxes for the submission.
112
+     *
113
+     * @var array
114
+     */
115
+    protected $taxes = array();
116
+
117
+    /**
118
+     * An array of items for the submission.
119
+     *
120
+     * @var GetPaid_Form_Item[]
121
+     */
122
+    protected $items = array();
123
+
124
+    /**
125
+     * The last error.
126
+     *
127
+     * @var string
128
+     */
129
+    public $last_error = null;
130
+
131
+    /**
132
+     * The last error code.
133
+     *
134
+     * @var string
135
+     */
136
+    public $last_error_code = null;
137
+
138
+    /**
139
+     * Class constructor.
140
+     *
141
+     */
142
+    public function __construct() {
143
+
144
+        // Set the state and country to the default state and country.
145
+        $this->country = wpinv_default_billing_country();
146
+        $this->state   = wpinv_get_default_state();
147
+
148
+        // Do we have an actual submission?
149
+        if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
150
+            $this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) );
151
+        }
152
+
153
+    }
154
+
155
+    /**
156
+     * Loads submission data.
157
+     *
158
+     * @param array $data
159
+     */
160
+    public function load_data( $data ) {
161
+
162
+        // Allow plugins to filter the data.
163
+        $data       = apply_filters( 'getpaid_submission_data', $data, $this );
164
+
165
+        // Cache it...
166
+        $this->data = $data;
167
+
168
+        // Then generate a unique id from the data.
169
+        $this->id   = md5( wp_json_encode( $data ) );
170
+
171
+        // Finally, process the submission.
172
+        try {
173
+
174
+            // Each process is passed an instance of the class (with reference)
175
+            // and should throw an Exception whenever it encounters one.
176
+            $processors = apply_filters(
177
+                'getpaid_payment_form_submission_processors',
178
+                array(
179
+                    array( $this, 'process_payment_form' ),
180
+                    array( $this, 'process_invoice' ),
181
+                    array( $this, 'process_fees' ),
182
+                    array( $this, 'process_items' ),
183
+                    array( $this, 'process_discount' ),
184
+                    array( $this, 'process_taxes' ),
185
+                ),
186
+                $this		
187
+            );
188
+
189
+            foreach ( $processors as $processor ) {
190
+                call_user_func_array( $processor, array( &$this ) );
191
+            }
192
+
193
+        } catch( GetPaid_Payment_Exception $e ) {
194
+            $this->last_error      = $e->getMessage();
195
+            $this->last_error_code = $e->getErrorCode();
196
+        } catch ( Exception $e ) {
197
+            $this->last_error      = $e->getMessage();
198
+            $this->last_error_code = $e->getCode();
199
+        }
200
+
201
+        // Fired when we are done processing a submission.
202
+        do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
203
+
204
+    }
205
+
206
+    /*
207 207
 	|--------------------------------------------------------------------------
208 208
 	| Payment Forms.
209 209
 	|--------------------------------------------------------------------------
@@ -212,39 +212,39 @@  discard block
 block discarded – undo
212 212
 	| submission has an active payment form etc.
213 213
     */
214 214
 
215
-	/**
216
-	 * Prepares the submission's payment form.
217
-	 *
218
-	 * @since 1.0.19
219
-	 */
220
-	public function process_payment_form() {
215
+    /**
216
+     * Prepares the submission's payment form.
217
+     *
218
+     * @since 1.0.19
219
+     */
220
+    public function process_payment_form() {
221 221
 
222
-		// Every submission needs an active payment form.
223
-		if ( empty( $this->data['form_id'] ) ) {
224
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
225
-		}
222
+        // Every submission needs an active payment form.
223
+        if ( empty( $this->data['form_id'] ) ) {
224
+            throw new Exception( __( 'Missing payment form', 'invoicing' ) );
225
+        }
226 226
 
227
-		// Fetch the payment form.
228
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
227
+        // Fetch the payment form.
228
+        $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
229 229
 
230
-		if ( ! $this->payment_form->is_active() ) {
231
-			throw new Exception( __( 'Payment form not active', 'invoicing' ) );
232
-		}
230
+        if ( ! $this->payment_form->is_active() ) {
231
+            throw new Exception( __( 'Payment form not active', 'invoicing' ) );
232
+        }
233 233
 
234
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
235
-	}
234
+        do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
235
+    }
236 236
 
237 237
     /**
238
-	 * Returns the payment form.
239
-	 *
240
-	 * @since 1.0.19
241
-	 * @return GetPaid_Payment_Form
242
-	 */
243
-	public function get_payment_form() {
244
-		return $this->payment_form;
245
-	}
238
+     * Returns the payment form.
239
+     *
240
+     * @since 1.0.19
241
+     * @return GetPaid_Payment_Form
242
+     */
243
+    public function get_payment_form() {
244
+        return $this->payment_form;
245
+    }
246 246
 
247
-	/*
247
+    /*
248 248
 	|--------------------------------------------------------------------------
249 249
 	| Invoices.
250 250
 	|--------------------------------------------------------------------------
@@ -253,84 +253,84 @@  discard block
 block discarded – undo
253 253
 	| might be for an existing invoice.
254 254
 	*/
255 255
 
256
-	/**
257
-	 * Prepares the submission's invoice.
258
-	 *
259
-	 * @since 1.0.19
260
-	 */
261
-	public function process_invoice() {
256
+    /**
257
+     * Prepares the submission's invoice.
258
+     *
259
+     * @since 1.0.19
260
+     */
261
+    public function process_invoice() {
262 262
 
263
-		// Abort if there is no invoice.
264
-		if ( empty( $this->data['invoice_id'] ) ) {
265
-			return;
266
-		}
263
+        // Abort if there is no invoice.
264
+        if ( empty( $this->data['invoice_id'] ) ) {
265
+            return;
266
+        }
267 267
 
268
-		// If the submission is for an existing invoice, ensure that it exists
269
-		// and that it is not paid for.
270
-		$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
268
+        // If the submission is for an existing invoice, ensure that it exists
269
+        // and that it is not paid for.
270
+        $invoice = wpinv_get_invoice( $this->data['invoice_id'] );
271 271
 
272 272
         if ( empty( $invoice ) ) {
273
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
274
-		}
273
+            throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
274
+        }
275 275
 
276
-		if ( $invoice->is_paid() ) {
277
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
278
-		}
276
+        if ( $invoice->is_paid() ) {
277
+            throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
278
+        }
279 279
 
280
-		$this->payment_form->invoice = $invoice;
281
-		if ( ! $this->payment_form->is_default() ) {
280
+        $this->payment_form->invoice = $invoice;
281
+        if ( ! $this->payment_form->is_default() ) {
282 282
 
283
-			$items    = array();
284
-			$item_ids = array();
283
+            $items    = array();
284
+            $item_ids = array();
285 285
 	
286
-			foreach ( $invoice->get_items() as $item ) {
287
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
288
-					$item_ids[] = $item->get_id();
289
-					$items[]    = $item;
290
-				}
291
-			}
286
+            foreach ( $invoice->get_items() as $item ) {
287
+                if ( ! in_array( $item->get_id(), $item_ids ) ) {
288
+                    $item_ids[] = $item->get_id();
289
+                    $items[]    = $item;
290
+                }
291
+            }
292 292
 	
293
-			foreach ( $this->payment_form->get_items() as $item ) {
294
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
295
-					$item_ids[] = $item->get_id();
296
-					$items[]    = $item;
297
-				}
298
-			}
293
+            foreach ( $this->payment_form->get_items() as $item ) {
294
+                if ( ! in_array( $item->get_id(), $item_ids ) ) {
295
+                    $item_ids[] = $item->get_id();
296
+                    $items[]    = $item;
297
+                }
298
+            }
299 299
 	
300
-			$this->payment_form->set_items( $items );
300
+            $this->payment_form->set_items( $items );
301 301
 	
302
-		} else {
303
-			$this->payment_form->set_items( $invoice->get_items() );
304
-		}
305
-
306
-		$this->country = $invoice->get_country();
307
-		$this->state   = $invoice->get_state();
308
-		$this->invoice = $invoice;
309
-
310
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
311
-	}
312
-
313
-	/**
314
-	 * Returns the associated invoice.
315
-	 *
316
-	 * @since 1.0.19
317
-	 * @return WPInv_Invoice
318
-	 */
319
-	public function get_invoice() {
320
-		return $this->invoice;
321
-	}
322
-
323
-	/**
324
-	 * Checks whether there is an invoice associated with this submission.
325
-	 *
326
-	 * @since 1.0.19
327
-	 * @return bool
328
-	 */
329
-	public function has_invoice() {
330
-		return ! empty( $this->invoice );
331
-	}
332
-
333
-	/*
302
+        } else {
303
+            $this->payment_form->set_items( $invoice->get_items() );
304
+        }
305
+
306
+        $this->country = $invoice->get_country();
307
+        $this->state   = $invoice->get_state();
308
+        $this->invoice = $invoice;
309
+
310
+        do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
311
+    }
312
+
313
+    /**
314
+     * Returns the associated invoice.
315
+     *
316
+     * @since 1.0.19
317
+     * @return WPInv_Invoice
318
+     */
319
+    public function get_invoice() {
320
+        return $this->invoice;
321
+    }
322
+
323
+    /**
324
+     * Checks whether there is an invoice associated with this submission.
325
+     *
326
+     * @since 1.0.19
327
+     * @return bool
328
+     */
329
+    public function has_invoice() {
330
+        return ! empty( $this->invoice );
331
+    }
332
+
333
+    /*
334 334
 	|--------------------------------------------------------------------------
335 335
 	| Items.
336 336
 	|--------------------------------------------------------------------------
@@ -339,129 +339,129 @@  discard block
 block discarded – undo
339 339
 	| recurring item. But can have an unlimited number of non-recurring items.
340 340
 	*/
341 341
 
342
-	/**
343
-	 * Prepares the submission's items.
344
-	 *
345
-	 * @since 1.0.19
346
-	 */
347
-	public function process_items() {
348
-
349
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
350
-
351
-		foreach ( $processor->items as $item ) {
352
-			$this->add_item( $item );
353
-		}
354
-
355
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
356
-	}
357
-
358
-	/**
359
-	 * Adds an item to the submission.
360
-	 *
361
-	 * @since 1.0.19
362
-	 * @param GetPaid_Form_Item $item
363
-	 */
364
-	public function add_item( $item ) {
365
-
366
-		// Make sure that it is available for purchase.
367
-		if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
368
-			return;
369
-		}
370
-
371
-		// Each submission can only contain one recurring item.
372
-		if ( $item->is_recurring() ) {
373
-			$this->has_recurring = $item->get_id();
374
-		}
375
-
376
-		// Update the items and totals.
377
-		$this->items[ $item->get_id() ]         = $item;
378
-		$this->totals['subtotal']['initial']   += $item->get_sub_total();
379
-		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
380
-
381
-	}
382
-
383
-	/**
384
-	 * Removes a specific item.
385
-	 * 
386
-	 * You should not call this method after the discounts and taxes
387
-	 * have been calculated.
388
-	 *
389
-	 * @since 1.0.19
390
-	 */
391
-	public function remove_item( $item_id ) {
392
-
393
-		if ( isset( $this->items[ $item_id ] ) ) {
394
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
395
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
396
-
397
-			if ( $this->items[ $item_id ]->is_recurring() ) {
398
-				$this->has_recurring = 0;
399
-			}
400
-
401
-			unset( $this->items[ $item_id ] );
402
-		}
403
-
404
-	}
405
-
406
-	/**
407
-	 * Returns the subtotal.
408
-	 *
409
-	 * @since 1.0.19
410
-	 */
411
-	public function get_subtotal() {
412
-
413
-		if ( wpinv_prices_include_tax() ) {
414
-			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
415
-		}
416
-
417
-		return $this->totals['subtotal']['initial'];
418
-	}
419
-
420
-	/**
421
-	 * Returns the recurring subtotal.
422
-	 *
423
-	 * @since 1.0.19
424
-	 */
425
-	public function get_recurring_subtotal() {
426
-
427
-		if ( wpinv_prices_include_tax() ) {
428
-			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
429
-		}
430
-
431
-		return $this->totals['subtotal']['recurring'];
432
-	}
433
-
434
-	/**
435
-	 * Returns all items.
436
-	 *
437
-	 * @since 1.0.19
438
-	 * @return GetPaid_Form_Item[]
439
-	 */
440
-	public function get_items() {
441
-		return $this->items;
442
-	}
443
-
444
-	/**
445
-	 * Checks if there's a single subscription group in the submission.
446
-	 *
447
-	 * @since 2.3.0
448
-	 * @return bool
449
-	 */
450
-	public function has_subscription_group() {
451
-		return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) );
452
-	}
453
-
454
-	/**
455
-	 * Checks if there are multipe subscription groups in the submission.
456
-	 *
457
-	 * @since 2.3.0
458
-	 * @return bool
459
-	 */
460
-	public function has_multiple_subscription_groups() {
461
-		return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) );
462
-	}
463
-
464
-	/*
342
+    /**
343
+     * Prepares the submission's items.
344
+     *
345
+     * @since 1.0.19
346
+     */
347
+    public function process_items() {
348
+
349
+        $processor = new GetPaid_Payment_Form_Submission_Items( $this );
350
+
351
+        foreach ( $processor->items as $item ) {
352
+            $this->add_item( $item );
353
+        }
354
+
355
+        do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
356
+    }
357
+
358
+    /**
359
+     * Adds an item to the submission.
360
+     *
361
+     * @since 1.0.19
362
+     * @param GetPaid_Form_Item $item
363
+     */
364
+    public function add_item( $item ) {
365
+
366
+        // Make sure that it is available for purchase.
367
+        if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
368
+            return;
369
+        }
370
+
371
+        // Each submission can only contain one recurring item.
372
+        if ( $item->is_recurring() ) {
373
+            $this->has_recurring = $item->get_id();
374
+        }
375
+
376
+        // Update the items and totals.
377
+        $this->items[ $item->get_id() ]         = $item;
378
+        $this->totals['subtotal']['initial']   += $item->get_sub_total();
379
+        $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
380
+
381
+    }
382
+
383
+    /**
384
+     * Removes a specific item.
385
+     * 
386
+     * You should not call this method after the discounts and taxes
387
+     * have been calculated.
388
+     *
389
+     * @since 1.0.19
390
+     */
391
+    public function remove_item( $item_id ) {
392
+
393
+        if ( isset( $this->items[ $item_id ] ) ) {
394
+            $this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
395
+            $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
396
+
397
+            if ( $this->items[ $item_id ]->is_recurring() ) {
398
+                $this->has_recurring = 0;
399
+            }
400
+
401
+            unset( $this->items[ $item_id ] );
402
+        }
403
+
404
+    }
405
+
406
+    /**
407
+     * Returns the subtotal.
408
+     *
409
+     * @since 1.0.19
410
+     */
411
+    public function get_subtotal() {
412
+
413
+        if ( wpinv_prices_include_tax() ) {
414
+            return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
415
+        }
416
+
417
+        return $this->totals['subtotal']['initial'];
418
+    }
419
+
420
+    /**
421
+     * Returns the recurring subtotal.
422
+     *
423
+     * @since 1.0.19
424
+     */
425
+    public function get_recurring_subtotal() {
426
+
427
+        if ( wpinv_prices_include_tax() ) {
428
+            return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
429
+        }
430
+
431
+        return $this->totals['subtotal']['recurring'];
432
+    }
433
+
434
+    /**
435
+     * Returns all items.
436
+     *
437
+     * @since 1.0.19
438
+     * @return GetPaid_Form_Item[]
439
+     */
440
+    public function get_items() {
441
+        return $this->items;
442
+    }
443
+
444
+    /**
445
+     * Checks if there's a single subscription group in the submission.
446
+     *
447
+     * @since 2.3.0
448
+     * @return bool
449
+     */
450
+    public function has_subscription_group() {
451
+        return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) );
452
+    }
453
+
454
+    /**
455
+     * Checks if there are multipe subscription groups in the submission.
456
+     *
457
+     * @since 2.3.0
458
+     * @return bool
459
+     */
460
+    public function has_multiple_subscription_groups() {
461
+        return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) );
462
+    }
463
+
464
+    /*
465 465
 	|--------------------------------------------------------------------------
466 466
 	| Taxes
467 467
 	|--------------------------------------------------------------------------
@@ -470,128 +470,128 @@  discard block
 block discarded – undo
470 470
 	| or only one-time.
471 471
     */
472 472
 
473
-	/**
474
-	 * Prepares the submission's taxes.
475
-	 *
476
-	 * @since 1.0.19
477
-	 */
478
-	public function process_taxes() {
479
-
480
-		// Abort if we're not using taxes.
481
-		if ( ! $this->use_taxes() ) {
482
-			return;
483
-		}
484
-
485
-		// If a custom country && state has been passed in, use it to calculate taxes.
486
-		$country = $this->get_field( 'wpinv_country', 'billing' );
487
-		if ( ! empty( $country ) ) {
488
-			$this->country = $country;
489
-		}
490
-
491
-		$state = $this->get_field( 'wpinv_state', 'billing' );
492
-		if ( ! empty( $state ) ) {
493
-			$this->state = $state;
494
-		}
495
-
496
-		// Confirm if the provided country and the ip country are similar.
497
-		$address_confirmed = $this->get_field( 'confirm-address' );
498
-		if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
499
-			throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
500
-		}
501
-
502
-		// Abort if the country is not taxable.
503
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
504
-			return;
505
-		}
506
-
507
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
508
-
509
-		foreach ( $processor->taxes as $tax ) {
510
-			$this->add_tax( $tax );
511
-		}
512
-
513
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
514
-	}
515
-
516
-	/**
517
-	 * Adds a tax to the submission.
518
-	 *
519
-	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
520
-	 * @since 1.0.19
521
-	 */
522
-	public function add_tax( $tax ) {
523
-
524
-		if ( wpinv_round_tax_per_tax_rate() ) {
525
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
526
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
527
-		}
528
-
529
-		$this->taxes[ $tax['name'] ]         = $tax;
530
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
531
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
532
-
533
-	}
534
-
535
-	/**
536
-	 * Removes a specific tax.
537
-	 *
538
-	 * @since 1.0.19
539
-	 */
540
-	public function remove_tax( $tax_name ) {
541
-
542
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
543
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
544
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
545
-			unset( $this->taxes[ $tax_name ] );
546
-		}
547
-
548
-	}
549
-
550
-	/**
551
-	 * Whether or not we'll use taxes for the submission.
552
-	 *
553
-	 * @since 1.0.19
554
-	 */
555
-	public function use_taxes() {
556
-
557
-		$use_taxes = wpinv_use_taxes();
558
-
559
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
560
-			$use_taxes = false;
561
-		}
562
-
563
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
564
-
565
-	}
566
-
567
-	/**
568
-	 * Returns the tax.
569
-	 *
570
-	 * @since 1.0.19
571
-	 */
572
-	public function get_tax() {
573
-		return $this->totals['taxes']['initial'];
574
-	}
575
-
576
-	/**
577
-	 * Returns the recurring tax.
578
-	 *
579
-	 * @since 1.0.19
580
-	 */
581
-	public function get_recurring_tax() {
582
-		return $this->totals['taxes']['recurring'];
583
-	}
584
-
585
-	/**
586
-	 * Returns all taxes.
587
-	 *
588
-	 * @since 1.0.19
589
-	 */
590
-	public function get_taxes() {
591
-		return $this->taxes;
592
-	}
593
-
594
-	/*
473
+    /**
474
+     * Prepares the submission's taxes.
475
+     *
476
+     * @since 1.0.19
477
+     */
478
+    public function process_taxes() {
479
+
480
+        // Abort if we're not using taxes.
481
+        if ( ! $this->use_taxes() ) {
482
+            return;
483
+        }
484
+
485
+        // If a custom country && state has been passed in, use it to calculate taxes.
486
+        $country = $this->get_field( 'wpinv_country', 'billing' );
487
+        if ( ! empty( $country ) ) {
488
+            $this->country = $country;
489
+        }
490
+
491
+        $state = $this->get_field( 'wpinv_state', 'billing' );
492
+        if ( ! empty( $state ) ) {
493
+            $this->state = $state;
494
+        }
495
+
496
+        // Confirm if the provided country and the ip country are similar.
497
+        $address_confirmed = $this->get_field( 'confirm-address' );
498
+        if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
499
+            throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
500
+        }
501
+
502
+        // Abort if the country is not taxable.
503
+        if ( ! wpinv_is_country_taxable( $this->country ) ) {
504
+            return;
505
+        }
506
+
507
+        $processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
508
+
509
+        foreach ( $processor->taxes as $tax ) {
510
+            $this->add_tax( $tax );
511
+        }
512
+
513
+        do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
514
+    }
515
+
516
+    /**
517
+     * Adds a tax to the submission.
518
+     *
519
+     * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
520
+     * @since 1.0.19
521
+     */
522
+    public function add_tax( $tax ) {
523
+
524
+        if ( wpinv_round_tax_per_tax_rate() ) {
525
+            $tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
526
+            $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
527
+        }
528
+
529
+        $this->taxes[ $tax['name'] ]         = $tax;
530
+        $this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
531
+        $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
532
+
533
+    }
534
+
535
+    /**
536
+     * Removes a specific tax.
537
+     *
538
+     * @since 1.0.19
539
+     */
540
+    public function remove_tax( $tax_name ) {
541
+
542
+        if ( isset( $this->taxes[ $tax_name ] ) ) {
543
+            $this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
544
+            $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
545
+            unset( $this->taxes[ $tax_name ] );
546
+        }
547
+
548
+    }
549
+
550
+    /**
551
+     * Whether or not we'll use taxes for the submission.
552
+     *
553
+     * @since 1.0.19
554
+     */
555
+    public function use_taxes() {
556
+
557
+        $use_taxes = wpinv_use_taxes();
558
+
559
+        if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
560
+            $use_taxes = false;
561
+        }
562
+
563
+        return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
564
+
565
+    }
566
+
567
+    /**
568
+     * Returns the tax.
569
+     *
570
+     * @since 1.0.19
571
+     */
572
+    public function get_tax() {
573
+        return $this->totals['taxes']['initial'];
574
+    }
575
+
576
+    /**
577
+     * Returns the recurring tax.
578
+     *
579
+     * @since 1.0.19
580
+     */
581
+    public function get_recurring_tax() {
582
+        return $this->totals['taxes']['recurring'];
583
+    }
584
+
585
+    /**
586
+     * Returns all taxes.
587
+     *
588
+     * @since 1.0.19
589
+     */
590
+    public function get_taxes() {
591
+        return $this->taxes;
592
+    }
593
+
594
+    /*
595 595
 	|--------------------------------------------------------------------------
596 596
 	| Discounts
597 597
 	|--------------------------------------------------------------------------
@@ -600,99 +600,99 @@  discard block
 block discarded – undo
600 600
 	| or only one-time. They also do not have to come from a discount code.
601 601
     */
602 602
 
603
-	/**
604
-	 * Prepares the submission's discount.
605
-	 *
606
-	 * @since 1.0.19
607
-	 */
608
-	public function process_discount() {
609
-
610
-		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
611
-		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
612
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
613
-
614
-		foreach ( $processor->discounts as $discount ) {
615
-			$this->add_discount( $discount );
616
-		}
617
-
618
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
619
-	}
620
-
621
-	/**
622
-	 * Adds a discount to the submission.
623
-	 *
624
-	 * @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.
625
-	 * @since 1.0.19
626
-	 */
627
-	public function add_discount( $discount ) {
628
-		$this->discounts[ $discount['name'] ]   = $discount;
629
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
630
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
631
-	}
632
-
633
-	/**
634
-	 * Removes a discount from the submission.
635
-	 *
636
-	 * @since 1.0.19
637
-	 */
638
-	public function remove_discount( $name ) {
639
-
640
-		if ( isset( $this->discounts[ $name ] ) ) {
641
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
642
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
643
-			unset( $this->discounts[ $name ] );
644
-		}
645
-
646
-	}
647
-
648
-	/**
649
-	 * Checks whether there is a discount code associated with this submission.
650
-	 *
651
-	 * @since 1.0.19
652
-	 * @return bool
653
-	 */
654
-	public function has_discount_code() {
655
-		return ! empty( $this->discounts['discount_code'] );
656
-	}
657
-
658
-	/**
659
-	 * Returns the discount code.
660
-	 *
661
-	 * @since 1.0.19
662
-	 * @return string
663
-	 */
664
-	public function get_discount_code() {
665
-		return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
666
-	}
667
-
668
-	/**
669
-	 * Returns the discount.
670
-	 *
671
-	 * @since 1.0.19
672
-	 */
673
-	public function get_discount() {
674
-		return $this->totals['discount']['initial'];
675
-	}
676
-
677
-	/**
678
-	 * Returns the recurring discount.
679
-	 *
680
-	 * @since 1.0.19
681
-	 */
682
-	public function get_recurring_discount() {
683
-		return $this->totals['discount']['recurring'];
684
-	}
685
-
686
-	/**
687
-	 * Returns all discounts.
688
-	 *
689
-	 * @since 1.0.19
690
-	 */
691
-	public function get_discounts() {
692
-		return $this->discounts;
693
-	}
694
-
695
-	/*
603
+    /**
604
+     * Prepares the submission's discount.
605
+     *
606
+     * @since 1.0.19
607
+     */
608
+    public function process_discount() {
609
+
610
+        $initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
611
+        $recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
612
+        $processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
613
+
614
+        foreach ( $processor->discounts as $discount ) {
615
+            $this->add_discount( $discount );
616
+        }
617
+
618
+        do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
619
+    }
620
+
621
+    /**
622
+     * Adds a discount to the submission.
623
+     *
624
+     * @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.
625
+     * @since 1.0.19
626
+     */
627
+    public function add_discount( $discount ) {
628
+        $this->discounts[ $discount['name'] ]   = $discount;
629
+        $this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
630
+        $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
631
+    }
632
+
633
+    /**
634
+     * Removes a discount from the submission.
635
+     *
636
+     * @since 1.0.19
637
+     */
638
+    public function remove_discount( $name ) {
639
+
640
+        if ( isset( $this->discounts[ $name ] ) ) {
641
+            $this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
642
+            $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
643
+            unset( $this->discounts[ $name ] );
644
+        }
645
+
646
+    }
647
+
648
+    /**
649
+     * Checks whether there is a discount code associated with this submission.
650
+     *
651
+     * @since 1.0.19
652
+     * @return bool
653
+     */
654
+    public function has_discount_code() {
655
+        return ! empty( $this->discounts['discount_code'] );
656
+    }
657
+
658
+    /**
659
+     * Returns the discount code.
660
+     *
661
+     * @since 1.0.19
662
+     * @return string
663
+     */
664
+    public function get_discount_code() {
665
+        return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
666
+    }
667
+
668
+    /**
669
+     * Returns the discount.
670
+     *
671
+     * @since 1.0.19
672
+     */
673
+    public function get_discount() {
674
+        return $this->totals['discount']['initial'];
675
+    }
676
+
677
+    /**
678
+     * Returns the recurring discount.
679
+     *
680
+     * @since 1.0.19
681
+     */
682
+    public function get_recurring_discount() {
683
+        return $this->totals['discount']['recurring'];
684
+    }
685
+
686
+    /**
687
+     * Returns all discounts.
688
+     *
689
+     * @since 1.0.19
690
+     */
691
+    public function get_discounts() {
692
+        return $this->discounts;
693
+    }
694
+
695
+    /*
696 696
 	|--------------------------------------------------------------------------
697 697
 	| Fees
698 698
 	|--------------------------------------------------------------------------
@@ -702,100 +702,100 @@  discard block
 block discarded – undo
702 702
 	| fees.
703 703
     */
704 704
 
705
-	/**
706
-	 * Prepares the submission's fees.
707
-	 *
708
-	 * @since 1.0.19
709
-	 */
710
-	public function process_fees() {
711
-
712
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
713
-
714
-		foreach ( $fees_processor->fees as $fee ) {
715
-			$this->add_fee( $fee );
716
-		}
717
-
718
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
719
-	}
720
-
721
-	/**
722
-	 * Adds a fee to the submission.
723
-	 *
724
-	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
725
-	 * @since 1.0.19
726
-	 */
727
-	public function add_fee( $fee ) {
728
-
729
-		if ( $fee['name'] == 'shipping' ) {
730
-			$this->totals['shipping']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
731
-			$this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
732
-			return;
733
-		}
734
-
735
-		$this->fees[ $fee['name'] ]         = $fee;
736
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
737
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
738
-
739
-	}
740
-
741
-	/**
742
-	 * Removes a fee from the submission.
743
-	 *
744
-	 * @since 1.0.19
745
-	 */
746
-	public function remove_fee( $name ) {
747
-
748
-		if ( isset( $this->fees[ $name ] ) ) {
749
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
750
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
751
-			unset( $this->fees[ $name ] );
752
-		}
753
-
754
-		if ( 'shipping' == $name ) {
755
-			$this->totals['shipping']['initial']   = 0;
756
-			$this->totals['shipping']['recurring'] = 0;
757
-		}
758
-
759
-	}
760
-
761
-	/**
762
-	 * Returns the fees.
763
-	 *
764
-	 * @since 1.0.19
765
-	 */
766
-	public function get_fee() {
767
-		return $this->totals['fees']['initial'];
768
-	}
769
-
770
-	/**
771
-	 * Returns the recurring fees.
772
-	 *
773
-	 * @since 1.0.19
774
-	 */
775
-	public function get_recurring_fee() {
776
-		return $this->totals['fees']['recurring'];
777
-	}
778
-
779
-	/**
780
-	 * Returns all fees.
781
-	 *
782
-	 * @since 1.0.19
783
-	 */
784
-	public function get_fees() {
785
-		return $this->fees;
786
-	}
787
-
788
-	/**
789
-	 * Checks if there are any fees for the form.
790
-	 *
791
-	 * @return bool
792
-	 * @since 1.0.19
793
-	 */
794
-	public function has_fees() {
795
-		return count( $this->fees ) !== 0;
796
-	}
797
-
798
-	/*
705
+    /**
706
+     * Prepares the submission's fees.
707
+     *
708
+     * @since 1.0.19
709
+     */
710
+    public function process_fees() {
711
+
712
+        $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
713
+
714
+        foreach ( $fees_processor->fees as $fee ) {
715
+            $this->add_fee( $fee );
716
+        }
717
+
718
+        do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
719
+    }
720
+
721
+    /**
722
+     * Adds a fee to the submission.
723
+     *
724
+     * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
725
+     * @since 1.0.19
726
+     */
727
+    public function add_fee( $fee ) {
728
+
729
+        if ( $fee['name'] == 'shipping' ) {
730
+            $this->totals['shipping']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
731
+            $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
732
+            return;
733
+        }
734
+
735
+        $this->fees[ $fee['name'] ]         = $fee;
736
+        $this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
737
+        $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
738
+
739
+    }
740
+
741
+    /**
742
+     * Removes a fee from the submission.
743
+     *
744
+     * @since 1.0.19
745
+     */
746
+    public function remove_fee( $name ) {
747
+
748
+        if ( isset( $this->fees[ $name ] ) ) {
749
+            $this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
750
+            $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
751
+            unset( $this->fees[ $name ] );
752
+        }
753
+
754
+        if ( 'shipping' == $name ) {
755
+            $this->totals['shipping']['initial']   = 0;
756
+            $this->totals['shipping']['recurring'] = 0;
757
+        }
758
+
759
+    }
760
+
761
+    /**
762
+     * Returns the fees.
763
+     *
764
+     * @since 1.0.19
765
+     */
766
+    public function get_fee() {
767
+        return $this->totals['fees']['initial'];
768
+    }
769
+
770
+    /**
771
+     * Returns the recurring fees.
772
+     *
773
+     * @since 1.0.19
774
+     */
775
+    public function get_recurring_fee() {
776
+        return $this->totals['fees']['recurring'];
777
+    }
778
+
779
+    /**
780
+     * Returns all fees.
781
+     *
782
+     * @since 1.0.19
783
+     */
784
+    public function get_fees() {
785
+        return $this->fees;
786
+    }
787
+
788
+    /**
789
+     * Checks if there are any fees for the form.
790
+     *
791
+     * @return bool
792
+     * @since 1.0.19
793
+     */
794
+    public function has_fees() {
795
+        return count( $this->fees ) !== 0;
796
+    }
797
+
798
+    /*
799 799
 	|--------------------------------------------------------------------------
800 800
 	| MISC
801 801
 	|--------------------------------------------------------------------------
@@ -803,147 +803,147 @@  discard block
 block discarded – undo
803 803
 	| Extra submission functions.
804 804
     */
805 805
 
806
-	/**
807
-	 * Returns the shipping amount.
808
-	 *
809
-	 * @since 1.0.19
810
-	 */
811
-	public function get_shipping() {
812
-		return $this->totals['shipping']['initial'];
813
-	}
814
-
815
-	/**
816
-	 * Returns the recurring shipping.
817
-	 *
818
-	 * @since 1.0.19
819
-	 */
820
-	public function get_recurring_shipping() {
821
-		return $this->totals['shipping']['recurring'];
822
-	}
823
-
824
-	/**
825
-	 * Checks if there are any shipping fees for the form.
826
-	 *
827
-	 * @return bool
828
-	 * @since 1.0.19
829
-	 */
830
-	public function has_shipping() {
831
-		return apply_filters( 'getpaid_payment_form_has_shipping', false, $this );
832
-	}
833
-
834
-	/**
835
-	 * Checks if this is the initial fetch.
836
-	 *
837
-	 * @return bool
838
-	 * @since 1.0.19
839
-	 */
840
-	public function is_initial_fetch() {
841
-		return empty( $this->data['initial_state'] );
842
-	}
843
-
844
-	/**
845
-	 * Returns the total amount to collect for this submission.
846
-	 *
847
-	 * @since 1.0.19
848
-	 */
849
-	public function get_total() {
850
-		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount();
851
-		return max( $total, 0 );
852
-	}
853
-
854
-	/**
855
-	 * Returns the recurring total amount to collect for this submission.
856
-	 *
857
-	 * @since 1.0.19
858
-	 */
859
-	public function get_recurring_total() {
860
-		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount();
861
-		return max( $total, 0 );
862
-	}
863
-
864
-	/**
865
-	 * Whether payment details should be collected for this submission.
866
-	 *
867
-	 * @since 1.0.19
868
-	 */
869
-	public function should_collect_payment_details() {
870
-		$initial   = $this->get_total();
871
-		$recurring = $this->get_recurring_total();
872
-
873
-		if ( $this->has_recurring == 0 ) {
874
-			$recurring = 0;
875
-		}
876
-
877
-		$collect = $initial > 0 || $recurring > 0;
878
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
879
-	}
880
-
881
-	/**
882
-	 * Returns the billing email of the user.
883
-	 *
884
-	 * @since 1.0.19
885
-	 */
886
-	public function get_billing_email() {
887
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
888
-	}
889
-
890
-	/**
891
-	 * Checks if the submitter has a billing email.
892
-	 *
893
-	 * @since 1.0.19
894
-	 */
895
-	public function has_billing_email() {
896
-		$billing_email = $this->get_billing_email();
897
-		return ! empty( $billing_email ) && is_email( $billing_email );
898
-	}
899
-
900
-	/**
901
-	 * Returns the appropriate currency for the submission.
902
-	 *
903
-	 * @since 1.0.19
904
-	 * @return string
905
-	 */
906
-	public function get_currency() {
907
-		return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
908
-    }
909
-
910
-    /**
911
-	 * Returns the raw submission data.
912
-	 *
913
-	 * @since 1.0.19
914
-	 * @return array
915
-	 */
916
-	public function get_data() {
917
-		return $this->data;
918
-	}
919
-
920
-	/**
921
-	 * Returns a field from the submission data
922
-	 *
923
-	 * @param string $field
924
-	 * @since 1.0.19
925
-	 * @return mixed|null
926
-	 */
927
-	public function get_field( $field, $sub_array_key = null ) {
928
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
929
-	}
930
-
931
-	/**
932
-	 * Checks if a required field is set.
933
-	 *
934
-	 * @since 1.0.19
935
-	 */
936
-	public function is_required_field_set( $field ) {
937
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
938
-	}
939
-
940
-	/**
941
-	 * Formats an amount
942
-	 *
943
-	 * @since 1.0.19
944
-	 */
945
-	public function format_amount( $amount ) {
946
-		return wpinv_price( $amount, $this->get_currency() );
947
-	}
806
+    /**
807
+     * Returns the shipping amount.
808
+     *
809
+     * @since 1.0.19
810
+     */
811
+    public function get_shipping() {
812
+        return $this->totals['shipping']['initial'];
813
+    }
814
+
815
+    /**
816
+     * Returns the recurring shipping.
817
+     *
818
+     * @since 1.0.19
819
+     */
820
+    public function get_recurring_shipping() {
821
+        return $this->totals['shipping']['recurring'];
822
+    }
823
+
824
+    /**
825
+     * Checks if there are any shipping fees for the form.
826
+     *
827
+     * @return bool
828
+     * @since 1.0.19
829
+     */
830
+    public function has_shipping() {
831
+        return apply_filters( 'getpaid_payment_form_has_shipping', false, $this );
832
+    }
833
+
834
+    /**
835
+     * Checks if this is the initial fetch.
836
+     *
837
+     * @return bool
838
+     * @since 1.0.19
839
+     */
840
+    public function is_initial_fetch() {
841
+        return empty( $this->data['initial_state'] );
842
+    }
843
+
844
+    /**
845
+     * Returns the total amount to collect for this submission.
846
+     *
847
+     * @since 1.0.19
848
+     */
849
+    public function get_total() {
850
+        $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount();
851
+        return max( $total, 0 );
852
+    }
853
+
854
+    /**
855
+     * Returns the recurring total amount to collect for this submission.
856
+     *
857
+     * @since 1.0.19
858
+     */
859
+    public function get_recurring_total() {
860
+        $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount();
861
+        return max( $total, 0 );
862
+    }
863
+
864
+    /**
865
+     * Whether payment details should be collected for this submission.
866
+     *
867
+     * @since 1.0.19
868
+     */
869
+    public function should_collect_payment_details() {
870
+        $initial   = $this->get_total();
871
+        $recurring = $this->get_recurring_total();
872
+
873
+        if ( $this->has_recurring == 0 ) {
874
+            $recurring = 0;
875
+        }
876
+
877
+        $collect = $initial > 0 || $recurring > 0;
878
+        return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
879
+    }
880
+
881
+    /**
882
+     * Returns the billing email of the user.
883
+     *
884
+     * @since 1.0.19
885
+     */
886
+    public function get_billing_email() {
887
+        return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
888
+    }
889
+
890
+    /**
891
+     * Checks if the submitter has a billing email.
892
+     *
893
+     * @since 1.0.19
894
+     */
895
+    public function has_billing_email() {
896
+        $billing_email = $this->get_billing_email();
897
+        return ! empty( $billing_email ) && is_email( $billing_email );
898
+    }
899
+
900
+    /**
901
+     * Returns the appropriate currency for the submission.
902
+     *
903
+     * @since 1.0.19
904
+     * @return string
905
+     */
906
+    public function get_currency() {
907
+        return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
908
+    }
909
+
910
+    /**
911
+     * Returns the raw submission data.
912
+     *
913
+     * @since 1.0.19
914
+     * @return array
915
+     */
916
+    public function get_data() {
917
+        return $this->data;
918
+    }
919
+
920
+    /**
921
+     * Returns a field from the submission data
922
+     *
923
+     * @param string $field
924
+     * @since 1.0.19
925
+     * @return mixed|null
926
+     */
927
+    public function get_field( $field, $sub_array_key = null ) {
928
+        return getpaid_get_array_field( $this->data, $field, $sub_array_key );
929
+    }
930
+
931
+    /**
932
+     * Checks if a required field is set.
933
+     *
934
+     * @since 1.0.19
935
+     */
936
+    public function is_required_field_set( $field ) {
937
+        return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
938
+    }
939
+
940
+    /**
941
+     * Formats an amount
942
+     *
943
+     * @since 1.0.19
944
+     */
945
+    public function format_amount( $amount ) {
946
+        return wpinv_price( $amount, $this->get_currency() );
947
+    }
948 948
 
949 949
 }
Please login to merge, or discard this patch.
Spacing   +129 added lines, -129 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
 
@@ -146,8 +146,8 @@  discard block
 block discarded – undo
146 146
 		$this->state   = wpinv_get_default_state();
147 147
 
148 148
 		// Do we have an actual submission?
149
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
150
-			$this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) );
149
+		if (isset($_POST['getpaid_payment_form_submission'])) {
150
+			$this->load_data(wp_kses_post_deep(wp_unslash($_POST)));
151 151
 		}
152 152
 
153 153
 	}
@@ -157,16 +157,16 @@  discard block
 block discarded – undo
157 157
 	 *
158 158
 	 * @param array $data
159 159
 	 */
160
-	public function load_data( $data ) {
160
+	public function load_data($data) {
161 161
 
162 162
 		// Allow plugins to filter the data.
163
-		$data       = apply_filters( 'getpaid_submission_data', $data, $this );
163
+		$data       = apply_filters('getpaid_submission_data', $data, $this);
164 164
 
165 165
 		// Cache it...
166 166
 		$this->data = $data;
167 167
 
168 168
 		// Then generate a unique id from the data.
169
-		$this->id   = md5( wp_json_encode( $data ) );
169
+		$this->id   = md5(wp_json_encode($data));
170 170
 
171 171
 		// Finally, process the submission.
172 172
 		try {
@@ -176,30 +176,30 @@  discard block
 block discarded – undo
176 176
 			$processors = apply_filters(
177 177
 				'getpaid_payment_form_submission_processors',
178 178
 				array(
179
-					array( $this, 'process_payment_form' ),
180
-					array( $this, 'process_invoice' ),
181
-					array( $this, 'process_fees' ),
182
-					array( $this, 'process_items' ),
183
-					array( $this, 'process_discount' ),
184
-					array( $this, 'process_taxes' ),
179
+					array($this, 'process_payment_form'),
180
+					array($this, 'process_invoice'),
181
+					array($this, 'process_fees'),
182
+					array($this, 'process_items'),
183
+					array($this, 'process_discount'),
184
+					array($this, 'process_taxes'),
185 185
 				),
186 186
 				$this		
187 187
 			);
188 188
 
189
-			foreach ( $processors as $processor ) {
190
-				call_user_func_array( $processor, array( &$this ) );
189
+			foreach ($processors as $processor) {
190
+				call_user_func_array($processor, array(&$this));
191 191
 			}
192 192
 
193
-		} catch( GetPaid_Payment_Exception $e ) {
193
+		} catch (GetPaid_Payment_Exception $e) {
194 194
 			$this->last_error      = $e->getMessage();
195 195
 			$this->last_error_code = $e->getErrorCode();
196
-		} catch ( Exception $e ) {
196
+		} catch (Exception $e) {
197 197
 			$this->last_error      = $e->getMessage();
198 198
 			$this->last_error_code = $e->getCode();
199 199
 		}
200 200
 
201 201
 		// Fired when we are done processing a submission.
202
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
202
+		do_action_ref_array('getpaid_process_submission', array(&$this));
203 203
 
204 204
 	}
205 205
 
@@ -220,18 +220,18 @@  discard block
 block discarded – undo
220 220
 	public function process_payment_form() {
221 221
 
222 222
 		// Every submission needs an active payment form.
223
-		if ( empty( $this->data['form_id'] ) ) {
224
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
223
+		if (empty($this->data['form_id'])) {
224
+			throw new Exception(__('Missing payment form', 'invoicing'));
225 225
 		}
226 226
 
227 227
 		// Fetch the payment form.
228
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
228
+		$this->payment_form = new GetPaid_Payment_Form($this->data['form_id']);
229 229
 
230
-		if ( ! $this->payment_form->is_active() ) {
231
-			throw new Exception( __( 'Payment form not active', 'invoicing' ) );
230
+		if (!$this->payment_form->is_active()) {
231
+			throw new Exception(__('Payment form not active', 'invoicing'));
232 232
 		}
233 233
 
234
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
234
+		do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this));
235 235
 	}
236 236
 
237 237
     /**
@@ -261,53 +261,53 @@  discard block
 block discarded – undo
261 261
 	public function process_invoice() {
262 262
 
263 263
 		// Abort if there is no invoice.
264
-		if ( empty( $this->data['invoice_id'] ) ) {
264
+		if (empty($this->data['invoice_id'])) {
265 265
 			return;
266 266
 		}
267 267
 
268 268
 		// If the submission is for an existing invoice, ensure that it exists
269 269
 		// and that it is not paid for.
270
-		$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
270
+		$invoice = wpinv_get_invoice($this->data['invoice_id']);
271 271
 
272
-        if ( empty( $invoice ) ) {
273
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
272
+        if (empty($invoice)) {
273
+			throw new Exception(__('Invalid invoice', 'invoicing'));
274 274
 		}
275 275
 
276
-		if ( $invoice->is_paid() ) {
277
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
276
+		if ($invoice->is_paid()) {
277
+			throw new Exception(__('This invoice is already paid for.', 'invoicing'));
278 278
 		}
279 279
 
280 280
 		$this->payment_form->invoice = $invoice;
281
-		if ( ! $this->payment_form->is_default() ) {
281
+		if (!$this->payment_form->is_default()) {
282 282
 
283 283
 			$items    = array();
284 284
 			$item_ids = array();
285 285
 	
286
-			foreach ( $invoice->get_items() as $item ) {
287
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
286
+			foreach ($invoice->get_items() as $item) {
287
+				if (!in_array($item->get_id(), $item_ids)) {
288 288
 					$item_ids[] = $item->get_id();
289 289
 					$items[]    = $item;
290 290
 				}
291 291
 			}
292 292
 	
293
-			foreach ( $this->payment_form->get_items() as $item ) {
294
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
293
+			foreach ($this->payment_form->get_items() as $item) {
294
+				if (!in_array($item->get_id(), $item_ids)) {
295 295
 					$item_ids[] = $item->get_id();
296 296
 					$items[]    = $item;
297 297
 				}
298 298
 			}
299 299
 	
300
-			$this->payment_form->set_items( $items );
300
+			$this->payment_form->set_items($items);
301 301
 	
302 302
 		} else {
303
-			$this->payment_form->set_items( $invoice->get_items() );
303
+			$this->payment_form->set_items($invoice->get_items());
304 304
 		}
305 305
 
306 306
 		$this->country = $invoice->get_country();
307 307
 		$this->state   = $invoice->get_state();
308 308
 		$this->invoice = $invoice;
309 309
 
310
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
310
+		do_action_ref_array('getpaid_submissions_process_invoice', array(&$this));
311 311
 	}
312 312
 
313 313
 	/**
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 	 * @return bool
328 328
 	 */
329 329
 	public function has_invoice() {
330
-		return ! empty( $this->invoice );
330
+		return !empty($this->invoice);
331 331
 	}
332 332
 
333 333
 	/*
@@ -346,13 +346,13 @@  discard block
 block discarded – undo
346 346
 	 */
347 347
 	public function process_items() {
348 348
 
349
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
349
+		$processor = new GetPaid_Payment_Form_Submission_Items($this);
350 350
 
351
-		foreach ( $processor->items as $item ) {
352
-			$this->add_item( $item );
351
+		foreach ($processor->items as $item) {
352
+			$this->add_item($item);
353 353
 		}
354 354
 
355
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
355
+		do_action_ref_array('getpaid_submissions_process_items', array(&$this));
356 356
 	}
357 357
 
358 358
 	/**
@@ -361,20 +361,20 @@  discard block
 block discarded – undo
361 361
 	 * @since 1.0.19
362 362
 	 * @param GetPaid_Form_Item $item
363 363
 	 */
364
-	public function add_item( $item ) {
364
+	public function add_item($item) {
365 365
 
366 366
 		// Make sure that it is available for purchase.
367
-		if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
367
+		if (!$item->can_purchase() || isset($this->items[$item->get_id()])) {
368 368
 			return;
369 369
 		}
370 370
 
371 371
 		// Each submission can only contain one recurring item.
372
-		if ( $item->is_recurring() ) {
372
+		if ($item->is_recurring()) {
373 373
 			$this->has_recurring = $item->get_id();
374 374
 		}
375 375
 
376 376
 		// Update the items and totals.
377
-		$this->items[ $item->get_id() ]         = $item;
377
+		$this->items[$item->get_id()]         = $item;
378 378
 		$this->totals['subtotal']['initial']   += $item->get_sub_total();
379 379
 		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
380 380
 
@@ -388,17 +388,17 @@  discard block
 block discarded – undo
388 388
 	 *
389 389
 	 * @since 1.0.19
390 390
 	 */
391
-	public function remove_item( $item_id ) {
391
+	public function remove_item($item_id) {
392 392
 
393
-		if ( isset( $this->items[ $item_id ] ) ) {
394
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
395
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
393
+		if (isset($this->items[$item_id])) {
394
+			$this->totals['subtotal']['initial']   -= $this->items[$item_id]->get_sub_total();
395
+			$this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total();
396 396
 
397
-			if ( $this->items[ $item_id ]->is_recurring() ) {
397
+			if ($this->items[$item_id]->is_recurring()) {
398 398
 				$this->has_recurring = 0;
399 399
 			}
400 400
 
401
-			unset( $this->items[ $item_id ] );
401
+			unset($this->items[$item_id]);
402 402
 		}
403 403
 
404 404
 	}
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
 	 */
411 411
 	public function get_subtotal() {
412 412
 
413
-		if ( wpinv_prices_include_tax() ) {
413
+		if (wpinv_prices_include_tax()) {
414 414
 			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
415 415
 		}
416 416
 
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
 	 */
425 425
 	public function get_recurring_subtotal() {
426 426
 
427
-		if ( wpinv_prices_include_tax() ) {
427
+		if (wpinv_prices_include_tax()) {
428 428
 			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
429 429
 		}
430 430
 
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
 	 * @return bool
449 449
 	 */
450 450
 	public function has_subscription_group() {
451
-		return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) );
451
+		return $this->has_recurring && getpaid_should_group_subscriptions($this) && 1 == count(getpaid_get_subscription_groups($this));
452 452
 	}
453 453
 
454 454
 	/**
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
 	 * @return bool
459 459
 	 */
460 460
 	public function has_multiple_subscription_groups() {
461
-		return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) );
461
+		return $this->has_recurring && 1 < count(getpaid_get_subscription_groups($this));
462 462
 	}
463 463
 
464 464
 	/*
@@ -478,39 +478,39 @@  discard block
 block discarded – undo
478 478
 	public function process_taxes() {
479 479
 
480 480
 		// Abort if we're not using taxes.
481
-		if ( ! $this->use_taxes() ) {
481
+		if (!$this->use_taxes()) {
482 482
 			return;
483 483
 		}
484 484
 
485 485
 		// If a custom country && state has been passed in, use it to calculate taxes.
486
-		$country = $this->get_field( 'wpinv_country', 'billing' );
487
-		if ( ! empty( $country ) ) {
486
+		$country = $this->get_field('wpinv_country', 'billing');
487
+		if (!empty($country)) {
488 488
 			$this->country = $country;
489 489
 		}
490 490
 
491
-		$state = $this->get_field( 'wpinv_state', 'billing' );
492
-		if ( ! empty( $state ) ) {
491
+		$state = $this->get_field('wpinv_state', 'billing');
492
+		if (!empty($state)) {
493 493
 			$this->state = $state;
494 494
 		}
495 495
 
496 496
 		// Confirm if the provided country and the ip country are similar.
497
-		$address_confirmed = $this->get_field( 'confirm-address' );
498
-		if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
499
-			throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
497
+		$address_confirmed = $this->get_field('confirm-address');
498
+		if (isset($_POST['billing']['country']) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) {
499
+			throw new Exception(__('The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing'));
500 500
 		}
501 501
 
502 502
 		// Abort if the country is not taxable.
503
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
503
+		if (!wpinv_is_country_taxable($this->country)) {
504 504
 			return;
505 505
 		}
506 506
 
507
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
507
+		$processor = new GetPaid_Payment_Form_Submission_Taxes($this);
508 508
 
509
-		foreach ( $processor->taxes as $tax ) {
510
-			$this->add_tax( $tax );
509
+		foreach ($processor->taxes as $tax) {
510
+			$this->add_tax($tax);
511 511
 		}
512 512
 
513
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
513
+		do_action_ref_array('getpaid_submissions_process_taxes', array(&$this));
514 514
 	}
515 515
 
516 516
 	/**
@@ -519,16 +519,16 @@  discard block
 block discarded – undo
519 519
 	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
520 520
 	 * @since 1.0.19
521 521
 	 */
522
-	public function add_tax( $tax ) {
522
+	public function add_tax($tax) {
523 523
 
524
-		if ( wpinv_round_tax_per_tax_rate() ) {
525
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
526
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
524
+		if (wpinv_round_tax_per_tax_rate()) {
525
+			$tax['initial_tax']   = wpinv_round_amount($tax['initial_tax']);
526
+			$tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']);
527 527
 		}
528 528
 
529
-		$this->taxes[ $tax['name'] ]         = $tax;
530
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
531
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
529
+		$this->taxes[$tax['name']]         = $tax;
530
+		$this->totals['taxes']['initial']   += wpinv_sanitize_amount($tax['initial_tax']);
531
+		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']);
532 532
 
533 533
 	}
534 534
 
@@ -537,12 +537,12 @@  discard block
 block discarded – undo
537 537
 	 *
538 538
 	 * @since 1.0.19
539 539
 	 */
540
-	public function remove_tax( $tax_name ) {
540
+	public function remove_tax($tax_name) {
541 541
 
542
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
543
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
544
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
545
-			unset( $this->taxes[ $tax_name ] );
542
+		if (isset($this->taxes[$tax_name])) {
543
+			$this->totals['taxes']['initial']   -= $this->taxes[$tax_name]['initial_tax'];
544
+			$this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax'];
545
+			unset($this->taxes[$tax_name]);
546 546
 		}
547 547
 
548 548
 	}
@@ -556,11 +556,11 @@  discard block
 block discarded – undo
556 556
 
557 557
 		$use_taxes = wpinv_use_taxes();
558 558
 
559
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
559
+		if ($this->has_invoice() && !$this->invoice->is_taxable()) {
560 560
 			$use_taxes = false;
561 561
 		}
562 562
 
563
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
563
+		return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this);
564 564
 
565 565
 	}
566 566
 
@@ -609,13 +609,13 @@  discard block
 block discarded – undo
609 609
 
610 610
 		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
611 611
 		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
612
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
612
+		$processor        = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total);
613 613
 
614
-		foreach ( $processor->discounts as $discount ) {
615
-			$this->add_discount( $discount );
614
+		foreach ($processor->discounts as $discount) {
615
+			$this->add_discount($discount);
616 616
 		}
617 617
 
618
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
618
+		do_action_ref_array('getpaid_submissions_process_discounts', array(&$this));
619 619
 	}
620 620
 
621 621
 	/**
@@ -624,10 +624,10 @@  discard block
 block discarded – undo
624 624
 	 * @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.
625 625
 	 * @since 1.0.19
626 626
 	 */
627
-	public function add_discount( $discount ) {
628
-		$this->discounts[ $discount['name'] ]   = $discount;
629
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
630
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
627
+	public function add_discount($discount) {
628
+		$this->discounts[$discount['name']]   = $discount;
629
+		$this->totals['discount']['initial']   += wpinv_sanitize_amount($discount['initial_discount']);
630
+		$this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']);
631 631
 	}
632 632
 
633 633
 	/**
@@ -635,12 +635,12 @@  discard block
 block discarded – undo
635 635
 	 *
636 636
 	 * @since 1.0.19
637 637
 	 */
638
-	public function remove_discount( $name ) {
638
+	public function remove_discount($name) {
639 639
 
640
-		if ( isset( $this->discounts[ $name ] ) ) {
641
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
642
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
643
-			unset( $this->discounts[ $name ] );
640
+		if (isset($this->discounts[$name])) {
641
+			$this->totals['discount']['initial']   -= $this->discounts[$name]['initial_discount'];
642
+			$this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount'];
643
+			unset($this->discounts[$name]);
644 644
 		}
645 645
 
646 646
 	}
@@ -652,7 +652,7 @@  discard block
 block discarded – undo
652 652
 	 * @return bool
653 653
 	 */
654 654
 	public function has_discount_code() {
655
-		return ! empty( $this->discounts['discount_code'] );
655
+		return !empty($this->discounts['discount_code']);
656 656
 	}
657 657
 
658 658
 	/**
@@ -709,13 +709,13 @@  discard block
 block discarded – undo
709 709
 	 */
710 710
 	public function process_fees() {
711 711
 
712
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
712
+		$fees_processor = new GetPaid_Payment_Form_Submission_Fees($this);
713 713
 
714
-		foreach ( $fees_processor->fees as $fee ) {
715
-			$this->add_fee( $fee );
714
+		foreach ($fees_processor->fees as $fee) {
715
+			$this->add_fee($fee);
716 716
 		}
717 717
 
718
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
718
+		do_action_ref_array('getpaid_submissions_process_fees', array(&$this));
719 719
 	}
720 720
 
721 721
 	/**
@@ -724,17 +724,17 @@  discard block
 block discarded – undo
724 724
 	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
725 725
 	 * @since 1.0.19
726 726
 	 */
727
-	public function add_fee( $fee ) {
727
+	public function add_fee($fee) {
728 728
 
729
-		if ( $fee['name'] == 'shipping' ) {
730
-			$this->totals['shipping']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
731
-			$this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
729
+		if ($fee['name'] == 'shipping') {
730
+			$this->totals['shipping']['initial']   += wpinv_sanitize_amount($fee['initial_fee']);
731
+			$this->totals['shipping']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']);
732 732
 			return;
733 733
 		}
734 734
 
735
-		$this->fees[ $fee['name'] ]         = $fee;
736
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
737
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
735
+		$this->fees[$fee['name']]         = $fee;
736
+		$this->totals['fees']['initial']   += wpinv_sanitize_amount($fee['initial_fee']);
737
+		$this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']);
738 738
 
739 739
 	}
740 740
 
@@ -743,15 +743,15 @@  discard block
 block discarded – undo
743 743
 	 *
744 744
 	 * @since 1.0.19
745 745
 	 */
746
-	public function remove_fee( $name ) {
746
+	public function remove_fee($name) {
747 747
 
748
-		if ( isset( $this->fees[ $name ] ) ) {
749
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
750
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
751
-			unset( $this->fees[ $name ] );
748
+		if (isset($this->fees[$name])) {
749
+			$this->totals['fees']['initial']   -= $this->fees[$name]['initial_fee'];
750
+			$this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee'];
751
+			unset($this->fees[$name]);
752 752
 		}
753 753
 
754
-		if ( 'shipping' == $name ) {
754
+		if ('shipping' == $name) {
755 755
 			$this->totals['shipping']['initial']   = 0;
756 756
 			$this->totals['shipping']['recurring'] = 0;
757 757
 		}
@@ -792,7 +792,7 @@  discard block
 block discarded – undo
792 792
 	 * @since 1.0.19
793 793
 	 */
794 794
 	public function has_fees() {
795
-		return count( $this->fees ) !== 0;
795
+		return count($this->fees) !== 0;
796 796
 	}
797 797
 
798 798
 	/*
@@ -828,7 +828,7 @@  discard block
 block discarded – undo
828 828
 	 * @since 1.0.19
829 829
 	 */
830 830
 	public function has_shipping() {
831
-		return apply_filters( 'getpaid_payment_form_has_shipping', false, $this );
831
+		return apply_filters('getpaid_payment_form_has_shipping', false, $this);
832 832
 	}
833 833
 
834 834
 	/**
@@ -838,7 +838,7 @@  discard block
 block discarded – undo
838 838
 	 * @since 1.0.19
839 839
 	 */
840 840
 	public function is_initial_fetch() {
841
-		return empty( $this->data['initial_state'] );
841
+		return empty($this->data['initial_state']);
842 842
 	}
843 843
 
844 844
 	/**
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
 	 */
849 849
 	public function get_total() {
850 850
 		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount();
851
-		return max( $total, 0 );
851
+		return max($total, 0);
852 852
 	}
853 853
 
854 854
 	/**
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
 	 */
859 859
 	public function get_recurring_total() {
860 860
 		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount();
861
-		return max( $total, 0 );
861
+		return max($total, 0);
862 862
 	}
863 863
 
864 864
 	/**
@@ -870,12 +870,12 @@  discard block
 block discarded – undo
870 870
 		$initial   = $this->get_total();
871 871
 		$recurring = $this->get_recurring_total();
872 872
 
873
-		if ( $this->has_recurring == 0 ) {
873
+		if ($this->has_recurring == 0) {
874 874
 			$recurring = 0;
875 875
 		}
876 876
 
877 877
 		$collect = $initial > 0 || $recurring > 0;
878
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
878
+		return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this);
879 879
 	}
880 880
 
881 881
 	/**
@@ -884,7 +884,7 @@  discard block
 block discarded – undo
884 884
 	 * @since 1.0.19
885 885
 	 */
886 886
 	public function get_billing_email() {
887
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
887
+		return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this);
888 888
 	}
889 889
 
890 890
 	/**
@@ -894,7 +894,7 @@  discard block
 block discarded – undo
894 894
 	 */
895 895
 	public function has_billing_email() {
896 896
 		$billing_email = $this->get_billing_email();
897
-		return ! empty( $billing_email ) && is_email( $billing_email );
897
+		return !empty($billing_email) && is_email($billing_email);
898 898
 	}
899 899
 
900 900
 	/**
@@ -924,8 +924,8 @@  discard block
 block discarded – undo
924 924
 	 * @since 1.0.19
925 925
 	 * @return mixed|null
926 926
 	 */
927
-	public function get_field( $field, $sub_array_key = null ) {
928
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
927
+	public function get_field($field, $sub_array_key = null) {
928
+		return getpaid_get_array_field($this->data, $field, $sub_array_key);
929 929
 	}
930 930
 
931 931
 	/**
@@ -933,8 +933,8 @@  discard block
 block discarded – undo
933 933
 	 *
934 934
 	 * @since 1.0.19
935 935
 	 */
936
-	public function is_required_field_set( $field ) {
937
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
936
+	public function is_required_field_set($field) {
937
+		return empty($field['required']) || !empty($this->data[$field['id']]);
938 938
 	}
939 939
 
940 940
 	/**
@@ -942,8 +942,8 @@  discard block
 block discarded – undo
942 942
 	 *
943 943
 	 * @since 1.0.19
944 944
 	 */
945
-	public function format_amount( $amount ) {
946
-		return wpinv_price( $amount, $this->get_currency() );
945
+	public function format_amount($amount) {
946
+		return wpinv_price($amount, $this->get_currency());
947 947
 	}
948 948
 
949 949
 }
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 2 patches
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -14,70 +14,70 @@  discard block
 block discarded – undo
14 14
 class WPInv_Ajax {
15 15
 
16 16
     /**
17
-	 * Hook in ajax handlers.
18
-	 */
19
-	public static function init() {
20
-		add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
-		add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
22
-		self::add_ajax_events();
17
+     * Hook in ajax handlers.
18
+     */
19
+    public static function init() {
20
+        add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
+        add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
22
+        self::add_ajax_events();
23 23
     }
24 24
 
25 25
     /**
26
-	 * Set GetPaid AJAX constant and headers.
27
-	 */
28
-	public static function define_ajax() {
29
-
30
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
-			getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
-			getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
-			if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
-				/** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
35
-			}
36
-			$GLOBALS['wpdb']->hide_errors();
37
-		}
26
+     * Set GetPaid AJAX constant and headers.
27
+     */
28
+    public static function define_ajax() {
29
+
30
+        if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
+            getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
+            getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
+            if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
+                /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
35
+            }
36
+            $GLOBALS['wpdb']->hide_errors();
37
+        }
38 38
 
39 39
     }
40 40
     
41 41
     /**
42
-	 * Send headers for GetPaid Ajax Requests.
43
-	 *
44
-	 * @since 1.0.18
45
-	 */
46
-	private static function wpinv_ajax_headers() {
47
-		if ( ! headers_sent() ) {
48
-			send_origin_headers();
49
-			send_nosniff_header();
50
-			nocache_headers();
51
-			header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
-			header( 'X-Robots-Tag: noindex' );
53
-			status_header( 200 );
54
-		}
42
+     * Send headers for GetPaid Ajax Requests.
43
+     *
44
+     * @since 1.0.18
45
+     */
46
+    private static function wpinv_ajax_headers() {
47
+        if ( ! headers_sent() ) {
48
+            send_origin_headers();
49
+            send_nosniff_header();
50
+            nocache_headers();
51
+            header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
+            header( 'X-Robots-Tag: noindex' );
53
+            status_header( 200 );
54
+        }
55 55
     }
56 56
     
57 57
     /**
58
-	 * Check for GetPaid Ajax request and fire action.
59
-	 */
60
-	public static function do_wpinv_ajax() {
61
-		global $wp_query;
58
+     * Check for GetPaid Ajax request and fire action.
59
+     */
60
+    public static function do_wpinv_ajax() {
61
+        global $wp_query;
62 62
 
63
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
-			$wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
65
-		}
63
+        if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
+            $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
65
+        }
66 66
 
67
-		$action = $wp_query->get( 'wpinv-ajax' );
67
+        $action = $wp_query->get( 'wpinv-ajax' );
68 68
 
69
-		if ( $action ) {
70
-			self::wpinv_ajax_headers();
71
-			$action = sanitize_text_field( $action );
72
-			do_action( 'wpinv_ajax_' . $action );
73
-			wp_die();
74
-		}
69
+        if ( $action ) {
70
+            self::wpinv_ajax_headers();
71
+            $action = sanitize_text_field( $action );
72
+            do_action( 'wpinv_ajax_' . $action );
73
+            wp_die();
74
+        }
75 75
 
76 76
     }
77 77
 
78 78
     /**
79
-	 * Hook in ajax methods.
80
-	 */
79
+     * Hook in ajax methods.
80
+     */
81 81
     public static function add_ajax_events() {
82 82
 
83 83
         // array( 'event' => is_frontend )
@@ -261,18 +261,18 @@  discard block
 block discarded – undo
261 261
         check_ajax_referer( 'getpaid_form_nonce' );
262 262
 
263 263
         // Is the request set up correctly?
264
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) {
265
-			echo aui()->alert(
266
-				array(
267
-					'type'    => 'warning',
268
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
269
-				)
264
+        if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) {
265
+            echo aui()->alert(
266
+                array(
267
+                    'type'    => 'warning',
268
+                    'content' => __( 'No payment form or item provided', 'invoicing' ),
269
+                )
270 270
             );
271 271
             exit;
272 272
         }
273 273
 
274 274
         // Payment form or button?
275
-		if ( ! empty( $_GET['form'] ) ) {
275
+        if ( ! empty( $_GET['form'] ) ) {
276 276
             $form = sanitize_text_field( urldecode( $_GET['form'] ) );
277 277
 
278 278
             if ( false !== strpos( $form, '|' ) ) {
@@ -326,11 +326,11 @@  discard block
 block discarded – undo
326 326
                 getpaid_display_payment_form( $form );
327 327
             }
328 328
 
329
-		} else if( ! empty( $_GET['invoice'] ) ) {
330
-		    getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) );
329
+        } else if( ! empty( $_GET['invoice'] ) ) {
330
+            getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) );
331 331
         } else {
332
-			$items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) );
333
-		    getpaid_display_item_payment_form( $items );
332
+            $items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) );
333
+            getpaid_display_item_payment_form( $items );
334 334
         }
335 335
 
336 336
         exit;
@@ -651,7 +651,7 @@  discard block
 block discarded – undo
651 651
         if ( is_wp_error( $error ) ) {
652 652
             $alert = $error->get_error_message();
653 653
             wp_send_json_success( compact( 'alert' ) );
654
-         }
654
+            }
655 655
 
656 656
         // Update totals.
657 657
         $invoice->recalculate_total();
@@ -1089,12 +1089,12 @@  discard block
 block discarded – undo
1089 1089
     }
1090 1090
 
1091 1091
     /**
1092
-	 * Handles file uploads.
1093
-	 *
1094
-	 * @since       1.0.0
1095
-	 * @return      void
1096
-	 */
1097
-	public static function file_upload() {
1092
+     * Handles file uploads.
1093
+     *
1094
+     * @since       1.0.0
1095
+     * @return      void
1096
+     */
1097
+    public static function file_upload() {
1098 1098
 
1099 1099
         // Check nonce.
1100 1100
         check_ajax_referer( 'getpaid_form_nonce' );
@@ -1155,7 +1155,7 @@  discard block
 block discarded – undo
1155 1155
 
1156 1156
         wp_send_json_success( $response );
1157 1157
 
1158
-	}
1158
+    }
1159 1159
 
1160 1160
 }
1161 1161
 
Please login to merge, or discard this patch.
Spacing   +326 added lines, -326 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
  * WPInv_Ajax class.
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
 	 * Hook in ajax handlers.
18 18
 	 */
19 19
 	public static function init() {
20
-		add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
-		add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
20
+		add_action('init', array(__CLASS__, 'define_ajax'), 0);
21
+		add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
22 22
 		self::add_ajax_events();
23 23
     }
24 24
 
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
 	 */
28 28
 	public static function define_ajax() {
29 29
 
30
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
-			getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
-			getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
-			if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
-				/** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
30
+		if (!empty($_GET['wpinv-ajax'])) {
31
+			getpaid_maybe_define_constant('DOING_AJAX', true);
32
+			getpaid_maybe_define_constant('WPInv_DOING_AJAX', true);
33
+			if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
34
+				/** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0);
35 35
 			}
36 36
 			$GLOBALS['wpdb']->hide_errors();
37 37
 		}
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
 	 * @since 1.0.18
45 45
 	 */
46 46
 	private static function wpinv_ajax_headers() {
47
-		if ( ! headers_sent() ) {
47
+		if (!headers_sent()) {
48 48
 			send_origin_headers();
49 49
 			send_nosniff_header();
50 50
 			nocache_headers();
51
-			header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
-			header( 'X-Robots-Tag: noindex' );
53
-			status_header( 200 );
51
+			header('Content-Type: text/html; charset=' . get_option('blog_charset'));
52
+			header('X-Robots-Tag: noindex');
53
+			status_header(200);
54 54
 		}
55 55
     }
56 56
     
@@ -60,16 +60,16 @@  discard block
 block discarded – undo
60 60
 	public static function do_wpinv_ajax() {
61 61
 		global $wp_query;
62 62
 
63
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
-			$wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
63
+		if (!empty($_GET['wpinv-ajax'])) {
64
+			$wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax'])));
65 65
 		}
66 66
 
67
-		$action = $wp_query->get( 'wpinv-ajax' );
67
+		$action = $wp_query->get('wpinv-ajax');
68 68
 
69
-		if ( $action ) {
69
+		if ($action) {
70 70
 			self::wpinv_ajax_headers();
71
-			$action = sanitize_text_field( $action );
72
-			do_action( 'wpinv_ajax_' . $action );
71
+			$action = sanitize_text_field($action);
72
+			do_action('wpinv_ajax_' . $action);
73 73
 			wp_die();
74 74
 		}
75 75
 
@@ -106,36 +106,36 @@  discard block
 block discarded – undo
106 106
             'file_upload'                 => true,
107 107
         );
108 108
 
109
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
110
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
111
-            add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
109
+        foreach ($ajax_events as $ajax_event => $nopriv) {
110
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
111
+            add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
112 112
 
113
-            if ( $nopriv ) {
114
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
115
-                add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
116
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
113
+            if ($nopriv) {
114
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
115
+                add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
116
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
117 117
             }
118 118
         }
119 119
     }
120 120
     
121 121
     public static function add_note() {
122
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
122
+        check_ajax_referer('add-invoice-note', '_nonce');
123 123
 
124
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
124
+        if (!wpinv_current_user_can_manage_invoicing()) {
125 125
             die(-1);
126 126
         }
127 127
 
128
-        $post_id   = absint( $_POST['post_id'] );
129
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
130
-        $note_type = sanitize_text_field( $_POST['note_type'] );
128
+        $post_id   = absint($_POST['post_id']);
129
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
130
+        $note_type = sanitize_text_field($_POST['note_type']);
131 131
 
132 132
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
133 133
 
134
-        if ( $post_id > 0 ) {
135
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
134
+        if ($post_id > 0) {
135
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
136 136
 
137
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
138
-                wpinv_get_invoice_note_line_item( $note_id );
137
+            if ($note_id > 0 && !is_wp_error($note_id)) {
138
+                wpinv_get_invoice_note_line_item($note_id);
139 139
             }
140 140
         }
141 141
 
@@ -143,16 +143,16 @@  discard block
 block discarded – undo
143 143
     }
144 144
 
145 145
     public static function delete_note() {
146
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
146
+        check_ajax_referer('delete-invoice-note', '_nonce');
147 147
 
148
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
148
+        if (!wpinv_current_user_can_manage_invoicing()) {
149 149
             die(-1);
150 150
         }
151 151
 
152
-        $note_id = (int)$_POST['note_id'];
152
+        $note_id = (int) $_POST['note_id'];
153 153
 
154
-        if ( $note_id > 0 ) {
155
-            wp_delete_comment( $note_id, true );
154
+        if ($note_id > 0) {
155
+            wp_delete_comment($note_id, true);
156 156
         }
157 157
 
158 158
         die();
@@ -170,34 +170,34 @@  discard block
 block discarded – undo
170 170
     public static function get_billing_details() {
171 171
 
172 172
         // Verify nonce.
173
-        check_ajax_referer( 'wpinv-nonce' );
173
+        check_ajax_referer('wpinv-nonce');
174 174
 
175 175
         // Can the user manage the plugin?
176
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
176
+        if (!wpinv_current_user_can_manage_invoicing()) {
177 177
             die(-1);
178 178
         }
179 179
 
180 180
         // Do we have a user id?
181 181
         $user_id = (int) $_GET['user_id'];
182 182
 
183
-        if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
183
+        if (empty($user_id) || !is_numeric($user_id)) {
184 184
             die(-1);
185 185
         }
186 186
 
187 187
         // Fetch the billing details.
188
-        $billing_details    = wpinv_get_user_address( $user_id );
189
-        $billing_details    = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id );
188
+        $billing_details    = wpinv_get_user_address($user_id);
189
+        $billing_details    = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id);
190 190
 
191 191
         // unset the user id and email.
192
-        $to_ignore = array( 'user_id', 'email' );
192
+        $to_ignore = array('user_id', 'email');
193 193
 
194
-        foreach ( $to_ignore as $key ) {
195
-            if ( isset( $billing_details[ $key ] ) ) {
196
-                unset( $billing_details[ $key ] );
194
+        foreach ($to_ignore as $key) {
195
+            if (isset($billing_details[$key])) {
196
+                unset($billing_details[$key]);
197 197
             }
198 198
         }
199 199
 
200
-        wp_send_json_success( $billing_details );
200
+        wp_send_json_success($billing_details);
201 201
 
202 202
     }
203 203
 
@@ -207,47 +207,47 @@  discard block
 block discarded – undo
207 207
     public static function check_new_user_email() {
208 208
 
209 209
         // Verify nonce.
210
-        check_ajax_referer( 'wpinv-nonce' );
210
+        check_ajax_referer('wpinv-nonce');
211 211
 
212 212
         // Can the user manage the plugin?
213
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
213
+        if (!wpinv_current_user_can_manage_invoicing()) {
214 214
             die(-1);
215 215
         }
216 216
 
217 217
         // We need an email address.
218
-        if ( empty( $_GET['email'] ) ) {
219
-            _e( "Provide the new user's email address", 'invoicing' );
218
+        if (empty($_GET['email'])) {
219
+            _e("Provide the new user's email address", 'invoicing');
220 220
             exit;
221 221
         }
222 222
 
223 223
         // Ensure the email is valid.
224
-        $email = sanitize_email( $_GET['email'] );
225
-        if ( ! is_email( $email ) ) {
226
-            _e( 'Invalid email address', 'invoicing' );
224
+        $email = sanitize_email($_GET['email']);
225
+        if (!is_email($email)) {
226
+            _e('Invalid email address', 'invoicing');
227 227
             exit;
228 228
         }
229 229
 
230 230
         // And it does not exist.
231
-        $id = email_exists( $email );
232
-        if ( $id ) {
233
-            wp_send_json_success( compact( 'id' ) );
231
+        $id = email_exists($email);
232
+        if ($id) {
233
+            wp_send_json_success(compact('id'));
234 234
         }
235 235
 
236
-        wp_send_json_success( true );
236
+        wp_send_json_success(true);
237 237
     }
238 238
     
239 239
     public static function run_tool() {
240
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
241
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
240
+        check_ajax_referer('wpinv-nonce', '_nonce');
241
+        if (!wpinv_current_user_can_manage_invoicing()) {
242 242
             die(-1);
243 243
         }
244 244
         
245
-        $tool = sanitize_text_field( $_POST['tool'] );
245
+        $tool = sanitize_text_field($_POST['tool']);
246 246
         
247
-        do_action( 'wpinv_run_tool' );
247
+        do_action('wpinv_run_tool');
248 248
         
249
-        if ( !empty( $tool ) ) {
250
-            do_action( 'wpinv_tool_' . $tool );
249
+        if (!empty($tool)) {
250
+            do_action('wpinv_tool_' . $tool);
251 251
         }
252 252
     }
253 253
 
@@ -258,43 +258,43 @@  discard block
 block discarded – undo
258 258
         global $getpaid_force_checkbox;
259 259
 
260 260
         // Check nonce.
261
-        check_ajax_referer( 'getpaid_form_nonce' );
261
+        check_ajax_referer('getpaid_form_nonce');
262 262
 
263 263
         // Is the request set up correctly?
264
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) {
264
+		if (empty($_GET['form']) && empty($_GET['item']) && empty($_GET['invoice'])) {
265 265
 			echo aui()->alert(
266 266
 				array(
267 267
 					'type'    => 'warning',
268
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
268
+					'content' => __('No payment form or item provided', 'invoicing'),
269 269
 				)
270 270
             );
271 271
             exit;
272 272
         }
273 273
 
274 274
         // Payment form or button?
275
-		if ( ! empty( $_GET['form'] ) ) {
276
-            $form = sanitize_text_field( urldecode( $_GET['form'] ) );
275
+		if (!empty($_GET['form'])) {
276
+            $form = sanitize_text_field(urldecode($_GET['form']));
277 277
 
278
-            if ( false !== strpos( $form, '|' ) ) {
279
-                $form_pos = strpos( $form, '|' );
280
-                $_items   = getpaid_convert_items_to_array( substr( $form, $form_pos + 1 ) );
281
-                $form     = substr( $form, 0, $form_pos );
278
+            if (false !== strpos($form, '|')) {
279
+                $form_pos = strpos($form, '|');
280
+                $_items   = getpaid_convert_items_to_array(substr($form, $form_pos + 1));
281
+                $form     = substr($form, 0, $form_pos);
282 282
 
283 283
                 // Retrieve appropriate payment form.
284
-                $payment_form = new GetPaid_Payment_Form( $form );
285
-                $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
284
+                $payment_form = new GetPaid_Payment_Form($form);
285
+                $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form());
286 286
 
287 287
                 $items    = array();
288 288
                 $item_ids = array();
289 289
 
290
-                foreach ( $_items as $item_id => $qty ) {
291
-                    if ( ! in_array( $item_id, $item_ids ) ) {
292
-                        $item = new GetPaid_Form_Item( $item_id );
293
-                        $item->set_quantity( $qty );
290
+                foreach ($_items as $item_id => $qty) {
291
+                    if (!in_array($item_id, $item_ids)) {
292
+                        $item = new GetPaid_Form_Item($item_id);
293
+                        $item->set_quantity($qty);
294 294
 
295
-                        if ( 0 == $qty ) {
296
-                            $item->set_allow_quantities( true );
297
-                            $item->set_is_required( false );
295
+                        if (0 == $qty) {
296
+                            $item->set_allow_quantities(true);
297
+                            $item->set_is_required(false);
298 298
                             $getpaid_force_checkbox = true;
299 299
                         }
300 300
 
@@ -303,10 +303,10 @@  discard block
 block discarded – undo
303 303
                     }
304 304
                 }
305 305
 
306
-                if ( ! $payment_form->is_default() ) {
306
+                if (!$payment_form->is_default()) {
307 307
 
308
-                    foreach ( $payment_form->get_items() as $item ) {
309
-                        if ( ! in_array( $item->get_id(), $item_ids ) ) {
308
+                    foreach ($payment_form->get_items() as $item) {
309
+                        if (!in_array($item->get_id(), $item_ids)) {
310 310
                             $item_ids[] = $item->get_id();
311 311
                             $items[]    = $item;
312 312
                         }
@@ -314,23 +314,23 @@  discard block
 block discarded – undo
314 314
 
315 315
                 }
316 316
 
317
-                $payment_form->set_items( $items );
318
-                $extra_items     = esc_attr( getpaid_convert_items_to_string( $_items ) );
319
-                $extra_items_key = md5( NONCE_KEY . AUTH_KEY . $extra_items );
317
+                $payment_form->set_items($items);
318
+                $extra_items     = esc_attr(getpaid_convert_items_to_string($_items));
319
+                $extra_items_key = md5(NONCE_KEY . AUTH_KEY . $extra_items);
320 320
                 $extra_items     = "<input type='hidden' name='getpaid-form-items' value='$extra_items' />";
321 321
                 $extra_items    .= "<input type='hidden' name='getpaid-form-items-key' value='$extra_items_key' />";
322
-                $payment_form->display( $extra_items );
322
+                $payment_form->display($extra_items);
323 323
                 $getpaid_force_checkbox = false;
324 324
 
325 325
             } else {
326
-                getpaid_display_payment_form( $form );
326
+                getpaid_display_payment_form($form);
327 327
             }
328 328
 
329
-		} else if( ! empty( $_GET['invoice'] ) ) {
330
-		    getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) );
329
+		} else if (!empty($_GET['invoice'])) {
330
+		    getpaid_display_invoice_payment_form((int) urldecode($_GET['invoice']));
331 331
         } else {
332
-			$items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) );
333
-		    getpaid_display_item_payment_form( $items );
332
+			$items = getpaid_convert_items_to_array(sanitize_text_field(urldecode($_GET['item'])));
333
+		    getpaid_display_item_payment_form($items);
334 334
         }
335 335
 
336 336
         exit;
@@ -345,17 +345,17 @@  discard block
 block discarded – undo
345 345
     public static function payment_form() {
346 346
 
347 347
         // Check nonce.
348
-        check_ajax_referer( 'getpaid_form_nonce' );
348
+        check_ajax_referer('getpaid_form_nonce');
349 349
 
350 350
         // ... form fields...
351
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
352
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
351
+        if (empty($_POST['getpaid_payment_form_submission'])) {
352
+            _e('Error: Reload the page and try again.', 'invoicing');
353 353
             exit;
354 354
         }
355 355
 
356 356
         // Process the payment form.
357
-        $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' );
358
-        $checkout       = new $checkout_class( new GetPaid_Payment_Form_Submission() );
357
+        $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout');
358
+        $checkout       = new $checkout_class(new GetPaid_Payment_Form_Submission());
359 359
         $checkout->process_checkout();
360 360
 
361 361
         exit;
@@ -368,55 +368,55 @@  discard block
 block discarded – undo
368 368
      */
369 369
     public static function get_payment_form_states_field() {
370 370
 
371
-        if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) {
371
+        if (empty($_GET['country']) || empty($_GET['form'])) {
372 372
             exit;
373 373
         }
374 374
 
375
-        $elements = getpaid_get_payment_form_elements( (int) $_GET['form'] );
375
+        $elements = getpaid_get_payment_form_elements((int) $_GET['form']);
376 376
 
377
-        if ( empty( $elements ) ) {
377
+        if (empty($elements)) {
378 378
             exit;
379 379
         }
380 380
 
381 381
         $address_fields = array();
382
-        foreach ( $elements as $element ) {
383
-            if ( 'address' === $element['type'] ) {
382
+        foreach ($elements as $element) {
383
+            if ('address' === $element['type']) {
384 384
                 $address_fields = $element;
385 385
                 break;
386 386
             }
387 387
         }
388 388
 
389
-        if ( empty( $address_fields ) ) {
389
+        if (empty($address_fields)) {
390 390
             exit;
391 391
         }
392 392
 
393
-        foreach ( $address_fields['fields'] as $address_field ) {
393
+        foreach ($address_fields['fields'] as $address_field) {
394 394
 
395
-            if ( 'wpinv_state' == $address_field['name'] ) {
395
+            if ('wpinv_state' == $address_field['name']) {
396 396
 
397
-                $wrap_class  = getpaid_get_form_element_grid_class( $address_field );
398
-                $wrap_class  = esc_attr( "$wrap_class getpaid-address-field-wrapper" );
399
-                $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] );
400
-                $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] );
401
-                $value       = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : '';
402
-                $label       = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] );
397
+                $wrap_class  = getpaid_get_form_element_grid_class($address_field);
398
+                $wrap_class  = esc_attr("$wrap_class getpaid-address-field-wrapper");
399
+                $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']);
400
+                $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']);
401
+                $value       = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : '';
402
+                $label       = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']);
403 403
 
404
-                if ( ! empty( $address_field['required'] ) ) {
404
+                if (!empty($address_field['required'])) {
405 405
                     $label .= "<span class='text-danger'> *</span>";
406 406
                 }
407 407
 
408
-                $html = getpaid_get_states_select_markup (
409
-                    sanitize_text_field( $_GET['country'] ),
408
+                $html = getpaid_get_states_select_markup(
409
+                    sanitize_text_field($_GET['country']),
410 410
                     $value,
411 411
                     $placeholder,
412 412
                     $label,
413 413
                     $description,
414
-                    ! empty( $address_field['required'] ),
414
+                    !empty($address_field['required']),
415 415
                     $wrap_class,
416
-                    sanitize_text_field( $_GET['name'] )
416
+                    sanitize_text_field($_GET['name'])
417 417
                 );
418 418
 
419
-                wp_send_json_success( $html );
419
+                wp_send_json_success($html);
420 420
                 exit;
421 421
 
422 422
             }
@@ -432,66 +432,66 @@  discard block
 block discarded – undo
432 432
     public static function recalculate_invoice_totals() {
433 433
 
434 434
         // Verify nonce.
435
-        check_ajax_referer( 'wpinv-nonce' );
435
+        check_ajax_referer('wpinv-nonce');
436 436
 
437
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
437
+        if (!wpinv_current_user_can_manage_invoicing()) {
438 438
             exit;
439 439
         }
440 440
 
441 441
         // We need an invoice.
442
-        if ( empty( $_POST['post_id'] ) ) {
442
+        if (empty($_POST['post_id'])) {
443 443
             exit;
444 444
         }
445 445
 
446 446
         // Fetch the invoice.
447
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
447
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
448 448
 
449 449
         // Ensure it exists.
450
-        if ( ! $invoice->get_id() ) {
450
+        if (!$invoice->get_id()) {
451 451
             exit;
452 452
         }
453 453
 
454 454
         // Maybe set the country, state, currency.
455
-        foreach ( array( 'country', 'state', 'currency', 'vat_number', 'discount_code' ) as $key ) {
456
-            if ( isset( $_POST[ $key ] ) ) {
455
+        foreach (array('country', 'state', 'currency', 'vat_number', 'discount_code') as $key) {
456
+            if (isset($_POST[$key])) {
457 457
                 $method = "set_$key";
458
-                $invoice->$method( sanitize_text_field( $_POST[ $key ] ) );
458
+                $invoice->$method(sanitize_text_field($_POST[$key]));
459 459
             }
460 460
         }
461 461
 
462 462
         // Maybe disable taxes.
463
-        $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) );
463
+        $invoice->set_disable_taxes(!empty($_POST['taxes']));
464 464
 
465 465
         // Discount code.
466
-        if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
467
-            $discount = new WPInv_Discount( $invoice->get_discount_code() );
468
-            if ( $discount->exists() ) {
469
-                $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
466
+        if (!$invoice->is_paid() && !$invoice->is_refunded()) {
467
+            $discount = new WPInv_Discount($invoice->get_discount_code());
468
+            if ($discount->exists()) {
469
+                $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
470 470
             } else {
471
-                $invoice->remove_discount( 'discount_code' );
471
+                $invoice->remove_discount('discount_code');
472 472
             }
473 473
         }
474 474
 
475 475
         // Recalculate totals.
476 476
         $invoice->recalculate_total();
477 477
 
478
-        $total        = wpinv_price( $invoice->get_total(), $invoice->get_currency() );
479
-        $suscriptions = getpaid_get_invoice_subscriptions( $invoice );
480
-        if ( is_a( $suscriptions, 'WPInv_Subscription' ) && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) {
481
-            $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() );
482
-            $total          .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>';
478
+        $total        = wpinv_price($invoice->get_total(), $invoice->get_currency());
479
+        $suscriptions = getpaid_get_invoice_subscriptions($invoice);
480
+        if (is_a($suscriptions, 'WPInv_Subscription') && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) {
481
+            $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency());
482
+            $total          .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>';
483 483
         }
484 484
 
485 485
         $totals = array(
486
-            'subtotal' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ),
487
-            'discount' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ),
488
-            'tax'      => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ),
486
+            'subtotal' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()),
487
+            'discount' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()),
488
+            'tax'      => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()),
489 489
             'total'    => $total,
490 490
         );
491 491
 
492
-        $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice );
492
+        $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice);
493 493
 
494
-        wp_send_json_success( compact( 'totals' ) );
494
+        wp_send_json_success(compact('totals'));
495 495
     }
496 496
 
497 497
     /**
@@ -500,33 +500,33 @@  discard block
 block discarded – undo
500 500
     public static function get_invoice_items() {
501 501
 
502 502
         // Verify nonce.
503
-        check_ajax_referer( 'wpinv-nonce' );
503
+        check_ajax_referer('wpinv-nonce');
504 504
 
505
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
505
+        if (!wpinv_current_user_can_manage_invoicing()) {
506 506
             exit;
507 507
         }
508 508
 
509 509
         // We need an invoice and items.
510
-        if ( empty( $_POST['post_id'] ) ) {
510
+        if (empty($_POST['post_id'])) {
511 511
             exit;
512 512
         }
513 513
 
514 514
         // Fetch the invoice.
515
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
515
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
516 516
 
517 517
         // Ensure it exists.
518
-        if ( ! $invoice->get_id() ) {
518
+        if (!$invoice->get_id()) {
519 519
             exit;
520 520
         }
521 521
 
522 522
         // Return an array of invoice items.
523 523
         $items = array();
524 524
 
525
-        foreach ( $invoice->get_items() as $item ) {
526
-            $items[] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency(), $invoice->is_renewal()  );
525
+        foreach ($invoice->get_items() as $item) {
526
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency(), $invoice->is_renewal());
527 527
         }
528 528
 
529
-        wp_send_json_success( compact( 'items' ) );
529
+        wp_send_json_success(compact('items'));
530 530
     }
531 531
 
532 532
     /**
@@ -535,50 +535,50 @@  discard block
 block discarded – undo
535 535
     public static function edit_invoice_item() {
536 536
 
537 537
         // Verify nonce.
538
-        check_ajax_referer( 'wpinv-nonce' );
538
+        check_ajax_referer('wpinv-nonce');
539 539
 
540
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
540
+        if (!wpinv_current_user_can_manage_invoicing()) {
541 541
             exit;
542 542
         }
543 543
 
544 544
         // We need an invoice and item details.
545
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) {
545
+        if (empty($_POST['post_id']) || empty($_POST['data'])) {
546 546
             exit;
547 547
         }
548 548
 
549 549
         // Fetch the invoice.
550
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
550
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
551 551
 
552 552
         // Ensure it exists and its not been paid for.
553
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
553
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
554 554
             exit;
555 555
         }
556 556
 
557 557
         // Format the data.
558
-        $data = wp_kses_post_deep( wp_unslash( wp_list_pluck( $_POST['data'], 'value', 'field' ) ) );
558
+        $data = wp_kses_post_deep(wp_unslash(wp_list_pluck($_POST['data'], 'value', 'field')));
559 559
 
560 560
         // Ensure that we have an item id.
561
-        if ( empty( $data['id'] ) ) {
561
+        if (empty($data['id'])) {
562 562
             exit;
563 563
         }
564 564
 
565 565
         // Abort if the invoice does not have the specified item.
566
-        $item = $invoice->get_item( (int) $data['id'] );
566
+        $item = $invoice->get_item((int) $data['id']);
567 567
 
568
-        if ( empty( $item ) ) {
568
+        if (empty($item)) {
569 569
             exit;
570 570
         }
571 571
 
572 572
         // Update the item.
573
-        $item->set_price( getpaid_standardize_amount( $data['price'] ) );
574
-        $item->set_name( sanitize_text_field( $data['name'] ) );
575
-        $item->set_description( wp_kses_post( $data['description'] ) );
576
-        $item->set_quantity( floatval( $data['quantity'] ) );
573
+        $item->set_price(getpaid_standardize_amount($data['price']));
574
+        $item->set_name(sanitize_text_field($data['name']));
575
+        $item->set_description(wp_kses_post($data['description']));
576
+        $item->set_quantity(floatval($data['quantity']));
577 577
 
578 578
         // Add it to the invoice.
579
-        $error = $invoice->add_item( $item );
579
+        $error = $invoice->add_item($item);
580 580
         $alert = false;
581
-        if ( is_wp_error( $error ) ) {
581
+        if (is_wp_error($error)) {
582 582
             $alert = $error->get_error_message();
583 583
         }
584 584
 
@@ -591,11 +591,11 @@  discard block
 block discarded – undo
591 591
         // Return an array of invoice items.
592 592
         $items = array();
593 593
 
594
-        foreach ( $invoice->get_items() as $item ) {
595
-            $items[] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
594
+        foreach ($invoice->get_items() as $item) {
595
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
596 596
         }
597 597
 
598
-        wp_send_json_success( compact( 'items', 'alert' ) );
598
+        wp_send_json_success(compact('items', 'alert'));
599 599
     }
600 600
 
601 601
     /**
@@ -604,53 +604,53 @@  discard block
 block discarded – undo
604 604
     public static function create_invoice_item() {
605 605
 
606 606
         // Verify nonce.
607
-        check_ajax_referer( 'wpinv-nonce' );
607
+        check_ajax_referer('wpinv-nonce');
608 608
 
609
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
609
+        if (!wpinv_current_user_can_manage_invoicing()) {
610 610
             exit;
611 611
         }
612 612
 
613 613
         // We need an invoice and item details.
614
-        if ( empty( $_POST['invoice_id'] ) || empty( $_POST['_wpinv_quick'] ) ) {
614
+        if (empty($_POST['invoice_id']) || empty($_POST['_wpinv_quick'])) {
615 615
             exit;
616 616
         }
617 617
 
618 618
         // Fetch the invoice.
619
-        $invoice = new WPInv_Invoice( intval( $_POST['invoice_id'] ) );
619
+        $invoice = new WPInv_Invoice(intval($_POST['invoice_id']));
620 620
 
621 621
         // Ensure it exists and its not been paid for.
622
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
622
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
623 623
             exit;
624 624
         }
625 625
 
626 626
         // Format the data.
627
-        $data = wp_kses_post_deep( wp_unslash( $_POST['_wpinv_quick'] ) );
627
+        $data = wp_kses_post_deep(wp_unslash($_POST['_wpinv_quick']));
628 628
 
629 629
         $item = new WPInv_Item();
630
-        $item->set_price( getpaid_standardize_amount( $data['price'] ) );
631
-        $item->set_name( sanitize_text_field( $data['name'] ) );
632
-        $item->set_description( wp_kses_post( $data['description'] ) );
633
-        $item->set_type( sanitize_text_field( $data['type'] ) );
634
-        $item->set_vat_rule( sanitize_text_field( $data['vat_rule'] ) );
635
-        $item->set_vat_class( sanitize_text_field( $data['vat_class'] ) );
636
-        $item->set_status( 'publish' );
630
+        $item->set_price(getpaid_standardize_amount($data['price']));
631
+        $item->set_name(sanitize_text_field($data['name']));
632
+        $item->set_description(wp_kses_post($data['description']));
633
+        $item->set_type(sanitize_text_field($data['type']));
634
+        $item->set_vat_rule(sanitize_text_field($data['vat_rule']));
635
+        $item->set_vat_class(sanitize_text_field($data['vat_class']));
636
+        $item->set_status('publish');
637 637
         $item->save();
638 638
 
639
-        if ( ! $item->exists() ) {
640
-            $alert = __( 'Could not create invoice item. Please try again.', 'invoicing' );
641
-            wp_send_json_success( compact( 'alert' ) );
639
+        if (!$item->exists()) {
640
+            $alert = __('Could not create invoice item. Please try again.', 'invoicing');
641
+            wp_send_json_success(compact('alert'));
642 642
         }
643 643
 
644
-        $item = new GetPaid_Form_Item( $item->get_id() );
645
-        $item->set_quantity( floatval( $data['qty'] ) );
644
+        $item = new GetPaid_Form_Item($item->get_id());
645
+        $item->set_quantity(floatval($data['qty']));
646 646
 
647 647
         // Add it to the invoice.
648
-        $error = $invoice->add_item( $item );
648
+        $error = $invoice->add_item($item);
649 649
         $alert = false;
650 650
 
651
-        if ( is_wp_error( $error ) ) {
651
+        if (is_wp_error($error)) {
652 652
             $alert = $error->get_error_message();
653
-            wp_send_json_success( compact( 'alert' ) );
653
+            wp_send_json_success(compact('alert'));
654 654
          }
655 655
 
656 656
         // Update totals.
@@ -663,9 +663,9 @@  discard block
 block discarded – undo
663 663
         $invoice->recalculate_total();
664 664
         $invoice->save();
665 665
         ob_start();
666
-        GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice );
666
+        GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice);
667 667
         $row = ob_get_clean();
668
-        wp_send_json_success( compact( 'row' ) );
668
+        wp_send_json_success(compact('row'));
669 669
     }
670 670
 
671 671
     /**
@@ -674,33 +674,33 @@  discard block
 block discarded – undo
674 674
     public static function remove_invoice_item() {
675 675
 
676 676
         // Verify nonce.
677
-        check_ajax_referer( 'wpinv-nonce' );
677
+        check_ajax_referer('wpinv-nonce');
678 678
 
679
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
679
+        if (!wpinv_current_user_can_manage_invoicing()) {
680 680
             exit;
681 681
         }
682 682
 
683 683
         // We need an invoice and an item.
684
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) {
684
+        if (empty($_POST['post_id']) || empty($_POST['item_id'])) {
685 685
             exit;
686 686
         }
687 687
 
688 688
         // Fetch the invoice.
689
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
689
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
690 690
 
691 691
         // Ensure it exists and its not been paid for.
692
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
692
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
693 693
             exit;
694 694
         }
695 695
 
696 696
         // Abort if the invoice does not have the specified item.
697
-        $item = $invoice->get_item( (int) $_POST['item_id'] );
697
+        $item = $invoice->get_item((int) $_POST['item_id']);
698 698
 
699
-        if ( empty( $item ) ) {
699
+        if (empty($item)) {
700 700
             exit;
701 701
         }
702 702
 
703
-        $invoice->remove_item( (int) $_POST['item_id'] );
703
+        $invoice->remove_item((int) $_POST['item_id']);
704 704
 
705 705
         // Update totals.
706 706
         $invoice->recalculate_total();
@@ -711,11 +711,11 @@  discard block
 block discarded – undo
711 711
         // Return an array of invoice items.
712 712
         $items = array();
713 713
 
714
-        foreach ( $invoice->get_items() as $item ) {
715
-            $items[] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
714
+        foreach ($invoice->get_items() as $item) {
715
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
716 716
         }
717 717
 
718
-        wp_send_json_success( compact( 'items' ) );
718
+        wp_send_json_success(compact('items'));
719 719
     }
720 720
 
721 721
     /**
@@ -724,69 +724,69 @@  discard block
 block discarded – undo
724 724
     public static function recalculate_full_prices() {
725 725
 
726 726
         // Verify nonce.
727
-        check_ajax_referer( 'wpinv-nonce' );
727
+        check_ajax_referer('wpinv-nonce');
728 728
 
729
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
729
+        if (!wpinv_current_user_can_manage_invoicing()) {
730 730
             exit;
731 731
         }
732 732
 
733 733
         // We need an invoice and item.
734
-        if ( empty( $_POST['post_id'] ) ) {
734
+        if (empty($_POST['post_id'])) {
735 735
             exit;
736 736
         }
737 737
 
738 738
         // Fetch the invoice.
739
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
739
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
740 740
         $alert   = false;
741 741
 
742 742
         // Ensure it exists and its not been paid for.
743
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
743
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
744 744
             exit;
745 745
         }
746 746
 
747
-        $invoice->set_items( array() );
747
+        $invoice->set_items(array());
748 748
 
749
-        if ( ! empty( $_POST['getpaid_items'] ) ) {
749
+        if (!empty($_POST['getpaid_items'])) {
750 750
 
751
-            foreach ( wp_kses_post_deep( $_POST['getpaid_items'] ) as $item_id => $args ) {
752
-                $item = new GetPaid_Form_Item( $item_id );
751
+            foreach (wp_kses_post_deep($_POST['getpaid_items']) as $item_id => $args) {
752
+                $item = new GetPaid_Form_Item($item_id);
753 753
 
754
-                if ( $item->exists() ) {
755
-                    $item->set_price( getpaid_standardize_amount( $args['price'] ) );
756
-                    $item->set_quantity( floatval( $args['quantity'] ) );
757
-                    $item->set_name( sanitize_text_field( $args['name'] ) );
758
-                    $item->set_description( wp_kses_post( $args['description'] ) );
759
-                    $invoice->add_item( $item );
754
+                if ($item->exists()) {
755
+                    $item->set_price(getpaid_standardize_amount($args['price']));
756
+                    $item->set_quantity(floatval($args['quantity']));
757
+                    $item->set_name(sanitize_text_field($args['name']));
758
+                    $item->set_description(wp_kses_post($args['description']));
759
+                    $invoice->add_item($item);
760 760
                 }
761 761
             }
762 762
 
763 763
         }
764 764
 
765
-        $invoice->set_disable_taxes( ! empty( $_POST['disable_taxes'] ) );
765
+        $invoice->set_disable_taxes(!empty($_POST['disable_taxes']));
766 766
 
767 767
         // Maybe set the country, state, currency.
768
-        foreach ( array( 'wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code' ) as $key ) {
769
-            if ( isset( $_POST[ $key ] ) ) {
770
-                $_key   = str_replace( 'wpinv_', '', $key );
768
+        foreach (array('wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code') as $key) {
769
+            if (isset($_POST[$key])) {
770
+                $_key   = str_replace('wpinv_', '', $key);
771 771
                 $method = "set_$_key";
772
-                $invoice->$method( sanitize_text_field( $_POST[ $key ] ) );
772
+                $invoice->$method(sanitize_text_field($_POST[$key]));
773 773
             }
774 774
         }
775 775
 
776
-        $discount = new WPInv_Discount( $invoice->get_discount_code() );
777
-        if ( $discount->exists() ) {
778
-            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
776
+        $discount = new WPInv_Discount($invoice->get_discount_code());
777
+        if ($discount->exists()) {
778
+            $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
779 779
         } else {
780
-            $invoice->remove_discount( 'discount_code' );
780
+            $invoice->remove_discount('discount_code');
781 781
         }
782 782
 
783 783
         // Save the invoice.
784 784
         $invoice->recalculate_total();
785 785
         $invoice->save();
786 786
         ob_start();
787
-        GetPaid_Meta_Box_Invoice_Items::output( get_post( $invoice->get_id() ), $invoice );
787
+        GetPaid_Meta_Box_Invoice_Items::output(get_post($invoice->get_id()), $invoice);
788 788
         $table = ob_get_clean();
789
-        wp_send_json_success( compact( 'table' ) );
789
+        wp_send_json_success(compact('table'));
790 790
     }
791 791
 
792 792
     /**
@@ -795,42 +795,42 @@  discard block
 block discarded – undo
795 795
     public static function admin_add_invoice_item() {
796 796
 
797 797
         // Verify nonce.
798
-        check_ajax_referer( 'wpinv-nonce' );
798
+        check_ajax_referer('wpinv-nonce');
799 799
 
800
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
800
+        if (!wpinv_current_user_can_manage_invoicing()) {
801 801
             exit;
802 802
         }
803 803
 
804 804
         // We need an invoice and item.
805
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) {
805
+        if (empty($_POST['post_id']) || empty($_POST['item_id'])) {
806 806
             exit;
807 807
         }
808 808
 
809 809
         // Fetch the invoice.
810
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
810
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
811 811
         $alert   = false;
812 812
 
813 813
         // Ensure it exists and its not been paid for.
814
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
814
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
815 815
             exit;
816 816
         }
817 817
 
818 818
         // Add the item.
819
-        $item  = new GetPaid_Form_Item( (int) $_POST['item_id'] );
820
-        $error = $invoice->add_item( $item );
819
+        $item  = new GetPaid_Form_Item((int) $_POST['item_id']);
820
+        $error = $invoice->add_item($item);
821 821
 
822
-        if ( is_wp_error( $error ) ) {
822
+        if (is_wp_error($error)) {
823 823
             $alert = $error->get_error_message();
824
-            wp_send_json_success( compact( 'alert' ) );
824
+            wp_send_json_success(compact('alert'));
825 825
         }
826 826
 
827 827
         // Save the invoice.
828 828
         $invoice->recalculate_total();
829 829
         $invoice->save();
830 830
         ob_start();
831
-        GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice );
831
+        GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice);
832 832
         $row = ob_get_clean();
833
-        wp_send_json_success( compact( 'row' ) );
833
+        wp_send_json_success(compact('row'));
834 834
     }
835 835
 
836 836
     /**
@@ -839,39 +839,39 @@  discard block
 block discarded – undo
839 839
     public static function add_invoice_items() {
840 840
 
841 841
         // Verify nonce.
842
-        check_ajax_referer( 'wpinv-nonce' );
842
+        check_ajax_referer('wpinv-nonce');
843 843
 
844
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
844
+        if (!wpinv_current_user_can_manage_invoicing()) {
845 845
             exit;
846 846
         }
847 847
 
848 848
         // We need an invoice and items.
849
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) {
849
+        if (empty($_POST['post_id']) || empty($_POST['items'])) {
850 850
             exit;
851 851
         }
852 852
 
853 853
         // Fetch the invoice.
854
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
854
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
855 855
         $alert   = false;
856 856
 
857 857
         // Ensure it exists and its not been paid for.
858
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
858
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
859 859
             exit;
860 860
         }
861 861
 
862 862
         // Add the items.
863
-        foreach ( wp_kses_post_deep( wp_unslash( $_POST['items'] ) ) as $data ) {
863
+        foreach (wp_kses_post_deep(wp_unslash($_POST['items'])) as $data) {
864 864
 
865
-            $item = new GetPaid_Form_Item( (int) $data[ 'id' ] );
865
+            $item = new GetPaid_Form_Item((int) $data['id']);
866 866
 
867
-            if ( is_numeric( $data[ 'qty' ] ) && (float) $data[ 'qty' ] > 0 ) {
868
-                $item->set_quantity( floatval( $data[ 'qty' ] ) );
867
+            if (is_numeric($data['qty']) && (float) $data['qty'] > 0) {
868
+                $item->set_quantity(floatval($data['qty']));
869 869
             }
870 870
 
871
-            if ( $item->get_id() > 0 ) {
872
-                $error = $invoice->add_item( $item );
871
+            if ($item->get_id() > 0) {
872
+                $error = $invoice->add_item($item);
873 873
 
874
-                if ( is_wp_error( $error ) ) {
874
+                if (is_wp_error($error)) {
875 875
                     $alert = $error->get_error_message();
876 876
                 }
877 877
 
@@ -886,11 +886,11 @@  discard block
 block discarded – undo
886 886
         // Return an array of invoice items.
887 887
         $items = array();
888 888
 
889
-        foreach ( $invoice->get_items() as $item ) {
890
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
889
+        foreach ($invoice->get_items() as $item) {
890
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
891 891
         }
892 892
 
893
-        wp_send_json_success( compact( 'items', 'alert' ) );
893
+        wp_send_json_success(compact('items', 'alert'));
894 894
     }
895 895
 
896 896
     /**
@@ -899,15 +899,15 @@  discard block
 block discarded – undo
899 899
     public static function get_invoicing_items() {
900 900
 
901 901
         // Verify nonce.
902
-        check_ajax_referer( 'wpinv-nonce' );
902
+        check_ajax_referer('wpinv-nonce');
903 903
 
904
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
904
+        if (!wpinv_current_user_can_manage_invoicing()) {
905 905
             exit;
906 906
         }
907 907
 
908 908
         // We need a search term.
909
-        if ( empty( $_GET['search'] ) ) {
910
-            wp_send_json_success( array() );
909
+        if (empty($_GET['search'])) {
910
+            wp_send_json_success(array());
911 911
         }
912 912
 
913 913
         // Retrieve items.
@@ -916,8 +916,8 @@  discard block
 block discarded – undo
916 916
             'orderby'        => 'title',
917 917
             'order'          => 'ASC',
918 918
             'posts_per_page' => -1,
919
-            'post_status'    => array( 'publish' ),
920
-            's'              => sanitize_text_field( urldecode( $_GET['search'] ) ),
919
+            'post_status'    => array('publish'),
920
+            's'              => sanitize_text_field(urldecode($_GET['search'])),
921 921
             'meta_query'     => array(
922 922
                 array(
923 923
                     'key'       => '_wpinv_type',
@@ -927,25 +927,25 @@  discard block
 block discarded – undo
927 927
             )
928 928
         );
929 929
 
930
-        if ( ! empty( $_GET['ignore'] ) ) {
931
-            $item_args['exclude'] = wp_parse_id_list( sanitize_text_field( $_GET['ignore'] ) );
930
+        if (!empty($_GET['ignore'])) {
931
+            $item_args['exclude'] = wp_parse_id_list(sanitize_text_field($_GET['ignore']));
932 932
         }
933 933
 
934
-        $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) );
934
+        $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args));
935 935
         $data  = array();
936 936
 
937
-        $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( (int) $_GET['post_id'] ) );
937
+        $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type((int) $_GET['post_id']));
938 938
 
939
-        foreach ( $items as $item ) {
940
-            $item      = new GetPaid_Form_Item( $item );
939
+        foreach ($items as $item) {
940
+            $item = new GetPaid_Form_Item($item);
941 941
             $data[] = array(
942 942
                 'id'        => (int) $item->get_id(),
943
-                'text'      => strip_tags( $item->get_name() ),
944
-                'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '',
943
+                'text'      => strip_tags($item->get_name()),
944
+                'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '',
945 945
             );
946 946
         }
947 947
 
948
-        wp_send_json_success( $data );
948
+        wp_send_json_success($data);
949 949
 
950 950
     }
951 951
 
@@ -955,37 +955,37 @@  discard block
 block discarded – undo
955 955
     public static function get_customers() {
956 956
 
957 957
         // Verify nonce.
958
-        check_ajax_referer( 'wpinv-nonce' );
958
+        check_ajax_referer('wpinv-nonce');
959 959
 
960
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
960
+        if (!wpinv_current_user_can_manage_invoicing()) {
961 961
             exit;
962 962
         }
963 963
 
964 964
         // We need a search term.
965
-        if ( empty( $_GET['search'] ) ) {
966
-            wp_send_json_success( array() );
965
+        if (empty($_GET['search'])) {
966
+            wp_send_json_success(array());
967 967
         }
968 968
 
969 969
         // Retrieve customers.
970 970
     
971 971
         $customer_args = array(
972
-            'fields'         => array( 'ID', 'user_email', 'display_name' ),
972
+            'fields'         => array('ID', 'user_email', 'display_name'),
973 973
             'orderby'        => 'display_name',
974
-            'search'         => '*' . sanitize_text_field( $_GET['search'] ) . '*',
975
-            'search_columns' => array( 'user_login', 'user_email', 'display_name' ),
974
+            'search'         => '*' . sanitize_text_field($_GET['search']) . '*',
975
+            'search_columns' => array('user_login', 'user_email', 'display_name'),
976 976
         );
977 977
 
978
-        $customers = get_users( apply_filters( 'getpaid_ajax_invoice_customers_query_args', $customer_args ) );
978
+        $customers = get_users(apply_filters('getpaid_ajax_invoice_customers_query_args', $customer_args));
979 979
         $data      = array();
980 980
 
981
-        foreach ( $customers as $customer ) {
981
+        foreach ($customers as $customer) {
982 982
             $data[] = array(
983 983
                 'id'        => (int) $customer->ID,
984
-                'text'      => strip_tags( sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ) ),
984
+                'text'      => strip_tags(sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email)),
985 985
             );
986 986
         }
987 987
 
988
-        wp_send_json_success( $data );
988
+        wp_send_json_success($data);
989 989
 
990 990
     }
991 991
 
@@ -995,28 +995,28 @@  discard block
 block discarded – undo
995 995
     public static function get_aui_states_field() {
996 996
 
997 997
         // Verify nonce.
998
-        check_ajax_referer( 'wpinv-nonce' );
998
+        check_ajax_referer('wpinv-nonce');
999 999
 
1000 1000
         // We need a country.
1001
-        if ( empty( $_GET['country'] ) ) {
1001
+        if (empty($_GET['country'])) {
1002 1002
             exit;
1003 1003
         }
1004 1004
 
1005
-        $states = wpinv_get_country_states( sanitize_text_field( $_GET['country'] ) );
1006
-        $state  = isset( $_GET['state'] ) ? sanitize_text_field( $_GET['state'] ) : wpinv_get_default_state();
1007
-        $name   = isset( $_GET['name'] ) ? sanitize_text_field( $_GET['name'] ) : 'wpinv_state';
1008
-        $class  = isset( $_GET['class'] ) ? sanitize_text_field( $_GET['class'] ) : 'form-control-sm';
1005
+        $states = wpinv_get_country_states(sanitize_text_field($_GET['country']));
1006
+        $state  = isset($_GET['state']) ? sanitize_text_field($_GET['state']) : wpinv_get_default_state();
1007
+        $name   = isset($_GET['name']) ? sanitize_text_field($_GET['name']) : 'wpinv_state';
1008
+        $class  = isset($_GET['class']) ? sanitize_text_field($_GET['class']) : 'form-control-sm';
1009 1009
 
1010
-        if ( empty( $states ) ) {
1010
+        if (empty($states)) {
1011 1011
 
1012 1012
             $html = aui()->input(
1013 1013
                 array(
1014 1014
                     'type'        => 'text',
1015 1015
                     'id'          => 'wpinv_state',
1016 1016
                     'name'        => $name,
1017
-                    'label'       => __( 'State', 'invoicing' ),
1017
+                    'label'       => __('State', 'invoicing'),
1018 1018
                     'label_type'  => 'vertical',
1019
-                    'placeholder' => __( 'State', 'invoicing' ),
1019
+                    'placeholder' => __('State', 'invoicing'),
1020 1020
                     'class'       => $class,
1021 1021
                     'value'       => $state,
1022 1022
                 )
@@ -1028,9 +1028,9 @@  discard block
 block discarded – undo
1028 1028
                 array(
1029 1029
                     'id'          => 'wpinv_state',
1030 1030
                     'name'        => $name,
1031
-                    'label'       => __( 'State', 'invoicing' ),
1031
+                    'label'       => __('State', 'invoicing'),
1032 1032
                     'label_type'  => 'vertical',
1033
-                    'placeholder' => __( 'Select a state', 'invoicing' ),
1033
+                    'placeholder' => __('Select a state', 'invoicing'),
1034 1034
                     'class'       => $class,
1035 1035
                     'value'       => $state,
1036 1036
                     'options'     => $states,
@@ -1044,7 +1044,7 @@  discard block
 block discarded – undo
1044 1044
         wp_send_json_success(
1045 1045
             array(
1046 1046
                 'html'   => $html,
1047
-                'select' => ! empty ( $states )
1047
+                'select' => !empty ($states)
1048 1048
             )
1049 1049
         );
1050 1050
 
@@ -1058,11 +1058,11 @@  discard block
 block discarded – undo
1058 1058
     public static function payment_form_refresh_prices() {
1059 1059
 
1060 1060
         // Check nonce.
1061
-        check_ajax_referer( 'getpaid_form_nonce' );
1061
+        check_ajax_referer('getpaid_form_nonce');
1062 1062
 
1063 1063
         // ... form fields...
1064
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
1065
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
1064
+        if (empty($_POST['getpaid_payment_form_submission'])) {
1065
+            _e('Error: Reload the page and try again.', 'invoicing');
1066 1066
             exit;
1067 1067
         }
1068 1068
 
@@ -1070,7 +1070,7 @@  discard block
 block discarded – undo
1070 1070
         $submission = new GetPaid_Payment_Form_Submission();
1071 1071
 
1072 1072
         // Do we have an error?
1073
-        if ( ! empty( $submission->last_error ) ) {
1073
+        if (!empty($submission->last_error)) {
1074 1074
             wp_send_json_error(
1075 1075
                 array(
1076 1076
                     'code'  => $submission->last_error_code,
@@ -1080,12 +1080,12 @@  discard block
 block discarded – undo
1080 1080
         }
1081 1081
 
1082 1082
         // Prepare the response.
1083
-        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission );
1083
+        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission);
1084 1084
 
1085 1085
         // Filter the response.
1086
-        $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission );
1086
+        $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission);
1087 1087
 
1088
-        wp_send_json_success( $response );
1088
+        wp_send_json_success($response);
1089 1089
     }
1090 1090
 
1091 1091
     /**
@@ -1097,63 +1097,63 @@  discard block
 block discarded – undo
1097 1097
 	public static function file_upload() {
1098 1098
 
1099 1099
         // Check nonce.
1100
-        check_ajax_referer( 'getpaid_form_nonce' );
1100
+        check_ajax_referer('getpaid_form_nonce');
1101 1101
 
1102
-        if ( empty( $_POST['form_id'] ) || empty( $_POST['field_name'] ) || empty( $_FILES['file'] ) ) {
1103
-            wp_die( __( 'Bad Request', 'invoicing' ), 400 );
1102
+        if (empty($_POST['form_id']) || empty($_POST['field_name']) || empty($_FILES['file'])) {
1103
+            wp_die(__('Bad Request', 'invoicing'), 400);
1104 1104
         }
1105 1105
 
1106 1106
         // Fetch form.
1107
-        $form = new GetPaid_Payment_Form( intval( $_POST['form_id'] ) );
1107
+        $form = new GetPaid_Payment_Form(intval($_POST['form_id']));
1108 1108
 
1109
-        if ( ! $form->is_active() ) {
1110
-            wp_send_json_error( __( 'Payment form not active', 'invoicing' ) );
1109
+        if (!$form->is_active()) {
1110
+            wp_send_json_error(__('Payment form not active', 'invoicing'));
1111 1111
         }
1112 1112
 
1113 1113
         // Fetch appropriate field.
1114
-        $upload_field = current( wp_list_filter( $form->get_elements(), array( 'id' => sanitize_text_field( $_POST['field_name'] ) ) ) );
1115
-        if ( empty( $upload_field ) ) {
1116
-            wp_send_json_error( __( 'Invalid upload field.', 'invoicing' ) );
1114
+        $upload_field = current(wp_list_filter($form->get_elements(), array('id' => sanitize_text_field($_POST['field_name']))));
1115
+        if (empty($upload_field)) {
1116
+            wp_send_json_error(__('Invalid upload field.', 'invoicing'));
1117 1117
         }
1118 1118
 
1119 1119
         // Prepare allowed file types.
1120
-        $file_types = isset( $upload_field['file_types'] ) ? $upload_field['file_types'] : array( 'jpg|jpeg|jpe', 'gif', 'png' );
1120
+        $file_types = isset($upload_field['file_types']) ? $upload_field['file_types'] : array('jpg|jpeg|jpe', 'gif', 'png');
1121 1121
         $all_types  = getpaid_get_allowed_mime_types();
1122 1122
         $mime_types = array();
1123 1123
 
1124
-        foreach ( $file_types as $file_type ) {
1125
-            if ( isset( $all_types[ $file_type ] ) ) {
1126
-                $mime_types[] = $all_types[ $file_type ];
1124
+        foreach ($file_types as $file_type) {
1125
+            if (isset($all_types[$file_type])) {
1126
+                $mime_types[] = $all_types[$file_type];
1127 1127
             }
1128 1128
         }
1129 1129
 
1130
-        if ( ! in_array( $_FILES['file']['type'], $mime_types ) ) {
1131
-            wp_send_json_error( __( 'Unsupported file type.', 'invoicing' ) );
1130
+        if (!in_array($_FILES['file']['type'], $mime_types)) {
1131
+            wp_send_json_error(__('Unsupported file type.', 'invoicing'));
1132 1132
         }
1133 1133
 
1134 1134
         // Upload file.
1135
-        $file_name = explode( '.', strtolower( $_FILES['file']['name'] ) );
1136
-        $file_name = uniqid( 'getpaid-' ) . '.' . array_pop( $file_name );
1135
+        $file_name = explode('.', strtolower($_FILES['file']['name']));
1136
+        $file_name = uniqid('getpaid-') . '.' . array_pop($file_name);
1137 1137
 
1138 1138
         $uploaded = wp_upload_bits(
1139 1139
             $file_name,
1140 1140
             null,
1141
-            file_get_contents( $_FILES["file"]["tmp_name"] )
1141
+            file_get_contents($_FILES["file"]["tmp_name"])
1142 1142
         );
1143 1143
 
1144
-        if ( ! empty( $uploaded['error'] ) ) {
1145
-            wp_send_json_error( $uploaded['error'] );
1144
+        if (!empty($uploaded['error'])) {
1145
+            wp_send_json_error($uploaded['error']);
1146 1146
         }
1147 1147
 
1148 1148
         // Retrieve response.
1149 1149
         $response = sprintf(
1150 1150
             '<input type="hidden" name="%s[%s]" value="%s" />',
1151
-            esc_attr( sanitize_text_field( $_POST['field_name'] ) ),
1152
-            esc_url( $uploaded['url'] ),
1153
-            esc_attr( sanitize_text_field( strtolower( $_FILES['file']['name'] ) ) )
1151
+            esc_attr(sanitize_text_field($_POST['field_name'])),
1152
+            esc_url($uploaded['url']),
1153
+            esc_attr(sanitize_text_field(strtolower($_FILES['file']['name'])))
1154 1154
         );
1155 1155
 
1156
-        wp_send_json_success( $response );
1156
+        wp_send_json_success($response);
1157 1157
 
1158 1158
 	}
1159 1159
 
Please login to merge, or discard this patch.