@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Paypal Payment Gateway IPN handler class. |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @param GetPaid_Paypal_Gateway $gateway |
33 | 33 | */ |
34 | - public function __construct( $gateway ) { |
|
34 | + public function __construct($gateway) { |
|
35 | 35 | $this->gateway = $gateway; |
36 | 36 | $this->verify_ipn(); |
37 | 37 | } |
@@ -43,37 +43,37 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function verify_ipn() { |
45 | 45 | |
46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler' ); |
|
46 | + wpinv_error_log('GetPaid PayPal IPN Handler'); |
|
47 | 47 | |
48 | 48 | // Validate the IPN. |
49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
49 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
50 | + wp_die('PayPal IPN Request Failure', 500); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | // Process the IPN. |
54 | - $posted = wp_unslash( $_POST ); |
|
55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
54 | + $posted = wp_unslash($_POST); |
|
55 | + $invoice = $this->get_ipn_invoice($posted); |
|
56 | 56 | |
57 | 57 | // Abort if it was not paid by our gateway. |
58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal' ); |
|
60 | - wp_die( 'Invoice not paid via PayPal', 500 ); |
|
58 | + if ($this->id != $invoice->get_gateway()) { |
|
59 | + wpinv_error_log('Aborting, Invoice was not paid via PayPal'); |
|
60 | + wp_die('Invoice not paid via PayPal', 500); |
|
61 | 61 | } |
62 | 62 | |
63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
63 | + $posted['payment_status'] = isset($posted['payment_status']) ? sanitize_key(strtolower($posted['payment_status'])) : ''; |
|
64 | + $posted['txn_type'] = sanitize_key(strtolower($posted['txn_type'])); |
|
65 | 65 | |
66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'] ); |
|
67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'] ); |
|
66 | + wpinv_error_log('Payment status:' . $posted['payment_status']); |
|
67 | + wpinv_error_log('IPN Type:' . $posted['txn_type']); |
|
68 | 68 | |
69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | - wpinv_error_log( 'Done processing IPN' ); |
|
72 | - wp_die( 'Processed', 200 ); |
|
69 | + if (method_exists($this, 'ipn_txn_' . $posted['txn_type'])) { |
|
70 | + call_user_func(array($this, 'ipn_txn_' . $posted['txn_type']), $invoice, $posted); |
|
71 | + wpinv_error_log('Done processing IPN'); |
|
72 | + wp_die('Processed', 200); |
|
73 | 73 | } |
74 | 74 | |
75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'] ); |
|
76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
75 | + wpinv_error_log('Aborting, Unsupported IPN type:' . $posted['txn_type']); |
|
76 | + wp_die('Unsupported IPN type', 200); |
|
77 | 77 | |
78 | 78 | } |
79 | 79 | |
@@ -83,22 +83,22 @@ discard block |
||
83 | 83 | * @param array $posted |
84 | 84 | * @return WPInv_Invoice |
85 | 85 | */ |
86 | - protected function get_ipn_invoice( $posted ) { |
|
86 | + protected function get_ipn_invoice($posted) { |
|
87 | 87 | |
88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice' ); |
|
88 | + wpinv_error_log('Retrieving PayPal IPN Response Invoice'); |
|
89 | 89 | |
90 | - if ( ! empty( $posted['custom'] ) ) { |
|
91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
90 | + if (!empty($posted['custom'])) { |
|
91 | + $invoice = new WPInv_Invoice($posted['custom']); |
|
92 | 92 | |
93 | - if ( $invoice->exists() ) { |
|
94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number() ); |
|
93 | + if ($invoice->exists()) { |
|
94 | + wpinv_error_log('Found invoice #' . $invoice->get_number()); |
|
95 | 95 | return $invoice; |
96 | 96 | } |
97 | 97 | |
98 | 98 | } |
99 | 99 | |
100 | - wpinv_error_log( 'Could not retrieve the associated invoice.' ); |
|
101 | - wp_die( 'Could not retrieve the associated invoice.', 500 ); |
|
100 | + wpinv_error_log('Could not retrieve the associated invoice.'); |
|
101 | + wp_die('Could not retrieve the associated invoice.', 500); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -106,14 +106,14 @@ discard block |
||
106 | 106 | */ |
107 | 107 | protected function validate_ipn() { |
108 | 108 | |
109 | - wpinv_error_log( 'Validating PayPal IPN response' ); |
|
109 | + wpinv_error_log('Validating PayPal IPN response'); |
|
110 | 110 | |
111 | 111 | // Retrieve the associated invoice. |
112 | - $posted = wp_unslash( $_POST ); |
|
113 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
112 | + $posted = wp_unslash($_POST); |
|
113 | + $invoice = $this->get_ipn_invoice($posted); |
|
114 | 114 | |
115 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
116 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data' ); |
|
115 | + if ($this->gateway->is_sandbox($invoice)) { |
|
116 | + wpinv_error_log($posted, 'Invoice was processed in sandbox hence logging the posted data'); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | // Validate the IPN. |
@@ -130,20 +130,20 @@ discard block |
||
130 | 130 | ); |
131 | 131 | |
132 | 132 | // Post back to get a response. |
133 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
133 | + $response = wp_safe_remote_post($this->gateway->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params); |
|
134 | 134 | |
135 | 135 | // Check to see if the request was valid. |
136 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
137 | - wpinv_error_log( $response['body'], 'Received valid response from PayPal IPN' ); |
|
136 | + if (!is_wp_error($response) && $response['response']['code'] < 300 && strstr($response['body'], 'VERIFIED')) { |
|
137 | + wpinv_error_log($response['body'], 'Received valid response from PayPal IPN'); |
|
138 | 138 | return true; |
139 | 139 | } |
140 | 140 | |
141 | - if ( is_wp_error( $response ) ) { |
|
142 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
141 | + if (is_wp_error($response)) { |
|
142 | + wpinv_error_log($response->get_error_message(), 'Received invalid response from PayPal IPN'); |
|
143 | 143 | return false; |
144 | 144 | } |
145 | 145 | |
146 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
146 | + wpinv_error_log($response['body'], 'Received invalid response from PayPal IPN'); |
|
147 | 147 | return false; |
148 | 148 | |
149 | 149 | } |
@@ -154,17 +154,17 @@ discard block |
||
154 | 154 | * @param WPInv_Invoice $invoice Invoice object. |
155 | 155 | * @param string $currency currency to validate. |
156 | 156 | */ |
157 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
157 | + protected function validate_ipn_currency($invoice, $currency) { |
|
158 | 158 | |
159 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
159 | + if (strtolower($invoice->get_currency()) !== strtolower($currency)) { |
|
160 | 160 | |
161 | 161 | /* translators: %s: currency code. */ |
162 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
162 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal currencies do not match (code %s).', 'invoicing'), $currency)); |
|
163 | 163 | |
164 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
164 | + wpinv_error_log("Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true); |
|
165 | 165 | } |
166 | 166 | |
167 | - wpinv_error_log( $currency, 'Validated IPN Currency' ); |
|
167 | + wpinv_error_log($currency, 'Validated IPN Currency'); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -173,16 +173,16 @@ discard block |
||
173 | 173 | * @param WPInv_Invoice $invoice Invoice object. |
174 | 174 | * @param float $amount amount to validate. |
175 | 175 | */ |
176 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
177 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
176 | + protected function validate_ipn_amount($invoice, $amount) { |
|
177 | + if (number_format($invoice->get_total(), 2, '.', '') !== number_format($amount, 2, '.', '')) { |
|
178 | 178 | |
179 | 179 | /* translators: %s: Amount. */ |
180 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
180 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal amounts do not match (gross %s).', 'invoicing'), $amount)); |
|
181 | 181 | |
182 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
182 | + wpinv_error_log("Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true); |
|
183 | 183 | } |
184 | 184 | |
185 | - wpinv_error_log( $amount, 'Validated IPN Amount' ); |
|
185 | + wpinv_error_log($amount, 'Validated IPN Amount'); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -191,19 +191,19 @@ discard block |
||
191 | 191 | * @param WPInv_Invoice $invoice Invoice object. |
192 | 192 | * @param string $receiver_email Email to validate. |
193 | 193 | */ |
194 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
195 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
194 | + protected function validate_ipn_receiver_email($invoice, $receiver_email) { |
|
195 | + $paypal_email = wpinv_get_option('paypal_email'); |
|
196 | 196 | |
197 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
198 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
197 | + if (strcasecmp(trim($receiver_email), trim($paypal_email)) !== 0) { |
|
198 | + wpinv_record_gateway_error('IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}"); |
|
199 | 199 | |
200 | 200 | /* translators: %s: email address . */ |
201 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
201 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal IPN response from a different email address (%s).', 'invoicing'), $receiver_email)); |
|
202 | 202 | |
203 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
203 | + return wpinv_error_log("IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true); |
|
204 | 204 | } |
205 | 205 | |
206 | - wpinv_error_log( 'Validated PayPal Email' ); |
|
206 | + wpinv_error_log('Validated PayPal Email'); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -212,68 +212,68 @@ discard block |
||
212 | 212 | * @param WPInv_Invoice $invoice Invoice object. |
213 | 213 | * @param array $posted Posted data. |
214 | 214 | */ |
215 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
215 | + protected function ipn_txn_web_accept($invoice, $posted) { |
|
216 | 216 | |
217 | 217 | // Collect payment details |
218 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
219 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
218 | + $payment_status = strtolower($posted['payment_status']); |
|
219 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
220 | 220 | |
221 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
222 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
221 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
222 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
223 | 223 | |
224 | 224 | // Update the transaction id. |
225 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
226 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
225 | + if (!empty($posted['txn_id'])) { |
|
226 | + $invoice->set_transaction_id(wpinv_clean($posted['txn_id'])); |
|
227 | 227 | $invoice->save(); |
228 | 228 | } |
229 | 229 | |
230 | 230 | // Process a refund. |
231 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
231 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
232 | 232 | |
233 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
233 | + update_post_meta($invoice->get_id(), 'refunded_remotely', 1); |
|
234 | 234 | |
235 | - if ( ! $invoice->is_refunded() ) { |
|
236 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
235 | + if (!$invoice->is_refunded()) { |
|
236 | + $invoice->update_status('wpi-refunded', $posted['reason_code']); |
|
237 | 237 | } |
238 | 238 | |
239 | - return wpinv_error_log( $posted['reason_code'] ); |
|
239 | + return wpinv_error_log($posted['reason_code']); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | // Process payments. |
243 | - if ( $payment_status == 'completed' ) { |
|
243 | + if ($payment_status == 'completed') { |
|
244 | 244 | |
245 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
246 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.' ); |
|
245 | + if ($invoice->is_paid() && 'wpi_processing' != $invoice->get_status()) { |
|
246 | + return wpinv_error_log('Aborting, Invoice #' . $invoice->get_number() . ' is already paid.'); |
|
247 | 247 | } |
248 | 248 | |
249 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
249 | + $this->validate_ipn_amount($invoice, $posted['mc_gross']); |
|
250 | 250 | |
251 | 251 | $note = ''; |
252 | 252 | |
253 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
254 | - $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
253 | + if (!empty($posted['mc_fee'])) { |
|
254 | + $note = sprintf(__('PayPal Transaction Fee %.', 'invoicing'), sanitize_text_field($posted['mc_fee'])); |
|
255 | 255 | } |
256 | 256 | |
257 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
258 | - $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
257 | + if (!empty($posted['payer_status'])) { |
|
258 | + $note = ' ' . sprintf(__('Buyer status %.', 'invoicing'), sanitize_text_field($posted['payer_status'])); |
|
259 | 259 | } |
260 | 260 | |
261 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
262 | - return wpinv_error_log( 'Invoice marked as paid.' ); |
|
261 | + $invoice->mark_paid((!empty($posted['txn_id']) ? sanitize_text_field($posted['txn_id']) : ''), trim($note)); |
|
262 | + return wpinv_error_log('Invoice marked as paid.'); |
|
263 | 263 | |
264 | 264 | } |
265 | 265 | |
266 | 266 | // Pending payments. |
267 | - if ( $payment_status == 'pending' ) { |
|
267 | + if ($payment_status == 'pending') { |
|
268 | 268 | |
269 | 269 | /* translators: %s: pending reason. */ |
270 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
270 | + $invoice->update_status('wpi-onhold', sprintf(__('Payment pending (%s).', 'invoicing'), $posted['pending_reason'])); |
|
271 | 271 | |
272 | - return wpinv_error_log( 'Invoice marked as "payment held".' ); |
|
272 | + return wpinv_error_log('Invoice marked as "payment held".'); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | /* translators: %s: payment status. */ |
276 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
276 | + $invoice->update_status('wpi-failed', sprintf(__('Payment %s via IPN.', 'invoicing'), sanitize_text_field($posted['payment_status']))); |
|
277 | 277 | |
278 | 278 | } |
279 | 279 | |
@@ -283,8 +283,8 @@ discard block |
||
283 | 283 | * @param WPInv_Invoice $invoice Invoice object. |
284 | 284 | * @param array $posted Posted data. |
285 | 285 | */ |
286 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
287 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
286 | + protected function ipn_txn_cart($invoice, $posted) { |
|
287 | + $this->ipn_txn_web_accept($invoice, $posted); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | /** |
@@ -293,40 +293,40 @@ discard block |
||
293 | 293 | * @param WPInv_Invoice $invoice Invoice object. |
294 | 294 | * @param array $posted Posted data. |
295 | 295 | */ |
296 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
296 | + protected function ipn_txn_subscr_signup($invoice, $posted) { |
|
297 | 297 | |
298 | - wpinv_error_log( 'Processing subscription signup' ); |
|
298 | + wpinv_error_log('Processing subscription signup'); |
|
299 | 299 | |
300 | 300 | // Make sure the invoice has a subscription. |
301 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
301 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
302 | 302 | |
303 | - if ( empty( $subscription ) ) { |
|
304 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
303 | + if (empty($subscription)) { |
|
304 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | // Validate the IPN. |
308 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
309 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
310 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
308 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
309 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
310 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
311 | 311 | |
312 | 312 | // Activate the subscription. |
313 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
314 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
315 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
316 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
313 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
314 | + $subscription->set_date_created(current_time('mysql')); |
|
315 | + $subscription->set_expiration(date('Y-m-d H:i:s', (current_time('timestamp') + $duration))); |
|
316 | + $subscription->set_profile_id(sanitize_text_field($posted['subscr_id'])); |
|
317 | 317 | $subscription->activate(); |
318 | 318 | |
319 | 319 | // Set the transaction id. |
320 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
321 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
320 | + if (!empty($posted['txn_id'])) { |
|
321 | + $invoice->set_transaction_id($posted['txn_id']); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | // Update the payment status. |
325 | 325 | $invoice->mark_paid(); |
326 | 326 | |
327 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
327 | + $invoice->add_note(sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
328 | 328 | |
329 | - wpinv_error_log( 'Subscription started.' ); |
|
329 | + wpinv_error_log('Subscription started.'); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | /** |
@@ -335,27 +335,27 @@ discard block |
||
335 | 335 | * @param WPInv_Invoice $invoice Invoice object. |
336 | 336 | * @param array $posted Posted data. |
337 | 337 | */ |
338 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
338 | + protected function ipn_txn_subscr_payment($invoice, $posted) { |
|
339 | 339 | |
340 | 340 | // Make sure the invoice has a subscription. |
341 | - $subscription = wpinv_get_subscription( $invoice ); |
|
341 | + $subscription = wpinv_get_subscription($invoice); |
|
342 | 342 | |
343 | - if ( empty( $subscription ) ) { |
|
344 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
343 | + if (empty($subscription)) { |
|
344 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | // Abort if this is the first payment. |
348 | - if ( date( 'Ynd', $subscription->get_time_created() ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) { |
|
349 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
348 | + if (date('Ynd', $subscription->get_time_created()) == date('Ynd', strtotime($posted['payment_date']))) { |
|
349 | + $invoice->set_transaction_id(sanitize_text_field($posted['txn_id'])); |
|
350 | 350 | $invoice->save(); |
351 | 351 | return; |
352 | 352 | } |
353 | 353 | |
354 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id() ); |
|
354 | + wpinv_error_log('Processing subscription renewal payment for the invoice ' . $invoice->get_id()); |
|
355 | 355 | |
356 | 356 | // Abort if the payment is already recorded. |
357 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
358 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed' ); |
|
357 | + if (wpinv_get_id_by_transaction_id($posted['txn_id'])) { |
|
358 | + return wpinv_error_log('Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed'); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | $args = array( |
@@ -363,17 +363,17 @@ discard block |
||
363 | 363 | 'gateway' => $this->id, |
364 | 364 | ); |
365 | 365 | |
366 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
366 | + $invoice = wpinv_get_invoice($subscription->add_payment($args)); |
|
367 | 367 | |
368 | - if ( empty( $invoice ) ) { |
|
368 | + if (empty($invoice)) { |
|
369 | 369 | return; |
370 | 370 | } |
371 | 371 | |
372 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
373 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
372 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
373 | + $invoice->add_note(wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
374 | 374 | |
375 | 375 | $subscription->renew(); |
376 | - wpinv_error_log( 'Subscription renewed.' ); |
|
376 | + wpinv_error_log('Subscription renewed.'); |
|
377 | 377 | |
378 | 378 | } |
379 | 379 | |
@@ -382,18 +382,18 @@ discard block |
||
382 | 382 | * |
383 | 383 | * @param WPInv_Invoice $invoice Invoice object. |
384 | 384 | */ |
385 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
385 | + protected function ipn_txn_subscr_cancel($invoice) { |
|
386 | 386 | |
387 | 387 | // Make sure the invoice has a subscription. |
388 | - $subscription = wpinv_get_subscription( $invoice ); |
|
388 | + $subscription = wpinv_get_subscription($invoice); |
|
389 | 389 | |
390 | - if ( empty( $subscription ) ) { |
|
391 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
390 | + if (empty($subscription)) { |
|
391 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
392 | 392 | } |
393 | 393 | |
394 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id() ); |
|
394 | + wpinv_error_log('Processing subscription cancellation for the invoice ' . $invoice->get_id()); |
|
395 | 395 | $subscription->cancel(); |
396 | - wpinv_error_log( 'Subscription cancelled.' ); |
|
396 | + wpinv_error_log('Subscription cancelled.'); |
|
397 | 397 | |
398 | 398 | } |
399 | 399 | |
@@ -403,18 +403,18 @@ discard block |
||
403 | 403 | * @param WPInv_Invoice $invoice Invoice object. |
404 | 404 | * @param array $posted Posted data. |
405 | 405 | */ |
406 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
406 | + protected function ipn_txn_subscr_eot($invoice) { |
|
407 | 407 | |
408 | 408 | // Make sure the invoice has a subscription. |
409 | - $subscription = wpinv_get_subscription( $invoice ); |
|
409 | + $subscription = wpinv_get_subscription($invoice); |
|
410 | 410 | |
411 | - if ( empty( $subscription ) ) { |
|
412 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
411 | + if (empty($subscription)) { |
|
412 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
413 | 413 | } |
414 | 414 | |
415 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id() ); |
|
415 | + wpinv_error_log('Processing subscription end of life for the invoice ' . $invoice->get_id()); |
|
416 | 416 | $subscription->complete(); |
417 | - wpinv_error_log( 'Subscription completed.' ); |
|
417 | + wpinv_error_log('Subscription completed.'); |
|
418 | 418 | |
419 | 419 | } |
420 | 420 | |
@@ -424,18 +424,18 @@ discard block |
||
424 | 424 | * @param WPInv_Invoice $invoice Invoice object. |
425 | 425 | * @param array $posted Posted data. |
426 | 426 | */ |
427 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
427 | + protected function ipn_txn_subscr_failed($invoice) { |
|
428 | 428 | |
429 | 429 | // Make sure the invoice has a subscription. |
430 | - $subscription = wpinv_get_subscription( $invoice ); |
|
430 | + $subscription = wpinv_get_subscription($invoice); |
|
431 | 431 | |
432 | - if ( empty( $subscription ) ) { |
|
433 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
432 | + if (empty($subscription)) { |
|
433 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
434 | 434 | } |
435 | 435 | |
436 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id() ); |
|
436 | + wpinv_error_log('Processing subscription payment failure for the invoice ' . $invoice->get_id()); |
|
437 | 437 | $subscription->failing(); |
438 | - wpinv_error_log( 'Subscription marked as failing.' ); |
|
438 | + wpinv_error_log('Subscription marked as failing.'); |
|
439 | 439 | |
440 | 440 | } |
441 | 441 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -72,28 +72,28 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 = (int) $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 |
||
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 |
||
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 | |
@@ -351,12 +351,12 @@ discard block |
||
351 | 351 | |
352 | 352 | } |
353 | 353 | |
354 | - if ( 'objects' == $return && 'view' == $context ) { |
|
354 | + if ('objects' == $return && 'view' == $context) { |
|
355 | 355 | return $prepared; |
356 | 356 | } |
357 | 357 | |
358 | 358 | $items = array(); |
359 | - foreach ( $prepared as $item ) { |
|
359 | + foreach ($prepared as $item) { |
|
360 | 360 | $items[] = $item->prepare_data_for_use(); |
361 | 361 | } |
362 | 362 | |
@@ -370,14 +370,14 @@ discard block |
||
370 | 370 | * @param int $item_id The item id to return. |
371 | 371 | * @return GetPaid_Form_Item|bool |
372 | 372 | */ |
373 | - public function get_item( $item_id ) { |
|
373 | + public function get_item($item_id) { |
|
374 | 374 | |
375 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
375 | + if (empty($item_id) || !is_numeric($item_id)) { |
|
376 | 376 | return false; |
377 | 377 | } |
378 | 378 | |
379 | - foreach( $this->get_items() as $item ) { |
|
380 | - if ( $item->get_id() == (int) $item_id ) { |
|
379 | + foreach ($this->get_items() as $item) { |
|
380 | + if ($item->get_id() == (int) $item_id) { |
|
381 | 381 | return $item; |
382 | 382 | } |
383 | 383 | } |
@@ -393,15 +393,15 @@ discard block |
||
393 | 393 | * @param string $element_type The element type to return. |
394 | 394 | * @return array|bool |
395 | 395 | */ |
396 | - public function get_element_type( $element_type ) { |
|
396 | + public function get_element_type($element_type) { |
|
397 | 397 | |
398 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
398 | + if (empty($element_type) || !is_scalar($element_type)) { |
|
399 | 399 | return false; |
400 | 400 | } |
401 | 401 | |
402 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
402 | + foreach ($this->get_prop('elements') as $element) { |
|
403 | 403 | |
404 | - if ( $element['type'] == $element_type ) { |
|
404 | + if ($element['type'] == $element_type) { |
|
405 | 405 | return $element; |
406 | 406 | } |
407 | 407 | |
@@ -418,8 +418,8 @@ discard block |
||
418 | 418 | * @param string $context View or edit context. |
419 | 419 | * @return array |
420 | 420 | */ |
421 | - public function get_earned( $context = 'view' ) { |
|
422 | - return $this->get_prop( 'earned', $context ); |
|
421 | + public function get_earned($context = 'view') { |
|
422 | + return $this->get_prop('earned', $context); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | /** |
@@ -429,8 +429,8 @@ discard block |
||
429 | 429 | * @param string $context View or edit context. |
430 | 430 | * @return array |
431 | 431 | */ |
432 | - public function get_refunded( $context = 'view' ) { |
|
433 | - return $this->get_prop( 'refunded', $context ); |
|
432 | + public function get_refunded($context = 'view') { |
|
433 | + return $this->get_prop('refunded', $context); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | /** |
@@ -440,8 +440,8 @@ discard block |
||
440 | 440 | * @param string $context View or edit context. |
441 | 441 | * @return array |
442 | 442 | */ |
443 | - public function get_cancelled( $context = 'view' ) { |
|
444 | - return $this->get_prop( 'cancelled', $context ); |
|
443 | + public function get_cancelled($context = 'view') { |
|
444 | + return $this->get_prop('cancelled', $context); |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | /** |
@@ -451,8 +451,8 @@ discard block |
||
451 | 451 | * @param string $context View or edit context. |
452 | 452 | * @return array |
453 | 453 | */ |
454 | - public function get_failed( $context = 'view' ) { |
|
455 | - return $this->get_prop( 'failed', $context ); |
|
454 | + public function get_failed($context = 'view') { |
|
455 | + return $this->get_prop('failed', $context); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | /** |
@@ -463,8 +463,8 @@ discard block |
||
463 | 463 | * @return string |
464 | 464 | */ |
465 | 465 | public function get_currency() { |
466 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
467 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
466 | + $currency = empty($this->invoice) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
467 | + return apply_filters('getpaid-payment-form-currency', $currency, $this); |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | /* |
@@ -482,8 +482,8 @@ discard block |
||
482 | 482 | * |
483 | 483 | * @since 1.0.19 |
484 | 484 | */ |
485 | - public function set_version( $value ) { |
|
486 | - $this->set_prop( 'version', $value ); |
|
485 | + public function set_version($value) { |
|
486 | + $this->set_prop('version', $value); |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | /** |
@@ -493,11 +493,11 @@ discard block |
||
493 | 493 | * @param string $value Value to set. |
494 | 494 | * @return bool Whether or not the date was set. |
495 | 495 | */ |
496 | - public function set_date_created( $value ) { |
|
497 | - $date = strtotime( $value ); |
|
496 | + public function set_date_created($value) { |
|
497 | + $date = strtotime($value); |
|
498 | 498 | |
499 | - if ( $date ) { |
|
500 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
499 | + if ($date) { |
|
500 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
501 | 501 | return true; |
502 | 502 | } |
503 | 503 | |
@@ -512,11 +512,11 @@ discard block |
||
512 | 512 | * @param string $value Value to set. |
513 | 513 | * @return bool Whether or not the date was set. |
514 | 514 | */ |
515 | - public function set_date_modified( $value ) { |
|
516 | - $date = strtotime( $value ); |
|
515 | + public function set_date_modified($value) { |
|
516 | + $date = strtotime($value); |
|
517 | 517 | |
518 | - if ( $date ) { |
|
519 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
518 | + if ($date) { |
|
519 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
520 | 520 | return true; |
521 | 521 | } |
522 | 522 | |
@@ -530,8 +530,8 @@ discard block |
||
530 | 530 | * @since 1.0.19 |
531 | 531 | * @param string $value New name. |
532 | 532 | */ |
533 | - public function set_name( $value ) { |
|
534 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
533 | + public function set_name($value) { |
|
534 | + $this->set_prop('name', sanitize_text_field($value)); |
|
535 | 535 | } |
536 | 536 | |
537 | 537 | /** |
@@ -540,8 +540,8 @@ discard block |
||
540 | 540 | * @since 1.0.19 |
541 | 541 | * @param string $value New name. |
542 | 542 | */ |
543 | - public function set_title( $value ) { |
|
544 | - $this->set_name( $value ); |
|
543 | + public function set_title($value) { |
|
544 | + $this->set_name($value); |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | /** |
@@ -550,8 +550,8 @@ discard block |
||
550 | 550 | * @since 1.0.19 |
551 | 551 | * @param int $value New author. |
552 | 552 | */ |
553 | - public function set_author( $value ) { |
|
554 | - $this->set_prop( 'author', (int) $value ); |
|
553 | + public function set_author($value) { |
|
554 | + $this->set_prop('author', (int) $value); |
|
555 | 555 | } |
556 | 556 | |
557 | 557 | /** |
@@ -560,9 +560,9 @@ discard block |
||
560 | 560 | * @since 1.0.19 |
561 | 561 | * @param array $value Form elements. |
562 | 562 | */ |
563 | - public function set_elements( $value ) { |
|
564 | - if ( is_array( $value ) ) { |
|
565 | - $this->set_prop( 'elements', $value ); |
|
563 | + public function set_elements($value) { |
|
564 | + if (is_array($value)) { |
|
565 | + $this->set_prop('elements', $value); |
|
566 | 566 | } |
567 | 567 | } |
568 | 568 | |
@@ -572,9 +572,9 @@ discard block |
||
572 | 572 | * @since 1.0.19 |
573 | 573 | * @param array $value Form elements. |
574 | 574 | */ |
575 | - public function set_items( $value ) { |
|
576 | - if ( is_array( $value ) ) { |
|
577 | - $this->set_prop( 'items', $value ); |
|
575 | + public function set_items($value) { |
|
576 | + if (is_array($value)) { |
|
577 | + $this->set_prop('items', $value); |
|
578 | 578 | } |
579 | 579 | } |
580 | 580 | |
@@ -584,9 +584,9 @@ discard block |
||
584 | 584 | * @since 1.0.19 |
585 | 585 | * @param float $value Amount earned. |
586 | 586 | */ |
587 | - public function set_earned( $value ) { |
|
588 | - $value = max( (float) $value, 0 ); |
|
589 | - $this->set_prop( 'earned', $value ); |
|
587 | + public function set_earned($value) { |
|
588 | + $value = max((float) $value, 0); |
|
589 | + $this->set_prop('earned', $value); |
|
590 | 590 | } |
591 | 591 | |
592 | 592 | /** |
@@ -595,9 +595,9 @@ discard block |
||
595 | 595 | * @since 1.0.19 |
596 | 596 | * @param float $value Amount refunded. |
597 | 597 | */ |
598 | - public function set_refunded( $value ) { |
|
599 | - $value = max( (float) $value, 0 ); |
|
600 | - $this->set_prop( 'refunded', $value ); |
|
598 | + public function set_refunded($value) { |
|
599 | + $value = max((float) $value, 0); |
|
600 | + $this->set_prop('refunded', $value); |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | /** |
@@ -606,9 +606,9 @@ discard block |
||
606 | 606 | * @since 1.0.19 |
607 | 607 | * @param float $value Amount cancelled. |
608 | 608 | */ |
609 | - public function set_cancelled( $value ) { |
|
610 | - $value = max( (float) $value, 0 ); |
|
611 | - $this->set_prop( 'cancelled', $value ); |
|
609 | + public function set_cancelled($value) { |
|
610 | + $value = max((float) $value, 0); |
|
611 | + $this->set_prop('cancelled', $value); |
|
612 | 612 | } |
613 | 613 | |
614 | 614 | /** |
@@ -617,9 +617,9 @@ discard block |
||
617 | 617 | * @since 1.0.19 |
618 | 618 | * @param float $value Amount cancelled. |
619 | 619 | */ |
620 | - public function set_failed( $value ) { |
|
621 | - $value = max( (float) $value, 0 ); |
|
622 | - $this->set_prop( 'failed', $value ); |
|
620 | + public function set_failed($value) { |
|
621 | + $value = max((float) $value, 0); |
|
622 | + $this->set_prop('failed', $value); |
|
623 | 623 | } |
624 | 624 | |
625 | 625 | /** |
@@ -628,11 +628,11 @@ discard block |
||
628 | 628 | * @deprecated |
629 | 629 | * @return int item id |
630 | 630 | */ |
631 | - public function create( $data = array() ) { |
|
631 | + public function create($data = array()) { |
|
632 | 632 | |
633 | 633 | // Set the properties. |
634 | - if ( is_array( $data ) ) { |
|
635 | - $this->set_props( $data ); |
|
634 | + if (is_array($data)) { |
|
635 | + $this->set_props($data); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | // Save the item. |
@@ -646,8 +646,8 @@ discard block |
||
646 | 646 | * @deprecated |
647 | 647 | * @return int item id |
648 | 648 | */ |
649 | - public function update( $data = array() ) { |
|
650 | - return $this->create( $data ); |
|
649 | + public function update($data = array()) { |
|
650 | + return $this->create($data); |
|
651 | 651 | } |
652 | 652 | |
653 | 653 | /* |
@@ -667,7 +667,7 @@ discard block |
||
667 | 667 | */ |
668 | 668 | public function is_default() { |
669 | 669 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
670 | - return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
|
670 | + return (bool) apply_filters('wpinv_is_default_payment_form', $is_default, $this->get_id(), $this); |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | /** |
@@ -679,11 +679,11 @@ discard block |
||
679 | 679 | public function is_active() { |
680 | 680 | $is_active = 0 !== (int) $this->get_id(); |
681 | 681 | |
682 | - if ( $is_active && ! current_user_can( 'edit_post', $this->get_id() ) && $this->get_status() != 'publish' ) { |
|
682 | + if ($is_active && !current_user_can('edit_post', $this->get_id()) && $this->get_status() != 'publish') { |
|
683 | 683 | $is_active = false; |
684 | 684 | } |
685 | 685 | |
686 | - return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
|
686 | + return (bool) apply_filters('wpinv_is_payment_form_active', $is_active, $this); |
|
687 | 687 | } |
688 | 688 | |
689 | 689 | /** |
@@ -692,8 +692,8 @@ discard block |
||
692 | 692 | * @since 1.0.19 |
693 | 693 | * @return bool |
694 | 694 | */ |
695 | - public function has_item( $item_id ) { |
|
696 | - return false !== $this->get_item( $item_id ); |
|
695 | + public function has_item($item_id) { |
|
696 | + return false !== $this->get_item($item_id); |
|
697 | 697 | } |
698 | 698 | |
699 | 699 | /** |
@@ -702,8 +702,8 @@ discard block |
||
702 | 702 | * @since 1.0.19 |
703 | 703 | * @return bool |
704 | 704 | */ |
705 | - public function has_element_type( $element_type ) { |
|
706 | - return false !== $this->get_element_type( $element_type ); |
|
705 | + public function has_element_type($element_type) { |
|
706 | + return false !== $this->get_element_type($element_type); |
|
707 | 707 | } |
708 | 708 | |
709 | 709 | /** |
@@ -714,13 +714,13 @@ discard block |
||
714 | 714 | */ |
715 | 715 | public function is_recurring() { |
716 | 716 | |
717 | - if ( ! empty( $this->invoice ) ) { |
|
717 | + if (!empty($this->invoice)) { |
|
718 | 718 | return $this->invoice->is_recurring(); |
719 | 719 | } |
720 | 720 | |
721 | - foreach ( $this->get_items() as $item ) { |
|
721 | + foreach ($this->get_items() as $item) { |
|
722 | 722 | |
723 | - if ( $item->is_recurring() ) { |
|
723 | + if ($item->is_recurring()) { |
|
724 | 724 | return true; |
725 | 725 | } |
726 | 726 | |
@@ -734,7 +734,7 @@ discard block |
||
734 | 734 | * |
735 | 735 | * @since 1.0.19 |
736 | 736 | */ |
737 | - public function get_html( $extra_markup = '' ) { |
|
737 | + public function get_html($extra_markup = '') { |
|
738 | 738 | |
739 | 739 | // Return the HTML. |
740 | 740 | return wpinv_get_template_html( |
@@ -752,8 +752,8 @@ discard block |
||
752 | 752 | * |
753 | 753 | * @since 1.0.19 |
754 | 754 | */ |
755 | - public function display( $extra_markup = '' ) { |
|
756 | - echo $this->get_html( $extra_markup ); |
|
755 | + public function display($extra_markup = '') { |
|
756 | + echo $this->get_html($extra_markup); |
|
757 | 757 | } |
758 | 758 | |
759 | 759 | } |
@@ -4,7 +4,7 @@ discard block |
||
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,26 +23,26 @@ discard block |
||
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 | // For default forms, ensure that an item has been set. |
38 | - if ( $payment_form->is_default() && ! $submission->has_invoice() && isset( $data['getpaid-form-items'] ) ) { |
|
39 | - $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
40 | - $payment_form->set_items( getpaid_convert_items_to_array( $form_items ) ); |
|
38 | + if ($payment_form->is_default() && !$submission->has_invoice() && isset($data['getpaid-form-items'])) { |
|
39 | + $form_items = wpinv_clean($data['getpaid-form-items']); |
|
40 | + $payment_form->set_items(getpaid_convert_items_to_array($form_items)); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | // Process each individual item. |
44 | - foreach ( $payment_form->get_items() as $item ) { |
|
45 | - $this->process_item( $item, $selected_items ); |
|
44 | + foreach ($payment_form->get_items() as $item) { |
|
45 | + $this->process_item($item, $selected_items); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | } |
@@ -53,30 +53,30 @@ discard block |
||
53 | 53 | * @param GetPaid_Form_Item $item |
54 | 54 | * @param array $selected_items |
55 | 55 | */ |
56 | - public function process_item( $item, $selected_items ) { |
|
56 | + public function process_item($item, $selected_items) { |
|
57 | 57 | |
58 | 58 | // Abort if this is an optional item and it has not been selected. |
59 | - if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
59 | + if (!$item->is_required() && !isset($selected_items[$item->get_id()])) { |
|
60 | 60 | return; |
61 | 61 | } |
62 | 62 | |
63 | 63 | // (maybe) let customers change the quantities and prices. |
64 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
64 | + if (isset($selected_items[$item->get_id()])) { |
|
65 | 65 | |
66 | 66 | // Maybe change the quantities. |
67 | - if ( $item->allows_quantities() ) { |
|
68 | - $item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] ); |
|
67 | + if ($item->allows_quantities()) { |
|
68 | + $item->set_quantity((int) $selected_items[$item->get_id()]['quantity']); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | // Maybe change the price. |
72 | - if ( $item->user_can_set_their_price() ) { |
|
73 | - $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
72 | + if ($item->user_can_set_their_price()) { |
|
73 | + $price = (float) wpinv_sanitize_amount($selected_items[$item->get_id()]['price']); |
|
74 | 74 | |
75 | - if ( $item->get_minimum_price() > $price ) { |
|
76 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), wpinv_sanitize_amount( $item->get_minimum_price() ) ) ); |
|
75 | + if ($item->get_minimum_price() > $price) { |
|
76 | + throw new Exception(sprintf(__('The minimum allowed amount is %s', 'invoicing'), wpinv_sanitize_amount($item->get_minimum_price()))); |
|
77 | 77 | } |
78 | 78 | |
79 | - $item->set_price( $price ); |
|
79 | + $item->set_price($price); |
|
80 | 80 | |
81 | 81 | } |
82 | 82 |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
10 | +if (!defined('WPINC')) { |
|
11 | 11 | exit; |
12 | 12 | } |
13 | 13 | |
@@ -24,40 +24,40 @@ discard block |
||
24 | 24 | * @param Array $assoc_args Key value arguments stored in associated array format. |
25 | 25 | * @since 1.0.13 |
26 | 26 | */ |
27 | - public function insert_invoice( $args, $assoc_args ) { |
|
27 | + public function insert_invoice($args, $assoc_args) { |
|
28 | 28 | |
29 | 29 | // Fetch invoice data from the args |
30 | - $invoice_data = wp_unslash( $assoc_args ); |
|
30 | + $invoice_data = wp_unslash($assoc_args); |
|
31 | 31 | |
32 | 32 | // Abort if no invoice data is provided |
33 | - if( empty( $invoice_data ) ) { |
|
34 | - return WP_CLI::error( __( 'Invoice data not provided', 'invoicing' ) ); |
|
33 | + if (empty($invoice_data)) { |
|
34 | + return WP_CLI::error(__('Invoice data not provided', 'invoicing')); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | //Cart details |
38 | - if( !empty( $invoice_data['cart_details'] ) ) { |
|
39 | - $invoice_data['cart_details'] = json_decode( $invoice_data['cart_details'], true ); |
|
38 | + if (!empty($invoice_data['cart_details'])) { |
|
39 | + $invoice_data['cart_details'] = json_decode($invoice_data['cart_details'], true); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | //User details |
43 | - if( !empty( $invoice_data['user_info'] ) ) { |
|
44 | - $invoice_data['user_info'] = json_decode( $invoice_data['user_info'], true ); |
|
43 | + if (!empty($invoice_data['user_info'])) { |
|
44 | + $invoice_data['user_info'] = json_decode($invoice_data['user_info'], true); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | //Payment info |
48 | - if( !empty( $invoice_data['payment_details'] ) ) { |
|
49 | - $invoice_data['payment_details'] = json_decode( $invoice_data['payment_details'], true ); |
|
48 | + if (!empty($invoice_data['payment_details'])) { |
|
49 | + $invoice_data['payment_details'] = json_decode($invoice_data['payment_details'], true); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | // Try creating the invoice |
53 | - $invoice = wpinv_insert_invoice( $invoice_data, true ); |
|
53 | + $invoice = wpinv_insert_invoice($invoice_data, true); |
|
54 | 54 | |
55 | - if ( is_wp_error( $invoice ) ) { |
|
56 | - return WP_CLI::error( $invoice->get_error_message() ); |
|
55 | + if (is_wp_error($invoice)) { |
|
56 | + return WP_CLI::error($invoice->get_error_message()); |
|
57 | 57 | } |
58 | 58 | |
59 | - $message = sprintf( __( 'Invoice %s created', 'invoicing' ), $invoice->get_id() ); |
|
60 | - WP_CLI::success( $message ); |
|
59 | + $message = sprintf(__('Invoice %s created', 'invoicing'), $invoice->get_id()); |
|
60 | + WP_CLI::success($message); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 |
@@ -8,23 +8,23 @@ |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | ?> |
14 | 14 | |
15 | 15 | <div class='form-group'> |
16 | - <label :for="active_form_element.id + '_edit_heading'"><?php esc_html_e( 'Heading', 'invoicing' ) ?></label> |
|
16 | + <label :for="active_form_element.id + '_edit_heading'"><?php esc_html_e('Heading', 'invoicing') ?></label> |
|
17 | 17 | <input :id="active_form_element.id + '_edit_heading'" v-model='active_form_element.text' class='form-control' type='text' /> |
18 | 18 | </div> |
19 | 19 | |
20 | 20 | <div class='form-group'> |
21 | - <label :for="active_form_element.id + '_edit_level'"><?php esc_html_e( 'Select Heading Level', 'invoicing' ) ?></label> |
|
21 | + <label :for="active_form_element.id + '_edit_level'"><?php esc_html_e('Select Heading Level', 'invoicing') ?></label> |
|
22 | 22 | <select class='form-control custom-select' :id="active_form_element.id + '_edit_level'" v-model='active_form_element.level'> |
23 | - <option value='h1'><?php esc_html_e( 'H1', 'invoicing' ); ?></option> |
|
24 | - <option value='h2'><?php esc_html_e( 'H2', 'invoicing' ); ?></option> |
|
25 | - <option value='h3'><?php esc_html_e( 'H3', 'invoicing' ); ?></option> |
|
26 | - <option value='h4'><?php esc_html_e( 'H4', 'invoicing' ); ?></option> |
|
27 | - <option value='h5'><?php esc_html_e( 'H5', 'invoicing' ); ?></option> |
|
28 | - <option value='h6'><?php esc_html_e( 'H6', 'invoicing' ); ?></option> |
|
23 | + <option value='h1'><?php esc_html_e('H1', 'invoicing'); ?></option> |
|
24 | + <option value='h2'><?php esc_html_e('H2', 'invoicing'); ?></option> |
|
25 | + <option value='h3'><?php esc_html_e('H3', 'invoicing'); ?></option> |
|
26 | + <option value='h4'><?php esc_html_e('H4', 'invoicing'); ?></option> |
|
27 | + <option value='h5'><?php esc_html_e('H5', 'invoicing'); ?></option> |
|
28 | + <option value='h6'><?php esc_html_e('H6', 'invoicing'); ?></option> |
|
29 | 29 | </select> |
30 | 30 | </div> |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -26,8 +26,8 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function __construct() { |
28 | 28 | |
29 | - $this->templates_dir = apply_filters( 'getpaid_default_templates_dir', WPINV_PLUGIN_DIR . 'templates' ); |
|
30 | - $this->templates_url = apply_filters( 'getpaid_default_templates_url', WPINV_PLUGIN_URL . 'templates' ); |
|
29 | + $this->templates_dir = apply_filters('getpaid_default_templates_dir', WPINV_PLUGIN_DIR . 'templates'); |
|
30 | + $this->templates_url = apply_filters('getpaid_default_templates_url', WPINV_PLUGIN_URL . 'templates'); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @return bool |
55 | 55 | */ |
56 | 56 | public function is_elementor_preview() { |
57 | - return isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ); |
|
57 | + return isset($_REQUEST['elementor-preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor') || (isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor_ajax'); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @return bool |
65 | 65 | */ |
66 | 66 | public function is_divi_preview() { |
67 | - return isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'et_pb' ); |
|
67 | + return isset($_REQUEST['et_fb']) || isset($_REQUEST['et_pb_preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'et_pb'); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * @return bool |
75 | 75 | */ |
76 | 76 | public function is_beaver_preview() { |
77 | - return isset( $_REQUEST['fl_builder'] ); |
|
77 | + return isset($_REQUEST['fl_builder']); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @return bool |
85 | 85 | */ |
86 | 86 | public function is_siteorigin_preview() { |
87 | - return ! empty( $_REQUEST['siteorigin_panels_live_editor'] ); |
|
87 | + return !empty($_REQUEST['siteorigin_panels_live_editor']); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @return bool |
95 | 95 | */ |
96 | 96 | public function is_cornerstone_preview() { |
97 | - return ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint'; |
|
97 | + return !empty($_REQUEST['cornerstone_preview']) || basename($_SERVER['REQUEST_URI']) == 'cornerstone-endpoint'; |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @return bool |
105 | 105 | */ |
106 | 106 | public function is_fusion_preview() { |
107 | - return ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] ); |
|
107 | + return !empty($_REQUEST['fb-edit']) || !empty($_REQUEST['fusion_load_nonce']); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * @return bool |
115 | 115 | */ |
116 | 116 | public function is_oxygen_preview() { |
117 | - return ! empty( $_REQUEST['ct_builder'] ) || ( ! empty( $_REQUEST['action'] ) && ( substr( $_REQUEST['action'], 0, 11 ) === "oxy_render_" || substr( $_REQUEST['action'], 0, 10 ) === "ct_render_" ) ); |
|
117 | + return !empty($_REQUEST['ct_builder']) || (!empty($_REQUEST['action']) && (substr($_REQUEST['action'], 0, 11) === "oxy_render_" || substr($_REQUEST['action'], 0, 10) === "ct_render_")); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -124,25 +124,25 @@ discard block |
||
124 | 124 | * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'. |
125 | 125 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
126 | 126 | */ |
127 | - public function locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
127 | + public function locate_template($template_name, $template_path = '', $default_path = '') { |
|
128 | 128 | |
129 | 129 | // Load the defaults for the template path and default path. |
130 | - $template_path = empty( $template_path ) ? 'invoicing' : $template_path; |
|
131 | - $default_path = empty( $default_path ) ? $this->templates_dir : $default_path; |
|
132 | - $default_path = apply_filters( 'getpaid_template_default_template_path', $default_path, $template_name ); |
|
130 | + $template_path = empty($template_path) ? 'invoicing' : $template_path; |
|
131 | + $default_path = empty($default_path) ? $this->templates_dir : $default_path; |
|
132 | + $default_path = apply_filters('getpaid_template_default_template_path', $default_path, $template_name); |
|
133 | 133 | |
134 | 134 | // Is it overidden? |
135 | 135 | $template = locate_template( |
136 | - array( trailingslashit( $template_path ) . $template_name ), |
|
137 | - array( 'wpinv-' . $template_name ) |
|
136 | + array(trailingslashit($template_path) . $template_name), |
|
137 | + array('wpinv-' . $template_name) |
|
138 | 138 | ); |
139 | 139 | |
140 | 140 | // If not, load the default template. |
141 | - if ( empty( $template ) ) { |
|
142 | - $template = trailingslashit( $default_path ) . $template_name; |
|
141 | + if (empty($template)) { |
|
142 | + $template = trailingslashit($default_path) . $template_name; |
|
143 | 143 | } |
144 | 144 | |
145 | - return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path, $default_path ); |
|
145 | + return apply_filters('wpinv_locate_template', $template, $template_name, $template_path, $default_path); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -151,20 +151,20 @@ discard block |
||
151 | 151 | * @since 1.0.19 |
152 | 152 | * @return bool |
153 | 153 | */ |
154 | - protected function load_template( $template_name, $template_path, $args ) { |
|
154 | + protected function load_template($template_name, $template_path, $args) { |
|
155 | 155 | |
156 | - if ( is_array( $args ) ){ |
|
157 | - extract( $args ); |
|
156 | + if (is_array($args)) { |
|
157 | + extract($args); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | // Fires before loading a template. |
161 | - do_action( 'wpinv_before_template_part', $template_name, $template_path, $args ); |
|
161 | + do_action('wpinv_before_template_part', $template_name, $template_path, $args); |
|
162 | 162 | |
163 | 163 | // Load the template. |
164 | - include( $template_path ); |
|
164 | + include($template_path); |
|
165 | 165 | |
166 | 166 | // Fires after loading a template. |
167 | - do_action( 'wpinv_after_template_part', $template_name, $template_path, $args ); |
|
167 | + do_action('wpinv_after_template_part', $template_name, $template_path, $args); |
|
168 | 168 | |
169 | 169 | } |
170 | 170 | |
@@ -178,18 +178,18 @@ discard block |
||
178 | 178 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
179 | 179 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
180 | 180 | */ |
181 | - public function display_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
181 | + public function display_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
182 | 182 | |
183 | 183 | // Locate the template. |
184 | - $located = wpinv_locate_template( $template_name, $template_path, $default_path ); |
|
184 | + $located = wpinv_locate_template($template_name, $template_path, $default_path); |
|
185 | 185 | |
186 | 186 | // Abort if the file does not exist. |
187 | - if ( ! file_exists( $located ) ) { |
|
188 | - getpaid_doing_it_wrong( __CLASS__ . '::' .__METHOD__, sprintf( '<code>%s</code> does not exist.', $located ), '1.0.19' ); |
|
187 | + if (!file_exists($located)) { |
|
188 | + getpaid_doing_it_wrong(__CLASS__ . '::' . __METHOD__, sprintf('<code>%s</code> does not exist.', $located), '1.0.19'); |
|
189 | 189 | return; |
190 | 190 | } |
191 | 191 | |
192 | - $this->load_template( $template_name, $located, $args ); |
|
192 | + $this->load_template($template_name, $located, $args); |
|
193 | 193 | |
194 | 194 | } |
195 | 195 | |
@@ -203,9 +203,9 @@ discard block |
||
203 | 203 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
204 | 204 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
205 | 205 | */ |
206 | - public function get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
206 | + public function get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
207 | 207 | ob_start(); |
208 | - $this->display_template( $template_name, $args, $template_path, $default_path ); |
|
208 | + $this->display_template($template_name, $args, $template_path, $default_path); |
|
209 | 209 | return ob_get_clean(); |
210 | 210 | } |
211 | 211 |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * @version 1.0.19 |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * REST API invoices controller class. |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | |
53 | 53 | |
54 | 54 | 'customers' => array( |
55 | - 'description' => __( 'Limit result set to invoices for specific user ids.', 'invoicing' ), |
|
55 | + 'description' => __('Limit result set to invoices for specific user ids.', 'invoicing'), |
|
56 | 56 | 'type' => 'array', |
57 | 57 | 'items' => array( |
58 | 58 | 'type' => 'integer', |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | ), |
63 | 63 | |
64 | 64 | 'exclude_customers' => array( |
65 | - 'description' => __( 'Exclude invoices to specific users.', 'invoicing' ), |
|
65 | + 'description' => __('Exclude invoices to specific users.', 'invoicing'), |
|
66 | 66 | 'type' => 'array', |
67 | 67 | 'items' => array( |
68 | 68 | 'type' => 'integer', |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | ), |
73 | 73 | |
74 | 74 | 'parent' => array( |
75 | - 'description' => __( 'Limit result set to those of particular parent IDs.', 'invoicing' ), |
|
75 | + 'description' => __('Limit result set to those of particular parent IDs.', 'invoicing'), |
|
76 | 76 | 'type' => 'array', |
77 | 77 | 'items' => array( |
78 | 78 | 'type' => 'integer', |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | ), |
83 | 83 | |
84 | 84 | 'parent_exclude' => array( |
85 | - 'description' => __( 'Limit result set to all items except those of a particular parent ID.', 'invoicing' ), |
|
85 | + 'description' => __('Limit result set to all items except those of a particular parent ID.', 'invoicing'), |
|
86 | 86 | 'type' => 'array', |
87 | 87 | 'items' => array( |
88 | 88 | 'type' => 'integer', |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | ); |
97 | 97 | |
98 | 98 | // Filter collection parameters for the invoices controller. |
99 | - return apply_filters( 'getpaid_rest_invoices_collection_params', $params, $this ); |
|
99 | + return apply_filters('getpaid_rest_invoices_collection_params', $params, $this); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -107,21 +107,21 @@ discard block |
||
107 | 107 | * @param WP_REST_Request $request Request object. |
108 | 108 | * @return array $query_args |
109 | 109 | */ |
110 | - protected function prepare_items_query( $prepared_args = array(), $request = null ) { |
|
110 | + protected function prepare_items_query($prepared_args = array(), $request = null) { |
|
111 | 111 | |
112 | - $query_args = parent::prepare_items_query( $prepared_args ); |
|
112 | + $query_args = parent::prepare_items_query($prepared_args); |
|
113 | 113 | |
114 | 114 | // Retrieve invoices for specific customers. |
115 | - if ( ! empty( $request['customers'] ) ) { |
|
115 | + if (!empty($request['customers'])) { |
|
116 | 116 | $query_args['author__in'] = $request['customers']; |
117 | 117 | } |
118 | 118 | |
119 | 119 | // Skip invoices for specific customers. |
120 | - if ( ! empty( $request['exclude_customers'] ) ) { |
|
120 | + if (!empty($request['exclude_customers'])) { |
|
121 | 121 | $query_args['author__not_in'] = $request['exclude_customers']; |
122 | 122 | } |
123 | 123 | |
124 | - return apply_filters( 'getpaid_rest_invoices_prepare_items_query', $query_args, $request, $this ); |
|
124 | + return apply_filters('getpaid_rest_invoices_prepare_items_query', $query_args, $request, $this); |
|
125 | 125 | |
126 | 126 | } |
127 | 127 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | * @return array A list of registered item statuses. |
134 | 134 | */ |
135 | 135 | public function get_post_statuses() { |
136 | - return array_keys( wpinv_get_invoice_statuses( true, false, $this->post_type ) ); |
|
136 | + return array_keys(wpinv_get_invoice_statuses(true, false, $this->post_type)); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -142,9 +142,9 @@ discard block |
||
142 | 142 | * @param WPInv_Invoice $invoice Invoice to save. |
143 | 143 | * @return WP_Error|WPInv_Invoice |
144 | 144 | */ |
145 | - protected function save_object( $invoice ) { |
|
145 | + protected function save_object($invoice) { |
|
146 | 146 | $invoice->recalculate_total(); |
147 | - return parent::save_object( $invoice ); |
|
147 | + return parent::save_object($invoice); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * GetPaid_Invoice_Data_Store class file. |
5 | 5 | * |
6 | 6 | */ |
7 | -if ( ! defined( 'ABSPATH' ) ) { |
|
7 | +if (!defined('ABSPATH')) { |
|
8 | 8 | exit; |
9 | 9 | } |
10 | 10 | |
@@ -108,61 +108,61 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @param WPInv_Invoice $invoice Invoice object. |
110 | 110 | */ |
111 | - public function create( &$invoice ) { |
|
112 | - $invoice->set_version( WPINV_VERSION ); |
|
113 | - $invoice->set_date_created( current_time('mysql') ); |
|
111 | + public function create(&$invoice) { |
|
112 | + $invoice->set_version(WPINV_VERSION); |
|
113 | + $invoice->set_date_created(current_time('mysql')); |
|
114 | 114 | |
115 | 115 | // Create a new post. |
116 | 116 | $id = wp_insert_post( |
117 | 117 | apply_filters( |
118 | 118 | 'getpaid_new_invoice_data', |
119 | 119 | array( |
120 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
121 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
122 | - 'post_status' => $this->get_post_status( $invoice ), |
|
120 | + 'post_date' => $invoice->get_date_created('edit'), |
|
121 | + 'post_type' => $invoice->get_post_type('edit'), |
|
122 | + 'post_status' => $this->get_post_status($invoice), |
|
123 | 123 | 'ping_status' => 'closed', |
124 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
125 | - 'post_title' => $invoice->get_title( 'edit' ), |
|
126 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
127 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
124 | + 'post_author' => $invoice->get_user_id('edit'), |
|
125 | + 'post_title' => $invoice->get_title('edit'), |
|
126 | + 'post_excerpt' => $invoice->get_description('edit'), |
|
127 | + 'post_parent' => $invoice->get_parent_id('edit'), |
|
128 | 128 | ) |
129 | 129 | ), |
130 | 130 | true |
131 | 131 | ); |
132 | 132 | |
133 | - if ( $id && ! is_wp_error( $id ) ) { |
|
133 | + if ($id && !is_wp_error($id)) { |
|
134 | 134 | |
135 | 135 | // Update the new id and regenerate a title. |
136 | - $invoice->set_id( $id ); |
|
136 | + $invoice->set_id($id); |
|
137 | 137 | |
138 | 138 | $invoice->maybe_set_number(); |
139 | 139 | |
140 | 140 | wp_update_post( |
141 | 141 | array( |
142 | 142 | 'ID' => $invoice->get_id(), |
143 | - 'post_title' => $invoice->get_number( 'edit' ), |
|
144 | - 'post_name' => $invoice->get_path( 'edit' ) |
|
143 | + 'post_title' => $invoice->get_number('edit'), |
|
144 | + 'post_name' => $invoice->get_path('edit') |
|
145 | 145 | ) |
146 | 146 | ); |
147 | 147 | |
148 | 148 | // Save special fields and items. |
149 | - $this->save_special_fields( $invoice ); |
|
150 | - $this->save_items( $invoice ); |
|
149 | + $this->save_special_fields($invoice); |
|
150 | + $this->save_items($invoice); |
|
151 | 151 | |
152 | 152 | // Update meta data. |
153 | - $this->update_post_meta( $invoice ); |
|
153 | + $this->update_post_meta($invoice); |
|
154 | 154 | $invoice->save_meta_data(); |
155 | 155 | |
156 | 156 | // Apply changes. |
157 | 157 | $invoice->apply_changes(); |
158 | - $this->clear_caches( $invoice ); |
|
158 | + $this->clear_caches($invoice); |
|
159 | 159 | |
160 | 160 | // Fires after a new invoice is created. |
161 | - do_action( 'getpaid_new_invoice', $invoice ); |
|
161 | + do_action('getpaid_new_invoice', $invoice); |
|
162 | 162 | return true; |
163 | 163 | } |
164 | 164 | |
165 | - if ( is_wp_error( $id ) ) { |
|
165 | + if (is_wp_error($id)) { |
|
166 | 166 | $invoice->last_error = $id->get_error_message(); |
167 | 167 | } |
168 | 168 | |
@@ -175,14 +175,14 @@ discard block |
||
175 | 175 | * @param WPInv_Invoice $invoice Invoice object. |
176 | 176 | * |
177 | 177 | */ |
178 | - public function read( &$invoice ) { |
|
178 | + public function read(&$invoice) { |
|
179 | 179 | |
180 | 180 | $invoice->set_defaults(); |
181 | - $invoice_object = get_post( $invoice->get_id() ); |
|
181 | + $invoice_object = get_post($invoice->get_id()); |
|
182 | 182 | |
183 | - if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
184 | - $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
185 | - $invoice->set_id( 0 ); |
|
183 | + if (!$invoice->get_id() || !$invoice_object || !getpaid_is_invoice_post_type($invoice_object->post_type)) { |
|
184 | + $invoice->last_error = __('Invalid invoice.', 'invoicing'); |
|
185 | + $invoice->set_id(0); |
|
186 | 186 | return false; |
187 | 187 | } |
188 | 188 | |
@@ -200,14 +200,14 @@ discard block |
||
200 | 200 | ) |
201 | 201 | ); |
202 | 202 | |
203 | - $invoice->set_type( $invoice_object->post_type ); |
|
203 | + $invoice->set_type($invoice_object->post_type); |
|
204 | 204 | |
205 | - $this->read_object_data( $invoice, $invoice_object ); |
|
206 | - $this->add_special_fields( $invoice ); |
|
207 | - $this->add_items( $invoice ); |
|
205 | + $this->read_object_data($invoice, $invoice_object); |
|
206 | + $this->add_special_fields($invoice); |
|
207 | + $this->add_items($invoice); |
|
208 | 208 | $invoice->read_meta_data(); |
209 | - $invoice->set_object_read( true ); |
|
210 | - do_action( 'getpaid_read_invoice', $invoice ); |
|
209 | + $invoice->set_object_read(true); |
|
210 | + do_action('getpaid_read_invoice', $invoice); |
|
211 | 211 | |
212 | 212 | } |
213 | 213 | |
@@ -216,35 +216,35 @@ discard block |
||
216 | 216 | * |
217 | 217 | * @param WPInv_Invoice $invoice Invoice object. |
218 | 218 | */ |
219 | - public function update( &$invoice ) { |
|
219 | + public function update(&$invoice) { |
|
220 | 220 | $invoice->save_meta_data(); |
221 | - $invoice->set_version( WPINV_VERSION ); |
|
221 | + $invoice->set_version(WPINV_VERSION); |
|
222 | 222 | |
223 | - if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
224 | - $invoice->set_date_created( current_time('mysql') ); |
|
223 | + if (null === $invoice->get_date_created('edit')) { |
|
224 | + $invoice->set_date_created(current_time('mysql')); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | // Ensure both the key and number are set. |
228 | 228 | $invoice->get_path(); |
229 | 229 | |
230 | 230 | // Grab the current status so we can compare. |
231 | - $previous_status = get_post_status( $invoice->get_id() ); |
|
231 | + $previous_status = get_post_status($invoice->get_id()); |
|
232 | 232 | |
233 | 233 | $changes = $invoice->get_changes(); |
234 | 234 | |
235 | 235 | // Only update the post when the post data changes. |
236 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
236 | + if (array_intersect(array('date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path'), array_keys($changes))) { |
|
237 | 237 | $post_data = array( |
238 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
239 | - 'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ), |
|
240 | - 'post_status' => $invoice->get_status( 'edit' ), |
|
241 | - 'post_title' => $invoice->get_name( 'edit' ), |
|
242 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
243 | - 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
244 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
245 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
246 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
247 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
238 | + 'post_date' => $invoice->get_date_created('edit'), |
|
239 | + 'post_date_gmt' => $invoice->get_date_created_gmt('edit'), |
|
240 | + 'post_status' => $invoice->get_status('edit'), |
|
241 | + 'post_title' => $invoice->get_name('edit'), |
|
242 | + 'post_author' => $invoice->get_user_id('edit'), |
|
243 | + 'post_modified' => $invoice->get_date_modified('edit'), |
|
244 | + 'post_excerpt' => $invoice->get_description('edit'), |
|
245 | + 'post_parent' => $invoice->get_parent_id('edit'), |
|
246 | + 'post_name' => $invoice->get_path('edit'), |
|
247 | + 'post_type' => $invoice->get_post_type('edit'), |
|
248 | 248 | ); |
249 | 249 | |
250 | 250 | /** |
@@ -255,35 +255,35 @@ discard block |
||
255 | 255 | * This ensures hooks are fired by either WP itself (admin screen save), |
256 | 256 | * or an update purely from CRUD. |
257 | 257 | */ |
258 | - if ( doing_action( 'save_post' ) ) { |
|
259 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
260 | - clean_post_cache( $invoice->get_id() ); |
|
258 | + if (doing_action('save_post')) { |
|
259 | + $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $invoice->get_id())); |
|
260 | + clean_post_cache($invoice->get_id()); |
|
261 | 261 | } else { |
262 | - wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
262 | + wp_update_post(array_merge(array('ID' => $invoice->get_id()), $post_data)); |
|
263 | 263 | } |
264 | - $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
264 | + $invoice->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | // Update meta data. |
268 | - $this->update_post_meta( $invoice ); |
|
268 | + $this->update_post_meta($invoice); |
|
269 | 269 | |
270 | 270 | // Save special fields and items. |
271 | - $this->save_special_fields( $invoice ); |
|
272 | - $this->save_items( $invoice ); |
|
271 | + $this->save_special_fields($invoice); |
|
272 | + $this->save_items($invoice); |
|
273 | 273 | |
274 | 274 | // Apply the changes. |
275 | 275 | $invoice->apply_changes(); |
276 | 276 | |
277 | 277 | // Clear caches. |
278 | - $this->clear_caches( $invoice ); |
|
278 | + $this->clear_caches($invoice); |
|
279 | 279 | |
280 | 280 | // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
281 | - $new_status = $invoice->get_status( 'edit' ); |
|
281 | + $new_status = $invoice->get_status('edit'); |
|
282 | 282 | |
283 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
284 | - do_action( 'getpaid_new_invoice', $invoice ); |
|
283 | + if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) { |
|
284 | + do_action('getpaid_new_invoice', $invoice); |
|
285 | 285 | } else { |
286 | - do_action( 'getpaid_update_invoice', $invoice ); |
|
286 | + do_action('getpaid_update_invoice', $invoice); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | } |
@@ -299,45 +299,45 @@ discard block |
||
299 | 299 | * |
300 | 300 | * @param WPInv_Invoice $invoice Invoice object. |
301 | 301 | */ |
302 | - public function add_special_fields( &$invoice ) { |
|
302 | + public function add_special_fields(&$invoice) { |
|
303 | 303 | global $wpdb; |
304 | 304 | |
305 | 305 | // Maybe retrieve from the cache. |
306 | - $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
306 | + $data = wp_cache_get($invoice->get_id(), 'getpaid_invoice_special_fields'); |
|
307 | 307 | |
308 | 308 | // If not found, retrieve from the db. |
309 | - if ( false === $data ) { |
|
310 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
309 | + if (false === $data) { |
|
310 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
311 | 311 | |
312 | 312 | $data = $wpdb->get_row( |
313 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
313 | + $wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id()), |
|
314 | 314 | ARRAY_A |
315 | 315 | ); |
316 | 316 | |
317 | 317 | // Update the cache with our data |
318 | - wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
318 | + wp_cache_set($invoice->get_id(), $data, 'getpaid_invoice_special_fields'); |
|
319 | 319 | |
320 | 320 | } |
321 | 321 | |
322 | 322 | // Abort if the data does not exist. |
323 | - if ( empty( $data ) ) { |
|
324 | - $invoice->set_object_read( true ); |
|
325 | - $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) ); |
|
323 | + if (empty($data)) { |
|
324 | + $invoice->set_object_read(true); |
|
325 | + $invoice->set_props(wpinv_get_user_address($invoice->get_user_id())); |
|
326 | 326 | return; |
327 | 327 | } |
328 | 328 | |
329 | 329 | $props = array(); |
330 | 330 | |
331 | - foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
331 | + foreach ($this->database_fields_to_props as $db_field => $prop) { |
|
332 | 332 | |
333 | - if ( $db_field == 'post_id' ) { |
|
333 | + if ($db_field == 'post_id') { |
|
334 | 334 | continue; |
335 | 335 | } |
336 | 336 | |
337 | - $props[ $prop ] = $data[ $db_field ]; |
|
337 | + $props[$prop] = $data[$db_field]; |
|
338 | 338 | } |
339 | 339 | |
340 | - $invoice->set_props( $props ); |
|
340 | + $invoice->set_props($props); |
|
341 | 341 | |
342 | 342 | } |
343 | 343 | |
@@ -348,14 +348,14 @@ discard block |
||
348 | 348 | * @param WPInv_Invoice $invoice The Invoice object. |
349 | 349 | * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
350 | 350 | */ |
351 | - protected function get_special_fields_to_update( $invoice ) { |
|
351 | + protected function get_special_fields_to_update($invoice) { |
|
352 | 352 | $fields_to_update = array(); |
353 | - $changed_props = $invoice->get_changes(); |
|
353 | + $changed_props = $invoice->get_changes(); |
|
354 | 354 | |
355 | 355 | // Props should be updated if they are a part of the $changed array or don't exist yet. |
356 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
357 | - if ( array_key_exists( $prop, $changed_props ) ) { |
|
358 | - $fields_to_update[ $database_field ] = $prop; |
|
356 | + foreach ($this->database_fields_to_props as $database_field => $prop) { |
|
357 | + if (array_key_exists($prop, $changed_props)) { |
|
358 | + $fields_to_update[$database_field] = $prop; |
|
359 | 359 | } |
360 | 360 | } |
361 | 361 | |
@@ -368,25 +368,25 @@ discard block |
||
368 | 368 | * @param WPInv_Invoice $invoice WPInv_Invoice object. |
369 | 369 | * @since 1.0.19 |
370 | 370 | */ |
371 | - protected function update_special_fields( &$invoice ) { |
|
371 | + protected function update_special_fields(&$invoice) { |
|
372 | 372 | global $wpdb; |
373 | 373 | |
374 | 374 | $updated_props = array(); |
375 | - $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
375 | + $fields_to_update = $this->get_special_fields_to_update($invoice); |
|
376 | 376 | |
377 | - foreach ( $fields_to_update as $database_field => $prop ) { |
|
378 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
379 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
380 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
381 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
377 | + foreach ($fields_to_update as $database_field => $prop) { |
|
378 | + $value = $invoice->{"get_$prop"}('edit'); |
|
379 | + $value = is_string($value) ? wp_slash($value) : $value; |
|
380 | + $value = is_bool($value) ? (int) $value : $value; |
|
381 | + $updated_props[$database_field] = maybe_serialize($value); |
|
382 | 382 | } |
383 | 383 | |
384 | - if ( ! empty( $updated_props ) ) { |
|
384 | + if (!empty($updated_props)) { |
|
385 | 385 | |
386 | 386 | $table = $wpdb->prefix . 'getpaid_invoices'; |
387 | - $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
388 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
389 | - do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props ); |
|
387 | + $wpdb->update($table, $updated_props, array('post_id' => $invoice->get_id())); |
|
388 | + wp_cache_delete($invoice->get_id(), 'getpaid_invoice_special_fields'); |
|
389 | + do_action("getpaid_invoice_update_database_fields", $invoice, $updated_props); |
|
390 | 390 | |
391 | 391 | } |
392 | 392 | |
@@ -398,22 +398,22 @@ discard block |
||
398 | 398 | * @param WPInv_Invoice $invoice WPInv_Invoice object. |
399 | 399 | * @since 1.0.19 |
400 | 400 | */ |
401 | - protected function insert_special_fields( &$invoice ) { |
|
401 | + protected function insert_special_fields(&$invoice) { |
|
402 | 402 | global $wpdb; |
403 | 403 | |
404 | - $updated_props = array(); |
|
404 | + $updated_props = array(); |
|
405 | 405 | |
406 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
407 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
408 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
409 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
410 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
406 | + foreach ($this->database_fields_to_props as $database_field => $prop) { |
|
407 | + $value = $invoice->{"get_$prop"}('edit'); |
|
408 | + $value = is_string($value) ? wp_slash($value) : $value; |
|
409 | + $value = is_bool($value) ? (int) $value : $value; |
|
410 | + $updated_props[$database_field] = maybe_serialize($value); |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | $table = $wpdb->prefix . 'getpaid_invoices'; |
414 | - $wpdb->insert( $table, $updated_props ); |
|
415 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
416 | - do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props ); |
|
414 | + $wpdb->insert($table, $updated_props); |
|
415 | + wp_cache_delete($invoice->get_id(), 'getpaid_invoice_special_fields'); |
|
416 | + do_action("getpaid_invoice_insert_database_fields", $invoice, $updated_props); |
|
417 | 417 | |
418 | 418 | } |
419 | 419 | |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | * |
423 | 423 | * @param WPInv_Invoice $invoice Invoice object. |
424 | 424 | */ |
425 | - public function save_special_fields( & $invoice ) { |
|
425 | + public function save_special_fields(& $invoice) { |
|
426 | 426 | global $wpdb; |
427 | 427 | |
428 | 428 | // The invoices table. |
@@ -430,13 +430,13 @@ discard block |
||
430 | 430 | $id = (int) $invoice->get_id(); |
431 | 431 | $invoice->maybe_set_key(); |
432 | 432 | |
433 | - if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
433 | + if ($wpdb->get_var("SELECT `post_id` FROM $table WHERE `post_id`= $id")) { |
|
434 | 434 | |
435 | - $this->update_special_fields( $invoice ); |
|
435 | + $this->update_special_fields($invoice); |
|
436 | 436 | |
437 | 437 | } else { |
438 | 438 | |
439 | - $this->insert_special_fields( $invoice ); |
|
439 | + $this->insert_special_fields($invoice); |
|
440 | 440 | |
441 | 441 | } |
442 | 442 | |
@@ -447,43 +447,43 @@ discard block |
||
447 | 447 | * |
448 | 448 | * @param WPInv_Invoice $invoice Invoice object. |
449 | 449 | */ |
450 | - public function add_items( &$invoice ) { |
|
450 | + public function add_items(&$invoice) { |
|
451 | 451 | global $wpdb; |
452 | 452 | |
453 | 453 | // Maybe retrieve from the cache. |
454 | - $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
454 | + $items = wp_cache_get($invoice->get_id(), 'getpaid_invoice_cart_details'); |
|
455 | 455 | |
456 | 456 | // If not found, retrieve from the db. |
457 | - if ( false === $items ) { |
|
458 | - $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
457 | + if (false === $items) { |
|
458 | + $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
459 | 459 | |
460 | 460 | $items = $wpdb->get_results( |
461 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
461 | + $wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id()) |
|
462 | 462 | ); |
463 | 463 | |
464 | 464 | // Update the cache with our data |
465 | - wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
465 | + wp_cache_set($invoice->get_id(), $items, 'getpaid_invoice_cart_details'); |
|
466 | 466 | |
467 | 467 | } |
468 | 468 | |
469 | 469 | // Abort if no items found. |
470 | - if ( empty( $items ) ) { |
|
470 | + if (empty($items)) { |
|
471 | 471 | return; |
472 | 472 | } |
473 | 473 | |
474 | - foreach ( $items as $item_data ) { |
|
475 | - $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
474 | + foreach ($items as $item_data) { |
|
475 | + $item = new GetPaid_Form_Item($item_data->item_id); |
|
476 | 476 | |
477 | 477 | // Set item data. |
478 | - $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
479 | - $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
480 | - $item->set_name( $item_data->item_name ); |
|
481 | - $item->set_description( $item_data->item_description ); |
|
482 | - $item->set_price( $item_data->item_price ); |
|
483 | - $item->set_quantity( $item_data->quantity ); |
|
484 | - $item->set_item_meta( $item_data->meta ); |
|
485 | - |
|
486 | - $invoice->add_item( $item ); |
|
478 | + $item->item_tax = wpinv_sanitize_amount($item_data->tax); |
|
479 | + $item->item_discount = wpinv_sanitize_amount($item_data->discount); |
|
480 | + $item->set_name($item_data->item_name); |
|
481 | + $item->set_description($item_data->item_description); |
|
482 | + $item->set_price($item_data->item_price); |
|
483 | + $item->set_quantity($item_data->quantity); |
|
484 | + $item->set_item_meta($item_data->meta); |
|
485 | + |
|
486 | + $invoice->add_item($item); |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | } |
@@ -493,20 +493,20 @@ discard block |
||
493 | 493 | * |
494 | 494 | * @param WPInv_Invoice $invoice Invoice object. |
495 | 495 | */ |
496 | - public function save_items( $invoice ) { |
|
496 | + public function save_items($invoice) { |
|
497 | 497 | |
498 | 498 | // Delete previously existing items. |
499 | - $this->delete_items( $invoice ); |
|
499 | + $this->delete_items($invoice); |
|
500 | 500 | |
501 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
501 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
502 | 502 | |
503 | - foreach ( $invoice->get_cart_details() as $item_data ) { |
|
504 | - $item_data = array_map( 'maybe_serialize', $item_data ); |
|
505 | - $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
503 | + foreach ($invoice->get_cart_details() as $item_data) { |
|
504 | + $item_data = array_map('maybe_serialize', $item_data); |
|
505 | + $GLOBALS['wpdb']->insert($table, $item_data); |
|
506 | 506 | } |
507 | 507 | |
508 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
509 | - do_action( "getpaid_invoice_save_items", $invoice ); |
|
508 | + wp_cache_delete($invoice->get_id(), 'getpaid_invoice_cart_details'); |
|
509 | + do_action("getpaid_invoice_save_items", $invoice); |
|
510 | 510 | |
511 | 511 | } |
512 | 512 | |
@@ -515,9 +515,9 @@ discard block |
||
515 | 515 | * |
516 | 516 | * @param WPInv_Invoice $invoice Invoice object. |
517 | 517 | */ |
518 | - public function delete_items( $invoice ) { |
|
519 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
520 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
518 | + public function delete_items($invoice) { |
|
519 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
520 | + return $GLOBALS['wpdb']->delete($table, array('post_id' => $invoice->get_id())); |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | /** |
@@ -525,9 +525,9 @@ discard block |
||
525 | 525 | * |
526 | 526 | * @param WPInv_Invoice $invoice Invoice object. |
527 | 527 | */ |
528 | - public function delete_special_fields( $invoice ) { |
|
529 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
530 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
528 | + public function delete_special_fields($invoice) { |
|
529 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
530 | + return $GLOBALS['wpdb']->delete($table, array('post_id' => $invoice->get_id())); |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | /** |
@@ -538,10 +538,10 @@ discard block |
||
538 | 538 | * @param WPInv_Invoice $object GetPaid_Data object. |
539 | 539 | * @return string |
540 | 540 | */ |
541 | - protected function get_post_status( $object ) { |
|
542 | - $object_status = $object->get_status( 'edit' ); |
|
541 | + protected function get_post_status($object) { |
|
542 | + $object_status = $object->get_status('edit'); |
|
543 | 543 | |
544 | - if ( ! $object_status ) { |
|
544 | + if (!$object_status) { |
|
545 | 545 | $object_status = $object->get_default_status(); |
546 | 546 | } |
547 | 547 |
@@ -11,55 +11,55 @@ discard block |
||
11 | 11 | * @since 1.0.0 |
12 | 12 | */ |
13 | 13 | function wpinv_automatic_upgrade() { |
14 | - $wpi_version = get_option( 'wpinv_version' ); |
|
14 | + $wpi_version = get_option('wpinv_version'); |
|
15 | 15 | |
16 | 16 | // Update tables. |
17 | - if ( ! get_option( 'getpaid_created_invoice_tables' ) ) { |
|
17 | + if (!get_option('getpaid_created_invoice_tables')) { |
|
18 | 18 | wpinv_v119_upgrades(); |
19 | - update_option( 'getpaid_created_invoice_tables', true ); |
|
19 | + update_option('getpaid_created_invoice_tables', true); |
|
20 | 20 | } |
21 | 21 | |
22 | - if ( $wpi_version == WPINV_VERSION ) { |
|
22 | + if ($wpi_version == WPINV_VERSION) { |
|
23 | 23 | return; |
24 | 24 | } |
25 | 25 | |
26 | - if ( version_compare( $wpi_version, '0.0.5', '<' ) ) { |
|
26 | + if (version_compare($wpi_version, '0.0.5', '<')) { |
|
27 | 27 | wpinv_v005_upgrades(); |
28 | 28 | } |
29 | 29 | |
30 | - if ( version_compare( $wpi_version, '1.0.3', '<' ) ) { |
|
30 | + if (version_compare($wpi_version, '1.0.3', '<')) { |
|
31 | 31 | wpinv_v110_upgrades(); |
32 | 32 | } |
33 | 33 | |
34 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
34 | + update_option('wpinv_version', WPINV_VERSION); |
|
35 | 35 | } |
36 | -add_action( 'admin_init', 'wpinv_automatic_upgrade' ); |
|
36 | +add_action('admin_init', 'wpinv_automatic_upgrade'); |
|
37 | 37 | |
38 | 38 | function wpinv_v005_upgrades() { |
39 | 39 | global $wpdb; |
40 | 40 | |
41 | 41 | // Invoices status |
42 | - $results = $wpdb->get_results( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
43 | - if ( !empty( $results ) ) { |
|
44 | - $wpdb->query( "UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
42 | + $results = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )"); |
|
43 | + if (!empty($results)) { |
|
44 | + $wpdb->query("UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )"); |
|
45 | 45 | |
46 | 46 | // Clean post cache |
47 | - foreach ( $results as $row ) { |
|
48 | - clean_post_cache( $row->ID ); |
|
47 | + foreach ($results as $row) { |
|
48 | + clean_post_cache($row->ID); |
|
49 | 49 | } |
50 | 50 | } |
51 | 51 | |
52 | 52 | // Item meta key changes |
53 | 53 | $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
54 | - $results = $wpdb->get_results( $query ); |
|
54 | + $results = $wpdb->get_results($query); |
|
55 | 55 | |
56 | - if ( !empty( $results ) ) { |
|
57 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
58 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
59 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
56 | + if (!empty($results)) { |
|
57 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )"); |
|
58 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'"); |
|
59 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'"); |
|
60 | 60 | |
61 | - foreach ( $results as $row ) { |
|
62 | - clean_post_cache( $row->post_id ); |
|
61 | + foreach ($results as $row) { |
|
62 | + clean_post_cache($row->post_id); |
|
63 | 63 | } |
64 | 64 | } |
65 | 65 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | function wpinv_create_invoices_table() { |
89 | 89 | global $wpdb; |
90 | 90 | |
91 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
91 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
92 | 92 | |
93 | 93 | // Create invoices table. |
94 | 94 | $table = $wpdb->prefix . 'getpaid_invoices'; |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | KEY `key` ( `key` ) |
133 | 133 | ) CHARACTER SET utf8 COLLATE utf8_general_ci;"; |
134 | 134 | |
135 | - dbDelta( $sql ); |
|
135 | + dbDelta($sql); |
|
136 | 136 | |
137 | 137 | // Create invoice items table. |
138 | 138 | $table = $wpdb->prefix . 'getpaid_invoice_items'; |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | KEY post_id ( post_id ) |
161 | 161 | ) CHARACTER SET utf8 COLLATE utf8_general_ci;"; |
162 | 162 | |
163 | - dbDelta( $sql ); |
|
163 | + dbDelta($sql); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -172,10 +172,10 @@ discard block |
||
172 | 172 | $invoices = array_unique( |
173 | 173 | get_posts( |
174 | 174 | array( |
175 | - 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
175 | + 'post_type' => array('wpi_invoice', 'wpi_quote'), |
|
176 | 176 | 'posts_per_page' => -1, |
177 | 177 | 'fields' => 'ids', |
178 | - 'post_status' => array_keys( get_post_stati() ), |
|
178 | + 'post_status' => array_keys(get_post_stati()), |
|
179 | 179 | ) |
180 | 180 | ) |
181 | 181 | ); |
@@ -183,19 +183,19 @@ discard block |
||
183 | 183 | $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
184 | 184 | $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
185 | 185 | |
186 | - if ( ! class_exists( 'WPInv_Legacy_Invoice' ) ) { |
|
187 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' ); |
|
186 | + if (!class_exists('WPInv_Legacy_Invoice')) { |
|
187 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php'); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | $invoice_rows = array(); |
191 | - foreach ( $invoices as $invoice ) { |
|
191 | + foreach ($invoices as $invoice) { |
|
192 | 192 | |
193 | - $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
194 | - $fields = array ( |
|
193 | + $invoice = new WPInv_Legacy_Invoice($invoice); |
|
194 | + $fields = array( |
|
195 | 195 | 'post_id' => $invoice->ID, |
196 | 196 | 'number' => $invoice->get_number(), |
197 | 197 | 'key' => $invoice->get_key(), |
198 | - 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
198 | + 'type' => str_replace('wpi_', '', $invoice->post_type), |
|
199 | 199 | 'mode' => $invoice->mode, |
200 | 200 | 'user_ip' => $invoice->get_ip(), |
201 | 201 | 'first_name' => $invoice->get_first_name(), |
@@ -224,27 +224,27 @@ discard block |
||
224 | 224 | 'custom_meta' => $invoice->payment_meta |
225 | 225 | ); |
226 | 226 | |
227 | - foreach ( $fields as $key => $val ) { |
|
228 | - if ( is_null( $val ) ) { |
|
227 | + foreach ($fields as $key => $val) { |
|
228 | + if (is_null($val)) { |
|
229 | 229 | $val = ''; |
230 | 230 | } |
231 | - $val = maybe_serialize( $val ); |
|
232 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
231 | + $val = maybe_serialize($val); |
|
232 | + $fields[$key] = $wpdb->prepare('%s', $val); |
|
233 | 233 | } |
234 | 234 | |
235 | - $fields = implode( ', ', $fields ); |
|
235 | + $fields = implode(', ', $fields); |
|
236 | 236 | $invoice_rows[] = "($fields)"; |
237 | 237 | |
238 | 238 | $item_rows = array(); |
239 | 239 | $item_columns = array(); |
240 | - foreach ( $invoice->get_cart_details() as $details ) { |
|
240 | + foreach ($invoice->get_cart_details() as $details) { |
|
241 | 241 | $fields = array( |
242 | 242 | 'post_id' => $invoice->ID, |
243 | 243 | 'item_id' => $details['id'], |
244 | 244 | 'item_name' => $details['name'], |
245 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
245 | + 'item_description' => empty($details['meta']['description']) ? '' : $details['meta']['description'], |
|
246 | 246 | 'vat_rate' => $details['vat_rate'], |
247 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
247 | + 'vat_class' => empty($details['vat_class']) ? '_standard' : $details['vat_class'], |
|
248 | 248 | 'tax' => $details['tax'], |
249 | 249 | 'item_price' => $details['item_price'], |
250 | 250 | 'custom_price' => $details['custom_price'], |
@@ -256,26 +256,26 @@ discard block |
||
256 | 256 | 'fees' => $details['fees'], |
257 | 257 | ); |
258 | 258 | |
259 | - $item_columns = array_keys ( $fields ); |
|
259 | + $item_columns = array_keys($fields); |
|
260 | 260 | |
261 | - foreach ( $fields as $key => $val ) { |
|
262 | - if ( is_null( $val ) ) { |
|
261 | + foreach ($fields as $key => $val) { |
|
262 | + if (is_null($val)) { |
|
263 | 263 | $val = ''; |
264 | 264 | } |
265 | - $val = maybe_serialize( $val ); |
|
266 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
265 | + $val = maybe_serialize($val); |
|
266 | + $fields[$key] = $wpdb->prepare('%s', $val); |
|
267 | 267 | } |
268 | 268 | |
269 | - $fields = implode( ', ', $fields ); |
|
269 | + $fields = implode(', ', $fields); |
|
270 | 270 | $item_rows[] = "($fields)"; |
271 | 271 | } |
272 | 272 | |
273 | - $item_rows = implode( ', ', $item_rows ); |
|
274 | - $item_columns = implode( ', ', $item_columns ); |
|
275 | - $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
273 | + $item_rows = implode(', ', $item_rows); |
|
274 | + $item_columns = implode(', ', $item_columns); |
|
275 | + $wpdb->query("INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows"); |
|
276 | 276 | } |
277 | 277 | |
278 | - $invoice_rows = implode( ', ', $invoice_rows ); |
|
279 | - $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
278 | + $invoice_rows = implode(', ', $invoice_rows); |
|
279 | + $wpdb->query("INSERT INTO $invoices_table VALUES $invoice_rows"); |
|
280 | 280 | |
281 | 281 | } |