Passed
Push — master ( 32accd...dc49db )
by Brian
05:22
created
includes/reports/class-getpaid-graph-downloader.php 1 patch
Spacing   +56 added lines, -56 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_Graph_Downloader Class.
@@ -30,13 +30,13 @@  discard block
 block discarded – undo
30 30
 	 *
31 31
 	 * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts
32 32
 	 */
33
-	public function prepare_handler( $graph ) {
33
+	public function prepare_handler($graph) {
34 34
 
35
-		if ( empty( $this->handler->views[ $graph ] ) ) {
36
-			wp_die( esc_html__( 'Invalid Graph', 'invoicing' ), 400 );
35
+		if (empty($this->handler->views[$graph])) {
36
+			wp_die(esc_html__('Invalid Graph', 'invoicing'), 400);
37 37
 		}
38 38
 
39
-		return new $this->handler->views[ $graph ]['class']();
39
+		return new $this->handler->views[$graph]['class']();
40 40
 
41 41
 	}
42 42
 
@@ -47,10 +47,10 @@  discard block
 block discarded – undo
47 47
 	 */
48 48
 	public function prepare_output() {
49 49
 
50
-		$output  = fopen( 'php://output', 'w' );
50
+		$output = fopen('php://output', 'w');
51 51
 
52
-		if ( false === $output ) {
53
-			wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 );
52
+		if (false === $output) {
53
+			wp_die(esc_html__('Unsupported server', 'invoicing'), 500);
54 54
 		}
55 55
 
56 56
 		return $output;
@@ -61,13 +61,13 @@  discard block
 block discarded – undo
61 61
 	 *
62 62
 	 * @return string
63 63
 	 */
64
-	public function prepare_file_type( $graph ) {
64
+	public function prepare_file_type($graph) {
65 65
 
66
-		$file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] );
67
-		$file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) );
66
+		$file_type = empty($_REQUEST['file_type']) ? 'csv' : sanitize_text_field($_REQUEST['file_type']);
67
+		$file_name = wpinv_sanitize_key("getpaid-$graph-" . current_time('Y-m-d'));
68 68
 
69
-		header( "Content-Type:application/$file_type" );
70
-		header( "Content-Disposition:attachment;filename=$file_name.$file_type" );
69
+		header("Content-Type:application/$file_type");
70
+		header("Content-Disposition:attachment;filename=$file_name.$file_type");
71 71
 
72 72
 		return $file_type;
73 73
 	}
@@ -76,24 +76,24 @@  discard block
 block discarded – undo
76 76
 	 * Handles the actual download.
77 77
 	 *
78 78
 	 */
79
-	public function download( $graph ) {
79
+	public function download($graph) {
80 80
 		global $wpdb;
81 81
 
82
-		$handler   = $this->prepare_handler( $graph );
82
+		$handler   = $this->prepare_handler($graph);
83 83
 		$stream    = $this->prepare_output();
84
-		$stats     = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) );
85
-		$headers   = array( $handler->field, 'total', 'total_raw' );
86
-		$file_type = $this->prepare_file_type( $graph );
87
-
88
-		if ( 'csv' == $file_type ) {
89
-			$this->download_csv( $stats, $stream, $headers );
90
-		} elseif ( 'xml' == $file_type ) {
91
-			$this->download_xml( $stats, $stream, $headers );
84
+		$stats     = $wpdb->get_results($handler->get_sql($handler->get_range()));
85
+		$headers   = array($handler->field, 'total', 'total_raw');
86
+		$file_type = $this->prepare_file_type($graph);
87
+
88
+		if ('csv' == $file_type) {
89
+			$this->download_csv($stats, $stream, $headers);
90
+		} elseif ('xml' == $file_type) {
91
+			$this->download_xml($stats, $stream, $headers);
92 92
 		} else {
93
-			$this->download_json( $stats, $stream, $headers );
93
+			$this->download_json($stats, $stream, $headers);
94 94
 		}
95 95
 
96
-		fclose( $stream );
96
+		fclose($stream);
97 97
 		exit;
98 98
 	}
99 99
 
@@ -105,16 +105,16 @@  discard block
 block discarded – undo
105 105
 	 * @param array $headers The fields to stream.
106 106
 	 * @since       1.0.19
107 107
 	 */
108
-	public function download_csv( $stats, $stream, $headers ) {
108
+	public function download_csv($stats, $stream, $headers) {
109 109
 
110 110
 		// Output the csv column headers.
111
-		fputcsv( $stream, $headers );
111
+		fputcsv($stream, $headers);
112 112
 
113 113
 		// Loop through
114
-		foreach ( $stats as $stat ) {
115
-			$row  = array_values( $this->prepare_row( $stat, $headers ) );
116
-			$row  = array_map( 'maybe_serialize', $row );
117
-			fputcsv( $stream, $row );
114
+		foreach ($stats as $stat) {
115
+			$row  = array_values($this->prepare_row($stat, $headers));
116
+			$row  = array_map('maybe_serialize', $row);
117
+			fputcsv($stream, $row);
118 118
 		}
119 119
 
120 120
 	}
@@ -127,16 +127,16 @@  discard block
 block discarded – undo
127 127
 	 * @param array $headers The fields to stream.
128 128
 	 * @since       1.0.19
129 129
 	 */
130
-	public function download_json( $stats, $stream, $headers ) {
130
+	public function download_json($stats, $stream, $headers) {
131 131
 
132 132
 		$prepared = array();
133 133
 
134 134
 		// Loop through
135
-		foreach ( $stats as $stat ) {
136
-			$prepared[] = $this->prepare_row( $stat, $headers );
135
+		foreach ($stats as $stat) {
136
+			$prepared[] = $this->prepare_row($stat, $headers);
137 137
 		}
138 138
 
139
-		fwrite( $stream, wp_json_encode( $prepared ) );
139
+		fwrite($stream, wp_json_encode($prepared));
140 140
 
141 141
 	}
142 142
 
@@ -148,19 +148,19 @@  discard block
 block discarded – undo
148 148
 	 * @param array $headers The fields to stream.
149 149
 	 * @since       1.0.19
150 150
 	 */
151
-	public function download_xml( $stats, $stream, $headers ) {
151
+	public function download_xml($stats, $stream, $headers) {
152 152
 
153 153
 		$prepared = array();
154 154
 
155 155
 		// Loop through
156
-		foreach ( $stats as $stat ) {
157
-			$prepared[] = $this->prepare_row( $stat, $headers );
156
+		foreach ($stats as $stat) {
157
+			$prepared[] = $this->prepare_row($stat, $headers);
158 158
 		}
159 159
 
160
-		$xml = new SimpleXMLElement( '<?xml version="1.0"?><data></data>' );
161
-		$this->convert_array_xml( $prepared, $xml );
160
+		$xml = new SimpleXMLElement('<?xml version="1.0"?><data></data>');
161
+		$this->convert_array_xml($prepared, $xml);
162 162
 
163
-		fwrite( $stream, $xml->asXML() );
163
+		fwrite($stream, $xml->asXML());
164 164
 
165 165
 	}
166 166
 
@@ -170,24 +170,24 @@  discard block
 block discarded – undo
170 170
 	 * @access      public
171 171
 	 * @since      1.0.19
172 172
 	 */
173
-	public function convert_array_xml( $data, $xml ) {
173
+	public function convert_array_xml($data, $xml) {
174 174
 
175 175
 		// Loop through
176
-		foreach ( $data as $key => $value ) {
176
+		foreach ($data as $key => $value) {
177 177
 
178
-			$key = preg_replace( '/[^A-Za-z0-9_\-]/', '', $key );
178
+			$key = preg_replace('/[^A-Za-z0-9_\-]/', '', $key);
179 179
 
180
-			if ( is_array( $value ) ) {
180
+			if (is_array($value)) {
181 181
 
182
-				if ( is_numeric( $key ) ) {
182
+				if (is_numeric($key)) {
183 183
 					$key = 'item' . $key; //dealing with <0/>..<n/> issues
184 184
 				}
185 185
 
186
-				$subnode = $xml->addChild( $key );
187
-				$this->convert_array_xml( $value, $subnode );
186
+				$subnode = $xml->addChild($key);
187
+				$this->convert_array_xml($value, $subnode);
188 188
 
189 189
 			} else {
190
-				$xml->addChild( $key, htmlspecialchars( $value ) );
190
+				$xml->addChild($key, htmlspecialchars($value));
191 191
 			}
192 192
 }
193 193
 
@@ -201,24 +201,24 @@  discard block
 block discarded – undo
201 201
 	 * @since       1.0.19
202 202
 	 * @return array
203 203
 	 */
204
-	public function prepare_row( $row, $fields ) {
204
+	public function prepare_row($row, $fields) {
205 205
 
206 206
 		$prepared = array();
207 207
 		$row      = (array) $row;
208 208
 
209
-		foreach ( $fields as $field ) {
209
+		foreach ($fields as $field) {
210 210
 
211
-			if ( $field === 'total' ) {
212
-				$prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES );
211
+			if ($field === 'total') {
212
+				$prepared[$field] = html_entity_decode(strip_tags(wpinv_price($row['total'])), ENT_QUOTES);
213 213
 				continue;
214 214
 			}
215 215
 
216
-			if ( $field === 'total_raw' ) {
217
-				$prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) );
216
+			if ($field === 'total_raw') {
217
+				$prepared[$field] = wpinv_round_amount(wpinv_sanitize_amount($row['total']));
218 218
 				continue;
219 219
 			}
220 220
 
221
-			$prepared[ $field ] = strip_tags( $row[ $field ] );
221
+			$prepared[$field] = strip_tags($row[$field]);
222 222
 
223 223
 		}
224 224
 
Please login to merge, or discard this patch.
includes/admin/html-admin-page-addons.php 1 patch
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -3,27 +3,27 @@  discard block
 block discarded – undo
3 3
  * Admin View: Page - Addons
4 4
  *
5 5
  */
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
 	exit;
8 8
 }
9 9
 add_ThickBox();
10 10
 ?>
11 11
 <div class="wrap wpi_addons_wrap">
12
-	<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
12
+	<h1><?php echo esc_html(get_admin_page_title()); ?></h1>
13 13
 
14
-	<?php if ( $tabs ) { ?>
14
+	<?php if ($tabs) { ?>
15 15
 		<nav class="nav-tab-wrapper wpi-nav-tab-wrapper">
16 16
 			<?php
17
-			foreach ( $tabs as $name => $label ) {
18
-				echo '<a href="' . esc_url( admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . esc_html( $label ) . '</a>';
17
+			foreach ($tabs as $name => $label) {
18
+				echo '<a href="' . esc_url(admin_url('admin.php?page=wpi-addons&tab=' . $name)) . '" class="nav-tab ' . ($current_tab == $name ? 'nav-tab-active' : '') . '">' . esc_html($label) . '</a>';
19 19
 			}
20
-			do_action( 'wpi_addons_tabs' );
20
+			do_action('wpi_addons_tabs');
21 21
 			?>
22 22
 		</nav>
23 23
 
24 24
 		<?php
25 25
 
26
-		if ( $current_tab == 'membership' ) {
26
+		if ($current_tab == 'membership') {
27 27
 
28 28
 			?>
29 29
 
@@ -32,42 +32,42 @@  discard block
 block discarded – undo
32 32
 <!--
33 33
 				<h2>With our WPInvoicing Membership you get access to all our products!</h2>
34 34
 				<p><a class="button button-primary" href="https://wpinvoicing.com/downloads/membership/">View Memberships</a></p>-->
35
-				<?php if ( defined( 'WP_EASY_UPDATES_ACTIVE' ) ) { ?>
36
-					<h2><?php esc_html_e( 'Have a membership key?', 'invoicing' ); ?></h2>
35
+				<?php if (defined('WP_EASY_UPDATES_ACTIVE')) { ?>
36
+					<h2><?php esc_html_e('Have a membership key?', 'invoicing'); ?></h2>
37 37
 					<p>
38 38
 						<?php
39
-						$wpeu_admin = new External_Updates_Admin( 'wpinvoicing.com', '1' );
40
-						echo wp_kses_post( $wpeu_admin->render_licence_actions( 'wpinvoicing.com', 'membership', array( 95, 106, 108, 12351 ) ) );
39
+						$wpeu_admin = new External_Updates_Admin('wpinvoicing.com', '1');
40
+						echo wp_kses_post($wpeu_admin->render_licence_actions('wpinvoicing.com', 'membership', array(95, 106, 108, 12351)));
41 41
 						?>
42 42
 					</p>
43 43
 				<?php } ?>
44 44
 
45 45
 				<div class="membership-cta-contet">
46 46
 					<div class="main-cta">
47
-							<h2><?php esc_html_e( 'Membership benefits Include:', 'invoicing' ); ?></h2>
47
+							<h2><?php esc_html_e('Membership benefits Include:', 'invoicing'); ?></h2>
48 48
 							<div class="feature-list">
49 49
 								<ul>
50 50
 									<?php
51 51
 									$addon_obj = new WPInv_Admin_Addons();
52
-									if ( $addons = $addon_obj->get_section_data( 'addons' ) ) {
53
-										foreach ( $addons as $addon ) {
54
-											echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html( $addon->info->title ) . '</li>';
52
+									if ($addons = $addon_obj->get_section_data('addons')) {
53
+										foreach ($addons as $addon) {
54
+											echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html($addon->info->title) . '</li>';
55 55
 										}
56 56
 									}
57 57
 									?>
58 58
 									</ul>
59 59
 
60 60
 									<div class="feature-cta">
61
-										<h3><?php esc_html_e( 'Membership Starts from', 'invoicing' ); ?></h3>
61
+										<h3><?php esc_html_e('Membership Starts from', 'invoicing'); ?></h3>
62 62
 										<h4>$99</h4>
63
-										<a href="https://wpinvoicing.com/downloads/membership/" target="_blank"><?php esc_attr_e( 'Buy Membership', 'invoicing' ); ?></a>
63
+										<a href="https://wpinvoicing.com/downloads/membership/" target="_blank"><?php esc_attr_e('Buy Membership', 'invoicing'); ?></a>
64 64
 									</div>
65
-									<h3><?php esc_html_e( 'Included Gateways:', 'invoicing' ); ?></h3>
65
+									<h3><?php esc_html_e('Included Gateways:', 'invoicing'); ?></h3>
66 66
 									<ul>
67 67
 										<?php
68
-										if ( $addons = $addon_obj->get_section_data( 'gateways' ) ) {
69
-											foreach ( $addons as $addon ) {
70
-												echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html( $addon->info->title ) . '</li>';
68
+										if ($addons = $addon_obj->get_section_data('gateways')) {
69
+											foreach ($addons as $addon) {
70
+												echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html($addon->info->title) . '</li>';
71 71
 											}
72 72
 										}
73 73
 										?>
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 						<div class="testimonial-content">
82 82
 							<div class="t-image">
83 83
 								<?php
84
-									echo '<img src="' . esc_url( plugins_url( 'images/t-image2.png', dirname( __FILE__ ) ) ) . '" > ';
84
+									echo '<img src="' . esc_url(plugins_url('images/t-image2.png', dirname(__FILE__))) . '" > ';
85 85
 								?>
86 86
 							</div>
87 87
 							<div class="t-content">
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 						<div class="testimonial-content">
102 102
 							<div class="t-image">
103 103
 								<?php
104
-									echo '<img src="' . esc_url( plugins_url( 'images/t-image1.png', dirname( __FILE__ ) ) ) . '" > ';
104
+									echo '<img src="' . esc_url(plugins_url('images/t-image1.png', dirname(__FILE__))) . '" > ';
105 105
 								?>
106 106
 							</div>
107 107
 							<div class="t-content">
@@ -117,8 +117,8 @@  discard block
 block discarded – undo
117 117
 						</div>
118 118
 					</div>
119 119
 					<div class="member-footer">
120
-						<a class="footer-btn" href="https://wpinvoicing.com/downloads/membership/" target="_blank"><?php esc_html_e( 'Buy Membership', 'invoicing' ); ?></a>
121
-						<a class="footer-link" href="post-new.php?post_type=wpi_invoice"><?php esc_html_e( 'Create Invoice', 'invoicing' ); ?></a>
120
+						<a class="footer-btn" href="https://wpinvoicing.com/downloads/membership/" target="_blank"><?php esc_html_e('Buy Membership', 'invoicing'); ?></a>
121
+						<a class="footer-link" href="post-new.php?post_type=wpi_invoice"><?php esc_html_e('Create Invoice', 'invoicing'); ?></a>
122 122
 					</div>
123 123
 				</div>
124 124
 
@@ -129,55 +129,55 @@  discard block
 block discarded – undo
129 129
 		} else {
130 130
 			$installed_plugins = get_plugins();
131 131
             $addon_obj = new WPInv_Admin_Addons();
132
-			if ( $addons = $addon_obj->get_section_data( $current_tab ) ) :
132
+			if ($addons = $addon_obj->get_section_data($current_tab)) :
133 133
 				//print_r($addons);
134 134
 				?>
135 135
 				<ul class="wpi-products">
136 136
                 <?php
137
-                foreach ( $addons as $addon ) :
138
-                        if ( 965 == $addon->info->id ) {
139
-continue;}// don't show quote add on
137
+                foreach ($addons as $addon) :
138
+                        if (965 == $addon->info->id) {
139
+continue; }// don't show quote add on
140 140
 						?>
141 141
                         <li class="wpi-product">
142 142
 								<div class="wpi-product-title">
143 143
 									<h3>
144 144
                                     <?php
145
-										if ( ! empty( $addon->info->excerpt ) ) {
146
-										wpi_help_tip( $addon->info->excerpt, false, false, true );
145
+										if (!empty($addon->info->excerpt)) {
146
+										wpi_help_tip($addon->info->excerpt, false, false, true);
147 147
 										}
148
-										echo esc_html( $addon->info->title );
148
+										echo esc_html($addon->info->title);
149 149
                                         ?>
150 150
                                         </h3>
151 151
 								</div>
152 152
 
153 153
 								<span class="wpi-product-image">
154
-									<?php if ( ! empty( $addon->info->thumbnail ) ) : ?>
155
-										<img src="<?php echo esc_attr( $addon->info->thumbnail ); ?>"/>
154
+									<?php if (!empty($addon->info->thumbnail)) : ?>
155
+										<img src="<?php echo esc_attr($addon->info->thumbnail); ?>"/>
156 156
 									<?php
157 157
                                     endif;
158 158
 
159
-									if ( 'stripe-payment-gateway' == $addon->info->slug ) {
159
+									if ('stripe-payment-gateway' == $addon->info->slug) {
160 160
 										$addon->info->slug = 'getpaid-stripe-payments';
161 161
 										$addon->info->link = 'https://wordpress.org/plugins/getpaid-stripe-payments/';
162 162
 									}
163 163
 
164
-									if ( isset( $addon->info->link ) && substr( $addon->info->link, 0, 21 ) === 'https://wordpress.org' ) {
165
-										echo '<a href="' . esc_url( admin_url( '/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug ) ) . '&width=770&height=660&TB_iframe=true" class="thickbox" >';
166
-										echo '<span class="wpi-product-info">' . esc_html__( 'More info', 'invoicing' ) . '</span>';
164
+									if (isset($addon->info->link) && substr($addon->info->link, 0, 21) === 'https://wordpress.org') {
165
+										echo '<a href="' . esc_url(admin_url('/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug)) . '&width=770&height=660&TB_iframe=true" class="thickbox" >';
166
+										echo '<span class="wpi-product-info">' . esc_html__('More info', 'invoicing') . '</span>';
167 167
 										echo '</a>';
168
-									} elseif ( isset( $addon->info->link ) && ( substr( $addon->info->link, 0, 23 ) === 'https://wpinvoicing.com' || substr( $addon->info->link, 0, 21 ) === 'https://wpgetpaid.com' ) ) {
169
-										if ( defined( 'WP_EASY_UPDATES_ACTIVE' ) ) {
170
-											$url = admin_url( '/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug . '&width=770&height=660&item_id=' . $addon->info->id . '&update_url=https://wpgetpaid.com&TB_iframe=true' );
168
+									} elseif (isset($addon->info->link) && (substr($addon->info->link, 0, 23) === 'https://wpinvoicing.com' || substr($addon->info->link, 0, 21) === 'https://wpgetpaid.com')) {
169
+										if (defined('WP_EASY_UPDATES_ACTIVE')) {
170
+											$url = admin_url('/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug . '&width=770&height=660&item_id=' . $addon->info->id . '&update_url=https://wpgetpaid.com&TB_iframe=true');
171 171
 										} else {
172 172
 											// if installed show activation link
173
-											if ( isset( $installed_plugins['wp-easy-updates/external-updates.php'] ) ) {
173
+											if (isset($installed_plugins['wp-easy-updates/external-updates.php'])) {
174 174
 												$url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation';
175 175
 											} else {
176 176
 												$url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external';
177 177
 											}
178 178
 										}
179
-										echo '<a href="' . esc_url( $url ) . '" class="thickbox">';
180
-										echo '<span class="wpi-product-info">' . esc_html__( 'More info', 'invoicing' ) . '</span>';
179
+										echo '<a href="' . esc_url($url) . '" class="thickbox">';
180
+										echo '<span class="wpi-product-info">' . esc_html__('More info', 'invoicing') . '</span>';
181 181
 										echo '</a>';
182 182
 									}
183 183
 
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 
189 189
 								<span class="wpi-product-button">
190 190
 									<?php
191
-                                    $addon_obj->output_button( $addon );
191
+                                    $addon_obj->output_button($addon);
192 192
 									?>
193 193
 								</span>
194 194
 
@@ -202,21 +202,21 @@  discard block
 block discarded – undo
202 202
 
203 203
 	<div class="clearfix" ></div>
204 204
 
205
-	<?php if ( $current_tab == 'addons' ) { ?>
206
-	<p><?php printf(  esc_attr__( 'All of our Addons can be found on wpGetPaid.com here: %sInvoicing Addons%s', 'invoicing' ), '<a href="https://wpinvoicing.com/downloads/category/addons/">','</a>' ); ?></p>
207
-	<?php } if ( $current_tab == 'gateways' ) { ?>
208
-    <p><?php printf( esc_attr__( 'All of our Payment Gateways can be found on wpGetPaid.com here: %sGetPaid Payment Gateways %s', 'invoicing' ), '<a href="https://wpinvoicing.com/downloads/category/gateways/">','</a>'  ); ?></p>
205
+	<?php if ($current_tab == 'addons') { ?>
206
+	<p><?php printf(esc_attr__('All of our Addons can be found on wpGetPaid.com here: %sInvoicing Addons%s', 'invoicing'), '<a href="https://wpinvoicing.com/downloads/category/addons/">', '</a>'); ?></p>
207
+	<?php } if ($current_tab == 'gateways') { ?>
208
+    <p><?php printf(esc_attr__('All of our Payment Gateways can be found on wpGetPaid.com here: %sGetPaid Payment Gateways %s', 'invoicing'), '<a href="https://wpinvoicing.com/downloads/category/gateways/">', '</a>'); ?></p>
209 209
     <?php } ?>
210 210
 
211
-	<div id="wpi-wpeu-required-activation" style="display:none;"><span class="wpi-notification "><?php echo wp_kses_post(  sprintf( __( "The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s'>activate</a> it now.", 'invoicing' ), wp_nonce_url( admin_url( 'plugins.php?action=activate&plugin=wp-easy-updates/external-updates.php' ), 'activate-plugin_wp-easy-updates/external-updates.php' ) ) ); ?></span></div>
212
-	<div id="wpi-wpeu-required-for-external" style="display:none;"><span class="wpi-notification "><?php echo wp_kses_post( sprintf( __( "The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s' onclick='window.open(\"https://wpeasyupdates.com/wp-easy-updates.zip\", \"_blank\");' >download</a> and install it now.", 'invoicing' ), admin_url( 'plugin-install.php?tab=upload&wpeu-install=true' ) ) ); ?></span></div>
211
+	<div id="wpi-wpeu-required-activation" style="display:none;"><span class="wpi-notification "><?php echo wp_kses_post(sprintf(__("The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s'>activate</a> it now.", 'invoicing'), wp_nonce_url(admin_url('plugins.php?action=activate&plugin=wp-easy-updates/external-updates.php'), 'activate-plugin_wp-easy-updates/external-updates.php'))); ?></span></div>
212
+	<div id="wpi-wpeu-required-for-external" style="display:none;"><span class="wpi-notification "><?php echo wp_kses_post(sprintf(__("The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s' onclick='window.open(\"https://wpeasyupdates.com/wp-easy-updates.zip\", \"_blank\");' >download</a> and install it now.", 'invoicing'), admin_url('plugin-install.php?tab=upload&wpeu-install=true'))); ?></span></div>
213 213
 	<div id="wpeu-licence-popup" style="display:none;">
214 214
 		<span class="wpi-notification noti-white">
215
-			<h3 class="wpeu-licence-title"><?php esc_html_e( 'Licence key', 'invoicing' ); ?></h3>
216
-			<input class="wpeu-licence-key" type="text" placeholder="<?php esc_attr_e( 'Enter your licence key', 'invoicing' ); ?>"> <button class="button-primary wpeu-licence-popup-button" ><?php esc_html_e( 'Install', 'invoicing' ); ?></button>
215
+			<h3 class="wpeu-licence-title"><?php esc_html_e('Licence key', 'invoicing'); ?></h3>
216
+			<input class="wpeu-licence-key" type="text" placeholder="<?php esc_attr_e('Enter your licence key', 'invoicing'); ?>"> <button class="button-primary wpeu-licence-popup-button" ><?php esc_html_e('Install', 'invoicing'); ?></button>
217 217
 			<br>
218 218
 			<?php
219
-			printf( esc_html__( '%1$sFind your licence key here%2$s OR %3$sBuy one here%4$s', 'invoicing' ), '<a href="https://wpinvoicing.com/your-account/" target="_blank">', '</a>', '<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">', '</a>' );
219
+			printf(esc_html__('%1$sFind your licence key here%2$s OR %3$sBuy one here%4$s', 'invoicing'), '<a href="https://wpinvoicing.com/your-account/" target="_blank">', '</a>', '<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">', '</a>');
220 220
 			?>
221 221
 		</span>
222 222
 	</div>
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 1 patch
Spacing   +325 added lines, -325 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
-            esc_html_e( "Provide the new user's email address", 'invoicing' );
218
+        if (empty($_GET['email'])) {
219
+            esc_html_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
-            esc_html_e( 'Invalid email address', 'invoicing' );
224
+        $email = sanitize_email($_GET['email']);
225
+        if (!is_email($email)) {
226
+            esc_html_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,14 +258,14 @@  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
 			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
                 true
271 271
             );
@@ -273,29 +273,29 @@  discard block
 block discarded – undo
273 273
         }
274 274
 
275 275
         // Payment form or button?
276
-		if ( ! empty( $_GET['form'] ) ) {
277
-            $form = sanitize_text_field( urldecode( $_GET['form'] ) );
276
+		if (!empty($_GET['form'])) {
277
+            $form = sanitize_text_field(urldecode($_GET['form']));
278 278
 
279
-            if ( false !== strpos( $form, '|' ) ) {
280
-                $form_pos = strpos( $form, '|' );
281
-                $_items   = getpaid_convert_items_to_array( substr( $form, $form_pos + 1 ) );
282
-                $form     = substr( $form, 0, $form_pos );
279
+            if (false !== strpos($form, '|')) {
280
+                $form_pos = strpos($form, '|');
281
+                $_items   = getpaid_convert_items_to_array(substr($form, $form_pos + 1));
282
+                $form     = substr($form, 0, $form_pos);
283 283
 
284 284
                 // Retrieve appropriate payment form.
285
-                $payment_form = new GetPaid_Payment_Form( $form );
286
-                $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
285
+                $payment_form = new GetPaid_Payment_Form($form);
286
+                $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form());
287 287
 
288 288
                 $items    = array();
289 289
                 $item_ids = array();
290 290
 
291
-                foreach ( $_items as $item_id => $qty ) {
292
-                    if ( ! in_array( $item_id, $item_ids ) ) {
293
-                        $item = new GetPaid_Form_Item( $item_id );
294
-                        $item->set_quantity( $qty );
291
+                foreach ($_items as $item_id => $qty) {
292
+                    if (!in_array($item_id, $item_ids)) {
293
+                        $item = new GetPaid_Form_Item($item_id);
294
+                        $item->set_quantity($qty);
295 295
 
296
-                        if ( 0 == $qty ) {
297
-                            $item->set_allow_quantities( true );
298
-                            $item->set_is_required( false );
296
+                        if (0 == $qty) {
297
+                            $item->set_allow_quantities(true);
298
+                            $item->set_is_required(false);
299 299
                             $getpaid_force_checkbox = true;
300 300
                         }
301 301
 
@@ -304,32 +304,32 @@  discard block
 block discarded – undo
304 304
                     }
305 305
                 }
306 306
 
307
-                if ( ! $payment_form->is_default() ) {
307
+                if (!$payment_form->is_default()) {
308 308
 
309
-                    foreach ( $payment_form->get_items() as $item ) {
310
-                        if ( ! in_array( $item->get_id(), $item_ids ) ) {
309
+                    foreach ($payment_form->get_items() as $item) {
310
+                        if (!in_array($item->get_id(), $item_ids)) {
311 311
                             $item_ids[] = $item->get_id();
312 312
                             $items[]    = $item;
313 313
                         }
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
-} elseif ( ! empty( $_GET['invoice'] ) ) {
329
-		    getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) );
328
+} elseif (!empty($_GET['invoice'])) {
329
+		    getpaid_display_invoice_payment_form((int) urldecode($_GET['invoice']));
330 330
         } else {
331
-			$items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) );
332
-		    getpaid_display_item_payment_form( $items );
331
+			$items = getpaid_convert_items_to_array(sanitize_text_field(urldecode($_GET['item'])));
332
+		    getpaid_display_item_payment_form($items);
333 333
         }
334 334
 
335 335
         exit;
@@ -344,17 +344,17 @@  discard block
 block discarded – undo
344 344
     public static function payment_form() {
345 345
 
346 346
         // Check nonce.
347
-        check_ajax_referer( 'getpaid_form_nonce' );
347
+        check_ajax_referer('getpaid_form_nonce');
348 348
 
349 349
         // ... form fields...
350
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
351
-            esc_html_e( 'Error: Reload the page and try again.', 'invoicing' );
350
+        if (empty($_POST['getpaid_payment_form_submission'])) {
351
+            esc_html_e('Error: Reload the page and try again.', 'invoicing');
352 352
             exit;
353 353
         }
354 354
 
355 355
         // Process the payment form.
356
-        $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' );
357
-        $checkout       = new $checkout_class( new GetPaid_Payment_Form_Submission() );
356
+        $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout');
357
+        $checkout       = new $checkout_class(new GetPaid_Payment_Form_Submission());
358 358
         $checkout->process_checkout();
359 359
 
360 360
         exit;
@@ -367,55 +367,55 @@  discard block
 block discarded – undo
367 367
      */
368 368
     public static function get_payment_form_states_field() {
369 369
 
370
-        if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) {
370
+        if (empty($_GET['country']) || empty($_GET['form'])) {
371 371
             exit;
372 372
         }
373 373
 
374
-        $elements = getpaid_get_payment_form_elements( (int) $_GET['form'] );
374
+        $elements = getpaid_get_payment_form_elements((int) $_GET['form']);
375 375
 
376
-        if ( empty( $elements ) ) {
376
+        if (empty($elements)) {
377 377
             exit;
378 378
         }
379 379
 
380 380
         $address_fields = array();
381
-        foreach ( $elements as $element ) {
382
-            if ( 'address' === $element['type'] ) {
381
+        foreach ($elements as $element) {
382
+            if ('address' === $element['type']) {
383 383
                 $address_fields = $element;
384 384
                 break;
385 385
             }
386 386
         }
387 387
 
388
-        if ( empty( $address_fields ) ) {
388
+        if (empty($address_fields)) {
389 389
             exit;
390 390
         }
391 391
 
392
-        foreach ( $address_fields['fields'] as $address_field ) {
392
+        foreach ($address_fields['fields'] as $address_field) {
393 393
 
394
-            if ( 'wpinv_state' == $address_field['name'] ) {
394
+            if ('wpinv_state' == $address_field['name']) {
395 395
 
396
-                $wrap_class  = getpaid_get_form_element_grid_class( $address_field );
397
-                $wrap_class  = esc_attr( "$wrap_class getpaid-address-field-wrapper" );
398
-                $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] );
399
-                $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] );
400
-                $value       = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : '';
401
-                $label       = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] );
396
+                $wrap_class  = getpaid_get_form_element_grid_class($address_field);
397
+                $wrap_class  = esc_attr("$wrap_class getpaid-address-field-wrapper");
398
+                $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']);
399
+                $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']);
400
+                $value       = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : '';
401
+                $label       = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']);
402 402
 
403
-                if ( ! empty( $address_field['required'] ) ) {
403
+                if (!empty($address_field['required'])) {
404 404
                     $label .= "<span class='text-danger'> *</span>";
405 405
                 }
406 406
 
407 407
                 $html = getpaid_get_states_select_markup(
408
-                    sanitize_text_field( $_GET['country'] ),
408
+                    sanitize_text_field($_GET['country']),
409 409
                     $value,
410 410
                     $placeholder,
411 411
                     $label,
412 412
                     $description,
413
-                    ! empty( $address_field['required'] ),
413
+                    !empty($address_field['required']),
414 414
                     $wrap_class,
415
-                    sanitize_text_field( $_GET['name'] )
415
+                    sanitize_text_field($_GET['name'])
416 416
                 );
417 417
 
418
-                wp_send_json_success( $html );
418
+                wp_send_json_success($html);
419 419
                 exit;
420 420
 
421 421
             }
@@ -430,66 +430,66 @@  discard block
 block discarded – undo
430 430
     public static function recalculate_invoice_totals() {
431 431
 
432 432
         // Verify nonce.
433
-        check_ajax_referer( 'wpinv-nonce' );
433
+        check_ajax_referer('wpinv-nonce');
434 434
 
435
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
435
+        if (!wpinv_current_user_can_manage_invoicing()) {
436 436
             exit;
437 437
         }
438 438
 
439 439
         // We need an invoice.
440
-        if ( empty( $_POST['post_id'] ) ) {
440
+        if (empty($_POST['post_id'])) {
441 441
             exit;
442 442
         }
443 443
 
444 444
         // Fetch the invoice.
445
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
445
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
446 446
 
447 447
         // Ensure it exists.
448
-        if ( ! $invoice->get_id() ) {
448
+        if (!$invoice->get_id()) {
449 449
             exit;
450 450
         }
451 451
 
452 452
         // Maybe set the country, state, currency.
453
-        foreach ( array( 'country', 'state', 'currency', 'vat_number', 'discount_code' ) as $key ) {
454
-            if ( isset( $_POST[ $key ] ) ) {
453
+        foreach (array('country', 'state', 'currency', 'vat_number', 'discount_code') as $key) {
454
+            if (isset($_POST[$key])) {
455 455
                 $method = "set_$key";
456
-                $invoice->$method( sanitize_text_field( $_POST[ $key ] ) );
456
+                $invoice->$method(sanitize_text_field($_POST[$key]));
457 457
             }
458 458
         }
459 459
 
460 460
         // Maybe disable taxes.
461
-        $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) );
461
+        $invoice->set_disable_taxes(!empty($_POST['taxes']));
462 462
 
463 463
         // Discount code.
464
-        if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
465
-            $discount = new WPInv_Discount( $invoice->get_discount_code() );
466
-            if ( $discount->exists() ) {
467
-                $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
464
+        if (!$invoice->is_paid() && !$invoice->is_refunded()) {
465
+            $discount = new WPInv_Discount($invoice->get_discount_code());
466
+            if ($discount->exists()) {
467
+                $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
468 468
             } else {
469
-                $invoice->remove_discount( 'discount_code' );
469
+                $invoice->remove_discount('discount_code');
470 470
             }
471 471
         }
472 472
 
473 473
         // Recalculate totals.
474 474
         $invoice->recalculate_total();
475 475
 
476
-        $total        = wpinv_price( $invoice->get_total(), $invoice->get_currency() );
477
-        $suscriptions = getpaid_get_invoice_subscriptions( $invoice );
478
-        if ( is_a( $suscriptions, 'WPInv_Subscription' ) && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) {
479
-            $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() );
480
-            $total          .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>';
476
+        $total        = wpinv_price($invoice->get_total(), $invoice->get_currency());
477
+        $suscriptions = getpaid_get_invoice_subscriptions($invoice);
478
+        if (is_a($suscriptions, 'WPInv_Subscription') && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) {
479
+            $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency());
480
+            $total          .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>';
481 481
         }
482 482
 
483 483
         $totals = array(
484
-            'subtotal' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ),
485
-            'discount' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ),
486
-            'tax'      => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ),
484
+            'subtotal' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()),
485
+            'discount' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()),
486
+            'tax'      => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()),
487 487
             'total'    => $total,
488 488
         );
489 489
 
490
-        $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice );
490
+        $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice);
491 491
 
492
-        wp_send_json_success( compact( 'totals' ) );
492
+        wp_send_json_success(compact('totals'));
493 493
     }
494 494
 
495 495
     /**
@@ -498,33 +498,33 @@  discard block
 block discarded – undo
498 498
     public static function get_invoice_items() {
499 499
 
500 500
         // Verify nonce.
501
-        check_ajax_referer( 'wpinv-nonce' );
501
+        check_ajax_referer('wpinv-nonce');
502 502
 
503
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
503
+        if (!wpinv_current_user_can_manage_invoicing()) {
504 504
             exit;
505 505
         }
506 506
 
507 507
         // We need an invoice and items.
508
-        if ( empty( $_POST['post_id'] ) ) {
508
+        if (empty($_POST['post_id'])) {
509 509
             exit;
510 510
         }
511 511
 
512 512
         // Fetch the invoice.
513
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
513
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
514 514
 
515 515
         // Ensure it exists.
516
-        if ( ! $invoice->get_id() ) {
516
+        if (!$invoice->get_id()) {
517 517
             exit;
518 518
         }
519 519
 
520 520
         // Return an array of invoice items.
521 521
         $items = array();
522 522
 
523
-        foreach ( $invoice->get_items() as $item ) {
524
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency(), $invoice->is_renewal() );
523
+        foreach ($invoice->get_items() as $item) {
524
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency(), $invoice->is_renewal());
525 525
         }
526 526
 
527
-        wp_send_json_success( compact( 'items' ) );
527
+        wp_send_json_success(compact('items'));
528 528
     }
529 529
 
530 530
     /**
@@ -533,50 +533,50 @@  discard block
 block discarded – undo
533 533
     public static function edit_invoice_item() {
534 534
 
535 535
         // Verify nonce.
536
-        check_ajax_referer( 'wpinv-nonce' );
536
+        check_ajax_referer('wpinv-nonce');
537 537
 
538
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
538
+        if (!wpinv_current_user_can_manage_invoicing()) {
539 539
             exit;
540 540
         }
541 541
 
542 542
         // We need an invoice and item details.
543
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) {
543
+        if (empty($_POST['post_id']) || empty($_POST['data'])) {
544 544
             exit;
545 545
         }
546 546
 
547 547
         // Fetch the invoice.
548
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
548
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
549 549
 
550 550
         // Ensure it exists and its not been paid for.
551
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
551
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
552 552
             exit;
553 553
         }
554 554
 
555 555
         // Format the data.
556
-        $data = wp_kses_post_deep( wp_unslash( wp_list_pluck( $_POST['data'], 'value', 'field' ) ) );
556
+        $data = wp_kses_post_deep(wp_unslash(wp_list_pluck($_POST['data'], 'value', 'field')));
557 557
 
558 558
         // Ensure that we have an item id.
559
-        if ( empty( $data['id'] ) ) {
559
+        if (empty($data['id'])) {
560 560
             exit;
561 561
         }
562 562
 
563 563
         // Abort if the invoice does not have the specified item.
564
-        $item = $invoice->get_item( (int) $data['id'] );
564
+        $item = $invoice->get_item((int) $data['id']);
565 565
 
566
-        if ( empty( $item ) ) {
566
+        if (empty($item)) {
567 567
             exit;
568 568
         }
569 569
 
570 570
         // Update the item.
571
-        $item->set_price( getpaid_standardize_amount( $data['price'] ) );
572
-        $item->set_name( sanitize_text_field( $data['name'] ) );
573
-        $item->set_description( wp_kses_post( $data['description'] ) );
574
-        $item->set_quantity( floatval( $data['quantity'] ) );
571
+        $item->set_price(getpaid_standardize_amount($data['price']));
572
+        $item->set_name(sanitize_text_field($data['name']));
573
+        $item->set_description(wp_kses_post($data['description']));
574
+        $item->set_quantity(floatval($data['quantity']));
575 575
 
576 576
         // Add it to the invoice.
577
-        $error = $invoice->add_item( $item );
577
+        $error = $invoice->add_item($item);
578 578
         $alert = false;
579
-        if ( is_wp_error( $error ) ) {
579
+        if (is_wp_error($error)) {
580 580
             $alert = $error->get_error_message();
581 581
         }
582 582
 
@@ -589,11 +589,11 @@  discard block
 block discarded – undo
589 589
         // Return an array of invoice items.
590 590
         $items = array();
591 591
 
592
-        foreach ( $invoice->get_items() as $item ) {
593
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
592
+        foreach ($invoice->get_items() as $item) {
593
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
594 594
         }
595 595
 
596
-        wp_send_json_success( compact( 'items', 'alert' ) );
596
+        wp_send_json_success(compact('items', 'alert'));
597 597
     }
598 598
 
599 599
     /**
@@ -602,53 +602,53 @@  discard block
 block discarded – undo
602 602
     public static function create_invoice_item() {
603 603
 
604 604
         // Verify nonce.
605
-        check_ajax_referer( 'wpinv-nonce' );
605
+        check_ajax_referer('wpinv-nonce');
606 606
 
607
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
607
+        if (!wpinv_current_user_can_manage_invoicing()) {
608 608
             exit;
609 609
         }
610 610
 
611 611
         // We need an invoice and item details.
612
-        if ( empty( $_POST['invoice_id'] ) || empty( $_POST['_wpinv_quick'] ) ) {
612
+        if (empty($_POST['invoice_id']) || empty($_POST['_wpinv_quick'])) {
613 613
             exit;
614 614
         }
615 615
 
616 616
         // Fetch the invoice.
617
-        $invoice = new WPInv_Invoice( intval( $_POST['invoice_id'] ) );
617
+        $invoice = new WPInv_Invoice(intval($_POST['invoice_id']));
618 618
 
619 619
         // Ensure it exists and its not been paid for.
620
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
620
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
621 621
             exit;
622 622
         }
623 623
 
624 624
         // Format the data.
625
-        $data = wp_kses_post_deep( wp_unslash( $_POST['_wpinv_quick'] ) );
625
+        $data = wp_kses_post_deep(wp_unslash($_POST['_wpinv_quick']));
626 626
 
627 627
         $item = new WPInv_Item();
628
-        $item->set_price( getpaid_standardize_amount( $data['price'] ) );
629
-        $item->set_name( sanitize_text_field( $data['name'] ) );
630
-        $item->set_description( wp_kses_post( $data['description'] ) );
631
-        $item->set_type( sanitize_text_field( $data['type'] ) );
632
-        $item->set_vat_rule( sanitize_text_field( $data['vat_rule'] ) );
633
-        $item->set_vat_class( sanitize_text_field( $data['vat_class'] ) );
634
-        $item->set_status( 'publish' );
628
+        $item->set_price(getpaid_standardize_amount($data['price']));
629
+        $item->set_name(sanitize_text_field($data['name']));
630
+        $item->set_description(wp_kses_post($data['description']));
631
+        $item->set_type(sanitize_text_field($data['type']));
632
+        $item->set_vat_rule(sanitize_text_field($data['vat_rule']));
633
+        $item->set_vat_class(sanitize_text_field($data['vat_class']));
634
+        $item->set_status('publish');
635 635
         $item->save();
636 636
 
637
-        if ( ! $item->exists() ) {
638
-            $alert = __( 'Could not create invoice item. Please try again.', 'invoicing' );
639
-            wp_send_json_success( compact( 'alert' ) );
637
+        if (!$item->exists()) {
638
+            $alert = __('Could not create invoice item. Please try again.', 'invoicing');
639
+            wp_send_json_success(compact('alert'));
640 640
         }
641 641
 
642
-        $item = new GetPaid_Form_Item( $item->get_id() );
643
-        $item->set_quantity( floatval( $data['qty'] ) );
642
+        $item = new GetPaid_Form_Item($item->get_id());
643
+        $item->set_quantity(floatval($data['qty']));
644 644
 
645 645
         // Add it to the invoice.
646
-        $error = $invoice->add_item( $item );
646
+        $error = $invoice->add_item($item);
647 647
         $alert = false;
648 648
 
649
-        if ( is_wp_error( $error ) ) {
649
+        if (is_wp_error($error)) {
650 650
             $alert = $error->get_error_message();
651
-            wp_send_json_success( compact( 'alert' ) );
651
+            wp_send_json_success(compact('alert'));
652 652
          }
653 653
 
654 654
         // Update totals.
@@ -661,9 +661,9 @@  discard block
 block discarded – undo
661 661
         $invoice->recalculate_total();
662 662
         $invoice->save();
663 663
         ob_start();
664
-        GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice );
664
+        GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice);
665 665
         $row = ob_get_clean();
666
-        wp_send_json_success( compact( 'row' ) );
666
+        wp_send_json_success(compact('row'));
667 667
     }
668 668
 
669 669
     /**
@@ -672,33 +672,33 @@  discard block
 block discarded – undo
672 672
     public static function remove_invoice_item() {
673 673
 
674 674
         // Verify nonce.
675
-        check_ajax_referer( 'wpinv-nonce' );
675
+        check_ajax_referer('wpinv-nonce');
676 676
 
677
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
677
+        if (!wpinv_current_user_can_manage_invoicing()) {
678 678
             exit;
679 679
         }
680 680
 
681 681
         // We need an invoice and an item.
682
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) {
682
+        if (empty($_POST['post_id']) || empty($_POST['item_id'])) {
683 683
             exit;
684 684
         }
685 685
 
686 686
         // Fetch the invoice.
687
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
687
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
688 688
 
689 689
         // Ensure it exists and its not been paid for.
690
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
690
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
691 691
             exit;
692 692
         }
693 693
 
694 694
         // Abort if the invoice does not have the specified item.
695
-        $item = $invoice->get_item( (int) $_POST['item_id'] );
695
+        $item = $invoice->get_item((int) $_POST['item_id']);
696 696
 
697
-        if ( empty( $item ) ) {
697
+        if (empty($item)) {
698 698
             exit;
699 699
         }
700 700
 
701
-        $invoice->remove_item( (int) $_POST['item_id'] );
701
+        $invoice->remove_item((int) $_POST['item_id']);
702 702
 
703 703
         // Update totals.
704 704
         $invoice->recalculate_total();
@@ -709,11 +709,11 @@  discard block
 block discarded – undo
709 709
         // Return an array of invoice items.
710 710
         $items = array();
711 711
 
712
-        foreach ( $invoice->get_items() as $item ) {
713
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
712
+        foreach ($invoice->get_items() as $item) {
713
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
714 714
         }
715 715
 
716
-        wp_send_json_success( compact( 'items' ) );
716
+        wp_send_json_success(compact('items'));
717 717
     }
718 718
 
719 719
     /**
@@ -722,68 +722,68 @@  discard block
 block discarded – undo
722 722
     public static function recalculate_full_prices() {
723 723
 
724 724
         // Verify nonce.
725
-        check_ajax_referer( 'wpinv-nonce' );
725
+        check_ajax_referer('wpinv-nonce');
726 726
 
727
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
727
+        if (!wpinv_current_user_can_manage_invoicing()) {
728 728
             exit;
729 729
         }
730 730
 
731 731
         // We need an invoice and item.
732
-        if ( empty( $_POST['post_id'] ) ) {
732
+        if (empty($_POST['post_id'])) {
733 733
             exit;
734 734
         }
735 735
 
736 736
         // Fetch the invoice.
737
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
737
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
738 738
         $alert   = false;
739 739
 
740 740
         // Ensure it exists and its not been paid for.
741
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
741
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
742 742
             exit;
743 743
         }
744 744
 
745
-        $invoice->set_items( array() );
745
+        $invoice->set_items(array());
746 746
 
747
-        if ( ! empty( $_POST['getpaid_items'] ) ) {
747
+        if (!empty($_POST['getpaid_items'])) {
748 748
 
749
-            foreach ( wp_kses_post_deep( $_POST['getpaid_items'] ) as $item_id => $args ) {
750
-                $item = new GetPaid_Form_Item( $item_id );
749
+            foreach (wp_kses_post_deep($_POST['getpaid_items']) as $item_id => $args) {
750
+                $item = new GetPaid_Form_Item($item_id);
751 751
 
752
-                if ( $item->exists() ) {
753
-                    $item->set_price( getpaid_standardize_amount( $args['price'] ) );
754
-                    $item->set_quantity( floatval( $args['quantity'] ) );
755
-                    $item->set_name( sanitize_text_field( $args['name'] ) );
756
-                    $item->set_description( wp_kses_post( $args['description'] ) );
757
-                    $invoice->add_item( $item );
752
+                if ($item->exists()) {
753
+                    $item->set_price(getpaid_standardize_amount($args['price']));
754
+                    $item->set_quantity(floatval($args['quantity']));
755
+                    $item->set_name(sanitize_text_field($args['name']));
756
+                    $item->set_description(wp_kses_post($args['description']));
757
+                    $invoice->add_item($item);
758 758
                 }
759 759
             }
760 760
 }
761 761
 
762
-        $invoice->set_disable_taxes( ! empty( $_POST['disable_taxes'] ) );
762
+        $invoice->set_disable_taxes(!empty($_POST['disable_taxes']));
763 763
 
764 764
         // Maybe set the country, state, currency.
765
-        foreach ( array( 'wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code' ) as $key ) {
766
-            if ( isset( $_POST[ $key ] ) ) {
767
-                $_key   = str_replace( 'wpinv_', '', $key );
765
+        foreach (array('wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code') as $key) {
766
+            if (isset($_POST[$key])) {
767
+                $_key   = str_replace('wpinv_', '', $key);
768 768
                 $method = "set_$_key";
769
-                $invoice->$method( sanitize_text_field( $_POST[ $key ] ) );
769
+                $invoice->$method(sanitize_text_field($_POST[$key]));
770 770
             }
771 771
         }
772 772
 
773
-        $discount = new WPInv_Discount( $invoice->get_discount_code() );
774
-        if ( $discount->exists() ) {
775
-            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
773
+        $discount = new WPInv_Discount($invoice->get_discount_code());
774
+        if ($discount->exists()) {
775
+            $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
776 776
         } else {
777
-            $invoice->remove_discount( 'discount_code' );
777
+            $invoice->remove_discount('discount_code');
778 778
         }
779 779
 
780 780
         // Save the invoice.
781 781
         $invoice->recalculate_total();
782 782
         $invoice->save();
783 783
         ob_start();
784
-        GetPaid_Meta_Box_Invoice_Items::output( get_post( $invoice->get_id() ), $invoice );
784
+        GetPaid_Meta_Box_Invoice_Items::output(get_post($invoice->get_id()), $invoice);
785 785
         $table = ob_get_clean();
786
-        wp_send_json_success( compact( 'table' ) );
786
+        wp_send_json_success(compact('table'));
787 787
     }
788 788
 
789 789
     /**
@@ -792,42 +792,42 @@  discard block
 block discarded – undo
792 792
     public static function admin_add_invoice_item() {
793 793
 
794 794
         // Verify nonce.
795
-        check_ajax_referer( 'wpinv-nonce' );
795
+        check_ajax_referer('wpinv-nonce');
796 796
 
797
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
797
+        if (!wpinv_current_user_can_manage_invoicing()) {
798 798
             exit;
799 799
         }
800 800
 
801 801
         // We need an invoice and item.
802
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) {
802
+        if (empty($_POST['post_id']) || empty($_POST['item_id'])) {
803 803
             exit;
804 804
         }
805 805
 
806 806
         // Fetch the invoice.
807
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
807
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
808 808
         $alert   = false;
809 809
 
810 810
         // Ensure it exists and its not been paid for.
811
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
811
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
812 812
             exit;
813 813
         }
814 814
 
815 815
         // Add the item.
816
-        $item  = new GetPaid_Form_Item( (int) $_POST['item_id'] );
817
-        $error = $invoice->add_item( $item );
816
+        $item  = new GetPaid_Form_Item((int) $_POST['item_id']);
817
+        $error = $invoice->add_item($item);
818 818
 
819
-        if ( is_wp_error( $error ) ) {
819
+        if (is_wp_error($error)) {
820 820
             $alert = $error->get_error_message();
821
-            wp_send_json_success( compact( 'alert' ) );
821
+            wp_send_json_success(compact('alert'));
822 822
         }
823 823
 
824 824
         // Save the invoice.
825 825
         $invoice->recalculate_total();
826 826
         $invoice->save();
827 827
         ob_start();
828
-        GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice );
828
+        GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice);
829 829
         $row = ob_get_clean();
830
-        wp_send_json_success( compact( 'row' ) );
830
+        wp_send_json_success(compact('row'));
831 831
     }
832 832
 
833 833
     /**
@@ -836,39 +836,39 @@  discard block
 block discarded – undo
836 836
     public static function add_invoice_items() {
837 837
 
838 838
         // Verify nonce.
839
-        check_ajax_referer( 'wpinv-nonce' );
839
+        check_ajax_referer('wpinv-nonce');
840 840
 
841
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
841
+        if (!wpinv_current_user_can_manage_invoicing()) {
842 842
             exit;
843 843
         }
844 844
 
845 845
         // We need an invoice and items.
846
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) {
846
+        if (empty($_POST['post_id']) || empty($_POST['items'])) {
847 847
             exit;
848 848
         }
849 849
 
850 850
         // Fetch the invoice.
851
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
851
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
852 852
         $alert   = false;
853 853
 
854 854
         // Ensure it exists and its not been paid for.
855
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
855
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
856 856
             exit;
857 857
         }
858 858
 
859 859
         // Add the items.
860
-        foreach ( wp_kses_post_deep( wp_unslash( $_POST['items'] ) ) as $data ) {
860
+        foreach (wp_kses_post_deep(wp_unslash($_POST['items'])) as $data) {
861 861
 
862
-            $item = new GetPaid_Form_Item( (int) $data['id'] );
862
+            $item = new GetPaid_Form_Item((int) $data['id']);
863 863
 
864
-            if ( is_numeric( $data['qty'] ) && (float) $data['qty'] > 0 ) {
865
-                $item->set_quantity( floatval( $data['qty'] ) );
864
+            if (is_numeric($data['qty']) && (float) $data['qty'] > 0) {
865
+                $item->set_quantity(floatval($data['qty']));
866 866
             }
867 867
 
868
-            if ( $item->get_id() > 0 ) {
869
-                $error = $invoice->add_item( $item );
868
+            if ($item->get_id() > 0) {
869
+                $error = $invoice->add_item($item);
870 870
 
871
-                if ( is_wp_error( $error ) ) {
871
+                if (is_wp_error($error)) {
872 872
                     $alert = $error->get_error_message();
873 873
                 }
874 874
 }
@@ -881,11 +881,11 @@  discard block
 block discarded – undo
881 881
         // Return an array of invoice items.
882 882
         $items = array();
883 883
 
884
-        foreach ( $invoice->get_items() as $item ) {
885
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
884
+        foreach ($invoice->get_items() as $item) {
885
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
886 886
         }
887 887
 
888
-        wp_send_json_success( compact( 'items', 'alert' ) );
888
+        wp_send_json_success(compact('items', 'alert'));
889 889
     }
890 890
 
891 891
     /**
@@ -894,15 +894,15 @@  discard block
 block discarded – undo
894 894
     public static function get_invoicing_items() {
895 895
 
896 896
         // Verify nonce.
897
-        check_ajax_referer( 'wpinv-nonce' );
897
+        check_ajax_referer('wpinv-nonce');
898 898
 
899
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
899
+        if (!wpinv_current_user_can_manage_invoicing()) {
900 900
             exit;
901 901
         }
902 902
 
903 903
         // We need a search term.
904
-        if ( empty( $_GET['search'] ) ) {
905
-            wp_send_json_success( array() );
904
+        if (empty($_GET['search'])) {
905
+            wp_send_json_success(array());
906 906
         }
907 907
 
908 908
         // Retrieve items.
@@ -911,8 +911,8 @@  discard block
 block discarded – undo
911 911
             'orderby'        => 'title',
912 912
             'order'          => 'ASC',
913 913
             'posts_per_page' => -1,
914
-            'post_status'    => array( 'publish' ),
915
-            's'              => sanitize_text_field( urldecode( $_GET['search'] ) ),
914
+            'post_status'    => array('publish'),
915
+            's'              => sanitize_text_field(urldecode($_GET['search'])),
916 916
             'meta_query'     => array(
917 917
                 array(
918 918
                     'key'     => '_wpinv_type',
@@ -922,25 +922,25 @@  discard block
 block discarded – undo
922 922
             ),
923 923
         );
924 924
 
925
-        if ( ! empty( $_GET['ignore'] ) ) {
926
-            $item_args['exclude'] = wp_parse_id_list( sanitize_text_field( $_GET['ignore'] ) );
925
+        if (!empty($_GET['ignore'])) {
926
+            $item_args['exclude'] = wp_parse_id_list(sanitize_text_field($_GET['ignore']));
927 927
         }
928 928
 
929
-        $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) );
929
+        $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args));
930 930
         $data  = array();
931 931
 
932
-        $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( (int) $_GET['post_id'] ) );
932
+        $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type((int) $_GET['post_id']));
933 933
 
934
-        foreach ( $items as $item ) {
935
-            $item      = new GetPaid_Form_Item( $item );
934
+        foreach ($items as $item) {
935
+            $item = new GetPaid_Form_Item($item);
936 936
             $data[] = array(
937 937
                 'id'        => (int) $item->get_id(),
938
-                'text'      => strip_tags( $item->get_name() ),
939
-                'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '',
938
+                'text'      => strip_tags($item->get_name()),
939
+                'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '',
940 940
             );
941 941
         }
942 942
 
943
-        wp_send_json_success( $data );
943
+        wp_send_json_success($data);
944 944
 
945 945
     }
946 946
 
@@ -950,37 +950,37 @@  discard block
 block discarded – undo
950 950
     public static function get_customers() {
951 951
 
952 952
         // Verify nonce.
953
-        check_ajax_referer( 'wpinv-nonce' );
953
+        check_ajax_referer('wpinv-nonce');
954 954
 
955
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
955
+        if (!wpinv_current_user_can_manage_invoicing()) {
956 956
             exit;
957 957
         }
958 958
 
959 959
         // We need a search term.
960
-        if ( empty( $_GET['search'] ) ) {
961
-            wp_send_json_success( array() );
960
+        if (empty($_GET['search'])) {
961
+            wp_send_json_success(array());
962 962
         }
963 963
 
964 964
         // Retrieve customers.
965 965
 
966 966
         $customer_args = array(
967
-            'fields'         => array( 'ID', 'user_email', 'display_name' ),
967
+            'fields'         => array('ID', 'user_email', 'display_name'),
968 968
             'orderby'        => 'display_name',
969
-            'search'         => '*' . sanitize_text_field( $_GET['search'] ) . '*',
970
-            'search_columns' => array( 'user_login', 'user_email', 'display_name' ),
969
+            'search'         => '*' . sanitize_text_field($_GET['search']) . '*',
970
+            'search_columns' => array('user_login', 'user_email', 'display_name'),
971 971
         );
972 972
 
973
-        $customers = get_users( apply_filters( 'getpaid_ajax_invoice_customers_query_args', $customer_args ) );
973
+        $customers = get_users(apply_filters('getpaid_ajax_invoice_customers_query_args', $customer_args));
974 974
         $data      = array();
975 975
 
976
-        foreach ( $customers as $customer ) {
976
+        foreach ($customers as $customer) {
977 977
             $data[] = array(
978 978
                 'id'   => (int) $customer->ID,
979
-                'text' => strip_tags( sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ) ),
979
+                'text' => strip_tags(sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email)),
980 980
             );
981 981
         }
982 982
 
983
-        wp_send_json_success( $data );
983
+        wp_send_json_success($data);
984 984
 
985 985
     }
986 986
 
@@ -990,28 +990,28 @@  discard block
 block discarded – undo
990 990
     public static function get_aui_states_field() {
991 991
 
992 992
         // Verify nonce.
993
-        check_ajax_referer( 'wpinv-nonce' );
993
+        check_ajax_referer('wpinv-nonce');
994 994
 
995 995
         // We need a country.
996
-        if ( empty( $_GET['country'] ) ) {
996
+        if (empty($_GET['country'])) {
997 997
             exit;
998 998
         }
999 999
 
1000
-        $states = wpinv_get_country_states( sanitize_text_field( $_GET['country'] ) );
1001
-        $state  = isset( $_GET['state'] ) ? sanitize_text_field( $_GET['state'] ) : wpinv_get_default_state();
1002
-        $name   = isset( $_GET['name'] ) ? sanitize_text_field( $_GET['name'] ) : 'wpinv_state';
1003
-        $class  = isset( $_GET['class'] ) ? sanitize_text_field( $_GET['class'] ) : 'form-control-sm';
1000
+        $states = wpinv_get_country_states(sanitize_text_field($_GET['country']));
1001
+        $state  = isset($_GET['state']) ? sanitize_text_field($_GET['state']) : wpinv_get_default_state();
1002
+        $name   = isset($_GET['name']) ? sanitize_text_field($_GET['name']) : 'wpinv_state';
1003
+        $class  = isset($_GET['class']) ? sanitize_text_field($_GET['class']) : 'form-control-sm';
1004 1004
 
1005
-        if ( empty( $states ) ) {
1005
+        if (empty($states)) {
1006 1006
 
1007 1007
             $html = aui()->input(
1008 1008
                 array(
1009 1009
                     'type'        => 'text',
1010 1010
                     'id'          => 'wpinv_state',
1011 1011
                     'name'        => $name,
1012
-                    'label'       => __( 'State', 'invoicing' ),
1012
+                    'label'       => __('State', 'invoicing'),
1013 1013
                     'label_type'  => 'vertical',
1014
-                    'placeholder' => __( 'State', 'invoicing' ),
1014
+                    'placeholder' => __('State', 'invoicing'),
1015 1015
                     'class'       => $class,
1016 1016
                     'value'       => $state,
1017 1017
                 )
@@ -1023,9 +1023,9 @@  discard block
 block discarded – undo
1023 1023
                 array(
1024 1024
                     'id'               => 'wpinv_state',
1025 1025
                     'name'             => $name,
1026
-                    'label'            => __( 'State', 'invoicing' ),
1026
+                    'label'            => __('State', 'invoicing'),
1027 1027
                     'label_type'       => 'vertical',
1028
-                    'placeholder'      => __( 'Select a state', 'invoicing' ),
1028
+                    'placeholder'      => __('Select a state', 'invoicing'),
1029 1029
                     'class'            => $class,
1030 1030
                     'value'            => $state,
1031 1031
                     'options'          => $states,
@@ -1039,7 +1039,7 @@  discard block
 block discarded – undo
1039 1039
         wp_send_json_success(
1040 1040
             array(
1041 1041
                 'html'   => $html,
1042
-                'select' => ! empty( $states ),
1042
+                'select' => !empty($states),
1043 1043
             )
1044 1044
         );
1045 1045
 
@@ -1053,11 +1053,11 @@  discard block
 block discarded – undo
1053 1053
     public static function payment_form_refresh_prices() {
1054 1054
 
1055 1055
         // Check nonce.
1056
-        check_ajax_referer( 'getpaid_form_nonce' );
1056
+        check_ajax_referer('getpaid_form_nonce');
1057 1057
 
1058 1058
         // ... form fields...
1059
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
1060
-            esc_html_e( 'Error: Reload the page and try again.', 'invoicing' );
1059
+        if (empty($_POST['getpaid_payment_form_submission'])) {
1060
+            esc_html_e('Error: Reload the page and try again.', 'invoicing');
1061 1061
             exit;
1062 1062
         }
1063 1063
 
@@ -1065,7 +1065,7 @@  discard block
 block discarded – undo
1065 1065
         $submission = new GetPaid_Payment_Form_Submission();
1066 1066
 
1067 1067
         // Do we have an error?
1068
-        if ( ! empty( $submission->last_error ) ) {
1068
+        if (!empty($submission->last_error)) {
1069 1069
             wp_send_json_error(
1070 1070
                 array(
1071 1071
                     'code'  => $submission->last_error_code,
@@ -1075,12 +1075,12 @@  discard block
 block discarded – undo
1075 1075
         }
1076 1076
 
1077 1077
         // Prepare the response.
1078
-        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission );
1078
+        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission);
1079 1079
 
1080 1080
         // Filter the response.
1081
-        $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission );
1081
+        $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission);
1082 1082
 
1083
-        wp_send_json_success( $response );
1083
+        wp_send_json_success($response);
1084 1084
     }
1085 1085
 
1086 1086
     /**
@@ -1092,63 +1092,63 @@  discard block
 block discarded – undo
1092 1092
 	public static function file_upload() {
1093 1093
 
1094 1094
         // Check nonce.
1095
-        check_ajax_referer( 'getpaid_form_nonce' );
1095
+        check_ajax_referer('getpaid_form_nonce');
1096 1096
 
1097
-        if ( empty( $_POST['form_id'] ) || empty( $_POST['field_name'] ) || empty( $_FILES['file'] ) ) {
1098
-            wp_die( esc_html_e( 'Bad Request', 'invoicing' ), 400 );
1097
+        if (empty($_POST['form_id']) || empty($_POST['field_name']) || empty($_FILES['file'])) {
1098
+            wp_die(esc_html_e('Bad Request', 'invoicing'), 400);
1099 1099
         }
1100 1100
 
1101 1101
         // Fetch form.
1102
-        $form = new GetPaid_Payment_Form( intval( $_POST['form_id'] ) );
1102
+        $form = new GetPaid_Payment_Form(intval($_POST['form_id']));
1103 1103
 
1104
-        if ( ! $form->is_active() ) {
1105
-            wp_send_json_error( __( 'Payment form not active', 'invoicing' ) );
1104
+        if (!$form->is_active()) {
1105
+            wp_send_json_error(__('Payment form not active', 'invoicing'));
1106 1106
         }
1107 1107
 
1108 1108
         // Fetch appropriate field.
1109
-        $upload_field = current( wp_list_filter( $form->get_elements(), array( 'id' => sanitize_text_field( $_POST['field_name'] ) ) ) );
1110
-        if ( empty( $upload_field ) ) {
1111
-            wp_send_json_error( __( 'Invalid upload field.', 'invoicing' ) );
1109
+        $upload_field = current(wp_list_filter($form->get_elements(), array('id' => sanitize_text_field($_POST['field_name']))));
1110
+        if (empty($upload_field)) {
1111
+            wp_send_json_error(__('Invalid upload field.', 'invoicing'));
1112 1112
         }
1113 1113
 
1114 1114
         // Prepare allowed file types.
1115
-        $file_types = isset( $upload_field['file_types'] ) ? $upload_field['file_types'] : array( 'jpg|jpeg|jpe', 'gif', 'png' );
1115
+        $file_types = isset($upload_field['file_types']) ? $upload_field['file_types'] : array('jpg|jpeg|jpe', 'gif', 'png');
1116 1116
         $all_types  = getpaid_get_allowed_mime_types();
1117 1117
         $mime_types = array();
1118 1118
 
1119
-        foreach ( $file_types as $file_type ) {
1120
-            if ( isset( $all_types[ $file_type ] ) ) {
1121
-                $mime_types[] = $all_types[ $file_type ];
1119
+        foreach ($file_types as $file_type) {
1120
+            if (isset($all_types[$file_type])) {
1121
+                $mime_types[] = $all_types[$file_type];
1122 1122
             }
1123 1123
         }
1124 1124
 
1125
-        if ( ! in_array( $_FILES['file']['type'], $mime_types ) ) {
1126
-            wp_send_json_error( __( 'Unsupported file type.', 'invoicing' ) );
1125
+        if (!in_array($_FILES['file']['type'], $mime_types)) {
1126
+            wp_send_json_error(__('Unsupported file type.', 'invoicing'));
1127 1127
         }
1128 1128
 
1129 1129
         // Upload file.
1130
-        $file_name = explode( '.', strtolower( $_FILES['file']['name'] ) );
1131
-        $file_name = uniqid( 'getpaid-' ) . '.' . array_pop( $file_name );
1130
+        $file_name = explode('.', strtolower($_FILES['file']['name']));
1131
+        $file_name = uniqid('getpaid-') . '.' . array_pop($file_name);
1132 1132
 
1133 1133
         $uploaded = wp_upload_bits(
1134 1134
             $file_name,
1135 1135
             null,
1136
-            file_get_contents( $_FILES['file']['tmp_name'] )
1136
+            file_get_contents($_FILES['file']['tmp_name'])
1137 1137
         );
1138 1138
 
1139
-        if ( ! empty( $uploaded['error'] ) ) {
1140
-            wp_send_json_error( $uploaded['error'] );
1139
+        if (!empty($uploaded['error'])) {
1140
+            wp_send_json_error($uploaded['error']);
1141 1141
         }
1142 1142
 
1143 1143
         // Retrieve response.
1144 1144
         $response = sprintf(
1145 1145
             '<input type="hidden" name="%s[%s]" value="%s" />',
1146
-            esc_attr( sanitize_text_field( $_POST['field_name'] ) ),
1147
-            esc_url( $uploaded['url'] ),
1148
-            esc_attr( sanitize_text_field( strtolower( $_FILES['file']['name'] ) ) )
1146
+            esc_attr(sanitize_text_field($_POST['field_name'])),
1147
+            esc_url($uploaded['url']),
1148
+            esc_attr(sanitize_text_field(strtolower($_FILES['file']['name'])))
1149 1149
         );
1150 1150
 
1151
-        wp_send_json_success( $response );
1151
+        wp_send_json_success($response);
1152 1152
 
1153 1153
 	}
1154 1154
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-items.php 1 patch
Spacing   +34 added lines, -34 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
  * Payment form submission itemss class
@@ -23,37 +23,37 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @param GetPaid_Payment_Form_Submission $submission
25 25
 	 */
26
-	public function __construct( $submission ) {
26
+	public function __construct($submission) {
27 27
 
28 28
 		$data         = $submission->get_data();
29 29
 		$payment_form = $submission->get_payment_form();
30 30
 
31 31
 		// Prepare the selected items.
32 32
 		$selected_items = array();
33
-		if ( ! empty( $data['getpaid-items'] ) ) {
34
-			$selected_items = wpinv_clean( $data['getpaid-items'] );
33
+		if (!empty($data['getpaid-items'])) {
34
+			$selected_items = wpinv_clean($data['getpaid-items']);
35 35
 		}
36 36
 
37 37
 		// (Maybe) set form items.
38
-		if ( isset( $data['getpaid-form-items'] ) ) {
38
+		if (isset($data['getpaid-form-items'])) {
39 39
 
40 40
 			// Confirm items key.
41
-			$form_items = wpinv_clean( $data['getpaid-form-items'] );
42
-			if ( ! isset( $data['getpaid-form-items-key'] ) || $data['getpaid-form-items-key'] !== md5( NONCE_KEY . AUTH_KEY . $form_items ) ) {
43
-				throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) );
41
+			$form_items = wpinv_clean($data['getpaid-form-items']);
42
+			if (!isset($data['getpaid-form-items-key']) || $data['getpaid-form-items-key'] !== md5(NONCE_KEY . AUTH_KEY . $form_items)) {
43
+				throw new Exception(__('We could not validate the form items. Please reload the page and try again.', 'invoicing'));
44 44
 			}
45 45
 
46
-			$items    = array();
46
+			$items = array();
47 47
             $item_ids = array();
48 48
 
49
-            foreach ( getpaid_convert_items_to_array( $form_items ) as $item_id => $qty ) {
50
-                if ( ! in_array( $item_id, $item_ids ) ) {
51
-                    $item = new GetPaid_Form_Item( $item_id );
52
-                    $item->set_quantity( $qty );
49
+            foreach (getpaid_convert_items_to_array($form_items) as $item_id => $qty) {
50
+                if (!in_array($item_id, $item_ids)) {
51
+                    $item = new GetPaid_Form_Item($item_id);
52
+                    $item->set_quantity($qty);
53 53
 
54
-                    if ( 0 == $qty ) {
55
-                        $item->set_allow_quantities( true );
56
-                        $item->set_is_required( false );
54
+                    if (0 == $qty) {
55
+                        $item->set_allow_quantities(true);
56
+                        $item->set_is_required(false);
57 57
                     }
58 58
 
59 59
                     $item_ids[] = $item->get_id();
@@ -61,23 +61,23 @@  discard block
 block discarded – undo
61 61
                 }
62 62
             }
63 63
 
64
-            if ( ! $payment_form->is_default() ) {
64
+            if (!$payment_form->is_default()) {
65 65
 
66
-                foreach ( $payment_form->get_items() as $item ) {
67
-                    if ( ! in_array( $item->get_id(), $item_ids ) ) {
66
+                foreach ($payment_form->get_items() as $item) {
67
+                    if (!in_array($item->get_id(), $item_ids)) {
68 68
                         $item_ids[] = $item->get_id();
69 69
                         $items[]    = $item;
70 70
                     }
71 71
                 }
72 72
 			}
73 73
 
74
-            $payment_form->set_items( $items );
74
+            $payment_form->set_items($items);
75 75
 
76 76
 		}
77 77
 
78 78
 		// Process each individual item.
79
-		foreach ( $payment_form->get_items() as $item ) {
80
-			$this->process_item( $item, $selected_items, $submission );
79
+		foreach ($payment_form->get_items() as $item) {
80
+			$this->process_item($item, $selected_items, $submission);
81 81
 		}
82 82
 
83 83
 	}
@@ -89,40 +89,40 @@  discard block
 block discarded – undo
89 89
 	 * @param array $selected_items
90 90
 	 * @param GetPaid_Payment_Form_Submission $submission
91 91
 	 */
92
-	public function process_item( $item, $selected_items, $submission ) {
92
+	public function process_item($item, $selected_items, $submission) {
93 93
 
94 94
 		// Abort if this is an optional item and it has not been selected.
95
-		if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
95
+		if (!$item->is_required() && !isset($selected_items[$item->get_id()])) {
96 96
 			return;
97 97
 		}
98 98
 
99 99
 		// (maybe) let customers change the quantities and prices.
100
-		if ( isset( $selected_items[ $item->get_id() ] ) ) {
100
+		if (isset($selected_items[$item->get_id()])) {
101 101
 
102 102
 			// Maybe change the quantities.
103
-			if ( $item->allows_quantities() ) {
104
-				$item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] );
103
+			if ($item->allows_quantities()) {
104
+				$item->set_quantity((float) $selected_items[$item->get_id()]['quantity']);
105 105
 			}
106 106
 
107 107
 			// Maybe change the price.
108
-			if ( $item->user_can_set_their_price() ) {
109
-				$price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
108
+			if ($item->user_can_set_their_price()) {
109
+				$price = (float) wpinv_sanitize_amount($selected_items[$item->get_id()]['price']);
110 110
 
111
-				if ( $item->get_minimum_price() > $price ) {
112
-					throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) );
111
+				if ($item->get_minimum_price() > $price) {
112
+					throw new Exception(sprintf(__('The minimum allowed amount is %s', 'invoicing'), getpaid_unstandardize_amount($item->get_minimum_price())));
113 113
 				}
114 114
 
115
-				$item->set_price( $price );
115
+				$item->set_price($price);
116 116
 
117 117
 			}
118 118
 		}
119 119
 
120
-		if ( 0 == $item->get_quantity() ) {
120
+		if (0 == $item->get_quantity()) {
121 121
 			return;
122 122
 		}
123 123
 
124 124
 		// Save the item.
125
-		$this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item', $item, $submission );
125
+		$this->items[] = apply_filters('getpaid_payment_form_submission_processed_item', $item, $submission);
126 126
 
127 127
 	}
128 128
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form.php 1 patch
Spacing   +158 added lines, -158 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
 
@@ -72,28 +72,28 @@  discard block
 block discarded – undo
72 72
 	 *
73 73
 	 * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74 74
 	 */
75
-	public function __construct( $form = 0 ) {
76
-		parent::__construct( $form );
75
+	public function __construct($form = 0) {
76
+		parent::__construct($form);
77 77
 
78
-		if ( is_numeric( $form ) && $form > 0 ) {
79
-			$this->set_id( $form );
80
-		} elseif ( $form instanceof self ) {
78
+		if (is_numeric($form) && $form > 0) {
79
+			$this->set_id($form);
80
+		} elseif ($form instanceof self) {
81 81
 
82
-			$this->set_id( $form->get_id() );
82
+			$this->set_id($form->get_id());
83 83
 			$this->invoice = $form->invoice;
84 84
 
85
-		} elseif ( ! empty( $form->ID ) ) {
86
-			$this->set_id( $form->ID );
85
+		} elseif (!empty($form->ID)) {
86
+			$this->set_id($form->ID);
87 87
 		} else {
88
-			$this->set_object_read( true );
88
+			$this->set_object_read(true);
89 89
 		}
90 90
 
91 91
         // Load the datastore.
92
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
92
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
93 93
 
94
-		if ( $this->get_id() > 0 ) {
95
-            $this->post = get_post( $this->get_id() );
96
-			$this->data_store->read( $this );
94
+		if ($this->get_id() > 0) {
95
+            $this->post = get_post($this->get_id());
96
+			$this->data_store->read($this);
97 97
         }
98 98
 
99 99
 	}
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
 	 * @param  string $context View or edit context.
121 121
 	 * @return string
122 122
 	 */
123
-	public function get_version( $context = 'view' ) {
124
-		return $this->get_prop( 'version', $context );
123
+	public function get_version($context = 'view') {
124
+		return $this->get_prop('version', $context);
125 125
     }
126 126
 
127 127
     /**
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
 	 * @param  string $context View or edit context.
132 132
 	 * @return string
133 133
 	 */
134
-	public function get_date_created( $context = 'view' ) {
135
-		return $this->get_prop( 'date_created', $context );
134
+	public function get_date_created($context = 'view') {
135
+		return $this->get_prop('date_created', $context);
136 136
     }
137 137
 
138 138
     /**
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
 	 * @param  string $context View or edit context.
143 143
 	 * @return string
144 144
 	 */
145
-	public function get_date_created_gmt( $context = 'view' ) {
146
-        $date = $this->get_date_created( $context );
145
+	public function get_date_created_gmt($context = 'view') {
146
+        $date = $this->get_date_created($context);
147 147
 
148
-        if ( $date ) {
149
-            $date = get_gmt_from_date( $date );
148
+        if ($date) {
149
+            $date = get_gmt_from_date($date);
150 150
         }
151 151
 		return $date;
152 152
     }
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
 	 * @param  string $context View or edit context.
159 159
 	 * @return string
160 160
 	 */
161
-	public function get_date_modified( $context = 'view' ) {
162
-		return $this->get_prop( 'date_modified', $context );
161
+	public function get_date_modified($context = 'view') {
162
+		return $this->get_prop('date_modified', $context);
163 163
     }
164 164
 
165 165
     /**
@@ -169,11 +169,11 @@  discard block
 block discarded – undo
169 169
 	 * @param  string $context View or edit context.
170 170
 	 * @return string
171 171
 	 */
172
-	public function get_date_modified_gmt( $context = 'view' ) {
173
-        $date = $this->get_date_modified( $context );
172
+	public function get_date_modified_gmt($context = 'view') {
173
+        $date = $this->get_date_modified($context);
174 174
 
175
-        if ( $date ) {
176
-            $date = get_gmt_from_date( $date );
175
+        if ($date) {
176
+            $date = get_gmt_from_date($date);
177 177
         }
178 178
 		return $date;
179 179
     }
@@ -185,8 +185,8 @@  discard block
 block discarded – undo
185 185
 	 * @param  string $context View or edit context.
186 186
 	 * @return string
187 187
 	 */
188
-	public function get_name( $context = 'view' ) {
189
-		return $this->get_prop( 'name', $context );
188
+	public function get_name($context = 'view') {
189
+		return $this->get_prop('name', $context);
190 190
     }
191 191
 
192 192
     /**
@@ -196,8 +196,8 @@  discard block
 block discarded – undo
196 196
 	 * @param  string $context View or edit context.
197 197
 	 * @return string
198 198
 	 */
199
-	public function get_title( $context = 'view' ) {
200
-		return $this->get_name( $context );
199
+	public function get_title($context = 'view') {
200
+		return $this->get_name($context);
201 201
 	}
202 202
 
203 203
     /**
@@ -207,8 +207,8 @@  discard block
 block discarded – undo
207 207
 	 * @param  string $context View or edit context.
208 208
 	 * @return int
209 209
 	 */
210
-	public function get_author( $context = 'view' ) {
211
-		return (int) $this->get_prop( 'author', $context );
210
+	public function get_author($context = 'view') {
211
+		return (int) $this->get_prop('author', $context);
212 212
     }
213 213
 
214 214
     /**
@@ -218,21 +218,21 @@  discard block
 block discarded – undo
218 218
 	 * @param  string $context View or edit context.
219 219
 	 * @return array
220 220
 	 */
221
-	public function get_elements( $context = 'view' ) {
222
-		$elements = $this->get_prop( 'elements', $context );
221
+	public function get_elements($context = 'view') {
222
+		$elements = $this->get_prop('elements', $context);
223 223
 
224
-		if ( empty( $elements ) || ! is_array( $elements ) ) {
225
-            return wpinv_get_data( 'sample-payment-form' );
224
+		if (empty($elements) || !is_array($elements)) {
225
+            return wpinv_get_data('sample-payment-form');
226 226
 		}
227 227
 
228 228
 		// Ensure that all required elements exist.
229 229
 		$_elements = array();
230
-		foreach ( $elements as $element ) {
230
+		foreach ($elements as $element) {
231 231
 
232
-			if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
232
+			if ($element['type'] == 'pay_button' && !$this->has_element_type('gateway_select')) {
233 233
 
234 234
 				$_elements[] = array(
235
-					'text'    => __( 'Select Payment Method', 'invoicing' ),
235
+					'text'    => __('Select Payment Method', 'invoicing'),
236 236
 					'id'      => 'gtscicd',
237 237
 					'name'    => 'gtscicd',
238 238
 					'type'    => 'gateway_select',
@@ -257,22 +257,22 @@  discard block
 block discarded – undo
257 257
 	 * @param  string $return objects or arrays.
258 258
 	 * @return GetPaid_Form_Item[]
259 259
 	 */
260
-	public function get_items( $context = 'view', $return = 'objects' ) {
261
-		$items = $this->get_prop( 'items', $context );
260
+	public function get_items($context = 'view', $return = 'objects') {
261
+		$items = $this->get_prop('items', $context);
262 262
 
263
-		if ( empty( $items ) || ! is_array( $items ) ) {
264
-            $items = wpinv_get_data( 'sample-payment-form-items' );
263
+		if (empty($items) || !is_array($items)) {
264
+            $items = wpinv_get_data('sample-payment-form-items');
265 265
 		}
266 266
 
267 267
 		// Convert the items.
268 268
 		$prepared = array();
269 269
 
270
-		foreach ( $items as $key => $value ) {
270
+		foreach ($items as $key => $value) {
271 271
 
272 272
 			// Form items.
273
-			if ( $value instanceof GetPaid_Form_Item ) {
273
+			if ($value instanceof GetPaid_Form_Item) {
274 274
 
275
-				if ( $value->can_purchase() ) {
275
+				if ($value->can_purchase()) {
276 276
 					$prepared[] = $value;
277 277
 				}
278 278
 
@@ -281,16 +281,16 @@  discard block
 block discarded – undo
281 281
 			}
282 282
 
283 283
 			// $item_id => $quantity (buy buttons)
284
-			if ( is_numeric( $key ) && is_numeric( $value ) ) {
285
-				$item = new GetPaid_Form_Item( $key );
284
+			if (is_numeric($key) && is_numeric($value)) {
285
+				$item = new GetPaid_Form_Item($key);
286 286
 
287
-				if ( $item->can_purchase() ) {
287
+				if ($item->can_purchase()) {
288 288
 
289 289
 					$value = (float) $value;
290
-					$item->set_quantity( $value );
291
-					if ( 0 == $value ) {
292
-						$item->set_quantity( 1 );
293
-						$item->set_allow_quantities( true );
290
+					$item->set_quantity($value);
291
+					if (0 == $value) {
292
+						$item->set_quantity(1);
293
+						$item->set_allow_quantities(true);
294 294
 					}
295 295
 
296 296
 					$prepared[] = $item;
@@ -300,33 +300,33 @@  discard block
 block discarded – undo
300 300
 			}
301 301
 
302 302
 			// Items saved via payment forms editor.
303
-			if ( is_array( $value ) && isset( $value['id'] ) ) {
303
+			if (is_array($value) && isset($value['id'])) {
304 304
 
305
-				$item = new GetPaid_Form_Item( $value['id'] );
305
+				$item = new GetPaid_Form_Item($value['id']);
306 306
 
307
-				if ( ! $item->can_purchase() ) {
307
+				if (!$item->can_purchase()) {
308 308
 					continue;
309 309
 				}
310 310
 
311 311
 				// Sub-total (Cart items).
312
-				if ( isset( $value['subtotal'] ) ) {
313
-					$item->set_price( $value['subtotal'] );
312
+				if (isset($value['subtotal'])) {
313
+					$item->set_price($value['subtotal']);
314 314
 				}
315 315
 
316
-				if ( isset( $value['quantity'] ) ) {
317
-					$item->set_quantity( $value['quantity'] );
316
+				if (isset($value['quantity'])) {
317
+					$item->set_quantity($value['quantity']);
318 318
 				}
319 319
 
320
-				if ( isset( $value['allow_quantities'] ) ) {
321
-					$item->set_allow_quantities( $value['allow_quantities'] );
320
+				if (isset($value['allow_quantities'])) {
321
+					$item->set_allow_quantities($value['allow_quantities']);
322 322
 				}
323 323
 
324
-				if ( isset( $value['required'] ) ) {
325
-					$item->set_is_required( $value['required'] );
324
+				if (isset($value['required'])) {
325
+					$item->set_is_required($value['required']);
326 326
 				}
327 327
 
328
-				if ( isset( $value['description'] ) ) {
329
-					$item->set_custom_description( $value['description'] );
328
+				if (isset($value['description'])) {
329
+					$item->set_custom_description($value['description']);
330 330
 				}
331 331
 
332 332
 				$prepared[] = $item;
@@ -335,14 +335,14 @@  discard block
 block discarded – undo
335 335
 			}
336 336
 
337 337
 			// $item_id => array( 'price' => 10 ) (item variations)
338
-			if ( is_numeric( $key ) && is_array( $value ) ) {
339
-				$item = new GetPaid_Form_Item( $key );
338
+			if (is_numeric($key) && is_array($value)) {
339
+				$item = new GetPaid_Form_Item($key);
340 340
 
341
-				if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
342
-					$item->set_price( $value['price'] );
341
+				if (isset($value['price']) && $item->user_can_set_their_price()) {
342
+					$item->set_price($value['price']);
343 343
 				}
344 344
 
345
-				if ( $item->can_purchase() ) {
345
+				if ($item->can_purchase()) {
346 346
 					$prepared[] = $item;
347 347
 				}
348 348
 
@@ -350,12 +350,12 @@  discard block
 block discarded – undo
350 350
 			}
351 351
 }
352 352
 
353
-		if ( 'objects' == $return && 'view' == $context ) {
353
+		if ('objects' == $return && 'view' == $context) {
354 354
 			return $prepared;
355 355
 		}
356 356
 
357 357
 		$items = array();
358
-		foreach ( $prepared as $item ) {
358
+		foreach ($prepared as $item) {
359 359
 			$items[] = $item->prepare_data_for_use();
360 360
 		}
361 361
 
@@ -369,14 +369,14 @@  discard block
 block discarded – undo
369 369
 	 * @param  int $item_id The item id to return.
370 370
 	 * @return GetPaid_Form_Item|bool
371 371
 	 */
372
-	public function get_item( $item_id ) {
372
+	public function get_item($item_id) {
373 373
 
374
-		if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
374
+		if (empty($item_id) || !is_numeric($item_id)) {
375 375
 			return false;
376 376
 		}
377 377
 
378
-		foreach ( $this->get_items() as $item ) {
379
-			if ( $item->get_id() == (int) $item_id ) {
378
+		foreach ($this->get_items() as $item) {
379
+			if ($item->get_id() == (int) $item_id) {
380 380
 				return $item;
381 381
 			}
382 382
 		}
@@ -392,15 +392,15 @@  discard block
 block discarded – undo
392 392
 	 * @param  string $element_type The element type to return.
393 393
 	 * @return array|bool
394 394
 	 */
395
-	public function get_element_type( $element_type ) {
395
+	public function get_element_type($element_type) {
396 396
 
397
-		if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
397
+		if (empty($element_type) || !is_scalar($element_type)) {
398 398
 			return false;
399 399
 		}
400 400
 
401
-		foreach ( $this->get_prop( 'elements' ) as $element ) {
401
+		foreach ($this->get_prop('elements') as $element) {
402 402
 
403
-			if ( $element['type'] == $element_type ) {
403
+			if ($element['type'] == $element_type) {
404 404
 				return $element;
405 405
 			}
406 406
 }
@@ -416,8 +416,8 @@  discard block
 block discarded – undo
416 416
 	 * @param  string $context View or edit context.
417 417
 	 * @return float
418 418
 	 */
419
-	public function get_earned( $context = 'view' ) {
420
-		return $this->get_prop( 'earned', $context );
419
+	public function get_earned($context = 'view') {
420
+		return $this->get_prop('earned', $context);
421 421
 	}
422 422
 
423 423
 	/**
@@ -427,8 +427,8 @@  discard block
 block discarded – undo
427 427
 	 * @param  string $context View or edit context.
428 428
 	 * @return float
429 429
 	 */
430
-	public function get_refunded( $context = 'view' ) {
431
-		return $this->get_prop( 'refunded', $context );
430
+	public function get_refunded($context = 'view') {
431
+		return $this->get_prop('refunded', $context);
432 432
 	}
433 433
 
434 434
 	/**
@@ -438,8 +438,8 @@  discard block
 block discarded – undo
438 438
 	 * @param  string $context View or edit context.
439 439
 	 * @return float
440 440
 	 */
441
-	public function get_cancelled( $context = 'view' ) {
442
-		return $this->get_prop( 'cancelled', $context );
441
+	public function get_cancelled($context = 'view') {
442
+		return $this->get_prop('cancelled', $context);
443 443
 	}
444 444
 
445 445
 	/**
@@ -449,8 +449,8 @@  discard block
 block discarded – undo
449 449
 	 * @param  string $context View or edit context.
450 450
 	 * @return float
451 451
 	 */
452
-	public function get_failed( $context = 'view' ) {
453
-		return $this->get_prop( 'failed', $context );
452
+	public function get_failed($context = 'view') {
453
+		return $this->get_prop('failed', $context);
454 454
 	}
455 455
 
456 456
 	/**
@@ -461,8 +461,8 @@  discard block
 block discarded – undo
461 461
 	 * @return string
462 462
 	 */
463 463
 	public function get_currency() {
464
-		$currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
465
-		return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
464
+		$currency = empty($this->invoice) ? wpinv_get_currency() : $this->invoice->get_currency();
465
+		return apply_filters('getpaid-payment-form-currency', $currency, $this);
466 466
 	}
467 467
 
468 468
     /*
@@ -480,8 +480,8 @@  discard block
 block discarded – undo
480 480
 	 *
481 481
 	 * @since 1.0.19
482 482
 	 */
483
-	public function set_version( $value ) {
484
-		$this->set_prop( 'version', $value );
483
+	public function set_version($value) {
484
+		$this->set_prop('version', $value);
485 485
     }
486 486
 
487 487
     /**
@@ -491,11 +491,11 @@  discard block
 block discarded – undo
491 491
 	 * @param string $value Value to set.
492 492
      * @return bool Whether or not the date was set.
493 493
 	 */
494
-	public function set_date_created( $value ) {
495
-        $date = strtotime( $value );
494
+	public function set_date_created($value) {
495
+        $date = strtotime($value);
496 496
 
497
-        if ( $date ) {
498
-            $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) );
497
+        if ($date) {
498
+            $this->set_prop('date_created', date('Y-m-d H:i:s', $date));
499 499
             return true;
500 500
         }
501 501
 
@@ -510,11 +510,11 @@  discard block
 block discarded – undo
510 510
 	 * @param string $value Value to set.
511 511
      * @return bool Whether or not the date was set.
512 512
 	 */
513
-	public function set_date_modified( $value ) {
514
-        $date = strtotime( $value );
513
+	public function set_date_modified($value) {
514
+        $date = strtotime($value);
515 515
 
516
-        if ( $date ) {
517
-            $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) );
516
+        if ($date) {
517
+            $this->set_prop('date_modified', date('Y-m-d H:i:s', $date));
518 518
             return true;
519 519
         }
520 520
 
@@ -528,8 +528,8 @@  discard block
 block discarded – undo
528 528
 	 * @since 1.0.19
529 529
 	 * @param  string $value New name.
530 530
 	 */
531
-	public function set_name( $value ) {
532
-		$this->set_prop( 'name', sanitize_text_field( $value ) );
531
+	public function set_name($value) {
532
+		$this->set_prop('name', sanitize_text_field($value));
533 533
     }
534 534
 
535 535
     /**
@@ -538,8 +538,8 @@  discard block
 block discarded – undo
538 538
 	 * @since 1.0.19
539 539
 	 * @param  string $value New name.
540 540
 	 */
541
-	public function set_title( $value ) {
542
-		$this->set_name( $value );
541
+	public function set_title($value) {
542
+		$this->set_name($value);
543 543
     }
544 544
 
545 545
     /**
@@ -548,8 +548,8 @@  discard block
 block discarded – undo
548 548
 	 * @since 1.0.19
549 549
 	 * @param  int $value New author.
550 550
 	 */
551
-	public function set_author( $value ) {
552
-		$this->set_prop( 'author', (int) $value );
551
+	public function set_author($value) {
552
+		$this->set_prop('author', (int) $value);
553 553
 	}
554 554
 
555 555
 	/**
@@ -559,9 +559,9 @@  discard block
 block discarded – undo
559 559
 	 * @sinve 2.3.4 Array values sanitized.
560 560
 	 * @param  array $value Form elements.
561 561
 	 */
562
-	public function set_elements( $value ) {
563
-		if ( is_array( $value ) ) {
564
-			$this->set_prop( 'elements', wp_kses_post_deep( $value ) );
562
+	public function set_elements($value) {
563
+		if (is_array($value)) {
564
+			$this->set_prop('elements', wp_kses_post_deep($value));
565 565
 		}
566 566
 	}
567 567
 
@@ -572,36 +572,36 @@  discard block
 block discarded – undo
572 572
 	 *
573 573
 	 * @return mixed
574 574
 	 */
575
-	public function sanitize_array_values( $value ) {
575
+	public function sanitize_array_values($value) {
576 576
 
577 577
 		// sanitize
578
-		if ( ! empty( $value ) ) {
578
+		if (!empty($value)) {
579 579
 
580
-			foreach ( $value as $key => $val_arr ) {
580
+			foreach ($value as $key => $val_arr) {
581 581
 
582
-				if ( is_array( $val_arr ) ) {
582
+				if (is_array($val_arr)) {
583 583
 					// check if we have sub array items.
584 584
 					$sub_arr = array();
585
-					foreach ( $val_arr as $key2 => $val2 ) {
586
-						if ( is_array( $val2 ) ) {
587
-							$sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 );
588
-							unset( $val_arr[ $key ][ $key2 ] );
585
+					foreach ($val_arr as $key2 => $val2) {
586
+						if (is_array($val2)) {
587
+							$sub_arr[$key2] = $this->sanitize_array_values($val2);
588
+							unset($val_arr[$key][$key2]);
589 589
 						}
590 590
 					}
591 591
 
592 592
 					// we allow some html in description so we sanitize it separately.
593
-					$help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : '';
593
+					$help_text = !empty($val_arr['description']) ? wp_kses_post($val_arr['description']) : '';
594 594
 
595 595
 					// sanitize array elements
596
-					$value[ $key ] = array_map( 'sanitize_text_field', $val_arr );
596
+					$value[$key] = array_map('sanitize_text_field', $val_arr);
597 597
 
598 598
 					// add back the description if set
599
-					if ( isset( $val_arr['description'] ) ) {
600
-$value[ $key ]['description'] = $help_text;}
599
+					if (isset($val_arr['description'])) {
600
+$value[$key]['description'] = $help_text; }
601 601
 
602 602
 					// add back sub array items after its been sanitized.
603
-					if ( ! empty( $sub_arr ) ) {
604
-						$value[ $key ] = array_merge( $value[ $key ], $sub_arr );
603
+					if (!empty($sub_arr)) {
604
+						$value[$key] = array_merge($value[$key], $sub_arr);
605 605
 					}
606 606
 				}
607 607
 }
@@ -616,9 +616,9 @@  discard block
 block discarded – undo
616 616
 	 * @since 1.0.19
617 617
 	 * @param  array $value Form elements.
618 618
 	 */
619
-	public function set_items( $value ) {
620
-		if ( is_array( $value ) ) {
621
-			$this->set_prop( 'items', $value );
619
+	public function set_items($value) {
620
+		if (is_array($value)) {
621
+			$this->set_prop('items', $value);
622 622
 		}
623 623
 	}
624 624
 
@@ -628,9 +628,9 @@  discard block
 block discarded – undo
628 628
 	 * @since 1.0.19
629 629
 	 * @param  float $value Amount earned.
630 630
 	 */
631
-	public function set_earned( $value ) {
632
-		$value = max( (float) $value, 0 );
633
-		$this->set_prop( 'earned', $value );
631
+	public function set_earned($value) {
632
+		$value = max((float) $value, 0);
633
+		$this->set_prop('earned', $value);
634 634
 	}
635 635
 
636 636
 	/**
@@ -639,9 +639,9 @@  discard block
 block discarded – undo
639 639
 	 * @since 1.0.19
640 640
 	 * @param  float $value Amount refunded.
641 641
 	 */
642
-	public function set_refunded( $value ) {
643
-		$value = max( (float) $value, 0 );
644
-		$this->set_prop( 'refunded', $value );
642
+	public function set_refunded($value) {
643
+		$value = max((float) $value, 0);
644
+		$this->set_prop('refunded', $value);
645 645
 	}
646 646
 
647 647
 	/**
@@ -650,9 +650,9 @@  discard block
 block discarded – undo
650 650
 	 * @since 1.0.19
651 651
 	 * @param  float $value Amount cancelled.
652 652
 	 */
653
-	public function set_cancelled( $value ) {
654
-		$value = max( (float) $value, 0 );
655
-		$this->set_prop( 'cancelled', $value );
653
+	public function set_cancelled($value) {
654
+		$value = max((float) $value, 0);
655
+		$this->set_prop('cancelled', $value);
656 656
 	}
657 657
 
658 658
 	/**
@@ -661,9 +661,9 @@  discard block
 block discarded – undo
661 661
 	 * @since 1.0.19
662 662
 	 * @param  float $value Amount cancelled.
663 663
 	 */
664
-	public function set_failed( $value ) {
665
-		$value = max( (float) $value, 0 );
666
-		$this->set_prop( 'failed', $value );
664
+	public function set_failed($value) {
665
+		$value = max((float) $value, 0);
666
+		$this->set_prop('failed', $value);
667 667
 	}
668 668
 
669 669
     /**
@@ -672,11 +672,11 @@  discard block
 block discarded – undo
672 672
      * @deprecated
673 673
 	 * @return int item id
674 674
      */
675
-    public function create( $data = array() ) {
675
+    public function create($data = array()) {
676 676
 
677 677
 		// Set the properties.
678
-		if ( is_array( $data ) ) {
679
-			$this->set_props( $data );
678
+		if (is_array($data)) {
679
+			$this->set_props($data);
680 680
 		}
681 681
 
682 682
 		// Save the item.
@@ -690,8 +690,8 @@  discard block
 block discarded – undo
690 690
      * @deprecated
691 691
 	 * @return int item id
692 692
      */
693
-    public function update( $data = array() ) {
694
-        return $this->create( $data );
693
+    public function update($data = array()) {
694
+        return $this->create($data);
695 695
     }
696 696
 
697 697
     /*
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
 	 */
712 712
     public function is_default() {
713 713
         $is_default = $this->get_id() == wpinv_get_default_payment_form();
714
-        return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this );
714
+        return (bool) apply_filters('wpinv_is_default_payment_form', $is_default, $this->get_id(), $this);
715 715
 	}
716 716
 
717 717
     /**
@@ -723,11 +723,11 @@  discard block
 block discarded – undo
723 723
     public function is_active() {
724 724
         $is_active = 0 !== (int) $this->get_id();
725 725
 
726
-        if ( $is_active && ! current_user_can( 'edit_post', $this->get_id() ) && $this->get_status() != 'publish' ) {
726
+        if ($is_active && !current_user_can('edit_post', $this->get_id()) && $this->get_status() != 'publish') {
727 727
             $is_active = false;
728 728
         }
729 729
 
730
-        return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this );
730
+        return (bool) apply_filters('wpinv_is_payment_form_active', $is_active, $this);
731 731
 	}
732 732
 
733 733
 	/**
@@ -736,8 +736,8 @@  discard block
 block discarded – undo
736 736
 	 * @since 1.0.19
737 737
 	 * @return bool
738 738
 	 */
739
-    public function has_item( $item_id ) {
740
-        return false !== $this->get_item( $item_id );
739
+    public function has_item($item_id) {
740
+        return false !== $this->get_item($item_id);
741 741
 	}
742 742
 
743 743
 	/**
@@ -746,8 +746,8 @@  discard block
 block discarded – undo
746 746
 	 * @since 1.0.19
747 747
 	 * @return bool
748 748
 	 */
749
-    public function has_element_type( $element_type ) {
750
-        return false !== $this->get_element_type( $element_type );
749
+    public function has_element_type($element_type) {
750
+        return false !== $this->get_element_type($element_type);
751 751
 	}
752 752
 
753 753
 	/**
@@ -758,13 +758,13 @@  discard block
 block discarded – undo
758 758
 	 */
759 759
     public function is_recurring() {
760 760
 
761
-		if ( ! empty( $this->invoice ) ) {
761
+		if (!empty($this->invoice)) {
762 762
 			return $this->invoice->is_recurring();
763 763
 		}
764 764
 
765
-		foreach ( $this->get_items() as $item ) {
765
+		foreach ($this->get_items() as $item) {
766 766
 
767
-			if ( $item->is_recurring() ) {
767
+			if ($item->is_recurring()) {
768 768
 				return true;
769 769
 			}
770 770
 }
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
 	 *
778 778
 	 * @since 1.0.19
779 779
 	 */
780
-    public function get_html( $extra_markup = '' ) {
780
+    public function get_html($extra_markup = '') {
781 781
 
782 782
 		// Return the HTML.
783 783
 		return wpinv_get_template_html(
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
 	 *
796 796
 	 * @since 1.0.19
797 797
 	 */
798
-    public function display( $extra_markup = '' ) {
798
+    public function display($extra_markup = '') {
799 799
 		wpinv_get_template(
800 800
 			'payment-forms/form.php',
801 801
 			array(
Please login to merge, or discard this patch.
includes/wpinv-address-functions.php 1 patch
Spacing   +142 added lines, -142 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' ) ) {
10
+if (!defined('WPINC')) {
11 11
     exit;
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
 }
@@ -128,22 +128,22 @@  discard block
 block discarded – undo
128 128
     $address_fields = apply_filters(
129 129
         'getpaid_user_address_fields',
130 130
         array(
131
-            'first_name' => __( 'First Name', 'invoicing' ),
132
-            'last_name'  => __( 'Last Name', 'invoicing' ),
133
-            'address'    => __( 'Address', 'invoicing' ),
134
-            'city'       => __( 'City', 'invoicing' ),
135
-            'country'    => __( 'Country', 'invoicing' ),
136
-            'state'      => __( 'State', 'invoicing' ),
137
-            'zip'        => __( 'Zip/Postal Code', 'invoicing' ),
138
-            'phone'      => __( 'Phone Number', 'invoicing' ),
139
-            'company'    => __( 'Company', 'invoicing' ),
140
-            'company_id' => __( 'Company ID', 'invoicing' ),
141
-            'vat_number' => __( 'VAT Number', 'invoicing' ),
131
+            'first_name' => __('First Name', 'invoicing'),
132
+            'last_name'  => __('Last Name', 'invoicing'),
133
+            'address'    => __('Address', 'invoicing'),
134
+            'city'       => __('City', 'invoicing'),
135
+            'country'    => __('Country', 'invoicing'),
136
+            'state'      => __('State', 'invoicing'),
137
+            'zip'        => __('Zip/Postal Code', 'invoicing'),
138
+            'phone'      => __('Phone Number', 'invoicing'),
139
+            'company'    => __('Company', 'invoicing'),
140
+            'company_id' => __('Company ID', 'invoicing'),
141
+            'vat_number' => __('VAT Number', 'invoicing'),
142 142
         )
143 143
     );
144 144
 
145
-    if ( ! wpinv_use_taxes() && isset( $address_fields['vat_number'] ) ) {
146
-        unset( $address_fields['vat_number'] );
145
+    if (!wpinv_use_taxes() && isset($address_fields['vat_number'])) {
146
+        unset($address_fields['vat_number']);
147 147
     }
148 148
 
149 149
     return $address_fields;
@@ -154,8 +154,8 @@  discard block
 block discarded – undo
154 154
  *
155 155
  * @return bool
156 156
  */
157
-function getpaid_is_address_field_whitelisted( $key ) {
158
-    return array_key_exists( $key, getpaid_user_address_fields() );
157
+function getpaid_is_address_field_whitelisted($key) {
158
+    return array_key_exists($key, getpaid_user_address_fields());
159 159
 }
160 160
 
161 161
 /**
@@ -165,30 +165,30 @@  discard block
 block discarded – undo
165 165
  *
166 166
  * @param WPInv_Invoice $invoice
167 167
  */
168
-function getpaid_save_invoice_user_address( $invoice ) {
168
+function getpaid_save_invoice_user_address($invoice) {
169 169
 
170 170
     // Retrieve the invoice.
171
-    $invoice = wpinv_get_invoice( $invoice );
171
+    $invoice = wpinv_get_invoice($invoice);
172 172
 
173 173
     // Abort if it does not exist.
174
-    if ( empty( $invoice ) || $invoice->is_renewal() ) {
174
+    if (empty($invoice) || $invoice->is_renewal()) {
175 175
         return;
176 176
     }
177 177
 
178
-    foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
178
+    foreach (array_keys(getpaid_user_address_fields()) as $field) {
179 179
 
180
-        if ( is_callable( array( $invoice, "get_$field" ) ) ) {
181
-            $value = call_user_func( array( $invoice, "get_$field" ) );
180
+        if (is_callable(array($invoice, "get_$field"))) {
181
+            $value = call_user_func(array($invoice, "get_$field"));
182 182
 
183 183
             // Only save if it is not empty.
184
-            if ( ! empty( $value ) ) {
185
-                update_user_meta( $invoice->get_user_id(), '_wpinv_' . $field, $value );
184
+            if (!empty($value)) {
185
+                update_user_meta($invoice->get_user_id(), '_wpinv_' . $field, $value);
186 186
             }
187 187
 }
188 188
 }
189 189
 
190 190
 }
191
-add_action( 'getpaid_checkout_invoice_updated', 'getpaid_save_invoice_user_address' );
191
+add_action('getpaid_checkout_invoice_updated', 'getpaid_save_invoice_user_address');
192 192
 
193 193
 /**
194 194
  * Retrieves a saved user address.
@@ -196,14 +196,14 @@  discard block
 block discarded – undo
196 196
  * @param int $user_id The user id whose address we should get. Defaults to the current user id.
197 197
  * @return array
198 198
  */
199
-function wpinv_get_user_address( $user_id = 0 ) {
199
+function wpinv_get_user_address($user_id = 0) {
200 200
 
201 201
     // Prepare the user id.
202
-    $user_id   = empty( $user_id ) ? get_current_user_id() : $user_id;
203
-    $user_info = get_userdata( $user_id );
202
+    $user_id   = empty($user_id) ? get_current_user_id() : $user_id;
203
+    $user_info = get_userdata($user_id);
204 204
 
205 205
     // Abort if non exists.
206
-    if ( empty( $user_info ) ) {
206
+    if (empty($user_info)) {
207 207
         return array();
208 208
     }
209 209
 
@@ -214,11 +214,11 @@  discard block
 block discarded – undo
214 214
         'display_name' => $user_info->display_name,
215 215
     );
216 216
 
217
-    foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
218
-        $address[ $field ] = getpaid_get_user_address_field( $user_id, $field );
217
+    foreach (array_keys(getpaid_user_address_fields()) as $field) {
218
+        $address[$field] = getpaid_get_user_address_field($user_id, $field);
219 219
     }
220 220
 
221
-    $address = array_filter( $address );
221
+    $address = array_filter($address);
222 222
 
223 223
     $defaults = array(
224 224
         'first_name' => $user_info->first_name,
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
         'country'    => wpinv_get_default_country(),
228 228
     );
229 229
 
230
-    return getpaid_array_merge_if_empty( $address, $defaults );
230
+    return getpaid_array_merge_if_empty($address, $defaults);
231 231
 
232 232
 }
233 233
 
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
  * @param string $field The field to use.
239 239
  * @return string|null
240 240
  */
241
-function getpaid_get_user_address_field( $user_id, $field ) {
241
+function getpaid_get_user_address_field($user_id, $field) {
242 242
 
243 243
     $prefixes = array(
244 244
         '_wpinv_',
@@ -246,15 +246,15 @@  discard block
 block discarded – undo
246 246
         '',
247 247
     );
248 248
 
249
-    foreach ( $prefixes as $prefix ) {
249
+    foreach ($prefixes as $prefix) {
250 250
 
251 251
         // Meta table.
252
-        $value = get_user_meta( $user_id, $prefix . $field, true );
252
+        $value = get_user_meta($user_id, $prefix . $field, true);
253 253
 
254 254
         // UWP table.
255
-        $value = ( empty( $value ) && function_exists( 'uwp_get_usermeta' ) ) ? uwp_get_usermeta( $user_id, $prefix . $field ) : $value;
255
+        $value = (empty($value) && function_exists('uwp_get_usermeta')) ? uwp_get_usermeta($user_id, $prefix . $field) : $value;
256 256
 
257
-        if ( ! empty( $value ) ) {
257
+        if (!empty($value)) {
258 258
             return $value;
259 259
         }
260 260
 }
@@ -270,16 +270,16 @@  discard block
 block discarded – undo
270 270
  * @param string $return What to return.
271 271
  * @return array
272 272
  */
273
-function wpinv_get_continents( $return = 'all' ) {
273
+function wpinv_get_continents($return = 'all') {
274 274
 
275
-    $continents = wpinv_get_data( 'continents' );
275
+    $continents = wpinv_get_data('continents');
276 276
 
277
-    switch ( $return ) {
277
+    switch ($return) {
278 278
         case 'name':
279
-            return wp_list_pluck( $continents, 'name' );
279
+            return wp_list_pluck($continents, 'name');
280 280
             break;
281 281
         case 'countries':
282
-            return wp_list_pluck( $continents, 'countries' );
282
+            return wp_list_pluck($continents, 'countries');
283 283
             break;
284 284
         default:
285 285
             return $continents;
@@ -295,12 +295,12 @@  discard block
 block discarded – undo
295 295
  * @param string $country Country code. If no code is specified, defaults to the default country.
296 296
  * @return string
297 297
  */
298
-function wpinv_get_continent_code_for_country( $country = false ) {
298
+function wpinv_get_continent_code_for_country($country = false) {
299 299
 
300
-    $country = wpinv_sanitize_country( $country );
300
+    $country = wpinv_sanitize_country($country);
301 301
 
302
-	foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) {
303
-		if ( false !== array_search( $country, $countries, true ) ) {
302
+	foreach (wpinv_get_continents('countries') as $continent_code => $countries) {
303
+		if (false !== array_search($country, $countries, true)) {
304 304
 			return $continent_code;
305 305
 		}
306 306
 	}
@@ -316,13 +316,13 @@  discard block
 block discarded – undo
316 316
  * @param string $country Country code. If no code is specified, defaults to the default country.
317 317
  * @return array
318 318
  */
319
-function wpinv_get_country_calling_code( $country = null ) {
319
+function wpinv_get_country_calling_code($country = null) {
320 320
 
321
-    $country = wpinv_sanitize_country( $country );
322
-    $codes   = wpinv_get_data( 'phone-codes' );
323
-    $code    = isset( $codes[ $country ] ) ? $codes[ $country ] : '';
321
+    $country = wpinv_sanitize_country($country);
322
+    $codes   = wpinv_get_data('phone-codes');
323
+    $code    = isset($codes[$country]) ? $codes[$country] : '';
324 324
 
325
-    if ( is_array( $code ) ) {
325
+    if (is_array($code)) {
326 326
         return $code[0];
327 327
     }
328 328
     return $code;
@@ -335,8 +335,8 @@  discard block
 block discarded – undo
335 335
  * @param bool $first_empty Whether or not the first item in the list should be empty
336 336
  * @return array
337 337
  */
338
-function wpinv_get_country_list( $first_empty = false ) {
339
-    return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty );
338
+function wpinv_get_country_list($first_empty = false) {
339
+    return wpinv_maybe_add_empty_option(apply_filters('wpinv_countries', wpinv_get_data('countries')), $first_empty);
340 340
 }
341 341
 
342 342
 /**
@@ -346,22 +346,22 @@  discard block
 block discarded – undo
346 346
  * @param bool $first_empty Whether or not the first item in the list should be empty
347 347
  * @return array
348 348
  */
349
-function wpinv_get_country_states( $country = null, $first_empty = false ) {
349
+function wpinv_get_country_states($country = null, $first_empty = false) {
350 350
 
351 351
     // Prepare the country.
352
-    $country = wpinv_sanitize_country( $country );
352
+    $country = wpinv_sanitize_country($country);
353 353
 
354 354
     // Fetch all states.
355
-    $all_states = wpinv_get_data( 'states' );
355
+    $all_states = wpinv_get_data('states');
356 356
 
357 357
     // Fetch the specified country's states.
358
-    $states     = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array();
359
-    $states     = apply_filters( "wpinv_{$country}_states", $states );
360
-    $states     = apply_filters( 'wpinv_country_states', $states, $country );
358
+    $states     = isset($all_states[$country]) ? $all_states[$country] : array();
359
+    $states     = apply_filters("wpinv_{$country}_states", $states);
360
+    $states     = apply_filters('wpinv_country_states', $states, $country);
361 361
 
362
-    asort( $states );
362
+    asort($states);
363 363
 
364
-    return wpinv_maybe_add_empty_option( $states, $first_empty );
364
+    return wpinv_maybe_add_empty_option($states, $first_empty);
365 365
 }
366 366
 
367 367
 /**
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
  * @return array
372 372
  */
373 373
 function wpinv_get_us_states_list() {
374
-    return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) );
374
+    return apply_filters('wpinv_usa_states', wpinv_get_country_states('US'));
375 375
 }
376 376
 
377 377
 /**
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
  * @return array
382 382
  */
383 383
 function wpinv_get_canada_states_list() {
384
-    return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) );
384
+    return apply_filters('wpinv_canada_provinces', wpinv_get_country_states('CA'));
385 385
 }
386 386
 
387 387
 /**
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
  * @return array
392 392
  */
393 393
 function wpinv_get_australia_states_list() {
394
-    return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) );
394
+    return apply_filters('wpinv_australia_states', wpinv_get_country_states('AU'));
395 395
 }
396 396
 
397 397
 /**
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
  * @return array
402 402
  */
403 403
 function wpinv_get_bangladesh_states_list() {
404
-    return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) );
404
+    return apply_filters('wpinv_bangladesh_states', wpinv_get_country_states('BD'));
405 405
 }
406 406
 
407 407
 /**
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
  * @return array
412 412
  */
413 413
 function wpinv_get_brazil_states_list() {
414
-    return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) );
414
+    return apply_filters('wpinv_brazil_states', wpinv_get_country_states('BR'));
415 415
 }
416 416
 
417 417
 /**
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
  * @return array
422 422
  */
423 423
 function wpinv_get_bulgaria_states_list() {
424
-    return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) );
424
+    return apply_filters('wpinv_bulgaria_states', wpinv_get_country_states('BG'));
425 425
 }
426 426
 
427 427
 /**
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
  * @return array
432 432
  */
433 433
 function wpinv_get_hong_kong_states_list() {
434
-    return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) );
434
+    return apply_filters('wpinv_hong_kong_states', wpinv_get_country_states('HK'));
435 435
 }
436 436
 
437 437
 /**
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
  * @return array
442 442
  */
443 443
 function wpinv_get_hungary_states_list() {
444
-    return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) );
444
+    return apply_filters('wpinv_hungary_states', wpinv_get_country_states('HU'));
445 445
 }
446 446
 
447 447
 /**
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
  * @return array
452 452
  */
453 453
 function wpinv_get_japan_states_list() {
454
-    return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) );
454
+    return apply_filters('wpinv_japan_states', wpinv_get_country_states('JP'));
455 455
 }
456 456
 
457 457
 /**
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
  * @return array
462 462
  */
463 463
 function wpinv_get_china_states_list() {
464
-    return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) );
464
+    return apply_filters('wpinv_china_states', wpinv_get_country_states('CN'));
465 465
 }
466 466
 
467 467
 /**
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
  * @return array
472 472
  */
473 473
 function wpinv_get_new_zealand_states_list() {
474
-    return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) );
474
+    return apply_filters('wpinv_new_zealand_states', wpinv_get_country_states('NZ'));
475 475
 }
476 476
 
477 477
 /**
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
  * @return array
482 482
  */
483 483
 function wpinv_get_peru_states_list() {
484
-    return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) );
484
+    return apply_filters('wpinv_peru_states', wpinv_get_country_states('PE'));
485 485
 }
486 486
 
487 487
 /**
@@ -491,7 +491,7 @@  discard block
 block discarded – undo
491 491
  * @return array
492 492
  */
493 493
 function wpinv_get_indonesia_states_list() {
494
-    return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) );
494
+    return apply_filters('wpinv_indonesia_states', wpinv_get_country_states('ID'));
495 495
 }
496 496
 
497 497
 /**
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
  * @return array
502 502
  */
503 503
 function wpinv_get_india_states_list() {
504
-    return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) );
504
+    return apply_filters('wpinv_india_states', wpinv_get_country_states('IN'));
505 505
 }
506 506
 
507 507
 /**
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
  * @return array
512 512
  */
513 513
 function wpinv_get_iran_states_list() {
514
-    return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) );
514
+    return apply_filters('wpinv_iran_states', wpinv_get_country_states('IR'));
515 515
 }
516 516
 
517 517
 /**
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
  * @return array
522 522
  */
523 523
 function wpinv_get_italy_states_list() {
524
-    return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) );
524
+    return apply_filters('wpinv_italy_states', wpinv_get_country_states('IT'));
525 525
 }
526 526
 
527 527
 /**
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
  * @return array
532 532
  */
533 533
 function wpinv_get_malaysia_states_list() {
534
-    return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) );
534
+    return apply_filters('wpinv_malaysia_states', wpinv_get_country_states('MY'));
535 535
 }
536 536
 
537 537
 /**
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
  * @return array
542 542
  */
543 543
 function wpinv_get_mexico_states_list() {
544
-    return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) );
544
+    return apply_filters('wpinv_mexico_states', wpinv_get_country_states('MX'));
545 545
 }
546 546
 
547 547
 /**
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
  * @return array
552 552
  */
553 553
 function wpinv_get_nepal_states_list() {
554
-    return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) );
554
+    return apply_filters('wpinv_nepal_states', wpinv_get_country_states('NP'));
555 555
 }
556 556
 
557 557
 /**
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
  * @return array
562 562
  */
563 563
 function wpinv_get_south_africa_states_list() {
564
-    return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) );
564
+    return apply_filters('wpinv_south_africa_states', wpinv_get_country_states('ZA'));
565 565
 }
566 566
 
567 567
 /**
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
  * @return array
572 572
  */
573 573
 function wpinv_get_thailand_states_list() {
574
-    return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) );
574
+    return apply_filters('wpinv_thailand_states', wpinv_get_country_states('TH'));
575 575
 }
576 576
 
577 577
 /**
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
  * @return array
582 582
  */
583 583
 function wpinv_get_turkey_states_list() {
584
-    return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) );
584
+    return apply_filters('wpinv_turkey_states', wpinv_get_country_states('TR'));
585 585
 }
586 586
 
587 587
 /**
@@ -591,31 +591,31 @@  discard block
 block discarded – undo
591 591
  * @return array
592 592
  */
593 593
 function wpinv_get_spain_states_list() {
594
-    return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) );
594
+    return apply_filters('wpinv_spain_states', wpinv_get_country_states('ES'));
595 595
 }
596 596
 
597 597
 function wpinv_get_states_field() {
598
-	if ( empty( $_POST['country'] ) ) {
598
+	if (empty($_POST['country'])) {
599 599
 		$_POST['country'] = wpinv_get_default_country();
600 600
 	}
601
-	$states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
601
+	$states = wpinv_get_country_states(sanitize_text_field($_POST['country']));
602 602
 
603
-	if ( ! empty( $states ) ) {
604
-		$sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
603
+	if (!empty($states)) {
604
+		$sanitized_field_name = sanitize_text_field($_POST['field_name']);
605 605
 
606
-        $class  = isset( $_POST['class'] ) ? esc_attr( sanitize_text_field( $_POST['class'] ) ) : '';
606
+        $class  = isset($_POST['class']) ? esc_attr(sanitize_text_field($_POST['class'])) : '';
607 607
         $class .= " $sanitized_field_name getpaid_js_field-state custom-select wpinv-select wpi_select2";
608 608
 
609
-        $args  = array(
609
+        $args = array(
610 610
 			'name'             => $sanitized_field_name,
611 611
 			'id'               => $sanitized_field_name,
612
-			'class'            => implode( ' ', array_unique( explode( ' ', $class ) ) ),
613
-			'options'          => array_merge( array( '' => '' ), $states ),
612
+			'class'            => implode(' ', array_unique(explode(' ', $class))),
613
+			'options'          => array_merge(array('' => ''), $states),
614 614
 			'show_option_all'  => false,
615 615
 			'show_option_none' => false,
616 616
 		);
617 617
 
618
-		wpinv_html_select( $args );
618
+		wpinv_html_select($args);
619 619
 
620 620
 	} else {
621 621
 		echo 'nostates';
@@ -623,10 +623,10 @@  discard block
 block discarded – undo
623 623
 
624 624
 }
625 625
 
626
-function wpinv_default_billing_country( $country = '', $user_id = 0 ) {
627
-    $country = ! empty( $country ) ? $country : wpinv_get_default_country();
626
+function wpinv_default_billing_country($country = '', $user_id = 0) {
627
+    $country = !empty($country) ? $country : wpinv_get_default_country();
628 628
 
629
-    return apply_filters( 'wpinv_default_billing_country', $country, $user_id );
629
+    return apply_filters('wpinv_default_billing_country', $country, $user_id);
630 630
 }
631 631
 
632 632
 /**
@@ -688,9 +688,9 @@  discard block
 block discarded – undo
688 688
  * @see `wpinv_get_invoice_address_replacements`
689 689
  * @return string
690 690
  */
691
-function wpinv_get_full_address_format( $country = false ) {
691
+function wpinv_get_full_address_format($country = false) {
692 692
 
693
-    if ( empty( $country ) ) {
693
+    if (empty($country)) {
694 694
         $country = wpinv_get_default_country();
695 695
     }
696 696
 
@@ -698,7 +698,7 @@  discard block
 block discarded – undo
698 698
 	$formats = wpinv_get_address_formats();
699 699
 
700 700
 	// Get format for the specified country.
701
-	$format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];
701
+	$format = ($country && isset($formats[$country])) ? $formats[$country] : $formats['default'];
702 702
 
703 703
     /**
704 704
 	 * Filters the address format to use on Invoices.
@@ -710,7 +710,7 @@  discard block
 block discarded – undo
710 710
 	 * @param string $format  The address format to use.
711 711
      * @param string $country The country who's address format is being retrieved.
712 712
 	 */
713
-    return apply_filters( 'wpinv_get_full_address_format', $format, $country );
713
+    return apply_filters('wpinv_get_full_address_format', $format, $country);
714 714
 }
715 715
 
716 716
 /**
@@ -721,7 +721,7 @@  discard block
 block discarded – undo
721 721
  * @param array $billing_details customer's billing details
722 722
  * @return array
723 723
  */
724
-function wpinv_get_invoice_address_replacements( $billing_details ) {
724
+function wpinv_get_invoice_address_replacements($billing_details) {
725 725
 
726 726
     $default_args = array(
727 727
         'address'    => '',
@@ -734,15 +734,15 @@  discard block
 block discarded – undo
734 734
 		'company'    => '',
735 735
     );
736 736
 
737
-    $args    = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' );
737
+    $args    = map_deep(wp_parse_args($billing_details, $default_args), 'trim');
738 738
     $state   = $args['state'];
739 739
     $country = $args['country'];
740 740
 
741 741
     // Handle full country name.
742
-    $full_country = empty( $country ) ? $country : wpinv_country_name( $country );
742
+    $full_country = empty($country) ? $country : wpinv_country_name($country);
743 743
 
744 744
     // Handle full state name.
745
-    $full_state   = ( $country && $state ) ? wpinv_state_name( $state, $country ) : $state;
745
+    $full_state   = ($country && $state) ? wpinv_state_name($state, $country) : $state;
746 746
 
747 747
     $args['postcode']    = $args['zip'];
748 748
     $args['name']        = $args['first_name'] . ' ' . $args['last_name'];
@@ -760,14 +760,14 @@  discard block
 block discarded – undo
760 760
 	 * @param array $replacements  The address replacements to use.
761 761
      * @param array $billing_details  The billing details to use.
762 762
 	 */
763
-    $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details );
763
+    $replacements = apply_filters('wpinv_get_invoice_address_replacements', $args, $billing_details);
764 764
 
765 765
     $return = array();
766 766
 
767
-    foreach ( $replacements as $key => $value ) {
768
-        $value  = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : '';
769
-        $return[ '{{' . $key . '}}' ] = $value;
770
-        $return[ '{{' . $key . '_upper}}' ] = wpinv_utf8_strtoupper( $value );
767
+    foreach ($replacements as $key => $value) {
768
+        $value = is_scalar($value) ? trim(sanitize_text_field($value)) : '';
769
+        $return['{{' . $key . '}}'] = $value;
770
+        $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper($value);
771 771
     }
772 772
 
773 773
     return $return;
@@ -781,6 +781,6 @@  discard block
 block discarded – undo
781 781
  * @since 1.0.14
782 782
  * @return string
783 783
  */
784
-function wpinv_trim_formatted_address_line( $line ) {
785
-	return trim( $line, ', ' );
784
+function wpinv_trim_formatted_address_line($line) {
785
+	return trim($line, ', ');
786 786
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-paypal-gateway.php 1 patch
Spacing   +144 added lines, -144 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
  * Paypal Payment Gateway class.
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @var array
26 26
 	 */
27
-    protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' );
27
+    protected $supports = array('subscription', 'sandbox', 'single_subscription_group');
28 28
 
29 29
     /**
30 30
 	 * Payment method order.
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	 *
60 60
 	 * @var array
61 61
 	 */
62
-	public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
62
+	public $currencies = array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR');
63 63
 
64 64
     /**
65 65
 	 * URL to view a transaction.
@@ -80,16 +80,16 @@  discard block
 block discarded – undo
80 80
 	 */
81 81
 	public function __construct() {
82 82
 
83
-        $this->title                = __( 'PayPal Standard', 'invoicing' );
84
-        $this->method_title         = __( 'PayPal Standard', 'invoicing' );
85
-        $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' );
86
-        $this->notify_url           = wpinv_get_ipn_url( $this->id );
83
+        $this->title                = __('PayPal Standard', 'invoicing');
84
+        $this->method_title         = __('PayPal Standard', 'invoicing');
85
+        $this->checkout_button_text = __('Proceed to PayPal', 'invoicing');
86
+        $this->notify_url           = wpinv_get_ipn_url($this->id);
87 87
 
88
-		add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
89
-        add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) );
90
-		add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
91
-		add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
92
-		add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) );
88
+		add_filter('getpaid_paypal_args', array($this, 'process_subscription'), 10, 2);
89
+        add_filter('getpaid_paypal_sandbox_notice', array($this, 'sandbox_notice'));
90
+		add_filter('getpaid_get_paypal_connect_url', array($this, 'maybe_get_connect_url'), 10, 2);
91
+		add_action('getpaid_authenticated_admin_action_connect_paypal', array($this, 'connect_paypal'));
92
+		add_action('wpinv_paypal_connect', array($this, 'display_connect_buttons'));
93 93
 		parent::__construct();
94 94
     }
95 95
 
@@ -102,16 +102,16 @@  discard block
 block discarded – undo
102 102
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
103 103
 	 * @return array
104 104
 	 */
105
-	public function process_payment( $invoice, $submission_data, $submission ) {
105
+	public function process_payment($invoice, $submission_data, $submission) {
106 106
 
107 107
         // Get redirect url.
108
-        $paypal_redirect = $this->get_request_url( $invoice );
108
+        $paypal_redirect = $this->get_request_url($invoice);
109 109
 
110 110
         // Add a note about the request url.
111 111
         $invoice->add_note(
112 112
             sprintf(
113
-                __( 'Redirecting to PayPal: %s', 'invoicing' ),
114
-                esc_url( $paypal_redirect )
113
+                __('Redirecting to PayPal: %s', 'invoicing'),
114
+                esc_url($paypal_redirect)
115 115
             ),
116 116
             false,
117 117
             false,
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         );
120 120
 
121 121
         // Redirect to PayPal
122
-        wp_redirect( $paypal_redirect );
122
+        wp_redirect($paypal_redirect);
123 123
         exit;
124 124
 
125 125
     }
@@ -130,21 +130,21 @@  discard block
 block discarded – undo
130 130
 	 * @param  WPInv_Invoice $invoice Invoice object.
131 131
 	 * @return string
132 132
 	 */
133
-	public function get_request_url( $invoice ) {
133
+	public function get_request_url($invoice) {
134 134
 
135 135
         // Endpoint for this request
136
-		$this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
136
+		$this->endpoint = $this->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
137 137
 
138 138
         // Retrieve paypal args.
139
-        $paypal_args       = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' );
139
+        $paypal_args = map_deep($this->get_paypal_args($invoice), 'urlencode');
140 140
 
141
-        if ( $invoice->is_recurring() ) {
141
+        if ($invoice->is_recurring()) {
142 142
             $paypal_args['bn'] = 'GetPaid_Subscribe_WPS_US';
143 143
         } else {
144 144
             $paypal_args['bn'] = 'GetPaid_ShoppingCart_WPS_US';
145 145
         }
146 146
 
147
-        return add_query_arg( $paypal_args, $this->endpoint );
147
+        return add_query_arg($paypal_args, $this->endpoint);
148 148
 
149 149
 	}
150 150
 
@@ -154,25 +154,25 @@  discard block
 block discarded – undo
154 154
 	 * @param  WPInv_Invoice $invoice Invoice object.
155 155
 	 * @return array
156 156
 	 */
157
-	protected function get_paypal_args( $invoice ) {
157
+	protected function get_paypal_args($invoice) {
158 158
 
159 159
         // Whether or not to send the line items as one item.
160
-		$force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
160
+		$force_one_line_item = apply_filters('getpaid_paypal_force_one_line_item', true, $invoice);
161 161
 
162
-		if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
162
+		if ($invoice->is_recurring() || (wpinv_use_taxes() && wpinv_prices_include_tax())) {
163 163
 			$force_one_line_item = true;
164 164
 		}
165 165
 
166 166
 		$paypal_args = apply_filters(
167 167
 			'getpaid_paypal_args',
168 168
 			array_merge(
169
-				$this->get_transaction_args( $invoice ),
170
-				$this->get_line_item_args( $invoice, $force_one_line_item )
169
+				$this->get_transaction_args($invoice),
170
+				$this->get_line_item_args($invoice, $force_one_line_item)
171 171
 			),
172 172
 			$invoice
173 173
 		);
174 174
 
175
-		return $this->fix_request_length( $invoice, $paypal_args );
175
+		return $this->fix_request_length($invoice, $paypal_args);
176 176
     }
177 177
 
178 178
     /**
@@ -181,9 +181,9 @@  discard block
 block discarded – undo
181 181
 	 * @param WPInv_Invoice $invoice Invoice object.
182 182
 	 * @return array
183 183
 	 */
184
-	protected function get_transaction_args( $invoice ) {
184
+	protected function get_transaction_args($invoice) {
185 185
 
186
-		$email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' );
186
+		$email = $this->is_sandbox($invoice) ? wpinv_get_option('paypal_sandbox_email', wpinv_get_option('paypal_email', '')) : wpinv_get_option('paypal_email', '');
187 187
 		return array(
188 188
             'cmd'           => '_cart',
189 189
             'business'      => $email,
@@ -194,16 +194,16 @@  discard block
 block discarded – undo
194 194
             'rm'            => is_ssl() ? 2 : 1,
195 195
             'upload'        => 1,
196 196
             'currency_code' => $invoice->get_currency(), // https://developer.paypal.com/docs/nvp-soap-api/currency-codes/#paypal
197
-            'return'        => esc_url_raw( $this->get_return_url( $invoice ) ),
198
-            'cancel_return' => esc_url_raw( $invoice->get_checkout_payment_url() ),
199
-            'notify_url'    => getpaid_limit_length( $this->notify_url, 255 ),
200
-            'invoice'       => getpaid_limit_length( $invoice->get_number(), 127 ),
197
+            'return'        => esc_url_raw($this->get_return_url($invoice)),
198
+            'cancel_return' => esc_url_raw($invoice->get_checkout_payment_url()),
199
+            'notify_url'    => getpaid_limit_length($this->notify_url, 255),
200
+            'invoice'       => getpaid_limit_length($invoice->get_number(), 127),
201 201
             'custom'        => $invoice->get_id(),
202
-            'first_name'    => getpaid_limit_length( $invoice->get_first_name(), 32 ),
203
-            'last_name'     => getpaid_limit_length( $invoice->get_last_name(), 64 ),
204
-            'country'       => getpaid_limit_length( $invoice->get_country(), 2 ),
205
-            'email'         => getpaid_limit_length( $invoice->get_email(), 127 ),
206
-            'cbt'           => get_bloginfo( 'name' ),
202
+            'first_name'    => getpaid_limit_length($invoice->get_first_name(), 32),
203
+            'last_name'     => getpaid_limit_length($invoice->get_last_name(), 64),
204
+            'country'       => getpaid_limit_length($invoice->get_country(), 2),
205
+            'email'         => getpaid_limit_length($invoice->get_email(), 127),
206
+            'cbt'           => get_bloginfo('name'),
207 207
         );
208 208
 
209 209
     }
@@ -215,30 +215,30 @@  discard block
 block discarded – undo
215 215
 	 * @param  bool     $force_one_line_item Create only one item for this invoice.
216 216
 	 * @return array
217 217
 	 */
218
-	protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
218
+	protected function get_line_item_args($invoice, $force_one_line_item = false) {
219 219
 
220 220
         // Maybe send invoice as a single item.
221
-		if ( $force_one_line_item ) {
222
-            return $this->get_line_item_args_single_item( $invoice );
221
+		if ($force_one_line_item) {
222
+            return $this->get_line_item_args_single_item($invoice);
223 223
         }
224 224
 
225 225
         // Send each line item individually.
226 226
         $line_item_args = array();
227 227
 
228 228
         // Prepare line items.
229
-        $this->prepare_line_items( $invoice );
229
+        $this->prepare_line_items($invoice);
230 230
 
231 231
         // Add taxes to the cart
232
-        if ( wpinv_use_taxes() && $invoice->is_taxable() ) {
233
-            $line_item_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_tax(), 2 );
232
+        if (wpinv_use_taxes() && $invoice->is_taxable()) {
233
+            $line_item_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_tax(), 2);
234 234
         }
235 235
 
236 236
         // Add discount.
237
-        if ( $invoice->get_total_discount() > 0 ) {
238
-            $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 );
237
+        if ($invoice->get_total_discount() > 0) {
238
+            $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_discount(), 2);
239 239
         }
240 240
 
241
-		return array_merge( $line_item_args, $this->get_line_items() );
241
+		return array_merge($line_item_args, $this->get_line_items());
242 242
 
243 243
     }
244 244
 
@@ -248,11 +248,11 @@  discard block
 block discarded – undo
248 248
 	 * @param  WPInv_Invoice $invoice Invoice object.
249 249
 	 * @return array
250 250
 	 */
251
-	protected function get_line_item_args_single_item( $invoice ) {
251
+	protected function get_line_item_args_single_item($invoice) {
252 252
 		$this->delete_line_items();
253 253
 
254
-        $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
255
-		$this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
254
+        $item_name = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number());
255
+		$this->add_line_item($item_name, 1, wpinv_round_amount((float) $invoice->get_total(), 2, true), $invoice->get_id());
256 256
 
257 257
 		return $this->get_line_items();
258 258
     }
@@ -276,19 +276,19 @@  discard block
 block discarded – undo
276 276
 	 *
277 277
 	 * @param  WPInv_Invoice $invoice Invoice object.
278 278
 	 */
279
-	protected function prepare_line_items( $invoice ) {
279
+	protected function prepare_line_items($invoice) {
280 280
 		$this->delete_line_items();
281 281
 
282 282
 		// Items.
283
-		foreach ( $invoice->get_items() as $item ) {
283
+		foreach ($invoice->get_items() as $item) {
284 284
 			$amount   = $item->get_price();
285 285
 			$quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
286
-			$this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
286
+			$this->add_line_item($item->get_raw_name(), $quantity, $amount, $item->get_id());
287 287
         }
288 288
 
289 289
         // Fees.
290
-		foreach ( $invoice->get_fees() as $fee => $data ) {
291
-            $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) );
290
+		foreach ($invoice->get_fees() as $fee => $data) {
291
+            $this->add_line_item($fee, 1, wpinv_sanitize_amount($data['initial_fee']));
292 292
         }
293 293
 
294 294
     }
@@ -301,15 +301,15 @@  discard block
 block discarded – undo
301 301
 	 * @param  float  $amount Amount.
302 302
 	 * @param  string $item_number Item number.
303 303
 	 */
304
-	protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
305
-		$index = ( count( $this->line_items ) / 4 ) + 1;
304
+	protected function add_line_item($item_name, $quantity = 1, $amount = 0.0, $item_number = '') {
305
+		$index = (count($this->line_items) / 4) + 1;
306 306
 
307 307
 		$item = apply_filters(
308 308
 			'getpaid_paypal_line_item',
309 309
 			array(
310
-				'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
310
+				'item_name'   => html_entity_decode(getpaid_limit_length($item_name ? wp_strip_all_tags($item_name) : __('Item', 'invoicing'), 127), ENT_NOQUOTES, 'UTF-8'),
311 311
 				'quantity'    => (float) $quantity,
312
-				'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
312
+				'amount'      => wpinv_sanitize_amount((float) $amount, 2),
313 313
 				'item_number' => $item_number,
314 314
 			),
315 315
 			$item_name,
@@ -318,12 +318,12 @@  discard block
 block discarded – undo
318 318
 			$item_number
319 319
 		);
320 320
 
321
-		$this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
322
-        $this->line_items[ 'quantity_' . $index ]    = $item['quantity'];
321
+		$this->line_items['item_name_' . $index] = getpaid_limit_length($item['item_name'], 127);
322
+        $this->line_items['quantity_' . $index] = $item['quantity'];
323 323
 
324 324
         // The price or amount of the product, service, or contribution, not including shipping, handling, or tax.
325
-		$this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
326
-		$this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
325
+		$this->line_items['amount_' . $index]      = $item['amount'] * $item['quantity'];
326
+		$this->line_items['item_number_' . $index] = getpaid_limit_length($item['item_number'], 127);
327 327
     }
328 328
 
329 329
     /**
@@ -335,19 +335,19 @@  discard block
 block discarded – undo
335 335
 	 * @param array    $paypal_args Arguments sent to Paypal in the request.
336 336
 	 * @return array
337 337
 	 */
338
-	protected function fix_request_length( $invoice, $paypal_args ) {
338
+	protected function fix_request_length($invoice, $paypal_args) {
339 339
 		$max_paypal_length = 2083;
340
-		$query_candidate   = http_build_query( $paypal_args, '', '&' );
340
+		$query_candidate   = http_build_query($paypal_args, '', '&');
341 341
 
342
-		if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
342
+		if (strlen($this->endpoint . $query_candidate) <= $max_paypal_length) {
343 343
 			return $paypal_args;
344 344
 		}
345 345
 
346 346
 		return apply_filters(
347 347
 			'getpaid_paypal_args',
348 348
 			array_merge(
349
-				$this->get_transaction_args( $invoice ),
350
-				$this->get_line_item_args( $invoice, true )
349
+				$this->get_transaction_args($invoice),
350
+				$this->get_line_item_args($invoice, true)
351 351
 			),
352 352
 			$invoice
353 353
 		);
@@ -360,10 +360,10 @@  discard block
 block discarded – undo
360 360
 	 * @param  array $paypal_args PayPal args.
361 361
 	 * @param  WPInv_Invoice    $invoice Invoice object.
362 362
 	 */
363
-	public function process_subscription( $paypal_args, $invoice ) {
363
+	public function process_subscription($paypal_args, $invoice) {
364 364
 
365 365
         // Make sure this is a subscription.
366
-        if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) {
366
+        if (!$invoice->is_recurring() || !$subscription = getpaid_get_invoice_subscription($invoice)) {
367 367
             return $paypal_args;
368 368
         }
369 369
 
@@ -371,23 +371,23 @@  discard block
 block discarded – undo
371 371
         $paypal_args['cmd'] = '_xclick-subscriptions';
372 372
 
373 373
         // Subscription name.
374
-        $paypal_args['item_name'] = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
374
+        $paypal_args['item_name'] = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number());
375 375
 
376 376
         // Get subscription args.
377
-        $period                 = strtoupper( substr( $subscription->get_period(), 0, 1 ) );
377
+        $period                 = strtoupper(substr($subscription->get_period(), 0, 1));
378 378
         $interval               = (int) $subscription->get_frequency();
379 379
         $bill_times             = (int) $subscription->get_bill_times();
380
-        $initial_amount         = (float) wpinv_sanitize_amount( $invoice->get_initial_total(), 2 );
381
-        $recurring_amount       = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 );
382
-        $subscription_item      = $invoice->get_recurring( true );
380
+        $initial_amount         = (float) wpinv_sanitize_amount($invoice->get_initial_total(), 2);
381
+        $recurring_amount       = (float) wpinv_sanitize_amount($invoice->get_recurring_total(), 2);
382
+        $subscription_item      = $invoice->get_recurring(true);
383 383
 
384 384
 		// Convert 365 days to 1 year.
385
-		if ( 'D' == $period && 365 == $interval ) {
385
+		if ('D' == $period && 365 == $interval) {
386 386
 			$period = 'Y';
387 387
 			$interval = 1;
388 388
 		}
389 389
 
390
-        if ( $subscription_item->has_free_trial() ) {
390
+        if ($subscription_item->has_free_trial()) {
391 391
 
392 392
             $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount;
393 393
 
@@ -397,28 +397,28 @@  discard block
 block discarded – undo
397 397
 			// Trial period.
398 398
 			$paypal_args['t1'] = $subscription_item->get_trial_period();
399 399
 
400
-        } elseif ( $initial_amount != $recurring_amount ) {
400
+        } elseif ($initial_amount != $recurring_amount) {
401 401
 
402 402
             // No trial period, but initial amount includes a sign-up fee and/or other items, so charge it as a separate period.
403 403
 
404
-            if ( 1 == $bill_times ) {
404
+            if (1 == $bill_times) {
405 405
                 $param_number = 3;
406 406
             } else {
407 407
                 $param_number = 1;
408 408
             }
409 409
 
410
-            $paypal_args[ 'a' . $param_number ] = $initial_amount ? $initial_amount : 0;
410
+            $paypal_args['a' . $param_number] = $initial_amount ? $initial_amount : 0;
411 411
 
412 412
             // Sign Up interval
413
-            $paypal_args[ 'p' . $param_number ] = $interval;
413
+            $paypal_args['p' . $param_number] = $interval;
414 414
 
415 415
             // Sign Up unit of duration
416
-            $paypal_args[ 't' . $param_number ] = $period;
416
+            $paypal_args['t' . $param_number] = $period;
417 417
 
418 418
         }
419 419
 
420 420
         // We have a recurring payment
421
-		if ( ! isset( $param_number ) || 1 == $param_number ) {
421
+		if (!isset($param_number) || 1 == $param_number) {
422 422
 
423 423
 			// Subscription price
424 424
 			$paypal_args['a3'] = $recurring_amount;
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
         }
433 433
 
434 434
         // Recurring payments
435
-		if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
435
+		if (1 == $bill_times || ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial() && 2 == $bill_times)) {
436 436
 
437 437
 			// Non-recurring payments
438 438
 			$paypal_args['src'] = 0;
@@ -441,15 +441,15 @@  discard block
 block discarded – undo
441 441
 
442 442
 			$paypal_args['src'] = 1;
443 443
 
444
-			if ( $bill_times > 0 ) {
444
+			if ($bill_times > 0) {
445 445
 
446 446
 				// An initial period is being used to charge a sign-up fee
447
-				if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
447
+				if ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial()) {
448 448
 					$bill_times--;
449 449
 				}
450 450
 
451 451
                 // Make sure it's not over the max of 52
452
-                $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
452
+                $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52);
453 453
 
454 454
 			}
455 455
         }
@@ -458,10 +458,10 @@  discard block
 block discarded – undo
458 458
         $paypal_args['rm'] = 2;
459 459
 
460 460
         // Get rid of redudant items.
461
-        foreach ( array( 'item_name_1', 'quantity_1', 'amount_1', 'item_number_1' ) as $arg ) {
461
+        foreach (array('item_name_1', 'quantity_1', 'amount_1', 'item_number_1') as $arg) {
462 462
 
463
-            if ( isset( $paypal_args[ $arg ] ) ) {
464
-                unset( $paypal_args[ $arg ] );
463
+            if (isset($paypal_args[$arg])) {
464
+                unset($paypal_args[$arg]);
465 465
             }
466 466
 }
467 467
 
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
 	 * @return void
480 480
 	 */
481 481
 	public function verify_ipn() {
482
-        new GetPaid_Paypal_Gateway_IPN_Handler( $this );
482
+        new GetPaid_Paypal_Gateway_IPN_Handler($this);
483 483
     }
484 484
 
485 485
     /**
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
     public function sandbox_notice() {
489 489
 
490 490
         return sprintf(
491
-			__( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ),
491
+			__('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing'),
492 492
 			'<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
493 493
 			'</a>'
494 494
 		);
@@ -500,49 +500,49 @@  discard block
 block discarded – undo
500 500
 	 *
501 501
 	 * @param array $admin_settings
502 502
 	 */
503
-	public function admin_settings( $admin_settings ) {
503
+	public function admin_settings($admin_settings) {
504 504
 
505 505
         $currencies = sprintf(
506
-            __( 'Supported Currencies: %s', 'invoicing' ),
507
-            implode( ', ', $this->currencies )
506
+            __('Supported Currencies: %s', 'invoicing'),
507
+            implode(', ', $this->currencies)
508 508
         );
509 509
 
510 510
         $admin_settings['paypal_active']['desc'] .= " ($currencies)";
511
-        $admin_settings['paypal_desc']['std']     = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
511
+        $admin_settings['paypal_desc']['std']     = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing');
512 512
 
513 513
 		// Access tokens.
514
-		$live_email      = wpinv_get_option( 'paypal_email' );
515
-		$sandbox_email   = wpinv_get_option( 'paypal_sandbox_email' );
514
+		$live_email      = wpinv_get_option('paypal_email');
515
+		$sandbox_email   = wpinv_get_option('paypal_sandbox_email');
516 516
 
517 517
 		$admin_settings['paypal_connect'] = array(
518 518
 			'type' => 'hook',
519 519
 			'id'   => 'paypal_connect',
520
-			'name' => __( 'Connect to PayPal', 'invoicing' ),
520
+			'name' => __('Connect to PayPal', 'invoicing'),
521 521
 		);
522 522
 
523 523
         $admin_settings['paypal_email'] = array(
524 524
             'type'  => 'text',
525 525
 			'class' => 'live-auth-data',
526 526
             'id'    => 'paypal_email',
527
-            'name'  => __( 'Live Email Address', 'invoicing' ),
528
-            'desc'  => __( 'The email address of your PayPal account.', 'invoicing' ),
527
+            'name'  => __('Live Email Address', 'invoicing'),
528
+            'desc'  => __('The email address of your PayPal account.', 'invoicing'),
529 529
         );
530 530
 
531 531
 		$admin_settings['paypal_sandbox_email'] = array(
532 532
             'type'  => 'text',
533 533
 			'class' => 'sandbox-auth-data',
534 534
             'id'    => 'paypal_sandbox_email',
535
-            'name'  => __( 'Sandbox Email Address', 'invoicing' ),
536
-            'desc'  => __( 'The email address of your sandbox PayPal account.', 'invoicing' ),
537
-			'std'   => wpinv_get_option( 'paypal_email', '' ),
535
+            'name'  => __('Sandbox Email Address', 'invoicing'),
536
+            'desc'  => __('The email address of your sandbox PayPal account.', 'invoicing'),
537
+			'std'   => wpinv_get_option('paypal_email', ''),
538 538
         );
539 539
 
540 540
         $admin_settings['paypal_ipn_url'] = array(
541 541
             'type'     => 'ipn_url',
542 542
             'id'       => 'paypal_ipn_url',
543
-            'name'     => __( 'IPN Url', 'invoicing' ),
543
+            'name'     => __('IPN Url', 'invoicing'),
544 544
             'std'      => $this->notify_url,
545
-            'desc'     => __( "If you've not enabled IPNs in your paypal account, use the above URL to enable them.", 'invoicing' ) . ' <a href="https://developer.paypal.com/docs/api-basics/notifications/ipn/"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
545
+            'desc'     => __("If you've not enabled IPNs in your paypal account, use the above URL to enable them.", 'invoicing') . ' <a href="https://developer.paypal.com/docs/api-basics/notifications/ipn/"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
546 546
             'readonly' => true,
547 547
         );
548 548
 
@@ -556,8 +556,8 @@  discard block
 block discarded – undo
556 556
      * @param array $data
557 557
      * @return string
558 558
 	 */
559
-	public static function maybe_get_connect_url( $url = '', $data = array() ) {
560
-		return self::get_connect_url( false, urldecode( $data['redirect'] ) );
559
+	public static function maybe_get_connect_url($url = '', $data = array()) {
560
+		return self::get_connect_url(false, urldecode($data['redirect']));
561 561
 	}
562 562
 
563 563
 	/**
@@ -568,25 +568,25 @@  discard block
 block discarded – undo
568 568
 	 * @param string $redirect
569 569
      * @return string
570 570
 	 */
571
-	public static function get_connect_url( $is_sandbox, $redirect = '' ) {
571
+	public static function get_connect_url($is_sandbox, $redirect = '') {
572 572
 
573 573
         $redirect_url = add_query_arg(
574 574
             array(
575 575
                 'getpaid-admin-action' => 'connect_paypal',
576 576
                 'page'                 => 'wpinv-settings',
577
-                'live_mode'            => (int) empty( $is_sandbox ),
577
+                'live_mode'            => (int) empty($is_sandbox),
578 578
                 'tab'                  => 'gateways',
579 579
                 'section'              => 'paypal',
580
-                'getpaid-nonce'        => wp_create_nonce( 'getpaid-nonce' ),
581
-				'redirect'             => urlencode( $redirect ),
580
+                'getpaid-nonce'        => wp_create_nonce('getpaid-nonce'),
581
+				'redirect'             => urlencode($redirect),
582 582
             ),
583
-            admin_url( 'admin.php' )
583
+            admin_url('admin.php')
584 584
         );
585 585
 
586 586
         return add_query_arg(
587 587
             array(
588
-                'live_mode'    => (int) empty( $is_sandbox ),
589
-                'redirect_url' => urlencode( str_replace( '&amp;', '&', $redirect_url ) ),
588
+                'live_mode'    => (int) empty($is_sandbox),
589
+                'redirect_url' => urlencode(str_replace('&amp;', '&', $redirect_url)),
590 590
             ),
591 591
             'https://ayecode.io/oauth/paypal'
592 592
         );
@@ -602,10 +602,10 @@  discard block
 block discarded – undo
602 602
 
603 603
         ?>
604 604
 			<div class="wpinv-paypal-connect-live">
605
-				<a class="button button-primary" href="<?php echo esc_url( self::get_connect_url( false ) ); ?>"><?php esc_html_e( 'Connect to PayPal', 'invoicing' ); ?></a>
605
+				<a class="button button-primary" href="<?php echo esc_url(self::get_connect_url(false)); ?>"><?php esc_html_e('Connect to PayPal', 'invoicing'); ?></a>
606 606
 			</div>
607 607
 			<div class="wpinv-paypal-connect-sandbox">
608
-				<a class="button button-primary" href="<?php echo esc_url( self::get_connect_url( true ) ); ?>"><?php esc_html_e( 'Connect to PayPal Sandbox', 'invoicing' ); ?></a>
608
+				<a class="button button-primary" href="<?php echo esc_url(self::get_connect_url(true)); ?>"><?php esc_html_e('Connect to PayPal Sandbox', 'invoicing'); ?></a>
609 609
 			</div>
610 610
 
611 611
             <script>
@@ -646,26 +646,26 @@  discard block
 block discarded – undo
646 646
 	 * @param array $data Connection data.
647 647
 	 * @return void
648 648
 	 */
649
-	public function connect_paypal( $data ) {
649
+	public function connect_paypal($data) {
650 650
 
651 651
 		$sandbox      = $this->is_sandbox();
652
-		$data         = wp_unslash( $data );
653
-		$access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
652
+		$data         = wp_unslash($data);
653
+		$access_token = empty($data['access_token']) ? '' : sanitize_text_field($data['access_token']);
654 654
 
655
-		if ( isset( $data['live_mode'] ) ) {
656
-			$sandbox = empty( $data['live_mode'] );
655
+		if (isset($data['live_mode'])) {
656
+			$sandbox = empty($data['live_mode']);
657 657
 		}
658 658
 
659
-		wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
660
-		wpinv_update_option( 'paypal_active', 1 );
659
+		wpinv_update_option('paypal_sandbox', (int) $sandbox);
660
+		wpinv_update_option('paypal_active', 1);
661 661
 
662
-		if ( ! empty( $data['error_description'] ) ) {
663
-			getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
662
+		if (!empty($data['error_description'])) {
663
+			getpaid_admin()->show_error(wp_kses_post(urldecode($data['error_description'])));
664 664
 		} else {
665 665
 
666 666
 			// Retrieve the user info.
667 667
 			$user_info = wp_remote_get(
668
-				! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
668
+				!$sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
669 669
 				array(
670 670
 
671 671
 					'headers' => array(
@@ -676,33 +676,33 @@  discard block
 block discarded – undo
676 676
 				)
677 677
 			);
678 678
 
679
-			if ( is_wp_error( $user_info ) ) {
680
-				getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
679
+			if (is_wp_error($user_info)) {
680
+				getpaid_admin()->show_error(wp_kses_post($user_info->get_error_message()));
681 681
 			} else {
682 682
 
683 683
 				// Create application.
684
-				$user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
684
+				$user_info = json_decode(wp_remote_retrieve_body($user_info));
685 685
 
686
-				if ( $sandbox ) {
687
-					wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
688
-					wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
689
-					set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
690
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
686
+				if ($sandbox) {
687
+					wpinv_update_option('paypal_sandbox_email', sanitize_email($user_info->emails[0]->value));
688
+					wpinv_update_option('paypal_sandbox_refresh_token', sanitize_text_field(urldecode($data['refresh_token'])));
689
+					set_transient('getpaid_paypal_sandbox_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']);
690
+					getpaid_admin()->show_success(__('Successfully connected your PayPal sandbox account', 'invoicing'));
691 691
 				} else {
692
-					wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
693
-					wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
694
-					set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
695
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
692
+					wpinv_update_option('paypal_email', sanitize_email($user_info->emails[0]->value));
693
+					wpinv_update_option('paypal_refresh_token', sanitize_text_field(urldecode($data['refresh_token'])));
694
+					set_transient('getpaid_paypal_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']);
695
+					getpaid_admin()->show_success(__('Successfully connected your PayPal account', 'invoicing'));
696 696
 				}
697 697
 }
698 698
 }
699 699
 
700
-		$redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
700
+		$redirect = empty($data['redirect']) ? admin_url('admin.php?page=wpinv-settings&tab=gateways&section=paypal') : urldecode($data['redirect']);
701 701
 
702
-		if ( isset( $data['step'] ) ) {
703
-			$redirect = add_query_arg( 'step', $data['step'], $redirect );
702
+		if (isset($data['step'])) {
703
+			$redirect = add_query_arg('step', $data['step'], $redirect);
704 704
 		}
705
-		wp_redirect( $redirect );
705
+		wp_redirect($redirect);
706 706
 		exit;
707 707
 	}
708 708
 
Please login to merge, or discard this patch.
widgets/subscriptions.php 1 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'  => '',
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 
46 46
 		);
47 47
 
48
-		parent::__construct( $options );
48
+		parent::__construct($options);
49 49
 	}
50 50
 
51 51
 	/**
@@ -56,12 +56,12 @@  discard block
 block discarded – undo
56 56
 	public function get_subscriptions() {
57 57
 
58 58
 		// Prepare license args.
59
-		$args  = array(
59
+		$args = array(
60 60
 			'customer_in' => get_current_user_id(),
61
-			'paged'       => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1,
61
+			'paged'       => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1,
62 62
 		);
63 63
 
64
-		return new GetPaid_Subscriptions_Query( $args );
64
+		return new GetPaid_Subscriptions_Query($args);
65 65
 
66 66
 	}
67 67
 
@@ -74,14 +74,14 @@  discard block
 block discarded – undo
74 74
 	 *
75 75
 	 * @return mixed|string|bool
76 76
 	 */
77
-	public function output( $args = array(), $widget_args = array(), $content = '' ) {
77
+	public function output($args = array(), $widget_args = array(), $content = '') {
78 78
 
79 79
 		// Ensure that the user is logged in.
80
-		if ( ! is_user_logged_in() ) {
80
+		if (!is_user_logged_in()) {
81 81
 
82 82
 			return aui()->alert(
83 83
 				array(
84
-					'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ),
84
+					'content' => wp_kses_post(__('You need to log-in or create an account to view this section.', 'invoicing')),
85 85
 					'type'    => 'error',
86 86
 				)
87 87
 			);
@@ -89,8 +89,8 @@  discard block
 block discarded – undo
89 89
 		}
90 90
 
91 91
 		// Are we displaying a single subscription?
92
-		if ( isset( $_GET['subscription'] ) ) {
93
-			return $this->display_single_subscription( intval( $_GET['subscription'] ) );
92
+		if (isset($_GET['subscription'])) {
93
+			return $this->display_single_subscription(intval($_GET['subscription']));
94 94
 		}
95 95
 
96 96
 		// Retrieve the user's subscriptions.
@@ -100,27 +100,27 @@  discard block
 block discarded – undo
100 100
 		ob_start();
101 101
 
102 102
 		// Backwards compatibility.
103
-		do_action( 'wpinv_before_user_subscriptions' );
103
+		do_action('wpinv_before_user_subscriptions');
104 104
 
105 105
 		// Display errors and notices.
106 106
 		wpinv_print_errors();
107 107
 
108
-		do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions );
108
+		do_action('getpaid_license_manager_before_subscriptions', $subscriptions);
109 109
 
110 110
 		// Print the table header.
111 111
 		$this->print_table_header();
112 112
 
113 113
 		// Print table body.
114
-		$this->print_table_body( $subscriptions->get_results() );
114
+		$this->print_table_body($subscriptions->get_results());
115 115
 
116 116
 		// Print table footer.
117 117
 		$this->print_table_footer();
118 118
 
119 119
 		// Print the navigation.
120
-		$this->print_navigation( $subscriptions->get_total() );
120
+		$this->print_navigation($subscriptions->get_total());
121 121
 
122 122
 		// Backwards compatibility.
123
-		do_action( 'wpinv_after_user_subscriptions' );
123
+		do_action('wpinv_after_user_subscriptions');
124 124
 
125 125
 		// Return the output.
126 126
 		return ob_get_clean();
@@ -135,13 +135,13 @@  discard block
 block discarded – undo
135 135
 	public function get_subscriptions_table_columns() {
136 136
 
137 137
 		$columns = array(
138
-			'subscription' => __( 'Subscription', 'invoicing' ),
139
-			'amount'       => __( 'Amount', 'invoicing' ),
140
-			'renewal-date' => __( 'Next payment', 'invoicing' ),
141
-			'status'       => __( 'Status', 'invoicing' ),
138
+			'subscription' => __('Subscription', 'invoicing'),
139
+			'amount'       => __('Amount', 'invoicing'),
140
+			'renewal-date' => __('Next payment', 'invoicing'),
141
+			'status'       => __('Status', 'invoicing'),
142 142
 		);
143 143
 
144
-		return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns );
144
+		return apply_filters('getpaid_frontend_subscriptions_table_columns', $columns);
145 145
 	}
146 146
 
147 147
 	/**
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
 
157 157
 				<thead>
158 158
 					<tr>
159
-						<?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?>
160
-							<th scope="col" class="font-weight-bold getpaid-subscriptions-table-<?php echo esc_attr( $key ); ?>">
161
-								<?php echo esc_html( $label ); ?>
159
+						<?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?>
160
+							<th scope="col" class="font-weight-bold getpaid-subscriptions-table-<?php echo esc_attr($key); ?>">
161
+								<?php echo esc_html($label); ?>
162 162
 							</th>
163 163
 						<?php endforeach; ?>
164 164
 					</tr>
@@ -173,12 +173,12 @@  discard block
 block discarded – undo
173 173
 	 *
174 174
 	 * @param WPInv_Subscription[] $subscriptions
175 175
 	 */
176
-	public function print_table_body( $subscriptions ) {
176
+	public function print_table_body($subscriptions) {
177 177
 
178
-		if ( empty( $subscriptions ) ) {
178
+		if (empty($subscriptions)) {
179 179
 			$this->print_table_body_no_subscriptions();
180 180
 		} else {
181
-			$this->print_table_body_subscriptions( $subscriptions );
181
+			$this->print_table_body_subscriptions($subscriptions);
182 182
 		}
183 183
 
184 184
 	}
@@ -193,12 +193,12 @@  discard block
 block discarded – undo
193 193
 		<tbody>
194 194
 
195 195
 			<tr>
196
-				<td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>">
196
+				<td colspan="<?php echo count($this->get_subscriptions_table_columns()); ?>">
197 197
 
198 198
 					<?php
199 199
 						aui()->alert(
200 200
 							array(
201
-								'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ),
201
+								'content' => wp_kses_post(__('No subscriptions found.', 'invoicing')),
202 202
 								'type'    => 'warning',
203 203
 							),
204 204
                             true
@@ -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 esc_attr( $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 esc_attr($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
 
@@ -331,9 +331,9 @@  discard block
 block discarded – undo
331 331
 				echo wp_kses_post(
332 332
 					getpaid_paginate_links(
333 333
 						array(
334
-							'base'   => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
334
+							'base'   => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
335 335
 							'format' => '?paged=%#%',
336
-							'total'  => (int) ceil( $total / 10 ),
336
+							'total'  => (int) ceil($total / 10),
337 337
 						)
338 338
 					)
339 339
 				);
@@ -350,42 +350,42 @@  discard block
 block discarded – undo
350 350
 	 *
351 351
 	 * @return array
352 352
 	 */
353
-	public function get_single_subscription_columns( $subscription ) {
353
+	public function get_single_subscription_columns($subscription) {
354 354
 
355 355
 		// Prepare subscription detail columns.
356
-		$subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() );
357
-		$items_count        = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] );
356
+		$subscription_group = getpaid_get_invoice_subscription_group($subscription->get_parent_invoice_id(), $subscription->get_id());
357
+		$items_count        = empty($subscription_group) ? 1 : count($subscription_group['items']);
358 358
 		$fields             = apply_filters(
359 359
 			'getpaid_single_subscription_details_fields',
360 360
 			array(
361
-				'status'           => __( 'Status', 'invoicing' ),
362
-				'initial_amount'   => __( 'Initial amount', 'invoicing' ),
363
-				'recurring_amount' => __( 'Recurring amount', 'invoicing' ),
364
-				'start_date'       => __( 'Start date', 'invoicing' ),
365
-				'expiry_date'      => __( 'Next payment', 'invoicing' ),
366
-				'payments'         => __( 'Payments', 'invoicing' ),
367
-				'item'             => _n( 'Item', 'Items', $items_count, 'invoicing' ),
361
+				'status'           => __('Status', 'invoicing'),
362
+				'initial_amount'   => __('Initial amount', 'invoicing'),
363
+				'recurring_amount' => __('Recurring amount', 'invoicing'),
364
+				'start_date'       => __('Start date', 'invoicing'),
365
+				'expiry_date'      => __('Next payment', 'invoicing'),
366
+				'payments'         => __('Payments', 'invoicing'),
367
+				'item'             => _n('Item', 'Items', $items_count, 'invoicing'),
368 368
 			),
369 369
 			$subscription
370 370
 		);
371 371
 
372
-		if ( isset( $fields['expiry_date'] ) ) {
372
+		if (isset($fields['expiry_date'])) {
373 373
 
374
-			if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) {
375
-				$fields['expiry_date'] = __( 'End date', 'invoicing' );
374
+			if (!$subscription->is_active() || $subscription->is_last_renewal()) {
375
+				$fields['expiry_date'] = __('End date', 'invoicing');
376 376
 			}
377 377
 
378
-			if ( 'pending' == $subscription->get_status() ) {
379
-				unset( $fields['expiry_date'] );
378
+			if ('pending' == $subscription->get_status()) {
379
+				unset($fields['expiry_date']);
380 380
 			}
381 381
 }
382 382
 
383
-		if ( isset( $fields['start_date'] ) && 'pending' == $subscription->get_status() ) {
384
-			unset( $fields['start_date'] );
383
+		if (isset($fields['start_date']) && 'pending' == $subscription->get_status()) {
384
+			unset($fields['start_date']);
385 385
 		}
386 386
 
387
-		if ( $subscription->get_initial_amount() == $subscription->get_recurring_amount() ) {
388
-			unset( $fields['initial_amount'] );
387
+		if ($subscription->get_initial_amount() == $subscription->get_recurring_amount()) {
388
+			unset($fields['initial_amount']);
389 389
 		}
390 390
 
391 391
 		return $fields;
@@ -398,16 +398,16 @@  discard block
 block discarded – undo
398 398
 	 *
399 399
 	 * @return string
400 400
 	 */
401
-	public function display_single_subscription( $subscription ) {
401
+	public function display_single_subscription($subscription) {
402 402
 
403 403
 		// Fetch the subscription.
404
-		$subscription = new WPInv_Subscription( (int) $subscription );
404
+		$subscription = new WPInv_Subscription((int) $subscription);
405 405
 
406
-		if ( ! $subscription->exists() ) {
406
+		if (!$subscription->exists()) {
407 407
 
408 408
 			return aui()->alert(
409 409
 				array(
410
-					'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ),
410
+					'content' => wp_kses_post(__('Subscription not found.', 'invoicing')),
411 411
 					'type'    => 'error',
412 412
 				)
413 413
 			);
@@ -415,11 +415,11 @@  discard block
 block discarded – undo
415 415
 		}
416 416
 
417 417
 		// Ensure that the user owns this subscription key.
418
-		if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) {
418
+		if (get_current_user_id() != $subscription->get_customer_id() && !wpinv_current_user_can_manage_invoicing()) {
419 419
 
420 420
 			return aui()->alert(
421 421
 				array(
422
-					'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
+					'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')),
423 423
 					'type'    => 'error',
424 424
 				)
425 425
 			);
Please login to merge, or discard this patch.
templates/invoice/fee-item.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -9,9 +9,9 @@  discard block
 block discarded – undo
9 9
  * @var array $fee
10 10
  */
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14
-do_action( 'getpaid_before_invoice_fee_item', $invoice, $fee );
14
+do_action('getpaid_before_invoice_fee_item', $invoice, $fee);
15 15
 
16 16
 ?>
17 17
 
@@ -19,64 +19,64 @@  discard block
 block discarded – undo
19 19
 
20 20
     <div class="form-row">
21 21
 
22
-        <?php foreach ( array_keys( $columns ) as $column ) : ?>
22
+        <?php foreach (array_keys($columns) as $column) : ?>
23 23
 
24
-            <div class="<?php echo 'name' == $column ? 'col-12 col-sm-6' : 'col-12 col-sm'; ?> getpaid-invoice-item-<?php echo esc_attr( $column ); ?>">
24
+            <div class="<?php echo 'name' == $column ? 'col-12 col-sm-6' : 'col-12 col-sm'; ?> getpaid-invoice-item-<?php echo esc_attr($column); ?>">
25 25
 
26 26
                 <?php
27 27
 
28 28
                     // Fires before printing a fee item column.
29
-                    do_action( "getpaid_invoice_fee_item_before_$column", $fee, $invoice );
29
+                    do_action("getpaid_invoice_fee_item_before_$column", $fee, $invoice);
30 30
 
31 31
                     // Item name.
32
-                    if ( 'name' == $column ) {
32
+                    if ('name' == $column) {
33 33
 
34 34
 					// Display the name.
35
-					echo '<div class="mb-1">' . esc_html( $fee['name'] ) . '</div>';
35
+					echo '<div class="mb-1">' . esc_html($fee['name']) . '</div>';
36 36
 
37 37
 					// And an optional description.
38
-					$description = empty( $fee['description'] ) ? esc_html__( 'Fee', 'invoicing' ) : esc_html( $fee['description'] );
39
-					echo wp_kses_post( "<small class='form-text text-muted pr-2 m-0'>$description</small>" );
38
+					$description = empty($fee['description']) ? esc_html__('Fee', 'invoicing') : esc_html($fee['description']);
39
+					echo wp_kses_post("<small class='form-text text-muted pr-2 m-0'>$description</small>");
40 40
 
41 41
                     }
42 42
 
43 43
                     // Item price.
44
-                    if ( 'price' == $column ) {
44
+                    if ('price' == $column) {
45 45
 
46 46
 					// Display the item price (or recurring price if this is a renewal invoice)
47
-					if ( $invoice->is_recurring() && $invoice->is_renewal() ) {
48
-						wpinv_the_price( $fee['recurring_fee'], $invoice->get_currency() );
47
+					if ($invoice->is_recurring() && $invoice->is_renewal()) {
48
+						wpinv_the_price($fee['recurring_fee'], $invoice->get_currency());
49 49
                         } else {
50
-                            wpinv_the_price( $fee['initial_fee'], $invoice->get_currency() );
50
+                            wpinv_the_price($fee['initial_fee'], $invoice->get_currency());
51 51
                         }
52 52
 }
53 53
 
54 54
                     // Item quantity.
55
-                    if ( 'quantity' == $column ) {
55
+                    if ('quantity' == $column) {
56 56
 					echo '&mdash;';
57 57
                     }
58 58
 
59 59
                     // Item tax.
60
-                    if ( 'tax_rate' == $column ) {
60
+                    if ('tax_rate' == $column) {
61 61
 					echo '&mdash;';
62 62
                     }
63 63
 
64 64
                     // Item sub total.
65
-                    if ( 'subtotal' == $column ) {
65
+                    if ('subtotal' == $column) {
66 66
 
67 67
 					// Display the item price (or recurring price if this is a renewal invoice)
68
-					if ( $invoice->is_recurring() && $invoice->is_renewal() ) {
69
-						wpinv_the_price( $fee['recurring_fee'], $invoice->get_currency() );
68
+					if ($invoice->is_recurring() && $invoice->is_renewal()) {
69
+						wpinv_the_price($fee['recurring_fee'], $invoice->get_currency());
70 70
                         } else {
71
-                            wpinv_the_price( $fee['initial_fee'], $invoice->get_currency() );
71
+                            wpinv_the_price($fee['initial_fee'], $invoice->get_currency());
72 72
                         }
73 73
 }
74 74
 
75 75
                     // Fires when printing a fee item column.
76
-                    do_action( "getpaid_invoice_fee_item_$column", $fee, $invoice );
76
+                    do_action("getpaid_invoice_fee_item_$column", $fee, $invoice);
77 77
 
78 78
                     // Fires after printing a fee item column.
79
-                    do_action( "getpaid_invoice_fee_item_after_$column", $fee, $invoice );
79
+                    do_action("getpaid_invoice_fee_item_after_$column", $fee, $invoice);
80 80
 
81 81
                 ?>
82 82
 
Please login to merge, or discard this patch.