@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,199 +10,199 @@ discard block |
||
10 | 10 | class GetPaid_Payment_Form_Submission { |
11 | 11 | |
12 | 12 | /** |
13 | - * Submission ID |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - public $id = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * The raw submission data. |
|
21 | - * |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $data = null; |
|
25 | - |
|
26 | - /** |
|
27 | - * Submission totals |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $totals = array( |
|
32 | - |
|
33 | - 'subtotal' => array( |
|
34 | - 'initial' => 0, |
|
35 | - 'recurring' => 0, |
|
36 | - ), |
|
37 | - |
|
38 | - 'discount' => array( |
|
39 | - 'initial' => 0, |
|
40 | - 'recurring' => 0, |
|
41 | - ), |
|
42 | - |
|
43 | - 'fees' => array( |
|
44 | - 'initial' => 0, |
|
45 | - 'recurring' => 0, |
|
46 | - ), |
|
47 | - |
|
48 | - 'taxes' => array( |
|
49 | - 'initial' => 0, |
|
50 | - 'recurring' => 0, |
|
51 | - ), |
|
52 | - |
|
53 | - 'shipping' => array( |
|
54 | - 'initial' => 0, |
|
55 | - 'recurring' => 0, |
|
56 | - ), |
|
57 | - |
|
58 | - ); |
|
59 | - |
|
60 | - /** |
|
61 | - * Sets the associated payment form. |
|
62 | - * |
|
63 | - * @var GetPaid_Payment_Form |
|
64 | - */ |
|
13 | + * Submission ID |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + public $id = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * The raw submission data. |
|
21 | + * |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $data = null; |
|
25 | + |
|
26 | + /** |
|
27 | + * Submission totals |
|
28 | + * |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $totals = array( |
|
32 | + |
|
33 | + 'subtotal' => array( |
|
34 | + 'initial' => 0, |
|
35 | + 'recurring' => 0, |
|
36 | + ), |
|
37 | + |
|
38 | + 'discount' => array( |
|
39 | + 'initial' => 0, |
|
40 | + 'recurring' => 0, |
|
41 | + ), |
|
42 | + |
|
43 | + 'fees' => array( |
|
44 | + 'initial' => 0, |
|
45 | + 'recurring' => 0, |
|
46 | + ), |
|
47 | + |
|
48 | + 'taxes' => array( |
|
49 | + 'initial' => 0, |
|
50 | + 'recurring' => 0, |
|
51 | + ), |
|
52 | + |
|
53 | + 'shipping' => array( |
|
54 | + 'initial' => 0, |
|
55 | + 'recurring' => 0, |
|
56 | + ), |
|
57 | + |
|
58 | + ); |
|
59 | + |
|
60 | + /** |
|
61 | + * Sets the associated payment form. |
|
62 | + * |
|
63 | + * @var GetPaid_Payment_Form |
|
64 | + */ |
|
65 | 65 | protected $payment_form = null; |
66 | 66 | |
67 | 67 | /** |
68 | - * The country for the submission. |
|
69 | - * |
|
70 | - * @var string |
|
71 | - */ |
|
72 | - public $country = null; |
|
73 | - |
|
74 | - /** |
|
75 | - * The state for the submission. |
|
76 | - * |
|
77 | - * @since 1.0.19 |
|
78 | - * @var string |
|
79 | - */ |
|
80 | - public $state = null; |
|
81 | - |
|
82 | - /** |
|
83 | - * The invoice associated with the submission. |
|
84 | - * |
|
85 | - * @var WPInv_Invoice |
|
86 | - */ |
|
87 | - protected $invoice = null; |
|
88 | - |
|
89 | - /** |
|
90 | - * The recurring item for the submission. |
|
91 | - * |
|
92 | - * @var int |
|
93 | - */ |
|
94 | - public $has_recurring = 0; |
|
95 | - |
|
96 | - /** |
|
97 | - * An array of fees for the submission. |
|
98 | - * |
|
99 | - * @var array |
|
100 | - */ |
|
101 | - protected $fees = array(); |
|
102 | - |
|
103 | - /** |
|
104 | - * An array of discounts for the submission. |
|
105 | - * |
|
106 | - * @var array |
|
107 | - */ |
|
108 | - protected $discounts = array(); |
|
109 | - |
|
110 | - /** |
|
111 | - * An array of taxes for the submission. |
|
112 | - * |
|
113 | - * @var array |
|
114 | - */ |
|
115 | - protected $taxes = array(); |
|
116 | - |
|
117 | - /** |
|
118 | - * An array of items for the submission. |
|
119 | - * |
|
120 | - * @var GetPaid_Form_Item[] |
|
121 | - */ |
|
122 | - protected $items = array(); |
|
123 | - |
|
124 | - /** |
|
125 | - * The last error. |
|
126 | - * |
|
127 | - * @var string |
|
128 | - */ |
|
129 | - public $last_error = null; |
|
130 | - |
|
131 | - /** |
|
132 | - * The last error code. |
|
133 | - * |
|
134 | - * @var string |
|
135 | - */ |
|
136 | - public $last_error_code = null; |
|
137 | - |
|
138 | - /** |
|
139 | - * Class constructor. |
|
140 | - * |
|
141 | - */ |
|
142 | - public function __construct() { |
|
143 | - |
|
144 | - // Set the state and country to the default state and country. |
|
145 | - $this->country = wpinv_default_billing_country(); |
|
146 | - $this->state = wpinv_get_default_state(); |
|
147 | - |
|
148 | - // Do we have an actual submission? |
|
149 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
150 | - $this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) ); |
|
151 | - } |
|
152 | - |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Loads submission data. |
|
157 | - * |
|
158 | - * @param array $data |
|
159 | - */ |
|
160 | - public function load_data( $data ) { |
|
161 | - |
|
162 | - // Allow plugins to filter the data. |
|
163 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
164 | - |
|
165 | - // Cache it... |
|
166 | - $this->data = $data; |
|
167 | - |
|
168 | - // Then generate a unique id from the data. |
|
169 | - $this->id = md5( wp_json_encode( $data ) ); |
|
170 | - |
|
171 | - // Finally, process the submission. |
|
172 | - try { |
|
173 | - |
|
174 | - // Each process is passed an instance of the class (with reference) |
|
175 | - // and should throw an Exception whenever it encounters one. |
|
176 | - $processors = apply_filters( |
|
177 | - 'getpaid_payment_form_submission_processors', |
|
178 | - array( |
|
179 | - array( $this, 'process_payment_form' ), |
|
180 | - array( $this, 'process_invoice' ), |
|
181 | - array( $this, 'process_fees' ), |
|
182 | - array( $this, 'process_items' ), |
|
183 | - array( $this, 'process_discount' ), |
|
184 | - array( $this, 'process_taxes' ), |
|
185 | - ), |
|
186 | - $this |
|
187 | - ); |
|
188 | - |
|
189 | - foreach ( $processors as $processor ) { |
|
190 | - call_user_func_array( $processor, array( &$this ) ); |
|
191 | - } |
|
192 | - } catch ( GetPaid_Payment_Exception $e ) { |
|
193 | - $this->last_error = $e->getMessage(); |
|
194 | - $this->last_error_code = $e->getErrorCode(); |
|
195 | - } catch ( Exception $e ) { |
|
196 | - $this->last_error = $e->getMessage(); |
|
197 | - $this->last_error_code = $e->getCode(); |
|
198 | - } |
|
199 | - |
|
200 | - // Fired when we are done processing a submission. |
|
201 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
202 | - |
|
203 | - } |
|
204 | - |
|
205 | - /* |
|
68 | + * The country for the submission. |
|
69 | + * |
|
70 | + * @var string |
|
71 | + */ |
|
72 | + public $country = null; |
|
73 | + |
|
74 | + /** |
|
75 | + * The state for the submission. |
|
76 | + * |
|
77 | + * @since 1.0.19 |
|
78 | + * @var string |
|
79 | + */ |
|
80 | + public $state = null; |
|
81 | + |
|
82 | + /** |
|
83 | + * The invoice associated with the submission. |
|
84 | + * |
|
85 | + * @var WPInv_Invoice |
|
86 | + */ |
|
87 | + protected $invoice = null; |
|
88 | + |
|
89 | + /** |
|
90 | + * The recurring item for the submission. |
|
91 | + * |
|
92 | + * @var int |
|
93 | + */ |
|
94 | + public $has_recurring = 0; |
|
95 | + |
|
96 | + /** |
|
97 | + * An array of fees for the submission. |
|
98 | + * |
|
99 | + * @var array |
|
100 | + */ |
|
101 | + protected $fees = array(); |
|
102 | + |
|
103 | + /** |
|
104 | + * An array of discounts for the submission. |
|
105 | + * |
|
106 | + * @var array |
|
107 | + */ |
|
108 | + protected $discounts = array(); |
|
109 | + |
|
110 | + /** |
|
111 | + * An array of taxes for the submission. |
|
112 | + * |
|
113 | + * @var array |
|
114 | + */ |
|
115 | + protected $taxes = array(); |
|
116 | + |
|
117 | + /** |
|
118 | + * An array of items for the submission. |
|
119 | + * |
|
120 | + * @var GetPaid_Form_Item[] |
|
121 | + */ |
|
122 | + protected $items = array(); |
|
123 | + |
|
124 | + /** |
|
125 | + * The last error. |
|
126 | + * |
|
127 | + * @var string |
|
128 | + */ |
|
129 | + public $last_error = null; |
|
130 | + |
|
131 | + /** |
|
132 | + * The last error code. |
|
133 | + * |
|
134 | + * @var string |
|
135 | + */ |
|
136 | + public $last_error_code = null; |
|
137 | + |
|
138 | + /** |
|
139 | + * Class constructor. |
|
140 | + * |
|
141 | + */ |
|
142 | + public function __construct() { |
|
143 | + |
|
144 | + // Set the state and country to the default state and country. |
|
145 | + $this->country = wpinv_default_billing_country(); |
|
146 | + $this->state = wpinv_get_default_state(); |
|
147 | + |
|
148 | + // Do we have an actual submission? |
|
149 | + if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
150 | + $this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) ); |
|
151 | + } |
|
152 | + |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Loads submission data. |
|
157 | + * |
|
158 | + * @param array $data |
|
159 | + */ |
|
160 | + public function load_data( $data ) { |
|
161 | + |
|
162 | + // Allow plugins to filter the data. |
|
163 | + $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
164 | + |
|
165 | + // Cache it... |
|
166 | + $this->data = $data; |
|
167 | + |
|
168 | + // Then generate a unique id from the data. |
|
169 | + $this->id = md5( wp_json_encode( $data ) ); |
|
170 | + |
|
171 | + // Finally, process the submission. |
|
172 | + try { |
|
173 | + |
|
174 | + // Each process is passed an instance of the class (with reference) |
|
175 | + // and should throw an Exception whenever it encounters one. |
|
176 | + $processors = apply_filters( |
|
177 | + 'getpaid_payment_form_submission_processors', |
|
178 | + array( |
|
179 | + array( $this, 'process_payment_form' ), |
|
180 | + array( $this, 'process_invoice' ), |
|
181 | + array( $this, 'process_fees' ), |
|
182 | + array( $this, 'process_items' ), |
|
183 | + array( $this, 'process_discount' ), |
|
184 | + array( $this, 'process_taxes' ), |
|
185 | + ), |
|
186 | + $this |
|
187 | + ); |
|
188 | + |
|
189 | + foreach ( $processors as $processor ) { |
|
190 | + call_user_func_array( $processor, array( &$this ) ); |
|
191 | + } |
|
192 | + } catch ( GetPaid_Payment_Exception $e ) { |
|
193 | + $this->last_error = $e->getMessage(); |
|
194 | + $this->last_error_code = $e->getErrorCode(); |
|
195 | + } catch ( Exception $e ) { |
|
196 | + $this->last_error = $e->getMessage(); |
|
197 | + $this->last_error_code = $e->getCode(); |
|
198 | + } |
|
199 | + |
|
200 | + // Fired when we are done processing a submission. |
|
201 | + do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
202 | + |
|
203 | + } |
|
204 | + |
|
205 | + /* |
|
206 | 206 | |-------------------------------------------------------------------------- |
207 | 207 | | Payment Forms. |
208 | 208 | |-------------------------------------------------------------------------- |
@@ -211,39 +211,39 @@ discard block |
||
211 | 211 | | submission has an active payment form etc. |
212 | 212 | */ |
213 | 213 | |
214 | - /** |
|
215 | - * Prepares the submission's payment form. |
|
216 | - * |
|
217 | - * @since 1.0.19 |
|
218 | - */ |
|
219 | - public function process_payment_form() { |
|
214 | + /** |
|
215 | + * Prepares the submission's payment form. |
|
216 | + * |
|
217 | + * @since 1.0.19 |
|
218 | + */ |
|
219 | + public function process_payment_form() { |
|
220 | 220 | |
221 | - // Every submission needs an active payment form. |
|
222 | - if ( empty( $this->data['form_id'] ) ) { |
|
223 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
224 | - } |
|
221 | + // Every submission needs an active payment form. |
|
222 | + if ( empty( $this->data['form_id'] ) ) { |
|
223 | + throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
224 | + } |
|
225 | 225 | |
226 | - // Fetch the payment form. |
|
227 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
226 | + // Fetch the payment form. |
|
227 | + $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
228 | 228 | |
229 | - if ( ! $this->payment_form->is_active() ) { |
|
230 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
231 | - } |
|
229 | + if ( ! $this->payment_form->is_active() ) { |
|
230 | + throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
231 | + } |
|
232 | 232 | |
233 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
234 | - } |
|
233 | + do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
234 | + } |
|
235 | 235 | |
236 | 236 | /** |
237 | - * Returns the payment form. |
|
238 | - * |
|
239 | - * @since 1.0.19 |
|
240 | - * @return GetPaid_Payment_Form |
|
241 | - */ |
|
242 | - public function get_payment_form() { |
|
243 | - return $this->payment_form; |
|
244 | - } |
|
237 | + * Returns the payment form. |
|
238 | + * |
|
239 | + * @since 1.0.19 |
|
240 | + * @return GetPaid_Payment_Form |
|
241 | + */ |
|
242 | + public function get_payment_form() { |
|
243 | + return $this->payment_form; |
|
244 | + } |
|
245 | 245 | |
246 | - /* |
|
246 | + /* |
|
247 | 247 | |-------------------------------------------------------------------------- |
248 | 248 | | Invoices. |
249 | 249 | |-------------------------------------------------------------------------- |
@@ -252,95 +252,95 @@ discard block |
||
252 | 252 | | might be for an existing invoice. |
253 | 253 | */ |
254 | 254 | |
255 | - /** |
|
256 | - * Prepares the submission's invoice. |
|
257 | - * |
|
258 | - * @since 1.0.19 |
|
259 | - */ |
|
260 | - public function process_invoice() { |
|
261 | - |
|
262 | - // Abort if there is no invoice. |
|
263 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
264 | - |
|
265 | - // Check if we are resuming a payment. |
|
266 | - if ( empty( $this->data['maybe_use_invoice'] ) ) { |
|
267 | - return; |
|
268 | - } |
|
269 | - |
|
270 | - $invoice = wpinv_get_invoice( $this->data['maybe_use_invoice'] ); |
|
271 | - if ( empty( $invoice ) || ! $invoice->has_status( 'draft, auto-draft, wpi-pending' ) ) { |
|
272 | - return; |
|
273 | - } |
|
274 | - } |
|
275 | - |
|
276 | - // If the submission is for an existing invoice, ensure that it exists |
|
277 | - // and that it is not paid for. |
|
278 | - if ( empty( $invoice ) ) { |
|
279 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
280 | - } |
|
255 | + /** |
|
256 | + * Prepares the submission's invoice. |
|
257 | + * |
|
258 | + * @since 1.0.19 |
|
259 | + */ |
|
260 | + public function process_invoice() { |
|
261 | + |
|
262 | + // Abort if there is no invoice. |
|
263 | + if ( empty( $this->data['invoice_id'] ) ) { |
|
264 | + |
|
265 | + // Check if we are resuming a payment. |
|
266 | + if ( empty( $this->data['maybe_use_invoice'] ) ) { |
|
267 | + return; |
|
268 | + } |
|
269 | + |
|
270 | + $invoice = wpinv_get_invoice( $this->data['maybe_use_invoice'] ); |
|
271 | + if ( empty( $invoice ) || ! $invoice->has_status( 'draft, auto-draft, wpi-pending' ) ) { |
|
272 | + return; |
|
273 | + } |
|
274 | + } |
|
275 | + |
|
276 | + // If the submission is for an existing invoice, ensure that it exists |
|
277 | + // and that it is not paid for. |
|
278 | + if ( empty( $invoice ) ) { |
|
279 | + $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
280 | + } |
|
281 | 281 | |
282 | 282 | if ( empty( $invoice ) ) { |
283 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
284 | - } |
|
285 | - |
|
286 | - if ( $invoice->is_paid() ) { |
|
287 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
288 | - } |
|
289 | - |
|
290 | - $this->payment_form->invoice = $invoice; |
|
291 | - if ( ! $this->payment_form->is_default() ) { |
|
292 | - |
|
293 | - $items = array(); |
|
294 | - $item_ids = array(); |
|
295 | - |
|
296 | - foreach ( $invoice->get_items() as $item ) { |
|
297 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
298 | - $item_ids[] = $item->get_id(); |
|
299 | - $items[] = $item; |
|
300 | - } |
|
301 | - } |
|
302 | - |
|
303 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
304 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
305 | - $item_ids[] = $item->get_id(); |
|
306 | - $items[] = $item; |
|
307 | - } |
|
308 | - } |
|
309 | - |
|
310 | - $this->payment_form->set_items( $items ); |
|
311 | - |
|
312 | - } else { |
|
313 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
314 | - } |
|
315 | - |
|
316 | - $this->country = $invoice->get_country(); |
|
317 | - $this->state = $invoice->get_state(); |
|
318 | - $this->invoice = $invoice; |
|
319 | - |
|
320 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * Returns the associated invoice. |
|
325 | - * |
|
326 | - * @since 1.0.19 |
|
327 | - * @return WPInv_Invoice |
|
328 | - */ |
|
329 | - public function get_invoice() { |
|
330 | - return $this->invoice; |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * Checks whether there is an invoice associated with this submission. |
|
335 | - * |
|
336 | - * @since 1.0.19 |
|
337 | - * @return bool |
|
338 | - */ |
|
339 | - public function has_invoice() { |
|
340 | - return ! empty( $this->invoice ); |
|
341 | - } |
|
342 | - |
|
343 | - /* |
|
283 | + throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
284 | + } |
|
285 | + |
|
286 | + if ( $invoice->is_paid() ) { |
|
287 | + throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
288 | + } |
|
289 | + |
|
290 | + $this->payment_form->invoice = $invoice; |
|
291 | + if ( ! $this->payment_form->is_default() ) { |
|
292 | + |
|
293 | + $items = array(); |
|
294 | + $item_ids = array(); |
|
295 | + |
|
296 | + foreach ( $invoice->get_items() as $item ) { |
|
297 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
298 | + $item_ids[] = $item->get_id(); |
|
299 | + $items[] = $item; |
|
300 | + } |
|
301 | + } |
|
302 | + |
|
303 | + foreach ( $this->payment_form->get_items() as $item ) { |
|
304 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
305 | + $item_ids[] = $item->get_id(); |
|
306 | + $items[] = $item; |
|
307 | + } |
|
308 | + } |
|
309 | + |
|
310 | + $this->payment_form->set_items( $items ); |
|
311 | + |
|
312 | + } else { |
|
313 | + $this->payment_form->set_items( $invoice->get_items() ); |
|
314 | + } |
|
315 | + |
|
316 | + $this->country = $invoice->get_country(); |
|
317 | + $this->state = $invoice->get_state(); |
|
318 | + $this->invoice = $invoice; |
|
319 | + |
|
320 | + do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * Returns the associated invoice. |
|
325 | + * |
|
326 | + * @since 1.0.19 |
|
327 | + * @return WPInv_Invoice |
|
328 | + */ |
|
329 | + public function get_invoice() { |
|
330 | + return $this->invoice; |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * Checks whether there is an invoice associated with this submission. |
|
335 | + * |
|
336 | + * @since 1.0.19 |
|
337 | + * @return bool |
|
338 | + */ |
|
339 | + public function has_invoice() { |
|
340 | + return ! empty( $this->invoice ); |
|
341 | + } |
|
342 | + |
|
343 | + /* |
|
344 | 344 | |-------------------------------------------------------------------------- |
345 | 345 | | Items. |
346 | 346 | |-------------------------------------------------------------------------- |
@@ -349,129 +349,129 @@ discard block |
||
349 | 349 | | recurring item. But can have an unlimited number of non-recurring items. |
350 | 350 | */ |
351 | 351 | |
352 | - /** |
|
353 | - * Prepares the submission's items. |
|
354 | - * |
|
355 | - * @since 1.0.19 |
|
356 | - */ |
|
357 | - public function process_items() { |
|
358 | - |
|
359 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
360 | - |
|
361 | - foreach ( $processor->items as $item ) { |
|
362 | - $this->add_item( $item ); |
|
363 | - } |
|
364 | - |
|
365 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
366 | - } |
|
367 | - |
|
368 | - /** |
|
369 | - * Adds an item to the submission. |
|
370 | - * |
|
371 | - * @since 1.0.19 |
|
372 | - * @param GetPaid_Form_Item $item |
|
373 | - */ |
|
374 | - public function add_item( $item ) { |
|
375 | - |
|
376 | - // Make sure that it is available for purchase. |
|
377 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
378 | - return; |
|
379 | - } |
|
380 | - |
|
381 | - // Each submission can only contain one recurring item. |
|
382 | - if ( $item->is_recurring() ) { |
|
383 | - $this->has_recurring = $item->get_id(); |
|
384 | - } |
|
385 | - |
|
386 | - // Update the items and totals. |
|
387 | - $this->items[ $item->get_id() ] = $item; |
|
388 | - $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
389 | - $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
390 | - |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * Removes a specific item. |
|
395 | - * |
|
396 | - * You should not call this method after the discounts and taxes |
|
397 | - * have been calculated. |
|
398 | - * |
|
399 | - * @since 1.0.19 |
|
400 | - */ |
|
401 | - public function remove_item( $item_id ) { |
|
402 | - |
|
403 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
404 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
405 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
406 | - |
|
407 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
408 | - $this->has_recurring = 0; |
|
409 | - } |
|
410 | - |
|
411 | - unset( $this->items[ $item_id ] ); |
|
412 | - } |
|
413 | - |
|
414 | - } |
|
415 | - |
|
416 | - /** |
|
417 | - * Returns the subtotal. |
|
418 | - * |
|
419 | - * @since 1.0.19 |
|
420 | - */ |
|
421 | - public function get_subtotal() { |
|
422 | - |
|
423 | - if ( wpinv_prices_include_tax() ) { |
|
424 | - return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
425 | - } |
|
426 | - |
|
427 | - return $this->totals['subtotal']['initial']; |
|
428 | - } |
|
429 | - |
|
430 | - /** |
|
431 | - * Returns the recurring subtotal. |
|
432 | - * |
|
433 | - * @since 1.0.19 |
|
434 | - */ |
|
435 | - public function get_recurring_subtotal() { |
|
436 | - |
|
437 | - if ( wpinv_prices_include_tax() ) { |
|
438 | - return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
439 | - } |
|
440 | - |
|
441 | - return $this->totals['subtotal']['recurring']; |
|
442 | - } |
|
443 | - |
|
444 | - /** |
|
445 | - * Returns all items. |
|
446 | - * |
|
447 | - * @since 1.0.19 |
|
448 | - * @return GetPaid_Form_Item[] |
|
449 | - */ |
|
450 | - public function get_items() { |
|
451 | - return $this->items; |
|
452 | - } |
|
453 | - |
|
454 | - /** |
|
455 | - * Checks if there's a single subscription group in the submission. |
|
456 | - * |
|
457 | - * @since 2.3.0 |
|
458 | - * @return bool |
|
459 | - */ |
|
460 | - public function has_subscription_group() { |
|
461 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
465 | - * Checks if there are multipe subscription groups in the submission. |
|
466 | - * |
|
467 | - * @since 2.3.0 |
|
468 | - * @return bool |
|
469 | - */ |
|
470 | - public function has_multiple_subscription_groups() { |
|
471 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
472 | - } |
|
473 | - |
|
474 | - /* |
|
352 | + /** |
|
353 | + * Prepares the submission's items. |
|
354 | + * |
|
355 | + * @since 1.0.19 |
|
356 | + */ |
|
357 | + public function process_items() { |
|
358 | + |
|
359 | + $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
360 | + |
|
361 | + foreach ( $processor->items as $item ) { |
|
362 | + $this->add_item( $item ); |
|
363 | + } |
|
364 | + |
|
365 | + do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * Adds an item to the submission. |
|
370 | + * |
|
371 | + * @since 1.0.19 |
|
372 | + * @param GetPaid_Form_Item $item |
|
373 | + */ |
|
374 | + public function add_item( $item ) { |
|
375 | + |
|
376 | + // Make sure that it is available for purchase. |
|
377 | + if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
378 | + return; |
|
379 | + } |
|
380 | + |
|
381 | + // Each submission can only contain one recurring item. |
|
382 | + if ( $item->is_recurring() ) { |
|
383 | + $this->has_recurring = $item->get_id(); |
|
384 | + } |
|
385 | + |
|
386 | + // Update the items and totals. |
|
387 | + $this->items[ $item->get_id() ] = $item; |
|
388 | + $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
389 | + $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
390 | + |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * Removes a specific item. |
|
395 | + * |
|
396 | + * You should not call this method after the discounts and taxes |
|
397 | + * have been calculated. |
|
398 | + * |
|
399 | + * @since 1.0.19 |
|
400 | + */ |
|
401 | + public function remove_item( $item_id ) { |
|
402 | + |
|
403 | + if ( isset( $this->items[ $item_id ] ) ) { |
|
404 | + $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
405 | + $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
406 | + |
|
407 | + if ( $this->items[ $item_id ]->is_recurring() ) { |
|
408 | + $this->has_recurring = 0; |
|
409 | + } |
|
410 | + |
|
411 | + unset( $this->items[ $item_id ] ); |
|
412 | + } |
|
413 | + |
|
414 | + } |
|
415 | + |
|
416 | + /** |
|
417 | + * Returns the subtotal. |
|
418 | + * |
|
419 | + * @since 1.0.19 |
|
420 | + */ |
|
421 | + public function get_subtotal() { |
|
422 | + |
|
423 | + if ( wpinv_prices_include_tax() ) { |
|
424 | + return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
425 | + } |
|
426 | + |
|
427 | + return $this->totals['subtotal']['initial']; |
|
428 | + } |
|
429 | + |
|
430 | + /** |
|
431 | + * Returns the recurring subtotal. |
|
432 | + * |
|
433 | + * @since 1.0.19 |
|
434 | + */ |
|
435 | + public function get_recurring_subtotal() { |
|
436 | + |
|
437 | + if ( wpinv_prices_include_tax() ) { |
|
438 | + return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
439 | + } |
|
440 | + |
|
441 | + return $this->totals['subtotal']['recurring']; |
|
442 | + } |
|
443 | + |
|
444 | + /** |
|
445 | + * Returns all items. |
|
446 | + * |
|
447 | + * @since 1.0.19 |
|
448 | + * @return GetPaid_Form_Item[] |
|
449 | + */ |
|
450 | + public function get_items() { |
|
451 | + return $this->items; |
|
452 | + } |
|
453 | + |
|
454 | + /** |
|
455 | + * Checks if there's a single subscription group in the submission. |
|
456 | + * |
|
457 | + * @since 2.3.0 |
|
458 | + * @return bool |
|
459 | + */ |
|
460 | + public function has_subscription_group() { |
|
461 | + return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
462 | + } |
|
463 | + |
|
464 | + /** |
|
465 | + * Checks if there are multipe subscription groups in the submission. |
|
466 | + * |
|
467 | + * @since 2.3.0 |
|
468 | + * @return bool |
|
469 | + */ |
|
470 | + public function has_multiple_subscription_groups() { |
|
471 | + return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
472 | + } |
|
473 | + |
|
474 | + /* |
|
475 | 475 | |-------------------------------------------------------------------------- |
476 | 476 | | Taxes |
477 | 477 | |-------------------------------------------------------------------------- |
@@ -480,128 +480,128 @@ discard block |
||
480 | 480 | | or only one-time. |
481 | 481 | */ |
482 | 482 | |
483 | - /** |
|
484 | - * Prepares the submission's taxes. |
|
485 | - * |
|
486 | - * @since 1.0.19 |
|
487 | - */ |
|
488 | - public function process_taxes() { |
|
489 | - |
|
490 | - // Abort if we're not using taxes. |
|
491 | - if ( ! $this->use_taxes() ) { |
|
492 | - return; |
|
493 | - } |
|
494 | - |
|
495 | - // If a custom country && state has been passed in, use it to calculate taxes. |
|
496 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
497 | - if ( ! empty( $country ) ) { |
|
498 | - $this->country = $country; |
|
499 | - } |
|
500 | - |
|
501 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
502 | - if ( ! empty( $state ) ) { |
|
503 | - $this->state = $state; |
|
504 | - } |
|
505 | - |
|
506 | - // Confirm if the provided country and the ip country are similar. |
|
507 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
508 | - if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
509 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
510 | - } |
|
511 | - |
|
512 | - // Abort if the country is not taxable. |
|
513 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
514 | - return; |
|
515 | - } |
|
516 | - |
|
517 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
518 | - |
|
519 | - foreach ( $processor->taxes as $tax ) { |
|
520 | - $this->add_tax( $tax ); |
|
521 | - } |
|
522 | - |
|
523 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * Adds a tax to the submission. |
|
528 | - * |
|
529 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
530 | - * @since 1.0.19 |
|
531 | - */ |
|
532 | - public function add_tax( $tax ) { |
|
533 | - |
|
534 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
535 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
536 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
537 | - } |
|
538 | - |
|
539 | - $this->taxes[ $tax['name'] ] = $tax; |
|
540 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
541 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
542 | - |
|
543 | - } |
|
544 | - |
|
545 | - /** |
|
546 | - * Removes a specific tax. |
|
547 | - * |
|
548 | - * @since 1.0.19 |
|
549 | - */ |
|
550 | - public function remove_tax( $tax_name ) { |
|
551 | - |
|
552 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
553 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
554 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
555 | - unset( $this->taxes[ $tax_name ] ); |
|
556 | - } |
|
557 | - |
|
558 | - } |
|
559 | - |
|
560 | - /** |
|
561 | - * Whether or not we'll use taxes for the submission. |
|
562 | - * |
|
563 | - * @since 1.0.19 |
|
564 | - */ |
|
565 | - public function use_taxes() { |
|
566 | - |
|
567 | - $use_taxes = wpinv_use_taxes(); |
|
568 | - |
|
569 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
570 | - $use_taxes = false; |
|
571 | - } |
|
572 | - |
|
573 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
574 | - |
|
575 | - } |
|
576 | - |
|
577 | - /** |
|
578 | - * Returns the tax. |
|
579 | - * |
|
580 | - * @since 1.0.19 |
|
581 | - */ |
|
582 | - public function get_tax() { |
|
583 | - return $this->totals['taxes']['initial']; |
|
584 | - } |
|
585 | - |
|
586 | - /** |
|
587 | - * Returns the recurring tax. |
|
588 | - * |
|
589 | - * @since 1.0.19 |
|
590 | - */ |
|
591 | - public function get_recurring_tax() { |
|
592 | - return $this->totals['taxes']['recurring']; |
|
593 | - } |
|
594 | - |
|
595 | - /** |
|
596 | - * Returns all taxes. |
|
597 | - * |
|
598 | - * @since 1.0.19 |
|
599 | - */ |
|
600 | - public function get_taxes() { |
|
601 | - return $this->taxes; |
|
602 | - } |
|
603 | - |
|
604 | - /* |
|
483 | + /** |
|
484 | + * Prepares the submission's taxes. |
|
485 | + * |
|
486 | + * @since 1.0.19 |
|
487 | + */ |
|
488 | + public function process_taxes() { |
|
489 | + |
|
490 | + // Abort if we're not using taxes. |
|
491 | + if ( ! $this->use_taxes() ) { |
|
492 | + return; |
|
493 | + } |
|
494 | + |
|
495 | + // If a custom country && state has been passed in, use it to calculate taxes. |
|
496 | + $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
497 | + if ( ! empty( $country ) ) { |
|
498 | + $this->country = $country; |
|
499 | + } |
|
500 | + |
|
501 | + $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
502 | + if ( ! empty( $state ) ) { |
|
503 | + $this->state = $state; |
|
504 | + } |
|
505 | + |
|
506 | + // Confirm if the provided country and the ip country are similar. |
|
507 | + $address_confirmed = $this->get_field( 'confirm-address' ); |
|
508 | + if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
509 | + throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
510 | + } |
|
511 | + |
|
512 | + // Abort if the country is not taxable. |
|
513 | + if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
514 | + return; |
|
515 | + } |
|
516 | + |
|
517 | + $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
518 | + |
|
519 | + foreach ( $processor->taxes as $tax ) { |
|
520 | + $this->add_tax( $tax ); |
|
521 | + } |
|
522 | + |
|
523 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * Adds a tax to the submission. |
|
528 | + * |
|
529 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
530 | + * @since 1.0.19 |
|
531 | + */ |
|
532 | + public function add_tax( $tax ) { |
|
533 | + |
|
534 | + if ( wpinv_round_tax_per_tax_rate() ) { |
|
535 | + $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
536 | + $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
537 | + } |
|
538 | + |
|
539 | + $this->taxes[ $tax['name'] ] = $tax; |
|
540 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
541 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
542 | + |
|
543 | + } |
|
544 | + |
|
545 | + /** |
|
546 | + * Removes a specific tax. |
|
547 | + * |
|
548 | + * @since 1.0.19 |
|
549 | + */ |
|
550 | + public function remove_tax( $tax_name ) { |
|
551 | + |
|
552 | + if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
553 | + $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
554 | + $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
555 | + unset( $this->taxes[ $tax_name ] ); |
|
556 | + } |
|
557 | + |
|
558 | + } |
|
559 | + |
|
560 | + /** |
|
561 | + * Whether or not we'll use taxes for the submission. |
|
562 | + * |
|
563 | + * @since 1.0.19 |
|
564 | + */ |
|
565 | + public function use_taxes() { |
|
566 | + |
|
567 | + $use_taxes = wpinv_use_taxes(); |
|
568 | + |
|
569 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
570 | + $use_taxes = false; |
|
571 | + } |
|
572 | + |
|
573 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
574 | + |
|
575 | + } |
|
576 | + |
|
577 | + /** |
|
578 | + * Returns the tax. |
|
579 | + * |
|
580 | + * @since 1.0.19 |
|
581 | + */ |
|
582 | + public function get_tax() { |
|
583 | + return $this->totals['taxes']['initial']; |
|
584 | + } |
|
585 | + |
|
586 | + /** |
|
587 | + * Returns the recurring tax. |
|
588 | + * |
|
589 | + * @since 1.0.19 |
|
590 | + */ |
|
591 | + public function get_recurring_tax() { |
|
592 | + return $this->totals['taxes']['recurring']; |
|
593 | + } |
|
594 | + |
|
595 | + /** |
|
596 | + * Returns all taxes. |
|
597 | + * |
|
598 | + * @since 1.0.19 |
|
599 | + */ |
|
600 | + public function get_taxes() { |
|
601 | + return $this->taxes; |
|
602 | + } |
|
603 | + |
|
604 | + /* |
|
605 | 605 | |-------------------------------------------------------------------------- |
606 | 606 | | Discounts |
607 | 607 | |-------------------------------------------------------------------------- |
@@ -610,99 +610,99 @@ discard block |
||
610 | 610 | | or only one-time. They also do not have to come from a discount code. |
611 | 611 | */ |
612 | 612 | |
613 | - /** |
|
614 | - * Prepares the submission's discount. |
|
615 | - * |
|
616 | - * @since 1.0.19 |
|
617 | - */ |
|
618 | - public function process_discount() { |
|
619 | - |
|
620 | - $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
621 | - $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
622 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
623 | - |
|
624 | - foreach ( $processor->discounts as $discount ) { |
|
625 | - $this->add_discount( $discount ); |
|
626 | - } |
|
627 | - |
|
628 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
629 | - } |
|
630 | - |
|
631 | - /** |
|
632 | - * Adds a discount to the submission. |
|
633 | - * |
|
634 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
635 | - * @since 1.0.19 |
|
636 | - */ |
|
637 | - public function add_discount( $discount ) { |
|
638 | - $this->discounts[ $discount['name'] ] = $discount; |
|
639 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
640 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
641 | - } |
|
642 | - |
|
643 | - /** |
|
644 | - * Removes a discount from the submission. |
|
645 | - * |
|
646 | - * @since 1.0.19 |
|
647 | - */ |
|
648 | - public function remove_discount( $name ) { |
|
649 | - |
|
650 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
651 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
652 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
653 | - unset( $this->discounts[ $name ] ); |
|
654 | - } |
|
655 | - |
|
656 | - } |
|
657 | - |
|
658 | - /** |
|
659 | - * Checks whether there is a discount code associated with this submission. |
|
660 | - * |
|
661 | - * @since 1.0.19 |
|
662 | - * @return bool |
|
663 | - */ |
|
664 | - public function has_discount_code() { |
|
665 | - return ! empty( $this->discounts['discount_code'] ); |
|
666 | - } |
|
667 | - |
|
668 | - /** |
|
669 | - * Returns the discount code. |
|
670 | - * |
|
671 | - * @since 1.0.19 |
|
672 | - * @return string |
|
673 | - */ |
|
674 | - public function get_discount_code() { |
|
675 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
676 | - } |
|
677 | - |
|
678 | - /** |
|
679 | - * Returns the discount. |
|
680 | - * |
|
681 | - * @since 1.0.19 |
|
682 | - */ |
|
683 | - public function get_discount() { |
|
684 | - return $this->totals['discount']['initial']; |
|
685 | - } |
|
686 | - |
|
687 | - /** |
|
688 | - * Returns the recurring discount. |
|
689 | - * |
|
690 | - * @since 1.0.19 |
|
691 | - */ |
|
692 | - public function get_recurring_discount() { |
|
693 | - return $this->totals['discount']['recurring']; |
|
694 | - } |
|
695 | - |
|
696 | - /** |
|
697 | - * Returns all discounts. |
|
698 | - * |
|
699 | - * @since 1.0.19 |
|
700 | - */ |
|
701 | - public function get_discounts() { |
|
702 | - return $this->discounts; |
|
703 | - } |
|
704 | - |
|
705 | - /* |
|
613 | + /** |
|
614 | + * Prepares the submission's discount. |
|
615 | + * |
|
616 | + * @since 1.0.19 |
|
617 | + */ |
|
618 | + public function process_discount() { |
|
619 | + |
|
620 | + $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
621 | + $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
622 | + $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
623 | + |
|
624 | + foreach ( $processor->discounts as $discount ) { |
|
625 | + $this->add_discount( $discount ); |
|
626 | + } |
|
627 | + |
|
628 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
629 | + } |
|
630 | + |
|
631 | + /** |
|
632 | + * Adds a discount to the submission. |
|
633 | + * |
|
634 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
635 | + * @since 1.0.19 |
|
636 | + */ |
|
637 | + public function add_discount( $discount ) { |
|
638 | + $this->discounts[ $discount['name'] ] = $discount; |
|
639 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
640 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
641 | + } |
|
642 | + |
|
643 | + /** |
|
644 | + * Removes a discount from the submission. |
|
645 | + * |
|
646 | + * @since 1.0.19 |
|
647 | + */ |
|
648 | + public function remove_discount( $name ) { |
|
649 | + |
|
650 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
651 | + $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
652 | + $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
653 | + unset( $this->discounts[ $name ] ); |
|
654 | + } |
|
655 | + |
|
656 | + } |
|
657 | + |
|
658 | + /** |
|
659 | + * Checks whether there is a discount code associated with this submission. |
|
660 | + * |
|
661 | + * @since 1.0.19 |
|
662 | + * @return bool |
|
663 | + */ |
|
664 | + public function has_discount_code() { |
|
665 | + return ! empty( $this->discounts['discount_code'] ); |
|
666 | + } |
|
667 | + |
|
668 | + /** |
|
669 | + * Returns the discount code. |
|
670 | + * |
|
671 | + * @since 1.0.19 |
|
672 | + * @return string |
|
673 | + */ |
|
674 | + public function get_discount_code() { |
|
675 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
676 | + } |
|
677 | + |
|
678 | + /** |
|
679 | + * Returns the discount. |
|
680 | + * |
|
681 | + * @since 1.0.19 |
|
682 | + */ |
|
683 | + public function get_discount() { |
|
684 | + return $this->totals['discount']['initial']; |
|
685 | + } |
|
686 | + |
|
687 | + /** |
|
688 | + * Returns the recurring discount. |
|
689 | + * |
|
690 | + * @since 1.0.19 |
|
691 | + */ |
|
692 | + public function get_recurring_discount() { |
|
693 | + return $this->totals['discount']['recurring']; |
|
694 | + } |
|
695 | + |
|
696 | + /** |
|
697 | + * Returns all discounts. |
|
698 | + * |
|
699 | + * @since 1.0.19 |
|
700 | + */ |
|
701 | + public function get_discounts() { |
|
702 | + return $this->discounts; |
|
703 | + } |
|
704 | + |
|
705 | + /* |
|
706 | 706 | |-------------------------------------------------------------------------- |
707 | 707 | | Fees |
708 | 708 | |-------------------------------------------------------------------------- |
@@ -712,100 +712,100 @@ discard block |
||
712 | 712 | | fees. |
713 | 713 | */ |
714 | 714 | |
715 | - /** |
|
716 | - * Prepares the submission's fees. |
|
717 | - * |
|
718 | - * @since 1.0.19 |
|
719 | - */ |
|
720 | - public function process_fees() { |
|
721 | - |
|
722 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
723 | - |
|
724 | - foreach ( $fees_processor->fees as $fee ) { |
|
725 | - $this->add_fee( $fee ); |
|
726 | - } |
|
727 | - |
|
728 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
729 | - } |
|
730 | - |
|
731 | - /** |
|
732 | - * Adds a fee to the submission. |
|
733 | - * |
|
734 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
735 | - * @since 1.0.19 |
|
736 | - */ |
|
737 | - public function add_fee( $fee ) { |
|
738 | - |
|
739 | - if ( $fee['name'] == 'shipping' ) { |
|
740 | - $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
741 | - $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
742 | - return; |
|
743 | - } |
|
744 | - |
|
745 | - $this->fees[ $fee['name'] ] = $fee; |
|
746 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
747 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
748 | - |
|
749 | - } |
|
750 | - |
|
751 | - /** |
|
752 | - * Removes a fee from the submission. |
|
753 | - * |
|
754 | - * @since 1.0.19 |
|
755 | - */ |
|
756 | - public function remove_fee( $name ) { |
|
757 | - |
|
758 | - if ( isset( $this->fees[ $name ] ) ) { |
|
759 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
760 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
761 | - unset( $this->fees[ $name ] ); |
|
762 | - } |
|
763 | - |
|
764 | - if ( 'shipping' == $name ) { |
|
765 | - $this->totals['shipping']['initial'] = 0; |
|
766 | - $this->totals['shipping']['recurring'] = 0; |
|
767 | - } |
|
768 | - |
|
769 | - } |
|
770 | - |
|
771 | - /** |
|
772 | - * Returns the fees. |
|
773 | - * |
|
774 | - * @since 1.0.19 |
|
775 | - */ |
|
776 | - public function get_fee() { |
|
777 | - return $this->totals['fees']['initial']; |
|
778 | - } |
|
779 | - |
|
780 | - /** |
|
781 | - * Returns the recurring fees. |
|
782 | - * |
|
783 | - * @since 1.0.19 |
|
784 | - */ |
|
785 | - public function get_recurring_fee() { |
|
786 | - return $this->totals['fees']['recurring']; |
|
787 | - } |
|
788 | - |
|
789 | - /** |
|
790 | - * Returns all fees. |
|
791 | - * |
|
792 | - * @since 1.0.19 |
|
793 | - */ |
|
794 | - public function get_fees() { |
|
795 | - return $this->fees; |
|
796 | - } |
|
797 | - |
|
798 | - /** |
|
799 | - * Checks if there are any fees for the form. |
|
800 | - * |
|
801 | - * @return bool |
|
802 | - * @since 1.0.19 |
|
803 | - */ |
|
804 | - public function has_fees() { |
|
805 | - return count( $this->fees ) !== 0; |
|
806 | - } |
|
807 | - |
|
808 | - /* |
|
715 | + /** |
|
716 | + * Prepares the submission's fees. |
|
717 | + * |
|
718 | + * @since 1.0.19 |
|
719 | + */ |
|
720 | + public function process_fees() { |
|
721 | + |
|
722 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
723 | + |
|
724 | + foreach ( $fees_processor->fees as $fee ) { |
|
725 | + $this->add_fee( $fee ); |
|
726 | + } |
|
727 | + |
|
728 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
729 | + } |
|
730 | + |
|
731 | + /** |
|
732 | + * Adds a fee to the submission. |
|
733 | + * |
|
734 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
735 | + * @since 1.0.19 |
|
736 | + */ |
|
737 | + public function add_fee( $fee ) { |
|
738 | + |
|
739 | + if ( $fee['name'] == 'shipping' ) { |
|
740 | + $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
741 | + $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
742 | + return; |
|
743 | + } |
|
744 | + |
|
745 | + $this->fees[ $fee['name'] ] = $fee; |
|
746 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
747 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
748 | + |
|
749 | + } |
|
750 | + |
|
751 | + /** |
|
752 | + * Removes a fee from the submission. |
|
753 | + * |
|
754 | + * @since 1.0.19 |
|
755 | + */ |
|
756 | + public function remove_fee( $name ) { |
|
757 | + |
|
758 | + if ( isset( $this->fees[ $name ] ) ) { |
|
759 | + $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
760 | + $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
761 | + unset( $this->fees[ $name ] ); |
|
762 | + } |
|
763 | + |
|
764 | + if ( 'shipping' == $name ) { |
|
765 | + $this->totals['shipping']['initial'] = 0; |
|
766 | + $this->totals['shipping']['recurring'] = 0; |
|
767 | + } |
|
768 | + |
|
769 | + } |
|
770 | + |
|
771 | + /** |
|
772 | + * Returns the fees. |
|
773 | + * |
|
774 | + * @since 1.0.19 |
|
775 | + */ |
|
776 | + public function get_fee() { |
|
777 | + return $this->totals['fees']['initial']; |
|
778 | + } |
|
779 | + |
|
780 | + /** |
|
781 | + * Returns the recurring fees. |
|
782 | + * |
|
783 | + * @since 1.0.19 |
|
784 | + */ |
|
785 | + public function get_recurring_fee() { |
|
786 | + return $this->totals['fees']['recurring']; |
|
787 | + } |
|
788 | + |
|
789 | + /** |
|
790 | + * Returns all fees. |
|
791 | + * |
|
792 | + * @since 1.0.19 |
|
793 | + */ |
|
794 | + public function get_fees() { |
|
795 | + return $this->fees; |
|
796 | + } |
|
797 | + |
|
798 | + /** |
|
799 | + * Checks if there are any fees for the form. |
|
800 | + * |
|
801 | + * @return bool |
|
802 | + * @since 1.0.19 |
|
803 | + */ |
|
804 | + public function has_fees() { |
|
805 | + return count( $this->fees ) !== 0; |
|
806 | + } |
|
807 | + |
|
808 | + /* |
|
809 | 809 | |-------------------------------------------------------------------------- |
810 | 810 | | MISC |
811 | 811 | |-------------------------------------------------------------------------- |
@@ -813,147 +813,147 @@ discard block |
||
813 | 813 | | Extra submission functions. |
814 | 814 | */ |
815 | 815 | |
816 | - /** |
|
817 | - * Returns the shipping amount. |
|
818 | - * |
|
819 | - * @since 1.0.19 |
|
820 | - */ |
|
821 | - public function get_shipping() { |
|
822 | - return $this->totals['shipping']['initial']; |
|
823 | - } |
|
824 | - |
|
825 | - /** |
|
826 | - * Returns the recurring shipping. |
|
827 | - * |
|
828 | - * @since 1.0.19 |
|
829 | - */ |
|
830 | - public function get_recurring_shipping() { |
|
831 | - return $this->totals['shipping']['recurring']; |
|
832 | - } |
|
833 | - |
|
834 | - /** |
|
835 | - * Checks if there are any shipping fees for the form. |
|
836 | - * |
|
837 | - * @return bool |
|
838 | - * @since 1.0.19 |
|
839 | - */ |
|
840 | - public function has_shipping() { |
|
841 | - return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
842 | - } |
|
843 | - |
|
844 | - /** |
|
845 | - * Checks if this is the initial fetch. |
|
846 | - * |
|
847 | - * @return bool |
|
848 | - * @since 1.0.19 |
|
849 | - */ |
|
850 | - public function is_initial_fetch() { |
|
851 | - return isset( $this->data['initial_state'] ) && empty( $this->data['initial_state'] ); |
|
852 | - } |
|
853 | - |
|
854 | - /** |
|
855 | - * Returns the total amount to collect for this submission. |
|
856 | - * |
|
857 | - * @since 1.0.19 |
|
858 | - */ |
|
859 | - public function get_total() { |
|
860 | - $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
|
861 | - return max( $total, 0 ); |
|
862 | - } |
|
863 | - |
|
864 | - /** |
|
865 | - * Returns the recurring total amount to collect for this submission. |
|
866 | - * |
|
867 | - * @since 1.0.19 |
|
868 | - */ |
|
869 | - public function get_recurring_total() { |
|
870 | - $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
|
871 | - return max( $total, 0 ); |
|
872 | - } |
|
873 | - |
|
874 | - /** |
|
875 | - * Whether payment details should be collected for this submission. |
|
876 | - * |
|
877 | - * @since 1.0.19 |
|
878 | - */ |
|
879 | - public function should_collect_payment_details() { |
|
880 | - $initial = $this->get_total(); |
|
881 | - $recurring = $this->get_recurring_total(); |
|
882 | - |
|
883 | - if ( $this->has_recurring == 0 ) { |
|
884 | - $recurring = 0; |
|
885 | - } |
|
886 | - |
|
887 | - $collect = $initial > 0 || $recurring > 0; |
|
888 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
889 | - } |
|
890 | - |
|
891 | - /** |
|
892 | - * Returns the billing email of the user. |
|
893 | - * |
|
894 | - * @since 1.0.19 |
|
895 | - */ |
|
896 | - public function get_billing_email() { |
|
897 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
898 | - } |
|
899 | - |
|
900 | - /** |
|
901 | - * Checks if the submitter has a billing email. |
|
902 | - * |
|
903 | - * @since 1.0.19 |
|
904 | - */ |
|
905 | - public function has_billing_email() { |
|
906 | - $billing_email = $this->get_billing_email(); |
|
907 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
908 | - } |
|
909 | - |
|
910 | - /** |
|
911 | - * Returns the appropriate currency for the submission. |
|
912 | - * |
|
913 | - * @since 1.0.19 |
|
914 | - * @return string |
|
915 | - */ |
|
916 | - public function get_currency() { |
|
917 | - return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
918 | - } |
|
919 | - |
|
920 | - /** |
|
921 | - * Returns the raw submission data. |
|
922 | - * |
|
923 | - * @since 1.0.19 |
|
924 | - * @return array |
|
925 | - */ |
|
926 | - public function get_data() { |
|
927 | - return $this->data; |
|
928 | - } |
|
929 | - |
|
930 | - /** |
|
931 | - * Returns a field from the submission data |
|
932 | - * |
|
933 | - * @param string $field |
|
934 | - * @since 1.0.19 |
|
935 | - * @return mixed|null |
|
936 | - */ |
|
937 | - public function get_field( $field, $sub_array_key = null ) { |
|
938 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
939 | - } |
|
940 | - |
|
941 | - /** |
|
942 | - * Checks if a required field is set. |
|
943 | - * |
|
944 | - * @since 1.0.19 |
|
945 | - */ |
|
946 | - public function is_required_field_set( $field ) { |
|
947 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
948 | - } |
|
949 | - |
|
950 | - /** |
|
951 | - * Formats an amount |
|
952 | - * |
|
953 | - * @since 1.0.19 |
|
954 | - */ |
|
955 | - public function format_amount( $amount ) { |
|
956 | - return wpinv_price( $amount, $this->get_currency() ); |
|
957 | - } |
|
816 | + /** |
|
817 | + * Returns the shipping amount. |
|
818 | + * |
|
819 | + * @since 1.0.19 |
|
820 | + */ |
|
821 | + public function get_shipping() { |
|
822 | + return $this->totals['shipping']['initial']; |
|
823 | + } |
|
824 | + |
|
825 | + /** |
|
826 | + * Returns the recurring shipping. |
|
827 | + * |
|
828 | + * @since 1.0.19 |
|
829 | + */ |
|
830 | + public function get_recurring_shipping() { |
|
831 | + return $this->totals['shipping']['recurring']; |
|
832 | + } |
|
833 | + |
|
834 | + /** |
|
835 | + * Checks if there are any shipping fees for the form. |
|
836 | + * |
|
837 | + * @return bool |
|
838 | + * @since 1.0.19 |
|
839 | + */ |
|
840 | + public function has_shipping() { |
|
841 | + return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
842 | + } |
|
843 | + |
|
844 | + /** |
|
845 | + * Checks if this is the initial fetch. |
|
846 | + * |
|
847 | + * @return bool |
|
848 | + * @since 1.0.19 |
|
849 | + */ |
|
850 | + public function is_initial_fetch() { |
|
851 | + return isset( $this->data['initial_state'] ) && empty( $this->data['initial_state'] ); |
|
852 | + } |
|
853 | + |
|
854 | + /** |
|
855 | + * Returns the total amount to collect for this submission. |
|
856 | + * |
|
857 | + * @since 1.0.19 |
|
858 | + */ |
|
859 | + public function get_total() { |
|
860 | + $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
|
861 | + return max( $total, 0 ); |
|
862 | + } |
|
863 | + |
|
864 | + /** |
|
865 | + * Returns the recurring total amount to collect for this submission. |
|
866 | + * |
|
867 | + * @since 1.0.19 |
|
868 | + */ |
|
869 | + public function get_recurring_total() { |
|
870 | + $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
|
871 | + return max( $total, 0 ); |
|
872 | + } |
|
873 | + |
|
874 | + /** |
|
875 | + * Whether payment details should be collected for this submission. |
|
876 | + * |
|
877 | + * @since 1.0.19 |
|
878 | + */ |
|
879 | + public function should_collect_payment_details() { |
|
880 | + $initial = $this->get_total(); |
|
881 | + $recurring = $this->get_recurring_total(); |
|
882 | + |
|
883 | + if ( $this->has_recurring == 0 ) { |
|
884 | + $recurring = 0; |
|
885 | + } |
|
886 | + |
|
887 | + $collect = $initial > 0 || $recurring > 0; |
|
888 | + return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
889 | + } |
|
890 | + |
|
891 | + /** |
|
892 | + * Returns the billing email of the user. |
|
893 | + * |
|
894 | + * @since 1.0.19 |
|
895 | + */ |
|
896 | + public function get_billing_email() { |
|
897 | + return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
898 | + } |
|
899 | + |
|
900 | + /** |
|
901 | + * Checks if the submitter has a billing email. |
|
902 | + * |
|
903 | + * @since 1.0.19 |
|
904 | + */ |
|
905 | + public function has_billing_email() { |
|
906 | + $billing_email = $this->get_billing_email(); |
|
907 | + return ! empty( $billing_email ) && is_email( $billing_email ); |
|
908 | + } |
|
909 | + |
|
910 | + /** |
|
911 | + * Returns the appropriate currency for the submission. |
|
912 | + * |
|
913 | + * @since 1.0.19 |
|
914 | + * @return string |
|
915 | + */ |
|
916 | + public function get_currency() { |
|
917 | + return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
918 | + } |
|
919 | + |
|
920 | + /** |
|
921 | + * Returns the raw submission data. |
|
922 | + * |
|
923 | + * @since 1.0.19 |
|
924 | + * @return array |
|
925 | + */ |
|
926 | + public function get_data() { |
|
927 | + return $this->data; |
|
928 | + } |
|
929 | + |
|
930 | + /** |
|
931 | + * Returns a field from the submission data |
|
932 | + * |
|
933 | + * @param string $field |
|
934 | + * @since 1.0.19 |
|
935 | + * @return mixed|null |
|
936 | + */ |
|
937 | + public function get_field( $field, $sub_array_key = null ) { |
|
938 | + return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
939 | + } |
|
940 | + |
|
941 | + /** |
|
942 | + * Checks if a required field is set. |
|
943 | + * |
|
944 | + * @since 1.0.19 |
|
945 | + */ |
|
946 | + public function is_required_field_set( $field ) { |
|
947 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
948 | + } |
|
949 | + |
|
950 | + /** |
|
951 | + * Formats an amount |
|
952 | + * |
|
953 | + * @since 1.0.19 |
|
954 | + */ |
|
955 | + public function format_amount( $amount ) { |
|
956 | + return wpinv_price( $amount, $this->get_currency() ); |
|
957 | + } |
|
958 | 958 | |
959 | 959 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | $this->state = wpinv_get_default_state(); |
147 | 147 | |
148 | 148 | // Do we have an actual submission? |
149 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
150 | - $this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) ); |
|
149 | + if (isset($_POST['getpaid_payment_form_submission'])) { |
|
150 | + $this->load_data(wp_kses_post_deep(wp_unslash($_POST))); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | } |
@@ -157,16 +157,16 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @param array $data |
159 | 159 | */ |
160 | - public function load_data( $data ) { |
|
160 | + public function load_data($data) { |
|
161 | 161 | |
162 | 162 | // Allow plugins to filter the data. |
163 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
163 | + $data = apply_filters('getpaid_submission_data', $data, $this); |
|
164 | 164 | |
165 | 165 | // Cache it... |
166 | 166 | $this->data = $data; |
167 | 167 | |
168 | 168 | // Then generate a unique id from the data. |
169 | - $this->id = md5( wp_json_encode( $data ) ); |
|
169 | + $this->id = md5(wp_json_encode($data)); |
|
170 | 170 | |
171 | 171 | // Finally, process the submission. |
172 | 172 | try { |
@@ -176,29 +176,29 @@ discard block |
||
176 | 176 | $processors = apply_filters( |
177 | 177 | 'getpaid_payment_form_submission_processors', |
178 | 178 | array( |
179 | - array( $this, 'process_payment_form' ), |
|
180 | - array( $this, 'process_invoice' ), |
|
181 | - array( $this, 'process_fees' ), |
|
182 | - array( $this, 'process_items' ), |
|
183 | - array( $this, 'process_discount' ), |
|
184 | - array( $this, 'process_taxes' ), |
|
179 | + array($this, 'process_payment_form'), |
|
180 | + array($this, 'process_invoice'), |
|
181 | + array($this, 'process_fees'), |
|
182 | + array($this, 'process_items'), |
|
183 | + array($this, 'process_discount'), |
|
184 | + array($this, 'process_taxes'), |
|
185 | 185 | ), |
186 | 186 | $this |
187 | 187 | ); |
188 | 188 | |
189 | - foreach ( $processors as $processor ) { |
|
190 | - call_user_func_array( $processor, array( &$this ) ); |
|
189 | + foreach ($processors as $processor) { |
|
190 | + call_user_func_array($processor, array(&$this)); |
|
191 | 191 | } |
192 | - } catch ( GetPaid_Payment_Exception $e ) { |
|
192 | + } catch (GetPaid_Payment_Exception $e) { |
|
193 | 193 | $this->last_error = $e->getMessage(); |
194 | 194 | $this->last_error_code = $e->getErrorCode(); |
195 | - } catch ( Exception $e ) { |
|
195 | + } catch (Exception $e) { |
|
196 | 196 | $this->last_error = $e->getMessage(); |
197 | 197 | $this->last_error_code = $e->getCode(); |
198 | 198 | } |
199 | 199 | |
200 | 200 | // Fired when we are done processing a submission. |
201 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
201 | + do_action_ref_array('getpaid_process_submission', array(&$this)); |
|
202 | 202 | |
203 | 203 | } |
204 | 204 | |
@@ -219,18 +219,18 @@ discard block |
||
219 | 219 | public function process_payment_form() { |
220 | 220 | |
221 | 221 | // Every submission needs an active payment form. |
222 | - if ( empty( $this->data['form_id'] ) ) { |
|
223 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
222 | + if (empty($this->data['form_id'])) { |
|
223 | + throw new Exception(__('Missing payment form', 'invoicing')); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | // Fetch the payment form. |
227 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
227 | + $this->payment_form = new GetPaid_Payment_Form($this->data['form_id']); |
|
228 | 228 | |
229 | - if ( ! $this->payment_form->is_active() ) { |
|
230 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
229 | + if (!$this->payment_form->is_active()) { |
|
230 | + throw new Exception(__('Payment form not active', 'invoicing')); |
|
231 | 231 | } |
232 | 232 | |
233 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
233 | + do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this)); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
@@ -260,64 +260,64 @@ discard block |
||
260 | 260 | public function process_invoice() { |
261 | 261 | |
262 | 262 | // Abort if there is no invoice. |
263 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
263 | + if (empty($this->data['invoice_id'])) { |
|
264 | 264 | |
265 | 265 | // Check if we are resuming a payment. |
266 | - if ( empty( $this->data['maybe_use_invoice'] ) ) { |
|
266 | + if (empty($this->data['maybe_use_invoice'])) { |
|
267 | 267 | return; |
268 | 268 | } |
269 | 269 | |
270 | - $invoice = wpinv_get_invoice( $this->data['maybe_use_invoice'] ); |
|
271 | - if ( empty( $invoice ) || ! $invoice->has_status( 'draft, auto-draft, wpi-pending' ) ) { |
|
270 | + $invoice = wpinv_get_invoice($this->data['maybe_use_invoice']); |
|
271 | + if (empty($invoice) || !$invoice->has_status('draft, auto-draft, wpi-pending')) { |
|
272 | 272 | return; |
273 | 273 | } |
274 | 274 | } |
275 | 275 | |
276 | 276 | // If the submission is for an existing invoice, ensure that it exists |
277 | 277 | // and that it is not paid for. |
278 | - if ( empty( $invoice ) ) { |
|
279 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
278 | + if (empty($invoice)) { |
|
279 | + $invoice = wpinv_get_invoice($this->data['invoice_id']); |
|
280 | 280 | } |
281 | 281 | |
282 | - if ( empty( $invoice ) ) { |
|
283 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
282 | + if (empty($invoice)) { |
|
283 | + throw new Exception(__('Invalid invoice', 'invoicing')); |
|
284 | 284 | } |
285 | 285 | |
286 | - if ( $invoice->is_paid() ) { |
|
287 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
286 | + if ($invoice->is_paid()) { |
|
287 | + throw new Exception(__('This invoice is already paid for.', 'invoicing')); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | $this->payment_form->invoice = $invoice; |
291 | - if ( ! $this->payment_form->is_default() ) { |
|
291 | + if (!$this->payment_form->is_default()) { |
|
292 | 292 | |
293 | 293 | $items = array(); |
294 | 294 | $item_ids = array(); |
295 | 295 | |
296 | - foreach ( $invoice->get_items() as $item ) { |
|
297 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
296 | + foreach ($invoice->get_items() as $item) { |
|
297 | + if (!in_array($item->get_id(), $item_ids)) { |
|
298 | 298 | $item_ids[] = $item->get_id(); |
299 | 299 | $items[] = $item; |
300 | 300 | } |
301 | 301 | } |
302 | 302 | |
303 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
304 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
303 | + foreach ($this->payment_form->get_items() as $item) { |
|
304 | + if (!in_array($item->get_id(), $item_ids)) { |
|
305 | 305 | $item_ids[] = $item->get_id(); |
306 | 306 | $items[] = $item; |
307 | 307 | } |
308 | 308 | } |
309 | 309 | |
310 | - $this->payment_form->set_items( $items ); |
|
310 | + $this->payment_form->set_items($items); |
|
311 | 311 | |
312 | 312 | } else { |
313 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
313 | + $this->payment_form->set_items($invoice->get_items()); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | $this->country = $invoice->get_country(); |
317 | 317 | $this->state = $invoice->get_state(); |
318 | 318 | $this->invoice = $invoice; |
319 | 319 | |
320 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
320 | + do_action_ref_array('getpaid_submissions_process_invoice', array(&$this)); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | /** |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | * @return bool |
338 | 338 | */ |
339 | 339 | public function has_invoice() { |
340 | - return ! empty( $this->invoice ); |
|
340 | + return !empty($this->invoice); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | /* |
@@ -356,13 +356,13 @@ discard block |
||
356 | 356 | */ |
357 | 357 | public function process_items() { |
358 | 358 | |
359 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
359 | + $processor = new GetPaid_Payment_Form_Submission_Items($this); |
|
360 | 360 | |
361 | - foreach ( $processor->items as $item ) { |
|
362 | - $this->add_item( $item ); |
|
361 | + foreach ($processor->items as $item) { |
|
362 | + $this->add_item($item); |
|
363 | 363 | } |
364 | 364 | |
365 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
365 | + do_action_ref_array('getpaid_submissions_process_items', array(&$this)); |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | /** |
@@ -371,20 +371,20 @@ discard block |
||
371 | 371 | * @since 1.0.19 |
372 | 372 | * @param GetPaid_Form_Item $item |
373 | 373 | */ |
374 | - public function add_item( $item ) { |
|
374 | + public function add_item($item) { |
|
375 | 375 | |
376 | 376 | // Make sure that it is available for purchase. |
377 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
377 | + if (!$item->can_purchase() || isset($this->items[$item->get_id()])) { |
|
378 | 378 | return; |
379 | 379 | } |
380 | 380 | |
381 | 381 | // Each submission can only contain one recurring item. |
382 | - if ( $item->is_recurring() ) { |
|
382 | + if ($item->is_recurring()) { |
|
383 | 383 | $this->has_recurring = $item->get_id(); |
384 | 384 | } |
385 | 385 | |
386 | 386 | // Update the items and totals. |
387 | - $this->items[ $item->get_id() ] = $item; |
|
387 | + $this->items[$item->get_id()] = $item; |
|
388 | 388 | $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
389 | 389 | $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
390 | 390 | |
@@ -398,17 +398,17 @@ discard block |
||
398 | 398 | * |
399 | 399 | * @since 1.0.19 |
400 | 400 | */ |
401 | - public function remove_item( $item_id ) { |
|
401 | + public function remove_item($item_id) { |
|
402 | 402 | |
403 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
404 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
405 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
403 | + if (isset($this->items[$item_id])) { |
|
404 | + $this->totals['subtotal']['initial'] -= $this->items[$item_id]->get_sub_total(); |
|
405 | + $this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total(); |
|
406 | 406 | |
407 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
407 | + if ($this->items[$item_id]->is_recurring()) { |
|
408 | 408 | $this->has_recurring = 0; |
409 | 409 | } |
410 | 410 | |
411 | - unset( $this->items[ $item_id ] ); |
|
411 | + unset($this->items[$item_id]); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | } |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | */ |
421 | 421 | public function get_subtotal() { |
422 | 422 | |
423 | - if ( wpinv_prices_include_tax() ) { |
|
423 | + if (wpinv_prices_include_tax()) { |
|
424 | 424 | return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
425 | 425 | } |
426 | 426 | |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | */ |
435 | 435 | public function get_recurring_subtotal() { |
436 | 436 | |
437 | - if ( wpinv_prices_include_tax() ) { |
|
437 | + if (wpinv_prices_include_tax()) { |
|
438 | 438 | return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
439 | 439 | } |
440 | 440 | |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | * @return bool |
459 | 459 | */ |
460 | 460 | public function has_subscription_group() { |
461 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
461 | + return $this->has_recurring && getpaid_should_group_subscriptions($this) && 1 == count(getpaid_get_subscription_groups($this)); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | /** |
@@ -468,7 +468,7 @@ discard block |
||
468 | 468 | * @return bool |
469 | 469 | */ |
470 | 470 | public function has_multiple_subscription_groups() { |
471 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
471 | + return $this->has_recurring && 1 < count(getpaid_get_subscription_groups($this)); |
|
472 | 472 | } |
473 | 473 | |
474 | 474 | /* |
@@ -488,39 +488,39 @@ discard block |
||
488 | 488 | public function process_taxes() { |
489 | 489 | |
490 | 490 | // Abort if we're not using taxes. |
491 | - if ( ! $this->use_taxes() ) { |
|
491 | + if (!$this->use_taxes()) { |
|
492 | 492 | return; |
493 | 493 | } |
494 | 494 | |
495 | 495 | // If a custom country && state has been passed in, use it to calculate taxes. |
496 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
497 | - if ( ! empty( $country ) ) { |
|
496 | + $country = $this->get_field('wpinv_country', 'billing'); |
|
497 | + if (!empty($country)) { |
|
498 | 498 | $this->country = $country; |
499 | 499 | } |
500 | 500 | |
501 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
502 | - if ( ! empty( $state ) ) { |
|
501 | + $state = $this->get_field('wpinv_state', 'billing'); |
|
502 | + if (!empty($state)) { |
|
503 | 503 | $this->state = $state; |
504 | 504 | } |
505 | 505 | |
506 | 506 | // Confirm if the provided country and the ip country are similar. |
507 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
508 | - if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
509 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
507 | + $address_confirmed = $this->get_field('confirm-address'); |
|
508 | + if (isset($_POST['billing']['country']) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) { |
|
509 | + throw new Exception(__('The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing')); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | // Abort if the country is not taxable. |
513 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
513 | + if (!wpinv_is_country_taxable($this->country)) { |
|
514 | 514 | return; |
515 | 515 | } |
516 | 516 | |
517 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
517 | + $processor = new GetPaid_Payment_Form_Submission_Taxes($this); |
|
518 | 518 | |
519 | - foreach ( $processor->taxes as $tax ) { |
|
520 | - $this->add_tax( $tax ); |
|
519 | + foreach ($processor->taxes as $tax) { |
|
520 | + $this->add_tax($tax); |
|
521 | 521 | } |
522 | 522 | |
523 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
523 | + do_action_ref_array('getpaid_submissions_process_taxes', array(&$this)); |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | /** |
@@ -529,16 +529,16 @@ discard block |
||
529 | 529 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
530 | 530 | * @since 1.0.19 |
531 | 531 | */ |
532 | - public function add_tax( $tax ) { |
|
532 | + public function add_tax($tax) { |
|
533 | 533 | |
534 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
535 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
536 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
534 | + if (wpinv_round_tax_per_tax_rate()) { |
|
535 | + $tax['initial_tax'] = wpinv_round_amount($tax['initial_tax']); |
|
536 | + $tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']); |
|
537 | 537 | } |
538 | 538 | |
539 | - $this->taxes[ $tax['name'] ] = $tax; |
|
540 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
541 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
539 | + $this->taxes[$tax['name']] = $tax; |
|
540 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount($tax['initial_tax']); |
|
541 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']); |
|
542 | 542 | |
543 | 543 | } |
544 | 544 | |
@@ -547,12 +547,12 @@ discard block |
||
547 | 547 | * |
548 | 548 | * @since 1.0.19 |
549 | 549 | */ |
550 | - public function remove_tax( $tax_name ) { |
|
550 | + public function remove_tax($tax_name) { |
|
551 | 551 | |
552 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
553 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
554 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
555 | - unset( $this->taxes[ $tax_name ] ); |
|
552 | + if (isset($this->taxes[$tax_name])) { |
|
553 | + $this->totals['taxes']['initial'] -= $this->taxes[$tax_name]['initial_tax']; |
|
554 | + $this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax']; |
|
555 | + unset($this->taxes[$tax_name]); |
|
556 | 556 | } |
557 | 557 | |
558 | 558 | } |
@@ -566,11 +566,11 @@ discard block |
||
566 | 566 | |
567 | 567 | $use_taxes = wpinv_use_taxes(); |
568 | 568 | |
569 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
569 | + if ($this->has_invoice() && !$this->invoice->is_taxable()) { |
|
570 | 570 | $use_taxes = false; |
571 | 571 | } |
572 | 572 | |
573 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
573 | + return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this); |
|
574 | 574 | |
575 | 575 | } |
576 | 576 | |
@@ -619,13 +619,13 @@ discard block |
||
619 | 619 | |
620 | 620 | $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
621 | 621 | $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
622 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
622 | + $processor = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total); |
|
623 | 623 | |
624 | - foreach ( $processor->discounts as $discount ) { |
|
625 | - $this->add_discount( $discount ); |
|
624 | + foreach ($processor->discounts as $discount) { |
|
625 | + $this->add_discount($discount); |
|
626 | 626 | } |
627 | 627 | |
628 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
628 | + do_action_ref_array('getpaid_submissions_process_discounts', array(&$this)); |
|
629 | 629 | } |
630 | 630 | |
631 | 631 | /** |
@@ -634,10 +634,10 @@ discard block |
||
634 | 634 | * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
635 | 635 | * @since 1.0.19 |
636 | 636 | */ |
637 | - public function add_discount( $discount ) { |
|
638 | - $this->discounts[ $discount['name'] ] = $discount; |
|
639 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
640 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
637 | + public function add_discount($discount) { |
|
638 | + $this->discounts[$discount['name']] = $discount; |
|
639 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount($discount['initial_discount']); |
|
640 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']); |
|
641 | 641 | } |
642 | 642 | |
643 | 643 | /** |
@@ -645,12 +645,12 @@ discard block |
||
645 | 645 | * |
646 | 646 | * @since 1.0.19 |
647 | 647 | */ |
648 | - public function remove_discount( $name ) { |
|
648 | + public function remove_discount($name) { |
|
649 | 649 | |
650 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
651 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
652 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
653 | - unset( $this->discounts[ $name ] ); |
|
650 | + if (isset($this->discounts[$name])) { |
|
651 | + $this->totals['discount']['initial'] -= $this->discounts[$name]['initial_discount']; |
|
652 | + $this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount']; |
|
653 | + unset($this->discounts[$name]); |
|
654 | 654 | } |
655 | 655 | |
656 | 656 | } |
@@ -662,7 +662,7 @@ discard block |
||
662 | 662 | * @return bool |
663 | 663 | */ |
664 | 664 | public function has_discount_code() { |
665 | - return ! empty( $this->discounts['discount_code'] ); |
|
665 | + return !empty($this->discounts['discount_code']); |
|
666 | 666 | } |
667 | 667 | |
668 | 668 | /** |
@@ -719,13 +719,13 @@ discard block |
||
719 | 719 | */ |
720 | 720 | public function process_fees() { |
721 | 721 | |
722 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
722 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees($this); |
|
723 | 723 | |
724 | - foreach ( $fees_processor->fees as $fee ) { |
|
725 | - $this->add_fee( $fee ); |
|
724 | + foreach ($fees_processor->fees as $fee) { |
|
725 | + $this->add_fee($fee); |
|
726 | 726 | } |
727 | 727 | |
728 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
728 | + do_action_ref_array('getpaid_submissions_process_fees', array(&$this)); |
|
729 | 729 | } |
730 | 730 | |
731 | 731 | /** |
@@ -734,17 +734,17 @@ discard block |
||
734 | 734 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
735 | 735 | * @since 1.0.19 |
736 | 736 | */ |
737 | - public function add_fee( $fee ) { |
|
737 | + public function add_fee($fee) { |
|
738 | 738 | |
739 | - if ( $fee['name'] == 'shipping' ) { |
|
740 | - $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
741 | - $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
739 | + if ($fee['name'] == 'shipping') { |
|
740 | + $this->totals['shipping']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
741 | + $this->totals['shipping']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
742 | 742 | return; |
743 | 743 | } |
744 | 744 | |
745 | - $this->fees[ $fee['name'] ] = $fee; |
|
746 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
747 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
745 | + $this->fees[$fee['name']] = $fee; |
|
746 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
747 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
748 | 748 | |
749 | 749 | } |
750 | 750 | |
@@ -753,15 +753,15 @@ discard block |
||
753 | 753 | * |
754 | 754 | * @since 1.0.19 |
755 | 755 | */ |
756 | - public function remove_fee( $name ) { |
|
756 | + public function remove_fee($name) { |
|
757 | 757 | |
758 | - if ( isset( $this->fees[ $name ] ) ) { |
|
759 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
760 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
761 | - unset( $this->fees[ $name ] ); |
|
758 | + if (isset($this->fees[$name])) { |
|
759 | + $this->totals['fees']['initial'] -= $this->fees[$name]['initial_fee']; |
|
760 | + $this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee']; |
|
761 | + unset($this->fees[$name]); |
|
762 | 762 | } |
763 | 763 | |
764 | - if ( 'shipping' == $name ) { |
|
764 | + if ('shipping' == $name) { |
|
765 | 765 | $this->totals['shipping']['initial'] = 0; |
766 | 766 | $this->totals['shipping']['recurring'] = 0; |
767 | 767 | } |
@@ -802,7 +802,7 @@ discard block |
||
802 | 802 | * @since 1.0.19 |
803 | 803 | */ |
804 | 804 | public function has_fees() { |
805 | - return count( $this->fees ) !== 0; |
|
805 | + return count($this->fees) !== 0; |
|
806 | 806 | } |
807 | 807 | |
808 | 808 | /* |
@@ -838,7 +838,7 @@ discard block |
||
838 | 838 | * @since 1.0.19 |
839 | 839 | */ |
840 | 840 | public function has_shipping() { |
841 | - return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
841 | + return apply_filters('getpaid_payment_form_has_shipping', false, $this); |
|
842 | 842 | } |
843 | 843 | |
844 | 844 | /** |
@@ -848,7 +848,7 @@ discard block |
||
848 | 848 | * @since 1.0.19 |
849 | 849 | */ |
850 | 850 | public function is_initial_fetch() { |
851 | - return isset( $this->data['initial_state'] ) && empty( $this->data['initial_state'] ); |
|
851 | + return isset($this->data['initial_state']) && empty($this->data['initial_state']); |
|
852 | 852 | } |
853 | 853 | |
854 | 854 | /** |
@@ -858,7 +858,7 @@ discard block |
||
858 | 858 | */ |
859 | 859 | public function get_total() { |
860 | 860 | $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
861 | - return max( $total, 0 ); |
|
861 | + return max($total, 0); |
|
862 | 862 | } |
863 | 863 | |
864 | 864 | /** |
@@ -868,7 +868,7 @@ discard block |
||
868 | 868 | */ |
869 | 869 | public function get_recurring_total() { |
870 | 870 | $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
871 | - return max( $total, 0 ); |
|
871 | + return max($total, 0); |
|
872 | 872 | } |
873 | 873 | |
874 | 874 | /** |
@@ -880,12 +880,12 @@ discard block |
||
880 | 880 | $initial = $this->get_total(); |
881 | 881 | $recurring = $this->get_recurring_total(); |
882 | 882 | |
883 | - if ( $this->has_recurring == 0 ) { |
|
883 | + if ($this->has_recurring == 0) { |
|
884 | 884 | $recurring = 0; |
885 | 885 | } |
886 | 886 | |
887 | 887 | $collect = $initial > 0 || $recurring > 0; |
888 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
888 | + return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this); |
|
889 | 889 | } |
890 | 890 | |
891 | 891 | /** |
@@ -894,7 +894,7 @@ discard block |
||
894 | 894 | * @since 1.0.19 |
895 | 895 | */ |
896 | 896 | public function get_billing_email() { |
897 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
897 | + return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this); |
|
898 | 898 | } |
899 | 899 | |
900 | 900 | /** |
@@ -904,7 +904,7 @@ discard block |
||
904 | 904 | */ |
905 | 905 | public function has_billing_email() { |
906 | 906 | $billing_email = $this->get_billing_email(); |
907 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
907 | + return !empty($billing_email) && is_email($billing_email); |
|
908 | 908 | } |
909 | 909 | |
910 | 910 | /** |
@@ -934,8 +934,8 @@ discard block |
||
934 | 934 | * @since 1.0.19 |
935 | 935 | * @return mixed|null |
936 | 936 | */ |
937 | - public function get_field( $field, $sub_array_key = null ) { |
|
938 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
937 | + public function get_field($field, $sub_array_key = null) { |
|
938 | + return getpaid_get_array_field($this->data, $field, $sub_array_key); |
|
939 | 939 | } |
940 | 940 | |
941 | 941 | /** |
@@ -943,8 +943,8 @@ discard block |
||
943 | 943 | * |
944 | 944 | * @since 1.0.19 |
945 | 945 | */ |
946 | - public function is_required_field_set( $field ) { |
|
947 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
946 | + public function is_required_field_set($field) { |
|
947 | + return empty($field['required']) || !empty($this->data[$field['id']]); |
|
948 | 948 | } |
949 | 949 | |
950 | 950 | /** |
@@ -952,8 +952,8 @@ discard block |
||
952 | 952 | * |
953 | 953 | * @since 1.0.19 |
954 | 954 | */ |
955 | - public function format_amount( $amount ) { |
|
956 | - return wpinv_price( $amount, $this->get_currency() ); |
|
955 | + public function format_amount($amount) { |
|
956 | + return wpinv_price($amount, $this->get_currency()); |
|
957 | 957 | } |
958 | 958 | |
959 | 959 | } |
@@ -52,27 +52,27 @@ |
||
52 | 52 | |
53 | 53 | // Total Fee. |
54 | 54 | if ( 'fee' === $key ) { |
55 | - wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() ); |
|
55 | + wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() ); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | // Total discount. |
59 | 59 | if ( 'discount' === $key ) { |
60 | - wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); |
|
60 | + wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | // Shipping. |
64 | 64 | if ( 'shipping' === $key ) { |
65 | - wpinv_the_price( $invoice->get_shipping(), $invoice->get_currency() ); |
|
65 | + wpinv_the_price( $invoice->get_shipping(), $invoice->get_currency() ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | // Sub total. |
69 | 69 | if ( 'subtotal' === $key ) { |
70 | - wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); |
|
70 | + wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // Total. |
74 | 74 | if ( 'total' === $key ) { |
75 | - wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
75 | + wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // Fires when printing a cart total. |
@@ -9,26 +9,26 @@ discard block |
||
9 | 9 | * @var WPInv_Invoice $invoice |
10 | 10 | */ |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | // Totals rows. |
15 | -$totals = getpaid_invoice_totals_rows( $invoice ); |
|
15 | +$totals = getpaid_invoice_totals_rows($invoice); |
|
16 | 16 | |
17 | -do_action( 'getpaid_before_invoice_line_totals', $invoice, $totals ); |
|
17 | +do_action('getpaid_before_invoice_line_totals', $invoice, $totals); |
|
18 | 18 | |
19 | 19 | ?> |
20 | 20 | <div class='getpaid-invoice-line-totals'> |
21 | 21 | <div class="row"> |
22 | 22 | <div class="col-12 offset-sm-6 col-sm-6 border-sm-left pl-sm-0"> |
23 | 23 | |
24 | - <?php foreach ( $totals as $key => $label ) : ?> |
|
24 | + <?php foreach ($totals as $key => $label) : ?> |
|
25 | 25 | |
26 | - <div class="getpaid-invoice-line-totals-col <?php echo esc_attr( $key ); ?>"> |
|
26 | + <div class="getpaid-invoice-line-totals-col <?php echo esc_attr($key); ?>"> |
|
27 | 27 | |
28 | 28 | <div class="form-row row"> |
29 | 29 | |
30 | 30 | <div class="col-8 getpaid-invoice-line-totals-label"> |
31 | - <?php echo esc_html( $label ); ?> |
|
31 | + <?php echo esc_html($label); ?> |
|
32 | 32 | </div> |
33 | 33 | |
34 | 34 | <div class="col-4 getpaid-invoice-line-totals-value pl-0"> |
@@ -36,62 +36,62 @@ discard block |
||
36 | 36 | <?php |
37 | 37 | |
38 | 38 | // Total tax. |
39 | - if ( 'tax' === $key ) { |
|
40 | - wpinv_the_price( $invoice->get_total_tax(), $invoice->get_currency() ); |
|
39 | + if ('tax' === $key) { |
|
40 | + wpinv_the_price($invoice->get_total_tax(), $invoice->get_currency()); |
|
41 | 41 | |
42 | - if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
42 | + if (wpinv_use_taxes() && !$invoice->get_disable_taxes()) { |
|
43 | 43 | |
44 | 44 | $taxes = $invoice->get_total_tax(); |
45 | - if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) { |
|
45 | + if (empty($taxes) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction($invoice->get_country())) { |
|
46 | 46 | echo ' <em class="text-muted small">'; |
47 | - _x( '(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing' ); |
|
47 | + _x('(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing'); |
|
48 | 48 | echo '</em>'; |
49 | 49 | } |
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
53 | 53 | // Check if field starts with tax__. |
54 | - if ( 0 === strpos( $key, 'tax__' ) ) { |
|
55 | - $tax_amount = $invoice->get_tax_total_by_name( str_replace( 'tax__', '', $key ) ); |
|
56 | - wpinv_the_price( $tax_amount, $invoice->get_currency() ); |
|
54 | + if (0 === strpos($key, 'tax__')) { |
|
55 | + $tax_amount = $invoice->get_tax_total_by_name(str_replace('tax__', '', $key)); |
|
56 | + wpinv_the_price($tax_amount, $invoice->get_currency()); |
|
57 | 57 | |
58 | - if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
58 | + if (wpinv_use_taxes() && !$invoice->get_disable_taxes()) { |
|
59 | 59 | |
60 | - if ( empty( $tax_amount ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) { |
|
60 | + if (empty($tax_amount) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction($invoice->get_country())) { |
|
61 | 61 | echo ' <em class="text-muted small">'; |
62 | - _x( '(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing' ); |
|
62 | + _x('(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing'); |
|
63 | 63 | echo '</em>'; |
64 | 64 | } |
65 | 65 | } |
66 | 66 | } |
67 | 67 | |
68 | 68 | // Total Fee. |
69 | - if ( 'fee' === $key ) { |
|
70 | - wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() ); |
|
69 | + if ('fee' === $key) { |
|
70 | + wpinv_the_price($invoice->get_total_fees(), $invoice->get_currency()); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // Total discount. |
74 | - if ( 'discount' === $key ) { |
|
75 | - wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); |
|
74 | + if ('discount' === $key) { |
|
75 | + wpinv_the_price($invoice->get_total_discount(), $invoice->get_currency()); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // Shipping. |
79 | - if ( 'shipping' === $key ) { |
|
80 | - wpinv_the_price( $invoice->get_shipping(), $invoice->get_currency() ); |
|
79 | + if ('shipping' === $key) { |
|
80 | + wpinv_the_price($invoice->get_shipping(), $invoice->get_currency()); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | // Sub total. |
84 | - if ( 'subtotal' === $key ) { |
|
85 | - wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); |
|
84 | + if ('subtotal' === $key) { |
|
85 | + wpinv_the_price($invoice->get_subtotal(), $invoice->get_currency()); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | // Total. |
89 | - if ( 'total' === $key ) { |
|
90 | - wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
89 | + if ('total' === $key) { |
|
90 | + wpinv_the_price($invoice->get_total(), $invoice->get_currency()); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | // Fires when printing a cart total. |
94 | - do_action( "getpaid_invoice_cart_totals_$key", $invoice ); |
|
94 | + do_action("getpaid_invoice_cart_totals_$key", $invoice); |
|
95 | 95 | |
96 | 96 | ?> |
97 | 97 | |
@@ -105,4 +105,4 @@ discard block |
||
105 | 105 | </div> |
106 | 106 | </div> <!-- end .getpaid-invoice-line-totals --> |
107 | 107 | |
108 | -<?php do_action( 'getpaid_after_invoice_line_totals', $invoice, $totals ); ?> |
|
108 | +<?php do_action('getpaid_after_invoice_line_totals', $invoice, $totals); ?> |
@@ -12,294 +12,294 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports_Helper { |
14 | 14 | |
15 | - /** |
|
16 | - * Get report totals such as invoice totals and discount amounts. |
|
17 | - * |
|
18 | - * Data example: |
|
19 | - * |
|
20 | - * 'subtotal' => array( |
|
21 | - * 'type' => 'invoice_data', |
|
22 | - * 'function' => 'SUM', |
|
23 | - * 'name' => 'subtotal' |
|
24 | - * ) |
|
25 | - * |
|
26 | - * @param array $args |
|
27 | - * @return mixed depending on query_type |
|
28 | - */ |
|
29 | - public static function get_invoice_report_data( $args = array() ) { |
|
30 | - global $wpdb; |
|
31 | - |
|
32 | - $default_args = array( |
|
33 | - 'data' => array(), // The data to retrieve. |
|
34 | - 'where' => array(), // An array of where queries. |
|
35 | - 'query_type' => 'get_row', // wpdb query to run. |
|
36 | - 'group_by' => '', // What to group results by. |
|
37 | - 'order_by' => '', // What to order by. |
|
38 | - 'limit' => '', // Results limit. |
|
39 | - 'filter_range' => array(), // An array of before and after dates to limit results by. |
|
40 | - 'invoice_types' => array( 'wpi_invoice' ), // An array of post types to retrieve. |
|
41 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold' ), |
|
42 | - 'parent_invoice_status' => false, // Optionally filter by parent invoice status. |
|
43 | - ); |
|
44 | - |
|
45 | - $args = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args ); |
|
46 | - $args = wp_parse_args( $args, $default_args ); |
|
47 | - |
|
48 | - extract( $args ); |
|
49 | - |
|
50 | - if ( empty( $data ) ) { |
|
51 | - return ''; |
|
52 | - } |
|
53 | - |
|
54 | - $query = array(); |
|
55 | - $query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) ); |
|
56 | - $query['from'] = "FROM {$wpdb->posts} AS posts"; |
|
57 | - $query['join'] = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) ); |
|
58 | - |
|
59 | - $query['where'] = " |
|
15 | + /** |
|
16 | + * Get report totals such as invoice totals and discount amounts. |
|
17 | + * |
|
18 | + * Data example: |
|
19 | + * |
|
20 | + * 'subtotal' => array( |
|
21 | + * 'type' => 'invoice_data', |
|
22 | + * 'function' => 'SUM', |
|
23 | + * 'name' => 'subtotal' |
|
24 | + * ) |
|
25 | + * |
|
26 | + * @param array $args |
|
27 | + * @return mixed depending on query_type |
|
28 | + */ |
|
29 | + public static function get_invoice_report_data( $args = array() ) { |
|
30 | + global $wpdb; |
|
31 | + |
|
32 | + $default_args = array( |
|
33 | + 'data' => array(), // The data to retrieve. |
|
34 | + 'where' => array(), // An array of where queries. |
|
35 | + 'query_type' => 'get_row', // wpdb query to run. |
|
36 | + 'group_by' => '', // What to group results by. |
|
37 | + 'order_by' => '', // What to order by. |
|
38 | + 'limit' => '', // Results limit. |
|
39 | + 'filter_range' => array(), // An array of before and after dates to limit results by. |
|
40 | + 'invoice_types' => array( 'wpi_invoice' ), // An array of post types to retrieve. |
|
41 | + 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold' ), |
|
42 | + 'parent_invoice_status' => false, // Optionally filter by parent invoice status. |
|
43 | + ); |
|
44 | + |
|
45 | + $args = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args ); |
|
46 | + $args = wp_parse_args( $args, $default_args ); |
|
47 | + |
|
48 | + extract( $args ); |
|
49 | + |
|
50 | + if ( empty( $data ) ) { |
|
51 | + return ''; |
|
52 | + } |
|
53 | + |
|
54 | + $query = array(); |
|
55 | + $query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) ); |
|
56 | + $query['from'] = "FROM {$wpdb->posts} AS posts"; |
|
57 | + $query['join'] = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) ); |
|
58 | + |
|
59 | + $query['where'] = " |
|
60 | 60 | WHERE posts.post_type IN ( '" . implode( "','", $invoice_types ) . "' ) |
61 | 61 | "; |
62 | 62 | |
63 | - if ( ! empty( $invoice_status ) ) { |
|
64 | - $query['where'] .= " |
|
63 | + if ( ! empty( $invoice_status ) ) { |
|
64 | + $query['where'] .= " |
|
65 | 65 | AND posts.post_status IN ( '" . implode( "','", $invoice_status ) . "' ) |
66 | 66 | "; |
67 | - } |
|
68 | - |
|
69 | - if ( ! empty( $parent_invoice_status ) ) { |
|
70 | - if ( ! empty( $invoice_status ) ) { |
|
71 | - $query['where'] .= " AND ( parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) OR parent.ID IS NULL ) "; |
|
72 | - } else { |
|
73 | - $query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) "; |
|
74 | - } |
|
75 | - } |
|
76 | - |
|
77 | - if ( ! empty( $filter_range['before'] ) ) { |
|
78 | - $query['where'] .= " |
|
67 | + } |
|
68 | + |
|
69 | + if ( ! empty( $parent_invoice_status ) ) { |
|
70 | + if ( ! empty( $invoice_status ) ) { |
|
71 | + $query['where'] .= " AND ( parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) OR parent.ID IS NULL ) "; |
|
72 | + } else { |
|
73 | + $query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) "; |
|
74 | + } |
|
75 | + } |
|
76 | + |
|
77 | + if ( ! empty( $filter_range['before'] ) ) { |
|
78 | + $query['where'] .= " |
|
79 | 79 | AND posts.post_date <= '" . gmdate( 'Y-m-d 23:59:59', strtotime( $filter_range['before'] ) ) . "' |
80 | 80 | "; |
81 | - } |
|
81 | + } |
|
82 | 82 | |
83 | - if ( ! empty( $filter_range['after'] ) ) { |
|
84 | - $query['where'] .= " |
|
83 | + if ( ! empty( $filter_range['after'] ) ) { |
|
84 | + $query['where'] .= " |
|
85 | 85 | AND posts.post_date >= '" . gmdate( 'Y-m-d 00:00:00', strtotime( $filter_range['after'] ) ) . "' |
86 | 86 | "; |
87 | - } |
|
87 | + } |
|
88 | 88 | |
89 | - if ( ! empty( $where ) ) { |
|
89 | + if ( ! empty( $where ) ) { |
|
90 | 90 | |
91 | - foreach ( $where as $value ) { |
|
91 | + foreach ( $where as $value ) { |
|
92 | 92 | |
93 | - if ( strtolower( $value['operator'] ) === 'in' || strtolower( $value['operator'] ) === 'not in' ) { |
|
94 | - |
|
95 | - if ( is_array( $value['value'] ) ) { |
|
96 | - $value['value'] = implode( "','", $value['value'] ); |
|
97 | - } |
|
98 | - |
|
99 | - if ( ! empty( $value['value'] ) ) { |
|
100 | - $where_value = "{$value['operator']} ('{$value['value']}')"; |
|
101 | - } |
|
102 | - } else { |
|
103 | - $where_value = "{$value['operator']} '{$value['value']}'"; |
|
104 | - } |
|
105 | - |
|
106 | - if ( ! empty( $where_value ) ) { |
|
107 | - $query['where'] .= " AND {$value['key']} {$where_value}"; |
|
108 | - } |
|
109 | - } |
|
110 | - } |
|
111 | - |
|
112 | - if ( $group_by ) { |
|
113 | - $query['group_by'] = "GROUP BY {$group_by}"; |
|
114 | - } |
|
115 | - |
|
116 | - if ( $order_by ) { |
|
117 | - $query['order_by'] = "ORDER BY {$order_by}"; |
|
118 | - } |
|
119 | - |
|
120 | - if ( $limit ) { |
|
121 | - $query['limit'] = "LIMIT {$limit}"; |
|
122 | - } |
|
123 | - |
|
124 | - $query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data ); |
|
125 | - $query = implode( ' ', $query ); |
|
126 | - |
|
127 | - return self::execute( $query_type, $query ); |
|
128 | - |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Prepares the data to select. |
|
133 | - * |
|
134 | - * |
|
135 | - * @param array $data |
|
136 | - * @return array |
|
137 | - */ |
|
138 | - public static function prepare_invoice_data( $data ) { |
|
139 | - |
|
140 | - $prepared = array(); |
|
141 | - |
|
142 | - foreach ( $data as $raw_key => $value ) { |
|
143 | - $key = sanitize_key( $raw_key ); |
|
144 | - $distinct = ''; |
|
145 | - |
|
146 | - if ( isset( $value['distinct'] ) ) { |
|
147 | - $distinct = 'DISTINCT'; |
|
148 | - } |
|
149 | - |
|
150 | - $get_key = self::get_invoice_table_key( $key, $value['type'] ); |
|
151 | - |
|
152 | - if ( false === $get_key ) { |
|
153 | - // Skip to the next foreach iteration else the query will be invalid. |
|
154 | - continue; |
|
155 | - } |
|
156 | - |
|
157 | - if ( ! empty( $value['function'] ) ) { |
|
158 | - $get = "{$value['function']}({$distinct} {$get_key})"; |
|
159 | - } else { |
|
160 | - $get = "{$distinct} {$get_key}"; |
|
161 | - } |
|
162 | - |
|
163 | - $prepared[] = "{$get} as {$value['name']}"; |
|
164 | - } |
|
165 | - |
|
166 | - return $prepared; |
|
167 | - |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Prepares the joins to use. |
|
172 | - * |
|
173 | - * |
|
174 | - * @param array $data |
|
175 | - * @param bool $with_parent |
|
176 | - * @return array |
|
177 | - */ |
|
178 | - public static function prepare_invoice_joins( $data, $with_parent ) { |
|
179 | - global $wpdb; |
|
180 | - |
|
181 | - $prepared = array(); |
|
182 | - |
|
183 | - foreach ( $data as $raw_key => $value ) { |
|
184 | - $join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER'; |
|
185 | - $type = isset( $value['type'] ) ? $value['type'] : false; |
|
186 | - $key = sanitize_key( $raw_key ); |
|
187 | - |
|
188 | - switch ( $type ) { |
|
189 | - case 'meta': |
|
190 | - $prepared[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )"; |
|
191 | - break; |
|
192 | - case 'parent_meta': |
|
193 | - $prepared[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')"; |
|
194 | - break; |
|
195 | - case 'invoice_data': |
|
196 | - $prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id"; |
|
197 | - break; |
|
198 | - case 'invoice_item': |
|
199 | - $prepared['invoice_items'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoice_items AS invoice_items ON posts.ID = invoice_items.post_id"; |
|
200 | - break; |
|
201 | - } |
|
202 | - } |
|
203 | - |
|
204 | - if ( $with_parent ) { |
|
205 | - $prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID"; |
|
206 | - } |
|
207 | - |
|
208 | - return $prepared; |
|
209 | - |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Retrieves the appropriate table key to use. |
|
214 | - * |
|
215 | - * |
|
216 | - * @param string $key |
|
217 | - * @param string $table |
|
218 | - * @return string|false |
|
219 | - */ |
|
220 | - public static function get_invoice_table_key( $key, $table ) { |
|
221 | - |
|
222 | - $keys = array( |
|
223 | - 'meta' => "meta_{$key}.meta_value", |
|
224 | - 'parent_meta' => "parent_meta_{$key}.meta_value", |
|
225 | - 'post_data' => "posts.{$key}", |
|
226 | - 'invoice_data' => "invoices.{$key}", |
|
227 | - 'invoice_item' => "invoice_items.{$key}", |
|
228 | - ); |
|
229 | - |
|
230 | - return isset( $keys[ $table ] ) ? $keys[ $table ] : false; |
|
231 | - |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * Executes a query and caches the result for a minute. |
|
236 | - * |
|
237 | - * |
|
238 | - * @param string $query_type |
|
239 | - * @param string $query |
|
240 | - * @return mixed depending on query_type |
|
241 | - */ |
|
242 | - public static function execute( $query_type, $query ) { |
|
243 | - global $wpdb; |
|
244 | - |
|
245 | - $query_hash = md5( $query_type . $query ); |
|
246 | - $result = self::get_cached_query( $query_hash ); |
|
247 | - if ( $result === false ) { |
|
248 | - self::enable_big_selects(); |
|
249 | - |
|
250 | - $result = $wpdb->$query_type( $query ); |
|
251 | - self::set_cached_query( $query_hash, $result ); |
|
252 | - } |
|
253 | - |
|
254 | - return $result; |
|
255 | - |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Enables big mysql selects for reports, just once for this session. |
|
260 | - */ |
|
261 | - protected static function enable_big_selects() { |
|
262 | - static $big_selects = false; |
|
263 | - |
|
264 | - global $wpdb; |
|
265 | - |
|
266 | - if ( ! $big_selects ) { |
|
267 | - $wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' ); |
|
268 | - $big_selects = true; |
|
269 | - } |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * Get the cached query result or null if it's not in the cache. |
|
274 | - * |
|
275 | - * @param string $query_hash The query hash. |
|
276 | - * |
|
277 | - * @return mixed|false The cache contents on success, false on failure to retrieve contents. |
|
278 | - */ |
|
279 | - protected static function get_cached_query( $query_hash ) { |
|
280 | - |
|
281 | - return wp_cache_get( |
|
282 | - $query_hash, |
|
283 | - strtolower( __CLASS__ ) |
|
284 | - ); |
|
285 | - |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * Set the cached query result. |
|
290 | - * |
|
291 | - * @param string $query_hash The query hash. |
|
292 | - * @param mixed $data The data to cache. |
|
293 | - */ |
|
294 | - protected static function set_cached_query( $query_hash, $data ) { |
|
295 | - |
|
296 | - wp_cache_set( |
|
297 | - $query_hash, |
|
298 | - $data, |
|
299 | - strtolower( __CLASS__ ), |
|
300 | - MINUTE_IN_SECONDS |
|
301 | - ); |
|
302 | - |
|
303 | - } |
|
93 | + if ( strtolower( $value['operator'] ) === 'in' || strtolower( $value['operator'] ) === 'not in' ) { |
|
94 | + |
|
95 | + if ( is_array( $value['value'] ) ) { |
|
96 | + $value['value'] = implode( "','", $value['value'] ); |
|
97 | + } |
|
98 | + |
|
99 | + if ( ! empty( $value['value'] ) ) { |
|
100 | + $where_value = "{$value['operator']} ('{$value['value']}')"; |
|
101 | + } |
|
102 | + } else { |
|
103 | + $where_value = "{$value['operator']} '{$value['value']}'"; |
|
104 | + } |
|
105 | + |
|
106 | + if ( ! empty( $where_value ) ) { |
|
107 | + $query['where'] .= " AND {$value['key']} {$where_value}"; |
|
108 | + } |
|
109 | + } |
|
110 | + } |
|
111 | + |
|
112 | + if ( $group_by ) { |
|
113 | + $query['group_by'] = "GROUP BY {$group_by}"; |
|
114 | + } |
|
115 | + |
|
116 | + if ( $order_by ) { |
|
117 | + $query['order_by'] = "ORDER BY {$order_by}"; |
|
118 | + } |
|
119 | + |
|
120 | + if ( $limit ) { |
|
121 | + $query['limit'] = "LIMIT {$limit}"; |
|
122 | + } |
|
123 | + |
|
124 | + $query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data ); |
|
125 | + $query = implode( ' ', $query ); |
|
126 | + |
|
127 | + return self::execute( $query_type, $query ); |
|
128 | + |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Prepares the data to select. |
|
133 | + * |
|
134 | + * |
|
135 | + * @param array $data |
|
136 | + * @return array |
|
137 | + */ |
|
138 | + public static function prepare_invoice_data( $data ) { |
|
139 | + |
|
140 | + $prepared = array(); |
|
141 | + |
|
142 | + foreach ( $data as $raw_key => $value ) { |
|
143 | + $key = sanitize_key( $raw_key ); |
|
144 | + $distinct = ''; |
|
145 | + |
|
146 | + if ( isset( $value['distinct'] ) ) { |
|
147 | + $distinct = 'DISTINCT'; |
|
148 | + } |
|
149 | + |
|
150 | + $get_key = self::get_invoice_table_key( $key, $value['type'] ); |
|
151 | + |
|
152 | + if ( false === $get_key ) { |
|
153 | + // Skip to the next foreach iteration else the query will be invalid. |
|
154 | + continue; |
|
155 | + } |
|
156 | + |
|
157 | + if ( ! empty( $value['function'] ) ) { |
|
158 | + $get = "{$value['function']}({$distinct} {$get_key})"; |
|
159 | + } else { |
|
160 | + $get = "{$distinct} {$get_key}"; |
|
161 | + } |
|
162 | + |
|
163 | + $prepared[] = "{$get} as {$value['name']}"; |
|
164 | + } |
|
165 | + |
|
166 | + return $prepared; |
|
167 | + |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Prepares the joins to use. |
|
172 | + * |
|
173 | + * |
|
174 | + * @param array $data |
|
175 | + * @param bool $with_parent |
|
176 | + * @return array |
|
177 | + */ |
|
178 | + public static function prepare_invoice_joins( $data, $with_parent ) { |
|
179 | + global $wpdb; |
|
180 | + |
|
181 | + $prepared = array(); |
|
182 | + |
|
183 | + foreach ( $data as $raw_key => $value ) { |
|
184 | + $join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER'; |
|
185 | + $type = isset( $value['type'] ) ? $value['type'] : false; |
|
186 | + $key = sanitize_key( $raw_key ); |
|
187 | + |
|
188 | + switch ( $type ) { |
|
189 | + case 'meta': |
|
190 | + $prepared[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )"; |
|
191 | + break; |
|
192 | + case 'parent_meta': |
|
193 | + $prepared[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')"; |
|
194 | + break; |
|
195 | + case 'invoice_data': |
|
196 | + $prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id"; |
|
197 | + break; |
|
198 | + case 'invoice_item': |
|
199 | + $prepared['invoice_items'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoice_items AS invoice_items ON posts.ID = invoice_items.post_id"; |
|
200 | + break; |
|
201 | + } |
|
202 | + } |
|
203 | + |
|
204 | + if ( $with_parent ) { |
|
205 | + $prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID"; |
|
206 | + } |
|
207 | + |
|
208 | + return $prepared; |
|
209 | + |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Retrieves the appropriate table key to use. |
|
214 | + * |
|
215 | + * |
|
216 | + * @param string $key |
|
217 | + * @param string $table |
|
218 | + * @return string|false |
|
219 | + */ |
|
220 | + public static function get_invoice_table_key( $key, $table ) { |
|
221 | + |
|
222 | + $keys = array( |
|
223 | + 'meta' => "meta_{$key}.meta_value", |
|
224 | + 'parent_meta' => "parent_meta_{$key}.meta_value", |
|
225 | + 'post_data' => "posts.{$key}", |
|
226 | + 'invoice_data' => "invoices.{$key}", |
|
227 | + 'invoice_item' => "invoice_items.{$key}", |
|
228 | + ); |
|
229 | + |
|
230 | + return isset( $keys[ $table ] ) ? $keys[ $table ] : false; |
|
231 | + |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * Executes a query and caches the result for a minute. |
|
236 | + * |
|
237 | + * |
|
238 | + * @param string $query_type |
|
239 | + * @param string $query |
|
240 | + * @return mixed depending on query_type |
|
241 | + */ |
|
242 | + public static function execute( $query_type, $query ) { |
|
243 | + global $wpdb; |
|
244 | + |
|
245 | + $query_hash = md5( $query_type . $query ); |
|
246 | + $result = self::get_cached_query( $query_hash ); |
|
247 | + if ( $result === false ) { |
|
248 | + self::enable_big_selects(); |
|
249 | + |
|
250 | + $result = $wpdb->$query_type( $query ); |
|
251 | + self::set_cached_query( $query_hash, $result ); |
|
252 | + } |
|
253 | + |
|
254 | + return $result; |
|
255 | + |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Enables big mysql selects for reports, just once for this session. |
|
260 | + */ |
|
261 | + protected static function enable_big_selects() { |
|
262 | + static $big_selects = false; |
|
263 | + |
|
264 | + global $wpdb; |
|
265 | + |
|
266 | + if ( ! $big_selects ) { |
|
267 | + $wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' ); |
|
268 | + $big_selects = true; |
|
269 | + } |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * Get the cached query result or null if it's not in the cache. |
|
274 | + * |
|
275 | + * @param string $query_hash The query hash. |
|
276 | + * |
|
277 | + * @return mixed|false The cache contents on success, false on failure to retrieve contents. |
|
278 | + */ |
|
279 | + protected static function get_cached_query( $query_hash ) { |
|
280 | + |
|
281 | + return wp_cache_get( |
|
282 | + $query_hash, |
|
283 | + strtolower( __CLASS__ ) |
|
284 | + ); |
|
285 | + |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * Set the cached query result. |
|
290 | + * |
|
291 | + * @param string $query_hash The query hash. |
|
292 | + * @param mixed $data The data to cache. |
|
293 | + */ |
|
294 | + protected static function set_cached_query( $query_hash, $data ) { |
|
295 | + |
|
296 | + wp_cache_set( |
|
297 | + $query_hash, |
|
298 | + $data, |
|
299 | + strtolower( __CLASS__ ), |
|
300 | + MINUTE_IN_SECONDS |
|
301 | + ); |
|
302 | + |
|
303 | + } |
|
304 | 304 | |
305 | 305 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Reports_Helper Class. |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * @param array $args |
27 | 27 | * @return mixed depending on query_type |
28 | 28 | */ |
29 | - public static function get_invoice_report_data( $args = array() ) { |
|
29 | + public static function get_invoice_report_data($args = array()) { |
|
30 | 30 | global $wpdb; |
31 | 31 | |
32 | 32 | $default_args = array( |
@@ -37,94 +37,94 @@ discard block |
||
37 | 37 | 'order_by' => '', // What to order by. |
38 | 38 | 'limit' => '', // Results limit. |
39 | 39 | 'filter_range' => array(), // An array of before and after dates to limit results by. |
40 | - 'invoice_types' => array( 'wpi_invoice' ), // An array of post types to retrieve. |
|
41 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold' ), |
|
40 | + 'invoice_types' => array('wpi_invoice'), // An array of post types to retrieve. |
|
41 | + 'invoice_status' => array('publish', 'wpi-processing', 'wpi-onhold'), |
|
42 | 42 | 'parent_invoice_status' => false, // Optionally filter by parent invoice status. |
43 | 43 | ); |
44 | 44 | |
45 | - $args = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args ); |
|
46 | - $args = wp_parse_args( $args, $default_args ); |
|
45 | + $args = apply_filters('getpaid_reports_get_invoice_report_data_args', $args); |
|
46 | + $args = wp_parse_args($args, $default_args); |
|
47 | 47 | |
48 | - extract( $args ); |
|
48 | + extract($args); |
|
49 | 49 | |
50 | - if ( empty( $data ) ) { |
|
50 | + if (empty($data)) { |
|
51 | 51 | return ''; |
52 | 52 | } |
53 | 53 | |
54 | 54 | $query = array(); |
55 | - $query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) ); |
|
55 | + $query['select'] = 'SELECT ' . implode(',', self::prepare_invoice_data($data)); |
|
56 | 56 | $query['from'] = "FROM {$wpdb->posts} AS posts"; |
57 | - $query['join'] = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) ); |
|
57 | + $query['join'] = implode(' ', self::prepare_invoice_joins($data + $where, !empty($parent_invoice_status))); |
|
58 | 58 | |
59 | 59 | $query['where'] = " |
60 | - WHERE posts.post_type IN ( '" . implode( "','", $invoice_types ) . "' ) |
|
60 | + WHERE posts.post_type IN ( '" . implode("','", $invoice_types) . "' ) |
|
61 | 61 | "; |
62 | 62 | |
63 | - if ( ! empty( $invoice_status ) ) { |
|
63 | + if (!empty($invoice_status)) { |
|
64 | 64 | $query['where'] .= " |
65 | - AND posts.post_status IN ( '" . implode( "','", $invoice_status ) . "' ) |
|
65 | + AND posts.post_status IN ( '" . implode("','", $invoice_status) . "' ) |
|
66 | 66 | "; |
67 | 67 | } |
68 | 68 | |
69 | - if ( ! empty( $parent_invoice_status ) ) { |
|
70 | - if ( ! empty( $invoice_status ) ) { |
|
71 | - $query['where'] .= " AND ( parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) OR parent.ID IS NULL ) "; |
|
69 | + if (!empty($parent_invoice_status)) { |
|
70 | + if (!empty($invoice_status)) { |
|
71 | + $query['where'] .= " AND ( parent.post_status IN ( '" . implode("','", $parent_invoice_status) . "' ) OR parent.ID IS NULL ) "; |
|
72 | 72 | } else { |
73 | - $query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) "; |
|
73 | + $query['where'] .= " AND parent.post_status IN ( '" . implode("','", $parent_invoice_status) . "' ) "; |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
77 | - if ( ! empty( $filter_range['before'] ) ) { |
|
77 | + if (!empty($filter_range['before'])) { |
|
78 | 78 | $query['where'] .= " |
79 | - AND posts.post_date <= '" . gmdate( 'Y-m-d 23:59:59', strtotime( $filter_range['before'] ) ) . "' |
|
79 | + AND posts.post_date <= '" . gmdate('Y-m-d 23:59:59', strtotime($filter_range['before'])) . "' |
|
80 | 80 | "; |
81 | 81 | } |
82 | 82 | |
83 | - if ( ! empty( $filter_range['after'] ) ) { |
|
83 | + if (!empty($filter_range['after'])) { |
|
84 | 84 | $query['where'] .= " |
85 | - AND posts.post_date >= '" . gmdate( 'Y-m-d 00:00:00', strtotime( $filter_range['after'] ) ) . "' |
|
85 | + AND posts.post_date >= '" . gmdate('Y-m-d 00:00:00', strtotime($filter_range['after'])) . "' |
|
86 | 86 | "; |
87 | 87 | } |
88 | 88 | |
89 | - if ( ! empty( $where ) ) { |
|
89 | + if (!empty($where)) { |
|
90 | 90 | |
91 | - foreach ( $where as $value ) { |
|
91 | + foreach ($where as $value) { |
|
92 | 92 | |
93 | - if ( strtolower( $value['operator'] ) === 'in' || strtolower( $value['operator'] ) === 'not in' ) { |
|
93 | + if (strtolower($value['operator']) === 'in' || strtolower($value['operator']) === 'not in') { |
|
94 | 94 | |
95 | - if ( is_array( $value['value'] ) ) { |
|
96 | - $value['value'] = implode( "','", $value['value'] ); |
|
95 | + if (is_array($value['value'])) { |
|
96 | + $value['value'] = implode("','", $value['value']); |
|
97 | 97 | } |
98 | 98 | |
99 | - if ( ! empty( $value['value'] ) ) { |
|
99 | + if (!empty($value['value'])) { |
|
100 | 100 | $where_value = "{$value['operator']} ('{$value['value']}')"; |
101 | 101 | } |
102 | 102 | } else { |
103 | 103 | $where_value = "{$value['operator']} '{$value['value']}'"; |
104 | 104 | } |
105 | 105 | |
106 | - if ( ! empty( $where_value ) ) { |
|
106 | + if (!empty($where_value)) { |
|
107 | 107 | $query['where'] .= " AND {$value['key']} {$where_value}"; |
108 | 108 | } |
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
112 | - if ( $group_by ) { |
|
112 | + if ($group_by) { |
|
113 | 113 | $query['group_by'] = "GROUP BY {$group_by}"; |
114 | 114 | } |
115 | 115 | |
116 | - if ( $order_by ) { |
|
116 | + if ($order_by) { |
|
117 | 117 | $query['order_by'] = "ORDER BY {$order_by}"; |
118 | 118 | } |
119 | 119 | |
120 | - if ( $limit ) { |
|
120 | + if ($limit) { |
|
121 | 121 | $query['limit'] = "LIMIT {$limit}"; |
122 | 122 | } |
123 | 123 | |
124 | - $query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data ); |
|
125 | - $query = implode( ' ', $query ); |
|
124 | + $query = apply_filters('getpaid_reports_get_invoice_report_query', $query, $data); |
|
125 | + $query = implode(' ', $query); |
|
126 | 126 | |
127 | - return self::execute( $query_type, $query ); |
|
127 | + return self::execute($query_type, $query); |
|
128 | 128 | |
129 | 129 | } |
130 | 130 | |
@@ -135,26 +135,26 @@ discard block |
||
135 | 135 | * @param array $data |
136 | 136 | * @return array |
137 | 137 | */ |
138 | - public static function prepare_invoice_data( $data ) { |
|
138 | + public static function prepare_invoice_data($data) { |
|
139 | 139 | |
140 | 140 | $prepared = array(); |
141 | 141 | |
142 | - foreach ( $data as $raw_key => $value ) { |
|
143 | - $key = sanitize_key( $raw_key ); |
|
142 | + foreach ($data as $raw_key => $value) { |
|
143 | + $key = sanitize_key($raw_key); |
|
144 | 144 | $distinct = ''; |
145 | 145 | |
146 | - if ( isset( $value['distinct'] ) ) { |
|
146 | + if (isset($value['distinct'])) { |
|
147 | 147 | $distinct = 'DISTINCT'; |
148 | 148 | } |
149 | 149 | |
150 | - $get_key = self::get_invoice_table_key( $key, $value['type'] ); |
|
150 | + $get_key = self::get_invoice_table_key($key, $value['type']); |
|
151 | 151 | |
152 | - if ( false === $get_key ) { |
|
152 | + if (false === $get_key) { |
|
153 | 153 | // Skip to the next foreach iteration else the query will be invalid. |
154 | 154 | continue; |
155 | 155 | } |
156 | 156 | |
157 | - if ( ! empty( $value['function'] ) ) { |
|
157 | + if (!empty($value['function'])) { |
|
158 | 158 | $get = "{$value['function']}({$distinct} {$get_key})"; |
159 | 159 | } else { |
160 | 160 | $get = "{$distinct} {$get_key}"; |
@@ -175,22 +175,22 @@ discard block |
||
175 | 175 | * @param bool $with_parent |
176 | 176 | * @return array |
177 | 177 | */ |
178 | - public static function prepare_invoice_joins( $data, $with_parent ) { |
|
178 | + public static function prepare_invoice_joins($data, $with_parent) { |
|
179 | 179 | global $wpdb; |
180 | 180 | |
181 | 181 | $prepared = array(); |
182 | 182 | |
183 | - foreach ( $data as $raw_key => $value ) { |
|
184 | - $join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER'; |
|
185 | - $type = isset( $value['type'] ) ? $value['type'] : false; |
|
186 | - $key = sanitize_key( $raw_key ); |
|
183 | + foreach ($data as $raw_key => $value) { |
|
184 | + $join_type = isset($value['join_type']) ? $value['join_type'] : 'INNER'; |
|
185 | + $type = isset($value['type']) ? $value['type'] : false; |
|
186 | + $key = sanitize_key($raw_key); |
|
187 | 187 | |
188 | - switch ( $type ) { |
|
188 | + switch ($type) { |
|
189 | 189 | case 'meta': |
190 | - $prepared[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )"; |
|
190 | + $prepared["meta_{$key}"] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )"; |
|
191 | 191 | break; |
192 | 192 | case 'parent_meta': |
193 | - $prepared[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')"; |
|
193 | + $prepared["parent_meta_{$key}"] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')"; |
|
194 | 194 | break; |
195 | 195 | case 'invoice_data': |
196 | 196 | $prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id"; |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
204 | - if ( $with_parent ) { |
|
204 | + if ($with_parent) { |
|
205 | 205 | $prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID"; |
206 | 206 | } |
207 | 207 | |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * @param string $table |
218 | 218 | * @return string|false |
219 | 219 | */ |
220 | - public static function get_invoice_table_key( $key, $table ) { |
|
220 | + public static function get_invoice_table_key($key, $table) { |
|
221 | 221 | |
222 | 222 | $keys = array( |
223 | 223 | 'meta' => "meta_{$key}.meta_value", |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | 'invoice_item' => "invoice_items.{$key}", |
228 | 228 | ); |
229 | 229 | |
230 | - return isset( $keys[ $table ] ) ? $keys[ $table ] : false; |
|
230 | + return isset($keys[$table]) ? $keys[$table] : false; |
|
231 | 231 | |
232 | 232 | } |
233 | 233 | |
@@ -239,16 +239,16 @@ discard block |
||
239 | 239 | * @param string $query |
240 | 240 | * @return mixed depending on query_type |
241 | 241 | */ |
242 | - public static function execute( $query_type, $query ) { |
|
242 | + public static function execute($query_type, $query) { |
|
243 | 243 | global $wpdb; |
244 | 244 | |
245 | - $query_hash = md5( $query_type . $query ); |
|
246 | - $result = self::get_cached_query( $query_hash ); |
|
247 | - if ( $result === false ) { |
|
245 | + $query_hash = md5($query_type . $query); |
|
246 | + $result = self::get_cached_query($query_hash); |
|
247 | + if ($result === false) { |
|
248 | 248 | self::enable_big_selects(); |
249 | 249 | |
250 | - $result = $wpdb->$query_type( $query ); |
|
251 | - self::set_cached_query( $query_hash, $result ); |
|
250 | + $result = $wpdb->$query_type($query); |
|
251 | + self::set_cached_query($query_hash, $result); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | return $result; |
@@ -263,8 +263,8 @@ discard block |
||
263 | 263 | |
264 | 264 | global $wpdb; |
265 | 265 | |
266 | - if ( ! $big_selects ) { |
|
267 | - $wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' ); |
|
266 | + if (!$big_selects) { |
|
267 | + $wpdb->query('SET SESSION SQL_BIG_SELECTS=1'); |
|
268 | 268 | $big_selects = true; |
269 | 269 | } |
270 | 270 | } |
@@ -276,11 +276,11 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @return mixed|false The cache contents on success, false on failure to retrieve contents. |
278 | 278 | */ |
279 | - protected static function get_cached_query( $query_hash ) { |
|
279 | + protected static function get_cached_query($query_hash) { |
|
280 | 280 | |
281 | 281 | return wp_cache_get( |
282 | 282 | $query_hash, |
283 | - strtolower( __CLASS__ ) |
|
283 | + strtolower(__CLASS__) |
|
284 | 284 | ); |
285 | 285 | |
286 | 286 | } |
@@ -291,12 +291,12 @@ discard block |
||
291 | 291 | * @param string $query_hash The query hash. |
292 | 292 | * @param mixed $data The data to cache. |
293 | 293 | */ |
294 | - protected static function set_cached_query( $query_hash, $data ) { |
|
294 | + protected static function set_cached_query($query_hash, $data) { |
|
295 | 295 | |
296 | 296 | wp_cache_set( |
297 | 297 | $query_hash, |
298 | 298 | $data, |
299 | - strtolower( __CLASS__ ), |
|
299 | + strtolower(__CLASS__), |
|
300 | 300 | MINUTE_IN_SECONDS |
301 | 301 | ); |
302 | 302 |
@@ -12,144 +12,144 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Daily_Maintenance { |
14 | 14 | |
15 | - /** |
|
16 | - * Class constructor. |
|
17 | - */ |
|
18 | - public function __construct() { |
|
19 | - |
|
20 | - // Clear deprecated events. |
|
21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | - |
|
23 | - // (Maybe) schedule a cron that runs daily. |
|
24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | - |
|
26 | - // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | - add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
31 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
32 | - |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Schedules a cron to run every day at 7 a.m |
|
37 | - * |
|
38 | - */ |
|
39 | - public function maybe_create_scheduled_event() { |
|
40 | - |
|
41 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
42 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
43 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
44 | - } |
|
45 | - |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Clears deprecated events. |
|
50 | - * |
|
51 | - */ |
|
52 | - public function maybe_clear_deprecated_events() { |
|
53 | - |
|
54 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
55 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
56 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
57 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
58 | - } |
|
59 | - |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Fires the old hook for backwards compatibility. |
|
64 | - * |
|
65 | - */ |
|
66 | - public function backwards_compat() { |
|
67 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Checks for subscriptions that are scheduled to renew. |
|
72 | - * |
|
73 | - */ |
|
74 | - public function check_renewing_subscriptions() { |
|
75 | - |
|
76 | - // Fetch subscriptions that expire today. |
|
77 | - $args = array( |
|
78 | - 'number' => -1, |
|
79 | - 'count_total' => false, |
|
80 | - 'status' => 'trialling active', |
|
81 | - 'date_expires_query' => array( |
|
82 | - array( |
|
83 | - 'year' => gmdate( 'Y' ), |
|
84 | - 'month' => gmdate( 'n' ), |
|
85 | - 'day' => gmdate( 'j' ), |
|
86 | - 'compare' => '=', |
|
87 | - ), |
|
88 | - ), |
|
89 | - ); |
|
90 | - |
|
91 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
92 | - |
|
93 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
94 | - |
|
95 | - /** @var WPInv_Subscription $subscription */ |
|
96 | - if ( $subscription->is_last_renewal() ) { |
|
97 | - $subscription->complete(); |
|
98 | - } else { |
|
99 | - do_action( 'getpaid_should_renew_subscription', $subscription ); |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Expires expired subscriptions. |
|
107 | - * |
|
108 | - */ |
|
109 | - public function maybe_expire_subscriptions() { |
|
110 | - |
|
111 | - // Fetch expired subscriptions (skips those that expire today). |
|
112 | - $args = array( |
|
113 | - 'number' => -1, |
|
114 | - 'count_total' => false, |
|
115 | - 'status' => 'trialling active failing cancelled', |
|
116 | - 'date_expires_query' => array( |
|
117 | - 'before' => 'yesterday', |
|
118 | - 'inclusive' => false, |
|
119 | - ), |
|
120 | - ); |
|
121 | - |
|
122 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
123 | - |
|
124 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
125 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
126 | - $subscription->set_status( 'expired' ); |
|
127 | - $subscription->save(); |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Logs cron runs. |
|
135 | - * |
|
136 | - */ |
|
137 | - public function log_cron_run() { |
|
138 | - wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Updates GeoIP databases. |
|
143 | - * |
|
144 | - */ |
|
145 | - public function maybe_update_geoip_databases() { |
|
146 | - $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
147 | - |
|
148 | - if ( false === $updated ) { |
|
149 | - set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
150 | - do_action( 'getpaid_update_geoip_databases' ); |
|
151 | - } |
|
152 | - |
|
153 | - } |
|
15 | + /** |
|
16 | + * Class constructor. |
|
17 | + */ |
|
18 | + public function __construct() { |
|
19 | + |
|
20 | + // Clear deprecated events. |
|
21 | + add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | + |
|
23 | + // (Maybe) schedule a cron that runs daily. |
|
24 | + add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | + |
|
26 | + // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | + add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | + add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | + add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
31 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
32 | + |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Schedules a cron to run every day at 7 a.m |
|
37 | + * |
|
38 | + */ |
|
39 | + public function maybe_create_scheduled_event() { |
|
40 | + |
|
41 | + if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
42 | + $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
43 | + wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
44 | + } |
|
45 | + |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Clears deprecated events. |
|
50 | + * |
|
51 | + */ |
|
52 | + public function maybe_clear_deprecated_events() { |
|
53 | + |
|
54 | + if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
55 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
56 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
57 | + update_option( 'wpinv_cleared_old_events', 1 ); |
|
58 | + } |
|
59 | + |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Fires the old hook for backwards compatibility. |
|
64 | + * |
|
65 | + */ |
|
66 | + public function backwards_compat() { |
|
67 | + do_action( 'wpinv_register_schedule_event_daily' ); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Checks for subscriptions that are scheduled to renew. |
|
72 | + * |
|
73 | + */ |
|
74 | + public function check_renewing_subscriptions() { |
|
75 | + |
|
76 | + // Fetch subscriptions that expire today. |
|
77 | + $args = array( |
|
78 | + 'number' => -1, |
|
79 | + 'count_total' => false, |
|
80 | + 'status' => 'trialling active', |
|
81 | + 'date_expires_query' => array( |
|
82 | + array( |
|
83 | + 'year' => gmdate( 'Y' ), |
|
84 | + 'month' => gmdate( 'n' ), |
|
85 | + 'day' => gmdate( 'j' ), |
|
86 | + 'compare' => '=', |
|
87 | + ), |
|
88 | + ), |
|
89 | + ); |
|
90 | + |
|
91 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
92 | + |
|
93 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
94 | + |
|
95 | + /** @var WPInv_Subscription $subscription */ |
|
96 | + if ( $subscription->is_last_renewal() ) { |
|
97 | + $subscription->complete(); |
|
98 | + } else { |
|
99 | + do_action( 'getpaid_should_renew_subscription', $subscription ); |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Expires expired subscriptions. |
|
107 | + * |
|
108 | + */ |
|
109 | + public function maybe_expire_subscriptions() { |
|
110 | + |
|
111 | + // Fetch expired subscriptions (skips those that expire today). |
|
112 | + $args = array( |
|
113 | + 'number' => -1, |
|
114 | + 'count_total' => false, |
|
115 | + 'status' => 'trialling active failing cancelled', |
|
116 | + 'date_expires_query' => array( |
|
117 | + 'before' => 'yesterday', |
|
118 | + 'inclusive' => false, |
|
119 | + ), |
|
120 | + ); |
|
121 | + |
|
122 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
123 | + |
|
124 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
125 | + if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
126 | + $subscription->set_status( 'expired' ); |
|
127 | + $subscription->save(); |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Logs cron runs. |
|
135 | + * |
|
136 | + */ |
|
137 | + public function log_cron_run() { |
|
138 | + wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Updates GeoIP databases. |
|
143 | + * |
|
144 | + */ |
|
145 | + public function maybe_update_geoip_databases() { |
|
146 | + $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
147 | + |
|
148 | + if ( false === $updated ) { |
|
149 | + set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
150 | + do_action( 'getpaid_update_geoip_databases' ); |
|
151 | + } |
|
152 | + |
|
153 | + } |
|
154 | 154 | |
155 | 155 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Daily maintenance class. |
@@ -18,17 +18,17 @@ discard block |
||
18 | 18 | public function __construct() { |
19 | 19 | |
20 | 20 | // Clear deprecated events. |
21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
21 | + add_action('wp', array($this, 'maybe_clear_deprecated_events')); |
|
22 | 22 | |
23 | 23 | // (Maybe) schedule a cron that runs daily. |
24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
24 | + add_action('wp', array($this, 'maybe_create_scheduled_event')); |
|
25 | 25 | |
26 | 26 | // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | - add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
31 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
27 | + add_action('getpaid_daily_maintenance', array($this, 'log_cron_run')); |
|
28 | + add_action('getpaid_daily_maintenance', array($this, 'backwards_compat')); |
|
29 | + add_action('getpaid_daily_maintenance', array($this, 'maybe_expire_subscriptions')); |
|
30 | + add_action('getpaid_daily_maintenance', array($this, 'check_renewing_subscriptions')); |
|
31 | + add_action('getpaid_daily_maintenance', array($this, 'maybe_update_geoip_databases')); |
|
32 | 32 | |
33 | 33 | } |
34 | 34 | |
@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function maybe_create_scheduled_event() { |
40 | 40 | |
41 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
42 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
43 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
41 | + if (!wp_next_scheduled('getpaid_daily_maintenance')) { |
|
42 | + $timestamp = strtotime('tomorrow 07:00:00', current_time('timestamp')); |
|
43 | + wp_schedule_event($timestamp, 'daily', 'getpaid_daily_maintenance'); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | } |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function maybe_clear_deprecated_events() { |
53 | 53 | |
54 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
55 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
56 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
57 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
54 | + if (!get_option('wpinv_cleared_old_events')) { |
|
55 | + wp_clear_scheduled_hook('wpinv_register_schedule_event_twicedaily'); |
|
56 | + wp_clear_scheduled_hook('wpinv_register_schedule_event_daily'); |
|
57 | + update_option('wpinv_cleared_old_events', 1); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * |
65 | 65 | */ |
66 | 66 | public function backwards_compat() { |
67 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
67 | + do_action('wpinv_register_schedule_event_daily'); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -74,29 +74,29 @@ discard block |
||
74 | 74 | public function check_renewing_subscriptions() { |
75 | 75 | |
76 | 76 | // Fetch subscriptions that expire today. |
77 | - $args = array( |
|
77 | + $args = array( |
|
78 | 78 | 'number' => -1, |
79 | 79 | 'count_total' => false, |
80 | 80 | 'status' => 'trialling active', |
81 | 81 | 'date_expires_query' => array( |
82 | 82 | array( |
83 | - 'year' => gmdate( 'Y' ), |
|
84 | - 'month' => gmdate( 'n' ), |
|
85 | - 'day' => gmdate( 'j' ), |
|
83 | + 'year' => gmdate('Y'), |
|
84 | + 'month' => gmdate('n'), |
|
85 | + 'day' => gmdate('j'), |
|
86 | 86 | 'compare' => '=', |
87 | 87 | ), |
88 | 88 | ), |
89 | 89 | ); |
90 | 90 | |
91 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
91 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
92 | 92 | |
93 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
93 | + foreach ($subscriptions->get_results() as $subscription) { |
|
94 | 94 | |
95 | 95 | /** @var WPInv_Subscription $subscription */ |
96 | - if ( $subscription->is_last_renewal() ) { |
|
96 | + if ($subscription->is_last_renewal()) { |
|
97 | 97 | $subscription->complete(); |
98 | 98 | } else { |
99 | - do_action( 'getpaid_should_renew_subscription', $subscription ); |
|
99 | + do_action('getpaid_should_renew_subscription', $subscription); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | public function maybe_expire_subscriptions() { |
110 | 110 | |
111 | 111 | // Fetch expired subscriptions (skips those that expire today). |
112 | - $args = array( |
|
112 | + $args = array( |
|
113 | 113 | 'number' => -1, |
114 | 114 | 'count_total' => false, |
115 | 115 | 'status' => 'trialling active failing cancelled', |
@@ -119,11 +119,11 @@ discard block |
||
119 | 119 | ), |
120 | 120 | ); |
121 | 121 | |
122 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
122 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
123 | 123 | |
124 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
125 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
126 | - $subscription->set_status( 'expired' ); |
|
124 | + foreach ($subscriptions->get_results() as $subscription) { |
|
125 | + if (apply_filters('getpaid_daily_maintenance_should_expire_subscription', false, $subscription)) { |
|
126 | + $subscription->set_status('expired'); |
|
127 | 127 | $subscription->save(); |
128 | 128 | } |
129 | 129 | } |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | * |
136 | 136 | */ |
137 | 137 | public function log_cron_run() { |
138 | - wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
138 | + wpinv_error_log('GetPaid Daily Cron', false); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -143,11 +143,11 @@ discard block |
||
143 | 143 | * |
144 | 144 | */ |
145 | 145 | public function maybe_update_geoip_databases() { |
146 | - $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
146 | + $updated = get_transient('getpaid_updated_geoip_databases'); |
|
147 | 147 | |
148 | - if ( false === $updated ) { |
|
149 | - set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
150 | - do_action( 'getpaid_update_geoip_databases' ); |
|
148 | + if (false === $updated) { |
|
149 | + set_transient('getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS); |
|
150 | + do_action('getpaid_update_geoip_databases'); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | } |
@@ -39,62 +39,62 @@ discard block |
||
39 | 39 | <td style="width: 65%"> |
40 | 40 | <?php |
41 | 41 | |
42 | - switch ( $key ) { |
|
42 | + switch ( $key ) { |
|
43 | 43 | |
44 | - case 'status': |
|
45 | - echo esc_html( $subscription->get_status_label() ); |
|
46 | - break; |
|
44 | + case 'status': |
|
45 | + echo esc_html( $subscription->get_status_label() ); |
|
46 | + break; |
|
47 | 47 | |
48 | - case 'start_date': |
|
49 | - echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
50 | - break; |
|
48 | + case 'start_date': |
|
49 | + echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
50 | + break; |
|
51 | 51 | |
52 | - case 'expiry_date': |
|
53 | - echo esc_html( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
54 | - break; |
|
52 | + case 'expiry_date': |
|
53 | + echo esc_html( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
54 | + break; |
|
55 | 55 | |
56 | - case 'initial_amount': |
|
57 | - echo wp_kses_post( wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ) ); |
|
56 | + case 'initial_amount': |
|
57 | + echo wp_kses_post( wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ) ); |
|
58 | 58 | |
59 | - if ( $subscription->has_trial_period() ) { |
|
59 | + if ( $subscription->has_trial_period() ) { |
|
60 | 60 | |
61 | - echo "<small class='text-muted'> "; |
|
62 | - printf( |
|
63 | - esc_html_x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
64 | - esc_html( $subscription->get_trial_period() ) |
|
65 | - ); |
|
66 | - echo '</small>'; |
|
61 | + echo "<small class='text-muted'> "; |
|
62 | + printf( |
|
63 | + esc_html_x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
64 | + esc_html( $subscription->get_trial_period() ) |
|
65 | + ); |
|
66 | + echo '</small>'; |
|
67 | 67 | |
68 | - } |
|
68 | + } |
|
69 | 69 | |
70 | - break; |
|
70 | + break; |
|
71 | 71 | |
72 | - case 'recurring_amount': |
|
73 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
74 | - $amount = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
75 | - echo wp_kses_post( strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" ) ); |
|
76 | - break; |
|
72 | + case 'recurring_amount': |
|
73 | + $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
74 | + $amount = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
75 | + echo wp_kses_post( strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" ) ); |
|
76 | + break; |
|
77 | 77 | |
78 | - case 'item': |
|
79 | - if ( empty( $subscription_group ) ) { |
|
80 | - echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
81 | - } else { |
|
82 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
83 | - echo wp_kses_post( implode( ' | ', $markup ) ); |
|
84 | - } |
|
78 | + case 'item': |
|
79 | + if ( empty( $subscription_group ) ) { |
|
80 | + echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
81 | + } else { |
|
82 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
83 | + echo wp_kses_post( implode( ' | ', $markup ) ); |
|
84 | + } |
|
85 | 85 | |
86 | - break; |
|
86 | + break; |
|
87 | 87 | |
88 | - case 'payments': |
|
89 | - $max_activations = (int) $subscription->get_bill_times(); |
|
90 | - echo ( (int) $subscription->get_times_billed() ) . ' / ' . ( empty( $max_activations ) ? '∞' : (int) $max_activations ); |
|
88 | + case 'payments': |
|
89 | + $max_activations = (int) $subscription->get_bill_times(); |
|
90 | + echo ( (int) $subscription->get_times_billed() ) . ' / ' . ( empty( $max_activations ) ? '∞' : (int) $max_activations ); |
|
91 | 91 | |
92 | - break; |
|
92 | + break; |
|
93 | 93 | |
94 | - } |
|
95 | - do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
94 | + } |
|
95 | + do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
96 | 96 | |
97 | - ?> |
|
97 | + ?> |
|
98 | 98 | </td> |
99 | 99 | |
100 | 100 | </tr> |
@@ -121,17 +121,17 @@ discard block |
||
121 | 121 | <span class="form-text"> |
122 | 122 | |
123 | 123 | <?php |
124 | - if ( $subscription->can_cancel() ) { |
|
125 | - printf( |
|
124 | + if ( $subscription->can_cancel() ) { |
|
125 | + printf( |
|
126 | 126 | '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a> ', |
127 | 127 | esc_url( $subscription->get_cancel_url() ), |
128 | 128 | esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ), |
129 | 129 | esc_html__( 'Cancel Subscription', 'invoicing' ) |
130 | 130 | ); |
131 | - } |
|
131 | + } |
|
132 | 132 | |
133 | - do_action( 'getpaid-single-subscription-page-actions', $subscription ); |
|
134 | - ?> |
|
133 | + do_action( 'getpaid-single-subscription-page-actions', $subscription ); |
|
134 | + ?> |
|
135 | 135 | |
136 | 136 | <a href="<?php echo esc_url( getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); ?>" class="btn btn-secondary btn-sm"><?php esc_html_e( 'Go Back', 'invoicing' ); ?></a> |
137 | 137 | </span> |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php |
|
1 | + <?php |
|
2 | 2 | |
3 | 3 | /** |
4 | 4 | * Template that prints a single subscription's details |
@@ -10,19 +10,19 @@ discard block |
||
10 | 10 | * @var WPInv_Subscriptions_Widget $widget |
11 | 11 | */ |
12 | 12 | |
13 | -defined( 'ABSPATH' ) || exit; |
|
13 | + defined( 'ABSPATH' ) || exit; |
|
14 | 14 | |
15 | -do_action( 'getpaid_single_subscription_before_notices', $subscription ); |
|
15 | + do_action( 'getpaid_single_subscription_before_notices', $subscription ); |
|
16 | 16 | |
17 | -// Display errors and notices. |
|
18 | -wpinv_print_errors(); |
|
17 | + // Display errors and notices. |
|
18 | + wpinv_print_errors(); |
|
19 | 19 | |
20 | -$subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_invoice_id() ); |
|
21 | -$subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
20 | + $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_invoice_id() ); |
|
21 | + $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
22 | 22 | |
23 | -do_action( 'getpaid_before_single_subscription', $subscription, $subscription_groups ); |
|
23 | + do_action( 'getpaid_before_single_subscription', $subscription, $subscription_groups ); |
|
24 | 24 | |
25 | -?> |
|
25 | + ?> |
|
26 | 26 | |
27 | 27 | <h2 class="mb-1 h4"><?php esc_html_e( 'Subscription Details', 'invoicing' ); ?></h2> |
28 | 28 | <table class="table table-bordered"> |
@@ -39,59 +39,59 @@ discard block |
||
39 | 39 | <td style="width: 65%"> |
40 | 40 | <?php |
41 | 41 | |
42 | - switch ( $key ) { |
|
42 | + switch ( $key ) { |
|
43 | 43 | |
44 | - case 'status': |
|
45 | - echo esc_html( $subscription->get_status_label() ); |
|
46 | - break; |
|
44 | + case 'status': |
|
45 | + echo esc_html( $subscription->get_status_label() ); |
|
46 | + break; |
|
47 | 47 | |
48 | - case 'start_date': |
|
49 | - echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
50 | - break; |
|
48 | + case 'start_date': |
|
49 | + echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
50 | + break; |
|
51 | 51 | |
52 | - case 'expiry_date': |
|
53 | - echo esc_html( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
54 | - break; |
|
52 | + case 'expiry_date': |
|
53 | + echo esc_html( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
54 | + break; |
|
55 | 55 | |
56 | - case 'initial_amount': |
|
57 | - echo wp_kses_post( wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ) ); |
|
56 | + case 'initial_amount': |
|
57 | + echo wp_kses_post( wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ) ); |
|
58 | 58 | |
59 | - if ( $subscription->has_trial_period() ) { |
|
59 | + if ( $subscription->has_trial_period() ) { |
|
60 | 60 | |
61 | - echo "<small class='text-muted'> "; |
|
62 | - printf( |
|
63 | - esc_html_x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
64 | - esc_html( $subscription->get_trial_period() ) |
|
65 | - ); |
|
66 | - echo '</small>'; |
|
61 | + echo "<small class='text-muted'> "; |
|
62 | + printf( |
|
63 | + esc_html_x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
64 | + esc_html( $subscription->get_trial_period() ) |
|
65 | + ); |
|
66 | + echo '</small>'; |
|
67 | 67 | |
68 | - } |
|
68 | + } |
|
69 | 69 | |
70 | - break; |
|
70 | + break; |
|
71 | 71 | |
72 | - case 'recurring_amount': |
|
73 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
74 | - $amount = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
75 | - echo wp_kses_post( strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" ) ); |
|
76 | - break; |
|
72 | + case 'recurring_amount': |
|
73 | + $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
74 | + $amount = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
75 | + echo wp_kses_post( strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" ) ); |
|
76 | + break; |
|
77 | 77 | |
78 | - case 'item': |
|
79 | - if ( empty( $subscription_group ) ) { |
|
80 | - echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
81 | - } else { |
|
82 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
83 | - echo wp_kses_post( implode( ' | ', $markup ) ); |
|
84 | - } |
|
78 | + case 'item': |
|
79 | + if ( empty( $subscription_group ) ) { |
|
80 | + echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
81 | + } else { |
|
82 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
83 | + echo wp_kses_post( implode( ' | ', $markup ) ); |
|
84 | + } |
|
85 | 85 | |
86 | - break; |
|
86 | + break; |
|
87 | 87 | |
88 | - case 'payments': |
|
89 | - $max_activations = (int) $subscription->get_bill_times(); |
|
90 | - echo ( (int) $subscription->get_times_billed() ) . ' / ' . ( empty( $max_activations ) ? '∞' : (int) $max_activations ); |
|
88 | + case 'payments': |
|
89 | + $max_activations = (int) $subscription->get_bill_times(); |
|
90 | + echo ( (int) $subscription->get_times_billed() ) . ' / ' . ( empty( $max_activations ) ? '∞' : (int) $max_activations ); |
|
91 | 91 | |
92 | - break; |
|
92 | + break; |
|
93 | 93 | |
94 | - } |
|
94 | + } |
|
95 | 95 | do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
96 | 96 | |
97 | 97 | ?> |
@@ -10,58 +10,58 @@ discard block |
||
10 | 10 | * @var WPInv_Subscriptions_Widget $widget |
11 | 11 | */ |
12 | 12 | |
13 | -defined( 'ABSPATH' ) || exit; |
|
13 | +defined('ABSPATH') || exit; |
|
14 | 14 | |
15 | -do_action( 'getpaid_single_subscription_before_notices', $subscription ); |
|
15 | +do_action('getpaid_single_subscription_before_notices', $subscription); |
|
16 | 16 | |
17 | 17 | // Display errors and notices. |
18 | 18 | wpinv_print_errors(); |
19 | 19 | |
20 | -$subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_invoice_id() ); |
|
21 | -$subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
20 | +$subscription_groups = getpaid_get_invoice_subscription_groups($subscription->get_parent_invoice_id()); |
|
21 | +$subscription_group = getpaid_get_invoice_subscription_group($subscription->get_parent_invoice_id(), $subscription->get_id()); |
|
22 | 22 | |
23 | -do_action( 'getpaid_before_single_subscription', $subscription, $subscription_groups ); |
|
23 | +do_action('getpaid_before_single_subscription', $subscription, $subscription_groups); |
|
24 | 24 | |
25 | 25 | ?> |
26 | 26 | |
27 | -<h2 class="mb-1 h4"><?php esc_html_e( 'Subscription Details', 'invoicing' ); ?></h2> |
|
27 | +<h2 class="mb-1 h4"><?php esc_html_e('Subscription Details', 'invoicing'); ?></h2> |
|
28 | 28 | <table class="table table-bordered"> |
29 | 29 | <tbody> |
30 | 30 | |
31 | - <?php foreach ( $widget->get_single_subscription_columns( $subscription ) as $key => $label ) : ?> |
|
31 | + <?php foreach ($widget->get_single_subscription_columns($subscription) as $key => $label) : ?> |
|
32 | 32 | |
33 | - <tr class="getpaid-subscription-meta-<?php echo esc_attr( $key ); ?>"> |
|
33 | + <tr class="getpaid-subscription-meta-<?php echo esc_attr($key); ?>"> |
|
34 | 34 | |
35 | 35 | <th class="font-weight-bold" style="width: 35%"> |
36 | - <?php echo esc_html( $label ); ?> |
|
36 | + <?php echo esc_html($label); ?> |
|
37 | 37 | </th> |
38 | 38 | |
39 | 39 | <td style="width: 65%"> |
40 | 40 | <?php |
41 | 41 | |
42 | - switch ( $key ) { |
|
42 | + switch ($key) { |
|
43 | 43 | |
44 | 44 | case 'status': |
45 | - echo esc_html( $subscription->get_status_label() ); |
|
45 | + echo esc_html($subscription->get_status_label()); |
|
46 | 46 | break; |
47 | 47 | |
48 | 48 | case 'start_date': |
49 | - echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
49 | + echo esc_html(getpaid_format_date_value($subscription->get_date_created())); |
|
50 | 50 | break; |
51 | 51 | |
52 | 52 | case 'expiry_date': |
53 | - echo esc_html( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
53 | + echo esc_html(getpaid_format_date_value($subscription->get_next_renewal_date())); |
|
54 | 54 | break; |
55 | 55 | |
56 | 56 | case 'initial_amount': |
57 | - echo wp_kses_post( wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ) ); |
|
57 | + echo wp_kses_post(wpinv_price($subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency())); |
|
58 | 58 | |
59 | - if ( $subscription->has_trial_period() ) { |
|
59 | + if ($subscription->has_trial_period()) { |
|
60 | 60 | |
61 | 61 | echo "<small class='text-muted'> "; |
62 | 62 | printf( |
63 | - esc_html_x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
64 | - esc_html( $subscription->get_trial_period() ) |
|
63 | + esc_html_x('( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing'), |
|
64 | + esc_html($subscription->get_trial_period()) |
|
65 | 65 | ); |
66 | 66 | echo '</small>'; |
67 | 67 | |
@@ -70,29 +70,29 @@ discard block |
||
70 | 70 | break; |
71 | 71 | |
72 | 72 | case 'recurring_amount': |
73 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
74 | - $amount = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
75 | - echo wp_kses_post( strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" ) ); |
|
73 | + $frequency = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), ''); |
|
74 | + $amount = wpinv_price($subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency()); |
|
75 | + echo wp_kses_post(strtolower("<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>")); |
|
76 | 76 | break; |
77 | 77 | |
78 | 78 | case 'item': |
79 | - if ( empty( $subscription_group ) ) { |
|
80 | - echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
79 | + if (empty($subscription_group)) { |
|
80 | + echo wp_kses_post(WPInv_Subscriptions_List_Table::generate_item_markup($subscription->get_product_id())); |
|
81 | 81 | } else { |
82 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
83 | - echo wp_kses_post( implode( ' | ', $markup ) ); |
|
82 | + $markup = array_map(array('WPInv_Subscriptions_List_Table', 'generate_item_markup'), array_keys($subscription_group['items'])); |
|
83 | + echo wp_kses_post(implode(' | ', $markup)); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | break; |
87 | 87 | |
88 | 88 | case 'payments': |
89 | 89 | $max_activations = (int) $subscription->get_bill_times(); |
90 | - echo ( (int) $subscription->get_times_billed() ) . ' / ' . ( empty( $max_activations ) ? '∞' : (int) $max_activations ); |
|
90 | + echo ((int) $subscription->get_times_billed()) . ' / ' . (empty($max_activations) ? '∞' : (int) $max_activations); |
|
91 | 91 | |
92 | 92 | break; |
93 | 93 | |
94 | 94 | } |
95 | - do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
95 | + do_action("getpaid_render_single_subscription_column_$key", $subscription); |
|
96 | 96 | |
97 | 97 | ?> |
98 | 98 | </td> |
@@ -104,34 +104,34 @@ discard block |
||
104 | 104 | </tbody> |
105 | 105 | </table> |
106 | 106 | |
107 | -<?php if ( ! empty( $subscription_group ) ) : ?> |
|
108 | - <h2 class='mt-5 mb-1 h4'><?php esc_html_e( 'Subscription Items', 'invoicing' ); ?></h2> |
|
109 | - <?php getpaid_admin_subscription_item_details_metabox( $subscription ); ?> |
|
107 | +<?php if (!empty($subscription_group)) : ?> |
|
108 | + <h2 class='mt-5 mb-1 h4'><?php esc_html_e('Subscription Items', 'invoicing'); ?></h2> |
|
109 | + <?php getpaid_admin_subscription_item_details_metabox($subscription); ?> |
|
110 | 110 | <?php endif; ?> |
111 | 111 | |
112 | -<h2 class='mt-5 mb-1 h4'><?php esc_html_e( 'Related Invoices', 'invoicing' ); ?></h2> |
|
112 | +<h2 class='mt-5 mb-1 h4'><?php esc_html_e('Related Invoices', 'invoicing'); ?></h2> |
|
113 | 113 | |
114 | -<?php ob_start();getpaid_admin_subscription_invoice_details_metabox( $subscription ); $invoice_details = ob_get_clean(); echo wp_kses_post( $invoice_details ); ?> |
|
114 | +<?php ob_start(); getpaid_admin_subscription_invoice_details_metabox($subscription); $invoice_details = ob_get_clean(); echo wp_kses_post($invoice_details); ?> |
|
115 | 115 | |
116 | -<?php if ( 1 < count( $subscription_groups ) ) : ?> |
|
117 | - <h2 class='mt-5 mb-1 h4'><?php esc_html_e( 'Related Subscriptions', 'invoicing' ); ?></h2> |
|
118 | - <?php getpaid_admin_subscription_related_subscriptions_metabox( $subscription ); ?> |
|
116 | +<?php if (1 < count($subscription_groups)) : ?> |
|
117 | + <h2 class='mt-5 mb-1 h4'><?php esc_html_e('Related Subscriptions', 'invoicing'); ?></h2> |
|
118 | + <?php getpaid_admin_subscription_related_subscriptions_metabox($subscription); ?> |
|
119 | 119 | <?php endif; ?> |
120 | 120 | |
121 | 121 | <span class="form-text"> |
122 | 122 | |
123 | 123 | <?php |
124 | - if ( $subscription->can_cancel() ) { |
|
124 | + if ($subscription->can_cancel()) { |
|
125 | 125 | printf( |
126 | 126 | '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a> ', |
127 | - esc_url( $subscription->get_cancel_url() ), |
|
128 | - esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ), |
|
129 | - esc_html__( 'Cancel Subscription', 'invoicing' ) |
|
127 | + esc_url($subscription->get_cancel_url()), |
|
128 | + esc_attr__('Are you sure you want to cancel this subscription?', 'invoicing'), |
|
129 | + esc_html__('Cancel Subscription', 'invoicing') |
|
130 | 130 | ); |
131 | 131 | } |
132 | 132 | |
133 | - do_action( 'getpaid-single-subscription-page-actions', $subscription ); |
|
133 | + do_action('getpaid-single-subscription-page-actions', $subscription); |
|
134 | 134 | ?> |
135 | 135 | |
136 | - <a href="<?php echo esc_url( getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); ?>" class="btn btn-secondary btn-sm"><?php esc_html_e( 'Go Back', 'invoicing' ); ?></a> |
|
136 | + <a href="<?php echo esc_url(getpaid_get_tab_url('gp-subscriptions', get_permalink((int) wpinv_get_option('invoice_subscription_page')))); ?>" class="btn btn-secondary btn-sm"><?php esc_html_e('Go Back', 'invoicing'); ?></a> |
|
137 | 137 | </span> |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -16,85 +16,85 @@ discard block |
||
16 | 16 | */ |
17 | 17 | class GetPaid_Meta_Box_Invoice_Address { |
18 | 18 | |
19 | - /** |
|
20 | - * Output the metabox. |
|
21 | - * |
|
22 | - * @param WP_Post $post |
|
23 | - */ |
|
24 | - public static function output( $post ) { |
|
25 | - |
|
26 | - // Prepare the invoice. |
|
27 | - $invoice = new WPInv_Invoice( $post ); |
|
28 | - $customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id(); |
|
29 | - $customer = new WP_User( $customer ); |
|
30 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ); |
|
31 | - wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
32 | - |
|
33 | - // Address fields. |
|
34 | - $address_fields = array( |
|
35 | - 'first_name' => array( |
|
36 | - 'label' => __( 'First Name', 'invoicing' ), |
|
37 | - 'type' => 'text', |
|
38 | - ), |
|
39 | - 'last_name' => array( |
|
40 | - 'label' => __( 'Last Name', 'invoicing' ), |
|
41 | - 'type' => 'text', |
|
42 | - ), |
|
43 | - 'company' => array( |
|
44 | - 'label' => __( 'Company', 'invoicing' ), |
|
45 | - 'type' => 'text', |
|
46 | - 'class' => 'getpaid-recalculate-prices-on-change', |
|
47 | - ), |
|
48 | - 'vat_number' => array( |
|
49 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
50 | - 'type' => 'text', |
|
51 | - 'class' => 'getpaid-recalculate-prices-on-change', |
|
52 | - ), |
|
53 | - 'address' => array( |
|
54 | - 'label' => __( 'Address', 'invoicing' ), |
|
55 | - 'type' => 'text', |
|
56 | - ), |
|
57 | - 'city' => array( |
|
58 | - 'label' => __( 'City', 'invoicing' ), |
|
59 | - 'type' => 'text', |
|
60 | - ), |
|
61 | - 'country' => array( |
|
62 | - 'label' => __( 'Country', 'invoicing' ), |
|
63 | - 'type' => 'select', |
|
64 | - 'class' => 'getpaid-recalculate-prices-on-change', |
|
65 | - 'options' => wpinv_get_country_list(), |
|
66 | - 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
67 | - ), |
|
68 | - 'state' => array( |
|
69 | - 'label' => __( 'State', 'invoicing' ), |
|
70 | - 'type' => 'text', |
|
71 | - 'class' => 'getpaid-recalculate-prices-on-change', |
|
72 | - ), |
|
73 | - 'zip' => array( |
|
74 | - 'label' => __( 'Zip', 'invoicing' ), |
|
75 | - 'type' => 'text', |
|
76 | - ), |
|
77 | - 'phone' => array( |
|
78 | - 'label' => __( 'Phone', 'invoicing' ), |
|
79 | - 'type' => 'text', |
|
80 | - ), |
|
81 | - ); |
|
82 | - |
|
83 | - $states = wpinv_get_country_states( $invoice->get_country( 'edit' ) ); |
|
84 | - |
|
85 | - if ( ! empty( $states ) ) { |
|
86 | - $address_fields['state']['type'] = 'select'; |
|
87 | - $address_fields['state']['options'] = $states; |
|
88 | - $address_fields['state']['placeholder'] = __( 'Choose a state', 'invoicing' ); |
|
89 | - } |
|
90 | - |
|
91 | - // Maybe remove the VAT field. |
|
92 | - if ( ! wpinv_use_taxes() ) { |
|
93 | - unset( $address_fields['vat_number'] ); |
|
94 | - } |
|
95 | - |
|
96 | - $address_fields = apply_filters( 'getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice ); |
|
97 | - ?> |
|
19 | + /** |
|
20 | + * Output the metabox. |
|
21 | + * |
|
22 | + * @param WP_Post $post |
|
23 | + */ |
|
24 | + public static function output( $post ) { |
|
25 | + |
|
26 | + // Prepare the invoice. |
|
27 | + $invoice = new WPInv_Invoice( $post ); |
|
28 | + $customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id(); |
|
29 | + $customer = new WP_User( $customer ); |
|
30 | + $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ); |
|
31 | + wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
32 | + |
|
33 | + // Address fields. |
|
34 | + $address_fields = array( |
|
35 | + 'first_name' => array( |
|
36 | + 'label' => __( 'First Name', 'invoicing' ), |
|
37 | + 'type' => 'text', |
|
38 | + ), |
|
39 | + 'last_name' => array( |
|
40 | + 'label' => __( 'Last Name', 'invoicing' ), |
|
41 | + 'type' => 'text', |
|
42 | + ), |
|
43 | + 'company' => array( |
|
44 | + 'label' => __( 'Company', 'invoicing' ), |
|
45 | + 'type' => 'text', |
|
46 | + 'class' => 'getpaid-recalculate-prices-on-change', |
|
47 | + ), |
|
48 | + 'vat_number' => array( |
|
49 | + 'label' => __( 'VAT Number', 'invoicing' ), |
|
50 | + 'type' => 'text', |
|
51 | + 'class' => 'getpaid-recalculate-prices-on-change', |
|
52 | + ), |
|
53 | + 'address' => array( |
|
54 | + 'label' => __( 'Address', 'invoicing' ), |
|
55 | + 'type' => 'text', |
|
56 | + ), |
|
57 | + 'city' => array( |
|
58 | + 'label' => __( 'City', 'invoicing' ), |
|
59 | + 'type' => 'text', |
|
60 | + ), |
|
61 | + 'country' => array( |
|
62 | + 'label' => __( 'Country', 'invoicing' ), |
|
63 | + 'type' => 'select', |
|
64 | + 'class' => 'getpaid-recalculate-prices-on-change', |
|
65 | + 'options' => wpinv_get_country_list(), |
|
66 | + 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
67 | + ), |
|
68 | + 'state' => array( |
|
69 | + 'label' => __( 'State', 'invoicing' ), |
|
70 | + 'type' => 'text', |
|
71 | + 'class' => 'getpaid-recalculate-prices-on-change', |
|
72 | + ), |
|
73 | + 'zip' => array( |
|
74 | + 'label' => __( 'Zip', 'invoicing' ), |
|
75 | + 'type' => 'text', |
|
76 | + ), |
|
77 | + 'phone' => array( |
|
78 | + 'label' => __( 'Phone', 'invoicing' ), |
|
79 | + 'type' => 'text', |
|
80 | + ), |
|
81 | + ); |
|
82 | + |
|
83 | + $states = wpinv_get_country_states( $invoice->get_country( 'edit' ) ); |
|
84 | + |
|
85 | + if ( ! empty( $states ) ) { |
|
86 | + $address_fields['state']['type'] = 'select'; |
|
87 | + $address_fields['state']['options'] = $states; |
|
88 | + $address_fields['state']['placeholder'] = __( 'Choose a state', 'invoicing' ); |
|
89 | + } |
|
90 | + |
|
91 | + // Maybe remove the VAT field. |
|
92 | + if ( ! wpinv_use_taxes() ) { |
|
93 | + unset( $address_fields['vat_number'] ); |
|
94 | + } |
|
95 | + |
|
96 | + $address_fields = apply_filters( 'getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice ); |
|
97 | + ?> |
|
98 | 98 | |
99 | 99 | <style> |
100 | 100 | #wpinv-address label { |
@@ -119,19 +119,19 @@ discard block |
||
119 | 119 | <div id="getpaid-invoice-email-wrapper" class="d-none"> |
120 | 120 | <input type="hidden" id="getpaid-invoice-create-new-user" name="wpinv_new_user" value="" /> |
121 | 121 | <?php |
122 | - aui()->input( |
|
123 | - array( |
|
124 | - 'type' => 'text', |
|
125 | - 'id' => 'getpaid-invoice-new-user-email', |
|
126 | - 'name' => 'wpinv_email', |
|
127 | - 'label' => __( 'Email', 'invoicing' ) . '<span class="required">*</span>', |
|
128 | - 'label_type' => 'vertical', |
|
129 | - 'placeholder' => '[email protected]', |
|
130 | - 'class' => 'form-control-sm', |
|
131 | - ), |
|
132 | - true |
|
133 | - ); |
|
134 | - ?> |
|
122 | + aui()->input( |
|
123 | + array( |
|
124 | + 'type' => 'text', |
|
125 | + 'id' => 'getpaid-invoice-new-user-email', |
|
126 | + 'name' => 'wpinv_email', |
|
127 | + 'label' => __( 'Email', 'invoicing' ) . '<span class="required">*</span>', |
|
128 | + 'label_type' => 'vertical', |
|
129 | + 'placeholder' => '[email protected]', |
|
130 | + 'class' => 'form-control-sm', |
|
131 | + ), |
|
132 | + true |
|
133 | + ); |
|
134 | + ?> |
|
135 | 135 | </div> |
136 | 136 | </div> |
137 | 137 | <div class="col-12 col-sm-6 form-group mb-3 mt-sm-4"> |
@@ -155,39 +155,39 @@ discard block |
||
155 | 155 | <div class="col-12 col-sm-6 getpaid-invoice-address-field__<?php echo esc_attr( $key ); ?>--wrapper"> |
156 | 156 | <?php |
157 | 157 | |
158 | - if ( 'select' === $field['type'] ) { |
|
159 | - aui()->select( |
|
160 | - array( |
|
161 | - 'id' => 'wpinv_' . $key, |
|
162 | - 'name' => 'wpinv_' . $key, |
|
163 | - 'label' => $field['label'], |
|
164 | - 'label_type' => 'vertical', |
|
165 | - 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
166 | - 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
167 | - 'value' => $invoice->get( $key, 'edit' ), |
|
168 | - 'options' => $field['options'], |
|
169 | - 'data-allow-clear' => 'false', |
|
170 | - 'select2' => true, |
|
171 | - ), |
|
172 | - true |
|
173 | - ); |
|
174 | - } else { |
|
175 | - aui()->input( |
|
176 | - array( |
|
177 | - 'type' => $field['type'], |
|
178 | - 'id' => 'wpinv_' . $key, |
|
179 | - 'name' => 'wpinv_' . $key, |
|
180 | - 'label' => $field['label'], |
|
181 | - 'label_type' => 'vertical', |
|
182 | - 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
183 | - 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
184 | - 'value' => $invoice->get( $key, 'edit' ), |
|
185 | - ), |
|
186 | - true |
|
187 | - ); |
|
188 | - } |
|
189 | - |
|
190 | - ?> |
|
158 | + if ( 'select' === $field['type'] ) { |
|
159 | + aui()->select( |
|
160 | + array( |
|
161 | + 'id' => 'wpinv_' . $key, |
|
162 | + 'name' => 'wpinv_' . $key, |
|
163 | + 'label' => $field['label'], |
|
164 | + 'label_type' => 'vertical', |
|
165 | + 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
166 | + 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
167 | + 'value' => $invoice->get( $key, 'edit' ), |
|
168 | + 'options' => $field['options'], |
|
169 | + 'data-allow-clear' => 'false', |
|
170 | + 'select2' => true, |
|
171 | + ), |
|
172 | + true |
|
173 | + ); |
|
174 | + } else { |
|
175 | + aui()->input( |
|
176 | + array( |
|
177 | + 'type' => $field['type'], |
|
178 | + 'id' => 'wpinv_' . $key, |
|
179 | + 'name' => 'wpinv_' . $key, |
|
180 | + 'label' => $field['label'], |
|
181 | + 'label_type' => 'vertical', |
|
182 | + 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
183 | + 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
184 | + 'value' => $invoice->get( $key, 'edit' ), |
|
185 | + ), |
|
186 | + true |
|
187 | + ); |
|
188 | + } |
|
189 | + |
|
190 | + ?> |
|
191 | 191 | </div> |
192 | 192 | <?php endforeach; ?> |
193 | 193 | </div> |
@@ -198,48 +198,48 @@ discard block |
||
198 | 198 | <div class="row"> |
199 | 199 | <div class="col-12 col-sm-6"> |
200 | 200 | <?php |
201 | - aui()->select( |
|
202 | - array( |
|
203 | - 'id' => 'wpinv_template', |
|
204 | - 'name' => 'wpinv_template', |
|
205 | - 'label' => __( 'Template', 'invoicing' ), |
|
206 | - 'label_type' => 'vertical', |
|
207 | - 'placeholder' => __( 'Choose a template', 'invoicing' ), |
|
208 | - 'class' => 'form-control-sm', |
|
209 | - 'value' => $invoice->get_template( 'edit' ), |
|
210 | - 'options' => array( |
|
211 | - 'quantity' => __( 'Quantity', 'invoicing' ), |
|
212 | - 'hours' => __( 'Hours', 'invoicing' ), |
|
213 | - ), |
|
214 | - 'data-allow-clear' => 'false', |
|
215 | - 'select2' => true, |
|
216 | - ), |
|
217 | - true |
|
218 | - ); |
|
219 | - ?> |
|
201 | + aui()->select( |
|
202 | + array( |
|
203 | + 'id' => 'wpinv_template', |
|
204 | + 'name' => 'wpinv_template', |
|
205 | + 'label' => __( 'Template', 'invoicing' ), |
|
206 | + 'label_type' => 'vertical', |
|
207 | + 'placeholder' => __( 'Choose a template', 'invoicing' ), |
|
208 | + 'class' => 'form-control-sm', |
|
209 | + 'value' => $invoice->get_template( 'edit' ), |
|
210 | + 'options' => array( |
|
211 | + 'quantity' => __( 'Quantity', 'invoicing' ), |
|
212 | + 'hours' => __( 'Hours', 'invoicing' ), |
|
213 | + ), |
|
214 | + 'data-allow-clear' => 'false', |
|
215 | + 'select2' => true, |
|
216 | + ), |
|
217 | + true |
|
218 | + ); |
|
219 | + ?> |
|
220 | 220 | </div> |
221 | 221 | <div class="col-12 col-sm-6"> |
222 | 222 | <?php |
223 | 223 | |
224 | - // Set currency. |
|
225 | - aui()->select( |
|
226 | - array( |
|
227 | - 'id' => 'wpinv_currency', |
|
228 | - 'name' => 'wpinv_currency', |
|
229 | - 'label' => __( 'Currency', 'invoicing' ), |
|
230 | - 'label_type' => 'vertical', |
|
231 | - 'placeholder' => __( 'Select Invoice Currency', 'invoicing' ), |
|
232 | - 'class' => 'form-control-sm getpaid-recalculate-prices-on-change', |
|
233 | - 'value' => $invoice->get_currency( 'edit' ), |
|
234 | - 'required' => false, |
|
235 | - 'data-allow-clear' => 'false', |
|
236 | - 'select2' => true, |
|
237 | - 'options' => wpinv_get_currencies(), |
|
238 | - ), |
|
239 | - true |
|
240 | - ); |
|
241 | - |
|
242 | - ?> |
|
224 | + // Set currency. |
|
225 | + aui()->select( |
|
226 | + array( |
|
227 | + 'id' => 'wpinv_currency', |
|
228 | + 'name' => 'wpinv_currency', |
|
229 | + 'label' => __( 'Currency', 'invoicing' ), |
|
230 | + 'label_type' => 'vertical', |
|
231 | + 'placeholder' => __( 'Select Invoice Currency', 'invoicing' ), |
|
232 | + 'class' => 'form-control-sm getpaid-recalculate-prices-on-change', |
|
233 | + 'value' => $invoice->get_currency( 'edit' ), |
|
234 | + 'required' => false, |
|
235 | + 'data-allow-clear' => 'false', |
|
236 | + 'select2' => true, |
|
237 | + 'options' => wpinv_get_currencies(), |
|
238 | + ), |
|
239 | + true |
|
240 | + ); |
|
241 | + |
|
242 | + ?> |
|
243 | 243 | </div> |
244 | 244 | </div> |
245 | 245 | |
@@ -249,123 +249,123 @@ discard block |
||
249 | 249 | <div class="row"> |
250 | 250 | <div class="col-12 col-sm-6"> |
251 | 251 | <?php |
252 | - aui()->input( |
|
253 | - array( |
|
254 | - 'type' => 'text', |
|
255 | - 'id' => 'wpinv_company_id', |
|
256 | - 'name' => 'wpinv_company_id', |
|
257 | - 'label' => __( 'Company ID', 'invoicing' ), |
|
258 | - 'label_type' => 'vertical', |
|
259 | - 'placeholder' => '', |
|
260 | - 'class' => 'form-control-sm', |
|
261 | - 'value' => $invoice->get_company_id( 'edit' ), |
|
262 | - ), |
|
263 | - true |
|
264 | - ); |
|
265 | - ?> |
|
252 | + aui()->input( |
|
253 | + array( |
|
254 | + 'type' => 'text', |
|
255 | + 'id' => 'wpinv_company_id', |
|
256 | + 'name' => 'wpinv_company_id', |
|
257 | + 'label' => __( 'Company ID', 'invoicing' ), |
|
258 | + 'label_type' => 'vertical', |
|
259 | + 'placeholder' => '', |
|
260 | + 'class' => 'form-control-sm', |
|
261 | + 'value' => $invoice->get_company_id( 'edit' ), |
|
262 | + ), |
|
263 | + true |
|
264 | + ); |
|
265 | + ?> |
|
266 | 266 | </div> |
267 | 267 | </div> |
268 | 268 | |
269 | 269 | <?php do_action( 'getpaid_after_metabox_invoice_address', $invoice ); ?> |
270 | 270 | </div> |
271 | 271 | <?php |
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Save meta box data. |
|
276 | - * |
|
277 | - * @param int $post_id |
|
278 | - * @param array $posted the posted data. |
|
279 | - */ |
|
280 | - public static function save( $post_id, $posted ) { |
|
281 | - |
|
282 | - // Prepare the invoice. |
|
283 | - $invoice = new WPInv_Invoice( $post_id ); |
|
284 | - |
|
285 | - // Load new data. |
|
286 | - $invoice->set_props( |
|
287 | - array( |
|
288 | - 'template' => isset( $posted['wpinv_template'] ) ? wpinv_clean( $posted['wpinv_template'] ) : null, |
|
289 | - 'email_cc' => isset( $posted['wpinv_cc'] ) ? wpinv_clean( $posted['wpinv_cc'] ) : null, |
|
290 | - 'disable_taxes' => ! empty( $posted['disable_taxes'] ), |
|
291 | - 'currency' => isset( $posted['wpinv_currency'] ) ? wpinv_clean( $posted['wpinv_currency'] ) : null, |
|
292 | - 'gateway' => ( $invoice->needs_payment() && isset( $posted['wpinv_gateway'] ) ) ? wpinv_clean( $posted['wpinv_gateway'] ) : null, |
|
293 | - 'address' => isset( $posted['wpinv_address'] ) ? wpinv_clean( $posted['wpinv_address'] ) : null, |
|
294 | - 'vat_number' => isset( $posted['wpinv_vat_number'] ) ? wpinv_clean( $posted['wpinv_vat_number'] ) : null, |
|
295 | - 'company' => isset( $posted['wpinv_company'] ) ? wpinv_clean( $posted['wpinv_company'] ) : null, |
|
296 | - 'company_id' => isset( $posted['wpinv_company_id'] ) ? wpinv_clean( $posted['wpinv_company_id'] ) : null, |
|
297 | - 'zip' => isset( $posted['wpinv_zip'] ) ? wpinv_clean( $posted['wpinv_zip'] ) : null, |
|
298 | - 'state' => isset( $posted['wpinv_state'] ) ? wpinv_clean( $posted['wpinv_state'] ) : null, |
|
299 | - 'city' => isset( $posted['wpinv_city'] ) ? wpinv_clean( $posted['wpinv_city'] ) : null, |
|
300 | - 'country' => isset( $posted['wpinv_country'] ) ? wpinv_clean( $posted['wpinv_country'] ) : null, |
|
301 | - 'phone' => isset( $posted['wpinv_phone'] ) ? wpinv_clean( $posted['wpinv_phone'] ) : null, |
|
302 | - 'first_name' => isset( $posted['wpinv_first_name'] ) ? wpinv_clean( $posted['wpinv_first_name'] ) : null, |
|
303 | - 'last_name' => isset( $posted['wpinv_last_name'] ) ? wpinv_clean( $posted['wpinv_last_name'] ) : null, |
|
304 | - 'author' => isset( $posted['post_author_override'] ) ? wpinv_clean( $posted['post_author_override'] ) : null, |
|
305 | - 'date_created' => isset( $posted['date_created'] ) ? wpinv_clean( $posted['date_created'] ) : null, |
|
306 | - 'date_completed' => isset( $posted['wpinv_date_completed'] ) ? wpinv_clean( $posted['wpinv_date_completed'] ) : null, |
|
307 | - 'due_date' => isset( $posted['wpinv_due_date'] ) ? wpinv_clean( $posted['wpinv_due_date'] ) : null, |
|
308 | - 'number' => isset( $posted['wpinv_number'] ) ? wpinv_clean( $posted['wpinv_number'] ) : null, |
|
309 | - 'status' => isset( $posted['wpinv_status'] ) ? wpinv_clean( $posted['wpinv_status'] ) : null, |
|
310 | - ) |
|
311 | - ); |
|
312 | - |
|
313 | - // Discount code. |
|
314 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
315 | - |
|
316 | - if ( isset( $posted['wpinv_discount_code'] ) ) { |
|
317 | - $invoice->set_discount_code( wpinv_clean( $posted['wpinv_discount_code'] ) ); |
|
318 | - } |
|
319 | - |
|
320 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
321 | - if ( $discount->exists() ) { |
|
322 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
323 | - } else { |
|
324 | - $invoice->remove_discount( 'discount_code' ); |
|
325 | - } |
|
326 | - |
|
327 | - // Recalculate totals. |
|
328 | - $invoice->recalculate_total(); |
|
329 | - |
|
330 | - } |
|
331 | - |
|
332 | - // If we're creating a new user... |
|
333 | - if ( ! empty( $posted['wpinv_new_user'] ) && is_email( stripslashes( $posted['wpinv_email'] ) ) ) { |
|
334 | - |
|
335 | - // Attempt to create the user. |
|
336 | - $user = wpinv_create_user( sanitize_email( stripslashes( $posted['wpinv_email'] ) ), $invoice->get_first_name() . $invoice->get_last_name() ); |
|
337 | - |
|
338 | - // If successful, update the invoice author. |
|
339 | - if ( is_numeric( $user ) ) { |
|
340 | - $invoice->set_author( $user ); |
|
341 | - } else { |
|
342 | - wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ ); |
|
343 | - } |
|
344 | - } |
|
345 | - |
|
346 | - // Do not send new invoice notifications. |
|
347 | - $GLOBALS['wpinv_skip_invoice_notification'] = true; |
|
348 | - |
|
349 | - // Save the invoice. |
|
350 | - $invoice->save(); |
|
351 | - |
|
352 | - // Save the user address. |
|
353 | - getpaid_save_invoice_user_address( $invoice ); |
|
354 | - |
|
355 | - // Undo do not send new invoice notifications. |
|
356 | - $GLOBALS['wpinv_skip_invoice_notification'] = false; |
|
357 | - |
|
358 | - // (Maybe) send new user notification. |
|
359 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
360 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) { |
|
361 | - wp_send_new_user_notifications( $user, 'user' ); |
|
362 | - } |
|
363 | - |
|
364 | - if ( ! empty( $posted['send_to_customer'] ) && ! $invoice->is_draft() ) { |
|
365 | - getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true ); |
|
366 | - } |
|
367 | - |
|
368 | - // Fires after an invoice is saved. |
|
369 | - do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
370 | - } |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Save meta box data. |
|
276 | + * |
|
277 | + * @param int $post_id |
|
278 | + * @param array $posted the posted data. |
|
279 | + */ |
|
280 | + public static function save( $post_id, $posted ) { |
|
281 | + |
|
282 | + // Prepare the invoice. |
|
283 | + $invoice = new WPInv_Invoice( $post_id ); |
|
284 | + |
|
285 | + // Load new data. |
|
286 | + $invoice->set_props( |
|
287 | + array( |
|
288 | + 'template' => isset( $posted['wpinv_template'] ) ? wpinv_clean( $posted['wpinv_template'] ) : null, |
|
289 | + 'email_cc' => isset( $posted['wpinv_cc'] ) ? wpinv_clean( $posted['wpinv_cc'] ) : null, |
|
290 | + 'disable_taxes' => ! empty( $posted['disable_taxes'] ), |
|
291 | + 'currency' => isset( $posted['wpinv_currency'] ) ? wpinv_clean( $posted['wpinv_currency'] ) : null, |
|
292 | + 'gateway' => ( $invoice->needs_payment() && isset( $posted['wpinv_gateway'] ) ) ? wpinv_clean( $posted['wpinv_gateway'] ) : null, |
|
293 | + 'address' => isset( $posted['wpinv_address'] ) ? wpinv_clean( $posted['wpinv_address'] ) : null, |
|
294 | + 'vat_number' => isset( $posted['wpinv_vat_number'] ) ? wpinv_clean( $posted['wpinv_vat_number'] ) : null, |
|
295 | + 'company' => isset( $posted['wpinv_company'] ) ? wpinv_clean( $posted['wpinv_company'] ) : null, |
|
296 | + 'company_id' => isset( $posted['wpinv_company_id'] ) ? wpinv_clean( $posted['wpinv_company_id'] ) : null, |
|
297 | + 'zip' => isset( $posted['wpinv_zip'] ) ? wpinv_clean( $posted['wpinv_zip'] ) : null, |
|
298 | + 'state' => isset( $posted['wpinv_state'] ) ? wpinv_clean( $posted['wpinv_state'] ) : null, |
|
299 | + 'city' => isset( $posted['wpinv_city'] ) ? wpinv_clean( $posted['wpinv_city'] ) : null, |
|
300 | + 'country' => isset( $posted['wpinv_country'] ) ? wpinv_clean( $posted['wpinv_country'] ) : null, |
|
301 | + 'phone' => isset( $posted['wpinv_phone'] ) ? wpinv_clean( $posted['wpinv_phone'] ) : null, |
|
302 | + 'first_name' => isset( $posted['wpinv_first_name'] ) ? wpinv_clean( $posted['wpinv_first_name'] ) : null, |
|
303 | + 'last_name' => isset( $posted['wpinv_last_name'] ) ? wpinv_clean( $posted['wpinv_last_name'] ) : null, |
|
304 | + 'author' => isset( $posted['post_author_override'] ) ? wpinv_clean( $posted['post_author_override'] ) : null, |
|
305 | + 'date_created' => isset( $posted['date_created'] ) ? wpinv_clean( $posted['date_created'] ) : null, |
|
306 | + 'date_completed' => isset( $posted['wpinv_date_completed'] ) ? wpinv_clean( $posted['wpinv_date_completed'] ) : null, |
|
307 | + 'due_date' => isset( $posted['wpinv_due_date'] ) ? wpinv_clean( $posted['wpinv_due_date'] ) : null, |
|
308 | + 'number' => isset( $posted['wpinv_number'] ) ? wpinv_clean( $posted['wpinv_number'] ) : null, |
|
309 | + 'status' => isset( $posted['wpinv_status'] ) ? wpinv_clean( $posted['wpinv_status'] ) : null, |
|
310 | + ) |
|
311 | + ); |
|
312 | + |
|
313 | + // Discount code. |
|
314 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
315 | + |
|
316 | + if ( isset( $posted['wpinv_discount_code'] ) ) { |
|
317 | + $invoice->set_discount_code( wpinv_clean( $posted['wpinv_discount_code'] ) ); |
|
318 | + } |
|
319 | + |
|
320 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
321 | + if ( $discount->exists() ) { |
|
322 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
323 | + } else { |
|
324 | + $invoice->remove_discount( 'discount_code' ); |
|
325 | + } |
|
326 | + |
|
327 | + // Recalculate totals. |
|
328 | + $invoice->recalculate_total(); |
|
329 | + |
|
330 | + } |
|
331 | + |
|
332 | + // If we're creating a new user... |
|
333 | + if ( ! empty( $posted['wpinv_new_user'] ) && is_email( stripslashes( $posted['wpinv_email'] ) ) ) { |
|
334 | + |
|
335 | + // Attempt to create the user. |
|
336 | + $user = wpinv_create_user( sanitize_email( stripslashes( $posted['wpinv_email'] ) ), $invoice->get_first_name() . $invoice->get_last_name() ); |
|
337 | + |
|
338 | + // If successful, update the invoice author. |
|
339 | + if ( is_numeric( $user ) ) { |
|
340 | + $invoice->set_author( $user ); |
|
341 | + } else { |
|
342 | + wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ ); |
|
343 | + } |
|
344 | + } |
|
345 | + |
|
346 | + // Do not send new invoice notifications. |
|
347 | + $GLOBALS['wpinv_skip_invoice_notification'] = true; |
|
348 | + |
|
349 | + // Save the invoice. |
|
350 | + $invoice->save(); |
|
351 | + |
|
352 | + // Save the user address. |
|
353 | + getpaid_save_invoice_user_address( $invoice ); |
|
354 | + |
|
355 | + // Undo do not send new invoice notifications. |
|
356 | + $GLOBALS['wpinv_skip_invoice_notification'] = false; |
|
357 | + |
|
358 | + // (Maybe) send new user notification. |
|
359 | + $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
360 | + if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) { |
|
361 | + wp_send_new_user_notifications( $user, 'user' ); |
|
362 | + } |
|
363 | + |
|
364 | + if ( ! empty( $posted['send_to_customer'] ) && ! $invoice->is_draft() ) { |
|
365 | + getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true ); |
|
366 | + } |
|
367 | + |
|
368 | + // Fires after an invoice is saved. |
|
369 | + do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
370 | + } |
|
371 | 371 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if (!defined('ABSPATH')) { |
|
11 | 11 | exit; // Exit if accessed directly |
12 | 12 | } |
13 | 13 | |
@@ -21,79 +21,79 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param WP_Post $post |
23 | 23 | */ |
24 | - public static function output( $post ) { |
|
24 | + public static function output($post) { |
|
25 | 25 | |
26 | 26 | // Prepare the invoice. |
27 | - $invoice = new WPInv_Invoice( $post ); |
|
28 | - $customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id(); |
|
29 | - $customer = new WP_User( $customer ); |
|
30 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ); |
|
31 | - wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
27 | + $invoice = new WPInv_Invoice($post); |
|
28 | + $customer = $invoice->exists() ? $invoice->get_user_id('edit') : get_current_user_id(); |
|
29 | + $customer = new WP_User($customer); |
|
30 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email); |
|
31 | + wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce'); |
|
32 | 32 | |
33 | 33 | // Address fields. |
34 | 34 | $address_fields = array( |
35 | 35 | 'first_name' => array( |
36 | - 'label' => __( 'First Name', 'invoicing' ), |
|
36 | + 'label' => __('First Name', 'invoicing'), |
|
37 | 37 | 'type' => 'text', |
38 | 38 | ), |
39 | 39 | 'last_name' => array( |
40 | - 'label' => __( 'Last Name', 'invoicing' ), |
|
40 | + 'label' => __('Last Name', 'invoicing'), |
|
41 | 41 | 'type' => 'text', |
42 | 42 | ), |
43 | 43 | 'company' => array( |
44 | - 'label' => __( 'Company', 'invoicing' ), |
|
44 | + 'label' => __('Company', 'invoicing'), |
|
45 | 45 | 'type' => 'text', |
46 | 46 | 'class' => 'getpaid-recalculate-prices-on-change', |
47 | 47 | ), |
48 | 48 | 'vat_number' => array( |
49 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
49 | + 'label' => __('VAT Number', 'invoicing'), |
|
50 | 50 | 'type' => 'text', |
51 | 51 | 'class' => 'getpaid-recalculate-prices-on-change', |
52 | 52 | ), |
53 | 53 | 'address' => array( |
54 | - 'label' => __( 'Address', 'invoicing' ), |
|
54 | + 'label' => __('Address', 'invoicing'), |
|
55 | 55 | 'type' => 'text', |
56 | 56 | ), |
57 | 57 | 'city' => array( |
58 | - 'label' => __( 'City', 'invoicing' ), |
|
58 | + 'label' => __('City', 'invoicing'), |
|
59 | 59 | 'type' => 'text', |
60 | 60 | ), |
61 | 61 | 'country' => array( |
62 | - 'label' => __( 'Country', 'invoicing' ), |
|
62 | + 'label' => __('Country', 'invoicing'), |
|
63 | 63 | 'type' => 'select', |
64 | 64 | 'class' => 'getpaid-recalculate-prices-on-change', |
65 | 65 | 'options' => wpinv_get_country_list(), |
66 | - 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
66 | + 'placeholder' => __('Choose a country', 'invoicing'), |
|
67 | 67 | ), |
68 | 68 | 'state' => array( |
69 | - 'label' => __( 'State', 'invoicing' ), |
|
69 | + 'label' => __('State', 'invoicing'), |
|
70 | 70 | 'type' => 'text', |
71 | 71 | 'class' => 'getpaid-recalculate-prices-on-change', |
72 | 72 | ), |
73 | 73 | 'zip' => array( |
74 | - 'label' => __( 'Zip', 'invoicing' ), |
|
74 | + 'label' => __('Zip', 'invoicing'), |
|
75 | 75 | 'type' => 'text', |
76 | 76 | ), |
77 | 77 | 'phone' => array( |
78 | - 'label' => __( 'Phone', 'invoicing' ), |
|
78 | + 'label' => __('Phone', 'invoicing'), |
|
79 | 79 | 'type' => 'text', |
80 | 80 | ), |
81 | 81 | ); |
82 | 82 | |
83 | - $states = wpinv_get_country_states( $invoice->get_country( 'edit' ) ); |
|
83 | + $states = wpinv_get_country_states($invoice->get_country('edit')); |
|
84 | 84 | |
85 | - if ( ! empty( $states ) ) { |
|
85 | + if (!empty($states)) { |
|
86 | 86 | $address_fields['state']['type'] = 'select'; |
87 | 87 | $address_fields['state']['options'] = $states; |
88 | - $address_fields['state']['placeholder'] = __( 'Choose a state', 'invoicing' ); |
|
88 | + $address_fields['state']['placeholder'] = __('Choose a state', 'invoicing'); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | // Maybe remove the VAT field. |
92 | - if ( ! wpinv_use_taxes() ) { |
|
93 | - unset( $address_fields['vat_number'] ); |
|
92 | + if (!wpinv_use_taxes()) { |
|
93 | + unset($address_fields['vat_number']); |
|
94 | 94 | } |
95 | 95 | |
96 | - $address_fields = apply_filters( 'getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice ); |
|
96 | + $address_fields = apply_filters('getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice); |
|
97 | 97 | ?> |
98 | 98 | |
99 | 99 | <style> |
@@ -107,11 +107,11 @@ discard block |
||
107 | 107 | <div class="col-12 col-sm-6"> |
108 | 108 | <div id="getpaid-invoice-user-id-wrapper" class="form-group mb-3"> |
109 | 109 | <div> |
110 | - <label for="post_author_override"><?php esc_html_e( 'Customer', 'invoicing' ); ?></label> |
|
110 | + <label for="post_author_override"><?php esc_html_e('Customer', 'invoicing'); ?></label> |
|
111 | 111 | </div> |
112 | 112 | <div> |
113 | - <select name="post_author_override" id="wpinv_post_author_override" class="getpaid-customer-search form-control regular-text" data-placeholder="<?php esc_attr_e( 'Search for a customer by email or name', 'invoicing' ); ?>"> |
|
114 | - <option selected="selected" value="<?php echo (int) $customer->ID; ?>"><?php echo esc_html( $display ); ?> </option>) |
|
113 | + <select name="post_author_override" id="wpinv_post_author_override" class="getpaid-customer-search form-control regular-text" data-placeholder="<?php esc_attr_e('Search for a customer by email or name', 'invoicing'); ?>"> |
|
114 | + <option selected="selected" value="<?php echo (int) $customer->ID; ?>"><?php echo esc_html($display); ?> </option>) |
|
115 | 115 | </select> |
116 | 116 | </div> |
117 | 117 | </div> |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | 'type' => 'text', |
125 | 125 | 'id' => 'getpaid-invoice-new-user-email', |
126 | 126 | 'name' => 'wpinv_email', |
127 | - 'label' => __( 'Email', 'invoicing' ) . '<span class="required">*</span>', |
|
127 | + 'label' => __('Email', 'invoicing') . '<span class="required">*</span>', |
|
128 | 128 | 'label_type' => 'vertical', |
129 | 129 | 'placeholder' => '[email protected]', |
130 | 130 | 'class' => 'form-control-sm', |
@@ -135,36 +135,36 @@ discard block |
||
135 | 135 | </div> |
136 | 136 | </div> |
137 | 137 | <div class="col-12 col-sm-6 form-group mb-3 mt-sm-4"> |
138 | - <?php if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) : ?> |
|
138 | + <?php if (!$invoice->is_paid() && !$invoice->is_refunded()) : ?> |
|
139 | 139 | <a id="getpaid-invoice-fill-user-details" class="button button-small button-secondary" href="javascript:void(0)"> |
140 | 140 | <i aria-hidden="true" class="fa fa-refresh"></i> |
141 | - <?php esc_html_e( 'Fill User Details', 'invoicing' ); ?> |
|
141 | + <?php esc_html_e('Fill User Details', 'invoicing'); ?> |
|
142 | 142 | </a> |
143 | 143 | <a id="getpaid-invoice-create-new-user-button" class="button button-small button-secondary" href="javascript:void(0)"> |
144 | 144 | <i aria-hidden="true" class="fa fa-plus"></i> |
145 | - <?php esc_html_e( 'Add New User', 'invoicing' ); ?> |
|
145 | + <?php esc_html_e('Add New User', 'invoicing'); ?> |
|
146 | 146 | </a> |
147 | 147 | <a id="getpaid-invoice-cancel-create-new-user" class="button button-small button-secondary d-none" href="javascript:void(0)"> |
148 | 148 | <i aria-hidden="true" class="fa fa-close"></i> |
149 | - <?php esc_html_e( 'Cancel', 'invoicing' ); ?> |
|
149 | + <?php esc_html_e('Cancel', 'invoicing'); ?> |
|
150 | 150 | </a> |
151 | 151 | <?php endif; ?> |
152 | 152 | </div> |
153 | 153 | |
154 | - <?php foreach ( $address_fields as $key => $field ) : ?> |
|
155 | - <div class="col-12 col-sm-6 getpaid-invoice-address-field__<?php echo esc_attr( $key ); ?>--wrapper"> |
|
154 | + <?php foreach ($address_fields as $key => $field) : ?> |
|
155 | + <div class="col-12 col-sm-6 getpaid-invoice-address-field__<?php echo esc_attr($key); ?>--wrapper"> |
|
156 | 156 | <?php |
157 | 157 | |
158 | - if ( 'select' === $field['type'] ) { |
|
158 | + if ('select' === $field['type']) { |
|
159 | 159 | aui()->select( |
160 | 160 | array( |
161 | 161 | 'id' => 'wpinv_' . $key, |
162 | 162 | 'name' => 'wpinv_' . $key, |
163 | 163 | 'label' => $field['label'], |
164 | 164 | 'label_type' => 'vertical', |
165 | - 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
166 | - 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
167 | - 'value' => $invoice->get( $key, 'edit' ), |
|
165 | + 'placeholder' => isset($field['placeholder']) ? $field['placeholder'] : '', |
|
166 | + 'class' => 'form-control-sm ' . (isset($field['class']) ? $field['class'] : ''), |
|
167 | + 'value' => $invoice->get($key, 'edit'), |
|
168 | 168 | 'options' => $field['options'], |
169 | 169 | 'data-allow-clear' => 'false', |
170 | 170 | 'select2' => true, |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | 'name' => 'wpinv_' . $key, |
180 | 180 | 'label' => $field['label'], |
181 | 181 | 'label_type' => 'vertical', |
182 | - 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
183 | - 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
184 | - 'value' => $invoice->get( $key, 'edit' ), |
|
182 | + 'placeholder' => isset($field['placeholder']) ? $field['placeholder'] : '', |
|
183 | + 'class' => 'form-control-sm ' . (isset($field['class']) ? $field['class'] : ''), |
|
184 | + 'value' => $invoice->get($key, 'edit'), |
|
185 | 185 | ), |
186 | 186 | true |
187 | 187 | ); |
@@ -192,8 +192,8 @@ discard block |
||
192 | 192 | <?php endforeach; ?> |
193 | 193 | </div> |
194 | 194 | |
195 | - <?php if ( ! apply_filters( 'getpaid_use_new_invoice_items_metabox', false ) ) : ?> |
|
196 | - <?php do_action( 'wpinv_meta_box_before_invoice_template_row', $invoice->get_id() ); ?> |
|
195 | + <?php if (!apply_filters('getpaid_use_new_invoice_items_metabox', false)) : ?> |
|
196 | + <?php do_action('wpinv_meta_box_before_invoice_template_row', $invoice->get_id()); ?> |
|
197 | 197 | |
198 | 198 | <div class="row"> |
199 | 199 | <div class="col-12 col-sm-6"> |
@@ -202,14 +202,14 @@ discard block |
||
202 | 202 | array( |
203 | 203 | 'id' => 'wpinv_template', |
204 | 204 | 'name' => 'wpinv_template', |
205 | - 'label' => __( 'Template', 'invoicing' ), |
|
205 | + 'label' => __('Template', 'invoicing'), |
|
206 | 206 | 'label_type' => 'vertical', |
207 | - 'placeholder' => __( 'Choose a template', 'invoicing' ), |
|
207 | + 'placeholder' => __('Choose a template', 'invoicing'), |
|
208 | 208 | 'class' => 'form-control-sm', |
209 | - 'value' => $invoice->get_template( 'edit' ), |
|
209 | + 'value' => $invoice->get_template('edit'), |
|
210 | 210 | 'options' => array( |
211 | - 'quantity' => __( 'Quantity', 'invoicing' ), |
|
212 | - 'hours' => __( 'Hours', 'invoicing' ), |
|
211 | + 'quantity' => __('Quantity', 'invoicing'), |
|
212 | + 'hours' => __('Hours', 'invoicing'), |
|
213 | 213 | ), |
214 | 214 | 'data-allow-clear' => 'false', |
215 | 215 | 'select2' => true, |
@@ -226,11 +226,11 @@ discard block |
||
226 | 226 | array( |
227 | 227 | 'id' => 'wpinv_currency', |
228 | 228 | 'name' => 'wpinv_currency', |
229 | - 'label' => __( 'Currency', 'invoicing' ), |
|
229 | + 'label' => __('Currency', 'invoicing'), |
|
230 | 230 | 'label_type' => 'vertical', |
231 | - 'placeholder' => __( 'Select Invoice Currency', 'invoicing' ), |
|
231 | + 'placeholder' => __('Select Invoice Currency', 'invoicing'), |
|
232 | 232 | 'class' => 'form-control-sm getpaid-recalculate-prices-on-change', |
233 | - 'value' => $invoice->get_currency( 'edit' ), |
|
233 | + 'value' => $invoice->get_currency('edit'), |
|
234 | 234 | 'required' => false, |
235 | 235 | 'data-allow-clear' => 'false', |
236 | 236 | 'select2' => true, |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | </div> |
244 | 244 | </div> |
245 | 245 | |
246 | - <?php do_action( 'wpinv_meta_box_invoice_template_row', $invoice->get_id() ); ?> |
|
246 | + <?php do_action('wpinv_meta_box_invoice_template_row', $invoice->get_id()); ?> |
|
247 | 247 | <?php endif; ?> |
248 | 248 | |
249 | 249 | <div class="row"> |
@@ -254,11 +254,11 @@ discard block |
||
254 | 254 | 'type' => 'text', |
255 | 255 | 'id' => 'wpinv_company_id', |
256 | 256 | 'name' => 'wpinv_company_id', |
257 | - 'label' => __( 'Company ID', 'invoicing' ), |
|
257 | + 'label' => __('Company ID', 'invoicing'), |
|
258 | 258 | 'label_type' => 'vertical', |
259 | 259 | 'placeholder' => '', |
260 | 260 | 'class' => 'form-control-sm', |
261 | - 'value' => $invoice->get_company_id( 'edit' ), |
|
261 | + 'value' => $invoice->get_company_id('edit'), |
|
262 | 262 | ), |
263 | 263 | true |
264 | 264 | ); |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | </div> |
267 | 267 | </div> |
268 | 268 | |
269 | - <?php do_action( 'getpaid_after_metabox_invoice_address', $invoice ); ?> |
|
269 | + <?php do_action('getpaid_after_metabox_invoice_address', $invoice); ?> |
|
270 | 270 | </div> |
271 | 271 | <?php |
272 | 272 | } |
@@ -277,51 +277,51 @@ discard block |
||
277 | 277 | * @param int $post_id |
278 | 278 | * @param array $posted the posted data. |
279 | 279 | */ |
280 | - public static function save( $post_id, $posted ) { |
|
280 | + public static function save($post_id, $posted) { |
|
281 | 281 | |
282 | 282 | // Prepare the invoice. |
283 | - $invoice = new WPInv_Invoice( $post_id ); |
|
283 | + $invoice = new WPInv_Invoice($post_id); |
|
284 | 284 | |
285 | 285 | // Load new data. |
286 | 286 | $invoice->set_props( |
287 | 287 | array( |
288 | - 'template' => isset( $posted['wpinv_template'] ) ? wpinv_clean( $posted['wpinv_template'] ) : null, |
|
289 | - 'email_cc' => isset( $posted['wpinv_cc'] ) ? wpinv_clean( $posted['wpinv_cc'] ) : null, |
|
290 | - 'disable_taxes' => ! empty( $posted['disable_taxes'] ), |
|
291 | - 'currency' => isset( $posted['wpinv_currency'] ) ? wpinv_clean( $posted['wpinv_currency'] ) : null, |
|
292 | - 'gateway' => ( $invoice->needs_payment() && isset( $posted['wpinv_gateway'] ) ) ? wpinv_clean( $posted['wpinv_gateway'] ) : null, |
|
293 | - 'address' => isset( $posted['wpinv_address'] ) ? wpinv_clean( $posted['wpinv_address'] ) : null, |
|
294 | - 'vat_number' => isset( $posted['wpinv_vat_number'] ) ? wpinv_clean( $posted['wpinv_vat_number'] ) : null, |
|
295 | - 'company' => isset( $posted['wpinv_company'] ) ? wpinv_clean( $posted['wpinv_company'] ) : null, |
|
296 | - 'company_id' => isset( $posted['wpinv_company_id'] ) ? wpinv_clean( $posted['wpinv_company_id'] ) : null, |
|
297 | - 'zip' => isset( $posted['wpinv_zip'] ) ? wpinv_clean( $posted['wpinv_zip'] ) : null, |
|
298 | - 'state' => isset( $posted['wpinv_state'] ) ? wpinv_clean( $posted['wpinv_state'] ) : null, |
|
299 | - 'city' => isset( $posted['wpinv_city'] ) ? wpinv_clean( $posted['wpinv_city'] ) : null, |
|
300 | - 'country' => isset( $posted['wpinv_country'] ) ? wpinv_clean( $posted['wpinv_country'] ) : null, |
|
301 | - 'phone' => isset( $posted['wpinv_phone'] ) ? wpinv_clean( $posted['wpinv_phone'] ) : null, |
|
302 | - 'first_name' => isset( $posted['wpinv_first_name'] ) ? wpinv_clean( $posted['wpinv_first_name'] ) : null, |
|
303 | - 'last_name' => isset( $posted['wpinv_last_name'] ) ? wpinv_clean( $posted['wpinv_last_name'] ) : null, |
|
304 | - 'author' => isset( $posted['post_author_override'] ) ? wpinv_clean( $posted['post_author_override'] ) : null, |
|
305 | - 'date_created' => isset( $posted['date_created'] ) ? wpinv_clean( $posted['date_created'] ) : null, |
|
306 | - 'date_completed' => isset( $posted['wpinv_date_completed'] ) ? wpinv_clean( $posted['wpinv_date_completed'] ) : null, |
|
307 | - 'due_date' => isset( $posted['wpinv_due_date'] ) ? wpinv_clean( $posted['wpinv_due_date'] ) : null, |
|
308 | - 'number' => isset( $posted['wpinv_number'] ) ? wpinv_clean( $posted['wpinv_number'] ) : null, |
|
309 | - 'status' => isset( $posted['wpinv_status'] ) ? wpinv_clean( $posted['wpinv_status'] ) : null, |
|
288 | + 'template' => isset($posted['wpinv_template']) ? wpinv_clean($posted['wpinv_template']) : null, |
|
289 | + 'email_cc' => isset($posted['wpinv_cc']) ? wpinv_clean($posted['wpinv_cc']) : null, |
|
290 | + 'disable_taxes' => !empty($posted['disable_taxes']), |
|
291 | + 'currency' => isset($posted['wpinv_currency']) ? wpinv_clean($posted['wpinv_currency']) : null, |
|
292 | + 'gateway' => ($invoice->needs_payment() && isset($posted['wpinv_gateway'])) ? wpinv_clean($posted['wpinv_gateway']) : null, |
|
293 | + 'address' => isset($posted['wpinv_address']) ? wpinv_clean($posted['wpinv_address']) : null, |
|
294 | + 'vat_number' => isset($posted['wpinv_vat_number']) ? wpinv_clean($posted['wpinv_vat_number']) : null, |
|
295 | + 'company' => isset($posted['wpinv_company']) ? wpinv_clean($posted['wpinv_company']) : null, |
|
296 | + 'company_id' => isset($posted['wpinv_company_id']) ? wpinv_clean($posted['wpinv_company_id']) : null, |
|
297 | + 'zip' => isset($posted['wpinv_zip']) ? wpinv_clean($posted['wpinv_zip']) : null, |
|
298 | + 'state' => isset($posted['wpinv_state']) ? wpinv_clean($posted['wpinv_state']) : null, |
|
299 | + 'city' => isset($posted['wpinv_city']) ? wpinv_clean($posted['wpinv_city']) : null, |
|
300 | + 'country' => isset($posted['wpinv_country']) ? wpinv_clean($posted['wpinv_country']) : null, |
|
301 | + 'phone' => isset($posted['wpinv_phone']) ? wpinv_clean($posted['wpinv_phone']) : null, |
|
302 | + 'first_name' => isset($posted['wpinv_first_name']) ? wpinv_clean($posted['wpinv_first_name']) : null, |
|
303 | + 'last_name' => isset($posted['wpinv_last_name']) ? wpinv_clean($posted['wpinv_last_name']) : null, |
|
304 | + 'author' => isset($posted['post_author_override']) ? wpinv_clean($posted['post_author_override']) : null, |
|
305 | + 'date_created' => isset($posted['date_created']) ? wpinv_clean($posted['date_created']) : null, |
|
306 | + 'date_completed' => isset($posted['wpinv_date_completed']) ? wpinv_clean($posted['wpinv_date_completed']) : null, |
|
307 | + 'due_date' => isset($posted['wpinv_due_date']) ? wpinv_clean($posted['wpinv_due_date']) : null, |
|
308 | + 'number' => isset($posted['wpinv_number']) ? wpinv_clean($posted['wpinv_number']) : null, |
|
309 | + 'status' => isset($posted['wpinv_status']) ? wpinv_clean($posted['wpinv_status']) : null, |
|
310 | 310 | ) |
311 | 311 | ); |
312 | 312 | |
313 | 313 | // Discount code. |
314 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
314 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
315 | 315 | |
316 | - if ( isset( $posted['wpinv_discount_code'] ) ) { |
|
317 | - $invoice->set_discount_code( wpinv_clean( $posted['wpinv_discount_code'] ) ); |
|
316 | + if (isset($posted['wpinv_discount_code'])) { |
|
317 | + $invoice->set_discount_code(wpinv_clean($posted['wpinv_discount_code'])); |
|
318 | 318 | } |
319 | 319 | |
320 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
321 | - if ( $discount->exists() ) { |
|
322 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
320 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
321 | + if ($discount->exists()) { |
|
322 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
323 | 323 | } else { |
324 | - $invoice->remove_discount( 'discount_code' ); |
|
324 | + $invoice->remove_discount('discount_code'); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | // Recalculate totals. |
@@ -330,16 +330,16 @@ discard block |
||
330 | 330 | } |
331 | 331 | |
332 | 332 | // If we're creating a new user... |
333 | - if ( ! empty( $posted['wpinv_new_user'] ) && is_email( stripslashes( $posted['wpinv_email'] ) ) ) { |
|
333 | + if (!empty($posted['wpinv_new_user']) && is_email(stripslashes($posted['wpinv_email']))) { |
|
334 | 334 | |
335 | 335 | // Attempt to create the user. |
336 | - $user = wpinv_create_user( sanitize_email( stripslashes( $posted['wpinv_email'] ) ), $invoice->get_first_name() . $invoice->get_last_name() ); |
|
336 | + $user = wpinv_create_user(sanitize_email(stripslashes($posted['wpinv_email'])), $invoice->get_first_name() . $invoice->get_last_name()); |
|
337 | 337 | |
338 | 338 | // If successful, update the invoice author. |
339 | - if ( is_numeric( $user ) ) { |
|
340 | - $invoice->set_author( $user ); |
|
339 | + if (is_numeric($user)) { |
|
340 | + $invoice->set_author($user); |
|
341 | 341 | } else { |
342 | - wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ ); |
|
342 | + wpinv_error_log($user->get_error_message(), __('Invoice add new user', 'invoicing'), __FILE__, __LINE__); |
|
343 | 343 | } |
344 | 344 | } |
345 | 345 | |
@@ -350,22 +350,22 @@ discard block |
||
350 | 350 | $invoice->save(); |
351 | 351 | |
352 | 352 | // Save the user address. |
353 | - getpaid_save_invoice_user_address( $invoice ); |
|
353 | + getpaid_save_invoice_user_address($invoice); |
|
354 | 354 | |
355 | 355 | // Undo do not send new invoice notifications. |
356 | 356 | $GLOBALS['wpinv_skip_invoice_notification'] = false; |
357 | 357 | |
358 | 358 | // (Maybe) send new user notification. |
359 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
360 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) { |
|
361 | - wp_send_new_user_notifications( $user, 'user' ); |
|
359 | + $should_send_notification = wpinv_get_option('disable_new_user_emails'); |
|
360 | + if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification))) { |
|
361 | + wp_send_new_user_notifications($user, 'user'); |
|
362 | 362 | } |
363 | 363 | |
364 | - if ( ! empty( $posted['send_to_customer'] ) && ! $invoice->is_draft() ) { |
|
365 | - getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true ); |
|
364 | + if (!empty($posted['send_to_customer']) && !$invoice->is_draft()) { |
|
365 | + getpaid()->get('invoice_emails')->user_invoice($invoice, true); |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | // Fires after an invoice is saved. |
369 | - do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
369 | + do_action('wpinv_invoice_metabox_saved', $invoice); |
|
370 | 370 | } |
371 | 371 | } |
@@ -13,17 +13,17 @@ discard block |
||
13 | 13 | class GetPaid_Manual_Gateway extends GetPaid_Payment_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 = 'manual'; |
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( |
28 | 28 | 'subscription', |
29 | 29 | 'addons', |
@@ -34,16 +34,16 @@ discard block |
||
34 | 34 | ); |
35 | 35 | |
36 | 36 | /** |
37 | - * Payment method order. |
|
38 | - * |
|
39 | - * @var int |
|
40 | - */ |
|
41 | - public $order = 11; |
|
37 | + * Payment method order. |
|
38 | + * |
|
39 | + * @var int |
|
40 | + */ |
|
41 | + public $order = 11; |
|
42 | 42 | |
43 | 43 | /** |
44 | - * Class constructor. |
|
45 | - */ |
|
46 | - public function __construct() { |
|
44 | + * Class constructor. |
|
45 | + */ |
|
46 | + public function __construct() { |
|
47 | 47 | parent::__construct(); |
48 | 48 | |
49 | 49 | $this->title = __( 'Test Gateway', 'invoicing' ); |
@@ -53,15 +53,15 @@ discard block |
||
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | - * Process Payment. |
|
57 | - * |
|
58 | - * |
|
59 | - * @param WPInv_Invoice $invoice Invoice. |
|
60 | - * @param array $submission_data Posted checkout fields. |
|
61 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
62 | - * @return array |
|
63 | - */ |
|
64 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
56 | + * Process Payment. |
|
57 | + * |
|
58 | + * |
|
59 | + * @param WPInv_Invoice $invoice Invoice. |
|
60 | + * @param array $submission_data Posted checkout fields. |
|
61 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
62 | + * @return array |
|
63 | + */ |
|
64 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
65 | 65 | |
66 | 66 | // Mark it as paid. |
67 | 67 | $invoice->mark_paid(); |
@@ -91,12 +91,12 @@ discard block |
||
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
94 | - * (Maybe) renews a manual subscription profile. |
|
95 | - * |
|
96 | - * |
|
94 | + * (Maybe) renews a manual subscription profile. |
|
95 | + * |
|
96 | + * |
|
97 | 97 | * @param WPInv_Subscription $subscription |
98 | - */ |
|
99 | - public function maybe_renew_subscription( $subscription ) { |
|
98 | + */ |
|
99 | + public function maybe_renew_subscription( $subscription ) { |
|
100 | 100 | |
101 | 101 | // Ensure its our subscription && it's active. |
102 | 102 | if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
@@ -116,13 +116,13 @@ discard block |
||
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
119 | - * Processes invoice addons. |
|
120 | - * |
|
121 | - * @param WPInv_Invoice $invoice |
|
122 | - * @param GetPaid_Form_Item[] $items |
|
123 | - * @return WPInv_Invoice |
|
124 | - */ |
|
125 | - public function process_addons( $invoice, $items ) { |
|
119 | + * Processes invoice addons. |
|
120 | + * |
|
121 | + * @param WPInv_Invoice $invoice |
|
122 | + * @param GetPaid_Form_Item[] $items |
|
123 | + * @return WPInv_Invoice |
|
124 | + */ |
|
125 | + public function process_addons( $invoice, $items ) { |
|
126 | 126 | |
127 | 127 | foreach ( $items as $item ) { |
128 | 128 | $invoice->add_item( $item ); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Manual Payment Gateway class. |
@@ -46,10 +46,10 @@ discard block |
||
46 | 46 | public function __construct() { |
47 | 47 | parent::__construct(); |
48 | 48 | |
49 | - $this->title = __( 'Test Gateway', 'invoicing' ); |
|
50 | - $this->method_title = __( 'Test Gateway', 'invoicing' ); |
|
49 | + $this->title = __('Test Gateway', 'invoicing'); |
|
50 | + $this->method_title = __('Test Gateway', 'invoicing'); |
|
51 | 51 | |
52 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
52 | + add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription')); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -61,32 +61,32 @@ discard block |
||
61 | 61 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
62 | 62 | * @return array |
63 | 63 | */ |
64 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
64 | + public function process_payment($invoice, $submission_data, $submission) { |
|
65 | 65 | |
66 | 66 | // Mark it as paid. |
67 | 67 | $invoice->mark_paid(); |
68 | 68 | |
69 | 69 | // (Maybe) activate subscriptions. |
70 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
70 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
71 | 71 | |
72 | - if ( ! empty( $subscriptions ) ) { |
|
73 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
72 | + if (!empty($subscriptions)) { |
|
73 | + $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions); |
|
74 | 74 | |
75 | - foreach ( $subscriptions as $subscription ) { |
|
76 | - if ( $subscription->exists() ) { |
|
77 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
78 | - $expiry = gmdate( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
75 | + foreach ($subscriptions as $subscription) { |
|
76 | + if ($subscription->exists()) { |
|
77 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
78 | + $expiry = gmdate('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
79 | 79 | |
80 | - $subscription->set_next_renewal_date( $expiry ); |
|
81 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
82 | - $subscription->set_profile_id( $invoice->generate_key( 'manual_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ) ); |
|
80 | + $subscription->set_next_renewal_date($expiry); |
|
81 | + $subscription->set_date_created(current_time('mysql')); |
|
82 | + $subscription->set_profile_id($invoice->generate_key('manual_sub_' . $invoice->get_id() . '_' . $subscription->get_id())); |
|
83 | 83 | $subscription->activate(); |
84 | 84 | } |
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
88 | 88 | // Send to the success page. |
89 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
89 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
90 | 90 | |
91 | 91 | } |
92 | 92 | |
@@ -96,10 +96,10 @@ discard block |
||
96 | 96 | * |
97 | 97 | * @param WPInv_Subscription $subscription |
98 | 98 | */ |
99 | - public function maybe_renew_subscription( $subscription ) { |
|
99 | + public function maybe_renew_subscription($subscription) { |
|
100 | 100 | |
101 | 101 | // Ensure its our subscription && it's active. |
102 | - if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
102 | + if ($this->id === $subscription->get_gateway() && $subscription->has_status('active trialling')) { |
|
103 | 103 | |
104 | 104 | // Renew the subscription. |
105 | 105 | $subscription->add_payment( |
@@ -122,10 +122,10 @@ discard block |
||
122 | 122 | * @param GetPaid_Form_Item[] $items |
123 | 123 | * @return WPInv_Invoice |
124 | 124 | */ |
125 | - public function process_addons( $invoice, $items ) { |
|
125 | + public function process_addons($invoice, $items) { |
|
126 | 126 | |
127 | - foreach ( $items as $item ) { |
|
128 | - $invoice->add_item( $item ); |
|
127 | + foreach ($items as $item) { |
|
128 | + $invoice->add_item($item); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | $invoice->recalculate_total(); |
@@ -128,7 +128,7 @@ |
||
128 | 128 | |
129 | 129 | if( !$version || version_compare($version,'5.999','>')){ |
130 | 130 | $url .= 'assets/js/fa-iconpicker-v6.min.js'; |
131 | - }else{ |
|
131 | + } else{ |
|
132 | 132 | $url .= 'assets/js/fa-iconpicker-v5.min.js'; |
133 | 133 | } |
134 | 134 |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * Bail if we are not in WP. |
14 | 14 | */ |
15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
16 | - exit; |
|
16 | + exit; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -21,406 +21,406 @@ discard block |
||
21 | 21 | */ |
22 | 22 | if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
23 | 23 | |
24 | - /** |
|
25 | - * A Class to be able to change settings for Font Awesome. |
|
26 | - * |
|
27 | - * Class WP_Font_Awesome_Settings |
|
28 | - */ |
|
29 | - class WP_Font_Awesome_Settings { |
|
30 | - |
|
31 | - /** |
|
32 | - * Class version version. |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - public $version = '1.1.7'; |
|
37 | - |
|
38 | - /** |
|
39 | - * Class textdomain. |
|
40 | - * |
|
41 | - * @var string |
|
42 | - */ |
|
43 | - public $textdomain = 'font-awesome-settings'; |
|
44 | - |
|
45 | - /** |
|
46 | - * Latest version of Font Awesome at time of publish published. |
|
47 | - * |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - public $latest = "6.4.2"; |
|
51 | - |
|
52 | - /** |
|
53 | - * The title. |
|
54 | - * |
|
55 | - * @var string |
|
56 | - */ |
|
57 | - public $name = 'Font Awesome'; |
|
58 | - |
|
59 | - /** |
|
60 | - * Holds the settings values. |
|
61 | - * |
|
62 | - * @var array |
|
63 | - */ |
|
64 | - private $settings; |
|
65 | - |
|
66 | - /** |
|
67 | - * WP_Font_Awesome_Settings instance. |
|
68 | - * |
|
69 | - * @access private |
|
70 | - * @since 1.0.0 |
|
71 | - * @var WP_Font_Awesome_Settings There can be only one! |
|
72 | - */ |
|
73 | - private static $instance = null; |
|
74 | - |
|
75 | - /** |
|
76 | - * Main WP_Font_Awesome_Settings Instance. |
|
77 | - * |
|
78 | - * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
79 | - * |
|
80 | - * @since 1.0.0 |
|
81 | - * @static |
|
82 | - * @return WP_Font_Awesome_Settings - Main instance. |
|
83 | - */ |
|
84 | - public static function instance() { |
|
85 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
86 | - self::$instance = new WP_Font_Awesome_Settings; |
|
87 | - |
|
88 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
89 | - |
|
90 | - if ( is_admin() ) { |
|
91 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
92 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
93 | - add_action( 'admin_init', array( self::$instance, 'constants' ) ); |
|
94 | - add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) ); |
|
95 | - } |
|
96 | - |
|
97 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
98 | - } |
|
99 | - |
|
100 | - return self::$instance; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
24 | + /** |
|
25 | + * A Class to be able to change settings for Font Awesome. |
|
26 | + * |
|
27 | + * Class WP_Font_Awesome_Settings |
|
28 | + */ |
|
29 | + class WP_Font_Awesome_Settings { |
|
30 | + |
|
31 | + /** |
|
32 | + * Class version version. |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + public $version = '1.1.7'; |
|
37 | + |
|
38 | + /** |
|
39 | + * Class textdomain. |
|
40 | + * |
|
41 | + * @var string |
|
42 | + */ |
|
43 | + public $textdomain = 'font-awesome-settings'; |
|
44 | + |
|
45 | + /** |
|
46 | + * Latest version of Font Awesome at time of publish published. |
|
47 | + * |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + public $latest = "6.4.2"; |
|
51 | + |
|
52 | + /** |
|
53 | + * The title. |
|
54 | + * |
|
55 | + * @var string |
|
56 | + */ |
|
57 | + public $name = 'Font Awesome'; |
|
58 | + |
|
59 | + /** |
|
60 | + * Holds the settings values. |
|
61 | + * |
|
62 | + * @var array |
|
63 | + */ |
|
64 | + private $settings; |
|
65 | + |
|
66 | + /** |
|
67 | + * WP_Font_Awesome_Settings instance. |
|
68 | + * |
|
69 | + * @access private |
|
70 | + * @since 1.0.0 |
|
71 | + * @var WP_Font_Awesome_Settings There can be only one! |
|
72 | + */ |
|
73 | + private static $instance = null; |
|
74 | + |
|
75 | + /** |
|
76 | + * Main WP_Font_Awesome_Settings Instance. |
|
77 | + * |
|
78 | + * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
79 | + * |
|
80 | + * @since 1.0.0 |
|
81 | + * @static |
|
82 | + * @return WP_Font_Awesome_Settings - Main instance. |
|
83 | + */ |
|
84 | + public static function instance() { |
|
85 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
86 | + self::$instance = new WP_Font_Awesome_Settings; |
|
87 | + |
|
88 | + add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
89 | + |
|
90 | + if ( is_admin() ) { |
|
91 | + add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
92 | + add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
93 | + add_action( 'admin_init', array( self::$instance, 'constants' ) ); |
|
94 | + add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) ); |
|
95 | + } |
|
96 | + |
|
97 | + do_action( 'wp_font_awesome_settings_loaded' ); |
|
98 | + } |
|
99 | + |
|
100 | + return self::$instance; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | 104 | * Define any constants that may be needed by other packages. |
105 | 105 | * |
106 | - * @return void |
|
107 | - */ |
|
108 | - public function constants(){ |
|
106 | + * @return void |
|
107 | + */ |
|
108 | + public function constants(){ |
|
109 | 109 | |
110 | - // register iconpicker constant |
|
111 | - if ( ! defined( 'FAS_ICONPICKER_JS_URL' ) ) { |
|
112 | - $url = $this->get_path_url(); |
|
113 | - $version = $this->settings['version']; |
|
110 | + // register iconpicker constant |
|
111 | + if ( ! defined( 'FAS_ICONPICKER_JS_URL' ) ) { |
|
112 | + $url = $this->get_path_url(); |
|
113 | + $version = $this->settings['version']; |
|
114 | 114 | |
115 | - if( !$version || version_compare($version,'5.999','>')){ |
|
116 | - $url .= 'assets/js/fa-iconpicker-v6.min.js'; |
|
117 | - }else{ |
|
118 | - $url .= 'assets/js/fa-iconpicker-v5.min.js'; |
|
119 | - } |
|
115 | + if( !$version || version_compare($version,'5.999','>')){ |
|
116 | + $url .= 'assets/js/fa-iconpicker-v6.min.js'; |
|
117 | + }else{ |
|
118 | + $url .= 'assets/js/fa-iconpicker-v5.min.js'; |
|
119 | + } |
|
120 | 120 | |
121 | - define( 'FAS_ICONPICKER_JS_URL', $url ); |
|
121 | + define( 'FAS_ICONPICKER_JS_URL', $url ); |
|
122 | 122 | |
123 | - } |
|
123 | + } |
|
124 | 124 | |
125 | 125 | // Set a constant if pro enbaled |
126 | - if ( ! defined( 'FAS_PRO' ) && $this->settings['pro'] ) { |
|
127 | - define( 'FAS_PRO', true ); |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Get the url path to the current folder. |
|
133 | - * |
|
134 | - * @return string |
|
135 | - */ |
|
136 | - public function get_path_url() { |
|
137 | - $content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) ); |
|
138 | - $content_url = untrailingslashit( WP_CONTENT_URL ); |
|
139 | - |
|
140 | - // Replace http:// to https://. |
|
141 | - if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) { |
|
142 | - $content_url = str_replace( 'http://', 'https://', $content_url ); |
|
143 | - } |
|
144 | - |
|
145 | - // Check if we are inside a plugin |
|
146 | - $file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
147 | - $url = str_replace( $content_dir, $content_url, $file_dir ); |
|
148 | - |
|
149 | - return trailingslashit( $url ); |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Initiate the settings and add the required action hooks. |
|
154 | - * |
|
155 | - * @since 1.0.8 Settings name wrong - FIXED |
|
156 | - */ |
|
157 | - public function init() { |
|
158 | - // Download fontawesome locally. |
|
159 | - add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 ); |
|
160 | - add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
|
161 | - |
|
162 | - $this->settings = $this->get_settings(); |
|
163 | - |
|
164 | - // Check if the official plugin is active and use that instead if so. |
|
165 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
166 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
167 | - add_action( 'admin_head', array( $this, 'add_generator' ), 99 ); |
|
168 | - } |
|
169 | - |
|
170 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
171 | - add_action( 'wp_head', array( $this, 'add_generator' ), 99 ); |
|
172 | - } |
|
173 | - |
|
174 | - if ( $this->settings['type'] == 'CSS' ) { |
|
175 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
176 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
177 | - //add_action( 'wp_footer', array( $this, 'enqueue_style' ), 5000 ); // not sure why this was added, seems to break frontend |
|
178 | - } |
|
179 | - |
|
180 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
181 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
182 | - add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 ); |
|
183 | - } |
|
184 | - } else { |
|
185 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
186 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
187 | - } |
|
188 | - |
|
189 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
190 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
191 | - add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 ); |
|
192 | - } |
|
193 | - } |
|
194 | - |
|
195 | - // remove font awesome if set to do so |
|
196 | - if ( $this->settings['dequeue'] == '1' ) { |
|
197 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
198 | - } |
|
199 | - } |
|
200 | - |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Add FA to the FSE. |
|
205 | - * |
|
206 | - * @param $editor_settings |
|
207 | - * @param $block_editor_context |
|
208 | - * |
|
209 | - * @return array |
|
210 | - */ |
|
211 | - public function enqueue_editor_styles( $editor_settings, $block_editor_context ){ |
|
212 | - |
|
213 | - if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) { |
|
214 | - $url = $this->get_url(); |
|
215 | - $editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css' href='$url' media='all' />"; |
|
216 | - } |
|
217 | - |
|
218 | - return $editor_settings; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Add FA to the FSE. |
|
223 | - * |
|
224 | - * @param $editor_settings |
|
225 | - * @param $block_editor_context |
|
226 | - * |
|
227 | - * @return array |
|
228 | - */ |
|
229 | - public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){ |
|
230 | - |
|
231 | - $url = $this->get_url(); |
|
232 | - $editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>"; |
|
233 | - |
|
234 | - return $editor_settings; |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * Adds the Font Awesome styles. |
|
239 | - */ |
|
240 | - public function enqueue_style() { |
|
241 | - // build url |
|
242 | - $url = $this->get_url(); |
|
243 | - $version = ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ? strip_tags( $this->settings['local_version'] ) : null; |
|
244 | - |
|
245 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
246 | - wp_register_style( 'font-awesome', $url, array(), $version ); |
|
247 | - wp_enqueue_style( 'font-awesome' ); |
|
248 | - |
|
249 | - // RTL language support CSS. |
|
250 | - if ( is_rtl() ) { |
|
251 | - wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
252 | - } |
|
253 | - |
|
254 | - if ( $this->settings['shims'] ) { |
|
255 | - $url = $this->get_url( true ); |
|
256 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
257 | - wp_register_style( 'font-awesome-shims', $url, array(), $version ); |
|
258 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
259 | - } |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Adds the Font Awesome JS. |
|
264 | - */ |
|
265 | - public function enqueue_scripts() { |
|
266 | - // build url |
|
267 | - $url = $this->get_url(); |
|
268 | - |
|
269 | - $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
270 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
271 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
272 | - wp_enqueue_script( 'font-awesome' ); |
|
273 | - |
|
274 | - if ( $this->settings['shims'] ) { |
|
275 | - $url = $this->get_url( true ); |
|
276 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
277 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
278 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
279 | - } |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * Get the url of the Font Awesome files. |
|
284 | - * |
|
285 | - * @param bool $shims If this is a shim file or not. |
|
286 | - * @param bool $local Load locally if allowed. |
|
287 | - * |
|
288 | - * @return string The url to the file. |
|
289 | - */ |
|
290 | - public function get_url( $shims = false, $local = true ) { |
|
291 | - $script = $shims ? 'v4-shims' : 'all'; |
|
292 | - $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
293 | - $type = $this->settings['type']; |
|
294 | - $version = $this->settings['version']; |
|
295 | - $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
296 | - $url = ''; |
|
297 | - |
|
298 | - if ( $type == 'KIT' && $kit_url ) { |
|
299 | - if ( $shims ) { |
|
300 | - // if its a kit then we don't add shims here |
|
301 | - return ''; |
|
302 | - } |
|
303 | - $url .= $kit_url; // CDN |
|
304 | - $url .= "?wpfas=true"; // set our var so our version is not removed |
|
305 | - } else { |
|
306 | - $v = ''; |
|
307 | - // Check and load locally. |
|
308 | - if ( $local && $this->has_local() ) { |
|
309 | - $script .= ".min"; |
|
310 | - $v .= '&ver=' . strip_tags( $this->settings['local_version'] ); |
|
311 | - $url .= $this->get_fonts_url(); // Local fonts url. |
|
312 | - } else { |
|
313 | - $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
314 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
315 | - } |
|
316 | - $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
317 | - $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
318 | - $url .= "?wpfas=true" . $v; // set our var so our version is not removed |
|
319 | - } |
|
320 | - |
|
321 | - return $url; |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
326 | - * |
|
327 | - * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
328 | - * |
|
329 | - * @param $url |
|
330 | - * @param $original_url |
|
331 | - * @param $_context |
|
332 | - * |
|
333 | - * @return string The filtered url. |
|
334 | - */ |
|
335 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
336 | - |
|
337 | - if ( $_context == 'display' |
|
338 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
339 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
340 | - ) {// it's a font-awesome-url (probably) |
|
341 | - |
|
342 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
343 | - if ( $this->settings['type'] == 'JS' ) { |
|
344 | - if ( $this->settings['js-pseudo'] ) { |
|
345 | - $url .= "' data-search-pseudo-elements defer='defer"; |
|
346 | - } else { |
|
347 | - $url .= "' defer='defer"; |
|
348 | - } |
|
349 | - } |
|
350 | - } else { |
|
351 | - $url = ''; // removing the url removes the file |
|
352 | - } |
|
353 | - |
|
354 | - } |
|
355 | - |
|
356 | - return $url; |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Register the database settings with WordPress. |
|
361 | - */ |
|
362 | - public function register_settings() { |
|
363 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Add the WordPress settings menu item. |
|
368 | - * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
369 | - */ |
|
370 | - public function menu_item() { |
|
371 | - $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
372 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
373 | - $this, |
|
374 | - 'settings_page' |
|
375 | - ) ); |
|
376 | - } |
|
377 | - |
|
378 | - /** |
|
379 | - * Get the current Font Awesome output settings. |
|
380 | - * |
|
381 | - * @return array The array of settings. |
|
382 | - */ |
|
383 | - public function get_settings() { |
|
384 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
385 | - |
|
386 | - $defaults = array( |
|
387 | - 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
388 | - 'version' => '', // latest |
|
389 | - 'enqueue' => '', // front and backend |
|
390 | - 'shims' => '0', // default OFF now in 2020 |
|
391 | - 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
392 | - 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
393 | - 'pro' => '0', // if pro CDN url should be used |
|
394 | - 'local' => '0', // Store fonts locally. |
|
395 | - 'local_version' => '', // Local fonts version. |
|
396 | - 'kit-url' => '', // the kit url |
|
397 | - ); |
|
398 | - |
|
399 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
400 | - |
|
401 | - /** |
|
402 | - * Filter the Font Awesome settings. |
|
403 | - * |
|
404 | - * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
405 | - */ |
|
406 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * The settings page html output. |
|
411 | - */ |
|
412 | - public function settings_page() { |
|
413 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
414 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'ayecode-connect' ) ); |
|
415 | - } |
|
416 | - |
|
417 | - // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
|
418 | - if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
419 | - $this->get_latest_version( $force_api = true ); |
|
420 | - } |
|
421 | - |
|
422 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
423 | - ?> |
|
126 | + if ( ! defined( 'FAS_PRO' ) && $this->settings['pro'] ) { |
|
127 | + define( 'FAS_PRO', true ); |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Get the url path to the current folder. |
|
133 | + * |
|
134 | + * @return string |
|
135 | + */ |
|
136 | + public function get_path_url() { |
|
137 | + $content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) ); |
|
138 | + $content_url = untrailingslashit( WP_CONTENT_URL ); |
|
139 | + |
|
140 | + // Replace http:// to https://. |
|
141 | + if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) { |
|
142 | + $content_url = str_replace( 'http://', 'https://', $content_url ); |
|
143 | + } |
|
144 | + |
|
145 | + // Check if we are inside a plugin |
|
146 | + $file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
147 | + $url = str_replace( $content_dir, $content_url, $file_dir ); |
|
148 | + |
|
149 | + return trailingslashit( $url ); |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Initiate the settings and add the required action hooks. |
|
154 | + * |
|
155 | + * @since 1.0.8 Settings name wrong - FIXED |
|
156 | + */ |
|
157 | + public function init() { |
|
158 | + // Download fontawesome locally. |
|
159 | + add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 ); |
|
160 | + add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
|
161 | + |
|
162 | + $this->settings = $this->get_settings(); |
|
163 | + |
|
164 | + // Check if the official plugin is active and use that instead if so. |
|
165 | + if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
166 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
167 | + add_action( 'admin_head', array( $this, 'add_generator' ), 99 ); |
|
168 | + } |
|
169 | + |
|
170 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
171 | + add_action( 'wp_head', array( $this, 'add_generator' ), 99 ); |
|
172 | + } |
|
173 | + |
|
174 | + if ( $this->settings['type'] == 'CSS' ) { |
|
175 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
176 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
177 | + //add_action( 'wp_footer', array( $this, 'enqueue_style' ), 5000 ); // not sure why this was added, seems to break frontend |
|
178 | + } |
|
179 | + |
|
180 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
181 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
182 | + add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 ); |
|
183 | + } |
|
184 | + } else { |
|
185 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
186 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
187 | + } |
|
188 | + |
|
189 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
190 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
191 | + add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 ); |
|
192 | + } |
|
193 | + } |
|
194 | + |
|
195 | + // remove font awesome if set to do so |
|
196 | + if ( $this->settings['dequeue'] == '1' ) { |
|
197 | + add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Add FA to the FSE. |
|
205 | + * |
|
206 | + * @param $editor_settings |
|
207 | + * @param $block_editor_context |
|
208 | + * |
|
209 | + * @return array |
|
210 | + */ |
|
211 | + public function enqueue_editor_styles( $editor_settings, $block_editor_context ){ |
|
212 | + |
|
213 | + if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) { |
|
214 | + $url = $this->get_url(); |
|
215 | + $editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css' href='$url' media='all' />"; |
|
216 | + } |
|
217 | + |
|
218 | + return $editor_settings; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Add FA to the FSE. |
|
223 | + * |
|
224 | + * @param $editor_settings |
|
225 | + * @param $block_editor_context |
|
226 | + * |
|
227 | + * @return array |
|
228 | + */ |
|
229 | + public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){ |
|
230 | + |
|
231 | + $url = $this->get_url(); |
|
232 | + $editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>"; |
|
233 | + |
|
234 | + return $editor_settings; |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Adds the Font Awesome styles. |
|
239 | + */ |
|
240 | + public function enqueue_style() { |
|
241 | + // build url |
|
242 | + $url = $this->get_url(); |
|
243 | + $version = ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ? strip_tags( $this->settings['local_version'] ) : null; |
|
244 | + |
|
245 | + wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
246 | + wp_register_style( 'font-awesome', $url, array(), $version ); |
|
247 | + wp_enqueue_style( 'font-awesome' ); |
|
248 | + |
|
249 | + // RTL language support CSS. |
|
250 | + if ( is_rtl() ) { |
|
251 | + wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
252 | + } |
|
253 | + |
|
254 | + if ( $this->settings['shims'] ) { |
|
255 | + $url = $this->get_url( true ); |
|
256 | + wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
257 | + wp_register_style( 'font-awesome-shims', $url, array(), $version ); |
|
258 | + wp_enqueue_style( 'font-awesome-shims' ); |
|
259 | + } |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Adds the Font Awesome JS. |
|
264 | + */ |
|
265 | + public function enqueue_scripts() { |
|
266 | + // build url |
|
267 | + $url = $this->get_url(); |
|
268 | + |
|
269 | + $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
270 | + call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
271 | + wp_register_script( 'font-awesome', $url, array(), null ); |
|
272 | + wp_enqueue_script( 'font-awesome' ); |
|
273 | + |
|
274 | + if ( $this->settings['shims'] ) { |
|
275 | + $url = $this->get_url( true ); |
|
276 | + call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
277 | + wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
278 | + wp_enqueue_script( 'font-awesome-shims' ); |
|
279 | + } |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * Get the url of the Font Awesome files. |
|
284 | + * |
|
285 | + * @param bool $shims If this is a shim file or not. |
|
286 | + * @param bool $local Load locally if allowed. |
|
287 | + * |
|
288 | + * @return string The url to the file. |
|
289 | + */ |
|
290 | + public function get_url( $shims = false, $local = true ) { |
|
291 | + $script = $shims ? 'v4-shims' : 'all'; |
|
292 | + $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
293 | + $type = $this->settings['type']; |
|
294 | + $version = $this->settings['version']; |
|
295 | + $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
296 | + $url = ''; |
|
297 | + |
|
298 | + if ( $type == 'KIT' && $kit_url ) { |
|
299 | + if ( $shims ) { |
|
300 | + // if its a kit then we don't add shims here |
|
301 | + return ''; |
|
302 | + } |
|
303 | + $url .= $kit_url; // CDN |
|
304 | + $url .= "?wpfas=true"; // set our var so our version is not removed |
|
305 | + } else { |
|
306 | + $v = ''; |
|
307 | + // Check and load locally. |
|
308 | + if ( $local && $this->has_local() ) { |
|
309 | + $script .= ".min"; |
|
310 | + $v .= '&ver=' . strip_tags( $this->settings['local_version'] ); |
|
311 | + $url .= $this->get_fonts_url(); // Local fonts url. |
|
312 | + } else { |
|
313 | + $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
314 | + $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
315 | + } |
|
316 | + $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
317 | + $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
318 | + $url .= "?wpfas=true" . $v; // set our var so our version is not removed |
|
319 | + } |
|
320 | + |
|
321 | + return $url; |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
326 | + * |
|
327 | + * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
328 | + * |
|
329 | + * @param $url |
|
330 | + * @param $original_url |
|
331 | + * @param $_context |
|
332 | + * |
|
333 | + * @return string The filtered url. |
|
334 | + */ |
|
335 | + public function remove_font_awesome( $url, $original_url, $_context ) { |
|
336 | + |
|
337 | + if ( $_context == 'display' |
|
338 | + && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
339 | + && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
340 | + ) {// it's a font-awesome-url (probably) |
|
341 | + |
|
342 | + if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
343 | + if ( $this->settings['type'] == 'JS' ) { |
|
344 | + if ( $this->settings['js-pseudo'] ) { |
|
345 | + $url .= "' data-search-pseudo-elements defer='defer"; |
|
346 | + } else { |
|
347 | + $url .= "' defer='defer"; |
|
348 | + } |
|
349 | + } |
|
350 | + } else { |
|
351 | + $url = ''; // removing the url removes the file |
|
352 | + } |
|
353 | + |
|
354 | + } |
|
355 | + |
|
356 | + return $url; |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Register the database settings with WordPress. |
|
361 | + */ |
|
362 | + public function register_settings() { |
|
363 | + register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Add the WordPress settings menu item. |
|
368 | + * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
369 | + */ |
|
370 | + public function menu_item() { |
|
371 | + $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
372 | + call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
373 | + $this, |
|
374 | + 'settings_page' |
|
375 | + ) ); |
|
376 | + } |
|
377 | + |
|
378 | + /** |
|
379 | + * Get the current Font Awesome output settings. |
|
380 | + * |
|
381 | + * @return array The array of settings. |
|
382 | + */ |
|
383 | + public function get_settings() { |
|
384 | + $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
385 | + |
|
386 | + $defaults = array( |
|
387 | + 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
388 | + 'version' => '', // latest |
|
389 | + 'enqueue' => '', // front and backend |
|
390 | + 'shims' => '0', // default OFF now in 2020 |
|
391 | + 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
392 | + 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
393 | + 'pro' => '0', // if pro CDN url should be used |
|
394 | + 'local' => '0', // Store fonts locally. |
|
395 | + 'local_version' => '', // Local fonts version. |
|
396 | + 'kit-url' => '', // the kit url |
|
397 | + ); |
|
398 | + |
|
399 | + $settings = wp_parse_args( $db_settings, $defaults ); |
|
400 | + |
|
401 | + /** |
|
402 | + * Filter the Font Awesome settings. |
|
403 | + * |
|
404 | + * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
405 | + */ |
|
406 | + return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | + * The settings page html output. |
|
411 | + */ |
|
412 | + public function settings_page() { |
|
413 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
414 | + wp_die( __( 'You do not have sufficient permissions to access this page.', 'ayecode-connect' ) ); |
|
415 | + } |
|
416 | + |
|
417 | + // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
|
418 | + if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
419 | + $this->get_latest_version( $force_api = true ); |
|
420 | + } |
|
421 | + |
|
422 | + if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
423 | + ?> |
|
424 | 424 | <style> |
425 | 425 | .wpfas-kit-show { |
426 | 426 | display: none; |
@@ -446,16 +446,16 @@ discard block |
||
446 | 446 | <h1><?php echo $this->name; ?></h1> |
447 | 447 | <form method="post" action="options.php" class="fas-settings-form"> |
448 | 448 | <?php |
449 | - settings_fields( 'wp-font-awesome-settings' ); |
|
450 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
451 | - $table_class = ''; |
|
452 | - if ( $this->settings['type'] ) { |
|
453 | - $table_class .= 'wpfas-' . sanitize_html_class( strtolower( $this->settings['type'] ) ) . '-set'; |
|
454 | - } |
|
455 | - if ( ! empty( $this->settings['pro'] ) ) { |
|
456 | - $table_class .= ' wpfas-has-pro'; |
|
457 | - } |
|
458 | - ?> |
|
449 | + settings_fields( 'wp-font-awesome-settings' ); |
|
450 | + do_settings_sections( 'wp-font-awesome-settings' ); |
|
451 | + $table_class = ''; |
|
452 | + if ( $this->settings['type'] ) { |
|
453 | + $table_class .= 'wpfas-' . sanitize_html_class( strtolower( $this->settings['type'] ) ) . '-set'; |
|
454 | + } |
|
455 | + if ( ! empty( $this->settings['pro'] ) ) { |
|
456 | + $table_class .= ' wpfas-has-pro'; |
|
457 | + } |
|
458 | + ?> |
|
459 | 459 | <?php if ( $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ) { ?> |
460 | 460 | <?php if ( $this->has_local() ) { ?> |
461 | 461 | <div class="notice notice-info"><p><strong><?php _e( 'Font Awesome fonts are loading locally.', 'ayecode-connect' ); ?></strong></p></div> |
@@ -480,12 +480,12 @@ discard block |
||
480 | 480 | <td> |
481 | 481 | <input class="regular-text" id="wpfas-kit-url" type="url" name="wp-font-awesome-settings[kit-url]" value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
482 | 482 | <span><?php |
483 | - echo wp_sprintf( |
|
484 | - __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'ayecode-connect' ), |
|
485 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
486 | - '</a>' |
|
487 | - ); |
|
488 | - ?></span> |
|
483 | + echo wp_sprintf( |
|
484 | + __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'ayecode-connect' ), |
|
485 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
486 | + '</a>' |
|
487 | + ); |
|
488 | + ?></span> |
|
489 | 489 | </td> |
490 | 490 | </tr> |
491 | 491 | |
@@ -526,14 +526,14 @@ discard block |
||
526 | 526 | <input type="hidden" name="wp-font-awesome-settings[pro]" value="0"/> |
527 | 527 | <input type="checkbox" name="wp-font-awesome-settings[pro]" value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro" onchange="if(jQuery(this).is(':checked')){jQuery('.wpfas-table-settings').addClass('wpfas-has-pro')}else{jQuery('.wpfas-table-settings').removeClass('wpfas-has-pro')}"/> |
528 | 528 | <span><?php |
529 | - echo wp_sprintf( |
|
530 | - __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'ayecode-connect' ), |
|
531 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">', |
|
532 | - ' <i class="fas fa-external-link-alt"></i></a>', |
|
533 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">', |
|
534 | - ' <i class="fas fa-external-link-alt"></i></a>' |
|
535 | - ); |
|
536 | - ?></span> |
|
529 | + echo wp_sprintf( |
|
530 | + __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'ayecode-connect' ), |
|
531 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">', |
|
532 | + ' <i class="fas fa-external-link-alt"></i></a>', |
|
533 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">', |
|
534 | + ' <i class="fas fa-external-link-alt"></i></a>' |
|
535 | + ); |
|
536 | + ?></span> |
|
537 | 537 | </td> |
538 | 538 | </tr> |
539 | 539 | |
@@ -587,8 +587,8 @@ discard block |
||
587 | 587 | </table> |
588 | 588 | <div class="fas-buttons"> |
589 | 589 | <?php |
590 | - submit_button(); |
|
591 | - ?> |
|
590 | + submit_button(); |
|
591 | + ?> |
|
592 | 592 | <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 24,000+ more icons with Font Awesome Pro','ayecode-connect'); ?> <i class="fas fa-external-link-alt"></i></a></p> |
593 | 593 | |
594 | 594 | </div> |
@@ -597,414 +597,414 @@ discard block |
||
597 | 597 | <div id="wpfas-version"><?php echo wp_sprintf(__( 'Version: %s (affiliate links provided)', 'ayecode-connect' ), $this->version ); ?></div> |
598 | 598 | </div> |
599 | 599 | <?php |
600 | - } |
|
601 | - } |
|
602 | - |
|
603 | - /** |
|
604 | - * Check a version number is valid and if so return it or else return an empty string. |
|
605 | - * |
|
606 | - * @param $version string The version number to check. |
|
607 | - * |
|
608 | - * @since 1.0.6 |
|
609 | - * |
|
610 | - * @return string Either a valid version number or an empty string. |
|
611 | - */ |
|
612 | - public function validate_version_number( $version ) { |
|
613 | - |
|
614 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
615 | - // valid |
|
616 | - } else { |
|
617 | - $version = '';// not validated |
|
618 | - } |
|
619 | - |
|
620 | - return $version; |
|
621 | - } |
|
622 | - |
|
623 | - |
|
624 | - /** |
|
625 | - * Get the latest version of Font Awesome. |
|
626 | - * |
|
627 | - * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours. |
|
628 | - * |
|
629 | - * @since 1.0.7 |
|
630 | - * @return mixed|string The latest version number found. |
|
631 | - */ |
|
632 | - public function get_latest_version( $force_api = false ) { |
|
633 | - $latest_version = $this->latest; |
|
634 | - |
|
635 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
636 | - |
|
637 | - if ( $cache === false || $force_api ) { // its not set |
|
638 | - $api_ver = $this->get_latest_version_from_api(); |
|
639 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
640 | - $latest_version = $api_ver; |
|
641 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
642 | - } |
|
643 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
644 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
645 | - $latest_version = $cache; |
|
646 | - } |
|
647 | - } |
|
648 | - |
|
649 | - // Check and auto download fonts locally. |
|
650 | - if ( empty( $this->settings['pro'] ) && empty( $this->settings['version'] ) && $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && ! empty( $this->settings['local_version'] ) && ! empty( $latest_version ) ) { |
|
651 | - if ( version_compare( $latest_version, $this->settings['local_version'], '>' ) && is_admin() && ! wp_doing_ajax() ) { |
|
652 | - $this->download_package( $latest_version ); |
|
653 | - } |
|
654 | - } |
|
655 | - |
|
656 | - return $latest_version; |
|
657 | - } |
|
658 | - |
|
659 | - /** |
|
660 | - * Get the latest Font Awesome version from the github API. |
|
661 | - * |
|
662 | - * @since 1.0.7 |
|
663 | - * @return string The latest version number or `0` on API fail. |
|
664 | - */ |
|
665 | - public function get_latest_version_from_api() { |
|
666 | - $version = "0"; |
|
667 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
668 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
669 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
670 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
671 | - $version = $api_response['tag_name']; |
|
672 | - } |
|
673 | - } |
|
674 | - |
|
675 | - return $version; |
|
676 | - } |
|
677 | - |
|
678 | - /** |
|
679 | - * Inline CSS for RTL language support. |
|
680 | - * |
|
681 | - * @since 1.0.13 |
|
682 | - * @return string Inline CSS. |
|
683 | - */ |
|
684 | - public function rtl_inline_css() { |
|
685 | - $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}'; |
|
686 | - |
|
687 | - return $inline_css; |
|
688 | - } |
|
689 | - |
|
690 | - /** |
|
691 | - * Show any warnings as an admin notice. |
|
692 | - * |
|
693 | - * @return void |
|
694 | - */ |
|
695 | - public function admin_notices() { |
|
696 | - $settings = $this->settings; |
|
697 | - |
|
698 | - if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
699 | - if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) { |
|
700 | - ?> |
|
600 | + } |
|
601 | + } |
|
602 | + |
|
603 | + /** |
|
604 | + * Check a version number is valid and if so return it or else return an empty string. |
|
605 | + * |
|
606 | + * @param $version string The version number to check. |
|
607 | + * |
|
608 | + * @since 1.0.6 |
|
609 | + * |
|
610 | + * @return string Either a valid version number or an empty string. |
|
611 | + */ |
|
612 | + public function validate_version_number( $version ) { |
|
613 | + |
|
614 | + if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
615 | + // valid |
|
616 | + } else { |
|
617 | + $version = '';// not validated |
|
618 | + } |
|
619 | + |
|
620 | + return $version; |
|
621 | + } |
|
622 | + |
|
623 | + |
|
624 | + /** |
|
625 | + * Get the latest version of Font Awesome. |
|
626 | + * |
|
627 | + * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours. |
|
628 | + * |
|
629 | + * @since 1.0.7 |
|
630 | + * @return mixed|string The latest version number found. |
|
631 | + */ |
|
632 | + public function get_latest_version( $force_api = false ) { |
|
633 | + $latest_version = $this->latest; |
|
634 | + |
|
635 | + $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
636 | + |
|
637 | + if ( $cache === false || $force_api ) { // its not set |
|
638 | + $api_ver = $this->get_latest_version_from_api(); |
|
639 | + if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
640 | + $latest_version = $api_ver; |
|
641 | + set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
642 | + } |
|
643 | + } elseif ( $this->validate_version_number( $cache ) ) { |
|
644 | + if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
645 | + $latest_version = $cache; |
|
646 | + } |
|
647 | + } |
|
648 | + |
|
649 | + // Check and auto download fonts locally. |
|
650 | + if ( empty( $this->settings['pro'] ) && empty( $this->settings['version'] ) && $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && ! empty( $this->settings['local_version'] ) && ! empty( $latest_version ) ) { |
|
651 | + if ( version_compare( $latest_version, $this->settings['local_version'], '>' ) && is_admin() && ! wp_doing_ajax() ) { |
|
652 | + $this->download_package( $latest_version ); |
|
653 | + } |
|
654 | + } |
|
655 | + |
|
656 | + return $latest_version; |
|
657 | + } |
|
658 | + |
|
659 | + /** |
|
660 | + * Get the latest Font Awesome version from the github API. |
|
661 | + * |
|
662 | + * @since 1.0.7 |
|
663 | + * @return string The latest version number or `0` on API fail. |
|
664 | + */ |
|
665 | + public function get_latest_version_from_api() { |
|
666 | + $version = "0"; |
|
667 | + $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
668 | + if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
669 | + $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
670 | + if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
671 | + $version = $api_response['tag_name']; |
|
672 | + } |
|
673 | + } |
|
674 | + |
|
675 | + return $version; |
|
676 | + } |
|
677 | + |
|
678 | + /** |
|
679 | + * Inline CSS for RTL language support. |
|
680 | + * |
|
681 | + * @since 1.0.13 |
|
682 | + * @return string Inline CSS. |
|
683 | + */ |
|
684 | + public function rtl_inline_css() { |
|
685 | + $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}'; |
|
686 | + |
|
687 | + return $inline_css; |
|
688 | + } |
|
689 | + |
|
690 | + /** |
|
691 | + * Show any warnings as an admin notice. |
|
692 | + * |
|
693 | + * @return void |
|
694 | + */ |
|
695 | + public function admin_notices() { |
|
696 | + $settings = $this->settings; |
|
697 | + |
|
698 | + if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
699 | + if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) { |
|
700 | + ?> |
|
701 | 701 | <div class="notice notice-error is-dismissible"> |
702 | 702 | <p><?php _e( 'The Official Font Awesome Plugin is active, please adjust your settings there.', 'ayecode-connect' ); ?></p> |
703 | 703 | </div> |
704 | 704 | <?php |
705 | - } |
|
706 | - } else { |
|
707 | - if ( ! empty( $settings ) ) { |
|
708 | - if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) { |
|
709 | - $link = admin_url('options-general.php?page=wp-font-awesome-settings'); |
|
710 | - ?> |
|
705 | + } |
|
706 | + } else { |
|
707 | + if ( ! empty( $settings ) ) { |
|
708 | + if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) { |
|
709 | + $link = admin_url('options-general.php?page=wp-font-awesome-settings'); |
|
710 | + ?> |
|
711 | 711 | <div class="notice notice-error is-dismissible"> |
712 | 712 | <p><?php echo wp_sprintf( __( 'Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'ayecode-connect' ),"<a href='". esc_url_raw( $link )."'>","</a>" ); ?></p> |
713 | 713 | </div> |
714 | 714 | <?php |
715 | - } |
|
716 | - } |
|
717 | - } |
|
718 | - } |
|
719 | - |
|
720 | - /** |
|
721 | - * Handle fontawesome add settings to download fontawesome to store locally. |
|
722 | - * |
|
723 | - * @since 1.1.1 |
|
724 | - * |
|
725 | - * @param string $option The option name. |
|
726 | - * @param mixed $value The option value. |
|
727 | - */ |
|
728 | - public function add_option_wp_font_awesome_settings( $option, $value ) { |
|
729 | - // Do nothing if WordPress is being installed. |
|
730 | - if ( wp_installing() ) { |
|
731 | - return; |
|
732 | - } |
|
733 | - |
|
734 | - if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) { |
|
735 | - $version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version(); |
|
736 | - |
|
737 | - if ( ! empty( $version ) ) { |
|
738 | - $response = $this->download_package( $version, $value ); |
|
739 | - |
|
740 | - if ( is_wp_error( $response ) ) { |
|
741 | - add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' ); |
|
742 | - } |
|
743 | - } |
|
744 | - } |
|
745 | - } |
|
746 | - |
|
747 | - /** |
|
748 | - * Handle fontawesome update settings to download fontawesome to store locally. |
|
749 | - * |
|
750 | - * @since 1.1.0 |
|
751 | - * |
|
752 | - * @param mixed $old_value The old option value. |
|
753 | - * @param mixed $value The new option value. |
|
754 | - */ |
|
755 | - public function update_option_wp_font_awesome_settings( $old_value, $new_value ) { |
|
756 | - // Do nothing if WordPress is being installed. |
|
757 | - if ( wp_installing() ) { |
|
758 | - return; |
|
759 | - } |
|
760 | - |
|
761 | - if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) { |
|
762 | - // Old values |
|
763 | - $old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' ); |
|
764 | - $old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0; |
|
765 | - |
|
766 | - // New values |
|
767 | - $new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version(); |
|
768 | - |
|
769 | - if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
|
770 | - $response = $this->download_package( $new_version, $new_value ); |
|
771 | - |
|
772 | - if ( is_wp_error( $response ) ) { |
|
773 | - add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' ); |
|
774 | - } |
|
775 | - } |
|
776 | - } |
|
777 | - } |
|
778 | - |
|
779 | - /** |
|
780 | - * Get the fonts directory local path. |
|
781 | - * |
|
782 | - * @since 1.1.0 |
|
783 | - * |
|
784 | - * @param string Fonts directory local path. |
|
785 | - */ |
|
786 | - public function get_fonts_dir() { |
|
787 | - $upload_dir = wp_upload_dir( null, false ); |
|
788 | - |
|
789 | - return $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR; |
|
790 | - } |
|
791 | - |
|
792 | - /** |
|
793 | - * Get the fonts directory local url. |
|
794 | - * |
|
795 | - * @since 1.1.0 |
|
796 | - * |
|
797 | - * @param string Fonts directory local url. |
|
798 | - */ |
|
799 | - public function get_fonts_url() { |
|
800 | - $upload_dir = wp_upload_dir( null, false ); |
|
801 | - |
|
802 | - return $upload_dir['baseurl'] . '/ayefonts/fa/'; |
|
803 | - } |
|
804 | - |
|
805 | - /** |
|
806 | - * Check whether load locally active. |
|
807 | - * |
|
808 | - * @since 1.1.0 |
|
809 | - * |
|
810 | - * @return bool True if active else false. |
|
811 | - */ |
|
812 | - public function has_local() { |
|
813 | - if ( ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) && file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
|
814 | - return true; |
|
815 | - } |
|
816 | - |
|
817 | - return false; |
|
818 | - } |
|
819 | - |
|
820 | - /** |
|
821 | - * Get the WP Filesystem access. |
|
822 | - * |
|
823 | - * @since 1.1.0 |
|
824 | - * |
|
825 | - * @return object The WP Filesystem. |
|
826 | - */ |
|
827 | - public function get_wp_filesystem() { |
|
828 | - if ( ! function_exists( 'get_filesystem_method' ) ) { |
|
829 | - require_once( ABSPATH . "/wp-admin/includes/file.php" ); |
|
830 | - } |
|
831 | - |
|
832 | - $access_type = get_filesystem_method(); |
|
833 | - |
|
834 | - if ( $access_type === 'direct' ) { |
|
835 | - /* You can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */ |
|
836 | - $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
|
837 | - |
|
838 | - /* Initialize the API */ |
|
839 | - if ( ! WP_Filesystem( $creds ) ) { |
|
840 | - /* Any problems and we exit */ |
|
841 | - return false; |
|
842 | - } |
|
843 | - |
|
844 | - global $wp_filesystem; |
|
845 | - |
|
846 | - return $wp_filesystem; |
|
847 | - /* Do our file manipulations below */ |
|
848 | - } else if ( defined( 'FTP_USER' ) ) { |
|
849 | - $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
|
850 | - |
|
851 | - /* Initialize the API */ |
|
852 | - if ( ! WP_Filesystem( $creds ) ) { |
|
853 | - /* Any problems and we exit */ |
|
854 | - return false; |
|
855 | - } |
|
856 | - |
|
857 | - global $wp_filesystem; |
|
858 | - |
|
859 | - return $wp_filesystem; |
|
860 | - } else { |
|
861 | - /* Don't have direct write access. Prompt user with our notice */ |
|
862 | - return false; |
|
863 | - } |
|
864 | - } |
|
865 | - |
|
866 | - /** |
|
867 | - * Download the fontawesome package file. |
|
868 | - * |
|
869 | - * @since 1.1.0 |
|
870 | - * |
|
871 | - * @param mixed $version The font awesome. |
|
872 | - * @param array $option Fontawesome settings. |
|
873 | - * @return WP_ERROR|bool Error on fail and true on success. |
|
874 | - */ |
|
875 | - public function download_package( $version, $option = array() ) { |
|
876 | - $filename = 'fontawesome-free-' . $version . '-web'; |
|
877 | - $url = 'https://use.fontawesome.com/releases/v' . $version . '/' . $filename . '.zip'; |
|
878 | - |
|
879 | - if ( ! function_exists( 'wp_handle_upload' ) ) { |
|
880 | - require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
881 | - } |
|
882 | - |
|
883 | - $download_file = download_url( esc_url_raw( $url ) ); |
|
884 | - |
|
885 | - if ( is_wp_error( $download_file ) ) { |
|
886 | - return new WP_Error( 'fontawesome_download_failed', __( $download_file->get_error_message(), 'ayecode-connect' ) ); |
|
887 | - } else if ( empty( $download_file ) ) { |
|
888 | - return new WP_Error( 'fontawesome_download_failed', __( 'Something went wrong in downloading the font awesome to store locally.', 'ayecode-connect' ) ); |
|
889 | - } |
|
890 | - |
|
891 | - $response = $this->extract_package( $download_file, $filename, true ); |
|
892 | - |
|
893 | - // Update local version. |
|
894 | - if ( is_wp_error( $response ) ) { |
|
895 | - return $response; |
|
896 | - } else if ( $response ) { |
|
897 | - if ( empty( $option ) ) { |
|
898 | - $option = get_option( 'wp-font-awesome-settings' ); |
|
899 | - } |
|
900 | - |
|
901 | - $option['local_version'] = $version; |
|
902 | - |
|
903 | - // Remove action to prevent looping. |
|
904 | - remove_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
|
905 | - |
|
906 | - update_option( 'wp-font-awesome-settings', $option ); |
|
907 | - |
|
908 | - return true; |
|
909 | - } |
|
910 | - |
|
911 | - return false; |
|
912 | - } |
|
913 | - |
|
914 | - /** |
|
915 | - * Extract the fontawesome package file. |
|
916 | - * |
|
917 | - * @since 1.1.0 |
|
918 | - * |
|
919 | - * @param string $package The package file path. |
|
920 | - * @param string $dirname Package file name. |
|
921 | - * @param bool $delete_package Delete temp file or not. |
|
922 | - * @return WP_Error|bool True on success WP_Error on fail. |
|
923 | - */ |
|
924 | - public function extract_package( $package, $dirname = '', $delete_package = false ) { |
|
925 | - global $wp_filesystem; |
|
926 | - |
|
927 | - $wp_filesystem = $this->get_wp_filesystem(); |
|
928 | - |
|
929 | - if ( empty( $wp_filesystem ) && isset( $wp_filesystem->errors ) && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { |
|
930 | - return new WP_Error( 'fontawesome_filesystem_error', __( $wp_filesystem->errors->get_error_message(), 'ayecode-connect' ) ); |
|
931 | - } else if ( empty( $wp_filesystem ) ) { |
|
932 | - return new WP_Error( 'fontawesome_filesystem_error', __( 'Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'ayecode-connect' ) ); |
|
933 | - } |
|
934 | - |
|
935 | - $fonts_dir = $this->get_fonts_dir(); |
|
936 | - $fonts_tmp_dir = dirname( $fonts_dir ) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR; |
|
937 | - |
|
938 | - if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
|
939 | - $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
940 | - } |
|
941 | - |
|
942 | - // Unzip package to working directory. |
|
943 | - $result = unzip_file( $package, $fonts_tmp_dir ); |
|
944 | - |
|
945 | - if ( is_wp_error( $result ) ) { |
|
946 | - $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
947 | - |
|
948 | - if ( 'incompatible_archive' === $result->get_error_code() ) { |
|
949 | - return new WP_Error( 'fontawesome_incompatible_archive', __( $result->get_error_message(), 'ayecode-connect' ) ); |
|
950 | - } |
|
951 | - |
|
952 | - return $result; |
|
953 | - } |
|
954 | - |
|
955 | - if ( $wp_filesystem->is_dir( $fonts_dir ) ) { |
|
956 | - $wp_filesystem->delete( $fonts_dir, true ); |
|
957 | - } |
|
958 | - |
|
959 | - $extract_dir = $fonts_tmp_dir; |
|
960 | - |
|
961 | - if ( $dirname && $wp_filesystem->is_dir( $extract_dir . $dirname . DIRECTORY_SEPARATOR ) ) { |
|
962 | - $extract_dir .= $dirname . DIRECTORY_SEPARATOR; |
|
963 | - } |
|
964 | - |
|
965 | - try { |
|
966 | - $return = $wp_filesystem->move( $extract_dir, $fonts_dir, true ); |
|
967 | - } catch ( Exception $e ) { |
|
968 | - $return = new WP_Error( 'fontawesome_move_package', __( 'Fail to move font awesome package!', 'ayecode-connect' ) ); |
|
969 | - } |
|
970 | - |
|
971 | - if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
|
972 | - $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
973 | - } |
|
974 | - |
|
975 | - // Once extracted, delete the package if required. |
|
976 | - if ( $delete_package ) { |
|
977 | - unlink( $package ); |
|
978 | - } |
|
979 | - |
|
980 | - return $return; |
|
981 | - } |
|
982 | - |
|
983 | - /** |
|
984 | - * Output the version in the header. |
|
985 | - */ |
|
986 | - public function add_generator() { |
|
987 | - $file = str_replace( array( "/", "\\" ), "/", realpath( __FILE__ ) ); |
|
988 | - $plugins_dir = str_replace( array( "/", "\\" ), "/", realpath( WP_PLUGIN_DIR ) ); |
|
989 | - |
|
990 | - // Find source plugin/theme. |
|
991 | - $source = array(); |
|
992 | - if ( strpos( $file, $plugins_dir ) !== false ) { |
|
993 | - $source = explode( "/", plugin_basename( $file ) ); |
|
994 | - } else if ( function_exists( 'get_theme_root' ) ) { |
|
995 | - $themes_dir = str_replace( array( "/", "\\" ), "/", realpath( get_theme_root() ) ); |
|
996 | - |
|
997 | - if ( strpos( $file, $themes_dir ) !== false ) { |
|
998 | - $source = explode( "/", ltrim( str_replace( $themes_dir, "", $file ), "/" ) ); |
|
999 | - } |
|
1000 | - } |
|
1001 | - |
|
1002 | - echo '<meta name="generator" content="WP Font Awesome Settings v' . esc_attr( $this->version ) . '"' . ( ! empty( $source[0] ) ? ' data-ac-source="' . esc_attr( $source[0] ) . '"' : '' ) . ' />'; |
|
1003 | - } |
|
1004 | - } |
|
1005 | - |
|
1006 | - /** |
|
1007 | - * Run the class if found. |
|
1008 | - */ |
|
1009 | - WP_Font_Awesome_Settings::instance(); |
|
715 | + } |
|
716 | + } |
|
717 | + } |
|
718 | + } |
|
719 | + |
|
720 | + /** |
|
721 | + * Handle fontawesome add settings to download fontawesome to store locally. |
|
722 | + * |
|
723 | + * @since 1.1.1 |
|
724 | + * |
|
725 | + * @param string $option The option name. |
|
726 | + * @param mixed $value The option value. |
|
727 | + */ |
|
728 | + public function add_option_wp_font_awesome_settings( $option, $value ) { |
|
729 | + // Do nothing if WordPress is being installed. |
|
730 | + if ( wp_installing() ) { |
|
731 | + return; |
|
732 | + } |
|
733 | + |
|
734 | + if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) { |
|
735 | + $version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version(); |
|
736 | + |
|
737 | + if ( ! empty( $version ) ) { |
|
738 | + $response = $this->download_package( $version, $value ); |
|
739 | + |
|
740 | + if ( is_wp_error( $response ) ) { |
|
741 | + add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' ); |
|
742 | + } |
|
743 | + } |
|
744 | + } |
|
745 | + } |
|
746 | + |
|
747 | + /** |
|
748 | + * Handle fontawesome update settings to download fontawesome to store locally. |
|
749 | + * |
|
750 | + * @since 1.1.0 |
|
751 | + * |
|
752 | + * @param mixed $old_value The old option value. |
|
753 | + * @param mixed $value The new option value. |
|
754 | + */ |
|
755 | + public function update_option_wp_font_awesome_settings( $old_value, $new_value ) { |
|
756 | + // Do nothing if WordPress is being installed. |
|
757 | + if ( wp_installing() ) { |
|
758 | + return; |
|
759 | + } |
|
760 | + |
|
761 | + if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) { |
|
762 | + // Old values |
|
763 | + $old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' ); |
|
764 | + $old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0; |
|
765 | + |
|
766 | + // New values |
|
767 | + $new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version(); |
|
768 | + |
|
769 | + if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
|
770 | + $response = $this->download_package( $new_version, $new_value ); |
|
771 | + |
|
772 | + if ( is_wp_error( $response ) ) { |
|
773 | + add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' ); |
|
774 | + } |
|
775 | + } |
|
776 | + } |
|
777 | + } |
|
778 | + |
|
779 | + /** |
|
780 | + * Get the fonts directory local path. |
|
781 | + * |
|
782 | + * @since 1.1.0 |
|
783 | + * |
|
784 | + * @param string Fonts directory local path. |
|
785 | + */ |
|
786 | + public function get_fonts_dir() { |
|
787 | + $upload_dir = wp_upload_dir( null, false ); |
|
788 | + |
|
789 | + return $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR; |
|
790 | + } |
|
791 | + |
|
792 | + /** |
|
793 | + * Get the fonts directory local url. |
|
794 | + * |
|
795 | + * @since 1.1.0 |
|
796 | + * |
|
797 | + * @param string Fonts directory local url. |
|
798 | + */ |
|
799 | + public function get_fonts_url() { |
|
800 | + $upload_dir = wp_upload_dir( null, false ); |
|
801 | + |
|
802 | + return $upload_dir['baseurl'] . '/ayefonts/fa/'; |
|
803 | + } |
|
804 | + |
|
805 | + /** |
|
806 | + * Check whether load locally active. |
|
807 | + * |
|
808 | + * @since 1.1.0 |
|
809 | + * |
|
810 | + * @return bool True if active else false. |
|
811 | + */ |
|
812 | + public function has_local() { |
|
813 | + if ( ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) && file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
|
814 | + return true; |
|
815 | + } |
|
816 | + |
|
817 | + return false; |
|
818 | + } |
|
819 | + |
|
820 | + /** |
|
821 | + * Get the WP Filesystem access. |
|
822 | + * |
|
823 | + * @since 1.1.0 |
|
824 | + * |
|
825 | + * @return object The WP Filesystem. |
|
826 | + */ |
|
827 | + public function get_wp_filesystem() { |
|
828 | + if ( ! function_exists( 'get_filesystem_method' ) ) { |
|
829 | + require_once( ABSPATH . "/wp-admin/includes/file.php" ); |
|
830 | + } |
|
831 | + |
|
832 | + $access_type = get_filesystem_method(); |
|
833 | + |
|
834 | + if ( $access_type === 'direct' ) { |
|
835 | + /* You can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */ |
|
836 | + $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
|
837 | + |
|
838 | + /* Initialize the API */ |
|
839 | + if ( ! WP_Filesystem( $creds ) ) { |
|
840 | + /* Any problems and we exit */ |
|
841 | + return false; |
|
842 | + } |
|
843 | + |
|
844 | + global $wp_filesystem; |
|
845 | + |
|
846 | + return $wp_filesystem; |
|
847 | + /* Do our file manipulations below */ |
|
848 | + } else if ( defined( 'FTP_USER' ) ) { |
|
849 | + $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
|
850 | + |
|
851 | + /* Initialize the API */ |
|
852 | + if ( ! WP_Filesystem( $creds ) ) { |
|
853 | + /* Any problems and we exit */ |
|
854 | + return false; |
|
855 | + } |
|
856 | + |
|
857 | + global $wp_filesystem; |
|
858 | + |
|
859 | + return $wp_filesystem; |
|
860 | + } else { |
|
861 | + /* Don't have direct write access. Prompt user with our notice */ |
|
862 | + return false; |
|
863 | + } |
|
864 | + } |
|
865 | + |
|
866 | + /** |
|
867 | + * Download the fontawesome package file. |
|
868 | + * |
|
869 | + * @since 1.1.0 |
|
870 | + * |
|
871 | + * @param mixed $version The font awesome. |
|
872 | + * @param array $option Fontawesome settings. |
|
873 | + * @return WP_ERROR|bool Error on fail and true on success. |
|
874 | + */ |
|
875 | + public function download_package( $version, $option = array() ) { |
|
876 | + $filename = 'fontawesome-free-' . $version . '-web'; |
|
877 | + $url = 'https://use.fontawesome.com/releases/v' . $version . '/' . $filename . '.zip'; |
|
878 | + |
|
879 | + if ( ! function_exists( 'wp_handle_upload' ) ) { |
|
880 | + require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
881 | + } |
|
882 | + |
|
883 | + $download_file = download_url( esc_url_raw( $url ) ); |
|
884 | + |
|
885 | + if ( is_wp_error( $download_file ) ) { |
|
886 | + return new WP_Error( 'fontawesome_download_failed', __( $download_file->get_error_message(), 'ayecode-connect' ) ); |
|
887 | + } else if ( empty( $download_file ) ) { |
|
888 | + return new WP_Error( 'fontawesome_download_failed', __( 'Something went wrong in downloading the font awesome to store locally.', 'ayecode-connect' ) ); |
|
889 | + } |
|
890 | + |
|
891 | + $response = $this->extract_package( $download_file, $filename, true ); |
|
892 | + |
|
893 | + // Update local version. |
|
894 | + if ( is_wp_error( $response ) ) { |
|
895 | + return $response; |
|
896 | + } else if ( $response ) { |
|
897 | + if ( empty( $option ) ) { |
|
898 | + $option = get_option( 'wp-font-awesome-settings' ); |
|
899 | + } |
|
900 | + |
|
901 | + $option['local_version'] = $version; |
|
902 | + |
|
903 | + // Remove action to prevent looping. |
|
904 | + remove_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
|
905 | + |
|
906 | + update_option( 'wp-font-awesome-settings', $option ); |
|
907 | + |
|
908 | + return true; |
|
909 | + } |
|
910 | + |
|
911 | + return false; |
|
912 | + } |
|
913 | + |
|
914 | + /** |
|
915 | + * Extract the fontawesome package file. |
|
916 | + * |
|
917 | + * @since 1.1.0 |
|
918 | + * |
|
919 | + * @param string $package The package file path. |
|
920 | + * @param string $dirname Package file name. |
|
921 | + * @param bool $delete_package Delete temp file or not. |
|
922 | + * @return WP_Error|bool True on success WP_Error on fail. |
|
923 | + */ |
|
924 | + public function extract_package( $package, $dirname = '', $delete_package = false ) { |
|
925 | + global $wp_filesystem; |
|
926 | + |
|
927 | + $wp_filesystem = $this->get_wp_filesystem(); |
|
928 | + |
|
929 | + if ( empty( $wp_filesystem ) && isset( $wp_filesystem->errors ) && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { |
|
930 | + return new WP_Error( 'fontawesome_filesystem_error', __( $wp_filesystem->errors->get_error_message(), 'ayecode-connect' ) ); |
|
931 | + } else if ( empty( $wp_filesystem ) ) { |
|
932 | + return new WP_Error( 'fontawesome_filesystem_error', __( 'Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'ayecode-connect' ) ); |
|
933 | + } |
|
934 | + |
|
935 | + $fonts_dir = $this->get_fonts_dir(); |
|
936 | + $fonts_tmp_dir = dirname( $fonts_dir ) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR; |
|
937 | + |
|
938 | + if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
|
939 | + $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
940 | + } |
|
941 | + |
|
942 | + // Unzip package to working directory. |
|
943 | + $result = unzip_file( $package, $fonts_tmp_dir ); |
|
944 | + |
|
945 | + if ( is_wp_error( $result ) ) { |
|
946 | + $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
947 | + |
|
948 | + if ( 'incompatible_archive' === $result->get_error_code() ) { |
|
949 | + return new WP_Error( 'fontawesome_incompatible_archive', __( $result->get_error_message(), 'ayecode-connect' ) ); |
|
950 | + } |
|
951 | + |
|
952 | + return $result; |
|
953 | + } |
|
954 | + |
|
955 | + if ( $wp_filesystem->is_dir( $fonts_dir ) ) { |
|
956 | + $wp_filesystem->delete( $fonts_dir, true ); |
|
957 | + } |
|
958 | + |
|
959 | + $extract_dir = $fonts_tmp_dir; |
|
960 | + |
|
961 | + if ( $dirname && $wp_filesystem->is_dir( $extract_dir . $dirname . DIRECTORY_SEPARATOR ) ) { |
|
962 | + $extract_dir .= $dirname . DIRECTORY_SEPARATOR; |
|
963 | + } |
|
964 | + |
|
965 | + try { |
|
966 | + $return = $wp_filesystem->move( $extract_dir, $fonts_dir, true ); |
|
967 | + } catch ( Exception $e ) { |
|
968 | + $return = new WP_Error( 'fontawesome_move_package', __( 'Fail to move font awesome package!', 'ayecode-connect' ) ); |
|
969 | + } |
|
970 | + |
|
971 | + if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
|
972 | + $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
973 | + } |
|
974 | + |
|
975 | + // Once extracted, delete the package if required. |
|
976 | + if ( $delete_package ) { |
|
977 | + unlink( $package ); |
|
978 | + } |
|
979 | + |
|
980 | + return $return; |
|
981 | + } |
|
982 | + |
|
983 | + /** |
|
984 | + * Output the version in the header. |
|
985 | + */ |
|
986 | + public function add_generator() { |
|
987 | + $file = str_replace( array( "/", "\\" ), "/", realpath( __FILE__ ) ); |
|
988 | + $plugins_dir = str_replace( array( "/", "\\" ), "/", realpath( WP_PLUGIN_DIR ) ); |
|
989 | + |
|
990 | + // Find source plugin/theme. |
|
991 | + $source = array(); |
|
992 | + if ( strpos( $file, $plugins_dir ) !== false ) { |
|
993 | + $source = explode( "/", plugin_basename( $file ) ); |
|
994 | + } else if ( function_exists( 'get_theme_root' ) ) { |
|
995 | + $themes_dir = str_replace( array( "/", "\\" ), "/", realpath( get_theme_root() ) ); |
|
996 | + |
|
997 | + if ( strpos( $file, $themes_dir ) !== false ) { |
|
998 | + $source = explode( "/", ltrim( str_replace( $themes_dir, "", $file ), "/" ) ); |
|
999 | + } |
|
1000 | + } |
|
1001 | + |
|
1002 | + echo '<meta name="generator" content="WP Font Awesome Settings v' . esc_attr( $this->version ) . '"' . ( ! empty( $source[0] ) ? ' data-ac-source="' . esc_attr( $source[0] ) . '"' : '' ) . ' />'; |
|
1003 | + } |
|
1004 | + } |
|
1005 | + |
|
1006 | + /** |
|
1007 | + * Run the class if found. |
|
1008 | + */ |
|
1009 | + WP_Font_Awesome_Settings::instance(); |
|
1010 | 1010 | } |
@@ -12,14 +12,14 @@ discard block |
||
12 | 12 | /** |
13 | 13 | * Bail if we are not in WP. |
14 | 14 | */ |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if (!defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Only add if the class does not already exist. |
21 | 21 | */ |
22 | -if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
|
22 | +if (!class_exists('WP_Font_Awesome_Settings')) { |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * A Class to be able to change settings for Font Awesome. |
@@ -82,19 +82,19 @@ discard block |
||
82 | 82 | * @return WP_Font_Awesome_Settings - Main instance. |
83 | 83 | */ |
84 | 84 | public static function instance() { |
85 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
85 | + if (!isset(self::$instance) && !(self::$instance instanceof WP_Font_Awesome_Settings)) { |
|
86 | 86 | self::$instance = new WP_Font_Awesome_Settings; |
87 | 87 | |
88 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
88 | + add_action('init', array(self::$instance, 'init')); // set settings |
|
89 | 89 | |
90 | - if ( is_admin() ) { |
|
91 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
92 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
93 | - add_action( 'admin_init', array( self::$instance, 'constants' ) ); |
|
94 | - add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) ); |
|
90 | + if (is_admin()) { |
|
91 | + add_action('admin_menu', array(self::$instance, 'menu_item')); |
|
92 | + add_action('admin_init', array(self::$instance, 'register_settings')); |
|
93 | + add_action('admin_init', array(self::$instance, 'constants')); |
|
94 | + add_action('admin_notices', array(self::$instance, 'admin_notices')); |
|
95 | 95 | } |
96 | 96 | |
97 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
97 | + do_action('wp_font_awesome_settings_loaded'); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | return self::$instance; |
@@ -105,26 +105,26 @@ discard block |
||
105 | 105 | * |
106 | 106 | * @return void |
107 | 107 | */ |
108 | - public function constants(){ |
|
108 | + public function constants() { |
|
109 | 109 | |
110 | 110 | // register iconpicker constant |
111 | - if ( ! defined( 'FAS_ICONPICKER_JS_URL' ) ) { |
|
111 | + if (!defined('FAS_ICONPICKER_JS_URL')) { |
|
112 | 112 | $url = $this->get_path_url(); |
113 | 113 | $version = $this->settings['version']; |
114 | 114 | |
115 | - if( !$version || version_compare($version,'5.999','>')){ |
|
115 | + if (!$version || version_compare($version, '5.999', '>')) { |
|
116 | 116 | $url .= 'assets/js/fa-iconpicker-v6.min.js'; |
117 | - }else{ |
|
117 | + } else { |
|
118 | 118 | $url .= 'assets/js/fa-iconpicker-v5.min.js'; |
119 | 119 | } |
120 | 120 | |
121 | - define( 'FAS_ICONPICKER_JS_URL', $url ); |
|
121 | + define('FAS_ICONPICKER_JS_URL', $url); |
|
122 | 122 | |
123 | 123 | } |
124 | 124 | |
125 | 125 | // Set a constant if pro enbaled |
126 | - if ( ! defined( 'FAS_PRO' ) && $this->settings['pro'] ) { |
|
127 | - define( 'FAS_PRO', true ); |
|
126 | + if (!defined('FAS_PRO') && $this->settings['pro']) { |
|
127 | + define('FAS_PRO', true); |
|
128 | 128 | } |
129 | 129 | } |
130 | 130 | |
@@ -134,19 +134,19 @@ discard block |
||
134 | 134 | * @return string |
135 | 135 | */ |
136 | 136 | public function get_path_url() { |
137 | - $content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) ); |
|
138 | - $content_url = untrailingslashit( WP_CONTENT_URL ); |
|
137 | + $content_dir = wp_normalize_path(untrailingslashit(WP_CONTENT_DIR)); |
|
138 | + $content_url = untrailingslashit(WP_CONTENT_URL); |
|
139 | 139 | |
140 | 140 | // Replace http:// to https://. |
141 | - if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) { |
|
142 | - $content_url = str_replace( 'http://', 'https://', $content_url ); |
|
141 | + if (strpos($content_url, 'http://') === 0 && strpos(plugins_url(), 'https://') === 0) { |
|
142 | + $content_url = str_replace('http://', 'https://', $content_url); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | // Check if we are inside a plugin |
146 | - $file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
147 | - $url = str_replace( $content_dir, $content_url, $file_dir ); |
|
146 | + $file_dir = str_replace("/includes", "", wp_normalize_path(dirname(__FILE__))); |
|
147 | + $url = str_replace($content_dir, $content_url, $file_dir); |
|
148 | 148 | |
149 | - return trailingslashit( $url ); |
|
149 | + return trailingslashit($url); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
@@ -156,45 +156,45 @@ discard block |
||
156 | 156 | */ |
157 | 157 | public function init() { |
158 | 158 | // Download fontawesome locally. |
159 | - add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 ); |
|
160 | - add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
|
159 | + add_action('add_option_wp-font-awesome-settings', array($this, 'add_option_wp_font_awesome_settings'), 10, 2); |
|
160 | + add_action('update_option_wp-font-awesome-settings', array($this, 'update_option_wp_font_awesome_settings'), 10, 2); |
|
161 | 161 | |
162 | 162 | $this->settings = $this->get_settings(); |
163 | 163 | |
164 | 164 | // Check if the official plugin is active and use that instead if so. |
165 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
166 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
167 | - add_action( 'admin_head', array( $this, 'add_generator' ), 99 ); |
|
165 | + if (!defined('FONTAWESOME_PLUGIN_FILE')) { |
|
166 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') { |
|
167 | + add_action('admin_head', array($this, 'add_generator'), 99); |
|
168 | 168 | } |
169 | 169 | |
170 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
171 | - add_action( 'wp_head', array( $this, 'add_generator' ), 99 ); |
|
170 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
171 | + add_action('wp_head', array($this, 'add_generator'), 99); |
|
172 | 172 | } |
173 | 173 | |
174 | - if ( $this->settings['type'] == 'CSS' ) { |
|
175 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
176 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
174 | + if ($this->settings['type'] == 'CSS') { |
|
175 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
176 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_style'), 5000); |
|
177 | 177 | //add_action( 'wp_footer', array( $this, 'enqueue_style' ), 5000 ); // not sure why this was added, seems to break frontend |
178 | 178 | } |
179 | 179 | |
180 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
181 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
182 | - add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 ); |
|
180 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') { |
|
181 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_style'), 5000); |
|
182 | + add_filter('block_editor_settings_all', array($this, 'enqueue_editor_styles'), 10, 2); |
|
183 | 183 | } |
184 | 184 | } else { |
185 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
186 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
185 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
186 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); |
|
187 | 187 | } |
188 | 188 | |
189 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
190 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
191 | - add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 ); |
|
189 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') { |
|
190 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); |
|
191 | + add_filter('block_editor_settings_all', array($this, 'enqueue_editor_scripts'), 10, 2); |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | |
195 | 195 | // remove font awesome if set to do so |
196 | - if ( $this->settings['dequeue'] == '1' ) { |
|
197 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
196 | + if ($this->settings['dequeue'] == '1') { |
|
197 | + add_action('clean_url', array($this, 'remove_font_awesome'), 5000, 3); |
|
198 | 198 | } |
199 | 199 | } |
200 | 200 | |
@@ -208,9 +208,9 @@ discard block |
||
208 | 208 | * |
209 | 209 | * @return array |
210 | 210 | */ |
211 | - public function enqueue_editor_styles( $editor_settings, $block_editor_context ){ |
|
211 | + public function enqueue_editor_styles($editor_settings, $block_editor_context) { |
|
212 | 212 | |
213 | - if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) { |
|
213 | + if (!empty($editor_settings['__unstableResolvedAssets']['styles'])) { |
|
214 | 214 | $url = $this->get_url(); |
215 | 215 | $editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css' href='$url' media='all' />"; |
216 | 216 | } |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | * |
227 | 227 | * @return array |
228 | 228 | */ |
229 | - public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){ |
|
229 | + public function enqueue_editor_scripts($editor_settings, $block_editor_context) { |
|
230 | 230 | |
231 | 231 | $url = $this->get_url(); |
232 | 232 | $editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>"; |
@@ -240,22 +240,22 @@ discard block |
||
240 | 240 | public function enqueue_style() { |
241 | 241 | // build url |
242 | 242 | $url = $this->get_url(); |
243 | - $version = ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ? strip_tags( $this->settings['local_version'] ) : null; |
|
243 | + $version = !empty($this->settings['local']) && empty($this->settings['pro']) ? strip_tags($this->settings['local_version']) : null; |
|
244 | 244 | |
245 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
246 | - wp_register_style( 'font-awesome', $url, array(), $version ); |
|
247 | - wp_enqueue_style( 'font-awesome' ); |
|
245 | + wp_deregister_style('font-awesome'); // deregister in case its already there |
|
246 | + wp_register_style('font-awesome', $url, array(), $version); |
|
247 | + wp_enqueue_style('font-awesome'); |
|
248 | 248 | |
249 | 249 | // RTL language support CSS. |
250 | - if ( is_rtl() ) { |
|
251 | - wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
250 | + if (is_rtl()) { |
|
251 | + wp_add_inline_style('font-awesome', $this->rtl_inline_css()); |
|
252 | 252 | } |
253 | 253 | |
254 | - if ( $this->settings['shims'] ) { |
|
255 | - $url = $this->get_url( true ); |
|
256 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
257 | - wp_register_style( 'font-awesome-shims', $url, array(), $version ); |
|
258 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
254 | + if ($this->settings['shims']) { |
|
255 | + $url = $this->get_url(true); |
|
256 | + wp_deregister_style('font-awesome-shims'); // deregister in case its already there |
|
257 | + wp_register_style('font-awesome-shims', $url, array(), $version); |
|
258 | + wp_enqueue_style('font-awesome-shims'); |
|
259 | 259 | } |
260 | 260 | } |
261 | 261 | |
@@ -267,15 +267,15 @@ discard block |
||
267 | 267 | $url = $this->get_url(); |
268 | 268 | |
269 | 269 | $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
270 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
271 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
272 | - wp_enqueue_script( 'font-awesome' ); |
|
270 | + call_user_func($deregister_function, 'font-awesome'); // deregister in case its already there |
|
271 | + wp_register_script('font-awesome', $url, array(), null); |
|
272 | + wp_enqueue_script('font-awesome'); |
|
273 | 273 | |
274 | - if ( $this->settings['shims'] ) { |
|
275 | - $url = $this->get_url( true ); |
|
276 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
277 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
278 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
274 | + if ($this->settings['shims']) { |
|
275 | + $url = $this->get_url(true); |
|
276 | + call_user_func($deregister_function, 'font-awesome-shims'); // deregister in case its already there |
|
277 | + wp_register_script('font-awesome-shims', $url, array(), null); |
|
278 | + wp_enqueue_script('font-awesome-shims'); |
|
279 | 279 | } |
280 | 280 | } |
281 | 281 | |
@@ -287,16 +287,16 @@ discard block |
||
287 | 287 | * |
288 | 288 | * @return string The url to the file. |
289 | 289 | */ |
290 | - public function get_url( $shims = false, $local = true ) { |
|
290 | + public function get_url($shims = false, $local = true) { |
|
291 | 291 | $script = $shims ? 'v4-shims' : 'all'; |
292 | 292 | $sub = $this->settings['pro'] ? 'pro' : 'use'; |
293 | 293 | $type = $this->settings['type']; |
294 | 294 | $version = $this->settings['version']; |
295 | - $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
295 | + $kit_url = $this->settings['kit-url'] ? esc_url($this->settings['kit-url']) : ''; |
|
296 | 296 | $url = ''; |
297 | 297 | |
298 | - if ( $type == 'KIT' && $kit_url ) { |
|
299 | - if ( $shims ) { |
|
298 | + if ($type == 'KIT' && $kit_url) { |
|
299 | + if ($shims) { |
|
300 | 300 | // if its a kit then we don't add shims here |
301 | 301 | return ''; |
302 | 302 | } |
@@ -305,13 +305,13 @@ discard block |
||
305 | 305 | } else { |
306 | 306 | $v = ''; |
307 | 307 | // Check and load locally. |
308 | - if ( $local && $this->has_local() ) { |
|
308 | + if ($local && $this->has_local()) { |
|
309 | 309 | $script .= ".min"; |
310 | - $v .= '&ver=' . strip_tags( $this->settings['local_version'] ); |
|
310 | + $v .= '&ver=' . strip_tags($this->settings['local_version']); |
|
311 | 311 | $url .= $this->get_fonts_url(); // Local fonts url. |
312 | 312 | } else { |
313 | 313 | $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
314 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
314 | + $url .= !empty($version) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
315 | 315 | } |
316 | 316 | $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
317 | 317 | $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
@@ -332,16 +332,16 @@ discard block |
||
332 | 332 | * |
333 | 333 | * @return string The filtered url. |
334 | 334 | */ |
335 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
335 | + public function remove_font_awesome($url, $original_url, $_context) { |
|
336 | 336 | |
337 | - if ( $_context == 'display' |
|
338 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
339 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
337 | + if ($_context == 'display' |
|
338 | + && (strstr($url, "fontawesome") !== false || strstr($url, "font-awesome") !== false) |
|
339 | + && (strstr($url, ".js") !== false || strstr($url, ".css") !== false) |
|
340 | 340 | ) {// it's a font-awesome-url (probably) |
341 | 341 | |
342 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
343 | - if ( $this->settings['type'] == 'JS' ) { |
|
344 | - if ( $this->settings['js-pseudo'] ) { |
|
342 | + if (strstr($url, "wpfas=true") !== false) { |
|
343 | + if ($this->settings['type'] == 'JS') { |
|
344 | + if ($this->settings['js-pseudo']) { |
|
345 | 345 | $url .= "' data-search-pseudo-elements defer='defer"; |
346 | 346 | } else { |
347 | 347 | $url .= "' defer='defer"; |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | * Register the database settings with WordPress. |
361 | 361 | */ |
362 | 362 | public function register_settings() { |
363 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
363 | + register_setting('wp-font-awesome-settings', 'wp-font-awesome-settings'); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | /** |
@@ -369,10 +369,10 @@ discard block |
||
369 | 369 | */ |
370 | 370 | public function menu_item() { |
371 | 371 | $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
372 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
372 | + call_user_func($menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
373 | 373 | $this, |
374 | 374 | 'settings_page' |
375 | - ) ); |
|
375 | + )); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | /** |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | * @return array The array of settings. |
382 | 382 | */ |
383 | 383 | public function get_settings() { |
384 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
384 | + $db_settings = get_option('wp-font-awesome-settings'); |
|
385 | 385 | |
386 | 386 | $defaults = array( |
387 | 387 | 'type' => 'CSS', // type to use, CSS or JS or KIT |
@@ -396,30 +396,30 @@ discard block |
||
396 | 396 | 'kit-url' => '', // the kit url |
397 | 397 | ); |
398 | 398 | |
399 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
399 | + $settings = wp_parse_args($db_settings, $defaults); |
|
400 | 400 | |
401 | 401 | /** |
402 | 402 | * Filter the Font Awesome settings. |
403 | 403 | * |
404 | 404 | * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
405 | 405 | */ |
406 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
406 | + return $this->settings = apply_filters('wp-font-awesome-settings', $settings, $db_settings, $defaults); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
410 | 410 | * The settings page html output. |
411 | 411 | */ |
412 | 412 | public function settings_page() { |
413 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
414 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'ayecode-connect' ) ); |
|
413 | + if (!current_user_can('manage_options')) { |
|
414 | + wp_die(__('You do not have sufficient permissions to access this page.', 'ayecode-connect')); |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
418 | - if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
419 | - $this->get_latest_version( $force_api = true ); |
|
418 | + if (isset($_REQUEST['force-version-check'])) { |
|
419 | + $this->get_latest_version($force_api = true); |
|
420 | 420 | } |
421 | 421 | |
422 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
422 | + if (!defined('FONTAWESOME_PLUGIN_FILE')) { |
|
423 | 423 | ?> |
424 | 424 | <style> |
425 | 425 | .wpfas-kit-show { |
@@ -446,42 +446,42 @@ discard block |
||
446 | 446 | <h1><?php echo $this->name; ?></h1> |
447 | 447 | <form method="post" action="options.php" class="fas-settings-form"> |
448 | 448 | <?php |
449 | - settings_fields( 'wp-font-awesome-settings' ); |
|
450 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
449 | + settings_fields('wp-font-awesome-settings'); |
|
450 | + do_settings_sections('wp-font-awesome-settings'); |
|
451 | 451 | $table_class = ''; |
452 | - if ( $this->settings['type'] ) { |
|
453 | - $table_class .= 'wpfas-' . sanitize_html_class( strtolower( $this->settings['type'] ) ) . '-set'; |
|
452 | + if ($this->settings['type']) { |
|
453 | + $table_class .= 'wpfas-' . sanitize_html_class(strtolower($this->settings['type'])) . '-set'; |
|
454 | 454 | } |
455 | - if ( ! empty( $this->settings['pro'] ) ) { |
|
455 | + if (!empty($this->settings['pro'])) { |
|
456 | 456 | $table_class .= ' wpfas-has-pro'; |
457 | 457 | } |
458 | 458 | ?> |
459 | - <?php if ( $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ) { ?> |
|
460 | - <?php if ( $this->has_local() ) { ?> |
|
461 | - <div class="notice notice-info"><p><strong><?php _e( 'Font Awesome fonts are loading locally.', 'ayecode-connect' ); ?></strong></p></div> |
|
459 | + <?php if ($this->settings['type'] != 'KIT' && !empty($this->settings['local']) && empty($this->settings['pro'])) { ?> |
|
460 | + <?php if ($this->has_local()) { ?> |
|
461 | + <div class="notice notice-info"><p><strong><?php _e('Font Awesome fonts are loading locally.', 'ayecode-connect'); ?></strong></p></div> |
|
462 | 462 | <?php } else { ?> |
463 | - <div class="notice notice-error"><p><strong><?php _e( 'Font Awesome fonts are not loading locally!', 'ayecode-connect' ); ?></strong></p></div> |
|
463 | + <div class="notice notice-error"><p><strong><?php _e('Font Awesome fonts are not loading locally!', 'ayecode-connect'); ?></strong></p></div> |
|
464 | 464 | <?php } ?> |
465 | 465 | <?php } ?> |
466 | - <table class="form-table wpfas-table-settings <?php echo esc_attr( $table_class ); ?>"> |
|
466 | + <table class="form-table wpfas-table-settings <?php echo esc_attr($table_class); ?>"> |
|
467 | 467 | <tr valign="top"> |
468 | - <th scope="row"><label for="wpfas-type"><?php _e( 'Type', 'ayecode-connect' ); ?></label></th> |
|
468 | + <th scope="row"><label for="wpfas-type"><?php _e('Type', 'ayecode-connect'); ?></label></th> |
|
469 | 469 | <td> |
470 | 470 | <select name="wp-font-awesome-settings[type]" id="wpfas-type" onchange="if(this.value=='KIT'){jQuery('.wpfas-table-settings').addClass('wpfas-kit-set');}else{jQuery('.wpfas-table-settings').removeClass('wpfas-kit-set');}"> |
471 | - <option value="CSS" <?php selected( $this->settings['type'], 'CSS' ); ?>><?php _e( 'CSS (default)', 'ayecode-connect' ); ?></option> |
|
472 | - <option value="JS" <?php selected( $this->settings['type'], 'JS' ); ?>>JS</option> |
|
473 | - <option value="KIT" <?php selected( $this->settings['type'], 'KIT' ); ?>><?php _e( 'Kits (settings managed on fontawesome.com)', 'ayecode-connect' ); ?></option> |
|
471 | + <option value="CSS" <?php selected($this->settings['type'], 'CSS'); ?>><?php _e('CSS (default)', 'ayecode-connect'); ?></option> |
|
472 | + <option value="JS" <?php selected($this->settings['type'], 'JS'); ?>>JS</option> |
|
473 | + <option value="KIT" <?php selected($this->settings['type'], 'KIT'); ?>><?php _e('Kits (settings managed on fontawesome.com)', 'ayecode-connect'); ?></option> |
|
474 | 474 | </select> |
475 | 475 | </td> |
476 | 476 | </tr> |
477 | 477 | |
478 | 478 | <tr valign="top" class="wpfas-kit-show"> |
479 | - <th scope="row"><label for="wpfas-kit-url"><?php _e( 'Kit URL', 'ayecode-connect' ); ?></label></th> |
|
479 | + <th scope="row"><label for="wpfas-kit-url"><?php _e('Kit URL', 'ayecode-connect'); ?></label></th> |
|
480 | 480 | <td> |
481 | - <input class="regular-text" id="wpfas-kit-url" type="url" name="wp-font-awesome-settings[kit-url]" value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
|
481 | + <input class="regular-text" id="wpfas-kit-url" type="url" name="wp-font-awesome-settings[kit-url]" value="<?php echo esc_attr($this->settings['kit-url']); ?>" placeholder="<?php echo 'https://kit.font'; echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
|
482 | 482 | <span><?php |
483 | 483 | echo wp_sprintf( |
484 | - __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'ayecode-connect' ), |
|
484 | + __('Requires a free account with Font Awesome. %sGet kit url%s', 'ayecode-connect'), |
|
485 | 485 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
486 | 486 | '</a>' |
487 | 487 | ); |
@@ -490,44 +490,44 @@ discard block |
||
490 | 490 | </tr> |
491 | 491 | |
492 | 492 | <tr valign="top" class="wpfas-kit-hide"> |
493 | - <th scope="row"><label for="wpfas-version"><?php _e( 'Version', 'ayecode-connect' ); ?></label></th> |
|
493 | + <th scope="row"><label for="wpfas-version"><?php _e('Version', 'ayecode-connect'); ?></label></th> |
|
494 | 494 | <td> |
495 | 495 | <select name="wp-font-awesome-settings[version]" id="wpfas-version"> |
496 | - <option value="" <?php selected( $this->settings['version'], '' ); ?>><?php echo wp_sprintf( __( 'Latest - %s (default)', 'ayecode-connect' ), $this->get_latest_version() ); ?></option> |
|
497 | - <option value="6.1.0" <?php selected( $this->settings['version'], '6.1.0' ); ?>>6.1.0</option> |
|
498 | - <option value="6.0.0" <?php selected( $this->settings['version'], '6.0.0' ); ?>>6.0.0</option> |
|
499 | - <option value="5.15.4" <?php selected( $this->settings['version'], '5.15.4' ); ?>>5.15.4</option> |
|
500 | - <option value="5.6.0" <?php selected( $this->settings['version'], '5.6.0' ); ?>>5.6.0</option> |
|
501 | - <option value="5.5.0" <?php selected( $this->settings['version'], '5.5.0' ); ?>>5.5.0</option> |
|
502 | - <option value="5.4.0" <?php selected( $this->settings['version'], '5.4.0' ); ?>>5.4.0</option> |
|
503 | - <option value="5.3.0" <?php selected( $this->settings['version'], '5.3.0' ); ?>>5.3.0</option> |
|
504 | - <option value="5.2.0" <?php selected( $this->settings['version'], '5.2.0' ); ?>>5.2.0</option> |
|
505 | - <option value="5.1.0" <?php selected( $this->settings['version'], '5.1.0' ); ?>>5.1.0</option> |
|
506 | - <option value="4.7.0" <?php selected( $this->settings['version'], '4.7.0' ); ?>>4.7.1 (CSS only)</option> |
|
496 | + <option value="" <?php selected($this->settings['version'], ''); ?>><?php echo wp_sprintf(__('Latest - %s (default)', 'ayecode-connect'), $this->get_latest_version()); ?></option> |
|
497 | + <option value="6.1.0" <?php selected($this->settings['version'], '6.1.0'); ?>>6.1.0</option> |
|
498 | + <option value="6.0.0" <?php selected($this->settings['version'], '6.0.0'); ?>>6.0.0</option> |
|
499 | + <option value="5.15.4" <?php selected($this->settings['version'], '5.15.4'); ?>>5.15.4</option> |
|
500 | + <option value="5.6.0" <?php selected($this->settings['version'], '5.6.0'); ?>>5.6.0</option> |
|
501 | + <option value="5.5.0" <?php selected($this->settings['version'], '5.5.0'); ?>>5.5.0</option> |
|
502 | + <option value="5.4.0" <?php selected($this->settings['version'], '5.4.0'); ?>>5.4.0</option> |
|
503 | + <option value="5.3.0" <?php selected($this->settings['version'], '5.3.0'); ?>>5.3.0</option> |
|
504 | + <option value="5.2.0" <?php selected($this->settings['version'], '5.2.0'); ?>>5.2.0</option> |
|
505 | + <option value="5.1.0" <?php selected($this->settings['version'], '5.1.0'); ?>>5.1.0</option> |
|
506 | + <option value="4.7.0" <?php selected($this->settings['version'], '4.7.0'); ?>>4.7.1 (CSS only)</option> |
|
507 | 507 | </select> |
508 | 508 | </td> |
509 | 509 | </tr> |
510 | 510 | |
511 | 511 | <tr valign="top"> |
512 | - <th scope="row"><label for="wpfas-enqueue"><?php _e( 'Enqueue', 'ayecode-connect' ); ?></label></th> |
|
512 | + <th scope="row"><label for="wpfas-enqueue"><?php _e('Enqueue', 'ayecode-connect'); ?></label></th> |
|
513 | 513 | <td> |
514 | 514 | <select name="wp-font-awesome-settings[enqueue]" id="wpfas-enqueue"> |
515 | - <option value="" <?php selected( $this->settings['enqueue'], '' ); ?>><?php _e( 'Frontend + Backend (default)', 'ayecode-connect' ); ?></option> |
|
516 | - <option value="frontend" <?php selected( $this->settings['enqueue'], 'frontend' ); ?>><?php _e( 'Frontend', 'ayecode-connect' ); ?></option> |
|
517 | - <option value="backend" <?php selected( $this->settings['enqueue'], 'backend' ); ?>><?php _e( 'Backend', 'ayecode-connect' ); ?></option> |
|
515 | + <option value="" <?php selected($this->settings['enqueue'], ''); ?>><?php _e('Frontend + Backend (default)', 'ayecode-connect'); ?></option> |
|
516 | + <option value="frontend" <?php selected($this->settings['enqueue'], 'frontend'); ?>><?php _e('Frontend', 'ayecode-connect'); ?></option> |
|
517 | + <option value="backend" <?php selected($this->settings['enqueue'], 'backend'); ?>><?php _e('Backend', 'ayecode-connect'); ?></option> |
|
518 | 518 | </select> |
519 | 519 | </td> |
520 | 520 | </tr> |
521 | 521 | |
522 | 522 | <tr valign="top" class="wpfas-kit-hide"> |
523 | 523 | <th scope="row"><label |
524 | - for="wpfas-pro"><?php _e( 'Enable pro', 'ayecode-connect' ); ?></label></th> |
|
524 | + for="wpfas-pro"><?php _e('Enable pro', 'ayecode-connect'); ?></label></th> |
|
525 | 525 | <td> |
526 | 526 | <input type="hidden" name="wp-font-awesome-settings[pro]" value="0"/> |
527 | - <input type="checkbox" name="wp-font-awesome-settings[pro]" value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro" onchange="if(jQuery(this).is(':checked')){jQuery('.wpfas-table-settings').addClass('wpfas-has-pro')}else{jQuery('.wpfas-table-settings').removeClass('wpfas-has-pro')}"/> |
|
527 | + <input type="checkbox" name="wp-font-awesome-settings[pro]" value="1" <?php checked($this->settings['pro'], '1'); ?> id="wpfas-pro" onchange="if(jQuery(this).is(':checked')){jQuery('.wpfas-table-settings').addClass('wpfas-has-pro')}else{jQuery('.wpfas-table-settings').removeClass('wpfas-has-pro')}"/> |
|
528 | 528 | <span><?php |
529 | 529 | echo wp_sprintf( |
530 | - __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'ayecode-connect' ), |
|
530 | + __('Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'ayecode-connect'), |
|
531 | 531 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">', |
532 | 532 | ' <i class="fas fa-external-link-alt"></i></a>', |
533 | 533 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">', |
@@ -538,49 +538,49 @@ discard block |
||
538 | 538 | </tr> |
539 | 539 | |
540 | 540 | <tr valign="top" class="wpfas-kit-hide wpfas-hide-pro"> |
541 | - <th scope="row"><label for="wpfas-local"><?php _e( 'Load Fonts Locally', 'ayecode-connect' ); ?></label></th> |
|
541 | + <th scope="row"><label for="wpfas-local"><?php _e('Load Fonts Locally', 'ayecode-connect'); ?></label></th> |
|
542 | 542 | <td> |
543 | 543 | <input type="hidden" name="wp-font-awesome-settings[local]" value="0"/> |
544 | - <input type="hidden" name="wp-font-awesome-settings[local_version]" value="<?php echo esc_attr( $this->settings['local_version'] ); ?>"/> |
|
545 | - <input type="checkbox" name="wp-font-awesome-settings[local]" value="1" <?php checked( $this->settings['local'], '1' ); ?> id="wpfas-local"/> |
|
546 | - <span><?php _e( '(For free version only) Load FontAwesome fonts from locally. This downloads FontAwesome fonts from fontawesome.com & stores at the local site.', 'ayecode-connect' ); ?></span> |
|
544 | + <input type="hidden" name="wp-font-awesome-settings[local_version]" value="<?php echo esc_attr($this->settings['local_version']); ?>"/> |
|
545 | + <input type="checkbox" name="wp-font-awesome-settings[local]" value="1" <?php checked($this->settings['local'], '1'); ?> id="wpfas-local"/> |
|
546 | + <span><?php _e('(For free version only) Load FontAwesome fonts from locally. This downloads FontAwesome fonts from fontawesome.com & stores at the local site.', 'ayecode-connect'); ?></span> |
|
547 | 547 | </td> |
548 | 548 | </tr> |
549 | 549 | |
550 | 550 | <tr valign="top" class="wpfas-kit-hide"> |
551 | 551 | <th scope="row"><label |
552 | - for="wpfas-shims"><?php _e( 'Enable v4 shims compatibility', 'ayecode-connect' ); ?></label> |
|
552 | + for="wpfas-shims"><?php _e('Enable v4 shims compatibility', 'ayecode-connect'); ?></label> |
|
553 | 553 | </th> |
554 | 554 | <td> |
555 | 555 | <input type="hidden" name="wp-font-awesome-settings[shims]" value="0"/> |
556 | 556 | <input type="checkbox" name="wp-font-awesome-settings[shims]" |
557 | - value="1" <?php checked( $this->settings['shims'], '1' ); ?> id="wpfas-shims"/> |
|
558 | - <span><?php _e( 'This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'ayecode-connect' ); ?></span> |
|
557 | + value="1" <?php checked($this->settings['shims'], '1'); ?> id="wpfas-shims"/> |
|
558 | + <span><?php _e('This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'ayecode-connect'); ?></span> |
|
559 | 559 | </td> |
560 | 560 | </tr> |
561 | 561 | |
562 | 562 | <tr valign="top" class="wpfas-kit-hide"> |
563 | 563 | <th scope="row"><label |
564 | - for="wpfas-js-pseudo"><?php _e( 'Enable JS pseudo elements (not recommended)', 'ayecode-connect' ); ?></label> |
|
564 | + for="wpfas-js-pseudo"><?php _e('Enable JS pseudo elements (not recommended)', 'ayecode-connect'); ?></label> |
|
565 | 565 | </th> |
566 | 566 | <td> |
567 | 567 | <input type="hidden" name="wp-font-awesome-settings[js-pseudo]" value="0"/> |
568 | 568 | <input type="checkbox" name="wp-font-awesome-settings[js-pseudo]" |
569 | - value="1" <?php checked( $this->settings['js-pseudo'], '1' ); ?> |
|
569 | + value="1" <?php checked($this->settings['js-pseudo'], '1'); ?> |
|
570 | 570 | id="wpfas-js-pseudo"/> |
571 | - <span><?php _e( 'Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'ayecode-connect' ); ?></span> |
|
571 | + <span><?php _e('Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'ayecode-connect'); ?></span> |
|
572 | 572 | </td> |
573 | 573 | </tr> |
574 | 574 | |
575 | 575 | <tr valign="top"> |
576 | 576 | <th scope="row"><label |
577 | - for="wpfas-dequeue"><?php _e( 'Dequeue', 'ayecode-connect' ); ?></label></th> |
|
577 | + for="wpfas-dequeue"><?php _e('Dequeue', 'ayecode-connect'); ?></label></th> |
|
578 | 578 | <td> |
579 | 579 | <input type="hidden" name="wp-font-awesome-settings[dequeue]" value="0"/> |
580 | 580 | <input type="checkbox" name="wp-font-awesome-settings[dequeue]" |
581 | - value="1" <?php checked( $this->settings['dequeue'], '1' ); ?> |
|
581 | + value="1" <?php checked($this->settings['dequeue'], '1'); ?> |
|
582 | 582 | id="wpfas-dequeue"/> |
583 | - <span><?php _e( 'This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'ayecode-connect' ); ?></span> |
|
583 | + <span><?php _e('This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'ayecode-connect'); ?></span> |
|
584 | 584 | </td> |
585 | 585 | </tr> |
586 | 586 | |
@@ -589,12 +589,12 @@ discard block |
||
589 | 589 | <?php |
590 | 590 | submit_button(); |
591 | 591 | ?> |
592 | - <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 24,000+ more icons with Font Awesome Pro','ayecode-connect'); ?> <i class="fas fa-external-link-alt"></i></a></p> |
|
592 | + <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 24,000+ more icons with Font Awesome Pro', 'ayecode-connect'); ?> <i class="fas fa-external-link-alt"></i></a></p> |
|
593 | 593 | |
594 | 594 | </div> |
595 | 595 | </form> |
596 | 596 | |
597 | - <div id="wpfas-version"><?php echo wp_sprintf(__( 'Version: %s (affiliate links provided)', 'ayecode-connect' ), $this->version ); ?></div> |
|
597 | + <div id="wpfas-version"><?php echo wp_sprintf(__('Version: %s (affiliate links provided)', 'ayecode-connect'), $this->version); ?></div> |
|
598 | 598 | </div> |
599 | 599 | <?php |
600 | 600 | } |
@@ -609,12 +609,12 @@ discard block |
||
609 | 609 | * |
610 | 610 | * @return string Either a valid version number or an empty string. |
611 | 611 | */ |
612 | - public function validate_version_number( $version ) { |
|
612 | + public function validate_version_number($version) { |
|
613 | 613 | |
614 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
614 | + if (version_compare($version, '0.0.1', '>=') >= 0) { |
|
615 | 615 | // valid |
616 | 616 | } else { |
617 | - $version = '';// not validated |
|
617 | + $version = ''; // not validated |
|
618 | 618 | } |
619 | 619 | |
620 | 620 | return $version; |
@@ -629,27 +629,27 @@ discard block |
||
629 | 629 | * @since 1.0.7 |
630 | 630 | * @return mixed|string The latest version number found. |
631 | 631 | */ |
632 | - public function get_latest_version( $force_api = false ) { |
|
632 | + public function get_latest_version($force_api = false) { |
|
633 | 633 | $latest_version = $this->latest; |
634 | 634 | |
635 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
635 | + $cache = get_transient('wp-font-awesome-settings-version'); |
|
636 | 636 | |
637 | - if ( $cache === false || $force_api ) { // its not set |
|
637 | + if ($cache === false || $force_api) { // its not set |
|
638 | 638 | $api_ver = $this->get_latest_version_from_api(); |
639 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
639 | + if (version_compare($api_ver, $this->latest, '>=') >= 0) { |
|
640 | 640 | $latest_version = $api_ver; |
641 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
641 | + set_transient('wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS); |
|
642 | 642 | } |
643 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
644 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
643 | + } elseif ($this->validate_version_number($cache)) { |
|
644 | + if (version_compare($cache, $this->latest, '>=') >= 0) { |
|
645 | 645 | $latest_version = $cache; |
646 | 646 | } |
647 | 647 | } |
648 | 648 | |
649 | 649 | // Check and auto download fonts locally. |
650 | - if ( empty( $this->settings['pro'] ) && empty( $this->settings['version'] ) && $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && ! empty( $this->settings['local_version'] ) && ! empty( $latest_version ) ) { |
|
651 | - if ( version_compare( $latest_version, $this->settings['local_version'], '>' ) && is_admin() && ! wp_doing_ajax() ) { |
|
652 | - $this->download_package( $latest_version ); |
|
650 | + if (empty($this->settings['pro']) && empty($this->settings['version']) && $this->settings['type'] != 'KIT' && !empty($this->settings['local']) && !empty($this->settings['local_version']) && !empty($latest_version)) { |
|
651 | + if (version_compare($latest_version, $this->settings['local_version'], '>') && is_admin() && !wp_doing_ajax()) { |
|
652 | + $this->download_package($latest_version); |
|
653 | 653 | } |
654 | 654 | } |
655 | 655 | |
@@ -664,10 +664,10 @@ discard block |
||
664 | 664 | */ |
665 | 665 | public function get_latest_version_from_api() { |
666 | 666 | $version = "0"; |
667 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
668 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
669 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
670 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
667 | + $response = wp_remote_get("https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest"); |
|
668 | + if (!is_wp_error($response) && is_array($response)) { |
|
669 | + $api_response = json_decode(wp_remote_retrieve_body($response), true); |
|
670 | + if (isset($api_response['tag_name']) && version_compare($api_response['tag_name'], $this->latest, '>=') >= 0 && empty($api_response['prerelease'])) { |
|
671 | 671 | $version = $api_response['tag_name']; |
672 | 672 | } |
673 | 673 | } |
@@ -695,21 +695,21 @@ discard block |
||
695 | 695 | public function admin_notices() { |
696 | 696 | $settings = $this->settings; |
697 | 697 | |
698 | - if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
699 | - if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) { |
|
698 | + if (defined('FONTAWESOME_PLUGIN_FILE')) { |
|
699 | + if (!empty($_REQUEST['page']) && $_REQUEST['page'] == 'wp-font-awesome-settings') { |
|
700 | 700 | ?> |
701 | 701 | <div class="notice notice-error is-dismissible"> |
702 | - <p><?php _e( 'The Official Font Awesome Plugin is active, please adjust your settings there.', 'ayecode-connect' ); ?></p> |
|
702 | + <p><?php _e('The Official Font Awesome Plugin is active, please adjust your settings there.', 'ayecode-connect'); ?></p> |
|
703 | 703 | </div> |
704 | 704 | <?php |
705 | 705 | } |
706 | 706 | } else { |
707 | - if ( ! empty( $settings ) ) { |
|
708 | - if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) { |
|
707 | + if (!empty($settings)) { |
|
708 | + if ($settings['type'] != 'KIT' && $settings['pro'] && ($settings['version'] == '' || version_compare($settings['version'], '6', '>='))) { |
|
709 | 709 | $link = admin_url('options-general.php?page=wp-font-awesome-settings'); |
710 | 710 | ?> |
711 | 711 | <div class="notice notice-error is-dismissible"> |
712 | - <p><?php echo wp_sprintf( __( 'Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'ayecode-connect' ),"<a href='". esc_url_raw( $link )."'>","</a>" ); ?></p> |
|
712 | + <p><?php echo wp_sprintf(__('Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'ayecode-connect'), "<a href='" . esc_url_raw($link) . "'>", "</a>"); ?></p> |
|
713 | 713 | </div> |
714 | 714 | <?php |
715 | 715 | } |
@@ -725,20 +725,20 @@ discard block |
||
725 | 725 | * @param string $option The option name. |
726 | 726 | * @param mixed $value The option value. |
727 | 727 | */ |
728 | - public function add_option_wp_font_awesome_settings( $option, $value ) { |
|
728 | + public function add_option_wp_font_awesome_settings($option, $value) { |
|
729 | 729 | // Do nothing if WordPress is being installed. |
730 | - if ( wp_installing() ) { |
|
730 | + if (wp_installing()) { |
|
731 | 731 | return; |
732 | 732 | } |
733 | 733 | |
734 | - if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) { |
|
735 | - $version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version(); |
|
734 | + if (!empty($value['local']) && empty($value['pro']) && !(!empty($value['type']) && $value['type'] == 'KIT')) { |
|
735 | + $version = isset($value['version']) && $value['version'] ? $value['version'] : $this->get_latest_version(); |
|
736 | 736 | |
737 | - if ( ! empty( $version ) ) { |
|
738 | - $response = $this->download_package( $version, $value ); |
|
737 | + if (!empty($version)) { |
|
738 | + $response = $this->download_package($version, $value); |
|
739 | 739 | |
740 | - if ( is_wp_error( $response ) ) { |
|
741 | - add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' ); |
|
740 | + if (is_wp_error($response)) { |
|
741 | + add_settings_error('general', 'fontawesome_download', __('ERROR:', 'ayecode-connect') . ' ' . $response->get_error_message(), 'error'); |
|
742 | 742 | } |
743 | 743 | } |
744 | 744 | } |
@@ -752,25 +752,25 @@ discard block |
||
752 | 752 | * @param mixed $old_value The old option value. |
753 | 753 | * @param mixed $value The new option value. |
754 | 754 | */ |
755 | - public function update_option_wp_font_awesome_settings( $old_value, $new_value ) { |
|
755 | + public function update_option_wp_font_awesome_settings($old_value, $new_value) { |
|
756 | 756 | // Do nothing if WordPress is being installed. |
757 | - if ( wp_installing() ) { |
|
757 | + if (wp_installing()) { |
|
758 | 758 | return; |
759 | 759 | } |
760 | 760 | |
761 | - if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) { |
|
761 | + if (!empty($new_value['local']) && empty($new_value['pro']) && !(!empty($new_value['type']) && $new_value['type'] == 'KIT')) { |
|
762 | 762 | // Old values |
763 | - $old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' ); |
|
764 | - $old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0; |
|
763 | + $old_version = isset($old_value['version']) && $old_value['version'] ? $old_value['version'] : (isset($old_value['local_version']) ? $old_value['local_version'] : ''); |
|
764 | + $old_local = isset($old_value['local']) ? (int) $old_value['local'] : 0; |
|
765 | 765 | |
766 | 766 | // New values |
767 | - $new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version(); |
|
767 | + $new_version = isset($new_value['version']) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version(); |
|
768 | 768 | |
769 | - if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
|
770 | - $response = $this->download_package( $new_version, $new_value ); |
|
769 | + if (empty($old_local) || $old_version !== $new_version || !file_exists($this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css')) { |
|
770 | + $response = $this->download_package($new_version, $new_value); |
|
771 | 771 | |
772 | - if ( is_wp_error( $response ) ) { |
|
773 | - add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' ); |
|
772 | + if (is_wp_error($response)) { |
|
773 | + add_settings_error('general', 'fontawesome_download', __('ERROR:', 'ayecode-connect') . ' ' . $response->get_error_message(), 'error'); |
|
774 | 774 | } |
775 | 775 | } |
776 | 776 | } |
@@ -784,9 +784,9 @@ discard block |
||
784 | 784 | * @param string Fonts directory local path. |
785 | 785 | */ |
786 | 786 | public function get_fonts_dir() { |
787 | - $upload_dir = wp_upload_dir( null, false ); |
|
787 | + $upload_dir = wp_upload_dir(null, false); |
|
788 | 788 | |
789 | - return $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR; |
|
789 | + return $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR; |
|
790 | 790 | } |
791 | 791 | |
792 | 792 | /** |
@@ -797,9 +797,9 @@ discard block |
||
797 | 797 | * @param string Fonts directory local url. |
798 | 798 | */ |
799 | 799 | public function get_fonts_url() { |
800 | - $upload_dir = wp_upload_dir( null, false ); |
|
800 | + $upload_dir = wp_upload_dir(null, false); |
|
801 | 801 | |
802 | - return $upload_dir['baseurl'] . '/ayefonts/fa/'; |
|
802 | + return $upload_dir['baseurl'] . '/ayefonts/fa/'; |
|
803 | 803 | } |
804 | 804 | |
805 | 805 | /** |
@@ -810,7 +810,7 @@ discard block |
||
810 | 810 | * @return bool True if active else false. |
811 | 811 | */ |
812 | 812 | public function has_local() { |
813 | - if ( ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) && file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
|
813 | + if (!empty($this->settings['local']) && empty($this->settings['pro']) && file_exists($this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css')) { |
|
814 | 814 | return true; |
815 | 815 | } |
816 | 816 | |
@@ -825,18 +825,18 @@ discard block |
||
825 | 825 | * @return object The WP Filesystem. |
826 | 826 | */ |
827 | 827 | public function get_wp_filesystem() { |
828 | - if ( ! function_exists( 'get_filesystem_method' ) ) { |
|
829 | - require_once( ABSPATH . "/wp-admin/includes/file.php" ); |
|
828 | + if (!function_exists('get_filesystem_method')) { |
|
829 | + require_once(ABSPATH . "/wp-admin/includes/file.php"); |
|
830 | 830 | } |
831 | 831 | |
832 | 832 | $access_type = get_filesystem_method(); |
833 | 833 | |
834 | - if ( $access_type === 'direct' ) { |
|
834 | + if ($access_type === 'direct') { |
|
835 | 835 | /* You can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */ |
836 | - $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
|
836 | + $creds = request_filesystem_credentials(trailingslashit(site_url()) . 'wp-admin/', '', false, false, array()); |
|
837 | 837 | |
838 | 838 | /* Initialize the API */ |
839 | - if ( ! WP_Filesystem( $creds ) ) { |
|
839 | + if (!WP_Filesystem($creds)) { |
|
840 | 840 | /* Any problems and we exit */ |
841 | 841 | return false; |
842 | 842 | } |
@@ -845,11 +845,11 @@ discard block |
||
845 | 845 | |
846 | 846 | return $wp_filesystem; |
847 | 847 | /* Do our file manipulations below */ |
848 | - } else if ( defined( 'FTP_USER' ) ) { |
|
849 | - $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
|
848 | + } else if (defined('FTP_USER')) { |
|
849 | + $creds = request_filesystem_credentials(trailingslashit(site_url()) . 'wp-admin/', '', false, false, array()); |
|
850 | 850 | |
851 | 851 | /* Initialize the API */ |
852 | - if ( ! WP_Filesystem( $creds ) ) { |
|
852 | + if (!WP_Filesystem($creds)) { |
|
853 | 853 | /* Any problems and we exit */ |
854 | 854 | return false; |
855 | 855 | } |
@@ -872,38 +872,38 @@ discard block |
||
872 | 872 | * @param array $option Fontawesome settings. |
873 | 873 | * @return WP_ERROR|bool Error on fail and true on success. |
874 | 874 | */ |
875 | - public function download_package( $version, $option = array() ) { |
|
875 | + public function download_package($version, $option = array()) { |
|
876 | 876 | $filename = 'fontawesome-free-' . $version . '-web'; |
877 | 877 | $url = 'https://use.fontawesome.com/releases/v' . $version . '/' . $filename . '.zip'; |
878 | 878 | |
879 | - if ( ! function_exists( 'wp_handle_upload' ) ) { |
|
879 | + if (!function_exists('wp_handle_upload')) { |
|
880 | 880 | require_once ABSPATH . 'wp-admin/includes/file.php'; |
881 | 881 | } |
882 | 882 | |
883 | - $download_file = download_url( esc_url_raw( $url ) ); |
|
883 | + $download_file = download_url(esc_url_raw($url)); |
|
884 | 884 | |
885 | - if ( is_wp_error( $download_file ) ) { |
|
886 | - return new WP_Error( 'fontawesome_download_failed', __( $download_file->get_error_message(), 'ayecode-connect' ) ); |
|
887 | - } else if ( empty( $download_file ) ) { |
|
888 | - return new WP_Error( 'fontawesome_download_failed', __( 'Something went wrong in downloading the font awesome to store locally.', 'ayecode-connect' ) ); |
|
885 | + if (is_wp_error($download_file)) { |
|
886 | + return new WP_Error('fontawesome_download_failed', __($download_file->get_error_message(), 'ayecode-connect')); |
|
887 | + } else if (empty($download_file)) { |
|
888 | + return new WP_Error('fontawesome_download_failed', __('Something went wrong in downloading the font awesome to store locally.', 'ayecode-connect')); |
|
889 | 889 | } |
890 | 890 | |
891 | - $response = $this->extract_package( $download_file, $filename, true ); |
|
891 | + $response = $this->extract_package($download_file, $filename, true); |
|
892 | 892 | |
893 | 893 | // Update local version. |
894 | - if ( is_wp_error( $response ) ) { |
|
894 | + if (is_wp_error($response)) { |
|
895 | 895 | return $response; |
896 | - } else if ( $response ) { |
|
897 | - if ( empty( $option ) ) { |
|
898 | - $option = get_option( 'wp-font-awesome-settings' ); |
|
896 | + } else if ($response) { |
|
897 | + if (empty($option)) { |
|
898 | + $option = get_option('wp-font-awesome-settings'); |
|
899 | 899 | } |
900 | 900 | |
901 | 901 | $option['local_version'] = $version; |
902 | 902 | |
903 | 903 | // Remove action to prevent looping. |
904 | - remove_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
|
904 | + remove_action('update_option_wp-font-awesome-settings', array($this, 'update_option_wp_font_awesome_settings'), 10, 2); |
|
905 | 905 | |
906 | - update_option( 'wp-font-awesome-settings', $option ); |
|
906 | + update_option('wp-font-awesome-settings', $option); |
|
907 | 907 | |
908 | 908 | return true; |
909 | 909 | } |
@@ -921,60 +921,60 @@ discard block |
||
921 | 921 | * @param bool $delete_package Delete temp file or not. |
922 | 922 | * @return WP_Error|bool True on success WP_Error on fail. |
923 | 923 | */ |
924 | - public function extract_package( $package, $dirname = '', $delete_package = false ) { |
|
924 | + public function extract_package($package, $dirname = '', $delete_package = false) { |
|
925 | 925 | global $wp_filesystem; |
926 | 926 | |
927 | 927 | $wp_filesystem = $this->get_wp_filesystem(); |
928 | 928 | |
929 | - if ( empty( $wp_filesystem ) && isset( $wp_filesystem->errors ) && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { |
|
930 | - return new WP_Error( 'fontawesome_filesystem_error', __( $wp_filesystem->errors->get_error_message(), 'ayecode-connect' ) ); |
|
931 | - } else if ( empty( $wp_filesystem ) ) { |
|
932 | - return new WP_Error( 'fontawesome_filesystem_error', __( 'Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'ayecode-connect' ) ); |
|
929 | + if (empty($wp_filesystem) && isset($wp_filesystem->errors) && is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) { |
|
930 | + return new WP_Error('fontawesome_filesystem_error', __($wp_filesystem->errors->get_error_message(), 'ayecode-connect')); |
|
931 | + } else if (empty($wp_filesystem)) { |
|
932 | + return new WP_Error('fontawesome_filesystem_error', __('Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'ayecode-connect')); |
|
933 | 933 | } |
934 | 934 | |
935 | 935 | $fonts_dir = $this->get_fonts_dir(); |
936 | - $fonts_tmp_dir = dirname( $fonts_dir ) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR; |
|
936 | + $fonts_tmp_dir = dirname($fonts_dir) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR; |
|
937 | 937 | |
938 | - if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
|
939 | - $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
938 | + if ($wp_filesystem->is_dir($fonts_tmp_dir)) { |
|
939 | + $wp_filesystem->delete($fonts_tmp_dir, true); |
|
940 | 940 | } |
941 | 941 | |
942 | 942 | // Unzip package to working directory. |
943 | - $result = unzip_file( $package, $fonts_tmp_dir ); |
|
943 | + $result = unzip_file($package, $fonts_tmp_dir); |
|
944 | 944 | |
945 | - if ( is_wp_error( $result ) ) { |
|
946 | - $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
945 | + if (is_wp_error($result)) { |
|
946 | + $wp_filesystem->delete($fonts_tmp_dir, true); |
|
947 | 947 | |
948 | - if ( 'incompatible_archive' === $result->get_error_code() ) { |
|
949 | - return new WP_Error( 'fontawesome_incompatible_archive', __( $result->get_error_message(), 'ayecode-connect' ) ); |
|
948 | + if ('incompatible_archive' === $result->get_error_code()) { |
|
949 | + return new WP_Error('fontawesome_incompatible_archive', __($result->get_error_message(), 'ayecode-connect')); |
|
950 | 950 | } |
951 | 951 | |
952 | 952 | return $result; |
953 | 953 | } |
954 | 954 | |
955 | - if ( $wp_filesystem->is_dir( $fonts_dir ) ) { |
|
956 | - $wp_filesystem->delete( $fonts_dir, true ); |
|
955 | + if ($wp_filesystem->is_dir($fonts_dir)) { |
|
956 | + $wp_filesystem->delete($fonts_dir, true); |
|
957 | 957 | } |
958 | 958 | |
959 | 959 | $extract_dir = $fonts_tmp_dir; |
960 | 960 | |
961 | - if ( $dirname && $wp_filesystem->is_dir( $extract_dir . $dirname . DIRECTORY_SEPARATOR ) ) { |
|
961 | + if ($dirname && $wp_filesystem->is_dir($extract_dir . $dirname . DIRECTORY_SEPARATOR)) { |
|
962 | 962 | $extract_dir .= $dirname . DIRECTORY_SEPARATOR; |
963 | 963 | } |
964 | 964 | |
965 | 965 | try { |
966 | - $return = $wp_filesystem->move( $extract_dir, $fonts_dir, true ); |
|
967 | - } catch ( Exception $e ) { |
|
968 | - $return = new WP_Error( 'fontawesome_move_package', __( 'Fail to move font awesome package!', 'ayecode-connect' ) ); |
|
966 | + $return = $wp_filesystem->move($extract_dir, $fonts_dir, true); |
|
967 | + } catch (Exception $e) { |
|
968 | + $return = new WP_Error('fontawesome_move_package', __('Fail to move font awesome package!', 'ayecode-connect')); |
|
969 | 969 | } |
970 | 970 | |
971 | - if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
|
972 | - $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
971 | + if ($wp_filesystem->is_dir($fonts_tmp_dir)) { |
|
972 | + $wp_filesystem->delete($fonts_tmp_dir, true); |
|
973 | 973 | } |
974 | 974 | |
975 | 975 | // Once extracted, delete the package if required. |
976 | - if ( $delete_package ) { |
|
977 | - unlink( $package ); |
|
976 | + if ($delete_package) { |
|
977 | + unlink($package); |
|
978 | 978 | } |
979 | 979 | |
980 | 980 | return $return; |
@@ -984,22 +984,22 @@ discard block |
||
984 | 984 | * Output the version in the header. |
985 | 985 | */ |
986 | 986 | public function add_generator() { |
987 | - $file = str_replace( array( "/", "\\" ), "/", realpath( __FILE__ ) ); |
|
988 | - $plugins_dir = str_replace( array( "/", "\\" ), "/", realpath( WP_PLUGIN_DIR ) ); |
|
987 | + $file = str_replace(array("/", "\\"), "/", realpath(__FILE__)); |
|
988 | + $plugins_dir = str_replace(array("/", "\\"), "/", realpath(WP_PLUGIN_DIR)); |
|
989 | 989 | |
990 | 990 | // Find source plugin/theme. |
991 | 991 | $source = array(); |
992 | - if ( strpos( $file, $plugins_dir ) !== false ) { |
|
993 | - $source = explode( "/", plugin_basename( $file ) ); |
|
994 | - } else if ( function_exists( 'get_theme_root' ) ) { |
|
995 | - $themes_dir = str_replace( array( "/", "\\" ), "/", realpath( get_theme_root() ) ); |
|
992 | + if (strpos($file, $plugins_dir) !== false) { |
|
993 | + $source = explode("/", plugin_basename($file)); |
|
994 | + } else if (function_exists('get_theme_root')) { |
|
995 | + $themes_dir = str_replace(array("/", "\\"), "/", realpath(get_theme_root())); |
|
996 | 996 | |
997 | - if ( strpos( $file, $themes_dir ) !== false ) { |
|
998 | - $source = explode( "/", ltrim( str_replace( $themes_dir, "", $file ), "/" ) ); |
|
997 | + if (strpos($file, $themes_dir) !== false) { |
|
998 | + $source = explode("/", ltrim(str_replace($themes_dir, "", $file), "/")); |
|
999 | 999 | } |
1000 | 1000 | } |
1001 | 1001 | |
1002 | - echo '<meta name="generator" content="WP Font Awesome Settings v' . esc_attr( $this->version ) . '"' . ( ! empty( $source[0] ) ? ' data-ac-source="' . esc_attr( $source[0] ) . '"' : '' ) . ' />'; |
|
1002 | + echo '<meta name="generator" content="WP Font Awesome Settings v' . esc_attr($this->version) . '"' . (!empty($source[0]) ? ' data-ac-source="' . esc_attr($source[0]) . '"' : '') . ' />'; |
|
1003 | 1003 | } |
1004 | 1004 | } |
1005 | 1005 |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | 'getpaid-nonce', |
58 | 58 | 'getpaid-nonce' |
59 | 59 | ); |
60 | - $anchor = __( 'Deactivate', 'invoicing' ); |
|
61 | - $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
60 | + $anchor = __( 'Deactivate', 'invoicing' ); |
|
61 | + $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
62 | 62 | $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
63 | 63 | |
64 | 64 | } elseif ( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) && wpinv_current_user_can( 'activate_discount', array( 'discount' => (int) $discount->ID ) ) ) { |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | 'getpaid-nonce', |
74 | 74 | 'getpaid-nonce' |
75 | 75 | ); |
76 | - $anchor = __( 'Activate', 'invoicing' ); |
|
77 | - $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
76 | + $anchor = __( 'Activate', 'invoicing' ); |
|
77 | + $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
78 | 78 | $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
79 | 79 | |
80 | 80 | } |
@@ -121,13 +121,13 @@ discard block |
||
121 | 121 | $types = wpinv_get_discount_types(); |
122 | 122 | |
123 | 123 | foreach ( $types as $name => $type ) { |
124 | - echo '<option value="' . esc_attr( $name ) . '"'; |
|
124 | + echo '<option value="' . esc_attr( $name ) . '"'; |
|
125 | 125 | |
126 | - if ( isset( $_GET['discount_type'] ) ) { |
|
127 | - selected( $name, sanitize_text_field( $_GET['discount_type'] ) ); |
|
126 | + if ( isset( $_GET['discount_type'] ) ) { |
|
127 | + selected( $name, sanitize_text_field( $_GET['discount_type'] ) ); |
|
128 | 128 | } |
129 | 129 | |
130 | - echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
130 | + echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
131 | 131 | } |
132 | 132 | ?> |
133 | 133 | </select> |
@@ -154,15 +154,15 @@ discard block |
||
154 | 154 | // Filter vat rule type |
155 | 155 | if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) { |
156 | 156 | $meta_query[] = array( |
157 | - 'key' => '_wpi_discount_type', |
|
158 | - 'value' => sanitize_key( urldecode( $_GET['discount_type'] ) ), |
|
159 | - 'compare' => '=', |
|
160 | - ); |
|
161 | - } |
|
157 | + 'key' => '_wpi_discount_type', |
|
158 | + 'value' => sanitize_key( urldecode( $_GET['discount_type'] ) ), |
|
159 | + 'compare' => '=', |
|
160 | + ); |
|
161 | + } |
|
162 | 162 | |
163 | 163 | if ( ! empty( $meta_query ) ) { |
164 | 164 | $vars['meta_query'] = $meta_query; |
165 | - } |
|
165 | + } |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | return $vars; |
@@ -1,51 +1,51 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( ! defined( 'WPINC' ) ) { |
|
3 | +if (!defined('WPINC')) { |
|
4 | 4 | exit; |
5 | 5 | } |
6 | 6 | |
7 | -add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' ); |
|
8 | -function wpinv_discount_custom_column( $column ) { |
|
7 | +add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column'); |
|
8 | +function wpinv_discount_custom_column($column) { |
|
9 | 9 | global $post; |
10 | 10 | |
11 | - $discount = new WPInv_Discount( $post ); |
|
11 | + $discount = new WPInv_Discount($post); |
|
12 | 12 | |
13 | - switch ( $column ) { |
|
13 | + switch ($column) { |
|
14 | 14 | case 'code': |
15 | - echo esc_html( $discount->get_code() ); |
|
15 | + echo esc_html($discount->get_code()); |
|
16 | 16 | break; |
17 | 17 | case 'amount': |
18 | - echo wp_kses_post( $discount->get_formatted_amount() ); |
|
18 | + echo wp_kses_post($discount->get_formatted_amount()); |
|
19 | 19 | break; |
20 | 20 | case 'usage': |
21 | - echo wp_kses_post( $discount->get_usage() ); |
|
21 | + echo wp_kses_post($discount->get_usage()); |
|
22 | 22 | break; |
23 | 23 | case 'start_date': |
24 | - echo wp_kses_post( getpaid_format_date_value( $discount->get_start_date() ) ); |
|
24 | + echo wp_kses_post(getpaid_format_date_value($discount->get_start_date())); |
|
25 | 25 | break; |
26 | 26 | case 'expiry_date': |
27 | - echo wp_kses_post( getpaid_format_date_value( $discount->get_expiration_date(), __( 'Never', 'invoicing' ) ) ); |
|
27 | + echo wp_kses_post(getpaid_format_date_value($discount->get_expiration_date(), __('Never', 'invoicing'))); |
|
28 | 28 | break; |
29 | 29 | } |
30 | 30 | } |
31 | 31 | |
32 | -add_filter( 'post_row_actions', 'wpinv_post_row_actions', 90, 2 ); |
|
33 | -function wpinv_post_row_actions( $actions, $post ) { |
|
34 | - $post_type = ! empty( $post->post_type ) ? $post->post_type : ''; |
|
32 | +add_filter('post_row_actions', 'wpinv_post_row_actions', 90, 2); |
|
33 | +function wpinv_post_row_actions($actions, $post) { |
|
34 | + $post_type = !empty($post->post_type) ? $post->post_type : ''; |
|
35 | 35 | |
36 | - if ( $post_type == 'wpi_discount' ) { |
|
37 | - $actions = wpinv_discount_row_actions( $post, $actions ); |
|
36 | + if ($post_type == 'wpi_discount') { |
|
37 | + $actions = wpinv_discount_row_actions($post, $actions); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | return $actions; |
41 | 41 | } |
42 | 42 | |
43 | -function wpinv_discount_row_actions( $discount, $row_actions ) { |
|
44 | - $row_actions = array(); |
|
45 | - $edit_link = get_edit_post_link( $discount->ID ); |
|
46 | - $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>'; |
|
43 | +function wpinv_discount_row_actions($discount, $row_actions) { |
|
44 | + $row_actions = array(); |
|
45 | + $edit_link = get_edit_post_link($discount->ID); |
|
46 | + $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>'; |
|
47 | 47 | |
48 | - if ( in_array( strtolower( $discount->post_status ), array( 'publish' ) ) && wpinv_current_user_can( 'deactivate_discount', array( 'discount' => (int) $discount->ID ) ) ) { |
|
48 | + if (in_array(strtolower($discount->post_status), array('publish')) && wpinv_current_user_can('deactivate_discount', array('discount' => (int) $discount->ID))) { |
|
49 | 49 | |
50 | 50 | $url = wp_nonce_url( |
51 | 51 | add_query_arg( |
@@ -57,13 +57,13 @@ discard block |
||
57 | 57 | 'getpaid-nonce', |
58 | 58 | 'getpaid-nonce' |
59 | 59 | ); |
60 | - $anchor = __( 'Deactivate', 'invoicing' ); |
|
61 | - $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
60 | + $anchor = __('Deactivate', 'invoicing'); |
|
61 | + $title = esc_attr__('Are you sure you want to deactivate this discount?', 'invoicing'); |
|
62 | 62 | $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
63 | 63 | |
64 | - } elseif ( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) && wpinv_current_user_can( 'activate_discount', array( 'discount' => (int) $discount->ID ) ) ) { |
|
64 | + } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft')) && wpinv_current_user_can('activate_discount', array('discount' => (int) $discount->ID))) { |
|
65 | 65 | |
66 | - $url = wp_nonce_url( |
|
66 | + $url = wp_nonce_url( |
|
67 | 67 | add_query_arg( |
68 | 68 | array( |
69 | 69 | 'getpaid-admin-action' => 'activate_discount', |
@@ -73,14 +73,14 @@ discard block |
||
73 | 73 | 'getpaid-nonce', |
74 | 74 | 'getpaid-nonce' |
75 | 75 | ); |
76 | - $anchor = __( 'Activate', 'invoicing' ); |
|
77 | - $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
76 | + $anchor = __('Activate', 'invoicing'); |
|
77 | + $title = esc_attr__('Are you sure you want to activate this discount?', 'invoicing'); |
|
78 | 78 | $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
79 | 79 | |
80 | 80 | } |
81 | 81 | |
82 | - if ( wpinv_current_user_can( 'delete_discount', array( 'discount' => (int) $discount->ID ) ) ) { |
|
83 | - $url = esc_url( |
|
82 | + if (wpinv_current_user_can('delete_discount', array('discount' => (int) $discount->ID))) { |
|
83 | + $url = esc_url( |
|
84 | 84 | wp_nonce_url( |
85 | 85 | add_query_arg( |
86 | 86 | array( |
@@ -93,12 +93,12 @@ discard block |
||
93 | 93 | ) |
94 | 94 | ); |
95 | 95 | |
96 | - $anchor = __( 'Delete', 'invoicing' ); |
|
97 | - $title = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' ); |
|
96 | + $anchor = __('Delete', 'invoicing'); |
|
97 | + $title = esc_attr__('Are you sure you want to delete this discount?', 'invoicing'); |
|
98 | 98 | $row_actions['delete'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
99 | 99 | } |
100 | 100 | |
101 | - $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount ); |
|
101 | + $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount); |
|
102 | 102 | |
103 | 103 | return $row_actions; |
104 | 104 | } |
@@ -106,68 +106,68 @@ discard block |
||
106 | 106 | function wpinv_restrict_manage_posts() { |
107 | 107 | global $typenow; |
108 | 108 | |
109 | - if ( 'wpi_discount' == $typenow ) { |
|
109 | + if ('wpi_discount' == $typenow) { |
|
110 | 110 | wpinv_discount_filters(); |
111 | 111 | } |
112 | 112 | } |
113 | -add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 ); |
|
113 | +add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10); |
|
114 | 114 | |
115 | 115 | function wpinv_discount_filters() { |
116 | 116 | |
117 | 117 | ?> |
118 | 118 | <select name="discount_type" id="dropdown_wpinv_discount_type"> |
119 | - <option value=""><?php esc_html_e( 'Show all types', 'invoicing' ); ?></option> |
|
119 | + <option value=""><?php esc_html_e('Show all types', 'invoicing'); ?></option> |
|
120 | 120 | <?php |
121 | 121 | $types = wpinv_get_discount_types(); |
122 | 122 | |
123 | - foreach ( $types as $name => $type ) { |
|
124 | - echo '<option value="' . esc_attr( $name ) . '"'; |
|
123 | + foreach ($types as $name => $type) { |
|
124 | + echo '<option value="' . esc_attr($name) . '"'; |
|
125 | 125 | |
126 | - if ( isset( $_GET['discount_type'] ) ) { |
|
127 | - selected( $name, sanitize_text_field( $_GET['discount_type'] ) ); |
|
126 | + if (isset($_GET['discount_type'])) { |
|
127 | + selected($name, sanitize_text_field($_GET['discount_type'])); |
|
128 | 128 | } |
129 | 129 | |
130 | - echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
130 | + echo '>' . esc_html__($type, 'invoicing') . '</option>'; |
|
131 | 131 | } |
132 | 132 | ?> |
133 | 133 | </select> |
134 | 134 | <?php |
135 | 135 | } |
136 | 136 | |
137 | -function wpinv_request( $vars ) { |
|
137 | +function wpinv_request($vars) { |
|
138 | 138 | global $typenow, $wp_post_statuses; |
139 | 139 | |
140 | - if ( getpaid_is_invoice_post_type( $typenow ) ) { |
|
141 | - if ( ! isset( $vars['post_status'] ) ) { |
|
142 | - $post_statuses = wpinv_get_invoice_statuses( false, false, $typenow ); |
|
140 | + if (getpaid_is_invoice_post_type($typenow)) { |
|
141 | + if (!isset($vars['post_status'])) { |
|
142 | + $post_statuses = wpinv_get_invoice_statuses(false, false, $typenow); |
|
143 | 143 | |
144 | - foreach ( $post_statuses as $status => $value ) { |
|
145 | - if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) { |
|
146 | - unset( $post_statuses[ $status ] ); |
|
144 | + foreach ($post_statuses as $status => $value) { |
|
145 | + if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) { |
|
146 | + unset($post_statuses[$status]); |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 | |
150 | - $vars['post_status'] = array_keys( $post_statuses ); |
|
150 | + $vars['post_status'] = array_keys($post_statuses); |
|
151 | 151 | } |
152 | -} elseif ( 'wpi_discount' == $typenow ) { |
|
153 | - $meta_query = ! empty( $vars['meta_query'] ) ? $vars['meta_query'] : array(); |
|
152 | +} elseif ('wpi_discount' == $typenow) { |
|
153 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array(); |
|
154 | 154 | // Filter vat rule type |
155 | - if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) { |
|
155 | + if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') { |
|
156 | 156 | $meta_query[] = array( |
157 | 157 | 'key' => '_wpi_discount_type', |
158 | - 'value' => sanitize_key( urldecode( $_GET['discount_type'] ) ), |
|
158 | + 'value' => sanitize_key(urldecode($_GET['discount_type'])), |
|
159 | 159 | 'compare' => '=', |
160 | 160 | ); |
161 | 161 | } |
162 | 162 | |
163 | - if ( ! empty( $meta_query ) ) { |
|
163 | + if (!empty($meta_query)) { |
|
164 | 164 | $vars['meta_query'] = $meta_query; |
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
168 | 168 | return $vars; |
169 | 169 | } |
170 | -add_filter( 'request', 'wpinv_request' ); |
|
170 | +add_filter('request', 'wpinv_request'); |
|
171 | 171 | |
172 | 172 | /** |
173 | 173 | * Create a page and store the ID in an option. |
@@ -179,61 +179,61 @@ discard block |
||
179 | 179 | * @param int $post_parent (default: 0) Parent for the new page |
180 | 180 | * @return int page ID |
181 | 181 | */ |
182 | -function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) { |
|
182 | +function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) { |
|
183 | 183 | global $wpdb; |
184 | 184 | |
185 | - $option_value = wpinv_get_option( $option ); |
|
185 | + $option_value = wpinv_get_option($option); |
|
186 | 186 | |
187 | - if ( ! empty( $option_value ) && ( $page_object = get_post( $option_value ) ) ) { |
|
188 | - if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) { |
|
187 | + if (!empty($option_value) && ($page_object = get_post($option_value))) { |
|
188 | + if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) { |
|
189 | 189 | // Valid page is already in place |
190 | 190 | return $page_object->ID; |
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
194 | - if ( ! empty( $post_parent ) ) { |
|
195 | - $page = get_page_by_path( $post_parent ); |
|
196 | - if ( $page ) { |
|
194 | + if (!empty($post_parent)) { |
|
195 | + $page = get_page_by_path($post_parent); |
|
196 | + if ($page) { |
|
197 | 197 | $post_parent = $page->ID; |
198 | 198 | } else { |
199 | 199 | $post_parent = ''; |
200 | 200 | } |
201 | 201 | } |
202 | 202 | |
203 | - if ( strlen( $page_content ) > 0 ) { |
|
203 | + if (strlen($page_content) > 0) { |
|
204 | 204 | // Search for an existing page with the specified page content (typically a shortcode) |
205 | - $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); |
|
205 | + $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
|
206 | 206 | } else { |
207 | 207 | // Search for an existing page with the specified page slug |
208 | - $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug ) ); |
|
208 | + $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug)); |
|
209 | 209 | } |
210 | 210 | |
211 | - $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content ); |
|
211 | + $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content); |
|
212 | 212 | |
213 | - if ( $valid_page_found ) { |
|
214 | - if ( $option ) { |
|
215 | - wpinv_update_option( $option, $valid_page_found ); |
|
213 | + if ($valid_page_found) { |
|
214 | + if ($option) { |
|
215 | + wpinv_update_option($option, $valid_page_found); |
|
216 | 216 | } |
217 | 217 | return $valid_page_found; |
218 | 218 | } |
219 | 219 | |
220 | 220 | // Search for a matching valid trashed page |
221 | - if ( strlen( $page_content ) > 0 ) { |
|
221 | + if (strlen($page_content) > 0) { |
|
222 | 222 | // Search for an existing page with the specified page content (typically a shortcode) |
223 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); |
|
223 | + $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
|
224 | 224 | } else { |
225 | 225 | // Search for an existing page with the specified page slug |
226 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) ); |
|
226 | + $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug)); |
|
227 | 227 | } |
228 | 228 | |
229 | - if ( $trashed_page_found ) { |
|
229 | + if ($trashed_page_found) { |
|
230 | 230 | $page_id = $trashed_page_found; |
231 | 231 | $page_data = array( |
232 | 232 | 'ID' => $page_id, |
233 | 233 | 'post_status' => 'publish', |
234 | 234 | 'post_parent' => $post_parent, |
235 | 235 | ); |
236 | - wp_update_post( $page_data ); |
|
236 | + wp_update_post($page_data); |
|
237 | 237 | } else { |
238 | 238 | $page_data = array( |
239 | 239 | 'post_status' => 'publish', |
@@ -245,11 +245,11 @@ discard block |
||
245 | 245 | 'post_parent' => $post_parent, |
246 | 246 | 'comment_status' => 'closed', |
247 | 247 | ); |
248 | - $page_id = wp_insert_post( $page_data ); |
|
248 | + $page_id = wp_insert_post($page_data); |
|
249 | 249 | } |
250 | 250 | |
251 | - if ( $option ) { |
|
252 | - wpinv_update_option( $option, (int) $page_id ); |
|
251 | + if ($option) { |
|
252 | + wpinv_update_option($option, (int) $page_id); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | return $page_id; |
@@ -262,11 +262,11 @@ discard block |
||
262 | 262 | * |
263 | 263 | * @return array |
264 | 264 | */ |
265 | -function wpinv_add_aui_screens( $screen_ids ) { |
|
265 | +function wpinv_add_aui_screens($screen_ids) { |
|
266 | 266 | |
267 | 267 | // load on these pages if set |
268 | - $screen_ids = array_merge( $screen_ids, wpinv_get_screen_ids() ); |
|
268 | + $screen_ids = array_merge($screen_ids, wpinv_get_screen_ids()); |
|
269 | 269 | |
270 | 270 | return $screen_ids; |
271 | 271 | } |
272 | -add_filter( 'aui_screen_ids', 'wpinv_add_aui_screens' ); |
|
272 | +add_filter('aui_screen_ids', 'wpinv_add_aui_screens'); |