@@ -13,464 +13,464 @@ discard block |
||
13 | 13 | */ |
14 | 14 | abstract class GetPaid_Payment_Gateway { |
15 | 15 | |
16 | - /** |
|
17 | - * Set if the place checkout button should be renamed on selection. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $checkout_button_text; |
|
22 | - |
|
23 | - /** |
|
24 | - * Boolean whether the method is enabled. |
|
25 | - * |
|
26 | - * @var bool |
|
27 | - */ |
|
28 | - public $enabled = true; |
|
29 | - |
|
30 | - /** |
|
31 | - * Payment method id. |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - public $id; |
|
36 | - |
|
37 | - /** |
|
38 | - * Payment method order. |
|
39 | - * |
|
40 | - * @var int |
|
41 | - */ |
|
42 | - public $order = 10; |
|
43 | - |
|
44 | - /** |
|
45 | - * Payment method title for the frontend. |
|
46 | - * |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - public $title; |
|
50 | - |
|
51 | - /** |
|
52 | - * Payment method description for the frontend. |
|
53 | - * |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - public $description; |
|
57 | - |
|
58 | - /** |
|
59 | - * Gateway title. |
|
60 | - * |
|
61 | - * @var string |
|
62 | - */ |
|
63 | - public $method_title = ''; |
|
64 | - |
|
65 | - /** |
|
66 | - * Gateway description. |
|
67 | - * |
|
68 | - * @var string |
|
69 | - */ |
|
70 | - public $method_description = ''; |
|
71 | - |
|
72 | - /** |
|
73 | - * Countries this gateway is allowed for. |
|
74 | - * |
|
75 | - * @var array |
|
76 | - */ |
|
77 | - public $countries; |
|
78 | - |
|
79 | - /** |
|
80 | - * Currencies this gateway is allowed for. |
|
81 | - * |
|
82 | - * @var array |
|
83 | - */ |
|
84 | - public $currencies; |
|
85 | - |
|
86 | - /** |
|
87 | - * Currencies this gateway is not allowed for. |
|
88 | - * |
|
89 | - * @var array |
|
90 | - */ |
|
91 | - public $exclude_currencies; |
|
92 | - |
|
93 | - /** |
|
94 | - * Maximum transaction amount, zero does not define a maximum. |
|
95 | - * |
|
96 | - * @var int |
|
97 | - */ |
|
98 | - public $max_amount = 0; |
|
99 | - |
|
100 | - /** |
|
101 | - * Optional URL to view a transaction. |
|
102 | - * |
|
103 | - * @var string |
|
104 | - */ |
|
105 | - public $view_transaction_url = ''; |
|
106 | - |
|
107 | - /** |
|
108 | - * Optional URL to view a subscription. |
|
109 | - * |
|
110 | - * @var string |
|
111 | - */ |
|
112 | - public $view_subscription_url = ''; |
|
113 | - |
|
114 | - /** |
|
115 | - * Optional label to show for "new payment method" in the payment |
|
116 | - * method/token selection radio selection. |
|
117 | - * |
|
118 | - * @var string |
|
119 | - */ |
|
120 | - public $new_method_label = ''; |
|
121 | - |
|
122 | - /** |
|
123 | - * Contains a user's saved tokens for this gateway. |
|
124 | - * |
|
125 | - * @var array |
|
126 | - */ |
|
127 | - protected $tokens = array(); |
|
128 | - |
|
129 | - /** |
|
130 | - * An array of features that this gateway supports. |
|
131 | - * |
|
132 | - * @var array |
|
133 | - */ |
|
134 | - protected $supports = array(); |
|
135 | - |
|
136 | - /** |
|
137 | - * Class constructor. |
|
138 | - */ |
|
139 | - public function __construct() { |
|
140 | - |
|
141 | - do_action( 'getpaid_before_init_payment_gateway_' . $this->id, $this ); |
|
142 | - |
|
143 | - // Register gateway. |
|
144 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
145 | - |
|
146 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
147 | - |
|
148 | - // Add support for various features. |
|
149 | - foreach ( $this->supports as $feature ) { |
|
150 | - add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' ); |
|
151 | - add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' ); |
|
152 | - add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
153 | - } |
|
154 | - |
|
155 | - // Invoice addons. |
|
156 | - if ( $this->supports( 'addons' ) ) { |
|
157 | - add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
158 | - } |
|
159 | - |
|
160 | - // Gateway settings. |
|
161 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
162 | - |
|
163 | - // Gateway checkout fiellds. |
|
164 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
165 | - |
|
166 | - // Process payment. |
|
167 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
168 | - |
|
169 | - // Change the checkout button text. |
|
170 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
171 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
172 | - } |
|
173 | - |
|
174 | - // Check if a gateway is valid for a given currency. |
|
175 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
176 | - |
|
177 | - // Generate the transaction url. |
|
178 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
179 | - |
|
180 | - // Generate the subscription url. |
|
181 | - add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
182 | - |
|
183 | - // Confirm payments. |
|
184 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
185 | - |
|
186 | - // Verify IPNs. |
|
187 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
188 | - |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Checks if this gateway is a given gateway. |
|
193 | - * |
|
194 | - * @since 1.0.19 |
|
195 | - * @return bool |
|
196 | - */ |
|
197 | - public function is( $gateway ) { |
|
198 | - return $gateway == $this->id; |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * Returns a users saved tokens for this gateway. |
|
203 | - * |
|
204 | - * @since 1.0.19 |
|
205 | - * @return array |
|
206 | - */ |
|
207 | - public function get_tokens( $sandbox = null ) { |
|
208 | - |
|
209 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
210 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
211 | - |
|
212 | - if ( is_array( $tokens ) ) { |
|
213 | - $this->tokens = $tokens; |
|
214 | - } |
|
16 | + /** |
|
17 | + * Set if the place checkout button should be renamed on selection. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $checkout_button_text; |
|
22 | + |
|
23 | + /** |
|
24 | + * Boolean whether the method is enabled. |
|
25 | + * |
|
26 | + * @var bool |
|
27 | + */ |
|
28 | + public $enabled = true; |
|
29 | + |
|
30 | + /** |
|
31 | + * Payment method id. |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + public $id; |
|
36 | + |
|
37 | + /** |
|
38 | + * Payment method order. |
|
39 | + * |
|
40 | + * @var int |
|
41 | + */ |
|
42 | + public $order = 10; |
|
43 | + |
|
44 | + /** |
|
45 | + * Payment method title for the frontend. |
|
46 | + * |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + public $title; |
|
50 | + |
|
51 | + /** |
|
52 | + * Payment method description for the frontend. |
|
53 | + * |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + public $description; |
|
57 | + |
|
58 | + /** |
|
59 | + * Gateway title. |
|
60 | + * |
|
61 | + * @var string |
|
62 | + */ |
|
63 | + public $method_title = ''; |
|
64 | + |
|
65 | + /** |
|
66 | + * Gateway description. |
|
67 | + * |
|
68 | + * @var string |
|
69 | + */ |
|
70 | + public $method_description = ''; |
|
71 | + |
|
72 | + /** |
|
73 | + * Countries this gateway is allowed for. |
|
74 | + * |
|
75 | + * @var array |
|
76 | + */ |
|
77 | + public $countries; |
|
78 | + |
|
79 | + /** |
|
80 | + * Currencies this gateway is allowed for. |
|
81 | + * |
|
82 | + * @var array |
|
83 | + */ |
|
84 | + public $currencies; |
|
85 | + |
|
86 | + /** |
|
87 | + * Currencies this gateway is not allowed for. |
|
88 | + * |
|
89 | + * @var array |
|
90 | + */ |
|
91 | + public $exclude_currencies; |
|
92 | + |
|
93 | + /** |
|
94 | + * Maximum transaction amount, zero does not define a maximum. |
|
95 | + * |
|
96 | + * @var int |
|
97 | + */ |
|
98 | + public $max_amount = 0; |
|
99 | + |
|
100 | + /** |
|
101 | + * Optional URL to view a transaction. |
|
102 | + * |
|
103 | + * @var string |
|
104 | + */ |
|
105 | + public $view_transaction_url = ''; |
|
106 | + |
|
107 | + /** |
|
108 | + * Optional URL to view a subscription. |
|
109 | + * |
|
110 | + * @var string |
|
111 | + */ |
|
112 | + public $view_subscription_url = ''; |
|
113 | + |
|
114 | + /** |
|
115 | + * Optional label to show for "new payment method" in the payment |
|
116 | + * method/token selection radio selection. |
|
117 | + * |
|
118 | + * @var string |
|
119 | + */ |
|
120 | + public $new_method_label = ''; |
|
121 | + |
|
122 | + /** |
|
123 | + * Contains a user's saved tokens for this gateway. |
|
124 | + * |
|
125 | + * @var array |
|
126 | + */ |
|
127 | + protected $tokens = array(); |
|
128 | + |
|
129 | + /** |
|
130 | + * An array of features that this gateway supports. |
|
131 | + * |
|
132 | + * @var array |
|
133 | + */ |
|
134 | + protected $supports = array(); |
|
135 | + |
|
136 | + /** |
|
137 | + * Class constructor. |
|
138 | + */ |
|
139 | + public function __construct() { |
|
140 | + |
|
141 | + do_action( 'getpaid_before_init_payment_gateway_' . $this->id, $this ); |
|
142 | + |
|
143 | + // Register gateway. |
|
144 | + add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
145 | + |
|
146 | + $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
147 | + |
|
148 | + // Add support for various features. |
|
149 | + foreach ( $this->supports as $feature ) { |
|
150 | + add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' ); |
|
151 | + add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' ); |
|
152 | + add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
153 | + } |
|
154 | + |
|
155 | + // Invoice addons. |
|
156 | + if ( $this->supports( 'addons' ) ) { |
|
157 | + add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
158 | + } |
|
159 | + |
|
160 | + // Gateway settings. |
|
161 | + add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
162 | + |
|
163 | + // Gateway checkout fiellds. |
|
164 | + add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
165 | + |
|
166 | + // Process payment. |
|
167 | + add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
168 | + |
|
169 | + // Change the checkout button text. |
|
170 | + if ( ! empty( $this->checkout_button_text ) ) { |
|
171 | + add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
172 | + } |
|
173 | + |
|
174 | + // Check if a gateway is valid for a given currency. |
|
175 | + add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
176 | + |
|
177 | + // Generate the transaction url. |
|
178 | + add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
179 | + |
|
180 | + // Generate the subscription url. |
|
181 | + add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
182 | + |
|
183 | + // Confirm payments. |
|
184 | + add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
185 | + |
|
186 | + // Verify IPNs. |
|
187 | + add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
188 | + |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Checks if this gateway is a given gateway. |
|
193 | + * |
|
194 | + * @since 1.0.19 |
|
195 | + * @return bool |
|
196 | + */ |
|
197 | + public function is( $gateway ) { |
|
198 | + return $gateway == $this->id; |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * Returns a users saved tokens for this gateway. |
|
203 | + * |
|
204 | + * @since 1.0.19 |
|
205 | + * @return array |
|
206 | + */ |
|
207 | + public function get_tokens( $sandbox = null ) { |
|
208 | + |
|
209 | + if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
210 | + $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
211 | + |
|
212 | + if ( is_array( $tokens ) ) { |
|
213 | + $this->tokens = $tokens; |
|
214 | + } |
|
215 | 215 | } |
216 | 216 | |
217 | - if ( ! is_bool( $sandbox ) ) { |
|
218 | - return $this->tokens; |
|
219 | - } |
|
220 | - |
|
221 | - // Filter tokens. |
|
222 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
223 | - return wp_list_filter( $this->tokens, $args ); |
|
224 | - |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * Saves a token for this gateway. |
|
229 | - * |
|
230 | - * @since 1.0.19 |
|
231 | - */ |
|
232 | - public function save_token( $token ) { |
|
233 | - |
|
234 | - $tokens = $this->get_tokens(); |
|
235 | - $tokens[] = $token; |
|
236 | - |
|
237 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
238 | - |
|
239 | - $this->tokens = $tokens; |
|
240 | - |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * Return the title for admin screens. |
|
245 | - * |
|
246 | - * @return string |
|
247 | - */ |
|
248 | - public function get_method_title() { |
|
249 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * Return the description for admin screens. |
|
254 | - * |
|
255 | - * @return string |
|
256 | - */ |
|
257 | - public function get_method_description() { |
|
258 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
259 | - } |
|
260 | - |
|
261 | - /** |
|
262 | - * Get the success url. |
|
263 | - * |
|
264 | - * @param WPInv_Invoice $invoice Invoice object. |
|
265 | - * @return string |
|
266 | - */ |
|
267 | - public function get_return_url( $invoice ) { |
|
268 | - |
|
269 | - // Payment success url |
|
270 | - $return_url = add_query_arg( |
|
271 | - array( |
|
272 | - 'payment-confirm' => $this->id, |
|
273 | - 'invoice_key' => $invoice->get_key(), |
|
274 | - 'utm_nooverride' => 1, |
|
275 | - ), |
|
276 | - wpinv_get_success_page_uri() |
|
277 | - ); |
|
278 | - |
|
279 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * Confirms payments when rendering the success page. |
|
284 | - * |
|
285 | - * @param string $content Success page content. |
|
286 | - * @return string |
|
287 | - */ |
|
288 | - public function confirm_payment( $content ) { |
|
289 | - |
|
290 | - // Retrieve the invoice. |
|
291 | - $invoice_id = getpaid_get_current_invoice_id(); |
|
292 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
293 | - |
|
294 | - // Ensure that it exists and that it is pending payment. |
|
295 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
296 | - return $content; |
|
297 | - } |
|
298 | - |
|
299 | - // Can the user view this invoice?? |
|
300 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
301 | - return $content; |
|
302 | - } |
|
303 | - |
|
304 | - // Show payment processing indicator. |
|
305 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Processes ipns and marks payments as complete. |
|
310 | - * |
|
311 | - * @return void |
|
312 | - */ |
|
313 | - public function verify_ipn() {} |
|
314 | - |
|
315 | - /** |
|
316 | - * Processes invoice addons. |
|
317 | - * |
|
318 | - * @param WPInv_Invoice $invoice |
|
319 | - * @param GetPaid_Form_Item[] $items |
|
320 | - * @return WPInv_Invoice |
|
321 | - */ |
|
322 | - public function process_addons( $invoice, $items ) { |
|
323 | - |
|
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
328 | - * |
|
329 | - * @param string $transaction_url transaction url. |
|
330 | - * @param WPInv_Invoice $invoice Invoice object. |
|
331 | - * @return string transaction URL, or empty string. |
|
332 | - */ |
|
333 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
334 | - |
|
335 | - $transaction_id = $invoice->get_transaction_id(); |
|
336 | - |
|
337 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
338 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
339 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
340 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
341 | - } |
|
342 | - |
|
343 | - return $transaction_url; |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
348 | - * |
|
349 | - * @param string $subscription_url transaction url. |
|
350 | - * @param WPInv_Subscription $subscription Subscription objectt. |
|
351 | - * @return string subscription URL, or empty string. |
|
352 | - */ |
|
353 | - public function generate_subscription_url( $subscription_url, $subscription ) { |
|
354 | - |
|
355 | - $profile_id = $subscription->get_profile_id(); |
|
356 | - |
|
357 | - if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
358 | - |
|
359 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
360 | - $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
361 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
362 | - |
|
363 | - } |
|
364 | - |
|
365 | - return $subscription_url; |
|
366 | - } |
|
367 | - |
|
368 | - /** |
|
369 | - * Check if the gateway is available for use. |
|
370 | - * |
|
371 | - * @return bool |
|
372 | - */ |
|
373 | - public function is_available() { |
|
374 | - return ! empty( $this->enabled ); |
|
375 | - } |
|
376 | - |
|
377 | - /** |
|
378 | - * Return the gateway's title. |
|
379 | - * |
|
380 | - * @return string |
|
381 | - */ |
|
382 | - public function get_title() { |
|
383 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * Return the gateway's description. |
|
388 | - * |
|
389 | - * @return string |
|
390 | - */ |
|
391 | - public function get_description() { |
|
392 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Process Payment. |
|
397 | - * |
|
398 | - * |
|
399 | - * @param WPInv_Invoice $invoice Invoice. |
|
400 | - * @param array $submission_data Posted checkout fields. |
|
401 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
402 | - * @return void |
|
403 | - */ |
|
404 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
405 | - // Process the payment then either redirect to the success page or the gateway. |
|
406 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * Process refund. |
|
411 | - * |
|
412 | - * If the gateway declares 'refunds' support, this will allow it to refund. |
|
413 | - * a passed in amount. |
|
414 | - * |
|
415 | - * @param WPInv_Invoice $invoice Invoice. |
|
416 | - * @param float $amount Refund amount. |
|
417 | - * @param string $reason Refund reason. |
|
418 | - * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
419 | - */ |
|
420 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
421 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
422 | - } |
|
423 | - |
|
424 | - /** |
|
425 | - * Displays the payment fields, credit cards etc. |
|
426 | - * |
|
427 | - * @param int $invoice_id 0 or invoice id. |
|
428 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
429 | - */ |
|
430 | - public function payment_fields( $invoice_id, $form ) { |
|
431 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * Filters the gateway settings. |
|
436 | - * |
|
437 | - * @param array $admin_settings |
|
438 | - */ |
|
439 | - public function admin_settings( $admin_settings ) { |
|
440 | - return $admin_settings; |
|
441 | - } |
|
442 | - |
|
443 | - /** |
|
444 | - * Retrieves the value of a gateway setting. |
|
445 | - * |
|
446 | - * @param string $option |
|
447 | - */ |
|
448 | - public function get_option( $option, $default = false ) { |
|
449 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
450 | - } |
|
451 | - |
|
452 | - /** |
|
453 | - * Check if a gateway supports a given feature. |
|
454 | - * |
|
455 | - * Gateways should override this to declare support (or lack of support) for a feature. |
|
456 | - * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
457 | - * |
|
458 | - * @param string $feature string The name of a feature to test support for. |
|
459 | - * @return bool True if the gateway supports the feature, false otherwise. |
|
460 | - * @since 1.0.19 |
|
461 | - */ |
|
462 | - public function supports( $feature ) { |
|
463 | - return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
464 | - } |
|
465 | - |
|
466 | - /** |
|
467 | - * Returns the credit card form html. |
|
468 | - * |
|
469 | - * @param bool $save whether or not to display the save button. |
|
470 | - */ |
|
217 | + if ( ! is_bool( $sandbox ) ) { |
|
218 | + return $this->tokens; |
|
219 | + } |
|
220 | + |
|
221 | + // Filter tokens. |
|
222 | + $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
223 | + return wp_list_filter( $this->tokens, $args ); |
|
224 | + |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * Saves a token for this gateway. |
|
229 | + * |
|
230 | + * @since 1.0.19 |
|
231 | + */ |
|
232 | + public function save_token( $token ) { |
|
233 | + |
|
234 | + $tokens = $this->get_tokens(); |
|
235 | + $tokens[] = $token; |
|
236 | + |
|
237 | + update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
238 | + |
|
239 | + $this->tokens = $tokens; |
|
240 | + |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Return the title for admin screens. |
|
245 | + * |
|
246 | + * @return string |
|
247 | + */ |
|
248 | + public function get_method_title() { |
|
249 | + return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * Return the description for admin screens. |
|
254 | + * |
|
255 | + * @return string |
|
256 | + */ |
|
257 | + public function get_method_description() { |
|
258 | + return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * Get the success url. |
|
263 | + * |
|
264 | + * @param WPInv_Invoice $invoice Invoice object. |
|
265 | + * @return string |
|
266 | + */ |
|
267 | + public function get_return_url( $invoice ) { |
|
268 | + |
|
269 | + // Payment success url |
|
270 | + $return_url = add_query_arg( |
|
271 | + array( |
|
272 | + 'payment-confirm' => $this->id, |
|
273 | + 'invoice_key' => $invoice->get_key(), |
|
274 | + 'utm_nooverride' => 1, |
|
275 | + ), |
|
276 | + wpinv_get_success_page_uri() |
|
277 | + ); |
|
278 | + |
|
279 | + return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * Confirms payments when rendering the success page. |
|
284 | + * |
|
285 | + * @param string $content Success page content. |
|
286 | + * @return string |
|
287 | + */ |
|
288 | + public function confirm_payment( $content ) { |
|
289 | + |
|
290 | + // Retrieve the invoice. |
|
291 | + $invoice_id = getpaid_get_current_invoice_id(); |
|
292 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
293 | + |
|
294 | + // Ensure that it exists and that it is pending payment. |
|
295 | + if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
296 | + return $content; |
|
297 | + } |
|
298 | + |
|
299 | + // Can the user view this invoice?? |
|
300 | + if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
301 | + return $content; |
|
302 | + } |
|
303 | + |
|
304 | + // Show payment processing indicator. |
|
305 | + return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Processes ipns and marks payments as complete. |
|
310 | + * |
|
311 | + * @return void |
|
312 | + */ |
|
313 | + public function verify_ipn() {} |
|
314 | + |
|
315 | + /** |
|
316 | + * Processes invoice addons. |
|
317 | + * |
|
318 | + * @param WPInv_Invoice $invoice |
|
319 | + * @param GetPaid_Form_Item[] $items |
|
320 | + * @return WPInv_Invoice |
|
321 | + */ |
|
322 | + public function process_addons( $invoice, $items ) { |
|
323 | + |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
328 | + * |
|
329 | + * @param string $transaction_url transaction url. |
|
330 | + * @param WPInv_Invoice $invoice Invoice object. |
|
331 | + * @return string transaction URL, or empty string. |
|
332 | + */ |
|
333 | + public function filter_transaction_url( $transaction_url, $invoice ) { |
|
334 | + |
|
335 | + $transaction_id = $invoice->get_transaction_id(); |
|
336 | + |
|
337 | + if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
338 | + $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
339 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
340 | + $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
341 | + } |
|
342 | + |
|
343 | + return $transaction_url; |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
348 | + * |
|
349 | + * @param string $subscription_url transaction url. |
|
350 | + * @param WPInv_Subscription $subscription Subscription objectt. |
|
351 | + * @return string subscription URL, or empty string. |
|
352 | + */ |
|
353 | + public function generate_subscription_url( $subscription_url, $subscription ) { |
|
354 | + |
|
355 | + $profile_id = $subscription->get_profile_id(); |
|
356 | + |
|
357 | + if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
358 | + |
|
359 | + $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
360 | + $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
361 | + $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
362 | + |
|
363 | + } |
|
364 | + |
|
365 | + return $subscription_url; |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * Check if the gateway is available for use. |
|
370 | + * |
|
371 | + * @return bool |
|
372 | + */ |
|
373 | + public function is_available() { |
|
374 | + return ! empty( $this->enabled ); |
|
375 | + } |
|
376 | + |
|
377 | + /** |
|
378 | + * Return the gateway's title. |
|
379 | + * |
|
380 | + * @return string |
|
381 | + */ |
|
382 | + public function get_title() { |
|
383 | + return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * Return the gateway's description. |
|
388 | + * |
|
389 | + * @return string |
|
390 | + */ |
|
391 | + public function get_description() { |
|
392 | + return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Process Payment. |
|
397 | + * |
|
398 | + * |
|
399 | + * @param WPInv_Invoice $invoice Invoice. |
|
400 | + * @param array $submission_data Posted checkout fields. |
|
401 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
402 | + * @return void |
|
403 | + */ |
|
404 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
405 | + // Process the payment then either redirect to the success page or the gateway. |
|
406 | + do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | + * Process refund. |
|
411 | + * |
|
412 | + * If the gateway declares 'refunds' support, this will allow it to refund. |
|
413 | + * a passed in amount. |
|
414 | + * |
|
415 | + * @param WPInv_Invoice $invoice Invoice. |
|
416 | + * @param float $amount Refund amount. |
|
417 | + * @param string $reason Refund reason. |
|
418 | + * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
419 | + */ |
|
420 | + public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
421 | + return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
422 | + } |
|
423 | + |
|
424 | + /** |
|
425 | + * Displays the payment fields, credit cards etc. |
|
426 | + * |
|
427 | + * @param int $invoice_id 0 or invoice id. |
|
428 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
429 | + */ |
|
430 | + public function payment_fields( $invoice_id, $form ) { |
|
431 | + do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * Filters the gateway settings. |
|
436 | + * |
|
437 | + * @param array $admin_settings |
|
438 | + */ |
|
439 | + public function admin_settings( $admin_settings ) { |
|
440 | + return $admin_settings; |
|
441 | + } |
|
442 | + |
|
443 | + /** |
|
444 | + * Retrieves the value of a gateway setting. |
|
445 | + * |
|
446 | + * @param string $option |
|
447 | + */ |
|
448 | + public function get_option( $option, $default = false ) { |
|
449 | + return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
450 | + } |
|
451 | + |
|
452 | + /** |
|
453 | + * Check if a gateway supports a given feature. |
|
454 | + * |
|
455 | + * Gateways should override this to declare support (or lack of support) for a feature. |
|
456 | + * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
457 | + * |
|
458 | + * @param string $feature string The name of a feature to test support for. |
|
459 | + * @return bool True if the gateway supports the feature, false otherwise. |
|
460 | + * @since 1.0.19 |
|
461 | + */ |
|
462 | + public function supports( $feature ) { |
|
463 | + return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
464 | + } |
|
465 | + |
|
466 | + /** |
|
467 | + * Returns the credit card form html. |
|
468 | + * |
|
469 | + * @param bool $save whether or not to display the save button. |
|
470 | + */ |
|
471 | 471 | public function get_cc_form( $save = false ) { |
472 | 472 | |
473 | - ob_start(); |
|
473 | + ob_start(); |
|
474 | 474 | |
475 | 475 | $id_prefix = esc_attr( uniqid( $this->id ) ); |
476 | 476 | |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | '11' => __( 'November', 'invoicing' ), |
489 | 489 | '12' => __( 'December', 'invoicing' ), |
490 | 490 | ); |
491 | - $months = apply_filters( 'getpaid_cc_months', $months, $this ); |
|
491 | + $months = apply_filters( 'getpaid_cc_months', $months, $this ); |
|
492 | 492 | |
493 | 493 | $year = (int) current_time( 'Y' ); |
494 | 494 | $years = array(); |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | $years[ $year + $i ] = $year + $i; |
498 | 498 | } |
499 | 499 | |
500 | - $years = apply_filters( 'getpaid_cc_years', $years, $this ); |
|
500 | + $years = apply_filters( 'getpaid_cc_years', $years, $this ); |
|
501 | 501 | |
502 | 502 | ?> |
503 | 503 | <div class="<?php echo esc_attr( $this->id ); ?>-cc-form getpaid-cc-form mt-1"> |
@@ -539,7 +539,7 @@ discard block |
||
539 | 539 | |
540 | 540 | <?php |
541 | 541 | foreach ( $months as $key => $month ) { |
542 | - echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $month ) . '</option>'; |
|
542 | + echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $month ) . '</option>'; |
|
543 | 543 | } |
544 | 544 | ?> |
545 | 545 | |
@@ -552,7 +552,7 @@ discard block |
||
552 | 552 | |
553 | 553 | <?php |
554 | 554 | foreach ( $years as $key => $year ) { |
555 | - echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $year ) . '</option>'; |
|
555 | + echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $year ) . '</option>'; |
|
556 | 556 | } |
557 | 557 | ?> |
558 | 558 | |
@@ -570,13 +570,13 @@ discard block |
||
570 | 570 | 'name' => $this->id . '[cc_cvv2]', |
571 | 571 | 'id' => "$id_prefix-cc-cvv2", |
572 | 572 | 'label' => __( 'CCV', 'invoicing' ), |
573 | - 'label_type' => 'vertical', |
|
574 | - 'class' => 'form-control-sm', |
|
575 | - 'extra_attributes' => array( |
|
576 | - 'autocomplete' => 'cc-csc', |
|
577 | - ), |
|
573 | + 'label_type' => 'vertical', |
|
574 | + 'class' => 'form-control-sm', |
|
575 | + 'extra_attributes' => array( |
|
576 | + 'autocomplete' => 'cc-csc', |
|
577 | + ), |
|
578 | 578 | ), |
579 | - true |
|
579 | + true |
|
580 | 580 | ); |
581 | 581 | ?> |
582 | 582 | </div> |
@@ -585,192 +585,192 @@ discard block |
||
585 | 585 | |
586 | 586 | <?php |
587 | 587 | |
588 | - if ( $save ) { |
|
589 | - $this->save_payment_method_checkbox(); |
|
590 | - } |
|
588 | + if ( $save ) { |
|
589 | + $this->save_payment_method_checkbox(); |
|
590 | + } |
|
591 | 591 | |
592 | - ?> |
|
592 | + ?> |
|
593 | 593 | </div> |
594 | 594 | |
595 | 595 | </div> |
596 | 596 | <?php |
597 | 597 | |
598 | - return ob_get_clean(); |
|
598 | + return ob_get_clean(); |
|
599 | + |
|
600 | + } |
|
601 | + |
|
602 | + /** |
|
603 | + * Displays a new payment method entry form. |
|
604 | + * |
|
605 | + * @since 1.0.19 |
|
606 | + */ |
|
607 | + public function new_payment_method_entry( $form ) { |
|
608 | + echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses( $form, getpaid_allowed_html() ) . '</div>'; |
|
609 | + } |
|
610 | + |
|
611 | + /** |
|
612 | + * Grab and display our saved payment methods. |
|
613 | + * |
|
614 | + * @since 1.0.19 |
|
615 | + */ |
|
616 | + public function saved_payment_methods() { |
|
617 | + echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
618 | + |
|
619 | + foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
620 | + $this->get_saved_payment_method_option_html( $token ); |
|
621 | + } |
|
622 | + |
|
623 | + $this->get_new_payment_method_option_html(); |
|
624 | + echo '</ul>'; |
|
599 | 625 | |
600 | 626 | } |
601 | 627 | |
602 | - /** |
|
603 | - * Displays a new payment method entry form. |
|
604 | - * |
|
605 | - * @since 1.0.19 |
|
606 | - */ |
|
607 | - public function new_payment_method_entry( $form ) { |
|
608 | - echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses( $form, getpaid_allowed_html() ) . '</div>'; |
|
609 | - } |
|
610 | - |
|
611 | - /** |
|
612 | - * Grab and display our saved payment methods. |
|
613 | - * |
|
614 | - * @since 1.0.19 |
|
615 | - */ |
|
616 | - public function saved_payment_methods() { |
|
617 | - echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
618 | - |
|
619 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
620 | - $this->get_saved_payment_method_option_html( $token ); |
|
621 | - } |
|
622 | - |
|
623 | - $this->get_new_payment_method_option_html(); |
|
624 | - echo '</ul>'; |
|
625 | - |
|
626 | - } |
|
627 | - |
|
628 | - /** |
|
629 | - * Gets saved payment method HTML from a token. |
|
630 | - * |
|
631 | - * @since 1.0.19 |
|
632 | - * @param array $token Payment Token. |
|
633 | - * @return string Generated payment method HTML |
|
634 | - */ |
|
635 | - public function get_saved_payment_method_option_html( $token ) { |
|
636 | - |
|
637 | - printf( |
|
638 | - '<li class="getpaid-payment-method form-group mb-3"> |
|
628 | + /** |
|
629 | + * Gets saved payment method HTML from a token. |
|
630 | + * |
|
631 | + * @since 1.0.19 |
|
632 | + * @param array $token Payment Token. |
|
633 | + * @return string Generated payment method HTML |
|
634 | + */ |
|
635 | + public function get_saved_payment_method_option_html( $token ) { |
|
636 | + |
|
637 | + printf( |
|
638 | + '<li class="getpaid-payment-method form-group mb-3"> |
|
639 | 639 | <label> |
640 | 640 | <input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" data-currency="%5$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s /> |
641 | 641 | <span>%3$s</span> |
642 | 642 | </label> |
643 | 643 | </li>', |
644 | - esc_attr( $this->id ), |
|
645 | - esc_attr( $token['id'] ), |
|
646 | - esc_html( $token['name'] ), |
|
647 | - checked( empty( $token['default'] ), false, false ), |
|
648 | - empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] ) |
|
649 | - ); |
|
650 | - |
|
651 | - } |
|
652 | - |
|
653 | - /** |
|
654 | - * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
655 | - * |
|
656 | - * @since 1.0.19 |
|
657 | - */ |
|
658 | - public function get_new_payment_method_option_html() { |
|
659 | - |
|
660 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
661 | - |
|
662 | - printf( |
|
663 | - '<li class="getpaid-new-payment-method"> |
|
644 | + esc_attr( $this->id ), |
|
645 | + esc_attr( $token['id'] ), |
|
646 | + esc_html( $token['name'] ), |
|
647 | + checked( empty( $token['default'] ), false, false ), |
|
648 | + empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] ) |
|
649 | + ); |
|
650 | + |
|
651 | + } |
|
652 | + |
|
653 | + /** |
|
654 | + * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
655 | + * |
|
656 | + * @since 1.0.19 |
|
657 | + */ |
|
658 | + public function get_new_payment_method_option_html() { |
|
659 | + |
|
660 | + $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
661 | + |
|
662 | + printf( |
|
663 | + '<li class="getpaid-new-payment-method"> |
|
664 | 664 | <label> |
665 | 665 | <input name="getpaid-%1$s-payment-method" type="radio" data-currency="none" value="new" style="width:auto;" /> |
666 | 666 | <span>%2$s</span> |
667 | 667 | </label> |
668 | 668 | </li>', |
669 | - esc_attr( $this->id ), |
|
670 | - esc_html( $label ) |
|
671 | - ); |
|
672 | - |
|
673 | - } |
|
674 | - |
|
675 | - /** |
|
676 | - * Outputs a checkbox for saving a new payment method to the database. |
|
677 | - * |
|
678 | - * @since 1.0.19 |
|
679 | - */ |
|
680 | - public function save_payment_method_checkbox() { |
|
681 | - |
|
682 | - aui()->input( |
|
683 | - array( |
|
684 | - 'type' => 'checkbox', |
|
685 | - 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
686 | - 'id' => esc_attr( uniqid( $this->id ) ), |
|
687 | - 'required' => false, |
|
688 | - 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
689 | - 'value' => 'true', |
|
690 | - 'checked' => true, |
|
691 | - 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
692 | - ), |
|
693 | - true |
|
694 | - ); |
|
695 | - |
|
696 | - } |
|
697 | - |
|
698 | - /** |
|
699 | - * Registers the gateway. |
|
700 | - * |
|
701 | - * @return array |
|
702 | - */ |
|
703 | - public function register_gateway( $gateways ) { |
|
704 | - |
|
705 | - $gateways[ $this->id ] = array( |
|
706 | - |
|
707 | - 'admin_label' => $this->method_title, |
|
669 | + esc_attr( $this->id ), |
|
670 | + esc_html( $label ) |
|
671 | + ); |
|
672 | + |
|
673 | + } |
|
674 | + |
|
675 | + /** |
|
676 | + * Outputs a checkbox for saving a new payment method to the database. |
|
677 | + * |
|
678 | + * @since 1.0.19 |
|
679 | + */ |
|
680 | + public function save_payment_method_checkbox() { |
|
681 | + |
|
682 | + aui()->input( |
|
683 | + array( |
|
684 | + 'type' => 'checkbox', |
|
685 | + 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
686 | + 'id' => esc_attr( uniqid( $this->id ) ), |
|
687 | + 'required' => false, |
|
688 | + 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
689 | + 'value' => 'true', |
|
690 | + 'checked' => true, |
|
691 | + 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
692 | + ), |
|
693 | + true |
|
694 | + ); |
|
695 | + |
|
696 | + } |
|
697 | + |
|
698 | + /** |
|
699 | + * Registers the gateway. |
|
700 | + * |
|
701 | + * @return array |
|
702 | + */ |
|
703 | + public function register_gateway( $gateways ) { |
|
704 | + |
|
705 | + $gateways[ $this->id ] = array( |
|
706 | + |
|
707 | + 'admin_label' => $this->method_title, |
|
708 | 708 | 'checkout_label' => $this->title, |
709 | - 'ordering' => $this->order, |
|
709 | + 'ordering' => $this->order, |
|
710 | 710 | |
711 | - ); |
|
711 | + ); |
|
712 | 712 | |
713 | - return $gateways; |
|
713 | + return $gateways; |
|
714 | 714 | |
715 | - } |
|
715 | + } |
|
716 | 716 | |
717 | - /** |
|
718 | - * Checks whether or not this is a sandbox request. |
|
719 | - * |
|
720 | - * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
721 | - * @return bool |
|
722 | - */ |
|
723 | - public function is_sandbox( $invoice = null ) { |
|
717 | + /** |
|
718 | + * Checks whether or not this is a sandbox request. |
|
719 | + * |
|
720 | + * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
721 | + * @return bool |
|
722 | + */ |
|
723 | + public function is_sandbox( $invoice = null ) { |
|
724 | 724 | |
725 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
726 | - return $invoice->get_mode() == 'test'; |
|
727 | - } |
|
725 | + if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
726 | + return $invoice->get_mode() == 'test'; |
|
727 | + } |
|
728 | 728 | |
729 | - return wpinv_is_test_mode( $this->id ); |
|
729 | + return wpinv_is_test_mode( $this->id ); |
|
730 | 730 | |
731 | - } |
|
731 | + } |
|
732 | 732 | |
733 | - /** |
|
734 | - * Renames the checkout button |
|
735 | - * |
|
736 | - * @return string |
|
737 | - */ |
|
738 | - public function rename_checkout_button() { |
|
739 | - return $this->checkout_button_text; |
|
740 | - } |
|
733 | + /** |
|
734 | + * Renames the checkout button |
|
735 | + * |
|
736 | + * @return string |
|
737 | + */ |
|
738 | + public function rename_checkout_button() { |
|
739 | + return $this->checkout_button_text; |
|
740 | + } |
|
741 | 741 | |
742 | - /** |
|
743 | - * Validate gateway currency |
|
744 | - * |
|
745 | - * @return bool |
|
746 | - */ |
|
747 | - public function validate_currency( $validation, $currency ) { |
|
742 | + /** |
|
743 | + * Validate gateway currency |
|
744 | + * |
|
745 | + * @return bool |
|
746 | + */ |
|
747 | + public function validate_currency( $validation, $currency ) { |
|
748 | 748 | |
749 | - // Required currencies. |
|
750 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
751 | - return false; |
|
752 | - } |
|
749 | + // Required currencies. |
|
750 | + if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
751 | + return false; |
|
752 | + } |
|
753 | 753 | |
754 | - // Excluded currencies. |
|
755 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
756 | - return false; |
|
757 | - } |
|
754 | + // Excluded currencies. |
|
755 | + if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
756 | + return false; |
|
757 | + } |
|
758 | 758 | |
759 | - return $validation; |
|
760 | - } |
|
759 | + return $validation; |
|
760 | + } |
|
761 | 761 | |
762 | - /** |
|
763 | - * Displays an error |
|
764 | - * |
|
765 | - */ |
|
766 | - public function show_error( $code, $message, $type ) { |
|
762 | + /** |
|
763 | + * Displays an error |
|
764 | + * |
|
765 | + */ |
|
766 | + public function show_error( $code, $message, $type ) { |
|
767 | 767 | |
768 | - if ( is_admin() ) { |
|
769 | - getpaid_admin()->{"show_$type"}( $message ); |
|
770 | - } |
|
768 | + if ( is_admin() ) { |
|
769 | + getpaid_admin()->{"show_$type"}( $message ); |
|
770 | + } |
|
771 | 771 | |
772 | - wpinv_set_error( $code, $message, $type ); |
|
772 | + wpinv_set_error( $code, $message, $type ); |
|
773 | 773 | |
774 | - } |
|
774 | + } |
|
775 | 775 | |
776 | 776 | } |
@@ -136,13 +136,13 @@ discard block |
||
136 | 136 | */ |
137 | 137 | function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) { |
138 | 138 | |
139 | - $invoice_statuses = array( |
|
140 | - 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
139 | + $invoice_statuses = array( |
|
140 | + 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
141 | 141 | 'publish' => _x( 'Paid', 'Invoice status', 'invoicing' ), |
142 | 142 | 'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
143 | - 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
144 | - 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
145 | - 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
143 | + 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
144 | + 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
145 | + 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
146 | 146 | 'wpi-failed' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
147 | 147 | 'wpi-renewal' => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ), |
148 | 148 | ); |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | $invoice = $invoice->get_post_type(); |
160 | 160 | } |
161 | 161 | |
162 | - return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
162 | + return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -277,25 +277,25 @@ discard block |
||
277 | 277 | * @return string |
278 | 278 | */ |
279 | 279 | function getpaid_get_price_format() { |
280 | - $currency_pos = wpinv_currency_position(); |
|
281 | - $format = '%1$s%2$s'; |
|
282 | - |
|
283 | - switch ( $currency_pos ) { |
|
284 | - case 'left': |
|
285 | - $format = '%1$s%2$s'; |
|
286 | - break; |
|
287 | - case 'right': |
|
288 | - $format = '%2$s%1$s'; |
|
289 | - break; |
|
290 | - case 'left_space': |
|
291 | - $format = '%1$s %2$s'; |
|
292 | - break; |
|
293 | - case 'right_space': |
|
294 | - $format = '%2$s %1$s'; |
|
295 | - break; |
|
296 | - } |
|
297 | - |
|
298 | - return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
280 | + $currency_pos = wpinv_currency_position(); |
|
281 | + $format = '%1$s%2$s'; |
|
282 | + |
|
283 | + switch ( $currency_pos ) { |
|
284 | + case 'left': |
|
285 | + $format = '%1$s%2$s'; |
|
286 | + break; |
|
287 | + case 'right': |
|
288 | + $format = '%2$s%1$s'; |
|
289 | + break; |
|
290 | + case 'left_space': |
|
291 | + $format = '%1$s %2$s'; |
|
292 | + break; |
|
293 | + case 'right_space': |
|
294 | + $format = '%2$s %1$s'; |
|
295 | + break; |
|
296 | + } |
|
297 | + |
|
298 | + return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | /** |
@@ -401,13 +401,13 @@ discard block |
||
401 | 401 | * @param mixed $value Value. |
402 | 402 | */ |
403 | 403 | function getpaid_maybe_define_constant( $name, $value ) { |
404 | - if ( ! defined( $name ) ) { |
|
405 | - define( $name, $value ); |
|
406 | - } |
|
404 | + if ( ! defined( $name ) ) { |
|
405 | + define( $name, $value ); |
|
406 | + } |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | function wpinv_get_php_arg_separator_output() { |
410 | - return ini_get( 'arg_separator.output' ); |
|
410 | + return ini_get( 'arg_separator.output' ); |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | function wpinv_rgb_from_hex( $color ) { |
@@ -718,16 +718,16 @@ discard block |
||
718 | 718 | return wp_kses( |
719 | 719 | html_entity_decode( $var ), |
720 | 720 | array( |
721 | - 'br' => array(), |
|
722 | - 'em' => array(), |
|
723 | - 'strong' => array(), |
|
724 | - 'b' => array(), |
|
725 | - 'small' => array(), |
|
726 | - 'span' => array(), |
|
727 | - 'ul' => array(), |
|
728 | - 'li' => array(), |
|
729 | - 'ol' => array(), |
|
730 | - 'p' => array(), |
|
721 | + 'br' => array(), |
|
722 | + 'em' => array(), |
|
723 | + 'strong' => array(), |
|
724 | + 'b' => array(), |
|
725 | + 'small' => array(), |
|
726 | + 'span' => array(), |
|
727 | + 'ul' => array(), |
|
728 | + 'li' => array(), |
|
729 | + 'ol' => array(), |
|
730 | + 'p' => array(), |
|
731 | 731 | ) |
732 | 732 | ); |
733 | 733 | } |
@@ -778,11 +778,11 @@ discard block |
||
778 | 778 | $list = array(); |
779 | 779 | } |
780 | 780 | |
781 | - if ( ! is_array( $list ) ) { |
|
782 | - return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
783 | - } |
|
781 | + if ( ! is_array( $list ) ) { |
|
782 | + return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
783 | + } |
|
784 | 784 | |
785 | - return $list; |
|
785 | + return $list; |
|
786 | 786 | } |
787 | 787 | |
788 | 788 | /** |
@@ -823,17 +823,17 @@ discard block |
||
823 | 823 | */ |
824 | 824 | function wpinv_clean( $var ) { |
825 | 825 | |
826 | - if ( is_array( $var ) ) { |
|
827 | - return array_map( 'wpinv_clean', $var ); |
|
826 | + if ( is_array( $var ) ) { |
|
827 | + return array_map( 'wpinv_clean', $var ); |
|
828 | 828 | } |
829 | 829 | |
830 | 830 | if ( is_object( $var ) ) { |
831 | - $object_vars = get_object_vars( $var ); |
|
832 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
833 | - $var->$property_name = wpinv_clean( $property_value ); |
|
831 | + $object_vars = get_object_vars( $var ); |
|
832 | + foreach ( $object_vars as $property_name => $property_value ) { |
|
833 | + $var->$property_name = wpinv_clean( $property_value ); |
|
834 | 834 | } |
835 | 835 | return $var; |
836 | - } |
|
836 | + } |
|
837 | 837 | |
838 | 838 | return is_string( $var ) ? sanitize_text_field( stripslashes( $var ) ) : $var; |
839 | 839 | } |
@@ -846,7 +846,7 @@ discard block |
||
846 | 846 | */ |
847 | 847 | function getpaid_convert_price_string_to_options( $str ) { |
848 | 848 | |
849 | - $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
849 | + $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
850 | 850 | $options = array(); |
851 | 851 | |
852 | 852 | foreach ( $raw_options as $option ) { |
@@ -935,7 +935,7 @@ discard block |
||
935 | 935 | * @return string |
936 | 936 | */ |
937 | 937 | function getpaid_date_format() { |
938 | - return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
938 | + return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
939 | 939 | } |
940 | 940 | |
941 | 941 | /** |
@@ -944,7 +944,7 @@ discard block |
||
944 | 944 | * @return string |
945 | 945 | */ |
946 | 946 | function getpaid_time_format() { |
947 | - return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
947 | + return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
948 | 948 | } |
949 | 949 | |
950 | 950 | /** |
@@ -957,15 +957,15 @@ discard block |
||
957 | 957 | function getpaid_limit_length( $string, $limit ) { |
958 | 958 | $str_limit = $limit - 3; |
959 | 959 | |
960 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
961 | - if ( mb_strlen( $string ) > $limit ) { |
|
962 | - $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
963 | - } |
|
964 | - } else { |
|
965 | - if ( strlen( $string ) > $limit ) { |
|
966 | - $string = substr( $string, 0, $str_limit ) . '...'; |
|
967 | - } |
|
968 | - } |
|
960 | + if ( function_exists( 'mb_strimwidth' ) ) { |
|
961 | + if ( mb_strlen( $string ) > $limit ) { |
|
962 | + $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
963 | + } |
|
964 | + } else { |
|
965 | + if ( strlen( $string ) > $limit ) { |
|
966 | + $string = substr( $string, 0, $str_limit ) . '...'; |
|
967 | + } |
|
968 | + } |
|
969 | 969 | return $string; |
970 | 970 | |
971 | 971 | } |
@@ -1095,12 +1095,12 @@ discard block |
||
1095 | 1095 | $types = get_allowed_mime_types(); |
1096 | 1096 | |
1097 | 1097 | if ( isset( $types['htm|html'] ) ) { |
1098 | - unset( $types['htm|html'] ); |
|
1099 | - } |
|
1098 | + unset( $types['htm|html'] ); |
|
1099 | + } |
|
1100 | 1100 | |
1101 | 1101 | if ( isset( $types['js'] ) ) { |
1102 | - unset( $types['js'] ); |
|
1103 | - } |
|
1102 | + unset( $types['js'] ); |
|
1103 | + } |
|
1104 | 1104 | |
1105 | 1105 | return $types; |
1106 | 1106 |
@@ -12,491 +12,491 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Invoice_Notification_Emails { |
14 | 14 | |
15 | - /** |
|
16 | - * The array of invoice email actions. |
|
17 | - * |
|
18 | - * @param array |
|
19 | - */ |
|
20 | - public $invoice_actions; |
|
21 | - |
|
22 | - /** |
|
23 | - * Class constructor |
|
24 | - * |
|
25 | - */ |
|
26 | - public function __construct() { |
|
27 | - |
|
28 | - $this->invoice_actions = apply_filters( |
|
29 | - 'getpaid_notification_email_invoice_triggers', |
|
30 | - array( |
|
31 | - 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
32 | - 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
33 | - 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
34 | - 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
35 | - 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
36 | - 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
37 | - 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
38 | - 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
39 | - 'getpaid_new_customer_note' => 'user_note', |
|
40 | - 'getpaid_daily_maintenance' => 'overdue', |
|
41 | - ) |
|
42 | - ); |
|
43 | - |
|
44 | - $this->init_hooks(); |
|
45 | - |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Registers email hooks. |
|
50 | - */ |
|
51 | - public function init_hooks() { |
|
52 | - |
|
53 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
54 | - add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
55 | - |
|
56 | - foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | - $this->init_email_type_hook( $hook, $email_type ); |
|
58 | - } |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Registers an email hook for an invoice action. |
|
63 | - * |
|
64 | - * @param string $hook |
|
65 | - * @param string|array $email_type |
|
66 | - */ |
|
67 | - public function init_email_type_hook( $hook, $email_type ) { |
|
68 | - |
|
69 | - $email_type = wpinv_parse_list( $email_type ); |
|
70 | - |
|
71 | - foreach ( $email_type as $type ) { |
|
72 | - |
|
73 | - $email = new GetPaid_Notification_Email( $type ); |
|
74 | - |
|
75 | - // Abort if it is not active. |
|
76 | - if ( ! $email->is_active() ) { |
|
77 | - continue; |
|
78 | - } |
|
79 | - |
|
80 | - if ( method_exists( $this, $type ) ) { |
|
81 | - add_action( $hook, array( $this, $type ), 100, 2 ); |
|
82 | - continue; |
|
83 | - } |
|
84 | - |
|
85 | - do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
86 | - } |
|
87 | - |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Filters invoice merge tags. |
|
92 | - * |
|
93 | - * @param array $merge_tags |
|
94 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
95 | - */ |
|
96 | - public function invoice_merge_tags( $merge_tags, $object ) { |
|
97 | - |
|
98 | - if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
99 | - return array_merge( |
|
100 | - $merge_tags, |
|
101 | - $this->get_invoice_merge_tags( $object ) |
|
102 | - ); |
|
103 | - } |
|
104 | - |
|
105 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
106 | - return array_merge( |
|
107 | - $merge_tags, |
|
108 | - $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
109 | - ); |
|
110 | - } |
|
111 | - |
|
112 | - return $merge_tags; |
|
113 | - |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Generates invoice merge tags. |
|
118 | - * |
|
119 | - * @param WPInv_Invoice $invoice |
|
120 | - * @return array |
|
121 | - */ |
|
122 | - public function get_invoice_merge_tags( $invoice ) { |
|
123 | - |
|
124 | - // Abort if it does not exist. |
|
125 | - if ( ! $invoice->get_id() ) { |
|
126 | - return array(); |
|
127 | - } |
|
128 | - |
|
129 | - $merge_tags = array( |
|
130 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
131 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
133 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
134 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
135 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
136 | - '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
137 | - '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
138 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
139 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
140 | - '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ), |
|
141 | - '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
142 | - '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
143 | - '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
144 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
145 | - '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
146 | - '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
147 | - '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
148 | - ); |
|
149 | - |
|
150 | - $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
151 | - |
|
152 | - if ( is_array( $payment_form_data ) ) { |
|
153 | - |
|
154 | - foreach ( $payment_form_data as $label => $value ) { |
|
155 | - |
|
156 | - $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
157 | - $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
158 | - |
|
159 | - if ( is_scalar( $value ) ) { |
|
160 | - $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
161 | - } |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Helper function to send an email. |
|
170 | - * |
|
171 | - * @param WPInv_Invoice $invoice |
|
172 | - * @param GetPaid_Notification_Email $email |
|
173 | - * @param string $type |
|
174 | - * @param string|array $recipients |
|
175 | - * @param array $extra_args Extra template args. |
|
176 | - */ |
|
177 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
178 | - |
|
179 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
180 | - |
|
181 | - $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
182 | - if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
183 | - return; |
|
184 | - } |
|
185 | - |
|
186 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
187 | - $merge_tags = $email->get_merge_tags(); |
|
188 | - |
|
189 | - $result = $mailer->send( |
|
190 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
191 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
192 | - $email->get_content( $merge_tags, $extra_args ), |
|
193 | - $email->get_attachments() |
|
194 | - ); |
|
195 | - |
|
196 | - // Maybe send a copy to the admin. |
|
197 | - if ( $email->include_admin_bcc() ) { |
|
198 | - $mailer->send( |
|
199 | - wpinv_get_admin_email(), |
|
200 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
201 | - $email->get_content( $merge_tags ), |
|
202 | - $email->get_attachments() |
|
203 | - ); |
|
204 | - } |
|
205 | - |
|
206 | - if ( $result ) { |
|
207 | - $invoice->add_system_note( |
|
208 | - sprintf( |
|
209 | - // translators: %1 is the email type, %2 is the invoice recipient. |
|
210 | - __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
211 | - sanitize_key( $type ), |
|
212 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
213 | - ) |
|
214 | - ); |
|
215 | - } else { |
|
216 | - $invoice->add_system_note( |
|
217 | - sprintf( |
|
218 | - // translators: %1 is the email type, %2 is the invoice recipient. |
|
219 | - __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
220 | - sanitize_key( $type ), |
|
221 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
222 | - ) |
|
223 | - ); |
|
224 | - } |
|
225 | - |
|
226 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
227 | - |
|
228 | - return $result; |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * Also send emails to any cc users. |
|
233 | - * |
|
234 | - * @param array $recipients |
|
235 | - * @param GetPaid_Notification_Email $email |
|
236 | - */ |
|
237 | - public function filter_email_recipients( $recipients, $email ) { |
|
238 | - |
|
239 | - if ( ! $email->is_admin_email() ) { |
|
240 | - $cc = $email->object->get_email_cc(); |
|
241 | - $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
242 | - |
|
243 | - if ( ! empty( $cc ) ) { |
|
244 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
245 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
246 | - } |
|
247 | - |
|
248 | - if ( ! empty( $cc_2 ) ) { |
|
249 | - $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
250 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
251 | - } |
|
252 | - } |
|
253 | - |
|
254 | - return $recipients; |
|
255 | - |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Sends a new invoice notification. |
|
260 | - * |
|
261 | - * @param WPInv_Invoice $invoice |
|
262 | - */ |
|
263 | - public function new_invoice( $invoice ) { |
|
264 | - |
|
265 | - // Only send this email for invoices created via the admin page. |
|
266 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
267 | - return; |
|
268 | - } |
|
269 | - |
|
270 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
271 | - $recipient = wpinv_get_admin_email(); |
|
272 | - |
|
273 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
274 | - |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Sends a cancelled invoice notification. |
|
279 | - * |
|
280 | - * @param WPInv_Invoice $invoice |
|
281 | - */ |
|
282 | - public function cancelled_invoice( $invoice ) { |
|
283 | - |
|
284 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
285 | - $recipient = $invoice->get_email(); |
|
286 | - |
|
287 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * Sends a failed invoice notification. |
|
292 | - * |
|
293 | - * @param WPInv_Invoice $invoice |
|
294 | - */ |
|
295 | - public function failed_invoice( $invoice ) { |
|
296 | - |
|
297 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
298 | - $recipient = wpinv_get_admin_email(); |
|
299 | - |
|
300 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
301 | - |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * Sends a notification whenever an invoice is put on hold. |
|
306 | - * |
|
307 | - * @param WPInv_Invoice $invoice |
|
308 | - */ |
|
309 | - public function onhold_invoice( $invoice ) { |
|
310 | - |
|
311 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
312 | - $recipient = $invoice->get_email(); |
|
313 | - |
|
314 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
315 | - |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * Sends a notification whenever an invoice is marked as processing payment. |
|
320 | - * |
|
321 | - * @param WPInv_Invoice $invoice |
|
322 | - */ |
|
323 | - public function processing_invoice( $invoice ) { |
|
324 | - |
|
325 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
326 | - $recipient = $invoice->get_email(); |
|
327 | - |
|
328 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
329 | - |
|
330 | - } |
|
331 | - |
|
332 | - /** |
|
333 | - * Sends a notification whenever an invoice is paid. |
|
334 | - * |
|
335 | - * @param WPInv_Invoice $invoice |
|
336 | - */ |
|
337 | - public function completed_invoice( $invoice ) { |
|
338 | - |
|
339 | - // (Maybe) abort if it is a renewal invoice. |
|
340 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
341 | - return; |
|
342 | - } |
|
343 | - |
|
344 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
345 | - $recipient = $invoice->get_email(); |
|
346 | - |
|
347 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
348 | - |
|
349 | - } |
|
15 | + /** |
|
16 | + * The array of invoice email actions. |
|
17 | + * |
|
18 | + * @param array |
|
19 | + */ |
|
20 | + public $invoice_actions; |
|
21 | + |
|
22 | + /** |
|
23 | + * Class constructor |
|
24 | + * |
|
25 | + */ |
|
26 | + public function __construct() { |
|
27 | + |
|
28 | + $this->invoice_actions = apply_filters( |
|
29 | + 'getpaid_notification_email_invoice_triggers', |
|
30 | + array( |
|
31 | + 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
32 | + 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
33 | + 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
34 | + 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
35 | + 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
36 | + 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
37 | + 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
38 | + 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
39 | + 'getpaid_new_customer_note' => 'user_note', |
|
40 | + 'getpaid_daily_maintenance' => 'overdue', |
|
41 | + ) |
|
42 | + ); |
|
43 | + |
|
44 | + $this->init_hooks(); |
|
45 | + |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Registers email hooks. |
|
50 | + */ |
|
51 | + public function init_hooks() { |
|
52 | + |
|
53 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
54 | + add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
55 | + |
|
56 | + foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | + $this->init_email_type_hook( $hook, $email_type ); |
|
58 | + } |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Registers an email hook for an invoice action. |
|
63 | + * |
|
64 | + * @param string $hook |
|
65 | + * @param string|array $email_type |
|
66 | + */ |
|
67 | + public function init_email_type_hook( $hook, $email_type ) { |
|
68 | + |
|
69 | + $email_type = wpinv_parse_list( $email_type ); |
|
70 | + |
|
71 | + foreach ( $email_type as $type ) { |
|
72 | + |
|
73 | + $email = new GetPaid_Notification_Email( $type ); |
|
74 | + |
|
75 | + // Abort if it is not active. |
|
76 | + if ( ! $email->is_active() ) { |
|
77 | + continue; |
|
78 | + } |
|
79 | + |
|
80 | + if ( method_exists( $this, $type ) ) { |
|
81 | + add_action( $hook, array( $this, $type ), 100, 2 ); |
|
82 | + continue; |
|
83 | + } |
|
84 | + |
|
85 | + do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
86 | + } |
|
87 | + |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Filters invoice merge tags. |
|
92 | + * |
|
93 | + * @param array $merge_tags |
|
94 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
95 | + */ |
|
96 | + public function invoice_merge_tags( $merge_tags, $object ) { |
|
97 | + |
|
98 | + if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
99 | + return array_merge( |
|
100 | + $merge_tags, |
|
101 | + $this->get_invoice_merge_tags( $object ) |
|
102 | + ); |
|
103 | + } |
|
104 | + |
|
105 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
106 | + return array_merge( |
|
107 | + $merge_tags, |
|
108 | + $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
109 | + ); |
|
110 | + } |
|
111 | + |
|
112 | + return $merge_tags; |
|
113 | + |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Generates invoice merge tags. |
|
118 | + * |
|
119 | + * @param WPInv_Invoice $invoice |
|
120 | + * @return array |
|
121 | + */ |
|
122 | + public function get_invoice_merge_tags( $invoice ) { |
|
123 | + |
|
124 | + // Abort if it does not exist. |
|
125 | + if ( ! $invoice->get_id() ) { |
|
126 | + return array(); |
|
127 | + } |
|
128 | + |
|
129 | + $merge_tags = array( |
|
130 | + '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
131 | + '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | + '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
133 | + '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
134 | + '{email}' => sanitize_email( $invoice->get_email() ), |
|
135 | + '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
136 | + '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
137 | + '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
138 | + '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
139 | + '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
140 | + '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ), |
|
141 | + '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
142 | + '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
143 | + '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
144 | + '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
145 | + '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
146 | + '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
147 | + '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
148 | + ); |
|
149 | + |
|
150 | + $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
151 | + |
|
152 | + if ( is_array( $payment_form_data ) ) { |
|
153 | + |
|
154 | + foreach ( $payment_form_data as $label => $value ) { |
|
155 | + |
|
156 | + $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
157 | + $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
158 | + |
|
159 | + if ( is_scalar( $value ) ) { |
|
160 | + $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
161 | + } |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
166 | + } |
|
350 | 167 | |
351 | - /** |
|
352 | - * Sends a notification whenever an invoice is refunded. |
|
353 | - * |
|
354 | - * @param WPInv_Invoice $invoice |
|
355 | - */ |
|
356 | - public function refunded_invoice( $invoice ) { |
|
357 | - |
|
358 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
359 | - $recipient = $invoice->get_email(); |
|
360 | - |
|
361 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
362 | - |
|
363 | - } |
|
168 | + /** |
|
169 | + * Helper function to send an email. |
|
170 | + * |
|
171 | + * @param WPInv_Invoice $invoice |
|
172 | + * @param GetPaid_Notification_Email $email |
|
173 | + * @param string $type |
|
174 | + * @param string|array $recipients |
|
175 | + * @param array $extra_args Extra template args. |
|
176 | + */ |
|
177 | + public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
364 | 178 | |
365 | - /** |
|
366 | - * Notifies a user about new invoices |
|
367 | - * |
|
368 | - * @param WPInv_Invoice $invoice |
|
369 | - * @param bool $force |
|
370 | - */ |
|
371 | - public function user_invoice( $invoice, $force = false ) { |
|
179 | + do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
372 | 180 | |
373 | - if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
374 | - return; |
|
375 | - } |
|
376 | - |
|
377 | - // Only send this email for invoices created via the admin page. |
|
378 | - if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
379 | - return; |
|
380 | - } |
|
381 | - |
|
382 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
383 | - $recipient = $invoice->get_email(); |
|
384 | - |
|
385 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
386 | - |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Checks if an invoice is a payment form invoice. |
|
391 | - * |
|
392 | - * @param int $invoice |
|
393 | - * @return bool |
|
394 | - */ |
|
395 | - public function is_payment_form_invoice( $invoice ) { |
|
396 | - $created_via = get_post_meta( $invoice, 'wpinv_created_via', true ); |
|
397 | - $is_payment_form_invoice = 'payment_form' === $created_via || 'geodirectory' === $created_via; |
|
398 | - $is_payment_form_invoice = apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
399 | - return empty( $_GET['getpaid-admin-action'] ) && $is_payment_form_invoice; |
|
400 | - } |
|
401 | - |
|
402 | - /** |
|
403 | - * Notifies admin about new invoice notes |
|
404 | - * |
|
405 | - * @param WPInv_Invoice $invoice |
|
406 | - * @param string $note |
|
407 | - */ |
|
408 | - public function user_note( $invoice, $note ) { |
|
409 | - |
|
410 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
411 | - $recipient = $invoice->get_email(); |
|
412 | - |
|
413 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
414 | - |
|
415 | - } |
|
416 | - |
|
417 | - /** |
|
418 | - * (Force) Sends overdue notices. |
|
419 | - * |
|
420 | - * @param WPInv_Invoice $invoice |
|
421 | - */ |
|
422 | - public function force_send_overdue_notice( $invoice ) { |
|
423 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
424 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
428 | - * Sends overdue notices. |
|
429 | - * |
|
430 | - * @TODO: Create an invoices query class. |
|
431 | - */ |
|
432 | - public function overdue() { |
|
433 | - global $wpdb; |
|
434 | - |
|
435 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
436 | - |
|
437 | - // Fetch reminder days. |
|
438 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
439 | - |
|
440 | - // Abort if non is set. |
|
441 | - if ( empty( $reminder_days ) ) { |
|
442 | - return; |
|
443 | - } |
|
444 | - |
|
445 | - // Retrieve date query. |
|
446 | - $date_query = $this->get_date_query( $reminder_days ); |
|
447 | - |
|
448 | - // Invoices table. |
|
449 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
450 | - |
|
451 | - // Fetch invoices. |
|
452 | - $invoices = $wpdb->get_col( |
|
453 | - "SELECT posts.ID FROM $wpdb->posts as posts |
|
181 | + $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
182 | + if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
183 | + return; |
|
184 | + } |
|
185 | + |
|
186 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
187 | + $merge_tags = $email->get_merge_tags(); |
|
188 | + |
|
189 | + $result = $mailer->send( |
|
190 | + apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
191 | + $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
192 | + $email->get_content( $merge_tags, $extra_args ), |
|
193 | + $email->get_attachments() |
|
194 | + ); |
|
195 | + |
|
196 | + // Maybe send a copy to the admin. |
|
197 | + if ( $email->include_admin_bcc() ) { |
|
198 | + $mailer->send( |
|
199 | + wpinv_get_admin_email(), |
|
200 | + $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
201 | + $email->get_content( $merge_tags ), |
|
202 | + $email->get_attachments() |
|
203 | + ); |
|
204 | + } |
|
205 | + |
|
206 | + if ( $result ) { |
|
207 | + $invoice->add_system_note( |
|
208 | + sprintf( |
|
209 | + // translators: %1 is the email type, %2 is the invoice recipient. |
|
210 | + __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
211 | + sanitize_key( $type ), |
|
212 | + $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
213 | + ) |
|
214 | + ); |
|
215 | + } else { |
|
216 | + $invoice->add_system_note( |
|
217 | + sprintf( |
|
218 | + // translators: %1 is the email type, %2 is the invoice recipient. |
|
219 | + __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
220 | + sanitize_key( $type ), |
|
221 | + $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
222 | + ) |
|
223 | + ); |
|
224 | + } |
|
225 | + |
|
226 | + do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
227 | + |
|
228 | + return $result; |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Also send emails to any cc users. |
|
233 | + * |
|
234 | + * @param array $recipients |
|
235 | + * @param GetPaid_Notification_Email $email |
|
236 | + */ |
|
237 | + public function filter_email_recipients( $recipients, $email ) { |
|
238 | + |
|
239 | + if ( ! $email->is_admin_email() ) { |
|
240 | + $cc = $email->object->get_email_cc(); |
|
241 | + $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
242 | + |
|
243 | + if ( ! empty( $cc ) ) { |
|
244 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
245 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
246 | + } |
|
247 | + |
|
248 | + if ( ! empty( $cc_2 ) ) { |
|
249 | + $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
250 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
251 | + } |
|
252 | + } |
|
253 | + |
|
254 | + return $recipients; |
|
255 | + |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Sends a new invoice notification. |
|
260 | + * |
|
261 | + * @param WPInv_Invoice $invoice |
|
262 | + */ |
|
263 | + public function new_invoice( $invoice ) { |
|
264 | + |
|
265 | + // Only send this email for invoices created via the admin page. |
|
266 | + if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
267 | + return; |
|
268 | + } |
|
269 | + |
|
270 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
271 | + $recipient = wpinv_get_admin_email(); |
|
272 | + |
|
273 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
274 | + |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Sends a cancelled invoice notification. |
|
279 | + * |
|
280 | + * @param WPInv_Invoice $invoice |
|
281 | + */ |
|
282 | + public function cancelled_invoice( $invoice ) { |
|
283 | + |
|
284 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
285 | + $recipient = $invoice->get_email(); |
|
286 | + |
|
287 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * Sends a failed invoice notification. |
|
292 | + * |
|
293 | + * @param WPInv_Invoice $invoice |
|
294 | + */ |
|
295 | + public function failed_invoice( $invoice ) { |
|
296 | + |
|
297 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
298 | + $recipient = wpinv_get_admin_email(); |
|
299 | + |
|
300 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
301 | + |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * Sends a notification whenever an invoice is put on hold. |
|
306 | + * |
|
307 | + * @param WPInv_Invoice $invoice |
|
308 | + */ |
|
309 | + public function onhold_invoice( $invoice ) { |
|
310 | + |
|
311 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
312 | + $recipient = $invoice->get_email(); |
|
313 | + |
|
314 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
315 | + |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * Sends a notification whenever an invoice is marked as processing payment. |
|
320 | + * |
|
321 | + * @param WPInv_Invoice $invoice |
|
322 | + */ |
|
323 | + public function processing_invoice( $invoice ) { |
|
324 | + |
|
325 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
326 | + $recipient = $invoice->get_email(); |
|
327 | + |
|
328 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
329 | + |
|
330 | + } |
|
331 | + |
|
332 | + /** |
|
333 | + * Sends a notification whenever an invoice is paid. |
|
334 | + * |
|
335 | + * @param WPInv_Invoice $invoice |
|
336 | + */ |
|
337 | + public function completed_invoice( $invoice ) { |
|
338 | + |
|
339 | + // (Maybe) abort if it is a renewal invoice. |
|
340 | + if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
341 | + return; |
|
342 | + } |
|
343 | + |
|
344 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
345 | + $recipient = $invoice->get_email(); |
|
346 | + |
|
347 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
348 | + |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * Sends a notification whenever an invoice is refunded. |
|
353 | + * |
|
354 | + * @param WPInv_Invoice $invoice |
|
355 | + */ |
|
356 | + public function refunded_invoice( $invoice ) { |
|
357 | + |
|
358 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
359 | + $recipient = $invoice->get_email(); |
|
360 | + |
|
361 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
362 | + |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * Notifies a user about new invoices |
|
367 | + * |
|
368 | + * @param WPInv_Invoice $invoice |
|
369 | + * @param bool $force |
|
370 | + */ |
|
371 | + public function user_invoice( $invoice, $force = false ) { |
|
372 | + |
|
373 | + if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
374 | + return; |
|
375 | + } |
|
376 | + |
|
377 | + // Only send this email for invoices created via the admin page. |
|
378 | + if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
379 | + return; |
|
380 | + } |
|
381 | + |
|
382 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
383 | + $recipient = $invoice->get_email(); |
|
384 | + |
|
385 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
386 | + |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Checks if an invoice is a payment form invoice. |
|
391 | + * |
|
392 | + * @param int $invoice |
|
393 | + * @return bool |
|
394 | + */ |
|
395 | + public function is_payment_form_invoice( $invoice ) { |
|
396 | + $created_via = get_post_meta( $invoice, 'wpinv_created_via', true ); |
|
397 | + $is_payment_form_invoice = 'payment_form' === $created_via || 'geodirectory' === $created_via; |
|
398 | + $is_payment_form_invoice = apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
399 | + return empty( $_GET['getpaid-admin-action'] ) && $is_payment_form_invoice; |
|
400 | + } |
|
401 | + |
|
402 | + /** |
|
403 | + * Notifies admin about new invoice notes |
|
404 | + * |
|
405 | + * @param WPInv_Invoice $invoice |
|
406 | + * @param string $note |
|
407 | + */ |
|
408 | + public function user_note( $invoice, $note ) { |
|
409 | + |
|
410 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
411 | + $recipient = $invoice->get_email(); |
|
412 | + |
|
413 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
414 | + |
|
415 | + } |
|
416 | + |
|
417 | + /** |
|
418 | + * (Force) Sends overdue notices. |
|
419 | + * |
|
420 | + * @param WPInv_Invoice $invoice |
|
421 | + */ |
|
422 | + public function force_send_overdue_notice( $invoice ) { |
|
423 | + $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
424 | + return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
425 | + } |
|
426 | + |
|
427 | + /** |
|
428 | + * Sends overdue notices. |
|
429 | + * |
|
430 | + * @TODO: Create an invoices query class. |
|
431 | + */ |
|
432 | + public function overdue() { |
|
433 | + global $wpdb; |
|
434 | + |
|
435 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
436 | + |
|
437 | + // Fetch reminder days. |
|
438 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
439 | + |
|
440 | + // Abort if non is set. |
|
441 | + if ( empty( $reminder_days ) ) { |
|
442 | + return; |
|
443 | + } |
|
444 | + |
|
445 | + // Retrieve date query. |
|
446 | + $date_query = $this->get_date_query( $reminder_days ); |
|
447 | + |
|
448 | + // Invoices table. |
|
449 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
450 | + |
|
451 | + // Fetch invoices. |
|
452 | + $invoices = $wpdb->get_col( |
|
453 | + "SELECT posts.ID FROM $wpdb->posts as posts |
|
454 | 454 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
455 | 455 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query" |
456 | 456 | ); |
457 | 457 | |
458 | - foreach ( $invoices as $invoice ) { |
|
458 | + foreach ( $invoices as $invoice ) { |
|
459 | 459 | |
460 | - // Only send this email for invoices created via the admin page. |
|
461 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
462 | - $invoice = new WPInv_Invoice( $invoice ); |
|
463 | - $email->object = $invoice; |
|
460 | + // Only send this email for invoices created via the admin page. |
|
461 | + if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
462 | + $invoice = new WPInv_Invoice( $invoice ); |
|
463 | + $email->object = $invoice; |
|
464 | 464 | |
465 | - if ( $invoice->needs_payment() && ! $invoice->is_renewal() ) { |
|
466 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
467 | - } |
|
468 | - } |
|
469 | - } |
|
465 | + if ( $invoice->needs_payment() && ! $invoice->is_renewal() ) { |
|
466 | + $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
467 | + } |
|
468 | + } |
|
469 | + } |
|
470 | 470 | |
471 | - } |
|
471 | + } |
|
472 | 472 | |
473 | - /** |
|
474 | - * Calculates the date query for an invoices query |
|
475 | - * |
|
476 | - * @param array $reminder_days |
|
477 | - * @return string |
|
478 | - */ |
|
479 | - public function get_date_query( $reminder_days ) { |
|
473 | + /** |
|
474 | + * Calculates the date query for an invoices query |
|
475 | + * |
|
476 | + * @param array $reminder_days |
|
477 | + * @return string |
|
478 | + */ |
|
479 | + public function get_date_query( $reminder_days ) { |
|
480 | 480 | |
481 | - $date_query = array( |
|
482 | - 'relation' => 'OR', |
|
483 | - ); |
|
481 | + $date_query = array( |
|
482 | + 'relation' => 'OR', |
|
483 | + ); |
|
484 | 484 | |
485 | - foreach ( $reminder_days as $days ) { |
|
486 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
485 | + foreach ( $reminder_days as $days ) { |
|
486 | + $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
487 | 487 | |
488 | - $date_query[] = array( |
|
489 | - 'year' => $date['year'], |
|
490 | - 'month' => $date['month'], |
|
491 | - 'day' => $date['day'], |
|
492 | - ); |
|
488 | + $date_query[] = array( |
|
489 | + 'year' => $date['year'], |
|
490 | + 'month' => $date['month'], |
|
491 | + 'day' => $date['day'], |
|
492 | + ); |
|
493 | 493 | |
494 | - } |
|
494 | + } |
|
495 | 495 | |
496 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
496 | + $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
497 | 497 | |
498 | - return $date_query->get_sql(); |
|
498 | + return $date_query->get_sql(); |
|
499 | 499 | |
500 | - } |
|
500 | + } |
|
501 | 501 | |
502 | 502 | } |
@@ -14,70 +14,70 @@ discard block |
||
14 | 14 | class WPInv_Ajax { |
15 | 15 | |
16 | 16 | /** |
17 | - * Hook in ajax handlers. |
|
18 | - */ |
|
19 | - public static function init() { |
|
20 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
22 | - self::add_ajax_events(); |
|
17 | + * Hook in ajax handlers. |
|
18 | + */ |
|
19 | + public static function init() { |
|
20 | + add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | + add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
22 | + self::add_ajax_events(); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
26 | - * Set GetPaid AJAX constant and headers. |
|
27 | - */ |
|
28 | - public static function define_ajax() { |
|
29 | - |
|
30 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | - getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | - getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
35 | - } |
|
36 | - $GLOBALS['wpdb']->hide_errors(); |
|
37 | - } |
|
26 | + * Set GetPaid AJAX constant and headers. |
|
27 | + */ |
|
28 | + public static function define_ajax() { |
|
29 | + |
|
30 | + if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | + getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | + getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | + if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | + /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
35 | + } |
|
36 | + $GLOBALS['wpdb']->hide_errors(); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | - * Send headers for GetPaid Ajax Requests. |
|
43 | - * |
|
44 | - * @since 1.0.18 |
|
45 | - */ |
|
46 | - private static function wpinv_ajax_headers() { |
|
47 | - if ( ! headers_sent() ) { |
|
48 | - send_origin_headers(); |
|
49 | - send_nosniff_header(); |
|
50 | - nocache_headers(); |
|
51 | - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | - header( 'X-Robots-Tag: noindex' ); |
|
53 | - status_header( 200 ); |
|
54 | - } |
|
42 | + * Send headers for GetPaid Ajax Requests. |
|
43 | + * |
|
44 | + * @since 1.0.18 |
|
45 | + */ |
|
46 | + private static function wpinv_ajax_headers() { |
|
47 | + if ( ! headers_sent() ) { |
|
48 | + send_origin_headers(); |
|
49 | + send_nosniff_header(); |
|
50 | + nocache_headers(); |
|
51 | + header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | + header( 'X-Robots-Tag: noindex' ); |
|
53 | + status_header( 200 ); |
|
54 | + } |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | - * Check for GetPaid Ajax request and fire action. |
|
59 | - */ |
|
60 | - public static function do_wpinv_ajax() { |
|
61 | - global $wp_query; |
|
58 | + * Check for GetPaid Ajax request and fire action. |
|
59 | + */ |
|
60 | + public static function do_wpinv_ajax() { |
|
61 | + global $wp_query; |
|
62 | 62 | |
63 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
65 | - } |
|
63 | + if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | + $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
65 | + } |
|
66 | 66 | |
67 | - $action = $wp_query->get( 'wpinv-ajax' ); |
|
67 | + $action = $wp_query->get( 'wpinv-ajax' ); |
|
68 | 68 | |
69 | - if ( $action ) { |
|
70 | - self::wpinv_ajax_headers(); |
|
71 | - $action = sanitize_text_field( $action ); |
|
72 | - do_action( 'wpinv_ajax_' . $action ); |
|
73 | - wp_die(); |
|
74 | - } |
|
69 | + if ( $action ) { |
|
70 | + self::wpinv_ajax_headers(); |
|
71 | + $action = sanitize_text_field( $action ); |
|
72 | + do_action( 'wpinv_ajax_' . $action ); |
|
73 | + wp_die(); |
|
74 | + } |
|
75 | 75 | |
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | - * Hook in ajax methods. |
|
80 | - */ |
|
79 | + * Hook in ajax methods. |
|
80 | + */ |
|
81 | 81 | public static function add_ajax_events() { |
82 | 82 | |
83 | 83 | // array( 'event' => is_frontend ) |
@@ -258,11 +258,11 @@ discard block |
||
258 | 258 | global $getpaid_force_checkbox; |
259 | 259 | |
260 | 260 | // Is the request set up correctly? |
261 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) { |
|
262 | - aui()->alert( |
|
263 | - array( |
|
264 | - 'type' => 'warning', |
|
265 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
261 | + if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) { |
|
262 | + aui()->alert( |
|
263 | + array( |
|
264 | + 'type' => 'warning', |
|
265 | + 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
266 | 266 | ), |
267 | 267 | true |
268 | 268 | ); |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | } |
271 | 271 | |
272 | 272 | // Payment form or button? |
273 | - if ( ! empty( $_GET['form'] ) ) { |
|
273 | + if ( ! empty( $_GET['form'] ) ) { |
|
274 | 274 | $form = sanitize_text_field( urldecode( $_GET['form'] ) ); |
275 | 275 | |
276 | 276 | if ( false !== strpos( $form, '|' ) ) { |
@@ -323,10 +323,10 @@ discard block |
||
323 | 323 | getpaid_display_payment_form( $form ); |
324 | 324 | } |
325 | 325 | } elseif ( ! empty( $_GET['invoice'] ) ) { |
326 | - getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) ); |
|
326 | + getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) ); |
|
327 | 327 | } else { |
328 | - $items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) ); |
|
329 | - getpaid_display_item_payment_form( $items ); |
|
328 | + $items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) ); |
|
329 | + getpaid_display_item_payment_form( $items ); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | exit; |
@@ -643,7 +643,7 @@ discard block |
||
643 | 643 | if ( is_wp_error( $error ) ) { |
644 | 644 | $alert = $error->get_error_message(); |
645 | 645 | wp_send_json_success( compact( 'alert' ) ); |
646 | - } |
|
646 | + } |
|
647 | 647 | |
648 | 648 | // Update totals. |
649 | 649 | $invoice->recalculate_total(); |
@@ -1072,12 +1072,12 @@ discard block |
||
1072 | 1072 | } |
1073 | 1073 | |
1074 | 1074 | /** |
1075 | - * Handles file uploads. |
|
1076 | - * |
|
1077 | - * @since 1.0.0 |
|
1078 | - * @return void |
|
1079 | - */ |
|
1080 | - public static function file_upload() { |
|
1075 | + * Handles file uploads. |
|
1076 | + * |
|
1077 | + * @since 1.0.0 |
|
1078 | + * @return void |
|
1079 | + */ |
|
1080 | + public static function file_upload() { |
|
1081 | 1081 | |
1082 | 1082 | // Check nonce. |
1083 | 1083 | check_ajax_referer( 'getpaid_form_nonce' ); |
@@ -1138,7 +1138,7 @@ discard block |
||
1138 | 1138 | |
1139 | 1139 | wp_send_json_success( $response ); |
1140 | 1140 | |
1141 | - } |
|
1141 | + } |
|
1142 | 1142 | |
1143 | 1143 | } |
1144 | 1144 |
@@ -14,635 +14,635 @@ |
||
14 | 14 | */ |
15 | 15 | class WPInv_Plugin { |
16 | 16 | |
17 | - /** |
|
18 | - * GetPaid version. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $version; |
|
23 | - |
|
24 | - /** |
|
25 | - * Data container. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $data = array(); |
|
30 | - |
|
31 | - /** |
|
32 | - * Form elements instance. |
|
33 | - * |
|
34 | - * @var WPInv_Payment_Form_Elements |
|
35 | - */ |
|
36 | - public $form_elements; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var array An array of payment gateways. |
|
40 | - */ |
|
41 | - public $gateways; |
|
42 | - |
|
43 | - /** |
|
44 | - * Class constructor. |
|
45 | - */ |
|
46 | - public function __construct() { |
|
47 | - $this->define_constants(); |
|
48 | - $this->includes(); |
|
49 | - $this->init_hooks(); |
|
50 | - $this->set_properties(); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Sets a custom data property. |
|
55 | - * |
|
56 | - * @param string $prop The prop to set. |
|
57 | - * @param mixed $value The value to retrieve. |
|
58 | - */ |
|
59 | - public function set( $prop, $value ) { |
|
60 | - $this->data[ $prop ] = $value; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Gets a custom data property. |
|
65 | - * |
|
66 | - * @param string $prop The prop to set. |
|
67 | - * @return mixed The value. |
|
68 | - */ |
|
69 | - public function get( $prop ) { |
|
70 | - |
|
71 | - if ( isset( $this->data[ $prop ] ) ) { |
|
72 | - return $this->data[ $prop ]; |
|
73 | - } |
|
74 | - |
|
75 | - return null; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Define class properties. |
|
80 | - */ |
|
81 | - public function set_properties() { |
|
82 | - |
|
83 | - // Sessions. |
|
84 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
86 | - $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
87 | - |
|
88 | - // Init other objects. |
|
89 | - $this->set( 'notes', new WPInv_Notes() ); |
|
90 | - $this->set( 'api', new WPInv_API() ); |
|
91 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
92 | - $this->set( 'template', new GetPaid_Template() ); |
|
93 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
94 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
95 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
96 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
97 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
98 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
99 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
100 | - |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Define plugin constants. |
|
105 | - */ |
|
106 | - public function define_constants() { |
|
107 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
108 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
109 | - $this->version = WPINV_VERSION; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Hook into actions and filters. |
|
114 | - * |
|
115 | - * @since 1.0.19 |
|
116 | - */ |
|
117 | - protected function init_hooks() { |
|
118 | - /* Internationalize the text strings used. */ |
|
119 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
120 | - |
|
121 | - // Init the plugin after WordPress inits. |
|
122 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
123 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
124 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
125 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
126 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
127 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
128 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
129 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
130 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
131 | - add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
132 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
133 | - |
|
134 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
17 | + /** |
|
18 | + * GetPaid version. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $version; |
|
23 | + |
|
24 | + /** |
|
25 | + * Data container. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $data = array(); |
|
30 | + |
|
31 | + /** |
|
32 | + * Form elements instance. |
|
33 | + * |
|
34 | + * @var WPInv_Payment_Form_Elements |
|
35 | + */ |
|
36 | + public $form_elements; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var array An array of payment gateways. |
|
40 | + */ |
|
41 | + public $gateways; |
|
42 | + |
|
43 | + /** |
|
44 | + * Class constructor. |
|
45 | + */ |
|
46 | + public function __construct() { |
|
47 | + $this->define_constants(); |
|
48 | + $this->includes(); |
|
49 | + $this->init_hooks(); |
|
50 | + $this->set_properties(); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Sets a custom data property. |
|
55 | + * |
|
56 | + * @param string $prop The prop to set. |
|
57 | + * @param mixed $value The value to retrieve. |
|
58 | + */ |
|
59 | + public function set( $prop, $value ) { |
|
60 | + $this->data[ $prop ] = $value; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Gets a custom data property. |
|
65 | + * |
|
66 | + * @param string $prop The prop to set. |
|
67 | + * @return mixed The value. |
|
68 | + */ |
|
69 | + public function get( $prop ) { |
|
70 | + |
|
71 | + if ( isset( $this->data[ $prop ] ) ) { |
|
72 | + return $this->data[ $prop ]; |
|
73 | + } |
|
74 | + |
|
75 | + return null; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Define class properties. |
|
80 | + */ |
|
81 | + public function set_properties() { |
|
82 | + |
|
83 | + // Sessions. |
|
84 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
86 | + $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
87 | + |
|
88 | + // Init other objects. |
|
89 | + $this->set( 'notes', new WPInv_Notes() ); |
|
90 | + $this->set( 'api', new WPInv_API() ); |
|
91 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
92 | + $this->set( 'template', new GetPaid_Template() ); |
|
93 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
94 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
95 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
96 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
97 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
98 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
99 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
100 | + |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Define plugin constants. |
|
105 | + */ |
|
106 | + public function define_constants() { |
|
107 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
108 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
109 | + $this->version = WPINV_VERSION; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Hook into actions and filters. |
|
114 | + * |
|
115 | + * @since 1.0.19 |
|
116 | + */ |
|
117 | + protected function init_hooks() { |
|
118 | + /* Internationalize the text strings used. */ |
|
119 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
120 | + |
|
121 | + // Init the plugin after WordPress inits. |
|
122 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
123 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
124 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
125 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
126 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
127 | + add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
128 | + add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
129 | + add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
130 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
131 | + add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
132 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
133 | + |
|
134 | + add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
135 | 135 | add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
136 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
137 | - |
|
138 | - // Fires after registering actions. |
|
139 | - do_action( 'wpinv_actions', $this ); |
|
140 | - do_action( 'getpaid_actions', $this ); |
|
141 | - |
|
142 | - } |
|
143 | - |
|
144 | - public function plugins_loaded() { |
|
145 | - /* Internationalize the text strings used. */ |
|
146 | - $this->load_textdomain(); |
|
147 | - |
|
148 | - do_action( 'wpinv_loaded' ); |
|
149 | - |
|
150 | - // Fix oxygen page builder conflict |
|
151 | - if ( function_exists( 'ct_css_output' ) ) { |
|
152 | - wpinv_oxygen_fix_conflict(); |
|
153 | - } |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Load Localisation files. |
|
158 | - * |
|
159 | - * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
160 | - * |
|
161 | - * Locales found in: |
|
162 | - * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
163 | - * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
164 | - * |
|
165 | - * @since 1.0.0 |
|
166 | - */ |
|
167 | - public function load_textdomain() { |
|
168 | - |
|
169 | - load_plugin_textdomain( |
|
170 | - 'invoicing', |
|
171 | - false, |
|
172 | - plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' |
|
173 | - ); |
|
174 | - |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * Include required core files used in admin and on the frontend. |
|
179 | - */ |
|
180 | - public function includes() { |
|
181 | - |
|
182 | - // Start with the settings. |
|
183 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
184 | - |
|
185 | - // Packages/libraries. |
|
186 | - require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
187 | - require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
188 | - |
|
189 | - // Load functions. |
|
190 | - require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
191 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
192 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
193 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
194 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
195 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
196 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
197 | - require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
198 | - require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
199 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
200 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
201 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
202 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
203 | - require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
204 | - require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
205 | - |
|
206 | - // Register autoloader. |
|
207 | - try { |
|
208 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
209 | - } catch ( Exception $e ) { |
|
210 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
211 | - } |
|
212 | - |
|
213 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
214 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
215 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
216 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
217 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
218 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
219 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
220 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
221 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
222 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
223 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
224 | - require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
225 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
226 | - require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
227 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
228 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
229 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
230 | - require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
231 | - require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
232 | - require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
233 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
234 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
235 | - |
|
236 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
237 | - GetPaid_Post_Types_Admin::init(); |
|
238 | - |
|
239 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
240 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
241 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
242 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
243 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
244 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
245 | - // load the user class only on the users.php page |
|
246 | - global $pagenow; |
|
247 | - if ( $pagenow == 'users.php' ) { |
|
248 | - new WPInv_Admin_Users(); |
|
249 | - } |
|
250 | - } |
|
251 | - |
|
252 | - // Register cli commands |
|
253 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
254 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
255 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
256 | - } |
|
257 | - |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Class autoloader |
|
262 | - * |
|
263 | - * @param string $class_name The name of the class to load. |
|
264 | - * @access public |
|
265 | - * @since 1.0.19 |
|
266 | - * @return void |
|
267 | - */ |
|
268 | - public function autoload( $class_name ) { |
|
269 | - |
|
270 | - // Normalize the class name... |
|
271 | - $class_name = strtolower( $class_name ); |
|
272 | - |
|
273 | - // ... and make sure it is our class. |
|
274 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
275 | - return; |
|
276 | - } |
|
277 | - |
|
278 | - // Next, prepare the file name from the class. |
|
279 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
280 | - |
|
281 | - // Base path of the classes. |
|
282 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
283 | - |
|
284 | - // And an array of possible locations in order of importance. |
|
285 | - $locations = array( |
|
286 | - "$plugin_path/includes", |
|
287 | - "$plugin_path/includes/data-stores", |
|
288 | - "$plugin_path/includes/gateways", |
|
289 | - "$plugin_path/includes/payments", |
|
290 | - "$plugin_path/includes/geolocation", |
|
291 | - "$plugin_path/includes/reports", |
|
292 | - "$plugin_path/includes/api", |
|
293 | - "$plugin_path/includes/admin", |
|
294 | - "$plugin_path/includes/admin/meta-boxes", |
|
295 | - ); |
|
296 | - |
|
297 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
298 | - |
|
299 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
300 | - include trailingslashit( $location ) . $file_name; |
|
301 | - break; |
|
302 | - } |
|
136 | + add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
137 | + |
|
138 | + // Fires after registering actions. |
|
139 | + do_action( 'wpinv_actions', $this ); |
|
140 | + do_action( 'getpaid_actions', $this ); |
|
141 | + |
|
142 | + } |
|
143 | + |
|
144 | + public function plugins_loaded() { |
|
145 | + /* Internationalize the text strings used. */ |
|
146 | + $this->load_textdomain(); |
|
147 | + |
|
148 | + do_action( 'wpinv_loaded' ); |
|
149 | + |
|
150 | + // Fix oxygen page builder conflict |
|
151 | + if ( function_exists( 'ct_css_output' ) ) { |
|
152 | + wpinv_oxygen_fix_conflict(); |
|
153 | + } |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Load Localisation files. |
|
158 | + * |
|
159 | + * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
160 | + * |
|
161 | + * Locales found in: |
|
162 | + * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
163 | + * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
164 | + * |
|
165 | + * @since 1.0.0 |
|
166 | + */ |
|
167 | + public function load_textdomain() { |
|
168 | + |
|
169 | + load_plugin_textdomain( |
|
170 | + 'invoicing', |
|
171 | + false, |
|
172 | + plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' |
|
173 | + ); |
|
174 | + |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * Include required core files used in admin and on the frontend. |
|
179 | + */ |
|
180 | + public function includes() { |
|
181 | + |
|
182 | + // Start with the settings. |
|
183 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
184 | + |
|
185 | + // Packages/libraries. |
|
186 | + require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
187 | + require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
188 | + |
|
189 | + // Load functions. |
|
190 | + require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
191 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
192 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
193 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
194 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
195 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
196 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
197 | + require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
198 | + require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
199 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
200 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
201 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
202 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
203 | + require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
204 | + require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
205 | + |
|
206 | + // Register autoloader. |
|
207 | + try { |
|
208 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
209 | + } catch ( Exception $e ) { |
|
210 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
211 | + } |
|
212 | + |
|
213 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
214 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
215 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
216 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
217 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
218 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
219 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
220 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
221 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
222 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
223 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
224 | + require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
225 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
226 | + require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
227 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
228 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
229 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
230 | + require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
231 | + require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
232 | + require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
233 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
234 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
235 | + |
|
236 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
237 | + GetPaid_Post_Types_Admin::init(); |
|
238 | + |
|
239 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
240 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
241 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
242 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
243 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
244 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
245 | + // load the user class only on the users.php page |
|
246 | + global $pagenow; |
|
247 | + if ( $pagenow == 'users.php' ) { |
|
248 | + new WPInv_Admin_Users(); |
|
249 | + } |
|
250 | + } |
|
251 | + |
|
252 | + // Register cli commands |
|
253 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
254 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
255 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
256 | + } |
|
257 | + |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Class autoloader |
|
262 | + * |
|
263 | + * @param string $class_name The name of the class to load. |
|
264 | + * @access public |
|
265 | + * @since 1.0.19 |
|
266 | + * @return void |
|
267 | + */ |
|
268 | + public function autoload( $class_name ) { |
|
269 | + |
|
270 | + // Normalize the class name... |
|
271 | + $class_name = strtolower( $class_name ); |
|
272 | + |
|
273 | + // ... and make sure it is our class. |
|
274 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
275 | + return; |
|
276 | + } |
|
277 | + |
|
278 | + // Next, prepare the file name from the class. |
|
279 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
280 | + |
|
281 | + // Base path of the classes. |
|
282 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
283 | + |
|
284 | + // And an array of possible locations in order of importance. |
|
285 | + $locations = array( |
|
286 | + "$plugin_path/includes", |
|
287 | + "$plugin_path/includes/data-stores", |
|
288 | + "$plugin_path/includes/gateways", |
|
289 | + "$plugin_path/includes/payments", |
|
290 | + "$plugin_path/includes/geolocation", |
|
291 | + "$plugin_path/includes/reports", |
|
292 | + "$plugin_path/includes/api", |
|
293 | + "$plugin_path/includes/admin", |
|
294 | + "$plugin_path/includes/admin/meta-boxes", |
|
295 | + ); |
|
296 | + |
|
297 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
298 | + |
|
299 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
300 | + include trailingslashit( $location ) . $file_name; |
|
301 | + break; |
|
302 | + } |
|
303 | 303 | } |
304 | 304 | |
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Inits hooks etc. |
|
309 | - */ |
|
310 | - public function init() { |
|
311 | - |
|
312 | - // Fires before getpaid inits. |
|
313 | - do_action( 'before_getpaid_init', $this ); |
|
314 | - |
|
315 | - // Maybe upgrade. |
|
316 | - $this->maybe_upgrade_database(); |
|
317 | - |
|
318 | - // Load default gateways. |
|
319 | - $gateways = apply_filters( |
|
320 | - 'getpaid_default_gateways', |
|
321 | - array( |
|
322 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
323 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
324 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
325 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
326 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
327 | - ) |
|
328 | - ); |
|
329 | - |
|
330 | - foreach ( $gateways as $id => $class ) { |
|
331 | - $this->gateways[ $id ] = new $class(); |
|
332 | - } |
|
333 | - |
|
334 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
335 | - GetPaid_Installer::rename_gateways_label(); |
|
336 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
337 | - } |
|
338 | - |
|
339 | - // Fires after getpaid inits. |
|
340 | - do_action( 'getpaid_init', $this ); |
|
341 | - |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Checks if this is an IPN request and processes it. |
|
346 | - */ |
|
347 | - public function maybe_process_ipn() { |
|
348 | - |
|
349 | - // Ensure that this is an IPN request. |
|
350 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
351 | - return; |
|
352 | - } |
|
353 | - |
|
354 | - $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
355 | - |
|
356 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
357 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
358 | - exit; |
|
359 | - |
|
360 | - } |
|
361 | - |
|
362 | - public function enqueue_scripts() { |
|
363 | - |
|
364 | - // Fires before adding scripts. |
|
365 | - do_action( 'getpaid_enqueue_scripts' ); |
|
366 | - |
|
367 | - $localize = array(); |
|
368 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
369 | - $localize['thousands'] = wpinv_thousands_separator(); |
|
370 | - $localize['decimals'] = wpinv_decimal_separator(); |
|
371 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
372 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
373 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
374 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
375 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
376 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
377 | - |
|
378 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
379 | - |
|
380 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
381 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
382 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
383 | - } |
|
384 | - |
|
385 | - public function wpinv_actions() { |
|
386 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
387 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
388 | - } |
|
389 | - |
|
390 | - if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
391 | - include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
392 | - } |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Inits hooks etc. |
|
309 | + */ |
|
310 | + public function init() { |
|
311 | + |
|
312 | + // Fires before getpaid inits. |
|
313 | + do_action( 'before_getpaid_init', $this ); |
|
314 | + |
|
315 | + // Maybe upgrade. |
|
316 | + $this->maybe_upgrade_database(); |
|
317 | + |
|
318 | + // Load default gateways. |
|
319 | + $gateways = apply_filters( |
|
320 | + 'getpaid_default_gateways', |
|
321 | + array( |
|
322 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
323 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
324 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
325 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
326 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
327 | + ) |
|
328 | + ); |
|
329 | + |
|
330 | + foreach ( $gateways as $id => $class ) { |
|
331 | + $this->gateways[ $id ] = new $class(); |
|
332 | + } |
|
333 | + |
|
334 | + if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
335 | + GetPaid_Installer::rename_gateways_label(); |
|
336 | + update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
337 | + } |
|
338 | + |
|
339 | + // Fires after getpaid inits. |
|
340 | + do_action( 'getpaid_init', $this ); |
|
341 | + |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Checks if this is an IPN request and processes it. |
|
346 | + */ |
|
347 | + public function maybe_process_ipn() { |
|
348 | + |
|
349 | + // Ensure that this is an IPN request. |
|
350 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
351 | + return; |
|
352 | + } |
|
353 | + |
|
354 | + $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
355 | + |
|
356 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
357 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
358 | + exit; |
|
359 | + |
|
360 | + } |
|
361 | + |
|
362 | + public function enqueue_scripts() { |
|
363 | + |
|
364 | + // Fires before adding scripts. |
|
365 | + do_action( 'getpaid_enqueue_scripts' ); |
|
366 | + |
|
367 | + $localize = array(); |
|
368 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
369 | + $localize['thousands'] = wpinv_thousands_separator(); |
|
370 | + $localize['decimals'] = wpinv_decimal_separator(); |
|
371 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
372 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
373 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
374 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
375 | + $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
376 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
377 | + |
|
378 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
379 | + |
|
380 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
381 | + wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
382 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
383 | + } |
|
384 | + |
|
385 | + public function wpinv_actions() { |
|
386 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
387 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
388 | + } |
|
389 | + |
|
390 | + if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
391 | + include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
392 | + } |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | 396 | * Fires an action after verifying that a user can fire them. |
397 | - * |
|
398 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
399 | - * current user owns the invoice/subscription. |
|
397 | + * |
|
398 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
399 | + * current user owns the invoice/subscription. |
|
400 | 400 | */ |
401 | 401 | public function maybe_do_authenticated_action() { |
402 | 402 | |
403 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
403 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
404 | 404 | |
405 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
406 | - $data = wp_unslash( $_REQUEST ); |
|
407 | - if ( is_user_logged_in() ) { |
|
408 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
409 | - } |
|
405 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
406 | + $data = wp_unslash( $_REQUEST ); |
|
407 | + if ( is_user_logged_in() ) { |
|
408 | + do_action( "getpaid_authenticated_action_$key", $data ); |
|
409 | + } |
|
410 | 410 | |
411 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
411 | + do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
412 | 412 | |
413 | - } |
|
413 | + } |
|
414 | 414 | |
415 | 415 | } |
416 | 416 | |
417 | - public function pre_get_posts( $wp_query ) { |
|
418 | - |
|
419 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
420 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
421 | - } |
|
422 | - |
|
423 | - return $wp_query; |
|
424 | - } |
|
425 | - |
|
426 | - /** |
|
427 | - * Register widgets |
|
428 | - * |
|
429 | - */ |
|
430 | - public function register_widgets() { |
|
431 | - global $pagenow; |
|
432 | - |
|
433 | - // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
434 | - // So we disable our widgets when editing a page with UX Builder. |
|
435 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
436 | - return; |
|
437 | - } |
|
438 | - |
|
439 | - $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
440 | - |
|
441 | - if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
442 | - // don't initiate in these conditions. |
|
443 | - } else { |
|
444 | - |
|
445 | - // Only load allowed widgets. |
|
446 | - $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
447 | - $widgets = apply_filters( |
|
448 | - 'getpaid_widget_classes', |
|
449 | - array( |
|
450 | - 'WPInv_Checkout_Widget', |
|
451 | - 'WPInv_History_Widget', |
|
452 | - 'WPInv_Receipt_Widget', |
|
453 | - 'WPInv_Subscriptions_Widget', |
|
454 | - 'WPInv_Buy_Item_Widget', |
|
455 | - 'WPInv_Messages_Widget', |
|
456 | - 'WPInv_GetPaid_Widget', |
|
457 | - 'WPInv_Invoice_Widget', |
|
458 | - ) |
|
459 | - ); |
|
460 | - |
|
461 | - // For each widget... |
|
462 | - foreach ( $widgets as $widget ) { |
|
463 | - |
|
464 | - // Abort early if it is excluded for this page. |
|
465 | - if ( in_array( $widget, $exclude ) ) { |
|
466 | - continue; |
|
467 | - } |
|
468 | - |
|
469 | - // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
470 | - if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
471 | - register_widget( $widget ); |
|
472 | - } else { |
|
473 | - new $widget(); |
|
474 | - } |
|
417 | + public function pre_get_posts( $wp_query ) { |
|
418 | + |
|
419 | + if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
420 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
421 | + } |
|
422 | + |
|
423 | + return $wp_query; |
|
424 | + } |
|
425 | + |
|
426 | + /** |
|
427 | + * Register widgets |
|
428 | + * |
|
429 | + */ |
|
430 | + public function register_widgets() { |
|
431 | + global $pagenow; |
|
432 | + |
|
433 | + // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
434 | + // So we disable our widgets when editing a page with UX Builder. |
|
435 | + if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
436 | + return; |
|
437 | + } |
|
438 | + |
|
439 | + $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
440 | + |
|
441 | + if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
442 | + // don't initiate in these conditions. |
|
443 | + } else { |
|
444 | + |
|
445 | + // Only load allowed widgets. |
|
446 | + $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
447 | + $widgets = apply_filters( |
|
448 | + 'getpaid_widget_classes', |
|
449 | + array( |
|
450 | + 'WPInv_Checkout_Widget', |
|
451 | + 'WPInv_History_Widget', |
|
452 | + 'WPInv_Receipt_Widget', |
|
453 | + 'WPInv_Subscriptions_Widget', |
|
454 | + 'WPInv_Buy_Item_Widget', |
|
455 | + 'WPInv_Messages_Widget', |
|
456 | + 'WPInv_GetPaid_Widget', |
|
457 | + 'WPInv_Invoice_Widget', |
|
458 | + ) |
|
459 | + ); |
|
460 | + |
|
461 | + // For each widget... |
|
462 | + foreach ( $widgets as $widget ) { |
|
463 | + |
|
464 | + // Abort early if it is excluded for this page. |
|
465 | + if ( in_array( $widget, $exclude ) ) { |
|
466 | + continue; |
|
467 | + } |
|
468 | + |
|
469 | + // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
470 | + if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
471 | + register_widget( $widget ); |
|
472 | + } else { |
|
473 | + new $widget(); |
|
474 | + } |
|
475 | 475 | } |
476 | 476 | } |
477 | 477 | |
478 | - } |
|
478 | + } |
|
479 | + |
|
480 | + /** |
|
481 | + * Upgrades the database. |
|
482 | + * |
|
483 | + * @since 2.0.2 |
|
484 | + */ |
|
485 | + public function maybe_upgrade_database() { |
|
486 | + |
|
487 | + $wpi_version = get_option( 'wpinv_version', 0 ); |
|
488 | + |
|
489 | + if ( $wpi_version == WPINV_VERSION ) { |
|
490 | + return; |
|
491 | + } |
|
479 | 492 | |
480 | - /** |
|
481 | - * Upgrades the database. |
|
482 | - * |
|
483 | - * @since 2.0.2 |
|
484 | - */ |
|
485 | - public function maybe_upgrade_database() { |
|
493 | + $installer = new GetPaid_Installer(); |
|
486 | 494 | |
487 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
495 | + if ( empty( $wpi_version ) ) { |
|
496 | + return $installer->upgrade_db( 0 ); |
|
497 | + } |
|
488 | 498 | |
489 | - if ( $wpi_version == WPINV_VERSION ) { |
|
490 | - return; |
|
491 | - } |
|
499 | + $upgrades = array( |
|
500 | + '0.0.5' => '004', |
|
501 | + '1.0.3' => '102', |
|
502 | + '2.0.0' => '118', |
|
503 | + '2.0.8' => '207', |
|
504 | + '2.6.16' => '2615', |
|
505 | + ); |
|
492 | 506 | |
493 | - $installer = new GetPaid_Installer(); |
|
507 | + foreach ( $upgrades as $key => $method ) { |
|
508 | + |
|
509 | + if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
510 | + return $installer->upgrade_db( $method ); |
|
511 | + } |
|
512 | + } |
|
513 | + |
|
514 | + } |
|
515 | + |
|
516 | + /** |
|
517 | + * Flushes the permalinks if needed. |
|
518 | + * |
|
519 | + * @since 2.0.8 |
|
520 | + */ |
|
521 | + public function maybe_flush_permalinks() { |
|
494 | 522 | |
495 | - if ( empty( $wpi_version ) ) { |
|
496 | - return $installer->upgrade_db( 0 ); |
|
497 | - } |
|
523 | + $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
498 | 524 | |
499 | - $upgrades = array( |
|
500 | - '0.0.5' => '004', |
|
501 | - '1.0.3' => '102', |
|
502 | - '2.0.0' => '118', |
|
503 | - '2.0.8' => '207', |
|
504 | - '2.6.16' => '2615', |
|
505 | - ); |
|
506 | - |
|
507 | - foreach ( $upgrades as $key => $method ) { |
|
508 | - |
|
509 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
510 | - return $installer->upgrade_db( $method ); |
|
511 | - } |
|
512 | - } |
|
513 | - |
|
514 | - } |
|
515 | - |
|
516 | - /** |
|
517 | - * Flushes the permalinks if needed. |
|
518 | - * |
|
519 | - * @since 2.0.8 |
|
520 | - */ |
|
521 | - public function maybe_flush_permalinks() { |
|
522 | - |
|
523 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
524 | - |
|
525 | - if ( ! empty( $flush ) ) { |
|
526 | - flush_rewrite_rules(); |
|
527 | - delete_option( 'wpinv_flush_permalinks' ); |
|
528 | - } |
|
529 | - |
|
530 | - } |
|
531 | - |
|
532 | - /** |
|
533 | - * Remove our pages from yoast sitemaps. |
|
534 | - * |
|
535 | - * @since 1.0.19 |
|
536 | - * @param int[] $excluded_posts_ids |
|
537 | - */ |
|
538 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
539 | - |
|
540 | - // Ensure that we have an array. |
|
541 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
542 | - $excluded_posts_ids = array(); |
|
543 | - } |
|
544 | - |
|
545 | - // Prepare our pages. |
|
546 | - $our_pages = array(); |
|
547 | - |
|
548 | - // Checkout page. |
|
549 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
550 | - |
|
551 | - // Success page. |
|
552 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
553 | - |
|
554 | - // Failure page. |
|
555 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
556 | - |
|
557 | - // History page. |
|
558 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
559 | - |
|
560 | - // Subscriptions page. |
|
561 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
562 | - |
|
563 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
564 | - |
|
565 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
566 | - return array_unique( $excluded_posts_ids ); |
|
567 | - |
|
568 | - } |
|
569 | - |
|
570 | - /** |
|
571 | - * Remove our pages from yoast sitemaps. |
|
572 | - * |
|
573 | - * @since 1.0.19 |
|
574 | - * @param string[] $post_types |
|
575 | - */ |
|
576 | - public function exclude_invoicing_post_types( $post_types ) { |
|
577 | - |
|
578 | - // Ensure that we have an array. |
|
579 | - if ( ! is_array( $post_types ) ) { |
|
580 | - $post_types = array(); |
|
581 | - } |
|
582 | - |
|
583 | - // Remove our post types. |
|
584 | - return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
585 | - } |
|
586 | - |
|
587 | - /** |
|
588 | - * Displays additional footer code. |
|
589 | - * |
|
590 | - * @since 2.0.0 |
|
591 | - */ |
|
592 | - public function wp_footer() { |
|
593 | - wpinv_get_template( 'frontend-footer.php' ); |
|
594 | - } |
|
595 | - |
|
596 | - /** |
|
597 | - * Displays additional header code. |
|
598 | - * |
|
599 | - * @since 2.0.0 |
|
600 | - */ |
|
601 | - public function wp_head() { |
|
602 | - wpinv_get_template( 'frontend-head.php' ); |
|
603 | - } |
|
604 | - |
|
605 | - /** |
|
606 | - * Custom query vars. |
|
607 | - * |
|
608 | - */ |
|
609 | - public function custom_query_vars( $vars ) { |
|
525 | + if ( ! empty( $flush ) ) { |
|
526 | + flush_rewrite_rules(); |
|
527 | + delete_option( 'wpinv_flush_permalinks' ); |
|
528 | + } |
|
529 | + |
|
530 | + } |
|
531 | + |
|
532 | + /** |
|
533 | + * Remove our pages from yoast sitemaps. |
|
534 | + * |
|
535 | + * @since 1.0.19 |
|
536 | + * @param int[] $excluded_posts_ids |
|
537 | + */ |
|
538 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
539 | + |
|
540 | + // Ensure that we have an array. |
|
541 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
542 | + $excluded_posts_ids = array(); |
|
543 | + } |
|
544 | + |
|
545 | + // Prepare our pages. |
|
546 | + $our_pages = array(); |
|
547 | + |
|
548 | + // Checkout page. |
|
549 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
550 | + |
|
551 | + // Success page. |
|
552 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
553 | + |
|
554 | + // Failure page. |
|
555 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
556 | + |
|
557 | + // History page. |
|
558 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
559 | + |
|
560 | + // Subscriptions page. |
|
561 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
562 | + |
|
563 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
564 | + |
|
565 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
566 | + return array_unique( $excluded_posts_ids ); |
|
567 | + |
|
568 | + } |
|
569 | + |
|
570 | + /** |
|
571 | + * Remove our pages from yoast sitemaps. |
|
572 | + * |
|
573 | + * @since 1.0.19 |
|
574 | + * @param string[] $post_types |
|
575 | + */ |
|
576 | + public function exclude_invoicing_post_types( $post_types ) { |
|
577 | + |
|
578 | + // Ensure that we have an array. |
|
579 | + if ( ! is_array( $post_types ) ) { |
|
580 | + $post_types = array(); |
|
581 | + } |
|
582 | + |
|
583 | + // Remove our post types. |
|
584 | + return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
585 | + } |
|
586 | + |
|
587 | + /** |
|
588 | + * Displays additional footer code. |
|
589 | + * |
|
590 | + * @since 2.0.0 |
|
591 | + */ |
|
592 | + public function wp_footer() { |
|
593 | + wpinv_get_template( 'frontend-footer.php' ); |
|
594 | + } |
|
595 | + |
|
596 | + /** |
|
597 | + * Displays additional header code. |
|
598 | + * |
|
599 | + * @since 2.0.0 |
|
600 | + */ |
|
601 | + public function wp_head() { |
|
602 | + wpinv_get_template( 'frontend-head.php' ); |
|
603 | + } |
|
604 | + |
|
605 | + /** |
|
606 | + * Custom query vars. |
|
607 | + * |
|
608 | + */ |
|
609 | + public function custom_query_vars( $vars ) { |
|
610 | 610 | $vars[] = 'getpaid-ipn'; |
611 | 611 | return $vars; |
612 | - } |
|
612 | + } |
|
613 | 613 | |
614 | - /** |
|
615 | - * Add rewrite tags and rules. |
|
616 | - * |
|
617 | - */ |
|
618 | - public function add_rewrite_rule() { |
|
614 | + /** |
|
615 | + * Add rewrite tags and rules. |
|
616 | + * |
|
617 | + */ |
|
618 | + public function add_rewrite_rule() { |
|
619 | 619 | $tag = 'getpaid-ipn'; |
620 | 620 | add_rewrite_tag( "%$tag%", '([^&]+)' ); |
621 | 621 | add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
622 | - } |
|
622 | + } |
|
623 | 623 | |
624 | - /** |
|
625 | - * Processes non-query string ipns. |
|
626 | - * |
|
627 | - */ |
|
628 | - public function maybe_process_new_ipn( $query ) { |
|
624 | + /** |
|
625 | + * Processes non-query string ipns. |
|
626 | + * |
|
627 | + */ |
|
628 | + public function maybe_process_new_ipn( $query ) { |
|
629 | 629 | |
630 | 630 | if ( is_admin() || ! $query->is_main_query() ) { |
631 | 631 | return; |
632 | 632 | } |
633 | 633 | |
634 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
634 | + $gateway = get_query_var( 'getpaid-ipn' ); |
|
635 | 635 | |
636 | 636 | if ( ! empty( $gateway ) ) { |
637 | 637 | |
638 | - $gateway = sanitize_text_field( $gateway ); |
|
639 | - nocache_headers(); |
|
640 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
641 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
642 | - exit; |
|
638 | + $gateway = sanitize_text_field( $gateway ); |
|
639 | + nocache_headers(); |
|
640 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
641 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
642 | + exit; |
|
643 | 643 | |
644 | 644 | } |
645 | 645 | |
646 | - } |
|
646 | + } |
|
647 | 647 | |
648 | 648 | } |
@@ -13,58 +13,58 @@ discard block |
||
13 | 13 | class GetPaid_Authorize_Net_Gateway extends GetPaid_Authorize_Net_Legacy_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'authorizenet'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | 34 | public $order = 4; |
35 | 35 | |
36 | 36 | /** |
37 | - * Endpoint for requests from Authorize.net. |
|
38 | - * |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - protected $notify_url; |
|
42 | - |
|
43 | - /** |
|
44 | - * Endpoint for requests to Authorize.net. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
37 | + * Endpoint for requests from Authorize.net. |
|
38 | + * |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + protected $notify_url; |
|
42 | + |
|
43 | + /** |
|
44 | + * Endpoint for requests to Authorize.net. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | 48 | protected $endpoint; |
49 | 49 | |
50 | 50 | /** |
51 | - * Currencies this gateway is allowed for. |
|
52 | - * |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
51 | + * Currencies this gateway is allowed for. |
|
52 | + * |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
56 | 56 | |
57 | 57 | /** |
58 | - * URL to view a transaction. |
|
59 | - * |
|
60 | - * @var string |
|
61 | - */ |
|
58 | + * URL to view a transaction. |
|
59 | + * |
|
60 | + * @var string |
|
61 | + */ |
|
62 | 62 | public $view_transaction_url = 'https://{sandbox}authorize.net/ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=%s'; |
63 | 63 | |
64 | 64 | /** |
65 | - * Class constructor. |
|
66 | - */ |
|
67 | - public function __construct() { |
|
65 | + * Class constructor. |
|
66 | + */ |
|
67 | + public function __construct() { |
|
68 | 68 | |
69 | 69 | $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
70 | 70 | $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
@@ -76,11 +76,11 @@ discard block |
||
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | - * Displays the payment method select field. |
|
80 | - * |
|
81 | - * @param int $invoice_id 0 or invoice id. |
|
82 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
83 | - */ |
|
79 | + * Displays the payment method select field. |
|
80 | + * |
|
81 | + * @param int $invoice_id 0 or invoice id. |
|
82 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
83 | + */ |
|
84 | 84 | public function payment_fields( $invoice_id, $form ) { |
85 | 85 | |
86 | 86 | // Let the user select a payment method. |
@@ -91,16 +91,16 @@ discard block |
||
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
94 | - * Creates a customer profile. |
|
95 | - * |
|
96 | - * |
|
97 | - * @param WPInv_Invoice $invoice Invoice. |
|
94 | + * Creates a customer profile. |
|
95 | + * |
|
96 | + * |
|
97 | + * @param WPInv_Invoice $invoice Invoice. |
|
98 | 98 | * @param array $submission_data Posted checkout fields. |
99 | 99 | * @param bool $save Whether or not to save the payment as a token. |
100 | 100 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
101 | - * @return string|WP_Error Payment profile id. |
|
102 | - */ |
|
103 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
101 | + * @return string|WP_Error Payment profile id. |
|
102 | + */ |
|
103 | + public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
104 | 104 | |
105 | 105 | // Remove non-digits from the number |
106 | 106 | $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -182,14 +182,14 @@ discard block |
||
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
185 | - * Retrieves a customer profile. |
|
186 | - * |
|
187 | - * |
|
188 | - * @param string $profile_id profile id. |
|
189 | - * @return string|WP_Error Profile id. |
|
185 | + * Retrieves a customer profile. |
|
186 | + * |
|
187 | + * |
|
188 | + * @param string $profile_id profile id. |
|
189 | + * @return string|WP_Error Profile id. |
|
190 | 190 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
191 | - */ |
|
192 | - public function get_customer_profile( $profile_id ) { |
|
191 | + */ |
|
192 | + public function get_customer_profile( $profile_id ) { |
|
193 | 193 | |
194 | 194 | // Generate args. |
195 | 195 | $args = array( |
@@ -204,17 +204,17 @@ discard block |
||
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
207 | - * Creates a customer profile. |
|
208 | - * |
|
209 | - * |
|
207 | + * Creates a customer profile. |
|
208 | + * |
|
209 | + * |
|
210 | 210 | * @param string $profile_id profile id. |
211 | - * @param WPInv_Invoice $invoice Invoice. |
|
211 | + * @param WPInv_Invoice $invoice Invoice. |
|
212 | 212 | * @param array $submission_data Posted checkout fields. |
213 | 213 | * @param bool $save Whether or not to save the payment as a token. |
214 | 214 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
215 | - * @return string|WP_Error Profile id. |
|
216 | - */ |
|
217 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
215 | + * @return string|WP_Error Profile id. |
|
216 | + */ |
|
217 | + public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
218 | 218 | |
219 | 219 | // Remove non-digits from the number |
220 | 220 | $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -302,13 +302,13 @@ discard block |
||
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
305 | - * Retrieves payment details from cache. |
|
306 | - * |
|
307 | - * |
|
305 | + * Retrieves payment details from cache. |
|
306 | + * |
|
307 | + * |
|
308 | 308 | * @param array $payment_details. |
309 | - * @return array|false Profile id. |
|
310 | - */ |
|
311 | - public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
309 | + * @return array|false Profile id. |
|
310 | + */ |
|
311 | + public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
312 | 312 | |
313 | 313 | $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
314 | 314 | $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
@@ -333,13 +333,13 @@ discard block |
||
333 | 333 | } |
334 | 334 | |
335 | 335 | /** |
336 | - * Securely adds payment details to cache. |
|
337 | - * |
|
338 | - * |
|
336 | + * Securely adds payment details to cache. |
|
337 | + * |
|
338 | + * |
|
339 | 339 | * @param array $payment_details. |
340 | 340 | * @param string $payment_profile_id. |
341 | - */ |
|
342 | - public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
341 | + */ |
|
342 | + public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
343 | 343 | |
344 | 344 | $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
345 | 345 | $cached_information = is_array( $cached_information ) ? $cached_information : array(); |
@@ -351,15 +351,15 @@ discard block |
||
351 | 351 | } |
352 | 352 | |
353 | 353 | /** |
354 | - * Retrieves a customer payment profile. |
|
355 | - * |
|
356 | - * |
|
357 | - * @param string $customer_profile_id customer profile id. |
|
354 | + * Retrieves a customer payment profile. |
|
355 | + * |
|
356 | + * |
|
357 | + * @param string $customer_profile_id customer profile id. |
|
358 | 358 | * @param string $payment_profile_id payment profile id. |
359 | - * @return string|WP_Error Profile id. |
|
359 | + * @return string|WP_Error Profile id. |
|
360 | 360 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
361 | - */ |
|
362 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
361 | + */ |
|
362 | + public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
363 | 363 | |
364 | 364 | // Generate args. |
365 | 365 | $args = array( |
@@ -375,15 +375,15 @@ discard block |
||
375 | 375 | } |
376 | 376 | |
377 | 377 | /** |
378 | - * Charges a customer payment profile. |
|
379 | - * |
|
378 | + * Charges a customer payment profile. |
|
379 | + * |
|
380 | 380 | * @param string $customer_profile_id customer profile id. |
381 | 381 | * @param string $payment_profile_id payment profile id. |
382 | - * @param WPInv_Invoice $invoice Invoice. |
|
382 | + * @param WPInv_Invoice $invoice Invoice. |
|
383 | 383 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
384 | - * @return WP_Error|object |
|
385 | - */ |
|
386 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
384 | + * @return WP_Error|object |
|
385 | + */ |
|
386 | + public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
387 | 387 | |
388 | 388 | // Generate args. |
389 | 389 | $args = array( |
@@ -429,41 +429,41 @@ discard block |
||
429 | 429 | } |
430 | 430 | |
431 | 431 | /** |
432 | - * Processes a customer charge. |
|
433 | - * |
|
432 | + * Processes a customer charge. |
|
433 | + * |
|
434 | 434 | * @param stdClass $result Api response. |
435 | - * @param WPInv_Invoice $invoice Invoice. |
|
436 | - */ |
|
437 | - public function process_charge_response( $result, $invoice ) { |
|
435 | + * @param WPInv_Invoice $invoice Invoice. |
|
436 | + */ |
|
437 | + public function process_charge_response( $result, $invoice ) { |
|
438 | 438 | |
439 | 439 | wpinv_clear_errors(); |
440 | - $response_code = (int) $result->transactionResponse->responseCode; |
|
440 | + $response_code = (int) $result->transactionResponse->responseCode; |
|
441 | 441 | |
442 | - // Succeeded. |
|
443 | - if ( 1 == $response_code || 4 == $response_code ) { |
|
442 | + // Succeeded. |
|
443 | + if ( 1 == $response_code || 4 == $response_code ) { |
|
444 | 444 | |
445 | - // Maybe set a transaction id. |
|
446 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
447 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
448 | - } |
|
445 | + // Maybe set a transaction id. |
|
446 | + if ( ! empty( $result->transactionResponse->transId ) ) { |
|
447 | + $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
448 | + } |
|
449 | 449 | |
450 | - $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
450 | + $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
451 | 451 | |
452 | - if ( 1 == $response_code ) { |
|
453 | - return $invoice->mark_paid(); |
|
454 | - } |
|
452 | + if ( 1 == $response_code ) { |
|
453 | + return $invoice->mark_paid(); |
|
454 | + } |
|
455 | 455 | |
456 | - $invoice->set_status( 'wpi-onhold' ); |
|
457 | - $invoice->add_note( |
|
456 | + $invoice->set_status( 'wpi-onhold' ); |
|
457 | + $invoice->add_note( |
|
458 | 458 | sprintf( |
459 | 459 | __( 'Held for review: %s', 'invoicing' ), |
460 | 460 | $result->transactionResponse->messages->message[0]->description |
461 | 461 | ) |
462 | - ); |
|
462 | + ); |
|
463 | 463 | |
464 | - return $invoice->save(); |
|
464 | + return $invoice->save(); |
|
465 | 465 | |
466 | - } |
|
466 | + } |
|
467 | 467 | |
468 | 468 | wpinv_set_error( 'card_declined' ); |
469 | 469 | |
@@ -475,13 +475,13 @@ discard block |
||
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
478 | - * Returns payment information. |
|
479 | - * |
|
480 | - * |
|
481 | - * @param array $card Card details. |
|
482 | - * @return array |
|
483 | - */ |
|
484 | - public function get_payment_information( $card ) { |
|
478 | + * Returns payment information. |
|
479 | + * |
|
480 | + * |
|
481 | + * @param array $card Card details. |
|
482 | + * @return array |
|
483 | + */ |
|
484 | + public function get_payment_information( $card ) { |
|
485 | 485 | return array( |
486 | 486 | |
487 | 487 | 'creditCard' => array( |
@@ -494,25 +494,25 @@ discard block |
||
494 | 494 | } |
495 | 495 | |
496 | 496 | /** |
497 | - * Returns the customer profile meta name. |
|
498 | - * |
|
499 | - * |
|
500 | - * @param WPInv_Invoice $invoice Invoice. |
|
501 | - * @return string |
|
502 | - */ |
|
503 | - public function get_customer_profile_meta_name( $invoice ) { |
|
497 | + * Returns the customer profile meta name. |
|
498 | + * |
|
499 | + * |
|
500 | + * @param WPInv_Invoice $invoice Invoice. |
|
501 | + * @return string |
|
502 | + */ |
|
503 | + public function get_customer_profile_meta_name( $invoice ) { |
|
504 | 504 | return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
505 | 505 | } |
506 | 506 | |
507 | 507 | /** |
508 | - * Validates the submitted data. |
|
509 | - * |
|
510 | - * |
|
511 | - * @param array $submission_data Posted checkout fields. |
|
508 | + * Validates the submitted data. |
|
509 | + * |
|
510 | + * |
|
511 | + * @param array $submission_data Posted checkout fields. |
|
512 | 512 | * @param WPInv_Invoice $invoice |
513 | - * @return WP_Error|string The payment profile id |
|
514 | - */ |
|
515 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
513 | + * @return WP_Error|string The payment profile id |
|
514 | + */ |
|
515 | + public function validate_submission_data( $submission_data, $invoice ) { |
|
516 | 516 | |
517 | 517 | // Validate authentication details. |
518 | 518 | $auth = $this->get_auth_params(); |
@@ -544,13 +544,13 @@ discard block |
||
544 | 544 | } |
545 | 545 | |
546 | 546 | /** |
547 | - * Returns invoice line items. |
|
548 | - * |
|
549 | - * |
|
550 | - * @param WPInv_Invoice $invoice Invoice. |
|
551 | - * @return array |
|
552 | - */ |
|
553 | - public function get_line_items( $invoice ) { |
|
547 | + * Returns invoice line items. |
|
548 | + * |
|
549 | + * |
|
550 | + * @param WPInv_Invoice $invoice Invoice. |
|
551 | + * @return array |
|
552 | + */ |
|
553 | + public function get_line_items( $invoice ) { |
|
554 | 554 | $items = array(); |
555 | 555 | |
556 | 556 | foreach ( $invoice->get_items() as $item ) { |
@@ -587,15 +587,15 @@ discard block |
||
587 | 587 | } |
588 | 588 | |
589 | 589 | /** |
590 | - * Process Payment. |
|
591 | - * |
|
592 | - * |
|
593 | - * @param WPInv_Invoice $invoice Invoice. |
|
594 | - * @param array $submission_data Posted checkout fields. |
|
595 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
596 | - * @return array |
|
597 | - */ |
|
598 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
590 | + * Process Payment. |
|
591 | + * |
|
592 | + * |
|
593 | + * @param WPInv_Invoice $invoice Invoice. |
|
594 | + * @param array $submission_data Posted checkout fields. |
|
595 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
596 | + * @return array |
|
597 | + */ |
|
598 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
599 | 599 | |
600 | 600 | // Validate the submitted data. |
601 | 601 | $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
@@ -628,45 +628,45 @@ discard block |
||
628 | 628 | |
629 | 629 | exit; |
630 | 630 | |
631 | - } |
|
631 | + } |
|
632 | 632 | |
633 | - /** |
|
634 | - * Processes the initial payment. |
|
635 | - * |
|
633 | + /** |
|
634 | + * Processes the initial payment. |
|
635 | + * |
|
636 | 636 | * @param WPInv_Invoice $invoice Invoice. |
637 | - */ |
|
638 | - protected function process_initial_payment( $invoice ) { |
|
637 | + */ |
|
638 | + protected function process_initial_payment( $invoice ) { |
|
639 | 639 | |
640 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
640 | + $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
641 | 641 | $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
642 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
642 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
643 | 643 | |
644 | - // Do we have an error? |
|
645 | - if ( is_wp_error( $result ) ) { |
|
646 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
647 | - wpinv_send_back_to_checkout( $invoice ); |
|
648 | - } |
|
644 | + // Do we have an error? |
|
645 | + if ( is_wp_error( $result ) ) { |
|
646 | + wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
647 | + wpinv_send_back_to_checkout( $invoice ); |
|
648 | + } |
|
649 | 649 | |
650 | - // Process the response. |
|
651 | - $this->process_charge_response( $result, $invoice ); |
|
650 | + // Process the response. |
|
651 | + $this->process_charge_response( $result, $invoice ); |
|
652 | 652 | |
653 | - if ( wpinv_get_errors() ) { |
|
654 | - wpinv_send_back_to_checkout( $invoice ); |
|
655 | - } |
|
653 | + if ( wpinv_get_errors() ) { |
|
654 | + wpinv_send_back_to_checkout( $invoice ); |
|
655 | + } |
|
656 | 656 | |
657 | - } |
|
657 | + } |
|
658 | 658 | |
659 | 659 | /** |
660 | - * Processes recurring payments. |
|
661 | - * |
|
660 | + * Processes recurring payments. |
|
661 | + * |
|
662 | 662 | * @param WPInv_Invoice $invoice Invoice. |
663 | 663 | * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions. |
664 | - */ |
|
665 | - public function process_subscription( $invoice, $subscriptions ) { |
|
664 | + */ |
|
665 | + public function process_subscription( $invoice, $subscriptions ) { |
|
666 | 666 | |
667 | 667 | // Check if there is an initial amount to charge. |
668 | 668 | if ( (float) $invoice->get_total() > 0 ) { |
669 | - $this->process_initial_payment( $invoice ); |
|
669 | + $this->process_initial_payment( $invoice ); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | // Activate the subscriptions. |
@@ -684,36 +684,36 @@ discard block |
||
684 | 684 | } |
685 | 685 | } |
686 | 686 | |
687 | - // Redirect to the success page. |
|
687 | + // Redirect to the success page. |
|
688 | 688 | wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
689 | 689 | |
690 | 690 | } |
691 | 691 | |
692 | - /** |
|
693 | - * (Maybe) renews an authorize.net subscription profile. |
|
694 | - * |
|
695 | - * |
|
692 | + /** |
|
693 | + * (Maybe) renews an authorize.net subscription profile. |
|
694 | + * |
|
695 | + * |
|
696 | 696 | * @param WPInv_Subscription $subscription |
697 | - */ |
|
698 | - public function maybe_renew_subscription( $subscription ) { |
|
697 | + */ |
|
698 | + public function maybe_renew_subscription( $subscription ) { |
|
699 | 699 | |
700 | 700 | // Ensure its our subscription && it's active. |
701 | 701 | if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
702 | 702 | $this->renew_subscription( $subscription ); |
703 | 703 | } |
704 | 704 | |
705 | - } |
|
705 | + } |
|
706 | 706 | |
707 | 707 | /** |
708 | - * Renews a subscription. |
|
709 | - * |
|
708 | + * Renews a subscription. |
|
709 | + * |
|
710 | 710 | * @param WPInv_Subscription $subscription |
711 | - */ |
|
712 | - public function renew_subscription( $subscription ) { |
|
711 | + */ |
|
712 | + public function renew_subscription( $subscription ) { |
|
713 | 713 | |
714 | - // Generate the renewal invoice. |
|
715 | - $new_invoice = $subscription->create_payment(); |
|
716 | - $old_invoice = $subscription->get_parent_payment(); |
|
714 | + // Generate the renewal invoice. |
|
715 | + $new_invoice = $subscription->create_payment(); |
|
716 | + $old_invoice = $subscription->get_parent_payment(); |
|
717 | 717 | |
718 | 718 | if ( empty( $new_invoice ) ) { |
719 | 719 | $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
@@ -722,37 +722,37 @@ discard block |
||
722 | 722 | } |
723 | 723 | |
724 | 724 | // Charge the payment method. |
725 | - $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
726 | - $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
727 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
728 | - |
|
729 | - // Do we have an error? |
|
730 | - if ( is_wp_error( $result ) ) { |
|
731 | - |
|
732 | - $old_invoice->add_note( |
|
733 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
734 | - true, |
|
735 | - false, |
|
736 | - true |
|
737 | - ); |
|
738 | - $subscription->failing(); |
|
739 | - return; |
|
740 | - |
|
741 | - } |
|
742 | - |
|
743 | - // Process the response. |
|
744 | - $this->process_charge_response( $result, $new_invoice ); |
|
745 | - |
|
746 | - if ( wpinv_get_errors() ) { |
|
747 | - |
|
748 | - $old_invoice->add_note( |
|
749 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
750 | - true, |
|
751 | - false, |
|
752 | - true |
|
753 | - ); |
|
754 | - $subscription->failing(); |
|
755 | - return; |
|
725 | + $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
726 | + $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
727 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
728 | + |
|
729 | + // Do we have an error? |
|
730 | + if ( is_wp_error( $result ) ) { |
|
731 | + |
|
732 | + $old_invoice->add_note( |
|
733 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
734 | + true, |
|
735 | + false, |
|
736 | + true |
|
737 | + ); |
|
738 | + $subscription->failing(); |
|
739 | + return; |
|
740 | + |
|
741 | + } |
|
742 | + |
|
743 | + // Process the response. |
|
744 | + $this->process_charge_response( $result, $new_invoice ); |
|
745 | + |
|
746 | + if ( wpinv_get_errors() ) { |
|
747 | + |
|
748 | + $old_invoice->add_note( |
|
749 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
750 | + true, |
|
751 | + false, |
|
752 | + true |
|
753 | + ); |
|
754 | + $subscription->failing(); |
|
755 | + return; |
|
756 | 756 | |
757 | 757 | } |
758 | 758 | |
@@ -761,13 +761,13 @@ discard block |
||
761 | 761 | } |
762 | 762 | |
763 | 763 | /** |
764 | - * Processes invoice addons. |
|
765 | - * |
|
766 | - * @param WPInv_Invoice $invoice |
|
767 | - * @param GetPaid_Form_Item[] $items |
|
768 | - * @return WPInv_Invoice |
|
769 | - */ |
|
770 | - public function process_addons( $invoice, $items ) { |
|
764 | + * Processes invoice addons. |
|
765 | + * |
|
766 | + * @param WPInv_Invoice $invoice |
|
767 | + * @param GetPaid_Form_Item[] $items |
|
768 | + * @return WPInv_Invoice |
|
769 | + */ |
|
770 | + public function process_addons( $invoice, $items ) { |
|
771 | 771 | |
772 | 772 | global $getpaid_authorize_addons; |
773 | 773 | |
@@ -786,7 +786,7 @@ discard block |
||
786 | 786 | $invoice->recalculate_total(); |
787 | 787 | |
788 | 788 | $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
789 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
789 | + $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
790 | 790 | |
791 | 791 | add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 ); |
792 | 792 | $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
@@ -801,11 +801,11 @@ discard block |
||
801 | 801 | } |
802 | 802 | |
803 | 803 | /** |
804 | - * Processes invoice addons. |
|
805 | - * |
|
804 | + * Processes invoice addons. |
|
805 | + * |
|
806 | 806 | * @param array $args |
807 | - * @return array |
|
808 | - */ |
|
807 | + * @return array |
|
808 | + */ |
|
809 | 809 | public function filter_addons_request( $args ) { |
810 | 810 | |
811 | 811 | global $getpaid_authorize_addons; |
@@ -839,11 +839,11 @@ discard block |
||
839 | 839 | } |
840 | 840 | |
841 | 841 | /** |
842 | - * Filters the gateway settings. |
|
843 | - * |
|
844 | - * @param array $admin_settings |
|
845 | - */ |
|
846 | - public function admin_settings( $admin_settings ) { |
|
842 | + * Filters the gateway settings. |
|
843 | + * |
|
844 | + * @param array $admin_settings |
|
845 | + */ |
|
846 | + public function admin_settings( $admin_settings ) { |
|
847 | 847 | |
848 | 848 | $currencies = sprintf( |
849 | 849 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -883,7 +883,7 @@ discard block |
||
883 | 883 | 'readonly' => true, |
884 | 884 | ); |
885 | 885 | |
886 | - return $admin_settings; |
|
887 | - } |
|
886 | + return $admin_settings; |
|
887 | + } |
|
888 | 888 | |
889 | 889 | } |
@@ -14,125 +14,125 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class WPInv_Session_Handler extends WPInv_Session { |
16 | 16 | |
17 | - /** |
|
18 | - * Cookie name used for the session. |
|
19 | - * |
|
20 | - * @var string cookie name |
|
21 | - */ |
|
22 | - protected $_cookie; |
|
23 | - |
|
24 | - /** |
|
25 | - * Stores session expiry. |
|
26 | - * |
|
27 | - * @var int session due to expire timestamp |
|
28 | - */ |
|
29 | - protected $_session_expiring; |
|
30 | - |
|
31 | - /** |
|
32 | - * Stores session due to expire timestamp. |
|
33 | - * |
|
34 | - * @var string session expiration timestamp |
|
35 | - */ |
|
36 | - protected $_session_expiration; |
|
37 | - |
|
38 | - /** |
|
39 | - * True when the cookie exists. |
|
40 | - * |
|
41 | - * @var bool Based on whether a cookie exists. |
|
42 | - */ |
|
43 | - protected $_has_cookie = false; |
|
44 | - |
|
45 | - /** |
|
46 | - * Table name for session data. |
|
47 | - * |
|
48 | - * @var string Custom session table name |
|
49 | - */ |
|
50 | - protected $_table; |
|
51 | - |
|
52 | - /** |
|
53 | - * Constructor for the session class. |
|
54 | - */ |
|
55 | - public function old__construct() { |
|
56 | - |
|
57 | - $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH ); |
|
17 | + /** |
|
18 | + * Cookie name used for the session. |
|
19 | + * |
|
20 | + * @var string cookie name |
|
21 | + */ |
|
22 | + protected $_cookie; |
|
23 | + |
|
24 | + /** |
|
25 | + * Stores session expiry. |
|
26 | + * |
|
27 | + * @var int session due to expire timestamp |
|
28 | + */ |
|
29 | + protected $_session_expiring; |
|
30 | + |
|
31 | + /** |
|
32 | + * Stores session due to expire timestamp. |
|
33 | + * |
|
34 | + * @var string session expiration timestamp |
|
35 | + */ |
|
36 | + protected $_session_expiration; |
|
37 | + |
|
38 | + /** |
|
39 | + * True when the cookie exists. |
|
40 | + * |
|
41 | + * @var bool Based on whether a cookie exists. |
|
42 | + */ |
|
43 | + protected $_has_cookie = false; |
|
44 | + |
|
45 | + /** |
|
46 | + * Table name for session data. |
|
47 | + * |
|
48 | + * @var string Custom session table name |
|
49 | + */ |
|
50 | + protected $_table; |
|
51 | + |
|
52 | + /** |
|
53 | + * Constructor for the session class. |
|
54 | + */ |
|
55 | + public function old__construct() { |
|
56 | + |
|
57 | + $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH ); |
|
58 | 58 | add_action( 'init', array( $this, 'init' ), -1 ); |
59 | - add_action( 'wp_logout', array( $this, 'destroy_session' ) ); |
|
60 | - add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 ); |
|
61 | - add_action( 'shutdown', array( $this, 'save_data' ), 20 ); |
|
62 | - |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Init hooks and session data. |
|
67 | - * |
|
68 | - * @since 3.3.0 |
|
69 | - */ |
|
70 | - public function init() { |
|
71 | - $this->init_session_cookie(); |
|
72 | - |
|
73 | - if ( ! is_user_logged_in() ) { |
|
74 | - add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ), 10, 2 ); |
|
75 | - } |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Setup cookie and customer ID. |
|
80 | - * |
|
81 | - * @since 3.6.0 |
|
82 | - */ |
|
83 | - public function init_session_cookie() { |
|
84 | - $cookie = $this->get_session_cookie(); |
|
85 | - |
|
86 | - if ( $cookie ) { |
|
87 | - $this->_customer_id = $cookie[0]; |
|
88 | - $this->_session_expiration = $cookie[1]; |
|
89 | - $this->_session_expiring = $cookie[2]; |
|
90 | - $this->_has_cookie = true; |
|
91 | - $this->_data = $this->get_session_data(); |
|
92 | - |
|
93 | - // If the user logs in, update session. |
|
94 | - if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) { |
|
95 | - $this->_customer_id = get_current_user_id(); |
|
96 | - $this->_dirty = true; |
|
97 | - $this->save_data(); |
|
98 | - $this->set_customer_session_cookie( true ); |
|
99 | - } |
|
100 | - |
|
101 | - // Update session if its close to expiring. |
|
102 | - if ( time() > $this->_session_expiring ) { |
|
103 | - $this->set_session_expiration(); |
|
104 | - $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration ); |
|
105 | - } |
|
106 | - } else { |
|
107 | - $this->set_session_expiration(); |
|
108 | - $this->_customer_id = $this->generate_customer_id(); |
|
109 | - $this->_data = $this->get_session_data(); |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Sets the session cookie on-demand (usually after adding an item to the cart). |
|
115 | - * |
|
116 | - * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set. |
|
117 | - * |
|
118 | - * Warning: Cookies will only be set if this is called before the headers are sent. |
|
119 | - * |
|
120 | - * @param bool $set Should the session cookie be set. |
|
121 | - */ |
|
122 | - public function set_customer_session_cookie( $set ) { |
|
123 | - if ( $set ) { |
|
124 | - $to_hash = $this->_customer_id . '|' . $this->_session_expiration; |
|
125 | - $cookie_hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
126 | - $cookie_value = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash; |
|
127 | - $this->_has_cookie = true; |
|
128 | - |
|
129 | - if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) { |
|
130 | - $this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true ); |
|
131 | - } |
|
132 | - } |
|
133 | - } |
|
134 | - |
|
135 | - public function setcookie( $name, $value, $expire = 0, $secure = false, $httponly = false ) { |
|
59 | + add_action( 'wp_logout', array( $this, 'destroy_session' ) ); |
|
60 | + add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 ); |
|
61 | + add_action( 'shutdown', array( $this, 'save_data' ), 20 ); |
|
62 | + |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Init hooks and session data. |
|
67 | + * |
|
68 | + * @since 3.3.0 |
|
69 | + */ |
|
70 | + public function init() { |
|
71 | + $this->init_session_cookie(); |
|
72 | + |
|
73 | + if ( ! is_user_logged_in() ) { |
|
74 | + add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ), 10, 2 ); |
|
75 | + } |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Setup cookie and customer ID. |
|
80 | + * |
|
81 | + * @since 3.6.0 |
|
82 | + */ |
|
83 | + public function init_session_cookie() { |
|
84 | + $cookie = $this->get_session_cookie(); |
|
85 | + |
|
86 | + if ( $cookie ) { |
|
87 | + $this->_customer_id = $cookie[0]; |
|
88 | + $this->_session_expiration = $cookie[1]; |
|
89 | + $this->_session_expiring = $cookie[2]; |
|
90 | + $this->_has_cookie = true; |
|
91 | + $this->_data = $this->get_session_data(); |
|
92 | + |
|
93 | + // If the user logs in, update session. |
|
94 | + if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) { |
|
95 | + $this->_customer_id = get_current_user_id(); |
|
96 | + $this->_dirty = true; |
|
97 | + $this->save_data(); |
|
98 | + $this->set_customer_session_cookie( true ); |
|
99 | + } |
|
100 | + |
|
101 | + // Update session if its close to expiring. |
|
102 | + if ( time() > $this->_session_expiring ) { |
|
103 | + $this->set_session_expiration(); |
|
104 | + $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration ); |
|
105 | + } |
|
106 | + } else { |
|
107 | + $this->set_session_expiration(); |
|
108 | + $this->_customer_id = $this->generate_customer_id(); |
|
109 | + $this->_data = $this->get_session_data(); |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Sets the session cookie on-demand (usually after adding an item to the cart). |
|
115 | + * |
|
116 | + * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set. |
|
117 | + * |
|
118 | + * Warning: Cookies will only be set if this is called before the headers are sent. |
|
119 | + * |
|
120 | + * @param bool $set Should the session cookie be set. |
|
121 | + */ |
|
122 | + public function set_customer_session_cookie( $set ) { |
|
123 | + if ( $set ) { |
|
124 | + $to_hash = $this->_customer_id . '|' . $this->_session_expiration; |
|
125 | + $cookie_hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
126 | + $cookie_value = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash; |
|
127 | + $this->_has_cookie = true; |
|
128 | + |
|
129 | + if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) { |
|
130 | + $this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true ); |
|
131 | + } |
|
132 | + } |
|
133 | + } |
|
134 | + |
|
135 | + public function setcookie( $name, $value, $expire = 0, $secure = false, $httponly = false ) { |
|
136 | 136 | if ( ! headers_sent() ) { |
137 | 137 | setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters( 'wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure ) ); |
138 | 138 | } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
@@ -141,86 +141,86 @@ discard block |
||
141 | 141 | } |
142 | 142 | } |
143 | 143 | |
144 | - /** |
|
145 | - * Should the session cookie be secure? |
|
146 | - * |
|
147 | - * @since 3.6.0 |
|
148 | - * @return bool |
|
149 | - */ |
|
150 | - protected function use_secure_cookie() { |
|
144 | + /** |
|
145 | + * Should the session cookie be secure? |
|
146 | + * |
|
147 | + * @since 3.6.0 |
|
148 | + * @return bool |
|
149 | + */ |
|
150 | + protected function use_secure_cookie() { |
|
151 | 151 | $is_https = false !== strstr( get_option( 'home' ), 'https:' ); |
152 | - return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() ); |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Return true if the current user has an active session, i.e. a cookie to retrieve values. |
|
157 | - * |
|
158 | - * @return bool |
|
159 | - */ |
|
160 | - public function has_session() { |
|
161 | - return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine. |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Set session expiration. |
|
166 | - */ |
|
167 | - public function set_session_expiration() { |
|
168 | - $this->_session_expiring = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours. |
|
169 | - $this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours. |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Generates session ids. |
|
174 | - * |
|
175 | - * @return string |
|
176 | - */ |
|
177 | - public function generate_customer_id() { |
|
178 | - require_once ABSPATH . 'wp-includes/class-phpass.php'; |
|
179 | - $hasher = new PasswordHash( 8, false ); |
|
180 | - return md5( $hasher->get_random_bytes( 32 ) ); |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * Get the session cookie, if set. Otherwise return false. |
|
185 | - * |
|
186 | - * Session cookies without a customer ID are invalid. |
|
187 | - * |
|
188 | - * @return bool|array |
|
189 | - */ |
|
190 | - public function get_session_cookie() { |
|
191 | - $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine. |
|
192 | - |
|
193 | - if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) { |
|
194 | - return false; |
|
195 | - } |
|
196 | - |
|
197 | - list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value ); |
|
198 | - |
|
199 | - if ( empty( $customer_id ) ) { |
|
200 | - return false; |
|
201 | - } |
|
202 | - |
|
203 | - // Validate hash. |
|
204 | - $to_hash = $customer_id . '|' . $session_expiration; |
|
205 | - $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
206 | - |
|
207 | - if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) { |
|
208 | - return false; |
|
209 | - } |
|
210 | - |
|
211 | - return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash ); |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * Get session data. |
|
216 | - * |
|
217 | - * @return array |
|
218 | - */ |
|
219 | - public function get_session_data() { |
|
220 | - return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array(); |
|
221 | - } |
|
222 | - |
|
223 | - public function generate_key( $customer_id ) { |
|
152 | + return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() ); |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Return true if the current user has an active session, i.e. a cookie to retrieve values. |
|
157 | + * |
|
158 | + * @return bool |
|
159 | + */ |
|
160 | + public function has_session() { |
|
161 | + return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine. |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Set session expiration. |
|
166 | + */ |
|
167 | + public function set_session_expiration() { |
|
168 | + $this->_session_expiring = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours. |
|
169 | + $this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours. |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Generates session ids. |
|
174 | + * |
|
175 | + * @return string |
|
176 | + */ |
|
177 | + public function generate_customer_id() { |
|
178 | + require_once ABSPATH . 'wp-includes/class-phpass.php'; |
|
179 | + $hasher = new PasswordHash( 8, false ); |
|
180 | + return md5( $hasher->get_random_bytes( 32 ) ); |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * Get the session cookie, if set. Otherwise return false. |
|
185 | + * |
|
186 | + * Session cookies without a customer ID are invalid. |
|
187 | + * |
|
188 | + * @return bool|array |
|
189 | + */ |
|
190 | + public function get_session_cookie() { |
|
191 | + $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine. |
|
192 | + |
|
193 | + if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) { |
|
194 | + return false; |
|
195 | + } |
|
196 | + |
|
197 | + list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value ); |
|
198 | + |
|
199 | + if ( empty( $customer_id ) ) { |
|
200 | + return false; |
|
201 | + } |
|
202 | + |
|
203 | + // Validate hash. |
|
204 | + $to_hash = $customer_id . '|' . $session_expiration; |
|
205 | + $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
206 | + |
|
207 | + if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) { |
|
208 | + return false; |
|
209 | + } |
|
210 | + |
|
211 | + return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash ); |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * Get session data. |
|
216 | + * |
|
217 | + * @return array |
|
218 | + */ |
|
219 | + public function get_session_data() { |
|
220 | + return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array(); |
|
221 | + } |
|
222 | + |
|
223 | + public function generate_key( $customer_id ) { |
|
224 | 224 | if ( ! $customer_id ) { |
225 | 225 | return; |
226 | 226 | } |
@@ -228,68 +228,68 @@ discard block |
||
228 | 228 | return 'wpi_trans_' . $customer_id; |
229 | 229 | } |
230 | 230 | |
231 | - /** |
|
232 | - * Save data. |
|
233 | - */ |
|
234 | - public function save_data() { |
|
235 | - // Dirty if something changed - prevents saving nothing new. |
|
236 | - if ( $this->_dirty && $this->has_session() ) { |
|
231 | + /** |
|
232 | + * Save data. |
|
233 | + */ |
|
234 | + public function save_data() { |
|
235 | + // Dirty if something changed - prevents saving nothing new. |
|
236 | + if ( $this->_dirty && $this->has_session() ) { |
|
237 | 237 | |
238 | 238 | set_transient( $this->generate_key( $this->_customer_id ), $this->_data, $this->_session_expiration ); |
239 | 239 | |
240 | - $this->_dirty = false; |
|
241 | - } |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * Destroy all session data. |
|
246 | - */ |
|
247 | - public function destroy_session() { |
|
248 | - $this->delete_session( $this->_customer_id ); |
|
249 | - $this->forget_session(); |
|
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * Forget all session data without destroying it. |
|
254 | - */ |
|
255 | - public function forget_session() { |
|
256 | - $this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true ); |
|
257 | - |
|
258 | - wpinv_empty_cart(); |
|
259 | - |
|
260 | - $this->_data = array(); |
|
261 | - $this->_dirty = false; |
|
262 | - $this->_customer_id = $this->generate_customer_id(); |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * When a user is logged out, ensure they have a unique nonce by using the customer/session ID. |
|
267 | - * |
|
268 | - * @param int $uid User ID. |
|
269 | - * @return string |
|
270 | - */ |
|
271 | - public function nonce_user_logged_out( $uid ) { |
|
272 | - |
|
273 | - // Check if one of our nonces. |
|
274 | - if ( substr( $uid, 0, 5 ) === 'wpinv' || substr( $uid, 0, 7 ) === 'getpaid' ) { |
|
275 | - return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid; |
|
276 | - } |
|
277 | - |
|
278 | - return $uid; |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * Returns the session. |
|
283 | - * |
|
284 | - * @param string $customer_id Customer ID. |
|
285 | - * @param mixed $default Default session value. |
|
286 | - * @return string|array |
|
287 | - */ |
|
288 | - public function get_session( $customer_id, $default = false ) { |
|
289 | - |
|
290 | - if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
291 | - return array(); |
|
292 | - } |
|
240 | + $this->_dirty = false; |
|
241 | + } |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * Destroy all session data. |
|
246 | + */ |
|
247 | + public function destroy_session() { |
|
248 | + $this->delete_session( $this->_customer_id ); |
|
249 | + $this->forget_session(); |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * Forget all session data without destroying it. |
|
254 | + */ |
|
255 | + public function forget_session() { |
|
256 | + $this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true ); |
|
257 | + |
|
258 | + wpinv_empty_cart(); |
|
259 | + |
|
260 | + $this->_data = array(); |
|
261 | + $this->_dirty = false; |
|
262 | + $this->_customer_id = $this->generate_customer_id(); |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * When a user is logged out, ensure they have a unique nonce by using the customer/session ID. |
|
267 | + * |
|
268 | + * @param int $uid User ID. |
|
269 | + * @return string |
|
270 | + */ |
|
271 | + public function nonce_user_logged_out( $uid ) { |
|
272 | + |
|
273 | + // Check if one of our nonces. |
|
274 | + if ( substr( $uid, 0, 5 ) === 'wpinv' || substr( $uid, 0, 7 ) === 'getpaid' ) { |
|
275 | + return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid; |
|
276 | + } |
|
277 | + |
|
278 | + return $uid; |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * Returns the session. |
|
283 | + * |
|
284 | + * @param string $customer_id Customer ID. |
|
285 | + * @param mixed $default Default session value. |
|
286 | + * @return string|array |
|
287 | + */ |
|
288 | + public function get_session( $customer_id, $default = false ) { |
|
289 | + |
|
290 | + if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
291 | + return array(); |
|
292 | + } |
|
293 | 293 | |
294 | 294 | $key = $this->generate_key( $customer_id ); |
295 | 295 | $value = get_transient( $key ); |
@@ -298,30 +298,30 @@ discard block |
||
298 | 298 | $value = $default; |
299 | 299 | } |
300 | 300 | |
301 | - return maybe_unserialize( $value ); |
|
302 | - } |
|
301 | + return maybe_unserialize( $value ); |
|
302 | + } |
|
303 | 303 | |
304 | - /** |
|
305 | - * Delete the session from the cache and database. |
|
306 | - * |
|
307 | - * @param int $customer_id Customer ID. |
|
308 | - */ |
|
309 | - public function delete_session( $customer_id ) { |
|
304 | + /** |
|
305 | + * Delete the session from the cache and database. |
|
306 | + * |
|
307 | + * @param int $customer_id Customer ID. |
|
308 | + */ |
|
309 | + public function delete_session( $customer_id ) { |
|
310 | 310 | |
311 | 311 | $key = $this->generate_key( $customer_id ); |
312 | 312 | |
313 | - delete_transient( $key ); |
|
314 | - } |
|
313 | + delete_transient( $key ); |
|
314 | + } |
|
315 | 315 | |
316 | - /** |
|
317 | - * Update the session expiry timestamp. |
|
318 | - * |
|
319 | - * @param string $customer_id Customer ID. |
|
320 | - * @param int $timestamp Timestamp to expire the cookie. |
|
321 | - */ |
|
322 | - public function update_session_timestamp( $customer_id, $timestamp ) { |
|
316 | + /** |
|
317 | + * Update the session expiry timestamp. |
|
318 | + * |
|
319 | + * @param string $customer_id Customer ID. |
|
320 | + * @param int $timestamp Timestamp to expire the cookie. |
|
321 | + */ |
|
322 | + public function update_session_timestamp( $customer_id, $timestamp ) { |
|
323 | 323 | |
324 | 324 | set_transient( $this->generate_key( $customer_id ), maybe_serialize( $this->_data ), $timestamp ); |
325 | 325 | |
326 | - } |
|
326 | + } |
|
327 | 327 | } |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * |
145 | 145 | */ |
146 | 146 | function wpinv_register_settings() { |
147 | - do_action( 'getpaid_before_register_settings' ); |
|
147 | + do_action( 'getpaid_before_register_settings' ); |
|
148 | 148 | |
149 | 149 | // Loop through all tabs. |
150 | 150 | foreach ( wpinv_get_registered_settings() as $tab => $sections ) { |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | $settings = $sections; |
160 | 160 | } |
161 | 161 | |
162 | - do_action( "getpaid_register_{$tab}_{$section}" ); |
|
162 | + do_action( "getpaid_register_{$tab}_{$section}" ); |
|
163 | 163 | |
164 | 164 | // Register the setting section. |
165 | 165 | add_settings_section( |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | // Creates our settings in the options table. |
181 | 181 | register_setting( 'wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize' ); |
182 | 182 | |
183 | - do_action( 'getpaid_after_register_settings' ); |
|
183 | + do_action( 'getpaid_after_register_settings' ); |
|
184 | 184 | } |
185 | 185 | add_action( 'admin_init', 'wpinv_register_settings' ); |
186 | 186 | |
@@ -197,13 +197,13 @@ discard block |
||
197 | 197 | $name = isset( $option['name'] ) ? $option['name'] : ''; |
198 | 198 | $cb = "wpinv_{$option['type']}_callback"; |
199 | 199 | $section = "wpinv_settings_{$tab}_$section"; |
200 | - $is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page']; |
|
200 | + $is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page']; |
|
201 | 201 | |
202 | - if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) { |
|
203 | - $tip = wpinv_clean( $option['desc'] ); |
|
204 | - $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
|
205 | - unset( $option['desc'] ); |
|
206 | - } |
|
202 | + if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) { |
|
203 | + $tip = wpinv_clean( $option['desc'] ); |
|
204 | + $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
|
205 | + unset( $option['desc'] ); |
|
206 | + } |
|
207 | 207 | |
208 | 208 | // Loop through all tabs. |
209 | 209 | add_settings_field( |
@@ -230,9 +230,9 @@ discard block |
||
230 | 230 | 'faux' => isset( $option['faux'] ) ? $option['faux'] : false, |
231 | 231 | 'onchange' => isset( $option['onchange'] ) ? $option['onchange'] : '', |
232 | 232 | 'custom' => isset( $option['custom'] ) ? $option['custom'] : '', |
233 | - 'default_content' => isset( $option['default_content'] ) ? $option['default_content'] : '', |
|
234 | - 'class' => isset( $option['class'] ) ? $option['class'] : '', |
|
235 | - 'style' => isset( $option['style'] ) ? $option['style'] : '', |
|
233 | + 'default_content' => isset( $option['default_content'] ) ? $option['default_content'] : '', |
|
234 | + 'class' => isset( $option['class'] ) ? $option['class'] : '', |
|
235 | + 'style' => isset( $option['style'] ) ? $option['style'] : '', |
|
236 | 236 | 'cols' => isset( $option['cols'] ) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50, |
237 | 237 | 'rows' => isset( $option['rows'] ) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5, |
238 | 238 | ) |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | * @return array |
247 | 247 | */ |
248 | 248 | function wpinv_get_registered_settings() { |
249 | - return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) ); |
|
249 | + return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) ); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
@@ -265,18 +265,18 @@ discard block |
||
265 | 265 | */ |
266 | 266 | function wpinv_settings_sanitize( $input = array() ) { |
267 | 267 | |
268 | - $wpinv_options = wpinv_get_options(); |
|
269 | - $raw_referrer = wp_get_raw_referer(); |
|
268 | + $wpinv_options = wpinv_get_options(); |
|
269 | + $raw_referrer = wp_get_raw_referer(); |
|
270 | 270 | |
271 | 271 | if ( empty( $raw_referrer ) ) { |
272 | - return array_merge( $wpinv_options, $input ); |
|
272 | + return array_merge( $wpinv_options, $input ); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | wp_parse_str( $raw_referrer, $referrer ); |
276 | 276 | |
277 | - if ( in_array( 'gp-setup', $referrer ) ) { |
|
278 | - return array_merge( $wpinv_options, $input ); |
|
279 | - } |
|
277 | + if ( in_array( 'gp-setup', $referrer ) ) { |
|
278 | + return array_merge( $wpinv_options, $input ); |
|
279 | + } |
|
280 | 280 | |
281 | 281 | $settings = wpinv_get_registered_settings(); |
282 | 282 | $tab = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general'; |
@@ -298,10 +298,10 @@ discard block |
||
298 | 298 | } |
299 | 299 | |
300 | 300 | // General filter |
301 | - $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
301 | + $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
302 | 302 | |
303 | - // Key specific filter. |
|
304 | - $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] ); |
|
303 | + // Key specific filter. |
|
304 | + $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] ); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | // Loop through the whitelist and unset any that are empty for the tab being saved |
@@ -344,14 +344,14 @@ discard block |
||
344 | 344 | |
345 | 345 | foreach ( $new_rates as $rate ) { |
346 | 346 | |
347 | - $rate['rate'] = wpinv_sanitize_amount( $rate['rate'] ); |
|
348 | - $rate['name'] = sanitize_text_field( $rate['name'] ); |
|
349 | - $rate['state'] = sanitize_text_field( $rate['state'] ); |
|
350 | - $rate['country'] = sanitize_text_field( $rate['country'] ); |
|
351 | - $rate['global'] = empty( $rate['state'] ); |
|
352 | - $tax_rates[] = $rate; |
|
347 | + $rate['rate'] = wpinv_sanitize_amount( $rate['rate'] ); |
|
348 | + $rate['name'] = sanitize_text_field( $rate['name'] ); |
|
349 | + $rate['state'] = sanitize_text_field( $rate['state'] ); |
|
350 | + $rate['country'] = sanitize_text_field( $rate['country'] ); |
|
351 | + $rate['global'] = empty( $rate['state'] ); |
|
352 | + $tax_rates[] = $rate; |
|
353 | 353 | |
354 | - } |
|
354 | + } |
|
355 | 355 | |
356 | 356 | update_option( 'wpinv_tax_rates', $tax_rates ); |
357 | 357 | |
@@ -364,21 +364,21 @@ discard block |
||
364 | 364 | return $input; |
365 | 365 | } |
366 | 366 | |
367 | - if ( empty( $_POST['wpinv_tax_rules_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_tax_rules_nonce'], 'wpinv_tax_rules' ) ) { |
|
368 | - return $input; |
|
369 | - } |
|
367 | + if ( empty( $_POST['wpinv_tax_rules_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_tax_rules_nonce'], 'wpinv_tax_rules' ) ) { |
|
368 | + return $input; |
|
369 | + } |
|
370 | 370 | |
371 | 371 | $new_rules = ! empty( $_POST['tax_rules'] ) ? wp_kses_post_deep( array_values( $_POST['tax_rules'] ) ) : array(); |
372 | 372 | $tax_rules = array(); |
373 | 373 | |
374 | 374 | foreach ( $new_rules as $rule ) { |
375 | 375 | |
376 | - $rule['key'] = sanitize_title_with_dashes( $rule['key'] ); |
|
377 | - $rule['label'] = sanitize_text_field( $rule['label'] ); |
|
378 | - $rule['tax_base'] = sanitize_text_field( $rule['tax_base'] ); |
|
379 | - $tax_rules[] = $rule; |
|
376 | + $rule['key'] = sanitize_title_with_dashes( $rule['key'] ); |
|
377 | + $rule['label'] = sanitize_text_field( $rule['label'] ); |
|
378 | + $rule['tax_base'] = sanitize_text_field( $rule['tax_base'] ); |
|
379 | + $tax_rules[] = $rule; |
|
380 | 380 | |
381 | - } |
|
381 | + } |
|
382 | 382 | |
383 | 383 | update_option( 'wpinv_tax_rules', $tax_rules ); |
384 | 384 | |
@@ -391,11 +391,11 @@ discard block |
||
391 | 391 | $tabs['general'] = __( 'General', 'invoicing' ); |
392 | 392 | $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' ); |
393 | 393 | $tabs['taxes'] = __( 'Taxes', 'invoicing' ); |
394 | - $tabs['emails'] = __( 'Emails', 'invoicing' ); |
|
394 | + $tabs['emails'] = __( 'Emails', 'invoicing' ); |
|
395 | 395 | |
396 | - if ( count( getpaid_get_integration_settings() ) > 0 ) { |
|
397 | - $tabs['integrations'] = __( 'Integrations', 'invoicing' ); |
|
398 | - } |
|
396 | + if ( count( getpaid_get_integration_settings() ) > 0 ) { |
|
397 | + $tabs['integrations'] = __( 'Integrations', 'invoicing' ); |
|
398 | + } |
|
399 | 399 | |
400 | 400 | $tabs['privacy'] = __( 'Privacy', 'invoicing' ); |
401 | 401 | $tabs['misc'] = __( 'Misc', 'invoicing' ); |
@@ -426,53 +426,53 @@ discard block |
||
426 | 426 | 'general' => apply_filters( |
427 | 427 | 'wpinv_settings_sections_general', |
428 | 428 | array( |
429 | - 'main' => __( 'General Settings', 'invoicing' ), |
|
430 | - 'page_section' => __( 'Page Settings', 'invoicing' ), |
|
431 | - 'currency_section' => __( 'Currency Settings', 'invoicing' ), |
|
432 | - 'labels' => __( 'Label Texts', 'invoicing' ), |
|
429 | + 'main' => __( 'General Settings', 'invoicing' ), |
|
430 | + 'page_section' => __( 'Page Settings', 'invoicing' ), |
|
431 | + 'currency_section' => __( 'Currency Settings', 'invoicing' ), |
|
432 | + 'labels' => __( 'Label Texts', 'invoicing' ), |
|
433 | 433 | ) |
434 | 434 | ), |
435 | 435 | 'gateways' => apply_filters( |
436 | 436 | 'wpinv_settings_sections_gateways', |
437 | 437 | array( |
438 | - 'main' => __( 'Gateway Settings', 'invoicing' ), |
|
438 | + 'main' => __( 'Gateway Settings', 'invoicing' ), |
|
439 | 439 | ) |
440 | 440 | ), |
441 | 441 | 'taxes' => apply_filters( |
442 | 442 | 'wpinv_settings_sections_taxes', |
443 | 443 | array( |
444 | - 'main' => __( 'Tax Settings', 'invoicing' ), |
|
445 | - 'rules' => __( 'Tax Rules', 'invoicing' ), |
|
446 | - 'rates' => __( 'Tax Rates', 'invoicing' ), |
|
447 | - 'vat' => __( 'EU VAT Settings', 'invoicing' ), |
|
444 | + 'main' => __( 'Tax Settings', 'invoicing' ), |
|
445 | + 'rules' => __( 'Tax Rules', 'invoicing' ), |
|
446 | + 'rates' => __( 'Tax Rates', 'invoicing' ), |
|
447 | + 'vat' => __( 'EU VAT Settings', 'invoicing' ), |
|
448 | 448 | ) |
449 | 449 | ), |
450 | 450 | 'emails' => apply_filters( |
451 | 451 | 'wpinv_settings_sections_emails', |
452 | 452 | array( |
453 | - 'main' => __( 'Email Settings', 'invoicing' ), |
|
453 | + 'main' => __( 'Email Settings', 'invoicing' ), |
|
454 | 454 | ) |
455 | 455 | ), |
456 | 456 | |
457 | - 'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ), |
|
457 | + 'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ), |
|
458 | 458 | |
459 | 459 | 'privacy' => apply_filters( |
460 | 460 | 'wpinv_settings_sections_privacy', |
461 | 461 | array( |
462 | - 'main' => __( 'Privacy policy', 'invoicing' ), |
|
462 | + 'main' => __( 'Privacy policy', 'invoicing' ), |
|
463 | 463 | ) |
464 | 464 | ), |
465 | 465 | 'misc' => apply_filters( |
466 | 466 | 'wpinv_settings_sections_misc', |
467 | 467 | array( |
468 | - 'main' => __( 'Miscellaneous', 'invoicing' ), |
|
469 | - 'custom-css' => __( 'Custom CSS', 'invoicing' ), |
|
468 | + 'main' => __( 'Miscellaneous', 'invoicing' ), |
|
469 | + 'custom-css' => __( 'Custom CSS', 'invoicing' ), |
|
470 | 470 | ) |
471 | 471 | ), |
472 | 472 | 'tools' => apply_filters( |
473 | 473 | 'wpinv_settings_sections_tools', |
474 | 474 | array( |
475 | - 'main' => __( 'Diagnostic Tools', 'invoicing' ), |
|
475 | + 'main' => __( 'Diagnostic Tools', 'invoicing' ), |
|
476 | 476 | ) |
477 | 477 | ), |
478 | 478 | ); |
@@ -483,46 +483,46 @@ discard block |
||
483 | 483 | } |
484 | 484 | |
485 | 485 | function wpinv_get_pages( $with_slug = false, $default_label = null ) { |
486 | - $pages_options = array(); |
|
486 | + $pages_options = array(); |
|
487 | 487 | |
488 | - if ( $default_label !== null && $default_label !== false ) { |
|
489 | - $pages_options = array( '' => $default_label ); // Blank option |
|
490 | - } |
|
488 | + if ( $default_label !== null && $default_label !== false ) { |
|
489 | + $pages_options = array( '' => $default_label ); // Blank option |
|
490 | + } |
|
491 | 491 | |
492 | - $pages = get_pages(); |
|
493 | - if ( $pages ) { |
|
494 | - foreach ( $pages as $page ) { |
|
495 | - $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
492 | + $pages = get_pages(); |
|
493 | + if ( $pages ) { |
|
494 | + foreach ( $pages as $page ) { |
|
495 | + $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
496 | 496 | $pages_options[ $page->ID ] = $title; |
497 | - } |
|
498 | - } |
|
497 | + } |
|
498 | + } |
|
499 | 499 | |
500 | - return $pages_options; |
|
500 | + return $pages_options; |
|
501 | 501 | } |
502 | 502 | |
503 | 503 | function wpinv_header_callback( $args ) { |
504 | - if ( ! empty( $args['desc'] ) ) { |
|
504 | + if ( ! empty( $args['desc'] ) ) { |
|
505 | 505 | echo wp_kses_post( $args['desc'] ); |
506 | 506 | } |
507 | 507 | } |
508 | 508 | |
509 | 509 | function wpinv_hidden_callback( $args ) { |
510 | 510 | |
511 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
512 | - $value = wpinv_get_option( $args['id'], $std ); |
|
511 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
512 | + $value = wpinv_get_option( $args['id'], $std ); |
|
513 | 513 | |
514 | - if ( isset( $args['set_value'] ) ) { |
|
515 | - $value = $args['set_value']; |
|
516 | - } |
|
514 | + if ( isset( $args['set_value'] ) ) { |
|
515 | + $value = $args['set_value']; |
|
516 | + } |
|
517 | 517 | |
518 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
519 | - $args['readonly'] = true; |
|
520 | - $name = ''; |
|
521 | - } else { |
|
522 | - $name = 'wpinv_settings[' . esc_attr( $args['id'] ) . ']'; |
|
523 | - } |
|
518 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
519 | + $args['readonly'] = true; |
|
520 | + $name = ''; |
|
521 | + } else { |
|
522 | + $name = 'wpinv_settings[' . esc_attr( $args['id'] ) . ']'; |
|
523 | + } |
|
524 | 524 | |
525 | - echo '<input type="hidden" id="wpinv_settings[' . esc_attr( $args['id'] ) . ']" name="' . esc_attr( $name ) . '" value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
525 | + echo '<input type="hidden" id="wpinv_settings[' . esc_attr( $args['id'] ) . ']" name="' . esc_attr( $name ) . '" value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
526 | 526 | |
527 | 527 | } |
528 | 528 | |
@@ -531,12 +531,12 @@ discard block |
||
531 | 531 | */ |
532 | 532 | function wpinv_checkbox_callback( $args ) { |
533 | 533 | |
534 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
535 | - $std = wpinv_get_option( $args['id'], $std ); |
|
536 | - $id = esc_attr( $args['id'] ); |
|
534 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
535 | + $std = wpinv_get_option( $args['id'], $std ); |
|
536 | + $id = esc_attr( $args['id'] ); |
|
537 | 537 | |
538 | - getpaid_hidden_field( "wpinv_settings[$id]", '0' ); |
|
539 | - ?> |
|
538 | + getpaid_hidden_field( "wpinv_settings[$id]", '0' ); |
|
539 | + ?> |
|
540 | 540 | <fieldset> |
541 | 541 | <label> |
542 | 542 | <input id="wpinv-settings-<?php echo esc_attr( $id ); ?>" name="wpinv_settings[<?php echo esc_attr( $id ); ?>]" <?php checked( empty( $std ), false ); ?> value="1" type="checkbox" /> |
@@ -548,75 +548,75 @@ discard block |
||
548 | 548 | |
549 | 549 | function wpinv_multicheck_callback( $args ) { |
550 | 550 | |
551 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
552 | - $class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
551 | + $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
552 | + $class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
553 | 553 | |
554 | - if ( ! empty( $args['options'] ) ) { |
|
554 | + if ( ! empty( $args['options'] ) ) { |
|
555 | 555 | |
556 | - $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
557 | - $value = wpinv_get_option( $args['id'], $std ); |
|
556 | + $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
557 | + $value = wpinv_get_option( $args['id'], $std ); |
|
558 | 558 | |
559 | - echo '<div class="wpi-mcheck-rows wpi-mcheck-' . esc_attr( $sanitize_id . $class ) . '">'; |
|
559 | + echo '<div class="wpi-mcheck-rows wpi-mcheck-' . esc_attr( $sanitize_id . $class ) . '">'; |
|
560 | 560 | foreach ( $args['options'] as $key => $option ) : |
561 | - $sanitize_key = esc_attr( wpinv_sanitize_key( $key ) ); |
|
562 | - if ( in_array( $sanitize_key, $value ) ) { |
|
563 | - $enabled = $sanitize_key; |
|
564 | - } else { |
|
565 | - $enabled = null; |
|
566 | - } |
|
567 | - echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
568 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
569 | - endforeach; |
|
570 | - echo '</div>'; |
|
571 | - echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
572 | - } |
|
561 | + $sanitize_key = esc_attr( wpinv_sanitize_key( $key ) ); |
|
562 | + if ( in_array( $sanitize_key, $value ) ) { |
|
563 | + $enabled = $sanitize_key; |
|
564 | + } else { |
|
565 | + $enabled = null; |
|
566 | + } |
|
567 | + echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
568 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
569 | + endforeach; |
|
570 | + echo '</div>'; |
|
571 | + echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
572 | + } |
|
573 | 573 | } |
574 | 574 | |
575 | 575 | function wpinv_payment_icons_callback( $args ) { |
576 | 576 | |
577 | 577 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
578 | - $value = wpinv_get_option( $args['id'], false ); |
|
578 | + $value = wpinv_get_option( $args['id'], false ); |
|
579 | 579 | |
580 | - if ( ! empty( $args['options'] ) ) { |
|
581 | - foreach ( $args['options'] as $key => $option ) { |
|
580 | + if ( ! empty( $args['options'] ) ) { |
|
581 | + foreach ( $args['options'] as $key => $option ) { |
|
582 | 582 | $sanitize_key = wpinv_sanitize_key( $key ); |
583 | 583 | |
584 | - if ( empty( $value ) ) { |
|
585 | - $enabled = $option; |
|
586 | - } else { |
|
587 | - $enabled = null; |
|
588 | - } |
|
589 | - |
|
590 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
591 | - |
|
592 | - echo '<input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
593 | - |
|
594 | - if ( wpinv_string_is_image_url( $key ) ) { |
|
595 | - echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
596 | - } else { |
|
597 | - $card = strtolower( str_replace( ' ', '', $option ) ); |
|
598 | - |
|
599 | - if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
600 | - $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
601 | - } else { |
|
602 | - $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
603 | - $content_dir = WP_CONTENT_DIR; |
|
604 | - |
|
605 | - if ( function_exists( 'wp_normalize_path' ) ) { |
|
606 | - // Replaces backslashes with forward slashes for Windows systems |
|
607 | - $image = wp_normalize_path( $image ); |
|
608 | - $content_dir = wp_normalize_path( $content_dir ); |
|
609 | - } |
|
610 | - |
|
611 | - $image = str_replace( $content_dir, content_url(), $image ); |
|
612 | - } |
|
613 | - |
|
614 | - echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
615 | - } |
|
616 | - echo wp_kses_post( $option ) . '</label>'; |
|
617 | - } |
|
618 | - echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
619 | - } |
|
584 | + if ( empty( $value ) ) { |
|
585 | + $enabled = $option; |
|
586 | + } else { |
|
587 | + $enabled = null; |
|
588 | + } |
|
589 | + |
|
590 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
591 | + |
|
592 | + echo '<input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
593 | + |
|
594 | + if ( wpinv_string_is_image_url( $key ) ) { |
|
595 | + echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
596 | + } else { |
|
597 | + $card = strtolower( str_replace( ' ', '', $option ) ); |
|
598 | + |
|
599 | + if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
600 | + $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
601 | + } else { |
|
602 | + $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
603 | + $content_dir = WP_CONTENT_DIR; |
|
604 | + |
|
605 | + if ( function_exists( 'wp_normalize_path' ) ) { |
|
606 | + // Replaces backslashes with forward slashes for Windows systems |
|
607 | + $image = wp_normalize_path( $image ); |
|
608 | + $content_dir = wp_normalize_path( $content_dir ); |
|
609 | + } |
|
610 | + |
|
611 | + $image = str_replace( $content_dir, content_url(), $image ); |
|
612 | + } |
|
613 | + |
|
614 | + echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
615 | + } |
|
616 | + echo wp_kses_post( $option ) . '</label>'; |
|
617 | + } |
|
618 | + echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
619 | + } |
|
620 | 620 | } |
621 | 621 | |
622 | 622 | /** |
@@ -624,9 +624,9 @@ discard block |
||
624 | 624 | */ |
625 | 625 | function wpinv_radio_callback( $args ) { |
626 | 626 | |
627 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
628 | - $std = wpinv_get_option( $args['id'], $std ); |
|
629 | - ?> |
|
627 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
628 | + $std = wpinv_get_option( $args['id'], $std ); |
|
629 | + ?> |
|
630 | 630 | <fieldset> |
631 | 631 | <ul id="wpinv-settings-<?php echo esc_attr( $args['id'] ); ?>" style="margin-top: 0;"> |
632 | 632 | <?php foreach ( $args['options'] as $key => $option ) : ?> |
@@ -640,7 +640,7 @@ discard block |
||
640 | 640 | </ul> |
641 | 641 | </fieldset> |
642 | 642 | <?php |
643 | - getpaid_settings_description_callback( $args ); |
|
643 | + getpaid_settings_description_callback( $args ); |
|
644 | 644 | } |
645 | 645 | |
646 | 646 | /** |
@@ -648,10 +648,10 @@ discard block |
||
648 | 648 | */ |
649 | 649 | function getpaid_settings_description_callback( $args ) { |
650 | 650 | |
651 | - if ( ! empty( $args['desc'] ) ) { |
|
652 | - $description = $args['desc']; |
|
653 | - echo wp_kses_post( "<p class='description'>$description</p>" ); |
|
654 | - } |
|
651 | + if ( ! empty( $args['desc'] ) ) { |
|
652 | + $description = $args['desc']; |
|
653 | + echo wp_kses_post( "<p class='description'>$description</p>" ); |
|
654 | + } |
|
655 | 655 | |
656 | 656 | } |
657 | 657 | |
@@ -660,7 +660,7 @@ discard block |
||
660 | 660 | */ |
661 | 661 | function wpinv_gateways_callback() { |
662 | 662 | |
663 | - ?> |
|
663 | + ?> |
|
664 | 664 | </td> |
665 | 665 | </tr> |
666 | 666 | <tr class="bsui"> |
@@ -674,26 +674,26 @@ discard block |
||
674 | 674 | |
675 | 675 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
676 | 676 | $class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
677 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
678 | - $value = wpinv_get_option( $args['id'], $std ); |
|
677 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
678 | + $value = wpinv_get_option( $args['id'], $std ); |
|
679 | 679 | |
680 | - echo '<select name="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" class="' . esc_attr( $class ) . '" >'; |
|
680 | + echo '<select name="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" class="' . esc_attr( $class ) . '" >'; |
|
681 | 681 | |
682 | - foreach ( $args['options'] as $key => $option ) : |
|
682 | + foreach ( $args['options'] as $key => $option ) : |
|
683 | 683 | |
684 | - echo '<option value="' . esc_attr( $key ) . '" '; |
|
684 | + echo '<option value="' . esc_attr( $key ) . '" '; |
|
685 | 685 | |
686 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
686 | + if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
687 | 687 | selected( $key, $args['selected'] ); |
688 | 688 | } else { |
689 | 689 | selected( $key, $value ); |
690 | 690 | } |
691 | 691 | |
692 | - echo '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
693 | - endforeach; |
|
692 | + echo '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
693 | + endforeach; |
|
694 | 694 | |
695 | - echo '</select>'; |
|
696 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
695 | + echo '</select>'; |
|
696 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
697 | 697 | } |
698 | 698 | |
699 | 699 | /** |
@@ -704,38 +704,38 @@ discard block |
||
704 | 704 | */ |
705 | 705 | function wpinv_settings_attrs_helper( $args ) { |
706 | 706 | |
707 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
708 | - $id = esc_attr( $args['id'] ); |
|
709 | - $value = is_scalar( $value ) ? $value : ''; |
|
710 | - |
|
711 | - $attrs = array( |
|
712 | - 'name' => ! empty( $args['faux'] ) ? false : "wpinv_settings[$id]", |
|
713 | - 'readonly' => ! empty( $args['faux'] ), |
|
714 | - 'value' => ! empty( $args['faux'] ) ? $value : wpinv_get_option( $args['id'], $value ), |
|
715 | - 'id' => 'wpinv-settings-' . $args['id'], |
|
716 | - 'style' => $args['style'], |
|
717 | - 'class' => $args['class'], |
|
718 | - 'placeholder' => $args['placeholder'], |
|
719 | - 'data-placeholder' => $args['placeholder'], |
|
720 | - ); |
|
707 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
708 | + $id = esc_attr( $args['id'] ); |
|
709 | + $value = is_scalar( $value ) ? $value : ''; |
|
710 | + |
|
711 | + $attrs = array( |
|
712 | + 'name' => ! empty( $args['faux'] ) ? false : "wpinv_settings[$id]", |
|
713 | + 'readonly' => ! empty( $args['faux'] ), |
|
714 | + 'value' => ! empty( $args['faux'] ) ? $value : wpinv_get_option( $args['id'], $value ), |
|
715 | + 'id' => 'wpinv-settings-' . $args['id'], |
|
716 | + 'style' => $args['style'], |
|
717 | + 'class' => $args['class'], |
|
718 | + 'placeholder' => $args['placeholder'], |
|
719 | + 'data-placeholder' => $args['placeholder'], |
|
720 | + ); |
|
721 | 721 | |
722 | - if ( ! empty( $args['onchange'] ) ) { |
|
723 | - $attrs['onchange'] = $args['onchange']; |
|
724 | - } |
|
722 | + if ( ! empty( $args['onchange'] ) ) { |
|
723 | + $attrs['onchange'] = $args['onchange']; |
|
724 | + } |
|
725 | 725 | |
726 | - foreach ( $attrs as $key => $value ) { |
|
726 | + foreach ( $attrs as $key => $value ) { |
|
727 | 727 | |
728 | - if ( false === $value ) { |
|
729 | - continue; |
|
730 | - } |
|
728 | + if ( false === $value ) { |
|
729 | + continue; |
|
730 | + } |
|
731 | 731 | |
732 | - if ( true === $value ) { |
|
733 | - echo ' ' . esc_attr( $key ); |
|
734 | - } else { |
|
735 | - echo ' ' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
736 | - } |
|
732 | + if ( true === $value ) { |
|
733 | + echo ' ' . esc_attr( $key ); |
|
734 | + } else { |
|
735 | + echo ' ' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
736 | + } |
|
737 | 737 | |
738 | - } |
|
738 | + } |
|
739 | 739 | |
740 | 740 | } |
741 | 741 | |
@@ -744,7 +744,7 @@ discard block |
||
744 | 744 | */ |
745 | 745 | function wpinv_text_callback( $args ) { |
746 | 746 | |
747 | - ?> |
|
747 | + ?> |
|
748 | 748 | <label style="width: 100%;"> |
749 | 749 | <input type="text" <?php wpinv_settings_attrs_helper( $args ); ?>> |
750 | 750 | <?php getpaid_settings_description_callback( $args ); ?> |
@@ -758,7 +758,7 @@ discard block |
||
758 | 758 | */ |
759 | 759 | function wpinv_number_callback( $args ) { |
760 | 760 | |
761 | - ?> |
|
761 | + ?> |
|
762 | 762 | <label style="width: 100%;"> |
763 | 763 | <input type="number" step="<?php echo esc_attr( $args['step'] ); ?>" max="<?php echo intval( $args['max'] ); ?>" min="<?php echo intval( $args['min'] ); ?>" <?php wpinv_settings_attrs_helper( $args ); ?>> |
764 | 764 | <?php getpaid_settings_description_callback( $args ); ?> |
@@ -770,34 +770,34 @@ discard block |
||
770 | 770 | function wpinv_textarea_callback( $args ) { |
771 | 771 | |
772 | 772 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
773 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
774 | - $value = wpinv_get_option( $args['id'], $std ); |
|
773 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
774 | + $value = wpinv_get_option( $args['id'], $std ); |
|
775 | 775 | |
776 | 776 | $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
777 | 777 | $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text'; |
778 | 778 | |
779 | - echo '<textarea class="' . esc_attr( $class ) . ' txtarea-' . esc_attr( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . esc_attr( $args['cols'] ) . '" rows="' . esc_attr( $args['rows'] ) . '" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
780 | - echo '<br /><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
779 | + echo '<textarea class="' . esc_attr( $class ) . ' txtarea-' . esc_attr( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . esc_attr( $args['cols'] ) . '" rows="' . esc_attr( $args['rows'] ) . '" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
780 | + echo '<br /><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
781 | 781 | |
782 | 782 | } |
783 | 783 | |
784 | 784 | function wpinv_password_callback( $args ) { |
785 | 785 | |
786 | 786 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
787 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
788 | - $value = wpinv_get_option( $args['id'], $std ); |
|
787 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
788 | + $value = wpinv_get_option( $args['id'], $std ); |
|
789 | 789 | |
790 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
791 | - echo '<input type="password" class="' . esc_attr( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
792 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
790 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
791 | + echo '<input type="password" class="' . esc_attr( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
792 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
793 | 793 | |
794 | 794 | } |
795 | 795 | |
796 | 796 | function wpinv_missing_callback( $args ) { |
797 | - printf( |
|
798 | - esc_html__( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
799 | - '<strong>' . esc_html( $args['id'] ) . '</strong>' |
|
800 | - ); |
|
797 | + printf( |
|
798 | + esc_html__( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
799 | + '<strong>' . esc_html( $args['id'] ) . '</strong>' |
|
800 | + ); |
|
801 | 801 | } |
802 | 802 | |
803 | 803 | /** |
@@ -805,13 +805,13 @@ discard block |
||
805 | 805 | */ |
806 | 806 | function wpinv_select_callback( $args ) { |
807 | 807 | |
808 | - $desc = wp_kses_post( $args['desc'] ); |
|
809 | - $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
810 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
811 | - $value = wpinv_get_option( $args['id'], $value ); |
|
812 | - $rand = uniqid( 'random_id' ); |
|
808 | + $desc = wp_kses_post( $args['desc'] ); |
|
809 | + $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
810 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
811 | + $value = wpinv_get_option( $args['id'], $value ); |
|
812 | + $rand = uniqid( 'random_id' ); |
|
813 | 813 | |
814 | - ?> |
|
814 | + ?> |
|
815 | 815 | <label style="width: 100%;"> |
816 | 816 | <select <?php wpinv_settings_attrs_helper( $args ); ?> data-allow-clear="true"> |
817 | 817 | <?php foreach ( $args['options'] as $option => $name ) : ?> |
@@ -844,50 +844,50 @@ discard block |
||
844 | 844 | function wpinv_color_select_callback( $args ) { |
845 | 845 | |
846 | 846 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
847 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
848 | - $value = wpinv_get_option( $args['id'], $std ); |
|
847 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
848 | + $value = wpinv_get_option( $args['id'], $std ); |
|
849 | 849 | |
850 | - echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
850 | + echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
851 | 851 | |
852 | - foreach ( $args['options'] as $option => $color ) { |
|
853 | - echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $color['label'] ) . '</option>'; |
|
854 | - } |
|
852 | + foreach ( $args['options'] as $option => $color ) { |
|
853 | + echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $color['label'] ) . '</option>'; |
|
854 | + } |
|
855 | 855 | |
856 | - echo '</select>'; |
|
857 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
856 | + echo '</select>'; |
|
857 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
858 | 858 | |
859 | 859 | } |
860 | 860 | |
861 | 861 | function wpinv_rich_editor_callback( $args ) { |
862 | - global $wp_version; |
|
862 | + global $wp_version; |
|
863 | 863 | |
864 | 864 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
865 | 865 | |
866 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
867 | - $value = wpinv_get_option( $args['id'], $std ); |
|
866 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
867 | + $value = wpinv_get_option( $args['id'], $std ); |
|
868 | 868 | |
869 | - if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
870 | - $value = $std; |
|
871 | - } |
|
869 | + if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
870 | + $value = $std; |
|
871 | + } |
|
872 | 872 | |
873 | - $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
873 | + $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
874 | 874 | |
875 | - echo '<div class="getpaid-settings-editor-input">'; |
|
876 | - if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
877 | - wp_editor( |
|
875 | + echo '<div class="getpaid-settings-editor-input">'; |
|
876 | + if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
877 | + wp_editor( |
|
878 | 878 | stripslashes( $value ), |
879 | 879 | 'wpinv_settings_' . esc_attr( $args['id'] ), |
880 | 880 | array( |
881 | - 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', |
|
882 | - 'textarea_rows' => absint( $rows ), |
|
883 | - 'media_buttons' => false, |
|
881 | + 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', |
|
882 | + 'textarea_rows' => absint( $rows ), |
|
883 | + 'media_buttons' => false, |
|
884 | 884 | ) |
885 | 885 | ); |
886 | - } else { |
|
887 | - echo '<textarea class="large-text" rows="10" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
888 | - } |
|
886 | + } else { |
|
887 | + echo '<textarea class="large-text" rows="10" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
888 | + } |
|
889 | 889 | |
890 | - echo '</div><br/><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
890 | + echo '</div><br/><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
891 | 891 | |
892 | 892 | } |
893 | 893 | |
@@ -895,51 +895,51 @@ discard block |
||
895 | 895 | |
896 | 896 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
897 | 897 | |
898 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
899 | - $value = wpinv_get_option( $args['id'], $std ); |
|
898 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
899 | + $value = wpinv_get_option( $args['id'], $std ); |
|
900 | 900 | |
901 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
902 | - echo '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
903 | - echo '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . esc_attr__( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
904 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
901 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
902 | + echo '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
903 | + echo '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . esc_attr__( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
904 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
905 | 905 | |
906 | 906 | } |
907 | 907 | |
908 | 908 | function wpinv_color_callback( $args ) { |
909 | 909 | |
910 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
911 | - $value = wpinv_get_option( $args['id'], $std ); |
|
910 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
911 | + $value = wpinv_get_option( $args['id'], $std ); |
|
912 | 912 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
913 | 913 | |
914 | - echo '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $std ) . '" />'; |
|
915 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
914 | + echo '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $std ) . '" />'; |
|
915 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
916 | 916 | |
917 | 917 | } |
918 | 918 | |
919 | 919 | function wpinv_country_states_callback( $args ) { |
920 | 920 | |
921 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
922 | - $value = wpinv_get_option( $args['id'], $std ); |
|
921 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
922 | + $value = wpinv_get_option( $args['id'], $std ); |
|
923 | 923 | |
924 | 924 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
925 | 925 | |
926 | - if ( isset( $args['placeholder'] ) ) { |
|
927 | - $placeholder = $args['placeholder']; |
|
928 | - } else { |
|
929 | - $placeholder = ''; |
|
930 | - } |
|
926 | + if ( isset( $args['placeholder'] ) ) { |
|
927 | + $placeholder = $args['placeholder']; |
|
928 | + } else { |
|
929 | + $placeholder = ''; |
|
930 | + } |
|
931 | 931 | |
932 | - $states = wpinv_get_country_states(); |
|
932 | + $states = wpinv_get_country_states(); |
|
933 | 933 | |
934 | - $class = empty( $states ) ? 'wpinv-no-states' : 'wpi_select2'; |
|
935 | - echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="' . esc_attr( $class ) . '" data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
934 | + $class = empty( $states ) ? 'wpinv-no-states' : 'wpi_select2'; |
|
935 | + echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="' . esc_attr( $class ) . '" data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
936 | 936 | |
937 | - foreach ( $states as $option => $name ) { |
|
938 | - echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $name ) . '</option>'; |
|
939 | - } |
|
937 | + foreach ( $states as $option => $name ) { |
|
938 | + echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $name ) . '</option>'; |
|
939 | + } |
|
940 | 940 | |
941 | - echo '</select>'; |
|
942 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
941 | + echo '</select>'; |
|
942 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
943 | 943 | |
944 | 944 | } |
945 | 945 | |
@@ -948,7 +948,7 @@ discard block |
||
948 | 948 | */ |
949 | 949 | function wpinv_tax_rates_callback() { |
950 | 950 | |
951 | - ?> |
|
951 | + ?> |
|
952 | 952 | </td> |
953 | 953 | </tr> |
954 | 954 | <tr class="bsui"> |
@@ -964,9 +964,9 @@ discard block |
||
964 | 964 | */ |
965 | 965 | function wpinv_tax_rate_callback( $tax_rate, $key ) { |
966 | 966 | |
967 | - $key = sanitize_key( $key ); |
|
968 | - $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate']; |
|
969 | - include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php'; |
|
967 | + $key = sanitize_key( $key ); |
|
968 | + $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate']; |
|
969 | + include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php'; |
|
970 | 970 | |
971 | 971 | } |
972 | 972 | |
@@ -975,7 +975,7 @@ discard block |
||
975 | 975 | */ |
976 | 976 | function wpinv_tax_rules_callback() { |
977 | 977 | |
978 | - ?> |
|
978 | + ?> |
|
979 | 979 | </td> |
980 | 980 | </tr> |
981 | 981 | <tr class="bsui"> |
@@ -1013,14 +1013,14 @@ discard block |
||
1013 | 1013 | <td> |
1014 | 1014 | <a href=" |
1015 | 1015 | <?php |
1016 | - echo esc_url( |
|
1017 | - wp_nonce_url( |
|
1018 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
1019 | - 'getpaid-nonce', |
|
1020 | - 'getpaid-nonce' |
|
1021 | - ) |
|
1022 | - ); |
|
1023 | - ?> |
|
1016 | + echo esc_url( |
|
1017 | + wp_nonce_url( |
|
1018 | + add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
1019 | + 'getpaid-nonce', |
|
1020 | + 'getpaid-nonce' |
|
1021 | + ) |
|
1022 | + ); |
|
1023 | + ?> |
|
1024 | 1024 | " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a> |
1025 | 1025 | </td> |
1026 | 1026 | </tr> |
@@ -1032,14 +1032,14 @@ discard block |
||
1032 | 1032 | <td> |
1033 | 1033 | <a href=" |
1034 | 1034 | <?php |
1035 | - echo esc_url( |
|
1036 | - wp_nonce_url( |
|
1037 | - add_query_arg( 'getpaid-admin-action', 'refresh_permalinks' ), |
|
1038 | - 'getpaid-nonce', |
|
1039 | - 'getpaid-nonce' |
|
1040 | - ) |
|
1041 | - ); |
|
1042 | - ?> |
|
1035 | + echo esc_url( |
|
1036 | + wp_nonce_url( |
|
1037 | + add_query_arg( 'getpaid-admin-action', 'refresh_permalinks' ), |
|
1038 | + 'getpaid-nonce', |
|
1039 | + 'getpaid-nonce' |
|
1040 | + ) |
|
1041 | + ); |
|
1042 | + ?> |
|
1043 | 1043 | " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a> |
1044 | 1044 | </td> |
1045 | 1045 | </tr> |
@@ -1051,14 +1051,14 @@ discard block |
||
1051 | 1051 | <td> |
1052 | 1052 | <a href=" |
1053 | 1053 | <?php |
1054 | - echo esc_url( |
|
1055 | - wp_nonce_url( |
|
1056 | - add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ), |
|
1057 | - 'getpaid-nonce', |
|
1058 | - 'getpaid-nonce' |
|
1059 | - ) |
|
1060 | - ); |
|
1061 | - ?> |
|
1054 | + echo esc_url( |
|
1055 | + wp_nonce_url( |
|
1056 | + add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ), |
|
1057 | + 'getpaid-nonce', |
|
1058 | + 'getpaid-nonce' |
|
1059 | + ) |
|
1060 | + ); |
|
1061 | + ?> |
|
1062 | 1062 | " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a> |
1063 | 1063 | </td> |
1064 | 1064 | </tr> |
@@ -1070,14 +1070,14 @@ discard block |
||
1070 | 1070 | <td> |
1071 | 1071 | <a href=" |
1072 | 1072 | <?php |
1073 | - echo esc_url( |
|
1074 | - wp_nonce_url( |
|
1075 | - add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ), |
|
1076 | - 'getpaid-nonce', |
|
1077 | - 'getpaid-nonce' |
|
1078 | - ) |
|
1079 | - ); |
|
1080 | - ?> |
|
1073 | + echo esc_url( |
|
1074 | + wp_nonce_url( |
|
1075 | + add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ), |
|
1076 | + 'getpaid-nonce', |
|
1077 | + 'getpaid-nonce' |
|
1078 | + ) |
|
1079 | + ); |
|
1080 | + ?> |
|
1081 | 1081 | " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a> |
1082 | 1082 | </td> |
1083 | 1083 | </tr> |
@@ -1090,14 +1090,14 @@ discard block |
||
1090 | 1090 | <td> |
1091 | 1091 | <a href=" |
1092 | 1092 | <?php |
1093 | - echo esc_url( |
|
1094 | - wp_nonce_url( |
|
1095 | - add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ), |
|
1096 | - 'getpaid-nonce', |
|
1097 | - 'getpaid-nonce' |
|
1098 | - ) |
|
1099 | - ); |
|
1100 | - ?> |
|
1093 | + echo esc_url( |
|
1094 | + wp_nonce_url( |
|
1095 | + add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ), |
|
1096 | + 'getpaid-nonce', |
|
1097 | + 'getpaid-nonce' |
|
1098 | + ) |
|
1099 | + ); |
|
1100 | + ?> |
|
1101 | 1101 | " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a> |
1102 | 1102 | </td> |
1103 | 1103 | </tr> |
@@ -1110,8 +1110,8 @@ discard block |
||
1110 | 1110 | <td> |
1111 | 1111 | <a href=" |
1112 | 1112 | <?php |
1113 | - echo esc_url( admin_url( 'index.php?page=gp-setup' ) ); |
|
1114 | - ?> |
|
1113 | + echo esc_url( admin_url( 'index.php?page=gp-setup' ) ); |
|
1114 | + ?> |
|
1115 | 1115 | " class="button button-primary"><?php esc_html_e( 'Launch', 'invoicing' ); ?></a> |
1116 | 1116 | </td> |
1117 | 1117 | </tr> |
@@ -1125,19 +1125,19 @@ discard block |
||
1125 | 1125 | |
1126 | 1126 | |
1127 | 1127 | function wpinv_descriptive_text_callback( $args ) { |
1128 | - echo wp_kses_post( $args['desc'] ); |
|
1128 | + echo wp_kses_post( $args['desc'] ); |
|
1129 | 1129 | } |
1130 | 1130 | |
1131 | 1131 | function wpinv_raw_html_callback( $args ) { |
1132 | - echo wp_kses( $args['desc'], getpaid_allowed_html() ); |
|
1132 | + echo wp_kses( $args['desc'], getpaid_allowed_html() ); |
|
1133 | 1133 | } |
1134 | 1134 | |
1135 | 1135 | function wpinv_hook_callback( $args ) { |
1136 | - do_action( 'wpinv_' . $args['id'], $args ); |
|
1136 | + do_action( 'wpinv_' . $args['id'], $args ); |
|
1137 | 1137 | } |
1138 | 1138 | |
1139 | 1139 | function wpinv_set_settings_cap() { |
1140 | - return wpinv_get_capability(); |
|
1140 | + return wpinv_get_capability(); |
|
1141 | 1141 | } |
1142 | 1142 | add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' ); |
1143 | 1143 | |
@@ -1161,15 +1161,15 @@ discard block |
||
1161 | 1161 | */ |
1162 | 1162 | function wpinv_get_merge_tags_help_text( $subscription = false ) { |
1163 | 1163 | |
1164 | - $url = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f'; |
|
1165 | - $link = sprintf( |
|
1166 | - '<strong><a href="%s" target="_blank">%s</a></strong>', |
|
1167 | - $url, |
|
1168 | - esc_html__( 'View available merge tags.', 'invoicing' ) |
|
1169 | - ); |
|
1164 | + $url = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f'; |
|
1165 | + $link = sprintf( |
|
1166 | + '<strong><a href="%s" target="_blank">%s</a></strong>', |
|
1167 | + $url, |
|
1168 | + esc_html__( 'View available merge tags.', 'invoicing' ) |
|
1169 | + ); |
|
1170 | 1170 | |
1171 | - $description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' ); |
|
1171 | + $description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' ); |
|
1172 | 1172 | |
1173 | - return "$description $link"; |
|
1173 | + return "$description $link"; |
|
1174 | 1174 | |
1175 | 1175 | } |
@@ -12,280 +12,280 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Metaboxes { |
14 | 14 | |
15 | - /** |
|
16 | - * Only save metaboxes once. |
|
17 | - * |
|
18 | - * @var boolean |
|
19 | - */ |
|
20 | - private static $saved_meta_boxes = false; |
|
15 | + /** |
|
16 | + * Only save metaboxes once. |
|
17 | + * |
|
18 | + * @var boolean |
|
19 | + */ |
|
20 | + private static $saved_meta_boxes = false; |
|
21 | 21 | |
22 | 22 | /** |
23 | - * Hook in methods. |
|
24 | - */ |
|
25 | - public static function init() { |
|
23 | + * Hook in methods. |
|
24 | + */ |
|
25 | + public static function init() { |
|
26 | 26 | |
27 | - // Register metaboxes. |
|
28 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 50, 2 ); |
|
27 | + // Register metaboxes. |
|
28 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 50, 2 ); |
|
29 | 29 | |
30 | - // Remove metaboxes. |
|
31 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
30 | + // Remove metaboxes. |
|
31 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
32 | 32 | |
33 | - // Rename metaboxes. |
|
34 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
33 | + // Rename metaboxes. |
|
34 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
35 | 35 | |
36 | - // Save metaboxes. |
|
37 | - add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
38 | - } |
|
36 | + // Save metaboxes. |
|
37 | + add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Register core metaboxes. |
|
42 | - */ |
|
43 | - public static function add_meta_boxes( $post_type, $post ) { |
|
40 | + /** |
|
41 | + * Register core metaboxes. |
|
42 | + */ |
|
43 | + public static function add_meta_boxes( $post_type, $post ) { |
|
44 | 44 | |
45 | - // For invoices. |
|
46 | - self::add_invoice_meta_boxes( $post_type, $post ); |
|
45 | + // For invoices. |
|
46 | + self::add_invoice_meta_boxes( $post_type, $post ); |
|
47 | 47 | |
48 | - // For payment forms. |
|
49 | - self::add_payment_form_meta_boxes( $post_type, $post ); |
|
48 | + // For payment forms. |
|
49 | + self::add_payment_form_meta_boxes( $post_type, $post ); |
|
50 | 50 | |
51 | - // For invoice items. |
|
52 | - self::add_item_meta_boxes( $post_type ); |
|
51 | + // For invoice items. |
|
52 | + self::add_item_meta_boxes( $post_type ); |
|
53 | 53 | |
54 | - // For invoice discounts. |
|
55 | - if ( 'wpi_discount' === $post_type ) { |
|
56 | - add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
57 | - } |
|
54 | + // For invoice discounts. |
|
55 | + if ( 'wpi_discount' === $post_type ) { |
|
56 | + add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
57 | + } |
|
58 | 58 | |
59 | - } |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Register core metaboxes. |
|
63 | - */ |
|
64 | - protected static function add_payment_form_meta_boxes( $post_type, $post ) { |
|
61 | + /** |
|
62 | + * Register core metaboxes. |
|
63 | + */ |
|
64 | + protected static function add_payment_form_meta_boxes( $post_type, $post ) { |
|
65 | 65 | |
66 | - // For payment forms. |
|
67 | - if ( 'wpi_payment_form' === $post_type ) { |
|
66 | + // For payment forms. |
|
67 | + if ( 'wpi_payment_form' === $post_type ) { |
|
68 | 68 | |
69 | - // Design payment form. |
|
70 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
69 | + // Design payment form. |
|
70 | + add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
71 | 71 | |
72 | - // Payment form information. |
|
73 | - if ( wpinv_get_default_payment_form() !== $post->ID ) { |
|
74 | - add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
75 | - } |
|
72 | + // Payment form information. |
|
73 | + if ( wpinv_get_default_payment_form() !== $post->ID ) { |
|
74 | + add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
75 | + } |
|
76 | 76 | } |
77 | 77 | |
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Register core metaboxes. |
|
82 | - */ |
|
83 | - protected static function add_item_meta_boxes( $post_type ) { |
|
78 | + } |
|
84 | 79 | |
85 | - if ( 'wpi_item' === $post_type ) { |
|
86 | - |
|
87 | - // Item details. |
|
88 | - add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
89 | - |
|
90 | - // If taxes are enabled, register the tax metabox. |
|
91 | - if ( wpinv_use_taxes() ) { |
|
92 | - add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
93 | - } |
|
80 | + /** |
|
81 | + * Register core metaboxes. |
|
82 | + */ |
|
83 | + protected static function add_item_meta_boxes( $post_type ) { |
|
94 | 84 | |
95 | - // Item info. |
|
96 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
85 | + if ( 'wpi_item' === $post_type ) { |
|
97 | 86 | |
98 | - // Item description. |
|
99 | - add_meta_box( 'postexcerpt', __( 'Item Description', 'invoicing' ), 'GetPaid_Meta_Box_Description::output', 'wpi_item', 'normal' ); |
|
100 | - } |
|
87 | + // Item details. |
|
88 | + add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
101 | 89 | |
102 | - } |
|
90 | + // If taxes are enabled, register the tax metabox. |
|
91 | + if ( wpinv_use_taxes() ) { |
|
92 | + add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
93 | + } |
|
103 | 94 | |
104 | - /** |
|
105 | - * Register invoice metaboxes. |
|
106 | - */ |
|
107 | - protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
95 | + // Item info. |
|
96 | + add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
108 | 97 | |
109 | - // For invoices... |
|
110 | - if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
111 | - $invoice = new WPInv_Invoice( $post ); |
|
98 | + // Item description. |
|
99 | + add_meta_box( 'postexcerpt', __( 'Item Description', 'invoicing' ), 'GetPaid_Meta_Box_Description::output', 'wpi_item', 'normal' ); |
|
100 | + } |
|
112 | 101 | |
113 | - // Resend invoice. |
|
114 | - if ( ! $invoice->is_draft() ) { |
|
102 | + } |
|
115 | 103 | |
116 | - add_meta_box( |
|
117 | - 'wpinv-mb-resend-invoice', |
|
118 | - sprintf( |
|
119 | - // translators: %s is the invoice type. |
|
120 | - __( 'Resend %s', 'invoicing' ), |
|
121 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
122 | - ), |
|
123 | - 'GetPaid_Meta_Box_Resend_Invoice::output', |
|
124 | - $post_type, |
|
125 | - 'side', |
|
126 | - 'low' |
|
127 | - ); |
|
104 | + /** |
|
105 | + * Register invoice metaboxes. |
|
106 | + */ |
|
107 | + protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
108 | + |
|
109 | + // For invoices... |
|
110 | + if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
111 | + $invoice = new WPInv_Invoice( $post ); |
|
112 | + |
|
113 | + // Resend invoice. |
|
114 | + if ( ! $invoice->is_draft() ) { |
|
115 | + |
|
116 | + add_meta_box( |
|
117 | + 'wpinv-mb-resend-invoice', |
|
118 | + sprintf( |
|
119 | + // translators: %s is the invoice type. |
|
120 | + __( 'Resend %s', 'invoicing' ), |
|
121 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
122 | + ), |
|
123 | + 'GetPaid_Meta_Box_Resend_Invoice::output', |
|
124 | + $post_type, |
|
125 | + 'side', |
|
126 | + 'low' |
|
127 | + ); |
|
128 | + |
|
129 | + } |
|
130 | + |
|
131 | + // Subscriptions. |
|
132 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
133 | + if ( ! empty( $subscriptions ) ) { |
|
134 | + |
|
135 | + if ( is_array( $subscriptions ) ) { |
|
136 | + add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
137 | + } else { |
|
138 | + add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
139 | + } |
|
140 | + |
|
141 | + if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
142 | + add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
143 | + } |
|
144 | +} |
|
128 | 145 | |
129 | - } |
|
146 | + // Invoice details. |
|
147 | + add_meta_box( |
|
148 | + 'wpinv-details', |
|
149 | + sprintf( |
|
150 | + // translators: %s is the invoice type. |
|
151 | + __( '%s Details', 'invoicing' ), |
|
152 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
153 | + ), |
|
154 | + 'GetPaid_Meta_Box_Invoice_Details::output', |
|
155 | + $post_type, |
|
156 | + 'side' |
|
157 | + ); |
|
158 | + |
|
159 | + // Payment details. |
|
160 | + add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
161 | + |
|
162 | + // Billing details. |
|
163 | + add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
164 | + |
|
165 | + // Invoice items. |
|
166 | + add_meta_box( |
|
167 | + 'wpinv-items', |
|
168 | + sprintf( |
|
169 | + // translators: %s is the invoice type. |
|
170 | + __( '%s Items', 'invoicing' ), |
|
171 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
172 | + ), |
|
173 | + 'GetPaid_Meta_Box_Invoice_Items::output', |
|
174 | + $post_type, |
|
175 | + 'normal', |
|
176 | + 'high' |
|
177 | + ); |
|
178 | + |
|
179 | + // Invoice notes. |
|
180 | + add_meta_box( |
|
181 | + 'wpinv-notes', |
|
182 | + sprintf( |
|
183 | + // translators: %s is the invoice type. |
|
184 | + __( '%s Notes', 'invoicing' ), |
|
185 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
186 | + ), |
|
187 | + 'WPInv_Meta_Box_Notes::output', |
|
188 | + $post_type, |
|
189 | + 'side', |
|
190 | + 'low' |
|
191 | + ); |
|
192 | + |
|
193 | + // Shipping Address. |
|
194 | + if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
195 | + add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
196 | + } |
|
197 | + |
|
198 | + // Payment form information. |
|
199 | + if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
200 | + add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
201 | + } |
|
202 | +} |
|
130 | 203 | |
131 | - // Subscriptions. |
|
132 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
133 | - if ( ! empty( $subscriptions ) ) { |
|
204 | + } |
|
134 | 205 | |
135 | - if ( is_array( $subscriptions ) ) { |
|
136 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
137 | - } else { |
|
138 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
139 | - } |
|
206 | + /** |
|
207 | + * Remove some metaboxes. |
|
208 | + */ |
|
209 | + public static function remove_meta_boxes() { |
|
210 | + remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
211 | + remove_meta_box( 'postexcerpt', 'wpi_item', 'normal' ); |
|
212 | + } |
|
140 | 213 | |
141 | - if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
142 | - add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
143 | - } |
|
144 | -} |
|
214 | + /** |
|
215 | + * Rename other metaboxes. |
|
216 | + */ |
|
217 | + public static function rename_meta_boxes() { |
|
145 | 218 | |
146 | - // Invoice details. |
|
147 | - add_meta_box( |
|
148 | - 'wpinv-details', |
|
149 | - sprintf( |
|
150 | - // translators: %s is the invoice type. |
|
151 | - __( '%s Details', 'invoicing' ), |
|
152 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
153 | - ), |
|
154 | - 'GetPaid_Meta_Box_Invoice_Details::output', |
|
155 | - $post_type, |
|
156 | - 'side' |
|
157 | - ); |
|
158 | - |
|
159 | - // Payment details. |
|
160 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
161 | - |
|
162 | - // Billing details. |
|
163 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
164 | - |
|
165 | - // Invoice items. |
|
166 | - add_meta_box( |
|
167 | - 'wpinv-items', |
|
168 | - sprintf( |
|
169 | - // translators: %s is the invoice type. |
|
170 | - __( '%s Items', 'invoicing' ), |
|
171 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
172 | - ), |
|
173 | - 'GetPaid_Meta_Box_Invoice_Items::output', |
|
174 | - $post_type, |
|
175 | - 'normal', |
|
176 | - 'high' |
|
177 | - ); |
|
178 | - |
|
179 | - // Invoice notes. |
|
180 | - add_meta_box( |
|
181 | - 'wpinv-notes', |
|
182 | - sprintf( |
|
183 | - // translators: %s is the invoice type. |
|
184 | - __( '%s Notes', 'invoicing' ), |
|
185 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
186 | - ), |
|
187 | - 'WPInv_Meta_Box_Notes::output', |
|
188 | - $post_type, |
|
189 | - 'side', |
|
190 | - 'low' |
|
191 | - ); |
|
192 | - |
|
193 | - // Shipping Address. |
|
194 | - if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
195 | - add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
196 | - } |
|
197 | - |
|
198 | - // Payment form information. |
|
199 | - if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
200 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
201 | - } |
|
202 | -} |
|
219 | + } |
|
203 | 220 | |
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Remove some metaboxes. |
|
208 | - */ |
|
209 | - public static function remove_meta_boxes() { |
|
210 | - remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
211 | - remove_meta_box( 'postexcerpt', 'wpi_item', 'normal' ); |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * Rename other metaboxes. |
|
216 | - */ |
|
217 | - public static function rename_meta_boxes() { |
|
218 | - |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Check if we're saving, then trigger an action based on the post type. |
|
223 | - * |
|
224 | - * @param int $post_id Post ID. |
|
225 | - * @param object $post Post object. |
|
226 | - */ |
|
227 | - public static function save_meta_boxes( $post_id, $post ) { |
|
228 | - $post_id = absint( $post_id ); |
|
229 | - $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
230 | - |
|
231 | - // Do not save for ajax requests. |
|
232 | - if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
233 | - return; |
|
234 | - } |
|
235 | - |
|
236 | - // $post_id and $post are required |
|
237 | - if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
238 | - return; |
|
239 | - } |
|
240 | - |
|
241 | - // Dont' save meta boxes for revisions or autosaves. |
|
242 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
243 | - return; |
|
244 | - } |
|
245 | - |
|
246 | - // Check the nonce. |
|
247 | - if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
248 | - return; |
|
249 | - } |
|
250 | - |
|
251 | - // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
252 | - if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
253 | - return; |
|
254 | - } |
|
255 | - |
|
256 | - // Check user has permission to edit. |
|
257 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
258 | - return; |
|
259 | - } |
|
260 | - |
|
261 | - if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
262 | - |
|
263 | - // We need this save event to run once to avoid potential endless loops. |
|
264 | - self::$saved_meta_boxes = true; |
|
265 | - |
|
266 | - return GetPaid_Meta_Box_Invoice_Address::save( $post_id, wp_kses_post_deep( $_POST ) ); |
|
267 | - |
|
268 | - } |
|
269 | - |
|
270 | - // Ensure this is our post type. |
|
271 | - $post_types_map = array( |
|
272 | - 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
273 | - 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
274 | - 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
275 | - ); |
|
276 | - |
|
277 | - // Is this our post type? |
|
278 | - if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
279 | - return; |
|
280 | - } |
|
281 | - |
|
282 | - // We need this save event to run once to avoid potential endless loops. |
|
283 | - self::$saved_meta_boxes = true; |
|
284 | - |
|
285 | - // Save the post. |
|
286 | - $class = $post_types_map[ $post->post_type ]; |
|
287 | - $class::save( $post_id, wp_kses_post_deep( $_POST ), $post ); |
|
288 | - |
|
289 | - } |
|
221 | + /** |
|
222 | + * Check if we're saving, then trigger an action based on the post type. |
|
223 | + * |
|
224 | + * @param int $post_id Post ID. |
|
225 | + * @param object $post Post object. |
|
226 | + */ |
|
227 | + public static function save_meta_boxes( $post_id, $post ) { |
|
228 | + $post_id = absint( $post_id ); |
|
229 | + $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
230 | + |
|
231 | + // Do not save for ajax requests. |
|
232 | + if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
233 | + return; |
|
234 | + } |
|
235 | + |
|
236 | + // $post_id and $post are required |
|
237 | + if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
238 | + return; |
|
239 | + } |
|
240 | + |
|
241 | + // Dont' save meta boxes for revisions or autosaves. |
|
242 | + if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
243 | + return; |
|
244 | + } |
|
245 | + |
|
246 | + // Check the nonce. |
|
247 | + if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
248 | + return; |
|
249 | + } |
|
250 | + |
|
251 | + // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
252 | + if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
253 | + return; |
|
254 | + } |
|
255 | + |
|
256 | + // Check user has permission to edit. |
|
257 | + if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
258 | + return; |
|
259 | + } |
|
260 | + |
|
261 | + if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
262 | + |
|
263 | + // We need this save event to run once to avoid potential endless loops. |
|
264 | + self::$saved_meta_boxes = true; |
|
265 | + |
|
266 | + return GetPaid_Meta_Box_Invoice_Address::save( $post_id, wp_kses_post_deep( $_POST ) ); |
|
267 | + |
|
268 | + } |
|
269 | + |
|
270 | + // Ensure this is our post type. |
|
271 | + $post_types_map = array( |
|
272 | + 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
273 | + 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
274 | + 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
275 | + ); |
|
276 | + |
|
277 | + // Is this our post type? |
|
278 | + if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
279 | + return; |
|
280 | + } |
|
281 | + |
|
282 | + // We need this save event to run once to avoid potential endless loops. |
|
283 | + self::$saved_meta_boxes = true; |
|
284 | + |
|
285 | + // Save the post. |
|
286 | + $class = $post_types_map[ $post->post_type ]; |
|
287 | + $class::save( $post_id, wp_kses_post_deep( $_POST ), $post ); |
|
288 | + |
|
289 | + } |
|
290 | 290 | |
291 | 291 | } |