@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | * |
98 | 98 | * @param null|string|array $query Optional. The query variables. |
99 | 99 | */ |
100 | - public function __construct( $query = null ) { |
|
101 | - if ( ! is_null( $query ) ) { |
|
102 | - $this->prepare_query( $query ); |
|
100 | + public function __construct($query = null) { |
|
101 | + if (!is_null($query)) { |
|
102 | + $this->prepare_query($query); |
|
103 | 103 | $this->query(); |
104 | 104 | } |
105 | 105 | } |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | * @param string|array $args Query vars, as passed to `GetPaid_Subscriptions_Query`. |
113 | 113 | * @return array Complete query variables with undefined ones filled in with defaults. |
114 | 114 | */ |
115 | - public static function fill_query_vars( $args ) { |
|
115 | + public static function fill_query_vars($args) { |
|
116 | 116 | $defaults = array( |
117 | 117 | 'status' => 'all', |
118 | 118 | 'customer_in' => array(), |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | 'fields' => 'all', |
131 | 131 | ); |
132 | 132 | |
133 | - return wp_parse_args( $args, $defaults ); |
|
133 | + return wp_parse_args($args, $defaults); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -182,45 +182,45 @@ discard block |
||
182 | 182 | * Use 'all' for all fields. Default 'all'. |
183 | 183 | * } |
184 | 184 | */ |
185 | - public function prepare_query( $query = array() ) { |
|
185 | + public function prepare_query($query = array()) { |
|
186 | 186 | global $wpdb; |
187 | 187 | |
188 | - if ( empty( $this->query_vars ) || ! empty( $query ) ) { |
|
188 | + if (empty($this->query_vars) || !empty($query)) { |
|
189 | 189 | $this->query_limit = null; |
190 | - $this->query_vars = $this->fill_query_vars( $query ); |
|
190 | + $this->query_vars = $this->fill_query_vars($query); |
|
191 | 191 | } |
192 | 192 | |
193 | - if ( ! empty( $this->query_vars['fields'] ) && 'all' !== $this->query_vars['fields'] ) { |
|
194 | - $this->query_vars['fields'] = wpinv_parse_list( $this->query_vars['fields'] ); |
|
193 | + if (!empty($this->query_vars['fields']) && 'all' !== $this->query_vars['fields']) { |
|
194 | + $this->query_vars['fields'] = wpinv_parse_list($this->query_vars['fields']); |
|
195 | 195 | } |
196 | 196 | |
197 | - do_action( 'getpaid_pre_get_subscriptions', array( &$this ) ); |
|
197 | + do_action('getpaid_pre_get_subscriptions', array(&$this)); |
|
198 | 198 | |
199 | 199 | // Ensure that query vars are filled after 'getpaid_pre_get_subscriptions'. |
200 | - $qv =& $this->query_vars; |
|
201 | - $qv = $this->fill_query_vars( $qv ); |
|
200 | + $qv = & $this->query_vars; |
|
201 | + $qv = $this->fill_query_vars($qv); |
|
202 | 202 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
203 | 203 | $this->query_from = "FROM $table"; |
204 | 204 | |
205 | 205 | // Prepare query fields. |
206 | - $this->prepare_query_fields( $qv, $table ); |
|
206 | + $this->prepare_query_fields($qv, $table); |
|
207 | 207 | |
208 | 208 | // Prepare query where. |
209 | - $this->prepare_query_where( $qv, $table ); |
|
209 | + $this->prepare_query_where($qv, $table); |
|
210 | 210 | |
211 | 211 | // Prepare query order. |
212 | - $this->prepare_query_order( $qv, $table ); |
|
212 | + $this->prepare_query_order($qv, $table); |
|
213 | 213 | |
214 | 214 | // limit |
215 | - if ( isset( $qv['number'] ) && $qv['number'] > 0 ) { |
|
216 | - if ( $qv['offset'] ) { |
|
217 | - $this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['offset'], $qv['number'] ); |
|
215 | + if (isset($qv['number']) && $qv['number'] > 0) { |
|
216 | + if ($qv['offset']) { |
|
217 | + $this->query_limit = $wpdb->prepare('LIMIT %d, %d', $qv['offset'], $qv['number']); |
|
218 | 218 | } else { |
219 | - $this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] ); |
|
219 | + $this->query_limit = $wpdb->prepare('LIMIT %d, %d', $qv['number'] * ($qv['paged'] - 1), $qv['number']); |
|
220 | 220 | } |
221 | 221 | } |
222 | 222 | |
223 | - do_action_ref_array( 'getpaid_after_subscriptions_query', array( &$this ) ); |
|
223 | + do_action_ref_array('getpaid_after_subscriptions_query', array(&$this)); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -231,22 +231,22 @@ discard block |
||
231 | 231 | * @param array $qv Query vars. |
232 | 232 | * @param string $table Table name. |
233 | 233 | */ |
234 | - protected function prepare_query_fields( &$qv, $table ) { |
|
234 | + protected function prepare_query_fields(&$qv, $table) { |
|
235 | 235 | |
236 | - if ( is_array( $qv['fields'] ) ) { |
|
237 | - $qv['fields'] = array_unique( $qv['fields'] ); |
|
236 | + if (is_array($qv['fields'])) { |
|
237 | + $qv['fields'] = array_unique($qv['fields']); |
|
238 | 238 | |
239 | 239 | $query_fields = array(); |
240 | - foreach ( $qv['fields'] as $field ) { |
|
241 | - $field = sanitize_key( $field ); |
|
240 | + foreach ($qv['fields'] as $field) { |
|
241 | + $field = sanitize_key($field); |
|
242 | 242 | $query_fields[] = "$table.`$field`"; |
243 | 243 | } |
244 | - $this->query_fields = implode( ',', $query_fields ); |
|
244 | + $this->query_fields = implode(',', $query_fields); |
|
245 | 245 | } else { |
246 | 246 | $this->query_fields = "$table.*"; |
247 | 247 | } |
248 | 248 | |
249 | - if ( isset( $qv['count_total'] ) && $qv['count_total'] ) { |
|
249 | + if (isset($qv['count_total']) && $qv['count_total']) { |
|
250 | 250 | $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields; |
251 | 251 | } |
252 | 252 | |
@@ -260,58 +260,58 @@ discard block |
||
260 | 260 | * @param array $qv Query vars. |
261 | 261 | * @param string $table Table name. |
262 | 262 | */ |
263 | - protected function prepare_query_where( &$qv, $table ) { |
|
263 | + protected function prepare_query_where(&$qv, $table) { |
|
264 | 264 | global $wpdb; |
265 | 265 | $this->query_where = 'WHERE 1=1'; |
266 | 266 | |
267 | 267 | // Status. |
268 | - if ( 'all' !== $qv['status'] ) { |
|
269 | - $statuses = wpinv_clean( wpinv_parse_list( $qv['status'] ) ); |
|
270 | - $prepared_statuses = join( ',', array_fill( 0, count( $statuses ), '%s' ) ); |
|
271 | - $this->query_where .= $wpdb->prepare( " AND $table.`status` IN ( $prepared_statuses )", $statuses ); |
|
268 | + if ('all' !== $qv['status']) { |
|
269 | + $statuses = wpinv_clean(wpinv_parse_list($qv['status'])); |
|
270 | + $prepared_statuses = join(',', array_fill(0, count($statuses), '%s')); |
|
271 | + $this->query_where .= $wpdb->prepare(" AND $table.`status` IN ( $prepared_statuses )", $statuses); |
|
272 | 272 | } |
273 | 273 | |
274 | - if ( ! empty( $qv['customer_in'] ) ) { |
|
275 | - $customer_in = implode( ',', wp_parse_id_list( $qv['customer_in'] ) ); |
|
274 | + if (!empty($qv['customer_in'])) { |
|
275 | + $customer_in = implode(',', wp_parse_id_list($qv['customer_in'])); |
|
276 | 276 | $this->query_where .= " AND $table.`customer_id` IN ($customer_in)"; |
277 | - } elseif ( ! empty( $qv['customer_not_in'] ) ) { |
|
278 | - $customer_not_in = implode( ',', wp_parse_id_list( $qv['customer_not_in'] ) ); |
|
277 | + } elseif (!empty($qv['customer_not_in'])) { |
|
278 | + $customer_not_in = implode(',', wp_parse_id_list($qv['customer_not_in'])); |
|
279 | 279 | $this->query_where .= " AND $table.`customer_id` NOT IN ($customer_not_in)"; |
280 | 280 | } |
281 | 281 | |
282 | - if ( ! empty( $qv['product_in'] ) ) { |
|
283 | - $product_in = implode( ',', wp_parse_id_list( $qv['product_in'] ) ); |
|
282 | + if (!empty($qv['product_in'])) { |
|
283 | + $product_in = implode(',', wp_parse_id_list($qv['product_in'])); |
|
284 | 284 | $this->query_where .= " AND $table.`product_id` IN ($product_in)"; |
285 | - } elseif ( ! empty( $qv['product_not_in'] ) ) { |
|
286 | - $product_not_in = implode( ',', wp_parse_id_list( $qv['product_not_in'] ) ); |
|
285 | + } elseif (!empty($qv['product_not_in'])) { |
|
286 | + $product_not_in = implode(',', wp_parse_id_list($qv['product_not_in'])); |
|
287 | 287 | $this->query_where .= " AND $table.`product_id` NOT IN ($product_not_in)"; |
288 | 288 | } |
289 | 289 | |
290 | - if ( ! empty( $qv['invoice_in'] ) ) { |
|
291 | - $invoice_in = implode( ',', wp_parse_id_list( $qv['invoice_in'] ) ); |
|
290 | + if (!empty($qv['invoice_in'])) { |
|
291 | + $invoice_in = implode(',', wp_parse_id_list($qv['invoice_in'])); |
|
292 | 292 | $this->query_where .= " AND $table.`parent_payment_id` IN ($invoice_in)"; |
293 | - } elseif ( ! empty( $qv['invoice_not_in'] ) ) { |
|
294 | - $invoice_not_in = implode( ',', wp_parse_id_list( $qv['invoice_not_in'] ) ); |
|
293 | + } elseif (!empty($qv['invoice_not_in'])) { |
|
294 | + $invoice_not_in = implode(',', wp_parse_id_list($qv['invoice_not_in'])); |
|
295 | 295 | $this->query_where .= " AND $table.`parent_payment_id` NOT IN ($invoice_not_in)"; |
296 | 296 | } |
297 | 297 | |
298 | - if ( ! empty( $qv['include'] ) ) { |
|
299 | - $include = implode( ',', wp_parse_id_list( $qv['include'] ) ); |
|
298 | + if (!empty($qv['include'])) { |
|
299 | + $include = implode(',', wp_parse_id_list($qv['include'])); |
|
300 | 300 | $this->query_where .= " AND $table.`id` IN ($include)"; |
301 | - } elseif ( ! empty( $qv['exclude'] ) ) { |
|
302 | - $exclude = implode( ',', wp_parse_id_list( $qv['exclude'] ) ); |
|
301 | + } elseif (!empty($qv['exclude'])) { |
|
302 | + $exclude = implode(',', wp_parse_id_list($qv['exclude'])); |
|
303 | 303 | $this->query_where .= " AND $table.`id` NOT IN ($exclude)"; |
304 | 304 | } |
305 | 305 | |
306 | 306 | // Date queries are allowed for the subscription creation date. |
307 | - if ( ! empty( $qv['date_created_query'] ) && is_array( $qv['date_created_query'] ) ) { |
|
308 | - $date_created_query = new WP_Date_Query( $qv['date_created_query'], "$table.created" ); |
|
307 | + if (!empty($qv['date_created_query']) && is_array($qv['date_created_query'])) { |
|
308 | + $date_created_query = new WP_Date_Query($qv['date_created_query'], "$table.created"); |
|
309 | 309 | $this->query_where .= $date_created_query->get_sql(); |
310 | 310 | } |
311 | 311 | |
312 | 312 | // Date queries are also allowed for the subscription expiration date. |
313 | - if ( ! empty( $qv['date_expires_query'] ) && is_array( $qv['date_expires_query'] ) ) { |
|
314 | - $date_expires_query = new WP_Date_Query( $qv['date_expires_query'], "$table.expiration" ); |
|
313 | + if (!empty($qv['date_expires_query']) && is_array($qv['date_expires_query'])) { |
|
314 | + $date_expires_query = new WP_Date_Query($qv['date_expires_query'], "$table.expiration"); |
|
315 | 315 | $this->query_where .= $date_expires_query->get_sql(); |
316 | 316 | } |
317 | 317 | |
@@ -325,24 +325,24 @@ discard block |
||
325 | 325 | * @param array $qv Query vars. |
326 | 326 | * @param string $table Table name. |
327 | 327 | */ |
328 | - protected function prepare_query_order( &$qv, $table ) { |
|
328 | + protected function prepare_query_order(&$qv, $table) { |
|
329 | 329 | |
330 | 330 | // sorting. |
331 | - $qv['order'] = isset( $qv['order'] ) ? strtoupper( $qv['order'] ) : ''; |
|
332 | - $order = $this->parse_order( $qv['order'] ); |
|
331 | + $qv['order'] = isset($qv['order']) ? strtoupper($qv['order']) : ''; |
|
332 | + $order = $this->parse_order($qv['order']); |
|
333 | 333 | |
334 | 334 | // Default order is by 'id' (latest subscriptions). |
335 | - if ( empty( $qv['orderby'] ) ) { |
|
336 | - $qv['orderby'] = array( 'id' ); |
|
335 | + if (empty($qv['orderby'])) { |
|
336 | + $qv['orderby'] = array('id'); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | // 'orderby' values may be an array, comma- or space-separated list. |
340 | - $ordersby = array_filter( wpinv_parse_list( $qv['orderby'] ) ); |
|
340 | + $ordersby = array_filter(wpinv_parse_list($qv['orderby'])); |
|
341 | 341 | |
342 | 342 | $orderby_array = array(); |
343 | - foreach ( $ordersby as $_key => $_value ) { |
|
343 | + foreach ($ordersby as $_key => $_value) { |
|
344 | 344 | |
345 | - if ( is_int( $_key ) ) { |
|
345 | + if (is_int($_key)) { |
|
346 | 346 | // Integer key means this is a flat array of 'orderby' fields. |
347 | 347 | $_orderby = $_value; |
348 | 348 | $_order = $order; |
@@ -352,20 +352,20 @@ discard block |
||
352 | 352 | $_order = $_value; |
353 | 353 | } |
354 | 354 | |
355 | - $parsed = $this->parse_orderby( $_orderby, $table ); |
|
355 | + $parsed = $this->parse_orderby($_orderby, $table); |
|
356 | 356 | |
357 | - if ( $parsed ) { |
|
358 | - $orderby_array[] = $parsed . ' ' . $this->parse_order( $_order ); |
|
357 | + if ($parsed) { |
|
358 | + $orderby_array[] = $parsed . ' ' . $this->parse_order($_order); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | } |
362 | 362 | |
363 | 363 | // If no valid clauses were found, order by id. |
364 | - if ( empty( $orderby_array ) ) { |
|
364 | + if (empty($orderby_array)) { |
|
365 | 365 | $orderby_array[] = "id $order"; |
366 | 366 | } |
367 | 367 | |
368 | - $this->query_orderby = 'ORDER BY ' . implode( ', ', $orderby_array ); |
|
368 | + $this->query_orderby = 'ORDER BY ' . implode(', ', $orderby_array); |
|
369 | 369 | |
370 | 370 | } |
371 | 371 | |
@@ -379,34 +379,34 @@ discard block |
||
379 | 379 | public function query() { |
380 | 380 | global $wpdb; |
381 | 381 | |
382 | - $qv =& $this->query_vars; |
|
382 | + $qv = & $this->query_vars; |
|
383 | 383 | |
384 | 384 | // Return a non-null value to bypass the default GetPaid subscriptions query and remember to set the |
385 | 385 | // total_subscriptions property. |
386 | - $this->results = apply_filters_ref_array( 'getpaid_subscriptions_pre_query', array( null, &$this ) ); |
|
386 | + $this->results = apply_filters_ref_array('getpaid_subscriptions_pre_query', array(null, &$this)); |
|
387 | 387 | |
388 | - if ( null === $this->results ) { |
|
388 | + if (null === $this->results) { |
|
389 | 389 | $this->request = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit"; |
390 | 390 | |
391 | - if ( ( is_array( $qv['fields'] ) && 1 != count( $qv['fields'] ) ) || 'all' == $qv['fields'] ) { |
|
392 | - $this->results = $wpdb->get_results( $this->request ); |
|
391 | + if ((is_array($qv['fields']) && 1 != count($qv['fields'])) || 'all' == $qv['fields']) { |
|
392 | + $this->results = $wpdb->get_results($this->request); |
|
393 | 393 | } else { |
394 | - $this->results = $wpdb->get_col( $this->request ); |
|
394 | + $this->results = $wpdb->get_col($this->request); |
|
395 | 395 | } |
396 | 396 | |
397 | - if ( isset( $qv['count_total'] ) && $qv['count_total'] ) { |
|
398 | - $found_subscriptions_query = apply_filters( 'getpaid_found_subscriptions_query', 'SELECT FOUND_ROWS()', $this ); |
|
399 | - $this->total_subscriptions = (int) $wpdb->get_var( $found_subscriptions_query ); |
|
397 | + if (isset($qv['count_total']) && $qv['count_total']) { |
|
398 | + $found_subscriptions_query = apply_filters('getpaid_found_subscriptions_query', 'SELECT FOUND_ROWS()', $this); |
|
399 | + $this->total_subscriptions = (int) $wpdb->get_var($found_subscriptions_query); |
|
400 | 400 | } |
401 | 401 | } |
402 | 402 | |
403 | - if ( 'all' == $qv['fields'] ) { |
|
404 | - foreach ( $this->results as $key => $subscription ) { |
|
405 | - wp_cache_set( $subscription->id, $subscription, 'getpaid_subscriptions' ); |
|
406 | - wp_cache_set( $subscription->profile_id, $subscription->id, 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
407 | - wp_cache_set( $subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
408 | - wp_cache_set( $subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
409 | - $this->results[ $key ] = new WPInv_Subscription( $subscription ); |
|
403 | + if ('all' == $qv['fields']) { |
|
404 | + foreach ($this->results as $key => $subscription) { |
|
405 | + wp_cache_set($subscription->id, $subscription, 'getpaid_subscriptions'); |
|
406 | + wp_cache_set($subscription->profile_id, $subscription->id, 'getpaid_subscription_profile_ids_to_subscription_ids'); |
|
407 | + wp_cache_set($subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids'); |
|
408 | + wp_cache_set($subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids'); |
|
409 | + $this->results[$key] = new WPInv_Subscription($subscription); |
|
410 | 410 | } |
411 | 411 | } |
412 | 412 | |
@@ -420,9 +420,9 @@ discard block |
||
420 | 420 | * @param string $query_var Query variable key. |
421 | 421 | * @return mixed |
422 | 422 | */ |
423 | - public function get( $query_var ) { |
|
424 | - if ( isset( $this->query_vars[ $query_var ] ) ) { |
|
425 | - return $this->query_vars[ $query_var ]; |
|
423 | + public function get($query_var) { |
|
424 | + if (isset($this->query_vars[$query_var])) { |
|
425 | + return $this->query_vars[$query_var]; |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | return null; |
@@ -436,8 +436,8 @@ discard block |
||
436 | 436 | * @param string $query_var Query variable key. |
437 | 437 | * @param mixed $value Query variable value. |
438 | 438 | */ |
439 | - public function set( $query_var, $value ) { |
|
440 | - $this->query_vars[ $query_var ] = $value; |
|
439 | + public function set($query_var, $value) { |
|
440 | + $this->query_vars[$query_var] = $value; |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | /** |
@@ -471,16 +471,16 @@ discard block |
||
471 | 471 | * @param string $table The current table. |
472 | 472 | * @return string Value to use in the ORDER clause, if `$orderby` is valid. |
473 | 473 | */ |
474 | - protected function parse_orderby( $orderby, $table ) { |
|
474 | + protected function parse_orderby($orderby, $table) { |
|
475 | 475 | |
476 | 476 | $_orderby = ''; |
477 | - if ( in_array( $orderby, array( 'customer_id', 'frequency', 'period', 'initial_amount', 'recurring_amount', 'bill_times', 'transaction_id', 'parent_payment_id', 'product_id', 'created', 'expiration', 'trial_period', 'status', 'profile_id' ) ) ) { |
|
477 | + if (in_array($orderby, array('customer_id', 'frequency', 'period', 'initial_amount', 'recurring_amount', 'bill_times', 'transaction_id', 'parent_payment_id', 'product_id', 'created', 'expiration', 'trial_period', 'status', 'profile_id'))) { |
|
478 | 478 | $_orderby = "$table.`$orderby`"; |
479 | - } elseif ( 'id' === strtolower( $orderby ) ) { |
|
479 | + } elseif ('id' === strtolower($orderby)) { |
|
480 | 480 | $_orderby = "$table.id"; |
481 | - } elseif ( 'include' === $orderby && ! empty( $this->query_vars['include'] ) ) { |
|
482 | - $include = wp_parse_id_list( $this->query_vars['include'] ); |
|
483 | - $include_sql = implode( ',', $include ); |
|
481 | + } elseif ('include' === $orderby && !empty($this->query_vars['include'])) { |
|
482 | + $include = wp_parse_id_list($this->query_vars['include']); |
|
483 | + $include_sql = implode(',', $include); |
|
484 | 484 | $_orderby = "FIELD( $table.id, $include_sql )"; |
485 | 485 | } |
486 | 486 | |
@@ -495,12 +495,12 @@ discard block |
||
495 | 495 | * @param string $order The 'order' query variable. |
496 | 496 | * @return string The sanitized 'order' query variable. |
497 | 497 | */ |
498 | - protected function parse_order( $order ) { |
|
499 | - if ( ! is_string( $order ) || empty( $order ) ) { |
|
498 | + protected function parse_order($order) { |
|
499 | + if (!is_string($order) || empty($order)) { |
|
500 | 500 | return 'DESC'; |
501 | 501 | } |
502 | 502 | |
503 | - if ( 'ASC' === strtoupper( $order ) ) { |
|
503 | + if ('ASC' === strtoupper($order)) { |
|
504 | 504 | return 'ASC'; |
505 | 505 | } else { |
506 | 506 | return 'DESC'; |
@@ -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,140 +813,140 @@ 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 | // Load the invoice meta. |
833 | - $meta = array( |
|
833 | + $meta = array( |
|
834 | 834 | |
835 | 835 | 'number' => array( |
836 | 836 | 'label' => sprintf( |
837 | - __( '%s Number', 'invoicing' ), |
|
838 | - ucfirst( $invoice->get_type() ) |
|
837 | + __('%s Number', 'invoicing'), |
|
838 | + ucfirst($invoice->get_type()) |
|
839 | 839 | ), |
840 | - 'value' => sanitize_text_field( $invoice->get_number() ), |
|
840 | + 'value' => sanitize_text_field($invoice->get_number()), |
|
841 | 841 | ), |
842 | 842 | |
843 | 843 | 'status' => array( |
844 | 844 | 'label' => sprintf( |
845 | - __( '%s Status', 'invoicing' ), |
|
846 | - ucfirst( $invoice->get_type() ) |
|
845 | + __('%s Status', 'invoicing'), |
|
846 | + ucfirst($invoice->get_type()) |
|
847 | 847 | ), |
848 | 848 | 'value' => $invoice->get_status_label_html(), |
849 | 849 | ), |
850 | 850 | |
851 | 851 | 'date' => array( |
852 | 852 | 'label' => sprintf( |
853 | - __( '%s Date', 'invoicing' ), |
|
854 | - ucfirst( $invoice->get_type() ) |
|
853 | + __('%s Date', 'invoicing'), |
|
854 | + ucfirst($invoice->get_type()) |
|
855 | 855 | ), |
856 | - 'value' => getpaid_format_date( $invoice->get_created_date() ), |
|
856 | + 'value' => getpaid_format_date($invoice->get_created_date()), |
|
857 | 857 | ), |
858 | 858 | |
859 | 859 | 'date_paid' => array( |
860 | - 'label' => __( 'Paid On', 'invoicing' ), |
|
861 | - 'value' => getpaid_format_date( $invoice->get_completed_date() ), |
|
860 | + 'label' => __('Paid On', 'invoicing'), |
|
861 | + 'value' => getpaid_format_date($invoice->get_completed_date()), |
|
862 | 862 | ), |
863 | 863 | |
864 | 864 | 'gateway' => array( |
865 | - 'label' => __( 'Payment Method', 'invoicing' ), |
|
866 | - 'value' => sanitize_text_field( $invoice->get_gateway_title() ), |
|
865 | + 'label' => __('Payment Method', 'invoicing'), |
|
866 | + 'value' => sanitize_text_field($invoice->get_gateway_title()), |
|
867 | 867 | ), |
868 | 868 | |
869 | 869 | 'transaction_id' => array( |
870 | - 'label' => __( 'Transaction ID', 'invoicing' ), |
|
871 | - 'value' => sanitize_text_field( $invoice->get_transaction_id() ), |
|
870 | + 'label' => __('Transaction ID', 'invoicing'), |
|
871 | + 'value' => sanitize_text_field($invoice->get_transaction_id()), |
|
872 | 872 | ), |
873 | 873 | |
874 | 874 | 'due_date' => array( |
875 | - 'label' => __( 'Due Date', 'invoicing' ), |
|
876 | - 'value' => getpaid_format_date( $invoice->get_due_date() ), |
|
875 | + 'label' => __('Due Date', 'invoicing'), |
|
876 | + 'value' => getpaid_format_date($invoice->get_due_date()), |
|
877 | 877 | ), |
878 | 878 | |
879 | 879 | 'vat_number' => array( |
880 | 880 | 'label' => sprintf( |
881 | - __( '%s Number', 'invoicing' ), |
|
881 | + __('%s Number', 'invoicing'), |
|
882 | 882 | getpaid_tax()->get_vat_name() |
883 | 883 | ), |
884 | - 'value' => sanitize_text_field( $invoice->get_vat_number() ), |
|
884 | + 'value' => sanitize_text_field($invoice->get_vat_number()), |
|
885 | 885 | ), |
886 | 886 | |
887 | 887 | ); |
888 | 888 | |
889 | 889 | // If it is not paid, remove the date of payment. |
890 | - if ( ! $invoice->is_paid() ) { |
|
891 | - unset( $meta[ 'date_paid' ] ); |
|
892 | - unset( $meta[ 'transaction_id' ] ); |
|
890 | + if (!$invoice->is_paid()) { |
|
891 | + unset($meta['date_paid']); |
|
892 | + unset($meta['transaction_id']); |
|
893 | 893 | } |
894 | 894 | |
895 | - if ( ! $invoice->is_paid() || 'none' == $invoice->get_gateway() ) { |
|
896 | - unset( $meta[ 'gateway' ] ); |
|
895 | + if (!$invoice->is_paid() || 'none' == $invoice->get_gateway()) { |
|
896 | + unset($meta['gateway']); |
|
897 | 897 | } |
898 | 898 | |
899 | 899 | // Only display the due date if due dates are enabled. |
900 | - if ( ! $invoice->needs_payment() || ! wpinv_get_option( 'overdue_active' ) ) { |
|
901 | - unset( $meta[ 'due_date' ] ); |
|
900 | + if (!$invoice->needs_payment() || !wpinv_get_option('overdue_active')) { |
|
901 | + unset($meta['due_date']); |
|
902 | 902 | } |
903 | 903 | |
904 | 904 | // Only display the vat number if taxes are enabled. |
905 | - if ( ! wpinv_use_taxes() ) { |
|
906 | - unset( $meta[ 'vat_number' ] ); |
|
905 | + if (!wpinv_use_taxes()) { |
|
906 | + unset($meta['vat_number']); |
|
907 | 907 | } |
908 | 908 | |
909 | - if ( $invoice->is_recurring() ) { |
|
909 | + if ($invoice->is_recurring()) { |
|
910 | 910 | |
911 | 911 | // Link to the parent invoice. |
912 | - if ( $invoice->is_renewal() ) { |
|
912 | + if ($invoice->is_renewal()) { |
|
913 | 913 | |
914 | - $meta[ 'parent' ] = array( |
|
914 | + $meta['parent'] = array( |
|
915 | 915 | |
916 | 916 | 'label' => sprintf( |
917 | - __( 'Parent %s', 'invoicing' ), |
|
918 | - ucfirst( $invoice->get_type() ) |
|
917 | + __('Parent %s', 'invoicing'), |
|
918 | + ucfirst($invoice->get_type()) |
|
919 | 919 | ), |
920 | 920 | |
921 | - 'value' => wpinv_invoice_link( $invoice->get_parent_id() ), |
|
921 | + 'value' => wpinv_invoice_link($invoice->get_parent_id()), |
|
922 | 922 | |
923 | 923 | ); |
924 | 924 | |
925 | 925 | } |
926 | 926 | |
927 | - $subscription = wpinv_get_subscription( $invoice ); |
|
927 | + $subscription = wpinv_get_subscription($invoice); |
|
928 | 928 | |
929 | - if ( ! empty ( $subscription ) ) { |
|
929 | + if (!empty ($subscription)) { |
|
930 | 930 | |
931 | 931 | // Display the renewal date. |
932 | - if ( $subscription->is_active() && 'cancelled' != $subscription->status ) { |
|
932 | + if ($subscription->is_active() && 'cancelled' != $subscription->status) { |
|
933 | 933 | |
934 | - $meta[ 'renewal_date' ] = array( |
|
934 | + $meta['renewal_date'] = array( |
|
935 | 935 | |
936 | - 'label' => __( 'Renews On', 'invoicing' ), |
|
937 | - 'value' => getpaid_format_date( $subscription->expiration ), |
|
936 | + 'label' => __('Renews On', 'invoicing'), |
|
937 | + 'value' => getpaid_format_date($subscription->expiration), |
|
938 | 938 | |
939 | 939 | ); |
940 | 940 | |
941 | 941 | } |
942 | 942 | |
943 | - if ( $invoice->is_parent() ) { |
|
943 | + if ($invoice->is_parent()) { |
|
944 | 944 | |
945 | 945 | // Display the recurring amount. |
946 | - $meta[ 'recurring_total' ] = array( |
|
946 | + $meta['recurring_total'] = array( |
|
947 | 947 | |
948 | - 'label' => __( 'Recurring Amount', 'invoicing' ), |
|
949 | - 'value' => wpinv_price( wpinv_format_amount( $subscription->recurring_amount ), $invoice->get_currency() ), |
|
948 | + 'label' => __('Recurring Amount', 'invoicing'), |
|
949 | + 'value' => wpinv_price(wpinv_format_amount($subscription->recurring_amount), $invoice->get_currency()), |
|
950 | 950 | |
951 | 951 | ); |
952 | 952 | |
@@ -956,20 +956,20 @@ discard block |
||
956 | 956 | } |
957 | 957 | |
958 | 958 | // Add the invoice total to the meta. |
959 | - $meta[ 'invoice_total' ] = array( |
|
959 | + $meta['invoice_total'] = array( |
|
960 | 960 | |
961 | - 'label' => __( 'Total Amount', 'invoicing' ), |
|
962 | - 'value' => wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() ), |
|
961 | + 'label' => __('Total Amount', 'invoicing'), |
|
962 | + 'value' => wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency()), |
|
963 | 963 | |
964 | 964 | ); |
965 | 965 | |
966 | 966 | // Provide a way for third party plugins to filter the meta. |
967 | - $meta = apply_filters( 'getpaid_invoice_meta_data', $meta, $invoice ); |
|
967 | + $meta = apply_filters('getpaid_invoice_meta_data', $meta, $invoice); |
|
968 | 968 | |
969 | - wpinv_get_template( 'invoice/invoice-meta.php', compact( 'invoice', 'meta' ) ); |
|
969 | + wpinv_get_template('invoice/invoice-meta.php', compact('invoice', 'meta')); |
|
970 | 970 | |
971 | 971 | } |
972 | -add_action( 'getpaid_invoice_details_right', 'getpaid_invoice_meta', 10 ); |
|
972 | +add_action('getpaid_invoice_details_right', 'getpaid_invoice_meta', 10); |
|
973 | 973 | |
974 | 974 | /** |
975 | 975 | * Retrieves the address markup to use on Invoices. |
@@ -981,29 +981,29 @@ discard block |
||
981 | 981 | * @param string $separator How to separate address lines. |
982 | 982 | * @return string |
983 | 983 | */ |
984 | -function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) { |
|
984 | +function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') { |
|
985 | 985 | |
986 | 986 | // Retrieve the address markup... |
987 | - $country= empty( $billing_details['country'] ) ? '' : $billing_details['country']; |
|
988 | - $format = wpinv_get_full_address_format( $country ); |
|
987 | + $country = empty($billing_details['country']) ? '' : $billing_details['country']; |
|
988 | + $format = wpinv_get_full_address_format($country); |
|
989 | 989 | |
990 | 990 | // ... and the replacements. |
991 | - $replacements = wpinv_get_invoice_address_replacements( $billing_details ); |
|
991 | + $replacements = wpinv_get_invoice_address_replacements($billing_details); |
|
992 | 992 | |
993 | - $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
|
993 | + $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format); |
|
994 | 994 | |
995 | 995 | // Remove unavailable tags. |
996 | - $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address ); |
|
996 | + $formatted_address = preg_replace("/\{\{\w+\}\}/", '', $formatted_address); |
|
997 | 997 | |
998 | 998 | // Clean up white space. |
999 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
1000 | - $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
|
999 | + $formatted_address = preg_replace('/ +/', ' ', trim($formatted_address)); |
|
1000 | + $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address); |
|
1001 | 1001 | |
1002 | 1002 | // Break newlines apart and remove empty lines/trim commas and white space. |
1003 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
1003 | + $formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address))); |
|
1004 | 1004 | |
1005 | 1005 | // Add html breaks. |
1006 | - $formatted_address = implode( $separator, $formatted_address ); |
|
1006 | + $formatted_address = implode($separator, $formatted_address); |
|
1007 | 1007 | |
1008 | 1008 | // We're done! |
1009 | 1009 | return $formatted_address; |
@@ -1015,88 +1015,88 @@ discard block |
||
1015 | 1015 | * |
1016 | 1016 | * @param WPInv_Invoice $invoice |
1017 | 1017 | */ |
1018 | -function wpinv_display_to_address( $invoice = 0 ) { |
|
1019 | - if ( ! empty( $invoice ) ) { |
|
1020 | - wpinv_get_template( 'invoice/billing-address.php', compact( 'invoice' ) ); |
|
1018 | +function wpinv_display_to_address($invoice = 0) { |
|
1019 | + if (!empty($invoice)) { |
|
1020 | + wpinv_get_template('invoice/billing-address.php', compact('invoice')); |
|
1021 | 1021 | } |
1022 | 1022 | } |
1023 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_to_address', 40 ); |
|
1023 | +add_action('getpaid_invoice_details_left', 'wpinv_display_to_address', 40); |
|
1024 | 1024 | |
1025 | 1025 | |
1026 | 1026 | /** |
1027 | 1027 | * Displays invoice line items. |
1028 | 1028 | */ |
1029 | -function wpinv_display_line_items( $invoice_id = 0 ) { |
|
1029 | +function wpinv_display_line_items($invoice_id = 0) { |
|
1030 | 1030 | |
1031 | 1031 | // Prepare the invoice. |
1032 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
1032 | + $invoice = new WPInv_Invoice($invoice_id); |
|
1033 | 1033 | |
1034 | 1034 | // Abort if there is no invoice. |
1035 | - if ( 0 == $invoice->get_id() ) { |
|
1035 | + if (0 == $invoice->get_id()) { |
|
1036 | 1036 | return; |
1037 | 1037 | } |
1038 | 1038 | |
1039 | 1039 | // Line item columns. |
1040 | - $columns = getpaid_invoice_item_columns( $invoice ); |
|
1041 | - $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice ); |
|
1040 | + $columns = getpaid_invoice_item_columns($invoice); |
|
1041 | + $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice); |
|
1042 | 1042 | |
1043 | - wpinv_get_template( 'invoice/line-items.php', compact( 'invoice', 'columns' ) ); |
|
1043 | + wpinv_get_template('invoice/line-items.php', compact('invoice', 'columns')); |
|
1044 | 1044 | } |
1045 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_line_items', 10 ); |
|
1045 | +add_action('getpaid_invoice_line_items', 'wpinv_display_line_items', 10); |
|
1046 | 1046 | |
1047 | 1047 | /** |
1048 | 1048 | * Displays invoice notices on invoices. |
1049 | 1049 | */ |
1050 | 1050 | function wpinv_display_invoice_notice() { |
1051 | 1051 | |
1052 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
1053 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
1052 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
1053 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
1054 | 1054 | |
1055 | - if ( empty( $label ) && empty( $notice ) ) { |
|
1055 | + if (empty($label) && empty($notice)) { |
|
1056 | 1056 | return; |
1057 | 1057 | } |
1058 | 1058 | |
1059 | 1059 | echo '<div class="mt-4 mb-4 wpinv-vat-notice">'; |
1060 | 1060 | |
1061 | - if ( ! empty( $label ) ) { |
|
1062 | - $label = sanitize_text_field( $label ); |
|
1061 | + if (!empty($label)) { |
|
1062 | + $label = sanitize_text_field($label); |
|
1063 | 1063 | echo "<h5>$label</h5>"; |
1064 | 1064 | } |
1065 | 1065 | |
1066 | - if ( ! empty( $notice ) ) { |
|
1067 | - echo '<small class="form-text text-muted">' . wpautop( wptexturize( $notice ) ) . '</small>'; |
|
1066 | + if (!empty($notice)) { |
|
1067 | + echo '<small class="form-text text-muted">' . wpautop(wptexturize($notice)) . '</small>'; |
|
1068 | 1068 | } |
1069 | 1069 | |
1070 | 1070 | echo '</div>'; |
1071 | 1071 | } |
1072 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100 ); |
|
1072 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100); |
|
1073 | 1073 | |
1074 | 1074 | /** |
1075 | 1075 | * @param WPInv_Invoice $invoice |
1076 | 1076 | */ |
1077 | -function wpinv_display_invoice_notes( $invoice ) { |
|
1077 | +function wpinv_display_invoice_notes($invoice) { |
|
1078 | 1078 | |
1079 | 1079 | // Retrieve the notes. |
1080 | - $notes = wpinv_get_invoice_notes( $invoice->get_id(), 'customer' ); |
|
1080 | + $notes = wpinv_get_invoice_notes($invoice->get_id(), 'customer'); |
|
1081 | 1081 | |
1082 | 1082 | // Abort if we have non. |
1083 | - if ( empty( $notes ) ) { |
|
1083 | + if (empty($notes)) { |
|
1084 | 1084 | return; |
1085 | 1085 | } |
1086 | 1086 | |
1087 | 1087 | // Echo the note. |
1088 | 1088 | echo '<div class="getpaid-invoice-notes-wrapper border position-relative w-100 mb-4 p-0">'; |
1089 | - echo '<h3 class="getpaid-invoice-notes-title text-dark bg-light border-bottom m-0 d-block">' . __( 'Notes', 'invoicing' ) .'</h3>'; |
|
1089 | + echo '<h3 class="getpaid-invoice-notes-title text-dark bg-light border-bottom m-0 d-block">' . __('Notes', 'invoicing') . '</h3>'; |
|
1090 | 1090 | echo '<ul class="getpaid-invoice-notes mt-4 p-0">'; |
1091 | 1091 | |
1092 | - foreach( $notes as $note ) { |
|
1093 | - wpinv_get_invoice_note_line_item( $note ); |
|
1092 | + foreach ($notes as $note) { |
|
1093 | + wpinv_get_invoice_note_line_item($note); |
|
1094 | 1094 | } |
1095 | 1095 | |
1096 | 1096 | echo '</ul>'; |
1097 | 1097 | echo '</div>'; |
1098 | 1098 | } |
1099 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60 ); |
|
1099 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60); |
|
1100 | 1100 | |
1101 | 1101 | /** |
1102 | 1102 | * Loads scripts on our invoice templates. |
@@ -1104,32 +1104,32 @@ discard block |
||
1104 | 1104 | function wpinv_display_style() { |
1105 | 1105 | |
1106 | 1106 | // Make sure that all scripts have been loaded. |
1107 | - if ( ! did_action( 'wp_enqueue_scripts' ) ) { |
|
1108 | - do_action( 'wp_enqueue_scripts' ); |
|
1107 | + if (!did_action('wp_enqueue_scripts')) { |
|
1108 | + do_action('wp_enqueue_scripts'); |
|
1109 | 1109 | } |
1110 | 1110 | |
1111 | 1111 | // Register the invoices style. |
1112 | - wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice.css' ) ); |
|
1112 | + wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice.css')); |
|
1113 | 1113 | |
1114 | 1114 | // Load required styles |
1115 | - wp_print_styles( 'open-sans' ); |
|
1116 | - wp_print_styles( 'wpinv-single-style' ); |
|
1117 | - wp_print_styles( 'ayecode-ui' ); |
|
1115 | + wp_print_styles('open-sans'); |
|
1116 | + wp_print_styles('wpinv-single-style'); |
|
1117 | + wp_print_styles('ayecode-ui'); |
|
1118 | 1118 | |
1119 | 1119 | // Maybe load custom css. |
1120 | - $custom_css = wpinv_get_option( 'template_custom_css' ); |
|
1120 | + $custom_css = wpinv_get_option('template_custom_css'); |
|
1121 | 1121 | |
1122 | - if ( isset( $custom_css ) && ! empty( $custom_css ) ) { |
|
1123 | - $custom_css = wp_kses( $custom_css, array( '\'', '\"' ) ); |
|
1124 | - $custom_css = str_replace( '>', '>', $custom_css ); |
|
1122 | + if (isset($custom_css) && !empty($custom_css)) { |
|
1123 | + $custom_css = wp_kses($custom_css, array('\'', '\"')); |
|
1124 | + $custom_css = str_replace('>', '>', $custom_css); |
|
1125 | 1125 | echo '<style type="text/css">'; |
1126 | 1126 | echo $custom_css; |
1127 | 1127 | echo '</style>'; |
1128 | 1128 | } |
1129 | 1129 | |
1130 | 1130 | } |
1131 | -add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
1132 | -add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' ); |
|
1131 | +add_action('wpinv_invoice_print_head', 'wpinv_display_style'); |
|
1132 | +add_action('wpinv_invalid_invoice_head', 'wpinv_display_style'); |
|
1133 | 1133 | |
1134 | 1134 | |
1135 | 1135 | /** |
@@ -1141,41 +1141,41 @@ discard block |
||
1141 | 1141 | // Retrieve the current invoice. |
1142 | 1142 | $invoice_id = getpaid_get_current_invoice_id(); |
1143 | 1143 | |
1144 | - if ( empty( $invoice_id ) ) { |
|
1144 | + if (empty($invoice_id)) { |
|
1145 | 1145 | |
1146 | 1146 | return aui()->alert( |
1147 | 1147 | array( |
1148 | 1148 | 'type' => 'warning', |
1149 | - 'content' => __( 'Invalid invoice', 'invoicing' ), |
|
1149 | + 'content' => __('Invalid invoice', 'invoicing'), |
|
1150 | 1150 | ) |
1151 | 1151 | ); |
1152 | 1152 | |
1153 | 1153 | } |
1154 | 1154 | |
1155 | 1155 | // Can the user view this invoice? |
1156 | - if ( ! wpinv_user_can_view_invoice( $invoice_id ) ) { |
|
1156 | + if (!wpinv_user_can_view_invoice($invoice_id)) { |
|
1157 | 1157 | |
1158 | 1158 | return aui()->alert( |
1159 | 1159 | array( |
1160 | 1160 | 'type' => 'warning', |
1161 | - 'content' => __( 'You are not allowed to view this invoice', 'invoicing' ), |
|
1161 | + 'content' => __('You are not allowed to view this invoice', 'invoicing'), |
|
1162 | 1162 | ) |
1163 | 1163 | ); |
1164 | 1164 | |
1165 | 1165 | } |
1166 | 1166 | |
1167 | 1167 | // Ensure that it is not yet paid for. |
1168 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
1168 | + $invoice = new WPInv_Invoice($invoice_id); |
|
1169 | 1169 | |
1170 | 1170 | // Maybe mark it as viewed. |
1171 | - getpaid_maybe_mark_invoice_as_viewed( $invoice ); |
|
1171 | + getpaid_maybe_mark_invoice_as_viewed($invoice); |
|
1172 | 1172 | |
1173 | - if ( $invoice->is_paid() ) { |
|
1173 | + if ($invoice->is_paid()) { |
|
1174 | 1174 | |
1175 | 1175 | return aui()->alert( |
1176 | 1176 | array( |
1177 | 1177 | 'type' => 'success', |
1178 | - 'content' => __( 'This invoice has already been paid.', 'invoicing' ), |
|
1178 | + 'content' => __('This invoice has already been paid.', 'invoicing'), |
|
1179 | 1179 | ) |
1180 | 1180 | ); |
1181 | 1181 | |
@@ -1185,14 +1185,14 @@ discard block |
||
1185 | 1185 | $wpi_checkout_id = $invoice_id; |
1186 | 1186 | |
1187 | 1187 | // We'll display this invoice via the default form. |
1188 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1188 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1189 | 1189 | |
1190 | - if ( 0 == $form->get_id() ) { |
|
1190 | + if (0 == $form->get_id()) { |
|
1191 | 1191 | |
1192 | 1192 | return aui()->alert( |
1193 | 1193 | array( |
1194 | 1194 | 'type' => 'warning', |
1195 | - 'content' => __( 'Error loading the payment form', 'invoicing' ), |
|
1195 | + 'content' => __('Error loading the payment form', 'invoicing'), |
|
1196 | 1196 | ) |
1197 | 1197 | ); |
1198 | 1198 | |
@@ -1200,7 +1200,7 @@ discard block |
||
1200 | 1200 | |
1201 | 1201 | // Set the invoice. |
1202 | 1202 | $form->invoice = $invoice; |
1203 | - $form->set_items( $invoice->get_items() ); |
|
1203 | + $form->set_items($invoice->get_items()); |
|
1204 | 1204 | |
1205 | 1205 | // Generate the html. |
1206 | 1206 | return $form->get_html(); |
@@ -1208,7 +1208,7 @@ discard block |
||
1208 | 1208 | } |
1209 | 1209 | |
1210 | 1210 | function wpinv_empty_cart_message() { |
1211 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1211 | + return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>'); |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | /** |
@@ -1225,38 +1225,38 @@ discard block |
||
1225 | 1225 | ) |
1226 | 1226 | ); |
1227 | 1227 | } |
1228 | -add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
1228 | +add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart'); |
|
1229 | 1229 | |
1230 | -function wpinv_receipt_billing_address( $invoice_id = 0 ) { |
|
1231 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1230 | +function wpinv_receipt_billing_address($invoice_id = 0) { |
|
1231 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1232 | 1232 | |
1233 | - if ( empty( $invoice ) ) { |
|
1233 | + if (empty($invoice)) { |
|
1234 | 1234 | return NULL; |
1235 | 1235 | } |
1236 | 1236 | |
1237 | 1237 | $billing_details = $invoice->get_user_info(); |
1238 | - $address_row = wpinv_get_invoice_address_markup( $billing_details ); |
|
1238 | + $address_row = wpinv_get_invoice_address_markup($billing_details); |
|
1239 | 1239 | |
1240 | 1240 | ob_start(); |
1241 | 1241 | ?> |
1242 | 1242 | <table class="table table-bordered table-sm wpi-billing-details"> |
1243 | 1243 | <tbody> |
1244 | 1244 | <tr class="wpi-receipt-name"> |
1245 | - <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th> |
|
1246 | - <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td> |
|
1245 | + <th class="text-left"><?php _e('Name', 'invoicing'); ?></th> |
|
1246 | + <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td> |
|
1247 | 1247 | </tr> |
1248 | 1248 | <tr class="wpi-receipt-email"> |
1249 | - <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th> |
|
1250 | - <td><?php echo $billing_details['email'] ;?></td> |
|
1249 | + <th class="text-left"><?php _e('Email', 'invoicing'); ?></th> |
|
1250 | + <td><?php echo $billing_details['email']; ?></td> |
|
1251 | 1251 | </tr> |
1252 | 1252 | <tr class="wpi-receipt-address"> |
1253 | - <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th> |
|
1254 | - <td><?php echo $address_row ;?></td> |
|
1253 | + <th class="text-left"><?php _e('Address', 'invoicing'); ?></th> |
|
1254 | + <td><?php echo $address_row; ?></td> |
|
1255 | 1255 | </tr> |
1256 | - <?php if ( $billing_details['phone'] ) { ?> |
|
1256 | + <?php if ($billing_details['phone']) { ?> |
|
1257 | 1257 | <tr class="wpi-receipt-phone"> |
1258 | - <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th> |
|
1259 | - <td><?php echo esc_html( $billing_details['phone'] ) ;?></td> |
|
1258 | + <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th> |
|
1259 | + <td><?php echo esc_html($billing_details['phone']); ?></td> |
|
1260 | 1260 | </tr> |
1261 | 1261 | <?php } ?> |
1262 | 1262 | </tbody> |
@@ -1264,7 +1264,7 @@ discard block |
||
1264 | 1264 | <?php |
1265 | 1265 | $output = ob_get_clean(); |
1266 | 1266 | |
1267 | - $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id ); |
|
1267 | + $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id); |
|
1268 | 1268 | |
1269 | 1269 | echo $output; |
1270 | 1270 | } |
@@ -1272,88 +1272,88 @@ discard block |
||
1272 | 1272 | /** |
1273 | 1273 | * Filters the receipt page. |
1274 | 1274 | */ |
1275 | -function wpinv_filter_success_page_content( $content ) { |
|
1275 | +function wpinv_filter_success_page_content($content) { |
|
1276 | 1276 | |
1277 | 1277 | // Ensure this is our page. |
1278 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
1278 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
1279 | 1279 | |
1280 | - $gateway = sanitize_text_field( $_GET['payment-confirm'] ); |
|
1281 | - return apply_filters( "wpinv_payment_confirm_$gateway", $content ); |
|
1280 | + $gateway = sanitize_text_field($_GET['payment-confirm']); |
|
1281 | + return apply_filters("wpinv_payment_confirm_$gateway", $content); |
|
1282 | 1282 | |
1283 | 1283 | } |
1284 | 1284 | |
1285 | 1285 | return $content; |
1286 | 1286 | } |
1287 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
1287 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
1288 | 1288 | |
1289 | -function wpinv_invoice_link( $invoice_id ) { |
|
1290 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1289 | +function wpinv_invoice_link($invoice_id) { |
|
1290 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1291 | 1291 | |
1292 | - if ( empty( $invoice ) ) { |
|
1292 | + if (empty($invoice)) { |
|
1293 | 1293 | return NULL; |
1294 | 1294 | } |
1295 | 1295 | |
1296 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
1296 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
1297 | 1297 | |
1298 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
1298 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
1299 | 1299 | } |
1300 | 1300 | |
1301 | -function wpinv_cart_total_label( $label, $invoice ) { |
|
1302 | - if ( empty( $invoice ) ) { |
|
1301 | +function wpinv_cart_total_label($label, $invoice) { |
|
1302 | + if (empty($invoice)) { |
|
1303 | 1303 | return $label; |
1304 | 1304 | } |
1305 | 1305 | |
1306 | 1306 | $prefix_label = ''; |
1307 | - if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) { |
|
1308 | - $prefix_label = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice ); |
|
1309 | - } else if ( $invoice->is_renewal() ) { |
|
1310 | - $prefix_label = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> '; |
|
1307 | + if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) { |
|
1308 | + $prefix_label = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice); |
|
1309 | + } else if ($invoice->is_renewal()) { |
|
1310 | + $prefix_label = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> '; |
|
1311 | 1311 | } |
1312 | 1312 | |
1313 | - if ( $prefix_label != '' ) { |
|
1314 | - $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
1313 | + if ($prefix_label != '') { |
|
1314 | + $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
1315 | 1315 | } |
1316 | 1316 | |
1317 | 1317 | return $label; |
1318 | 1318 | } |
1319 | -add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
1320 | -add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
1321 | -add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
1319 | +add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
1320 | +add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
1321 | +add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
1322 | 1322 | |
1323 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
1324 | - if ( empty( $note ) ) { |
|
1323 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
1324 | + if (empty($note)) { |
|
1325 | 1325 | return NULL; |
1326 | 1326 | } |
1327 | 1327 | |
1328 | - if ( is_int( $note ) ) { |
|
1329 | - $note = get_comment( $note ); |
|
1328 | + if (is_int($note)) { |
|
1329 | + $note = get_comment($note); |
|
1330 | 1330 | } |
1331 | 1331 | |
1332 | - if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
1332 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
1333 | 1333 | return NULL; |
1334 | 1334 | } |
1335 | 1335 | |
1336 | - $note_classes = array( 'note' ); |
|
1337 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
1336 | + $note_classes = array('note'); |
|
1337 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
1338 | 1338 | $note_classes[] = $note->comment_author === 'System' ? 'system-note' : ''; |
1339 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
1340 | - $note_classes = !empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
1339 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
1340 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
1341 | 1341 | |
1342 | 1342 | ob_start(); |
1343 | 1343 | ?> |
1344 | - <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?> mt-4 pl-3 pr-3"> |
|
1344 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?> mt-4 pl-3 pr-3"> |
|
1345 | 1345 | <div class="note_content bg-light border position-relative p-4"> |
1346 | 1346 | |
1347 | - <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?> |
|
1347 | + <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?> |
|
1348 | 1348 | |
1349 | - <?php if ( ! is_admin() ) : ?> |
|
1349 | + <?php if (!is_admin()) : ?> |
|
1350 | 1350 | <em class="meta position-absolute form-text"> |
1351 | 1351 | <?php |
1352 | 1352 | printf( |
1353 | - __( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
1353 | + __('%1$s - %2$s at %3$s', 'invoicing'), |
|
1354 | 1354 | $note->comment_author, |
1355 | - date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), |
|
1356 | - date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) |
|
1355 | + date_i18n(get_option('date_format'), strtotime($note->comment_date)), |
|
1356 | + date_i18n(get_option('time_format'), strtotime($note->comment_date)) |
|
1357 | 1357 | ); |
1358 | 1358 | ?> |
1359 | 1359 | </em> |
@@ -1361,12 +1361,12 @@ discard block |
||
1361 | 1361 | |
1362 | 1362 | </div> |
1363 | 1363 | |
1364 | - <?php if ( is_admin() ) : ?> |
|
1364 | + <?php if (is_admin()) : ?> |
|
1365 | 1365 | |
1366 | 1366 | <p class="meta px-4 py-2"> |
1367 | - <abbr class="exact-date" title="<?php echo esc_attr( $note->comment_date ); ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr> |
|
1368 | - <?php if ( $note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing() ) { ?> |
|
1369 | - <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a> |
|
1367 | + <abbr class="exact-date" title="<?php echo esc_attr($note->comment_date); ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr> |
|
1368 | + <?php if ($note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing()) { ?> |
|
1369 | + <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a> |
|
1370 | 1370 | <?php } ?> |
1371 | 1371 | </p> |
1372 | 1372 | |
@@ -1375,9 +1375,9 @@ discard block |
||
1375 | 1375 | </li> |
1376 | 1376 | <?php |
1377 | 1377 | $note_content = ob_get_clean(); |
1378 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
1378 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
1379 | 1379 | |
1380 | - if ( $echo ) { |
|
1380 | + if ($echo) { |
|
1381 | 1381 | echo $note_content; |
1382 | 1382 | } else { |
1383 | 1383 | return $note_content; |
@@ -1387,36 +1387,36 @@ discard block |
||
1387 | 1387 | function wpinv_invalid_invoice_content() { |
1388 | 1388 | global $post; |
1389 | 1389 | |
1390 | - $invoice = wpinv_get_invoice( $post->ID ); |
|
1390 | + $invoice = wpinv_get_invoice($post->ID); |
|
1391 | 1391 | |
1392 | - $error = __( 'This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing' ); |
|
1393 | - if ( !empty( $invoice->get_id() ) && $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) { |
|
1394 | - if ( is_user_logged_in() ) { |
|
1395 | - if ( wpinv_require_login_to_checkout() ) { |
|
1396 | - if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
1397 | - $error = __( 'You are not allowed to view this invoice.', 'invoicing' ); |
|
1392 | + $error = __('This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing'); |
|
1393 | + if (!empty($invoice->get_id()) && $invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) { |
|
1394 | + if (is_user_logged_in()) { |
|
1395 | + if (wpinv_require_login_to_checkout()) { |
|
1396 | + if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
1397 | + $error = __('You are not allowed to view this invoice.', 'invoicing'); |
|
1398 | 1398 | } |
1399 | 1399 | } |
1400 | 1400 | } else { |
1401 | - if ( wpinv_require_login_to_checkout() ) { |
|
1402 | - if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
1403 | - $error = __( 'You must be logged in to view this invoice.', 'invoicing' ); |
|
1401 | + if (wpinv_require_login_to_checkout()) { |
|
1402 | + if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
1403 | + $error = __('You must be logged in to view this invoice.', 'invoicing'); |
|
1404 | 1404 | } |
1405 | 1405 | } |
1406 | 1406 | } |
1407 | 1407 | } else { |
1408 | - $error = __( 'This invoice is deleted or does not exist.', 'invoicing' ); |
|
1408 | + $error = __('This invoice is deleted or does not exist.', 'invoicing'); |
|
1409 | 1409 | } |
1410 | 1410 | ?> |
1411 | 1411 | <div class="row wpinv-row-invalid"> |
1412 | 1412 | <div class="col-md-6 col-md-offset-3 wpinv-message error"> |
1413 | - <h3><?php _e( 'Access Denied', 'invoicing' ); ?></h3> |
|
1413 | + <h3><?php _e('Access Denied', 'invoicing'); ?></h3> |
|
1414 | 1414 | <p class="wpinv-msg-text"><?php echo $error; ?></p> |
1415 | 1415 | </div> |
1416 | 1416 | </div> |
1417 | 1417 | <?php |
1418 | 1418 | } |
1419 | -add_action( 'wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content' ); |
|
1419 | +add_action('wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content'); |
|
1420 | 1420 | |
1421 | 1421 | /** |
1422 | 1422 | * Function to get privacy policy text. |
@@ -1425,21 +1425,21 @@ discard block |
||
1425 | 1425 | * @return string |
1426 | 1426 | */ |
1427 | 1427 | function wpinv_get_policy_text() { |
1428 | - $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 ); |
|
1428 | + $privacy_page_id = get_option('wp_page_for_privacy_policy', 0); |
|
1429 | 1429 | |
1430 | - $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]' )); |
|
1430 | + $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]')); |
|
1431 | 1431 | |
1432 | - if(!$privacy_page_id){ |
|
1433 | - $privacy_page_id = wpinv_get_option( 'privacy_page', 0 ); |
|
1432 | + if (!$privacy_page_id) { |
|
1433 | + $privacy_page_id = wpinv_get_option('privacy_page', 0); |
|
1434 | 1434 | } |
1435 | 1435 | |
1436 | - $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' ); |
|
1436 | + $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'); |
|
1437 | 1437 | |
1438 | 1438 | $find_replace = array( |
1439 | 1439 | '[wpinv_privacy_policy]' => $privacy_link, |
1440 | 1440 | ); |
1441 | 1441 | |
1442 | - $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text ); |
|
1442 | + $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text); |
|
1443 | 1443 | |
1444 | 1444 | return wp_kses_post(wpautop($privacy_text)); |
1445 | 1445 | } |
@@ -1447,21 +1447,21 @@ discard block |
||
1447 | 1447 | function wpinv_oxygen_fix_conflict() { |
1448 | 1448 | global $ct_ignore_post_types; |
1449 | 1449 | |
1450 | - if ( ! is_array( $ct_ignore_post_types ) ) { |
|
1450 | + if (!is_array($ct_ignore_post_types)) { |
|
1451 | 1451 | $ct_ignore_post_types = array(); |
1452 | 1452 | } |
1453 | 1453 | |
1454 | - $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item' ); |
|
1454 | + $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item'); |
|
1455 | 1455 | |
1456 | - foreach ( $post_types as $post_type ) { |
|
1456 | + foreach ($post_types as $post_type) { |
|
1457 | 1457 | $ct_ignore_post_types[] = $post_type; |
1458 | 1458 | |
1459 | 1459 | // Ignore post type |
1460 | - add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 ); |
|
1460 | + add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999); |
|
1461 | 1461 | } |
1462 | 1462 | |
1463 | - remove_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
1464 | - add_filter( 'template_include', 'wpinv_template', 999, 1 ); |
|
1463 | + remove_filter('template_include', 'wpinv_template', 10, 1); |
|
1464 | + add_filter('template_include', 'wpinv_template', 999, 1); |
|
1465 | 1465 | } |
1466 | 1466 | |
1467 | 1467 | /** |
@@ -1469,10 +1469,10 @@ discard block |
||
1469 | 1469 | * |
1470 | 1470 | * @param GetPaid_Payment_Form $form |
1471 | 1471 | */ |
1472 | -function getpaid_display_payment_form( $form ) { |
|
1472 | +function getpaid_display_payment_form($form) { |
|
1473 | 1473 | |
1474 | - if ( is_numeric( $form ) ) { |
|
1475 | - $form = new GetPaid_Payment_Form( $form ); |
|
1474 | + if (is_numeric($form)) { |
|
1475 | + $form = new GetPaid_Payment_Form($form); |
|
1476 | 1476 | } |
1477 | 1477 | |
1478 | 1478 | $form->display(); |
@@ -1482,16 +1482,16 @@ discard block |
||
1482 | 1482 | /** |
1483 | 1483 | * Helper function to display a item payment form on the frontend. |
1484 | 1484 | */ |
1485 | -function getpaid_display_item_payment_form( $items ) { |
|
1485 | +function getpaid_display_item_payment_form($items) { |
|
1486 | 1486 | |
1487 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1488 | - $form->set_items( $items ); |
|
1487 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1488 | + $form->set_items($items); |
|
1489 | 1489 | |
1490 | - if ( 0 == count( $form->get_items() ) ) { |
|
1490 | + if (0 == count($form->get_items())) { |
|
1491 | 1491 | echo aui()->alert( |
1492 | 1492 | array( |
1493 | 1493 | 'type' => 'warning', |
1494 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
1494 | + 'content' => __('No published items found', 'invoicing'), |
|
1495 | 1495 | ) |
1496 | 1496 | ); |
1497 | 1497 | return; |
@@ -1503,75 +1503,75 @@ discard block |
||
1503 | 1503 | /** |
1504 | 1504 | * Helper function to display an invoice payment form on the frontend. |
1505 | 1505 | */ |
1506 | -function getpaid_display_invoice_payment_form( $invoice_id ) { |
|
1506 | +function getpaid_display_invoice_payment_form($invoice_id) { |
|
1507 | 1507 | global $invoicing; |
1508 | 1508 | |
1509 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1509 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1510 | 1510 | |
1511 | - if ( empty( $invoice ) ) { |
|
1511 | + if (empty($invoice)) { |
|
1512 | 1512 | return aui()->alert( |
1513 | 1513 | array( |
1514 | 1514 | 'type' => 'warning', |
1515 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1515 | + 'content' => __('Invoice not found', 'invoicing'), |
|
1516 | 1516 | ) |
1517 | 1517 | ); |
1518 | 1518 | } |
1519 | 1519 | |
1520 | - if ( $invoice->is_paid() ) { |
|
1520 | + if ($invoice->is_paid()) { |
|
1521 | 1521 | return aui()->alert( |
1522 | 1522 | array( |
1523 | 1523 | 'type' => 'warning', |
1524 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1524 | + 'content' => __('Invoice has already been paid', 'invoicing'), |
|
1525 | 1525 | ) |
1526 | 1526 | ); |
1527 | 1527 | } |
1528 | 1528 | |
1529 | 1529 | // Get the form elements and items. |
1530 | - $form = wpinv_get_default_payment_form(); |
|
1531 | - $elements = $invoicing->form_elements->get_form_elements( $form ); |
|
1532 | - $items = $invoicing->form_elements->convert_checkout_items( $invoice->cart_details, $invoice ); |
|
1530 | + $form = wpinv_get_default_payment_form(); |
|
1531 | + $elements = $invoicing->form_elements->get_form_elements($form); |
|
1532 | + $items = $invoicing->form_elements->convert_checkout_items($invoice->cart_details, $invoice); |
|
1533 | 1533 | |
1534 | 1534 | ob_start(); |
1535 | 1535 | echo "<form class='wpinv_payment_form'>"; |
1536 | - do_action( 'wpinv_payment_form_top' ); |
|
1536 | + do_action('wpinv_payment_form_top'); |
|
1537 | 1537 | echo "<input type='hidden' name='form_id' value='$form'/>"; |
1538 | 1538 | echo "<input type='hidden' name='invoice_id' value='$invoice_id'/>"; |
1539 | - wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' ); |
|
1540 | - wp_nonce_field( 'vat_validation', '_wpi_nonce' ); |
|
1539 | + wp_nonce_field('wpinv_payment_form', 'wpinv_payment_form'); |
|
1540 | + wp_nonce_field('vat_validation', '_wpi_nonce'); |
|
1541 | 1541 | |
1542 | - foreach ( $elements as $element ) { |
|
1543 | - do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $form ); |
|
1544 | - do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form ); |
|
1542 | + foreach ($elements as $element) { |
|
1543 | + do_action('wpinv_frontend_render_payment_form_element', $element, $items, $form); |
|
1544 | + do_action("wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form); |
|
1545 | 1545 | } |
1546 | 1546 | |
1547 | 1547 | echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>"; |
1548 | - do_action( 'wpinv_payment_form_bottom' ); |
|
1548 | + do_action('wpinv_payment_form_bottom'); |
|
1549 | 1549 | echo '</form>'; |
1550 | 1550 | |
1551 | 1551 | $content = ob_get_clean(); |
1552 | - return str_replace( 'sr-only', '', $content ); |
|
1552 | + return str_replace('sr-only', '', $content); |
|
1553 | 1553 | } |
1554 | 1554 | |
1555 | 1555 | /** |
1556 | 1556 | * Helper function to convert item string to array. |
1557 | 1557 | */ |
1558 | -function getpaid_convert_items_to_array( $items ) { |
|
1559 | - $items = array_filter( array_map( 'trim', explode( ',', $items ) ) ); |
|
1558 | +function getpaid_convert_items_to_array($items) { |
|
1559 | + $items = array_filter(array_map('trim', explode(',', $items))); |
|
1560 | 1560 | $prepared = array(); |
1561 | 1561 | |
1562 | - foreach ( $items as $item ) { |
|
1563 | - $data = array_map( 'trim', explode( '|', $item ) ); |
|
1562 | + foreach ($items as $item) { |
|
1563 | + $data = array_map('trim', explode('|', $item)); |
|
1564 | 1564 | |
1565 | - if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) { |
|
1565 | + if (empty($data[0]) || !is_numeric($data[0])) { |
|
1566 | 1566 | continue; |
1567 | 1567 | } |
1568 | 1568 | |
1569 | 1569 | $quantity = 1; |
1570 | - if ( isset( $data[1] ) && is_numeric( $data[1] ) ) { |
|
1570 | + if (isset($data[1]) && is_numeric($data[1])) { |
|
1571 | 1571 | $quantity = (int) $data[1]; |
1572 | 1572 | } |
1573 | 1573 | |
1574 | - $prepared[ $data[0] ] = $quantity; |
|
1574 | + $prepared[$data[0]] = $quantity; |
|
1575 | 1575 | |
1576 | 1576 | } |
1577 | 1577 | |
@@ -1581,13 +1581,13 @@ discard block |
||
1581 | 1581 | /** |
1582 | 1582 | * Helper function to convert item array to string. |
1583 | 1583 | */ |
1584 | -function getpaid_convert_items_to_string( $items ) { |
|
1584 | +function getpaid_convert_items_to_string($items) { |
|
1585 | 1585 | $prepared = array(); |
1586 | 1586 | |
1587 | - foreach ( $items as $item => $quantity ) { |
|
1587 | + foreach ($items as $item => $quantity) { |
|
1588 | 1588 | $prepared[] = "$item|$quantity"; |
1589 | 1589 | } |
1590 | - return implode( ',', $prepared ); |
|
1590 | + return implode(',', $prepared); |
|
1591 | 1591 | } |
1592 | 1592 | |
1593 | 1593 | /** |
@@ -1595,22 +1595,22 @@ discard block |
||
1595 | 1595 | * |
1596 | 1596 | * Provide a label and one of $form, $items or $invoice. |
1597 | 1597 | */ |
1598 | -function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) { |
|
1599 | - $label = sanitize_text_field( $label ); |
|
1598 | +function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) { |
|
1599 | + $label = sanitize_text_field($label); |
|
1600 | 1600 | $nonce = wp_create_nonce('getpaid_ajax_form'); |
1601 | 1601 | |
1602 | - if ( ! empty( $form ) ) { |
|
1603 | - $form = esc_attr( $form ); |
|
1602 | + if (!empty($form)) { |
|
1603 | + $form = esc_attr($form); |
|
1604 | 1604 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-form='$form'>$label</button>"; |
1605 | 1605 | } |
1606 | 1606 | |
1607 | - if ( ! empty( $items ) ) { |
|
1608 | - $items = esc_attr( $items ); |
|
1607 | + if (!empty($items)) { |
|
1608 | + $items = esc_attr($items); |
|
1609 | 1609 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-item='$items'>$label</button>"; |
1610 | 1610 | } |
1611 | 1611 | |
1612 | - if ( ! empty( $invoice ) ) { |
|
1613 | - $invoice = esc_attr( $invoice ); |
|
1612 | + if (!empty($invoice)) { |
|
1613 | + $invoice = esc_attr($invoice); |
|
1614 | 1614 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-invoice='$invoice'>$label</button>"; |
1615 | 1615 | } |
1616 | 1616 | |
@@ -1621,17 +1621,17 @@ discard block |
||
1621 | 1621 | * |
1622 | 1622 | * @param WPInv_Invoice $invoice |
1623 | 1623 | */ |
1624 | -function getpaid_the_invoice_description( $invoice ) { |
|
1624 | +function getpaid_the_invoice_description($invoice) { |
|
1625 | 1625 | $description = $invoice->get_description(); |
1626 | 1626 | |
1627 | - if ( empty( $description ) ) { |
|
1627 | + if (empty($description)) { |
|
1628 | 1628 | return; |
1629 | 1629 | } |
1630 | 1630 | |
1631 | - $description = wp_kses_post( $description ); |
|
1631 | + $description = wp_kses_post($description); |
|
1632 | 1632 | echo "<small class='getpaid-invoice-description text-dark p-2 form-text'><em>$description</em></small>"; |
1633 | 1633 | } |
1634 | -add_action( 'getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100 ); |
|
1634 | +add_action('getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100); |
|
1635 | 1635 | |
1636 | 1636 | /** |
1637 | 1637 | * Render element on a form. |
@@ -1639,41 +1639,41 @@ discard block |
||
1639 | 1639 | * @param array $element |
1640 | 1640 | * @param GetPaid_Payment_Form $form |
1641 | 1641 | */ |
1642 | -function getpaid_payment_form_element( $element, $form ) { |
|
1642 | +function getpaid_payment_form_element($element, $form) { |
|
1643 | 1643 | |
1644 | 1644 | // Set up the args. |
1645 | - $element_type = trim( $element['type'] ); |
|
1645 | + $element_type = trim($element['type']); |
|
1646 | 1646 | $element['form'] = $form; |
1647 | - extract( $element ); |
|
1647 | + extract($element); |
|
1648 | 1648 | |
1649 | 1649 | // Try to locate the appropriate template. |
1650 | - $located = wpinv_locate_template( "payment-forms/elements/$element_type.php" ); |
|
1650 | + $located = wpinv_locate_template("payment-forms/elements/$element_type.php"); |
|
1651 | 1651 | |
1652 | 1652 | // Abort if this is not our element. |
1653 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1653 | + if (empty($located) || !file_exists($located)) { |
|
1654 | 1654 | return; |
1655 | 1655 | } |
1656 | 1656 | |
1657 | 1657 | // Generate the class and id of the element. |
1658 | - $wrapper_class = 'getpaid-payment-form-element-' . trim( esc_attr( $element_type ) ); |
|
1659 | - $id = isset( $id ) ? $id : uniqid( 'gp' ); |
|
1658 | + $wrapper_class = 'getpaid-payment-form-element-' . trim(esc_attr($element_type)); |
|
1659 | + $id = isset($id) ? $id : uniqid('gp'); |
|
1660 | 1660 | |
1661 | 1661 | // Echo the opening wrapper. |
1662 | 1662 | echo "<div class='getpaid-payment-form-element $wrapper_class'>"; |
1663 | 1663 | |
1664 | 1664 | // Fires before displaying a given element type's content. |
1665 | - do_action( "getpaid_before_payment_form_{$element_type}_element", $element, $form ); |
|
1665 | + do_action("getpaid_before_payment_form_{$element_type}_element", $element, $form); |
|
1666 | 1666 | |
1667 | 1667 | // Include the template for the element. |
1668 | 1668 | include $located; |
1669 | 1669 | |
1670 | 1670 | // Fires after displaying a given element type's content. |
1671 | - do_action( "getpaid_payment_form_{$element_type}_element", $element, $form ); |
|
1671 | + do_action("getpaid_payment_form_{$element_type}_element", $element, $form); |
|
1672 | 1672 | |
1673 | 1673 | // Echo the closing wrapper. |
1674 | 1674 | echo '</div>'; |
1675 | 1675 | } |
1676 | -add_action( 'getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2 ); |
|
1676 | +add_action('getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2); |
|
1677 | 1677 | |
1678 | 1678 | /** |
1679 | 1679 | * Shows a list of gateways that support recurring payments. |
@@ -1681,17 +1681,17 @@ discard block |
||
1681 | 1681 | function wpinv_get_recurring_gateways_text() { |
1682 | 1682 | $gateways = array(); |
1683 | 1683 | |
1684 | - foreach ( wpinv_get_payment_gateways() as $key => $gateway ) { |
|
1685 | - if ( wpinv_gateway_support_subscription( $key ) ) { |
|
1686 | - $gateways[] = sanitize_text_field( $gateway['admin_label'] ); |
|
1684 | + foreach (wpinv_get_payment_gateways() as $key => $gateway) { |
|
1685 | + if (wpinv_gateway_support_subscription($key)) { |
|
1686 | + $gateways[] = sanitize_text_field($gateway['admin_label']); |
|
1687 | 1687 | } |
1688 | 1688 | } |
1689 | 1689 | |
1690 | - if ( empty( $gateways ) ) { |
|
1691 | - return "<span class='form-text text-danger'>" . __( 'No active gateways support subscription payments.', 'invoicing' ) ."</span>"; |
|
1690 | + if (empty($gateways)) { |
|
1691 | + return "<span class='form-text text-danger'>" . __('No active gateways support subscription payments.', 'invoicing') . "</span>"; |
|
1692 | 1692 | } |
1693 | 1693 | |
1694 | - return "<span class='form-text text-muted'>" . wp_sprintf( __( 'Subscription payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ) ."</span>"; |
|
1694 | + return "<span class='form-text text-muted'>" . wp_sprintf(__('Subscription payments only supported by: %s', 'invoicing'), implode(', ', $gateways)) . "</span>"; |
|
1695 | 1695 | |
1696 | 1696 | } |
1697 | 1697 | |
@@ -1701,7 +1701,7 @@ discard block |
||
1701 | 1701 | * @return GetPaid_Template |
1702 | 1702 | */ |
1703 | 1703 | function getpaid_template() { |
1704 | - return getpaid()->get( 'template' ); |
|
1704 | + return getpaid()->get('template'); |
|
1705 | 1705 | } |
1706 | 1706 | |
1707 | 1707 | /** |
@@ -1710,23 +1710,23 @@ discard block |
||
1710 | 1710 | * @param array args |
1711 | 1711 | * @return string |
1712 | 1712 | */ |
1713 | -function getpaid_paginate_links( $args ) { |
|
1713 | +function getpaid_paginate_links($args) { |
|
1714 | 1714 | |
1715 | 1715 | $args['type'] = 'array'; |
1716 | 1716 | $args['mid_size'] = 1; |
1717 | - $pages = paginate_links( $args ); |
|
1717 | + $pages = paginate_links($args); |
|
1718 | 1718 | |
1719 | - if ( ! is_array( $pages ) ) { |
|
1719 | + if (!is_array($pages)) { |
|
1720 | 1720 | return ''; |
1721 | 1721 | } |
1722 | 1722 | |
1723 | 1723 | $_pages = array(); |
1724 | - foreach ( $pages as $page ) { |
|
1725 | - $_pages[] = str_replace( 'page-numbers', 'page-link text-decoration-none', $page ); |
|
1724 | + foreach ($pages as $page) { |
|
1725 | + $_pages[] = str_replace('page-numbers', 'page-link text-decoration-none', $page); |
|
1726 | 1726 | } |
1727 | 1727 | |
1728 | 1728 | $links = "<nav>\n\t<ul class='pagination justify-content-end m-0'>\n\t\t<li class='page-item'>"; |
1729 | - $links .= join( "</li>\n\t\t<li class='page-item'>", $_pages ); |
|
1729 | + $links .= join("</li>\n\t\t<li class='page-item'>", $_pages); |
|
1730 | 1730 | $links .= "</li>\n\t</ul>\n</nav>\n"; |
1731 | 1731 | |
1732 | 1732 | return $links; |
@@ -9,14 +9,14 @@ discard block |
||
9 | 9 | * @var WPInv_Subscriptions_Widget $widget |
10 | 10 | */ |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | -do_action( 'getpaid_single_subscription_before_notices', $subscription ); |
|
14 | +do_action('getpaid_single_subscription_before_notices', $subscription); |
|
15 | 15 | |
16 | 16 | // Display errors and notices. |
17 | 17 | wpinv_print_errors(); |
18 | 18 | |
19 | -do_action( 'getpaid_before_single_subscription', $subscription ); |
|
19 | +do_action('getpaid_before_single_subscription', $subscription); |
|
20 | 20 | |
21 | 21 | ?> |
22 | 22 | |
@@ -28,44 +28,44 @@ discard block |
||
28 | 28 | |
29 | 29 | </style> |
30 | 30 | |
31 | -<h2 class="mb-1 h4"><?php _e( 'Subscription Details', 'invoicing' ); ?></h2> |
|
31 | +<h2 class="mb-1 h4"><?php _e('Subscription Details', 'invoicing'); ?></h2> |
|
32 | 32 | <table class="table table-bordered"> |
33 | 33 | <tbody> |
34 | 34 | |
35 | - <?php foreach ( $widget->get_single_subscription_columns( $subscription ) as $key => $label ) : ?> |
|
35 | + <?php foreach ($widget->get_single_subscription_columns($subscription) as $key => $label) : ?> |
|
36 | 36 | |
37 | - <tr class="getpaid-subscription-meta-<?php echo sanitize_html_class( $key ); ?>"> |
|
37 | + <tr class="getpaid-subscription-meta-<?php echo sanitize_html_class($key); ?>"> |
|
38 | 38 | |
39 | 39 | <th class="w-25" style="font-weight: 500;"> |
40 | - <?php echo sanitize_text_field( $label ); ?> |
|
40 | + <?php echo sanitize_text_field($label); ?> |
|
41 | 41 | </th> |
42 | 42 | |
43 | 43 | <td class="w-75"> |
44 | 44 | <?php |
45 | 45 | |
46 | - switch ( $key ) { |
|
46 | + switch ($key) { |
|
47 | 47 | |
48 | 48 | case 'status': |
49 | - echo sanitize_text_field( $subscription->get_status_label() ); |
|
49 | + echo sanitize_text_field($subscription->get_status_label()); |
|
50 | 50 | break; |
51 | 51 | |
52 | 52 | case 'start_date': |
53 | - echo sanitize_text_field( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
53 | + echo sanitize_text_field(getpaid_format_date_value($subscription->get_date_created())); |
|
54 | 54 | break; |
55 | 55 | |
56 | 56 | case 'expiry_date': |
57 | - echo sanitize_text_field( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
57 | + echo sanitize_text_field(getpaid_format_date_value($subscription->get_next_renewal_date())); |
|
58 | 58 | break; |
59 | 59 | |
60 | 60 | case 'initial_amount': |
61 | - echo wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
61 | + echo wpinv_price(wpinv_format_amount($subscription->get_initial_amount()), $subscription->get_parent_payment()->get_currency()); |
|
62 | 62 | |
63 | - if ( $subscription->has_trial_period() ) { |
|
63 | + if ($subscription->has_trial_period()) { |
|
64 | 64 | |
65 | 65 | echo "<small class='text-muted'> "; |
66 | 66 | printf( |
67 | - _x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
68 | - sanitize_text_field( $subscription->get_trial_period() ) |
|
67 | + _x('( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing'), |
|
68 | + sanitize_text_field($subscription->get_trial_period()) |
|
69 | 69 | ); |
70 | 70 | echo '</small>'; |
71 | 71 | |
@@ -74,18 +74,18 @@ discard block |
||
74 | 74 | break; |
75 | 75 | |
76 | 76 | case 'recurring_amount': |
77 | - $frequency = sanitize_text_field( WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->get_period(), $subscription->get_frequency(), true ) ); |
|
78 | - $amount = wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
79 | - echo strtolower( "<strong style='font-weight: 500;'>$amount</strong> / $frequency" ); |
|
77 | + $frequency = sanitize_text_field(WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($subscription->get_period(), $subscription->get_frequency(), true)); |
|
78 | + $amount = wpinv_price(wpinv_format_amount($subscription->get_recurring_amount()), $subscription->get_parent_payment()->get_currency()); |
|
79 | + echo strtolower("<strong style='font-weight: 500;'>$amount</strong> / $frequency"); |
|
80 | 80 | break; |
81 | 81 | |
82 | 82 | case 'item': |
83 | - $item = get_post( $subscription->get_product_id() ); |
|
83 | + $item = get_post($subscription->get_product_id()); |
|
84 | 84 | |
85 | - if ( ! empty( $item ) ) { |
|
86 | - echo esc_html( get_the_title( $item ) ); |
|
85 | + if (!empty($item)) { |
|
86 | + echo esc_html(get_the_title($item)); |
|
87 | 87 | } else { |
88 | - echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
88 | + echo sprintf(__('Item #%s', 'invoicing'), $subscription->get_product_id()); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | break; |
@@ -93,12 +93,12 @@ discard block |
||
93 | 93 | case 'payments': |
94 | 94 | |
95 | 95 | $max_activations = (int) $subscription->get_bill_times(); |
96 | - echo (int) $subscription->get_times_billed() . ' / ' . ( empty( $max_activations ) ? "∞" : $max_activations ); |
|
96 | + echo (int) $subscription->get_times_billed() . ' / ' . (empty($max_activations) ? "∞" : $max_activations); |
|
97 | 97 | |
98 | 98 | break; |
99 | 99 | |
100 | 100 | } |
101 | - do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
101 | + do_action("getpaid_render_single_subscription_column_$key", $subscription); |
|
102 | 102 | |
103 | 103 | ?> |
104 | 104 | </td> |
@@ -110,22 +110,22 @@ discard block |
||
110 | 110 | </tbody> |
111 | 111 | </table> |
112 | 112 | |
113 | -<h2 class='mt-5 mb-1 h4'><?php _e( 'Subscription Invoices', 'invoicing' ); ?></h2> |
|
113 | +<h2 class='mt-5 mb-1 h4'><?php _e('Subscription Invoices', 'invoicing'); ?></h2> |
|
114 | 114 | |
115 | -<?php echo getpaid_admin_subscription_invoice_details_metabox( $subscription ); ?> |
|
115 | +<?php echo getpaid_admin_subscription_invoice_details_metabox($subscription); ?> |
|
116 | 116 | |
117 | 117 | <span class="form-text"> |
118 | 118 | |
119 | 119 | <?php |
120 | - if ( $subscription->can_cancel() ) { |
|
120 | + if ($subscription->can_cancel()) { |
|
121 | 121 | printf( |
122 | 122 | '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a> ', |
123 | - esc_url( $subscription->get_cancel_url() ), |
|
124 | - esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ), |
|
125 | - __( 'Cancel Subscription', 'invoicing' ) |
|
123 | + esc_url($subscription->get_cancel_url()), |
|
124 | + esc_attr__('Are you sure you want to cancel this subscription?', 'invoicing'), |
|
125 | + __('Cancel Subscription', 'invoicing') |
|
126 | 126 | ); |
127 | 127 | } |
128 | 128 | ?> |
129 | 129 | |
130 | - <a href="<?php echo esc_url( get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); ?>" class="btn btn-secondary btn-sm"><?php _e( 'Go Back', 'invoicing' ); ?></a> |
|
130 | + <a href="<?php echo esc_url(get_permalink((int) wpinv_get_option('invoice_subscription_page'))); ?>" class="btn btn-secondary btn-sm"><?php _e('Go Back', 'invoicing'); ?></a> |
|
131 | 131 | </span> |
132 | 132 | \ No newline at end of file |
@@ -9,21 +9,21 @@ discard block |
||
9 | 9 | * @var WPInv_Subscriptions_Widget $widget |
10 | 10 | */ |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | -foreach ( array_keys( $widget->get_subscriptions_table_columns() ) as $column ) : |
|
14 | +foreach (array_keys($widget->get_subscriptions_table_columns()) as $column) : |
|
15 | 15 | |
16 | - $class = sanitize_html_class( $column ); |
|
16 | + $class = sanitize_html_class($column); |
|
17 | 17 | echo "<td class='getpaid-subscriptions-table-column-$class'>"; |
18 | 18 | |
19 | - do_action( "getpaid_subscriptions_before_frontend_subscription_table_$column", $subscription ); |
|
19 | + do_action("getpaid_subscriptions_before_frontend_subscription_table_$column", $subscription); |
|
20 | 20 | |
21 | - switch( $column ) : |
|
21 | + switch ($column) : |
|
22 | 22 | |
23 | 23 | case 'subscription': |
24 | 24 | $subscription_id = (int) $subscription->get_id(); |
25 | - $url = esc_url( $subscription->get_view_url() ); |
|
26 | - echo $widget->add_row_actions( "<a href='$url' class='text-decoration-none'>#$subscription_id</a>", $subscription ); |
|
25 | + $url = esc_url($subscription->get_view_url()); |
|
26 | + echo $widget->add_row_actions("<a href='$url' class='text-decoration-none'>#$subscription_id</a>", $subscription); |
|
27 | 27 | break; |
28 | 28 | |
29 | 29 | case 'status': |
@@ -31,19 +31,19 @@ discard block |
||
31 | 31 | break; |
32 | 32 | |
33 | 33 | case 'renewal-date': |
34 | - $renewal = getpaid_format_date_value( $subscription->get_next_renewal_date() ); |
|
34 | + $renewal = getpaid_format_date_value($subscription->get_next_renewal_date()); |
|
35 | 35 | echo $subscription->is_active() ? $renewal : "—"; |
36 | 36 | break; |
37 | 37 | |
38 | 38 | case 'amount': |
39 | - $frequency = sanitize_text_field( WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->get_period(), $subscription->get_frequency(), true ) ); |
|
40 | - $amount = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_recurring_amount() ) ), $subscription->get_parent_payment()->get_currency() ); |
|
39 | + $frequency = sanitize_text_field(WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($subscription->get_period(), $subscription->get_frequency(), true)); |
|
40 | + $amount = wpinv_price(wpinv_format_amount(wpinv_sanitize_amount($subscription->get_recurring_amount())), $subscription->get_parent_payment()->get_currency()); |
|
41 | 41 | echo "<strong style='font-weight: 500;'>$amount</strong> / $frequency"; |
42 | 42 | break; |
43 | 43 | |
44 | 44 | endswitch; |
45 | 45 | |
46 | - do_action( "getpaid_subscriptions_frontend_subscription_table_$column", $subscription ); |
|
46 | + do_action("getpaid_subscriptions_frontend_subscription_table_$column", $subscription); |
|
47 | 47 | |
48 | 48 | echo '</td>'; |
49 | 49 |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Contains functions that display the subscriptions admin page. |
4 | 4 | */ |
5 | 5 | |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * Render the Subscriptions page |
@@ -17,22 +17,22 @@ discard block |
||
17 | 17 | ?> |
18 | 18 | |
19 | 19 | <div class="wrap"> |
20 | - <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
|
20 | + <h1><?php echo esc_html(get_admin_page_title()); ?></h1> |
|
21 | 21 | <div class="bsui"> |
22 | 22 | |
23 | 23 | <?php |
24 | 24 | |
25 | 25 | // Verify user permissions. |
26 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
26 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
27 | 27 | |
28 | 28 | echo aui()->alert( |
29 | 29 | array( |
30 | 30 | 'type' => 'danger', |
31 | - 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
31 | + 'content' => __('You are not permitted to view this page.', 'invoicing'), |
|
32 | 32 | ) |
33 | 33 | ); |
34 | 34 | |
35 | - } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
35 | + } else if (!empty($_GET['id']) && is_numeric($_GET['id'])) { |
|
36 | 36 | |
37 | 37 | // Display a single subscription. |
38 | 38 | wpinv_recurring_subscription_details(); |
@@ -81,13 +81,13 @@ discard block |
||
81 | 81 | function wpinv_recurring_subscription_details() { |
82 | 82 | |
83 | 83 | // Fetch the subscription. |
84 | - $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
85 | - if ( ! $sub->get_id() ) { |
|
84 | + $sub = new WPInv_Subscription((int) $_GET['id']); |
|
85 | + if (!$sub->get_id()) { |
|
86 | 86 | |
87 | 87 | echo aui()->alert( |
88 | 88 | array( |
89 | 89 | 'type' => 'danger', |
90 | - 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
90 | + 'content' => __('Subscription not found.', 'invoicing'), |
|
91 | 91 | ) |
92 | 92 | ); |
93 | 93 | |
@@ -95,31 +95,31 @@ discard block |
||
95 | 95 | } |
96 | 96 | |
97 | 97 | // Use metaboxes to display the subscription details. |
98 | - add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal' ); |
|
99 | - add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
100 | - add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
101 | - do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
98 | + add_meta_box('getpaid_admin_subscription_details_metabox', __('Subscription Details', 'invoicing'), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal'); |
|
99 | + add_meta_box('getpaid_admin_subscription_update_metabox', __('Change Status', 'invoicing'), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side'); |
|
100 | + add_meta_box('getpaid_admin_subscription_invoice_details_metabox', __('Invoices', 'invoicing'), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced'); |
|
101 | + do_action('getpaid_admin_single_subscription_register_metabox', $sub); |
|
102 | 102 | |
103 | 103 | ?> |
104 | 104 | |
105 | - <form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>"> |
|
105 | + <form method="post" action="<?php echo admin_url('admin.php?page=wpinv-subscriptions&id=' . absint($sub->get_id())); ?>"> |
|
106 | 106 | |
107 | - <?php wp_nonce_field( 'getpaid-nonce', 'getpaid-nonce' ); ?> |
|
108 | - <?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?> |
|
109 | - <?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?> |
|
107 | + <?php wp_nonce_field('getpaid-nonce', 'getpaid-nonce'); ?> |
|
108 | + <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); ?> |
|
109 | + <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); ?> |
|
110 | 110 | <input type="hidden" name="getpaid-admin-action" value="update_single_subscription" /> |
111 | - <input type="hidden" name="subscription_id" value="<?php echo (int) $sub->get_id() ;?>" /> |
|
111 | + <input type="hidden" name="subscription_id" value="<?php echo (int) $sub->get_id(); ?>" /> |
|
112 | 112 | |
113 | 113 | <div id="poststuff"> |
114 | 114 | <div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>"> |
115 | 115 | |
116 | 116 | <div id="postbox-container-1" class="postbox-container"> |
117 | - <?php do_meta_boxes( get_current_screen(), 'side', $sub ); ?> |
|
117 | + <?php do_meta_boxes(get_current_screen(), 'side', $sub); ?> |
|
118 | 118 | </div> |
119 | 119 | |
120 | 120 | <div id="postbox-container-2" class="postbox-container"> |
121 | - <?php do_meta_boxes( get_current_screen(), 'normal', $sub ); ?> |
|
122 | - <?php do_meta_boxes( get_current_screen(), 'advanced', $sub ); ?> |
|
121 | + <?php do_meta_boxes(get_current_screen(), 'normal', $sub); ?> |
|
122 | + <?php do_meta_boxes(get_current_screen(), 'advanced', $sub); ?> |
|
123 | 123 | </div> |
124 | 124 | |
125 | 125 | </div> |
@@ -138,27 +138,27 @@ discard block |
||
138 | 138 | * |
139 | 139 | * @param WPInv_Subscription $sub |
140 | 140 | */ |
141 | -function getpaid_admin_subscription_details_metabox( $sub ) { |
|
141 | +function getpaid_admin_subscription_details_metabox($sub) { |
|
142 | 142 | |
143 | 143 | // Prepare subscription detail columns. |
144 | 144 | $fields = apply_filters( |
145 | 145 | 'getpaid_subscription_admin_page_fields', |
146 | 146 | array( |
147 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
148 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
149 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
150 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
151 | - 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
152 | - 'renewals' => __( 'Renewals', 'invoicing' ), |
|
153 | - 'item' => __( 'Item', 'invoicing' ), |
|
154 | - 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
155 | - 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
156 | - 'status' => __( 'Status', 'invoicing' ), |
|
147 | + 'subscription' => __('Subscription', 'invoicing'), |
|
148 | + 'customer' => __('Customer', 'invoicing'), |
|
149 | + 'amount' => __('Amount', 'invoicing'), |
|
150 | + 'start_date' => __('Start Date', 'invoicing'), |
|
151 | + 'renews_on' => __('Next Payment', 'invoicing'), |
|
152 | + 'renewals' => __('Renewals', 'invoicing'), |
|
153 | + 'item' => __('Item', 'invoicing'), |
|
154 | + 'gateway' => __('Payment Method', 'invoicing'), |
|
155 | + 'profile_id' => __('Profile ID', 'invoicing'), |
|
156 | + 'status' => __('Status', 'invoicing'), |
|
157 | 157 | ) |
158 | 158 | ); |
159 | 159 | |
160 | - if ( ! $sub->is_active() && isset( $fields['renews_on'] ) ) { |
|
161 | - unset( $fields['renews_on'] ); |
|
160 | + if (!$sub->is_active() && isset($fields['renews_on'])) { |
|
161 | + unset($fields['renews_on']); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | ?> |
@@ -166,16 +166,16 @@ discard block |
||
166 | 166 | <table class="table table-borderless" style="font-size: 14px;"> |
167 | 167 | <tbody> |
168 | 168 | |
169 | - <?php foreach ( $fields as $key => $label ) : ?> |
|
169 | + <?php foreach ($fields as $key => $label) : ?> |
|
170 | 170 | |
171 | - <tr class="getpaid-subscription-meta-<?php echo sanitize_html_class( $key ); ?>"> |
|
171 | + <tr class="getpaid-subscription-meta-<?php echo sanitize_html_class($key); ?>"> |
|
172 | 172 | |
173 | 173 | <th class="w-25" style="font-weight: 500;"> |
174 | - <?php echo sanitize_text_field( $label ); ?> |
|
174 | + <?php echo sanitize_text_field($label); ?> |
|
175 | 175 | </th> |
176 | 176 | |
177 | 177 | <td class="w-75 text-muted"> |
178 | - <?php do_action( 'getpaid_subscription_admin_display_' . sanitize_text_field( $key ), $sub ); ?> |
|
178 | + <?php do_action('getpaid_subscription_admin_display_' . sanitize_text_field($key), $sub); ?> |
|
179 | 179 | </td> |
180 | 180 | |
181 | 181 | </tr> |
@@ -193,201 +193,201 @@ discard block |
||
193 | 193 | * |
194 | 194 | * @param WPInv_Subscription $subscription |
195 | 195 | */ |
196 | -function getpaid_admin_subscription_metabox_display_customer( $subscription ) { |
|
196 | +function getpaid_admin_subscription_metabox_display_customer($subscription) { |
|
197 | 197 | |
198 | - $username = __( '(Missing User)', 'invoicing' ); |
|
198 | + $username = __('(Missing User)', 'invoicing'); |
|
199 | 199 | |
200 | - $user = get_userdata( $subscription->get_customer_id() ); |
|
201 | - if ( $user ) { |
|
200 | + $user = get_userdata($subscription->get_customer_id()); |
|
201 | + if ($user) { |
|
202 | 202 | |
203 | 203 | $username = sprintf( |
204 | 204 | '<a href="user-edit.php?user_id=%s">%s</a>', |
205 | - absint( $user->ID ), |
|
206 | - ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
205 | + absint($user->ID), |
|
206 | + !empty($user->display_name) ? sanitize_text_field($user->display_name) : sanitize_email($user->user_email) |
|
207 | 207 | ); |
208 | 208 | |
209 | 209 | } |
210 | 210 | |
211 | 211 | echo $username; |
212 | 212 | } |
213 | -add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' ); |
|
213 | +add_action('getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer'); |
|
214 | 214 | |
215 | 215 | /** |
216 | 216 | * Displays the subscription amount. |
217 | 217 | * |
218 | 218 | * @param WPInv_Subscription $subscription |
219 | 219 | */ |
220 | -function getpaid_admin_subscription_metabox_display_amount( $subscription ) { |
|
220 | +function getpaid_admin_subscription_metabox_display_amount($subscription) { |
|
221 | 221 | |
222 | - $initial = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_initial_amount() ) ), $subscription->get_parent_payment()->get_currency() ); |
|
223 | - $recurring = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_recurring_amount() ) ), $subscription->get_parent_payment()->get_currency() ); |
|
224 | - $period = 1 == $subscription->get_frequency() ? getpaid_get_subscription_period_label( $subscription->get_period() ) : WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->get_period(),$subscription->get_frequency() ); |
|
222 | + $initial = wpinv_price(wpinv_format_amount(wpinv_sanitize_amount($subscription->get_initial_amount())), $subscription->get_parent_payment()->get_currency()); |
|
223 | + $recurring = wpinv_price(wpinv_format_amount(wpinv_sanitize_amount($subscription->get_recurring_amount())), $subscription->get_parent_payment()->get_currency()); |
|
224 | + $period = 1 == $subscription->get_frequency() ? getpaid_get_subscription_period_label($subscription->get_period()) : WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($subscription->get_period(), $subscription->get_frequency()); |
|
225 | 225 | |
226 | - if ( $subscription->has_trial_period() ) { |
|
226 | + if ($subscription->has_trial_period()) { |
|
227 | 227 | |
228 | 228 | // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
229 | 229 | $amount = sprintf( |
230 | - _x( '%1$s trial for %2$s(s) then %3$s / %4$s', 'Subscription amount on admin table. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
230 | + _x('%1$s trial for %2$s(s) then %3$s / %4$s', 'Subscription amount on admin table. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing'), |
|
231 | 231 | $initial, |
232 | - sanitize_text_field( $subscription->get_trial_period() ), |
|
232 | + sanitize_text_field($subscription->get_trial_period()), |
|
233 | 233 | $recurring, |
234 | - sanitize_text_field( strtolower( $period ) ) |
|
234 | + sanitize_text_field(strtolower($period)) |
|
235 | 235 | ); |
236 | 236 | |
237 | - } else if ( $initial != $recurring ) { |
|
237 | + } else if ($initial != $recurring) { |
|
238 | 238 | |
239 | 239 | // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring perio |
240 | 240 | $amount = sprintf( |
241 | - _x( 'Initial payment of %1$s then %2$s / %3$s', 'Subscription amount on admin table. (e.g.:Initial payment of $100 then $120 / year)', 'invoicing' ), |
|
241 | + _x('Initial payment of %1$s then %2$s / %3$s', 'Subscription amount on admin table. (e.g.:Initial payment of $100 then $120 / year)', 'invoicing'), |
|
242 | 242 | $initial, |
243 | 243 | $recurring, |
244 | - sanitize_text_field( strtolower( $period ) ) |
|
244 | + sanitize_text_field(strtolower($period)) |
|
245 | 245 | ); |
246 | 246 | |
247 | 247 | } else { |
248 | 248 | |
249 | 249 | // translators: $1: is the recurring amount, $2: is the recurring period |
250 | 250 | $amount = sprintf( |
251 | - _x( '%1$s / %2$s', 'Subscription amount on admin table. (e.g.: $120 / year)', 'invoicing' ), |
|
251 | + _x('%1$s / %2$s', 'Subscription amount on admin table. (e.g.: $120 / year)', 'invoicing'), |
|
252 | 252 | $initial, |
253 | - sanitize_text_field( strtolower( $period ) ) |
|
253 | + sanitize_text_field(strtolower($period)) |
|
254 | 254 | ); |
255 | 255 | |
256 | 256 | } |
257 | 257 | |
258 | 258 | echo "<span>$amount</span>"; |
259 | 259 | } |
260 | -add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' ); |
|
260 | +add_action('getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount'); |
|
261 | 261 | |
262 | 262 | /** |
263 | 263 | * Displays the subscription id. |
264 | 264 | * |
265 | 265 | * @param WPInv_Subscription $subscription |
266 | 266 | */ |
267 | -function getpaid_admin_subscription_metabox_display_id( $subscription ) { |
|
268 | - echo '#' . absint( $subscription->get_id() ); |
|
267 | +function getpaid_admin_subscription_metabox_display_id($subscription) { |
|
268 | + echo '#' . absint($subscription->get_id()); |
|
269 | 269 | } |
270 | -add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' ); |
|
270 | +add_action('getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id'); |
|
271 | 271 | |
272 | 272 | /** |
273 | 273 | * Displays the subscription renewal date. |
274 | 274 | * |
275 | 275 | * @param WPInv_Subscription $subscription |
276 | 276 | */ |
277 | -function getpaid_admin_subscription_metabox_display_start_date( $subscription ) { |
|
277 | +function getpaid_admin_subscription_metabox_display_start_date($subscription) { |
|
278 | 278 | |
279 | 279 | $created = $subscription->get_date_created(); |
280 | - if ( empty( $created ) || '0000-00-00 00:00:00' == $created ) { |
|
280 | + if (empty($created) || '0000-00-00 00:00:00' == $created) { |
|
281 | 281 | echo "—"; |
282 | 282 | } else { |
283 | - echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $created ) ); |
|
283 | + echo date_i18n(/** @scrutinizer ignore-type */get_option('date_format'), strtotime($created)); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | } |
287 | -add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' ); |
|
287 | +add_action('getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date'); |
|
288 | 288 | |
289 | 289 | /** |
290 | 290 | * Displays the subscription renewal date. |
291 | 291 | * |
292 | 292 | * @param WPInv_Subscription $subscription |
293 | 293 | */ |
294 | -function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) { |
|
294 | +function getpaid_admin_subscription_metabox_display_renews_on($subscription) { |
|
295 | 295 | |
296 | 296 | $expiration = $subscription->get_expiration(); |
297 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
297 | + if (empty($expiration) || '0000-00-00 00:00:00' == $expiration) { |
|
298 | 298 | echo "—"; |
299 | 299 | } else { |
300 | - echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $expiration ) ); |
|
300 | + echo date_i18n(/** @scrutinizer ignore-type */get_option('date_format'), strtotime($expiration)); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | } |
304 | -add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' ); |
|
304 | +add_action('getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on'); |
|
305 | 305 | |
306 | 306 | /** |
307 | 307 | * Displays the subscription renewal count. |
308 | 308 | * |
309 | 309 | * @param WPInv_Subscription $subscription |
310 | 310 | */ |
311 | -function getpaid_admin_subscription_metabox_display_renewals( $subscription ) { |
|
311 | +function getpaid_admin_subscription_metabox_display_renewals($subscription) { |
|
312 | 312 | $max_bills = $subscription->get_bill_times(); |
313 | - echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
313 | + echo $subscription->get_times_billed() . ' / ' . (empty($max_bills) ? "∞" : $max_bills); |
|
314 | 314 | } |
315 | -add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' ); |
|
315 | +add_action('getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals'); |
|
316 | 316 | |
317 | 317 | /** |
318 | 318 | * Displays the subscription item. |
319 | 319 | * |
320 | 320 | * @param WPInv_Subscription $subscription |
321 | 321 | */ |
322 | -function getpaid_admin_subscription_metabox_display_item( $subscription ) { |
|
322 | +function getpaid_admin_subscription_metabox_display_item($subscription) { |
|
323 | 323 | |
324 | - $item = get_post( $subscription->get_product_id() ); |
|
324 | + $item = get_post($subscription->get_product_id()); |
|
325 | 325 | |
326 | - if ( ! empty( $item ) ) { |
|
327 | - $link = get_edit_post_link( $item ); |
|
328 | - $link = esc_url( $link ); |
|
329 | - $name = esc_html( get_the_title( $item ) ); |
|
326 | + if (!empty($item)) { |
|
327 | + $link = get_edit_post_link($item); |
|
328 | + $link = esc_url($link); |
|
329 | + $name = esc_html(get_the_title($item)); |
|
330 | 330 | echo "<a href='$link'>$name</a>"; |
331 | 331 | } else { |
332 | - echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
332 | + echo sprintf(__('Item #%s', 'invoicing'), $subscription->get_product_id()); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | } |
336 | -add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item' ); |
|
336 | +add_action('getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item'); |
|
337 | 337 | |
338 | 338 | /** |
339 | 339 | * Displays the subscription gateway. |
340 | 340 | * |
341 | 341 | * @param WPInv_Subscription $subscription |
342 | 342 | */ |
343 | -function getpaid_admin_subscription_metabox_display_gateway( $subscription ) { |
|
343 | +function getpaid_admin_subscription_metabox_display_gateway($subscription) { |
|
344 | 344 | |
345 | 345 | $gateway = $subscription->get_gateway(); |
346 | 346 | |
347 | - if ( ! empty( $gateway ) ) { |
|
348 | - echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) ); |
|
347 | + if (!empty($gateway)) { |
|
348 | + echo sanitize_text_field(wpinv_get_gateway_admin_label($gateway)); |
|
349 | 349 | } else { |
350 | 350 | echo "—"; |
351 | 351 | } |
352 | 352 | |
353 | 353 | } |
354 | -add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' ); |
|
354 | +add_action('getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway'); |
|
355 | 355 | |
356 | 356 | /** |
357 | 357 | * Displays the subscription status. |
358 | 358 | * |
359 | 359 | * @param WPInv_Subscription $subscription |
360 | 360 | */ |
361 | -function getpaid_admin_subscription_metabox_display_status( $subscription ) { |
|
361 | +function getpaid_admin_subscription_metabox_display_status($subscription) { |
|
362 | 362 | echo $subscription->get_status_label_html(); |
363 | 363 | } |
364 | -add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' ); |
|
364 | +add_action('getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status'); |
|
365 | 365 | |
366 | 366 | /** |
367 | 367 | * Displays the subscription profile id. |
368 | 368 | * |
369 | 369 | * @param WPInv_Subscription $subscription |
370 | 370 | */ |
371 | -function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) { |
|
371 | +function getpaid_admin_subscription_metabox_display_profile_id($subscription) { |
|
372 | 372 | |
373 | 373 | $profile_id = $subscription->get_profile_id(); |
374 | 374 | |
375 | - if ( ! empty( $profile_id ) ) { |
|
376 | - $profile_id = sanitize_text_field( $profile_id ); |
|
377 | - echo apply_filters( 'getpaid_subscription_profile_id_display', $profile_id, $subscription ); |
|
375 | + if (!empty($profile_id)) { |
|
376 | + $profile_id = sanitize_text_field($profile_id); |
|
377 | + echo apply_filters('getpaid_subscription_profile_id_display', $profile_id, $subscription); |
|
378 | 378 | } else { |
379 | 379 | echo "—"; |
380 | 380 | } |
381 | 381 | |
382 | 382 | } |
383 | -add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' ); |
|
383 | +add_action('getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id'); |
|
384 | 384 | |
385 | 385 | /** |
386 | 386 | * Displays the subscriptions update metabox. |
387 | 387 | * |
388 | 388 | * @param WPInv_Subscription $subscription |
389 | 389 | */ |
390 | -function getpaid_admin_subscription_update_metabox( $subscription ) { |
|
390 | +function getpaid_admin_subscription_update_metabox($subscription) { |
|
391 | 391 | |
392 | 392 | ?> |
393 | 393 | <div class="mt-3"> |
@@ -400,10 +400,10 @@ discard block |
||
400 | 400 | 'id' => 'subscription_status_update_select', |
401 | 401 | 'required' => true, |
402 | 402 | 'no_wrap' => false, |
403 | - 'label' => __( 'Subscription Status', 'invoicing' ), |
|
404 | - 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
403 | + 'label' => __('Subscription Status', 'invoicing'), |
|
404 | + 'help_text' => __('Updating the status will trigger related actions and hooks', 'invoicing'), |
|
405 | 405 | 'select2' => true, |
406 | - 'value' => $subscription->get_status( 'edit' ), |
|
406 | + 'value' => $subscription->get_status('edit'), |
|
407 | 407 | ) |
408 | 408 | ); |
409 | 409 | ?> |
@@ -411,13 +411,13 @@ discard block |
||
411 | 411 | <div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;"> |
412 | 412 | |
413 | 413 | <?php |
414 | - submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
414 | + submit_button(__('Update', 'invoicing'), 'primary', 'submit', false); |
|
415 | 415 | |
416 | - $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
417 | - $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
418 | - $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
416 | + $url = esc_url(wp_nonce_url(add_query_arg('getpaid-admin-action', 'subscription_manual_renew'), 'getpaid-nonce', 'getpaid-nonce')); |
|
417 | + $anchor = __('Renew Subscription', 'invoicing'); |
|
418 | + $title = esc_attr__('Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing'); |
|
419 | 419 | |
420 | - if ( $subscription->is_active() ) { |
|
420 | + if ($subscription->is_active()) { |
|
421 | 421 | echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
422 | 422 | } |
423 | 423 | |
@@ -429,16 +429,16 @@ discard block |
||
429 | 429 | * |
430 | 430 | * @param WPInv_Subscription $subscription |
431 | 431 | */ |
432 | -function getpaid_admin_subscription_invoice_details_metabox( $subscription ) { |
|
432 | +function getpaid_admin_subscription_invoice_details_metabox($subscription) { |
|
433 | 433 | |
434 | 434 | $columns = apply_filters( |
435 | 435 | 'getpaid_subscription_related_invoices_columns', |
436 | 436 | array( |
437 | - 'invoice' => __( 'Invoice', 'invoicing' ), |
|
438 | - 'relationship' => __( 'Relationship', 'invoicing' ), |
|
439 | - 'date' => __( 'Date', 'invoicing' ), |
|
440 | - 'status' => __( 'Status', 'invoicing' ), |
|
441 | - 'total' => __( 'Total', 'invoicing' ), |
|
437 | + 'invoice' => __('Invoice', 'invoicing'), |
|
438 | + 'relationship' => __('Relationship', 'invoicing'), |
|
439 | + 'date' => __('Date', 'invoicing'), |
|
440 | + 'status' => __('Status', 'invoicing'), |
|
441 | + 'total' => __('Total', 'invoicing'), |
|
442 | 442 | ), |
443 | 443 | $subscription |
444 | 444 | ); |
@@ -447,13 +447,13 @@ discard block |
||
447 | 447 | $payments = $subscription->get_child_payments(); |
448 | 448 | $parent = $subscription->get_parent_invoice(); |
449 | 449 | |
450 | - if ( $parent->get_id() ) { |
|
451 | - $payments = array_merge( array( $parent ), $payments ); |
|
450 | + if ($parent->get_id()) { |
|
451 | + $payments = array_merge(array($parent), $payments); |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | $table_class = 'w-100 bg-white'; |
455 | 455 | |
456 | - if ( ! is_admin() ) { |
|
456 | + if (!is_admin()) { |
|
457 | 457 | $table_class = 'table table-bordered table-striped'; |
458 | 458 | } |
459 | 459 | |
@@ -465,9 +465,9 @@ discard block |
||
465 | 465 | <thead> |
466 | 466 | <tr> |
467 | 467 | <?php |
468 | - foreach ( $columns as $key => $label ) { |
|
469 | - $key = esc_attr( $key ); |
|
470 | - $label = sanitize_text_field( $label ); |
|
468 | + foreach ($columns as $key => $label) { |
|
469 | + $key = esc_attr($key); |
|
470 | + $label = sanitize_text_field($label); |
|
471 | 471 | |
472 | 472 | echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark'>$label</th>"; |
473 | 473 | } |
@@ -477,50 +477,50 @@ discard block |
||
477 | 477 | |
478 | 478 | <tbody> |
479 | 479 | |
480 | - <?php if ( empty( $payments ) ) : ?> |
|
480 | + <?php if (empty($payments)) : ?> |
|
481 | 481 | <tr> |
482 | 482 | <td colspan="<?php echo count($columns); ?>" class="p-2 text-left text-muted"> |
483 | - <?php _e( 'This subscription has no invoices.', 'invoicing' ); ?> |
|
483 | + <?php _e('This subscription has no invoices.', 'invoicing'); ?> |
|
484 | 484 | </td> |
485 | 485 | </tr> |
486 | 486 | <?php endif; ?> |
487 | 487 | |
488 | 488 | <?php |
489 | 489 | |
490 | - foreach( $payments as $payment ) : |
|
490 | + foreach ($payments as $payment) : |
|
491 | 491 | |
492 | 492 | // Ensure that we have an invoice. |
493 | - $payment = new WPInv_Invoice( $payment ); |
|
493 | + $payment = new WPInv_Invoice($payment); |
|
494 | 494 | |
495 | 495 | // Abort if the invoice is invalid. |
496 | - if ( ! $payment->get_id() ) { |
|
496 | + if (!$payment->get_id()) { |
|
497 | 497 | continue; |
498 | 498 | } |
499 | 499 | |
500 | 500 | echo '<tr>'; |
501 | 501 | |
502 | - foreach ( array_keys( $columns ) as $key ) { |
|
502 | + foreach (array_keys($columns) as $key) { |
|
503 | 503 | |
504 | 504 | echo '<td class="p-2 text-left">'; |
505 | 505 | |
506 | - switch( $key ) { |
|
506 | + switch ($key) { |
|
507 | 507 | |
508 | 508 | case 'total': |
509 | - echo '<strong>' . wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $payment->get_total ) ), $payment->get_currency() ) . '</strong>'; |
|
509 | + echo '<strong>' . wpinv_price(wpinv_format_amount(wpinv_sanitize_amount($payment->get_total)), $payment->get_currency()) . '</strong>'; |
|
510 | 510 | break; |
511 | 511 | |
512 | 512 | case 'relationship': |
513 | - echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
513 | + echo $payment->is_renewal() ? __('Renewal Invoice', 'invoicing') : __('Initial Invoice', 'invoicing'); |
|
514 | 514 | break; |
515 | 515 | |
516 | 516 | case 'date': |
517 | - echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $payment->get_date_created() ) ); |
|
517 | + echo date_i18n(/** @scrutinizer ignore-type */get_option('date_format'), strtotime($payment->get_date_created())); |
|
518 | 518 | break; |
519 | 519 | |
520 | 520 | case 'status': |
521 | 521 | |
522 | 522 | $status = $payment->get_status_nicename(); |
523 | - if ( is_admin() ) { |
|
523 | + if (is_admin()) { |
|
524 | 524 | $status = $payment->get_status_label_html(); |
525 | 525 | } |
526 | 526 | |
@@ -528,13 +528,13 @@ discard block |
||
528 | 528 | break; |
529 | 529 | |
530 | 530 | case 'invoice': |
531 | - $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
531 | + $link = esc_url(get_edit_post_link($payment->get_id())); |
|
532 | 532 | |
533 | - if ( ! is_admin() ) { |
|
534 | - $link = esc_url( $payment->get_view_url() ); |
|
533 | + if (!is_admin()) { |
|
534 | + $link = esc_url($payment->get_view_url()); |
|
535 | 535 | } |
536 | 536 | |
537 | - $invoice = sanitize_text_field( $payment->get_number() ); |
|
537 | + $invoice = sanitize_text_field($payment->get_number()); |
|
538 | 538 | echo "<a href='$link'>$invoice</a>"; |
539 | 539 | break; |
540 | 540 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | /** |
9 | 9 | * Main Subscriptions class. |
10 | 10 | * |
@@ -14,25 +14,25 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * Class constructor. |
16 | 16 | */ |
17 | - public function __construct(){ |
|
17 | + public function __construct() { |
|
18 | 18 | |
19 | 19 | // Fire gateway specific hooks when a subscription changes. |
20 | - add_action( 'getpaid_subscription_status_changed', array( $this, 'process_subscription_status_change' ), 10, 3 ); |
|
20 | + add_action('getpaid_subscription_status_changed', array($this, 'process_subscription_status_change'), 10, 3); |
|
21 | 21 | |
22 | 22 | // Handles subscription cancelations. |
23 | - add_action( 'getpaid_authenticated_action_subscription_cancel', array( $this, 'user_cancel_single_subscription' ) ); |
|
23 | + add_action('getpaid_authenticated_action_subscription_cancel', array($this, 'user_cancel_single_subscription')); |
|
24 | 24 | |
25 | 25 | // Create a subscription whenever an invoice is created, (and update it when it is updated). |
26 | - add_action( 'getpaid_new_invoice', array( $this, 'maybe_create_invoice_subscription' ) ); |
|
27 | - add_action( 'getpaid_update_invoice', array( $this, 'maybe_update_invoice_subscription' ) ); |
|
26 | + add_action('getpaid_new_invoice', array($this, 'maybe_create_invoice_subscription')); |
|
27 | + add_action('getpaid_update_invoice', array($this, 'maybe_update_invoice_subscription')); |
|
28 | 28 | |
29 | 29 | // Handles admin subscription update actions. |
30 | - add_action( 'getpaid_authenticated_admin_action_update_single_subscription', array( $this, 'admin_update_single_subscription' ) ); |
|
31 | - add_action( 'getpaid_authenticated_admin_action_subscription_manual_renew', array( $this, 'admin_renew_single_subscription' ) ); |
|
32 | - add_action( 'getpaid_authenticated_admin_action_subscription_manual_delete', array( $this, 'admin_delete_single_subscription' ) ); |
|
30 | + add_action('getpaid_authenticated_admin_action_update_single_subscription', array($this, 'admin_update_single_subscription')); |
|
31 | + add_action('getpaid_authenticated_admin_action_subscription_manual_renew', array($this, 'admin_renew_single_subscription')); |
|
32 | + add_action('getpaid_authenticated_admin_action_subscription_manual_delete', array($this, 'admin_delete_single_subscription')); |
|
33 | 33 | |
34 | 34 | // Filter invoice item row actions. |
35 | - add_action( 'getpaid-invoice-page-line-item-actions', array( $this, 'filter_invoice_line_item_actions' ), 10, 3 ); |
|
35 | + add_action('getpaid-invoice-page-line-item-actions', array($this, 'filter_invoice_line_item_actions'), 10, 3); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -42,15 +42,15 @@ discard block |
||
42 | 42 | * @param string $from |
43 | 43 | * @param string $to |
44 | 44 | */ |
45 | - public function process_subscription_status_change( $subscription, $from, $to ) { |
|
45 | + public function process_subscription_status_change($subscription, $from, $to) { |
|
46 | 46 | |
47 | 47 | $gateway = $subscription->get_gateway(); |
48 | 48 | |
49 | - if ( ! empty( $gateway ) ) { |
|
50 | - $gateway = sanitize_key( $gateway ); |
|
51 | - $from = sanitize_key( $from ); |
|
52 | - $to = sanitize_key( $to ); |
|
53 | - do_action( "getpaid_{$gateway}subscription_$to", $subscription, $from ); |
|
49 | + if (!empty($gateway)) { |
|
50 | + $gateway = sanitize_key($gateway); |
|
51 | + $from = sanitize_key($from); |
|
52 | + $to = sanitize_key($to); |
|
53 | + do_action("getpaid_{$gateway}subscription_$to", $subscription, $from); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | } |
@@ -62,38 +62,38 @@ discard block |
||
62 | 62 | * @param int $frequency_count The frequency of the period. |
63 | 63 | * @return mixed|string|void |
64 | 64 | */ |
65 | - public static function wpinv_get_pretty_subscription_frequency( $period, $frequency_count = 1, $skip_1 = false ) { |
|
65 | + public static function wpinv_get_pretty_subscription_frequency($period, $frequency_count = 1, $skip_1 = false) { |
|
66 | 66 | |
67 | 67 | $frequency = ''; |
68 | 68 | |
69 | 69 | //Format period details |
70 | - switch ( strtolower( $period ) ) { |
|
70 | + switch (strtolower($period)) { |
|
71 | 71 | case 'day' : |
72 | 72 | case 'd' : |
73 | - $frequency = sprintf( _n( '%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count); |
|
73 | + $frequency = sprintf(_n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count); |
|
74 | 74 | break; |
75 | 75 | case 'week' : |
76 | 76 | case 'w' : |
77 | - $frequency = sprintf( _n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count); |
|
77 | + $frequency = sprintf(_n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count); |
|
78 | 78 | break; |
79 | 79 | case 'month' : |
80 | 80 | case 'm' : |
81 | - $frequency = sprintf( _n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count); |
|
81 | + $frequency = sprintf(_n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count); |
|
82 | 82 | break; |
83 | 83 | case 'year' : |
84 | 84 | case 'y' : |
85 | - $frequency = sprintf( _n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count); |
|
85 | + $frequency = sprintf(_n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count); |
|
86 | 86 | break; |
87 | 87 | default : |
88 | - $frequency = apply_filters( 'wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count ); |
|
88 | + $frequency = apply_filters('wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count); |
|
89 | 89 | break; |
90 | 90 | } |
91 | 91 | |
92 | - if ( $skip_1 && 1 == $frequency_count ) { |
|
93 | - $frequency = str_replace( '1', '', $frequency ); |
|
92 | + if ($skip_1 && 1 == $frequency_count) { |
|
93 | + $frequency = str_replace('1', '', $frequency); |
|
94 | 94 | } |
95 | 95 | |
96 | - return trim( $frequency ); |
|
96 | + return trim($frequency); |
|
97 | 97 | |
98 | 98 | } |
99 | 99 | |
@@ -104,29 +104,29 @@ discard block |
||
104 | 104 | * @since 1.0.0 |
105 | 105 | * @return void |
106 | 106 | */ |
107 | - public function user_cancel_single_subscription( $data ) { |
|
107 | + public function user_cancel_single_subscription($data) { |
|
108 | 108 | |
109 | 109 | // Ensure there is a subscription to cancel. |
110 | - if ( empty( $data['subscription'] ) ) { |
|
110 | + if (empty($data['subscription'])) { |
|
111 | 111 | return; |
112 | 112 | } |
113 | 113 | |
114 | - $subscription = new WPInv_Subscription( (int) $data['subscription'] ); |
|
114 | + $subscription = new WPInv_Subscription((int) $data['subscription']); |
|
115 | 115 | |
116 | 116 | // Ensure that it exists and that it belongs to the current user. |
117 | - if ( ! $subscription->get_id() || $subscription->get_customer_id() != get_current_user_id() ) { |
|
118 | - wpinv_set_error( 'invalid_subscription', __( 'You do not have permission to cancel this subscription', 'invoicing' ) ); |
|
117 | + if (!$subscription->get_id() || $subscription->get_customer_id() != get_current_user_id()) { |
|
118 | + wpinv_set_error('invalid_subscription', __('You do not have permission to cancel this subscription', 'invoicing')); |
|
119 | 119 | |
120 | 120 | // Can it be cancelled. |
121 | - } else if ( ! $subscription->can_cancel() ) { |
|
122 | - wpinv_set_error( 'cannot_cancel', __( 'This subscription cannot be cancelled as it is not active.', 'invoicing' ) ); |
|
121 | + } else if (!$subscription->can_cancel()) { |
|
122 | + wpinv_set_error('cannot_cancel', __('This subscription cannot be cancelled as it is not active.', 'invoicing')); |
|
123 | 123 | |
124 | 124 | |
125 | 125 | // Cancel it. |
126 | 126 | } else { |
127 | 127 | |
128 | 128 | $subscription->cancel(); |
129 | - wpinv_set_error( 'cancelled', __( 'This subscription has been cancelled.', 'invoicing' ), 'info' ); |
|
129 | + wpinv_set_error('cancelled', __('This subscription has been cancelled.', 'invoicing'), 'info'); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | $redirect = add_query_arg( |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | ) |
137 | 137 | ); |
138 | 138 | |
139 | - wp_safe_redirect( esc_url( $redirect ) ); |
|
139 | + wp_safe_redirect(esc_url($redirect)); |
|
140 | 140 | exit; |
141 | 141 | |
142 | 142 | } |
@@ -148,15 +148,15 @@ discard block |
||
148 | 148 | * @param WPInv_Invoice $invoice |
149 | 149 | * @since 1.0.0 |
150 | 150 | */ |
151 | - public function maybe_create_invoice_subscription( $invoice ) { |
|
151 | + public function maybe_create_invoice_subscription($invoice) { |
|
152 | 152 | |
153 | 153 | // Abort if it is not recurring. |
154 | - if ( $invoice->is_free() || ! $invoice->is_recurring() || $invoice->is_renewal() ) { |
|
154 | + if ($invoice->is_free() || !$invoice->is_recurring() || $invoice->is_renewal()) { |
|
155 | 155 | return; |
156 | 156 | } |
157 | 157 | |
158 | 158 | $subscription = new WPInv_Subscription(); |
159 | - return $this->update_invoice_subscription( $subscription, $invoice ); |
|
159 | + return $this->update_invoice_subscription($subscription, $invoice); |
|
160 | 160 | |
161 | 161 | } |
162 | 162 | |
@@ -167,33 +167,33 @@ discard block |
||
167 | 167 | * @param WPInv_Invoice $invoice |
168 | 168 | * @since 1.0.19 |
169 | 169 | */ |
170 | - public function maybe_update_invoice_subscription( $invoice ) { |
|
170 | + public function maybe_update_invoice_subscription($invoice) { |
|
171 | 171 | |
172 | 172 | // Do not process renewals. |
173 | - if ( $invoice->is_renewal() ) { |
|
173 | + if ($invoice->is_renewal()) { |
|
174 | 174 | return; |
175 | 175 | } |
176 | 176 | |
177 | 177 | // (Maybe) create a new subscription. |
178 | - if ( ! $invoice->get_subscription_id() ) { |
|
179 | - return $this->maybe_create_invoice_subscription( $invoice ); |
|
178 | + if (!$invoice->get_subscription_id()) { |
|
179 | + return $this->maybe_create_invoice_subscription($invoice); |
|
180 | 180 | } |
181 | 181 | |
182 | - $subscription = new WPInv_Subscription( $invoice->get_subscription_id() ); |
|
182 | + $subscription = new WPInv_Subscription($invoice->get_subscription_id()); |
|
183 | 183 | |
184 | 184 | // In case the subscription was deleted... |
185 | - if ( ! $subscription->get_id() ) { |
|
185 | + if (!$subscription->get_id()) { |
|
186 | 186 | $invoice->set_subscription_id(0); |
187 | 187 | $invoice->save(); |
188 | - return $this->maybe_create_invoice_subscription( $invoice ); |
|
188 | + return $this->maybe_create_invoice_subscription($invoice); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | // Abort if an invoice is paid and already has a subscription. |
192 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
192 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
193 | 193 | return; |
194 | 194 | } |
195 | 195 | |
196 | - return $this->update_invoice_subscription( $subscription, $invoice ); |
|
196 | + return $this->update_invoice_subscription($subscription, $invoice); |
|
197 | 197 | |
198 | 198 | } |
199 | 199 | |
@@ -205,53 +205,53 @@ discard block |
||
205 | 205 | * @param WPInv_Invoice $invoice |
206 | 206 | * @since 1.0.19 |
207 | 207 | */ |
208 | - public function update_invoice_subscription( $subscription, $invoice ) { |
|
208 | + public function update_invoice_subscription($subscription, $invoice) { |
|
209 | 209 | |
210 | 210 | // Delete the subscription if an invoice is free. |
211 | - if ( $invoice->is_free() || ! $invoice->is_recurring() ) { |
|
211 | + if ($invoice->is_free() || !$invoice->is_recurring()) { |
|
212 | 212 | return $subscription->delete(); |
213 | 213 | } |
214 | 214 | |
215 | - $subscription->set_customer_id( $invoice->get_customer_id() ); |
|
216 | - $subscription->set_parent_invoice_id( $invoice->get_id() ); |
|
217 | - $subscription->set_initial_amount( $invoice->get_initial_total() ); |
|
218 | - $subscription->set_recurring_amount( $invoice->get_recurring_total() ); |
|
219 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
220 | - $subscription->set_status( $invoice->is_paid() ? 'active' : 'pending' ); |
|
215 | + $subscription->set_customer_id($invoice->get_customer_id()); |
|
216 | + $subscription->set_parent_invoice_id($invoice->get_id()); |
|
217 | + $subscription->set_initial_amount($invoice->get_initial_total()); |
|
218 | + $subscription->set_recurring_amount($invoice->get_recurring_total()); |
|
219 | + $subscription->set_date_created(current_time('mysql')); |
|
220 | + $subscription->set_status($invoice->is_paid() ? 'active' : 'pending'); |
|
221 | 221 | |
222 | 222 | // Get the recurring item and abort if it does not exist. |
223 | - $subscription_item = $invoice->get_recurring( true ); |
|
224 | - if ( ! $subscription_item->get_id() ) { |
|
223 | + $subscription_item = $invoice->get_recurring(true); |
|
224 | + if (!$subscription_item->get_id()) { |
|
225 | 225 | return $subscription->delete(); |
226 | 226 | } |
227 | 227 | |
228 | - $subscription->set_product_id( $subscription_item->get_id() ); |
|
229 | - $subscription->set_period( $subscription_item->get_recurring_period( true ) ); |
|
230 | - $subscription->set_frequency( $subscription_item->get_recurring_interval() ); |
|
231 | - $subscription->set_bill_times( $subscription_item->get_recurring_limit() ); |
|
228 | + $subscription->set_product_id($subscription_item->get_id()); |
|
229 | + $subscription->set_period($subscription_item->get_recurring_period(true)); |
|
230 | + $subscription->set_frequency($subscription_item->get_recurring_interval()); |
|
231 | + $subscription->set_bill_times($subscription_item->get_recurring_limit()); |
|
232 | 232 | |
233 | 233 | // Calculate the next renewal date. |
234 | - $period = $subscription_item->get_recurring_period( true ); |
|
234 | + $period = $subscription_item->get_recurring_period(true); |
|
235 | 235 | $interval = $subscription_item->get_recurring_interval(); |
236 | 236 | |
237 | 237 | // If the subscription item has a trial period... |
238 | - if ( $subscription_item->has_free_trial() ) { |
|
239 | - $period = $subscription_item->get_trial_period( true ); |
|
238 | + if ($subscription_item->has_free_trial()) { |
|
239 | + $period = $subscription_item->get_trial_period(true); |
|
240 | 240 | $interval = $subscription_item->get_trial_interval(); |
241 | - $subscription->set_trial_period( $interval . ' ' . $period ); |
|
242 | - $subscription->set_status( 'trialling' ); |
|
241 | + $subscription->set_trial_period($interval . ' ' . $period); |
|
242 | + $subscription->set_status('trialling'); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | // If initial amount is free, treat it as a free trial even if the subscription item does not have a free trial. |
246 | - if ( $invoice->has_free_trial() ) { |
|
247 | - $subscription->set_trial_period( $interval . ' ' . $period ); |
|
248 | - $subscription->set_status( 'trialling' ); |
|
246 | + if ($invoice->has_free_trial()) { |
|
247 | + $subscription->set_trial_period($interval . ' ' . $period); |
|
248 | + $subscription->set_status('trialling'); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | // Calculate the next renewal date. |
252 | - $expiration = date( 'Y-m-d H:i:s', strtotime( "+ $interval $period", strtotime( $subscription->get_date_created() ) ) ); |
|
252 | + $expiration = date('Y-m-d H:i:s', strtotime("+ $interval $period", strtotime($subscription->get_date_created()))); |
|
253 | 253 | |
254 | - $subscription->set_next_renewal_date( $expiration ); |
|
254 | + $subscription->set_next_renewal_date($expiration); |
|
255 | 255 | return $subscription->save(); |
256 | 256 | |
257 | 257 | } |
@@ -262,21 +262,21 @@ discard block |
||
262 | 262 | * @param array $data |
263 | 263 | * @since 1.0.19 |
264 | 264 | */ |
265 | - public function admin_update_single_subscription( $args ) { |
|
265 | + public function admin_update_single_subscription($args) { |
|
266 | 266 | |
267 | 267 | // Ensure the subscription exists and that a status has been given. |
268 | - if ( empty( $args['subscription_id'] ) || empty( $args['subscription_status'] ) ) { |
|
268 | + if (empty($args['subscription_id']) || empty($args['subscription_status'])) { |
|
269 | 269 | return; |
270 | 270 | } |
271 | 271 | |
272 | 272 | // Retrieve the subscriptions. |
273 | - $subscription = new WPInv_Subscription( $args['subscription_id'] ); |
|
273 | + $subscription = new WPInv_Subscription($args['subscription_id']); |
|
274 | 274 | |
275 | - if ( $subscription->get_id() ) { |
|
275 | + if ($subscription->get_id()) { |
|
276 | 276 | |
277 | - $subscription->set_status( $args['subscription_status'] ); |
|
277 | + $subscription->set_status($args['subscription_status']); |
|
278 | 278 | $subscription->save(); |
279 | - getpaid_admin()->show_info( __( 'Your changes have been saved', 'invoicing' ) ); |
|
279 | + getpaid_admin()->show_info(__('Your changes have been saved', 'invoicing')); |
|
280 | 280 | |
281 | 281 | } |
282 | 282 | |
@@ -288,25 +288,25 @@ discard block |
||
288 | 288 | * @param array $data |
289 | 289 | * @since 1.0.19 |
290 | 290 | */ |
291 | - public function admin_renew_single_subscription( $args ) { |
|
291 | + public function admin_renew_single_subscription($args) { |
|
292 | 292 | |
293 | 293 | // Ensure the subscription exists and that a status has been given. |
294 | - if ( empty( $args['id'] ) ) { |
|
294 | + if (empty($args['id'])) { |
|
295 | 295 | return; |
296 | 296 | } |
297 | 297 | |
298 | 298 | // Retrieve the subscriptions. |
299 | - $subscription = new WPInv_Subscription( $args['id'] ); |
|
299 | + $subscription = new WPInv_Subscription($args['id']); |
|
300 | 300 | |
301 | - if ( $subscription->get_id() ) { |
|
301 | + if ($subscription->get_id()) { |
|
302 | 302 | |
303 | - $args = array( 'transaction_id', $subscription->get_parent_invoice()->generate_key( 'renewal_' ) ); |
|
303 | + $args = array('transaction_id', $subscription->get_parent_invoice()->generate_key('renewal_')); |
|
304 | 304 | |
305 | - if ( $subscription->add_payment( $args ) ) { |
|
305 | + if ($subscription->add_payment($args)) { |
|
306 | 306 | $subscription->renew(); |
307 | - getpaid_admin()->show_info( __( 'This subscription has been renewed and extended.', 'invoicing' ) ); |
|
307 | + getpaid_admin()->show_info(__('This subscription has been renewed and extended.', 'invoicing')); |
|
308 | 308 | } else { |
309 | - getpaid_admin()->show_error( __( 'We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing' ) ); |
|
309 | + getpaid_admin()->show_error(__('We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing')); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | wp_safe_redirect( |
@@ -329,20 +329,20 @@ discard block |
||
329 | 329 | * @param array $data |
330 | 330 | * @since 1.0.19 |
331 | 331 | */ |
332 | - public function admin_delete_single_subscription( $args ) { |
|
332 | + public function admin_delete_single_subscription($args) { |
|
333 | 333 | |
334 | 334 | // Ensure the subscription exists and that a status has been given. |
335 | - if ( empty( $args['id'] ) ) { |
|
335 | + if (empty($args['id'])) { |
|
336 | 336 | return; |
337 | 337 | } |
338 | 338 | |
339 | 339 | // Retrieve the subscriptions. |
340 | - $subscription = new WPInv_Subscription( $args['id'] ); |
|
340 | + $subscription = new WPInv_Subscription($args['id']); |
|
341 | 341 | |
342 | - if ( $subscription->delete() ) { |
|
343 | - getpaid_admin()->show_info( __( 'This subscription has been deleted.', 'invoicing' ) ); |
|
342 | + if ($subscription->delete()) { |
|
343 | + getpaid_admin()->show_info(__('This subscription has been deleted.', 'invoicing')); |
|
344 | 344 | } else { |
345 | - getpaid_admin()->show_error( __( 'We are unable to delete this subscription. Please try again.', 'invoicing' ) ); |
|
345 | + getpaid_admin()->show_error(__('We are unable to delete this subscription. Please try again.', 'invoicing')); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | $redirected = wp_safe_redirect( |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | ) |
356 | 356 | ); |
357 | 357 | |
358 | - if ( $redirected ) { |
|
358 | + if ($redirected) { |
|
359 | 359 | exit; |
360 | 360 | } |
361 | 361 | |
@@ -368,10 +368,10 @@ discard block |
||
368 | 368 | * @param WPInv_Item $item |
369 | 369 | * @param WPInv_Invoice $invoice |
370 | 370 | */ |
371 | - public function filter_invoice_line_item_actions( $actions, $item, $invoice ) { |
|
371 | + public function filter_invoice_line_item_actions($actions, $item, $invoice) { |
|
372 | 372 | |
373 | 373 | // Fetch item subscription. |
374 | - $args = array( |
|
374 | + $args = array( |
|
375 | 375 | 'invoice_in' => $invoice->is_parent() ? $invoice->get_id() : $invoice->get_parent_id(), |
376 | 376 | 'item_in' => $item->get_id(), |
377 | 377 | 'number' => 1, |
@@ -379,13 +379,13 @@ discard block |
||
379 | 379 | 'fields' => 'id', |
380 | 380 | ); |
381 | 381 | |
382 | - $subscription = new GetPaid_Subscriptions_Query( $args ); |
|
382 | + $subscription = new GetPaid_Subscriptions_Query($args); |
|
383 | 383 | $subscription = $subscription->get_results(); |
384 | 384 | |
385 | 385 | // In case we found a match... |
386 | - if ( ! empty( $subscription ) ) { |
|
387 | - $url = esc_url( add_query_arg( 'subscription', (int) $subscription[0], get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); |
|
388 | - $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __( 'Manage Subscription', 'getpaid-license-manager' ) . '</a>'; |
|
386 | + if (!empty($subscription)) { |
|
387 | + $url = esc_url(add_query_arg('subscription', (int) $subscription[0], get_permalink((int) wpinv_get_option('invoice_subscription_page')))); |
|
388 | + $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __('Manage Subscription', 'getpaid-license-manager') . '</a>'; |
|
389 | 389 | } |
390 | 390 | |
391 | 391 | return $actions; |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * The Subscription Class |
@@ -68,27 +68,27 @@ discard block |
||
68 | 68 | * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
69 | 69 | * @param bool $deprecated |
70 | 70 | */ |
71 | - function __construct( $subscription = 0, $deprecated = false ) { |
|
71 | + function __construct($subscription = 0, $deprecated = false) { |
|
72 | 72 | |
73 | - parent::__construct( $subscription ); |
|
73 | + parent::__construct($subscription); |
|
74 | 74 | |
75 | - if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
76 | - $this->set_id( $subscription ); |
|
77 | - } elseif ( $subscription instanceof self ) { |
|
78 | - $this->set_id( $subscription->get_id() ); |
|
79 | - } elseif ( ! empty( $subscription->id ) ) { |
|
80 | - $this->set_id( $subscription->id ); |
|
81 | - } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
82 | - $this->set_id( $subscription_id ); |
|
75 | + if (!$deprecated && !empty($subscription) && is_numeric($subscription)) { |
|
76 | + $this->set_id($subscription); |
|
77 | + } elseif ($subscription instanceof self) { |
|
78 | + $this->set_id($subscription->get_id()); |
|
79 | + } elseif (!empty($subscription->id)) { |
|
80 | + $this->set_id($subscription->id); |
|
81 | + } elseif ($deprecated && $subscription_id = self::get_subscription_id_by_field($subscription, 'profile_id')) { |
|
82 | + $this->set_id($subscription_id); |
|
83 | 83 | } else { |
84 | - $this->set_object_read( true ); |
|
84 | + $this->set_object_read(true); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | // Load the datastore. |
88 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
88 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
89 | 89 | |
90 | - if ( $this->get_id() > 0 ) { |
|
91 | - $this->data_store->read( $this ); |
|
90 | + if ($this->get_id() > 0) { |
|
91 | + $this->data_store->read($this); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | } |
@@ -103,17 +103,17 @@ discard block |
||
103 | 103 | * @since 1.0.19 |
104 | 104 | * @return int |
105 | 105 | */ |
106 | - public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
106 | + public static function get_subscription_id_by_field($value, $field = 'profile_id') { |
|
107 | 107 | global $wpdb; |
108 | 108 | |
109 | 109 | // Trim the value. |
110 | - $value = trim( $value ); |
|
110 | + $value = trim($value); |
|
111 | 111 | |
112 | - if ( empty( $value ) ) { |
|
112 | + if (empty($value)) { |
|
113 | 113 | return 0; |
114 | 114 | } |
115 | 115 | |
116 | - if ( 'invoice_id' == $field ) { |
|
116 | + if ('invoice_id' == $field) { |
|
117 | 117 | $field = 'parent_payment_id'; |
118 | 118 | } |
119 | 119 | |
@@ -125,28 +125,28 @@ discard block |
||
125 | 125 | ); |
126 | 126 | |
127 | 127 | // Ensure a field has been passed. |
128 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
128 | + if (empty($field) || !in_array($field, $fields)) { |
|
129 | 129 | return 0; |
130 | 130 | } |
131 | 131 | |
132 | 132 | // Maybe retrieve from the cache. |
133 | - $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
134 | - if ( ! empty( $subscription_id ) ) { |
|
133 | + $subscription_id = wp_cache_get($value, "getpaid_subscription_{$field}s_to_subscription_ids"); |
|
134 | + if (!empty($subscription_id)) { |
|
135 | 135 | return $subscription_id; |
136 | 136 | } |
137 | 137 | |
138 | 138 | // Fetch from the db. |
139 | 139 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
140 | 140 | $subscription_id = (int) $wpdb->get_var( |
141 | - $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
|
141 | + $wpdb->prepare("SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value) |
|
142 | 142 | ); |
143 | 143 | |
144 | - if ( empty( $subscription_id ) ) { |
|
144 | + if (empty($subscription_id)) { |
|
145 | 145 | return 0; |
146 | 146 | } |
147 | 147 | |
148 | 148 | // Update the cache with our data. |
149 | - wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
149 | + wp_cache_set($value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids"); |
|
150 | 150 | |
151 | 151 | return $subscription_id; |
152 | 152 | } |
@@ -155,17 +155,17 @@ discard block |
||
155 | 155 | * Clears the subscription's cache. |
156 | 156 | */ |
157 | 157 | public function clear_cache() { |
158 | - wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
159 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
160 | - wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
161 | - wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
158 | + wp_cache_delete($this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids'); |
|
159 | + wp_cache_delete($this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids'); |
|
160 | + wp_cache_delete($this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids'); |
|
161 | + wp_cache_delete($this->get_id(), 'getpaid_subscriptions'); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
165 | 165 | * Checks if a subscription key is set. |
166 | 166 | */ |
167 | - public function _isset( $key ) { |
|
168 | - return isset( $this->data[$key] ) || method_exists( $this, "get_$key" ); |
|
167 | + public function _isset($key) { |
|
168 | + return isset($this->data[$key]) || method_exists($this, "get_$key"); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /* |
@@ -190,8 +190,8 @@ discard block |
||
190 | 190 | * @param string $context View or edit context. |
191 | 191 | * @return int |
192 | 192 | */ |
193 | - public function get_customer_id( $context = 'view' ) { |
|
194 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
193 | + public function get_customer_id($context = 'view') { |
|
194 | + return (int) $this->get_prop('customer_id', $context); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
@@ -201,8 +201,8 @@ discard block |
||
201 | 201 | * @param string $context View or edit context. |
202 | 202 | * @return WP_User|false WP_User object on success, false on failure. |
203 | 203 | */ |
204 | - public function get_customer( $context = 'view' ) { |
|
205 | - return get_userdata( $this->get_customer_id( $context ) ); |
|
204 | + public function get_customer($context = 'view') { |
|
205 | + return get_userdata($this->get_customer_id($context)); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -212,8 +212,8 @@ discard block |
||
212 | 212 | * @param string $context View or edit context. |
213 | 213 | * @return int |
214 | 214 | */ |
215 | - public function get_parent_invoice_id( $context = 'view' ) { |
|
216 | - return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
215 | + public function get_parent_invoice_id($context = 'view') { |
|
216 | + return (int) $this->get_prop('parent_payment_id', $context); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -223,8 +223,8 @@ discard block |
||
223 | 223 | * @param string $context View or edit context. |
224 | 224 | * @return int |
225 | 225 | */ |
226 | - public function get_parent_payment_id( $context = 'view' ) { |
|
227 | - return $this->get_parent_invoice_id( $context ); |
|
226 | + public function get_parent_payment_id($context = 'view') { |
|
227 | + return $this->get_parent_invoice_id($context); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
@@ -233,8 +233,8 @@ discard block |
||
233 | 233 | * @since 1.0.0 |
234 | 234 | * @return int |
235 | 235 | */ |
236 | - public function get_original_payment_id( $context = 'view' ) { |
|
237 | - return $this->get_parent_invoice_id( $context ); |
|
236 | + public function get_original_payment_id($context = 'view') { |
|
237 | + return $this->get_parent_invoice_id($context); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -244,8 +244,8 @@ discard block |
||
244 | 244 | * @param string $context View or edit context. |
245 | 245 | * @return WPInv_Invoice |
246 | 246 | */ |
247 | - public function get_parent_invoice( $context = 'view' ) { |
|
248 | - return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
247 | + public function get_parent_invoice($context = 'view') { |
|
248 | + return new WPInv_Invoice($this->get_parent_invoice_id($context)); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | /** |
@@ -255,8 +255,8 @@ discard block |
||
255 | 255 | * @param string $context View or edit context. |
256 | 256 | * @return WPInv_Invoice |
257 | 257 | */ |
258 | - public function get_parent_payment( $context = 'view' ) { |
|
259 | - return $this->get_parent_invoice( $context ); |
|
258 | + public function get_parent_payment($context = 'view') { |
|
259 | + return $this->get_parent_invoice($context); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -266,8 +266,8 @@ discard block |
||
266 | 266 | * @param string $context View or edit context. |
267 | 267 | * @return int |
268 | 268 | */ |
269 | - public function get_product_id( $context = 'view' ) { |
|
270 | - return (int) $this->get_prop( 'product_id', $context ); |
|
269 | + public function get_product_id($context = 'view') { |
|
270 | + return (int) $this->get_prop('product_id', $context); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
@@ -277,8 +277,8 @@ discard block |
||
277 | 277 | * @param string $context View or edit context. |
278 | 278 | * @return WPInv_Item |
279 | 279 | */ |
280 | - public function get_product( $context = 'view' ) { |
|
281 | - return new WPInv_Item( $this->get_product_id( $context ) ); |
|
280 | + public function get_product($context = 'view') { |
|
281 | + return new WPInv_Item($this->get_product_id($context)); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
@@ -290,8 +290,8 @@ discard block |
||
290 | 290 | * @param string $context View or edit context. |
291 | 291 | * @return string |
292 | 292 | */ |
293 | - public function get_gateway( $context = 'view' ) { |
|
294 | - return $this->get_parent_invoice( $context )->get_gateway(); |
|
293 | + public function get_gateway($context = 'view') { |
|
294 | + return $this->get_parent_invoice($context)->get_gateway(); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
@@ -301,8 +301,8 @@ discard block |
||
301 | 301 | * @param string $context View or edit context. |
302 | 302 | * @return string |
303 | 303 | */ |
304 | - public function get_period( $context = 'view' ) { |
|
305 | - return $this->get_prop( 'period', $context ); |
|
304 | + public function get_period($context = 'view') { |
|
305 | + return $this->get_prop('period', $context); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
@@ -312,8 +312,8 @@ discard block |
||
312 | 312 | * @param string $context View or edit context. |
313 | 313 | * @return int |
314 | 314 | */ |
315 | - public function get_frequency( $context = 'view' ) { |
|
316 | - return (int) $this->get_prop( 'frequency', $context ); |
|
315 | + public function get_frequency($context = 'view') { |
|
316 | + return (int) $this->get_prop('frequency', $context); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -323,8 +323,8 @@ discard block |
||
323 | 323 | * @param string $context View or edit context. |
324 | 324 | * @return float |
325 | 325 | */ |
326 | - public function get_initial_amount( $context = 'view' ) { |
|
327 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
326 | + public function get_initial_amount($context = 'view') { |
|
327 | + return (float) wpinv_sanitize_amount($this->get_prop('initial_amount', $context)); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
@@ -334,8 +334,8 @@ discard block |
||
334 | 334 | * @param string $context View or edit context. |
335 | 335 | * @return float |
336 | 336 | */ |
337 | - public function get_recurring_amount( $context = 'view' ) { |
|
338 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
337 | + public function get_recurring_amount($context = 'view') { |
|
338 | + return (float) wpinv_sanitize_amount($this->get_prop('recurring_amount', $context)); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
@@ -345,8 +345,8 @@ discard block |
||
345 | 345 | * @param string $context View or edit context. |
346 | 346 | * @return int |
347 | 347 | */ |
348 | - public function get_bill_times( $context = 'view' ) { |
|
349 | - return (int) $this->get_prop( 'bill_times', $context ); |
|
348 | + public function get_bill_times($context = 'view') { |
|
349 | + return (int) $this->get_prop('bill_times', $context); |
|
350 | 350 | } |
351 | 351 | |
352 | 352 | /** |
@@ -356,8 +356,8 @@ discard block |
||
356 | 356 | * @param string $context View or edit context. |
357 | 357 | * @return string |
358 | 358 | */ |
359 | - public function get_transaction_id( $context = 'view' ) { |
|
360 | - return $this->get_prop( 'transaction_id', $context ); |
|
359 | + public function get_transaction_id($context = 'view') { |
|
360 | + return $this->get_prop('transaction_id', $context); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | /** |
@@ -367,8 +367,8 @@ discard block |
||
367 | 367 | * @param string $context View or edit context. |
368 | 368 | * @return string |
369 | 369 | */ |
370 | - public function get_created( $context = 'view' ) { |
|
371 | - return $this->get_prop( 'created', $context ); |
|
370 | + public function get_created($context = 'view') { |
|
371 | + return $this->get_prop('created', $context); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | /** |
@@ -378,8 +378,8 @@ discard block |
||
378 | 378 | * @param string $context View or edit context. |
379 | 379 | * @return string |
380 | 380 | */ |
381 | - public function get_date_created( $context = 'view' ) { |
|
382 | - return $this->get_created( $context ); |
|
381 | + public function get_date_created($context = 'view') { |
|
382 | + return $this->get_created($context); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | /** |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | */ |
391 | 391 | public function get_time_created() { |
392 | 392 | $created = $this->get_date_created(); |
393 | - return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
393 | + return empty($created) ? current_time('timestamp') : strtotime($created, current_time('timestamp')); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | /** |
@@ -400,11 +400,11 @@ discard block |
||
400 | 400 | * @param string $context View or edit context. |
401 | 401 | * @return string |
402 | 402 | */ |
403 | - public function get_date_created_gmt( $context = 'view' ) { |
|
404 | - $date = $this->get_date_created( $context ); |
|
403 | + public function get_date_created_gmt($context = 'view') { |
|
404 | + $date = $this->get_date_created($context); |
|
405 | 405 | |
406 | - if ( $date ) { |
|
407 | - $date = get_gmt_from_date( $date ); |
|
406 | + if ($date) { |
|
407 | + $date = get_gmt_from_date($date); |
|
408 | 408 | } |
409 | 409 | return $date; |
410 | 410 | } |
@@ -416,8 +416,8 @@ discard block |
||
416 | 416 | * @param string $context View or edit context. |
417 | 417 | * @return string |
418 | 418 | */ |
419 | - public function get_next_renewal_date( $context = 'view' ) { |
|
420 | - return $this->get_prop( 'expiration', $context ); |
|
419 | + public function get_next_renewal_date($context = 'view') { |
|
420 | + return $this->get_prop('expiration', $context); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | /** |
@@ -427,8 +427,8 @@ discard block |
||
427 | 427 | * @param string $context View or edit context. |
428 | 428 | * @return string |
429 | 429 | */ |
430 | - public function get_expiration( $context = 'view' ) { |
|
431 | - return $this->get_next_renewal_date( $context ); |
|
430 | + public function get_expiration($context = 'view') { |
|
431 | + return $this->get_next_renewal_date($context); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | /** |
@@ -440,12 +440,12 @@ discard block |
||
440 | 440 | public function get_expiration_time() { |
441 | 441 | $expiration = $this->get_expiration(); |
442 | 442 | |
443 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
444 | - return current_time( 'timestamp' ); |
|
443 | + if (empty($expiration) || '0000-00-00 00:00:00' == $expiration) { |
|
444 | + return current_time('timestamp'); |
|
445 | 445 | } |
446 | 446 | |
447 | - $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
448 | - return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
447 | + $expiration = strtotime($expiration, current_time('timestamp')); |
|
448 | + return $expiration < current_time('timestamp') ? current_time('timestamp') : $expiration; |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | /** |
@@ -455,11 +455,11 @@ discard block |
||
455 | 455 | * @param string $context View or edit context. |
456 | 456 | * @return string |
457 | 457 | */ |
458 | - public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
459 | - $date = $this->get_next_renewal_date( $context ); |
|
458 | + public function get_next_renewal_date_gmt($context = 'view') { |
|
459 | + $date = $this->get_next_renewal_date($context); |
|
460 | 460 | |
461 | - if ( $date ) { |
|
462 | - $date = get_gmt_from_date( $date ); |
|
461 | + if ($date) { |
|
462 | + $date = get_gmt_from_date($date); |
|
463 | 463 | } |
464 | 464 | return $date; |
465 | 465 | } |
@@ -471,8 +471,8 @@ discard block |
||
471 | 471 | * @param string $context View or edit context. |
472 | 472 | * @return string |
473 | 473 | */ |
474 | - public function get_trial_period( $context = 'view' ) { |
|
475 | - return $this->get_prop( 'trial_period', $context ); |
|
474 | + public function get_trial_period($context = 'view') { |
|
475 | + return $this->get_prop('trial_period', $context); |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | /** |
@@ -482,8 +482,8 @@ discard block |
||
482 | 482 | * @param string $context View or edit context. |
483 | 483 | * @return string |
484 | 484 | */ |
485 | - public function get_status( $context = 'view' ) { |
|
486 | - return $this->get_prop( 'status', $context ); |
|
485 | + public function get_status($context = 'view') { |
|
486 | + return $this->get_prop('status', $context); |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | /** |
@@ -493,8 +493,8 @@ discard block |
||
493 | 493 | * @param string $context View or edit context. |
494 | 494 | * @return string |
495 | 495 | */ |
496 | - public function get_profile_id( $context = 'view' ) { |
|
497 | - return $this->get_prop( 'profile_id', $context ); |
|
496 | + public function get_profile_id($context = 'view') { |
|
497 | + return $this->get_prop('profile_id', $context); |
|
498 | 498 | } |
499 | 499 | |
500 | 500 | /* |
@@ -509,8 +509,8 @@ discard block |
||
509 | 509 | * @since 1.0.19 |
510 | 510 | * @param int $value The customer's id. |
511 | 511 | */ |
512 | - public function set_customer_id( $value ) { |
|
513 | - $this->set_prop( 'customer_id', (int) $value ); |
|
512 | + public function set_customer_id($value) { |
|
513 | + $this->set_prop('customer_id', (int) $value); |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | /** |
@@ -519,8 +519,8 @@ discard block |
||
519 | 519 | * @since 1.0.19 |
520 | 520 | * @param int $value The parent invoice id. |
521 | 521 | */ |
522 | - public function set_parent_invoice_id( $value ) { |
|
523 | - $this->set_prop( 'parent_payment_id', (int) $value ); |
|
522 | + public function set_parent_invoice_id($value) { |
|
523 | + $this->set_prop('parent_payment_id', (int) $value); |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | /** |
@@ -529,8 +529,8 @@ discard block |
||
529 | 529 | * @since 1.0.19 |
530 | 530 | * @param int $value The parent invoice id. |
531 | 531 | */ |
532 | - public function set_parent_payment_id( $value ) { |
|
533 | - $this->set_parent_invoice_id( $value ); |
|
532 | + public function set_parent_payment_id($value) { |
|
533 | + $this->set_parent_invoice_id($value); |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | /** |
@@ -539,8 +539,8 @@ discard block |
||
539 | 539 | * @since 1.0.19 |
540 | 540 | * @param int $value The parent invoice id. |
541 | 541 | */ |
542 | - public function set_original_payment_id( $value ) { |
|
543 | - $this->set_parent_invoice_id( $value ); |
|
542 | + public function set_original_payment_id($value) { |
|
543 | + $this->set_parent_invoice_id($value); |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | /** |
@@ -549,8 +549,8 @@ discard block |
||
549 | 549 | * @since 1.0.19 |
550 | 550 | * @param int $value The subscription product id. |
551 | 551 | */ |
552 | - public function set_product_id( $value ) { |
|
553 | - $this->set_prop( 'product_id', (int) $value ); |
|
552 | + public function set_product_id($value) { |
|
553 | + $this->set_prop('product_id', (int) $value); |
|
554 | 554 | } |
555 | 555 | |
556 | 556 | /** |
@@ -559,8 +559,8 @@ discard block |
||
559 | 559 | * @since 1.0.19 |
560 | 560 | * @param string $value The renewal period. |
561 | 561 | */ |
562 | - public function set_period( $value ) { |
|
563 | - $this->set_prop( 'period', $value ); |
|
562 | + public function set_period($value) { |
|
563 | + $this->set_prop('period', $value); |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | /** |
@@ -569,9 +569,9 @@ discard block |
||
569 | 569 | * @since 1.0.19 |
570 | 570 | * @param int $value The subscription frequency. |
571 | 571 | */ |
572 | - public function set_frequency( $value ) { |
|
573 | - $value = empty( $value ) ? 1 : (int) $value; |
|
574 | - $this->set_prop( 'frequency', absint( $value ) ); |
|
572 | + public function set_frequency($value) { |
|
573 | + $value = empty($value) ? 1 : (int) $value; |
|
574 | + $this->set_prop('frequency', absint($value)); |
|
575 | 575 | } |
576 | 576 | |
577 | 577 | /** |
@@ -580,8 +580,8 @@ discard block |
||
580 | 580 | * @since 1.0.19 |
581 | 581 | * @param float $value The initial subcription amount. |
582 | 582 | */ |
583 | - public function set_initial_amount( $value ) { |
|
584 | - $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
583 | + public function set_initial_amount($value) { |
|
584 | + $this->set_prop('initial_amount', wpinv_sanitize_amount($value)); |
|
585 | 585 | } |
586 | 586 | |
587 | 587 | /** |
@@ -590,8 +590,8 @@ discard block |
||
590 | 590 | * @since 1.0.19 |
591 | 591 | * @param float $value The recurring subcription amount. |
592 | 592 | */ |
593 | - public function set_recurring_amount( $value ) { |
|
594 | - $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
593 | + public function set_recurring_amount($value) { |
|
594 | + $this->set_prop('recurring_amount', wpinv_sanitize_amount($value)); |
|
595 | 595 | } |
596 | 596 | |
597 | 597 | /** |
@@ -600,8 +600,8 @@ discard block |
||
600 | 600 | * @since 1.0.19 |
601 | 601 | * @param int $value Bill times. |
602 | 602 | */ |
603 | - public function set_bill_times( $value ) { |
|
604 | - $this->set_prop( 'bill_times', (int) $value ); |
|
603 | + public function set_bill_times($value) { |
|
604 | + $this->set_prop('bill_times', (int) $value); |
|
605 | 605 | } |
606 | 606 | |
607 | 607 | /** |
@@ -610,8 +610,8 @@ discard block |
||
610 | 610 | * @since 1.0.19 |
611 | 611 | * @param string $value Bill times. |
612 | 612 | */ |
613 | - public function set_transaction_id( $value ) { |
|
614 | - $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
613 | + public function set_transaction_id($value) { |
|
614 | + $this->set_prop('transaction_id', sanitize_text_field($value)); |
|
615 | 615 | } |
616 | 616 | |
617 | 617 | /** |
@@ -620,15 +620,15 @@ discard block |
||
620 | 620 | * @since 1.0.19 |
621 | 621 | * @param string $value strtotime compliant date. |
622 | 622 | */ |
623 | - public function set_created( $value ) { |
|
624 | - $date = strtotime( $value ); |
|
623 | + public function set_created($value) { |
|
624 | + $date = strtotime($value); |
|
625 | 625 | |
626 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
627 | - $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
626 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
627 | + $this->set_prop('created', date('Y-m-d H:i:s', $date)); |
|
628 | 628 | return; |
629 | 629 | } |
630 | 630 | |
631 | - $this->set_prop( 'created', '' ); |
|
631 | + $this->set_prop('created', ''); |
|
632 | 632 | |
633 | 633 | } |
634 | 634 | |
@@ -638,8 +638,8 @@ discard block |
||
638 | 638 | * @since 1.0.19 |
639 | 639 | * @param string $value strtotime compliant date. |
640 | 640 | */ |
641 | - public function set_date_created( $value ) { |
|
642 | - $this->set_created( $value ); |
|
641 | + public function set_date_created($value) { |
|
642 | + $this->set_created($value); |
|
643 | 643 | } |
644 | 644 | |
645 | 645 | /** |
@@ -648,15 +648,15 @@ discard block |
||
648 | 648 | * @since 1.0.19 |
649 | 649 | * @param string $value strtotime compliant date. |
650 | 650 | */ |
651 | - public function set_next_renewal_date( $value ) { |
|
652 | - $date = strtotime( $value ); |
|
651 | + public function set_next_renewal_date($value) { |
|
652 | + $date = strtotime($value); |
|
653 | 653 | |
654 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
655 | - $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
654 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
655 | + $this->set_prop('expiration', date('Y-m-d H:i:s', $date)); |
|
656 | 656 | return; |
657 | 657 | } |
658 | 658 | |
659 | - $this->set_prop( 'expiration', '' ); |
|
659 | + $this->set_prop('expiration', ''); |
|
660 | 660 | |
661 | 661 | } |
662 | 662 | |
@@ -666,8 +666,8 @@ discard block |
||
666 | 666 | * @since 1.0.19 |
667 | 667 | * @param string $value strtotime compliant date. |
668 | 668 | */ |
669 | - public function set_expiration( $value ) { |
|
670 | - $this->set_next_renewal_date( $value ); |
|
669 | + public function set_expiration($value) { |
|
670 | + $this->set_next_renewal_date($value); |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | /** |
@@ -676,8 +676,8 @@ discard block |
||
676 | 676 | * @since 1.0.19 |
677 | 677 | * @param string $value trial period e.g 1 year. |
678 | 678 | */ |
679 | - public function set_trial_period( $value ) { |
|
680 | - $this->set_prop( 'trial_period', $value ); |
|
679 | + public function set_trial_period($value) { |
|
680 | + $this->set_prop('trial_period', $value); |
|
681 | 681 | } |
682 | 682 | |
683 | 683 | /** |
@@ -686,19 +686,19 @@ discard block |
||
686 | 686 | * @since 1.0.19 |
687 | 687 | * @param string $new_status New subscription status. |
688 | 688 | */ |
689 | - public function set_status( $new_status ) { |
|
689 | + public function set_status($new_status) { |
|
690 | 690 | |
691 | 691 | // Abort if this is not a valid status; |
692 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
692 | + if (!array_key_exists($new_status, getpaid_get_subscription_statuses())) { |
|
693 | 693 | return; |
694 | 694 | } |
695 | 695 | |
696 | 696 | $old_status = $this->get_status(); |
697 | - $this->set_prop( 'status', $new_status ); |
|
697 | + $this->set_prop('status', $new_status); |
|
698 | 698 | |
699 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
699 | + if (true === $this->object_read && $old_status !== $new_status) { |
|
700 | 700 | $this->status_transition = array( |
701 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
701 | + 'from' => !empty($this->status_transition['from']) ? $this->status_transition['from'] : $old_status, |
|
702 | 702 | 'to' => $new_status, |
703 | 703 | ); |
704 | 704 | } |
@@ -711,8 +711,8 @@ discard block |
||
711 | 711 | * @since 1.0.19 |
712 | 712 | * @param string $value the remote profile id. |
713 | 713 | */ |
714 | - public function set_profile_id( $value ) { |
|
715 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
714 | + public function set_profile_id($value) { |
|
715 | + $this->set_prop('profile_id', sanitize_text_field($value)); |
|
716 | 716 | } |
717 | 717 | |
718 | 718 | /* |
@@ -730,8 +730,8 @@ discard block |
||
730 | 730 | * @param string|array String or array of strings to check for. |
731 | 731 | * @return bool |
732 | 732 | */ |
733 | - public function has_status( $status ) { |
|
734 | - return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) ); |
|
733 | + public function has_status($status) { |
|
734 | + return in_array($this->get_status(), wpinv_clean(wpinv_parse_list($status))); |
|
735 | 735 | } |
736 | 736 | |
737 | 737 | /** |
@@ -741,7 +741,7 @@ discard block |
||
741 | 741 | */ |
742 | 742 | public function has_trial_period() { |
743 | 743 | $period = $this->get_trial_period(); |
744 | - return ! empty( $period ); |
|
744 | + return !empty($period); |
|
745 | 745 | } |
746 | 746 | |
747 | 747 | /** |
@@ -750,7 +750,7 @@ discard block |
||
750 | 750 | * @return bool |
751 | 751 | */ |
752 | 752 | public function is_active() { |
753 | - return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
753 | + return $this->has_status('active trialling') && !$this->is_expired(); |
|
754 | 754 | } |
755 | 755 | |
756 | 756 | /** |
@@ -759,7 +759,7 @@ discard block |
||
759 | 759 | * @return bool |
760 | 760 | */ |
761 | 761 | public function is_expired() { |
762 | - return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) ); |
|
762 | + return $this->has_status('expired') || ($this->has_status('active cancelled trialling') && $this->get_expiration_time() < current_time('mysql')); |
|
763 | 763 | } |
764 | 764 | |
765 | 765 | /** |
@@ -769,7 +769,7 @@ discard block |
||
769 | 769 | */ |
770 | 770 | public function is_last_renewal() { |
771 | 771 | $max_bills = $this->get_bill_times(); |
772 | - return ! empty( $max_bills ) && $max_bills == $this->get_times_billed(); |
|
772 | + return !empty($max_bills) && $max_bills == $this->get_times_billed(); |
|
773 | 773 | } |
774 | 774 | |
775 | 775 | /* |
@@ -784,11 +784,11 @@ discard block |
||
784 | 784 | /** |
785 | 785 | * Backwards compatibilty. |
786 | 786 | */ |
787 | - public function create( $data = array() ) { |
|
787 | + public function create($data = array()) { |
|
788 | 788 | |
789 | 789 | // Set the properties. |
790 | - if ( is_array( $data ) ) { |
|
791 | - $this->set_props( $data ); |
|
790 | + if (is_array($data)) { |
|
791 | + $this->set_props($data); |
|
792 | 792 | } |
793 | 793 | |
794 | 794 | // Save the item. |
@@ -799,8 +799,8 @@ discard block |
||
799 | 799 | /** |
800 | 800 | * Backwards compatibilty. |
801 | 801 | */ |
802 | - public function update( $args = array() ) { |
|
803 | - return $this->create( $args ); |
|
802 | + public function update($args = array()) { |
|
803 | + return $this->create($args); |
|
804 | 804 | } |
805 | 805 | |
806 | 806 | /** |
@@ -814,7 +814,7 @@ discard block |
||
814 | 814 | array( |
815 | 815 | 'post_parent' => $this->get_parent_payment_id(), |
816 | 816 | 'numberposts' => -1, |
817 | - 'post_status' => array( 'publish', 'wpi-processing', 'wpi-renewal' ), |
|
817 | + 'post_status' => array('publish', 'wpi-processing', 'wpi-renewal'), |
|
818 | 818 | 'orderby' => 'ID', |
819 | 819 | 'order' => 'DESC', |
820 | 820 | 'post_type' => 'wpi_invoice' |
@@ -839,7 +839,7 @@ discard block |
||
839 | 839 | ); |
840 | 840 | |
841 | 841 | // Maybe include parent invoice. |
842 | - if ( ! $this->has_status( 'pending' ) ) { |
|
842 | + if (!$this->has_status('pending')) { |
|
843 | 843 | $count++; |
844 | 844 | } |
845 | 845 | |
@@ -855,7 +855,7 @@ discard block |
||
855 | 855 | public function get_times_billed() { |
856 | 856 | $times_billed = $this->get_total_payments(); |
857 | 857 | |
858 | - if ( $this->has_trial_period() && $times_billed > 0 ) { |
|
858 | + if ($this->has_trial_period() && $times_billed > 0) { |
|
859 | 859 | $times_billed--; |
860 | 860 | } |
861 | 861 | |
@@ -870,49 +870,49 @@ discard block |
||
870 | 870 | * @param WPInv_Invoice $invoice If adding an existing invoice. |
871 | 871 | * @return bool |
872 | 872 | */ |
873 | - public function add_payment( $args = array(), $invoice = false ) { |
|
873 | + public function add_payment($args = array(), $invoice = false) { |
|
874 | 874 | |
875 | 875 | // Process each payment once. |
876 | - if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
|
876 | + if (!empty($args['transaction_id']) && $this->payment_exists($args['transaction_id'])) { |
|
877 | 877 | return false; |
878 | 878 | } |
879 | 879 | |
880 | 880 | // Are we creating a new invoice? |
881 | - if ( empty( $invoice ) ) { |
|
881 | + if (empty($invoice)) { |
|
882 | 882 | $invoice = $this->create_payment(); |
883 | 883 | |
884 | - if ( empty( $invoice ) ) { |
|
884 | + if (empty($invoice)) { |
|
885 | 885 | return false; |
886 | 886 | } |
887 | 887 | |
888 | - $invoice->set_status( 'wpi-renewal' ); |
|
888 | + $invoice->set_status('wpi-renewal'); |
|
889 | 889 | |
890 | 890 | } |
891 | 891 | |
892 | 892 | // Maybe set a transaction id. |
893 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
894 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
893 | + if (!empty($args['transaction_id'])) { |
|
894 | + $invoice->set_transaction_id($args['transaction_id']); |
|
895 | 895 | } |
896 | 896 | |
897 | 897 | // Set the completed date. |
898 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
898 | + $invoice->set_completed_date(current_time('mysql')); |
|
899 | 899 | |
900 | 900 | // And the gateway. |
901 | - if ( ! empty( $args['gateway'] ) ) { |
|
902 | - $invoice->set_gateway( $args['gateway'] ); |
|
901 | + if (!empty($args['gateway'])) { |
|
902 | + $invoice->set_gateway($args['gateway']); |
|
903 | 903 | } |
904 | 904 | |
905 | 905 | $invoice->save(); |
906 | 906 | |
907 | - if ( ! $invoice->get_id() ) { |
|
907 | + if (!$invoice->get_id()) { |
|
908 | 908 | return 0; |
909 | 909 | } |
910 | 910 | |
911 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
912 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
913 | - do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
|
911 | + do_action('getpaid_after_create_subscription_renewal_invoice', $invoice, $this); |
|
912 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $this); |
|
913 | + do_action('wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id()); |
|
914 | 914 | |
915 | - update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
|
915 | + update_post_meta($invoice->get_id(), '_wpinv_subscription_id', $this->id); |
|
916 | 916 | |
917 | 917 | return $invoice->get_id(); |
918 | 918 | } |
@@ -927,21 +927,21 @@ discard block |
||
927 | 927 | |
928 | 928 | $parent_invoice = $this->get_parent_payment(); |
929 | 929 | |
930 | - if ( ! $parent_invoice->get_id() ) { |
|
930 | + if (!$parent_invoice->get_id()) { |
|
931 | 931 | return false; |
932 | 932 | } |
933 | 933 | |
934 | 934 | // Duplicate the parent invoice. |
935 | 935 | $invoice = new WPInv_Invoice(); |
936 | - $invoice->set_props( $parent_invoice->get_data() ); |
|
937 | - $invoice->set_id( 0 ); |
|
938 | - $invoice->set_items( $parent_invoice->get_items() ); |
|
939 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
940 | - $invoice->set_transaction_id( '' ); |
|
941 | - $invoice->set_key( $invoice->generate_key( 'renewal_' ) ); |
|
942 | - $invoice->set_number( '' ); |
|
943 | - $invoice->set_completed_date( '' ); |
|
944 | - $invoice->set_status( 'wpi-pending' ); |
|
936 | + $invoice->set_props($parent_invoice->get_data()); |
|
937 | + $invoice->set_id(0); |
|
938 | + $invoice->set_items($parent_invoice->get_items()); |
|
939 | + $invoice->set_parent_id($parent_invoice->get_id()); |
|
940 | + $invoice->set_transaction_id(''); |
|
941 | + $invoice->set_key($invoice->generate_key('renewal_')); |
|
942 | + $invoice->set_number(''); |
|
943 | + $invoice->set_completed_date(''); |
|
944 | + $invoice->set_status('wpi-pending'); |
|
945 | 945 | $invoice->recalculate_total(); |
946 | 946 | $invoice->save(); |
947 | 947 | |
@@ -957,20 +957,20 @@ discard block |
||
957 | 957 | public function renew() { |
958 | 958 | |
959 | 959 | // Complete subscription if applicable |
960 | - if ( $this->get_bill_times() > 0 && $this->get_times_billed() >= $this->get_bill_times() ) { |
|
960 | + if ($this->get_bill_times() > 0 && $this->get_times_billed() >= $this->get_bill_times()) { |
|
961 | 961 | return $this->complete(); |
962 | 962 | } |
963 | 963 | |
964 | 964 | // Calculate new expiration |
965 | 965 | $frequency = $this->get_frequency(); |
966 | 966 | $period = $this->get_period(); |
967 | - $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
967 | + $new_expiration = strtotime("+ $frequency $period", $this->get_expiration_time()); |
|
968 | 968 | |
969 | - $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
970 | - $this->set_status( 'active' ); |
|
969 | + $this->set_expiration(date('Y-m-d H:i:s', $new_expiration)); |
|
970 | + $this->set_status('active'); |
|
971 | 971 | return $this->save(); |
972 | 972 | |
973 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
973 | + do_action('getpaid_subscription_renewed', $this); |
|
974 | 974 | |
975 | 975 | } |
976 | 976 | |
@@ -985,11 +985,11 @@ discard block |
||
985 | 985 | public function complete() { |
986 | 986 | |
987 | 987 | // Only mark a subscription as complete if it's not already cancelled. |
988 | - if ( $this->has_status( 'cancelled' ) ) { |
|
988 | + if ($this->has_status('cancelled')) { |
|
989 | 989 | return false; |
990 | 990 | } |
991 | 991 | |
992 | - $this->set_status( 'completed' ); |
|
992 | + $this->set_status('completed'); |
|
993 | 993 | return $this->save(); |
994 | 994 | |
995 | 995 | } |
@@ -1001,14 +1001,14 @@ discard block |
||
1001 | 1001 | * @param bool $check_expiration |
1002 | 1002 | * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
1003 | 1003 | */ |
1004 | - public function expire( $check_expiration = false ) { |
|
1004 | + public function expire($check_expiration = false) { |
|
1005 | 1005 | |
1006 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
1006 | + if ($check_expiration && $this->get_expiration_time() > current_time('timestamp')) { |
|
1007 | 1007 | // Do not mark as expired since real expiration date is in the future |
1008 | 1008 | return false; |
1009 | 1009 | } |
1010 | 1010 | |
1011 | - $this->set_status( 'expired' ); |
|
1011 | + $this->set_status('expired'); |
|
1012 | 1012 | return $this->save(); |
1013 | 1013 | |
1014 | 1014 | } |
@@ -1020,7 +1020,7 @@ discard block |
||
1020 | 1020 | * @return int Subscription id. |
1021 | 1021 | */ |
1022 | 1022 | public function failing() { |
1023 | - $this->set_status( 'failing' ); |
|
1023 | + $this->set_status('failing'); |
|
1024 | 1024 | return $this->save(); |
1025 | 1025 | } |
1026 | 1026 | |
@@ -1031,7 +1031,7 @@ discard block |
||
1031 | 1031 | * @return int Subscription id. |
1032 | 1032 | */ |
1033 | 1033 | public function cancel() { |
1034 | - $this->set_status( 'cancelled' ); |
|
1034 | + $this->set_status('cancelled'); |
|
1035 | 1035 | return $this->save(); |
1036 | 1036 | } |
1037 | 1037 | |
@@ -1042,7 +1042,7 @@ discard block |
||
1042 | 1042 | * @return bool |
1043 | 1043 | */ |
1044 | 1044 | public function can_cancel() { |
1045 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
1045 | + return apply_filters('wpinv_subscription_can_cancel', $this->has_status($this->get_cancellable_statuses()), $this); |
|
1046 | 1046 | } |
1047 | 1047 | |
1048 | 1048 | /** |
@@ -1053,7 +1053,7 @@ discard block |
||
1053 | 1053 | * @return array |
1054 | 1054 | */ |
1055 | 1055 | public function get_cancellable_statuses() { |
1056 | - return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
|
1056 | + return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing')); |
|
1057 | 1057 | } |
1058 | 1058 | |
1059 | 1059 | /** |
@@ -1063,8 +1063,8 @@ discard block |
||
1063 | 1063 | * @return string |
1064 | 1064 | */ |
1065 | 1065 | public function get_cancel_url() { |
1066 | - $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
1067 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
1066 | + $url = getpaid_get_authenticated_action_url('subscription_cancel', $this->get_view_url()); |
|
1067 | + return apply_filters('wpinv_subscription_cancel_url', $url, $this); |
|
1068 | 1068 | } |
1069 | 1069 | |
1070 | 1070 | /** |
@@ -1074,8 +1074,8 @@ discard block |
||
1074 | 1074 | * @return string |
1075 | 1075 | */ |
1076 | 1076 | public function get_view_url() { |
1077 | - $url = add_query_arg( 'subscription', $this->get_id(), get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
1078 | - return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
1077 | + $url = add_query_arg('subscription', $this->get_id(), get_permalink((int) wpinv_get_option('invoice_subscription_page'))); |
|
1078 | + return apply_filters('getpaid_get_subscription_view_url', $url, $this); |
|
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | /** |
@@ -1088,7 +1088,7 @@ discard block |
||
1088 | 1088 | * @return bool |
1089 | 1089 | */ |
1090 | 1090 | public function can_renew() { |
1091 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
1091 | + return apply_filters('wpinv_subscription_can_renew', true, $this); |
|
1092 | 1092 | } |
1093 | 1093 | |
1094 | 1094 | /** |
@@ -1098,8 +1098,8 @@ discard block |
||
1098 | 1098 | * @return string |
1099 | 1099 | */ |
1100 | 1100 | public function get_renew_url() { |
1101 | - $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' ); |
|
1102 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
1101 | + $url = wp_nonce_url(add_query_arg(array('getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id)), 'getpaid-nonce'); |
|
1102 | + return apply_filters('wpinv_subscription_renew_url', $url, $this); |
|
1103 | 1103 | } |
1104 | 1104 | |
1105 | 1105 | /** |
@@ -1109,7 +1109,7 @@ discard block |
||
1109 | 1109 | * @return bool |
1110 | 1110 | */ |
1111 | 1111 | public function can_update() { |
1112 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
1112 | + return apply_filters('wpinv_subscription_can_update', false, $this); |
|
1113 | 1113 | } |
1114 | 1114 | |
1115 | 1115 | /** |
@@ -1119,8 +1119,8 @@ discard block |
||
1119 | 1119 | * @return string |
1120 | 1120 | */ |
1121 | 1121 | public function get_update_url() { |
1122 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
1123 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
1122 | + $url = add_query_arg(array('action' => 'update', 'subscription_id' => $this->get_id())); |
|
1123 | + return apply_filters('wpinv_subscription_update_url', $url, $this); |
|
1124 | 1124 | } |
1125 | 1125 | |
1126 | 1126 | /** |
@@ -1130,7 +1130,7 @@ discard block |
||
1130 | 1130 | * @return string |
1131 | 1131 | */ |
1132 | 1132 | public function get_status_label() { |
1133 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
1133 | + return getpaid_get_subscription_status_label($this->get_status()); |
|
1134 | 1134 | } |
1135 | 1135 | |
1136 | 1136 | /** |
@@ -1141,7 +1141,7 @@ discard block |
||
1141 | 1141 | */ |
1142 | 1142 | public function get_status_class() { |
1143 | 1143 | $statuses = getpaid_get_subscription_status_classes(); |
1144 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary'; |
|
1144 | + return isset($statuses[$this->get_status()]) ? $statuses[$this->get_status()] : 'text-white bg-secondary'; |
|
1145 | 1145 | } |
1146 | 1146 | |
1147 | 1147 | /** |
@@ -1152,9 +1152,9 @@ discard block |
||
1152 | 1152 | */ |
1153 | 1153 | public function get_status_label_html() { |
1154 | 1154 | |
1155 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
1156 | - $class = esc_attr( $this->get_status_class() ); |
|
1157 | - $status = sanitize_html_class( $this->get_status_label() ); |
|
1155 | + $status_label = sanitize_text_field($this->get_status_label()); |
|
1156 | + $class = esc_attr($this->get_status_class()); |
|
1157 | + $status = sanitize_html_class($this->get_status_label()); |
|
1158 | 1158 | |
1159 | 1159 | return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>"; |
1160 | 1160 | } |
@@ -1166,9 +1166,9 @@ discard block |
||
1166 | 1166 | * @param string $txn_id The transaction ID from the merchant processor |
1167 | 1167 | * @return bool |
1168 | 1168 | */ |
1169 | - public function payment_exists( $txn_id = '' ) { |
|
1170 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
1171 | - return ! empty( $invoice_id ); |
|
1169 | + public function payment_exists($txn_id = '') { |
|
1170 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field($txn_id, 'transaction_id'); |
|
1171 | + return !empty($invoice_id); |
|
1172 | 1172 | } |
1173 | 1173 | |
1174 | 1174 | /** |
@@ -1180,35 +1180,35 @@ discard block |
||
1180 | 1180 | // Reset status transition variable. |
1181 | 1181 | $this->status_transition = false; |
1182 | 1182 | |
1183 | - if ( $status_transition ) { |
|
1183 | + if ($status_transition) { |
|
1184 | 1184 | try { |
1185 | 1185 | |
1186 | 1186 | // Fire a hook for the status change. |
1187 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
1188 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
1187 | + do_action('wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition); |
|
1188 | + do_action('getpaid_subscription_' . $status_transition['to'], $this, $status_transition); |
|
1189 | 1189 | |
1190 | - if ( ! empty( $status_transition['from'] ) ) { |
|
1190 | + if (!empty($status_transition['from'])) { |
|
1191 | 1191 | |
1192 | 1192 | /* translators: 1: old subscription status 2: new subscription status */ |
1193 | - $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1193 | + $transition_note = sprintf(__('Subscription status changed from %1$s to %2$s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['from']), getpaid_get_subscription_status_label($status_transition['to'])); |
|
1194 | 1194 | |
1195 | 1195 | // Note the transition occurred. |
1196 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1196 | + $this->get_parent_payment()->add_note($transition_note, false, false, true); |
|
1197 | 1197 | |
1198 | 1198 | // Fire another hook. |
1199 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
1200 | - do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
1199 | + do_action('getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this); |
|
1200 | + do_action('getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to']); |
|
1201 | 1201 | |
1202 | 1202 | } else { |
1203 | 1203 | /* translators: %s: new invoice status */ |
1204 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1204 | + $transition_note = sprintf(__('Subscription status set to %s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['to'])); |
|
1205 | 1205 | |
1206 | 1206 | // Note the transition occurred. |
1207 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1207 | + $this->get_parent_payment()->add_note($transition_note, false, false, true); |
|
1208 | 1208 | |
1209 | 1209 | } |
1210 | - } catch ( Exception $e ) { |
|
1211 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
1210 | + } catch (Exception $e) { |
|
1211 | + $this->get_parent_payment()->add_note(__('Error during subscription status transition.', 'invoicing') . ' ' . $e->getMessage()); |
|
1212 | 1212 | } |
1213 | 1213 | } |
1214 | 1214 |
@@ -7,86 +7,86 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_item_quantities_enabled() { |
15 | - $ret = wpinv_get_option( 'item_quantities', true ); |
|
15 | + $ret = wpinv_get_option('item_quantities', true); |
|
16 | 16 | |
17 | - return (bool) apply_filters( 'wpinv_item_quantities_enabled', $ret ); |
|
17 | + return (bool) apply_filters('wpinv_item_quantities_enabled', $ret); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | function wpinv_get_ip() { |
21 | 21 | $ip = '127.0.0.1'; |
22 | 22 | |
23 | - if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { |
|
24 | - $ip = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] ); |
|
25 | - } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { |
|
26 | - $ip = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] ); |
|
27 | - } elseif( !empty( $_SERVER['REMOTE_ADDR'] ) ) { |
|
28 | - $ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] ); |
|
23 | + if (!empty($_SERVER['HTTP_CLIENT_IP'])) { |
|
24 | + $ip = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']); |
|
25 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
26 | + $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']); |
|
27 | + } elseif (!empty($_SERVER['REMOTE_ADDR'])) { |
|
28 | + $ip = sanitize_text_field($_SERVER['REMOTE_ADDR']); |
|
29 | 29 | } |
30 | 30 | |
31 | - return apply_filters( 'wpinv_get_ip', $ip ); |
|
31 | + return apply_filters('wpinv_get_ip', $ip); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | function wpinv_get_user_agent() { |
35 | - if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
|
36 | - $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ); |
|
35 | + if (!empty($_SERVER['HTTP_USER_AGENT'])) { |
|
36 | + $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']); |
|
37 | 37 | } else { |
38 | 38 | $user_agent = ''; |
39 | 39 | } |
40 | 40 | |
41 | - return apply_filters( 'wpinv_get_user_agent', $user_agent ); |
|
41 | + return apply_filters('wpinv_get_user_agent', $user_agent); |
|
42 | 42 | } |
43 | 43 | |
44 | -function wpinv_sanitize_amount( $amount, $decimals = NULL ) { |
|
44 | +function wpinv_sanitize_amount($amount, $decimals = NULL) { |
|
45 | 45 | $is_negative = false; |
46 | 46 | $thousands_sep = wpinv_thousands_separator(); |
47 | 47 | $decimal_sep = wpinv_decimal_separator(); |
48 | - if ( $decimals === NULL ) { |
|
48 | + if ($decimals === NULL) { |
|
49 | 49 | $decimals = wpinv_decimals(); |
50 | 50 | } |
51 | 51 | |
52 | 52 | // Sanitize the amount |
53 | - if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) { |
|
54 | - if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
55 | - $amount = str_replace( $thousands_sep, '', $amount ); |
|
56 | - } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) { |
|
57 | - $amount = str_replace( '.', '', $amount ); |
|
53 | + if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) { |
|
54 | + if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) { |
|
55 | + $amount = str_replace($thousands_sep, '', $amount); |
|
56 | + } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) { |
|
57 | + $amount = str_replace('.', '', $amount); |
|
58 | 58 | } |
59 | 59 | |
60 | - $amount = str_replace( $decimal_sep, '.', $amount ); |
|
61 | - } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
62 | - $amount = str_replace( $thousands_sep, '', $amount ); |
|
60 | + $amount = str_replace($decimal_sep, '.', $amount); |
|
61 | + } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
62 | + $amount = str_replace($thousands_sep, '', $amount); |
|
63 | 63 | } |
64 | 64 | |
65 | - if( $amount < 0 ) { |
|
65 | + if ($amount < 0) { |
|
66 | 66 | $is_negative = true; |
67 | 67 | } |
68 | 68 | |
69 | - $amount = preg_replace( '/[^0-9\.]/', '', $amount ); |
|
69 | + $amount = preg_replace('/[^0-9\.]/', '', $amount); |
|
70 | 70 | |
71 | - $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', absint( $decimals ), $amount ); |
|
72 | - $amount = number_format( (double) $amount, absint( $decimals ), '.', '' ); |
|
71 | + $decimals = apply_filters('wpinv_sanitize_amount_decimals', absint($decimals), $amount); |
|
72 | + $amount = number_format((double) $amount, absint($decimals), '.', ''); |
|
73 | 73 | |
74 | - if( $is_negative ) { |
|
74 | + if ($is_negative) { |
|
75 | 75 | $amount *= -1; |
76 | 76 | } |
77 | 77 | |
78 | - return apply_filters( 'wpinv_sanitize_amount', $amount, $decimals ); |
|
78 | + return apply_filters('wpinv_sanitize_amount', $amount, $decimals); |
|
79 | 79 | } |
80 | -add_filter( 'wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1 ); |
|
80 | +add_filter('wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1); |
|
81 | 81 | |
82 | -function wpinv_round_amount( $amount, $decimals = NULL ) { |
|
83 | - if ( $decimals === NULL ) { |
|
82 | +function wpinv_round_amount($amount, $decimals = NULL) { |
|
83 | + if ($decimals === NULL) { |
|
84 | 84 | $decimals = wpinv_decimals(); |
85 | 85 | } |
86 | 86 | |
87 | - $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) ); |
|
87 | + $amount = round((double) $amount, wpinv_currency_decimal_filter(absint($decimals))); |
|
88 | 88 | |
89 | - return apply_filters( 'wpinv_round_amount', $amount, $decimals ); |
|
89 | + return apply_filters('wpinv_round_amount', $amount, $decimals); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -95,32 +95,32 @@ discard block |
||
95 | 95 | * @since 1.0.19 |
96 | 96 | * @return array |
97 | 97 | */ |
98 | -function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) { |
|
98 | +function wpinv_get_invoice_statuses($draft = false, $trashed = false, $invoice = false) { |
|
99 | 99 | $invoice_statuses = array( |
100 | - 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
101 | - 'publish' => _x( 'Paid', 'Invoice status', 'invoicing' ), |
|
102 | - 'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
103 | - 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
104 | - 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
105 | - 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
106 | - 'wpi-failed' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
107 | - 'wpi-renewal' => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ), |
|
100 | + 'wpi-pending' => _x('Pending payment', 'Invoice status', 'invoicing'), |
|
101 | + 'publish' => _x('Paid', 'Invoice status', 'invoicing'), |
|
102 | + 'wpi-processing' => _x('Processing', 'Invoice status', 'invoicing'), |
|
103 | + 'wpi-onhold' => _x('On hold', 'Invoice status', 'invoicing'), |
|
104 | + 'wpi-cancelled' => _x('Cancelled', 'Invoice status', 'invoicing'), |
|
105 | + 'wpi-refunded' => _x('Refunded', 'Invoice status', 'invoicing'), |
|
106 | + 'wpi-failed' => _x('Failed', 'Invoice status', 'invoicing'), |
|
107 | + 'wpi-renewal' => _x('Renewal Payment', 'Invoice status', 'invoicing'), |
|
108 | 108 | ); |
109 | 109 | |
110 | - if ( $draft ) { |
|
111 | - $invoice_statuses['draft'] = __( 'Draft', 'invoicing' ); |
|
110 | + if ($draft) { |
|
111 | + $invoice_statuses['draft'] = __('Draft', 'invoicing'); |
|
112 | 112 | } |
113 | 113 | |
114 | - if ( $trashed ) { |
|
115 | - $invoice_statuses['trash'] = __( 'Trash', 'invoicing' ); |
|
114 | + if ($trashed) { |
|
115 | + $invoice_statuses['trash'] = __('Trash', 'invoicing'); |
|
116 | 116 | } |
117 | 117 | |
118 | - return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
118 | + return apply_filters('wpinv_statuses', $invoice_statuses, $invoice); |
|
119 | 119 | } |
120 | 120 | |
121 | -function wpinv_status_nicename( $status ) { |
|
122 | - $statuses = wpinv_get_invoice_statuses( true, true ); |
|
123 | - $status = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' ); |
|
121 | +function wpinv_status_nicename($status) { |
|
122 | + $statuses = wpinv_get_invoice_statuses(true, true); |
|
123 | + $status = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing'); |
|
124 | 124 | |
125 | 125 | return $status; |
126 | 126 | } |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * Retrieves the default currency code. |
130 | 130 | */ |
131 | 131 | function wpinv_get_currency() { |
132 | - return apply_filters( 'wpinv_currency', wpinv_get_option( 'currency', 'USD' ) ); |
|
132 | + return apply_filters('wpinv_currency', wpinv_get_option('currency', 'USD')); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -137,61 +137,61 @@ discard block |
||
137 | 137 | * |
138 | 138 | * @param string|null $currency The currency code. Defaults to the default currency. |
139 | 139 | */ |
140 | -function wpinv_currency_symbol( $currency = null ) { |
|
140 | +function wpinv_currency_symbol($currency = null) { |
|
141 | 141 | |
142 | 142 | // Prepare the currency. |
143 | - $currency = empty( $currency ) ? wpinv_get_currency() : wpinv_clean( $currency ); |
|
143 | + $currency = empty($currency) ? wpinv_get_currency() : wpinv_clean($currency); |
|
144 | 144 | |
145 | 145 | // Fetch all symbols. |
146 | 146 | $symbols = wpinv_get_currency_symbols(); |
147 | 147 | |
148 | 148 | // Fetch this currencies symbol. |
149 | - $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : $currency; |
|
149 | + $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency; |
|
150 | 150 | |
151 | 151 | // Filter the symbol. |
152 | - return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency ); |
|
152 | + return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | function wpinv_currency_position() { |
156 | - $position = wpinv_get_option( 'currency_position', 'left' ); |
|
156 | + $position = wpinv_get_option('currency_position', 'left'); |
|
157 | 157 | |
158 | - return apply_filters( 'wpinv_currency_position', $position ); |
|
158 | + return apply_filters('wpinv_currency_position', $position); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | function wpinv_thousands_separator() { |
162 | - $thousand_sep = wpinv_get_option( 'thousands_separator', ',' ); |
|
162 | + $thousand_sep = wpinv_get_option('thousands_separator', ','); |
|
163 | 163 | |
164 | - return apply_filters( 'wpinv_thousands_separator', $thousand_sep ); |
|
164 | + return apply_filters('wpinv_thousands_separator', $thousand_sep); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | function wpinv_decimal_separator() { |
168 | - $decimal_sep = wpinv_get_option( 'decimal_separator', '.' ); |
|
168 | + $decimal_sep = wpinv_get_option('decimal_separator', '.'); |
|
169 | 169 | |
170 | - return apply_filters( 'wpinv_decimal_separator', $decimal_sep ); |
|
170 | + return apply_filters('wpinv_decimal_separator', $decimal_sep); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | function wpinv_decimals() { |
174 | - $decimals = apply_filters( 'wpinv_decimals', wpinv_get_option( 'decimals', 2 ) ); |
|
174 | + $decimals = apply_filters('wpinv_decimals', wpinv_get_option('decimals', 2)); |
|
175 | 175 | |
176 | - return absint( $decimals ); |
|
176 | + return absint($decimals); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
180 | 180 | * Retrieves a list of all supported currencies. |
181 | 181 | */ |
182 | 182 | function wpinv_get_currencies() { |
183 | - return apply_filters( 'wpinv_currencies', wpinv_get_data( 'currencies' ) ); |
|
183 | + return apply_filters('wpinv_currencies', wpinv_get_data('currencies')); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
187 | 187 | * Retrieves a list of all currency symbols. |
188 | 188 | */ |
189 | 189 | function wpinv_get_currency_symbols() { |
190 | - return apply_filters( 'wpinv_currency_symbols', wpinv_get_data( 'currency-symbols' ) ); |
|
190 | + return apply_filters('wpinv_currency_symbols', wpinv_get_data('currency-symbols')); |
|
191 | 191 | } |
192 | 192 | |
193 | -function wpinv_price( $amount = '', $currency = '' ) { |
|
194 | - if( empty( $currency ) ) { |
|
193 | +function wpinv_price($amount = '', $currency = '') { |
|
194 | + if (empty($currency)) { |
|
195 | 195 | $currency = wpinv_get_currency(); |
196 | 196 | } |
197 | 197 | |
@@ -199,14 +199,14 @@ discard block |
||
199 | 199 | |
200 | 200 | $negative = $amount < 0; |
201 | 201 | |
202 | - if ( $negative ) { |
|
203 | - $amount = substr( $amount, 1 ); |
|
202 | + if ($negative) { |
|
203 | + $amount = substr($amount, 1); |
|
204 | 204 | } |
205 | 205 | |
206 | - $symbol = wpinv_currency_symbol( $currency ); |
|
206 | + $symbol = wpinv_currency_symbol($currency); |
|
207 | 207 | |
208 | - if ( $position == 'left' || $position == 'left_space' ) { |
|
209 | - switch ( $currency ) { |
|
208 | + if ($position == 'left' || $position == 'left_space') { |
|
209 | + switch ($currency) { |
|
210 | 210 | case "GBP" : |
211 | 211 | case "BRL" : |
212 | 212 | case "EUR" : |
@@ -218,15 +218,15 @@ discard block |
||
218 | 218 | case "NZD" : |
219 | 219 | case "SGD" : |
220 | 220 | case "JPY" : |
221 | - $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
221 | + $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
222 | 222 | break; |
223 | 223 | default : |
224 | 224 | //$price = $currency . ' ' . $amount; |
225 | - $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
225 | + $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
226 | 226 | break; |
227 | 227 | } |
228 | 228 | } else { |
229 | - switch ( $currency ) { |
|
229 | + switch ($currency) { |
|
230 | 230 | case "GBP" : |
231 | 231 | case "BRL" : |
232 | 232 | case "EUR" : |
@@ -237,83 +237,83 @@ discard block |
||
237 | 237 | case "MXN" : |
238 | 238 | case "SGD" : |
239 | 239 | case "JPY" : |
240 | - $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
240 | + $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
241 | 241 | break; |
242 | 242 | default : |
243 | 243 | //$price = $amount . ' ' . $currency; |
244 | - $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
244 | + $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
245 | 245 | break; |
246 | 246 | } |
247 | 247 | } |
248 | 248 | |
249 | - if ( $negative ) { |
|
249 | + if ($negative) { |
|
250 | 250 | $price = '-' . $price; |
251 | 251 | } |
252 | 252 | |
253 | - $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount ); |
|
253 | + $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount); |
|
254 | 254 | |
255 | 255 | return $price; |
256 | 256 | } |
257 | 257 | |
258 | -function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) { |
|
258 | +function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) { |
|
259 | 259 | $thousands_sep = wpinv_thousands_separator(); |
260 | 260 | $decimal_sep = wpinv_decimal_separator(); |
261 | 261 | |
262 | - if ( $decimals === NULL ) { |
|
262 | + if ($decimals === NULL) { |
|
263 | 263 | $decimals = wpinv_decimals(); |
264 | 264 | } |
265 | 265 | |
266 | - if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) { |
|
267 | - $whole = substr( $amount, 0, $sep_found ); |
|
268 | - $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) ); |
|
266 | + if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) { |
|
267 | + $whole = substr($amount, 0, $sep_found); |
|
268 | + $part = substr($amount, $sep_found + 1, (strlen($amount) - 1)); |
|
269 | 269 | $amount = $whole . '.' . $part; |
270 | 270 | } |
271 | 271 | |
272 | - if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
273 | - $amount = str_replace( ',', '', $amount ); |
|
272 | + if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
273 | + $amount = str_replace(',', '', $amount); |
|
274 | 274 | } |
275 | 275 | |
276 | - if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
277 | - $amount = str_replace( ' ', '', $amount ); |
|
276 | + if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
277 | + $amount = str_replace(' ', '', $amount); |
|
278 | 278 | } |
279 | 279 | |
280 | - if ( empty( $amount ) ) { |
|
280 | + if (empty($amount)) { |
|
281 | 281 | $amount = 0; |
282 | 282 | } |
283 | 283 | |
284 | - $decimals = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate ); |
|
285 | - $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep ); |
|
284 | + $decimals = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate); |
|
285 | + $formatted = number_format((float) $amount, $decimals, $decimal_sep, $thousands_sep); |
|
286 | 286 | |
287 | - if ( $calculate ) { |
|
288 | - if ( $thousands_sep === "," ) { |
|
289 | - $formatted = str_replace( ",", "", $formatted ); |
|
287 | + if ($calculate) { |
|
288 | + if ($thousands_sep === ",") { |
|
289 | + $formatted = str_replace(",", "", $formatted); |
|
290 | 290 | } |
291 | 291 | |
292 | - if ( $decimal_sep === "," ) { |
|
293 | - $formatted = str_replace( ",", ".", $formatted ); |
|
292 | + if ($decimal_sep === ",") { |
|
293 | + $formatted = str_replace(",", ".", $formatted); |
|
294 | 294 | } |
295 | 295 | } |
296 | 296 | |
297 | - return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate ); |
|
297 | + return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate); |
|
298 | 298 | } |
299 | -add_filter( 'wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1 ); |
|
299 | +add_filter('wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1); |
|
300 | 300 | |
301 | -function wpinv_sanitize_key( $key ) { |
|
301 | +function wpinv_sanitize_key($key) { |
|
302 | 302 | $raw_key = $key; |
303 | - $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key ); |
|
303 | + $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key); |
|
304 | 304 | |
305 | - return apply_filters( 'wpinv_sanitize_key', $key, $raw_key ); |
|
305 | + return apply_filters('wpinv_sanitize_key', $key, $raw_key); |
|
306 | 306 | } |
307 | 307 | |
308 | -function wpinv_get_file_extension( $str ) { |
|
309 | - $parts = explode( '.', $str ); |
|
310 | - return end( $parts ); |
|
308 | +function wpinv_get_file_extension($str) { |
|
309 | + $parts = explode('.', $str); |
|
310 | + return end($parts); |
|
311 | 311 | } |
312 | 312 | |
313 | -function wpinv_string_is_image_url( $str ) { |
|
314 | - $ext = wpinv_get_file_extension( $str ); |
|
313 | +function wpinv_string_is_image_url($str) { |
|
314 | + $ext = wpinv_get_file_extension($str); |
|
315 | 315 | |
316 | - switch ( strtolower( $ext ) ) { |
|
316 | + switch (strtolower($ext)) { |
|
317 | 317 | case 'jpeg'; |
318 | 318 | case 'jpg'; |
319 | 319 | $return = true; |
@@ -329,33 +329,33 @@ discard block |
||
329 | 329 | break; |
330 | 330 | } |
331 | 331 | |
332 | - return (bool)apply_filters( 'wpinv_string_is_image', $return, $str ); |
|
332 | + return (bool) apply_filters('wpinv_string_is_image', $return, $str); |
|
333 | 333 | } |
334 | 334 | |
335 | -function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) { |
|
336 | - $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG ); |
|
335 | +function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) { |
|
336 | + $should_log = apply_filters('wpinv_log_errors', WP_DEBUG); |
|
337 | 337 | |
338 | - if ( true === $should_log ) { |
|
338 | + if (true === $should_log) { |
|
339 | 339 | $label = ''; |
340 | - if ( $file && $file !== '' ) { |
|
341 | - $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' ); |
|
340 | + if ($file && $file !== '') { |
|
341 | + $label .= basename($file) . ($line ? '(' . $line . ')' : ''); |
|
342 | 342 | } |
343 | 343 | |
344 | - if ( $title && $title !== '' ) { |
|
344 | + if ($title && $title !== '') { |
|
345 | 345 | $label = $label !== '' ? $label . ' ' : ''; |
346 | 346 | $label .= $title . ' '; |
347 | 347 | } |
348 | 348 | |
349 | - $label = $label !== '' ? trim( $label ) . ' : ' : ''; |
|
349 | + $label = $label !== '' ? trim($label) . ' : ' : ''; |
|
350 | 350 | |
351 | - if ( is_array( $log ) || is_object( $log ) ) { |
|
352 | - error_log( $label . print_r( $log, true ) ); |
|
351 | + if (is_array($log) || is_object($log)) { |
|
352 | + error_log($label . print_r($log, true)); |
|
353 | 353 | } else { |
354 | - error_log( $label . $log ); |
|
354 | + error_log($label . $log); |
|
355 | 355 | } |
356 | 356 | |
357 | - error_log( wp_debug_backtrace_summary() ); |
|
358 | - if ( $exit ) { |
|
357 | + error_log(wp_debug_backtrace_summary()); |
|
358 | + if ($exit) { |
|
359 | 359 | exit; |
360 | 360 | } |
361 | 361 | } |
@@ -363,32 +363,32 @@ discard block |
||
363 | 363 | |
364 | 364 | function wpinv_is_ajax_disabled() { |
365 | 365 | $retval = false; |
366 | - return apply_filters( 'wpinv_is_ajax_disabled', $retval ); |
|
366 | + return apply_filters('wpinv_is_ajax_disabled', $retval); |
|
367 | 367 | } |
368 | 368 | |
369 | -function wpinv_get_current_page_url( $nocache = false ) { |
|
369 | +function wpinv_get_current_page_url($nocache = false) { |
|
370 | 370 | global $wp; |
371 | 371 | |
372 | - if ( get_option( 'permalink_structure' ) ) { |
|
373 | - $base = trailingslashit( home_url( $wp->request ) ); |
|
372 | + if (get_option('permalink_structure')) { |
|
373 | + $base = trailingslashit(home_url($wp->request)); |
|
374 | 374 | } else { |
375 | - $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) ); |
|
376 | - $base = remove_query_arg( array( 'post_type', 'name' ), $base ); |
|
375 | + $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request))); |
|
376 | + $base = remove_query_arg(array('post_type', 'name'), $base); |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | $scheme = is_ssl() ? 'https' : 'http'; |
380 | - $uri = set_url_scheme( $base, $scheme ); |
|
380 | + $uri = set_url_scheme($base, $scheme); |
|
381 | 381 | |
382 | - if ( is_front_page() ) { |
|
383 | - $uri = home_url( '/' ); |
|
384 | - } elseif ( wpinv_is_checkout( array(), false ) ) { |
|
382 | + if (is_front_page()) { |
|
383 | + $uri = home_url('/'); |
|
384 | + } elseif (wpinv_is_checkout(array(), false)) { |
|
385 | 385 | $uri = wpinv_get_checkout_uri(); |
386 | 386 | } |
387 | 387 | |
388 | - $uri = apply_filters( 'wpinv_get_current_page_url', $uri ); |
|
388 | + $uri = apply_filters('wpinv_get_current_page_url', $uri); |
|
389 | 389 | |
390 | - if ( $nocache ) { |
|
391 | - $uri = wpinv_add_cache_busting( $uri ); |
|
390 | + if ($nocache) { |
|
391 | + $uri = wpinv_add_cache_busting($uri); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | return $uri; |
@@ -401,46 +401,46 @@ discard block |
||
401 | 401 | * @param string $name Constant name. |
402 | 402 | * @param mixed $value Value. |
403 | 403 | */ |
404 | -function getpaid_maybe_define_constant( $name, $value ) { |
|
405 | - if ( ! defined( $name ) ) { |
|
406 | - define( $name, $value ); |
|
404 | +function getpaid_maybe_define_constant($name, $value) { |
|
405 | + if (!defined($name)) { |
|
406 | + define($name, $value); |
|
407 | 407 | } |
408 | 408 | } |
409 | 409 | |
410 | 410 | function wpinv_get_php_arg_separator_output() { |
411 | - return ini_get( 'arg_separator.output' ); |
|
411 | + return ini_get('arg_separator.output'); |
|
412 | 412 | } |
413 | 413 | |
414 | -function wpinv_rgb_from_hex( $color ) { |
|
415 | - $color = str_replace( '#', '', $color ); |
|
414 | +function wpinv_rgb_from_hex($color) { |
|
415 | + $color = str_replace('#', '', $color); |
|
416 | 416 | |
417 | 417 | // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF" |
418 | - $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color ); |
|
419 | - if ( empty( $color ) ) { |
|
418 | + $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color); |
|
419 | + if (empty($color)) { |
|
420 | 420 | return NULL; |
421 | 421 | } |
422 | 422 | |
423 | - $color = str_split( $color ); |
|
423 | + $color = str_split($color); |
|
424 | 424 | |
425 | 425 | $rgb = array(); |
426 | - $rgb['R'] = hexdec( $color[0] . $color[1] ); |
|
427 | - $rgb['G'] = hexdec( $color[2] . $color[3] ); |
|
428 | - $rgb['B'] = hexdec( $color[4] . $color[5] ); |
|
426 | + $rgb['R'] = hexdec($color[0] . $color[1]); |
|
427 | + $rgb['G'] = hexdec($color[2] . $color[3]); |
|
428 | + $rgb['B'] = hexdec($color[4] . $color[5]); |
|
429 | 429 | |
430 | 430 | return $rgb; |
431 | 431 | } |
432 | 432 | |
433 | -function wpinv_hex_darker( $color, $factor = 30 ) { |
|
434 | - $base = wpinv_rgb_from_hex( $color ); |
|
433 | +function wpinv_hex_darker($color, $factor = 30) { |
|
434 | + $base = wpinv_rgb_from_hex($color); |
|
435 | 435 | $color = '#'; |
436 | 436 | |
437 | - foreach ( $base as $k => $v ) { |
|
437 | + foreach ($base as $k => $v) { |
|
438 | 438 | $amount = $v / 100; |
439 | - $amount = round( $amount * $factor ); |
|
439 | + $amount = round($amount * $factor); |
|
440 | 440 | $new_decimal = $v - $amount; |
441 | 441 | |
442 | - $new_hex_component = dechex( $new_decimal ); |
|
443 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
442 | + $new_hex_component = dechex($new_decimal); |
|
443 | + if (strlen($new_hex_component) < 2) { |
|
444 | 444 | $new_hex_component = "0" . $new_hex_component; |
445 | 445 | } |
446 | 446 | $color .= $new_hex_component; |
@@ -449,18 +449,18 @@ discard block |
||
449 | 449 | return $color; |
450 | 450 | } |
451 | 451 | |
452 | -function wpinv_hex_lighter( $color, $factor = 30 ) { |
|
453 | - $base = wpinv_rgb_from_hex( $color ); |
|
452 | +function wpinv_hex_lighter($color, $factor = 30) { |
|
453 | + $base = wpinv_rgb_from_hex($color); |
|
454 | 454 | $color = '#'; |
455 | 455 | |
456 | - foreach ( $base as $k => $v ) { |
|
456 | + foreach ($base as $k => $v) { |
|
457 | 457 | $amount = 255 - $v; |
458 | 458 | $amount = $amount / 100; |
459 | - $amount = round( $amount * $factor ); |
|
459 | + $amount = round($amount * $factor); |
|
460 | 460 | $new_decimal = $v + $amount; |
461 | 461 | |
462 | - $new_hex_component = dechex( $new_decimal ); |
|
463 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
462 | + $new_hex_component = dechex($new_decimal); |
|
463 | + if (strlen($new_hex_component) < 2) { |
|
464 | 464 | $new_hex_component = "0" . $new_hex_component; |
465 | 465 | } |
466 | 466 | $color .= $new_hex_component; |
@@ -469,22 +469,22 @@ discard block |
||
469 | 469 | return $color; |
470 | 470 | } |
471 | 471 | |
472 | -function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { |
|
473 | - $hex = str_replace( '#', '', $color ); |
|
472 | +function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') { |
|
473 | + $hex = str_replace('#', '', $color); |
|
474 | 474 | |
475 | - $c_r = hexdec( substr( $hex, 0, 2 ) ); |
|
476 | - $c_g = hexdec( substr( $hex, 2, 2 ) ); |
|
477 | - $c_b = hexdec( substr( $hex, 4, 2 ) ); |
|
475 | + $c_r = hexdec(substr($hex, 0, 2)); |
|
476 | + $c_g = hexdec(substr($hex, 2, 2)); |
|
477 | + $c_b = hexdec(substr($hex, 4, 2)); |
|
478 | 478 | |
479 | - $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; |
|
479 | + $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000; |
|
480 | 480 | |
481 | 481 | return $brightness > 155 ? $dark : $light; |
482 | 482 | } |
483 | 483 | |
484 | -function wpinv_format_hex( $hex ) { |
|
485 | - $hex = trim( str_replace( '#', '', $hex ) ); |
|
484 | +function wpinv_format_hex($hex) { |
|
485 | + $hex = trim(str_replace('#', '', $hex)); |
|
486 | 486 | |
487 | - if ( strlen( $hex ) == 3 ) { |
|
487 | + if (strlen($hex) == 3) { |
|
488 | 488 | $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; |
489 | 489 | } |
490 | 490 | |
@@ -504,12 +504,12 @@ discard block |
||
504 | 504 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
505 | 505 | * @return string |
506 | 506 | */ |
507 | -function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) { |
|
508 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
509 | - return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding ); |
|
507 | +function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') { |
|
508 | + if (function_exists('mb_strimwidth')) { |
|
509 | + return mb_strimwidth($str, $start, $width, $trimmaker, $encoding); |
|
510 | 510 | } |
511 | 511 | |
512 | - return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker; |
|
512 | + return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker; |
|
513 | 513 | } |
514 | 514 | |
515 | 515 | /** |
@@ -521,28 +521,28 @@ discard block |
||
521 | 521 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
522 | 522 | * @return int Returns the number of characters in string. |
523 | 523 | */ |
524 | -function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) { |
|
525 | - if ( function_exists( 'mb_strlen' ) ) { |
|
526 | - return mb_strlen( $str, $encoding ); |
|
524 | +function wpinv_utf8_strlen($str, $encoding = 'UTF-8') { |
|
525 | + if (function_exists('mb_strlen')) { |
|
526 | + return mb_strlen($str, $encoding); |
|
527 | 527 | } |
528 | 528 | |
529 | - return strlen( $str ); |
|
529 | + return strlen($str); |
|
530 | 530 | } |
531 | 531 | |
532 | -function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) { |
|
533 | - if ( function_exists( 'mb_strtolower' ) ) { |
|
534 | - return mb_strtolower( $str, $encoding ); |
|
532 | +function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') { |
|
533 | + if (function_exists('mb_strtolower')) { |
|
534 | + return mb_strtolower($str, $encoding); |
|
535 | 535 | } |
536 | 536 | |
537 | - return strtolower( $str ); |
|
537 | + return strtolower($str); |
|
538 | 538 | } |
539 | 539 | |
540 | -function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) { |
|
541 | - if ( function_exists( 'mb_strtoupper' ) ) { |
|
542 | - return mb_strtoupper( $str, $encoding ); |
|
540 | +function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') { |
|
541 | + if (function_exists('mb_strtoupper')) { |
|
542 | + return mb_strtoupper($str, $encoding); |
|
543 | 543 | } |
544 | 544 | |
545 | - return strtoupper( $str ); |
|
545 | + return strtoupper($str); |
|
546 | 546 | } |
547 | 547 | |
548 | 548 | /** |
@@ -556,12 +556,12 @@ discard block |
||
556 | 556 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
557 | 557 | * @return int Returns the position of the first occurrence of search in the string. |
558 | 558 | */ |
559 | -function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
560 | - if ( function_exists( 'mb_strpos' ) ) { |
|
561 | - return mb_strpos( $str, $find, $offset, $encoding ); |
|
559 | +function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
560 | + if (function_exists('mb_strpos')) { |
|
561 | + return mb_strpos($str, $find, $offset, $encoding); |
|
562 | 562 | } |
563 | 563 | |
564 | - return strpos( $str, $find, $offset ); |
|
564 | + return strpos($str, $find, $offset); |
|
565 | 565 | } |
566 | 566 | |
567 | 567 | /** |
@@ -575,12 +575,12 @@ discard block |
||
575 | 575 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
576 | 576 | * @return int Returns the position of the last occurrence of search. |
577 | 577 | */ |
578 | -function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
579 | - if ( function_exists( 'mb_strrpos' ) ) { |
|
580 | - return mb_strrpos( $str, $find, $offset, $encoding ); |
|
578 | +function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
579 | + if (function_exists('mb_strrpos')) { |
|
580 | + return mb_strrpos($str, $find, $offset, $encoding); |
|
581 | 581 | } |
582 | 582 | |
583 | - return strrpos( $str, $find, $offset ); |
|
583 | + return strrpos($str, $find, $offset); |
|
584 | 584 | } |
585 | 585 | |
586 | 586 | /** |
@@ -595,16 +595,16 @@ discard block |
||
595 | 595 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
596 | 596 | * @return string |
597 | 597 | */ |
598 | -function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) { |
|
599 | - if ( function_exists( 'mb_substr' ) ) { |
|
600 | - if ( $length === null ) { |
|
601 | - return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
598 | +function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') { |
|
599 | + if (function_exists('mb_substr')) { |
|
600 | + if ($length === null) { |
|
601 | + return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
602 | 602 | } else { |
603 | - return mb_substr( $str, $start, $length, $encoding ); |
|
603 | + return mb_substr($str, $start, $length, $encoding); |
|
604 | 604 | } |
605 | 605 | } |
606 | 606 | |
607 | - return substr( $str, $start, $length ); |
|
607 | + return substr($str, $start, $length); |
|
608 | 608 | } |
609 | 609 | |
610 | 610 | /** |
@@ -616,48 +616,48 @@ discard block |
||
616 | 616 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
617 | 617 | * @return string The width of string. |
618 | 618 | */ |
619 | -function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) { |
|
620 | - if ( function_exists( 'mb_strwidth' ) ) { |
|
621 | - return mb_strwidth( $str, $encoding ); |
|
619 | +function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') { |
|
620 | + if (function_exists('mb_strwidth')) { |
|
621 | + return mb_strwidth($str, $encoding); |
|
622 | 622 | } |
623 | 623 | |
624 | - return wpinv_utf8_strlen( $str, $encoding ); |
|
624 | + return wpinv_utf8_strlen($str, $encoding); |
|
625 | 625 | } |
626 | 626 | |
627 | -function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) { |
|
628 | - if ( function_exists( 'mb_strlen' ) ) { |
|
629 | - $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding ); |
|
627 | +function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') { |
|
628 | + if (function_exists('mb_strlen')) { |
|
629 | + $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding); |
|
630 | 630 | $str_end = ""; |
631 | 631 | |
632 | - if ( $lower_str_end ) { |
|
633 | - $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding ); |
|
632 | + if ($lower_str_end) { |
|
633 | + $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding); |
|
634 | 634 | } else { |
635 | - $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
635 | + $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | return $first_letter . $str_end; |
639 | 639 | } |
640 | 640 | |
641 | - return ucfirst( $str ); |
|
641 | + return ucfirst($str); |
|
642 | 642 | } |
643 | 643 | |
644 | -function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) { |
|
645 | - if ( function_exists( 'mb_convert_case' ) ) { |
|
646 | - return mb_convert_case( $str, MB_CASE_TITLE, $encoding ); |
|
644 | +function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') { |
|
645 | + if (function_exists('mb_convert_case')) { |
|
646 | + return mb_convert_case($str, MB_CASE_TITLE, $encoding); |
|
647 | 647 | } |
648 | 648 | |
649 | - return ucwords( $str ); |
|
649 | + return ucwords($str); |
|
650 | 650 | } |
651 | 651 | |
652 | -function wpinv_period_in_days( $period, $unit ) { |
|
653 | - $period = absint( $period ); |
|
652 | +function wpinv_period_in_days($period, $unit) { |
|
653 | + $period = absint($period); |
|
654 | 654 | |
655 | - if ( $period > 0 ) { |
|
656 | - if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) { |
|
655 | + if ($period > 0) { |
|
656 | + if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) { |
|
657 | 657 | $period = $period * 7; |
658 | - } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) { |
|
658 | + } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) { |
|
659 | 659 | $period = $period * 30; |
660 | - } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) { |
|
660 | + } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) { |
|
661 | 661 | $period = $period * 365; |
662 | 662 | } |
663 | 663 | } |
@@ -665,14 +665,14 @@ discard block |
||
665 | 665 | return $period; |
666 | 666 | } |
667 | 667 | |
668 | -function wpinv_cal_days_in_month( $calendar, $month, $year ) { |
|
669 | - if ( function_exists( 'cal_days_in_month' ) ) { |
|
670 | - return cal_days_in_month( $calendar, $month, $year ); |
|
668 | +function wpinv_cal_days_in_month($calendar, $month, $year) { |
|
669 | + if (function_exists('cal_days_in_month')) { |
|
670 | + return cal_days_in_month($calendar, $month, $year); |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | // Fallback in case the calendar extension is not loaded in PHP |
674 | 674 | // Only supports Gregorian calendar |
675 | - return date( 't', mktime( 0, 0, 0, $month, 1, $year ) ); |
|
675 | + return date('t', mktime(0, 0, 0, $month, 1, $year)); |
|
676 | 676 | } |
677 | 677 | |
678 | 678 | /** |
@@ -683,11 +683,11 @@ discard block |
||
683 | 683 | * |
684 | 684 | * @return string |
685 | 685 | */ |
686 | -function wpi_help_tip( $tip, $allow_html = false ) { |
|
687 | - if ( $allow_html ) { |
|
688 | - $tip = wpi_sanitize_tooltip( $tip ); |
|
686 | +function wpi_help_tip($tip, $allow_html = false) { |
|
687 | + if ($allow_html) { |
|
688 | + $tip = wpi_sanitize_tooltip($tip); |
|
689 | 689 | } else { |
690 | - $tip = esc_attr( $tip ); |
|
690 | + $tip = esc_attr($tip); |
|
691 | 691 | } |
692 | 692 | |
693 | 693 | return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
@@ -701,8 +701,8 @@ discard block |
||
701 | 701 | * @param string $var |
702 | 702 | * @return string |
703 | 703 | */ |
704 | -function wpi_sanitize_tooltip( $var ) { |
|
705 | - return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
|
704 | +function wpi_sanitize_tooltip($var) { |
|
705 | + return htmlspecialchars(wp_kses(html_entity_decode($var), array( |
|
706 | 706 | 'br' => array(), |
707 | 707 | 'em' => array(), |
708 | 708 | 'strong' => array(), |
@@ -712,7 +712,7 @@ discard block |
||
712 | 712 | 'li' => array(), |
713 | 713 | 'ol' => array(), |
714 | 714 | 'p' => array(), |
715 | - ) ) ); |
|
715 | + ))); |
|
716 | 716 | } |
717 | 717 | |
718 | 718 | /** |
@@ -722,7 +722,7 @@ discard block |
||
722 | 722 | */ |
723 | 723 | function wpinv_get_screen_ids() { |
724 | 724 | |
725 | - $screen_id = sanitize_title( __( 'Invoicing', 'invoicing' ) ); |
|
725 | + $screen_id = sanitize_title(__('Invoicing', 'invoicing')); |
|
726 | 726 | |
727 | 727 | $screen_ids = array( |
728 | 728 | 'toplevel_page_' . $screen_id, |
@@ -740,7 +740,7 @@ discard block |
||
740 | 740 | 'invoicing_page_wpi-addons', |
741 | 741 | ); |
742 | 742 | |
743 | - return apply_filters( 'wpinv_screen_ids', $screen_ids ); |
|
743 | + return apply_filters('wpinv_screen_ids', $screen_ids); |
|
744 | 744 | } |
745 | 745 | |
746 | 746 | /** |
@@ -751,14 +751,14 @@ discard block |
||
751 | 751 | * @param array|string $list List of values. |
752 | 752 | * @return array Sanitized array of values. |
753 | 753 | */ |
754 | -function wpinv_parse_list( $list ) { |
|
754 | +function wpinv_parse_list($list) { |
|
755 | 755 | |
756 | - if ( empty( $list ) ) { |
|
756 | + if (empty($list)) { |
|
757 | 757 | $list = array(); |
758 | 758 | } |
759 | 759 | |
760 | - if ( ! is_array( $list ) ) { |
|
761 | - return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
760 | + if (!is_array($list)) { |
|
761 | + return preg_split('/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY); |
|
762 | 762 | } |
763 | 763 | |
764 | 764 | return $list; |
@@ -772,16 +772,16 @@ discard block |
||
772 | 772 | * @param string $key Type of data to fetch. |
773 | 773 | * @return mixed Fetched data. |
774 | 774 | */ |
775 | -function wpinv_get_data( $key ) { |
|
775 | +function wpinv_get_data($key) { |
|
776 | 776 | |
777 | 777 | // Try fetching it from the cache. |
778 | - $data = wp_cache_get( "wpinv-data-$key", 'wpinv' ); |
|
779 | - if( $data ) { |
|
778 | + $data = wp_cache_get("wpinv-data-$key", 'wpinv'); |
|
779 | + if ($data) { |
|
780 | 780 | return $data; |
781 | 781 | } |
782 | 782 | |
783 | - $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" ); |
|
784 | - wp_cache_set( "wpinv-data-$key", $data, 'wpinv' ); |
|
783 | + $data = apply_filters("wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php"); |
|
784 | + wp_cache_set("wpinv-data-$key", $data, 'wpinv'); |
|
785 | 785 | |
786 | 786 | return $data; |
787 | 787 | } |
@@ -795,10 +795,10 @@ discard block |
||
795 | 795 | * @param bool $first_empty Whether or not the first item in the list should be empty |
796 | 796 | * @return mixed Fetched data. |
797 | 797 | */ |
798 | -function wpinv_maybe_add_empty_option( $options, $first_empty ) { |
|
798 | +function wpinv_maybe_add_empty_option($options, $first_empty) { |
|
799 | 799 | |
800 | - if ( ! empty( $options ) && $first_empty ) { |
|
801 | - return array_merge( array( '' => '' ), $options ); |
|
800 | + if (!empty($options) && $first_empty) { |
|
801 | + return array_merge(array('' => ''), $options); |
|
802 | 802 | } |
803 | 803 | return $options; |
804 | 804 | |
@@ -810,21 +810,21 @@ discard block |
||
810 | 810 | * @param mixed $var Data to sanitize. |
811 | 811 | * @return string|array |
812 | 812 | */ |
813 | -function wpinv_clean( $var ) { |
|
813 | +function wpinv_clean($var) { |
|
814 | 814 | |
815 | - if ( is_array( $var ) ) { |
|
816 | - return array_map( 'wpinv_clean', $var ); |
|
815 | + if (is_array($var)) { |
|
816 | + return array_map('wpinv_clean', $var); |
|
817 | 817 | } |
818 | 818 | |
819 | - if ( is_object( $var ) ) { |
|
820 | - $object_vars = get_object_vars( $var ); |
|
821 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
822 | - $var->$property_name = wpinv_clean( $property_value ); |
|
819 | + if (is_object($var)) { |
|
820 | + $object_vars = get_object_vars($var); |
|
821 | + foreach ($object_vars as $property_name => $property_value) { |
|
822 | + $var->$property_name = wpinv_clean($property_value); |
|
823 | 823 | } |
824 | 824 | return $var; |
825 | 825 | } |
826 | 826 | |
827 | - return is_string( $var ) ? sanitize_text_field( $var ) : $var; |
|
827 | + return is_string($var) ? sanitize_text_field($var) : $var; |
|
828 | 828 | } |
829 | 829 | |
830 | 830 | /** |
@@ -833,43 +833,43 @@ discard block |
||
833 | 833 | * @param string $str Data to convert. |
834 | 834 | * @return string|array |
835 | 835 | */ |
836 | -function getpaid_convert_price_string_to_options( $str ) { |
|
836 | +function getpaid_convert_price_string_to_options($str) { |
|
837 | 837 | |
838 | - $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
839 | - $options = array(); |
|
838 | + $raw_options = array_map('trim', explode(',', $str)); |
|
839 | + $options = array(); |
|
840 | 840 | |
841 | - foreach ( $raw_options as $option ) { |
|
841 | + foreach ($raw_options as $option) { |
|
842 | 842 | |
843 | - if ( '' == $option ) { |
|
843 | + if ('' == $option) { |
|
844 | 844 | continue; |
845 | 845 | } |
846 | 846 | |
847 | - $option = array_map( 'trim', explode( '|', $option ) ); |
|
847 | + $option = array_map('trim', explode('|', $option)); |
|
848 | 848 | |
849 | 849 | $price = null; |
850 | 850 | $label = null; |
851 | 851 | |
852 | - if ( isset( $option[0] ) && '' != $option[0] ) { |
|
853 | - $label = $option[0]; |
|
852 | + if (isset($option[0]) && '' != $option[0]) { |
|
853 | + $label = $option[0]; |
|
854 | 854 | } |
855 | 855 | |
856 | - if ( isset( $option[1] ) && '' != $option[1] ) { |
|
856 | + if (isset($option[1]) && '' != $option[1]) { |
|
857 | 857 | $price = $option[1]; |
858 | 858 | } |
859 | 859 | |
860 | - if ( ! isset( $price ) ) { |
|
860 | + if (!isset($price)) { |
|
861 | 861 | $price = $label; |
862 | 862 | } |
863 | 863 | |
864 | - if ( ! isset( $price ) || ! is_numeric( $price ) ) { |
|
864 | + if (!isset($price) || !is_numeric($price)) { |
|
865 | 865 | continue; |
866 | 866 | } |
867 | 867 | |
868 | - if ( ! isset( $label ) ) { |
|
868 | + if (!isset($label)) { |
|
869 | 869 | $label = $price; |
870 | 870 | } |
871 | 871 | |
872 | - $options[ $price ] = $label; |
|
872 | + $options[$price] = $label; |
|
873 | 873 | } |
874 | 874 | |
875 | 875 | return $options; |
@@ -878,23 +878,23 @@ discard block |
||
878 | 878 | /** |
879 | 879 | * Returns the help tip. |
880 | 880 | */ |
881 | -function getpaid_get_help_tip( $tip, $additional_classes = '' ) { |
|
882 | - $additional_classes = sanitize_html_class( $additional_classes ); |
|
883 | - $tip = esc_attr__( $tip ); |
|
881 | +function getpaid_get_help_tip($tip, $additional_classes = '') { |
|
882 | + $additional_classes = sanitize_html_class($additional_classes); |
|
883 | + $tip = esc_attr__($tip); |
|
884 | 884 | return "<span class='wpi-help-tip dashicons dashicons-editor-help $additional_classes' title='$tip'></span>"; |
885 | 885 | } |
886 | 886 | |
887 | 887 | /** |
888 | 888 | * Formats a date |
889 | 889 | */ |
890 | -function getpaid_format_date( $date ) { |
|
890 | +function getpaid_format_date($date) { |
|
891 | 891 | |
892 | - if ( empty( $date ) || $date == '0000-00-00 00:00:00' ) { |
|
892 | + if (empty($date) || $date == '0000-00-00 00:00:00') { |
|
893 | 893 | return ''; |
894 | 894 | } |
895 | 895 | |
896 | 896 | |
897 | - return date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $date ) ); |
|
897 | + return date_i18n(/** @scrutinizer ignore-type */get_option('date_format'), strtotime($date)); |
|
898 | 898 | |
899 | 899 | } |
900 | 900 | |
@@ -905,16 +905,16 @@ discard block |
||
905 | 905 | * @param integer $limit Limit size in characters. |
906 | 906 | * @return string |
907 | 907 | */ |
908 | -function getpaid_limit_length( $string, $limit ) { |
|
908 | +function getpaid_limit_length($string, $limit) { |
|
909 | 909 | $str_limit = $limit - 3; |
910 | 910 | |
911 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
912 | - if ( mb_strlen( $string ) > $limit ) { |
|
913 | - $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
911 | + if (function_exists('mb_strimwidth')) { |
|
912 | + if (mb_strlen($string) > $limit) { |
|
913 | + $string = mb_strimwidth($string, 0, $str_limit) . '...'; |
|
914 | 914 | } |
915 | 915 | } else { |
916 | - if ( strlen( $string ) > $limit ) { |
|
917 | - $string = substr( $string, 0, $str_limit ) . '...'; |
|
916 | + if (strlen($string) > $limit) { |
|
917 | + $string = substr($string, 0, $str_limit) . '...'; |
|
918 | 918 | } |
919 | 919 | } |
920 | 920 | return $string; |
@@ -928,7 +928,7 @@ discard block |
||
928 | 928 | * @since 1.0.19 |
929 | 929 | */ |
930 | 930 | function getpaid_api() { |
931 | - return getpaid()->get( 'api' ); |
|
931 | + return getpaid()->get('api'); |
|
932 | 932 | } |
933 | 933 | |
934 | 934 | /** |
@@ -938,7 +938,7 @@ discard block |
||
938 | 938 | * @since 1.0.19 |
939 | 939 | */ |
940 | 940 | function getpaid_post_types() { |
941 | - return getpaid()->get( 'post_types' ); |
|
941 | + return getpaid()->get('post_types'); |
|
942 | 942 | } |
943 | 943 | |
944 | 944 | /** |
@@ -948,7 +948,7 @@ discard block |
||
948 | 948 | * @since 1.0.19 |
949 | 949 | */ |
950 | 950 | function getpaid_session() { |
951 | - return getpaid()->get( 'session' ); |
|
951 | + return getpaid()->get('session'); |
|
952 | 952 | } |
953 | 953 | |
954 | 954 | /** |
@@ -958,7 +958,7 @@ discard block |
||
958 | 958 | * @since 1.0.19 |
959 | 959 | */ |
960 | 960 | function getpaid_notes() { |
961 | - return getpaid()->get( 'notes' ); |
|
961 | + return getpaid()->get('notes'); |
|
962 | 962 | } |
963 | 963 | |
964 | 964 | /** |
@@ -970,26 +970,26 @@ discard block |
||
970 | 970 | * |
971 | 971 | * @return int|array|WPInv_Subscription[]|GetPaid_Subscriptions_Query |
972 | 972 | */ |
973 | -function getpaid_get_subscriptions( $args = array(), $return = 'results' ) { |
|
973 | +function getpaid_get_subscriptions($args = array(), $return = 'results') { |
|
974 | 974 | |
975 | 975 | // Do not retrieve all fields if we just want the count. |
976 | - if ( 'count' == $return ) { |
|
976 | + if ('count' == $return) { |
|
977 | 977 | $args['fields'] = 'id'; |
978 | 978 | $args['number'] = 1; |
979 | 979 | } |
980 | 980 | |
981 | 981 | // Do not count all matches if we just want the results. |
982 | - if ( 'results' == $return ) { |
|
982 | + if ('results' == $return) { |
|
983 | 983 | $args['count_total'] = false; |
984 | 984 | } |
985 | 985 | |
986 | - $query = new GetPaid_Subscriptions_Query( $args ); |
|
986 | + $query = new GetPaid_Subscriptions_Query($args); |
|
987 | 987 | |
988 | - if ( 'results' == $return ) { |
|
988 | + if ('results' == $return) { |
|
989 | 989 | return $query->get_results(); |
990 | 990 | } |
991 | 991 | |
992 | - if ( 'count' == $return ) { |
|
992 | + if ('count' == $return) { |
|
993 | 993 | return $query->get_total(); |
994 | 994 | } |
995 | 995 | |
@@ -1006,13 +1006,13 @@ discard block |
||
1006 | 1006 | return apply_filters( |
1007 | 1007 | 'getpaid_get_subscription_statuses', |
1008 | 1008 | array( |
1009 | - 'pending' => __( 'Pending', 'invoicing' ), |
|
1010 | - 'trialling' => __( 'Trialing', 'invoicing' ), |
|
1011 | - 'active' => __( 'Active', 'invoicing' ), |
|
1012 | - 'failing' => __( 'Failing', 'invoicing' ), |
|
1013 | - 'expired' => __( 'Expired', 'invoicing' ), |
|
1014 | - 'completed' => __( 'Complete', 'invoicing' ), |
|
1015 | - 'cancelled' =>__( 'Cancelled', 'invoicing' ), |
|
1009 | + 'pending' => __('Pending', 'invoicing'), |
|
1010 | + 'trialling' => __('Trialing', 'invoicing'), |
|
1011 | + 'active' => __('Active', 'invoicing'), |
|
1012 | + 'failing' => __('Failing', 'invoicing'), |
|
1013 | + 'expired' => __('Expired', 'invoicing'), |
|
1014 | + 'completed' => __('Complete', 'invoicing'), |
|
1015 | + 'cancelled' =>__('Cancelled', 'invoicing'), |
|
1016 | 1016 | ) |
1017 | 1017 | ); |
1018 | 1018 | |
@@ -1023,9 +1023,9 @@ discard block |
||
1023 | 1023 | * |
1024 | 1024 | * @return string |
1025 | 1025 | */ |
1026 | -function getpaid_get_subscription_status_label( $status ) { |
|
1026 | +function getpaid_get_subscription_status_label($status) { |
|
1027 | 1027 | $statuses = getpaid_get_subscription_statuses(); |
1028 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( $status ); |
|
1028 | + return isset($statuses[$status]) ? $statuses[$status] : ucfirst($status); |
|
1029 | 1029 | } |
1030 | 1030 | |
1031 | 1031 | /** |
@@ -1055,14 +1055,14 @@ discard block |
||
1055 | 1055 | * |
1056 | 1056 | * @return array |
1057 | 1057 | */ |
1058 | -function getpaid_get_subscription_status_counts( $args = array() ) { |
|
1058 | +function getpaid_get_subscription_status_counts($args = array()) { |
|
1059 | 1059 | |
1060 | - $statuses = array_keys( getpaid_get_subscription_statuses() ); |
|
1060 | + $statuses = array_keys(getpaid_get_subscription_statuses()); |
|
1061 | 1061 | $counts = array(); |
1062 | 1062 | |
1063 | - foreach ( $statuses as $status ) { |
|
1064 | - $_args = wp_parse_args( "status=$status", $args ); |
|
1065 | - $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' ); |
|
1063 | + foreach ($statuses as $status) { |
|
1064 | + $_args = wp_parse_args("status=$status", $args); |
|
1065 | + $counts[$status] = getpaid_get_subscriptions($_args, 'count'); |
|
1066 | 1066 | } |
1067 | 1067 | |
1068 | 1068 | return $counts; |
@@ -1074,20 +1074,20 @@ discard block |
||
1074 | 1074 | * |
1075 | 1075 | * @return string |
1076 | 1076 | */ |
1077 | -function getpaid_get_subscription_period_label( $period ) { |
|
1077 | +function getpaid_get_subscription_period_label($period) { |
|
1078 | 1078 | |
1079 | 1079 | $periods = array( |
1080 | - 'd' => __( 'day', 'invoicing' ), |
|
1081 | - 'day' => __( 'day', 'invoicing' ), |
|
1082 | - 'w' => __( 'week', 'invoicing' ), |
|
1083 | - 'week' => __( 'week', 'invoicing' ), |
|
1084 | - 'm' => __( 'month', 'invoicing' ), |
|
1085 | - 'month' => __( 'month', 'invoicing' ), |
|
1086 | - 'y' => __( 'year', 'invoicing' ), |
|
1087 | - 'year' => __( 'year', 'invoicing' ), |
|
1080 | + 'd' => __('day', 'invoicing'), |
|
1081 | + 'day' => __('day', 'invoicing'), |
|
1082 | + 'w' => __('week', 'invoicing'), |
|
1083 | + 'week' => __('week', 'invoicing'), |
|
1084 | + 'm' => __('month', 'invoicing'), |
|
1085 | + 'month' => __('month', 'invoicing'), |
|
1086 | + 'y' => __('year', 'invoicing'), |
|
1087 | + 'year' => __('year', 'invoicing'), |
|
1088 | 1088 | ); |
1089 | 1089 | |
1090 | - return isset( $periods[ $period ] ) ? strtolower( $periods[ $period ] ) : strtolower( $periods['d'] ); |
|
1090 | + return isset($periods[$period]) ? strtolower($periods[$period]) : strtolower($periods['d']); |
|
1091 | 1091 | } |
1092 | 1092 | |
1093 | 1093 | /** |
@@ -1096,7 +1096,7 @@ discard block |
||
1096 | 1096 | * @return GetPaid_Admin |
1097 | 1097 | */ |
1098 | 1098 | function getpaid_admin() { |
1099 | - return getpaid()->get( 'admin' ); |
|
1099 | + return getpaid()->get('admin'); |
|
1100 | 1100 | } |
1101 | 1101 | |
1102 | 1102 | /** |
@@ -1104,13 +1104,13 @@ discard block |
||
1104 | 1104 | * |
1105 | 1105 | * @return string |
1106 | 1106 | */ |
1107 | -function getpaid_format_date_value( $date, $default = "—" ) { |
|
1107 | +function getpaid_format_date_value($date, $default = "—") { |
|
1108 | 1108 | |
1109 | - if ( empty( $date ) || '0000-00-00 00:00:00' == $date ) { |
|
1109 | + if (empty($date) || '0000-00-00 00:00:00' == $date) { |
|
1110 | 1110 | return $default; |
1111 | 1111 | } |
1112 | 1112 | |
1113 | - return date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $date ) ); |
|
1113 | + return date_i18n(/** @scrutinizer ignore-type */get_option('date_format'), strtotime($date)); |
|
1114 | 1114 | |
1115 | 1115 | } |
1116 | 1116 | |
@@ -1121,6 +1121,6 @@ discard block |
||
1121 | 1121 | * @param string $base the base url |
1122 | 1122 | * @return string |
1123 | 1123 | */ |
1124 | -function getpaid_get_authenticated_action_url( $action, $base = false ) { |
|
1125 | - return wp_nonce_url( add_query_arg( 'getpaid-action', $action, $base ), 'getpaid-nonce', 'getpaid-nonce' ); |
|
1124 | +function getpaid_get_authenticated_action_url($action, $base = false) { |
|
1125 | + return wp_nonce_url(add_query_arg('getpaid-action', $action, $base), 'getpaid-nonce', 'getpaid-nonce'); |
|
1126 | 1126 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * @version 1.0.0 |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Contains the subscriptions widget. |
@@ -27,15 +27,15 @@ discard block |
||
27 | 27 | 'block-keywords'=> "['invoicing','subscriptions', 'getpaid']", |
28 | 28 | 'class_name' => __CLASS__, |
29 | 29 | 'base_id' => 'wpinv_subscriptions', |
30 | - 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
30 | + 'name' => __('GetPaid > Subscriptions', 'invoicing'), |
|
31 | 31 | 'widget_ops' => array( |
32 | 32 | 'classname' => 'getpaid-subscriptions bsui', |
33 | - 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
33 | + 'description' => esc_html__("Displays the current user's subscriptions.", 'invoicing'), |
|
34 | 34 | ), |
35 | 35 | 'arguments' => array( |
36 | 36 | 'title' => array( |
37 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
38 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
37 | + 'title' => __('Widget title', 'invoicing'), |
|
38 | + 'desc' => __('Enter widget title.', 'invoicing'), |
|
39 | 39 | 'type' => 'text', |
40 | 40 | 'desc_tip' => true, |
41 | 41 | 'default' => '', |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | ); |
47 | 47 | |
48 | 48 | |
49 | - parent::__construct( $options ); |
|
49 | + parent::__construct($options); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -57,12 +57,12 @@ discard block |
||
57 | 57 | public function get_subscriptions() { |
58 | 58 | |
59 | 59 | // Prepare license args. |
60 | - $args = array( |
|
60 | + $args = array( |
|
61 | 61 | 'customer_in' => get_current_user_id(), |
62 | - 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
62 | + 'paged' => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1, |
|
63 | 63 | ); |
64 | 64 | |
65 | - return new GetPaid_Subscriptions_Query( $args ); |
|
65 | + return new GetPaid_Subscriptions_Query($args); |
|
66 | 66 | |
67 | 67 | } |
68 | 68 | |
@@ -75,14 +75,14 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @return mixed|string|bool |
77 | 77 | */ |
78 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
78 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
79 | 79 | |
80 | 80 | // Ensure that the user is logged in. |
81 | - if ( ! is_user_logged_in() ) { |
|
81 | + if (!is_user_logged_in()) { |
|
82 | 82 | |
83 | 83 | return aui()->alert( |
84 | 84 | array( |
85 | - 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
85 | + 'content' => wp_kses_post(__('You need to log-in or create an account to view this section.', 'invoicing')), |
|
86 | 86 | 'type' => 'error', |
87 | 87 | ) |
88 | 88 | ); |
@@ -90,8 +90,8 @@ discard block |
||
90 | 90 | } |
91 | 91 | |
92 | 92 | // Are we displaying a single subscription? |
93 | - if ( isset( $_GET['subscription'] ) ) { |
|
94 | - return $this->display_single_subscription( trim( $_GET['subscription'] ) ); |
|
93 | + if (isset($_GET['subscription'])) { |
|
94 | + return $this->display_single_subscription(trim($_GET['subscription'])); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | // Retrieve the user's subscriptions. |
@@ -101,27 +101,27 @@ discard block |
||
101 | 101 | ob_start(); |
102 | 102 | |
103 | 103 | // Backwards compatibility. |
104 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
104 | + do_action('wpinv_before_user_subscriptions'); |
|
105 | 105 | |
106 | 106 | // Display errors and notices. |
107 | 107 | wpinv_print_errors(); |
108 | 108 | |
109 | - do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
109 | + do_action('getpaid_license_manager_before_subscriptions', $subscriptions); |
|
110 | 110 | |
111 | 111 | // Print the table header. |
112 | 112 | $this->print_table_header(); |
113 | 113 | |
114 | 114 | // Print table body. |
115 | - $this->print_table_body( $subscriptions->get_results() ); |
|
115 | + $this->print_table_body($subscriptions->get_results()); |
|
116 | 116 | |
117 | 117 | // Print table footer. |
118 | 118 | $this->print_table_footer(); |
119 | 119 | |
120 | 120 | // Print the navigation. |
121 | - $this->print_navigation( $subscriptions->get_total() ); |
|
121 | + $this->print_navigation($subscriptions->get_total()); |
|
122 | 122 | |
123 | 123 | // Backwards compatibility. |
124 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
124 | + do_action('wpinv_after_user_subscriptions'); |
|
125 | 125 | |
126 | 126 | // Return the output. |
127 | 127 | return ob_get_clean(); |
@@ -136,13 +136,13 @@ discard block |
||
136 | 136 | public function get_subscriptions_table_columns() { |
137 | 137 | |
138 | 138 | $columns = array( |
139 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
140 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
141 | - 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
142 | - 'status' => __( 'Status', 'invoicing' ), |
|
139 | + 'subscription' => __('Subscription', 'invoicing'), |
|
140 | + 'amount' => __('Amount', 'invoicing'), |
|
141 | + 'renewal-date' => __('Next payment', 'invoicing'), |
|
142 | + 'status' => __('Status', 'invoicing'), |
|
143 | 143 | ); |
144 | 144 | |
145 | - return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
145 | + return apply_filters('getpaid_frontend_subscriptions_table_columns', $columns); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | |
158 | 158 | <thead> |
159 | 159 | <tr> |
160 | - <?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?> |
|
161 | - <th scope="col" class="getpaid-subscriptions-table-<?php echo sanitize_html_class( $key ); ?>"> |
|
162 | - <?php echo sanitize_text_field( $label ); ?> |
|
160 | + <?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?> |
|
161 | + <th scope="col" class="getpaid-subscriptions-table-<?php echo sanitize_html_class($key); ?>"> |
|
162 | + <?php echo sanitize_text_field($label); ?> |
|
163 | 163 | </th> |
164 | 164 | <?php endforeach; ?> |
165 | 165 | </tr> |
@@ -174,12 +174,12 @@ discard block |
||
174 | 174 | * |
175 | 175 | * @param WPInv_Subscription[] $subscriptions |
176 | 176 | */ |
177 | - public function print_table_body( $subscriptions ) { |
|
177 | + public function print_table_body($subscriptions) { |
|
178 | 178 | |
179 | - if ( empty( $subscriptions ) ) { |
|
179 | + if (empty($subscriptions)) { |
|
180 | 180 | $this->print_table_body_no_subscriptions(); |
181 | 181 | } else { |
182 | - $this->print_table_body_subscriptions( $subscriptions ); |
|
182 | + $this->print_table_body_subscriptions($subscriptions); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | } |
@@ -194,12 +194,12 @@ discard block |
||
194 | 194 | <tbody> |
195 | 195 | |
196 | 196 | <tr> |
197 | - <td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>"> |
|
197 | + <td colspan="<?php echo count($this->get_subscriptions_table_columns()); ?>"> |
|
198 | 198 | |
199 | 199 | <?php |
200 | 200 | echo aui()->alert( |
201 | 201 | array( |
202 | - 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
202 | + 'content' => wp_kses_post(__('No subscriptions found.', 'invoicing')), |
|
203 | 203 | 'type' => 'warning', |
204 | 204 | ) |
205 | 205 | ); |
@@ -217,12 +217,12 @@ discard block |
||
217 | 217 | * |
218 | 218 | * @param WPInv_Subscription[] $subscriptions |
219 | 219 | */ |
220 | - public function print_table_body_subscriptions( $subscriptions ) { |
|
220 | + public function print_table_body_subscriptions($subscriptions) { |
|
221 | 221 | |
222 | 222 | ?> |
223 | 223 | <tbody> |
224 | 224 | |
225 | - <?php foreach ( $subscriptions as $subscription ) : ?> |
|
225 | + <?php foreach ($subscriptions as $subscription) : ?> |
|
226 | 226 | <tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>"> |
227 | 227 | <?php |
228 | 228 | wpinv_get_template( |
@@ -248,27 +248,27 @@ discard block |
||
248 | 248 | * @since 1.0.0 |
249 | 249 | * @return string |
250 | 250 | */ |
251 | - public function add_row_actions( $content, $subscription ) { |
|
251 | + public function add_row_actions($content, $subscription) { |
|
252 | 252 | |
253 | 253 | // Prepare row actions. |
254 | 254 | $actions = array(); |
255 | 255 | |
256 | 256 | // View subscription action. |
257 | - $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); |
|
258 | - $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
257 | + $view_url = esc_url(add_query_arg('subscription', (int) $subscription->get_id(), get_permalink((int) wpinv_get_option('invoice_subscription_page')))); |
|
258 | + $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __('Manage Subscription', 'invoicing') . '</a>'; |
|
259 | 259 | |
260 | 260 | // Filter the actions. |
261 | - $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
261 | + $actions = apply_filters('getpaid_subscriptions_table_subscription_actions', $actions, $subscription); |
|
262 | 262 | |
263 | - $sanitized = array(); |
|
264 | - foreach ( $actions as $key => $action ) { |
|
265 | - $key = sanitize_html_class( $key ); |
|
266 | - $action = wp_kses_post( $action ); |
|
263 | + $sanitized = array(); |
|
264 | + foreach ($actions as $key => $action) { |
|
265 | + $key = sanitize_html_class($key); |
|
266 | + $action = wp_kses_post($action); |
|
267 | 267 | $sanitized[] = "<span class='$key'>$action</span>"; |
268 | 268 | } |
269 | 269 | |
270 | 270 | $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
271 | - $row_actions .= implode( ' | ', $sanitized ); |
|
271 | + $row_actions .= implode(' | ', $sanitized); |
|
272 | 272 | $row_actions .= '</small>'; |
273 | 273 | |
274 | 274 | return $content . $row_actions; |
@@ -284,9 +284,9 @@ discard block |
||
284 | 284 | |
285 | 285 | <tfoot> |
286 | 286 | <tr> |
287 | - <?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?> |
|
288 | - <th class="getpaid-subscriptions-<?php echo sanitize_html_class( $key ); ?>"> |
|
289 | - <?php echo sanitize_text_field( $label ); ?> |
|
287 | + <?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?> |
|
288 | + <th class="getpaid-subscriptions-<?php echo sanitize_html_class($key); ?>"> |
|
289 | + <?php echo sanitize_text_field($label); ?> |
|
290 | 290 | </th> |
291 | 291 | <?php endforeach; ?> |
292 | 292 | </tr> |
@@ -302,22 +302,22 @@ discard block |
||
302 | 302 | * |
303 | 303 | * @param int $total |
304 | 304 | */ |
305 | - public function print_navigation( $total ) { |
|
305 | + public function print_navigation($total) { |
|
306 | 306 | |
307 | - if ( $total < 1 ) { |
|
307 | + if ($total < 1) { |
|
308 | 308 | |
309 | 309 | // Out-of-bounds, run the query again without LIMIT for total count. |
310 | - $args = array( |
|
310 | + $args = array( |
|
311 | 311 | 'customer_in' => get_current_user_id(), |
312 | 312 | 'fields' => 'id', |
313 | 313 | ); |
314 | 314 | |
315 | - $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
315 | + $count_query = new GetPaid_Subscriptions_Query($args); |
|
316 | 316 | $total = $count_query->get_total(); |
317 | 317 | } |
318 | 318 | |
319 | 319 | // Abort if we do not have pages. |
320 | - if ( 2 > $total ) { |
|
320 | + if (2 > $total) { |
|
321 | 321 | return; |
322 | 322 | } |
323 | 323 | |
@@ -329,9 +329,9 @@ discard block |
||
329 | 329 | |
330 | 330 | echo getpaid_paginate_links( |
331 | 331 | array( |
332 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
332 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
333 | 333 | 'format' => '?paged=%#%', |
334 | - 'total' => (int) ceil( $total / 10 ), |
|
334 | + 'total' => (int) ceil($total / 10), |
|
335 | 335 | ) |
336 | 336 | ); |
337 | 337 | ?> |
@@ -347,29 +347,29 @@ discard block |
||
347 | 347 | * |
348 | 348 | * @return array |
349 | 349 | */ |
350 | - public function get_single_subscription_columns( $subscription ) { |
|
350 | + public function get_single_subscription_columns($subscription) { |
|
351 | 351 | |
352 | 352 | // Prepare subscription detail columns. |
353 | 353 | $fields = apply_filters( |
354 | 354 | 'getpaid_single_subscription_details_fields', |
355 | 355 | array( |
356 | - 'status' => __( 'Status', 'invoicing' ), |
|
357 | - 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
358 | - 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
359 | - 'start_date' => __( 'Start date', 'invoicing' ), |
|
360 | - 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
361 | - 'payments' => __( 'Payments', 'invoicing' ), |
|
362 | - 'item' => __( 'Item', 'invoicing' ), |
|
356 | + 'status' => __('Status', 'invoicing'), |
|
357 | + 'initial_amount' => __('Initial amount', 'invoicing'), |
|
358 | + 'recurring_amount' => __('Recurring amount', 'invoicing'), |
|
359 | + 'start_date' => __('Start date', 'invoicing'), |
|
360 | + 'expiry_date' => __('Next payment', 'invoicing'), |
|
361 | + 'payments' => __('Payments', 'invoicing'), |
|
362 | + 'item' => __('Item', 'invoicing'), |
|
363 | 363 | ), |
364 | 364 | $subscription |
365 | 365 | ); |
366 | 366 | |
367 | - if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
368 | - $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
367 | + if (!$subscription->is_active() || $subscription->is_last_renewal()) { |
|
368 | + $fields['expiry_date'] = __('End date', 'invoicing'); |
|
369 | 369 | } |
370 | 370 | |
371 | - if ( $subscription->get_initial_amount() == $subscription->get_recurring_amount() ) { |
|
372 | - unset( $fields['initial_amount'] ); |
|
371 | + if ($subscription->get_initial_amount() == $subscription->get_recurring_amount()) { |
|
372 | + unset($fields['initial_amount']); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | return $fields; |
@@ -382,16 +382,16 @@ discard block |
||
382 | 382 | * |
383 | 383 | * @return string |
384 | 384 | */ |
385 | - public function display_single_subscription( $subscription ) { |
|
385 | + public function display_single_subscription($subscription) { |
|
386 | 386 | |
387 | 387 | // Fetch the subscription. |
388 | - $subscription = new WPInv_Subscription( (int) $subscription ); |
|
388 | + $subscription = new WPInv_Subscription((int) $subscription); |
|
389 | 389 | |
390 | - if ( ! $subscription->get_id() ) { |
|
390 | + if (!$subscription->get_id()) { |
|
391 | 391 | |
392 | 392 | return aui()->alert( |
393 | 393 | array( |
394 | - 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
394 | + 'content' => wp_kses_post(__('Subscription not found.', 'invoicing')), |
|
395 | 395 | 'type' => 'error', |
396 | 396 | ) |
397 | 397 | ); |
@@ -399,11 +399,11 @@ discard block |
||
399 | 399 | } |
400 | 400 | |
401 | 401 | // Ensure that the user owns this subscription key. |
402 | - if ( get_current_user_id() != $subscription->get_customer_id() ) { |
|
402 | + if (get_current_user_id() != $subscription->get_customer_id()) { |
|
403 | 403 | |
404 | 404 | return aui()->alert( |
405 | 405 | array( |
406 | - 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
406 | + 'content' => wp_kses_post(__('You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing')), |
|
407 | 407 | 'type' => 'error', |
408 | 408 | ) |
409 | 409 | ); |