@@ -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,55 +10,55 @@ discard block |
||
10 | 10 | class GetPaid_Payment_Form extends GetPaid_Data { |
11 | 11 | |
12 | 12 | /** |
13 | - * Which data store to load. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
13 | + * Which data store to load. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | 17 | protected $data_store_name = 'payment_form'; |
18 | 18 | |
19 | 19 | /** |
20 | - * This is the name of this object type. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $object_type = 'payment_form'; |
|
20 | + * This is the name of this object type. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $object_type = 'payment_form'; |
|
25 | 25 | |
26 | 26 | /** |
27 | - * Form Data array. This is the core form data exposed in APIs. |
|
28 | - * |
|
29 | - * @since 1.0.19 |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $data = array( |
|
33 | - 'status' => 'draft', |
|
34 | - 'version' => '', |
|
35 | - 'date_created' => null, |
|
27 | + * Form Data array. This is the core form data exposed in APIs. |
|
28 | + * |
|
29 | + * @since 1.0.19 |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $data = array( |
|
33 | + 'status' => 'draft', |
|
34 | + 'version' => '', |
|
35 | + 'date_created' => null, |
|
36 | 36 | 'date_modified' => null, |
37 | 37 | 'name' => '', |
38 | 38 | 'author' => 1, |
39 | 39 | 'elements' => null, |
40 | - 'items' => null, |
|
41 | - 'earned' => 0, |
|
42 | - 'refunded' => 0, |
|
43 | - 'cancelled' => 0, |
|
44 | - 'failed' => 0, |
|
45 | - ); |
|
46 | - |
|
47 | - /** |
|
48 | - * Stores meta in cache for future reads. |
|
49 | - * |
|
50 | - * A group must be set to to enable caching. |
|
51 | - * |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - protected $cache_group = 'getpaid_forms'; |
|
55 | - |
|
56 | - /** |
|
57 | - * Stores a reference to the invoice if the form is for an invoice.. |
|
58 | - * |
|
59 | - * @var WPInv_Invoice |
|
60 | - */ |
|
61 | - public $invoice = 0; |
|
40 | + 'items' => null, |
|
41 | + 'earned' => 0, |
|
42 | + 'refunded' => 0, |
|
43 | + 'cancelled' => 0, |
|
44 | + 'failed' => 0, |
|
45 | + ); |
|
46 | + |
|
47 | + /** |
|
48 | + * Stores meta in cache for future reads. |
|
49 | + * |
|
50 | + * A group must be set to to enable caching. |
|
51 | + * |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + protected $cache_group = 'getpaid_forms'; |
|
55 | + |
|
56 | + /** |
|
57 | + * Stores a reference to the invoice if the form is for an invoice.. |
|
58 | + * |
|
59 | + * @var WPInv_Invoice |
|
60 | + */ |
|
61 | + public $invoice = 0; |
|
62 | 62 | |
63 | 63 | /** |
64 | 64 | * Stores a reference to the original WP_Post object |
@@ -68,35 +68,35 @@ discard block |
||
68 | 68 | protected $post = null; |
69 | 69 | |
70 | 70 | /** |
71 | - * Get the form if ID is passed, otherwise the form is new and empty. |
|
72 | - * |
|
73 | - * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
74 | - */ |
|
75 | - public function __construct( $form = 0 ) { |
|
76 | - parent::__construct( $form ); |
|
71 | + * Get the form if ID is passed, otherwise the form is new and empty. |
|
72 | + * |
|
73 | + * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
74 | + */ |
|
75 | + public function __construct( $form = 0 ) { |
|
76 | + parent::__construct( $form ); |
|
77 | 77 | |
78 | - if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | - $this->set_id( $form ); |
|
80 | - } elseif ( $form instanceof self ) { |
|
78 | + if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | + $this->set_id( $form ); |
|
80 | + } elseif ( $form instanceof self ) { |
|
81 | 81 | |
82 | - $this->set_id( $form->get_id() ); |
|
83 | - $this->invoice = $form->invoice; |
|
82 | + $this->set_id( $form->get_id() ); |
|
83 | + $this->invoice = $form->invoice; |
|
84 | 84 | |
85 | - } elseif ( ! empty( $form->ID ) ) { |
|
86 | - $this->set_id( $form->ID ); |
|
87 | - } else { |
|
88 | - $this->set_object_read( true ); |
|
89 | - } |
|
85 | + } elseif ( ! empty( $form->ID ) ) { |
|
86 | + $this->set_id( $form->ID ); |
|
87 | + } else { |
|
88 | + $this->set_object_read( true ); |
|
89 | + } |
|
90 | 90 | |
91 | 91 | // Load the datastore. |
92 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
92 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
93 | 93 | |
94 | - if ( $this->get_id() > 0 ) { |
|
94 | + if ( $this->get_id() > 0 ) { |
|
95 | 95 | $this->post = get_post( $this->get_id() ); |
96 | - $this->data_store->read( $this ); |
|
96 | + $this->data_store->read( $this ); |
|
97 | 97 | } |
98 | 98 | |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | 101 | /* |
102 | 102 | |-------------------------------------------------------------------------- |
@@ -114,358 +114,358 @@ discard block |
||
114 | 114 | */ |
115 | 115 | |
116 | 116 | /** |
117 | - * Get plugin version when the form was created. |
|
118 | - * |
|
119 | - * @since 1.0.19 |
|
120 | - * @param string $context View or edit context. |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function get_version( $context = 'view' ) { |
|
124 | - return $this->get_prop( 'version', $context ); |
|
117 | + * Get plugin version when the form was created. |
|
118 | + * |
|
119 | + * @since 1.0.19 |
|
120 | + * @param string $context View or edit context. |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function get_version( $context = 'view' ) { |
|
124 | + return $this->get_prop( 'version', $context ); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | - * Get date when the form was created. |
|
129 | - * |
|
130 | - * @since 1.0.19 |
|
131 | - * @param string $context View or edit context. |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - public function get_date_created( $context = 'view' ) { |
|
135 | - return $this->get_prop( 'date_created', $context ); |
|
128 | + * Get date when the form was created. |
|
129 | + * |
|
130 | + * @since 1.0.19 |
|
131 | + * @param string $context View or edit context. |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + public function get_date_created( $context = 'view' ) { |
|
135 | + return $this->get_prop( 'date_created', $context ); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | - * Get GMT date when the form was created. |
|
140 | - * |
|
141 | - * @since 1.0.19 |
|
142 | - * @param string $context View or edit context. |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - public function get_date_created_gmt( $context = 'view' ) { |
|
139 | + * Get GMT date when the form was created. |
|
140 | + * |
|
141 | + * @since 1.0.19 |
|
142 | + * @param string $context View or edit context. |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + public function get_date_created_gmt( $context = 'view' ) { |
|
146 | 146 | $date = $this->get_date_created( $context ); |
147 | 147 | |
148 | 148 | if ( $date ) { |
149 | 149 | $date = get_gmt_from_date( $date ); |
150 | 150 | } |
151 | - return $date; |
|
151 | + return $date; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
155 | - * Get date when the form was last modified. |
|
156 | - * |
|
157 | - * @since 1.0.19 |
|
158 | - * @param string $context View or edit context. |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - public function get_date_modified( $context = 'view' ) { |
|
162 | - return $this->get_prop( 'date_modified', $context ); |
|
155 | + * Get date when the form was last modified. |
|
156 | + * |
|
157 | + * @since 1.0.19 |
|
158 | + * @param string $context View or edit context. |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + public function get_date_modified( $context = 'view' ) { |
|
162 | + return $this->get_prop( 'date_modified', $context ); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
166 | - * Get GMT date when the form was last modified. |
|
167 | - * |
|
168 | - * @since 1.0.19 |
|
169 | - * @param string $context View or edit context. |
|
170 | - * @return string |
|
171 | - */ |
|
172 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
166 | + * Get GMT date when the form was last modified. |
|
167 | + * |
|
168 | + * @since 1.0.19 |
|
169 | + * @param string $context View or edit context. |
|
170 | + * @return string |
|
171 | + */ |
|
172 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
173 | 173 | $date = $this->get_date_modified( $context ); |
174 | 174 | |
175 | 175 | if ( $date ) { |
176 | 176 | $date = get_gmt_from_date( $date ); |
177 | 177 | } |
178 | - return $date; |
|
178 | + return $date; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
182 | - * Get the form name. |
|
183 | - * |
|
184 | - * @since 1.0.19 |
|
185 | - * @param string $context View or edit context. |
|
186 | - * @return string |
|
187 | - */ |
|
188 | - public function get_name( $context = 'view' ) { |
|
189 | - return $this->get_prop( 'name', $context ); |
|
182 | + * Get the form name. |
|
183 | + * |
|
184 | + * @since 1.0.19 |
|
185 | + * @param string $context View or edit context. |
|
186 | + * @return string |
|
187 | + */ |
|
188 | + public function get_name( $context = 'view' ) { |
|
189 | + return $this->get_prop( 'name', $context ); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
193 | - * Alias of self::get_name(). |
|
194 | - * |
|
195 | - * @since 1.0.19 |
|
196 | - * @param string $context View or edit context. |
|
197 | - * @return string |
|
198 | - */ |
|
199 | - public function get_title( $context = 'view' ) { |
|
200 | - return $this->get_name( $context ); |
|
201 | - } |
|
193 | + * Alias of self::get_name(). |
|
194 | + * |
|
195 | + * @since 1.0.19 |
|
196 | + * @param string $context View or edit context. |
|
197 | + * @return string |
|
198 | + */ |
|
199 | + public function get_title( $context = 'view' ) { |
|
200 | + return $this->get_name( $context ); |
|
201 | + } |
|
202 | 202 | |
203 | 203 | /** |
204 | - * Get the owner of the form. |
|
205 | - * |
|
206 | - * @since 1.0.19 |
|
207 | - * @param string $context View or edit context. |
|
208 | - * @return int |
|
209 | - */ |
|
210 | - public function get_author( $context = 'view' ) { |
|
211 | - return (int) $this->get_prop( 'author', $context ); |
|
204 | + * Get the owner of the form. |
|
205 | + * |
|
206 | + * @since 1.0.19 |
|
207 | + * @param string $context View or edit context. |
|
208 | + * @return int |
|
209 | + */ |
|
210 | + public function get_author( $context = 'view' ) { |
|
211 | + return (int) $this->get_prop( 'author', $context ); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
215 | - * Get the elements that make up the form. |
|
216 | - * |
|
217 | - * @since 1.0.19 |
|
218 | - * @param string $context View or edit context. |
|
219 | - * @return array |
|
220 | - */ |
|
221 | - public function get_elements( $context = 'view' ) { |
|
222 | - $elements = $this->get_prop( 'elements', $context ); |
|
215 | + * Get the elements that make up the form. |
|
216 | + * |
|
217 | + * @since 1.0.19 |
|
218 | + * @param string $context View or edit context. |
|
219 | + * @return array |
|
220 | + */ |
|
221 | + public function get_elements( $context = 'view' ) { |
|
222 | + $elements = $this->get_prop( 'elements', $context ); |
|
223 | 223 | |
224 | - if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
224 | + if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
225 | 225 | return wpinv_get_data( 'sample-payment-form' ); |
226 | - } |
|
226 | + } |
|
227 | 227 | |
228 | - // Ensure that all required elements exist. |
|
229 | - $_elements = array(); |
|
230 | - foreach ( $elements as $element ) { |
|
228 | + // Ensure that all required elements exist. |
|
229 | + $_elements = array(); |
|
230 | + foreach ( $elements as $element ) { |
|
231 | 231 | |
232 | - if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
232 | + if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
233 | 233 | |
234 | - $_elements[] = array( |
|
235 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
236 | - 'id' => 'gtscicd', |
|
237 | - 'name' => 'gtscicd', |
|
238 | - 'type' => 'gateway_select', |
|
239 | - 'premade' => true |
|
234 | + $_elements[] = array( |
|
235 | + 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
236 | + 'id' => 'gtscicd', |
|
237 | + 'name' => 'gtscicd', |
|
238 | + 'type' => 'gateway_select', |
|
239 | + 'premade' => true |
|
240 | 240 | |
241 | - ); |
|
241 | + ); |
|
242 | 242 | |
243 | - } |
|
243 | + } |
|
244 | 244 | |
245 | - $_elements[] = $element; |
|
245 | + $_elements[] = $element; |
|
246 | 246 | |
247 | - } |
|
247 | + } |
|
248 | 248 | |
249 | 249 | return $_elements; |
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * Get the items sold via the form. |
|
254 | - * |
|
255 | - * @since 1.0.19 |
|
256 | - * @param string $context View or edit context. |
|
257 | - * @param string $return objects or arrays. |
|
258 | - * @return GetPaid_Form_Item[] |
|
259 | - */ |
|
260 | - public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | - $items = $this->get_prop( 'items', $context ); |
|
262 | - |
|
263 | - if ( empty( $items ) || ! is_array( $items ) ) { |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * Get the items sold via the form. |
|
254 | + * |
|
255 | + * @since 1.0.19 |
|
256 | + * @param string $context View or edit context. |
|
257 | + * @param string $return objects or arrays. |
|
258 | + * @return GetPaid_Form_Item[] |
|
259 | + */ |
|
260 | + public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | + $items = $this->get_prop( 'items', $context ); |
|
262 | + |
|
263 | + if ( empty( $items ) || ! is_array( $items ) ) { |
|
264 | 264 | $items = wpinv_get_data( 'sample-payment-form-items' ); |
265 | - } |
|
265 | + } |
|
266 | + |
|
267 | + // Convert the items. |
|
268 | + $prepared = array(); |
|
266 | 269 | |
267 | - // Convert the items. |
|
268 | - $prepared = array(); |
|
270 | + foreach ( $items as $key => $value ) { |
|
269 | 271 | |
270 | - foreach ( $items as $key => $value ) { |
|
272 | + // Form items. |
|
273 | + if ( $value instanceof GetPaid_Form_Item ) { |
|
271 | 274 | |
272 | - // Form items. |
|
273 | - if ( $value instanceof GetPaid_Form_Item ) { |
|
275 | + if ( $value->can_purchase() ) { |
|
276 | + $prepared[] = $value; |
|
277 | + } |
|
274 | 278 | |
275 | - if ( $value->can_purchase() ) { |
|
276 | - $prepared[] = $value; |
|
277 | - } |
|
279 | + continue; |
|
278 | 280 | |
279 | - continue; |
|
281 | + } |
|
280 | 282 | |
281 | - } |
|
283 | + // $item_id => $quantity (buy buttons) |
|
284 | + if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | + $item = new GetPaid_Form_Item( $key ); |
|
282 | 286 | |
283 | - // $item_id => $quantity (buy buttons) |
|
284 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | - $item = new GetPaid_Form_Item( $key ); |
|
287 | + if ( $item->can_purchase() ) { |
|
286 | 288 | |
287 | - if ( $item->can_purchase() ) { |
|
289 | + $value = (int) $value; |
|
290 | + $item->set_quantity( $value ); |
|
291 | + if ( 0 == $value ) { |
|
292 | + $item->set_quantity( 1 ); |
|
293 | + $item->set_allow_quantities( true ); |
|
294 | + } |
|
288 | 295 | |
289 | - $value = (int) $value; |
|
290 | - $item->set_quantity( $value ); |
|
291 | - if ( 0 == $value ) { |
|
292 | - $item->set_quantity( 1 ); |
|
293 | - $item->set_allow_quantities( true ); |
|
294 | - } |
|
296 | + $prepared[] = $item; |
|
297 | + } |
|
295 | 298 | |
296 | - $prepared[] = $item; |
|
297 | - } |
|
299 | + continue; |
|
300 | + } |
|
298 | 301 | |
299 | - continue; |
|
300 | - } |
|
302 | + // Items saved via payment forms editor. |
|
303 | + if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
301 | 304 | |
302 | - // Items saved via payment forms editor. |
|
303 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
305 | + $item = new GetPaid_Form_Item( $value['id'] ); |
|
304 | 306 | |
305 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
307 | + if ( ! $item->can_purchase() ) { |
|
308 | + continue; |
|
309 | + } |
|
306 | 310 | |
307 | - if ( ! $item->can_purchase() ) { |
|
308 | - continue; |
|
309 | - } |
|
311 | + // Sub-total (Cart items). |
|
312 | + if ( isset( $value['subtotal'] ) ) { |
|
313 | + $item->set_price( $value['subtotal'] ); |
|
314 | + } |
|
310 | 315 | |
311 | - // Sub-total (Cart items). |
|
312 | - if ( isset( $value['subtotal'] ) ) { |
|
313 | - $item->set_price( $value['subtotal'] ); |
|
314 | - } |
|
316 | + if ( isset( $value['quantity'] ) ) { |
|
317 | + $item->set_quantity( $value['quantity'] ); |
|
318 | + } |
|
315 | 319 | |
316 | - if ( isset( $value['quantity'] ) ) { |
|
317 | - $item->set_quantity( $value['quantity'] ); |
|
318 | - } |
|
320 | + if ( isset( $value['allow_quantities'] ) ) { |
|
321 | + $item->set_allow_quantities( $value['allow_quantities'] ); |
|
322 | + } |
|
319 | 323 | |
320 | - if ( isset( $value['allow_quantities'] ) ) { |
|
321 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
322 | - } |
|
324 | + if ( isset( $value['required'] ) ) { |
|
325 | + $item->set_is_required( $value['required'] ); |
|
326 | + } |
|
323 | 327 | |
324 | - if ( isset( $value['required'] ) ) { |
|
325 | - $item->set_is_required( $value['required'] ); |
|
326 | - } |
|
328 | + if ( isset( $value['description'] ) ) { |
|
329 | + $item->set_custom_description( $value['description'] ); |
|
330 | + } |
|
327 | 331 | |
328 | - if ( isset( $value['description'] ) ) { |
|
329 | - $item->set_custom_description( $value['description'] ); |
|
330 | - } |
|
332 | + $prepared[] = $item; |
|
333 | + continue; |
|
331 | 334 | |
332 | - $prepared[] = $item; |
|
333 | - continue; |
|
335 | + } |
|
336 | + |
|
337 | + // $item_id => array( 'price' => 10 ) (item variations) |
|
338 | + if ( is_numeric( $key ) && is_array( $value ) ) { |
|
339 | + $item = new GetPaid_Form_Item( $key ); |
|
340 | + |
|
341 | + if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
342 | + $item->set_price( $value['price'] ); |
|
343 | + } |
|
344 | + |
|
345 | + if ( $item->can_purchase() ) { |
|
346 | + $prepared[] = $item; |
|
347 | + } |
|
348 | + |
|
349 | + continue; |
|
350 | + } |
|
351 | + |
|
352 | + } |
|
353 | + |
|
354 | + if ( 'objects' == $return && 'view' == $context ) { |
|
355 | + return $prepared; |
|
356 | + } |
|
357 | + |
|
358 | + $items = array(); |
|
359 | + foreach ( $prepared as $item ) { |
|
360 | + $items[] = $item->prepare_data_for_use(); |
|
361 | + } |
|
362 | + |
|
363 | + return $items; |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Get a single item belonging to the form. |
|
368 | + * |
|
369 | + * @since 1.0.19 |
|
370 | + * @param int $item_id The item id to return. |
|
371 | + * @return GetPaid_Form_Item|bool |
|
372 | + */ |
|
373 | + public function get_item( $item_id ) { |
|
374 | + |
|
375 | + if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
376 | + return false; |
|
377 | + } |
|
378 | + |
|
379 | + foreach( $this->get_items() as $item ) { |
|
380 | + if ( $item->get_id() == (int) $item_id ) { |
|
381 | + return $item; |
|
382 | + } |
|
383 | + } |
|
384 | + |
|
385 | + return false; |
|
386 | + |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Gets a single element. |
|
391 | + * |
|
392 | + * @since 1.0.19 |
|
393 | + * @param string $element_type The element type to return. |
|
394 | + * @return array|bool |
|
395 | + */ |
|
396 | + public function get_element_type( $element_type ) { |
|
397 | + |
|
398 | + if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
399 | + return false; |
|
400 | + } |
|
401 | + |
|
402 | + foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
403 | + |
|
404 | + if ( $element['type'] == $element_type ) { |
|
405 | + return $element; |
|
406 | + } |
|
407 | + |
|
408 | + } |
|
409 | + |
|
410 | + return false; |
|
411 | + |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | + * Get the total amount earned via this form. |
|
416 | + * |
|
417 | + * @since 1.0.19 |
|
418 | + * @param string $context View or edit context. |
|
419 | + * @return array |
|
420 | + */ |
|
421 | + public function get_earned( $context = 'view' ) { |
|
422 | + return $this->get_prop( 'earned', $context ); |
|
423 | + } |
|
424 | + |
|
425 | + /** |
|
426 | + * Get the total amount refunded via this form. |
|
427 | + * |
|
428 | + * @since 1.0.19 |
|
429 | + * @param string $context View or edit context. |
|
430 | + * @return array |
|
431 | + */ |
|
432 | + public function get_refunded( $context = 'view' ) { |
|
433 | + return $this->get_prop( 'refunded', $context ); |
|
434 | + } |
|
334 | 435 | |
335 | - } |
|
436 | + /** |
|
437 | + * Get the total amount cancelled via this form. |
|
438 | + * |
|
439 | + * @since 1.0.19 |
|
440 | + * @param string $context View or edit context. |
|
441 | + * @return array |
|
442 | + */ |
|
443 | + public function get_cancelled( $context = 'view' ) { |
|
444 | + return $this->get_prop( 'cancelled', $context ); |
|
445 | + } |
|
336 | 446 | |
337 | - // $item_id => array( 'price' => 10 ) (item variations) |
|
338 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
339 | - $item = new GetPaid_Form_Item( $key ); |
|
447 | + /** |
|
448 | + * Get the total amount failed via this form. |
|
449 | + * |
|
450 | + * @since 1.0.19 |
|
451 | + * @param string $context View or edit context. |
|
452 | + * @return array |
|
453 | + */ |
|
454 | + public function get_failed( $context = 'view' ) { |
|
455 | + return $this->get_prop( 'failed', $context ); |
|
456 | + } |
|
340 | 457 | |
341 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
342 | - $item->set_price( $value['price'] ); |
|
343 | - } |
|
344 | - |
|
345 | - if ( $item->can_purchase() ) { |
|
346 | - $prepared[] = $item; |
|
347 | - } |
|
348 | - |
|
349 | - continue; |
|
350 | - } |
|
351 | - |
|
352 | - } |
|
353 | - |
|
354 | - if ( 'objects' == $return && 'view' == $context ) { |
|
355 | - return $prepared; |
|
356 | - } |
|
357 | - |
|
358 | - $items = array(); |
|
359 | - foreach ( $prepared as $item ) { |
|
360 | - $items[] = $item->prepare_data_for_use(); |
|
361 | - } |
|
362 | - |
|
363 | - return $items; |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Get a single item belonging to the form. |
|
368 | - * |
|
369 | - * @since 1.0.19 |
|
370 | - * @param int $item_id The item id to return. |
|
371 | - * @return GetPaid_Form_Item|bool |
|
372 | - */ |
|
373 | - public function get_item( $item_id ) { |
|
374 | - |
|
375 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
376 | - return false; |
|
377 | - } |
|
378 | - |
|
379 | - foreach( $this->get_items() as $item ) { |
|
380 | - if ( $item->get_id() == (int) $item_id ) { |
|
381 | - return $item; |
|
382 | - } |
|
383 | - } |
|
384 | - |
|
385 | - return false; |
|
386 | - |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Gets a single element. |
|
391 | - * |
|
392 | - * @since 1.0.19 |
|
393 | - * @param string $element_type The element type to return. |
|
394 | - * @return array|bool |
|
395 | - */ |
|
396 | - public function get_element_type( $element_type ) { |
|
397 | - |
|
398 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
399 | - return false; |
|
400 | - } |
|
401 | - |
|
402 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
403 | - |
|
404 | - if ( $element['type'] == $element_type ) { |
|
405 | - return $element; |
|
406 | - } |
|
407 | - |
|
408 | - } |
|
409 | - |
|
410 | - return false; |
|
411 | - |
|
412 | - } |
|
413 | - |
|
414 | - /** |
|
415 | - * Get the total amount earned via this form. |
|
416 | - * |
|
417 | - * @since 1.0.19 |
|
418 | - * @param string $context View or edit context. |
|
419 | - * @return array |
|
420 | - */ |
|
421 | - public function get_earned( $context = 'view' ) { |
|
422 | - return $this->get_prop( 'earned', $context ); |
|
423 | - } |
|
424 | - |
|
425 | - /** |
|
426 | - * Get the total amount refunded via this form. |
|
427 | - * |
|
428 | - * @since 1.0.19 |
|
429 | - * @param string $context View or edit context. |
|
430 | - * @return array |
|
431 | - */ |
|
432 | - public function get_refunded( $context = 'view' ) { |
|
433 | - return $this->get_prop( 'refunded', $context ); |
|
434 | - } |
|
435 | - |
|
436 | - /** |
|
437 | - * Get the total amount cancelled via this form. |
|
438 | - * |
|
439 | - * @since 1.0.19 |
|
440 | - * @param string $context View or edit context. |
|
441 | - * @return array |
|
442 | - */ |
|
443 | - public function get_cancelled( $context = 'view' ) { |
|
444 | - return $this->get_prop( 'cancelled', $context ); |
|
445 | - } |
|
446 | - |
|
447 | - /** |
|
448 | - * Get the total amount failed via this form. |
|
449 | - * |
|
450 | - * @since 1.0.19 |
|
451 | - * @param string $context View or edit context. |
|
452 | - * @return array |
|
453 | - */ |
|
454 | - public function get_failed( $context = 'view' ) { |
|
455 | - return $this->get_prop( 'failed', $context ); |
|
456 | - } |
|
457 | - |
|
458 | - /** |
|
459 | - * Get the currency. |
|
460 | - * |
|
461 | - * @since 1.0.19 |
|
462 | - * @param string $context View or edit context. |
|
463 | - * @return string |
|
464 | - */ |
|
465 | - public function get_currency() { |
|
466 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
467 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
468 | - } |
|
458 | + /** |
|
459 | + * Get the currency. |
|
460 | + * |
|
461 | + * @since 1.0.19 |
|
462 | + * @param string $context View or edit context. |
|
463 | + * @return string |
|
464 | + */ |
|
465 | + public function get_currency() { |
|
466 | + $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
467 | + return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
468 | + } |
|
469 | 469 | |
470 | 470 | /* |
471 | 471 | |-------------------------------------------------------------------------- |
@@ -478,22 +478,22 @@ discard block |
||
478 | 478 | */ |
479 | 479 | |
480 | 480 | /** |
481 | - * Set plugin version when the item was created. |
|
482 | - * |
|
483 | - * @since 1.0.19 |
|
484 | - */ |
|
485 | - public function set_version( $value ) { |
|
486 | - $this->set_prop( 'version', $value ); |
|
481 | + * Set plugin version when the item was created. |
|
482 | + * |
|
483 | + * @since 1.0.19 |
|
484 | + */ |
|
485 | + public function set_version( $value ) { |
|
486 | + $this->set_prop( 'version', $value ); |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | /** |
490 | - * Set date when the item was created. |
|
491 | - * |
|
492 | - * @since 1.0.19 |
|
493 | - * @param string $value Value to set. |
|
490 | + * Set date when the item was created. |
|
491 | + * |
|
492 | + * @since 1.0.19 |
|
493 | + * @param string $value Value to set. |
|
494 | 494 | * @return bool Whether or not the date was set. |
495 | - */ |
|
496 | - public function set_date_created( $value ) { |
|
495 | + */ |
|
496 | + public function set_date_created( $value ) { |
|
497 | 497 | $date = strtotime( $value ); |
498 | 498 | |
499 | 499 | if ( $date ) { |
@@ -506,13 +506,13 @@ discard block |
||
506 | 506 | } |
507 | 507 | |
508 | 508 | /** |
509 | - * Set date when the item was last modified. |
|
510 | - * |
|
511 | - * @since 1.0.19 |
|
512 | - * @param string $value Value to set. |
|
509 | + * Set date when the item was last modified. |
|
510 | + * |
|
511 | + * @since 1.0.19 |
|
512 | + * @param string $value Value to set. |
|
513 | 513 | * @return bool Whether or not the date was set. |
514 | - */ |
|
515 | - public function set_date_modified( $value ) { |
|
514 | + */ |
|
515 | + public function set_date_modified( $value ) { |
|
516 | 516 | $date = strtotime( $value ); |
517 | 517 | |
518 | 518 | if ( $date ) { |
@@ -525,118 +525,118 @@ discard block |
||
525 | 525 | } |
526 | 526 | |
527 | 527 | /** |
528 | - * Set the item name. |
|
529 | - * |
|
530 | - * @since 1.0.19 |
|
531 | - * @param string $value New name. |
|
532 | - */ |
|
533 | - public function set_name( $value ) { |
|
534 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
535 | - } |
|
536 | - |
|
537 | - /** |
|
538 | - * Alias of self::set_name(). |
|
539 | - * |
|
540 | - * @since 1.0.19 |
|
541 | - * @param string $value New name. |
|
542 | - */ |
|
543 | - public function set_title( $value ) { |
|
544 | - $this->set_name( $value ); |
|
545 | - } |
|
546 | - |
|
547 | - /** |
|
548 | - * Set the owner of the item. |
|
549 | - * |
|
550 | - * @since 1.0.19 |
|
551 | - * @param int $value New author. |
|
552 | - */ |
|
553 | - public function set_author( $value ) { |
|
554 | - $this->set_prop( 'author', (int) $value ); |
|
555 | - } |
|
556 | - |
|
557 | - /** |
|
558 | - * Set the form elements. |
|
559 | - * |
|
560 | - * @since 1.0.19 |
|
561 | - * @param array $value Form elements. |
|
562 | - */ |
|
563 | - public function set_elements( $value ) { |
|
564 | - if ( is_array( $value ) ) { |
|
565 | - $this->set_prop( 'elements', $value ); |
|
566 | - } |
|
567 | - } |
|
568 | - |
|
569 | - /** |
|
570 | - * Set the form items. |
|
571 | - * |
|
572 | - * @since 1.0.19 |
|
573 | - * @param array $value Form elements. |
|
574 | - */ |
|
575 | - public function set_items( $value ) { |
|
576 | - if ( is_array( $value ) ) { |
|
577 | - $this->set_prop( 'items', $value ); |
|
578 | - } |
|
579 | - } |
|
580 | - |
|
581 | - /** |
|
582 | - * Set the total amount earned via this form. |
|
583 | - * |
|
584 | - * @since 1.0.19 |
|
585 | - * @param float $value Amount earned. |
|
586 | - */ |
|
587 | - public function set_earned( $value ) { |
|
588 | - $value = max( (float) $value, 0 ); |
|
589 | - $this->set_prop( 'earned', $value ); |
|
590 | - } |
|
591 | - |
|
592 | - /** |
|
593 | - * Set the total amount refunded via this form. |
|
594 | - * |
|
595 | - * @since 1.0.19 |
|
596 | - * @param float $value Amount refunded. |
|
597 | - */ |
|
598 | - public function set_refunded( $value ) { |
|
599 | - $value = max( (float) $value, 0 ); |
|
600 | - $this->set_prop( 'refunded', $value ); |
|
601 | - } |
|
602 | - |
|
603 | - /** |
|
604 | - * Set the total amount cancelled via this form. |
|
605 | - * |
|
606 | - * @since 1.0.19 |
|
607 | - * @param float $value Amount cancelled. |
|
608 | - */ |
|
609 | - public function set_cancelled( $value ) { |
|
610 | - $value = max( (float) $value, 0 ); |
|
611 | - $this->set_prop( 'cancelled', $value ); |
|
612 | - } |
|
613 | - |
|
614 | - /** |
|
615 | - * Set the total amount failed via this form. |
|
616 | - * |
|
617 | - * @since 1.0.19 |
|
618 | - * @param float $value Amount cancelled. |
|
619 | - */ |
|
620 | - public function set_failed( $value ) { |
|
621 | - $value = max( (float) $value, 0 ); |
|
622 | - $this->set_prop( 'failed', $value ); |
|
623 | - } |
|
528 | + * Set the item name. |
|
529 | + * |
|
530 | + * @since 1.0.19 |
|
531 | + * @param string $value New name. |
|
532 | + */ |
|
533 | + public function set_name( $value ) { |
|
534 | + $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
535 | + } |
|
536 | + |
|
537 | + /** |
|
538 | + * Alias of self::set_name(). |
|
539 | + * |
|
540 | + * @since 1.0.19 |
|
541 | + * @param string $value New name. |
|
542 | + */ |
|
543 | + public function set_title( $value ) { |
|
544 | + $this->set_name( $value ); |
|
545 | + } |
|
546 | + |
|
547 | + /** |
|
548 | + * Set the owner of the item. |
|
549 | + * |
|
550 | + * @since 1.0.19 |
|
551 | + * @param int $value New author. |
|
552 | + */ |
|
553 | + public function set_author( $value ) { |
|
554 | + $this->set_prop( 'author', (int) $value ); |
|
555 | + } |
|
556 | + |
|
557 | + /** |
|
558 | + * Set the form elements. |
|
559 | + * |
|
560 | + * @since 1.0.19 |
|
561 | + * @param array $value Form elements. |
|
562 | + */ |
|
563 | + public function set_elements( $value ) { |
|
564 | + if ( is_array( $value ) ) { |
|
565 | + $this->set_prop( 'elements', $value ); |
|
566 | + } |
|
567 | + } |
|
568 | + |
|
569 | + /** |
|
570 | + * Set the form items. |
|
571 | + * |
|
572 | + * @since 1.0.19 |
|
573 | + * @param array $value Form elements. |
|
574 | + */ |
|
575 | + public function set_items( $value ) { |
|
576 | + if ( is_array( $value ) ) { |
|
577 | + $this->set_prop( 'items', $value ); |
|
578 | + } |
|
579 | + } |
|
580 | + |
|
581 | + /** |
|
582 | + * Set the total amount earned via this form. |
|
583 | + * |
|
584 | + * @since 1.0.19 |
|
585 | + * @param float $value Amount earned. |
|
586 | + */ |
|
587 | + public function set_earned( $value ) { |
|
588 | + $value = max( (float) $value, 0 ); |
|
589 | + $this->set_prop( 'earned', $value ); |
|
590 | + } |
|
591 | + |
|
592 | + /** |
|
593 | + * Set the total amount refunded via this form. |
|
594 | + * |
|
595 | + * @since 1.0.19 |
|
596 | + * @param float $value Amount refunded. |
|
597 | + */ |
|
598 | + public function set_refunded( $value ) { |
|
599 | + $value = max( (float) $value, 0 ); |
|
600 | + $this->set_prop( 'refunded', $value ); |
|
601 | + } |
|
602 | + |
|
603 | + /** |
|
604 | + * Set the total amount cancelled via this form. |
|
605 | + * |
|
606 | + * @since 1.0.19 |
|
607 | + * @param float $value Amount cancelled. |
|
608 | + */ |
|
609 | + public function set_cancelled( $value ) { |
|
610 | + $value = max( (float) $value, 0 ); |
|
611 | + $this->set_prop( 'cancelled', $value ); |
|
612 | + } |
|
613 | + |
|
614 | + /** |
|
615 | + * Set the total amount failed via this form. |
|
616 | + * |
|
617 | + * @since 1.0.19 |
|
618 | + * @param float $value Amount cancelled. |
|
619 | + */ |
|
620 | + public function set_failed( $value ) { |
|
621 | + $value = max( (float) $value, 0 ); |
|
622 | + $this->set_prop( 'failed', $value ); |
|
623 | + } |
|
624 | 624 | |
625 | 625 | /** |
626 | 626 | * Create an item. For backwards compatibilty. |
627 | 627 | * |
628 | 628 | * @deprecated |
629 | - * @return int item id |
|
629 | + * @return int item id |
|
630 | 630 | */ |
631 | 631 | public function create( $data = array() ) { |
632 | 632 | |
633 | - // Set the properties. |
|
634 | - if ( is_array( $data ) ) { |
|
635 | - $this->set_props( $data ); |
|
636 | - } |
|
633 | + // Set the properties. |
|
634 | + if ( is_array( $data ) ) { |
|
635 | + $this->set_props( $data ); |
|
636 | + } |
|
637 | 637 | |
638 | - // Save the item. |
|
639 | - return $this->save(); |
|
638 | + // Save the item. |
|
639 | + return $this->save(); |
|
640 | 640 | |
641 | 641 | } |
642 | 642 | |
@@ -644,7 +644,7 @@ discard block |
||
644 | 644 | * Updates an item. For backwards compatibilty. |
645 | 645 | * |
646 | 646 | * @deprecated |
647 | - * @return int item id |
|
647 | + * @return int item id |
|
648 | 648 | */ |
649 | 649 | public function update( $data = array() ) { |
650 | 650 | return $this->create( $data ); |
@@ -660,22 +660,22 @@ discard block |
||
660 | 660 | */ |
661 | 661 | |
662 | 662 | /** |
663 | - * Checks whether this is the default payment form. |
|
664 | - * |
|
665 | - * @since 1.0.19 |
|
666 | - * @return bool |
|
667 | - */ |
|
663 | + * Checks whether this is the default payment form. |
|
664 | + * |
|
665 | + * @since 1.0.19 |
|
666 | + * @return bool |
|
667 | + */ |
|
668 | 668 | public function is_default() { |
669 | 669 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
670 | 670 | return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
671 | - } |
|
671 | + } |
|
672 | 672 | |
673 | 673 | /** |
674 | - * Checks whether the form is active. |
|
675 | - * |
|
676 | - * @since 1.0.19 |
|
677 | - * @return bool |
|
678 | - */ |
|
674 | + * Checks whether the form is active. |
|
675 | + * |
|
676 | + * @since 1.0.19 |
|
677 | + * @return bool |
|
678 | + */ |
|
679 | 679 | public function is_active() { |
680 | 680 | $is_active = 0 !== (int) $this->get_id(); |
681 | 681 | |
@@ -684,76 +684,76 @@ discard block |
||
684 | 684 | } |
685 | 685 | |
686 | 686 | return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
687 | - } |
|
688 | - |
|
689 | - /** |
|
690 | - * Checks whether the form has a given item. |
|
691 | - * |
|
692 | - * @since 1.0.19 |
|
693 | - * @return bool |
|
694 | - */ |
|
687 | + } |
|
688 | + |
|
689 | + /** |
|
690 | + * Checks whether the form has a given item. |
|
691 | + * |
|
692 | + * @since 1.0.19 |
|
693 | + * @return bool |
|
694 | + */ |
|
695 | 695 | public function has_item( $item_id ) { |
696 | 696 | return false !== $this->get_item( $item_id ); |
697 | - } |
|
698 | - |
|
699 | - /** |
|
700 | - * Checks whether the form has a given element. |
|
701 | - * |
|
702 | - * @since 1.0.19 |
|
703 | - * @return bool |
|
704 | - */ |
|
697 | + } |
|
698 | + |
|
699 | + /** |
|
700 | + * Checks whether the form has a given element. |
|
701 | + * |
|
702 | + * @since 1.0.19 |
|
703 | + * @return bool |
|
704 | + */ |
|
705 | 705 | public function has_element_type( $element_type ) { |
706 | 706 | return false !== $this->get_element_type( $element_type ); |
707 | - } |
|
708 | - |
|
709 | - /** |
|
710 | - * Checks whether this form is recurring or not. |
|
711 | - * |
|
712 | - * @since 1.0.19 |
|
713 | - * @return bool |
|
714 | - */ |
|
707 | + } |
|
708 | + |
|
709 | + /** |
|
710 | + * Checks whether this form is recurring or not. |
|
711 | + * |
|
712 | + * @since 1.0.19 |
|
713 | + * @return bool |
|
714 | + */ |
|
715 | 715 | public function is_recurring() { |
716 | 716 | |
717 | - if ( ! empty( $this->invoice ) ) { |
|
718 | - return $this->invoice->is_recurring(); |
|
719 | - } |
|
717 | + if ( ! empty( $this->invoice ) ) { |
|
718 | + return $this->invoice->is_recurring(); |
|
719 | + } |
|
720 | 720 | |
721 | - foreach ( $this->get_items() as $item ) { |
|
721 | + foreach ( $this->get_items() as $item ) { |
|
722 | 722 | |
723 | - if ( $item->is_recurring() ) { |
|
724 | - return true; |
|
725 | - } |
|
723 | + if ( $item->is_recurring() ) { |
|
724 | + return true; |
|
725 | + } |
|
726 | 726 | |
727 | - } |
|
727 | + } |
|
728 | 728 | |
729 | 729 | return false; |
730 | - } |
|
730 | + } |
|
731 | 731 | |
732 | - /** |
|
733 | - * Retrieves the form's html. |
|
734 | - * |
|
735 | - * @since 1.0.19 |
|
736 | - */ |
|
732 | + /** |
|
733 | + * Retrieves the form's html. |
|
734 | + * |
|
735 | + * @since 1.0.19 |
|
736 | + */ |
|
737 | 737 | public function get_html( $extra_markup = '' ) { |
738 | 738 | |
739 | - // Return the HTML. |
|
740 | - return wpinv_get_template_html( |
|
741 | - 'payment-forms/form.php', |
|
742 | - array( |
|
743 | - 'form' => $this, |
|
744 | - 'extra_markup' => $extra_markup, |
|
745 | - ) |
|
746 | - ); |
|
747 | - |
|
748 | - } |
|
749 | - |
|
750 | - /** |
|
751 | - * Displays the payment form. |
|
752 | - * |
|
753 | - * @since 1.0.19 |
|
754 | - */ |
|
739 | + // Return the HTML. |
|
740 | + return wpinv_get_template_html( |
|
741 | + 'payment-forms/form.php', |
|
742 | + array( |
|
743 | + 'form' => $this, |
|
744 | + 'extra_markup' => $extra_markup, |
|
745 | + ) |
|
746 | + ); |
|
747 | + |
|
748 | + } |
|
749 | + |
|
750 | + /** |
|
751 | + * Displays the payment form. |
|
752 | + * |
|
753 | + * @since 1.0.19 |
|
754 | + */ |
|
755 | 755 | public function display( $extra_markup = '' ) { |
756 | - echo $this->get_html( $extra_markup ); |
|
756 | + echo $this->get_html( $extra_markup ); |
|
757 | 757 | } |
758 | 758 | |
759 | 759 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -72,28 +72,28 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
74 | 74 | */ |
75 | - public function __construct( $form = 0 ) { |
|
76 | - parent::__construct( $form ); |
|
75 | + public function __construct($form = 0) { |
|
76 | + parent::__construct($form); |
|
77 | 77 | |
78 | - if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | - $this->set_id( $form ); |
|
80 | - } elseif ( $form instanceof self ) { |
|
78 | + if (is_numeric($form) && $form > 0) { |
|
79 | + $this->set_id($form); |
|
80 | + } elseif ($form instanceof self) { |
|
81 | 81 | |
82 | - $this->set_id( $form->get_id() ); |
|
82 | + $this->set_id($form->get_id()); |
|
83 | 83 | $this->invoice = $form->invoice; |
84 | 84 | |
85 | - } elseif ( ! empty( $form->ID ) ) { |
|
86 | - $this->set_id( $form->ID ); |
|
85 | + } elseif (!empty($form->ID)) { |
|
86 | + $this->set_id($form->ID); |
|
87 | 87 | } else { |
88 | - $this->set_object_read( true ); |
|
88 | + $this->set_object_read(true); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | // Load the datastore. |
92 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
92 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
93 | 93 | |
94 | - if ( $this->get_id() > 0 ) { |
|
95 | - $this->post = get_post( $this->get_id() ); |
|
96 | - $this->data_store->read( $this ); |
|
94 | + if ($this->get_id() > 0) { |
|
95 | + $this->post = get_post($this->get_id()); |
|
96 | + $this->data_store->read($this); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | } |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | * @param string $context View or edit context. |
121 | 121 | * @return string |
122 | 122 | */ |
123 | - public function get_version( $context = 'view' ) { |
|
124 | - return $this->get_prop( 'version', $context ); |
|
123 | + public function get_version($context = 'view') { |
|
124 | + return $this->get_prop('version', $context); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | * @param string $context View or edit context. |
132 | 132 | * @return string |
133 | 133 | */ |
134 | - public function get_date_created( $context = 'view' ) { |
|
135 | - return $this->get_prop( 'date_created', $context ); |
|
134 | + public function get_date_created($context = 'view') { |
|
135 | + return $this->get_prop('date_created', $context); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | * @param string $context View or edit context. |
143 | 143 | * @return string |
144 | 144 | */ |
145 | - public function get_date_created_gmt( $context = 'view' ) { |
|
146 | - $date = $this->get_date_created( $context ); |
|
145 | + public function get_date_created_gmt($context = 'view') { |
|
146 | + $date = $this->get_date_created($context); |
|
147 | 147 | |
148 | - if ( $date ) { |
|
149 | - $date = get_gmt_from_date( $date ); |
|
148 | + if ($date) { |
|
149 | + $date = get_gmt_from_date($date); |
|
150 | 150 | } |
151 | 151 | return $date; |
152 | 152 | } |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * @param string $context View or edit context. |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - public function get_date_modified( $context = 'view' ) { |
|
162 | - return $this->get_prop( 'date_modified', $context ); |
|
161 | + public function get_date_modified($context = 'view') { |
|
162 | + return $this->get_prop('date_modified', $context); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -169,11 +169,11 @@ discard block |
||
169 | 169 | * @param string $context View or edit context. |
170 | 170 | * @return string |
171 | 171 | */ |
172 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
173 | - $date = $this->get_date_modified( $context ); |
|
172 | + public function get_date_modified_gmt($context = 'view') { |
|
173 | + $date = $this->get_date_modified($context); |
|
174 | 174 | |
175 | - if ( $date ) { |
|
176 | - $date = get_gmt_from_date( $date ); |
|
175 | + if ($date) { |
|
176 | + $date = get_gmt_from_date($date); |
|
177 | 177 | } |
178 | 178 | return $date; |
179 | 179 | } |
@@ -185,8 +185,8 @@ discard block |
||
185 | 185 | * @param string $context View or edit context. |
186 | 186 | * @return string |
187 | 187 | */ |
188 | - public function get_name( $context = 'view' ) { |
|
189 | - return $this->get_prop( 'name', $context ); |
|
188 | + public function get_name($context = 'view') { |
|
189 | + return $this->get_prop('name', $context); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -196,8 +196,8 @@ discard block |
||
196 | 196 | * @param string $context View or edit context. |
197 | 197 | * @return string |
198 | 198 | */ |
199 | - public function get_title( $context = 'view' ) { |
|
200 | - return $this->get_name( $context ); |
|
199 | + public function get_title($context = 'view') { |
|
200 | + return $this->get_name($context); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -207,8 +207,8 @@ discard block |
||
207 | 207 | * @param string $context View or edit context. |
208 | 208 | * @return int |
209 | 209 | */ |
210 | - public function get_author( $context = 'view' ) { |
|
211 | - return (int) $this->get_prop( 'author', $context ); |
|
210 | + public function get_author($context = 'view') { |
|
211 | + return (int) $this->get_prop('author', $context); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -218,21 +218,21 @@ discard block |
||
218 | 218 | * @param string $context View or edit context. |
219 | 219 | * @return array |
220 | 220 | */ |
221 | - public function get_elements( $context = 'view' ) { |
|
222 | - $elements = $this->get_prop( 'elements', $context ); |
|
221 | + public function get_elements($context = 'view') { |
|
222 | + $elements = $this->get_prop('elements', $context); |
|
223 | 223 | |
224 | - if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
225 | - return wpinv_get_data( 'sample-payment-form' ); |
|
224 | + if (empty($elements) || !is_array($elements)) { |
|
225 | + return wpinv_get_data('sample-payment-form'); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | // Ensure that all required elements exist. |
229 | 229 | $_elements = array(); |
230 | - foreach ( $elements as $element ) { |
|
230 | + foreach ($elements as $element) { |
|
231 | 231 | |
232 | - if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
232 | + if ($element['type'] == 'pay_button' && !$this->has_element_type('gateway_select')) { |
|
233 | 233 | |
234 | 234 | $_elements[] = array( |
235 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
235 | + 'text' => __('Select Payment Method', 'invoicing'), |
|
236 | 236 | 'id' => 'gtscicd', |
237 | 237 | 'name' => 'gtscicd', |
238 | 238 | 'type' => 'gateway_select', |
@@ -257,22 +257,22 @@ discard block |
||
257 | 257 | * @param string $return objects or arrays. |
258 | 258 | * @return GetPaid_Form_Item[] |
259 | 259 | */ |
260 | - public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | - $items = $this->get_prop( 'items', $context ); |
|
260 | + public function get_items($context = 'view', $return = 'objects') { |
|
261 | + $items = $this->get_prop('items', $context); |
|
262 | 262 | |
263 | - if ( empty( $items ) || ! is_array( $items ) ) { |
|
264 | - $items = wpinv_get_data( 'sample-payment-form-items' ); |
|
263 | + if (empty($items) || !is_array($items)) { |
|
264 | + $items = wpinv_get_data('sample-payment-form-items'); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | // Convert the items. |
268 | 268 | $prepared = array(); |
269 | 269 | |
270 | - foreach ( $items as $key => $value ) { |
|
270 | + foreach ($items as $key => $value) { |
|
271 | 271 | |
272 | 272 | // Form items. |
273 | - if ( $value instanceof GetPaid_Form_Item ) { |
|
273 | + if ($value instanceof GetPaid_Form_Item) { |
|
274 | 274 | |
275 | - if ( $value->can_purchase() ) { |
|
275 | + if ($value->can_purchase()) { |
|
276 | 276 | $prepared[] = $value; |
277 | 277 | } |
278 | 278 | |
@@ -281,16 +281,16 @@ discard block |
||
281 | 281 | } |
282 | 282 | |
283 | 283 | // $item_id => $quantity (buy buttons) |
284 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | - $item = new GetPaid_Form_Item( $key ); |
|
284 | + if (is_numeric($key) && is_numeric($value)) { |
|
285 | + $item = new GetPaid_Form_Item($key); |
|
286 | 286 | |
287 | - if ( $item->can_purchase() ) { |
|
287 | + if ($item->can_purchase()) { |
|
288 | 288 | |
289 | 289 | $value = (int) $value; |
290 | - $item->set_quantity( $value ); |
|
291 | - if ( 0 == $value ) { |
|
292 | - $item->set_quantity( 1 ); |
|
293 | - $item->set_allow_quantities( true ); |
|
290 | + $item->set_quantity($value); |
|
291 | + if (0 == $value) { |
|
292 | + $item->set_quantity(1); |
|
293 | + $item->set_allow_quantities(true); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | $prepared[] = $item; |
@@ -300,33 +300,33 @@ discard block |
||
300 | 300 | } |
301 | 301 | |
302 | 302 | // Items saved via payment forms editor. |
303 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
303 | + if (is_array($value) && isset($value['id'])) { |
|
304 | 304 | |
305 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
305 | + $item = new GetPaid_Form_Item($value['id']); |
|
306 | 306 | |
307 | - if ( ! $item->can_purchase() ) { |
|
307 | + if (!$item->can_purchase()) { |
|
308 | 308 | continue; |
309 | 309 | } |
310 | 310 | |
311 | 311 | // Sub-total (Cart items). |
312 | - if ( isset( $value['subtotal'] ) ) { |
|
313 | - $item->set_price( $value['subtotal'] ); |
|
312 | + if (isset($value['subtotal'])) { |
|
313 | + $item->set_price($value['subtotal']); |
|
314 | 314 | } |
315 | 315 | |
316 | - if ( isset( $value['quantity'] ) ) { |
|
317 | - $item->set_quantity( $value['quantity'] ); |
|
316 | + if (isset($value['quantity'])) { |
|
317 | + $item->set_quantity($value['quantity']); |
|
318 | 318 | } |
319 | 319 | |
320 | - if ( isset( $value['allow_quantities'] ) ) { |
|
321 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
320 | + if (isset($value['allow_quantities'])) { |
|
321 | + $item->set_allow_quantities($value['allow_quantities']); |
|
322 | 322 | } |
323 | 323 | |
324 | - if ( isset( $value['required'] ) ) { |
|
325 | - $item->set_is_required( $value['required'] ); |
|
324 | + if (isset($value['required'])) { |
|
325 | + $item->set_is_required($value['required']); |
|
326 | 326 | } |
327 | 327 | |
328 | - if ( isset( $value['description'] ) ) { |
|
329 | - $item->set_custom_description( $value['description'] ); |
|
328 | + if (isset($value['description'])) { |
|
329 | + $item->set_custom_description($value['description']); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | $prepared[] = $item; |
@@ -335,14 +335,14 @@ discard block |
||
335 | 335 | } |
336 | 336 | |
337 | 337 | // $item_id => array( 'price' => 10 ) (item variations) |
338 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
339 | - $item = new GetPaid_Form_Item( $key ); |
|
338 | + if (is_numeric($key) && is_array($value)) { |
|
339 | + $item = new GetPaid_Form_Item($key); |
|
340 | 340 | |
341 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
342 | - $item->set_price( $value['price'] ); |
|
341 | + if (isset($value['price']) && $item->user_can_set_their_price()) { |
|
342 | + $item->set_price($value['price']); |
|
343 | 343 | } |
344 | 344 | |
345 | - if ( $item->can_purchase() ) { |
|
345 | + if ($item->can_purchase()) { |
|
346 | 346 | $prepared[] = $item; |
347 | 347 | } |
348 | 348 | |
@@ -351,12 +351,12 @@ discard block |
||
351 | 351 | |
352 | 352 | } |
353 | 353 | |
354 | - if ( 'objects' == $return && 'view' == $context ) { |
|
354 | + if ('objects' == $return && 'view' == $context) { |
|
355 | 355 | return $prepared; |
356 | 356 | } |
357 | 357 | |
358 | 358 | $items = array(); |
359 | - foreach ( $prepared as $item ) { |
|
359 | + foreach ($prepared as $item) { |
|
360 | 360 | $items[] = $item->prepare_data_for_use(); |
361 | 361 | } |
362 | 362 | |
@@ -370,14 +370,14 @@ discard block |
||
370 | 370 | * @param int $item_id The item id to return. |
371 | 371 | * @return GetPaid_Form_Item|bool |
372 | 372 | */ |
373 | - public function get_item( $item_id ) { |
|
373 | + public function get_item($item_id) { |
|
374 | 374 | |
375 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
375 | + if (empty($item_id) || !is_numeric($item_id)) { |
|
376 | 376 | return false; |
377 | 377 | } |
378 | 378 | |
379 | - foreach( $this->get_items() as $item ) { |
|
380 | - if ( $item->get_id() == (int) $item_id ) { |
|
379 | + foreach ($this->get_items() as $item) { |
|
380 | + if ($item->get_id() == (int) $item_id) { |
|
381 | 381 | return $item; |
382 | 382 | } |
383 | 383 | } |
@@ -393,15 +393,15 @@ discard block |
||
393 | 393 | * @param string $element_type The element type to return. |
394 | 394 | * @return array|bool |
395 | 395 | */ |
396 | - public function get_element_type( $element_type ) { |
|
396 | + public function get_element_type($element_type) { |
|
397 | 397 | |
398 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
398 | + if (empty($element_type) || !is_scalar($element_type)) { |
|
399 | 399 | return false; |
400 | 400 | } |
401 | 401 | |
402 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
402 | + foreach ($this->get_prop('elements') as $element) { |
|
403 | 403 | |
404 | - if ( $element['type'] == $element_type ) { |
|
404 | + if ($element['type'] == $element_type) { |
|
405 | 405 | return $element; |
406 | 406 | } |
407 | 407 | |
@@ -418,8 +418,8 @@ discard block |
||
418 | 418 | * @param string $context View or edit context. |
419 | 419 | * @return array |
420 | 420 | */ |
421 | - public function get_earned( $context = 'view' ) { |
|
422 | - return $this->get_prop( 'earned', $context ); |
|
421 | + public function get_earned($context = 'view') { |
|
422 | + return $this->get_prop('earned', $context); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | /** |
@@ -429,8 +429,8 @@ discard block |
||
429 | 429 | * @param string $context View or edit context. |
430 | 430 | * @return array |
431 | 431 | */ |
432 | - public function get_refunded( $context = 'view' ) { |
|
433 | - return $this->get_prop( 'refunded', $context ); |
|
432 | + public function get_refunded($context = 'view') { |
|
433 | + return $this->get_prop('refunded', $context); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | /** |
@@ -440,8 +440,8 @@ discard block |
||
440 | 440 | * @param string $context View or edit context. |
441 | 441 | * @return array |
442 | 442 | */ |
443 | - public function get_cancelled( $context = 'view' ) { |
|
444 | - return $this->get_prop( 'cancelled', $context ); |
|
443 | + public function get_cancelled($context = 'view') { |
|
444 | + return $this->get_prop('cancelled', $context); |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | /** |
@@ -451,8 +451,8 @@ discard block |
||
451 | 451 | * @param string $context View or edit context. |
452 | 452 | * @return array |
453 | 453 | */ |
454 | - public function get_failed( $context = 'view' ) { |
|
455 | - return $this->get_prop( 'failed', $context ); |
|
454 | + public function get_failed($context = 'view') { |
|
455 | + return $this->get_prop('failed', $context); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | /** |
@@ -463,8 +463,8 @@ discard block |
||
463 | 463 | * @return string |
464 | 464 | */ |
465 | 465 | public function get_currency() { |
466 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
467 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
466 | + $currency = empty($this->invoice) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
467 | + return apply_filters('getpaid-payment-form-currency', $currency, $this); |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | /* |
@@ -482,8 +482,8 @@ discard block |
||
482 | 482 | * |
483 | 483 | * @since 1.0.19 |
484 | 484 | */ |
485 | - public function set_version( $value ) { |
|
486 | - $this->set_prop( 'version', $value ); |
|
485 | + public function set_version($value) { |
|
486 | + $this->set_prop('version', $value); |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | /** |
@@ -493,11 +493,11 @@ discard block |
||
493 | 493 | * @param string $value Value to set. |
494 | 494 | * @return bool Whether or not the date was set. |
495 | 495 | */ |
496 | - public function set_date_created( $value ) { |
|
497 | - $date = strtotime( $value ); |
|
496 | + public function set_date_created($value) { |
|
497 | + $date = strtotime($value); |
|
498 | 498 | |
499 | - if ( $date ) { |
|
500 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
499 | + if ($date) { |
|
500 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
501 | 501 | return true; |
502 | 502 | } |
503 | 503 | |
@@ -512,11 +512,11 @@ discard block |
||
512 | 512 | * @param string $value Value to set. |
513 | 513 | * @return bool Whether or not the date was set. |
514 | 514 | */ |
515 | - public function set_date_modified( $value ) { |
|
516 | - $date = strtotime( $value ); |
|
515 | + public function set_date_modified($value) { |
|
516 | + $date = strtotime($value); |
|
517 | 517 | |
518 | - if ( $date ) { |
|
519 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
518 | + if ($date) { |
|
519 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
520 | 520 | return true; |
521 | 521 | } |
522 | 522 | |
@@ -530,8 +530,8 @@ discard block |
||
530 | 530 | * @since 1.0.19 |
531 | 531 | * @param string $value New name. |
532 | 532 | */ |
533 | - public function set_name( $value ) { |
|
534 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
533 | + public function set_name($value) { |
|
534 | + $this->set_prop('name', sanitize_text_field($value)); |
|
535 | 535 | } |
536 | 536 | |
537 | 537 | /** |
@@ -540,8 +540,8 @@ discard block |
||
540 | 540 | * @since 1.0.19 |
541 | 541 | * @param string $value New name. |
542 | 542 | */ |
543 | - public function set_title( $value ) { |
|
544 | - $this->set_name( $value ); |
|
543 | + public function set_title($value) { |
|
544 | + $this->set_name($value); |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | /** |
@@ -550,8 +550,8 @@ discard block |
||
550 | 550 | * @since 1.0.19 |
551 | 551 | * @param int $value New author. |
552 | 552 | */ |
553 | - public function set_author( $value ) { |
|
554 | - $this->set_prop( 'author', (int) $value ); |
|
553 | + public function set_author($value) { |
|
554 | + $this->set_prop('author', (int) $value); |
|
555 | 555 | } |
556 | 556 | |
557 | 557 | /** |
@@ -560,9 +560,9 @@ discard block |
||
560 | 560 | * @since 1.0.19 |
561 | 561 | * @param array $value Form elements. |
562 | 562 | */ |
563 | - public function set_elements( $value ) { |
|
564 | - if ( is_array( $value ) ) { |
|
565 | - $this->set_prop( 'elements', $value ); |
|
563 | + public function set_elements($value) { |
|
564 | + if (is_array($value)) { |
|
565 | + $this->set_prop('elements', $value); |
|
566 | 566 | } |
567 | 567 | } |
568 | 568 | |
@@ -572,9 +572,9 @@ discard block |
||
572 | 572 | * @since 1.0.19 |
573 | 573 | * @param array $value Form elements. |
574 | 574 | */ |
575 | - public function set_items( $value ) { |
|
576 | - if ( is_array( $value ) ) { |
|
577 | - $this->set_prop( 'items', $value ); |
|
575 | + public function set_items($value) { |
|
576 | + if (is_array($value)) { |
|
577 | + $this->set_prop('items', $value); |
|
578 | 578 | } |
579 | 579 | } |
580 | 580 | |
@@ -584,9 +584,9 @@ discard block |
||
584 | 584 | * @since 1.0.19 |
585 | 585 | * @param float $value Amount earned. |
586 | 586 | */ |
587 | - public function set_earned( $value ) { |
|
588 | - $value = max( (float) $value, 0 ); |
|
589 | - $this->set_prop( 'earned', $value ); |
|
587 | + public function set_earned($value) { |
|
588 | + $value = max((float) $value, 0); |
|
589 | + $this->set_prop('earned', $value); |
|
590 | 590 | } |
591 | 591 | |
592 | 592 | /** |
@@ -595,9 +595,9 @@ discard block |
||
595 | 595 | * @since 1.0.19 |
596 | 596 | * @param float $value Amount refunded. |
597 | 597 | */ |
598 | - public function set_refunded( $value ) { |
|
599 | - $value = max( (float) $value, 0 ); |
|
600 | - $this->set_prop( 'refunded', $value ); |
|
598 | + public function set_refunded($value) { |
|
599 | + $value = max((float) $value, 0); |
|
600 | + $this->set_prop('refunded', $value); |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | /** |
@@ -606,9 +606,9 @@ discard block |
||
606 | 606 | * @since 1.0.19 |
607 | 607 | * @param float $value Amount cancelled. |
608 | 608 | */ |
609 | - public function set_cancelled( $value ) { |
|
610 | - $value = max( (float) $value, 0 ); |
|
611 | - $this->set_prop( 'cancelled', $value ); |
|
609 | + public function set_cancelled($value) { |
|
610 | + $value = max((float) $value, 0); |
|
611 | + $this->set_prop('cancelled', $value); |
|
612 | 612 | } |
613 | 613 | |
614 | 614 | /** |
@@ -617,9 +617,9 @@ discard block |
||
617 | 617 | * @since 1.0.19 |
618 | 618 | * @param float $value Amount cancelled. |
619 | 619 | */ |
620 | - public function set_failed( $value ) { |
|
621 | - $value = max( (float) $value, 0 ); |
|
622 | - $this->set_prop( 'failed', $value ); |
|
620 | + public function set_failed($value) { |
|
621 | + $value = max((float) $value, 0); |
|
622 | + $this->set_prop('failed', $value); |
|
623 | 623 | } |
624 | 624 | |
625 | 625 | /** |
@@ -628,11 +628,11 @@ discard block |
||
628 | 628 | * @deprecated |
629 | 629 | * @return int item id |
630 | 630 | */ |
631 | - public function create( $data = array() ) { |
|
631 | + public function create($data = array()) { |
|
632 | 632 | |
633 | 633 | // Set the properties. |
634 | - if ( is_array( $data ) ) { |
|
635 | - $this->set_props( $data ); |
|
634 | + if (is_array($data)) { |
|
635 | + $this->set_props($data); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | // Save the item. |
@@ -646,8 +646,8 @@ discard block |
||
646 | 646 | * @deprecated |
647 | 647 | * @return int item id |
648 | 648 | */ |
649 | - public function update( $data = array() ) { |
|
650 | - return $this->create( $data ); |
|
649 | + public function update($data = array()) { |
|
650 | + return $this->create($data); |
|
651 | 651 | } |
652 | 652 | |
653 | 653 | /* |
@@ -667,7 +667,7 @@ discard block |
||
667 | 667 | */ |
668 | 668 | public function is_default() { |
669 | 669 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
670 | - return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
|
670 | + return (bool) apply_filters('wpinv_is_default_payment_form', $is_default, $this->get_id(), $this); |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | /** |
@@ -679,11 +679,11 @@ discard block |
||
679 | 679 | public function is_active() { |
680 | 680 | $is_active = 0 !== (int) $this->get_id(); |
681 | 681 | |
682 | - if ( $is_active && ! current_user_can( 'edit_post', $this->get_id() ) && $this->get_status() != 'publish' ) { |
|
682 | + if ($is_active && !current_user_can('edit_post', $this->get_id()) && $this->get_status() != 'publish') { |
|
683 | 683 | $is_active = false; |
684 | 684 | } |
685 | 685 | |
686 | - return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
|
686 | + return (bool) apply_filters('wpinv_is_payment_form_active', $is_active, $this); |
|
687 | 687 | } |
688 | 688 | |
689 | 689 | /** |
@@ -692,8 +692,8 @@ discard block |
||
692 | 692 | * @since 1.0.19 |
693 | 693 | * @return bool |
694 | 694 | */ |
695 | - public function has_item( $item_id ) { |
|
696 | - return false !== $this->get_item( $item_id ); |
|
695 | + public function has_item($item_id) { |
|
696 | + return false !== $this->get_item($item_id); |
|
697 | 697 | } |
698 | 698 | |
699 | 699 | /** |
@@ -702,8 +702,8 @@ discard block |
||
702 | 702 | * @since 1.0.19 |
703 | 703 | * @return bool |
704 | 704 | */ |
705 | - public function has_element_type( $element_type ) { |
|
706 | - return false !== $this->get_element_type( $element_type ); |
|
705 | + public function has_element_type($element_type) { |
|
706 | + return false !== $this->get_element_type($element_type); |
|
707 | 707 | } |
708 | 708 | |
709 | 709 | /** |
@@ -714,13 +714,13 @@ discard block |
||
714 | 714 | */ |
715 | 715 | public function is_recurring() { |
716 | 716 | |
717 | - if ( ! empty( $this->invoice ) ) { |
|
717 | + if (!empty($this->invoice)) { |
|
718 | 718 | return $this->invoice->is_recurring(); |
719 | 719 | } |
720 | 720 | |
721 | - foreach ( $this->get_items() as $item ) { |
|
721 | + foreach ($this->get_items() as $item) { |
|
722 | 722 | |
723 | - if ( $item->is_recurring() ) { |
|
723 | + if ($item->is_recurring()) { |
|
724 | 724 | return true; |
725 | 725 | } |
726 | 726 | |
@@ -734,7 +734,7 @@ discard block |
||
734 | 734 | * |
735 | 735 | * @since 1.0.19 |
736 | 736 | */ |
737 | - public function get_html( $extra_markup = '' ) { |
|
737 | + public function get_html($extra_markup = '') { |
|
738 | 738 | |
739 | 739 | // Return the HTML. |
740 | 740 | return wpinv_get_template_html( |
@@ -752,8 +752,8 @@ discard block |
||
752 | 752 | * |
753 | 753 | * @since 1.0.19 |
754 | 754 | */ |
755 | - public function display( $extra_markup = '' ) { |
|
756 | - echo $this->get_html( $extra_markup ); |
|
755 | + public function display($extra_markup = '') { |
|
756 | + echo $this->get_html($extra_markup); |
|
757 | 757 | } |
758 | 758 | |
759 | 759 | } |
@@ -12,78 +12,78 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Items { |
14 | 14 | |
15 | - /** |
|
16 | - * Submission items. |
|
17 | - * @var GetPaid_Form_Item[] |
|
18 | - */ |
|
19 | - public $items = array(); |
|
20 | - |
|
21 | 15 | /** |
22 | - * Class constructor |
|
23 | - * |
|
24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
25 | - */ |
|
26 | - public function __construct( $submission ) { |
|
27 | - |
|
28 | - $data = $submission->get_data(); |
|
29 | - $payment_form = $submission->get_payment_form(); |
|
30 | - |
|
31 | - // Prepare the selected items. |
|
32 | - $selected_items = array(); |
|
33 | - if ( ! empty( $data['getpaid-items'] ) ) { |
|
34 | - $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
35 | - } |
|
36 | - |
|
37 | - // For default forms, ensure that an item has been set. |
|
38 | - if ( $payment_form->is_default() && ! $submission->has_invoice() && isset( $data['getpaid-form-items'] ) ) { |
|
39 | - $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
40 | - $payment_form->set_items( getpaid_convert_items_to_array( $form_items ) ); |
|
41 | - } |
|
16 | + * Submission items. |
|
17 | + * @var GetPaid_Form_Item[] |
|
18 | + */ |
|
19 | + public $items = array(); |
|
42 | 20 | |
43 | - // Process each individual item. |
|
44 | - foreach ( $payment_form->get_items() as $item ) { |
|
45 | - $this->process_item( $item, $selected_items ); |
|
46 | - } |
|
47 | - |
|
48 | - } |
|
21 | + /** |
|
22 | + * Class constructor |
|
23 | + * |
|
24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
25 | + */ |
|
26 | + public function __construct( $submission ) { |
|
27 | + |
|
28 | + $data = $submission->get_data(); |
|
29 | + $payment_form = $submission->get_payment_form(); |
|
30 | + |
|
31 | + // Prepare the selected items. |
|
32 | + $selected_items = array(); |
|
33 | + if ( ! empty( $data['getpaid-items'] ) ) { |
|
34 | + $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
35 | + } |
|
36 | + |
|
37 | + // For default forms, ensure that an item has been set. |
|
38 | + if ( $payment_form->is_default() && ! $submission->has_invoice() && isset( $data['getpaid-form-items'] ) ) { |
|
39 | + $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
40 | + $payment_form->set_items( getpaid_convert_items_to_array( $form_items ) ); |
|
41 | + } |
|
42 | + |
|
43 | + // Process each individual item. |
|
44 | + foreach ( $payment_form->get_items() as $item ) { |
|
45 | + $this->process_item( $item, $selected_items ); |
|
46 | + } |
|
47 | + |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Process a single item. |
|
52 | - * |
|
53 | - * @param GetPaid_Form_Item $item |
|
54 | - * @param array $selected_items |
|
55 | - */ |
|
56 | - public function process_item( $item, $selected_items ) { |
|
50 | + /** |
|
51 | + * Process a single item. |
|
52 | + * |
|
53 | + * @param GetPaid_Form_Item $item |
|
54 | + * @param array $selected_items |
|
55 | + */ |
|
56 | + public function process_item( $item, $selected_items ) { |
|
57 | 57 | |
58 | - // Abort if this is an optional item and it has not been selected. |
|
59 | - if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
60 | - return; |
|
61 | - } |
|
58 | + // Abort if this is an optional item and it has not been selected. |
|
59 | + if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
60 | + return; |
|
61 | + } |
|
62 | 62 | |
63 | - // (maybe) let customers change the quantities and prices. |
|
64 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
63 | + // (maybe) let customers change the quantities and prices. |
|
64 | + if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
65 | 65 | |
66 | - // Maybe change the quantities. |
|
67 | - if ( $item->allows_quantities() ) { |
|
68 | - $item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] ); |
|
69 | - } |
|
66 | + // Maybe change the quantities. |
|
67 | + if ( $item->allows_quantities() ) { |
|
68 | + $item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] ); |
|
69 | + } |
|
70 | 70 | |
71 | - // Maybe change the price. |
|
72 | - if ( $item->user_can_set_their_price() ) { |
|
73 | - $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
71 | + // Maybe change the price. |
|
72 | + if ( $item->user_can_set_their_price() ) { |
|
73 | + $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
74 | 74 | |
75 | - // But don't get lower than the minimum price. |
|
76 | - $price = max( $price, $item->get_minimum_price() ); |
|
75 | + // But don't get lower than the minimum price. |
|
76 | + $price = max( $price, $item->get_minimum_price() ); |
|
77 | 77 | |
78 | - $item->set_price( $price ); |
|
78 | + $item->set_price( $price ); |
|
79 | 79 | |
80 | - } |
|
80 | + } |
|
81 | 81 | |
82 | - } |
|
82 | + } |
|
83 | 83 | |
84 | - // Save the item. |
|
85 | - $this->items[] = $item; |
|
84 | + // Save the item. |
|
85 | + $this->items[] = $item; |
|
86 | 86 | |
87 | - } |
|
87 | + } |
|
88 | 88 | |
89 | 89 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Payment form submission itemss class |
@@ -23,26 +23,26 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @param GetPaid_Payment_Form_Submission $submission |
25 | 25 | */ |
26 | - public function __construct( $submission ) { |
|
26 | + public function __construct($submission) { |
|
27 | 27 | |
28 | 28 | $data = $submission->get_data(); |
29 | 29 | $payment_form = $submission->get_payment_form(); |
30 | 30 | |
31 | 31 | // Prepare the selected items. |
32 | 32 | $selected_items = array(); |
33 | - if ( ! empty( $data['getpaid-items'] ) ) { |
|
34 | - $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
33 | + if (!empty($data['getpaid-items'])) { |
|
34 | + $selected_items = wpinv_clean($data['getpaid-items']); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | // For default forms, ensure that an item has been set. |
38 | - if ( $payment_form->is_default() && ! $submission->has_invoice() && isset( $data['getpaid-form-items'] ) ) { |
|
39 | - $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
40 | - $payment_form->set_items( getpaid_convert_items_to_array( $form_items ) ); |
|
38 | + if ($payment_form->is_default() && !$submission->has_invoice() && isset($data['getpaid-form-items'])) { |
|
39 | + $form_items = wpinv_clean($data['getpaid-form-items']); |
|
40 | + $payment_form->set_items(getpaid_convert_items_to_array($form_items)); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | // Process each individual item. |
44 | - foreach ( $payment_form->get_items() as $item ) { |
|
45 | - $this->process_item( $item, $selected_items ); |
|
44 | + foreach ($payment_form->get_items() as $item) { |
|
45 | + $this->process_item($item, $selected_items); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | } |
@@ -53,29 +53,29 @@ discard block |
||
53 | 53 | * @param GetPaid_Form_Item $item |
54 | 54 | * @param array $selected_items |
55 | 55 | */ |
56 | - public function process_item( $item, $selected_items ) { |
|
56 | + public function process_item($item, $selected_items) { |
|
57 | 57 | |
58 | 58 | // Abort if this is an optional item and it has not been selected. |
59 | - if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
59 | + if (!$item->is_required() && !isset($selected_items[$item->get_id()])) { |
|
60 | 60 | return; |
61 | 61 | } |
62 | 62 | |
63 | 63 | // (maybe) let customers change the quantities and prices. |
64 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
64 | + if (isset($selected_items[$item->get_id()])) { |
|
65 | 65 | |
66 | 66 | // Maybe change the quantities. |
67 | - if ( $item->allows_quantities() ) { |
|
68 | - $item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] ); |
|
67 | + if ($item->allows_quantities()) { |
|
68 | + $item->set_quantity((int) $selected_items[$item->get_id()]['quantity']); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | // Maybe change the price. |
72 | - if ( $item->user_can_set_their_price() ) { |
|
73 | - $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
72 | + if ($item->user_can_set_their_price()) { |
|
73 | + $price = (float) wpinv_sanitize_amount($selected_items[$item->get_id()]['price']); |
|
74 | 74 | |
75 | 75 | // But don't get lower than the minimum price. |
76 | - $price = max( $price, $item->get_minimum_price() ); |
|
76 | + $price = max($price, $item->get_minimum_price()); |
|
77 | 77 | |
78 | - $item->set_price( $price ); |
|
78 | + $item->set_price($price); |
|
79 | 79 | |
80 | 80 | } |
81 | 81 |
@@ -4,99 +4,99 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Displays an invoice. |
11 | 11 | * |
12 | 12 | * @param WPInv_Invoice $invoice. |
13 | 13 | */ |
14 | -function getpaid_invoice( $invoice ) { |
|
15 | - if ( ! empty( $invoice ) ) { |
|
16 | - wpinv_get_template( 'invoice/invoice.php', compact( 'invoice' ) ); |
|
14 | +function getpaid_invoice($invoice) { |
|
15 | + if (!empty($invoice)) { |
|
16 | + wpinv_get_template('invoice/invoice.php', compact('invoice')); |
|
17 | 17 | } |
18 | 18 | } |
19 | -add_action( 'getpaid_invoice', 'getpaid_invoice', 10 ); |
|
19 | +add_action('getpaid_invoice', 'getpaid_invoice', 10); |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Displays the invoice footer. |
23 | 23 | */ |
24 | -function getpaid_invoice_footer( $invoice ) { |
|
25 | - if ( ! empty( $invoice ) ) { |
|
26 | - wpinv_get_template( 'invoice/footer.php', compact( 'invoice' ) ); |
|
24 | +function getpaid_invoice_footer($invoice) { |
|
25 | + if (!empty($invoice)) { |
|
26 | + wpinv_get_template('invoice/footer.php', compact('invoice')); |
|
27 | 27 | } |
28 | 28 | } |
29 | -add_action( 'getpaid_invoice_footer', 'getpaid_invoice_footer', 10 ); |
|
29 | +add_action('getpaid_invoice_footer', 'getpaid_invoice_footer', 10); |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Displays the invoice top bar. |
33 | 33 | */ |
34 | -function getpaid_invoice_header( $invoice ) { |
|
35 | - if ( ! empty( $invoice ) ) { |
|
36 | - wpinv_get_template( 'invoice/header.php', compact( 'invoice' ) ); |
|
34 | +function getpaid_invoice_header($invoice) { |
|
35 | + if (!empty($invoice)) { |
|
36 | + wpinv_get_template('invoice/header.php', compact('invoice')); |
|
37 | 37 | } |
38 | 38 | } |
39 | -add_action( 'getpaid_invoice_header', 'getpaid_invoice_header', 10 ); |
|
39 | +add_action('getpaid_invoice_header', 'getpaid_invoice_header', 10); |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * Displays actions on the left side of the header. |
43 | 43 | */ |
44 | -function getpaid_invoice_header_left_actions( $invoice ) { |
|
45 | - if ( ! empty( $invoice ) ) { |
|
46 | - wpinv_get_template( 'invoice/header-left-actions.php', compact( 'invoice' ) ); |
|
44 | +function getpaid_invoice_header_left_actions($invoice) { |
|
45 | + if (!empty($invoice)) { |
|
46 | + wpinv_get_template('invoice/header-left-actions.php', compact('invoice')); |
|
47 | 47 | } |
48 | 48 | } |
49 | -add_action( 'getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10 ); |
|
49 | +add_action('getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10); |
|
50 | 50 | |
51 | 51 | /** |
52 | 52 | * Displays actions on the right side of the invoice top bar. |
53 | 53 | */ |
54 | -function getpaid_invoice_header_right_actions( $invoice ) { |
|
55 | - if ( ! empty( $invoice ) ) { |
|
56 | - wpinv_get_template( 'invoice/header-right-actions.php', compact( 'invoice' ) ); |
|
54 | +function getpaid_invoice_header_right_actions($invoice) { |
|
55 | + if (!empty($invoice)) { |
|
56 | + wpinv_get_template('invoice/header-right-actions.php', compact('invoice')); |
|
57 | 57 | } |
58 | 58 | } |
59 | -add_action( 'getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10 ); |
|
59 | +add_action('getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10); |
|
60 | 60 | |
61 | 61 | /** |
62 | 62 | * Displays the invoice title, watermark, logo etc. |
63 | 63 | */ |
64 | -function getpaid_invoice_details_top( $invoice ) { |
|
65 | - if ( ! empty( $invoice ) ) { |
|
66 | - wpinv_get_template( 'invoice/details-top.php', compact( 'invoice' ) ); |
|
64 | +function getpaid_invoice_details_top($invoice) { |
|
65 | + if (!empty($invoice)) { |
|
66 | + wpinv_get_template('invoice/details-top.php', compact('invoice')); |
|
67 | 67 | } |
68 | 68 | } |
69 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_top', 10 ); |
|
69 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_top', 10); |
|
70 | 70 | |
71 | 71 | /** |
72 | 72 | * Displays the company logo. |
73 | 73 | */ |
74 | -function getpaid_invoice_logo( $invoice ) { |
|
75 | - if ( ! empty( $invoice ) ) { |
|
76 | - wpinv_get_template( 'invoice/invoice-logo.php', compact( 'invoice' ) ); |
|
74 | +function getpaid_invoice_logo($invoice) { |
|
75 | + if (!empty($invoice)) { |
|
76 | + wpinv_get_template('invoice/invoice-logo.php', compact('invoice')); |
|
77 | 77 | } |
78 | 78 | } |
79 | -add_action( 'getpaid_invoice_details_top_left', 'getpaid_invoice_logo' ); |
|
79 | +add_action('getpaid_invoice_details_top_left', 'getpaid_invoice_logo'); |
|
80 | 80 | |
81 | 81 | /** |
82 | 82 | * Displays the type of invoice. |
83 | 83 | */ |
84 | -function getpaid_invoice_type( $invoice ) { |
|
85 | - if ( ! empty( $invoice ) ) { |
|
86 | - wpinv_get_template( 'invoice/invoice-type.php', compact( 'invoice' ) ); |
|
84 | +function getpaid_invoice_type($invoice) { |
|
85 | + if (!empty($invoice)) { |
|
86 | + wpinv_get_template('invoice/invoice-type.php', compact('invoice')); |
|
87 | 87 | } |
88 | 88 | } |
89 | -add_action( 'getpaid_invoice_details_top_right', 'getpaid_invoice_type' ); |
|
89 | +add_action('getpaid_invoice_details_top_right', 'getpaid_invoice_type'); |
|
90 | 90 | |
91 | 91 | /** |
92 | 92 | * Displays the invoice details. |
93 | 93 | */ |
94 | -function getpaid_invoice_details_main( $invoice ) { |
|
95 | - if ( ! empty( $invoice ) ) { |
|
96 | - wpinv_get_template( 'invoice/details.php', compact( 'invoice' ) ); |
|
94 | +function getpaid_invoice_details_main($invoice) { |
|
95 | + if (!empty($invoice)) { |
|
96 | + wpinv_get_template('invoice/details.php', compact('invoice')); |
|
97 | 97 | } |
98 | 98 | } |
99 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_main', 50 ); |
|
99 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_main', 50); |
|
100 | 100 | |
101 | 101 | /** |
102 | 102 | * Returns a path to the templates directory. |
@@ -125,8 +125,8 @@ discard block |
||
125 | 125 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
126 | 126 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
127 | 127 | */ |
128 | -function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
129 | - return getpaid_template()->display_template( $template_name, $args, $template_path, $default_path ); |
|
128 | +function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
129 | + return getpaid_template()->display_template($template_name, $args, $template_path, $default_path); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
140 | 140 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
141 | 141 | */ |
142 | -function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
143 | - return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
142 | +function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
143 | + return getpaid_template()->get_template($template_name, $args, $template_path, $default_path); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @return string |
150 | 150 | */ |
151 | 151 | function wpinv_template_path() { |
152 | - return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() ); |
|
152 | + return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name()); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | function wpinv_get_theme_template_dir_name() { |
161 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
161 | + return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing')); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -170,56 +170,56 @@ discard block |
||
170 | 170 | * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'. |
171 | 171 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
172 | 172 | */ |
173 | -function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
174 | - return getpaid_template()->locate_template( $template_name, $template_path, $default_path ); |
|
173 | +function wpinv_locate_template($template_name, $template_path = '', $default_path = '') { |
|
174 | + return getpaid_template()->locate_template($template_name, $template_path, $default_path); |
|
175 | 175 | } |
176 | 176 | |
177 | -function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
|
178 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
177 | +function wpinv_get_template_part($slug, $name = null, $load = true) { |
|
178 | + do_action('get_template_part_' . $slug, $slug, $name); |
|
179 | 179 | |
180 | 180 | // Setup possible parts |
181 | 181 | $templates = array(); |
182 | - if ( isset( $name ) ) |
|
182 | + if (isset($name)) |
|
183 | 183 | $templates[] = $slug . '-' . $name . '.php'; |
184 | 184 | $templates[] = $slug . '.php'; |
185 | 185 | |
186 | 186 | // Allow template parts to be filtered |
187 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
187 | + $templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name); |
|
188 | 188 | |
189 | 189 | // Return the part that is found |
190 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
190 | + return wpinv_locate_tmpl($templates, $load, false); |
|
191 | 191 | } |
192 | 192 | |
193 | -function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
|
193 | +function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) { |
|
194 | 194 | // No file found yet |
195 | 195 | $located = false; |
196 | 196 | |
197 | 197 | // Try to find a template file |
198 | - foreach ( (array)$template_names as $template_name ) { |
|
198 | + foreach ((array) $template_names as $template_name) { |
|
199 | 199 | |
200 | 200 | // Continue if template is empty |
201 | - if ( empty( $template_name ) ) |
|
201 | + if (empty($template_name)) |
|
202 | 202 | continue; |
203 | 203 | |
204 | 204 | // Trim off any slashes from the template name |
205 | - $template_name = ltrim( $template_name, '/' ); |
|
205 | + $template_name = ltrim($template_name, '/'); |
|
206 | 206 | |
207 | 207 | // try locating this template file by looping through the template paths |
208 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
208 | + foreach (wpinv_get_theme_template_paths() as $template_path) { |
|
209 | 209 | |
210 | - if( file_exists( $template_path . $template_name ) ) { |
|
210 | + if (file_exists($template_path . $template_name)) { |
|
211 | 211 | $located = $template_path . $template_name; |
212 | 212 | break; |
213 | 213 | } |
214 | 214 | } |
215 | 215 | |
216 | - if( !empty( $located ) ) { |
|
216 | + if (!empty($located)) { |
|
217 | 217 | break; |
218 | 218 | } |
219 | 219 | } |
220 | 220 | |
221 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
222 | - load_template( $located, $require_once ); |
|
221 | + if ((true == $load) && !empty($located)) |
|
222 | + load_template($located, $require_once); |
|
223 | 223 | |
224 | 224 | return $located; |
225 | 225 | } |
@@ -228,155 +228,155 @@ discard block |
||
228 | 228 | $template_dir = wpinv_get_theme_template_dir_name(); |
229 | 229 | |
230 | 230 | $file_paths = array( |
231 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
232 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
231 | + 1 => trailingslashit(get_stylesheet_directory()) . $template_dir, |
|
232 | + 10 => trailingslashit(get_template_directory()) . $template_dir, |
|
233 | 233 | 100 => wpinv_get_templates_dir() |
234 | 234 | ); |
235 | 235 | |
236 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
236 | + $file_paths = apply_filters('wpinv_template_paths', $file_paths); |
|
237 | 237 | |
238 | 238 | // sort the file paths based on priority |
239 | - ksort( $file_paths, SORT_NUMERIC ); |
|
239 | + ksort($file_paths, SORT_NUMERIC); |
|
240 | 240 | |
241 | - return array_map( 'trailingslashit', $file_paths ); |
|
241 | + return array_map('trailingslashit', $file_paths); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | function wpinv_checkout_meta_tags() { |
245 | 245 | |
246 | 246 | $pages = array(); |
247 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
248 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
249 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
250 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
247 | + $pages[] = wpinv_get_option('success_page'); |
|
248 | + $pages[] = wpinv_get_option('failure_page'); |
|
249 | + $pages[] = wpinv_get_option('invoice_history_page'); |
|
250 | + $pages[] = wpinv_get_option('invoice_subscription_page'); |
|
251 | 251 | |
252 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
252 | + if (!wpinv_is_checkout() && !is_page($pages)) { |
|
253 | 253 | return; |
254 | 254 | } |
255 | 255 | |
256 | 256 | echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
257 | 257 | } |
258 | -add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
|
258 | +add_action('wp_head', 'wpinv_checkout_meta_tags'); |
|
259 | 259 | |
260 | -function wpinv_add_body_classes( $class ) { |
|
261 | - $classes = (array)$class; |
|
260 | +function wpinv_add_body_classes($class) { |
|
261 | + $classes = (array) $class; |
|
262 | 262 | |
263 | - if( wpinv_is_checkout() ) { |
|
263 | + if (wpinv_is_checkout()) { |
|
264 | 264 | $classes[] = 'wpinv-checkout'; |
265 | 265 | $classes[] = 'wpinv-page'; |
266 | 266 | } |
267 | 267 | |
268 | - if( wpinv_is_success_page() ) { |
|
268 | + if (wpinv_is_success_page()) { |
|
269 | 269 | $classes[] = 'wpinv-success'; |
270 | 270 | $classes[] = 'wpinv-page'; |
271 | 271 | } |
272 | 272 | |
273 | - if( wpinv_is_failed_transaction_page() ) { |
|
273 | + if (wpinv_is_failed_transaction_page()) { |
|
274 | 274 | $classes[] = 'wpinv-failed-transaction'; |
275 | 275 | $classes[] = 'wpinv-page'; |
276 | 276 | } |
277 | 277 | |
278 | - if( wpinv_is_invoice_history_page() ) { |
|
278 | + if (wpinv_is_invoice_history_page()) { |
|
279 | 279 | $classes[] = 'wpinv-history'; |
280 | 280 | $classes[] = 'wpinv-page'; |
281 | 281 | } |
282 | 282 | |
283 | - if( wpinv_is_subscriptions_history_page() ) { |
|
283 | + if (wpinv_is_subscriptions_history_page()) { |
|
284 | 284 | $classes[] = 'wpinv-subscription'; |
285 | 285 | $classes[] = 'wpinv-page'; |
286 | 286 | } |
287 | 287 | |
288 | - if( wpinv_is_test_mode() ) { |
|
288 | + if (wpinv_is_test_mode()) { |
|
289 | 289 | $classes[] = 'wpinv-test-mode'; |
290 | 290 | $classes[] = 'wpinv-page'; |
291 | 291 | } |
292 | 292 | |
293 | - return array_unique( $classes ); |
|
293 | + return array_unique($classes); |
|
294 | 294 | } |
295 | -add_filter( 'body_class', 'wpinv_add_body_classes' ); |
|
295 | +add_filter('body_class', 'wpinv_add_body_classes'); |
|
296 | 296 | |
297 | -function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) { |
|
298 | - $args = array( 'nopaging' => true ); |
|
297 | +function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') { |
|
298 | + $args = array('nopaging' => true); |
|
299 | 299 | |
300 | - if ( ! empty( $status ) ) |
|
300 | + if (!empty($status)) |
|
301 | 301 | $args['post_status'] = $status; |
302 | 302 | |
303 | - $discounts = wpinv_get_discounts( $args ); |
|
303 | + $discounts = wpinv_get_discounts($args); |
|
304 | 304 | $options = array(); |
305 | 305 | |
306 | - if ( $discounts ) { |
|
307 | - foreach ( $discounts as $discount ) { |
|
308 | - $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) ); |
|
306 | + if ($discounts) { |
|
307 | + foreach ($discounts as $discount) { |
|
308 | + $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID)); |
|
309 | 309 | } |
310 | 310 | } else { |
311 | - $options[0] = __( 'No discounts found', 'invoicing' ); |
|
311 | + $options[0] = __('No discounts found', 'invoicing'); |
|
312 | 312 | } |
313 | 313 | |
314 | - $output = wpinv_html_select( array( |
|
314 | + $output = wpinv_html_select(array( |
|
315 | 315 | 'name' => $name, |
316 | 316 | 'selected' => $selected, |
317 | 317 | 'options' => $options, |
318 | 318 | 'show_option_all' => false, |
319 | 319 | 'show_option_none' => false, |
320 | - ) ); |
|
320 | + )); |
|
321 | 321 | |
322 | 322 | return $output; |
323 | 323 | } |
324 | 324 | |
325 | -function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) { |
|
326 | - $current = date( 'Y' ); |
|
327 | - $start_year = $current - absint( $years_before ); |
|
328 | - $end_year = $current + absint( $years_after ); |
|
329 | - $selected = empty( $selected ) ? date( 'Y' ) : $selected; |
|
325 | +function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) { |
|
326 | + $current = date('Y'); |
|
327 | + $start_year = $current - absint($years_before); |
|
328 | + $end_year = $current + absint($years_after); |
|
329 | + $selected = empty($selected) ? date('Y') : $selected; |
|
330 | 330 | $options = array(); |
331 | 331 | |
332 | - while ( $start_year <= $end_year ) { |
|
333 | - $options[ absint( $start_year ) ] = $start_year; |
|
332 | + while ($start_year <= $end_year) { |
|
333 | + $options[absint($start_year)] = $start_year; |
|
334 | 334 | $start_year++; |
335 | 335 | } |
336 | 336 | |
337 | - $output = wpinv_html_select( array( |
|
337 | + $output = wpinv_html_select(array( |
|
338 | 338 | 'name' => $name, |
339 | 339 | 'selected' => $selected, |
340 | 340 | 'options' => $options, |
341 | 341 | 'show_option_all' => false, |
342 | 342 | 'show_option_none' => false |
343 | - ) ); |
|
343 | + )); |
|
344 | 344 | |
345 | 345 | return $output; |
346 | 346 | } |
347 | 347 | |
348 | -function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) { |
|
348 | +function wpinv_html_month_dropdown($name = 'month', $selected = 0) { |
|
349 | 349 | |
350 | 350 | $options = array( |
351 | - '1' => __( 'January', 'invoicing' ), |
|
352 | - '2' => __( 'February', 'invoicing' ), |
|
353 | - '3' => __( 'March', 'invoicing' ), |
|
354 | - '4' => __( 'April', 'invoicing' ), |
|
355 | - '5' => __( 'May', 'invoicing' ), |
|
356 | - '6' => __( 'June', 'invoicing' ), |
|
357 | - '7' => __( 'July', 'invoicing' ), |
|
358 | - '8' => __( 'August', 'invoicing' ), |
|
359 | - '9' => __( 'September', 'invoicing' ), |
|
360 | - '10' => __( 'October', 'invoicing' ), |
|
361 | - '11' => __( 'November', 'invoicing' ), |
|
362 | - '12' => __( 'December', 'invoicing' ), |
|
351 | + '1' => __('January', 'invoicing'), |
|
352 | + '2' => __('February', 'invoicing'), |
|
353 | + '3' => __('March', 'invoicing'), |
|
354 | + '4' => __('April', 'invoicing'), |
|
355 | + '5' => __('May', 'invoicing'), |
|
356 | + '6' => __('June', 'invoicing'), |
|
357 | + '7' => __('July', 'invoicing'), |
|
358 | + '8' => __('August', 'invoicing'), |
|
359 | + '9' => __('September', 'invoicing'), |
|
360 | + '10' => __('October', 'invoicing'), |
|
361 | + '11' => __('November', 'invoicing'), |
|
362 | + '12' => __('December', 'invoicing'), |
|
363 | 363 | ); |
364 | 364 | |
365 | 365 | // If no month is selected, default to the current month |
366 | - $selected = empty( $selected ) ? date( 'n' ) : $selected; |
|
366 | + $selected = empty($selected) ? date('n') : $selected; |
|
367 | 367 | |
368 | - $output = wpinv_html_select( array( |
|
368 | + $output = wpinv_html_select(array( |
|
369 | 369 | 'name' => $name, |
370 | 370 | 'selected' => $selected, |
371 | 371 | 'options' => $options, |
372 | 372 | 'show_option_all' => false, |
373 | 373 | 'show_option_none' => false |
374 | - ) ); |
|
374 | + )); |
|
375 | 375 | |
376 | 376 | return $output; |
377 | 377 | } |
378 | 378 | |
379 | -function wpinv_html_select( $args = array() ) { |
|
379 | +function wpinv_html_select($args = array()) { |
|
380 | 380 | $defaults = array( |
381 | 381 | 'options' => array(), |
382 | 382 | 'name' => null, |
@@ -385,8 +385,8 @@ discard block |
||
385 | 385 | 'selected' => 0, |
386 | 386 | 'placeholder' => null, |
387 | 387 | 'multiple' => false, |
388 | - 'show_option_all' => _x( 'All', 'all dropdown items', 'invoicing' ), |
|
389 | - 'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ), |
|
388 | + 'show_option_all' => _x('All', 'all dropdown items', 'invoicing'), |
|
389 | + 'show_option_none' => _x('None', 'no dropdown items', 'invoicing'), |
|
390 | 390 | 'data' => array(), |
391 | 391 | 'onchange' => null, |
392 | 392 | 'required' => false, |
@@ -394,74 +394,74 @@ discard block |
||
394 | 394 | 'readonly' => false, |
395 | 395 | ); |
396 | 396 | |
397 | - $args = wp_parse_args( $args, $defaults ); |
|
397 | + $args = wp_parse_args($args, $defaults); |
|
398 | 398 | |
399 | 399 | $data_elements = ''; |
400 | - foreach ( $args['data'] as $key => $value ) { |
|
401 | - $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
400 | + foreach ($args['data'] as $key => $value) { |
|
401 | + $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"'; |
|
402 | 402 | } |
403 | 403 | |
404 | - if( $args['multiple'] ) { |
|
404 | + if ($args['multiple']) { |
|
405 | 405 | $multiple = ' MULTIPLE'; |
406 | 406 | } else { |
407 | 407 | $multiple = ''; |
408 | 408 | } |
409 | 409 | |
410 | - if( $args['placeholder'] ) { |
|
410 | + if ($args['placeholder']) { |
|
411 | 411 | $placeholder = $args['placeholder']; |
412 | 412 | } else { |
413 | 413 | $placeholder = ''; |
414 | 414 | } |
415 | 415 | |
416 | 416 | $options = ''; |
417 | - if( !empty( $args['onchange'] ) ) { |
|
418 | - $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
417 | + if (!empty($args['onchange'])) { |
|
418 | + $options .= ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
419 | 419 | } |
420 | 420 | |
421 | - if( !empty( $args['required'] ) ) { |
|
421 | + if (!empty($args['required'])) { |
|
422 | 422 | $options .= ' required="required"'; |
423 | 423 | } |
424 | 424 | |
425 | - if( !empty( $args['disabled'] ) ) { |
|
425 | + if (!empty($args['disabled'])) { |
|
426 | 426 | $options .= ' disabled'; |
427 | 427 | } |
428 | 428 | |
429 | - if( !empty( $args['readonly'] ) ) { |
|
429 | + if (!empty($args['readonly'])) { |
|
430 | 430 | $options .= ' readonly'; |
431 | 431 | } |
432 | 432 | |
433 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
434 | - $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>'; |
|
433 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
434 | + $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>'; |
|
435 | 435 | |
436 | - if ( $args['show_option_all'] ) { |
|
437 | - if( $args['multiple'] ) { |
|
438 | - $selected = selected( true, in_array( 0, $args['selected'] ), false ); |
|
436 | + if ($args['show_option_all']) { |
|
437 | + if ($args['multiple']) { |
|
438 | + $selected = selected(true, in_array(0, $args['selected']), false); |
|
439 | 439 | } else { |
440 | - $selected = selected( $args['selected'], 0, false ); |
|
440 | + $selected = selected($args['selected'], 0, false); |
|
441 | 441 | } |
442 | - $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
442 | + $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>'; |
|
443 | 443 | } |
444 | 444 | |
445 | - if ( !empty( $args['options'] ) ) { |
|
445 | + if (!empty($args['options'])) { |
|
446 | 446 | |
447 | - if ( $args['show_option_none'] ) { |
|
448 | - if( $args['multiple'] ) { |
|
449 | - $selected = selected( true, in_array( "", $args['selected'] ), false ); |
|
447 | + if ($args['show_option_none']) { |
|
448 | + if ($args['multiple']) { |
|
449 | + $selected = selected(true, in_array("", $args['selected']), false); |
|
450 | 450 | } else { |
451 | - $selected = selected( $args['selected'] === "", true, false ); |
|
451 | + $selected = selected($args['selected'] === "", true, false); |
|
452 | 452 | } |
453 | - $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
453 | + $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>'; |
|
454 | 454 | } |
455 | 455 | |
456 | - foreach( $args['options'] as $key => $option ) { |
|
456 | + foreach ($args['options'] as $key => $option) { |
|
457 | 457 | |
458 | - if( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
459 | - $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false ); |
|
458 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
459 | + $selected = selected(true, (bool) in_array($key, $args['selected']), false); |
|
460 | 460 | } else { |
461 | - $selected = selected( $args['selected'], $key, false ); |
|
461 | + $selected = selected($args['selected'], $key, false); |
|
462 | 462 | } |
463 | 463 | |
464 | - $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>'; |
|
464 | + $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>'; |
|
465 | 465 | } |
466 | 466 | } |
467 | 467 | |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | return $output; |
471 | 471 | } |
472 | 472 | |
473 | -function wpinv_item_dropdown( $args = array() ) { |
|
473 | +function wpinv_item_dropdown($args = array()) { |
|
474 | 474 | $defaults = array( |
475 | 475 | 'name' => 'wpi_item', |
476 | 476 | 'id' => 'wpi_item', |
@@ -478,14 +478,14 @@ discard block |
||
478 | 478 | 'multiple' => false, |
479 | 479 | 'selected' => 0, |
480 | 480 | 'number' => 100, |
481 | - 'placeholder' => __( 'Choose a item', 'invoicing' ), |
|
482 | - 'data' => array( 'search-type' => 'item' ), |
|
481 | + 'placeholder' => __('Choose a item', 'invoicing'), |
|
482 | + 'data' => array('search-type' => 'item'), |
|
483 | 483 | 'show_option_all' => false, |
484 | 484 | 'show_option_none' => false, |
485 | 485 | 'show_recurring' => false, |
486 | 486 | ); |
487 | 487 | |
488 | - $args = wp_parse_args( $args, $defaults ); |
|
488 | + $args = wp_parse_args($args, $defaults); |
|
489 | 489 | |
490 | 490 | $item_args = array( |
491 | 491 | 'post_type' => 'wpi_item', |
@@ -494,44 +494,44 @@ discard block |
||
494 | 494 | 'posts_per_page' => $args['number'] |
495 | 495 | ); |
496 | 496 | |
497 | - $item_args = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults ); |
|
497 | + $item_args = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults); |
|
498 | 498 | |
499 | - $items = get_posts( $item_args ); |
|
499 | + $items = get_posts($item_args); |
|
500 | 500 | $options = array(); |
501 | - if ( $items ) { |
|
502 | - foreach ( $items as $item ) { |
|
503 | - $title = esc_html( $item->post_title ); |
|
501 | + if ($items) { |
|
502 | + foreach ($items as $item) { |
|
503 | + $title = esc_html($item->post_title); |
|
504 | 504 | |
505 | - if ( !empty( $args['show_recurring'] ) ) { |
|
506 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
505 | + if (!empty($args['show_recurring'])) { |
|
506 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
507 | 507 | } |
508 | 508 | |
509 | - $options[ absint( $item->ID ) ] = $title; |
|
509 | + $options[absint($item->ID)] = $title; |
|
510 | 510 | } |
511 | 511 | } |
512 | 512 | |
513 | 513 | // This ensures that any selected items are included in the drop down |
514 | - if( is_array( $args['selected'] ) ) { |
|
515 | - foreach( $args['selected'] as $item ) { |
|
516 | - if( ! in_array( $item, $options ) ) { |
|
517 | - $title = get_the_title( $item ); |
|
518 | - if ( !empty( $args['show_recurring'] ) ) { |
|
519 | - $title .= wpinv_get_item_suffix( $item, false ); |
|
514 | + if (is_array($args['selected'])) { |
|
515 | + foreach ($args['selected'] as $item) { |
|
516 | + if (!in_array($item, $options)) { |
|
517 | + $title = get_the_title($item); |
|
518 | + if (!empty($args['show_recurring'])) { |
|
519 | + $title .= wpinv_get_item_suffix($item, false); |
|
520 | 520 | } |
521 | 521 | $options[$item] = $title; |
522 | 522 | } |
523 | 523 | } |
524 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
525 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
526 | - $title = get_the_title( $args['selected'] ); |
|
527 | - if ( !empty( $args['show_recurring'] ) ) { |
|
528 | - $title .= wpinv_get_item_suffix( $args['selected'], false ); |
|
524 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
525 | + if (!in_array($args['selected'], $options)) { |
|
526 | + $title = get_the_title($args['selected']); |
|
527 | + if (!empty($args['show_recurring'])) { |
|
528 | + $title .= wpinv_get_item_suffix($args['selected'], false); |
|
529 | 529 | } |
530 | - $options[$args['selected']] = get_the_title( $args['selected'] ); |
|
530 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
531 | 531 | } |
532 | 532 | } |
533 | 533 | |
534 | - $output = wpinv_html_select( array( |
|
534 | + $output = wpinv_html_select(array( |
|
535 | 535 | 'name' => $args['name'], |
536 | 536 | 'selected' => $args['selected'], |
537 | 537 | 'id' => $args['id'], |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | 'show_option_all' => $args['show_option_all'], |
543 | 543 | 'show_option_none' => $args['show_option_none'], |
544 | 544 | 'data' => $args['data'], |
545 | - ) ); |
|
545 | + )); |
|
546 | 546 | |
547 | 547 | return $output; |
548 | 548 | } |
@@ -562,16 +562,16 @@ discard block |
||
562 | 562 | ); |
563 | 563 | |
564 | 564 | $options = array(); |
565 | - if ( $items ) { |
|
566 | - foreach ( $items as $item ) { |
|
567 | - $options[ $item->ID ] = esc_html( $item->post_title ) . wpinv_get_item_suffix( $item->ID, false ); |
|
565 | + if ($items) { |
|
566 | + foreach ($items as $item) { |
|
567 | + $options[$item->ID] = esc_html($item->post_title) . wpinv_get_item_suffix($item->ID, false); |
|
568 | 568 | } |
569 | 569 | } |
570 | 570 | |
571 | 571 | return $options; |
572 | 572 | } |
573 | 573 | |
574 | -function wpinv_html_checkbox( $args = array() ) { |
|
574 | +function wpinv_html_checkbox($args = array()) { |
|
575 | 575 | $defaults = array( |
576 | 576 | 'name' => null, |
577 | 577 | 'current' => null, |
@@ -582,17 +582,17 @@ discard block |
||
582 | 582 | ) |
583 | 583 | ); |
584 | 584 | |
585 | - $args = wp_parse_args( $args, $defaults ); |
|
585 | + $args = wp_parse_args($args, $defaults); |
|
586 | 586 | |
587 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
587 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
588 | 588 | $options = ''; |
589 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
589 | + if (!empty($args['options']['disabled'])) { |
|
590 | 590 | $options .= ' disabled="disabled"'; |
591 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
591 | + } elseif (!empty($args['options']['readonly'])) { |
|
592 | 592 | $options .= ' readonly'; |
593 | 593 | } |
594 | 594 | |
595 | - $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />'; |
|
595 | + $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />'; |
|
596 | 596 | |
597 | 597 | return $output; |
598 | 598 | } |
@@ -600,30 +600,30 @@ discard block |
||
600 | 600 | /** |
601 | 601 | * Displays a hidden field. |
602 | 602 | */ |
603 | -function getpaid_hidden_field( $name, $value ) { |
|
604 | - $name = sanitize_text_field( $name ); |
|
605 | - $value = esc_attr( $value ); |
|
603 | +function getpaid_hidden_field($name, $value) { |
|
604 | + $name = sanitize_text_field($name); |
|
605 | + $value = esc_attr($value); |
|
606 | 606 | |
607 | 607 | echo "<input type='hidden' name='$name' value='$value' />"; |
608 | 608 | } |
609 | 609 | |
610 | -function wpinv_html_text( $args = array() ) { |
|
610 | +function wpinv_html_text($args = array()) { |
|
611 | 611 | // Backwards compatibility |
612 | - if ( func_num_args() > 1 ) { |
|
612 | + if (func_num_args() > 1) { |
|
613 | 613 | $args = func_get_args(); |
614 | 614 | |
615 | 615 | $name = $args[0]; |
616 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
617 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
618 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
616 | + $value = isset($args[1]) ? $args[1] : ''; |
|
617 | + $label = isset($args[2]) ? $args[2] : ''; |
|
618 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
619 | 619 | } |
620 | 620 | |
621 | 621 | $defaults = array( |
622 | 622 | 'id' => '', |
623 | - 'name' => isset( $name ) ? $name : 'text', |
|
624 | - 'value' => isset( $value ) ? $value : null, |
|
625 | - 'label' => isset( $label ) ? $label : null, |
|
626 | - 'desc' => isset( $desc ) ? $desc : null, |
|
623 | + 'name' => isset($name) ? $name : 'text', |
|
624 | + 'value' => isset($value) ? $value : null, |
|
625 | + 'label' => isset($label) ? $label : null, |
|
626 | + 'desc' => isset($desc) ? $desc : null, |
|
627 | 627 | 'placeholder' => '', |
628 | 628 | 'class' => 'regular-text', |
629 | 629 | 'disabled' => false, |
@@ -633,51 +633,51 @@ discard block |
||
633 | 633 | 'data' => false |
634 | 634 | ); |
635 | 635 | |
636 | - $args = wp_parse_args( $args, $defaults ); |
|
636 | + $args = wp_parse_args($args, $defaults); |
|
637 | 637 | |
638 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
638 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
639 | 639 | $options = ''; |
640 | - if( $args['required'] ) { |
|
640 | + if ($args['required']) { |
|
641 | 641 | $options .= ' required="required"'; |
642 | 642 | } |
643 | - if( $args['readonly'] ) { |
|
643 | + if ($args['readonly']) { |
|
644 | 644 | $options .= ' readonly'; |
645 | 645 | } |
646 | - if( $args['readonly'] ) { |
|
646 | + if ($args['readonly']) { |
|
647 | 647 | $options .= ' readonly'; |
648 | 648 | } |
649 | 649 | |
650 | 650 | $data = ''; |
651 | - if ( !empty( $args['data'] ) ) { |
|
652 | - foreach ( $args['data'] as $key => $value ) { |
|
653 | - $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" '; |
|
651 | + if (!empty($args['data'])) { |
|
652 | + foreach ($args['data'] as $key => $value) { |
|
653 | + $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" '; |
|
654 | 654 | } |
655 | 655 | } |
656 | 656 | |
657 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
658 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
659 | - if ( ! empty( $args['desc'] ) ) { |
|
660 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
657 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
658 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>'; |
|
659 | + if (!empty($args['desc'])) { |
|
660 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
661 | 661 | } |
662 | 662 | |
663 | - $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>'; |
|
663 | + $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>'; |
|
664 | 664 | |
665 | 665 | $output .= '</span>'; |
666 | 666 | |
667 | 667 | return $output; |
668 | 668 | } |
669 | 669 | |
670 | -function wpinv_html_date_field( $args = array() ) { |
|
671 | - if( empty( $args['class'] ) ) { |
|
670 | +function wpinv_html_date_field($args = array()) { |
|
671 | + if (empty($args['class'])) { |
|
672 | 672 | $args['class'] = 'wpiDatepicker'; |
673 | - } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) { |
|
673 | + } elseif (!strpos($args['class'], 'wpiDatepicker')) { |
|
674 | 674 | $args['class'] .= ' wpiDatepicker'; |
675 | 675 | } |
676 | 676 | |
677 | - return wpinv_html_text( $args ); |
|
677 | + return wpinv_html_text($args); |
|
678 | 678 | } |
679 | 679 | |
680 | -function wpinv_html_textarea( $args = array() ) { |
|
680 | +function wpinv_html_textarea($args = array()) { |
|
681 | 681 | $defaults = array( |
682 | 682 | 'name' => 'textarea', |
683 | 683 | 'value' => null, |
@@ -688,31 +688,31 @@ discard block |
||
688 | 688 | 'placeholder' => '', |
689 | 689 | ); |
690 | 690 | |
691 | - $args = wp_parse_args( $args, $defaults ); |
|
691 | + $args = wp_parse_args($args, $defaults); |
|
692 | 692 | |
693 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
693 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
694 | 694 | $disabled = ''; |
695 | - if( $args['disabled'] ) { |
|
695 | + if ($args['disabled']) { |
|
696 | 696 | $disabled = ' disabled="disabled"'; |
697 | 697 | } |
698 | 698 | |
699 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
700 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
701 | - $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
699 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
700 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>'; |
|
701 | + $output .= '<textarea name="' . esc_attr($args['name']) . '" placeholder="' . esc_attr($args['placeholder']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>'; |
|
702 | 702 | |
703 | - if ( ! empty( $args['desc'] ) ) { |
|
704 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
703 | + if (!empty($args['desc'])) { |
|
704 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
705 | 705 | } |
706 | 706 | $output .= '</span>'; |
707 | 707 | |
708 | 708 | return $output; |
709 | 709 | } |
710 | 710 | |
711 | -function wpinv_html_ajax_user_search( $args = array() ) { |
|
711 | +function wpinv_html_ajax_user_search($args = array()) { |
|
712 | 712 | $defaults = array( |
713 | 713 | 'name' => 'user_id', |
714 | 714 | 'value' => null, |
715 | - 'placeholder' => __( 'Enter username', 'invoicing' ), |
|
715 | + 'placeholder' => __('Enter username', 'invoicing'), |
|
716 | 716 | 'label' => null, |
717 | 717 | 'desc' => null, |
718 | 718 | 'class' => '', |
@@ -721,13 +721,13 @@ discard block |
||
721 | 721 | 'data' => false |
722 | 722 | ); |
723 | 723 | |
724 | - $args = wp_parse_args( $args, $defaults ); |
|
724 | + $args = wp_parse_args($args, $defaults); |
|
725 | 725 | |
726 | 726 | $args['class'] = 'wpinv-ajax-user-search ' . $args['class']; |
727 | 727 | |
728 | 728 | $output = '<span class="wpinv_user_search_wrap">'; |
729 | - $output .= wpinv_html_text( $args ); |
|
730 | - $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>'; |
|
729 | + $output .= wpinv_html_text($args); |
|
730 | + $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>'; |
|
731 | 731 | $output .= '</span>'; |
732 | 732 | |
733 | 733 | return $output; |
@@ -743,20 +743,20 @@ discard block |
||
743 | 743 | * |
744 | 744 | * @param string $template the template that is currently being used. |
745 | 745 | */ |
746 | -function wpinv_template( $template ) { |
|
746 | +function wpinv_template($template) { |
|
747 | 747 | global $post; |
748 | 748 | |
749 | - if ( ! is_admin() && ( is_single() || is_404() ) && ! empty( $post->ID ) && getpaid_is_invoice_post_type( get_post_type( $post->ID ) ) ) { |
|
749 | + if (!is_admin() && (is_single() || is_404()) && !empty($post->ID) && getpaid_is_invoice_post_type(get_post_type($post->ID))) { |
|
750 | 750 | |
751 | 751 | // If the user can view this invoice, display it. |
752 | - if ( wpinv_user_can_view_invoice( $post->ID ) ) { |
|
752 | + if (wpinv_user_can_view_invoice($post->ID)) { |
|
753 | 753 | |
754 | - return wpinv_get_template_part( 'wpinv-invoice-print', false, false ); |
|
754 | + return wpinv_get_template_part('wpinv-invoice-print', false, false); |
|
755 | 755 | |
756 | 756 | // Else display an error message. |
757 | 757 | } else { |
758 | 758 | |
759 | - return wpinv_get_template_part( 'wpinv-invalid-access', false, false ); |
|
759 | + return wpinv_get_template_part('wpinv-invalid-access', false, false); |
|
760 | 760 | |
761 | 761 | } |
762 | 762 | |
@@ -764,46 +764,46 @@ discard block |
||
764 | 764 | |
765 | 765 | return $template; |
766 | 766 | } |
767 | -add_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
767 | +add_filter('template_include', 'wpinv_template', 10, 1); |
|
768 | 768 | |
769 | 769 | function wpinv_get_business_address() { |
770 | 770 | $business_address = wpinv_store_address(); |
771 | - $business_address = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : ''; |
|
771 | + $business_address = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : ''; |
|
772 | 772 | |
773 | 773 | $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : ''; |
774 | 774 | |
775 | - return apply_filters( 'wpinv_get_business_address', $business_address ); |
|
775 | + return apply_filters('wpinv_get_business_address', $business_address); |
|
776 | 776 | } |
777 | 777 | |
778 | 778 | /** |
779 | 779 | * Displays the company address. |
780 | 780 | */ |
781 | 781 | function wpinv_display_from_address() { |
782 | - wpinv_get_template( 'invoice/company-address.php' ); |
|
782 | + wpinv_get_template('invoice/company-address.php'); |
|
783 | 783 | } |
784 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_from_address', 10 ); |
|
784 | +add_action('getpaid_invoice_details_left', 'wpinv_display_from_address', 10); |
|
785 | 785 | |
786 | -function wpinv_watermark( $id = 0 ) { |
|
787 | - $output = wpinv_get_watermark( $id ); |
|
788 | - return apply_filters( 'wpinv_get_watermark', $output, $id ); |
|
786 | +function wpinv_watermark($id = 0) { |
|
787 | + $output = wpinv_get_watermark($id); |
|
788 | + return apply_filters('wpinv_get_watermark', $output, $id); |
|
789 | 789 | } |
790 | 790 | |
791 | -function wpinv_get_watermark( $id ) { |
|
792 | - if ( !$id > 0 ) { |
|
791 | +function wpinv_get_watermark($id) { |
|
792 | + if (!$id > 0) { |
|
793 | 793 | return NULL; |
794 | 794 | } |
795 | 795 | |
796 | - $invoice = wpinv_get_invoice( $id ); |
|
796 | + $invoice = wpinv_get_invoice($id); |
|
797 | 797 | |
798 | - if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) { |
|
799 | - if ( $invoice->is_paid() ) { |
|
800 | - return __( 'Paid', 'invoicing' ); |
|
798 | + if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) { |
|
799 | + if ($invoice->is_paid()) { |
|
800 | + return __('Paid', 'invoicing'); |
|
801 | 801 | } |
802 | - if ( $invoice->is_refunded() ) { |
|
803 | - return __( 'Refunded', 'invoicing' ); |
|
802 | + if ($invoice->is_refunded()) { |
|
803 | + return __('Refunded', 'invoicing'); |
|
804 | 804 | } |
805 | - if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) { |
|
806 | - return __( 'Cancelled', 'invoicing' ); |
|
805 | + if ($invoice->has_status(array('wpi-cancelled'))) { |
|
806 | + return __('Cancelled', 'invoicing'); |
|
807 | 807 | } |
808 | 808 | } |
809 | 809 | |
@@ -813,30 +813,30 @@ discard block |
||
813 | 813 | /** |
814 | 814 | * @deprecated |
815 | 815 | */ |
816 | -function wpinv_display_invoice_details( $invoice ) { |
|
817 | - return getpaid_invoice_meta( $invoice ); |
|
816 | +function wpinv_display_invoice_details($invoice) { |
|
817 | + return getpaid_invoice_meta($invoice); |
|
818 | 818 | } |
819 | 819 | |
820 | 820 | /** |
821 | 821 | * Displays invoice meta. |
822 | 822 | */ |
823 | -function getpaid_invoice_meta( $invoice ) { |
|
823 | +function getpaid_invoice_meta($invoice) { |
|
824 | 824 | |
825 | - $invoice = new WPInv_Invoice( $invoice ); |
|
825 | + $invoice = new WPInv_Invoice($invoice); |
|
826 | 826 | |
827 | 827 | // Ensure that we have an invoice. |
828 | - if ( 0 == $invoice->get_id() ) { |
|
828 | + if (0 == $invoice->get_id()) { |
|
829 | 829 | return; |
830 | 830 | } |
831 | 831 | |
832 | 832 | // Get the invoice meta. |
833 | - $meta = getpaid_get_invoice_meta( $invoice ); |
|
833 | + $meta = getpaid_get_invoice_meta($invoice); |
|
834 | 834 | |
835 | 835 | // Display the meta. |
836 | - wpinv_get_template( 'invoice/invoice-meta.php', compact( 'invoice', 'meta' ) ); |
|
836 | + wpinv_get_template('invoice/invoice-meta.php', compact('invoice', 'meta')); |
|
837 | 837 | |
838 | 838 | } |
839 | -add_action( 'getpaid_invoice_details_right', 'getpaid_invoice_meta', 10 ); |
|
839 | +add_action('getpaid_invoice_details_right', 'getpaid_invoice_meta', 10); |
|
840 | 840 | |
841 | 841 | /** |
842 | 842 | * Retrieves the address markup to use on Invoices. |
@@ -848,29 +848,29 @@ discard block |
||
848 | 848 | * @param string $separator How to separate address lines. |
849 | 849 | * @return string |
850 | 850 | */ |
851 | -function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) { |
|
851 | +function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') { |
|
852 | 852 | |
853 | 853 | // Retrieve the address markup... |
854 | - $country= empty( $billing_details['country'] ) ? '' : $billing_details['country']; |
|
855 | - $format = wpinv_get_full_address_format( $country ); |
|
854 | + $country = empty($billing_details['country']) ? '' : $billing_details['country']; |
|
855 | + $format = wpinv_get_full_address_format($country); |
|
856 | 856 | |
857 | 857 | // ... and the replacements. |
858 | - $replacements = wpinv_get_invoice_address_replacements( $billing_details ); |
|
858 | + $replacements = wpinv_get_invoice_address_replacements($billing_details); |
|
859 | 859 | |
860 | - $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
|
860 | + $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format); |
|
861 | 861 | |
862 | 862 | // Remove unavailable tags. |
863 | - $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address ); |
|
863 | + $formatted_address = preg_replace("/\{\{\w+\}\}/", '', $formatted_address); |
|
864 | 864 | |
865 | 865 | // Clean up white space. |
866 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
867 | - $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
|
866 | + $formatted_address = preg_replace('/ +/', ' ', trim($formatted_address)); |
|
867 | + $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address); |
|
868 | 868 | |
869 | 869 | // Break newlines apart and remove empty lines/trim commas and white space. |
870 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
870 | + $formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address))); |
|
871 | 871 | |
872 | 872 | // Add html breaks. |
873 | - $formatted_address = implode( $separator, $formatted_address ); |
|
873 | + $formatted_address = implode($separator, $formatted_address); |
|
874 | 874 | |
875 | 875 | // We're done! |
876 | 876 | return $formatted_address; |
@@ -882,88 +882,88 @@ discard block |
||
882 | 882 | * |
883 | 883 | * @param WPInv_Invoice $invoice |
884 | 884 | */ |
885 | -function wpinv_display_to_address( $invoice = 0 ) { |
|
886 | - if ( ! empty( $invoice ) ) { |
|
887 | - wpinv_get_template( 'invoice/billing-address.php', compact( 'invoice' ) ); |
|
885 | +function wpinv_display_to_address($invoice = 0) { |
|
886 | + if (!empty($invoice)) { |
|
887 | + wpinv_get_template('invoice/billing-address.php', compact('invoice')); |
|
888 | 888 | } |
889 | 889 | } |
890 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_to_address', 40 ); |
|
890 | +add_action('getpaid_invoice_details_left', 'wpinv_display_to_address', 40); |
|
891 | 891 | |
892 | 892 | |
893 | 893 | /** |
894 | 894 | * Displays invoice line items. |
895 | 895 | */ |
896 | -function wpinv_display_line_items( $invoice_id = 0 ) { |
|
896 | +function wpinv_display_line_items($invoice_id = 0) { |
|
897 | 897 | |
898 | 898 | // Prepare the invoice. |
899 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
899 | + $invoice = new WPInv_Invoice($invoice_id); |
|
900 | 900 | |
901 | 901 | // Abort if there is no invoice. |
902 | - if ( 0 == $invoice->get_id() ) { |
|
902 | + if (0 == $invoice->get_id()) { |
|
903 | 903 | return; |
904 | 904 | } |
905 | 905 | |
906 | 906 | // Line item columns. |
907 | - $columns = getpaid_invoice_item_columns( $invoice ); |
|
908 | - $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice ); |
|
907 | + $columns = getpaid_invoice_item_columns($invoice); |
|
908 | + $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice); |
|
909 | 909 | |
910 | - wpinv_get_template( 'invoice/line-items.php', compact( 'invoice', 'columns' ) ); |
|
910 | + wpinv_get_template('invoice/line-items.php', compact('invoice', 'columns')); |
|
911 | 911 | } |
912 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_line_items', 10 ); |
|
912 | +add_action('getpaid_invoice_line_items', 'wpinv_display_line_items', 10); |
|
913 | 913 | |
914 | 914 | /** |
915 | 915 | * Displays invoice notices on invoices. |
916 | 916 | */ |
917 | 917 | function wpinv_display_invoice_notice() { |
918 | 918 | |
919 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
920 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
919 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
920 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
921 | 921 | |
922 | - if ( empty( $label ) && empty( $notice ) ) { |
|
922 | + if (empty($label) && empty($notice)) { |
|
923 | 923 | return; |
924 | 924 | } |
925 | 925 | |
926 | 926 | echo '<div class="mt-4 mb-4 wpinv-vat-notice">'; |
927 | 927 | |
928 | - if ( ! empty( $label ) ) { |
|
929 | - $label = sanitize_text_field( $label ); |
|
928 | + if (!empty($label)) { |
|
929 | + $label = sanitize_text_field($label); |
|
930 | 930 | echo "<h5>$label</h5>"; |
931 | 931 | } |
932 | 932 | |
933 | - if ( ! empty( $notice ) ) { |
|
934 | - echo '<small class="form-text text-muted">' . wpautop( wptexturize( $notice ) ) . '</small>'; |
|
933 | + if (!empty($notice)) { |
|
934 | + echo '<small class="form-text text-muted">' . wpautop(wptexturize($notice)) . '</small>'; |
|
935 | 935 | } |
936 | 936 | |
937 | 937 | echo '</div>'; |
938 | 938 | } |
939 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100 ); |
|
939 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100); |
|
940 | 940 | |
941 | 941 | /** |
942 | 942 | * @param WPInv_Invoice $invoice |
943 | 943 | */ |
944 | -function wpinv_display_invoice_notes( $invoice ) { |
|
944 | +function wpinv_display_invoice_notes($invoice) { |
|
945 | 945 | |
946 | 946 | // Retrieve the notes. |
947 | - $notes = wpinv_get_invoice_notes( $invoice->get_id(), 'customer' ); |
|
947 | + $notes = wpinv_get_invoice_notes($invoice->get_id(), 'customer'); |
|
948 | 948 | |
949 | 949 | // Abort if we have non. |
950 | - if ( empty( $notes ) ) { |
|
950 | + if (empty($notes)) { |
|
951 | 951 | return; |
952 | 952 | } |
953 | 953 | |
954 | 954 | // Echo the note. |
955 | 955 | echo '<div class="getpaid-invoice-notes-wrapper border position-relative w-100 mb-4 p-0">'; |
956 | - echo '<h3 class="getpaid-invoice-notes-title text-dark bg-light border-bottom m-0 d-block">' . __( 'Notes', 'invoicing' ) .'</h3>'; |
|
956 | + echo '<h3 class="getpaid-invoice-notes-title text-dark bg-light border-bottom m-0 d-block">' . __('Notes', 'invoicing') . '</h3>'; |
|
957 | 957 | echo '<ul class="getpaid-invoice-notes mt-4 p-0">'; |
958 | 958 | |
959 | - foreach( $notes as $note ) { |
|
960 | - wpinv_get_invoice_note_line_item( $note ); |
|
959 | + foreach ($notes as $note) { |
|
960 | + wpinv_get_invoice_note_line_item($note); |
|
961 | 961 | } |
962 | 962 | |
963 | 963 | echo '</ul>'; |
964 | 964 | echo '</div>'; |
965 | 965 | } |
966 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60 ); |
|
966 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60); |
|
967 | 967 | |
968 | 968 | /** |
969 | 969 | * Loads scripts on our invoice templates. |
@@ -971,32 +971,32 @@ discard block |
||
971 | 971 | function wpinv_display_style() { |
972 | 972 | |
973 | 973 | // Make sure that all scripts have been loaded. |
974 | - if ( ! did_action( 'wp_enqueue_scripts' ) ) { |
|
975 | - do_action( 'wp_enqueue_scripts' ); |
|
974 | + if (!did_action('wp_enqueue_scripts')) { |
|
975 | + do_action('wp_enqueue_scripts'); |
|
976 | 976 | } |
977 | 977 | |
978 | 978 | // Register the invoices style. |
979 | - wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice.css' ) ); |
|
979 | + wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice.css')); |
|
980 | 980 | |
981 | 981 | // Load required styles |
982 | - wp_print_styles( 'open-sans' ); |
|
983 | - wp_print_styles( 'wpinv-single-style' ); |
|
984 | - wp_print_styles( 'ayecode-ui' ); |
|
982 | + wp_print_styles('open-sans'); |
|
983 | + wp_print_styles('wpinv-single-style'); |
|
984 | + wp_print_styles('ayecode-ui'); |
|
985 | 985 | |
986 | 986 | // Maybe load custom css. |
987 | - $custom_css = wpinv_get_option( 'template_custom_css' ); |
|
987 | + $custom_css = wpinv_get_option('template_custom_css'); |
|
988 | 988 | |
989 | - if ( isset( $custom_css ) && ! empty( $custom_css ) ) { |
|
990 | - $custom_css = wp_kses( $custom_css, array( '\'', '\"' ) ); |
|
991 | - $custom_css = str_replace( '>', '>', $custom_css ); |
|
989 | + if (isset($custom_css) && !empty($custom_css)) { |
|
990 | + $custom_css = wp_kses($custom_css, array('\'', '\"')); |
|
991 | + $custom_css = str_replace('>', '>', $custom_css); |
|
992 | 992 | echo '<style type="text/css">'; |
993 | 993 | echo $custom_css; |
994 | 994 | echo '</style>'; |
995 | 995 | } |
996 | 996 | |
997 | 997 | } |
998 | -add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
999 | -add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' ); |
|
998 | +add_action('wpinv_invoice_print_head', 'wpinv_display_style'); |
|
999 | +add_action('wpinv_invalid_invoice_head', 'wpinv_display_style'); |
|
1000 | 1000 | |
1001 | 1001 | |
1002 | 1002 | /** |
@@ -1008,41 +1008,41 @@ discard block |
||
1008 | 1008 | // Retrieve the current invoice. |
1009 | 1009 | $invoice_id = getpaid_get_current_invoice_id(); |
1010 | 1010 | |
1011 | - if ( empty( $invoice_id ) ) { |
|
1011 | + if (empty($invoice_id)) { |
|
1012 | 1012 | |
1013 | 1013 | return aui()->alert( |
1014 | 1014 | array( |
1015 | 1015 | 'type' => 'warning', |
1016 | - 'content' => __( 'Invalid invoice', 'invoicing' ), |
|
1016 | + 'content' => __('Invalid invoice', 'invoicing'), |
|
1017 | 1017 | ) |
1018 | 1018 | ); |
1019 | 1019 | |
1020 | 1020 | } |
1021 | 1021 | |
1022 | 1022 | // Can the user view this invoice? |
1023 | - if ( ! wpinv_user_can_view_invoice( $invoice_id ) ) { |
|
1023 | + if (!wpinv_user_can_view_invoice($invoice_id)) { |
|
1024 | 1024 | |
1025 | 1025 | return aui()->alert( |
1026 | 1026 | array( |
1027 | 1027 | 'type' => 'warning', |
1028 | - 'content' => __( 'You are not allowed to view this invoice', 'invoicing' ), |
|
1028 | + 'content' => __('You are not allowed to view this invoice', 'invoicing'), |
|
1029 | 1029 | ) |
1030 | 1030 | ); |
1031 | 1031 | |
1032 | 1032 | } |
1033 | 1033 | |
1034 | 1034 | // Ensure that it is not yet paid for. |
1035 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
1035 | + $invoice = new WPInv_Invoice($invoice_id); |
|
1036 | 1036 | |
1037 | 1037 | // Maybe mark it as viewed. |
1038 | - getpaid_maybe_mark_invoice_as_viewed( $invoice ); |
|
1038 | + getpaid_maybe_mark_invoice_as_viewed($invoice); |
|
1039 | 1039 | |
1040 | - if ( $invoice->is_paid() ) { |
|
1040 | + if ($invoice->is_paid()) { |
|
1041 | 1041 | |
1042 | 1042 | return aui()->alert( |
1043 | 1043 | array( |
1044 | 1044 | 'type' => 'success', |
1045 | - 'content' => __( 'This invoice has already been paid.', 'invoicing' ), |
|
1045 | + 'content' => __('This invoice has already been paid.', 'invoicing'), |
|
1046 | 1046 | ) |
1047 | 1047 | ); |
1048 | 1048 | |
@@ -1052,14 +1052,14 @@ discard block |
||
1052 | 1052 | $wpi_checkout_id = $invoice_id; |
1053 | 1053 | |
1054 | 1054 | // We'll display this invoice via the default form. |
1055 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1055 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1056 | 1056 | |
1057 | - if ( 0 == $form->get_id() ) { |
|
1057 | + if (0 == $form->get_id()) { |
|
1058 | 1058 | |
1059 | 1059 | return aui()->alert( |
1060 | 1060 | array( |
1061 | 1061 | 'type' => 'warning', |
1062 | - 'content' => __( 'Error loading the payment form', 'invoicing' ), |
|
1062 | + 'content' => __('Error loading the payment form', 'invoicing'), |
|
1063 | 1063 | ) |
1064 | 1064 | ); |
1065 | 1065 | |
@@ -1067,7 +1067,7 @@ discard block |
||
1067 | 1067 | |
1068 | 1068 | // Set the invoice. |
1069 | 1069 | $form->invoice = $invoice; |
1070 | - $form->set_items( $invoice->get_items() ); |
|
1070 | + $form->set_items($invoice->get_items()); |
|
1071 | 1071 | |
1072 | 1072 | // Generate the html. |
1073 | 1073 | return $form->get_html(); |
@@ -1075,7 +1075,7 @@ discard block |
||
1075 | 1075 | } |
1076 | 1076 | |
1077 | 1077 | function wpinv_empty_cart_message() { |
1078 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1078 | + return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>'); |
|
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | /** |
@@ -1092,38 +1092,38 @@ discard block |
||
1092 | 1092 | ) |
1093 | 1093 | ); |
1094 | 1094 | } |
1095 | -add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
1095 | +add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart'); |
|
1096 | 1096 | |
1097 | -function wpinv_receipt_billing_address( $invoice_id = 0 ) { |
|
1098 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1097 | +function wpinv_receipt_billing_address($invoice_id = 0) { |
|
1098 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1099 | 1099 | |
1100 | - if ( empty( $invoice ) ) { |
|
1100 | + if (empty($invoice)) { |
|
1101 | 1101 | return NULL; |
1102 | 1102 | } |
1103 | 1103 | |
1104 | 1104 | $billing_details = $invoice->get_user_info(); |
1105 | - $address_row = wpinv_get_invoice_address_markup( $billing_details ); |
|
1105 | + $address_row = wpinv_get_invoice_address_markup($billing_details); |
|
1106 | 1106 | |
1107 | 1107 | ob_start(); |
1108 | 1108 | ?> |
1109 | 1109 | <table class="table table-bordered table-sm wpi-billing-details"> |
1110 | 1110 | <tbody> |
1111 | 1111 | <tr class="wpi-receipt-name"> |
1112 | - <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th> |
|
1113 | - <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td> |
|
1112 | + <th class="text-left"><?php _e('Name', 'invoicing'); ?></th> |
|
1113 | + <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td> |
|
1114 | 1114 | </tr> |
1115 | 1115 | <tr class="wpi-receipt-email"> |
1116 | - <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th> |
|
1117 | - <td><?php echo $billing_details['email'] ;?></td> |
|
1116 | + <th class="text-left"><?php _e('Email', 'invoicing'); ?></th> |
|
1117 | + <td><?php echo $billing_details['email']; ?></td> |
|
1118 | 1118 | </tr> |
1119 | 1119 | <tr class="wpi-receipt-address"> |
1120 | - <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th> |
|
1121 | - <td><?php echo $address_row ;?></td> |
|
1120 | + <th class="text-left"><?php _e('Address', 'invoicing'); ?></th> |
|
1121 | + <td><?php echo $address_row; ?></td> |
|
1122 | 1122 | </tr> |
1123 | - <?php if ( $billing_details['phone'] ) { ?> |
|
1123 | + <?php if ($billing_details['phone']) { ?> |
|
1124 | 1124 | <tr class="wpi-receipt-phone"> |
1125 | - <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th> |
|
1126 | - <td><?php echo esc_html( $billing_details['phone'] ) ;?></td> |
|
1125 | + <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th> |
|
1126 | + <td><?php echo esc_html($billing_details['phone']); ?></td> |
|
1127 | 1127 | </tr> |
1128 | 1128 | <?php } ?> |
1129 | 1129 | </tbody> |
@@ -1131,7 +1131,7 @@ discard block |
||
1131 | 1131 | <?php |
1132 | 1132 | $output = ob_get_clean(); |
1133 | 1133 | |
1134 | - $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id ); |
|
1134 | + $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id); |
|
1135 | 1135 | |
1136 | 1136 | echo $output; |
1137 | 1137 | } |
@@ -1139,66 +1139,66 @@ discard block |
||
1139 | 1139 | /** |
1140 | 1140 | * Filters the receipt page. |
1141 | 1141 | */ |
1142 | -function wpinv_filter_success_page_content( $content ) { |
|
1142 | +function wpinv_filter_success_page_content($content) { |
|
1143 | 1143 | |
1144 | 1144 | // Ensure this is our page. |
1145 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
1145 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
1146 | 1146 | |
1147 | - $gateway = sanitize_text_field( $_GET['payment-confirm'] ); |
|
1148 | - return apply_filters( "wpinv_payment_confirm_$gateway", $content ); |
|
1147 | + $gateway = sanitize_text_field($_GET['payment-confirm']); |
|
1148 | + return apply_filters("wpinv_payment_confirm_$gateway", $content); |
|
1149 | 1149 | |
1150 | 1150 | } |
1151 | 1151 | |
1152 | 1152 | return $content; |
1153 | 1153 | } |
1154 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
1154 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
1155 | 1155 | |
1156 | -function wpinv_invoice_link( $invoice_id ) { |
|
1157 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1156 | +function wpinv_invoice_link($invoice_id) { |
|
1157 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1158 | 1158 | |
1159 | - if ( empty( $invoice ) ) { |
|
1159 | + if (empty($invoice)) { |
|
1160 | 1160 | return NULL; |
1161 | 1161 | } |
1162 | 1162 | |
1163 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
1163 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
1164 | 1164 | |
1165 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
1165 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
1166 | 1166 | } |
1167 | 1167 | |
1168 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
1169 | - if ( empty( $note ) ) { |
|
1168 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
1169 | + if (empty($note)) { |
|
1170 | 1170 | return NULL; |
1171 | 1171 | } |
1172 | 1172 | |
1173 | - if ( is_int( $note ) ) { |
|
1174 | - $note = get_comment( $note ); |
|
1173 | + if (is_int($note)) { |
|
1174 | + $note = get_comment($note); |
|
1175 | 1175 | } |
1176 | 1176 | |
1177 | - if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
1177 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
1178 | 1178 | return NULL; |
1179 | 1179 | } |
1180 | 1180 | |
1181 | - $note_classes = array( 'note' ); |
|
1182 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
1181 | + $note_classes = array('note'); |
|
1182 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
1183 | 1183 | $note_classes[] = $note->comment_author === 'System' ? 'system-note' : ''; |
1184 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
1185 | - $note_classes = !empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
1184 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
1185 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
1186 | 1186 | |
1187 | 1187 | ob_start(); |
1188 | 1188 | ?> |
1189 | - <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?> mt-4 pl-3 pr-3"> |
|
1189 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?> mt-4 pl-3 pr-3"> |
|
1190 | 1190 | <div class="note_content bg-light border position-relative p-4"> |
1191 | 1191 | |
1192 | - <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?> |
|
1192 | + <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?> |
|
1193 | 1193 | |
1194 | - <?php if ( ! is_admin() ) : ?> |
|
1194 | + <?php if (!is_admin()) : ?> |
|
1195 | 1195 | <em class="meta position-absolute form-text"> |
1196 | 1196 | <?php |
1197 | 1197 | printf( |
1198 | - __( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
1198 | + __('%1$s - %2$s at %3$s', 'invoicing'), |
|
1199 | 1199 | $note->comment_author, |
1200 | - getpaid_format_date_value( $note->comment_date ), |
|
1201 | - date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) |
|
1200 | + getpaid_format_date_value($note->comment_date), |
|
1201 | + date_i18n(get_option('time_format'), strtotime($note->comment_date)) |
|
1202 | 1202 | ); |
1203 | 1203 | ?> |
1204 | 1204 | </em> |
@@ -1206,21 +1206,21 @@ discard block |
||
1206 | 1206 | |
1207 | 1207 | </div> |
1208 | 1208 | |
1209 | - <?php if ( is_admin() ) : ?> |
|
1209 | + <?php if (is_admin()) : ?> |
|
1210 | 1210 | |
1211 | 1211 | <p class="meta px-4 py-2"> |
1212 | - <abbr class="exact-date" title="<?php echo esc_attr( $note->comment_date ); ?>"> |
|
1212 | + <abbr class="exact-date" title="<?php echo esc_attr($note->comment_date); ?>"> |
|
1213 | 1213 | <?php |
1214 | 1214 | printf( |
1215 | - __( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
1215 | + __('%1$s - %2$s at %3$s', 'invoicing'), |
|
1216 | 1216 | $note->comment_author, |
1217 | - getpaid_format_date_value( $note->comment_date ), |
|
1218 | - date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) |
|
1217 | + getpaid_format_date_value($note->comment_date), |
|
1218 | + date_i18n(get_option('time_format'), strtotime($note->comment_date)) |
|
1219 | 1219 | ); |
1220 | 1220 | ?> |
1221 | 1221 | </abbr> |
1222 | - <?php if ( $note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing() ) { ?> |
|
1223 | - <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a> |
|
1222 | + <?php if ($note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing()) { ?> |
|
1223 | + <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a> |
|
1224 | 1224 | <?php } ?> |
1225 | 1225 | </p> |
1226 | 1226 | |
@@ -1229,9 +1229,9 @@ discard block |
||
1229 | 1229 | </li> |
1230 | 1230 | <?php |
1231 | 1231 | $note_content = ob_get_clean(); |
1232 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
1232 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
1233 | 1233 | |
1234 | - if ( $echo ) { |
|
1234 | + if ($echo) { |
|
1235 | 1235 | echo $note_content; |
1236 | 1236 | } else { |
1237 | 1237 | return $note_content; |
@@ -1241,36 +1241,36 @@ discard block |
||
1241 | 1241 | function wpinv_invalid_invoice_content() { |
1242 | 1242 | global $post; |
1243 | 1243 | |
1244 | - $invoice = wpinv_get_invoice( $post->ID ); |
|
1244 | + $invoice = wpinv_get_invoice($post->ID); |
|
1245 | 1245 | |
1246 | - $error = __( 'This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing' ); |
|
1247 | - if ( !empty( $invoice->get_id() ) && $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) { |
|
1248 | - if ( is_user_logged_in() ) { |
|
1249 | - if ( wpinv_require_login_to_checkout() ) { |
|
1250 | - if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
1251 | - $error = __( 'You are not allowed to view this invoice.', 'invoicing' ); |
|
1246 | + $error = __('This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing'); |
|
1247 | + if (!empty($invoice->get_id()) && $invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) { |
|
1248 | + if (is_user_logged_in()) { |
|
1249 | + if (wpinv_require_login_to_checkout()) { |
|
1250 | + if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
1251 | + $error = __('You are not allowed to view this invoice.', 'invoicing'); |
|
1252 | 1252 | } |
1253 | 1253 | } |
1254 | 1254 | } else { |
1255 | - if ( wpinv_require_login_to_checkout() ) { |
|
1256 | - if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
1257 | - $error = __( 'You must be logged in to view this invoice.', 'invoicing' ); |
|
1255 | + if (wpinv_require_login_to_checkout()) { |
|
1256 | + if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
1257 | + $error = __('You must be logged in to view this invoice.', 'invoicing'); |
|
1258 | 1258 | } |
1259 | 1259 | } |
1260 | 1260 | } |
1261 | 1261 | } else { |
1262 | - $error = __( 'This invoice is deleted or does not exist.', 'invoicing' ); |
|
1262 | + $error = __('This invoice is deleted or does not exist.', 'invoicing'); |
|
1263 | 1263 | } |
1264 | 1264 | ?> |
1265 | 1265 | <div class="row wpinv-row-invalid"> |
1266 | 1266 | <div class="col-md-6 col-md-offset-3 wpinv-message error"> |
1267 | - <h3><?php _e( 'Access Denied', 'invoicing' ); ?></h3> |
|
1267 | + <h3><?php _e('Access Denied', 'invoicing'); ?></h3> |
|
1268 | 1268 | <p class="wpinv-msg-text"><?php echo $error; ?></p> |
1269 | 1269 | </div> |
1270 | 1270 | </div> |
1271 | 1271 | <?php |
1272 | 1272 | } |
1273 | -add_action( 'wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content' ); |
|
1273 | +add_action('wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content'); |
|
1274 | 1274 | |
1275 | 1275 | /** |
1276 | 1276 | * Function to get privacy policy text. |
@@ -1279,21 +1279,21 @@ discard block |
||
1279 | 1279 | * @return string |
1280 | 1280 | */ |
1281 | 1281 | function wpinv_get_policy_text() { |
1282 | - $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 ); |
|
1282 | + $privacy_page_id = get_option('wp_page_for_privacy_policy', 0); |
|
1283 | 1283 | |
1284 | - $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' )); |
|
1284 | + $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]')); |
|
1285 | 1285 | |
1286 | - if(!$privacy_page_id){ |
|
1287 | - $privacy_page_id = wpinv_get_option( 'privacy_page', 0 ); |
|
1286 | + if (!$privacy_page_id) { |
|
1287 | + $privacy_page_id = wpinv_get_option('privacy_page', 0); |
|
1288 | 1288 | } |
1289 | 1289 | |
1290 | - $privacy_link = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' ); |
|
1290 | + $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing'); |
|
1291 | 1291 | |
1292 | 1292 | $find_replace = array( |
1293 | 1293 | '[wpinv_privacy_policy]' => $privacy_link, |
1294 | 1294 | ); |
1295 | 1295 | |
1296 | - $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text ); |
|
1296 | + $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text); |
|
1297 | 1297 | |
1298 | 1298 | return wp_kses_post(wpautop($privacy_text)); |
1299 | 1299 | } |
@@ -1301,21 +1301,21 @@ discard block |
||
1301 | 1301 | function wpinv_oxygen_fix_conflict() { |
1302 | 1302 | global $ct_ignore_post_types; |
1303 | 1303 | |
1304 | - if ( ! is_array( $ct_ignore_post_types ) ) { |
|
1304 | + if (!is_array($ct_ignore_post_types)) { |
|
1305 | 1305 | $ct_ignore_post_types = array(); |
1306 | 1306 | } |
1307 | 1307 | |
1308 | - $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item' ); |
|
1308 | + $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item'); |
|
1309 | 1309 | |
1310 | - foreach ( $post_types as $post_type ) { |
|
1310 | + foreach ($post_types as $post_type) { |
|
1311 | 1311 | $ct_ignore_post_types[] = $post_type; |
1312 | 1312 | |
1313 | 1313 | // Ignore post type |
1314 | - add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 ); |
|
1314 | + add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999); |
|
1315 | 1315 | } |
1316 | 1316 | |
1317 | - remove_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
1318 | - add_filter( 'template_include', 'wpinv_template', 999, 1 ); |
|
1317 | + remove_filter('template_include', 'wpinv_template', 10, 1); |
|
1318 | + add_filter('template_include', 'wpinv_template', 999, 1); |
|
1319 | 1319 | } |
1320 | 1320 | |
1321 | 1321 | /** |
@@ -1323,10 +1323,10 @@ discard block |
||
1323 | 1323 | * |
1324 | 1324 | * @param GetPaid_Payment_Form $form |
1325 | 1325 | */ |
1326 | -function getpaid_display_payment_form( $form ) { |
|
1326 | +function getpaid_display_payment_form($form) { |
|
1327 | 1327 | |
1328 | - if ( is_numeric( $form ) ) { |
|
1329 | - $form = new GetPaid_Payment_Form( $form ); |
|
1328 | + if (is_numeric($form)) { |
|
1329 | + $form = new GetPaid_Payment_Form($form); |
|
1330 | 1330 | } |
1331 | 1331 | |
1332 | 1332 | $form->display(); |
@@ -1336,55 +1336,55 @@ discard block |
||
1336 | 1336 | /** |
1337 | 1337 | * Helper function to display a item payment form on the frontend. |
1338 | 1338 | */ |
1339 | -function getpaid_display_item_payment_form( $items ) { |
|
1339 | +function getpaid_display_item_payment_form($items) { |
|
1340 | 1340 | |
1341 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1342 | - $form->set_items( $items ); |
|
1341 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1342 | + $form->set_items($items); |
|
1343 | 1343 | |
1344 | - if ( 0 == count( $form->get_items() ) ) { |
|
1344 | + if (0 == count($form->get_items())) { |
|
1345 | 1345 | echo aui()->alert( |
1346 | 1346 | array( |
1347 | 1347 | 'type' => 'warning', |
1348 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
1348 | + 'content' => __('No published items found', 'invoicing'), |
|
1349 | 1349 | ) |
1350 | 1350 | ); |
1351 | 1351 | return; |
1352 | 1352 | } |
1353 | 1353 | |
1354 | - $form_items = esc_attr( getpaid_convert_items_to_string( $items ) ); |
|
1354 | + $form_items = esc_attr(getpaid_convert_items_to_string($items)); |
|
1355 | 1355 | $form_items = "<input type='hidden' name='getpaid-form-items' value='$form_items' />"; |
1356 | - $form->display( $form_items ); |
|
1356 | + $form->display($form_items); |
|
1357 | 1357 | } |
1358 | 1358 | |
1359 | 1359 | /** |
1360 | 1360 | * Helper function to display an invoice payment form on the frontend. |
1361 | 1361 | */ |
1362 | -function getpaid_display_invoice_payment_form( $invoice_id ) { |
|
1362 | +function getpaid_display_invoice_payment_form($invoice_id) { |
|
1363 | 1363 | |
1364 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1364 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1365 | 1365 | |
1366 | - if ( empty( $invoice ) ) { |
|
1366 | + if (empty($invoice)) { |
|
1367 | 1367 | echo aui()->alert( |
1368 | 1368 | array( |
1369 | 1369 | 'type' => 'warning', |
1370 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1370 | + 'content' => __('Invoice not found', 'invoicing'), |
|
1371 | 1371 | ) |
1372 | 1372 | ); |
1373 | 1373 | return; |
1374 | 1374 | } |
1375 | 1375 | |
1376 | - if ( $invoice->is_paid() ) { |
|
1376 | + if ($invoice->is_paid()) { |
|
1377 | 1377 | echo aui()->alert( |
1378 | 1378 | array( |
1379 | 1379 | 'type' => 'warning', |
1380 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1380 | + 'content' => __('Invoice has already been paid', 'invoicing'), |
|
1381 | 1381 | ) |
1382 | 1382 | ); |
1383 | 1383 | return; |
1384 | 1384 | } |
1385 | 1385 | |
1386 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1387 | - $form->set_items( $invoice->get_items() ); |
|
1386 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1387 | + $form->set_items($invoice->get_items()); |
|
1388 | 1388 | |
1389 | 1389 | $form->display(); |
1390 | 1390 | } |
@@ -1392,23 +1392,23 @@ discard block |
||
1392 | 1392 | /** |
1393 | 1393 | * Helper function to convert item string to array. |
1394 | 1394 | */ |
1395 | -function getpaid_convert_items_to_array( $items ) { |
|
1396 | - $items = array_filter( array_map( 'trim', explode( ',', $items ) ) ); |
|
1395 | +function getpaid_convert_items_to_array($items) { |
|
1396 | + $items = array_filter(array_map('trim', explode(',', $items))); |
|
1397 | 1397 | $prepared = array(); |
1398 | 1398 | |
1399 | - foreach ( $items as $item ) { |
|
1400 | - $data = array_map( 'trim', explode( '|', $item ) ); |
|
1399 | + foreach ($items as $item) { |
|
1400 | + $data = array_map('trim', explode('|', $item)); |
|
1401 | 1401 | |
1402 | - if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) { |
|
1402 | + if (empty($data[0]) || !is_numeric($data[0])) { |
|
1403 | 1403 | continue; |
1404 | 1404 | } |
1405 | 1405 | |
1406 | 1406 | $quantity = 1; |
1407 | - if ( isset( $data[1] ) && is_numeric( $data[1] ) ) { |
|
1407 | + if (isset($data[1]) && is_numeric($data[1])) { |
|
1408 | 1408 | $quantity = (int) $data[1]; |
1409 | 1409 | } |
1410 | 1410 | |
1411 | - $prepared[ $data[0] ] = $quantity; |
|
1411 | + $prepared[$data[0]] = $quantity; |
|
1412 | 1412 | |
1413 | 1413 | } |
1414 | 1414 | |
@@ -1418,13 +1418,13 @@ discard block |
||
1418 | 1418 | /** |
1419 | 1419 | * Helper function to convert item array to string. |
1420 | 1420 | */ |
1421 | -function getpaid_convert_items_to_string( $items ) { |
|
1421 | +function getpaid_convert_items_to_string($items) { |
|
1422 | 1422 | $prepared = array(); |
1423 | 1423 | |
1424 | - foreach ( $items as $item => $quantity ) { |
|
1424 | + foreach ($items as $item => $quantity) { |
|
1425 | 1425 | $prepared[] = "$item|$quantity"; |
1426 | 1426 | } |
1427 | - return implode( ',', $prepared ); |
|
1427 | + return implode(',', $prepared); |
|
1428 | 1428 | } |
1429 | 1429 | |
1430 | 1430 | /** |
@@ -1432,22 +1432,22 @@ discard block |
||
1432 | 1432 | * |
1433 | 1433 | * Provide a label and one of $form, $items or $invoice. |
1434 | 1434 | */ |
1435 | -function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) { |
|
1436 | - $label = sanitize_text_field( $label ); |
|
1435 | +function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) { |
|
1436 | + $label = sanitize_text_field($label); |
|
1437 | 1437 | $nonce = wp_create_nonce('getpaid_ajax_form'); |
1438 | 1438 | |
1439 | - if ( ! empty( $form ) ) { |
|
1440 | - $form = esc_attr( $form ); |
|
1439 | + if (!empty($form)) { |
|
1440 | + $form = esc_attr($form); |
|
1441 | 1441 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-form='$form'>$label</button>"; |
1442 | 1442 | } |
1443 | 1443 | |
1444 | - if ( ! empty( $items ) ) { |
|
1445 | - $items = esc_attr( $items ); |
|
1444 | + if (!empty($items)) { |
|
1445 | + $items = esc_attr($items); |
|
1446 | 1446 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-item='$items'>$label</button>"; |
1447 | 1447 | } |
1448 | 1448 | |
1449 | - if ( ! empty( $invoice ) ) { |
|
1450 | - $invoice = esc_attr( $invoice ); |
|
1449 | + if (!empty($invoice)) { |
|
1450 | + $invoice = esc_attr($invoice); |
|
1451 | 1451 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-invoice='$invoice'>$label</button>"; |
1452 | 1452 | } |
1453 | 1453 | |
@@ -1458,17 +1458,17 @@ discard block |
||
1458 | 1458 | * |
1459 | 1459 | * @param WPInv_Invoice $invoice |
1460 | 1460 | */ |
1461 | -function getpaid_the_invoice_description( $invoice ) { |
|
1461 | +function getpaid_the_invoice_description($invoice) { |
|
1462 | 1462 | $description = $invoice->get_description(); |
1463 | 1463 | |
1464 | - if ( empty( $description ) ) { |
|
1464 | + if (empty($description)) { |
|
1465 | 1465 | return; |
1466 | 1466 | } |
1467 | 1467 | |
1468 | - $description = wp_kses_post( $description ); |
|
1468 | + $description = wp_kses_post($description); |
|
1469 | 1469 | echo "<small class='getpaid-invoice-description text-dark p-2 form-text'><em>$description</em></small>"; |
1470 | 1470 | } |
1471 | -add_action( 'getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100 ); |
|
1471 | +add_action('getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100); |
|
1472 | 1472 | |
1473 | 1473 | /** |
1474 | 1474 | * Render element on a form. |
@@ -1476,60 +1476,60 @@ discard block |
||
1476 | 1476 | * @param array $element |
1477 | 1477 | * @param GetPaid_Payment_Form $form |
1478 | 1478 | */ |
1479 | -function getpaid_payment_form_element( $element, $form ) { |
|
1479 | +function getpaid_payment_form_element($element, $form) { |
|
1480 | 1480 | |
1481 | 1481 | // Set up the args. |
1482 | - $element_type = trim( $element['type'] ); |
|
1482 | + $element_type = trim($element['type']); |
|
1483 | 1483 | $element['form'] = $form; |
1484 | - extract( $element ); |
|
1484 | + extract($element); |
|
1485 | 1485 | |
1486 | 1486 | // Try to locate the appropriate template. |
1487 | - $located = wpinv_locate_template( "payment-forms/elements/$element_type.php" ); |
|
1487 | + $located = wpinv_locate_template("payment-forms/elements/$element_type.php"); |
|
1488 | 1488 | |
1489 | 1489 | // Abort if this is not our element. |
1490 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1490 | + if (empty($located) || !file_exists($located)) { |
|
1491 | 1491 | return; |
1492 | 1492 | } |
1493 | 1493 | |
1494 | 1494 | // Generate the class and id of the element. |
1495 | - $wrapper_class = 'getpaid-payment-form-element-' . trim( esc_attr( $element_type ) ); |
|
1496 | - $id = isset( $id ) ? $id : uniqid( 'gp' ); |
|
1495 | + $wrapper_class = 'getpaid-payment-form-element-' . trim(esc_attr($element_type)); |
|
1496 | + $id = isset($id) ? $id : uniqid('gp'); |
|
1497 | 1497 | |
1498 | 1498 | // Echo the opening wrapper. |
1499 | 1499 | echo "<div class='getpaid-payment-form-element $wrapper_class'>"; |
1500 | 1500 | |
1501 | 1501 | // Fires before displaying a given element type's content. |
1502 | - do_action( "getpaid_before_payment_form_{$element_type}_element", $element, $form ); |
|
1502 | + do_action("getpaid_before_payment_form_{$element_type}_element", $element, $form); |
|
1503 | 1503 | |
1504 | 1504 | // Include the template for the element. |
1505 | 1505 | include $located; |
1506 | 1506 | |
1507 | 1507 | // Fires after displaying a given element type's content. |
1508 | - do_action( "getpaid_payment_form_{$element_type}_element", $element, $form ); |
|
1508 | + do_action("getpaid_payment_form_{$element_type}_element", $element, $form); |
|
1509 | 1509 | |
1510 | 1510 | // Echo the closing wrapper. |
1511 | 1511 | echo '</div>'; |
1512 | 1512 | } |
1513 | -add_action( 'getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2 ); |
|
1513 | +add_action('getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2); |
|
1514 | 1514 | |
1515 | 1515 | /** |
1516 | 1516 | * Render an element's edit page. |
1517 | 1517 | * |
1518 | 1518 | * @param WP_Post $post |
1519 | 1519 | */ |
1520 | -function getpaid_payment_form_edit_element_template( $post ) { |
|
1520 | +function getpaid_payment_form_edit_element_template($post) { |
|
1521 | 1521 | |
1522 | 1522 | // Retrieve all elements. |
1523 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
1523 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
1524 | 1524 | |
1525 | - foreach ( $all_elements as $element ) { |
|
1525 | + foreach ($all_elements as $element) { |
|
1526 | 1526 | |
1527 | 1527 | // Try to locate the appropriate template. |
1528 | - $element = sanitize_key( $element ); |
|
1529 | - $located = wpinv_locate_template( "payment-forms-admin/edit/$element.php" ); |
|
1528 | + $element = sanitize_key($element); |
|
1529 | + $located = wpinv_locate_template("payment-forms-admin/edit/$element.php"); |
|
1530 | 1530 | |
1531 | 1531 | // Continue if this is not our element. |
1532 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1532 | + if (empty($located) || !file_exists($located)) { |
|
1533 | 1533 | continue; |
1534 | 1534 | } |
1535 | 1535 | |
@@ -1540,7 +1540,7 @@ discard block |
||
1540 | 1540 | } |
1541 | 1541 | |
1542 | 1542 | } |
1543 | -add_action( 'getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template' ); |
|
1543 | +add_action('getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template'); |
|
1544 | 1544 | |
1545 | 1545 | /** |
1546 | 1546 | * Render an element's preview. |
@@ -1549,16 +1549,16 @@ discard block |
||
1549 | 1549 | function getpaid_payment_form_render_element_preview_template() { |
1550 | 1550 | |
1551 | 1551 | // Retrieve all elements. |
1552 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
1552 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
1553 | 1553 | |
1554 | - foreach ( $all_elements as $element ) { |
|
1554 | + foreach ($all_elements as $element) { |
|
1555 | 1555 | |
1556 | 1556 | // Try to locate the appropriate template. |
1557 | - $element = sanitize_key( $element ); |
|
1558 | - $located = wpinv_locate_template( "payment-forms-admin/previews/$element.php" ); |
|
1557 | + $element = sanitize_key($element); |
|
1558 | + $located = wpinv_locate_template("payment-forms-admin/previews/$element.php"); |
|
1559 | 1559 | |
1560 | 1560 | // Continue if this is not our element. |
1561 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1561 | + if (empty($located) || !file_exists($located)) { |
|
1562 | 1562 | continue; |
1563 | 1563 | } |
1564 | 1564 | |
@@ -1569,7 +1569,7 @@ discard block |
||
1569 | 1569 | } |
1570 | 1570 | |
1571 | 1571 | } |
1572 | -add_action( 'wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template' ); |
|
1572 | +add_action('wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template'); |
|
1573 | 1573 | |
1574 | 1574 | /** |
1575 | 1575 | * Shows a list of gateways that support recurring payments. |
@@ -1577,17 +1577,17 @@ discard block |
||
1577 | 1577 | function wpinv_get_recurring_gateways_text() { |
1578 | 1578 | $gateways = array(); |
1579 | 1579 | |
1580 | - foreach ( wpinv_get_payment_gateways() as $key => $gateway ) { |
|
1581 | - if ( wpinv_gateway_support_subscription( $key ) ) { |
|
1582 | - $gateways[] = sanitize_text_field( $gateway['admin_label'] ); |
|
1580 | + foreach (wpinv_get_payment_gateways() as $key => $gateway) { |
|
1581 | + if (wpinv_gateway_support_subscription($key)) { |
|
1582 | + $gateways[] = sanitize_text_field($gateway['admin_label']); |
|
1583 | 1583 | } |
1584 | 1584 | } |
1585 | 1585 | |
1586 | - if ( empty( $gateways ) ) { |
|
1587 | - return "<span class='form-text text-danger'>" . __( 'No active gateways support subscription payments.', 'invoicing' ) ."</span>"; |
|
1586 | + if (empty($gateways)) { |
|
1587 | + return "<span class='form-text text-danger'>" . __('No active gateways support subscription payments.', 'invoicing') . "</span>"; |
|
1588 | 1588 | } |
1589 | 1589 | |
1590 | - return "<span class='form-text text-muted'>" . wp_sprintf( __( 'Subscription payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ) ."</span>"; |
|
1590 | + return "<span class='form-text text-muted'>" . wp_sprintf(__('Subscription payments only supported by: %s', 'invoicing'), implode(', ', $gateways)) . "</span>"; |
|
1591 | 1591 | |
1592 | 1592 | } |
1593 | 1593 | |
@@ -1597,7 +1597,7 @@ discard block |
||
1597 | 1597 | * @return GetPaid_Template |
1598 | 1598 | */ |
1599 | 1599 | function getpaid_template() { |
1600 | - return getpaid()->get( 'template' ); |
|
1600 | + return getpaid()->get('template'); |
|
1601 | 1601 | } |
1602 | 1602 | |
1603 | 1603 | /** |
@@ -1606,23 +1606,23 @@ discard block |
||
1606 | 1606 | * @param array args |
1607 | 1607 | * @return string |
1608 | 1608 | */ |
1609 | -function getpaid_paginate_links( $args ) { |
|
1609 | +function getpaid_paginate_links($args) { |
|
1610 | 1610 | |
1611 | 1611 | $args['type'] = 'array'; |
1612 | 1612 | $args['mid_size'] = 1; |
1613 | - $pages = paginate_links( $args ); |
|
1613 | + $pages = paginate_links($args); |
|
1614 | 1614 | |
1615 | - if ( ! is_array( $pages ) ) { |
|
1615 | + if (!is_array($pages)) { |
|
1616 | 1616 | return ''; |
1617 | 1617 | } |
1618 | 1618 | |
1619 | 1619 | $_pages = array(); |
1620 | - foreach ( $pages as $page ) { |
|
1621 | - $_pages[] = str_replace( 'page-numbers', 'page-link text-decoration-none', $page ); |
|
1620 | + foreach ($pages as $page) { |
|
1621 | + $_pages[] = str_replace('page-numbers', 'page-link text-decoration-none', $page); |
|
1622 | 1622 | } |
1623 | 1623 | |
1624 | 1624 | $links = "<nav>\n\t<ul class='pagination justify-content-end m-0'>\n\t\t<li class='page-item'>"; |
1625 | - $links .= join( "</li>\n\t\t<li class='page-item'>", $_pages ); |
|
1625 | + $links .= join("</li>\n\t\t<li class='page-item'>", $_pages); |
|
1626 | 1626 | $links .= "</li>\n\t</ul>\n</nav>\n"; |
1627 | 1627 | |
1628 | 1628 | return $links; |
@@ -7,21 +7,21 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | // Make sure that the form is active. |
13 | -if ( ! $form->is_active() ) { |
|
13 | +if (!$form->is_active()) { |
|
14 | 14 | echo aui()->alert( |
15 | 15 | array( |
16 | 16 | 'type' => 'warning', |
17 | - 'content' => __( 'This payment form is no longer active', 'invoicing' ), |
|
17 | + 'content' => __('This payment form is no longer active', 'invoicing'), |
|
18 | 18 | ) |
19 | 19 | ); |
20 | 20 | return; |
21 | 21 | } |
22 | 22 | |
23 | 23 | // Fires before displaying a payment form. |
24 | -do_action( 'getpaid_before_payment_form', $form ); |
|
24 | +do_action('getpaid_before_payment_form', $form); |
|
25 | 25 | ?> |
26 | 26 | |
27 | 27 | <form class='getpaid-payment-form bsui' method='POST' data-key='<?php echo uniqid('gpf'); ?>'> |
@@ -30,44 +30,44 @@ discard block |
||
30 | 30 | <?php |
31 | 31 | |
32 | 32 | // Fires when printing the top of a payment form. |
33 | - do_action( 'getpaid_payment_form_top', $form ); |
|
33 | + do_action('getpaid_payment_form_top', $form); |
|
34 | 34 | |
35 | 35 | // Add the vat validation nonce. |
36 | - wp_nonce_field( 'vat_validation', '_wpi_nonce' ); |
|
36 | + wp_nonce_field('vat_validation', '_wpi_nonce'); |
|
37 | 37 | |
38 | 38 | // And the optional invoice id. |
39 | - if ( ! empty( $form->invoice ) ) { |
|
40 | - echo getpaid_hidden_field( 'invoice_id', $form->invoice->get_id() ); |
|
39 | + if (!empty($form->invoice)) { |
|
40 | + echo getpaid_hidden_field('invoice_id', $form->invoice->get_id()); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | // We also want to include the form id. |
44 | - echo getpaid_hidden_field( 'form_id', $form->get_id() ); |
|
44 | + echo getpaid_hidden_field('form_id', $form->get_id()); |
|
45 | 45 | |
46 | 46 | // And an indication that this is a payment form submission. |
47 | - echo getpaid_hidden_field( 'getpaid_payment_form_submission', '1' ); |
|
47 | + echo getpaid_hidden_field('getpaid_payment_form_submission', '1'); |
|
48 | 48 | |
49 | 49 | // Fires before displaying payment form elements. |
50 | - do_action( 'getpaid_payment_form_before_elements', $form ); |
|
50 | + do_action('getpaid_payment_form_before_elements', $form); |
|
51 | 51 | |
52 | 52 | // Display the elements. |
53 | - foreach ( $form->get_elements() as $element ) { |
|
54 | - if ( isset( $element['type'] ) ) { |
|
55 | - do_action( 'getpaid_payment_form_element', $element, $form ); |
|
56 | - do_action( "getpaid_payment_form_element_{$element['type']}_template", $element, $form ); |
|
53 | + foreach ($form->get_elements() as $element) { |
|
54 | + if (isset($element['type'])) { |
|
55 | + do_action('getpaid_payment_form_element', $element, $form); |
|
56 | + do_action("getpaid_payment_form_element_{$element['type']}_template", $element, $form); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
60 | 60 | // Fires after displaying payment form elements. |
61 | - do_action( 'getpaid_payment_form_after_elements', $form ); |
|
61 | + do_action('getpaid_payment_form_after_elements', $form); |
|
62 | 62 | |
63 | 63 | echo "<div class='getpaid-payment-form-errors alert alert-danger d-none'></div>"; |
64 | 64 | |
65 | - if ( wpinv_current_user_can_manage_invoicing() ) { |
|
65 | + if (wpinv_current_user_can_manage_invoicing()) { |
|
66 | 66 | |
67 | 67 | edit_post_link( |
68 | - __( 'Edit this form.', 'invoicing' ), |
|
68 | + __('Edit this form.', 'invoicing'), |
|
69 | 69 | '<small class="form-text text-muted">', |
70 | - ' ' . __( 'This is only visible to website administators.', 'invoicing' ) . '</small>', |
|
70 | + ' ' . __('This is only visible to website administators.', 'invoicing') . '</small>', |
|
71 | 71 | $form->get_id(), |
72 | 72 | 'text-danger' |
73 | 73 | ); |
@@ -82,4 +82,4 @@ discard block |
||
82 | 82 | <?php |
83 | 83 | |
84 | 84 | // Fires after displaying a payment form. |
85 | -do_action( 'getpaid_after_payment_form', $form ); |
|
85 | +do_action('getpaid_after_payment_form', $form); |