@@ -76,7 +76,7 @@ |
||
76 | 76 | // This is for backwards compatibility. Do not remove except for a |
77 | 77 | // major version bump. |
78 | 78 | if (is_string($options)) { |
79 | - $options = array( 'host' => $options ); |
|
79 | + $options = array('host' => $options); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | if (!isset($options['host'])) { |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | if ($nodesWithStyleAttributes !== false) { |
239 | 239 | /** @var $nodeWithStyleAttribute DOMNode */ |
240 | 240 | foreach ($nodesWithStyleAttributes as $node) { |
241 | - $normalizedOriginalStyle = preg_replace_callback( '/[A-z\\-]+(?=\\:)/S', array( $this, 'strtolower' ), $node->getAttribute('style') ); |
|
241 | + $normalizedOriginalStyle = preg_replace_callback('/[A-z\\-]+(?=\\:)/S', array($this, 'strtolower'), $node->getAttribute('style')); |
|
242 | 242 | |
243 | 243 | // in order to not overwrite existing style attributes in the HTML, we have to save the original HTML styles |
244 | 244 | $nodePath = $node->getNodePath(); |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | } |
290 | 290 | |
291 | 291 | // now sort the selectors by precedence |
292 | - usort($allSelectors, array($this,'sortBySelectorPrecedence')); |
|
292 | + usort($allSelectors, array($this, 'sortBySelectorPrecedence')); |
|
293 | 293 | |
294 | 294 | $this->caches[self::CACHE_KEY_CSS][$cssKey] = $allSelectors; |
295 | 295 | } |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | if ($nodesWithStyleDisplayNone->length > 0) { |
330 | 330 | /** @var $node \DOMNode */ |
331 | 331 | foreach ($nodesWithStyleDisplayNone as $node) { |
332 | - if ($node->parentNode && is_callable(array($node->parentNode,'removeChild'))) { |
|
332 | + if ($node->parentNode && is_callable(array($node->parentNode, 'removeChild'))) { |
|
333 | 333 | $node->parentNode->removeChild($node); |
334 | 334 | } |
335 | 335 | } |
@@ -338,10 +338,10 @@ discard block |
||
338 | 338 | $this->copyCssWithMediaToStyleNode($cssParts, $xmlDocument); |
339 | 339 | |
340 | 340 | if ($this->preserveEncoding) { |
341 | - if ( function_exists( 'mb_convert_encoding' ) ) { |
|
342 | - return mb_convert_encoding( $xmlDocument->saveHTML(), self::ENCODING, 'HTML-ENTITIES' ); |
|
341 | + if (function_exists('mb_convert_encoding')) { |
|
342 | + return mb_convert_encoding($xmlDocument->saveHTML(), self::ENCODING, 'HTML-ENTITIES'); |
|
343 | 343 | } else { |
344 | - return htmlspecialchars_decode( utf8_encode( html_entity_decode( $xmlDocument->saveHTML(), ENT_COMPAT, self::ENCODING ) ) ); |
|
344 | + return htmlspecialchars_decode(utf8_encode(html_entity_decode($xmlDocument->saveHTML(), ENT_COMPAT, self::ENCODING))); |
|
345 | 345 | } |
346 | 346 | } else { |
347 | 347 | return $xmlDocument->saveHTML(); |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | * @return array |
463 | 463 | */ |
464 | 464 | private function splitCssAndMediaQuery($css) { |
465 | - $css = preg_replace_callback( '#@media\\s+(?:only\\s)?(?:[\\s{\(]|screen|all)\\s?[^{]+{.*}\\s*}\\s*#misU', array( $this, '_media_concat' ), $css ); |
|
465 | + $css = preg_replace_callback('#@media\\s+(?:only\\s)?(?:[\\s{\(]|screen|all)\\s?[^{]+{.*}\\s*}\\s*#misU', array($this, '_media_concat'), $css); |
|
466 | 466 | |
467 | 467 | // filter the CSS |
468 | 468 | $search = array( |
@@ -486,7 +486,7 @@ discard block |
||
486 | 486 | return array('css' => $css, 'media' => self::$_media); |
487 | 487 | } |
488 | 488 | |
489 | - private function _media_concat( $matches ) { |
|
489 | + private function _media_concat($matches) { |
|
490 | 490 | self::$_media .= $matches[0]; |
491 | 491 | } |
492 | 492 | |
@@ -524,10 +524,10 @@ discard block |
||
524 | 524 | $bodyWithoutUnprocessableTags = $this->html; |
525 | 525 | } |
526 | 526 | |
527 | - if ( function_exists( 'mb_convert_encoding' ) ) { |
|
528 | - return mb_convert_encoding( $bodyWithoutUnprocessableTags, 'HTML-ENTITIES', self::ENCODING ); |
|
527 | + if (function_exists('mb_convert_encoding')) { |
|
528 | + return mb_convert_encoding($bodyWithoutUnprocessableTags, 'HTML-ENTITIES', self::ENCODING); |
|
529 | 529 | } else { |
530 | - return htmlspecialchars_decode( utf8_decode( htmlentities( $bodyWithoutUnprocessableTags, ENT_COMPAT, self::ENCODING, false ) ) ); |
|
530 | + return htmlspecialchars_decode(utf8_decode(htmlentities($bodyWithoutUnprocessableTags, ENT_COMPAT, self::ENCODING, false))); |
|
531 | 531 | } |
532 | 532 | } |
533 | 533 | |
@@ -562,7 +562,7 @@ discard block |
||
562 | 562 | $precedence = 0; |
563 | 563 | $value = 100; |
564 | 564 | // ids: worth 100, classes: worth 10, elements: worth 1 |
565 | - $search = array('\\#','\\.',''); |
|
565 | + $search = array('\\#', '\\.', ''); |
|
566 | 566 | |
567 | 567 | foreach ($search as $s) { |
568 | 568 | if (trim($selector == '')) { |
@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | */ |
591 | 591 | private function translateCssToXpath($paramCssSelector) { |
592 | 592 | $cssSelector = ' ' . $paramCssSelector . ' '; |
593 | - $cssSelector = preg_replace_callback( '/\s+\w+\s+/', array( $this, 'strtolower' ), $cssSelector ); |
|
593 | + $cssSelector = preg_replace_callback('/\s+\w+\s+/', array($this, 'strtolower'), $cssSelector); |
|
594 | 594 | $cssSelector = trim($cssSelector); |
595 | 595 | $xpathKey = md5($cssSelector); |
596 | 596 | if (!isset($this->caches[self::CACHE_KEY_XPATH][$xpathKey])) { |
@@ -713,7 +713,7 @@ discard block |
||
713 | 713 | * @return array |
714 | 714 | */ |
715 | 715 | private function parseNth(array $match) { |
716 | - if (in_array(strtolower($match[2]), array('even','odd'))) { |
|
716 | + if (in_array(strtolower($match[2]), array('even', 'odd'))) { |
|
717 | 717 | $index = strtolower($match[2]) == 'even' ? 0 : 1; |
718 | 718 | return array(self::MULTIPLIER => 2, self::INDEX => $index); |
719 | 719 | } elseif (stripos($match[2], 'n') === false) { |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly. |
3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | 5 | class WPInv_EUVat { |
6 | 6 | private static $is_ajax = false; |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | private static $instance = false; |
9 | 9 | |
10 | 10 | public static function get_instance() { |
11 | - if ( !self::$instance ) { |
|
11 | + if (!self::$instance) { |
|
12 | 12 | self::$instance = new self(); |
13 | 13 | self::$instance->actions(); |
14 | 14 | } |
@@ -17,126 +17,126 @@ discard block |
||
17 | 17 | } |
18 | 18 | |
19 | 19 | public function __construct() { |
20 | - self::$is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
20 | + self::$is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
21 | 21 | self::$default_country = wpinv_get_default_country(); |
22 | 22 | } |
23 | 23 | |
24 | 24 | public static function actions() { |
25 | - if ( is_admin() ) { |
|
26 | - add_action( 'admin_enqueue_scripts', array( self::$instance, 'enqueue_admin_scripts' ) ); |
|
27 | - add_action( 'wpinv_settings_sections_taxes', array( self::$instance, 'section_vat_settings' ) ); |
|
28 | - add_action( 'wpinv_settings_taxes', array( self::$instance, 'vat_settings' ) ); |
|
29 | - add_filter( 'wpinv_settings_taxes-vat_sanitize', array( self::$instance, 'sanitize_vat_settings' ) ); |
|
30 | - add_filter( 'wpinv_settings_taxes-vat_rates_sanitize', array( self::$instance, 'sanitize_vat_rates' ) ); |
|
31 | - add_action( 'wp_ajax_wpinv_add_vat_class', array( self::$instance, 'add_class' ) ); |
|
32 | - add_action( 'wp_ajax_nopriv_wpinv_add_vat_class', array( self::$instance, 'add_class' ) ); |
|
33 | - add_action( 'wp_ajax_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) ); |
|
34 | - add_action( 'wp_ajax_nopriv_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) ); |
|
35 | - add_action( 'wp_ajax_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) ); |
|
36 | - add_action( 'wp_ajax_nopriv_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) ); |
|
37 | - add_action( 'wp_ajax_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) ); |
|
38 | - add_action( 'wp_ajax_nopriv_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) ); |
|
39 | - } |
|
40 | - |
|
41 | - add_action( 'wp_enqueue_scripts', array( self::$instance, 'enqueue_vat_scripts' ) ); |
|
42 | - add_filter( 'wpinv_default_billing_country', array( self::$instance, 'get_user_country' ), 10 ); |
|
43 | - add_filter( 'wpinv_get_user_country', array( self::$instance, 'set_user_country' ), 10 ); |
|
44 | - add_filter( 'wpinv_tax_rate', array( self::$instance, 'get_rate' ), 10, 4 ); |
|
45 | - add_action( 'wp_ajax_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) ); |
|
46 | - add_action( 'wp_ajax_nopriv_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) ); |
|
47 | - add_action( 'wp_ajax_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) ); |
|
48 | - add_action( 'wp_ajax_nopriv_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) ); |
|
49 | - add_action( 'wpinv_checkout_error_checks', array( self::$instance, 'checkout_vat_validate' ), 10, 2 ); |
|
50 | - add_action( 'wpinv_after_billing_fields', array( self::$instance, 'checkout_vat_fields' ) ); |
|
51 | - add_action( 'wpinv_invoice_print_after_line_items', array( self::$instance, 'show_vat_notice' ), 999, 1 ); |
|
25 | + if (is_admin()) { |
|
26 | + add_action('admin_enqueue_scripts', array(self::$instance, 'enqueue_admin_scripts')); |
|
27 | + add_action('wpinv_settings_sections_taxes', array(self::$instance, 'section_vat_settings')); |
|
28 | + add_action('wpinv_settings_taxes', array(self::$instance, 'vat_settings')); |
|
29 | + add_filter('wpinv_settings_taxes-vat_sanitize', array(self::$instance, 'sanitize_vat_settings')); |
|
30 | + add_filter('wpinv_settings_taxes-vat_rates_sanitize', array(self::$instance, 'sanitize_vat_rates')); |
|
31 | + add_action('wp_ajax_wpinv_add_vat_class', array(self::$instance, 'add_class')); |
|
32 | + add_action('wp_ajax_nopriv_wpinv_add_vat_class', array(self::$instance, 'add_class')); |
|
33 | + add_action('wp_ajax_wpinv_delete_vat_class', array(self::$instance, 'delete_class')); |
|
34 | + add_action('wp_ajax_nopriv_wpinv_delete_vat_class', array(self::$instance, 'delete_class')); |
|
35 | + add_action('wp_ajax_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates')); |
|
36 | + add_action('wp_ajax_nopriv_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates')); |
|
37 | + add_action('wp_ajax_wpinv_geoip2', array(self::$instance, 'geoip2_download_database')); |
|
38 | + add_action('wp_ajax_nopriv_wpinv_geoip2', array(self::$instance, 'geoip2_download_database')); |
|
39 | + } |
|
40 | + |
|
41 | + add_action('wp_enqueue_scripts', array(self::$instance, 'enqueue_vat_scripts')); |
|
42 | + add_filter('wpinv_default_billing_country', array(self::$instance, 'get_user_country'), 10); |
|
43 | + add_filter('wpinv_get_user_country', array(self::$instance, 'set_user_country'), 10); |
|
44 | + add_filter('wpinv_tax_rate', array(self::$instance, 'get_rate'), 10, 4); |
|
45 | + add_action('wp_ajax_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate')); |
|
46 | + add_action('wp_ajax_nopriv_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate')); |
|
47 | + add_action('wp_ajax_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset')); |
|
48 | + add_action('wp_ajax_nopriv_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset')); |
|
49 | + add_action('wpinv_checkout_error_checks', array(self::$instance, 'checkout_vat_validate'), 10, 2); |
|
50 | + add_action('wpinv_after_billing_fields', array(self::$instance, 'checkout_vat_fields')); |
|
51 | + add_action('wpinv_invoice_print_after_line_items', array(self::$instance, 'show_vat_notice'), 999, 1); |
|
52 | 52 | } |
53 | 53 | |
54 | - public static function get_eu_states( $sort = true ) { |
|
55 | - $eu_states = array( 'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE' ); |
|
56 | - if ( $sort ) { |
|
57 | - $sort = sort( $eu_states ); |
|
54 | + public static function get_eu_states($sort = true) { |
|
55 | + $eu_states = array('AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE'); |
|
56 | + if ($sort) { |
|
57 | + $sort = sort($eu_states); |
|
58 | 58 | } |
59 | 59 | |
60 | - return apply_filters( 'wpinv_get_eu_states', $eu_states, $sort ); |
|
60 | + return apply_filters('wpinv_get_eu_states', $eu_states, $sort); |
|
61 | 61 | } |
62 | 62 | |
63 | - public static function get_gst_countries( $sort = true ) { |
|
64 | - $gst_countries = array( 'AU', 'NZ', 'CA', 'CN' ); |
|
63 | + public static function get_gst_countries($sort = true) { |
|
64 | + $gst_countries = array('AU', 'NZ', 'CA', 'CN'); |
|
65 | 65 | |
66 | - if ( $sort ) { |
|
67 | - $sort = sort( $gst_countries ); |
|
66 | + if ($sort) { |
|
67 | + $sort = sort($gst_countries); |
|
68 | 68 | } |
69 | 69 | |
70 | - return apply_filters( 'wpinv_get_gst_countries', $gst_countries, $sort ); |
|
70 | + return apply_filters('wpinv_get_gst_countries', $gst_countries, $sort); |
|
71 | 71 | } |
72 | 72 | |
73 | - public static function is_eu_state( $country_code ) { |
|
74 | - $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_eu_states() ) ? true : false; |
|
73 | + public static function is_eu_state($country_code) { |
|
74 | + $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_eu_states()) ? true : false; |
|
75 | 75 | |
76 | - return apply_filters( 'wpinv_is_eu_state', $return, $country_code ); |
|
76 | + return apply_filters('wpinv_is_eu_state', $return, $country_code); |
|
77 | 77 | } |
78 | 78 | |
79 | - public static function is_gst_country( $country_code ) { |
|
80 | - $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_gst_countries() ) ? true : false; |
|
79 | + public static function is_gst_country($country_code) { |
|
80 | + $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_gst_countries()) ? true : false; |
|
81 | 81 | |
82 | - return apply_filters( 'wpinv_is_gst_country', $return, $country_code ); |
|
82 | + return apply_filters('wpinv_is_gst_country', $return, $country_code); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | public static function enqueue_vat_scripts() { |
86 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
86 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
87 | 87 | |
88 | - wp_register_script( 'wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
89 | - wp_register_script( 'wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
88 | + wp_register_script('wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
89 | + wp_register_script('wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
90 | 90 | |
91 | - $vat_name = self::get_vat_name(); |
|
91 | + $vat_name = self::get_vat_name(); |
|
92 | 92 | |
93 | 93 | $vars = array(); |
94 | 94 | $vars['EUStates'] = self::get_eu_states(); |
95 | - $vars['NoRateSet'] = __( 'You have not set a rate. Do you want to continue?', 'invoicing' ); |
|
96 | - $vars['EmptyCompany'] = __( 'Please enter your registered company name!', 'invoicing' ); |
|
97 | - $vars['EmptyVAT'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name ); |
|
98 | - $vars['TotalsRefreshed'] = wp_sprintf( __( 'The invoice totals will be refreshed to update the %s.', 'invoicing' ), $vat_name ); |
|
99 | - $vars['ErrValidateVAT'] = wp_sprintf( __( 'Fail to validate the %s number!', 'invoicing' ), $vat_name ); |
|
100 | - $vars['ErrResetVAT'] = wp_sprintf( __( 'Fail to reset the %s number!', 'invoicing' ), $vat_name ); |
|
101 | - $vars['ErrInvalidVat'] = wp_sprintf( __( 'The %s number supplied does not have a valid format!', 'invoicing' ), $vat_name ); |
|
102 | - $vars['ErrInvalidResponse'] = __( 'An invalid response has been received from the server!', 'invoicing' ); |
|
95 | + $vars['NoRateSet'] = __('You have not set a rate. Do you want to continue?', 'invoicing'); |
|
96 | + $vars['EmptyCompany'] = __('Please enter your registered company name!', 'invoicing'); |
|
97 | + $vars['EmptyVAT'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name); |
|
98 | + $vars['TotalsRefreshed'] = wp_sprintf(__('The invoice totals will be refreshed to update the %s.', 'invoicing'), $vat_name); |
|
99 | + $vars['ErrValidateVAT'] = wp_sprintf(__('Fail to validate the %s number!', 'invoicing'), $vat_name); |
|
100 | + $vars['ErrResetVAT'] = wp_sprintf(__('Fail to reset the %s number!', 'invoicing'), $vat_name); |
|
101 | + $vars['ErrInvalidVat'] = wp_sprintf(__('The %s number supplied does not have a valid format!', 'invoicing'), $vat_name); |
|
102 | + $vars['ErrInvalidResponse'] = __('An invalid response has been received from the server!', 'invoicing'); |
|
103 | 103 | $vars['ApplyVATRules'] = self::allow_vat_rules(); |
104 | - $vars['ErrResponse'] = __( 'The request response is invalid!', 'invoicing' ); |
|
105 | - $vars['ErrRateResponse'] = __( 'The get rate request response is invalid', 'invoicing' ); |
|
106 | - $vars['PageRefresh'] = __( 'The page will be refreshed in 10 seconds to show the new options.', 'invoicing' ); |
|
107 | - $vars['RequestResponseNotValidJSON'] = __( 'The get rate request response is not valid JSON', 'invoicing' ); |
|
108 | - $vars['GetRateRequestFailed'] = __( 'The get rate request failed: ', 'invoicing' ); |
|
109 | - $vars['NoRateInformationInResponse'] = __( 'The get rate request response does not contain any rate information', 'invoicing' ); |
|
110 | - $vars['RatesUpdated'] = __( 'The rates have been updated. Press the save button to record these new rates.', 'invoicing' ); |
|
111 | - $vars['IPAddressInformation'] = __( 'IP Address Information', 'invoicing' ); |
|
112 | - $vars['VatValidating'] = wp_sprintf( __( 'Validating %s number...', 'invoicing' ), $vat_name ); |
|
113 | - $vars['VatReseting'] = __( 'Reseting...', 'invoicing' ); |
|
114 | - $vars['VatValidated'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
115 | - $vars['VatNotValidated'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
116 | - $vars['ConfirmDeleteClass'] = __( 'Are you sure you wish to delete this rates class?', 'invoicing' ); |
|
104 | + $vars['ErrResponse'] = __('The request response is invalid!', 'invoicing'); |
|
105 | + $vars['ErrRateResponse'] = __('The get rate request response is invalid', 'invoicing'); |
|
106 | + $vars['PageRefresh'] = __('The page will be refreshed in 10 seconds to show the new options.', 'invoicing'); |
|
107 | + $vars['RequestResponseNotValidJSON'] = __('The get rate request response is not valid JSON', 'invoicing'); |
|
108 | + $vars['GetRateRequestFailed'] = __('The get rate request failed: ', 'invoicing'); |
|
109 | + $vars['NoRateInformationInResponse'] = __('The get rate request response does not contain any rate information', 'invoicing'); |
|
110 | + $vars['RatesUpdated'] = __('The rates have been updated. Press the save button to record these new rates.', 'invoicing'); |
|
111 | + $vars['IPAddressInformation'] = __('IP Address Information', 'invoicing'); |
|
112 | + $vars['VatValidating'] = wp_sprintf(__('Validating %s number...', 'invoicing'), $vat_name); |
|
113 | + $vars['VatReseting'] = __('Reseting...', 'invoicing'); |
|
114 | + $vars['VatValidated'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
115 | + $vars['VatNotValidated'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
116 | + $vars['ConfirmDeleteClass'] = __('Are you sure you wish to delete this rates class?', 'invoicing'); |
|
117 | 117 | $vars['isFront'] = is_admin() ? false : true; |
118 | - $vars['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
118 | + $vars['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce'); |
|
119 | 119 | $vars['baseCountry'] = wpinv_get_default_country(); |
120 | - $vars['disableVATSameCountry'] = ( self::same_country_rule() == 'no' ? true : false ); |
|
121 | - $vars['disableVATSimpleCheck'] = wpinv_get_option( 'vat_offline_check' ) ? true : false; |
|
120 | + $vars['disableVATSameCountry'] = (self::same_country_rule() == 'no' ? true : false); |
|
121 | + $vars['disableVATSimpleCheck'] = wpinv_get_option('vat_offline_check') ? true : false; |
|
122 | 122 | |
123 | - wp_enqueue_script( 'wpinv-vat-validation-script' ); |
|
124 | - wp_enqueue_script( 'wpinv-vat-script' ); |
|
125 | - wp_localize_script( 'wpinv-vat-script', 'WPInv_VAT_Vars', $vars ); |
|
123 | + wp_enqueue_script('wpinv-vat-validation-script'); |
|
124 | + wp_enqueue_script('wpinv-vat-script'); |
|
125 | + wp_localize_script('wpinv-vat-script', 'WPInv_VAT_Vars', $vars); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | public static function enqueue_admin_scripts() { |
129 | - if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) { |
|
129 | + if (isset($_GET['page']) && 'wpinv-settings' == $_GET['page']) { |
|
130 | 130 | self::enqueue_vat_scripts(); |
131 | 131 | } |
132 | 132 | } |
133 | 133 | |
134 | - public static function section_vat_settings( $sections ) { |
|
135 | - if ( !empty( $sections ) ) { |
|
136 | - $sections['vat'] = __( 'EU VAT Settings', 'invoicing' ); |
|
134 | + public static function section_vat_settings($sections) { |
|
135 | + if (!empty($sections)) { |
|
136 | + $sections['vat'] = __('EU VAT Settings', 'invoicing'); |
|
137 | 137 | |
138 | - if ( self::allow_vat_classes() ) { |
|
139 | - $sections['vat_rates'] = __( 'EU VAT Rates', 'invoicing' ); |
|
138 | + if (self::allow_vat_classes()) { |
|
139 | + $sections['vat_rates'] = __('EU VAT Rates', 'invoicing'); |
|
140 | 140 | } |
141 | 141 | } |
142 | 142 | return $sections; |
@@ -145,52 +145,52 @@ discard block |
||
145 | 145 | public static function vat_rates_settings() { |
146 | 146 | $vat_classes = self::get_rate_classes(); |
147 | 147 | $vat_rates = array(); |
148 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_new'; |
|
149 | - $current_url = remove_query_arg( 'wpi_sub' ); |
|
148 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_new'; |
|
149 | + $current_url = remove_query_arg('wpi_sub'); |
|
150 | 150 | |
151 | 151 | $vat_rates['vat_rates_header'] = array( |
152 | 152 | 'id' => 'vat_rates_header', |
153 | - 'name' => '<h3>' . __( 'Manage VAT Rates', 'invoicing' ) . '</h3>', |
|
153 | + 'name' => '<h3>' . __('Manage VAT Rates', 'invoicing') . '</h3>', |
|
154 | 154 | 'desc' => '', |
155 | 155 | 'type' => 'header', |
156 | 156 | 'size' => 'regular' |
157 | 157 | ); |
158 | 158 | $vat_rates['vat_rates_class'] = array( |
159 | 159 | 'id' => 'vat_rates_class', |
160 | - 'name' => __( 'Edit VAT Rates', 'invoicing' ), |
|
161 | - 'desc' => __( 'The standard rate will apply where no explicit rate is provided.', 'invoicing' ), |
|
160 | + 'name' => __('Edit VAT Rates', 'invoicing'), |
|
161 | + 'desc' => __('The standard rate will apply where no explicit rate is provided.', 'invoicing'), |
|
162 | 162 | 'type' => 'select', |
163 | - 'options' => array_merge( $vat_classes, array( '_new' => __( 'Add New Rate Class', 'invoicing' ) ) ), |
|
163 | + 'options' => array_merge($vat_classes, array('_new' => __('Add New Rate Class', 'invoicing'))), |
|
164 | 164 | 'chosen' => true, |
165 | - 'placeholder' => __( 'Select a VAT Rate', 'invoicing' ), |
|
165 | + 'placeholder' => __('Select a VAT Rate', 'invoicing'), |
|
166 | 166 | 'selected' => $vat_class, |
167 | 167 | 'onchange' => 'document.location.href="' . $current_url . '&wpi_sub=" + this.value;', |
168 | 168 | ); |
169 | 169 | |
170 | - if ( $vat_class != '_standard' && $vat_class != '_new' ) { |
|
170 | + if ($vat_class != '_standard' && $vat_class != '_new') { |
|
171 | 171 | $vat_rates['vat_rate_delete'] = array( |
172 | 172 | 'id' => 'vat_rate_delete', |
173 | 173 | 'type' => 'vat_rate_delete', |
174 | 174 | ); |
175 | 175 | } |
176 | 176 | |
177 | - if ( $vat_class == '_new' ) { |
|
177 | + if ($vat_class == '_new') { |
|
178 | 178 | $vat_rates['vat_rates_settings'] = array( |
179 | 179 | 'id' => 'vat_rates_settings', |
180 | - 'name' => '<h3>' . __( 'Add New Rate Class', 'invoicing' ) . '</h3>', |
|
180 | + 'name' => '<h3>' . __('Add New Rate Class', 'invoicing') . '</h3>', |
|
181 | 181 | 'type' => 'header', |
182 | 182 | ); |
183 | 183 | $vat_rates['vat_rate_name'] = array( |
184 | 184 | 'id' => 'vat_rate_name', |
185 | - 'name' => __( 'Name', 'invoicing' ), |
|
186 | - 'desc' => __( 'A short name for the new VAT Rate class', 'invoicing' ), |
|
185 | + 'name' => __('Name', 'invoicing'), |
|
186 | + 'desc' => __('A short name for the new VAT Rate class', 'invoicing'), |
|
187 | 187 | 'type' => 'text', |
188 | 188 | 'size' => 'regular', |
189 | 189 | ); |
190 | 190 | $vat_rates['vat_rate_desc'] = array( |
191 | 191 | 'id' => 'vat_rate_desc', |
192 | - 'name' => __( 'Description', 'invoicing' ), |
|
193 | - 'desc' => __( 'Manage VAT Rate class', 'invoicing' ), |
|
192 | + 'name' => __('Description', 'invoicing'), |
|
193 | + 'desc' => __('Manage VAT Rate class', 'invoicing'), |
|
194 | 194 | 'type' => 'text', |
195 | 195 | 'size' => 'regular', |
196 | 196 | ); |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | $vat_rates['vat_rates'] = array( |
203 | 203 | 'id' => 'vat_rates', |
204 | 204 | 'name' => '<h3>' . $vat_classes[$vat_class] . '</h3>', |
205 | - 'desc' => self::get_class_desc( $vat_class ), |
|
205 | + 'desc' => self::get_class_desc($vat_class), |
|
206 | 206 | 'type' => 'vat_rates', |
207 | 207 | ); |
208 | 208 | } |
@@ -210,12 +210,12 @@ discard block |
||
210 | 210 | return $vat_rates; |
211 | 211 | } |
212 | 212 | |
213 | - public static function vat_settings( $settings ) { |
|
214 | - if ( !empty( $settings ) ) { |
|
213 | + public static function vat_settings($settings) { |
|
214 | + if (!empty($settings)) { |
|
215 | 215 | $vat_settings = array(); |
216 | 216 | $vat_settings['vat_company_title'] = array( |
217 | 217 | 'id' => 'vat_company_title', |
218 | - 'name' => '<h3>' . __( 'Your Company Details', 'invoicing' ) . '</h3>', |
|
218 | + 'name' => '<h3>' . __('Your Company Details', 'invoicing') . '</h3>', |
|
219 | 219 | 'desc' => '', |
220 | 220 | 'type' => 'header', |
221 | 221 | 'size' => 'regular' |
@@ -223,22 +223,22 @@ discard block |
||
223 | 223 | |
224 | 224 | $vat_settings['vat_company_name'] = array( |
225 | 225 | 'id' => 'vat_company_name', |
226 | - 'name' => __( 'Your Company Name', 'invoicing' ), |
|
227 | - 'desc' => wp_sprintf(__( 'Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ), |
|
226 | + 'name' => __('Your Company Name', 'invoicing'), |
|
227 | + 'desc' => wp_sprintf(__('Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'), |
|
228 | 228 | 'type' => 'text', |
229 | 229 | 'size' => 'regular', |
230 | 230 | ); |
231 | 231 | |
232 | 232 | $vat_settings['vat_number'] = array( |
233 | 233 | 'id' => 'vat_number', |
234 | - 'name' => __( 'Your VAT Number', 'invoicing' ), |
|
234 | + 'name' => __('Your VAT Number', 'invoicing'), |
|
235 | 235 | 'type' => 'vat_number', |
236 | 236 | 'size' => 'regular', |
237 | 237 | ); |
238 | 238 | |
239 | 239 | $vat_settings['vat_settings_title'] = array( |
240 | 240 | 'id' => 'vat_settings_title', |
241 | - 'name' => '<h3>' . __( 'Apply VAT Settings', 'invoicing' ) . '</h3>', |
|
241 | + 'name' => '<h3>' . __('Apply VAT Settings', 'invoicing') . '</h3>', |
|
242 | 242 | 'desc' => '', |
243 | 243 | 'type' => 'header', |
244 | 244 | 'size' => 'regular' |
@@ -246,8 +246,8 @@ discard block |
||
246 | 246 | |
247 | 247 | $vat_settings['apply_vat_rules'] = array( |
248 | 248 | 'id' => 'apply_vat_rules', |
249 | - 'name' => __( 'Enable VAT rules', 'invoicing' ), |
|
250 | - 'desc' => __( 'Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable unless you know what you are doing.', 'invoicing' ) . '</font>', |
|
249 | + 'name' => __('Enable VAT rules', 'invoicing'), |
|
250 | + 'desc' => __('Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable unless you know what you are doing.', 'invoicing') . '</font>', |
|
251 | 251 | 'type' => 'checkbox', |
252 | 252 | 'std' => '1' |
253 | 253 | ); |
@@ -263,8 +263,8 @@ discard block |
||
263 | 263 | |
264 | 264 | $vat_settings['vat_prevent_b2c_purchase'] = array( |
265 | 265 | 'id' => 'vat_prevent_b2c_purchase', |
266 | - 'name' => __( 'Prevent EU B2C sales', 'invoicing' ), |
|
267 | - 'desc' => __( 'Enable this option if you are not registered for VAT in the EU.', 'invoicing' ), |
|
266 | + 'name' => __('Prevent EU B2C sales', 'invoicing'), |
|
267 | + 'desc' => __('Enable this option if you are not registered for VAT in the EU.', 'invoicing'), |
|
268 | 268 | 'type' => 'checkbox' |
269 | 269 | ); |
270 | 270 | |
@@ -272,21 +272,21 @@ discard block |
||
272 | 272 | |
273 | 273 | $vat_settings['vat_same_country_rule'] = array( |
274 | 274 | 'id' => 'vat_same_country_rule', |
275 | - 'name' => __( 'Same country rule', 'invoicing' ), |
|
276 | - 'desc' => __( 'Select how you want handle VAT charge if sales are in the same country as the base country.', 'invoicing' ), |
|
275 | + 'name' => __('Same country rule', 'invoicing'), |
|
276 | + 'desc' => __('Select how you want handle VAT charge if sales are in the same country as the base country.', 'invoicing'), |
|
277 | 277 | 'type' => 'select', |
278 | 278 | 'options' => array( |
279 | - '' => __( 'Normal', 'invoicing' ), |
|
280 | - 'no' => __( 'No VAT', 'invoicing' ), |
|
281 | - 'always' => __( 'Always apply VAT', 'invoicing' ), |
|
279 | + '' => __('Normal', 'invoicing'), |
|
280 | + 'no' => __('No VAT', 'invoicing'), |
|
281 | + 'always' => __('Always apply VAT', 'invoicing'), |
|
282 | 282 | ), |
283 | - 'placeholder' => __( 'Select a option', 'invoicing' ), |
|
283 | + 'placeholder' => __('Select a option', 'invoicing'), |
|
284 | 284 | 'std' => '' |
285 | 285 | ); |
286 | 286 | |
287 | 287 | $vat_settings['vat_checkout_title'] = array( |
288 | 288 | 'id' => 'vat_checkout_title', |
289 | - 'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>', |
|
289 | + 'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>', |
|
290 | 290 | 'desc' => '', |
291 | 291 | 'type' => 'header', |
292 | 292 | 'size' => 'regular' |
@@ -294,14 +294,14 @@ discard block |
||
294 | 294 | |
295 | 295 | $vat_settings['vat_disable_fields'] = array( |
296 | 296 | 'id' => 'vat_disable_fields', |
297 | - 'name' => __( 'Disable VAT fields', 'invoicing' ), |
|
298 | - 'desc' => __( 'Disable VAT fields if Invoicing is being used for GST.', 'invoicing' ), |
|
297 | + 'name' => __('Disable VAT fields', 'invoicing'), |
|
298 | + 'desc' => __('Disable VAT fields if Invoicing is being used for GST.', 'invoicing'), |
|
299 | 299 | 'type' => 'checkbox' |
300 | 300 | ); |
301 | 301 | |
302 | 302 | $vat_settings['vat_ip_lookup'] = array( |
303 | 303 | 'id' => 'vat_ip_lookup', |
304 | - 'name' => __( 'IP Country lookup', 'invoicing' ), |
|
304 | + 'name' => __('IP Country lookup', 'invoicing'), |
|
305 | 305 | 'type' => 'vat_ip_lookup', |
306 | 306 | 'size' => 'regular', |
307 | 307 | 'std' => 'default' |
@@ -309,21 +309,21 @@ discard block |
||
309 | 309 | |
310 | 310 | $vat_settings['hide_ip_address'] = array( |
311 | 311 | 'id' => 'hide_ip_address', |
312 | - 'name' => __( 'Hide IP info at checkout', 'invoicing' ), |
|
313 | - 'desc' => __( 'Hide the user IP info at checkout.', 'invoicing' ), |
|
312 | + 'name' => __('Hide IP info at checkout', 'invoicing'), |
|
313 | + 'desc' => __('Hide the user IP info at checkout.', 'invoicing'), |
|
314 | 314 | 'type' => 'checkbox' |
315 | 315 | ); |
316 | 316 | |
317 | 317 | $vat_settings['vat_ip_country_default'] = array( |
318 | 318 | 'id' => 'vat_ip_country_default', |
319 | - 'name' => __( 'Enable IP Country as Default', 'invoicing' ), |
|
320 | - 'desc' => __( 'Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing' ), |
|
319 | + 'name' => __('Enable IP Country as Default', 'invoicing'), |
|
320 | + 'desc' => __('Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing'), |
|
321 | 321 | 'type' => 'checkbox' |
322 | 322 | ); |
323 | 323 | |
324 | 324 | $vat_settings['vies_validation_title'] = array( |
325 | 325 | 'id' => 'vies_validation_title', |
326 | - 'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>', |
|
326 | + 'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>', |
|
327 | 327 | 'desc' => '', |
328 | 328 | 'type' => 'header', |
329 | 329 | 'size' => 'regular' |
@@ -331,37 +331,37 @@ discard block |
||
331 | 331 | |
332 | 332 | $vat_settings['vat_vies_check'] = array( |
333 | 333 | 'id' => 'vat_vies_check', |
334 | - 'name' => __( 'Disable VIES VAT ID check', 'invoicing' ), |
|
335 | - 'desc' => wp_sprintf( __( 'Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ), |
|
334 | + 'name' => __('Disable VIES VAT ID check', 'invoicing'), |
|
335 | + 'desc' => wp_sprintf(__('Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'), |
|
336 | 336 | 'type' => 'checkbox' |
337 | 337 | ); |
338 | 338 | |
339 | 339 | $vat_settings['vat_disable_company_name_check'] = array( |
340 | 340 | 'id' => 'vat_disable_company_name_check', |
341 | - 'name' => __( 'Disable VIES name check', 'invoicing' ), |
|
342 | - 'desc' => wp_sprintf( __( 'Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ), |
|
341 | + 'name' => __('Disable VIES name check', 'invoicing'), |
|
342 | + 'desc' => wp_sprintf(__('Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'), |
|
343 | 343 | 'type' => 'checkbox' |
344 | 344 | ); |
345 | 345 | |
346 | 346 | $vat_settings['vat_offline_check'] = array( |
347 | 347 | 'id' => 'vat_offline_check', |
348 | - 'name' => __( 'Disable basic checks', 'invoicing' ), |
|
349 | - 'desc' => __( 'This will disable basic JS correct format validation attempts, it is very rare this should need to be disabled.', 'invoicing' ), |
|
348 | + 'name' => __('Disable basic checks', 'invoicing'), |
|
349 | + 'desc' => __('This will disable basic JS correct format validation attempts, it is very rare this should need to be disabled.', 'invoicing'), |
|
350 | 350 | 'type' => 'checkbox' |
351 | 351 | ); |
352 | 352 | |
353 | 353 | |
354 | 354 | $settings['vat'] = $vat_settings; |
355 | 355 | |
356 | - if ( self::allow_vat_classes() ) { |
|
356 | + if (self::allow_vat_classes()) { |
|
357 | 357 | $settings['vat_rates'] = self::vat_rates_settings(); |
358 | 358 | } |
359 | 359 | |
360 | 360 | $eu_fallback_rate = array( |
361 | 361 | 'id' => 'eu_fallback_rate', |
362 | - 'name' => '<h3>' . __( 'VAT rate for EU member states', 'invoicing' ) . '</h3>', |
|
362 | + 'name' => '<h3>' . __('VAT rate for EU member states', 'invoicing') . '</h3>', |
|
363 | 363 | 'type' => 'eu_fallback_rate', |
364 | - 'desc' => __( 'Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing' ), |
|
364 | + 'desc' => __('Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing'), |
|
365 | 365 | 'std' => '20', |
366 | 366 | 'size' => 'small' |
367 | 367 | ); |
@@ -377,11 +377,11 @@ discard block |
||
377 | 377 | $database_url = 'http' . (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === 'on' ? 's' : '') . '://geolite.maxmind.com/download/geoip/database/'; |
378 | 378 | $destination_dir = $upload_dir['basedir'] . '/invoicing'; |
379 | 379 | |
380 | - if ( !is_dir( $destination_dir ) ) { |
|
381 | - mkdir( $destination_dir ); |
|
380 | + if (!is_dir($destination_dir)) { |
|
381 | + mkdir($destination_dir); |
|
382 | 382 | } |
383 | 383 | |
384 | - $database_files = array( |
|
384 | + $database_files = array( |
|
385 | 385 | 'country' => array( |
386 | 386 | 'source' => $database_url . 'GeoLite2-Country.mmdb.gz', |
387 | 387 | 'destination' => $destination_dir . '/GeoLite2-Country.mmdb', |
@@ -392,57 +392,57 @@ discard block |
||
392 | 392 | ) |
393 | 393 | ); |
394 | 394 | |
395 | - foreach( $database_files as $database => $files ) { |
|
396 | - $result = self::geoip2_download_file( $files['source'], $files['destination'] ); |
|
395 | + foreach ($database_files as $database => $files) { |
|
396 | + $result = self::geoip2_download_file($files['source'], $files['destination']); |
|
397 | 397 | |
398 | - if ( empty( $result['success'] ) ) { |
|
398 | + if (empty($result['success'])) { |
|
399 | 399 | echo $result['message']; |
400 | 400 | exit; |
401 | 401 | } |
402 | 402 | |
403 | - wpinv_update_option( 'wpinv_geoip2_date_updated', current_time( 'timestamp' ) ); |
|
404 | - echo sprintf(__( 'GeoIp2 %s database updated successfully.', 'invoicing' ), $database ) . ' '; |
|
403 | + wpinv_update_option('wpinv_geoip2_date_updated', current_time('timestamp')); |
|
404 | + echo sprintf(__('GeoIp2 %s database updated successfully.', 'invoicing'), $database) . ' '; |
|
405 | 405 | } |
406 | 406 | |
407 | 407 | exit; |
408 | 408 | } |
409 | 409 | |
410 | - public static function geoip2_download_file( $source_url, $destination_file ) { |
|
410 | + public static function geoip2_download_file($source_url, $destination_file) { |
|
411 | 411 | $success = false; |
412 | 412 | $message = ''; |
413 | 413 | |
414 | - if ( !function_exists( 'download_url' ) ) { |
|
415 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
414 | + if (!function_exists('download_url')) { |
|
415 | + require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
416 | 416 | } |
417 | 417 | |
418 | - $temp_file = download_url( $source_url ); |
|
418 | + $temp_file = download_url($source_url); |
|
419 | 419 | |
420 | - if ( is_wp_error( $temp_file ) ) { |
|
421 | - $message = sprintf( __( 'Error while downloading GeoIp2 database( %s ): %s', 'invoicing' ), $source_url, $temp_file->get_error_message() ); |
|
420 | + if (is_wp_error($temp_file)) { |
|
421 | + $message = sprintf(__('Error while downloading GeoIp2 database( %s ): %s', 'invoicing'), $source_url, $temp_file->get_error_message()); |
|
422 | 422 | } else { |
423 | - $handle = gzopen( $temp_file, 'rb' ); |
|
423 | + $handle = gzopen($temp_file, 'rb'); |
|
424 | 424 | |
425 | - if ( $handle ) { |
|
426 | - $fopen = fopen( $destination_file, 'wb' ); |
|
427 | - if ( $fopen ) { |
|
428 | - while ( ( $data = gzread( $handle, 4096 ) ) != false ) { |
|
429 | - fwrite( $fopen, $data ); |
|
425 | + if ($handle) { |
|
426 | + $fopen = fopen($destination_file, 'wb'); |
|
427 | + if ($fopen) { |
|
428 | + while (($data = gzread($handle, 4096)) != false) { |
|
429 | + fwrite($fopen, $data); |
|
430 | 430 | } |
431 | 431 | |
432 | - gzclose( $handle ); |
|
433 | - fclose( $fopen ); |
|
432 | + gzclose($handle); |
|
433 | + fclose($fopen); |
|
434 | 434 | |
435 | 435 | $success = true; |
436 | 436 | } else { |
437 | - gzclose( $handle ); |
|
438 | - $message = sprintf( __( 'Error could not open destination GeoIp2 database file for writing: %s', 'invoicing' ), $destination_file ); |
|
437 | + gzclose($handle); |
|
438 | + $message = sprintf(__('Error could not open destination GeoIp2 database file for writing: %s', 'invoicing'), $destination_file); |
|
439 | 439 | } |
440 | 440 | } else { |
441 | - $message = sprintf( __( 'Error could not open GeoIp2 database file for reading: %s', 'invoicing' ), $temp_file ); |
|
441 | + $message = sprintf(__('Error could not open GeoIp2 database file for reading: %s', 'invoicing'), $temp_file); |
|
442 | 442 | } |
443 | 443 | |
444 | - if ( file_exists( $temp_file ) ) { |
|
445 | - unlink( $temp_file ); |
|
444 | + if (file_exists($temp_file)) { |
|
445 | + unlink($temp_file); |
|
446 | 446 | } |
447 | 447 | } |
448 | 448 | |
@@ -454,11 +454,11 @@ discard block |
||
454 | 454 | } |
455 | 455 | |
456 | 456 | public static function load_geoip2() { |
457 | - if ( defined( 'WPINV_GEOIP2_LODDED' ) ) { |
|
457 | + if (defined('WPINV_GEOIP2_LODDED')) { |
|
458 | 458 | return; |
459 | 459 | } |
460 | 460 | |
461 | - if ( !class_exists( '\MaxMind\Db\Reader' ) ) { |
|
461 | + if (!class_exists('\MaxMind\Db\Reader')) { |
|
462 | 462 | $maxmind_db_files = array( |
463 | 463 | 'Reader/Decoder.php', |
464 | 464 | 'Reader/InvalidDatabaseException.php', |
@@ -467,12 +467,12 @@ discard block |
||
467 | 467 | 'Reader.php', |
468 | 468 | ); |
469 | 469 | |
470 | - foreach ( $maxmind_db_files as $key => $file ) { |
|
471 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file ); |
|
470 | + foreach ($maxmind_db_files as $key => $file) { |
|
471 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file); |
|
472 | 472 | } |
473 | 473 | } |
474 | 474 | |
475 | - if ( !class_exists( '\GeoIp2\Database\Reader' ) ) { |
|
475 | + if (!class_exists('\GeoIp2\Database\Reader')) { |
|
476 | 476 | $geoip2_files = array( |
477 | 477 | 'ProviderInterface.php', |
478 | 478 | 'Compat/JsonSerializable.php', |
@@ -506,23 +506,23 @@ discard block |
||
506 | 506 | 'WebService/Client.php', |
507 | 507 | ); |
508 | 508 | |
509 | - foreach ( $geoip2_files as $key => $file ) { |
|
510 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file ); |
|
509 | + foreach ($geoip2_files as $key => $file) { |
|
510 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file); |
|
511 | 511 | } |
512 | 512 | } |
513 | 513 | |
514 | - define( 'WPINV_GEOIP2_LODDED', true ); |
|
514 | + define('WPINV_GEOIP2_LODDED', true); |
|
515 | 515 | } |
516 | 516 | |
517 | 517 | public static function geoip2_country_dbfile() { |
518 | 518 | $upload_dir = wp_upload_dir(); |
519 | 519 | |
520 | - if ( !isset( $upload_dir['basedir'] ) ) { |
|
520 | + if (!isset($upload_dir['basedir'])) { |
|
521 | 521 | return false; |
522 | 522 | } |
523 | 523 | |
524 | 524 | $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-Country.mmdb'; |
525 | - if ( !file_exists( $filename ) ) { |
|
525 | + if (!file_exists($filename)) { |
|
526 | 526 | return false; |
527 | 527 | } |
528 | 528 | |
@@ -532,12 +532,12 @@ discard block |
||
532 | 532 | public static function geoip2_city_dbfile() { |
533 | 533 | $upload_dir = wp_upload_dir(); |
534 | 534 | |
535 | - if ( !isset( $upload_dir['basedir'] ) ) { |
|
535 | + if (!isset($upload_dir['basedir'])) { |
|
536 | 536 | return false; |
537 | 537 | } |
538 | 538 | |
539 | 539 | $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-City.mmdb'; |
540 | - if ( !file_exists( $filename ) ) { |
|
540 | + if (!file_exists($filename)) { |
|
541 | 541 | return false; |
542 | 542 | } |
543 | 543 | |
@@ -548,10 +548,10 @@ discard block |
||
548 | 548 | try { |
549 | 549 | self::load_geoip2(); |
550 | 550 | |
551 | - if ( $filename = self::geoip2_country_dbfile() ) { |
|
552 | - return new \GeoIp2\Database\Reader( $filename ); |
|
551 | + if ($filename = self::geoip2_country_dbfile()) { |
|
552 | + return new \GeoIp2\Database\Reader($filename); |
|
553 | 553 | } |
554 | - } catch( Exception $e ) { |
|
554 | + } catch (Exception $e) { |
|
555 | 555 | return false; |
556 | 556 | } |
557 | 557 | |
@@ -562,173 +562,173 @@ discard block |
||
562 | 562 | try { |
563 | 563 | self::load_geoip2(); |
564 | 564 | |
565 | - if ( $filename = self::geoip2_city_dbfile() ) { |
|
566 | - return new \GeoIp2\Database\Reader( $filename ); |
|
565 | + if ($filename = self::geoip2_city_dbfile()) { |
|
566 | + return new \GeoIp2\Database\Reader($filename); |
|
567 | 567 | } |
568 | - } catch( Exception $e ) { |
|
568 | + } catch (Exception $e) { |
|
569 | 569 | return false; |
570 | 570 | } |
571 | 571 | |
572 | 572 | return false; |
573 | 573 | } |
574 | 574 | |
575 | - public static function geoip2_country_record( $ip_address ) { |
|
575 | + public static function geoip2_country_record($ip_address) { |
|
576 | 576 | try { |
577 | 577 | $reader = self::geoip2_country_reader(); |
578 | 578 | |
579 | - if ( $reader ) { |
|
580 | - $record = $reader->country( $ip_address ); |
|
579 | + if ($reader) { |
|
580 | + $record = $reader->country($ip_address); |
|
581 | 581 | |
582 | - if ( !empty( $record->country->isoCode ) ) { |
|
582 | + if (!empty($record->country->isoCode)) { |
|
583 | 583 | return $record; |
584 | 584 | } |
585 | 585 | } |
586 | - } catch(\InvalidArgumentException $e) { |
|
587 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
586 | + } catch (\InvalidArgumentException $e) { |
|
587 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
588 | 588 | |
589 | 589 | return false; |
590 | - } catch(\GeoIp2\Exception\AddressNotFoundException $e) { |
|
591 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
590 | + } catch (\GeoIp2\Exception\AddressNotFoundException $e) { |
|
591 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
592 | 592 | |
593 | 593 | return false; |
594 | - } catch( Exception $e ) { |
|
594 | + } catch (Exception $e) { |
|
595 | 595 | return false; |
596 | 596 | } |
597 | 597 | |
598 | 598 | return false; |
599 | 599 | } |
600 | 600 | |
601 | - public static function geoip2_city_record( $ip_address ) { |
|
601 | + public static function geoip2_city_record($ip_address) { |
|
602 | 602 | try { |
603 | 603 | $reader = self::geoip2_city_reader(); |
604 | 604 | |
605 | - if ( $reader ) { |
|
606 | - $record = $reader->city( $ip_address ); |
|
605 | + if ($reader) { |
|
606 | + $record = $reader->city($ip_address); |
|
607 | 607 | |
608 | - if ( !empty( $record->country->isoCode ) ) { |
|
608 | + if (!empty($record->country->isoCode)) { |
|
609 | 609 | return $record; |
610 | 610 | } |
611 | 611 | } |
612 | - } catch(\InvalidArgumentException $e) { |
|
613 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
612 | + } catch (\InvalidArgumentException $e) { |
|
613 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
614 | 614 | |
615 | 615 | return false; |
616 | - } catch(\GeoIp2\Exception\AddressNotFoundException $e) { |
|
617 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
616 | + } catch (\GeoIp2\Exception\AddressNotFoundException $e) { |
|
617 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
618 | 618 | |
619 | 619 | return false; |
620 | - } catch( Exception $e ) { |
|
620 | + } catch (Exception $e) { |
|
621 | 621 | return false; |
622 | 622 | } |
623 | 623 | |
624 | 624 | return false; |
625 | 625 | } |
626 | 626 | |
627 | - public static function geoip2_country_code( $ip_address ) { |
|
628 | - $record = self::geoip2_country_record( $ip_address ); |
|
629 | - return !empty( $record->country->isoCode ) ? $record->country->isoCode : wpinv_get_default_country(); |
|
627 | + public static function geoip2_country_code($ip_address) { |
|
628 | + $record = self::geoip2_country_record($ip_address); |
|
629 | + return !empty($record->country->isoCode) ? $record->country->isoCode : wpinv_get_default_country(); |
|
630 | 630 | } |
631 | 631 | |
632 | 632 | // Find country by IP address. |
633 | - public static function get_country_by_ip( $ip = '' ) { |
|
633 | + public static function get_country_by_ip($ip = '') { |
|
634 | 634 | global $wpinv_ip_address_country; |
635 | 635 | |
636 | - if ( !empty( $wpinv_ip_address_country ) ) { |
|
636 | + if (!empty($wpinv_ip_address_country)) { |
|
637 | 637 | return $wpinv_ip_address_country; |
638 | 638 | } |
639 | 639 | |
640 | - if ( empty( $ip ) ) { |
|
640 | + if (empty($ip)) { |
|
641 | 641 | $ip = wpinv_get_ip(); |
642 | 642 | } |
643 | 643 | |
644 | - $ip_country_service = wpinv_get_option( 'vat_ip_lookup' ); |
|
645 | - $is_default = empty( $ip_country_service ) || $ip_country_service === 'default' ? true : false; |
|
644 | + $ip_country_service = wpinv_get_option('vat_ip_lookup'); |
|
645 | + $is_default = empty($ip_country_service) || $ip_country_service === 'default' ? true : false; |
|
646 | 646 | |
647 | - if ( !empty( $ip ) && $ip !== '127.0.0.1' ) { // For 127.0.0.1(localhost) use default country. |
|
648 | - if ( function_exists( 'geoip_country_code_by_name') && ( $ip_country_service === 'geoip' || $is_default ) ) { |
|
647 | + if (!empty($ip) && $ip !== '127.0.0.1') { // For 127.0.0.1(localhost) use default country. |
|
648 | + if (function_exists('geoip_country_code_by_name') && ($ip_country_service === 'geoip' || $is_default)) { |
|
649 | 649 | try { |
650 | - $wpinv_ip_address_country = geoip_country_code_by_name( $ip ); |
|
651 | - } catch( Exception $e ) { |
|
652 | - wpinv_error_log( $e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )' ); |
|
650 | + $wpinv_ip_address_country = geoip_country_code_by_name($ip); |
|
651 | + } catch (Exception $e) { |
|
652 | + wpinv_error_log($e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )'); |
|
653 | 653 | } |
654 | - } else if ( self::geoip2_country_dbfile() && ( $ip_country_service === 'geoip2' || $is_default ) ) { |
|
655 | - $wpinv_ip_address_country = self::geoip2_country_code( $ip ); |
|
656 | - } else if ( function_exists( 'simplexml_load_file' ) && ( $ip_country_service === 'geoplugin' || $is_default ) ) { |
|
657 | - $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip ); |
|
654 | + } else if (self::geoip2_country_dbfile() && ($ip_country_service === 'geoip2' || $is_default)) { |
|
655 | + $wpinv_ip_address_country = self::geoip2_country_code($ip); |
|
656 | + } else if (function_exists('simplexml_load_file') && ($ip_country_service === 'geoplugin' || $is_default)) { |
|
657 | + $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip); |
|
658 | 658 | |
659 | - if ( !empty( $load_xml ) && !empty( $load_xml->geoplugin_countryCode ) ) { |
|
659 | + if (!empty($load_xml) && !empty($load_xml->geoplugin_countryCode)) { |
|
660 | 660 | $wpinv_ip_address_country = (string)$load_xml->geoplugin_countryCode; |
661 | 661 | } |
662 | 662 | } |
663 | 663 | } |
664 | 664 | |
665 | - if ( empty( $wpinv_ip_address_country ) ) { |
|
665 | + if (empty($wpinv_ip_address_country)) { |
|
666 | 666 | $wpinv_ip_address_country = wpinv_get_default_country(); |
667 | 667 | } |
668 | 668 | |
669 | 669 | return $wpinv_ip_address_country; |
670 | 670 | } |
671 | 671 | |
672 | - public static function sanitize_vat_settings( $input ) { |
|
672 | + public static function sanitize_vat_settings($input) { |
|
673 | 673 | global $wpinv_options; |
674 | 674 | |
675 | 675 | $valid = false; |
676 | 676 | $message = ''; |
677 | 677 | |
678 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
679 | - if ( empty( $wpinv_options['vat_offline_check'] ) ) { |
|
680 | - $valid = self::offline_check( $input['vat_number'] ); |
|
678 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
679 | + if (empty($wpinv_options['vat_offline_check'])) { |
|
680 | + $valid = self::offline_check($input['vat_number']); |
|
681 | 681 | } else { |
682 | 682 | $valid = true; |
683 | 683 | } |
684 | 684 | |
685 | - $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' ); |
|
685 | + $message = $valid ? '' : __('VAT number not validated', 'invoicing'); |
|
686 | 686 | } else { |
687 | - $result = self::check_vat( $input['vat_number'] ); |
|
687 | + $result = self::check_vat($input['vat_number']); |
|
688 | 688 | |
689 | - if ( empty( $result['valid'] ) ) { |
|
689 | + if (empty($result['valid'])) { |
|
690 | 690 | $valid = false; |
691 | 691 | $message = $result['message']; |
692 | 692 | } else { |
693 | - $valid = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] ); |
|
694 | - $message = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' ); |
|
693 | + $valid = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']); |
|
694 | + $message = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing'); |
|
695 | 695 | } |
696 | 696 | } |
697 | 697 | |
698 | - if ( $message && self::is_vat_validated() != $valid ) { |
|
699 | - add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) ); |
|
698 | + if ($message && self::is_vat_validated() != $valid) { |
|
699 | + add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error')); |
|
700 | 700 | } |
701 | 701 | |
702 | 702 | $input['vat_valid'] = $valid; |
703 | 703 | return $input; |
704 | 704 | } |
705 | 705 | |
706 | - public static function sanitize_vat_rates( $input ) { |
|
707 | - if( !current_user_can( 'manage_options' ) ) { |
|
708 | - add_settings_error( 'wpinv-notices', '', __( 'Your account does not have permission to add rate classes.', 'invoicing' ), 'error' ); |
|
706 | + public static function sanitize_vat_rates($input) { |
|
707 | + if (!current_user_can('manage_options')) { |
|
708 | + add_settings_error('wpinv-notices', '', __('Your account does not have permission to add rate classes.', 'invoicing'), 'error'); |
|
709 | 709 | return $input; |
710 | 710 | } |
711 | 711 | |
712 | 712 | $vat_classes = self::get_rate_classes(); |
713 | - $vat_class = !empty( $_REQUEST['wpi_vat_class'] ) && isset( $vat_classes[$_REQUEST['wpi_vat_class']] )? sanitize_text_field( $_REQUEST['wpi_vat_class'] ) : ''; |
|
713 | + $vat_class = !empty($_REQUEST['wpi_vat_class']) && isset($vat_classes[$_REQUEST['wpi_vat_class']]) ? sanitize_text_field($_REQUEST['wpi_vat_class']) : ''; |
|
714 | 714 | |
715 | - if ( empty( $vat_class ) ) { |
|
716 | - add_settings_error( 'wpinv-notices', '', __( 'No valid VAT rates class contained in the request to save rates.', 'invoicing' ), 'error' ); |
|
715 | + if (empty($vat_class)) { |
|
716 | + add_settings_error('wpinv-notices', '', __('No valid VAT rates class contained in the request to save rates.', 'invoicing'), 'error'); |
|
717 | 717 | |
718 | 718 | return $input; |
719 | 719 | } |
720 | 720 | |
721 | - $new_rates = ! empty( $_POST['vat_rates'] ) ? array_values( $_POST['vat_rates'] ) : array(); |
|
721 | + $new_rates = !empty($_POST['vat_rates']) ? array_values($_POST['vat_rates']) : array(); |
|
722 | 722 | |
723 | - if ( $vat_class === '_standard' ) { |
|
723 | + if ($vat_class === '_standard') { |
|
724 | 724 | // Save the active rates in the invoice settings |
725 | - update_option( 'wpinv_tax_rates', $new_rates ); |
|
725 | + update_option('wpinv_tax_rates', $new_rates); |
|
726 | 726 | } else { |
727 | 727 | // Get the existing set of rates |
728 | 728 | $rates = self::get_non_standard_rates(); |
729 | 729 | $rates[$vat_class] = $new_rates; |
730 | 730 | |
731 | - update_option( 'wpinv_vat_rates', $rates ); |
|
731 | + update_option('wpinv_vat_rates', $rates); |
|
732 | 732 | } |
733 | 733 | |
734 | 734 | return $input; |
@@ -738,71 +738,71 @@ discard block |
||
738 | 738 | $response = array(); |
739 | 739 | $response['success'] = false; |
740 | 740 | |
741 | - if ( !current_user_can( 'manage_options' ) ) { |
|
742 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
743 | - wp_send_json( $response ); |
|
741 | + if (!current_user_can('manage_options')) { |
|
742 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
743 | + wp_send_json($response); |
|
744 | 744 | } |
745 | 745 | |
746 | - $vat_class_name = !empty( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false; |
|
747 | - $vat_class_desc = !empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : false; |
|
746 | + $vat_class_name = !empty($_POST['name']) ? sanitize_text_field($_POST['name']) : false; |
|
747 | + $vat_class_desc = !empty($_POST['desc']) ? sanitize_text_field($_POST['desc']) : false; |
|
748 | 748 | |
749 | - if ( empty( $vat_class_name ) ) { |
|
750 | - $response['error'] = __( 'Select the VAT rate name', 'invoicing' ); |
|
751 | - wp_send_json( $response ); |
|
749 | + if (empty($vat_class_name)) { |
|
750 | + $response['error'] = __('Select the VAT rate name', 'invoicing'); |
|
751 | + wp_send_json($response); |
|
752 | 752 | } |
753 | 753 | |
754 | 754 | $vat_classes = (array)self::get_rate_classes(); |
755 | 755 | |
756 | - if ( !empty( $vat_classes ) && in_array( strtolower( $vat_class_name ), array_map( 'strtolower', array_values( $vat_classes ) ) ) ) { |
|
757 | - $response['error'] = wp_sprintf( __( 'A VAT Rate name "%s" already exists', 'invoicing' ), $vat_class_name ); |
|
758 | - wp_send_json( $response ); |
|
756 | + if (!empty($vat_classes) && in_array(strtolower($vat_class_name), array_map('strtolower', array_values($vat_classes)))) { |
|
757 | + $response['error'] = wp_sprintf(__('A VAT Rate name "%s" already exists', 'invoicing'), $vat_class_name); |
|
758 | + wp_send_json($response); |
|
759 | 759 | } |
760 | 760 | |
761 | - $rate_class_key = normalize_whitespace( 'wpi-' . $vat_class_name ); |
|
762 | - $rate_class_key = sanitize_key( str_replace( " ", "-", $rate_class_key ) ); |
|
761 | + $rate_class_key = normalize_whitespace('wpi-' . $vat_class_name); |
|
762 | + $rate_class_key = sanitize_key(str_replace(" ", "-", $rate_class_key)); |
|
763 | 763 | |
764 | - $vat_classes = (array)self::get_rate_classes( true ); |
|
765 | - $vat_classes[$rate_class_key] = array( 'name' => $vat_class_name, 'desc' => $vat_class_desc ); |
|
764 | + $vat_classes = (array)self::get_rate_classes(true); |
|
765 | + $vat_classes[$rate_class_key] = array('name' => $vat_class_name, 'desc' => $vat_class_desc); |
|
766 | 766 | |
767 | - update_option( '_wpinv_vat_rate_classes', $vat_classes ); |
|
767 | + update_option('_wpinv_vat_rate_classes', $vat_classes); |
|
768 | 768 | |
769 | 769 | $response['success'] = true; |
770 | - $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=' . $rate_class_key ); |
|
770 | + $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=' . $rate_class_key); |
|
771 | 771 | |
772 | - wp_send_json( $response ); |
|
772 | + wp_send_json($response); |
|
773 | 773 | } |
774 | 774 | |
775 | 775 | public static function delete_class() { |
776 | 776 | $response = array(); |
777 | 777 | $response['success'] = false; |
778 | 778 | |
779 | - if ( !current_user_can( 'manage_options' ) || !isset( $_POST['class'] ) ) { |
|
780 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
781 | - wp_send_json( $response ); |
|
779 | + if (!current_user_can('manage_options') || !isset($_POST['class'])) { |
|
780 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
781 | + wp_send_json($response); |
|
782 | 782 | } |
783 | 783 | |
784 | - $vat_class = isset( $_POST['class'] ) && $_POST['class'] !== '' ? sanitize_text_field( $_POST['class'] ) : false; |
|
784 | + $vat_class = isset($_POST['class']) && $_POST['class'] !== '' ? sanitize_text_field($_POST['class']) : false; |
|
785 | 785 | $vat_classes = (array)self::get_rate_classes(); |
786 | 786 | |
787 | - if ( !isset( $vat_classes[$vat_class] ) ) { |
|
788 | - $response['error'] = __( 'Requested class does not exists', 'invoicing' ); |
|
789 | - wp_send_json( $response ); |
|
787 | + if (!isset($vat_classes[$vat_class])) { |
|
788 | + $response['error'] = __('Requested class does not exists', 'invoicing'); |
|
789 | + wp_send_json($response); |
|
790 | 790 | } |
791 | 791 | |
792 | - if ( $vat_class == '_new' || $vat_class == '_standard' ) { |
|
793 | - $response['error'] = __( 'You can not delete standard rates class', 'invoicing' ); |
|
794 | - wp_send_json( $response ); |
|
792 | + if ($vat_class == '_new' || $vat_class == '_standard') { |
|
793 | + $response['error'] = __('You can not delete standard rates class', 'invoicing'); |
|
794 | + wp_send_json($response); |
|
795 | 795 | } |
796 | 796 | |
797 | - $vat_classes = (array)self::get_rate_classes( true ); |
|
798 | - unset( $vat_classes[$vat_class] ); |
|
797 | + $vat_classes = (array)self::get_rate_classes(true); |
|
798 | + unset($vat_classes[$vat_class]); |
|
799 | 799 | |
800 | - update_option( '_wpinv_vat_rate_classes', $vat_classes ); |
|
800 | + update_option('_wpinv_vat_rate_classes', $vat_classes); |
|
801 | 801 | |
802 | 802 | $response['success'] = true; |
803 | - $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=_new' ); |
|
803 | + $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=_new'); |
|
804 | 804 | |
805 | - wp_send_json( $response ); |
|
805 | + wp_send_json($response); |
|
806 | 806 | } |
807 | 807 | |
808 | 808 | public static function update_eu_rates() { |
@@ -811,72 +811,72 @@ discard block |
||
811 | 811 | $response['error'] = null; |
812 | 812 | $response['data'] = null; |
813 | 813 | |
814 | - if ( !current_user_can( 'manage_options' ) ) { |
|
815 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
816 | - wp_send_json( $response ); |
|
814 | + if (!current_user_can('manage_options')) { |
|
815 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
816 | + wp_send_json($response); |
|
817 | 817 | } |
818 | 818 | |
819 | - $group = !empty( $_POST['group'] ) ? sanitize_text_field( $_POST['group'] ) : ''; |
|
820 | - $euvatrates = self::request_euvatrates( $group ); |
|
819 | + $group = !empty($_POST['group']) ? sanitize_text_field($_POST['group']) : ''; |
|
820 | + $euvatrates = self::request_euvatrates($group); |
|
821 | 821 | |
822 | - if ( !empty( $euvatrates ) ) { |
|
823 | - if ( !empty( $euvatrates['success'] ) && !empty( $euvatrates['rates'] ) ) { |
|
822 | + if (!empty($euvatrates)) { |
|
823 | + if (!empty($euvatrates['success']) && !empty($euvatrates['rates'])) { |
|
824 | 824 | $response['success'] = true; |
825 | 825 | $response['data']['rates'] = $euvatrates['rates']; |
826 | - } else if ( !empty( $euvatrates['error'] ) ) { |
|
826 | + } else if (!empty($euvatrates['error'])) { |
|
827 | 827 | $response['error'] = $euvatrates['error']; |
828 | 828 | } |
829 | 829 | } |
830 | 830 | |
831 | - wp_send_json( $response ); |
|
831 | + wp_send_json($response); |
|
832 | 832 | } |
833 | 833 | |
834 | 834 | public static function hide_vat_fields() { |
835 | - $hide = wpinv_get_option( 'vat_disable_fields' ); |
|
835 | + $hide = wpinv_get_option('vat_disable_fields'); |
|
836 | 836 | |
837 | - return apply_filters( 'wpinv_hide_vat_fields', $hide ); |
|
837 | + return apply_filters('wpinv_hide_vat_fields', $hide); |
|
838 | 838 | } |
839 | 839 | |
840 | 840 | public static function same_country_rule() { |
841 | - $same_country_rule = wpinv_get_option( 'vat_same_country_rule' ); |
|
841 | + $same_country_rule = wpinv_get_option('vat_same_country_rule'); |
|
842 | 842 | |
843 | - return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule ); |
|
843 | + return apply_filters('wpinv_vat_same_country_rule', $same_country_rule); |
|
844 | 844 | } |
845 | 845 | |
846 | 846 | public static function get_vat_name() { |
847 | - $vat_name = wpinv_get_option( 'vat_name' ); |
|
848 | - $vat_name = !empty( $vat_name ) ? $vat_name : 'VAT'; |
|
847 | + $vat_name = wpinv_get_option('vat_name'); |
|
848 | + $vat_name = !empty($vat_name) ? $vat_name : 'VAT'; |
|
849 | 849 | |
850 | - return apply_filters( 'wpinv_get_owner_vat_name', $vat_name ); |
|
850 | + return apply_filters('wpinv_get_owner_vat_name', $vat_name); |
|
851 | 851 | } |
852 | 852 | |
853 | 853 | public static function get_company_name() { |
854 | - $company_name = wpinv_get_option( 'vat_company_name' ); |
|
854 | + $company_name = wpinv_get_option('vat_company_name'); |
|
855 | 855 | |
856 | - return apply_filters( 'wpinv_get_owner_company_name', $company_name ); |
|
856 | + return apply_filters('wpinv_get_owner_company_name', $company_name); |
|
857 | 857 | } |
858 | 858 | |
859 | 859 | public static function get_vat_number() { |
860 | - $vat_number = wpinv_get_option( 'vat_number' ); |
|
860 | + $vat_number = wpinv_get_option('vat_number'); |
|
861 | 861 | |
862 | - return apply_filters( 'wpinv_get_owner_vat_number', $vat_number ); |
|
862 | + return apply_filters('wpinv_get_owner_vat_number', $vat_number); |
|
863 | 863 | } |
864 | 864 | |
865 | 865 | public static function is_vat_validated() { |
866 | - $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' ); |
|
866 | + $validated = self::get_vat_number() && wpinv_get_option('vat_valid'); |
|
867 | 867 | |
868 | - return apply_filters( 'wpinv_is_owner_vat_validated', $validated ); |
|
868 | + return apply_filters('wpinv_is_owner_vat_validated', $validated); |
|
869 | 869 | } |
870 | 870 | |
871 | - public static function sanitize_vat( $vat_number, $country_code = '' ) { |
|
872 | - $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) ); |
|
871 | + public static function sanitize_vat($vat_number, $country_code = '') { |
|
872 | + $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number))); |
|
873 | 873 | |
874 | - if ( empty( $country_code ) ) { |
|
875 | - $country_code = substr( $vat_number, 0, 2 ); |
|
874 | + if (empty($country_code)) { |
|
875 | + $country_code = substr($vat_number, 0, 2); |
|
876 | 876 | } |
877 | 877 | |
878 | - if ( strpos( $vat_number , $country_code ) === 0 ) { |
|
879 | - $vat = str_replace( $country_code, '', $vat_number ); |
|
878 | + if (strpos($vat_number, $country_code) === 0) { |
|
879 | + $vat = str_replace($country_code, '', $vat_number); |
|
880 | 880 | } else { |
881 | 881 | $vat = $country_code . $vat_number; |
882 | 882 | } |
@@ -889,140 +889,140 @@ discard block |
||
889 | 889 | return $return; |
890 | 890 | } |
891 | 891 | |
892 | - public static function offline_check( $vat_number, $country_code = '', $formatted = false ) { |
|
893 | - $vat = self::sanitize_vat( $vat_number, $country_code ); |
|
892 | + public static function offline_check($vat_number, $country_code = '', $formatted = false) { |
|
893 | + $vat = self::sanitize_vat($vat_number, $country_code); |
|
894 | 894 | $vat_number = $vat['vat_number']; |
895 | 895 | $country_code = $vat['iso']; |
896 | 896 | $regex = array(); |
897 | 897 | |
898 | - switch ( $country_code ) { |
|
898 | + switch ($country_code) { |
|
899 | 899 | case 'AT': |
900 | - $regex[] = '/^(AT)U(\d{8})$/'; // Austria |
|
900 | + $regex[] = '/^(AT)U(\d{8})$/'; // Austria |
|
901 | 901 | break; |
902 | 902 | case 'BE': |
903 | - $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium |
|
903 | + $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium |
|
904 | 904 | break; |
905 | 905 | case 'BG': |
906 | - $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria |
|
906 | + $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria |
|
907 | 907 | break; |
908 | 908 | case 'CH': |
909 | 909 | case 'CHE': |
910 | - $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU) |
|
910 | + $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU) |
|
911 | 911 | break; |
912 | 912 | case 'CY': |
913 | - $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus |
|
913 | + $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus |
|
914 | 914 | break; |
915 | 915 | case 'CZ': |
916 | - $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic |
|
916 | + $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic |
|
917 | 917 | break; |
918 | 918 | case 'DE': |
919 | - $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany |
|
919 | + $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany |
|
920 | 920 | break; |
921 | 921 | case 'DK': |
922 | - $regex[] = '/^(DK)(\d{8})$/'; // Denmark |
|
922 | + $regex[] = '/^(DK)(\d{8})$/'; // Denmark |
|
923 | 923 | break; |
924 | 924 | case 'EE': |
925 | - $regex[] = '/^(EE)(10\d{7})$/'; // Estonia |
|
925 | + $regex[] = '/^(EE)(10\d{7})$/'; // Estonia |
|
926 | 926 | break; |
927 | 927 | case 'EL': |
928 | - $regex[] = '/^(EL)(\d{9})$/'; // Greece |
|
928 | + $regex[] = '/^(EL)(\d{9})$/'; // Greece |
|
929 | 929 | break; |
930 | 930 | case 'ES': |
931 | - $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities) |
|
932 | - $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities) |
|
933 | - $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1) |
|
934 | - $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2) |
|
931 | + $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities) |
|
932 | + $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities) |
|
933 | + $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1) |
|
934 | + $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2) |
|
935 | 935 | break; |
936 | 936 | case 'EU': |
937 | - $regex[] = '/^(EU)(\d{9})$/'; // EU-type |
|
937 | + $regex[] = '/^(EU)(\d{9})$/'; // EU-type |
|
938 | 938 | break; |
939 | 939 | case 'FI': |
940 | - $regex[] = '/^(FI)(\d{8})$/'; // Finland |
|
940 | + $regex[] = '/^(FI)(\d{8})$/'; // Finland |
|
941 | 941 | break; |
942 | 942 | case 'FR': |
943 | - $regex[] = '/^(FR)(\d{11})$/'; // France (1) |
|
944 | - $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2) |
|
945 | - $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3) |
|
946 | - $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4) |
|
943 | + $regex[] = '/^(FR)(\d{11})$/'; // France (1) |
|
944 | + $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2) |
|
945 | + $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3) |
|
946 | + $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4) |
|
947 | 947 | break; |
948 | 948 | case 'GB': |
949 | - $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard) |
|
950 | - $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches) |
|
951 | - $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government) |
|
952 | - $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority) |
|
949 | + $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard) |
|
950 | + $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches) |
|
951 | + $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government) |
|
952 | + $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority) |
|
953 | 953 | break; |
954 | 954 | case 'GR': |
955 | - $regex[] = '/^(GR)(\d{8,9})$/'; // Greece |
|
955 | + $regex[] = '/^(GR)(\d{8,9})$/'; // Greece |
|
956 | 956 | break; |
957 | 957 | case 'HR': |
958 | - $regex[] = '/^(HR)(\d{11})$/'; // Croatia |
|
958 | + $regex[] = '/^(HR)(\d{11})$/'; // Croatia |
|
959 | 959 | break; |
960 | 960 | case 'HU': |
961 | - $regex[] = '/^(HU)(\d{8})$/'; // Hungary |
|
961 | + $regex[] = '/^(HU)(\d{8})$/'; // Hungary |
|
962 | 962 | break; |
963 | 963 | case 'IE': |
964 | - $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1) |
|
965 | - $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2) |
|
966 | - $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013) |
|
964 | + $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1) |
|
965 | + $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2) |
|
966 | + $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013) |
|
967 | 967 | break; |
968 | 968 | case 'IT': |
969 | - $regex[] = '/^(IT)(\d{11})$/'; // Italy |
|
969 | + $regex[] = '/^(IT)(\d{11})$/'; // Italy |
|
970 | 970 | break; |
971 | 971 | case 'LV': |
972 | - $regex[] = '/^(LV)(\d{11})$/'; // Latvia |
|
972 | + $regex[] = '/^(LV)(\d{11})$/'; // Latvia |
|
973 | 973 | break; |
974 | 974 | case 'LT': |
975 | - $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania |
|
975 | + $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania |
|
976 | 976 | break; |
977 | 977 | case 'LU': |
978 | - $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg |
|
978 | + $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg |
|
979 | 979 | break; |
980 | 980 | case 'MT': |
981 | - $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta |
|
981 | + $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta |
|
982 | 982 | break; |
983 | 983 | case 'NL': |
984 | - $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands |
|
984 | + $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands |
|
985 | 985 | break; |
986 | 986 | case 'NO': |
987 | - $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU) |
|
987 | + $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU) |
|
988 | 988 | break; |
989 | 989 | case 'PL': |
990 | - $regex[] = '/^(PL)(\d{10})$/'; // Poland |
|
990 | + $regex[] = '/^(PL)(\d{10})$/'; // Poland |
|
991 | 991 | break; |
992 | 992 | case 'PT': |
993 | - $regex[] = '/^(PT)(\d{9})$/'; // Portugal |
|
993 | + $regex[] = '/^(PT)(\d{9})$/'; // Portugal |
|
994 | 994 | break; |
995 | 995 | case 'RO': |
996 | - $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania |
|
996 | + $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania |
|
997 | 997 | break; |
998 | 998 | case 'RS': |
999 | - $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU) |
|
999 | + $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU) |
|
1000 | 1000 | break; |
1001 | 1001 | case 'SI': |
1002 | - $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia |
|
1002 | + $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia |
|
1003 | 1003 | break; |
1004 | 1004 | case 'SK': |
1005 | - $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic |
|
1005 | + $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic |
|
1006 | 1006 | break; |
1007 | 1007 | case 'SE': |
1008 | - $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden |
|
1008 | + $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden |
|
1009 | 1009 | break; |
1010 | 1010 | default: |
1011 | 1011 | $regex = array(); |
1012 | 1012 | break; |
1013 | 1013 | } |
1014 | 1014 | |
1015 | - if ( empty( $regex ) ) { |
|
1015 | + if (empty($regex)) { |
|
1016 | 1016 | return false; |
1017 | 1017 | } |
1018 | 1018 | |
1019 | - foreach ( $regex as $pattern ) { |
|
1019 | + foreach ($regex as $pattern) { |
|
1020 | 1020 | $matches = null; |
1021 | - preg_match_all( $pattern, $vat_number, $matches ); |
|
1021 | + preg_match_all($pattern, $vat_number, $matches); |
|
1022 | 1022 | |
1023 | - if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) { |
|
1024 | - if ( $formatted ) { |
|
1025 | - return array( 'code' => $matches[1][0], 'number' => $matches[2][0] ); |
|
1023 | + if (!empty($matches[1][0]) && !empty($matches[2][0])) { |
|
1024 | + if ($formatted) { |
|
1025 | + return array('code' => $matches[1][0], 'number' => $matches[2][0]); |
|
1026 | 1026 | } else { |
1027 | 1027 | return true; |
1028 | 1028 | } |
@@ -1032,75 +1032,75 @@ discard block |
||
1032 | 1032 | return false; |
1033 | 1033 | } |
1034 | 1034 | |
1035 | - public static function vies_check( $vat_number, $country_code = '', $result = false ) { |
|
1036 | - $vat = self::sanitize_vat( $vat_number, $country_code ); |
|
1035 | + public static function vies_check($vat_number, $country_code = '', $result = false) { |
|
1036 | + $vat = self::sanitize_vat($vat_number, $country_code); |
|
1037 | 1037 | $vat_number = $vat['vat']; |
1038 | 1038 | $iso = $vat['iso']; |
1039 | 1039 | |
1040 | - $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number ); |
|
1040 | + $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number); |
|
1041 | 1041 | |
1042 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
1043 | - $response = file_get_contents( $url ); |
|
1044 | - } else if ( function_exists( 'curl_init' ) ) { |
|
1042 | + if (ini_get('allow_url_fopen')) { |
|
1043 | + $response = file_get_contents($url); |
|
1044 | + } else if (function_exists('curl_init')) { |
|
1045 | 1045 | $ch = curl_init(); |
1046 | 1046 | |
1047 | - curl_setopt( $ch, CURLOPT_URL, $url ); |
|
1048 | - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 ); |
|
1049 | - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); |
|
1050 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 ); |
|
1051 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); |
|
1047 | + curl_setopt($ch, CURLOPT_URL, $url); |
|
1048 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); |
|
1049 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
1050 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
|
1051 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
1052 | 1052 | |
1053 | - $response = curl_exec( $ch ); |
|
1053 | + $response = curl_exec($ch); |
|
1054 | 1054 | |
1055 | - if ( curl_errno( $ch ) ) { |
|
1056 | - wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' ); |
|
1055 | + if (curl_errno($ch)) { |
|
1056 | + wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR'); |
|
1057 | 1057 | $response = ''; |
1058 | 1058 | } |
1059 | 1059 | |
1060 | - curl_close( $ch ); |
|
1060 | + curl_close($ch); |
|
1061 | 1061 | } else { |
1062 | - wpinv_error_log( 'To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR' ); |
|
1062 | + wpinv_error_log('To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR'); |
|
1063 | 1063 | } |
1064 | 1064 | |
1065 | - if ( empty( $response ) ) { |
|
1065 | + if (empty($response)) { |
|
1066 | 1066 | return $result; |
1067 | 1067 | } |
1068 | 1068 | |
1069 | - if ( preg_match( '/invalid VAT number/i', $response ) ) { |
|
1069 | + if (preg_match('/invalid VAT number/i', $response)) { |
|
1070 | 1070 | return false; |
1071 | - } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) { |
|
1072 | - $content = explode( "valid VAT number", htmlentities( $response ) ); |
|
1071 | + } else if (preg_match('/valid VAT number/i', $response, $matches)) { |
|
1072 | + $content = explode("valid VAT number", htmlentities($response)); |
|
1073 | 1073 | |
1074 | - if ( !empty( $content[1] ) ) { |
|
1075 | - preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches ); |
|
1074 | + if (!empty($content[1])) { |
|
1075 | + preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches); |
|
1076 | 1076 | |
1077 | - if ( !empty( $matches[2] ) && $matches[3] ) { |
|
1077 | + if (!empty($matches[2]) && $matches[3]) { |
|
1078 | 1078 | $return = array(); |
1079 | 1079 | |
1080 | - foreach ( $matches[2] as $key => $label ) { |
|
1081 | - $label = trim( $label ); |
|
1080 | + foreach ($matches[2] as $key => $label) { |
|
1081 | + $label = trim($label); |
|
1082 | 1082 | |
1083 | - switch ( strtolower( $label ) ) { |
|
1083 | + switch (strtolower($label)) { |
|
1084 | 1084 | case 'member state': |
1085 | - $return['state'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1085 | + $return['state'] = trim(strip_tags($matches[3][$key])); |
|
1086 | 1086 | break; |
1087 | 1087 | case 'vat number': |
1088 | - $return['number'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1088 | + $return['number'] = trim(strip_tags($matches[3][$key])); |
|
1089 | 1089 | break; |
1090 | 1090 | case 'name': |
1091 | - $return['company'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1091 | + $return['company'] = trim(strip_tags($matches[3][$key])); |
|
1092 | 1092 | break; |
1093 | 1093 | case 'address': |
1094 | - $address = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) ); |
|
1095 | - $return['address'] = trim( strip_tags( $address, '<br>' ) ); |
|
1094 | + $address = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key]))); |
|
1095 | + $return['address'] = trim(strip_tags($address, '<br>')); |
|
1096 | 1096 | break; |
1097 | 1097 | case 'consultation number': |
1098 | - $return['consultation'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1098 | + $return['consultation'] = trim(strip_tags($matches[3][$key])); |
|
1099 | 1099 | break; |
1100 | 1100 | } |
1101 | 1101 | } |
1102 | 1102 | |
1103 | - if ( !empty( $return ) ) { |
|
1103 | + if (!empty($return)) { |
|
1104 | 1104 | return $return; |
1105 | 1105 | } |
1106 | 1106 | } |
@@ -1112,55 +1112,55 @@ discard block |
||
1112 | 1112 | } |
1113 | 1113 | } |
1114 | 1114 | |
1115 | - public static function check_vat( $vat_number, $country_code = '' ) { |
|
1115 | + public static function check_vat($vat_number, $country_code = '') { |
|
1116 | 1116 | $vat_name = self::get_vat_name(); |
1117 | 1117 | |
1118 | 1118 | $return = array(); |
1119 | 1119 | $return['valid'] = false; |
1120 | - $return['message'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
1120 | + $return['message'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
1121 | 1121 | |
1122 | - if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) { |
|
1122 | + if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) { |
|
1123 | 1123 | return $return; |
1124 | 1124 | } |
1125 | 1125 | |
1126 | - $response = self::vies_check( $vat_number, $country_code ); |
|
1126 | + $response = self::vies_check($vat_number, $country_code); |
|
1127 | 1127 | |
1128 | - if ( $response ) { |
|
1129 | - $return['valid'] = true; |
|
1128 | + if ($response) { |
|
1129 | + $return['valid'] = true; |
|
1130 | 1130 | |
1131 | - if ( is_array( $response ) ) { |
|
1132 | - $return['company'] = isset( $response['company'] ) ? $response['company'] : ''; |
|
1133 | - $return['address'] = isset( $response['address'] ) ? $response['address'] : ''; |
|
1131 | + if (is_array($response)) { |
|
1132 | + $return['company'] = isset($response['company']) ? $response['company'] : ''; |
|
1133 | + $return['address'] = isset($response['address']) ? $response['address'] : ''; |
|
1134 | 1134 | $return['message'] = $return['company'] . '<br/>' . $return['address']; |
1135 | 1135 | } |
1136 | 1136 | } else { |
1137 | 1137 | $return['valid'] = false; |
1138 | - $return['message'] = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name ); |
|
1138 | + $return['message'] = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name); |
|
1139 | 1139 | } |
1140 | 1140 | |
1141 | 1141 | return $return; |
1142 | 1142 | } |
1143 | 1143 | |
1144 | - public static function request_euvatrates( $group ) { |
|
1144 | + public static function request_euvatrates($group) { |
|
1145 | 1145 | $response = array(); |
1146 | 1146 | $response['success'] = false; |
1147 | 1147 | $response['error'] = null; |
1148 | 1148 | $response['eurates'] = null; |
1149 | 1149 | |
1150 | 1150 | $euvatrates_url = 'https://euvatrates.com/rates.json'; |
1151 | - $euvatrates_url = apply_filters( 'wpinv_euvatrates_url', $euvatrates_url ); |
|
1152 | - $api_response = wp_remote_get( $euvatrates_url ); |
|
1151 | + $euvatrates_url = apply_filters('wpinv_euvatrates_url', $euvatrates_url); |
|
1152 | + $api_response = wp_remote_get($euvatrates_url); |
|
1153 | 1153 | |
1154 | 1154 | try { |
1155 | - if ( is_wp_error( $api_response ) ) { |
|
1156 | - $response['error'] = __( $api_response->get_error_message(), 'invoicing' ); |
|
1155 | + if (is_wp_error($api_response)) { |
|
1156 | + $response['error'] = __($api_response->get_error_message(), 'invoicing'); |
|
1157 | 1157 | } else { |
1158 | - $body = json_decode( $api_response['body'] ); |
|
1158 | + $body = json_decode($api_response['body']); |
|
1159 | 1159 | |
1160 | - if ( isset( $body->rates ) ) { |
|
1160 | + if (isset($body->rates)) { |
|
1161 | 1161 | $rates = array(); |
1162 | 1162 | |
1163 | - foreach ( $body->rates as $country_code => $rate ) { |
|
1163 | + foreach ($body->rates as $country_code => $rate) { |
|
1164 | 1164 | $vat_rate = array(); |
1165 | 1165 | $vat_rate['country'] = $rate->country; |
1166 | 1166 | $vat_rate['standard'] = (float)$rate->standard_rate; |
@@ -1168,7 +1168,7 @@ discard block |
||
1168 | 1168 | $vat_rate['superreduced'] = (float)$rate->super_reduced_rate; |
1169 | 1169 | $vat_rate['parking'] = (float)$rate->parking_rate; |
1170 | 1170 | |
1171 | - if ( $group !== '' && in_array( $group, array( 'standard', 'reduced', 'superreduced', 'parking' ) ) ) { |
|
1171 | + if ($group !== '' && in_array($group, array('standard', 'reduced', 'superreduced', 'parking'))) { |
|
1172 | 1172 | $vat_rate_group = array(); |
1173 | 1173 | $vat_rate_group['country'] = $rate->country; |
1174 | 1174 | $vat_rate_group[$group] = $vat_rate[$group]; |
@@ -1180,79 +1180,79 @@ discard block |
||
1180 | 1180 | } |
1181 | 1181 | |
1182 | 1182 | $response['success'] = true; |
1183 | - $response['rates'] = apply_filters( 'wpinv_process_euvatrates', $rates, $api_response, $group ); |
|
1183 | + $response['rates'] = apply_filters('wpinv_process_euvatrates', $rates, $api_response, $group); |
|
1184 | 1184 | } else { |
1185 | - $response['error'] = __( 'No EU rates found!', 'invoicing' ); |
|
1185 | + $response['error'] = __('No EU rates found!', 'invoicing'); |
|
1186 | 1186 | } |
1187 | 1187 | } |
1188 | - } catch ( Exception $e ) { |
|
1189 | - $response['error'] = __( $e->getMessage(), 'invoicing' ); |
|
1188 | + } catch (Exception $e) { |
|
1189 | + $response['error'] = __($e->getMessage(), 'invoicing'); |
|
1190 | 1190 | } |
1191 | 1191 | |
1192 | - return apply_filters( 'wpinv_response_euvatrates', $response, $group ); |
|
1192 | + return apply_filters('wpinv_response_euvatrates', $response, $group); |
|
1193 | 1193 | } |
1194 | 1194 | |
1195 | - public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) { |
|
1195 | + public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) { |
|
1196 | 1196 | global $wpi_item_id, $wpi_country; |
1197 | 1197 | |
1198 | - if ( !empty( $_POST['wpinv_country'] ) ) { |
|
1199 | - $country_code = trim( $_POST['wpinv_country'] ); |
|
1200 | - } else if ( !empty( $_POST['country'] ) ) { |
|
1201 | - $country_code = trim( $_POST['country'] ); |
|
1202 | - } else if ( !empty( $wpi_country ) ) { |
|
1198 | + if (!empty($_POST['wpinv_country'])) { |
|
1199 | + $country_code = trim($_POST['wpinv_country']); |
|
1200 | + } else if (!empty($_POST['country'])) { |
|
1201 | + $country_code = trim($_POST['country']); |
|
1202 | + } else if (!empty($wpi_country)) { |
|
1203 | 1203 | $country_code = $wpi_country; |
1204 | 1204 | } else { |
1205 | - $country_code = self::get_user_country( '', $user_id ); |
|
1205 | + $country_code = self::get_user_country('', $user_id); |
|
1206 | 1206 | } |
1207 | 1207 | |
1208 | - if ( $is_digital === null && $wpi_item_id ) { |
|
1209 | - $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules(); |
|
1208 | + if ($is_digital === null && $wpi_item_id) { |
|
1209 | + $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules(); |
|
1210 | 1210 | } |
1211 | 1211 | |
1212 | - if ( !empty( $country_code ) ) { |
|
1213 | - $requires_vat = ( self::is_eu_state( $country_code ) && ( self::is_eu_state( self::$default_country ) || $is_digital ) ) || ( self::is_gst_country( $country_code ) && self::is_gst_country( self::$default_country ) ); |
|
1212 | + if (!empty($country_code)) { |
|
1213 | + $requires_vat = (self::is_eu_state($country_code) && (self::is_eu_state(self::$default_country) || $is_digital)) || (self::is_gst_country($country_code) && self::is_gst_country(self::$default_country)); |
|
1214 | 1214 | } |
1215 | 1215 | |
1216 | - return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id ); |
|
1216 | + return apply_filters('wpinv_requires_vat', $requires_vat, $user_id); |
|
1217 | 1217 | } |
1218 | 1218 | |
1219 | - public static function tax_label( $label = '' ) { |
|
1219 | + public static function tax_label($label = '') { |
|
1220 | 1220 | global $wpi_requires_vat; |
1221 | 1221 | |
1222 | - if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) { |
|
1223 | - $wpi_requires_vat = self::requires_vat( 0, false ); |
|
1222 | + if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) { |
|
1223 | + $wpi_requires_vat = self::requires_vat(0, false); |
|
1224 | 1224 | } |
1225 | 1225 | |
1226 | - return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) ); |
|
1226 | + return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing')); |
|
1227 | 1227 | } |
1228 | 1228 | |
1229 | 1229 | public static function standard_rates_label() { |
1230 | - return __( 'Standard Rates', 'invoicing' ); |
|
1230 | + return __('Standard Rates', 'invoicing'); |
|
1231 | 1231 | } |
1232 | 1232 | |
1233 | - public static function get_rate_classes( $with_desc = false ) { |
|
1234 | - $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true ); |
|
1235 | - $classes = maybe_unserialize( $rate_classes_option ); |
|
1233 | + public static function get_rate_classes($with_desc = false) { |
|
1234 | + $rate_classes_option = get_option('_wpinv_vat_rate_classes', true); |
|
1235 | + $classes = maybe_unserialize($rate_classes_option); |
|
1236 | 1236 | |
1237 | - if ( empty( $classes ) || !is_array( $classes ) ) { |
|
1237 | + if (empty($classes) || !is_array($classes)) { |
|
1238 | 1238 | $classes = array(); |
1239 | 1239 | } |
1240 | 1240 | |
1241 | 1241 | $rate_classes = array(); |
1242 | - if ( !array_key_exists( '_standard', $classes ) ) { |
|
1243 | - if ( $with_desc ) { |
|
1244 | - $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) ); |
|
1242 | + if (!array_key_exists('_standard', $classes)) { |
|
1243 | + if ($with_desc) { |
|
1244 | + $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing')); |
|
1245 | 1245 | } else { |
1246 | 1246 | $rate_classes['_standard'] = self::standard_rates_label(); |
1247 | 1247 | } |
1248 | 1248 | } |
1249 | 1249 | |
1250 | - foreach ( $classes as $key => $class ) { |
|
1251 | - $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key; |
|
1252 | - $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : ''; |
|
1250 | + foreach ($classes as $key => $class) { |
|
1251 | + $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key; |
|
1252 | + $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : ''; |
|
1253 | 1253 | |
1254 | - if ( $with_desc ) { |
|
1255 | - $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc ); |
|
1254 | + if ($with_desc) { |
|
1255 | + $rate_classes[$key] = array('name' => $name, 'desc' => $desc); |
|
1256 | 1256 | } else { |
1257 | 1257 | $rate_classes[$key] = $name; |
1258 | 1258 | } |
@@ -1263,15 +1263,15 @@ discard block |
||
1263 | 1263 | |
1264 | 1264 | public static function get_all_classes() { |
1265 | 1265 | $classes = self::get_rate_classes(); |
1266 | - $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' ); |
|
1266 | + $classes['_exempt'] = __('Exempt (0%)', 'invoicing'); |
|
1267 | 1267 | |
1268 | - return apply_filters( 'wpinv_vat_get_all_classes', $classes ); |
|
1268 | + return apply_filters('wpinv_vat_get_all_classes', $classes); |
|
1269 | 1269 | } |
1270 | 1270 | |
1271 | - public static function get_class_desc( $rate_class ) { |
|
1272 | - $rate_classes = self::get_rate_classes( true ); |
|
1271 | + public static function get_class_desc($rate_class) { |
|
1272 | + $rate_classes = self::get_rate_classes(true); |
|
1273 | 1273 | |
1274 | - if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) { |
|
1274 | + if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) { |
|
1275 | 1275 | return $rate_classes[$rate_class]['desc']; |
1276 | 1276 | } |
1277 | 1277 | |
@@ -1287,106 +1287,106 @@ discard block |
||
1287 | 1287 | 'increased' => 'Increased' |
1288 | 1288 | ); |
1289 | 1289 | |
1290 | - return apply_filters( 'wpinv_get_vat_groups', $vat_groups ); |
|
1290 | + return apply_filters('wpinv_get_vat_groups', $vat_groups); |
|
1291 | 1291 | } |
1292 | 1292 | |
1293 | 1293 | public static function get_rules() { |
1294 | 1294 | $vat_rules = array( |
1295 | - 'digital' => __( 'Digital Product', 'invoicing' ), |
|
1296 | - 'physical' => __( 'Physical Product', 'invoicing' ) |
|
1295 | + 'digital' => __('Digital Product', 'invoicing'), |
|
1296 | + 'physical' => __('Physical Product', 'invoicing') |
|
1297 | 1297 | ); |
1298 | - return apply_filters( 'wpinv_get_vat_rules', $vat_rules ); |
|
1298 | + return apply_filters('wpinv_get_vat_rules', $vat_rules); |
|
1299 | 1299 | } |
1300 | 1300 | |
1301 | - public static function get_vat_rates( $class ) { |
|
1302 | - if ( $class === '_standard' ) { |
|
1301 | + public static function get_vat_rates($class) { |
|
1302 | + if ($class === '_standard') { |
|
1303 | 1303 | return wpinv_get_tax_rates(); |
1304 | 1304 | } |
1305 | 1305 | |
1306 | 1306 | $rates = self::get_non_standard_rates(); |
1307 | 1307 | |
1308 | - return array_key_exists( $class, $rates ) ? $rates[$class] : array(); |
|
1308 | + return array_key_exists($class, $rates) ? $rates[$class] : array(); |
|
1309 | 1309 | } |
1310 | 1310 | |
1311 | 1311 | public static function get_non_standard_rates() { |
1312 | - $option = get_option( 'wpinv_vat_rates', array()); |
|
1313 | - return is_array( $option ) ? $option : array(); |
|
1312 | + $option = get_option('wpinv_vat_rates', array()); |
|
1313 | + return is_array($option) ? $option : array(); |
|
1314 | 1314 | } |
1315 | 1315 | |
1316 | 1316 | public static function allow_vat_rules() { |
1317 | - return ( wpinv_get_option( 'apply_vat_rules' ) ? true : false ); |
|
1317 | + return (wpinv_get_option('apply_vat_rules') ? true : false); |
|
1318 | 1318 | } |
1319 | 1319 | |
1320 | 1320 | public static function allow_vat_classes() { |
1321 | 1321 | return false; // TODO |
1322 | - return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false ); |
|
1322 | + return (wpinv_get_option('vat_allow_classes') ? true : false); |
|
1323 | 1323 | } |
1324 | 1324 | |
1325 | - public static function get_item_class( $postID ) { |
|
1326 | - $class = get_post_meta( $postID, '_wpinv_vat_class', true ); |
|
1325 | + public static function get_item_class($postID) { |
|
1326 | + $class = get_post_meta($postID, '_wpinv_vat_class', true); |
|
1327 | 1327 | |
1328 | - if ( empty( $class ) ) { |
|
1328 | + if (empty($class)) { |
|
1329 | 1329 | $class = '_standard'; |
1330 | 1330 | } |
1331 | 1331 | |
1332 | - return apply_filters( 'wpinv_get_item_vat_class', $class, $postID ); |
|
1332 | + return apply_filters('wpinv_get_item_vat_class', $class, $postID); |
|
1333 | 1333 | } |
1334 | 1334 | |
1335 | - public static function item_class_label( $postID ) { |
|
1335 | + public static function item_class_label($postID) { |
|
1336 | 1336 | $vat_classes = self::get_all_classes(); |
1337 | 1337 | |
1338 | - $class = self::get_item_class( $postID ); |
|
1339 | - $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' ); |
|
1338 | + $class = self::get_item_class($postID); |
|
1339 | + $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing'); |
|
1340 | 1340 | |
1341 | - return apply_filters( 'wpinv_item_class_label', $class, $postID ); |
|
1341 | + return apply_filters('wpinv_item_class_label', $class, $postID); |
|
1342 | 1342 | } |
1343 | 1343 | |
1344 | - public static function get_item_rule( $postID ) { |
|
1345 | - $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true ); |
|
1344 | + public static function get_item_rule($postID) { |
|
1345 | + $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true); |
|
1346 | 1346 | |
1347 | - if ( empty( $rule_type ) ) { |
|
1347 | + if (empty($rule_type)) { |
|
1348 | 1348 | $rule_type = self::allow_vat_rules() ? 'digital' : 'physical'; |
1349 | 1349 | } |
1350 | 1350 | |
1351 | - return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID ); |
|
1351 | + return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID); |
|
1352 | 1352 | } |
1353 | 1353 | |
1354 | - public static function item_rule_label( $postID ) { |
|
1354 | + public static function item_rule_label($postID) { |
|
1355 | 1355 | $vat_rules = self::get_rules(); |
1356 | - $vat_rule = self::get_item_rule( $postID ); |
|
1357 | - $vat_rule = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule; |
|
1356 | + $vat_rule = self::get_item_rule($postID); |
|
1357 | + $vat_rule = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule; |
|
1358 | 1358 | |
1359 | - return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID ); |
|
1359 | + return apply_filters('wpinv_item_rule_label', $vat_rule, $postID); |
|
1360 | 1360 | } |
1361 | 1361 | |
1362 | - public static function item_has_digital_rule( $item_id = 0 ) { |
|
1363 | - return self::get_item_rule( $item_id ) == 'digital' ? true : false; |
|
1362 | + public static function item_has_digital_rule($item_id = 0) { |
|
1363 | + return self::get_item_rule($item_id) == 'digital' ? true : false; |
|
1364 | 1364 | } |
1365 | 1365 | |
1366 | - public static function invoice_has_digital_rule( $invoice = 0 ) { |
|
1367 | - if ( !self::allow_vat_rules() ) { |
|
1366 | + public static function invoice_has_digital_rule($invoice = 0) { |
|
1367 | + if (!self::allow_vat_rules()) { |
|
1368 | 1368 | return false; |
1369 | 1369 | } |
1370 | 1370 | |
1371 | - if ( empty( $invoice ) ) { |
|
1371 | + if (empty($invoice)) { |
|
1372 | 1372 | return true; |
1373 | 1373 | } |
1374 | 1374 | |
1375 | - if ( is_int( $invoice ) ) { |
|
1376 | - $invoice = new WPInv_Invoice( $invoice ); |
|
1375 | + if (is_int($invoice)) { |
|
1376 | + $invoice = new WPInv_Invoice($invoice); |
|
1377 | 1377 | } |
1378 | 1378 | |
1379 | - if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) { |
|
1379 | + if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) { |
|
1380 | 1380 | return true; |
1381 | 1381 | } |
1382 | 1382 | |
1383 | - $cart_items = $invoice->get_cart_details(); |
|
1383 | + $cart_items = $invoice->get_cart_details(); |
|
1384 | 1384 | |
1385 | - if ( !empty( $cart_items ) ) { |
|
1385 | + if (!empty($cart_items)) { |
|
1386 | 1386 | $has_digital_rule = false; |
1387 | 1387 | |
1388 | - foreach ( $cart_items as $key => $item ) { |
|
1389 | - if ( self::item_has_digital_rule( $item['id'] ) ) { |
|
1388 | + foreach ($cart_items as $key => $item) { |
|
1389 | + if (self::item_has_digital_rule($item['id'])) { |
|
1390 | 1390 | $has_digital_rule = true; |
1391 | 1391 | break; |
1392 | 1392 | } |
@@ -1398,67 +1398,67 @@ discard block |
||
1398 | 1398 | return $has_digital_rule; |
1399 | 1399 | } |
1400 | 1400 | |
1401 | - public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) { |
|
1402 | - if ( !wpinv_use_taxes() ) { |
|
1401 | + public static function item_is_taxable($item_id = 0, $country = false, $state = false) { |
|
1402 | + if (!wpinv_use_taxes()) { |
|
1403 | 1403 | return false; |
1404 | 1404 | } |
1405 | 1405 | |
1406 | 1406 | $is_taxable = true; |
1407 | 1407 | |
1408 | - if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) { |
|
1408 | + if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') { |
|
1409 | 1409 | $is_taxable = false; |
1410 | 1410 | } |
1411 | 1411 | |
1412 | - return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state ); |
|
1412 | + return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state); |
|
1413 | 1413 | } |
1414 | 1414 | |
1415 | - public static function find_rate( $country, $state, $rate, $class ) { |
|
1415 | + public static function find_rate($country, $state, $rate, $class) { |
|
1416 | 1416 | global $wpi_zero_tax; |
1417 | 1417 | |
1418 | - if ( $class === '_exempt' || $wpi_zero_tax ) { |
|
1418 | + if ($class === '_exempt' || $wpi_zero_tax) { |
|
1419 | 1419 | return 0; |
1420 | 1420 | } |
1421 | 1421 | |
1422 | - $tax_rates = wpinv_get_tax_rates(); |
|
1422 | + $tax_rates = wpinv_get_tax_rates(); |
|
1423 | 1423 | |
1424 | - if ( $class !== '_standard' ) { |
|
1425 | - $class_rates = self::get_vat_rates( $class ); |
|
1424 | + if ($class !== '_standard') { |
|
1425 | + $class_rates = self::get_vat_rates($class); |
|
1426 | 1426 | |
1427 | - if ( is_array( $class_rates ) ) { |
|
1427 | + if (is_array($class_rates)) { |
|
1428 | 1428 | $indexed_class_rates = array(); |
1429 | 1429 | |
1430 | - foreach ( $class_rates as $key => $cr ) { |
|
1430 | + foreach ($class_rates as $key => $cr) { |
|
1431 | 1431 | $indexed_class_rates[$cr['country']] = $cr; |
1432 | 1432 | } |
1433 | 1433 | |
1434 | - $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) { |
|
1434 | + $tax_rates = array_map(function($tr) use($indexed_class_rates) { |
|
1435 | 1435 | $tr_country = $tr['country']; |
1436 | - if ( !isset( $indexed_class_rates[$tr_country] ) ) { |
|
1436 | + if (!isset($indexed_class_rates[$tr_country])) { |
|
1437 | 1437 | return $tr; |
1438 | 1438 | } |
1439 | 1439 | $icr = $indexed_class_rates[$tr_country]; |
1440 | - return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr; |
|
1440 | + return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr; |
|
1441 | 1441 | |
1442 | - }, $tax_rates, $class_rates ); |
|
1442 | + }, $tax_rates, $class_rates); |
|
1443 | 1443 | } |
1444 | 1444 | } |
1445 | 1445 | |
1446 | - if ( !empty( $tax_rates ) ) { |
|
1447 | - foreach ( $tax_rates as $key => $tax_rate ) { |
|
1448 | - if ( $country != $tax_rate['country'] ) |
|
1446 | + if (!empty($tax_rates)) { |
|
1447 | + foreach ($tax_rates as $key => $tax_rate) { |
|
1448 | + if ($country != $tax_rate['country']) |
|
1449 | 1449 | continue; |
1450 | 1450 | |
1451 | - if ( !empty( $tax_rate['global'] ) ) { |
|
1452 | - if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) { |
|
1453 | - $rate = number_format( $tax_rate['rate'], 4 ); |
|
1451 | + if (!empty($tax_rate['global'])) { |
|
1452 | + if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) { |
|
1453 | + $rate = number_format($tax_rate['rate'], 4); |
|
1454 | 1454 | } |
1455 | 1455 | } else { |
1456 | - if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
1456 | + if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) |
|
1457 | 1457 | continue; |
1458 | 1458 | |
1459 | 1459 | $state_rate = $tax_rate['rate']; |
1460 | - if ( 0 !== $state_rate || !empty( $state_rate ) ) { |
|
1461 | - $rate = number_format( $state_rate, 4 ); |
|
1460 | + if (0 !== $state_rate || !empty($state_rate)) { |
|
1461 | + $rate = number_format($state_rate, 4); |
|
1462 | 1462 | } |
1463 | 1463 | } |
1464 | 1464 | } |
@@ -1467,84 +1467,84 @@ discard block |
||
1467 | 1467 | return $rate; |
1468 | 1468 | } |
1469 | 1469 | |
1470 | - public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) { |
|
1470 | + public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) { |
|
1471 | 1471 | global $wpinv_options, $wpi_session, $wpi_item_id, $wpi_zero_tax; |
1472 | 1472 | |
1473 | 1473 | $item_id = $item_id > 0 ? $item_id : $wpi_item_id; |
1474 | 1474 | $allow_vat_classes = self::allow_vat_classes(); |
1475 | - $class = $item_id ? self::get_item_class( $item_id ) : '_standard'; |
|
1475 | + $class = $item_id ? self::get_item_class($item_id) : '_standard'; |
|
1476 | 1476 | |
1477 | - if ( $class === '_exempt' || $wpi_zero_tax ) { |
|
1477 | + if ($class === '_exempt' || $wpi_zero_tax) { |
|
1478 | 1478 | return 0; |
1479 | - } else if ( !$allow_vat_classes ) { |
|
1479 | + } else if (!$allow_vat_classes) { |
|
1480 | 1480 | $class = '_standard'; |
1481 | 1481 | } |
1482 | 1482 | |
1483 | - if( !empty( $_POST['wpinv_country'] ) ) { |
|
1483 | + if (!empty($_POST['wpinv_country'])) { |
|
1484 | 1484 | $post_country = $_POST['wpinv_country']; |
1485 | - } elseif( !empty( $_POST['wpinv_country'] ) ) { |
|
1485 | + } elseif (!empty($_POST['wpinv_country'])) { |
|
1486 | 1486 | $post_country = $_POST['wpinv_country']; |
1487 | - } elseif( !empty( $_POST['country'] ) ) { |
|
1487 | + } elseif (!empty($_POST['country'])) { |
|
1488 | 1488 | $post_country = $_POST['country']; |
1489 | 1489 | } else { |
1490 | 1490 | $post_country = ''; |
1491 | 1491 | } |
1492 | 1492 | |
1493 | - $country = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country ); |
|
1494 | - $base_country = wpinv_is_base_country( $country ); |
|
1493 | + $country = !empty($post_country) ? $post_country : wpinv_default_billing_country($country); |
|
1494 | + $base_country = wpinv_is_base_country($country); |
|
1495 | 1495 | |
1496 | - $requires_vat = self::requires_vat( 0, false ); |
|
1497 | - $is_digital = self::get_item_rule( $item_id ) == 'digital' ; |
|
1498 | - $rate = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate; |
|
1496 | + $requires_vat = self::requires_vat(0, false); |
|
1497 | + $is_digital = self::get_item_rule($item_id) == 'digital'; |
|
1498 | + $rate = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate; |
|
1499 | 1499 | |
1500 | - if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country |
|
1500 | + if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country |
|
1501 | 1501 | $rate = 0; |
1502 | - } else if ( $requires_vat ) { |
|
1503 | - $vat_number = self::get_user_vat_number( '', 0, true ); |
|
1502 | + } else if ($requires_vat) { |
|
1503 | + $vat_number = self::get_user_vat_number('', 0, true); |
|
1504 | 1504 | $vat_info = self::current_vat_data(); |
1505 | 1505 | |
1506 | - if ( is_array( $vat_info ) ) { |
|
1507 | - $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : ""; |
|
1506 | + if (is_array($vat_info)) { |
|
1507 | + $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : ""; |
|
1508 | 1508 | } |
1509 | 1509 | |
1510 | - if ( $country == 'UK' ) { |
|
1510 | + if ($country == 'UK') { |
|
1511 | 1511 | $country = 'GB'; |
1512 | 1512 | } |
1513 | 1513 | |
1514 | - if ( !empty( $vat_number ) ) { |
|
1514 | + if (!empty($vat_number)) { |
|
1515 | 1515 | $rate = 0; |
1516 | 1516 | } else { |
1517 | - $rate = self::find_rate( $country, $state, $rate, $class ); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate |
|
1517 | + $rate = self::find_rate($country, $state, $rate, $class); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate |
|
1518 | 1518 | } |
1519 | 1519 | |
1520 | - if ( empty( $vat_number ) && !$is_digital ) { |
|
1521 | - if ( $base_country ) { |
|
1522 | - $rate = self::find_rate( $country, null, $rate, $class ); |
|
1520 | + if (empty($vat_number) && !$is_digital) { |
|
1521 | + if ($base_country) { |
|
1522 | + $rate = self::find_rate($country, null, $rate, $class); |
|
1523 | 1523 | } else { |
1524 | - if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) { |
|
1524 | + if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) { |
|
1525 | 1525 | $rate = $wpinv_options['eu_fallback_rate']; |
1526 | - } else if( !empty( $country ) ) { |
|
1527 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1526 | + } else if (!empty($country)) { |
|
1527 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1528 | 1528 | } |
1529 | 1529 | } |
1530 | - } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) { |
|
1531 | - if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) { |
|
1530 | + } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) { |
|
1531 | + if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) { |
|
1532 | 1532 | $rate = $wpinv_options['eu_fallback_rate']; |
1533 | - } else if( !empty( $country ) ) { |
|
1534 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1533 | + } else if (!empty($country)) { |
|
1534 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1535 | 1535 | } |
1536 | 1536 | } |
1537 | 1537 | } else { |
1538 | - if ( $is_digital ) { |
|
1538 | + if ($is_digital) { |
|
1539 | 1539 | $ip_country_code = self::get_country_by_ip(); |
1540 | 1540 | |
1541 | - if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) { |
|
1542 | - $rate = self::find_rate( $ip_country_code, '', 0, $class ); |
|
1541 | + if ($ip_country_code && self::is_eu_state($ip_country_code)) { |
|
1542 | + $rate = self::find_rate($ip_country_code, '', 0, $class); |
|
1543 | 1543 | } else { |
1544 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1544 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1545 | 1545 | } |
1546 | 1546 | } else { |
1547 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1547 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1548 | 1548 | } |
1549 | 1549 | } |
1550 | 1550 | |
@@ -1554,48 +1554,48 @@ discard block |
||
1554 | 1554 | public static function current_vat_data() { |
1555 | 1555 | global $wpi_session; |
1556 | 1556 | |
1557 | - return $wpi_session->get( 'user_vat_data' ); |
|
1557 | + return $wpi_session->get('user_vat_data'); |
|
1558 | 1558 | } |
1559 | 1559 | |
1560 | - public static function get_user_country( $country = '', $user_id = 0 ) { |
|
1561 | - $user_address = wpinv_get_user_address( $user_id, false ); |
|
1560 | + public static function get_user_country($country = '', $user_id = 0) { |
|
1561 | + $user_address = wpinv_get_user_address($user_id, false); |
|
1562 | 1562 | |
1563 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
1563 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
1564 | 1564 | $country = ''; |
1565 | 1565 | } |
1566 | 1566 | |
1567 | - $country = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country']; |
|
1568 | - $result = apply_filters( 'wpinv_get_user_country', $country, $user_id ); |
|
1567 | + $country = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country']; |
|
1568 | + $result = apply_filters('wpinv_get_user_country', $country, $user_id); |
|
1569 | 1569 | |
1570 | - if ( empty( $result ) ) { |
|
1570 | + if (empty($result)) { |
|
1571 | 1571 | $result = self::get_country_by_ip(); |
1572 | 1572 | } |
1573 | 1573 | |
1574 | 1574 | return $result; |
1575 | 1575 | } |
1576 | 1576 | |
1577 | - public static function set_user_country( $country = '', $user_id = 0 ) { |
|
1577 | + public static function set_user_country($country = '', $user_id = 0) { |
|
1578 | 1578 | global $wpi_userID; |
1579 | 1579 | |
1580 | - if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) { |
|
1580 | + if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) { |
|
1581 | 1581 | $country = wpinv_get_default_country(); |
1582 | 1582 | } |
1583 | 1583 | |
1584 | 1584 | return $country; |
1585 | 1585 | } |
1586 | 1586 | |
1587 | - public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) { |
|
1587 | + public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) { |
|
1588 | 1588 | global $wpi_current_id, $wpi_userID; |
1589 | 1589 | |
1590 | - if ( !empty( $_POST['new_user'] ) ) { |
|
1590 | + if (!empty($_POST['new_user'])) { |
|
1591 | 1591 | return ''; |
1592 | 1592 | } |
1593 | 1593 | |
1594 | - if ( empty( $user_id ) ) { |
|
1595 | - $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() ); |
|
1594 | + if (empty($user_id)) { |
|
1595 | + $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id()); |
|
1596 | 1596 | } |
1597 | 1597 | |
1598 | - $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true ); |
|
1598 | + $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true); |
|
1599 | 1599 | |
1600 | 1600 | /* TODO |
1601 | 1601 | if ( $is_valid && $vat_number ) { |
@@ -1606,36 +1606,36 @@ discard block |
||
1606 | 1606 | } |
1607 | 1607 | */ |
1608 | 1608 | |
1609 | - return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid ); |
|
1609 | + return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid); |
|
1610 | 1610 | } |
1611 | 1611 | |
1612 | - public static function get_user_company( $company = '', $user_id = 0 ) { |
|
1613 | - if ( empty( $user_id ) ) { |
|
1612 | + public static function get_user_company($company = '', $user_id = 0) { |
|
1613 | + if (empty($user_id)) { |
|
1614 | 1614 | $user_id = get_current_user_id(); |
1615 | 1615 | } |
1616 | 1616 | |
1617 | - $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true ); |
|
1617 | + $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true); |
|
1618 | 1618 | |
1619 | - return apply_filters( 'wpinv_user_company', $company, $user_id ); |
|
1619 | + return apply_filters('wpinv_user_company', $company, $user_id); |
|
1620 | 1620 | } |
1621 | 1621 | |
1622 | - public static function save_user_vat_details( $company = '', $vat_number = '' ) { |
|
1623 | - $save = apply_filters( 'wpinv_allow_save_user_vat_details', true ); |
|
1622 | + public static function save_user_vat_details($company = '', $vat_number = '') { |
|
1623 | + $save = apply_filters('wpinv_allow_save_user_vat_details', true); |
|
1624 | 1624 | |
1625 | - if ( is_user_logged_in() && $save ) { |
|
1625 | + if (is_user_logged_in() && $save) { |
|
1626 | 1626 | $user_id = get_current_user_id(); |
1627 | 1627 | |
1628 | - if ( !empty( $vat_number ) ) { |
|
1629 | - update_user_meta( $user_id, '_wpinv_vat_number', $vat_number ); |
|
1628 | + if (!empty($vat_number)) { |
|
1629 | + update_user_meta($user_id, '_wpinv_vat_number', $vat_number); |
|
1630 | 1630 | } else { |
1631 | - delete_user_meta( $user_id, '_wpinv_vat_number'); |
|
1631 | + delete_user_meta($user_id, '_wpinv_vat_number'); |
|
1632 | 1632 | } |
1633 | 1633 | |
1634 | - if ( !empty( $company ) ) { |
|
1635 | - update_user_meta( $user_id, '_wpinv_company', $company ); |
|
1634 | + if (!empty($company)) { |
|
1635 | + update_user_meta($user_id, '_wpinv_company', $company); |
|
1636 | 1636 | } else { |
1637 | - delete_user_meta( $user_id, '_wpinv_company'); |
|
1638 | - delete_user_meta( $user_id, '_wpinv_vat_number'); |
|
1637 | + delete_user_meta($user_id, '_wpinv_company'); |
|
1638 | + delete_user_meta($user_id, '_wpinv_vat_number'); |
|
1639 | 1639 | } |
1640 | 1640 | } |
1641 | 1641 | |
@@ -1645,113 +1645,113 @@ discard block |
||
1645 | 1645 | public static function ajax_vat_validate() { |
1646 | 1646 | global $wpinv_options, $wpi_session; |
1647 | 1647 | |
1648 | - $is_checkout = ( !empty( $_POST['source'] ) && $_POST['source'] == 'checkout' ) ? true : false; |
|
1648 | + $is_checkout = (!empty($_POST['source']) && $_POST['source'] == 'checkout') ? true : false; |
|
1649 | 1649 | $response = array(); |
1650 | 1650 | $response['success'] = false; |
1651 | 1651 | |
1652 | - if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) { |
|
1653 | - $response['error'] = __( 'Invalid security nonce', 'invoicing' ); |
|
1654 | - wp_send_json( $response ); |
|
1652 | + if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) { |
|
1653 | + $response['error'] = __('Invalid security nonce', 'invoicing'); |
|
1654 | + wp_send_json($response); |
|
1655 | 1655 | } |
1656 | 1656 | |
1657 | - $vat_name = self::get_vat_name(); |
|
1657 | + $vat_name = self::get_vat_name(); |
|
1658 | 1658 | |
1659 | - if ( $is_checkout ) { |
|
1659 | + if ($is_checkout) { |
|
1660 | 1660 | $invoice = wpinv_get_invoice_cart(); |
1661 | 1661 | |
1662 | - if ( !self::requires_vat( false, 0, self::invoice_has_digital_rule( $invoice ) ) ) { |
|
1662 | + if (!self::requires_vat(false, 0, self::invoice_has_digital_rule($invoice))) { |
|
1663 | 1663 | $vat_info = array(); |
1664 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1664 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1665 | 1665 | |
1666 | 1666 | self::save_user_vat_details(); |
1667 | 1667 | |
1668 | 1668 | $response['success'] = true; |
1669 | - $response['message'] = wp_sprintf( __( 'Ignore %s', 'invoicing' ), $vat_name ); |
|
1670 | - wp_send_json( $response ); |
|
1669 | + $response['message'] = wp_sprintf(__('Ignore %s', 'invoicing'), $vat_name); |
|
1670 | + wp_send_json($response); |
|
1671 | 1671 | } |
1672 | 1672 | } |
1673 | 1673 | |
1674 | - $company = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : ''; |
|
1675 | - $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : ''; |
|
1674 | + $company = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : ''; |
|
1675 | + $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : ''; |
|
1676 | 1676 | |
1677 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
1678 | - if ( !is_array( $vat_info ) || empty( $vat_info ) ) { |
|
1679 | - $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true ); |
|
1677 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
1678 | + if (!is_array($vat_info) || empty($vat_info)) { |
|
1679 | + $vat_info = array('company'=> $company, 'number' => '', 'valid' => true); |
|
1680 | 1680 | } |
1681 | 1681 | |
1682 | - if ( empty( $vat_number ) ) { |
|
1683 | - if ( $is_checkout ) { |
|
1682 | + if (empty($vat_number)) { |
|
1683 | + if ($is_checkout) { |
|
1684 | 1684 | $response['success'] = true; |
1685 | - $response['message'] = wp_sprintf( __( 'No %s number has been applied. %s will be added to invoice totals', 'invoicing' ), $vat_name, $vat_name ); |
|
1685 | + $response['message'] = wp_sprintf(__('No %s number has been applied. %s will be added to invoice totals', 'invoicing'), $vat_name, $vat_name); |
|
1686 | 1686 | |
1687 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
1687 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
1688 | 1688 | $vat_info['number'] = ""; |
1689 | 1689 | $vat_info['valid'] = true; |
1690 | 1690 | |
1691 | - self::save_user_vat_details( $company ); |
|
1691 | + self::save_user_vat_details($company); |
|
1692 | 1692 | } else { |
1693 | - $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name ); |
|
1693 | + $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name); |
|
1694 | 1694 | |
1695 | 1695 | $vat_info['valid'] = false; |
1696 | 1696 | } |
1697 | 1697 | |
1698 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1699 | - wp_send_json( $response ); |
|
1698 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1699 | + wp_send_json($response); |
|
1700 | 1700 | } |
1701 | 1701 | |
1702 | - if ( empty( $company ) ) { |
|
1702 | + if (empty($company)) { |
|
1703 | 1703 | $vat_info['valid'] = false; |
1704 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1704 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1705 | 1705 | |
1706 | - $response['error'] = __( 'Please enter your registered company name!', 'invoicing' ); |
|
1707 | - wp_send_json( $response ); |
|
1706 | + $response['error'] = __('Please enter your registered company name!', 'invoicing'); |
|
1707 | + wp_send_json($response); |
|
1708 | 1708 | } |
1709 | 1709 | |
1710 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
1711 | - if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) { |
|
1710 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
1711 | + if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) { |
|
1712 | 1712 | $vat_info['valid'] = false; |
1713 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1713 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1714 | 1714 | |
1715 | - $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
1716 | - wp_send_json( $response ); |
|
1715 | + $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
1716 | + wp_send_json($response); |
|
1717 | 1717 | } |
1718 | 1718 | |
1719 | 1719 | $response['success'] = true; |
1720 | - $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
1720 | + $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
1721 | 1721 | } else { |
1722 | - $result = self::check_vat( $vat_number ); |
|
1722 | + $result = self::check_vat($vat_number); |
|
1723 | 1723 | |
1724 | - if ( empty( $result['valid'] ) ) { |
|
1724 | + if (empty($result['valid'])) { |
|
1725 | 1725 | $response['error'] = $result['message']; |
1726 | - wp_send_json( $response ); |
|
1726 | + wp_send_json($response); |
|
1727 | 1727 | } |
1728 | 1728 | |
1729 | - $vies_company = !empty( $result['company'] ) ? $result['company'] : ''; |
|
1730 | - $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company ); |
|
1729 | + $vies_company = !empty($result['company']) ? $result['company'] : ''; |
|
1730 | + $vies_company = apply_filters('wpinv_vies_company_name', $vies_company); |
|
1731 | 1731 | |
1732 | - $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false; |
|
1732 | + $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false; |
|
1733 | 1733 | |
1734 | - if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) { |
|
1734 | + if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) { |
|
1735 | 1735 | $response['success'] = true; |
1736 | - $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
1736 | + $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
1737 | 1737 | } else { |
1738 | 1738 | $vat_info['valid'] = false; |
1739 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1739 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1740 | 1740 | |
1741 | 1741 | $response['success'] = false; |
1742 | - $response['message'] = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name ); |
|
1743 | - wp_send_json( $response ); |
|
1742 | + $response['message'] = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name); |
|
1743 | + wp_send_json($response); |
|
1744 | 1744 | } |
1745 | 1745 | } |
1746 | 1746 | |
1747 | - if ( $is_checkout ) { |
|
1748 | - self::save_user_vat_details( $company, $vat_number ); |
|
1747 | + if ($is_checkout) { |
|
1748 | + self::save_user_vat_details($company, $vat_number); |
|
1749 | 1749 | |
1750 | - $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true ); |
|
1751 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1750 | + $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true); |
|
1751 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1752 | 1752 | } |
1753 | 1753 | |
1754 | - wp_send_json( $response ); |
|
1754 | + wp_send_json($response); |
|
1755 | 1755 | } |
1756 | 1756 | |
1757 | 1757 | public static function ajax_vat_reset() { |
@@ -1760,161 +1760,161 @@ discard block |
||
1760 | 1760 | $company = is_user_logged_in() ? self::get_user_company() : ''; |
1761 | 1761 | $vat_number = self::get_user_vat_number(); |
1762 | 1762 | |
1763 | - $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => false ); |
|
1764 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1763 | + $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => false); |
|
1764 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1765 | 1765 | |
1766 | 1766 | $response = array(); |
1767 | 1767 | $response['success'] = true; |
1768 | 1768 | $response['data']['company'] = $company; |
1769 | 1769 | $response['data']['number'] = $vat_number; |
1770 | 1770 | |
1771 | - wp_send_json( $response ); |
|
1771 | + wp_send_json($response); |
|
1772 | 1772 | } |
1773 | 1773 | |
1774 | - public static function checkout_vat_validate( $valid_data, $post ) { |
|
1774 | + public static function checkout_vat_validate($valid_data, $post) { |
|
1775 | 1775 | global $wpinv_options, $wpi_session; |
1776 | 1776 | |
1777 | - $vat_name = __( self::get_vat_name(), 'invoicing' ); |
|
1777 | + $vat_name = __(self::get_vat_name(), 'invoicing'); |
|
1778 | 1778 | |
1779 | - if ( !isset( $_POST['_wpi_nonce'] ) || !wp_verify_nonce( $_POST['_wpi_nonce'], 'vat_validation' ) ) { |
|
1780 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( "Invalid %s validation request.", 'invoicing' ), $vat_name ) ); |
|
1779 | + if (!isset($_POST['_wpi_nonce']) || !wp_verify_nonce($_POST['_wpi_nonce'], 'vat_validation')) { |
|
1780 | + wpinv_set_error('vat_validation', wp_sprintf(__("Invalid %s validation request.", 'invoicing'), $vat_name)); |
|
1781 | 1781 | return; |
1782 | 1782 | } |
1783 | 1783 | |
1784 | - $vat_saved = $wpi_session->get( 'user_vat_data' ); |
|
1785 | - $wpi_session->set( 'user_vat_data', null ); |
|
1784 | + $vat_saved = $wpi_session->get('user_vat_data'); |
|
1785 | + $wpi_session->set('user_vat_data', null); |
|
1786 | 1786 | |
1787 | 1787 | $invoice = wpinv_get_invoice_cart(); |
1788 | 1788 | $amount = $invoice->get_total(); |
1789 | - $is_digital = self::invoice_has_digital_rule( $invoice ); |
|
1790 | - $no_vat = !self::requires_vat( 0, false, $is_digital ); |
|
1789 | + $is_digital = self::invoice_has_digital_rule($invoice); |
|
1790 | + $no_vat = !self::requires_vat(0, false, $is_digital); |
|
1791 | 1791 | |
1792 | - $company = !empty( $_POST['wpinv_company'] ) ? $_POST['wpinv_company'] : null; |
|
1793 | - $vat_number = !empty( $_POST['wpinv_vat_number'] ) ? $_POST['wpinv_vat_number'] : null; |
|
1794 | - $country = !empty( $_POST['wpinv_country'] ) ? $_POST['wpinv_country'] : $invoice->country; |
|
1795 | - if ( empty( $country ) ) { |
|
1792 | + $company = !empty($_POST['wpinv_company']) ? $_POST['wpinv_company'] : null; |
|
1793 | + $vat_number = !empty($_POST['wpinv_vat_number']) ? $_POST['wpinv_vat_number'] : null; |
|
1794 | + $country = !empty($_POST['wpinv_country']) ? $_POST['wpinv_country'] : $invoice->country; |
|
1795 | + if (empty($country)) { |
|
1796 | 1796 | $country = wpinv_default_billing_country(); |
1797 | 1797 | } |
1798 | 1798 | |
1799 | - if ( !$is_digital && $no_vat ) { |
|
1799 | + if (!$is_digital && $no_vat) { |
|
1800 | 1800 | return; |
1801 | 1801 | } |
1802 | 1802 | |
1803 | - $vat_data = array( 'company' => '', 'number' => '', 'valid' => false ); |
|
1803 | + $vat_data = array('company' => '', 'number' => '', 'valid' => false); |
|
1804 | 1804 | |
1805 | 1805 | $ip_country_code = self::get_country_by_ip(); |
1806 | - $is_eu_state = self::is_eu_state( $country ); |
|
1807 | - $is_eu_state_ip = self::is_eu_state( $ip_country_code ); |
|
1806 | + $is_eu_state = self::is_eu_state($country); |
|
1807 | + $is_eu_state_ip = self::is_eu_state($ip_country_code); |
|
1808 | 1808 | $is_non_eu_user = !$is_eu_state && !$is_eu_state_ip; |
1809 | 1809 | |
1810 | - if ( $is_digital && !$is_non_eu_user && empty( $vat_number ) && apply_filters( 'wpinv_checkout_requires_country', true, $amount ) ) { |
|
1810 | + if ($is_digital && !$is_non_eu_user && empty($vat_number) && apply_filters('wpinv_checkout_requires_country', true, $amount)) { |
|
1811 | 1811 | $vat_data['adddress_confirmed'] = false; |
1812 | 1812 | |
1813 | - if ( !isset( $_POST['wpinv_adddress_confirmed'] ) ) { |
|
1814 | - if ( $ip_country_code != $country ) { |
|
1815 | - wpinv_set_error( 'vat_validation', sprintf( __( 'The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing' ), '<a href="#wpinv_adddress_confirm">', '</a>' ) ); |
|
1813 | + if (!isset($_POST['wpinv_adddress_confirmed'])) { |
|
1814 | + if ($ip_country_code != $country) { |
|
1815 | + wpinv_set_error('vat_validation', sprintf(__('The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing'), '<a href="#wpinv_adddress_confirm">', '</a>')); |
|
1816 | 1816 | } |
1817 | 1817 | } else { |
1818 | 1818 | $vat_data['adddress_confirmed'] = true; |
1819 | 1819 | } |
1820 | 1820 | } |
1821 | 1821 | |
1822 | - if ( !empty( $wpinv_options['vat_prevent_b2c_purchase'] ) && !$is_non_eu_user && ( empty( $vat_number ) || $no_vat ) ) { |
|
1823 | - if ( $is_eu_state ) { |
|
1824 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing' ), $vat_name ) ); |
|
1825 | - } else if ( $is_digital && $is_eu_state_ip ) { |
|
1826 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing' ), $vat_name ) ); |
|
1822 | + if (!empty($wpinv_options['vat_prevent_b2c_purchase']) && !$is_non_eu_user && (empty($vat_number) || $no_vat)) { |
|
1823 | + if ($is_eu_state) { |
|
1824 | + wpinv_set_error('vat_validation', wp_sprintf(__('Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing'), $vat_name)); |
|
1825 | + } else if ($is_digital && $is_eu_state_ip) { |
|
1826 | + wpinv_set_error('vat_validation', wp_sprintf(__('Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing'), $vat_name)); |
|
1827 | 1827 | } |
1828 | 1828 | } |
1829 | 1829 | |
1830 | - if ( !$is_eu_state || $no_vat || empty( $vat_number ) ) { |
|
1830 | + if (!$is_eu_state || $no_vat || empty($vat_number)) { |
|
1831 | 1831 | return; |
1832 | 1832 | } |
1833 | 1833 | |
1834 | - if ( !empty( $vat_saved ) && isset( $vat_saved['valid'] ) ) { |
|
1835 | - $vat_data['valid'] = $vat_saved['valid']; |
|
1834 | + if (!empty($vat_saved) && isset($vat_saved['valid'])) { |
|
1835 | + $vat_data['valid'] = $vat_saved['valid']; |
|
1836 | 1836 | } |
1837 | 1837 | |
1838 | - if ( $company !== null ) { |
|
1838 | + if ($company !== null) { |
|
1839 | 1839 | $vat_data['company'] = $company; |
1840 | 1840 | } |
1841 | 1841 | |
1842 | 1842 | $message = ''; |
1843 | - if ( $vat_number !== null ) { |
|
1843 | + if ($vat_number !== null) { |
|
1844 | 1844 | $vat_data['number'] = $vat_number; |
1845 | 1845 | |
1846 | - if ( !$vat_data['valid'] || ( $vat_saved['number'] !== $vat_data['number'] ) || ( $vat_saved['company'] !== $vat_data['company'] ) ) { |
|
1847 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
1848 | - if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) { |
|
1846 | + if (!$vat_data['valid'] || ($vat_saved['number'] !== $vat_data['number']) || ($vat_saved['company'] !== $vat_data['company'])) { |
|
1847 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
1848 | + if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) { |
|
1849 | 1849 | $vat_data['valid'] = false; |
1850 | 1850 | } |
1851 | 1851 | } else { |
1852 | - $result = self::check_vat( $vat_number ); |
|
1852 | + $result = self::check_vat($vat_number); |
|
1853 | 1853 | |
1854 | - if ( !empty( $result['valid'] ) ) { |
|
1854 | + if (!empty($result['valid'])) { |
|
1855 | 1855 | $vat_data['valid'] = true; |
1856 | - $vies_company = !empty( $result['company'] ) ? $result['company'] : ''; |
|
1857 | - $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company ); |
|
1856 | + $vies_company = !empty($result['company']) ? $result['company'] : ''; |
|
1857 | + $vies_company = apply_filters('wpinv_vies_company_name', $vies_company); |
|
1858 | 1858 | |
1859 | - $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false; |
|
1859 | + $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false; |
|
1860 | 1860 | |
1861 | - if ( !( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) ) { |
|
1861 | + if (!(!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company)) { |
|
1862 | 1862 | $vat_data['valid'] = false; |
1863 | 1863 | |
1864 | - $message = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name ); |
|
1864 | + $message = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name); |
|
1865 | 1865 | } |
1866 | 1866 | } else { |
1867 | - $message = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name ); |
|
1867 | + $message = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name); |
|
1868 | 1868 | } |
1869 | 1869 | } |
1870 | 1870 | |
1871 | - if ( !$vat_data['valid'] ) { |
|
1872 | - $error = wp_sprintf( __( 'The %s %s number %s you have entered has not been validated', 'invoicing' ), '<a href="#wpi-vat-details">', $vat_name, '</a>' ) . ( $message ? ' ( ' . $message . ' )' : '' ); |
|
1873 | - wpinv_set_error( 'vat_validation', $error ); |
|
1871 | + if (!$vat_data['valid']) { |
|
1872 | + $error = wp_sprintf(__('The %s %s number %s you have entered has not been validated', 'invoicing'), '<a href="#wpi-vat-details">', $vat_name, '</a>') . ($message ? ' ( ' . $message . ' )' : ''); |
|
1873 | + wpinv_set_error('vat_validation', $error); |
|
1874 | 1874 | } |
1875 | 1875 | } |
1876 | 1876 | } |
1877 | 1877 | |
1878 | - $wpi_session->set( 'user_vat_data', $vat_data ); |
|
1878 | + $wpi_session->set('user_vat_data', $vat_data); |
|
1879 | 1879 | } |
1880 | 1880 | |
1881 | - public static function checkout_vat_fields( $billing_details ) { |
|
1881 | + public static function checkout_vat_fields($billing_details) { |
|
1882 | 1882 | global $wpi_session, $wpinv_options, $wpi_country, $wpi_requires_vat; |
1883 | 1883 | |
1884 | 1884 | $ip_address = wpinv_get_ip(); |
1885 | 1885 | $ip_country_code = self::get_country_by_ip(); |
1886 | 1886 | |
1887 | - $tax_label = __( self::get_vat_name(), 'invoicing' ); |
|
1887 | + $tax_label = __(self::get_vat_name(), 'invoicing'); |
|
1888 | 1888 | $invoice = wpinv_get_invoice_cart(); |
1889 | - $is_digital = self::invoice_has_digital_rule( $invoice ); |
|
1889 | + $is_digital = self::invoice_has_digital_rule($invoice); |
|
1890 | 1890 | $wpi_country = $invoice->country; |
1891 | 1891 | |
1892 | - $requires_vat = !self::hide_vat_fields() && $invoice->get_total() > 0 && self::requires_vat( 0, false, $is_digital ); |
|
1892 | + $requires_vat = !self::hide_vat_fields() && $invoice->get_total() > 0 && self::requires_vat(0, false, $is_digital); |
|
1893 | 1893 | $wpi_requires_vat = $requires_vat; |
1894 | 1894 | |
1895 | 1895 | $company = is_user_logged_in() ? self::get_user_company() : ''; |
1896 | 1896 | $vat_number = self::get_user_vat_number(); |
1897 | 1897 | |
1898 | - $validated = $vat_number ? self::get_user_vat_number( '', 0, true ) : 1; |
|
1899 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
1898 | + $validated = $vat_number ? self::get_user_vat_number('', 0, true) : 1; |
|
1899 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
1900 | 1900 | |
1901 | - if ( is_array( $vat_info ) ) { |
|
1902 | - $company = isset( $vat_info['company'] ) ? $vat_info['company'] : ''; |
|
1903 | - $vat_number = isset( $vat_info['number'] ) ? $vat_info['number'] : ''; |
|
1904 | - $validated = isset( $vat_info['valid'] ) ? $vat_info['valid'] : false; |
|
1901 | + if (is_array($vat_info)) { |
|
1902 | + $company = isset($vat_info['company']) ? $vat_info['company'] : ''; |
|
1903 | + $vat_number = isset($vat_info['number']) ? $vat_info['number'] : ''; |
|
1904 | + $validated = isset($vat_info['valid']) ? $vat_info['valid'] : false; |
|
1905 | 1905 | } |
1906 | 1906 | |
1907 | 1907 | $selected_country = $invoice->country ? $invoice->country : wpinv_default_billing_country(); |
1908 | 1908 | |
1909 | - if ( $ip_country_code == 'UK' ) { |
|
1909 | + if ($ip_country_code == 'UK') { |
|
1910 | 1910 | $ip_country_code = 'GB'; |
1911 | 1911 | } |
1912 | 1912 | |
1913 | - if ( $selected_country == 'UK' ) { |
|
1913 | + if ($selected_country == 'UK') { |
|
1914 | 1914 | $selected_country = 'GB'; |
1915 | 1915 | } |
1916 | 1916 | |
1917 | - if ( self::same_country_rule() == 'no' && wpinv_is_base_country( $selected_country ) ) { |
|
1917 | + if (self::same_country_rule() == 'no' && wpinv_is_base_country($selected_country)) { |
|
1918 | 1918 | $requires_vat = false; |
1919 | 1919 | } |
1920 | 1920 | |
@@ -1922,52 +1922,52 @@ discard block |
||
1922 | 1922 | $display_validate_btn = 'none'; |
1923 | 1923 | $display_reset_btn = 'none'; |
1924 | 1924 | |
1925 | - if ( !empty( $vat_number ) && $validated ) { |
|
1926 | - $vat_vailidated_text = wp_sprintf( __( '%s number validated', 'invoicing' ), $tax_label ); |
|
1925 | + if (!empty($vat_number) && $validated) { |
|
1926 | + $vat_vailidated_text = wp_sprintf(__('%s number validated', 'invoicing'), $tax_label); |
|
1927 | 1927 | $vat_vailidated_class = 'wpinv-vat-stat-1'; |
1928 | 1928 | $display_reset_btn = 'block'; |
1929 | 1929 | } else { |
1930 | - $vat_vailidated_text = empty( $vat_number ) ? '' : wp_sprintf( __( '%s number not validated', 'invoicing' ), $tax_label ); |
|
1931 | - $vat_vailidated_class = empty( $vat_number ) ? '' : 'wpinv-vat-stat-0'; |
|
1930 | + $vat_vailidated_text = empty($vat_number) ? '' : wp_sprintf(__('%s number not validated', 'invoicing'), $tax_label); |
|
1931 | + $vat_vailidated_class = empty($vat_number) ? '' : 'wpinv-vat-stat-0'; |
|
1932 | 1932 | $display_validate_btn = 'block'; |
1933 | 1933 | } |
1934 | 1934 | |
1935 | - $show_ip_country = $is_digital && ( empty( $vat_number ) || !$requires_vat ) && $ip_country_code != $selected_country ? 'block' : 'none'; |
|
1935 | + $show_ip_country = $is_digital && (empty($vat_number) || !$requires_vat) && $ip_country_code != $selected_country ? 'block' : 'none'; |
|
1936 | 1936 | ?> |
1937 | 1937 | <div id="wpi-vat-details" class="wpi-vat-details clearfix" style="display:<?php echo $display_vat_details; ?>"> |
1938 | 1938 | <div id="wpi_vat_info" class="clearfix panel panel-default"> |
1939 | - <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf( __( '%s Details', 'invoicing' ), $tax_label );?></h3></div> |
|
1939 | + <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf(__('%s Details', 'invoicing'), $tax_label); ?></h3></div> |
|
1940 | 1940 | <div id="wpinv-fields-box" class="panel-body"> |
1941 | 1941 | <p id="wpi_show_vat_note"> |
1942 | - <?php echo wp_sprintf( __( 'Validate your registered %s number to exclude tax.', 'invoicing' ), $tax_label ); ?> |
|
1942 | + <?php echo wp_sprintf(__('Validate your registered %s number to exclude tax.', 'invoicing'), $tax_label); ?> |
|
1943 | 1943 | </p> |
1944 | 1944 | <div id="wpi_vat_fields" class="wpi_vat_info"> |
1945 | 1945 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1946 | - <label for="wpinv_company" class="wpi-label"><?php _e( 'Company Name', 'invoicing' );?></label> |
|
1946 | + <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label> |
|
1947 | 1947 | <?php |
1948 | - echo wpinv_html_text( array( |
|
1948 | + echo wpinv_html_text(array( |
|
1949 | 1949 | 'id' => 'wpinv_company', |
1950 | 1950 | 'name' => 'wpinv_company', |
1951 | 1951 | 'value' => $company, |
1952 | 1952 | 'class' => 'wpi-input form-control', |
1953 | - 'placeholder' => __( 'Company name', 'invoicing' ), |
|
1954 | - ) ); |
|
1953 | + 'placeholder' => __('Company name', 'invoicing'), |
|
1954 | + )); |
|
1955 | 1955 | ?> |
1956 | 1956 | </p> |
1957 | 1957 | <p class="wpi-cart-field wpi-col2 wpi-coll wpi-cart-field-vat"> |
1958 | - <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf( __( '%s Number', 'invoicing' ), $tax_label );?></label> |
|
1958 | + <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf(__('%s Number', 'invoicing'), $tax_label); ?></label> |
|
1959 | 1959 | <span id="wpinv_vat_number-wrap"> |
1960 | 1960 | <label for="wpinv_vat_number" class="wpinv-label"></label> |
1961 | - <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr( wp_sprintf( __( '%s number', 'invoicing' ), $tax_label ) );?>" value="<?php esc_attr_e( $vat_number );?>" id="wpinv_vat_number" name="wpinv_vat_number"> |
|
1962 | - <span class="wpinv-vat-stat <?php echo $vat_vailidated_class;?>"><i class="fa"></i> <font><?php echo $vat_vailidated_text;?></font></span> |
|
1961 | + <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr(wp_sprintf(__('%s number', 'invoicing'), $tax_label)); ?>" value="<?php esc_attr_e($vat_number); ?>" id="wpinv_vat_number" name="wpinv_vat_number"> |
|
1962 | + <span class="wpinv-vat-stat <?php echo $vat_vailidated_class; ?>"><i class="fa"></i> <font><?php echo $vat_vailidated_text; ?></font></span> |
|
1963 | 1963 | </span> |
1964 | 1964 | </p> |
1965 | 1965 | <p class="wpi-cart-field wpi-col wpi-colf wpi-cart-field-actions"> |
1966 | - <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf( __("Validate %s Number", 'invoicing'), $tax_label ); ?></button> |
|
1967 | - <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf( __("Reset %s", 'invoicing'), $tax_label ); ?></button> |
|
1966 | + <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf(__("Validate %s Number", 'invoicing'), $tax_label); ?></button> |
|
1967 | + <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf(__("Reset %s", 'invoicing'), $tax_label); ?></button> |
|
1968 | 1968 | <span class="wpi-vat-box wpi-vat-box-info"><span id="text"></span></span> |
1969 | 1969 | <span class="wpi-vat-box wpi-vat-box-error"><span id="text"></span></span> |
1970 | - <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce( 'vat_validation' ) ?>" /> |
|
1970 | + <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce('vat_validation') ?>" /> |
|
1971 | 1971 | </p> |
1972 | 1972 | </div> |
1973 | 1973 | </div> |
@@ -1981,32 +1981,32 @@ discard block |
||
1981 | 1981 | </span> |
1982 | 1982 | </div> |
1983 | 1983 | </div> |
1984 | - <?php if ( empty( $wpinv_options['hide_ip_address'] ) ) { |
|
1985 | - $ip_link = '<a title="' . esc_attr( __( 'View more details on map', 'invoicing' ) ) . '" target="_blank" href="' . esc_url( admin_url( 'admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address ) ) . '" class="wpi-ip-address-link">' . $ip_address . ' <i class="fa fa-external-link-square" aria-hidden="true"></i></a>'; |
|
1984 | + <?php if (empty($wpinv_options['hide_ip_address'])) { |
|
1985 | + $ip_link = '<a title="' . esc_attr(__('View more details on map', 'invoicing')) . '" target="_blank" href="' . esc_url(admin_url('admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address)) . '" class="wpi-ip-address-link">' . $ip_address . ' <i class="fa fa-external-link-square" aria-hidden="true"></i></a>'; |
|
1986 | 1986 | ?> |
1987 | 1987 | <div class="wpi-ip-info clearfix panel panel-info"> |
1988 | 1988 | <div id="wpinv-fields-box" class="panel-body"> |
1989 | - <span><?php echo wp_sprintf( __( "Your IP address is: %s", 'invoicing' ), $ip_link ); ?></span> |
|
1989 | + <span><?php echo wp_sprintf(__("Your IP address is: %s", 'invoicing'), $ip_link); ?></span> |
|
1990 | 1990 | </div> |
1991 | 1991 | </div> |
1992 | 1992 | <?php } |
1993 | 1993 | } |
1994 | 1994 | |
1995 | - public static function show_vat_notice( $invoice ) { |
|
1996 | - if ( empty( $invoice ) ) { |
|
1995 | + public static function show_vat_notice($invoice) { |
|
1996 | + if (empty($invoice)) { |
|
1997 | 1997 | return NULL; |
1998 | 1998 | } |
1999 | 1999 | |
2000 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
2001 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
2002 | - if ( $label || $notice ) { |
|
2000 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
2001 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
2002 | + if ($label || $notice) { |
|
2003 | 2003 | ?> |
2004 | 2004 | <div class="row wpinv-vat-notice"> |
2005 | 2005 | <div class="col-sm-12"> |
2006 | - <?php if ( $label ) { ?> |
|
2007 | - <strong><?php _e( $label, 'invoicing' ); ?></strong> |
|
2008 | - <?php } if ( $notice ) { ?> |
|
2009 | - <?php echo wpautop( wptexturize( __( $notice, 'invoicing' ) ) ) ?> |
|
2006 | + <?php if ($label) { ?> |
|
2007 | + <strong><?php _e($label, 'invoicing'); ?></strong> |
|
2008 | + <?php } if ($notice) { ?> |
|
2009 | + <?php echo wpautop(wptexturize(__($notice, 'invoicing'))) ?> |
|
2010 | 2010 | <?php } ?> |
2011 | 2011 | </div> |
2012 | 2012 | </div> |
@@ -21,10 +21,10 @@ discard block |
||
21 | 21 | * @param array $args |
22 | 22 | * @param array $assoc_args |
23 | 23 | */ |
24 | - public function count( $args, $assoc_args ) { |
|
24 | + public function count($args, $assoc_args) { |
|
25 | 25 | $sessions = WP_Session_Utils::count_sessions(); |
26 | 26 | |
27 | - \WP_CLI::line( sprintf( '%d sessions currently exist.', absint( $sessions ) ) ); |
|
27 | + \WP_CLI::line(sprintf('%d sessions currently exist.', absint($sessions))); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -53,14 +53,14 @@ discard block |
||
53 | 53 | * @param array $args |
54 | 54 | * @param array $assoc_args |
55 | 55 | */ |
56 | - public function delete( $args, $assoc_args ) { |
|
57 | - if ( isset( $assoc_args['limit'] ) ) { |
|
58 | - $limit = absint( $assoc_args['limit'] ); |
|
56 | + public function delete($args, $assoc_args) { |
|
57 | + if (isset($assoc_args['limit'])) { |
|
58 | + $limit = absint($assoc_args['limit']); |
|
59 | 59 | |
60 | - $count = WP_Session_Utils::delete_old_sessions( $limit ); |
|
60 | + $count = WP_Session_Utils::delete_old_sessions($limit); |
|
61 | 61 | |
62 | - if ( $count > 0 ) { |
|
63 | - \WP_CLI::line( sprintf( 'Deleted %d sessions.', $count ) ); |
|
62 | + if ($count > 0) { |
|
63 | + \WP_CLI::line(sprintf('Deleted %d sessions.', $count)); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | // Clear memory |
@@ -69,32 +69,32 @@ discard block |
||
69 | 69 | } |
70 | 70 | |
71 | 71 | // Determine if we're deleting all sessions or just a subset. |
72 | - $all = isset( $assoc_args['all'] ); |
|
72 | + $all = isset($assoc_args['all']); |
|
73 | 73 | |
74 | 74 | /** |
75 | 75 | * Determine the size of each batch for deletion. |
76 | 76 | * |
77 | 77 | * @param int |
78 | 78 | */ |
79 | - $batch = isset( $assoc_args['batch'] ) ? absint( $assoc_args['batch'] ) : apply_filters( 'wp_session_delete_batch_size', 1000 ); |
|
79 | + $batch = isset($assoc_args['batch']) ? absint($assoc_args['batch']) : apply_filters('wp_session_delete_batch_size', 1000); |
|
80 | 80 | |
81 | - switch ( $all ) { |
|
81 | + switch ($all) { |
|
82 | 82 | case true: |
83 | 83 | $count = WP_Session_Utils::delete_all_sessions(); |
84 | 84 | |
85 | - \WP_CLI::line( sprintf( 'Deleted all %d sessions.', $count ) ); |
|
85 | + \WP_CLI::line(sprintf('Deleted all %d sessions.', $count)); |
|
86 | 86 | break; |
87 | 87 | case false: |
88 | 88 | do { |
89 | - $count = WP_Session_Utils::delete_old_sessions( $batch ); |
|
89 | + $count = WP_Session_Utils::delete_old_sessions($batch); |
|
90 | 90 | |
91 | - if ( $count > 0 ) { |
|
92 | - \WP_CLI::line( sprintf( 'Deleted %d sessions.', $count ) ); |
|
91 | + if ($count > 0) { |
|
92 | + \WP_CLI::line(sprintf('Deleted %d sessions.', $count)); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | // Clear memory |
96 | 96 | self::free_up_memory(); |
97 | - } while ( $count > 0 ); |
|
97 | + } while ($count > 0); |
|
98 | 98 | break; |
99 | 99 | } |
100 | 100 | } |
@@ -120,14 +120,14 @@ discard block |
||
120 | 120 | * @param array $args |
121 | 121 | * @param array $assoc_args |
122 | 122 | */ |
123 | - public function generate( $args, $assoc_args ) { |
|
124 | - $count = absint( $args[0] ); |
|
125 | - $date = isset( $assoc_args['expires'] ) ? $assoc_args['expires'] : null; |
|
123 | + public function generate($args, $assoc_args) { |
|
124 | + $count = absint($args[0]); |
|
125 | + $date = isset($assoc_args['expires']) ? $assoc_args['expires'] : null; |
|
126 | 126 | |
127 | - $notify = \WP_CLI\Utils\make_progress_bar( 'Generating sessions', $count ); |
|
127 | + $notify = \WP_CLI\Utils\make_progress_bar('Generating sessions', $count); |
|
128 | 128 | |
129 | - for ( $i = 0; $i < $count; $i ++ ) { |
|
130 | - WP_Session_Utils::create_dummy_session( $date ); |
|
129 | + for ($i = 0; $i < $count; $i++) { |
|
130 | + WP_Session_Utils::create_dummy_session($date); |
|
131 | 131 | $notify->tick(); |
132 | 132 | } |
133 | 133 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | global $wp_object_cache, $wpdb; |
145 | 145 | $wpdb->queries = array(); |
146 | 146 | |
147 | - if ( ! is_object( $wp_object_cache ) ) { |
|
147 | + if (!is_object($wp_object_cache)) { |
|
148 | 148 | return; |
149 | 149 | } |
150 | 150 | |
@@ -155,4 +155,4 @@ discard block |
||
155 | 155 | } |
156 | 156 | } |
157 | 157 | |
158 | -\WP_CLI::add_command( 'session', 'WP_Session_Command' ); |
|
159 | 158 | \ No newline at end of file |
159 | +\WP_CLI::add_command('session', 'WP_Session_Command'); |
|
160 | 160 | \ No newline at end of file |
@@ -33,10 +33,10 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @param string $data |
35 | 35 | */ |
36 | -function wp_session_decode( $data ) { |
|
36 | +function wp_session_decode($data) { |
|
37 | 37 | $wp_session = WP_Session::get_instance(); |
38 | 38 | |
39 | - return $wp_session->json_in( $data ); |
|
39 | + return $wp_session->json_in($data); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -57,10 +57,10 @@ discard block |
||
57 | 57 | * |
58 | 58 | * @return bool |
59 | 59 | */ |
60 | -function wp_session_regenerate_id( $delete_old_session = false ) { |
|
60 | +function wp_session_regenerate_id($delete_old_session = false) { |
|
61 | 61 | $wp_session = WP_Session::get_instance(); |
62 | 62 | |
63 | - $wp_session->regenerate_id( $delete_old_session ); |
|
63 | + $wp_session->regenerate_id($delete_old_session); |
|
64 | 64 | |
65 | 65 | return true; |
66 | 66 | } |
@@ -74,12 +74,12 @@ discard block |
||
74 | 74 | */ |
75 | 75 | function wp_session_start() { |
76 | 76 | $wp_session = WP_Session::get_instance(); |
77 | - do_action( 'wp_session_start' ); |
|
77 | + do_action('wp_session_start'); |
|
78 | 78 | |
79 | 79 | return $wp_session->session_started(); |
80 | 80 | } |
81 | -if ( ! defined( 'WP_CLI' ) || false === WP_CLI ) { |
|
82 | - add_action( 'plugins_loaded', 'wp_session_start' ); |
|
81 | +if (!defined('WP_CLI') || false === WP_CLI) { |
|
82 | + add_action('plugins_loaded', 'wp_session_start'); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | function wp_session_status() { |
91 | 91 | $wp_session = WP_Session::get_instance(); |
92 | 92 | |
93 | - if ( $wp_session->session_started() ) { |
|
93 | + if ($wp_session->session_started()) { |
|
94 | 94 | return PHP_SESSION_ACTIVE; |
95 | 95 | } |
96 | 96 | |
@@ -113,10 +113,10 @@ discard block |
||
113 | 113 | $wp_session = WP_Session::get_instance(); |
114 | 114 | |
115 | 115 | $wp_session->write_data(); |
116 | - do_action( 'wp_session_commit' ); |
|
116 | + do_action('wp_session_commit'); |
|
117 | 117 | } |
118 | -if ( ! defined( 'WP_CLI' ) || false === WP_CLI ) { |
|
119 | - add_action( 'shutdown', 'wp_session_write_close' ); |
|
118 | +if (!defined('WP_CLI') || false === WP_CLI) { |
|
119 | + add_action('shutdown', 'wp_session_write_close'); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -127,33 +127,33 @@ discard block |
||
127 | 127 | * of a scheduled task or cron job. |
128 | 128 | */ |
129 | 129 | function wp_session_cleanup() { |
130 | - if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
130 | + if (defined('WP_SETUP_CONFIG')) { |
|
131 | 131 | return; |
132 | 132 | } |
133 | 133 | |
134 | - if ( ! defined( 'WP_INSTALLING' ) ) { |
|
134 | + if (!defined('WP_INSTALLING')) { |
|
135 | 135 | /** |
136 | 136 | * Determine the size of each batch for deletion. |
137 | 137 | * |
138 | 138 | * @param int |
139 | 139 | */ |
140 | - $batch_size = apply_filters( 'wp_session_delete_batch_size', 1000 ); |
|
140 | + $batch_size = apply_filters('wp_session_delete_batch_size', 1000); |
|
141 | 141 | |
142 | 142 | // Delete a batch of old sessions |
143 | - WP_Session_Utils::delete_old_sessions( $batch_size ); |
|
143 | + WP_Session_Utils::delete_old_sessions($batch_size); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | // Allow other plugins to hook in to the garbage collection process. |
147 | - do_action( 'wp_session_cleanup' ); |
|
147 | + do_action('wp_session_cleanup'); |
|
148 | 148 | } |
149 | -add_action( 'wp_session_garbage_collection', 'wp_session_cleanup' ); |
|
149 | +add_action('wp_session_garbage_collection', 'wp_session_cleanup'); |
|
150 | 150 | |
151 | 151 | /** |
152 | 152 | * Register the garbage collector as a twice daily event. |
153 | 153 | */ |
154 | 154 | function wp_session_register_garbage_collection() { |
155 | - if ( ! wp_next_scheduled( 'wp_session_garbage_collection' ) ) { |
|
156 | - wp_schedule_event( time(), 'hourly', 'wp_session_garbage_collection' ); |
|
155 | + if (!wp_next_scheduled('wp_session_garbage_collection')) { |
|
156 | + wp_schedule_event(time(), 'hourly', 'wp_session_garbage_collection'); |
|
157 | 157 | } |
158 | 158 | } |
159 | -add_action( 'wp', 'wp_session_register_garbage_collection' ); |
|
159 | +add_action('wp', 'wp_session_register_garbage_collection'); |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @return bool|WP_Session |
54 | 54 | */ |
55 | 55 | public static function get_instance() { |
56 | - if ( ! self::$instance ) { |
|
56 | + if (!self::$instance) { |
|
57 | 57 | self::$instance = new self(); |
58 | 58 | } |
59 | 59 | |
@@ -69,19 +69,19 @@ discard block |
||
69 | 69 | * @uses apply_filters Calls `wp_session_expiration` to determine how long until sessions expire. |
70 | 70 | */ |
71 | 71 | protected function __construct() { |
72 | - if ( isset( $_COOKIE[WP_SESSION_COOKIE] ) ) { |
|
73 | - $cookie = stripslashes( $_COOKIE[WP_SESSION_COOKIE] ); |
|
74 | - $cookie_crumbs = explode( '||', $cookie ); |
|
72 | + if (isset($_COOKIE[WP_SESSION_COOKIE])) { |
|
73 | + $cookie = stripslashes($_COOKIE[WP_SESSION_COOKIE]); |
|
74 | + $cookie_crumbs = explode('||', $cookie); |
|
75 | 75 | |
76 | - $this->session_id = preg_replace("/[^A-Za-z0-9_]/", '', $cookie_crumbs[0] ); |
|
77 | - $this->expires = absint( $cookie_crumbs[1] ); |
|
78 | - $this->exp_variant = absint( $cookie_crumbs[2] ); |
|
76 | + $this->session_id = preg_replace("/[^A-Za-z0-9_]/", '', $cookie_crumbs[0]); |
|
77 | + $this->expires = absint($cookie_crumbs[1]); |
|
78 | + $this->exp_variant = absint($cookie_crumbs[2]); |
|
79 | 79 | |
80 | 80 | // Update the session expiration if we're past the variant time |
81 | - if ( time() > $this->exp_variant ) { |
|
81 | + if (time() > $this->exp_variant) { |
|
82 | 82 | $this->set_expiration(); |
83 | - delete_option( "_wp_session_expires_{$this->session_id}" ); |
|
84 | - add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' ); |
|
83 | + delete_option("_wp_session_expires_{$this->session_id}"); |
|
84 | + add_option("_wp_session_expires_{$this->session_id}", $this->expires, '', 'no'); |
|
85 | 85 | } |
86 | 86 | } else { |
87 | 87 | $this->session_id = WP_Session_Utils::generate_id(); |
@@ -113,8 +113,8 @@ discard block |
||
113 | 113 | * @uses apply_filters Calls `wp_session_expiration` to get the standard expiration time for sessions. |
114 | 114 | */ |
115 | 115 | protected function set_expiration() { |
116 | - $this->exp_variant = time() + (int) apply_filters( 'wp_session_expiration_variant', 24 * 60 ); |
|
117 | - $this->expires = time() + (int) apply_filters( 'wp_session_expiration', 30 * 60 ); |
|
116 | + $this->exp_variant = time() + (int)apply_filters('wp_session_expiration_variant', 24 * 60); |
|
117 | + $this->expires = time() + (int)apply_filters('wp_session_expiration', 30 * 60); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -123,13 +123,13 @@ discard block |
||
123 | 123 | * @uses apply_filters Calls `wp_session_cookie_httponly` to set the $httponly parameter of setcookie() |
124 | 124 | */ |
125 | 125 | protected function set_cookie() { |
126 | - if ( !defined( 'WPI_TESTING_MODE' ) ) { |
|
126 | + if (!defined('WPI_TESTING_MODE')) { |
|
127 | 127 | try { |
128 | 128 | $secure = apply_filters('wp_session_cookie_secure', false); |
129 | 129 | $httponly = apply_filters('wp_session_cookie_httponly', false); |
130 | - setcookie( WP_SESSION_COOKIE, $this->session_id . '||' . $this->expires . '||' . $this->exp_variant , $this->expires, COOKIEPATH, COOKIE_DOMAIN, $secure, $httponly ); |
|
131 | - } catch(Exception $e) { |
|
132 | - error_log( 'Set Cookie Error: ' . $e->getMessage() ); |
|
130 | + setcookie(WP_SESSION_COOKIE, $this->session_id . '||' . $this->expires . '||' . $this->exp_variant, $this->expires, COOKIEPATH, COOKIE_DOMAIN, $secure, $httponly); |
|
131 | + } catch (Exception $e) { |
|
132 | + error_log('Set Cookie Error: ' . $e->getMessage()); |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | } |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @return array |
143 | 143 | */ |
144 | 144 | protected function read_data() { |
145 | - $this->container = get_option( "_wp_session_{$this->session_id}", array() ); |
|
145 | + $this->container = get_option("_wp_session_{$this->session_id}", array()); |
|
146 | 146 | |
147 | 147 | return $this->container; |
148 | 148 | } |
@@ -153,12 +153,12 @@ discard block |
||
153 | 153 | public function write_data() { |
154 | 154 | $option_key = "_wp_session_{$this->session_id}"; |
155 | 155 | |
156 | - if ( false === get_option( $option_key ) ) { |
|
157 | - add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' ); |
|
158 | - add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' ); |
|
156 | + if (false === get_option($option_key)) { |
|
157 | + add_option("_wp_session_{$this->session_id}", $this->container, '', 'no'); |
|
158 | + add_option("_wp_session_expires_{$this->session_id}", $this->expires, '', 'no'); |
|
159 | 159 | } else { |
160 | - delete_option( "_wp_session_{$this->session_id}" ); |
|
161 | - add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' ); |
|
160 | + delete_option("_wp_session_{$this->session_id}"); |
|
161 | + add_option("_wp_session_{$this->session_id}", $this->container, '', 'no'); |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * @return string |
169 | 169 | */ |
170 | 170 | public function json_out() { |
171 | - return json_encode( $this->container ); |
|
171 | + return json_encode($this->container); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | * |
179 | 179 | * @return bool |
180 | 180 | */ |
181 | - public function json_in( $data ) { |
|
182 | - $array = json_decode( $data ); |
|
181 | + public function json_in($data) { |
|
182 | + $array = json_decode($data); |
|
183 | 183 | |
184 | - if ( is_array( $array ) ) { |
|
184 | + if (is_array($array)) { |
|
185 | 185 | $this->container = $array; |
186 | 186 | return true; |
187 | 187 | } |
@@ -194,9 +194,9 @@ discard block |
||
194 | 194 | * |
195 | 195 | * @param bool $delete_old Flag whether or not to delete the old session data from the server. |
196 | 196 | */ |
197 | - public function regenerate_id( $delete_old = false ) { |
|
198 | - if ( $delete_old ) { |
|
199 | - delete_option( "_wp_session_{$this->session_id}" ); |
|
197 | + public function regenerate_id($delete_old = false) { |
|
198 | + if ($delete_old) { |
|
199 | + delete_option("_wp_session_{$this->session_id}"); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | $this->session_id = WP_Session_Utils::generate_id(); |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @param array $data |
38 | 38 | */ |
39 | - protected function __construct( $data = array() ) { |
|
40 | - foreach ( $data as $key => $value ) { |
|
41 | - $this[ $key ] = $value; |
|
39 | + protected function __construct($data = array()) { |
|
40 | + foreach ($data as $key => $value) { |
|
41 | + $this[$key] = $value; |
|
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
@@ -46,9 +46,9 @@ discard block |
||
46 | 46 | * Allow deep copies of objects |
47 | 47 | */ |
48 | 48 | public function __clone() { |
49 | - foreach ( $this->container as $key => $value ) { |
|
50 | - if ( $value instanceof self ) { |
|
51 | - $this[ $key ] = clone $value; |
|
49 | + foreach ($this->container as $key => $value) { |
|
50 | + if ($value instanceof self) { |
|
51 | + $this[$key] = clone $value; |
|
52 | 52 | } |
53 | 53 | } |
54 | 54 | } |
@@ -60,9 +60,9 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function toArray() { |
62 | 62 | $data = $this->container; |
63 | - foreach ( $data as $key => $value ) { |
|
64 | - if ( $value instanceof self ) { |
|
65 | - $data[ $key ] = $value->toArray(); |
|
63 | + foreach ($data as $key => $value) { |
|
64 | + if ($value instanceof self) { |
|
65 | + $data[$key] = $value->toArray(); |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 | return $data; |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | * |
82 | 82 | * @return boolean true on success or false on failure. |
83 | 83 | */ |
84 | - public function offsetExists( $offset ) { |
|
85 | - return isset( $this->container[ $offset ]) ; |
|
84 | + public function offsetExists($offset) { |
|
85 | + return isset($this->container[$offset]); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @return mixed Can return all value types. |
96 | 96 | */ |
97 | - public function offsetGet( $offset ) { |
|
98 | - return isset( $this->container[ $offset ] ) ? $this->container[ $offset ] : null; |
|
97 | + public function offsetGet($offset) { |
|
98 | + return isset($this->container[$offset]) ? $this->container[$offset] : null; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -108,14 +108,14 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @return void |
110 | 110 | */ |
111 | - public function offsetSet( $offset, $data ) { |
|
112 | - if ( is_array( $data ) ) { |
|
113 | - $data = new self( $data ); |
|
111 | + public function offsetSet($offset, $data) { |
|
112 | + if (is_array($data)) { |
|
113 | + $data = new self($data); |
|
114 | 114 | } |
115 | - if ( $offset === null ) { // don't forget this! |
|
115 | + if ($offset === null) { // don't forget this! |
|
116 | 116 | $this->container[] = $data; |
117 | 117 | } else { |
118 | - $this->container[ $offset ] = $data; |
|
118 | + $this->container[$offset] = $data; |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | $this->dirty = true; |
@@ -130,8 +130,8 @@ discard block |
||
130 | 130 | * |
131 | 131 | * @return void |
132 | 132 | */ |
133 | - public function offsetUnset( $offset ) { |
|
134 | - unset( $this->container[ $offset ] ); |
|
133 | + public function offsetUnset($offset) { |
|
134 | + unset($this->container[$offset]); |
|
135 | 135 | |
136 | 136 | $this->dirty = true; |
137 | 137 | } |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @return mixed |
150 | 150 | */ |
151 | 151 | public function current() { |
152 | - return current( $this->container ); |
|
152 | + return current($this->container); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | * @return mixed |
161 | 161 | */ |
162 | 162 | public function key() { |
163 | - return key( $this->container ); |
|
163 | + return key($this->container); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | * @return void |
172 | 172 | */ |
173 | 173 | public function next() { |
174 | - next( $this->container ); |
|
174 | + next($this->container); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * @return void |
183 | 183 | */ |
184 | 184 | public function rewind() { |
185 | - reset( $this->container ); |
|
185 | + reset($this->container); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | * @return bool |
194 | 194 | */ |
195 | 195 | public function valid() { |
196 | - return $this->offsetExists( $this->key() ); |
|
196 | + return $this->offsetExists($this->key()); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /*****************************************************************/ |
@@ -208,6 +208,6 @@ discard block |
||
208 | 208 | * @return int |
209 | 209 | */ |
210 | 210 | public function count() { |
211 | - return count( $this->container ); |
|
211 | + return count($this->container); |
|
212 | 212 | } |
213 | 213 | } |
@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @param string $query Database count query |
25 | 25 | */ |
26 | - $query = apply_filters( 'wp_session_count_query', $query ); |
|
26 | + $query = apply_filters('wp_session_count_query', $query); |
|
27 | 27 | |
28 | - $sessions = $wpdb->get_var( $query ); |
|
28 | + $sessions = $wpdb->get_var($query); |
|
29 | 29 | |
30 | - return absint( $sessions ); |
|
30 | + return absint($sessions); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -35,33 +35,33 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @param null|string $date |
37 | 37 | */ |
38 | - public static function create_dummy_session( $date = null ) { |
|
38 | + public static function create_dummy_session($date = null) { |
|
39 | 39 | // Generate our date |
40 | - if ( null !== $date ) { |
|
41 | - $time = strtotime( $date ); |
|
40 | + if (null !== $date) { |
|
41 | + $time = strtotime($date); |
|
42 | 42 | |
43 | - if ( false === $time ) { |
|
43 | + if (false === $time) { |
|
44 | 44 | $date = null; |
45 | 45 | } else { |
46 | - $expires = date( 'U', strtotime( $date ) ); |
|
46 | + $expires = date('U', strtotime($date)); |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
50 | 50 | // If null was passed, or if the string parsing failed, fall back on a default |
51 | - if ( null === $date ) { |
|
51 | + if (null === $date) { |
|
52 | 52 | /** |
53 | 53 | * Filter the expiration of the session in the database |
54 | 54 | * |
55 | 55 | * @param int |
56 | 56 | */ |
57 | - $expires = time() + (int) apply_filters( 'wp_session_expiration', 30 * 60 ); |
|
57 | + $expires = time() + (int)apply_filters('wp_session_expiration', 30 * 60); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | $session_id = self::generate_id(); |
61 | 61 | |
62 | 62 | // Store the session |
63 | - add_option( "_wp_session_{$session_id}", array(), '', 'no' ); |
|
64 | - add_option( "_wp_session_expires_{$session_id}", $expires, '', 'no' ); |
|
63 | + add_option("_wp_session_{$session_id}", array(), '', 'no'); |
|
64 | + add_option("_wp_session_expires_{$session_id}", $expires, '', 'no'); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -73,22 +73,22 @@ discard block |
||
73 | 73 | * |
74 | 74 | * @return int Sessions deleted. |
75 | 75 | */ |
76 | - public static function delete_old_sessions( $limit = 1000 ) { |
|
76 | + public static function delete_old_sessions($limit = 1000) { |
|
77 | 77 | global $wpdb; |
78 | 78 | |
79 | - $limit = absint( $limit ); |
|
80 | - $keys = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE option_name LIKE '_wp_session_expires_%' ORDER BY option_value ASC LIMIT 0, {$limit}" ); |
|
79 | + $limit = absint($limit); |
|
80 | + $keys = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options WHERE option_name LIKE '_wp_session_expires_%' ORDER BY option_value ASC LIMIT 0, {$limit}"); |
|
81 | 81 | |
82 | 82 | $now = time(); |
83 | 83 | $expired = array(); |
84 | 84 | $count = 0; |
85 | 85 | |
86 | - foreach( $keys as $expiration ) { |
|
86 | + foreach ($keys as $expiration) { |
|
87 | 87 | $key = $expiration->option_name; |
88 | 88 | $expires = $expiration->option_value; |
89 | 89 | |
90 | - if ( $now > $expires ) { |
|
91 | - $session_id = preg_replace("/[^A-Za-z0-9_]/", '', substr( $key, 20 ) ); |
|
90 | + if ($now > $expires) { |
|
91 | + $session_id = preg_replace("/[^A-Za-z0-9_]/", '', substr($key, 20)); |
|
92 | 92 | |
93 | 93 | $expired[] = $key; |
94 | 94 | $expired[] = "_wp_session_{$session_id}"; |
@@ -98,13 +98,13 @@ discard block |
||
98 | 98 | } |
99 | 99 | |
100 | 100 | // Delete expired sessions |
101 | - if ( ! empty( $expired ) ) { |
|
102 | - $placeholders = array_fill( 0, count( $expired ), '%s' ); |
|
103 | - $format = implode( ', ', $placeholders ); |
|
101 | + if (!empty($expired)) { |
|
102 | + $placeholders = array_fill(0, count($expired), '%s'); |
|
103 | + $format = implode(', ', $placeholders); |
|
104 | 104 | $query = "DELETE FROM $wpdb->options WHERE option_name IN ($format)"; |
105 | 105 | |
106 | - $prepared = $wpdb->prepare( $query, $expired ); |
|
107 | - $wpdb->query( $prepared ); |
|
106 | + $prepared = $wpdb->prepare($query, $expired); |
|
107 | + $wpdb->query($prepared); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | return $count; |
@@ -120,9 +120,9 @@ discard block |
||
120 | 120 | public static function delete_all_sessions() { |
121 | 121 | global $wpdb; |
122 | 122 | |
123 | - $count = $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_wp_session_%'" ); |
|
123 | + $count = $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_wp_session_%'"); |
|
124 | 124 | |
125 | - return (int) ( $count / 2 ); |
|
125 | + return (int)($count / 2); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | * @return string |
132 | 132 | */ |
133 | 133 | public static function generate_id() { |
134 | - require_once( ABSPATH . 'wp-includes/class-phpass.php' ); |
|
135 | - $hash = new PasswordHash( 8, false ); |
|
134 | + require_once(ABSPATH . 'wp-includes/class-phpass.php'); |
|
135 | + $hash = new PasswordHash(8, false); |
|
136 | 136 | |
137 | - return md5( $hash->get_random_bytes( 32 ) ); |
|
137 | + return md5($hash->get_random_bytes(32)); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | \ No newline at end of file |
@@ -7,12 +7,12 @@ 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_init_transactional_emails() { |
15 | - $email_actions = apply_filters( 'wpinv_email_actions', array( |
|
15 | + $email_actions = apply_filters('wpinv_email_actions', array( |
|
16 | 16 | 'wpinv_status_pending_to_processing', |
17 | 17 | 'wpinv_status_pending_to_publish', |
18 | 18 | 'wpinv_status_pending_to_cancelled', |
@@ -28,74 +28,74 @@ discard block |
||
28 | 28 | 'wpinv_fully_refunded', |
29 | 29 | 'wpinv_partially_refunded', |
30 | 30 | 'wpinv_new_invoice_note' |
31 | - ) ); |
|
31 | + )); |
|
32 | 32 | |
33 | - foreach ( $email_actions as $action ) { |
|
34 | - add_action( $action, 'wpinv_send_transactional_email', 10, 10 ); |
|
33 | + foreach ($email_actions as $action) { |
|
34 | + add_action($action, 'wpinv_send_transactional_email', 10, 10); |
|
35 | 35 | } |
36 | 36 | } |
37 | -add_action( 'init', 'wpinv_init_transactional_emails' ); |
|
37 | +add_action('init', 'wpinv_init_transactional_emails'); |
|
38 | 38 | |
39 | 39 | // New invoice email |
40 | -add_action( 'wpinv_status_pending_to_processing_notification', 'wpinv_new_invoice_notification' ); |
|
41 | -add_action( 'wpinv_status_pending_to_publish_notification', 'wpinv_new_invoice_notification' ); |
|
42 | -add_action( 'wpinv_status_pending_to_onhold_notification', 'wpinv_new_invoice_notification' ); |
|
43 | -add_action( 'wpinv_status_failed_to_processing_notification', 'wpinv_new_invoice_notification' ); |
|
44 | -add_action( 'wpinv_status_failed_to_publish_notification', 'wpinv_new_invoice_notification' ); |
|
45 | -add_action( 'wpinv_status_failed_to_onhold_notification', 'wpinv_new_invoice_notification' ); |
|
40 | +add_action('wpinv_status_pending_to_processing_notification', 'wpinv_new_invoice_notification'); |
|
41 | +add_action('wpinv_status_pending_to_publish_notification', 'wpinv_new_invoice_notification'); |
|
42 | +add_action('wpinv_status_pending_to_onhold_notification', 'wpinv_new_invoice_notification'); |
|
43 | +add_action('wpinv_status_failed_to_processing_notification', 'wpinv_new_invoice_notification'); |
|
44 | +add_action('wpinv_status_failed_to_publish_notification', 'wpinv_new_invoice_notification'); |
|
45 | +add_action('wpinv_status_failed_to_onhold_notification', 'wpinv_new_invoice_notification'); |
|
46 | 46 | |
47 | 47 | // Cancelled invoice email |
48 | -add_action( 'wpinv_status_pending_to_cancelled_notification', 'wpinv_cancelled_invoice_notification' ); |
|
49 | -add_action( 'wpinv_status_onhold_to_cancelled_notification', 'wpinv_cancelled_invoice_notification' ); |
|
48 | +add_action('wpinv_status_pending_to_cancelled_notification', 'wpinv_cancelled_invoice_notification'); |
|
49 | +add_action('wpinv_status_onhold_to_cancelled_notification', 'wpinv_cancelled_invoice_notification'); |
|
50 | 50 | |
51 | 51 | // Failed invoice email |
52 | -add_action( 'wpinv_status_pending_to_failed_notification', 'wpinv_failed_invoice_notification' ); |
|
53 | -add_action( 'wpinv_status_onhold_to_failed_notification', 'wpinv_failed_invoice_notification' ); |
|
52 | +add_action('wpinv_status_pending_to_failed_notification', 'wpinv_failed_invoice_notification'); |
|
53 | +add_action('wpinv_status_onhold_to_failed_notification', 'wpinv_failed_invoice_notification'); |
|
54 | 54 | |
55 | 55 | // On hold invoice email |
56 | -add_action( 'wpinv_status_pending_to_onhold_notification', 'wpinv_onhold_invoice_notification' ); |
|
57 | -add_action( 'wpinv_status_failed_to_onhold_notification', 'wpinv_onhold_invoice_notification' ); |
|
56 | +add_action('wpinv_status_pending_to_onhold_notification', 'wpinv_onhold_invoice_notification'); |
|
57 | +add_action('wpinv_status_failed_to_onhold_notification', 'wpinv_onhold_invoice_notification'); |
|
58 | 58 | |
59 | 59 | // Processing invoice email |
60 | -add_action( 'wpinv_status_pending_to_processing_notification', 'wpinv_processing_invoice_notification' ); |
|
60 | +add_action('wpinv_status_pending_to_processing_notification', 'wpinv_processing_invoice_notification'); |
|
61 | 61 | |
62 | 62 | // Paid invoice email |
63 | -add_action( 'wpinv_status_publish_notification', 'wpinv_completed_invoice_notification' ); |
|
63 | +add_action('wpinv_status_publish_notification', 'wpinv_completed_invoice_notification'); |
|
64 | 64 | |
65 | 65 | // Refunded invoice email |
66 | -add_action( 'wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification' ); |
|
67 | -add_action( 'wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification' ); |
|
66 | +add_action('wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification'); |
|
67 | +add_action('wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification'); |
|
68 | 68 | |
69 | 69 | // Invoice note |
70 | -add_action( 'wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification' ); |
|
70 | +add_action('wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification'); |
|
71 | 71 | |
72 | -add_action( 'wpinv_email_header', 'wpinv_email_header' ); |
|
73 | -add_action( 'wpinv_email_footer', 'wpinv_email_footer' ); |
|
74 | -add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 ); |
|
75 | -add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 ); |
|
76 | -add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 ); |
|
72 | +add_action('wpinv_email_header', 'wpinv_email_header'); |
|
73 | +add_action('wpinv_email_footer', 'wpinv_email_footer'); |
|
74 | +add_action('wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3); |
|
75 | +add_action('wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3); |
|
76 | +add_action('wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3); |
|
77 | 77 | |
78 | 78 | function wpinv_send_transactional_email() { |
79 | 79 | $args = func_get_args(); |
80 | 80 | $function = current_filter() . '_notification'; |
81 | - do_action_ref_array( $function, $args ); |
|
81 | + do_action_ref_array($function, $args); |
|
82 | 82 | } |
83 | 83 | |
84 | -function wpinv_new_invoice_notification( $invoice_id, $new_status = '' ) { |
|
84 | +function wpinv_new_invoice_notification($invoice_id, $new_status = '') { |
|
85 | 85 | global $wpinv_email_search, $wpinv_email_replace; |
86 | 86 | |
87 | 87 | $email_type = 'new_invoice'; |
88 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
88 | + if (!wpinv_email_is_enabled($email_type)) { |
|
89 | 89 | return false; |
90 | 90 | } |
91 | 91 | |
92 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
93 | - if ( empty( $invoice ) ) { |
|
92 | + $invoice = wpinv_get_invoice($invoice_id); |
|
93 | + if (empty($invoice)) { |
|
94 | 94 | return false; |
95 | 95 | } |
96 | 96 | |
97 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
98 | - if ( !is_email( $recipient ) ) { |
|
97 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
98 | + if (!is_email($recipient)) { |
|
99 | 99 | return false; |
100 | 100 | } |
101 | 101 | |
@@ -112,37 +112,37 @@ discard block |
||
112 | 112 | $wpinv_email_search = $search; |
113 | 113 | $wpinv_email_replace = $replace; |
114 | 114 | |
115 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
116 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
117 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
118 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
115 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
116 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
117 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
118 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
119 | 119 | |
120 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
120 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
121 | 121 | 'invoice' => $invoice, |
122 | 122 | 'email_type' => $email_type, |
123 | 123 | 'email_heading' => $email_heading, |
124 | 124 | 'sent_to_admin' => true, |
125 | 125 | 'plain_text' => false, |
126 | - ) ); |
|
126 | + )); |
|
127 | 127 | |
128 | - return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
128 | + return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
129 | 129 | } |
130 | 130 | |
131 | -function wpinv_cancelled_invoice_notification( $invoice_id, $new_status = '' ) { |
|
131 | +function wpinv_cancelled_invoice_notification($invoice_id, $new_status = '') { |
|
132 | 132 | global $wpinv_email_search, $wpinv_email_replace; |
133 | 133 | |
134 | 134 | $email_type = 'cancelled_invoice'; |
135 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
135 | + if (!wpinv_email_is_enabled($email_type)) { |
|
136 | 136 | return false; |
137 | 137 | } |
138 | 138 | |
139 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
140 | - if ( empty( $invoice ) ) { |
|
139 | + $invoice = wpinv_get_invoice($invoice_id); |
|
140 | + if (empty($invoice)) { |
|
141 | 141 | return false; |
142 | 142 | } |
143 | 143 | |
144 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
145 | - if ( !is_email( $recipient ) ) { |
|
144 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
145 | + if (!is_email($recipient)) { |
|
146 | 146 | return false; |
147 | 147 | } |
148 | 148 | |
@@ -159,37 +159,37 @@ discard block |
||
159 | 159 | $wpinv_email_search = $search; |
160 | 160 | $wpinv_email_replace = $replace; |
161 | 161 | |
162 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
163 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
164 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
165 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
162 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
163 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
164 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
165 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
166 | 166 | |
167 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
167 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
168 | 168 | 'invoice' => $invoice, |
169 | 169 | 'email_type' => $email_type, |
170 | 170 | 'email_heading' => $email_heading, |
171 | 171 | 'sent_to_admin' => true, |
172 | 172 | 'plain_text' => false, |
173 | - ) ); |
|
173 | + )); |
|
174 | 174 | |
175 | - return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
175 | + return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
176 | 176 | } |
177 | 177 | |
178 | -function wpinv_failed_invoice_notification( $invoice_id, $new_status = '' ) { |
|
178 | +function wpinv_failed_invoice_notification($invoice_id, $new_status = '') { |
|
179 | 179 | global $wpinv_email_search, $wpinv_email_replace; |
180 | 180 | |
181 | 181 | $email_type = 'failed_invoice'; |
182 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
182 | + if (!wpinv_email_is_enabled($email_type)) { |
|
183 | 183 | return false; |
184 | 184 | } |
185 | 185 | |
186 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
187 | - if ( empty( $invoice ) ) { |
|
186 | + $invoice = wpinv_get_invoice($invoice_id); |
|
187 | + if (empty($invoice)) { |
|
188 | 188 | return false; |
189 | 189 | } |
190 | 190 | |
191 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
192 | - if ( !is_email( $recipient ) ) { |
|
191 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
192 | + if (!is_email($recipient)) { |
|
193 | 193 | return false; |
194 | 194 | } |
195 | 195 | |
@@ -206,37 +206,37 @@ discard block |
||
206 | 206 | $wpinv_email_search = $search; |
207 | 207 | $wpinv_email_replace = $replace; |
208 | 208 | |
209 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
210 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
211 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
212 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
209 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
210 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
211 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
212 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
213 | 213 | |
214 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
214 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
215 | 215 | 'invoice' => $invoice, |
216 | 216 | 'email_type' => $email_type, |
217 | 217 | 'email_heading' => $email_heading, |
218 | 218 | 'sent_to_admin' => true, |
219 | 219 | 'plain_text' => false, |
220 | - ) ); |
|
220 | + )); |
|
221 | 221 | |
222 | - return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
222 | + return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
223 | 223 | } |
224 | 224 | |
225 | -function wpinv_onhold_invoice_notification( $invoice_id, $new_status = '' ) { |
|
225 | +function wpinv_onhold_invoice_notification($invoice_id, $new_status = '') { |
|
226 | 226 | global $wpinv_email_search, $wpinv_email_replace; |
227 | 227 | |
228 | 228 | $email_type = 'onhold_invoice'; |
229 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
229 | + if (!wpinv_email_is_enabled($email_type)) { |
|
230 | 230 | return false; |
231 | 231 | } |
232 | 232 | |
233 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
234 | - if ( empty( $invoice ) ) { |
|
233 | + $invoice = wpinv_get_invoice($invoice_id); |
|
234 | + if (empty($invoice)) { |
|
235 | 235 | return false; |
236 | 236 | } |
237 | 237 | |
238 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
239 | - if ( !is_email( $recipient ) ) { |
|
238 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
239 | + if (!is_email($recipient)) { |
|
240 | 240 | return false; |
241 | 241 | } |
242 | 242 | |
@@ -253,45 +253,45 @@ discard block |
||
253 | 253 | $wpinv_email_search = $search; |
254 | 254 | $wpinv_email_replace = $replace; |
255 | 255 | |
256 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
257 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
258 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
259 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
256 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
257 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
258 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
259 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
260 | 260 | |
261 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
261 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
262 | 262 | 'invoice' => $invoice, |
263 | 263 | 'email_type' => $email_type, |
264 | 264 | 'email_heading' => $email_heading, |
265 | 265 | 'sent_to_admin' => false, |
266 | 266 | 'plain_text' => false, |
267 | - ) ); |
|
267 | + )); |
|
268 | 268 | |
269 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
269 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
270 | 270 | |
271 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
272 | - $recipient = wpinv_get_admin_email(); |
|
273 | - $subject .= ' - ADMIN BCC COPY'; |
|
274 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
271 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
272 | + $recipient = wpinv_get_admin_email(); |
|
273 | + $subject .= ' - ADMIN BCC COPY'; |
|
274 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | return $sent; |
278 | 278 | } |
279 | 279 | |
280 | -function wpinv_processing_invoice_notification( $invoice_id, $new_status = '' ) { |
|
280 | +function wpinv_processing_invoice_notification($invoice_id, $new_status = '') { |
|
281 | 281 | global $wpinv_email_search, $wpinv_email_replace; |
282 | 282 | |
283 | 283 | $email_type = 'processing_invoice'; |
284 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
284 | + if (!wpinv_email_is_enabled($email_type)) { |
|
285 | 285 | return false; |
286 | 286 | } |
287 | 287 | |
288 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
289 | - if ( empty( $invoice ) ) { |
|
288 | + $invoice = wpinv_get_invoice($invoice_id); |
|
289 | + if (empty($invoice)) { |
|
290 | 290 | return false; |
291 | 291 | } |
292 | 292 | |
293 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
294 | - if ( !is_email( $recipient ) ) { |
|
293 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
294 | + if (!is_email($recipient)) { |
|
295 | 295 | return false; |
296 | 296 | } |
297 | 297 | |
@@ -308,45 +308,45 @@ discard block |
||
308 | 308 | $wpinv_email_search = $search; |
309 | 309 | $wpinv_email_replace = $replace; |
310 | 310 | |
311 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
312 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
313 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
314 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
311 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
312 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
313 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
314 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
315 | 315 | |
316 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
316 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
317 | 317 | 'invoice' => $invoice, |
318 | 318 | 'email_type' => $email_type, |
319 | 319 | 'email_heading' => $email_heading, |
320 | 320 | 'sent_to_admin' => false, |
321 | 321 | 'plain_text' => false, |
322 | - ) ); |
|
322 | + )); |
|
323 | 323 | |
324 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
324 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
325 | 325 | |
326 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
327 | - $recipient = wpinv_get_admin_email(); |
|
328 | - $subject .= ' - ADMIN BCC COPY'; |
|
329 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
326 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
327 | + $recipient = wpinv_get_admin_email(); |
|
328 | + $subject .= ' - ADMIN BCC COPY'; |
|
329 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | return $sent; |
333 | 333 | } |
334 | 334 | |
335 | -function wpinv_completed_invoice_notification( $invoice_id, $new_status = '' ) { |
|
335 | +function wpinv_completed_invoice_notification($invoice_id, $new_status = '') { |
|
336 | 336 | global $wpinv_email_search, $wpinv_email_replace; |
337 | 337 | |
338 | 338 | $email_type = 'completed_invoice'; |
339 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
339 | + if (!wpinv_email_is_enabled($email_type)) { |
|
340 | 340 | return false; |
341 | 341 | } |
342 | 342 | |
343 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
344 | - if ( empty( $invoice ) ) { |
|
343 | + $invoice = wpinv_get_invoice($invoice_id); |
|
344 | + if (empty($invoice)) { |
|
345 | 345 | return false; |
346 | 346 | } |
347 | 347 | |
348 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
349 | - if ( !is_email( $recipient ) ) { |
|
348 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
349 | + if (!is_email($recipient)) { |
|
350 | 350 | return false; |
351 | 351 | } |
352 | 352 | |
@@ -363,45 +363,45 @@ discard block |
||
363 | 363 | $wpinv_email_search = $search; |
364 | 364 | $wpinv_email_replace = $replace; |
365 | 365 | |
366 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
367 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
368 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
369 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
366 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
367 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
368 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
369 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
370 | 370 | |
371 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
371 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
372 | 372 | 'invoice' => $invoice, |
373 | 373 | 'email_type' => $email_type, |
374 | 374 | 'email_heading' => $email_heading, |
375 | 375 | 'sent_to_admin' => false, |
376 | 376 | 'plain_text' => false, |
377 | - ) ); |
|
377 | + )); |
|
378 | 378 | |
379 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
379 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
380 | 380 | |
381 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
382 | - $recipient = wpinv_get_admin_email(); |
|
383 | - $subject .= ' - ADMIN BCC COPY'; |
|
384 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
381 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
382 | + $recipient = wpinv_get_admin_email(); |
|
383 | + $subject .= ' - ADMIN BCC COPY'; |
|
384 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | return $sent; |
388 | 388 | } |
389 | 389 | |
390 | -function wpinv_fully_refunded_notification( $invoice_id, $new_status = '' ) { |
|
390 | +function wpinv_fully_refunded_notification($invoice_id, $new_status = '') { |
|
391 | 391 | global $wpinv_email_search, $wpinv_email_replace; |
392 | 392 | |
393 | 393 | $email_type = 'refunded_invoice'; |
394 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
394 | + if (!wpinv_email_is_enabled($email_type)) { |
|
395 | 395 | return false; |
396 | 396 | } |
397 | 397 | |
398 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
399 | - if ( empty( $invoice ) ) { |
|
398 | + $invoice = wpinv_get_invoice($invoice_id); |
|
399 | + if (empty($invoice)) { |
|
400 | 400 | return false; |
401 | 401 | } |
402 | 402 | |
403 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
404 | - if ( !is_email( $recipient ) ) { |
|
403 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
404 | + if (!is_email($recipient)) { |
|
405 | 405 | return false; |
406 | 406 | } |
407 | 407 | |
@@ -418,46 +418,46 @@ discard block |
||
418 | 418 | $wpinv_email_search = $search; |
419 | 419 | $wpinv_email_replace = $replace; |
420 | 420 | |
421 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
422 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
423 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
424 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
421 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
422 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
423 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
424 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
425 | 425 | |
426 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
426 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
427 | 427 | 'invoice' => $invoice, |
428 | 428 | 'email_type' => $email_type, |
429 | 429 | 'email_heading' => $email_heading, |
430 | 430 | 'sent_to_admin' => false, |
431 | 431 | 'plain_text' => false, |
432 | 432 | 'partial_refund' => false |
433 | - ) ); |
|
433 | + )); |
|
434 | 434 | |
435 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
435 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
436 | 436 | |
437 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
438 | - $recipient = wpinv_get_admin_email(); |
|
439 | - $subject .= ' - ADMIN BCC COPY'; |
|
440 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
437 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
438 | + $recipient = wpinv_get_admin_email(); |
|
439 | + $subject .= ' - ADMIN BCC COPY'; |
|
440 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | return $sent; |
444 | 444 | } |
445 | 445 | |
446 | -function wpinv_partially_refunded_notification( $invoice_id, $new_status = '' ) { |
|
446 | +function wpinv_partially_refunded_notification($invoice_id, $new_status = '') { |
|
447 | 447 | global $wpinv_email_search, $wpinv_email_replace; |
448 | 448 | |
449 | 449 | $email_type = 'refunded_invoice'; |
450 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
450 | + if (!wpinv_email_is_enabled($email_type)) { |
|
451 | 451 | return false; |
452 | 452 | } |
453 | 453 | |
454 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
455 | - if ( empty( $invoice ) ) { |
|
454 | + $invoice = wpinv_get_invoice($invoice_id); |
|
455 | + if (empty($invoice)) { |
|
456 | 456 | return false; |
457 | 457 | } |
458 | 458 | |
459 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
460 | - if ( !is_email( $recipient ) ) { |
|
459 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
460 | + if (!is_email($recipient)) { |
|
461 | 461 | return false; |
462 | 462 | } |
463 | 463 | |
@@ -474,49 +474,49 @@ discard block |
||
474 | 474 | $wpinv_email_search = $search; |
475 | 475 | $wpinv_email_replace = $replace; |
476 | 476 | |
477 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
478 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
479 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
480 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
477 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
478 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
479 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
480 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
481 | 481 | |
482 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
482 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
483 | 483 | 'invoice' => $invoice, |
484 | 484 | 'email_type' => $email_type, |
485 | 485 | 'email_heading' => $email_heading, |
486 | 486 | 'sent_to_admin' => false, |
487 | 487 | 'plain_text' => false, |
488 | 488 | 'partial_refund' => true |
489 | - ) ); |
|
489 | + )); |
|
490 | 490 | |
491 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
491 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
492 | 492 | |
493 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
494 | - $recipient = wpinv_get_admin_email(); |
|
495 | - $subject .= ' - ADMIN BCC COPY'; |
|
496 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
493 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
494 | + $recipient = wpinv_get_admin_email(); |
|
495 | + $subject .= ' - ADMIN BCC COPY'; |
|
496 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
497 | 497 | } |
498 | 498 | |
499 | 499 | return $sent; |
500 | 500 | } |
501 | 501 | |
502 | -function wpinv_new_invoice_note_notification( $invoice_id, $new_status = '' ) { |
|
502 | +function wpinv_new_invoice_note_notification($invoice_id, $new_status = '') { |
|
503 | 503 | } |
504 | 504 | |
505 | -function wpinv_user_invoice_notification( $invoice_id ) { |
|
505 | +function wpinv_user_invoice_notification($invoice_id) { |
|
506 | 506 | global $wpinv_email_search, $wpinv_email_replace; |
507 | 507 | |
508 | 508 | $email_type = 'user_invoice'; |
509 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
509 | + if (!wpinv_email_is_enabled($email_type)) { |
|
510 | 510 | return false; |
511 | 511 | } |
512 | 512 | |
513 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
514 | - if ( empty( $invoice ) ) { |
|
513 | + $invoice = wpinv_get_invoice($invoice_id); |
|
514 | + if (empty($invoice)) { |
|
515 | 515 | return false; |
516 | 516 | } |
517 | 517 | |
518 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
519 | - if ( !is_email( $recipient ) ) { |
|
518 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
519 | + if (!is_email($recipient)) { |
|
520 | 520 | return false; |
521 | 521 | } |
522 | 522 | |
@@ -533,52 +533,52 @@ discard block |
||
533 | 533 | $wpinv_email_search = $search; |
534 | 534 | $wpinv_email_replace = $replace; |
535 | 535 | |
536 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
537 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
538 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
539 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
536 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
537 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
538 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
539 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
540 | 540 | |
541 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
541 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
542 | 542 | 'invoice' => $invoice, |
543 | 543 | 'email_type' => $email_type, |
544 | 544 | 'email_heading' => $email_heading, |
545 | 545 | 'sent_to_admin' => false, |
546 | 546 | 'plain_text' => false, |
547 | - ) ); |
|
547 | + )); |
|
548 | 548 | |
549 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
549 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
550 | 550 | |
551 | - if ( $sent ) { |
|
552 | - $note = __( 'Invoice has been emailed to the user.', 'invoicing' ); |
|
551 | + if ($sent) { |
|
552 | + $note = __('Invoice has been emailed to the user.', 'invoicing'); |
|
553 | 553 | } else { |
554 | - $note = __( 'Fail to send invoice to the user!', 'invoicing' ); |
|
554 | + $note = __('Fail to send invoice to the user!', 'invoicing'); |
|
555 | 555 | } |
556 | - $invoice->add_note( $note ); // Add private note. |
|
556 | + $invoice->add_note($note); // Add private note. |
|
557 | 557 | |
558 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
559 | - $recipient = wpinv_get_admin_email(); |
|
560 | - $subject .= ' - ADMIN BCC COPY'; |
|
561 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
558 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
559 | + $recipient = wpinv_get_admin_email(); |
|
560 | + $subject .= ' - ADMIN BCC COPY'; |
|
561 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
562 | 562 | } |
563 | 563 | |
564 | 564 | return $sent; |
565 | 565 | } |
566 | 566 | |
567 | -function wpinv_user_note_notification( $invoice_id, $args = array() ) { |
|
567 | +function wpinv_user_note_notification($invoice_id, $args = array()) { |
|
568 | 568 | global $wpinv_email_search, $wpinv_email_replace; |
569 | 569 | |
570 | 570 | $email_type = 'user_note'; |
571 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
571 | + if (!wpinv_email_is_enabled($email_type)) { |
|
572 | 572 | return false; |
573 | 573 | } |
574 | 574 | |
575 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
576 | - if ( empty( $invoice ) ) { |
|
575 | + $invoice = wpinv_get_invoice($invoice_id); |
|
576 | + if (empty($invoice)) { |
|
577 | 577 | return false; |
578 | 578 | } |
579 | 579 | |
580 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
581 | - if ( !is_email( $recipient ) ) { |
|
580 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
581 | + if (!is_email($recipient)) { |
|
582 | 582 | return false; |
583 | 583 | } |
584 | 584 | |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | 'user_note' => '' |
587 | 587 | ); |
588 | 588 | |
589 | - $args = wp_parse_args( $args, $defaults ); |
|
589 | + $args = wp_parse_args($args, $defaults); |
|
590 | 590 | |
591 | 591 | $search = array(); |
592 | 592 | $search['invoice_number'] = '{invoice_number}'; |
@@ -603,46 +603,46 @@ discard block |
||
603 | 603 | $wpinv_email_search = $search; |
604 | 604 | $wpinv_email_replace = $replace; |
605 | 605 | |
606 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
607 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
608 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
609 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
606 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
607 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
608 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
609 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
610 | 610 | |
611 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
611 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
612 | 612 | 'invoice' => $invoice, |
613 | 613 | 'email_type' => $email_type, |
614 | 614 | 'email_heading' => $email_heading, |
615 | 615 | 'sent_to_admin' => false, |
616 | 616 | 'plain_text' => false, |
617 | 617 | 'customer_note' => $args['user_note'] |
618 | - ) ); |
|
618 | + )); |
|
619 | 619 | |
620 | - $content = wpinv_email_format_text( $content ); |
|
620 | + $content = wpinv_email_format_text($content); |
|
621 | 621 | |
622 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
622 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
623 | 623 | |
624 | 624 | return $sent; |
625 | 625 | } |
626 | 626 | |
627 | 627 | function wpinv_mail_get_from_address() { |
628 | - $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from' ) ); |
|
629 | - return sanitize_email( $from_address ); |
|
628 | + $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from')); |
|
629 | + return sanitize_email($from_address); |
|
630 | 630 | } |
631 | 631 | |
632 | 632 | function wpinv_mail_get_from_name() { |
633 | - $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name' ) ); |
|
634 | - return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES ); |
|
633 | + $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name')); |
|
634 | + return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES); |
|
635 | 635 | } |
636 | 636 | |
637 | -function wpinv_mail_admin_bcc_active( $mail_type = '' ) { |
|
638 | - $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) ); |
|
639 | - return ( $active ? true : false ); |
|
637 | +function wpinv_mail_admin_bcc_active($mail_type = '') { |
|
638 | + $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc')); |
|
639 | + return ($active ? true : false); |
|
640 | 640 | } |
641 | 641 | |
642 | -function wpinv_mail_get_content_type( $content_type = 'text/html', $email_type = 'html' ) { |
|
643 | - $email_type = apply_filters( 'wpinv_mail_content_type', $email_type ); |
|
642 | +function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') { |
|
643 | + $email_type = apply_filters('wpinv_mail_content_type', $email_type); |
|
644 | 644 | |
645 | - switch ( $email_type ) { |
|
645 | + switch ($email_type) { |
|
646 | 646 | case 'html' : |
647 | 647 | $content_type = 'text/html'; |
648 | 648 | break; |
@@ -657,35 +657,35 @@ discard block |
||
657 | 657 | return $content_type; |
658 | 658 | } |
659 | 659 | |
660 | -function wpinv_mail_send( $to, $subject, $message, $headers, $attachments ) { |
|
661 | - add_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' ); |
|
662 | - add_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' ); |
|
663 | - add_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' ); |
|
660 | +function wpinv_mail_send($to, $subject, $message, $headers, $attachments) { |
|
661 | + add_filter('wp_mail_from', 'wpinv_mail_get_from_address'); |
|
662 | + add_filter('wp_mail_from_name', 'wpinv_mail_get_from_name'); |
|
663 | + add_filter('wp_mail_content_type', 'wpinv_mail_get_content_type'); |
|
664 | 664 | |
665 | - $message = wpinv_email_style_body( $message ); |
|
666 | - $message = apply_filters( 'wpinv_mail_content', $message ); |
|
665 | + $message = wpinv_email_style_body($message); |
|
666 | + $message = apply_filters('wpinv_mail_content', $message); |
|
667 | 667 | |
668 | - $sent = wp_mail( $to, $subject, $message, $headers, $attachments ); |
|
668 | + $sent = wp_mail($to, $subject, $message, $headers, $attachments); |
|
669 | 669 | |
670 | - if ( !$sent ) { |
|
671 | - $log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), ( is_array( $to ) ? implode( ', ', $to ) : $to ), $subject ); |
|
672 | - wpinv_error_log( $log_message, __( "Email from Invoicing plugin failed to send", 'invoicing' ), __FILE__, __LINE__ ); |
|
670 | + if (!$sent) { |
|
671 | + $log_message = wp_sprintf(__("\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing'), date_i18n('F j Y H:i:s', current_time('timestamp')), (is_array($to) ? implode(', ', $to) : $to), $subject); |
|
672 | + wpinv_error_log($log_message, __("Email from Invoicing plugin failed to send", 'invoicing'), __FILE__, __LINE__); |
|
673 | 673 | } |
674 | 674 | |
675 | - remove_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' ); |
|
676 | - remove_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' ); |
|
677 | - remove_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' ); |
|
675 | + remove_filter('wp_mail_from', 'wpinv_mail_get_from_address'); |
|
676 | + remove_filter('wp_mail_from_name', 'wpinv_mail_get_from_name'); |
|
677 | + remove_filter('wp_mail_content_type', 'wpinv_mail_get_content_type'); |
|
678 | 678 | |
679 | 679 | return $sent; |
680 | 680 | } |
681 | 681 | |
682 | 682 | function wpinv_get_emails() { |
683 | 683 | $overdue_days_options = array(); |
684 | - $overdue_days_options[0] = __( 'On the Due Date', 'invoicing' ); |
|
685 | - $overdue_days_options[1] = __( '1 day after Due Date', 'invoicing' ); |
|
684 | + $overdue_days_options[0] = __('On the Due Date', 'invoicing'); |
|
685 | + $overdue_days_options[1] = __('1 day after Due Date', 'invoicing'); |
|
686 | 686 | |
687 | - for ( $i = 2; $i <= 10; $i++ ) { |
|
688 | - $overdue_days_options[$i] = wp_sprintf( __( '%d days after Due Date', 'invoicing' ), $i ); |
|
687 | + for ($i = 2; $i <= 10; $i++) { |
|
688 | + $overdue_days_options[$i] = wp_sprintf(__('%d days after Due Date', 'invoicing'), $i); |
|
689 | 689 | } |
690 | 690 | |
691 | 691 | // Default, built-in gateways |
@@ -693,130 +693,130 @@ discard block |
||
693 | 693 | 'new_invoice' => array( |
694 | 694 | 'email_new_invoice_header' => array( |
695 | 695 | 'id' => 'email_new_invoice_header', |
696 | - 'name' => '<h3>' . __( 'New Invoice', 'invoicing' ) . '</h3>', |
|
697 | - 'desc' => __( 'New invoice emails are sent to admin when a new invoice is received.', 'invoicing' ), |
|
696 | + 'name' => '<h3>' . __('New Invoice', 'invoicing') . '</h3>', |
|
697 | + 'desc' => __('New invoice emails are sent to admin when a new invoice is received.', 'invoicing'), |
|
698 | 698 | 'type' => 'header', |
699 | 699 | ), |
700 | 700 | 'email_new_invoice_active' => array( |
701 | 701 | 'id' => 'email_new_invoice_active', |
702 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
703 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
702 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
703 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
704 | 704 | 'type' => 'checkbox', |
705 | 705 | 'std' => 1 |
706 | 706 | ), |
707 | 707 | 'email_new_invoice_subject' => array( |
708 | 708 | 'id' => 'email_new_invoice_subject', |
709 | - 'name' => __( 'Subject', 'invoicing' ), |
|
710 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
709 | + 'name' => __('Subject', 'invoicing'), |
|
710 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
711 | 711 | 'type' => 'text', |
712 | - 'std' => __( '[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing' ), |
|
712 | + 'std' => __('[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing'), |
|
713 | 713 | 'size' => 'large' |
714 | 714 | ), |
715 | 715 | 'email_new_invoice_heading' => array( |
716 | 716 | 'id' => 'email_new_invoice_heading', |
717 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
718 | - 'desc' => __( 'Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
717 | + 'name' => __('Email Heading', 'invoicing'), |
|
718 | + 'desc' => __('Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
719 | 719 | 'type' => 'text', |
720 | - 'std' => __( 'New payment invoice', 'invoicing' ), |
|
720 | + 'std' => __('New payment invoice', 'invoicing'), |
|
721 | 721 | 'size' => 'large' |
722 | 722 | ), |
723 | 723 | ), |
724 | 724 | 'cancelled_invoice' => array( |
725 | 725 | 'email_cancelled_invoice_header' => array( |
726 | 726 | 'id' => 'email_cancelled_invoice_header', |
727 | - 'name' => '<h3>' . __( 'Cancelled Invoice', 'invoicing' ) . '</h3>', |
|
728 | - 'desc' => __( 'Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing' ), |
|
727 | + 'name' => '<h3>' . __('Cancelled Invoice', 'invoicing') . '</h3>', |
|
728 | + 'desc' => __('Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing'), |
|
729 | 729 | 'type' => 'header', |
730 | 730 | ), |
731 | 731 | 'email_cancelled_invoice_active' => array( |
732 | 732 | 'id' => 'email_cancelled_invoice_active', |
733 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
734 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
733 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
734 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
735 | 735 | 'type' => 'checkbox', |
736 | 736 | 'std' => 1 |
737 | 737 | ), |
738 | 738 | 'email_cancelled_invoice_subject' => array( |
739 | 739 | 'id' => 'email_cancelled_invoice_subject', |
740 | - 'name' => __( 'Subject', 'invoicing' ), |
|
741 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
740 | + 'name' => __('Subject', 'invoicing'), |
|
741 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
742 | 742 | 'type' => 'text', |
743 | - 'std' => __( '[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing' ), |
|
743 | + 'std' => __('[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing'), |
|
744 | 744 | 'size' => 'large' |
745 | 745 | ), |
746 | 746 | 'email_cancelled_invoice_heading' => array( |
747 | 747 | 'id' => 'email_cancelled_invoice_heading', |
748 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
749 | - 'desc' => __( 'Enter the the main heading contained within the email notification.', 'invoicing' ), |
|
748 | + 'name' => __('Email Heading', 'invoicing'), |
|
749 | + 'desc' => __('Enter the the main heading contained within the email notification.', 'invoicing'), |
|
750 | 750 | 'type' => 'text', |
751 | - 'std' => __( 'Cancelled invoice', 'invoicing' ), |
|
751 | + 'std' => __('Cancelled invoice', 'invoicing'), |
|
752 | 752 | 'size' => 'large' |
753 | 753 | ), |
754 | 754 | ), |
755 | 755 | 'failed_invoice' => array( |
756 | 756 | 'email_failed_invoice_header' => array( |
757 | 757 | 'id' => 'email_failed_invoice_header', |
758 | - 'name' => '<h3>' . __( 'Failed Invoice', 'invoicing' ) . '</h3>', |
|
759 | - 'desc' => __( 'Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing' ), |
|
758 | + 'name' => '<h3>' . __('Failed Invoice', 'invoicing') . '</h3>', |
|
759 | + 'desc' => __('Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing'), |
|
760 | 760 | 'type' => 'header', |
761 | 761 | ), |
762 | 762 | 'email_failed_invoice_active' => array( |
763 | 763 | 'id' => 'email_failed_invoice_active', |
764 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
765 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
764 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
765 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
766 | 766 | 'type' => 'checkbox', |
767 | 767 | 'std' => 1 |
768 | 768 | ), |
769 | 769 | 'email_failed_invoice_subject' => array( |
770 | 770 | 'id' => 'email_failed_invoice_subject', |
771 | - 'name' => __( 'Subject', 'invoicing' ), |
|
772 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
771 | + 'name' => __('Subject', 'invoicing'), |
|
772 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
773 | 773 | 'type' => 'text', |
774 | - 'std' => __( '[{site_title}] Failed invoice ({invoice_number})', 'invoicing' ), |
|
774 | + 'std' => __('[{site_title}] Failed invoice ({invoice_number})', 'invoicing'), |
|
775 | 775 | 'size' => 'large' |
776 | 776 | ), |
777 | 777 | 'email_failed_invoice_heading' => array( |
778 | 778 | 'id' => 'email_failed_invoice_heading', |
779 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
780 | - 'desc' => __( 'Enter the the main heading contained within the email notification.', 'invoicing' ), |
|
779 | + 'name' => __('Email Heading', 'invoicing'), |
|
780 | + 'desc' => __('Enter the the main heading contained within the email notification.', 'invoicing'), |
|
781 | 781 | 'type' => 'text', |
782 | - 'std' => __( 'Failed invoice', 'invoicing' ), |
|
782 | + 'std' => __('Failed invoice', 'invoicing'), |
|
783 | 783 | 'size' => 'large' |
784 | 784 | ) |
785 | 785 | ), |
786 | 786 | 'onhold_invoice' => array( |
787 | 787 | 'email_onhold_invoice_header' => array( |
788 | 788 | 'id' => 'email_onhold_invoice_header', |
789 | - 'name' => '<h3>' . __( 'On Hold Invoice', 'invoicing' ) . '</h3>', |
|
790 | - 'desc' => __( 'This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing' ), |
|
789 | + 'name' => '<h3>' . __('On Hold Invoice', 'invoicing') . '</h3>', |
|
790 | + 'desc' => __('This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing'), |
|
791 | 791 | 'type' => 'header', |
792 | 792 | ), |
793 | 793 | 'email_onhold_invoice_active' => array( |
794 | 794 | 'id' => 'email_onhold_invoice_active', |
795 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
796 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
795 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
796 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
797 | 797 | 'type' => 'checkbox', |
798 | 798 | 'std' => 1 |
799 | 799 | ), |
800 | 800 | 'email_onhold_invoice_subject' => array( |
801 | 801 | 'id' => 'email_onhold_invoice_subject', |
802 | - 'name' => __( 'Subject', 'invoicing' ), |
|
803 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
802 | + 'name' => __('Subject', 'invoicing'), |
|
803 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
804 | 804 | 'type' => 'text', |
805 | - 'std' => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ), |
|
805 | + 'std' => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'), |
|
806 | 806 | 'size' => 'large' |
807 | 807 | ), |
808 | 808 | 'email_onhold_invoice_heading' => array( |
809 | 809 | 'id' => 'email_onhold_invoice_heading', |
810 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
811 | - 'desc' => __( 'Enter the the main heading contained within the email notification.', 'invoicing' ), |
|
810 | + 'name' => __('Email Heading', 'invoicing'), |
|
811 | + 'desc' => __('Enter the the main heading contained within the email notification.', 'invoicing'), |
|
812 | 812 | 'type' => 'text', |
813 | - 'std' => __( 'Thank you for your invoice', 'invoicing' ), |
|
813 | + 'std' => __('Thank you for your invoice', 'invoicing'), |
|
814 | 814 | 'size' => 'large' |
815 | 815 | ), |
816 | 816 | 'email_onhold_invoice_admin_bcc' => array( |
817 | 817 | 'id' => 'email_onhold_invoice_admin_bcc', |
818 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
819 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
818 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
819 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
820 | 820 | 'type' => 'checkbox', |
821 | 821 | 'std' => 1 |
822 | 822 | ), |
@@ -824,37 +824,37 @@ discard block |
||
824 | 824 | 'processing_invoice' => array( |
825 | 825 | 'email_processing_invoice_header' => array( |
826 | 826 | 'id' => 'email_processing_invoice_header', |
827 | - 'name' => '<h3>' . __( 'Processing Invoice', 'invoicing' ) . '</h3>', |
|
828 | - 'desc' => __( 'This is an invoice notification sent to users containing invoice details after payment.', 'invoicing' ), |
|
827 | + 'name' => '<h3>' . __('Processing Invoice', 'invoicing') . '</h3>', |
|
828 | + 'desc' => __('This is an invoice notification sent to users containing invoice details after payment.', 'invoicing'), |
|
829 | 829 | 'type' => 'header', |
830 | 830 | ), |
831 | 831 | 'email_processing_invoice_active' => array( |
832 | 832 | 'id' => 'email_processing_invoice_active', |
833 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
834 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
833 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
834 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
835 | 835 | 'type' => 'checkbox', |
836 | 836 | 'std' => 1 |
837 | 837 | ), |
838 | 838 | 'email_processing_invoice_subject' => array( |
839 | 839 | 'id' => 'email_processing_invoice_subject', |
840 | - 'name' => __( 'Subject', 'invoicing' ), |
|
841 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
840 | + 'name' => __('Subject', 'invoicing'), |
|
841 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
842 | 842 | 'type' => 'text', |
843 | - 'std' => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ), |
|
843 | + 'std' => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'), |
|
844 | 844 | 'size' => 'large' |
845 | 845 | ), |
846 | 846 | 'email_processing_invoice_heading' => array( |
847 | 847 | 'id' => 'email_processing_invoice_heading', |
848 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
849 | - 'desc' => __( 'Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
848 | + 'name' => __('Email Heading', 'invoicing'), |
|
849 | + 'desc' => __('Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
850 | 850 | 'type' => 'text', |
851 | - 'std' => __( 'Thank you for your invoice', 'invoicing' ), |
|
851 | + 'std' => __('Thank you for your invoice', 'invoicing'), |
|
852 | 852 | 'size' => 'large' |
853 | 853 | ), |
854 | 854 | 'email_processing_invoice_admin_bcc' => array( |
855 | 855 | 'id' => 'email_processing_invoice_admin_bcc', |
856 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
857 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
856 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
857 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
858 | 858 | 'type' => 'checkbox', |
859 | 859 | 'std' => 1 |
860 | 860 | ), |
@@ -862,37 +862,37 @@ discard block |
||
862 | 862 | 'completed_invoice' => array( |
863 | 863 | 'email_completed_invoice_header' => array( |
864 | 864 | 'id' => 'email_completed_invoice_header', |
865 | - 'name' => '<h3>' . __( 'Paid Invoice', 'invoicing' ) . '</h3>', |
|
866 | - 'desc' => __( 'Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing' ), |
|
865 | + 'name' => '<h3>' . __('Paid Invoice', 'invoicing') . '</h3>', |
|
866 | + 'desc' => __('Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing'), |
|
867 | 867 | 'type' => 'header', |
868 | 868 | ), |
869 | 869 | 'email_completed_invoice_active' => array( |
870 | 870 | 'id' => 'email_completed_invoice_active', |
871 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
872 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
871 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
872 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
873 | 873 | 'type' => 'checkbox', |
874 | 874 | 'std' => 1 |
875 | 875 | ), |
876 | 876 | 'email_completed_invoice_subject' => array( |
877 | 877 | 'id' => 'email_completed_invoice_subject', |
878 | - 'name' => __( 'Subject', 'invoicing' ), |
|
879 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
878 | + 'name' => __('Subject', 'invoicing'), |
|
879 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
880 | 880 | 'type' => 'text', |
881 | - 'std' => __( '[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing' ), |
|
881 | + 'std' => __('[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing'), |
|
882 | 882 | 'size' => 'large' |
883 | 883 | ), |
884 | 884 | 'email_completed_invoice_heading' => array( |
885 | 885 | 'id' => 'email_completed_invoice_heading', |
886 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
887 | - 'desc' => __( 'Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
886 | + 'name' => __('Email Heading', 'invoicing'), |
|
887 | + 'desc' => __('Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
888 | 888 | 'type' => 'text', |
889 | - 'std' => __( 'Your invoice has been paid', 'invoicing' ), |
|
889 | + 'std' => __('Your invoice has been paid', 'invoicing'), |
|
890 | 890 | 'size' => 'large' |
891 | 891 | ), |
892 | 892 | 'email_completed_invoice_admin_bcc' => array( |
893 | 893 | 'id' => 'email_completed_invoice_admin_bcc', |
894 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
895 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
894 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
895 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
896 | 896 | 'type' => 'checkbox', |
897 | 897 | ), |
898 | 898 | 'std' => 1 |
@@ -900,37 +900,37 @@ discard block |
||
900 | 900 | 'refunded_invoice' => array( |
901 | 901 | 'email_refunded_invoice_header' => array( |
902 | 902 | 'id' => 'email_refunded_invoice_header', |
903 | - 'name' => '<h3>' . __( 'Refunded Invoice', 'invoicing' ) . '</h3>', |
|
904 | - 'desc' => __( 'Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing' ), |
|
903 | + 'name' => '<h3>' . __('Refunded Invoice', 'invoicing') . '</h3>', |
|
904 | + 'desc' => __('Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing'), |
|
905 | 905 | 'type' => 'header', |
906 | 906 | ), |
907 | 907 | 'email_refunded_invoice_active' => array( |
908 | 908 | 'id' => 'email_refunded_invoice_active', |
909 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
910 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
909 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
910 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
911 | 911 | 'type' => 'checkbox', |
912 | 912 | 'std' => 1 |
913 | 913 | ), |
914 | 914 | 'email_refunded_invoice_subject' => array( |
915 | 915 | 'id' => 'email_refunded_invoice_subject', |
916 | - 'name' => __( 'Subject', 'invoicing' ), |
|
917 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
916 | + 'name' => __('Subject', 'invoicing'), |
|
917 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
918 | 918 | 'type' => 'text', |
919 | - 'std' => __( '[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing' ), |
|
919 | + 'std' => __('[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing'), |
|
920 | 920 | 'size' => 'large' |
921 | 921 | ), |
922 | 922 | 'email_refunded_invoice_heading' => array( |
923 | 923 | 'id' => 'email_refunded_invoice_heading', |
924 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
925 | - 'desc' => __( 'Enter the the main heading contained within the email notification.', 'invoicing' ), |
|
924 | + 'name' => __('Email Heading', 'invoicing'), |
|
925 | + 'desc' => __('Enter the the main heading contained within the email notification.', 'invoicing'), |
|
926 | 926 | 'type' => 'text', |
927 | - 'std' => __( 'Your invoice has been refunded', 'invoicing' ), |
|
927 | + 'std' => __('Your invoice has been refunded', 'invoicing'), |
|
928 | 928 | 'size' => 'large' |
929 | 929 | ), |
930 | 930 | 'email_refunded_invoice_admin_bcc' => array( |
931 | 931 | 'id' => 'email_refunded_invoice_admin_bcc', |
932 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
933 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
932 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
933 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
934 | 934 | 'type' => 'checkbox', |
935 | 935 | 'std' => 1 |
936 | 936 | ), |
@@ -938,37 +938,37 @@ discard block |
||
938 | 938 | 'user_invoice' => array( |
939 | 939 | 'email_user_invoice_header' => array( |
940 | 940 | 'id' => 'email_user_invoice_header', |
941 | - 'name' => '<h3>' . __( 'Customer Invoice', 'invoicing' ) . '</h3>', |
|
942 | - 'desc' => __( 'Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing' ), |
|
941 | + 'name' => '<h3>' . __('Customer Invoice', 'invoicing') . '</h3>', |
|
942 | + 'desc' => __('Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing'), |
|
943 | 943 | 'type' => 'header', |
944 | 944 | ), |
945 | 945 | 'email_user_invoice_active' => array( |
946 | 946 | 'id' => 'email_user_invoice_active', |
947 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
948 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
947 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
948 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
949 | 949 | 'type' => 'checkbox', |
950 | 950 | 'std' => 1 |
951 | 951 | ), |
952 | 952 | 'email_user_invoice_subject' => array( |
953 | 953 | 'id' => 'email_user_invoice_subject', |
954 | - 'name' => __( 'Subject', 'invoicing' ), |
|
955 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
954 | + 'name' => __('Subject', 'invoicing'), |
|
955 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
956 | 956 | 'type' => 'text', |
957 | - 'std' => __( '[{site_title}] Your invoice from {invoice_date}', 'invoicing' ), |
|
957 | + 'std' => __('[{site_title}] Your invoice from {invoice_date}', 'invoicing'), |
|
958 | 958 | 'size' => 'large' |
959 | 959 | ), |
960 | 960 | 'email_user_invoice_heading' => array( |
961 | 961 | 'id' => 'email_user_invoice_heading', |
962 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
963 | - 'desc' => __( 'Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
962 | + 'name' => __('Email Heading', 'invoicing'), |
|
963 | + 'desc' => __('Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
964 | 964 | 'type' => 'text', |
965 | - 'std' => __( 'Your invoice {invoice_number} details', 'invoicing' ), |
|
965 | + 'std' => __('Your invoice {invoice_number} details', 'invoicing'), |
|
966 | 966 | 'size' => 'large' |
967 | 967 | ), |
968 | 968 | 'email_user_invoice_admin_bcc' => array( |
969 | 969 | 'id' => 'email_user_invoice_admin_bcc', |
970 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
971 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
970 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
971 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
972 | 972 | 'type' => 'checkbox', |
973 | 973 | 'std' => 1 |
974 | 974 | ), |
@@ -976,177 +976,177 @@ discard block |
||
976 | 976 | 'user_note' => array( |
977 | 977 | 'email_user_note_header' => array( |
978 | 978 | 'id' => 'email_user_note_header', |
979 | - 'name' => '<h3>' . __( 'Customer Note', 'invoicing' ) . '</h3>', |
|
980 | - 'desc' => __( 'Customer note emails are sent when you add a note to an invoice.', 'invoicing' ), |
|
979 | + 'name' => '<h3>' . __('Customer Note', 'invoicing') . '</h3>', |
|
980 | + 'desc' => __('Customer note emails are sent when you add a note to an invoice.', 'invoicing'), |
|
981 | 981 | 'type' => 'header', |
982 | 982 | ), |
983 | 983 | 'email_user_note_active' => array( |
984 | 984 | 'id' => 'email_user_note_active', |
985 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
986 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
985 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
986 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
987 | 987 | 'type' => 'checkbox', |
988 | 988 | 'std' => 1 |
989 | 989 | ), |
990 | 990 | 'email_user_note_subject' => array( |
991 | 991 | 'id' => 'email_user_note_subject', |
992 | - 'name' => __( 'Subject', 'invoicing' ), |
|
993 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
992 | + 'name' => __('Subject', 'invoicing'), |
|
993 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
994 | 994 | 'type' => 'text', |
995 | - 'std' => __( '[{site_title}] Note added to your invoice #{invoice_number} from {invoice_date}', 'invoicing' ), |
|
995 | + 'std' => __('[{site_title}] Note added to your invoice #{invoice_number} from {invoice_date}', 'invoicing'), |
|
996 | 996 | 'size' => 'large' |
997 | 997 | ), |
998 | 998 | 'email_user_note_heading' => array( |
999 | 999 | 'id' => 'email_user_note_heading', |
1000 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
1001 | - 'desc' => __( 'Enter the the main heading contained within the email notification.', 'invoicing' ), |
|
1000 | + 'name' => __('Email Heading', 'invoicing'), |
|
1001 | + 'desc' => __('Enter the the main heading contained within the email notification.', 'invoicing'), |
|
1002 | 1002 | 'type' => 'text', |
1003 | - 'std' => __( 'A note has been added to your invoice', 'invoicing' ), |
|
1003 | + 'std' => __('A note has been added to your invoice', 'invoicing'), |
|
1004 | 1004 | 'size' => 'large' |
1005 | 1005 | ), |
1006 | 1006 | ), |
1007 | 1007 | 'overdue' => array( |
1008 | 1008 | 'email_overdue_header' => array( |
1009 | 1009 | 'id' => 'email_overdue_header', |
1010 | - 'name' => '<h3>' . __( 'Payment Reminder', 'invoicing' ) . '</h3>', |
|
1011 | - 'desc' => __( 'Payment reminder emails are sent to user automatically.', 'invoicing' ), |
|
1010 | + 'name' => '<h3>' . __('Payment Reminder', 'invoicing') . '</h3>', |
|
1011 | + 'desc' => __('Payment reminder emails are sent to user automatically.', 'invoicing'), |
|
1012 | 1012 | 'type' => 'header', |
1013 | 1013 | ), |
1014 | 1014 | 'email_overdue_active' => array( |
1015 | 1015 | 'id' => 'email_overdue_active', |
1016 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
1017 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
1016 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
1017 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
1018 | 1018 | 'type' => 'checkbox', |
1019 | 1019 | 'std' => 1 |
1020 | 1020 | ), |
1021 | 1021 | 'email_due_reminder_days' => array( |
1022 | 1022 | 'id' => 'email_due_reminder_days', |
1023 | - 'name' => __( 'When to Send', 'sliced-invoices' ), |
|
1024 | - 'desc' => __( 'Check when you would like payment reminders sent out.', 'invoicing' ), |
|
1023 | + 'name' => __('When to Send', 'sliced-invoices'), |
|
1024 | + 'desc' => __('Check when you would like payment reminders sent out.', 'invoicing'), |
|
1025 | 1025 | 'default' => '', |
1026 | 1026 | 'type' => 'multicheck', |
1027 | 1027 | 'options' => $overdue_days_options, |
1028 | 1028 | ), |
1029 | 1029 | 'email_overdue_subject' => array( |
1030 | 1030 | 'id' => 'email_overdue_subject', |
1031 | - 'name' => __( 'Subject', 'invoicing' ), |
|
1032 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
1031 | + 'name' => __('Subject', 'invoicing'), |
|
1032 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
1033 | 1033 | 'type' => 'text', |
1034 | - 'std' => __( '[{site_title}] Payment Reminder', 'invoicing' ), |
|
1034 | + 'std' => __('[{site_title}] Payment Reminder', 'invoicing'), |
|
1035 | 1035 | 'size' => 'large' |
1036 | 1036 | ), |
1037 | 1037 | 'email_overdue_heading' => array( |
1038 | 1038 | 'id' => 'email_overdue_heading', |
1039 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
1040 | - 'desc' => __( 'Enter the the main heading contained within the email notification.', 'invoicing' ), |
|
1039 | + 'name' => __('Email Heading', 'invoicing'), |
|
1040 | + 'desc' => __('Enter the the main heading contained within the email notification.', 'invoicing'), |
|
1041 | 1041 | 'type' => 'text', |
1042 | - 'std' => __( 'Payment reminder for your invoice', 'invoicing' ), |
|
1042 | + 'std' => __('Payment reminder for your invoice', 'invoicing'), |
|
1043 | 1043 | 'size' => 'large' |
1044 | 1044 | ), |
1045 | 1045 | 'email_overdue_body' => array( |
1046 | 1046 | 'id' => 'email_overdue_body', |
1047 | - 'name' => __( 'Email Content', 'invoicing' ), |
|
1048 | - 'desc' => __( 'The content of the email.', 'invoicing' ), |
|
1047 | + 'name' => __('Email Content', 'invoicing'), |
|
1048 | + 'desc' => __('The content of the email.', 'invoicing'), |
|
1049 | 1049 | 'type' => 'rich_editor', |
1050 | - 'std' => __( '<p>Hi {full_name},</p><p>This is just a friendly reminder your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To pay now for this invoice please use the following link: <a href="{invoice_pay_link}">Pay Now</a></p>', 'invoicing' ), |
|
1050 | + 'std' => __('<p>Hi {full_name},</p><p>This is just a friendly reminder your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To pay now for this invoice please use the following link: <a href="{invoice_pay_link}">Pay Now</a></p>', 'invoicing'), |
|
1051 | 1051 | 'class' => 'large', |
1052 | 1052 | 'size' => 10, |
1053 | 1053 | ), |
1054 | 1054 | ), |
1055 | 1055 | ); |
1056 | 1056 | |
1057 | - return apply_filters( 'wpinv_get_emails', $emails ); |
|
1057 | + return apply_filters('wpinv_get_emails', $emails); |
|
1058 | 1058 | } |
1059 | 1059 | |
1060 | -function wpinv_settings_emails( $settings = array() ) { |
|
1060 | +function wpinv_settings_emails($settings = array()) { |
|
1061 | 1061 | $emails = wpinv_get_emails(); |
1062 | 1062 | |
1063 | - if ( !empty( $emails ) ) { |
|
1064 | - foreach ( $emails as $key => $email ) { |
|
1063 | + if (!empty($emails)) { |
|
1064 | + foreach ($emails as $key => $email) { |
|
1065 | 1065 | $settings[$key] = $email; |
1066 | 1066 | } |
1067 | 1067 | } |
1068 | 1068 | |
1069 | - return apply_filters( 'wpinv_settings_get_emails', $settings ); |
|
1069 | + return apply_filters('wpinv_settings_get_emails', $settings); |
|
1070 | 1070 | } |
1071 | -add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 ); |
|
1071 | +add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1); |
|
1072 | 1072 | |
1073 | -function wpinv_settings_sections_emails( $settings ) { |
|
1073 | +function wpinv_settings_sections_emails($settings) { |
|
1074 | 1074 | $emails = wpinv_get_emails(); |
1075 | 1075 | |
1076 | 1076 | if (!empty($emails)) { |
1077 | - foreach ($emails as $key => $email) { |
|
1078 | - $settings[$key] = !empty( $email['email_' . $key . '_header']['name'] ) ? strip_tags( $email['email_' . $key . '_header']['name'] ) : $key; |
|
1077 | + foreach ($emails as $key => $email) { |
|
1078 | + $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : $key; |
|
1079 | 1079 | } |
1080 | 1080 | } |
1081 | 1081 | |
1082 | 1082 | return $settings; |
1083 | 1083 | } |
1084 | -add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 ); |
|
1084 | +add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1); |
|
1085 | 1085 | |
1086 | -function wpinv_email_is_enabled( $email_type ) { |
|
1086 | +function wpinv_email_is_enabled($email_type) { |
|
1087 | 1087 | $emails = wpinv_get_emails(); |
1088 | - $enabled = isset( $emails[$email_type] ) && wpinv_get_option( $email_type . '_active', 1 ) ? true : false; |
|
1088 | + $enabled = isset($emails[$email_type]) && wpinv_get_option($email_type . '_active', 1) ? true : false; |
|
1089 | 1089 | |
1090 | - return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type ); |
|
1090 | + return apply_filters('wpinv_email_is_enabled', $enabled, $email_type); |
|
1091 | 1091 | } |
1092 | 1092 | |
1093 | -function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1094 | - switch ( $email_type ) { |
|
1093 | +function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1094 | + switch ($email_type) { |
|
1095 | 1095 | case 'new_invoice': |
1096 | 1096 | case 'cancelled_invoice': |
1097 | 1097 | case 'failed_invoice': |
1098 | 1098 | $recipient = wpinv_get_admin_email(); |
1099 | 1099 | break; |
1100 | 1100 | default: |
1101 | - $invoice = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL ); |
|
1102 | - $recipient = !empty( $invoice ) ? $invoice->get_email() : ''; |
|
1101 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL); |
|
1102 | + $recipient = !empty($invoice) ? $invoice->get_email() : ''; |
|
1103 | 1103 | break; |
1104 | 1104 | } |
1105 | 1105 | |
1106 | - return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice ); |
|
1106 | + return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice); |
|
1107 | 1107 | } |
1108 | 1108 | |
1109 | -function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1110 | - $subject = wpinv_get_option( 'email_' . $email_type . '_subject' ); |
|
1109 | +function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1110 | + $subject = wpinv_get_option('email_' . $email_type . '_subject'); |
|
1111 | 1111 | |
1112 | - $subject = wpinv_email_format_text( $subject ); |
|
1112 | + $subject = wpinv_email_format_text($subject); |
|
1113 | 1113 | |
1114 | - return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice ); |
|
1114 | + return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice); |
|
1115 | 1115 | } |
1116 | 1116 | |
1117 | -function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1118 | - $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' ); |
|
1117 | +function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1118 | + $email_heading = wpinv_get_option('email_' . $email_type . '_heading'); |
|
1119 | 1119 | |
1120 | - $email_heading = wpinv_email_format_text( $email_heading ); |
|
1120 | + $email_heading = wpinv_email_format_text($email_heading); |
|
1121 | 1121 | |
1122 | - return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice ); |
|
1122 | + return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice); |
|
1123 | 1123 | } |
1124 | 1124 | |
1125 | -function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1126 | - $content = wpinv_get_option( 'email_' . $email_type . '_body' ); |
|
1125 | +function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1126 | + $content = wpinv_get_option('email_' . $email_type . '_body'); |
|
1127 | 1127 | |
1128 | - $content = wpinv_email_format_text( $content ); |
|
1128 | + $content = wpinv_email_format_text($content); |
|
1129 | 1129 | |
1130 | - return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice ); |
|
1130 | + return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice); |
|
1131 | 1131 | } |
1132 | 1132 | |
1133 | -function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1133 | +function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1134 | 1134 | $from_name = wpinv_mail_get_from_address(); |
1135 | 1135 | $from_email = wpinv_mail_get_from_address(); |
1136 | 1136 | |
1137 | - $invoice = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL ); |
|
1137 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL); |
|
1138 | 1138 | |
1139 | - $headers = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n"; |
|
1140 | - $headers .= "Reply-To: ". $from_email . "\r\n"; |
|
1139 | + $headers = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n"; |
|
1140 | + $headers .= "Reply-To: " . $from_email . "\r\n"; |
|
1141 | 1141 | $headers .= "Content-Type: " . wpinv_mail_get_content_type() . "\r\n"; |
1142 | 1142 | |
1143 | - return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice ); |
|
1143 | + return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice); |
|
1144 | 1144 | } |
1145 | 1145 | |
1146 | -function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1146 | +function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1147 | 1147 | $attachments = array(); |
1148 | 1148 | |
1149 | - return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice ); |
|
1149 | + return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice); |
|
1150 | 1150 | } |
1151 | 1151 | |
1152 | 1152 | function wpinv_email_global_vars() { |
@@ -1163,73 +1163,73 @@ discard block |
||
1163 | 1163 | $replace['sitename'] = $blogname; |
1164 | 1164 | $replace['site-title'] = $blogname; |
1165 | 1165 | |
1166 | - return apply_filters( 'wpinv_email_global_vars', array( $search, $replace ) ); |
|
1166 | + return apply_filters('wpinv_email_global_vars', array($search, $replace)); |
|
1167 | 1167 | } |
1168 | 1168 | |
1169 | -function wpinv_email_format_text( $content ) { |
|
1169 | +function wpinv_email_format_text($content) { |
|
1170 | 1170 | global $wpinv_email_search, $wpinv_email_replace; |
1171 | 1171 | |
1172 | - if ( empty( $wpinv_email_search ) ) { |
|
1172 | + if (empty($wpinv_email_search)) { |
|
1173 | 1173 | $wpinv_email_search = array(); |
1174 | 1174 | } |
1175 | 1175 | |
1176 | - if ( empty( $wpinv_email_replace ) ) { |
|
1176 | + if (empty($wpinv_email_replace)) { |
|
1177 | 1177 | $wpinv_email_replace = array(); |
1178 | 1178 | } |
1179 | 1179 | |
1180 | - $wpinv_email_search = (array)apply_filters( 'wpinv_email_format_text_search', $wpinv_email_search ); |
|
1181 | - $wpinv_email_replace = (array)apply_filters( 'wpinv_email_format_text_replace', $wpinv_email_replace ); |
|
1180 | + $wpinv_email_search = (array)apply_filters('wpinv_email_format_text_search', $wpinv_email_search); |
|
1181 | + $wpinv_email_replace = (array)apply_filters('wpinv_email_format_text_replace', $wpinv_email_replace); |
|
1182 | 1182 | |
1183 | 1183 | $global_vars = wpinv_email_global_vars(); |
1184 | 1184 | |
1185 | - $search = array_merge( $global_vars[0], $wpinv_email_search ); |
|
1186 | - $replace = array_merge( $global_vars[1], $wpinv_email_replace ); |
|
1185 | + $search = array_merge($global_vars[0], $wpinv_email_search); |
|
1186 | + $replace = array_merge($global_vars[1], $wpinv_email_replace); |
|
1187 | 1187 | |
1188 | - if ( empty( $search ) || empty( $replace ) || !is_array( $search ) || !is_array( $replace ) ) { |
|
1188 | + if (empty($search) || empty($replace) || !is_array($search) || !is_array($replace)) { |
|
1189 | 1189 | return $content; |
1190 | 1190 | } |
1191 | 1191 | |
1192 | - return str_replace( $search, $replace, $content ); |
|
1192 | + return str_replace($search, $replace, $content); |
|
1193 | 1193 | } |
1194 | 1194 | |
1195 | -function wpinv_email_style_body( $content ) { |
|
1195 | +function wpinv_email_style_body($content) { |
|
1196 | 1196 | // make sure we only inline CSS for html emails |
1197 | - if ( in_array( wpinv_mail_get_content_type(), array( 'text/html', 'multipart/alternative' ) ) && class_exists( 'DOMDocument' ) ) { |
|
1197 | + if (in_array(wpinv_mail_get_content_type(), array('text/html', 'multipart/alternative')) && class_exists('DOMDocument')) { |
|
1198 | 1198 | ob_start(); |
1199 | - wpinv_get_template( 'emails/wpinv-email-styles.php' ); |
|
1200 | - $css = apply_filters( 'wpinv_email_styles', ob_get_clean() ); |
|
1199 | + wpinv_get_template('emails/wpinv-email-styles.php'); |
|
1200 | + $css = apply_filters('wpinv_email_styles', ob_get_clean()); |
|
1201 | 1201 | |
1202 | 1202 | // apply CSS styles inline for picky email clients |
1203 | 1203 | try { |
1204 | - $emogrifier = new Emogrifier( $content, $css ); |
|
1204 | + $emogrifier = new Emogrifier($content, $css); |
|
1205 | 1205 | $content = $emogrifier->emogrify(); |
1206 | - } catch ( Exception $e ) { |
|
1207 | - wpinv_error_log( $e->getMessage(), 'emogrifier' ); |
|
1206 | + } catch (Exception $e) { |
|
1207 | + wpinv_error_log($e->getMessage(), 'emogrifier'); |
|
1208 | 1208 | } |
1209 | 1209 | } |
1210 | 1210 | return $content; |
1211 | 1211 | } |
1212 | 1212 | |
1213 | -function wpinv_email_header( $email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false ) { |
|
1214 | - wpinv_get_template( 'emails/wpinv-email-header.php', array( 'email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1213 | +function wpinv_email_header($email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false) { |
|
1214 | + wpinv_get_template('emails/wpinv-email-header.php', array('email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1215 | 1215 | } |
1216 | 1216 | |
1217 | 1217 | /** |
1218 | 1218 | * Get the email footer. |
1219 | 1219 | */ |
1220 | -function wpinv_email_footer( $invoice = array(), $email_type = '', $sent_to_admin = false ) { |
|
1221 | - wpinv_get_template( 'emails/wpinv-email-footer.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1220 | +function wpinv_email_footer($invoice = array(), $email_type = '', $sent_to_admin = false) { |
|
1221 | + wpinv_get_template('emails/wpinv-email-footer.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1222 | 1222 | } |
1223 | 1223 | |
1224 | -function wpinv_email_wrap_message( $message ) { |
|
1224 | +function wpinv_email_wrap_message($message) { |
|
1225 | 1225 | // Buffer |
1226 | 1226 | ob_start(); |
1227 | 1227 | |
1228 | - do_action( 'wpinv_email_header' ); |
|
1228 | + do_action('wpinv_email_header'); |
|
1229 | 1229 | |
1230 | - echo wpautop( wptexturize( $message ) ); |
|
1230 | + echo wpautop(wptexturize($message)); |
|
1231 | 1231 | |
1232 | - do_action( 'wpinv_email_footer' ); |
|
1232 | + do_action('wpinv_email_footer'); |
|
1233 | 1233 | |
1234 | 1234 | // Get contents |
1235 | 1235 | $message = ob_get_clean(); |
@@ -1237,86 +1237,86 @@ discard block |
||
1237 | 1237 | return $message; |
1238 | 1238 | } |
1239 | 1239 | |
1240 | -function wpinv_email_invoice_details( $invoice, $email_type = '', $sent_to_admin = false ) { |
|
1241 | - wpinv_get_template( 'emails/wpinv-email-invoice-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1240 | +function wpinv_email_invoice_details($invoice, $email_type = '', $sent_to_admin = false) { |
|
1241 | + wpinv_get_template('emails/wpinv-email-invoice-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1242 | 1242 | } |
1243 | 1243 | |
1244 | -function wpinv_email_invoice_items( $invoice, $email_type = '', $sent_to_admin = false ) { |
|
1245 | - wpinv_get_template( 'emails/wpinv-email-invoice-items.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1244 | +function wpinv_email_invoice_items($invoice, $email_type = '', $sent_to_admin = false) { |
|
1245 | + wpinv_get_template('emails/wpinv-email-invoice-items.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1246 | 1246 | } |
1247 | 1247 | |
1248 | -function wpinv_email_billing_details( $invoice, $email_type = '', $sent_to_admin = false ) { |
|
1249 | - wpinv_get_template( 'emails/wpinv-email-billing-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1248 | +function wpinv_email_billing_details($invoice, $email_type = '', $sent_to_admin = false) { |
|
1249 | + wpinv_get_template('emails/wpinv-email-billing-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1250 | 1250 | } |
1251 | 1251 | |
1252 | -function wpinv_send_customer_invoice( $data = array() ) { |
|
1253 | - $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL; |
|
1252 | +function wpinv_send_customer_invoice($data = array()) { |
|
1253 | + $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL; |
|
1254 | 1254 | |
1255 | - if ( empty( $invoice_id ) ) { |
|
1255 | + if (empty($invoice_id)) { |
|
1256 | 1256 | return; |
1257 | 1257 | } |
1258 | 1258 | |
1259 | - if ( !current_user_can( 'manage_options' ) ) { |
|
1260 | - wp_die( __( 'You do not have permission to send invoice notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
1259 | + if (!current_user_can('manage_options')) { |
|
1260 | + wp_die(__('You do not have permission to send invoice notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
1261 | 1261 | } |
1262 | 1262 | |
1263 | - $sent = wpinv_user_invoice_notification( $invoice_id ); |
|
1263 | + $sent = wpinv_user_invoice_notification($invoice_id); |
|
1264 | 1264 | |
1265 | 1265 | $status = $sent ? 'email_sent' : 'email_fail'; |
1266 | 1266 | |
1267 | - $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) ); |
|
1268 | - wp_redirect( $redirect ); |
|
1267 | + $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false)); |
|
1268 | + wp_redirect($redirect); |
|
1269 | 1269 | exit; |
1270 | 1270 | } |
1271 | -add_action( 'wpinv_send_invoice', 'wpinv_send_customer_invoice' ); |
|
1271 | +add_action('wpinv_send_invoice', 'wpinv_send_customer_invoice'); |
|
1272 | 1272 | |
1273 | -function wpinv_send_overdue_reminder( $data = array() ) { |
|
1274 | - $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL; |
|
1273 | +function wpinv_send_overdue_reminder($data = array()) { |
|
1274 | + $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL; |
|
1275 | 1275 | |
1276 | - if ( empty( $invoice_id ) ) { |
|
1276 | + if (empty($invoice_id)) { |
|
1277 | 1277 | return; |
1278 | 1278 | } |
1279 | 1279 | |
1280 | - if ( !current_user_can( 'manage_options' ) ) { |
|
1281 | - wp_die( __( 'You do not have permission to send reminder notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
1280 | + if (!current_user_can('manage_options')) { |
|
1281 | + wp_die(__('You do not have permission to send reminder notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
1282 | 1282 | } |
1283 | 1283 | |
1284 | - $sent = wpinv_send_payment_reminder_notification( $invoice_id ); |
|
1284 | + $sent = wpinv_send_payment_reminder_notification($invoice_id); |
|
1285 | 1285 | |
1286 | 1286 | $status = $sent ? 'email_sent' : 'email_fail'; |
1287 | 1287 | |
1288 | - $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) ); |
|
1289 | - wp_redirect( $redirect ); |
|
1288 | + $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false)); |
|
1289 | + wp_redirect($redirect); |
|
1290 | 1290 | exit; |
1291 | 1291 | } |
1292 | -add_action( 'wpinv_send_reminder', 'wpinv_send_overdue_reminder' ); |
|
1292 | +add_action('wpinv_send_reminder', 'wpinv_send_overdue_reminder'); |
|
1293 | 1293 | |
1294 | -function wpinv_send_customer_note_email( $data ) { |
|
1295 | - $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL; |
|
1294 | +function wpinv_send_customer_note_email($data) { |
|
1295 | + $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL; |
|
1296 | 1296 | |
1297 | - if ( empty( $invoice_id ) ) { |
|
1297 | + if (empty($invoice_id)) { |
|
1298 | 1298 | return; |
1299 | 1299 | } |
1300 | 1300 | |
1301 | - $sent = wpinv_user_note_notification( $invoice_id, $data ); |
|
1301 | + $sent = wpinv_user_note_notification($invoice_id, $data); |
|
1302 | 1302 | } |
1303 | -add_action( 'wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1 ); |
|
1303 | +add_action('wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1); |
|
1304 | 1304 | |
1305 | -function wpinv_add_notes_to_invoice_email( $invoice, $email_type, $sent_to_admin ) { |
|
1306 | - if ( !empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->ID, true ) ) { |
|
1307 | - $date_format = get_option( 'date_format' ); |
|
1308 | - $time_format = get_option( 'time_format' ); |
|
1305 | +function wpinv_add_notes_to_invoice_email($invoice, $email_type, $sent_to_admin) { |
|
1306 | + if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->ID, true)) { |
|
1307 | + $date_format = get_option('date_format'); |
|
1308 | + $time_format = get_option('time_format'); |
|
1309 | 1309 | ?> |
1310 | 1310 | <div id="wpinv-email-notes"> |
1311 | - <h3 class="wpinv-notes-t"><?php echo apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ); ?></h3> |
|
1311 | + <h3 class="wpinv-notes-t"><?php echo apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing')); ?></h3> |
|
1312 | 1312 | <ol class="wpinv-notes-lists"> |
1313 | 1313 | <?php |
1314 | - foreach ( $invoice_notes as $note ) { |
|
1315 | - $note_time = strtotime( $note->comment_date ); |
|
1314 | + foreach ($invoice_notes as $note) { |
|
1315 | + $note_time = strtotime($note->comment_date); |
|
1316 | 1316 | ?> |
1317 | 1317 | <li class="comment wpinv-note"> |
1318 | - <p class="wpinv-note-date meta"><?php printf( __( '%2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( $date_format, $note_time ), date_i18n( $time_format, $note_time ), $note_time ); ?></p> |
|
1319 | - <div class="wpinv-note-desc description"><?php echo wpautop( wptexturize( $note->comment_content ) ); ?></div> |
|
1318 | + <p class="wpinv-note-date meta"><?php printf(__('%2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n($date_format, $note_time), date_i18n($time_format, $note_time), $note_time); ?></p> |
|
1319 | + <div class="wpinv-note-desc description"><?php echo wpautop(wptexturize($note->comment_content)); ?></div> |
|
1320 | 1320 | </li> |
1321 | 1321 | <?php |
1322 | 1322 | } |
@@ -1325,21 +1325,21 @@ discard block |
||
1325 | 1325 | <?php |
1326 | 1326 | } |
1327 | 1327 | } |
1328 | -add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 ); |
|
1328 | +add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3); |
|
1329 | 1329 | |
1330 | 1330 | function wpinv_email_payment_reminders() { |
1331 | 1331 | global $wpi_auto_reminder; |
1332 | - if ( !wpinv_get_option( 'email_overdue_active' ) ) { |
|
1332 | + if (!wpinv_get_option('email_overdue_active')) { |
|
1333 | 1333 | return; |
1334 | 1334 | } |
1335 | 1335 | |
1336 | - if ( $reminder_days = wpinv_get_option( 'email_due_reminder_days' ) ) { |
|
1337 | - $reminder_days = is_array( $reminder_days ) ? array_values( $reminder_days ) : ''; |
|
1336 | + if ($reminder_days = wpinv_get_option('email_due_reminder_days')) { |
|
1337 | + $reminder_days = is_array($reminder_days) ? array_values($reminder_days) : ''; |
|
1338 | 1338 | |
1339 | - if ( empty( $reminder_days ) ) { |
|
1339 | + if (empty($reminder_days)) { |
|
1340 | 1340 | return; |
1341 | 1341 | } |
1342 | - $reminder_days = array_unique( array_map( 'absint', $reminder_days ) ); |
|
1342 | + $reminder_days = array_unique(array_map('absint', $reminder_days)); |
|
1343 | 1343 | |
1344 | 1344 | $args = array( |
1345 | 1345 | 'post_type' => 'wpi_invoice', |
@@ -1349,7 +1349,7 @@ discard block |
||
1349 | 1349 | 'meta_query' => array( |
1350 | 1350 | array( |
1351 | 1351 | 'key' => '_wpinv_due_date', |
1352 | - 'value' => array( '', 'none' ), |
|
1352 | + 'value' => array('', 'none'), |
|
1353 | 1353 | 'compare' => 'NOT IN', |
1354 | 1354 | ) |
1355 | 1355 | ), |
@@ -1358,64 +1358,64 @@ discard block |
||
1358 | 1358 | 'order' => 'ASC', |
1359 | 1359 | ); |
1360 | 1360 | |
1361 | - $invoices = get_posts( $args ); |
|
1361 | + $invoices = get_posts($args); |
|
1362 | 1362 | |
1363 | - if ( empty( $invoices ) ) { |
|
1363 | + if (empty($invoices)) { |
|
1364 | 1364 | return; |
1365 | 1365 | } |
1366 | 1366 | |
1367 | - $date_to_send = array(); |
|
1367 | + $date_to_send = array(); |
|
1368 | 1368 | |
1369 | - foreach ( $invoices as $id ) { |
|
1370 | - $due_date = get_post_meta( $id, '_wpinv_due_date', true ); |
|
1369 | + foreach ($invoices as $id) { |
|
1370 | + $due_date = get_post_meta($id, '_wpinv_due_date', true); |
|
1371 | 1371 | |
1372 | - foreach ( $reminder_days as $key => $days ) { |
|
1373 | - if ( $days !== '' ) { |
|
1374 | - $date_to_send[$id][] = date_i18n( 'Y-m-d', strtotime( $due_date ) + ( $days * DAY_IN_SECONDS ) ); |
|
1372 | + foreach ($reminder_days as $key => $days) { |
|
1373 | + if ($days !== '') { |
|
1374 | + $date_to_send[$id][] = date_i18n('Y-m-d', strtotime($due_date) + ($days * DAY_IN_SECONDS)); |
|
1375 | 1375 | } |
1376 | 1376 | } |
1377 | 1377 | } |
1378 | 1378 | |
1379 | - $today = date_i18n( 'Y-m-d' ); |
|
1379 | + $today = date_i18n('Y-m-d'); |
|
1380 | 1380 | $wpi_auto_reminder = true; |
1381 | 1381 | |
1382 | - foreach ( $date_to_send as $id => $values ) { |
|
1383 | - if ( in_array( $today, $values ) ) { |
|
1384 | - $sent = get_post_meta( $id, '_wpinv_reminder_sent', true ); |
|
1382 | + foreach ($date_to_send as $id => $values) { |
|
1383 | + if (in_array($today, $values)) { |
|
1384 | + $sent = get_post_meta($id, '_wpinv_reminder_sent', true); |
|
1385 | 1385 | |
1386 | - if ( isset( $sent ) && !empty( $sent ) ) { |
|
1387 | - if ( !in_array( $today, $sent ) ) { |
|
1388 | - do_action( 'wpinv_send_payment_reminder_notification', $id ); |
|
1386 | + if (isset($sent) && !empty($sent)) { |
|
1387 | + if (!in_array($today, $sent)) { |
|
1388 | + do_action('wpinv_send_payment_reminder_notification', $id); |
|
1389 | 1389 | } |
1390 | 1390 | } else { |
1391 | - do_action( 'wpinv_send_payment_reminder_notification', $id ); |
|
1391 | + do_action('wpinv_send_payment_reminder_notification', $id); |
|
1392 | 1392 | } |
1393 | 1393 | } |
1394 | 1394 | } |
1395 | 1395 | |
1396 | - $wpi_auto_reminder = false; |
|
1396 | + $wpi_auto_reminder = false; |
|
1397 | 1397 | } |
1398 | 1398 | } |
1399 | 1399 | |
1400 | -function wpinv_send_payment_reminder_notification( $invoice_id ) { |
|
1400 | +function wpinv_send_payment_reminder_notification($invoice_id) { |
|
1401 | 1401 | global $wpinv_email_search, $wpinv_email_replace; |
1402 | 1402 | |
1403 | 1403 | $email_type = 'overdue'; |
1404 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
1404 | + if (!wpinv_email_is_enabled($email_type)) { |
|
1405 | 1405 | return false; |
1406 | 1406 | } |
1407 | 1407 | |
1408 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1409 | - if ( empty( $invoice ) ) { |
|
1408 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1409 | + if (empty($invoice)) { |
|
1410 | 1410 | return false; |
1411 | 1411 | } |
1412 | 1412 | |
1413 | - if ( !$invoice->needs_payment() ) { |
|
1413 | + if (!$invoice->needs_payment()) { |
|
1414 | 1414 | return false; |
1415 | 1415 | } |
1416 | 1416 | |
1417 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
1418 | - if ( !is_email( $recipient ) ) { |
|
1417 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
1418 | + if (!is_email($recipient)) { |
|
1419 | 1419 | return false; |
1420 | 1420 | } |
1421 | 1421 | |
@@ -1431,60 +1431,60 @@ discard block |
||
1431 | 1431 | $replace = array(); |
1432 | 1432 | $replace['full_name'] = $invoice->get_user_full_name(); |
1433 | 1433 | $replace['invoice_number'] = $invoice->get_number(); |
1434 | - $replace['invoice_due_date']= $invoice->get_due_date( true ); |
|
1435 | - $replace['invoice_total'] = $invoice->get_total( true ); |
|
1436 | - $replace['invoice_link'] = $invoice->get_view_url( true ); |
|
1437 | - $replace['invoice_pay_link']= $invoice->get_checkout_payment_url( false, true ); |
|
1438 | - $replace['is_was'] = strtotime( $invoice->get_due_date() ) < strtotime( date_i18n( 'Y-m-d' ) ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ); |
|
1434 | + $replace['invoice_due_date'] = $invoice->get_due_date(true); |
|
1435 | + $replace['invoice_total'] = $invoice->get_total(true); |
|
1436 | + $replace['invoice_link'] = $invoice->get_view_url(true); |
|
1437 | + $replace['invoice_pay_link'] = $invoice->get_checkout_payment_url(false, true); |
|
1438 | + $replace['is_was'] = strtotime($invoice->get_due_date()) < strtotime(date_i18n('Y-m-d')) ? __('was', 'invoicing') : __('is', 'invoicing'); |
|
1439 | 1439 | |
1440 | 1440 | $wpinv_email_search = $search; |
1441 | 1441 | $wpinv_email_replace = $replace; |
1442 | 1442 | |
1443 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
1444 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
1445 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
1446 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
1443 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
1444 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
1445 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
1446 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
1447 | 1447 | |
1448 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
1448 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
1449 | 1449 | |
1450 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
1450 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
1451 | 1451 | 'invoice' => $invoice, |
1452 | 1452 | 'email_type' => $email_type, |
1453 | 1453 | 'email_heading' => $email_heading, |
1454 | 1454 | 'sent_to_admin' => false, |
1455 | 1455 | 'plain_text' => false, |
1456 | 1456 | 'message_body' => $message_body |
1457 | - ) ); |
|
1457 | + )); |
|
1458 | 1458 | |
1459 | - $content = wpinv_email_format_text( $content ); |
|
1459 | + $content = wpinv_email_format_text($content); |
|
1460 | 1460 | |
1461 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
1462 | - if ( $sent ) { |
|
1463 | - do_action( 'wpinv_payment_reminder_sent', $invoice_id, $invoice ); |
|
1461 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
1462 | + if ($sent) { |
|
1463 | + do_action('wpinv_payment_reminder_sent', $invoice_id, $invoice); |
|
1464 | 1464 | } |
1465 | 1465 | |
1466 | 1466 | return $sent; |
1467 | 1467 | } |
1468 | -add_action( 'wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1 ); |
|
1468 | +add_action('wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1); |
|
1469 | 1469 | |
1470 | -function wpinv_payment_reminder_sent( $invoice_id, $invoice ) { |
|
1470 | +function wpinv_payment_reminder_sent($invoice_id, $invoice) { |
|
1471 | 1471 | global $wpi_auto_reminder; |
1472 | 1472 | |
1473 | - $sent = get_post_meta( $invoice_id, '_wpinv_reminder_sent', true ); |
|
1473 | + $sent = get_post_meta($invoice_id, '_wpinv_reminder_sent', true); |
|
1474 | 1474 | |
1475 | - if ( empty( $sent ) ) { |
|
1475 | + if (empty($sent)) { |
|
1476 | 1476 | $sent = array(); |
1477 | 1477 | } |
1478 | - $sent[] = date_i18n( 'Y-m-d' ); |
|
1478 | + $sent[] = date_i18n('Y-m-d'); |
|
1479 | 1479 | |
1480 | - update_post_meta( $invoice_id, '_wpinv_reminder_sent', $sent ); |
|
1480 | + update_post_meta($invoice_id, '_wpinv_reminder_sent', $sent); |
|
1481 | 1481 | |
1482 | - if ( $wpi_auto_reminder ) { // Auto reminder note. |
|
1483 | - $note = __( 'Manual reminder sent to the user.', 'invoicing' ); |
|
1484 | - $invoice->add_note( $note, false, false, true ); |
|
1482 | + if ($wpi_auto_reminder) { // Auto reminder note. |
|
1483 | + $note = __('Manual reminder sent to the user.', 'invoicing'); |
|
1484 | + $invoice->add_note($note, false, false, true); |
|
1485 | 1485 | } else { // Menual reminder note. |
1486 | - $note = __( 'Manual reminder sent to the user.', 'invoicing' ); |
|
1487 | - $invoice->add_note( $note ); |
|
1486 | + $note = __('Manual reminder sent to the user.', 'invoicing'); |
|
1487 | + $invoice->add_note($note); |
|
1488 | 1488 | } |
1489 | 1489 | } |
1490 | -add_action( 'wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2 ); |
|
1491 | 1490 | \ No newline at end of file |
1491 | +add_action('wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2); |
|
1492 | 1492 | \ No newline at end of file |