Passed
Branch master (50908e)
by Stiofan
07:01
created
includes/gateways/authorizenet/anet_php_sdk/lib/AuthorizeNetAIM.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -77,19 +77,19 @@  discard block
 block discarded – undo
77 77
      * A list of all fields in the AIM API.
78 78
      * Used to warn user if they try to set a field not offered in the API.
79 79
      */
80
-    private $_all_aim_fields = array("address","allow_partial_auth","amount",
81
-        "auth_code","authentication_indicator", "bank_aba_code","bank_acct_name",
82
-        "bank_acct_num","bank_acct_type","bank_check_number","bank_name",
83
-        "card_code","card_num","cardholder_authentication_value","city","company",
84
-        "country","cust_id","customer_ip","delim_char","delim_data","description",
85
-        "duplicate_window","duty","echeck_type","email","email_customer",
86
-        "encap_char","exp_date","fax","first_name","footer_email_receipt",
87
-        "freight","header_email_receipt","invoice_num","last_name","line_item",
88
-        "login","method","phone","po_num","recurring_billing","relay_response",
89
-        "ship_to_address","ship_to_city","ship_to_company","ship_to_country",
90
-        "ship_to_first_name","ship_to_last_name","ship_to_state","ship_to_zip",
91
-        "split_tender_id","state","tax","tax_exempt","test_request","tran_key",
92
-        "trans_id","type","version","zip"
80
+    private $_all_aim_fields = array("address", "allow_partial_auth", "amount",
81
+        "auth_code", "authentication_indicator", "bank_aba_code", "bank_acct_name",
82
+        "bank_acct_num", "bank_acct_type", "bank_check_number", "bank_name",
83
+        "card_code", "card_num", "cardholder_authentication_value", "city", "company",
84
+        "country", "cust_id", "customer_ip", "delim_char", "delim_data", "description",
85
+        "duplicate_window", "duty", "echeck_type", "email", "email_customer",
86
+        "encap_char", "exp_date", "fax", "first_name", "footer_email_receipt",
87
+        "freight", "header_email_receipt", "invoice_num", "last_name", "line_item",
88
+        "login", "method", "phone", "po_num", "recurring_billing", "relay_response",
89
+        "ship_to_address", "ship_to_city", "ship_to_company", "ship_to_country",
90
+        "ship_to_first_name", "ship_to_last_name", "ship_to_state", "ship_to_zip",
91
+        "split_tender_id", "state", "tax", "tax_exempt", "test_request", "tran_key",
92
+        "trans_id", "type", "version", "zip"
93 93
         );
94 94
     
95 95
     /**
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
      */
235 235
     public function setFields($fields)
236 236
     {
237
-        $array = (array)$fields;
237
+        $array = (array) $fields;
238 238
         foreach ($array as $key => $value) {
239 239
             $this->setField($key, $value);
240 240
         }
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
      */
248 248
     public function setCustomFields($fields)
249 249
     {
250
-        $array = (array)$fields;
250
+        $array = (array) $fields;
251 251
         foreach ($array as $key => $value) {
252 252
             $this->setCustomField($key, $value);
253 253
         }
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
             // Split Array
404 404
             $this->response = $response;
405 405
             if ($encap_char) {
406
-                $this->_response_array = explode($encap_char.$delimiter.$encap_char, substr($response, 1, -1));
406
+                $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1));
407 407
             } else {
408 408
                 $this->_response_array = explode($delimiter, $response);
409 409
             }
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
             $this->duty                 = $this->_response_array[33];
458 458
             $this->freight              = $this->_response_array[34];
459 459
             $this->tax_exempt           = $this->_response_array[35];
460
-            $this->purchase_order_number= $this->_response_array[36];
460
+            $this->purchase_order_number = $this->_response_array[36];
461 461
             $this->md5_hash             = $this->_response_array[37];
462 462
             $this->card_code_response   = $this->_response_array[38];
463 463
             $this->cavv_response        = $this->_response_array[39];
@@ -484,10 +484,10 @@  discard block
 block discarded – undo
484 484
             
485 485
             if ($this->error) {
486 486
                 $this->error_message = "AuthorizeNet Error:
487
-                Response Code: ".$this->response_code."
488
-                Response Subcode: ".$this->response_subcode."
489
-                Response Reason Code: ".$this->response_reason_code."
490
-                Response Reason Text: ".$this->response_reason_text."
487
+                Response Code: ".$this->response_code . "
488
+                Response Subcode: ".$this->response_subcode . "
489
+                Response Reason Code: ".$this->response_reason_code . "
490
+                Response Reason Text: ".$this->response_reason_text . "
491 491
                 ";
492 492
             }
493 493
         } else {
Please login to merge, or discard this patch.
includes/gateways/authorizenet/anet_php_sdk/lib/AuthorizeNetCP.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -116,27 +116,27 @@  discard block
 block discarded – undo
116 116
                 
117 117
                 $this->xml = @simplexml_load_string($response);
118 118
                 // Set all fields
119
-                $this->version              = array_pop(array_slice(explode('"', $response), 1,1));
120
-                $this->response_code        = (string)$this->xml->ResponseCode;
119
+                $this->version              = array_pop(array_slice(explode('"', $response), 1, 1));
120
+                $this->response_code        = (string) $this->xml->ResponseCode;
121 121
                 
122 122
                 if ($this->response_code == 1) {
123
-                    $this->response_reason_code = (string)$this->xml->Messages->Message->Code;
124
-                    $this->response_reason_text = (string)$this->xml->Messages->Message->Description;
123
+                    $this->response_reason_code = (string) $this->xml->Messages->Message->Code;
124
+                    $this->response_reason_text = (string) $this->xml->Messages->Message->Description;
125 125
                 } else {
126
-                    $this->response_reason_code = (string)$this->xml->Errors->Error->ErrorCode;
127
-                    $this->response_reason_text = (string)$this->xml->Errors->Error->ErrorText;
126
+                    $this->response_reason_code = (string) $this->xml->Errors->Error->ErrorCode;
127
+                    $this->response_reason_text = (string) $this->xml->Errors->Error->ErrorText;
128 128
                 }
129 129
                 
130
-                $this->authorization_code   = (string)$this->xml->AuthCode;
131
-                $this->avs_code             = (string)$this->xml->AVSResultCode;
132
-                $this->card_code_response   = (string)$this->xml->CVVResultCode;
133
-                $this->transaction_id       = (string)$this->xml->TransID;
134
-                $this->md5_hash             = (string)$this->xml->TransHash;
135
-                $this->user_ref             = (string)$this->xml->UserRef;
136
-                $this->card_num             = (string)$this->xml->AccountNumber;
137
-                $this->card_type            = (string)$this->xml->AccountType;
138
-                $this->test_mode            = (string)$this->xml->TestMode;
139
-                $this->ref_trans_id         = (string)$this->xml->RefTransID;
130
+                $this->authorization_code   = (string) $this->xml->AuthCode;
131
+                $this->avs_code             = (string) $this->xml->AVSResultCode;
132
+                $this->card_code_response   = (string) $this->xml->CVVResultCode;
133
+                $this->transaction_id       = (string) $this->xml->TransID;
134
+                $this->md5_hash             = (string) $this->xml->TransHash;
135
+                $this->user_ref             = (string) $this->xml->UserRef;
136
+                $this->card_num             = (string) $this->xml->AccountNumber;
137
+                $this->card_type            = (string) $this->xml->AccountType;
138
+                $this->test_mode            = (string) $this->xml->TestMode;
139
+                $this->ref_trans_id         = (string) $this->xml->RefTransID;
140 140
                 
141 141
                 
142 142
             } else { // If it's an NVP response
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
                 // Split Array
145 145
                 $this->response = $response;
146 146
                 if ($encap_char) {
147
-                    $this->_response_array = explode($encap_char.$delimiter.$encap_char, substr($response, 1, -1));
147
+                    $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1));
148 148
                 } else {
149 149
                     $this->_response_array = explode($delimiter, $response);
150 150
                 }
@@ -190,9 +190,9 @@  discard block
 block discarded – undo
190 190
             
191 191
             if ($this->error) {
192 192
                 $this->error_message = "AuthorizeNet Error:
193
-                Response Code: ".$this->response_code."
194
-                Response Reason Code: ".$this->response_reason_code."
195
-                Response Reason Text: ".$this->response_reason_text."
193
+                Response Code: ".$this->response_code . "
194
+                Response Reason Code: ".$this->response_reason_code . "
195
+                Response Reason Text: ".$this->response_reason_text . "
196 196
                 ";
197 197
             }
198 198
             
Please login to merge, or discard this patch.
includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 
51 51
 	public function __construct($login, $transkey, $test = self::USE_PRODUCTION_SERVER)
52 52
 	{
53
-		$login    = trim($login);
53
+		$login = trim($login);
54 54
         $transkey = trim($transkey);
55 55
         if (empty($login) || empty($transkey))
56 56
         {
@@ -73,14 +73,14 @@  discard block
 block discarded – undo
73 73
     private function removeResponseXMLNS($input)
74 74
     {
75 75
         // why remove them one at a time? all three aren't consistantly used in the response
76
-        $input = str_replace(' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"','',$input);
77
-        $input = str_replace(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"','',$input);
78
-        return str_replace(' xmlns:xsd="http://www.w3.org/2001/XMLSchema"','',$input);
76
+        $input = str_replace(' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"', '', $input);
77
+        $input = str_replace(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"', '', $input);
78
+        return str_replace(' xmlns:xsd="http://www.w3.org/2001/XMLSchema"', '', $input);
79 79
     }
80 80
 
81 81
 	public function __toString()
82 82
 	{
83
-	    $output  = '';
83
+	    $output = '';
84 84
         $output .= '<table summary="Authorize.Net Results" id="authnet">' . "\n";
85 85
         $output .= '<tr>' . "\n\t\t" . '<th colspan="2"><b>Class Parameters</b></th>' . "\n" . '</tr>' . "\n";
86 86
         $output .= '<tr>' . "\n\t\t" . '<td><b>API Login ID</b></td><td>' . $this->login . '</td>' . "\n" . '</tr>' . "\n";
@@ -159,9 +159,9 @@  discard block
 block discarded – undo
159 159
             {
160 160
                 if (is_array($value))
161 161
                 {
162
-                    if(is_numeric($key))
162
+                    if (is_numeric($key))
163 163
                     {
164
-                        if($first === true)
164
+                        if ($first === true)
165 165
                         {
166 166
                             $xmlx  = $xml;
167 167
                             $first = false;
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
     	curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 2);
201 201
     	curl_setopt($this->ch, CURLOPT_CAINFO, dirname(__FILE__) . '/ssl/cert.pem');
202 202
 
203
-        if(($this->response = curl_exec($this->ch)) !== false)
203
+        if (($this->response = curl_exec($this->ch)) !== false)
204 204
         {
205 205
             $this->response_xml = @new SimpleXMLElement($this->response);
206 206
 
Please login to merge, or discard this patch.
includes/class-wpinv-addons.php 1 patch
Spacing   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * All Invoicing extensions screen related functions can be found here.
6 6
  *
7 7
  */
8
-if ( ! defined( 'ABSPATH' ) ) {
8
+if (!defined('ABSPATH')) {
9 9
 	exit;
10 10
 }
11 11
 
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 	 *
21 21
 	 * @return array of tabs.
22 22
 	 */
23
-	public function get_tabs(){
23
+	public function get_tabs() {
24 24
 		$tabs = array(
25 25
 			'addons' => __("Addons", "invoicing"),
26 26
             'gateways' => __("Payment Gateways", "invoicing"),
@@ -38,28 +38,28 @@  discard block
 block discarded – undo
38 38
 	 *
39 39
 	 * @return array
40 40
 	 */
41
-	public function get_section_data( $section_id ) {
42
-		$section      = self::get_tab( $section_id );
41
+	public function get_section_data($section_id) {
42
+		$section      = self::get_tab($section_id);
43 43
 		$api_url = "https://wpinvoicing.com/edd-api/v2/products/";
44 44
 		$section_data = new stdClass();
45 45
 
46
-		if($section_id=='recommended_plugins'){
46
+		if ($section_id == 'recommended_plugins') {
47 47
 			$section_data->products = self::get_recommend_wp_plugins_edd_formatted();
48 48
 		}
49
-		elseif ( ! empty( $section ) ) {
50
-			if ( false === ( $section_data = get_transient( 'wpi_addons_section_' . $section_id ) ) ) { //@todo restore after testing
49
+		elseif (!empty($section)) {
50
+			if (false === ($section_data = get_transient('wpi_addons_section_' . $section_id))) { //@todo restore after testing
51 51
 			//if ( 1==1) {
52 52
 
53
-				$query_args = array( 'category' => $section_id, 'number' => 100);
54
-				$query_args = apply_filters('wpeu_edd_api_query_args',$query_args,$api_url,$section_id);
53
+				$query_args = array('category' => $section_id, 'number' => 100);
54
+				$query_args = apply_filters('wpeu_edd_api_query_args', $query_args, $api_url, $section_id);
55 55
 
56
-				$raw_section = wp_safe_remote_get( esc_url_raw( add_query_arg($query_args ,$api_url) ), array( 'user-agent' => 'Invoicing Addons Page','timeout'     => 15, ) );
56
+				$raw_section = wp_safe_remote_get(esc_url_raw(add_query_arg($query_args, $api_url)), array('user-agent' => 'Invoicing Addons Page', 'timeout'     => 15,));
57 57
 
58
-				if ( ! is_wp_error( $raw_section ) ) {
59
-					$section_data = json_decode( wp_remote_retrieve_body( $raw_section ) );
58
+				if (!is_wp_error($raw_section)) {
59
+					$section_data = json_decode(wp_remote_retrieve_body($raw_section));
60 60
 
61
-					if ( ! empty( $section_data->products ) ) {
62
-						set_transient( 'wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS );
61
+					if (!empty($section_data->products)) {
62
+						set_transient('wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS);
63 63
 					}
64 64
 				}
65 65
 			}
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 
68 68
 		$products = isset($section_data->products) ? $section_data->products : '';
69 69
 
70
-		return apply_filters( 'wpi_addons_section_data', $products, $section_id );
70
+		return apply_filters('wpi_addons_section_data', $products, $section_id);
71 71
 	}
72 72
 
73 73
 	/**
@@ -78,8 +78,8 @@  discard block
 block discarded – undo
78 78
 	 * @param string $theme
79 79
 	 * @param string $plugin
80 80
 	 */
81
-	public function output_button( $addon ) {
82
-		$current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
81
+	public function output_button($addon) {
82
+		$current_tab = empty($_GET['tab']) ? 'addons' : sanitize_title($_GET['tab']);
83 83
 //		$button_text = __('Free','invoicing');
84 84
 //		$licensing = false;
85 85
 //		$installed = false;
@@ -91,14 +91,14 @@  discard block
 block discarded – undo
91 91
 //		$install_status = 'get';
92 92
 //		$onclick = '';
93 93
 
94
-		$wp_org_themes = array('supreme-directory','directory-starter');
94
+		$wp_org_themes = array('supreme-directory', 'directory-starter');
95 95
 
96 96
 		$button_args = array(
97
-			'type' => ($current_tab == 'addons' || $current_tab =='gateways') ? 'addons' : $current_tab,
97
+			'type' => ($current_tab == 'addons' || $current_tab == 'gateways') ? 'addons' : $current_tab,
98 98
 			'id' => isset($addon->info->id) ? absint($addon->info->id) : '',
99 99
 			'title' => isset($addon->info->title) ? $addon->info->title : '',
100
-			'button_text' => __('Free','invoicing'),
101
-			'price_text' => __('Free','invoicing'),
100
+			'button_text' => __('Free', 'invoicing'),
101
+			'price_text' => __('Free', 'invoicing'),
102 102
 			'link' => isset($addon->info->link) ? $addon->info->link : '', // link to product
103 103
 			'url' => isset($addon->info->link) ? $addon->info->link : '', // button url
104 104
 			'class' => 'button-primary',
@@ -114,83 +114,83 @@  discard block
 block discarded – undo
114 114
 			'update_url' => '',
115 115
 		);
116 116
 
117
-		if( ($current_tab == 'addons' || $current_tab =='gateways') && isset($addon->info->id) && $addon->info->id){
118
-			include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api..
119
-			if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;}
117
+		if (($current_tab == 'addons' || $current_tab == 'gateways') && isset($addon->info->id) && $addon->info->id) {
118
+			include_once(ABSPATH . 'wp-admin/includes/plugin-install.php'); //for plugins_api..
119
+			if (!empty($addon->licensing->edd_slug)) {$button_args['slug'] = $addon->licensing->edd_slug; }
120 120
 			$status = self::install_plugin_install_status($addon);
121 121
 			$button_args['file'] = isset($status['file']) ? $status['file'] : '';
122
-			if(isset($status['status'])){$button_args['install_status'] = $status['status'];}
122
+			if (isset($status['status'])) {$button_args['install_status'] = $status['status']; }
123 123
 			$button_args['update_url'] = "https://wpinvoicing.com";
124
-		}elseif($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) {
125
-			if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;}
124
+		}elseif ($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) {
125
+			if (!empty($addon->licensing->edd_slug)) {$button_args['slug'] = $addon->licensing->edd_slug; }
126 126
 			$button_args['installed'] = self::is_theme_installed($addon);
127
-			if(!in_array($button_args['slug'],$wp_org_themes)){
127
+			if (!in_array($button_args['slug'], $wp_org_themes)) {
128 128
 				$button_args['update_url'] = "https://wpinvoicing.com";
129 129
 			}
130
-		}elseif($current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug){
131
-			include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api..
132
-			$status = install_plugin_install_status(array("slug"=>$button_args['slug'],"version"=>""));
130
+		}elseif ($current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug) {
131
+			include_once(ABSPATH . 'wp-admin/includes/plugin-install.php'); //for plugins_api..
132
+			$status = install_plugin_install_status(array("slug"=>$button_args['slug'], "version"=>""));
133 133
 			$button_args['install_status'] = isset($status['status']) ? $status['status'] : 'install';
134 134
 			$button_args['file'] = isset($status['file']) ? $status['file'] : '';
135 135
 		}
136 136
 
137 137
 		// set price
138
-		if(isset($addon->pricing) && !empty($addon->pricing)){
139
-			if(is_object($addon->pricing)){
140
-				$prices = (Array)$addon->pricing;
138
+		if (isset($addon->pricing) && !empty($addon->pricing)) {
139
+			if (is_object($addon->pricing)) {
140
+				$prices = (Array) $addon->pricing;
141 141
 				$button_args['price'] = reset($prices);
142
-			}elseif(isset($addon->pricing)){
142
+			}elseif (isset($addon->pricing)) {
143 143
 				$button_args['price'] = $addon->pricing;
144 144
 			}
145 145
 		}
146 146
 
147 147
 		// set price text
148
-		if( $button_args['price'] && $button_args['price'] != '0.00' ){
149
-			$button_args['price_text'] = sprintf( __('From: $%d', 'invoicing'), $button_args['price']);
148
+		if ($button_args['price'] && $button_args['price'] != '0.00') {
149
+			$button_args['price_text'] = sprintf(__('From: $%d', 'invoicing'), $button_args['price']);
150 150
 		}
151 151
 
152 152
 
153 153
 		// set if installed
154
-		if(in_array($button_args['install_status'], array('installed','latest_installed','update_available','newer_installed'))){
154
+		if (in_array($button_args['install_status'], array('installed', 'latest_installed', 'update_available', 'newer_installed'))) {
155 155
 			$button_args['installed'] = true;
156 156
 		}
157 157
 
158 158
 //		print_r($button_args);
159 159
 		// set if active
160
-		if($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')){
161
-			if($button_args['type'] != 'themes'){
160
+		if ($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')) {
161
+			if ($button_args['type'] != 'themes') {
162 162
 				$button_args['active'] = is_plugin_active($button_args['file']);
163
-			}else{
163
+			} else {
164 164
 				$button_args['active'] = self::is_theme_active($addon);
165 165
 			}
166 166
 		}
167 167
 
168 168
 		// set button text and class
169
-		if($button_args['active']){
170
-			$button_args['button_text'] = __('Active','invoicing');
169
+		if ($button_args['active']) {
170
+			$button_args['button_text'] = __('Active', 'invoicing');
171 171
 			$button_args['class'] = ' button-secondary disabled ';
172
-		}elseif($button_args['installed']){
173
-			$button_args['button_text'] = __('Activate','invoicing');
172
+		}elseif ($button_args['installed']) {
173
+			$button_args['button_text'] = __('Activate', 'invoicing');
174 174
 
175
-			if($button_args['type'] != 'themes'){
176
-				if ( current_user_can( 'manage_options' ) ) {
177
-					$button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin='.$button_args['file']), 'activate-plugin_' . $button_args['file']);
178
-				}else{
175
+			if ($button_args['type'] != 'themes') {
176
+				if (current_user_can('manage_options')) {
177
+					$button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin=' . $button_args['file']), 'activate-plugin_' . $button_args['file']);
178
+				} else {
179 179
 					$button_args['url'] = '#';
180 180
 				}
181
-			}else{
182
-				if ( current_user_can( 'switch_themes' ) ) {
181
+			} else {
182
+				if (current_user_can('switch_themes')) {
183 183
 					$button_args['url'] = self::get_theme_activation_url($addon);
184
-				}else{
184
+				} else {
185 185
 					$button_args['url'] = '#';
186 186
 				}
187 187
 			}
188 188
 
189
-		}else{
190
-			if($button_args['type'] == 'recommended_plugins'){
191
-				$button_args['button_text'] = __('Install','invoicing');
192
-			}else{
193
-				$button_args['button_text'] = __('Get it','invoicing');
189
+		} else {
190
+			if ($button_args['type'] == 'recommended_plugins') {
191
+				$button_args['button_text'] = __('Install', 'invoicing');
192
+			} else {
193
+				$button_args['button_text'] = __('Get it', 'invoicing');
194 194
 
195 195
 				/*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){
196 196
 					$button_args['button_text'] = __('Install','invoicing');
@@ -203,45 +203,45 @@  discard block
 block discarded – undo
203 203
 
204 204
 		
205 205
 		// filter the button arguments
206
-		$button_args = apply_filters('edd_api_button_args',$button_args);
206
+		$button_args = apply_filters('edd_api_button_args', $button_args);
207 207
 //		print_r($button_args);
208 208
 		// set price text
209
-		if(isset($button_args['price_text'])){
209
+		if (isset($button_args['price_text'])) {
210 210
 			?>
211 211
 			<a
212 212
 				target="_blank"
213 213
 				class="addons-price-text"
214
-				href="<?php echo esc_url( $button_args['link'] ); ?>">
215
-				<?php echo esc_html( $button_args['price_text'] ); ?>
214
+				href="<?php echo esc_url($button_args['link']); ?>">
215
+				<?php echo esc_html($button_args['price_text']); ?>
216 216
 			</a>
217 217
 			<?php
218 218
 		}
219 219
 
220 220
 
221 221
 		$target = '';
222
-		if ( ! empty( $button_args['url'] ) ) {
222
+		if (!empty($button_args['url'])) {
223 223
 			$target = strpos($button_args['url'], get_site_url()) !== false ? '' : ' target="_blank" ';
224 224
 		}
225 225
 
226 226
 		?>
227 227
 		<a
228
-			data-licence="<?php echo esc_attr($button_args['license']);?>"
229
-			data-licensing="<?php echo $button_args['licensing'] ? 1 : 0;?>"
230
-			data-title="<?php echo esc_attr($button_args['title']);?>"
231
-			data-type="<?php echo esc_attr($button_args['type']);?>"
232
-			data-text-error-message="<?php _e('Something went wrong!','invoicing');?>"
233
-			data-text-activate="<?php _e('Activate','invoicing');?>"
234
-			data-text-activating="<?php _e('Activating','invoicing');?>"
235
-			data-text-deactivate="<?php _e('Deactivate','invoicing');?>"
236
-			data-text-installed="<?php _e('Installed','invoicing');?>"
237
-			data-text-install="<?php _e('Install','invoicing');?>"
238
-			data-text-installing="<?php _e('Installing','invoicing');?>"
239
-			data-text-error="<?php _e('Error','invoicing');?>"
240
-			<?php if(!empty($button_args['onclick'])){echo " onclick='".$button_args['onclick']."' ";}?>
241
-			<?php echo $target;?>
242
-			class="addons-button  <?php echo esc_attr( $button_args['class'] ); ?>"
243
-			href="<?php echo esc_url( $button_args['url'] ); ?>">
244
-			<?php echo esc_html( $button_args['button_text'] ); ?>
228
+			data-licence="<?php echo esc_attr($button_args['license']); ?>"
229
+			data-licensing="<?php echo $button_args['licensing'] ? 1 : 0; ?>"
230
+			data-title="<?php echo esc_attr($button_args['title']); ?>"
231
+			data-type="<?php echo esc_attr($button_args['type']); ?>"
232
+			data-text-error-message="<?php _e('Something went wrong!', 'invoicing'); ?>"
233
+			data-text-activate="<?php _e('Activate', 'invoicing'); ?>"
234
+			data-text-activating="<?php _e('Activating', 'invoicing'); ?>"
235
+			data-text-deactivate="<?php _e('Deactivate', 'invoicing'); ?>"
236
+			data-text-installed="<?php _e('Installed', 'invoicing'); ?>"
237
+			data-text-install="<?php _e('Install', 'invoicing'); ?>"
238
+			data-text-installing="<?php _e('Installing', 'invoicing'); ?>"
239
+			data-text-error="<?php _e('Error', 'invoicing'); ?>"
240
+			<?php if (!empty($button_args['onclick'])) {echo " onclick='" . $button_args['onclick'] . "' "; }?>
241
+			<?php echo $target; ?>
242
+			class="addons-button  <?php echo esc_attr($button_args['class']); ?>"
243
+			href="<?php echo esc_url($button_args['url']); ?>">
244
+			<?php echo esc_html($button_args['button_text']); ?>
245 245
 		</a>
246 246
 		<?php
247 247
 
@@ -256,35 +256,35 @@  discard block
 block discarded – undo
256 256
 		$tabs            = self::get_tabs();
257 257
 		$sections        = self::get_sections();
258 258
 		$theme           = wp_get_theme();
259
-		$section_keys    = array_keys( $sections );
260
-		$current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys );
261
-		$current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
262
-		include_once( WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php' );
259
+		$section_keys    = array_keys($sections);
260
+		$current_section = isset($_GET['section']) ? sanitize_text_field($_GET['section']) : current($section_keys);
261
+		$current_tab     = empty($_GET['tab']) ? 'addons' : sanitize_title($_GET['tab']);
262
+		include_once(WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php');
263 263
 	}
264 264
 
265 265
 	/**
266 266
 	 * A list of recommended wp.org plugins.
267 267
 	 * @return array
268 268
 	 */
269
-	public function get_recommend_wp_plugins(){
269
+	public function get_recommend_wp_plugins() {
270 270
 		$plugins = array(
271 271
             'invoicing-quotes' => array(
272 272
                 'url'   => 'https://wordpress.org/plugins/invoicing-quotes/',
273 273
                 'slug'   => 'invoicing-quotes',
274 274
                 'name'   => 'Quotes',
275
-                'desc'   => __('Allows you to create quotes, send them to clients and convert them to Invoices when accepted by the customer.','invoicing'),
275
+                'desc'   => __('Allows you to create quotes, send them to clients and convert them to Invoices when accepted by the customer.', 'invoicing'),
276 276
             ),
277 277
             'geodirectory' => array(
278 278
                 'url'   => 'https://wordpress.org/plugins/geodirectory/',
279 279
                 'slug'   => 'geodirectory',
280 280
                 'name'   => 'GeoDirectory',
281
-                'desc'   => __('Turn any WordPress theme into a global business directory portal.','invoicing'),
281
+                'desc'   => __('Turn any WordPress theme into a global business directory portal.', 'invoicing'),
282 282
             ),
283 283
             'userswp' => array(
284 284
                 'url'   => 'https://wordpress.org/plugins/userswp/',
285 285
                 'slug'   => 'userswp',
286 286
                 'name'   => 'UsersWP',
287
-                'desc'   => __('Allow frontend user login and registration as well as have slick profile pages.','invoicing'),
287
+                'desc'   => __('Allow frontend user login and registration as well as have slick profile pages.', 'invoicing'),
288 288
             ),
289 289
 		);
290 290
 
Please login to merge, or discard this patch.
includes/class-wpinv-invoice.php 1 patch
Spacing   +617 added lines, -617 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  discard block
 block discarded – undo
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
 final class WPInv_Invoice {
15
-    public $ID  = 0;
15
+    public $ID = 0;
16 16
     public $title;
17 17
     public $post_type;
18 18
     
@@ -65,17 +65,17 @@  discard block
 block discarded – undo
65 65
     public $full_name = '';
66 66
     public $parent_invoice = 0;
67 67
     
68
-    public function __construct( $invoice_id = false ) {
69
-        if( empty( $invoice_id ) ) {
68
+    public function __construct($invoice_id = false) {
69
+        if (empty($invoice_id)) {
70 70
             return false;
71 71
         }
72 72
 
73
-        $this->setup_invoice( $invoice_id );
73
+        $this->setup_invoice($invoice_id);
74 74
     }
75 75
 
76
-    public function get( $key ) {
77
-        if ( method_exists( $this, 'get_' . $key ) ) {
78
-            $value = call_user_func( array( $this, 'get_' . $key ) );
76
+    public function get($key) {
77
+        if (method_exists($this, 'get_' . $key)) {
78
+            $value = call_user_func(array($this, 'get_' . $key));
79 79
         } else {
80 80
             $value = $this->$key;
81 81
         }
@@ -83,51 +83,51 @@  discard block
 block discarded – undo
83 83
         return $value;
84 84
     }
85 85
 
86
-    public function set( $key, $value ) {
87
-        $ignore = array( 'items', 'cart_details', 'fees', '_ID' );
86
+    public function set($key, $value) {
87
+        $ignore = array('items', 'cart_details', 'fees', '_ID');
88 88
 
89
-        if ( $key === 'status' ) {
89
+        if ($key === 'status') {
90 90
             $this->old_status = $this->status;
91 91
         }
92 92
 
93
-        if ( ! in_array( $key, $ignore ) ) {
94
-            $this->pending[ $key ] = $value;
93
+        if (!in_array($key, $ignore)) {
94
+            $this->pending[$key] = $value;
95 95
         }
96 96
 
97
-        if( '_ID' !== $key ) {
97
+        if ('_ID' !== $key) {
98 98
             $this->$key = $value;
99 99
         }
100 100
     }
101 101
 
102
-    public function _isset( $name ) {
103
-        if ( property_exists( $this, $name) ) {
104
-            return false === empty( $this->$name );
102
+    public function _isset($name) {
103
+        if (property_exists($this, $name)) {
104
+            return false === empty($this->$name);
105 105
         } else {
106 106
             return null;
107 107
         }
108 108
     }
109 109
 
110
-    private function setup_invoice( $invoice_id ) {
110
+    private function setup_invoice($invoice_id) {
111 111
         $this->pending = array();
112 112
 
113
-        if ( empty( $invoice_id ) ) {
113
+        if (empty($invoice_id)) {
114 114
             return false;
115 115
         }
116 116
 
117
-        $invoice = get_post( $invoice_id );
117
+        $invoice = get_post($invoice_id);
118 118
 
119
-        if( !$invoice || is_wp_error( $invoice ) ) {
119
+        if (!$invoice || is_wp_error($invoice)) {
120 120
             return false;
121 121
         }
122 122
 
123
-        if( !('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type) ) {
123
+        if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) {
124 124
             return false;
125 125
         }
126 126
 
127
-        do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id );
127
+        do_action('wpinv_pre_setup_invoice', $this, $invoice_id);
128 128
         
129 129
         // Primary Identifier
130
-        $this->ID              = absint( $invoice_id );
130
+        $this->ID              = absint($invoice_id);
131 131
         $this->post_type       = $invoice->post_type;
132 132
         
133 133
         // We have a payment, get the generic payment_meta item to reduce calls to it
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
         $this->post_status     = $this->status;
140 140
         $this->mode            = $this->setup_mode();
141 141
         $this->parent_invoice  = $invoice->post_parent;
142
-        $this->post_name       = $this->setup_post_name( $invoice );
142
+        $this->post_name       = $this->setup_post_name($invoice);
143 143
         $this->status_nicename = $this->setup_status_nicename($invoice->post_status);
144 144
 
145 145
         // Items
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
         
162 162
         // User based
163 163
         $this->ip              = $this->setup_ip();
164
-        $this->user_id         = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id();
165
-        $this->email           = get_the_author_meta( 'email', $this->user_id );
164
+        $this->user_id         = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id();
165
+        $this->email           = get_the_author_meta('email', $this->user_id);
166 166
         
167 167
         $this->user_info       = $this->setup_user_info();
168 168
                 
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
         $this->company         = $this->user_info['company'];
172 172
         $this->vat_number      = $this->user_info['vat_number'];
173 173
         $this->vat_rate        = $this->user_info['vat_rate'];
174
-        $this->adddress_confirmed  = $this->user_info['adddress_confirmed'];
174
+        $this->adddress_confirmed = $this->user_info['adddress_confirmed'];
175 175
         $this->address         = $this->user_info['address'];
176 176
         $this->city            = $this->user_info['city'];
177 177
         $this->country         = $this->user_info['country'];
@@ -186,35 +186,35 @@  discard block
 block discarded – undo
186 186
         // Other Identifiers
187 187
         $this->key             = $this->setup_invoice_key();
188 188
         $this->number          = $this->setup_invoice_number();
189
-        $this->title           = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number;
189
+        $this->title           = !empty($invoice->post_title) ? $invoice->post_title : $this->number;
190 190
         
191
-        $this->full_name       = trim( $this->first_name . ' '. $this->last_name );
191
+        $this->full_name       = trim($this->first_name . ' ' . $this->last_name);
192 192
         
193 193
         // Allow extensions to add items to this object via hook
194
-        do_action( 'wpinv_setup_invoice', $this, $invoice_id );
194
+        do_action('wpinv_setup_invoice', $this, $invoice_id);
195 195
 
196 196
         return true;
197 197
     }
198 198
     
199
-    private function setup_status_nicename( $status ) {
200
-        $all_invoice_statuses  = wpinv_get_invoice_statuses( true, true, $this );
201
-        $status   = isset( $all_invoice_statuses[$status] ) ? $all_invoice_statuses[$status] : __( $status, 'invoicing' );
199
+    private function setup_status_nicename($status) {
200
+        $all_invoice_statuses = wpinv_get_invoice_statuses(true, true, $this);
201
+        $status = isset($all_invoice_statuses[$status]) ? $all_invoice_statuses[$status] : __($status, 'invoicing');
202 202
 
203
-        return apply_filters( 'setup_status_nicename', $status );
203
+        return apply_filters('setup_status_nicename', $status);
204 204
     }
205 205
     
206
-    private function setup_post_name( $post = NULL ) {
206
+    private function setup_post_name($post = NULL) {
207 207
         global $wpdb;
208 208
         
209 209
         $post_name = '';
210 210
         
211
-        if ( !empty( $post ) ) {
212
-            if( !empty( $post->post_name ) ) {
211
+        if (!empty($post)) {
212
+            if (!empty($post->post_name)) {
213 213
                 $post_name = $post->post_name;
214
-            } else if ( !empty( $post->ID ) ) {
215
-                $post_name = wpinv_generate_post_name( $post->ID );
214
+            } else if (!empty($post->ID)) {
215
+                $post_name = wpinv_generate_post_name($post->ID);
216 216
 
217
-                $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) );
217
+                $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID));
218 218
             }
219 219
         }
220 220
 
@@ -222,12 +222,12 @@  discard block
 block discarded – undo
222 222
     }
223 223
     
224 224
     private function setup_due_date() {
225
-        $due_date = $this->get_meta( '_wpinv_due_date' );
225
+        $due_date = $this->get_meta('_wpinv_due_date');
226 226
         
227
-        if ( empty( $due_date ) ) {
228
-            $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) );
229
-            $due_date = date_i18n( 'Y-m-d', $overdue_time );
230
-        } else if ( $due_date == 'none' ) {
227
+        if (empty($due_date)) {
228
+            $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days')));
229
+            $due_date = date_i18n('Y-m-d', $overdue_time);
230
+        } else if ($due_date == 'none') {
231 231
             $due_date = '';
232 232
         }
233 233
         
@@ -235,66 +235,66 @@  discard block
 block discarded – undo
235 235
     }
236 236
     
237 237
     private function setup_completed_date() {
238
-        $invoice = get_post( $this->ID );
238
+        $invoice = get_post($this->ID);
239 239
 
240
-        if ( 'wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) {
240
+        if ('wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) {
241 241
             return false; // This invoice was never paid
242 242
         }
243 243
 
244
-        $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date;
244
+        $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date;
245 245
 
246 246
         return $date;
247 247
     }
248 248
     
249 249
     private function setup_cart_details() {
250
-        $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array();
250
+        $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array();
251 251
         return $cart_details;
252 252
     }
253 253
     
254 254
     public function array_convert() {
255
-        return get_object_vars( $this );
255
+        return get_object_vars($this);
256 256
     }
257 257
     
258 258
     private function setup_items() {
259
-        $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array();
259
+        $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array();
260 260
         return $items;
261 261
     }
262 262
     
263 263
     private function setup_fees() {
264
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
264
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
265 265
         return $payment_fees;
266 266
     }
267 267
         
268 268
     private function setup_currency() {
269
-        $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this );
269
+        $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this);
270 270
         return $currency;
271 271
     }
272 272
     
273 273
     private function setup_discount() {
274 274
         //$discount = $this->get_meta( '_wpinv_discount', true );
275
-        $discount = (float)$this->subtotal - ( (float)$this->total - (float)$this->tax - (float)$this->fees_total );
276
-        if ( $discount < 0 ) {
275
+        $discount = (float) $this->subtotal - ((float) $this->total - (float) $this->tax - (float) $this->fees_total);
276
+        if ($discount < 0) {
277 277
             $discount = 0;
278 278
         }
279
-        $discount = wpinv_round_amount( $discount );
279
+        $discount = wpinv_round_amount($discount);
280 280
         
281 281
         return $discount;
282 282
     }
283 283
     
284 284
     private function setup_discount_code() {
285
-        $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true );
285
+        $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true);
286 286
         return $discount_code;
287 287
     }
288 288
     
289 289
     private function setup_tax() {
290
-        $tax = $this->get_meta( '_wpinv_tax', true );
290
+        $tax = $this->get_meta('_wpinv_tax', true);
291 291
 
292 292
         // We don't have tax as it's own meta and no meta was passed
293
-        if ( '' === $tax ) {            
294
-            $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0;
293
+        if ('' === $tax) {            
294
+            $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0;
295 295
         }
296 296
         
297
-        if ( $tax < 0 ) {
297
+        if ($tax < 0) {
298 298
             $tax = 0;
299 299
         }
300 300
 
@@ -305,9 +305,9 @@  discard block
 block discarded – undo
305 305
         $subtotal     = 0;
306 306
         $cart_details = $this->cart_details;
307 307
 
308
-        if ( is_array( $cart_details ) ) {
309
-            foreach ( $cart_details as $item ) {
310
-                if ( isset( $item['subtotal'] ) ) {
308
+        if (is_array($cart_details)) {
309
+            foreach ($cart_details as $item) {
310
+                if (isset($item['subtotal'])) {
311 311
                     $subtotal += $item['subtotal'];
312 312
                 }
313 313
             }
@@ -321,23 +321,23 @@  discard block
 block discarded – undo
321 321
     }
322 322
     
323 323
     private function setup_discounts() {
324
-        $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array();
324
+        $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array();
325 325
         return $discounts;
326 326
     }
327 327
     
328 328
     private function setup_total() {
329
-        $amount = $this->get_meta( '_wpinv_total', true );
329
+        $amount = $this->get_meta('_wpinv_total', true);
330 330
 
331
-        if ( empty( $amount ) && '0.00' != $amount ) {
332
-            $meta   = $this->get_meta( '_wpinv_payment_meta', true );
333
-            $meta   = maybe_unserialize( $meta );
331
+        if (empty($amount) && '0.00' != $amount) {
332
+            $meta   = $this->get_meta('_wpinv_payment_meta', true);
333
+            $meta   = maybe_unserialize($meta);
334 334
 
335
-            if ( isset( $meta['amount'] ) ) {
335
+            if (isset($meta['amount'])) {
336 336
                 $amount = $meta['amount'];
337 337
             }
338 338
         }
339 339
 
340
-        if($amount < 0){
340
+        if ($amount < 0) {
341 341
             $amount = 0;
342 342
         }
343 343
 
@@ -345,13 +345,13 @@  discard block
 block discarded – undo
345 345
     }
346 346
     
347 347
     private function setup_mode() {
348
-        return $this->get_meta( '_wpinv_mode' );
348
+        return $this->get_meta('_wpinv_mode');
349 349
     }
350 350
 
351 351
     private function setup_gateway() {
352
-        $gateway = $this->get_meta( '_wpinv_gateway' );
352
+        $gateway = $this->get_meta('_wpinv_gateway');
353 353
         
354
-        if ( empty( $gateway ) && 'publish' === $this->status ) {
354
+        if (empty($gateway) && 'publish' === $this->status) {
355 355
             $gateway = 'manual';
356 356
         }
357 357
         
@@ -359,23 +359,23 @@  discard block
 block discarded – undo
359 359
     }
360 360
     
361 361
     private function setup_gateway_title() {
362
-        $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway );
362
+        $gateway_title = wpinv_get_gateway_checkout_label($this->gateway);
363 363
         return $gateway_title;
364 364
     }
365 365
 
366 366
     private function setup_transaction_id() {
367
-        $transaction_id = $this->get_meta( '_wpinv_transaction_id' );
367
+        $transaction_id = $this->get_meta('_wpinv_transaction_id');
368 368
 
369
-        if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) {
369
+        if (empty($transaction_id) || (int) $transaction_id === (int) $this->ID) {
370 370
             $gateway        = $this->gateway;
371
-            $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID );
371
+            $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID);
372 372
         }
373 373
 
374 374
         return $transaction_id;
375 375
     }
376 376
 
377 377
     private function setup_ip() {
378
-        $ip = $this->get_meta( '_wpinv_user_ip' );
378
+        $ip = $this->get_meta('_wpinv_user_ip');
379 379
         return $ip;
380 380
     }
381 381
 
@@ -385,62 +385,62 @@  discard block
 block discarded – undo
385 385
     ///}
386 386
         
387 387
     private function setup_first_name() {
388
-        $first_name = $this->get_meta( '_wpinv_first_name' );
388
+        $first_name = $this->get_meta('_wpinv_first_name');
389 389
         return $first_name;
390 390
     }
391 391
     
392 392
     private function setup_last_name() {
393
-        $last_name = $this->get_meta( '_wpinv_last_name' );
393
+        $last_name = $this->get_meta('_wpinv_last_name');
394 394
         return $last_name;
395 395
     }
396 396
     
397 397
     private function setup_company() {
398
-        $company = $this->get_meta( '_wpinv_company' );
398
+        $company = $this->get_meta('_wpinv_company');
399 399
         return $company;
400 400
     }
401 401
     
402 402
     private function setup_vat_number() {
403
-        $vat_number = $this->get_meta( '_wpinv_vat_number' );
403
+        $vat_number = $this->get_meta('_wpinv_vat_number');
404 404
         return $vat_number;
405 405
     }
406 406
     
407 407
     private function setup_vat_rate() {
408
-        $vat_rate = $this->get_meta( '_wpinv_vat_rate' );
408
+        $vat_rate = $this->get_meta('_wpinv_vat_rate');
409 409
         return $vat_rate;
410 410
     }
411 411
     
412 412
     private function setup_adddress_confirmed() {
413
-        $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' );
413
+        $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed');
414 414
         return $adddress_confirmed;
415 415
     }
416 416
     
417 417
     private function setup_phone() {
418
-        $phone = $this->get_meta( '_wpinv_phone' );
418
+        $phone = $this->get_meta('_wpinv_phone');
419 419
         return $phone;
420 420
     }
421 421
     
422 422
     private function setup_address() {
423
-        $address = $this->get_meta( '_wpinv_address', true );
423
+        $address = $this->get_meta('_wpinv_address', true);
424 424
         return $address;
425 425
     }
426 426
     
427 427
     private function setup_city() {
428
-        $city = $this->get_meta( '_wpinv_city', true );
428
+        $city = $this->get_meta('_wpinv_city', true);
429 429
         return $city;
430 430
     }
431 431
     
432 432
     private function setup_country() {
433
-        $country = $this->get_meta( '_wpinv_country', true );
433
+        $country = $this->get_meta('_wpinv_country', true);
434 434
         return $country;
435 435
     }
436 436
     
437 437
     private function setup_state() {
438
-        $state = $this->get_meta( '_wpinv_state', true );
438
+        $state = $this->get_meta('_wpinv_state', true);
439 439
         return $state;
440 440
     }
441 441
     
442 442
     private function setup_zip() {
443
-        $zip = $this->get_meta( '_wpinv_zip', true );
443
+        $zip = $this->get_meta('_wpinv_zip', true);
444 444
         return $zip;
445 445
     }
446 446
 
@@ -449,7 +449,7 @@  discard block
 block discarded – undo
449 449
             'user_id'        => $this->user_id,
450 450
             'first_name'     => $this->first_name,
451 451
             'last_name'      => $this->last_name,
452
-            'email'          => get_the_author_meta( 'email', $this->user_id ),
452
+            'email'          => get_the_author_meta('email', $this->user_id),
453 453
             'phone'          => $this->phone,
454 454
             'address'        => $this->address,
455 455
             'city'           => $this->city,
@@ -464,12 +464,12 @@  discard block
 block discarded – undo
464 464
         );
465 465
         
466 466
         $user_info = array();
467
-        if ( isset( $this->payment_meta['user_info'] ) ) {
468
-            $user_info = maybe_unserialize( $this->payment_meta['user_info'] );
467
+        if (isset($this->payment_meta['user_info'])) {
468
+            $user_info = maybe_unserialize($this->payment_meta['user_info']);
469 469
             
470
-            if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) {
470
+            if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) {
471 471
                 $this->user_id = $post->post_author;
472
-                $this->email = get_the_author_meta( 'email', $this->user_id );
472
+                $this->email = get_the_author_meta('email', $this->user_id);
473 473
                 
474 474
                 $user_info['user_id'] = $this->user_id;
475 475
                 $user_info['email'] = $this->email;
@@ -478,13 +478,13 @@  discard block
 block discarded – undo
478 478
             }
479 479
         }
480 480
         
481
-        $user_info    = wp_parse_args( $user_info, $defaults );
481
+        $user_info = wp_parse_args($user_info, $defaults);
482 482
         
483 483
         // Get the user, but only if it's been created
484
-        $user = get_userdata( $this->user_id );
484
+        $user = get_userdata($this->user_id);
485 485
         
486
-        if ( !empty( $user ) && $user->ID > 0 ) {
487
-            if ( empty( $user_info ) ) {
486
+        if (!empty($user) && $user->ID > 0) {
487
+            if (empty($user_info)) {
488 488
                 $user_info = array(
489 489
                     'user_id'    => $user->ID,
490 490
                     'first_name' => $user->first_name,
@@ -493,23 +493,23 @@  discard block
 block discarded – undo
493 493
                     'discount'   => '',
494 494
                 );
495 495
             } else {
496
-                foreach ( $user_info as $key => $value ) {
497
-                    if ( ! empty( $value ) ) {
496
+                foreach ($user_info as $key => $value) {
497
+                    if (!empty($value)) {
498 498
                         continue;
499 499
                     }
500 500
 
501
-                    switch( $key ) {
501
+                    switch ($key) {
502 502
                         case 'user_id':
503
-                            $user_info[ $key ] = $user->ID;
503
+                            $user_info[$key] = $user->ID;
504 504
                             break;
505 505
                         case 'first_name':
506
-                            $user_info[ $key ] = $user->first_name;
506
+                            $user_info[$key] = $user->first_name;
507 507
                             break;
508 508
                         case 'last_name':
509
-                            $user_info[ $key ] = $user->last_name;
509
+                            $user_info[$key] = $user->last_name;
510 510
                             break;
511 511
                         case 'email':
512
-                            $user_info[ $key ] = $user->user_email;
512
+                            $user_info[$key] = $user->user_email;
513 513
                             break;
514 514
                     }
515 515
                 }
@@ -520,25 +520,25 @@  discard block
 block discarded – undo
520 520
     }
521 521
 
522 522
     private function setup_invoice_key() {
523
-        $key = $this->get_meta( '_wpinv_key', true );
523
+        $key = $this->get_meta('_wpinv_key', true);
524 524
         
525 525
         return $key;
526 526
     }
527 527
 
528 528
     private function setup_invoice_number() {
529
-        $number = $this->get_meta( '_wpinv_number', true );
529
+        $number = $this->get_meta('_wpinv_number', true);
530 530
 
531
-        if ( !$number ) {
531
+        if (!$number) {
532 532
             $number = $this->ID;
533 533
 
534
-            if ( $this->status == 'auto-draft' ) {
535
-                if ( wpinv_sequential_number_active( $this->post_type ) ) {
536
-                    $next_number = wpinv_get_next_invoice_number( $this->post_type );
534
+            if ($this->status == 'auto-draft') {
535
+                if (wpinv_sequential_number_active($this->post_type)) {
536
+                    $next_number = wpinv_get_next_invoice_number($this->post_type);
537 537
                     $number      = $next_number;
538 538
                 }
539 539
             }
540 540
             
541
-            $number = wpinv_format_invoice_number( $number, $this->post_type );
541
+            $number = wpinv_format_invoice_number($number, $this->post_type);
542 542
         }
543 543
 
544 544
         return $number;
@@ -547,10 +547,10 @@  discard block
 block discarded – undo
547 547
     private function insert_invoice() {
548 548
         global $wpdb;
549 549
 
550
-        if ( empty( $this->post_type ) ) {
551
-            if ( !empty( $this->ID ) && $post_type = get_post_type( $this->ID ) ) {
550
+        if (empty($this->post_type)) {
551
+            if (!empty($this->ID) && $post_type = get_post_type($this->ID)) {
552 552
                 $this->post_type = $post_type;
553
-            } else if ( !empty( $this->parent_invoice ) && $post_type = get_post_type( $this->parent_invoice ) ) {
553
+            } else if (!empty($this->parent_invoice) && $post_type = get_post_type($this->parent_invoice)) {
554 554
                 $this->post_type = $post_type;
555 555
             } else {
556 556
                 $this->post_type = 'wpi_invoice';
@@ -558,16 +558,16 @@  discard block
 block discarded – undo
558 558
         }
559 559
 
560 560
         $invoice_number = $this->ID;
561
-        if ( $number = $this->get_meta( '_wpinv_number', true ) ) {
561
+        if ($number = $this->get_meta('_wpinv_number', true)) {
562 562
             $invoice_number = $number;
563 563
         }
564 564
 
565
-        if ( empty( $this->key ) ) {
565
+        if (empty($this->key)) {
566 566
             $this->key = self::generate_key();
567 567
             $this->pending['key'] = $this->key;
568 568
         }
569 569
 
570
-        if ( empty( $this->ip ) ) {
570
+        if (empty($this->ip)) {
571 571
             $this->ip = wpinv_get_ip();
572 572
             $this->pending['ip'] = $this->ip;
573 573
         }
@@ -604,61 +604,61 @@  discard block
 block discarded – undo
604 604
                         'post_status'   => $this->status,
605 605
                         'post_author'   => $this->user_id,
606 606
                         'post_type'     => $this->post_type,
607
-                        'post_date'     => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ),
608
-                        'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ),
607
+                        'post_date'     => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'),
608
+                        'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1),
609 609
                         'post_parent'   => $this->parent_invoice,
610 610
                     );
611
-        $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this );
611
+        $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this);
612 612
 
613 613
         // Create a blank invoice
614
-        if ( !empty( $this->ID ) ) {
615
-            $args['ID']         = $this->ID;
614
+        if (!empty($this->ID)) {
615
+            $args['ID'] = $this->ID;
616 616
 
617
-            $invoice_id = wp_update_post( $args, true );
617
+            $invoice_id = wp_update_post($args, true);
618 618
         } else {
619
-            $invoice_id = wp_insert_post( $args, true );
619
+            $invoice_id = wp_insert_post($args, true);
620 620
         }
621 621
 
622
-        if ( is_wp_error( $invoice_id ) ) {
622
+        if (is_wp_error($invoice_id)) {
623 623
             return false;
624 624
         }
625 625
 
626
-        if ( !empty( $invoice_id ) ) {
626
+        if (!empty($invoice_id)) {
627 627
             $this->ID  = $invoice_id;
628 628
             $this->_ID = $invoice_id;
629 629
 
630
-            $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data );
631
-            if ( ! empty( $this->payment_meta['fees'] ) ) {
632
-                $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] );
633
-                foreach( $this->fees as $fee ) {
634
-                    $this->increase_fees( $fee['amount'] );
630
+            $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data);
631
+            if (!empty($this->payment_meta['fees'])) {
632
+                $this->fees = array_merge($this->fees, $this->payment_meta['fees']);
633
+                foreach ($this->fees as $fee) {
634
+                    $this->increase_fees($fee['amount']);
635 635
                 }
636 636
             }
637 637
 
638
-            $this->update_meta( '_wpinv_payment_meta', $this->payment_meta );            
638
+            $this->update_meta('_wpinv_payment_meta', $this->payment_meta);            
639 639
             $this->new = true;
640 640
         }
641 641
 
642 642
         return $this->ID;
643 643
     }
644 644
 
645
-    public function save( $setup = false ) {
645
+    public function save($setup = false) {
646 646
         global $wpi_session;
647 647
         
648 648
         $saved = false;
649
-        if ( empty( $this->items ) ) {
649
+        if (empty($this->items)) {
650 650
             return $saved; // Don't save empty invoice.
651 651
         }
652 652
         
653
-        if ( empty( $this->key ) ) {
653
+        if (empty($this->key)) {
654 654
             $this->key = self::generate_key();
655 655
             $this->pending['key'] = $this->key;
656 656
         }
657 657
         
658
-        if ( empty( $this->ID ) ) {
658
+        if (empty($this->ID)) {
659 659
             $invoice_id = $this->insert_invoice();
660 660
 
661
-            if ( false === $invoice_id ) {
661
+            if (false === $invoice_id) {
662 662
                 $saved = false;
663 663
             } else {
664 664
                 $this->ID = $invoice_id;
@@ -666,27 +666,27 @@  discard block
 block discarded – undo
666 666
         }
667 667
 
668 668
         // If we have something pending, let's save it
669
-        if ( !empty( $this->pending ) ) {
669
+        if (!empty($this->pending)) {
670 670
             $total_increase = 0;
671 671
             $total_decrease = 0;
672 672
 
673
-            foreach ( $this->pending as $key => $value ) {
674
-                switch( $key ) {
673
+            foreach ($this->pending as $key => $value) {
674
+                switch ($key) {
675 675
                     case 'items':
676 676
                         // Update totals for pending items
677
-                        foreach ( $this->pending[ $key ] as $item ) {
678
-                            switch( $item['action'] ) {
677
+                        foreach ($this->pending[$key] as $item) {
678
+                            switch ($item['action']) {
679 679
                                 case 'add':
680 680
                                     $price = $item['price'];
681 681
                                     $taxes = $item['tax'];
682 682
 
683
-                                    if ( 'publish' === $this->status ) {
683
+                                    if ('publish' === $this->status) {
684 684
                                         $total_increase += $price;
685 685
                                     }
686 686
                                     break;
687 687
 
688 688
                                 case 'remove':
689
-                                    if ( 'publish' === $this->status ) {
689
+                                    if ('publish' === $this->status) {
690 690
                                         $total_decrease += $item['price'];
691 691
                                     }
692 692
                                     break;
@@ -694,16 +694,16 @@  discard block
 block discarded – undo
694 694
                         }
695 695
                         break;
696 696
                     case 'fees':
697
-                        if ( 'publish' !== $this->status ) {
697
+                        if ('publish' !== $this->status) {
698 698
                             break;
699 699
                         }
700 700
 
701
-                        if ( empty( $this->pending[ $key ] ) ) {
701
+                        if (empty($this->pending[$key])) {
702 702
                             break;
703 703
                         }
704 704
 
705
-                        foreach ( $this->pending[ $key ] as $fee ) {
706
-                            switch( $fee['action'] ) {
705
+                        foreach ($this->pending[$key] as $fee) {
706
+                            switch ($fee['action']) {
707 707
                                 case 'add':
708 708
                                     $total_increase += $fee['amount'];
709 709
                                     break;
@@ -715,83 +715,83 @@  discard block
 block discarded – undo
715 715
                         }
716 716
                         break;
717 717
                     case 'status':
718
-                        $this->update_status( $this->status );
718
+                        $this->update_status($this->status);
719 719
                         break;
720 720
                     case 'gateway':
721
-                        $this->update_meta( '_wpinv_gateway', $this->gateway );
721
+                        $this->update_meta('_wpinv_gateway', $this->gateway);
722 722
                         break;
723 723
                     case 'mode':
724
-                        $this->update_meta( '_wpinv_mode', $this->mode );
724
+                        $this->update_meta('_wpinv_mode', $this->mode);
725 725
                         break;
726 726
                     case 'transaction_id':
727
-                        $this->update_meta( '_wpinv_transaction_id', $this->transaction_id );
727
+                        $this->update_meta('_wpinv_transaction_id', $this->transaction_id);
728 728
                         break;
729 729
                     case 'ip':
730
-                        $this->update_meta( '_wpinv_user_ip', $this->ip );
730
+                        $this->update_meta('_wpinv_user_ip', $this->ip);
731 731
                         break;
732 732
                     ///case 'user_id':
733 733
                         ///$this->update_meta( '_wpinv_user_id', $this->user_id );
734 734
                         ///$this->user_info['user_id'] = $this->user_id;
735 735
                         ///break;
736 736
                     case 'first_name':
737
-                        $this->update_meta( '_wpinv_first_name', $this->first_name );
737
+                        $this->update_meta('_wpinv_first_name', $this->first_name);
738 738
                         $this->user_info['first_name'] = $this->first_name;
739 739
                         break;
740 740
                     case 'last_name':
741
-                        $this->update_meta( '_wpinv_last_name', $this->last_name );
741
+                        $this->update_meta('_wpinv_last_name', $this->last_name);
742 742
                         $this->user_info['last_name'] = $this->last_name;
743 743
                         break;
744 744
                     case 'phone':
745
-                        $this->update_meta( '_wpinv_phone', $this->phone );
745
+                        $this->update_meta('_wpinv_phone', $this->phone);
746 746
                         $this->user_info['phone'] = $this->phone;
747 747
                         break;
748 748
                     case 'address':
749
-                        $this->update_meta( '_wpinv_address', $this->address );
749
+                        $this->update_meta('_wpinv_address', $this->address);
750 750
                         $this->user_info['address'] = $this->address;
751 751
                         break;
752 752
                     case 'city':
753
-                        $this->update_meta( '_wpinv_city', $this->city );
753
+                        $this->update_meta('_wpinv_city', $this->city);
754 754
                         $this->user_info['city'] = $this->city;
755 755
                         break;
756 756
                     case 'country':
757
-                        $this->update_meta( '_wpinv_country', $this->country );
757
+                        $this->update_meta('_wpinv_country', $this->country);
758 758
                         $this->user_info['country'] = $this->country;
759 759
                         break;
760 760
                     case 'state':
761
-                        $this->update_meta( '_wpinv_state', $this->state );
761
+                        $this->update_meta('_wpinv_state', $this->state);
762 762
                         $this->user_info['state'] = $this->state;
763 763
                         break;
764 764
                     case 'zip':
765
-                        $this->update_meta( '_wpinv_zip', $this->zip );
765
+                        $this->update_meta('_wpinv_zip', $this->zip);
766 766
                         $this->user_info['zip'] = $this->zip;
767 767
                         break;
768 768
                     case 'company':
769
-                        $this->update_meta( '_wpinv_company', $this->company );
769
+                        $this->update_meta('_wpinv_company', $this->company);
770 770
                         $this->user_info['company'] = $this->company;
771 771
                         break;
772 772
                     case 'vat_number':
773
-                        $this->update_meta( '_wpinv_vat_number', $this->vat_number );
773
+                        $this->update_meta('_wpinv_vat_number', $this->vat_number);
774 774
                         $this->user_info['vat_number'] = $this->vat_number;
775 775
                         
776
-                        $vat_info = $wpi_session->get( 'user_vat_data' );
777
-                        if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) {
778
-                            $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false;
779
-                            $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed );
780
-                            $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed;
776
+                        $vat_info = $wpi_session->get('user_vat_data');
777
+                        if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) {
778
+                            $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
779
+                            $this->update_meta('_wpinv_adddress_confirmed', (bool) $adddress_confirmed);
780
+                            $this->user_info['adddress_confirmed'] = (bool) $adddress_confirmed;
781 781
                         }
782 782
     
783 783
                         break;
784 784
                     case 'vat_rate':
785
-                        $this->update_meta( '_wpinv_vat_rate', $this->vat_rate );
785
+                        $this->update_meta('_wpinv_vat_rate', $this->vat_rate);
786 786
                         $this->user_info['vat_rate'] = $this->vat_rate;
787 787
                         break;
788 788
                     case 'adddress_confirmed':
789
-                        $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed );
789
+                        $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed);
790 790
                         $this->user_info['adddress_confirmed'] = $this->adddress_confirmed;
791 791
                         break;
792 792
                     
793 793
                     case 'key':
794
-                        $this->update_meta( '_wpinv_key', $this->key );
794
+                        $this->update_meta('_wpinv_key', $this->key);
795 795
                         break;
796 796
                     case 'date':
797 797
                         $args = array(
@@ -800,49 +800,49 @@  discard block
 block discarded – undo
800 800
                             'edit_date' => true,
801 801
                         );
802 802
 
803
-                        wp_update_post( $args );
803
+                        wp_update_post($args);
804 804
                         break;
805 805
                     case 'due_date':
806
-                        if ( empty( $this->due_date ) ) {
806
+                        if (empty($this->due_date)) {
807 807
                             $this->due_date = 'none';
808 808
                         }
809 809
                         
810
-                        $this->update_meta( '_wpinv_due_date', $this->due_date );
810
+                        $this->update_meta('_wpinv_due_date', $this->due_date);
811 811
                         break;
812 812
                     case 'completed_date':
813
-                        $this->update_meta( '_wpinv_completed_date', $this->completed_date );
813
+                        $this->update_meta('_wpinv_completed_date', $this->completed_date);
814 814
                         break;
815 815
                     case 'discounts':
816
-                        if ( ! is_array( $this->discounts ) ) {
817
-                            $this->discounts = explode( ',', $this->discounts );
816
+                        if (!is_array($this->discounts)) {
817
+                            $this->discounts = explode(',', $this->discounts);
818 818
                         }
819 819
 
820
-                        $this->user_info['discount'] = implode( ',', $this->discounts );
820
+                        $this->user_info['discount'] = implode(',', $this->discounts);
821 821
                         break;
822 822
                     case 'discount':
823
-                        $this->update_meta( '_wpinv_discount', wpinv_round_amount( $this->discount ) );
823
+                        $this->update_meta('_wpinv_discount', wpinv_round_amount($this->discount));
824 824
                         break;
825 825
                     case 'discount_code':
826
-                        $this->update_meta( '_wpinv_discount_code', $this->discount_code );
826
+                        $this->update_meta('_wpinv_discount_code', $this->discount_code);
827 827
                         break;
828 828
                     case 'parent_invoice':
829 829
                         $args = array(
830 830
                             'ID'          => $this->ID,
831 831
                             'post_parent' => $this->parent_invoice,
832 832
                         );
833
-                        wp_update_post( $args );
833
+                        wp_update_post($args);
834 834
                         break;
835 835
                     default:
836
-                        do_action( 'wpinv_save', $this, $key );
836
+                        do_action('wpinv_save', $this, $key);
837 837
                         break;
838 838
                 }
839 839
             }
840 840
 
841
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
842
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
843
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
841
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
842
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
843
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
844 844
             
845
-            $this->items    = array_values( $this->items );
845
+            $this->items = array_values($this->items);
846 846
             
847 847
             $new_meta = array(
848 848
                 'items'         => $this->items,
@@ -853,12 +853,12 @@  discard block
 block discarded – undo
853 853
             );
854 854
             
855 855
             $meta        = $this->get_meta();
856
-            $merged_meta = array_merge( $meta, $new_meta );
856
+            $merged_meta = array_merge($meta, $new_meta);
857 857
 
858 858
             // Only save the payment meta if it's changed
859
-            if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) {
860
-                $updated     = $this->update_meta( '_wpinv_payment_meta', $merged_meta );
861
-                if ( false !== $updated ) {
859
+            if (md5(serialize($meta)) !== md5(serialize($merged_meta))) {
860
+                $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta);
861
+                if (false !== $updated) {
862 862
                     $saved = true;
863 863
                 }
864 864
             }
@@ -866,15 +866,15 @@  discard block
 block discarded – undo
866 866
             $this->pending = array();
867 867
             $saved         = true;
868 868
         } else {
869
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
870
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
871
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
869
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
870
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
871
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
872 872
         }
873 873
         
874
-        do_action( 'wpinv_invoice_save', $this, $saved );
874
+        do_action('wpinv_invoice_save', $this, $saved);
875 875
 
876
-        if ( true === $saved || $setup ) {
877
-            $this->setup_invoice( $this->ID );
876
+        if (true === $saved || $setup) {
877
+            $this->setup_invoice($this->ID);
878 878
         }
879 879
         
880 880
         $this->refresh_item_ids();
@@ -882,7 +882,7 @@  discard block
 block discarded – undo
882 882
         return $saved;
883 883
     }
884 884
     
885
-    public function add_fee( $args, $global = true ) {
885
+    public function add_fee($args, $global = true) {
886 886
         $default_args = array(
887 887
             'label'       => '',
888 888
             'amount'      => 0,
@@ -892,75 +892,75 @@  discard block
 block discarded – undo
892 892
             'item_id'     => 0,
893 893
         );
894 894
 
895
-        $fee = wp_parse_args( $args, $default_args );
895
+        $fee = wp_parse_args($args, $default_args);
896 896
         
897
-        if ( empty( $fee['label'] ) ) {
897
+        if (empty($fee['label'])) {
898 898
             return false;
899 899
         }
900 900
         
901
-        $fee['id']  = sanitize_title( $fee['label'] );
901
+        $fee['id'] = sanitize_title($fee['label']);
902 902
         
903
-        $this->fees[]               = $fee;
903
+        $this->fees[] = $fee;
904 904
         
905 905
         $added_fee               = $fee;
906 906
         $added_fee['action']     = 'add';
907 907
         $this->pending['fees'][] = $added_fee;
908
-        reset( $this->fees );
908
+        reset($this->fees);
909 909
 
910
-        $this->increase_fees( $fee['amount'] );
910
+        $this->increase_fees($fee['amount']);
911 911
         return true;
912 912
     }
913 913
 
914
-    public function remove_fee( $key ) {
914
+    public function remove_fee($key) {
915 915
         $removed = false;
916 916
 
917
-        if ( is_numeric( $key ) ) {
918
-            $removed = $this->remove_fee_by( 'index', $key );
917
+        if (is_numeric($key)) {
918
+            $removed = $this->remove_fee_by('index', $key);
919 919
         }
920 920
 
921 921
         return $removed;
922 922
     }
923 923
 
924
-    public function remove_fee_by( $key, $value, $global = false ) {
925
-        $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array(
924
+    public function remove_fee_by($key, $value, $global = false) {
925
+        $allowed_fee_keys = apply_filters('wpinv_fee_keys', array(
926 926
             'index', 'label', 'amount', 'type',
927
-        ) );
927
+        ));
928 928
 
929
-        if ( ! in_array( $key, $allowed_fee_keys ) ) {
929
+        if (!in_array($key, $allowed_fee_keys)) {
930 930
             return false;
931 931
         }
932 932
 
933 933
         $removed = false;
934
-        if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) {
935
-            $removed_fee             = $this->fees[ $value ];
934
+        if ('index' === $key && array_key_exists($value, $this->fees)) {
935
+            $removed_fee             = $this->fees[$value];
936 936
             $removed_fee['action']   = 'remove';
937 937
             $this->pending['fees'][] = $removed_fee;
938 938
 
939
-            $this->decrease_fees( $removed_fee['amount'] );
939
+            $this->decrease_fees($removed_fee['amount']);
940 940
 
941
-            unset( $this->fees[ $value ] );
941
+            unset($this->fees[$value]);
942 942
             $removed = true;
943
-        } else if ( 'index' !== $key ) {
944
-            foreach ( $this->fees as $index => $fee ) {
945
-                if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) {
943
+        } else if ('index' !== $key) {
944
+            foreach ($this->fees as $index => $fee) {
945
+                if (isset($fee[$key]) && $fee[$key] == $value) {
946 946
                     $removed_fee             = $fee;
947 947
                     $removed_fee['action']   = 'remove';
948 948
                     $this->pending['fees'][] = $removed_fee;
949 949
 
950
-                    $this->decrease_fees( $removed_fee['amount'] );
950
+                    $this->decrease_fees($removed_fee['amount']);
951 951
 
952
-                    unset( $this->fees[ $index ] );
952
+                    unset($this->fees[$index]);
953 953
                     $removed = true;
954 954
 
955
-                    if ( false === $global ) {
955
+                    if (false === $global) {
956 956
                         break;
957 957
                     }
958 958
                 }
959 959
             }
960 960
         }
961 961
 
962
-        if ( true === $removed ) {
963
-            $this->fees = array_values( $this->fees );
962
+        if (true === $removed) {
963
+            $this->fees = array_values($this->fees);
964 964
         }
965 965
 
966 966
         return $removed;
@@ -968,35 +968,35 @@  discard block
 block discarded – undo
968 968
 
969 969
     
970 970
 
971
-    public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
971
+    public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) {
972 972
         // Bail if no note specified
973
-        if( !$note ) {
973
+        if (!$note) {
974 974
             return false;
975 975
         }
976 976
 
977
-        if ( empty( $this->ID ) )
977
+        if (empty($this->ID))
978 978
             return false;
979 979
         
980
-        if ( ( ( is_user_logged_in() && wpinv_current_user_can_manage_invoicing() ) || $added_by_user ) && !$system ) {
981
-            $user                 = get_user_by( 'id', get_current_user_id() );
980
+        if (((is_user_logged_in() && wpinv_current_user_can_manage_invoicing()) || $added_by_user) && !$system) {
981
+            $user                 = get_user_by('id', get_current_user_id());
982 982
             $comment_author       = $user->display_name;
983 983
             $comment_author_email = $user->user_email;
984 984
         } else {
985 985
             $comment_author       = 'System';
986 986
             $comment_author_email = 'system@';
987
-            $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com';
988
-            $comment_author_email = sanitize_email( $comment_author_email );
987
+            $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com';
988
+            $comment_author_email = sanitize_email($comment_author_email);
989 989
         }
990 990
 
991
-        do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type );
991
+        do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type);
992 992
 
993
-        $note_id = wp_insert_comment( wp_filter_comment( array(
993
+        $note_id = wp_insert_comment(wp_filter_comment(array(
994 994
             'comment_post_ID'      => $this->ID,
995 995
             'comment_content'      => $note,
996 996
             'comment_agent'        => 'WPInvoicing',
997 997
             'user_id'              => is_admin() ? get_current_user_id() : 0,
998
-            'comment_date'         => current_time( 'mysql' ),
999
-            'comment_date_gmt'     => current_time( 'mysql', 1 ),
998
+            'comment_date'         => current_time('mysql'),
999
+            'comment_date_gmt'     => current_time('mysql', 1),
1000 1000
             'comment_approved'     => 1,
1001 1001
             'comment_parent'       => 0,
1002 1002
             'comment_author'       => $comment_author,
@@ -1004,53 +1004,53 @@  discard block
 block discarded – undo
1004 1004
             'comment_author_url'   => '',
1005 1005
             'comment_author_email' => $comment_author_email,
1006 1006
             'comment_type'         => 'wpinv_note'
1007
-        ) ) );
1007
+        )));
1008 1008
 
1009
-        do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note );
1009
+        do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note);
1010 1010
         
1011
-        if ( $customer_type ) {
1012
-            add_comment_meta( $note_id, '_wpi_customer_note', 1 );
1011
+        if ($customer_type) {
1012
+            add_comment_meta($note_id, '_wpi_customer_note', 1);
1013 1013
 
1014
-            do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) );
1014
+            do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note));
1015 1015
         }
1016 1016
 
1017 1017
         return $note_id;
1018 1018
     }
1019 1019
 
1020
-    private function increase_subtotal( $amount = 0.00 ) {
1020
+    private function increase_subtotal($amount = 0.00) {
1021 1021
         $amount          = (float) $amount;
1022 1022
         $this->subtotal += $amount;
1023
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1023
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1024 1024
 
1025 1025
         $this->recalculate_total();
1026 1026
     }
1027 1027
 
1028
-    private function decrease_subtotal( $amount = 0.00 ) {
1028
+    private function decrease_subtotal($amount = 0.00) {
1029 1029
         $amount          = (float) $amount;
1030 1030
         $this->subtotal -= $amount;
1031
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1031
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1032 1032
 
1033
-        if ( $this->subtotal < 0 ) {
1033
+        if ($this->subtotal < 0) {
1034 1034
             $this->subtotal = 0;
1035 1035
         }
1036 1036
 
1037 1037
         $this->recalculate_total();
1038 1038
     }
1039 1039
 
1040
-    private function increase_fees( $amount = 0.00 ) {
1041
-        $amount            = (float)$amount;
1040
+    private function increase_fees($amount = 0.00) {
1041
+        $amount            = (float) $amount;
1042 1042
         $this->fees_total += $amount;
1043
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1043
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1044 1044
 
1045 1045
         $this->recalculate_total();
1046 1046
     }
1047 1047
 
1048
-    private function decrease_fees( $amount = 0.00 ) {
1048
+    private function decrease_fees($amount = 0.00) {
1049 1049
         $amount            = (float) $amount;
1050 1050
         $this->fees_total -= $amount;
1051
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1051
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1052 1052
 
1053
-        if ( $this->fees_total < 0 ) {
1053
+        if ($this->fees_total < 0) {
1054 1054
             $this->fees_total = 0;
1055 1055
         }
1056 1056
 
@@ -1061,54 +1061,54 @@  discard block
 block discarded – undo
1061 1061
         global $wpi_nosave;
1062 1062
         
1063 1063
         $this->total = $this->subtotal + $this->tax + $this->fees_total;
1064
-        $this->total = wpinv_round_amount( $this->total );
1064
+        $this->total = wpinv_round_amount($this->total);
1065 1065
         
1066
-        do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave );
1066
+        do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave);
1067 1067
     }
1068 1068
     
1069
-    public function increase_tax( $amount = 0.00 ) {
1069
+    public function increase_tax($amount = 0.00) {
1070 1070
         $amount       = (float) $amount;
1071 1071
         $this->tax   += $amount;
1072 1072
 
1073 1073
         $this->recalculate_total();
1074 1074
     }
1075 1075
 
1076
-    public function decrease_tax( $amount = 0.00 ) {
1076
+    public function decrease_tax($amount = 0.00) {
1077 1077
         $amount     = (float) $amount;
1078 1078
         $this->tax -= $amount;
1079 1079
 
1080
-        if ( $this->tax < 0 ) {
1080
+        if ($this->tax < 0) {
1081 1081
             $this->tax = 0;
1082 1082
         }
1083 1083
 
1084 1084
         $this->recalculate_total();
1085 1085
     }
1086 1086
 
1087
-    public function update_status( $new_status = false, $note = '', $manual = false ) {
1088
-        $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID );
1087
+    public function update_status($new_status = false, $note = '', $manual = false) {
1088
+        $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID);
1089 1089
 
1090
-        if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses( true ) ) ) ) {
1090
+        if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses(true)))) {
1091 1091
             return false; // Don't permit status changes that aren't changes
1092 1092
         }
1093 1093
 
1094
-        $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status );
1094
+        $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status);
1095 1095
         $updated = false;
1096 1096
 
1097
-        if ( $do_change ) {
1098
-            do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status );
1097
+        if ($do_change) {
1098
+            do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status);
1099 1099
 
1100 1100
             $update_post_data                   = array();
1101 1101
             $update_post_data['ID']             = $this->ID;
1102 1102
             $update_post_data['post_status']    = $new_status;
1103
-            $update_post_data['edit_date']      = current_time( 'mysql', 0 );
1104
-            $update_post_data['edit_date_gmt']  = current_time( 'mysql', 1 );
1103
+            $update_post_data['edit_date']      = current_time('mysql', 0);
1104
+            $update_post_data['edit_date_gmt']  = current_time('mysql', 1);
1105 1105
             
1106
-            $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID );
1106
+            $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID);
1107 1107
 
1108
-            $updated = wp_update_post( $update_post_data );     
1108
+            $updated = wp_update_post($update_post_data);     
1109 1109
            
1110 1110
             // Process any specific status functions
1111
-            switch( $new_status ) {
1111
+            switch ($new_status) {
1112 1112
                 case 'wpi-refunded':
1113 1113
                     $this->process_refund();
1114 1114
                     break;
@@ -1121,9 +1121,9 @@  discard block
 block discarded – undo
1121 1121
             }
1122 1122
             
1123 1123
             // Status was changed.
1124
-            do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status );
1125
-            do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status );
1126
-            do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status );
1124
+            do_action('wpinv_status_' . $new_status, $this->ID, $old_status);
1125
+            do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status);
1126
+            do_action('wpinv_update_status', $this->ID, $new_status, $old_status);
1127 1127
         }
1128 1128
 
1129 1129
         return $updated;
@@ -1137,20 +1137,20 @@  discard block
 block discarded – undo
1137 1137
         $this->save();
1138 1138
     }
1139 1139
 
1140
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
1141
-        if ( empty( $meta_key ) ) {
1140
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
1141
+        if (empty($meta_key)) {
1142 1142
             return false;
1143 1143
         }
1144 1144
 
1145
-        if ( $meta_key == 'key' || $meta_key == 'date' ) {
1145
+        if ($meta_key == 'key' || $meta_key == 'date') {
1146 1146
             $current_meta = $this->get_meta();
1147
-            $current_meta[ $meta_key ] = $meta_value;
1147
+            $current_meta[$meta_key] = $meta_value;
1148 1148
 
1149 1149
             $meta_key     = '_wpinv_payment_meta';
1150 1150
             $meta_value   = $current_meta;
1151 1151
         }
1152 1152
 
1153
-        $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID );
1153
+        $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID);
1154 1154
         
1155 1155
         // Do not update created date on invoice marked as paid.
1156 1156
         /*if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) {
@@ -1165,45 +1165,45 @@  discard block
 block discarded – undo
1165 1165
             wp_update_post( $args );
1166 1166
         }*/
1167 1167
         
1168
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
1168
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
1169 1169
     }
1170 1170
 
1171 1171
     private function process_refund() {
1172 1172
         $process_refund = true;
1173 1173
 
1174 1174
         // If the payment was not in publish, don't decrement stats as they were never incremented
1175
-        if ( 'publish' != $this->old_status || 'wpi-refunded' != $this->status ) {
1175
+        if ('publish' != $this->old_status || 'wpi-refunded' != $this->status) {
1176 1176
             $process_refund = false;
1177 1177
         }
1178 1178
 
1179 1179
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1180
-        $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this );
1180
+        $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this);
1181 1181
 
1182
-        if ( false === $process_refund ) {
1182
+        if (false === $process_refund) {
1183 1183
             return;
1184 1184
         }
1185 1185
 
1186
-        do_action( 'wpinv_pre_refund_invoice', $this );
1186
+        do_action('wpinv_pre_refund_invoice', $this);
1187 1187
         
1188
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this );
1189
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this );
1190
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this );
1188
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this);
1189
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this);
1190
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this);
1191 1191
         
1192
-        do_action( 'wpinv_post_refund_invoice', $this );
1192
+        do_action('wpinv_post_refund_invoice', $this);
1193 1193
     }
1194 1194
 
1195 1195
     private function process_failure() {
1196 1196
         $discounts = $this->discounts;
1197
-        if ( empty( $discounts ) ) {
1197
+        if (empty($discounts)) {
1198 1198
             return;
1199 1199
         }
1200 1200
 
1201
-        if ( ! is_array( $discounts ) ) {
1202
-            $discounts = array_map( 'trim', explode( ',', $discounts ) );
1201
+        if (!is_array($discounts)) {
1202
+            $discounts = array_map('trim', explode(',', $discounts));
1203 1203
         }
1204 1204
 
1205
-        foreach ( $discounts as $discount ) {
1206
-            wpinv_decrease_discount_usage( $discount );
1205
+        foreach ($discounts as $discount) {
1206
+            wpinv_decrease_discount_usage($discount);
1207 1207
         }
1208 1208
     }
1209 1209
     
@@ -1211,92 +1211,92 @@  discard block
 block discarded – undo
1211 1211
         $process_pending = true;
1212 1212
 
1213 1213
         // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented
1214
-        if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'wpi-pending' != $this->status ) {
1214
+        if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'wpi-pending' != $this->status) {
1215 1215
             $process_pending = false;
1216 1216
         }
1217 1217
 
1218 1218
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1219
-        $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this );
1219
+        $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this);
1220 1220
 
1221
-        if ( false === $process_pending ) {
1221
+        if (false === $process_pending) {
1222 1222
             return;
1223 1223
         }
1224 1224
 
1225
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this );
1226
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this );
1227
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this );
1225
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this);
1226
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this);
1227
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this);
1228 1228
 
1229 1229
         $this->completed_date = '';
1230
-        $this->update_meta( '_wpinv_completed_date', '' );
1230
+        $this->update_meta('_wpinv_completed_date', '');
1231 1231
     }
1232 1232
     
1233 1233
     // get data
1234
-    public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) {
1235
-        $meta = get_post_meta( $this->ID, $meta_key, $single );
1234
+    public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) {
1235
+        $meta = get_post_meta($this->ID, $meta_key, $single);
1236 1236
 
1237
-        if ( $meta_key === '_wpinv_payment_meta' ) {
1237
+        if ($meta_key === '_wpinv_payment_meta') {
1238 1238
 
1239
-            if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is.
1239
+            if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is.
1240 1240
 
1241
-            if ( empty( $meta['key'] ) ) {
1241
+            if (empty($meta['key'])) {
1242 1242
                 $meta['key'] = $this->setup_invoice_key();
1243 1243
             }
1244 1244
 
1245
-            if ( empty( $meta['date'] ) ) {
1246
-                $meta['date'] = get_post_field( 'post_date', $this->ID );
1245
+            if (empty($meta['date'])) {
1246
+                $meta['date'] = get_post_field('post_date', $this->ID);
1247 1247
             }
1248 1248
         }
1249 1249
 
1250
-        $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID );
1250
+        $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID);
1251 1251
 
1252
-        return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key );
1252
+        return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key);
1253 1253
     }
1254 1254
     
1255 1255
     public function get_description() {
1256
-        $post = get_post( $this->ID );
1256
+        $post = get_post($this->ID);
1257 1257
         
1258
-        $description = !empty( $post ) ? $post->post_content : '';
1259
-        return apply_filters( 'wpinv_get_description', $description, $this->ID, $this );
1258
+        $description = !empty($post) ? $post->post_content : '';
1259
+        return apply_filters('wpinv_get_description', $description, $this->ID, $this);
1260 1260
     }
1261 1261
     
1262
-    public function get_status( $nicename = false ) {
1263
-        if ( !$nicename ) {
1262
+    public function get_status($nicename = false) {
1263
+        if (!$nicename) {
1264 1264
             $status = $this->status;
1265 1265
         } else {
1266 1266
             $status = $this->status_nicename;
1267 1267
         }
1268 1268
         
1269
-        return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this );
1269
+        return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this);
1270 1270
     }
1271 1271
     
1272 1272
     public function get_cart_details() {
1273
-        return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this );
1273
+        return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this);
1274 1274
     }
1275 1275
     
1276
-    public function get_subtotal( $currency = false ) {
1277
-        $subtotal = wpinv_round_amount( $this->subtotal );
1276
+    public function get_subtotal($currency = false) {
1277
+        $subtotal = wpinv_round_amount($this->subtotal);
1278 1278
         
1279
-        if ( $currency ) {
1280
-            $subtotal = wpinv_price( wpinv_format_amount( $subtotal, NULL, !$currency ), $this->get_currency() );
1279
+        if ($currency) {
1280
+            $subtotal = wpinv_price(wpinv_format_amount($subtotal, NULL, !$currency), $this->get_currency());
1281 1281
         }
1282 1282
         
1283
-        return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency );
1283
+        return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency);
1284 1284
     }
1285 1285
     
1286
-    public function get_total( $currency = false ) {        
1287
-        if ( $this->is_free_trial() ) {
1288
-            $total = wpinv_round_amount( 0 );
1286
+    public function get_total($currency = false) {        
1287
+        if ($this->is_free_trial()) {
1288
+            $total = wpinv_round_amount(0);
1289 1289
         } else {
1290
-            $total = wpinv_round_amount( $this->total );
1290
+            $total = wpinv_round_amount($this->total);
1291 1291
         }
1292
-        if ( $currency ) {
1293
-            $total = wpinv_price( wpinv_format_amount( $total, NULL, !$currency ), $this->get_currency() );
1292
+        if ($currency) {
1293
+            $total = wpinv_price(wpinv_format_amount($total, NULL, !$currency), $this->get_currency());
1294 1294
         }
1295 1295
         
1296
-        return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency );
1296
+        return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency);
1297 1297
     }
1298 1298
     
1299
-    public function get_recurring_details( $field = '', $currency = false ) {        
1299
+    public function get_recurring_details($field = '', $currency = false) {        
1300 1300
         $data                 = array();
1301 1301
         $data['cart_details'] = $this->cart_details;
1302 1302
         $data['subtotal']     = $this->get_subtotal();
@@ -1304,164 +1304,164 @@  discard block
 block discarded – undo
1304 1304
         $data['tax']          = $this->get_tax();
1305 1305
         $data['total']        = $this->get_total();
1306 1306
     
1307
-        if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) {
1307
+        if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) {
1308 1308
             $is_free_trial = $this->is_free_trial();
1309
-            $discounts = $this->get_discounts( true );
1309
+            $discounts = $this->get_discounts(true);
1310 1310
             
1311
-            if ( $is_free_trial || !empty( $discounts ) ) {
1311
+            if ($is_free_trial || !empty($discounts)) {
1312 1312
                 $first_use_only = false;
1313 1313
                 
1314
-                if ( !empty( $discounts ) ) {
1315
-                    foreach ( $discounts as $key => $code ) {
1316
-                        if ( wpinv_discount_is_recurring( $code, true ) && !$this->is_renewal() ) {
1314
+                if (!empty($discounts)) {
1315
+                    foreach ($discounts as $key => $code) {
1316
+                        if (wpinv_discount_is_recurring($code, true) && !$this->is_renewal()) {
1317 1317
                             $first_use_only = true;
1318 1318
                             break;
1319 1319
                         }
1320 1320
                     }
1321 1321
                 }
1322 1322
                     
1323
-                if ( !$first_use_only ) {
1324
-                    $data['subtotal'] = wpinv_round_amount( $this->subtotal );
1325
-                    $data['discount'] = wpinv_round_amount( $this->discount );
1326
-                    $data['tax']      = wpinv_round_amount( $this->tax );
1327
-                    $data['total']    = wpinv_round_amount( $this->total );
1323
+                if (!$first_use_only) {
1324
+                    $data['subtotal'] = wpinv_round_amount($this->subtotal);
1325
+                    $data['discount'] = wpinv_round_amount($this->discount);
1326
+                    $data['tax']      = wpinv_round_amount($this->tax);
1327
+                    $data['total']    = wpinv_round_amount($this->total);
1328 1328
                 } else {
1329 1329
                     $cart_subtotal   = 0;
1330 1330
                     $cart_discount   = $this->discount;
1331 1331
                     $cart_tax        = 0;
1332 1332
 
1333
-                    foreach ( $this->cart_details as $key => $item ) {
1334
-                        $item_quantity  = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1335
-                        $item_subtotal  = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1333
+                    foreach ($this->cart_details as $key => $item) {
1334
+                        $item_quantity  = $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1335
+                        $item_subtotal  = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1336 1336
                         $item_discount  = 0;
1337
-                        $item_tax       = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0;
1337
+                        $item_tax       = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float) $item['vat_rate']) : 0;
1338 1338
                         
1339
-                        if ( wpinv_prices_include_tax() ) {
1340
-                            $item_subtotal -= wpinv_round_amount( $item_tax );
1339
+                        if (wpinv_prices_include_tax()) {
1340
+                            $item_subtotal -= wpinv_round_amount($item_tax);
1341 1341
                         }
1342 1342
                         
1343 1343
                         $item_total     = $item_subtotal - $item_discount + $item_tax;
1344 1344
                         // Do not allow totals to go negative
1345
-                        if ( $item_total < 0 ) {
1345
+                        if ($item_total < 0) {
1346 1346
                             $item_total = 0;
1347 1347
                         }
1348 1348
                         
1349
-                        $cart_subtotal  += (float)($item_subtotal);
1350
-                        $cart_discount  += (float)($item_discount);
1351
-                        $cart_tax       += (float)($item_tax);
1349
+                        $cart_subtotal  += (float) ($item_subtotal);
1350
+                        $cart_discount  += (float) ($item_discount);
1351
+                        $cart_tax       += (float) ($item_tax);
1352 1352
                         
1353
-                        $data['cart_details'][$key]['discount']   = wpinv_round_amount( $item_discount );
1354
-                        $data['cart_details'][$key]['tax']        = wpinv_round_amount( $item_tax );
1355
-                        $data['cart_details'][$key]['price']      = wpinv_round_amount( $item_total );
1353
+                        $data['cart_details'][$key]['discount']   = wpinv_round_amount($item_discount);
1354
+                        $data['cart_details'][$key]['tax']        = wpinv_round_amount($item_tax);
1355
+                        $data['cart_details'][$key]['price']      = wpinv_round_amount($item_total);
1356 1356
                     }
1357 1357
 
1358 1358
 	                $total = $data['subtotal'] - $data['discount'] + $data['tax'];
1359
-	                if ( $total < 0 ) {
1359
+	                if ($total < 0) {
1360 1360
 		                $total = 0;
1361 1361
 	                }
1362 1362
 
1363
-                    $data['subtotal'] = wpinv_round_amount( $cart_subtotal );
1364
-                    $data['discount'] = wpinv_round_amount( $cart_discount );
1365
-                    $data['tax']      = wpinv_round_amount( $cart_tax );
1366
-                    $data['total']    = wpinv_round_amount( $total );
1363
+                    $data['subtotal'] = wpinv_round_amount($cart_subtotal);
1364
+                    $data['discount'] = wpinv_round_amount($cart_discount);
1365
+                    $data['tax']      = wpinv_round_amount($cart_tax);
1366
+                    $data['total']    = wpinv_round_amount($total);
1367 1367
                 }
1368 1368
             }
1369 1369
         }
1370 1370
         
1371
-        $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency );
1371
+        $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency);
1372 1372
 
1373
-        if ( isset( $data[$field] ) ) {
1374
-            return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
1373
+        if (isset($data[$field])) {
1374
+            return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]);
1375 1375
         }
1376 1376
         
1377 1377
         return $data;
1378 1378
     }
1379 1379
     
1380
-    public function get_final_tax( $currency = false ) {        
1381
-        $final_total = wpinv_round_amount( $this->tax );
1382
-        if ( $currency ) {
1383
-            $final_total = wpinv_price( wpinv_format_amount( $final_total, NULL, !$currency ), $this->get_currency() );
1380
+    public function get_final_tax($currency = false) {        
1381
+        $final_total = wpinv_round_amount($this->tax);
1382
+        if ($currency) {
1383
+            $final_total = wpinv_price(wpinv_format_amount($final_total, NULL, !$currency), $this->get_currency());
1384 1384
         }
1385 1385
         
1386
-        return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency );
1386
+        return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency);
1387 1387
     }
1388 1388
     
1389
-    public function get_discounts( $array = false ) {
1389
+    public function get_discounts($array = false) {
1390 1390
         $discounts = $this->discounts;
1391
-        if ( $array && $discounts ) {
1392
-            $discounts = explode( ',', $discounts );
1391
+        if ($array && $discounts) {
1392
+            $discounts = explode(',', $discounts);
1393 1393
         }
1394
-        return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array );
1394
+        return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array);
1395 1395
     }
1396 1396
     
1397
-    public function get_discount( $currency = false, $dash = false ) {
1398
-        if ( !empty( $this->discounts ) ) {
1397
+    public function get_discount($currency = false, $dash = false) {
1398
+        if (!empty($this->discounts)) {
1399 1399
             global $ajax_cart_details;
1400 1400
             $ajax_cart_details = $this->get_cart_details();
1401 1401
             
1402
-            if ( !empty( $ajax_cart_details ) && count( $ajax_cart_details ) == count( $this->items ) ) {
1402
+            if (!empty($ajax_cart_details) && count($ajax_cart_details) == count($this->items)) {
1403 1403
                 $cart_items = $ajax_cart_details;
1404 1404
             } else {
1405 1405
                 $cart_items = $this->items;
1406 1406
             }
1407 1407
 
1408
-            $this->discount = wpinv_get_cart_items_discount_amount( $cart_items , $this->discounts );
1408
+            $this->discount = wpinv_get_cart_items_discount_amount($cart_items, $this->discounts);
1409 1409
         }
1410
-        $discount   = wpinv_round_amount( $this->discount );
1410
+        $discount   = wpinv_round_amount($this->discount);
1411 1411
         $dash       = $dash && $discount > 0 ? '&ndash;' : '';
1412 1412
         
1413
-        if ( $currency ) {
1414
-            $discount = wpinv_price( wpinv_format_amount( $discount, NULL, !$currency ), $this->get_currency() );
1413
+        if ($currency) {
1414
+            $discount = wpinv_price(wpinv_format_amount($discount, NULL, !$currency), $this->get_currency());
1415 1415
         }
1416 1416
         
1417
-        $discount   = $dash . $discount;
1417
+        $discount = $dash . $discount;
1418 1418
         
1419
-        return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash );
1419
+        return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash);
1420 1420
     }
1421 1421
     
1422 1422
     public function get_discount_code() {
1423 1423
         return $this->discount_code;
1424 1424
     }
1425 1425
     
1426
-    public function get_tax( $currency = false ) {
1427
-        $tax = wpinv_round_amount( $this->tax );
1426
+    public function get_tax($currency = false) {
1427
+        $tax = wpinv_round_amount($this->tax);
1428 1428
         
1429
-        if ( $currency ) {
1430
-            $tax = wpinv_price( wpinv_format_amount( $tax, NULL, !$currency ), $this->get_currency() );
1429
+        if ($currency) {
1430
+            $tax = wpinv_price(wpinv_format_amount($tax, NULL, !$currency), $this->get_currency());
1431 1431
         }
1432 1432
         
1433
-        return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency );
1433
+        return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency);
1434 1434
     }
1435 1435
     
1436
-    public function get_fees( $type = 'all' ) {
1437
-        $fees    = array();
1436
+    public function get_fees($type = 'all') {
1437
+        $fees = array();
1438 1438
 
1439
-        if ( ! empty( $this->fees ) && is_array( $this->fees ) ) {
1440
-            foreach ( $this->fees as $fee ) {
1441
-                if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) {
1439
+        if (!empty($this->fees) && is_array($this->fees)) {
1440
+            foreach ($this->fees as $fee) {
1441
+                if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) {
1442 1442
                     continue;
1443 1443
                 }
1444 1444
 
1445
-                $fee['label'] = stripslashes( $fee['label'] );
1446
-                $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() );
1447
-                $fees[]    = $fee;
1445
+                $fee['label'] = stripslashes($fee['label']);
1446
+                $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency());
1447
+                $fees[] = $fee;
1448 1448
             }
1449 1449
         }
1450 1450
 
1451
-        return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this );
1451
+        return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this);
1452 1452
     }
1453 1453
     
1454
-    public function get_fees_total( $type = 'all' ) {
1454
+    public function get_fees_total($type = 'all') {
1455 1455
         $fees_total = (float) 0.00;
1456 1456
 
1457
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
1458
-        if ( ! empty( $payment_fees ) ) {
1459
-            foreach ( $payment_fees as $fee ) {
1457
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
1458
+        if (!empty($payment_fees)) {
1459
+            foreach ($payment_fees as $fee) {
1460 1460
                 $fees_total += (float) $fee['amount'];
1461 1461
             }
1462 1462
         }
1463 1463
 
1464
-        return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this );
1464
+        return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this);
1465 1465
         /*
1466 1466
         $fees = $this->get_fees( $type );
1467 1467
 
@@ -1481,116 +1481,116 @@  discard block
 block discarded – undo
1481 1481
     }
1482 1482
 
1483 1483
     public function get_user_id() {
1484
-        return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this );
1484
+        return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this);
1485 1485
     }
1486 1486
     
1487 1487
     public function get_first_name() {
1488
-        return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this );
1488
+        return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this);
1489 1489
     }
1490 1490
     
1491 1491
     public function get_last_name() {
1492
-        return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this );
1492
+        return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this);
1493 1493
     }
1494 1494
     
1495 1495
     public function get_user_full_name() {
1496
-        return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this );
1496
+        return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this);
1497 1497
     }
1498 1498
     
1499 1499
     public function get_user_info() {
1500
-        return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this );
1500
+        return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this);
1501 1501
     }
1502 1502
     
1503 1503
     public function get_email() {
1504
-        return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this );
1504
+        return apply_filters('wpinv_user_email', $this->email, $this->ID, $this);
1505 1505
     }
1506 1506
     
1507 1507
     public function get_address() {
1508
-        return apply_filters( 'wpinv_address', $this->address, $this->ID, $this );
1508
+        return apply_filters('wpinv_address', $this->address, $this->ID, $this);
1509 1509
     }
1510 1510
     
1511 1511
     public function get_phone() {
1512
-        return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this );
1512
+        return apply_filters('wpinv_phone', $this->phone, $this->ID, $this);
1513 1513
     }
1514 1514
     
1515 1515
     public function get_number() {
1516
-        return apply_filters( 'wpinv_number', $this->number, $this->ID, $this );
1516
+        return apply_filters('wpinv_number', $this->number, $this->ID, $this);
1517 1517
     }
1518 1518
     
1519 1519
     public function get_items() {
1520
-        return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this );
1520
+        return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this);
1521 1521
     }
1522 1522
     
1523 1523
     public function get_key() {
1524
-        return apply_filters( 'wpinv_key', $this->key, $this->ID, $this );
1524
+        return apply_filters('wpinv_key', $this->key, $this->ID, $this);
1525 1525
     }
1526 1526
     
1527 1527
     public function get_transaction_id() {
1528
-        return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this );
1528
+        return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this);
1529 1529
     }
1530 1530
     
1531 1531
     public function get_gateway() {
1532
-        return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this );
1532
+        return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this);
1533 1533
     }
1534 1534
     
1535 1535
     public function get_gateway_title() {
1536
-        $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway );
1536
+        $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway);
1537 1537
         
1538
-        return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this );
1538
+        return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this);
1539 1539
     }
1540 1540
     
1541 1541
     public function get_currency() {
1542
-        return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this );
1542
+        return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this);
1543 1543
     }
1544 1544
     
1545 1545
     public function get_created_date() {
1546
-        return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this );
1546
+        return apply_filters('wpinv_created_date', $this->date, $this->ID, $this);
1547 1547
     }
1548 1548
     
1549
-    public function get_due_date( $display = false ) {
1550
-        $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this );
1549
+    public function get_due_date($display = false) {
1550
+        $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this);
1551 1551
         
1552
-        if ( !$display || empty( $due_date ) ) {
1552
+        if (!$display || empty($due_date)) {
1553 1553
             return $due_date;
1554 1554
         }
1555 1555
         
1556
-        return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) );
1556
+        return date_i18n(get_option('date_format'), strtotime($due_date));
1557 1557
     }
1558 1558
     
1559 1559
     public function get_completed_date() {
1560
-        return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this );
1560
+        return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this);
1561 1561
     }
1562 1562
     
1563
-    public function get_invoice_date( $formatted = true ) {
1563
+    public function get_invoice_date($formatted = true) {
1564 1564
         $date_completed = $this->completed_date;
1565 1565
         $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';
1566 1566
         
1567
-        if ( $invoice_date == '' ) {
1567
+        if ($invoice_date == '') {
1568 1568
             $date_created   = $this->date;
1569 1569
             $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : '';
1570 1570
         }
1571 1571
         
1572
-        if ( $formatted && $invoice_date ) {
1573
-            $invoice_date   = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) );
1572
+        if ($formatted && $invoice_date) {
1573
+            $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date));
1574 1574
         }
1575 1575
 
1576
-        return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this );
1576
+        return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this);
1577 1577
     }
1578 1578
     
1579 1579
     public function get_ip() {
1580
-        return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this );
1580
+        return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this);
1581 1581
     }
1582 1582
         
1583
-    public function has_status( $status ) {
1584
-        return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status );
1583
+    public function has_status($status) {
1584
+        return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status);
1585 1585
     }
1586 1586
     
1587
-    public function add_item( $item_id = 0, $args = array() ) {
1587
+    public function add_item($item_id = 0, $args = array()) {
1588 1588
         global $wpi_current_id, $wpi_item_id;
1589 1589
         
1590
-        $item = new WPInv_Item( $item_id );
1590
+        $item = new WPInv_Item($item_id);
1591 1591
 
1592 1592
         // Bail if this post isn't a item
1593
-        if( !$item || $item->post_type !== 'wpi_item' ) {
1593
+        if (!$item || $item->post_type !== 'wpi_item') {
1594 1594
             return false;
1595 1595
         }
1596 1596
         
@@ -1609,8 +1609,8 @@  discard block
 block discarded – undo
1609 1609
             'fees'          => array()
1610 1610
         );
1611 1611
 
1612
-        $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults );
1613
-        $args['quantity']   = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1;
1612
+        $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults);
1613
+        $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1;
1614 1614
 
1615 1615
         $wpi_current_id         = $this->ID;
1616 1616
         $wpi_item_id            = $item->ID;
@@ -1622,19 +1622,19 @@  discard block
 block discarded – undo
1622 1622
         $found_cart_key         = false;
1623 1623
         
1624 1624
         if ($has_quantities) {
1625
-            $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1625
+            $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1626 1626
             
1627
-            foreach ( $this->items as $key => $cart_item ) {
1628
-                if ( (int)$item_id !== (int)$cart_item['id'] ) {
1627
+            foreach ($this->items as $key => $cart_item) {
1628
+                if ((int) $item_id !== (int) $cart_item['id']) {
1629 1629
                     continue;
1630 1630
                 }
1631 1631
 
1632
-                $this->items[ $key ]['quantity'] += $args['quantity'];
1632
+                $this->items[$key]['quantity'] += $args['quantity'];
1633 1633
                 break;
1634 1634
             }
1635 1635
             
1636
-            foreach ( $this->cart_details as $cart_key => $cart_item ) {
1637
-                if ( $item_id != $cart_item['id'] ) {
1636
+            foreach ($this->cart_details as $cart_key => $cart_item) {
1637
+                if ($item_id != $cart_item['id']) {
1638 1638
                     continue;
1639 1639
                 }
1640 1640
 
@@ -1646,29 +1646,29 @@  discard block
 block discarded – undo
1646 1646
         if ($has_quantities && $found_cart_key !== false) {
1647 1647
             $cart_item          = $this->cart_details[$found_cart_key];
1648 1648
             $item_price         = $cart_item['item_price'];
1649
-            $quantity           = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1650
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1649
+            $quantity           = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1650
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1651 1651
             
1652 1652
             $new_quantity       = $quantity + $args['quantity'];
1653 1653
             $subtotal           = $item_price * $new_quantity;
1654 1654
             
1655 1655
             $args['quantity']   = $new_quantity;
1656
-            $discount           = !empty( $args['discount'] ) ? $args['discount'] : 0;
1657
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1656
+            $discount           = !empty($args['discount']) ? $args['discount'] : 0;
1657
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
1658 1658
             
1659
-            $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0;
1660
-            $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0;
1659
+            $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float) $cart_item['discount'] ? $discount - (float) $cart_item['discount'] : 0;
1660
+            $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float) $cart_item['tax'] ? $tax - (float) $cart_item['tax'] : 0;
1661 1661
             // The total increase equals the number removed * the item_price
1662
-            $total_increased    = wpinv_round_amount( $item_price );
1662
+            $total_increased    = wpinv_round_amount($item_price);
1663 1663
             
1664
-            if ( wpinv_prices_include_tax() ) {
1665
-                $subtotal -= wpinv_round_amount( $tax );
1664
+            if (wpinv_prices_include_tax()) {
1665
+                $subtotal -= wpinv_round_amount($tax);
1666 1666
             }
1667 1667
 
1668
-            $total              = $subtotal - $discount + $tax;
1668
+            $total = $subtotal - $discount + $tax;
1669 1669
 
1670 1670
             // Do not allow totals to go negative
1671
-            if( $total < 0 ) {
1671
+            if ($total < 0) {
1672 1672
                 $total = 0;
1673 1673
             }
1674 1674
             
@@ -1684,25 +1684,25 @@  discard block
 block discarded – undo
1684 1684
             $this->cart_details[$found_cart_key] = $cart_item;
1685 1685
         } else {
1686 1686
             // Set custom price.
1687
-            if ( $args['custom_price'] !== '' ) {
1687
+            if ($args['custom_price'] !== '') {
1688 1688
                 $item_price = $args['custom_price'];
1689 1689
             } else {
1690 1690
                 // Allow overriding the price
1691
-                if ( false !== $args['item_price'] ) {
1691
+                if (false !== $args['item_price']) {
1692 1692
                     $item_price = $args['item_price'];
1693 1693
                 } else {
1694
-                    $item_price = wpinv_get_item_price( $item->ID );
1694
+                    $item_price = wpinv_get_item_price($item->ID);
1695 1695
                 }
1696 1696
             }
1697 1697
 
1698 1698
             // Sanitizing the price here so we don't have a dozen calls later
1699
-            $item_price = wpinv_sanitize_amount( $item_price );
1700
-            $subtotal   = wpinv_round_amount( $item_price * $args['quantity'] );
1699
+            $item_price = wpinv_sanitize_amount($item_price);
1700
+            $subtotal   = wpinv_round_amount($item_price * $args['quantity']);
1701 1701
         
1702
-            $discount   = !empty( $args['discount'] ) ? $args['discount'] : 0;
1703
-            $tax_class  = !empty( $args['vat_class'] ) ? $args['vat_class'] : '';
1704
-            $tax_rate   = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0;
1705
-            $tax        = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1702
+            $discount   = !empty($args['discount']) ? $args['discount'] : 0;
1703
+            $tax_class  = !empty($args['vat_class']) ? $args['vat_class'] : '';
1704
+            $tax_rate   = !empty($args['vat_rate']) ? $args['vat_rate'] : 0;
1705
+            $tax        = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
1706 1706
 
1707 1707
             // Setup the items meta item
1708 1708
             $new_item = array(
@@ -1710,29 +1710,29 @@  discard block
 block discarded – undo
1710 1710
                 'quantity' => $args['quantity'],
1711 1711
             );
1712 1712
 
1713
-            $this->items[]  = $new_item;
1713
+            $this->items[] = $new_item;
1714 1714
 
1715
-            if ( wpinv_prices_include_tax() ) {
1716
-                $subtotal -= wpinv_round_amount( $tax );
1715
+            if (wpinv_prices_include_tax()) {
1716
+                $subtotal -= wpinv_round_amount($tax);
1717 1717
             }
1718 1718
 
1719
-            $total      = $subtotal - $discount + $tax;
1719
+            $total = $subtotal - $discount + $tax;
1720 1720
 
1721 1721
             // Do not allow totals to go negative
1722
-            if( $total < 0 ) {
1722
+            if ($total < 0) {
1723 1723
                 $total = 0;
1724 1724
             }
1725 1725
         
1726 1726
             $this->cart_details[] = array(
1727 1727
                 'name'          => !empty($args['name']) ? $args['name'] : $item->get_name(),
1728 1728
                 'id'            => $item->ID,
1729
-                'item_price'    => wpinv_round_amount( $item_price ),
1730
-                'custom_price'  => ( $args['custom_price'] !== '' ? wpinv_round_amount( $args['custom_price'] ) : '' ),
1729
+                'item_price'    => wpinv_round_amount($item_price),
1730
+                'custom_price'  => ($args['custom_price'] !== '' ? wpinv_round_amount($args['custom_price']) : ''),
1731 1731
                 'quantity'      => $args['quantity'],
1732 1732
                 'discount'      => $discount,
1733
-                'subtotal'      => wpinv_round_amount( $subtotal ),
1734
-                'tax'           => wpinv_round_amount( $tax ),
1735
-                'price'         => wpinv_round_amount( $total ),
1733
+                'subtotal'      => wpinv_round_amount($subtotal),
1734
+                'tax'           => wpinv_round_amount($tax),
1735
+                'price'         => wpinv_round_amount($total),
1736 1736
                 'vat_rate'      => $tax_rate,
1737 1737
                 'vat_class'     => $tax_class,
1738 1738
                 'meta'          => $args['meta'],
@@ -1742,18 +1742,18 @@  discard block
 block discarded – undo
1742 1742
             $subtotal = $subtotal - $discount;
1743 1743
         }
1744 1744
         
1745
-        $added_item = end( $this->cart_details );
1746
-        $added_item['action']  = 'add';
1745
+        $added_item = end($this->cart_details);
1746
+        $added_item['action'] = 'add';
1747 1747
         
1748 1748
         $this->pending['items'][] = $added_item;
1749 1749
         
1750
-        $this->increase_subtotal( $subtotal );
1751
-        $this->increase_tax( $tax );
1750
+        $this->increase_subtotal($subtotal);
1751
+        $this->increase_tax($tax);
1752 1752
 
1753 1753
         return true;
1754 1754
     }
1755 1755
     
1756
-    public function remove_item( $item_id, $args = array() ) {
1756
+    public function remove_item($item_id, $args = array()) {
1757 1757
         // Set some defaults
1758 1758
         $defaults = array(
1759 1759
             'quantity'      => 1,
@@ -1761,51 +1761,51 @@  discard block
 block discarded – undo
1761 1761
             'custom_price'  => '',
1762 1762
             'cart_index'    => false,
1763 1763
         );
1764
-        $args = wp_parse_args( $args, $defaults );
1764
+        $args = wp_parse_args($args, $defaults);
1765 1765
 
1766 1766
         // Bail if this post isn't a item
1767
-        if ( get_post_type( $item_id ) !== 'wpi_item' ) {
1767
+        if (get_post_type($item_id) !== 'wpi_item') {
1768 1768
             return false;
1769 1769
         }
1770 1770
         
1771
-        $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1771
+        $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1772 1772
 
1773
-        foreach ( $this->items as $key => $item ) {
1774
-            if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) {
1773
+        foreach ($this->items as $key => $item) {
1774
+            if (!empty($item['id']) && (int) $item_id !== (int) $item['id']) {
1775 1775
                 continue;
1776 1776
             }
1777 1777
 
1778
-            if ( false !== $args['cart_index'] ) {
1779
-                $cart_index = absint( $args['cart_index'] );
1780
-                $cart_item  = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false;
1778
+            if (false !== $args['cart_index']) {
1779
+                $cart_index = absint($args['cart_index']);
1780
+                $cart_item  = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false;
1781 1781
 
1782
-                if ( ! empty( $cart_item ) ) {
1782
+                if (!empty($cart_item)) {
1783 1783
                     // If the cart index item isn't the same item ID, don't remove it
1784
-                    if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) {
1784
+                    if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) {
1785 1785
                         continue;
1786 1786
                     }
1787 1787
                 }
1788 1788
             }
1789 1789
 
1790
-            $item_quantity = $this->items[ $key ]['quantity'];
1791
-            if ( $item_quantity > $args['quantity'] ) {
1792
-                $this->items[ $key ]['quantity'] -= $args['quantity'];
1790
+            $item_quantity = $this->items[$key]['quantity'];
1791
+            if ($item_quantity > $args['quantity']) {
1792
+                $this->items[$key]['quantity'] -= $args['quantity'];
1793 1793
                 break;
1794 1794
             } else {
1795
-                unset( $this->items[ $key ] );
1795
+                unset($this->items[$key]);
1796 1796
                 break;
1797 1797
             }
1798 1798
         }
1799 1799
 
1800 1800
         $found_cart_key = false;
1801
-        if ( false === $args['cart_index'] ) {
1802
-            foreach ( $this->cart_details as $cart_key => $item ) {
1803
-                if ( $item_id != $item['id'] ) {
1801
+        if (false === $args['cart_index']) {
1802
+            foreach ($this->cart_details as $cart_key => $item) {
1803
+                if ($item_id != $item['id']) {
1804 1804
                     continue;
1805 1805
                 }
1806 1806
 
1807
-                if ( false !== $args['item_price'] ) {
1808
-                    if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) {
1807
+                if (false !== $args['item_price']) {
1808
+                    if (isset($item['item_price']) && (float) $args['item_price'] != (float) $item['item_price']) {
1809 1809
                         continue;
1810 1810
                     }
1811 1811
                 }
@@ -1814,13 +1814,13 @@  discard block
 block discarded – undo
1814 1814
                 break;
1815 1815
             }
1816 1816
         } else {
1817
-            $cart_index = absint( $args['cart_index'] );
1817
+            $cart_index = absint($args['cart_index']);
1818 1818
 
1819
-            if ( ! array_key_exists( $cart_index, $this->cart_details ) ) {
1819
+            if (!array_key_exists($cart_index, $this->cart_details)) {
1820 1820
                 return false; // Invalid cart index passed.
1821 1821
             }
1822 1822
 
1823
-            if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) {
1823
+            if ((int) $this->cart_details[$cart_index]['id'] > 0 && (int) $this->cart_details[$cart_index]['id'] !== (int) $item_id) {
1824 1824
                 return false; // We still need the proper Item ID to be sure.
1825 1825
             }
1826 1826
 
@@ -1828,41 +1828,41 @@  discard block
 block discarded – undo
1828 1828
         }
1829 1829
         
1830 1830
         $cart_item  = $this->cart_details[$found_cart_key];
1831
-        $quantity   = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1831
+        $quantity   = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1832 1832
         
1833
-        if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) {
1833
+        if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) {
1834 1834
             return false; // Invoice must contain at least one item.
1835 1835
         }
1836 1836
         
1837
-        $discounts  = $this->get_discounts();
1837
+        $discounts = $this->get_discounts();
1838 1838
         
1839
-        if ( $quantity > $args['quantity'] ) {
1839
+        if ($quantity > $args['quantity']) {
1840 1840
             $item_price         = $cart_item['item_price'];
1841
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1841
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1842 1842
             
1843
-            $new_quantity       = max( $quantity - $args['quantity'], 1);
1843
+            $new_quantity       = max($quantity - $args['quantity'], 1);
1844 1844
             $subtotal           = $item_price * $new_quantity;
1845 1845
             
1846 1846
             $args['quantity']   = $new_quantity;
1847
-            $discount           = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1848
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1847
+            $discount           = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1848
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
1849 1849
             
1850
-            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['discount'] / $quantity ) ) : 0;
1851
-            $discount_decrease  = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; 
1852
-            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['tax'] / $quantity ) ) : 0;
1853
-            $tax_decrease       = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease;
1850
+            $discount_decrease  = (float) $cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['discount'] / $quantity)) : 0;
1851
+            $discount_decrease  = $discount > 0 && $subtotal > 0 && (float) $cart_item['discount'] > $discount ? (float) $cart_item['discount'] - $discount : $discount_decrease; 
1852
+            $tax_decrease       = (float) $cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['tax'] / $quantity)) : 0;
1853
+            $tax_decrease       = $tax > 0 && $subtotal > 0 && (float) $cart_item['tax'] > $tax ? (float) $cart_item['tax'] - $tax : $tax_decrease;
1854 1854
             
1855 1855
             // The total increase equals the number removed * the item_price
1856
-            $total_decrease     = wpinv_round_amount( $item_price );
1856
+            $total_decrease     = wpinv_round_amount($item_price);
1857 1857
             
1858
-            if ( wpinv_prices_include_tax() ) {
1859
-                $subtotal -= wpinv_round_amount( $tax );
1858
+            if (wpinv_prices_include_tax()) {
1859
+                $subtotal -= wpinv_round_amount($tax);
1860 1860
             }
1861 1861
 
1862
-            $total              = $subtotal - $discount + $tax;
1862
+            $total = $subtotal - $discount + $tax;
1863 1863
 
1864 1864
             // Do not allow totals to go negative
1865
-            if( $total < 0 ) {
1865
+            if ($total < 0) {
1866 1866
                 $total = 0;
1867 1867
             }
1868 1868
             
@@ -1881,16 +1881,16 @@  discard block
 block discarded – undo
1881 1881
             
1882 1882
             $this->cart_details[$found_cart_key] = $cart_item;
1883 1883
             
1884
-            $remove_item = end( $this->cart_details );
1884
+            $remove_item = end($this->cart_details);
1885 1885
         } else {
1886 1886
             $item_price     = $cart_item['item_price'];
1887
-            $discount       = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1888
-            $tax            = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0;
1887
+            $discount       = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1888
+            $tax            = !empty($cart_item['tax']) ? $cart_item['tax'] : 0;
1889 1889
         
1890
-            $subtotal_decrease  = ( $item_price * $quantity ) - $discount;
1890
+            $subtotal_decrease  = ($item_price * $quantity) - $discount;
1891 1891
             $tax_decrease       = $tax;
1892 1892
 
1893
-            unset( $this->cart_details[$found_cart_key] );
1893
+            unset($this->cart_details[$found_cart_key]);
1894 1894
             
1895 1895
             $remove_item             = $args;
1896 1896
             $remove_item['id']       = $item_id;
@@ -1901,8 +1901,8 @@  discard block
 block discarded – undo
1901 1901
         $remove_item['action']      = 'remove';
1902 1902
         $this->pending['items'][]   = $remove_item;
1903 1903
                
1904
-        $this->decrease_subtotal( $subtotal_decrease );
1905
-        $this->decrease_tax( $tax_decrease );
1904
+        $this->decrease_subtotal($subtotal_decrease);
1905
+        $this->decrease_tax($tax_decrease);
1906 1906
         
1907 1907
         return true;
1908 1908
     }
@@ -1910,7 +1910,7 @@  discard block
 block discarded – undo
1910 1910
     public function update_items($temp = false) {
1911 1911
         global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave;
1912 1912
         
1913
-        if ( !empty( $this->cart_details ) ) {
1913
+        if (!empty($this->cart_details)) {
1914 1914
             $wpi_nosave             = $temp;
1915 1915
             $cart_subtotal          = 0;
1916 1916
             $cart_discount          = 0;
@@ -1920,61 +1920,61 @@  discard block
 block discarded – undo
1920 1920
             $_POST['wpinv_country'] = $this->country;
1921 1921
             $_POST['wpinv_state']   = $this->state;
1922 1922
             
1923
-            foreach ( $this->cart_details as $key => $item ) {
1923
+            foreach ($this->cart_details as $key => $item) {
1924 1924
                 $item_price = $item['item_price'];
1925
-                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1926
-                $amount     = wpinv_round_amount( $item_price * $quantity );
1925
+                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1926
+                $amount     = wpinv_round_amount($item_price * $quantity);
1927 1927
                 $subtotal   = $item_price * $quantity;
1928 1928
                 
1929 1929
                 $wpi_current_id         = $this->ID;
1930 1930
                 $wpi_item_id            = $item['id'];
1931 1931
                 
1932
-                $discount   = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() );
1932
+                $discount   = wpinv_get_cart_item_discount_amount($item, $this->get_discounts());
1933 1933
                 
1934
-                $tax_rate   = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id );
1935
-                $tax_class  = $wpinv_euvat->get_item_class( $wpi_item_id );
1936
-                $tax        = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1934
+                $tax_rate   = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id);
1935
+                $tax_class  = $wpinv_euvat->get_item_class($wpi_item_id);
1936
+                $tax        = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
1937 1937
 
1938
-                if ( wpinv_prices_include_tax() ) {
1939
-                    $subtotal -= wpinv_round_amount( $tax );
1938
+                if (wpinv_prices_include_tax()) {
1939
+                    $subtotal -= wpinv_round_amount($tax);
1940 1940
                 }
1941 1941
 
1942
-                $total      = $subtotal - $discount + $tax;
1942
+                $total = $subtotal - $discount + $tax;
1943 1943
 
1944 1944
                 // Do not allow totals to go negative
1945
-                if( $total < 0 ) {
1945
+                if ($total < 0) {
1946 1946
                     $total = 0;
1947 1947
                 }
1948 1948
 
1949 1949
                 $cart_details[] = array(
1950 1950
                     'id'          => $item['id'],
1951 1951
                     'name'        => $item['name'],
1952
-                    'item_price'  => wpinv_round_amount( $item_price ),
1953
-                    'custom_price'=> ( isset( $item['custom_price'] ) ? $item['custom_price'] : '' ),
1952
+                    'item_price'  => wpinv_round_amount($item_price),
1953
+                    'custom_price'=> (isset($item['custom_price']) ? $item['custom_price'] : ''),
1954 1954
                     'quantity'    => $quantity,
1955 1955
                     'discount'    => $discount,
1956
-                    'subtotal'    => wpinv_round_amount( $subtotal ),
1957
-                    'tax'         => wpinv_round_amount( $tax ),
1958
-                    'price'       => wpinv_round_amount( $total ),
1956
+                    'subtotal'    => wpinv_round_amount($subtotal),
1957
+                    'tax'         => wpinv_round_amount($tax),
1958
+                    'price'       => wpinv_round_amount($total),
1959 1959
                     'vat_rate'    => $tax_rate,
1960 1960
                     'vat_class'   => $tax_class,
1961 1961
                     'meta'        => isset($item['meta']) ? $item['meta'] : array(),
1962 1962
                     'fees'        => isset($item['fees']) ? $item['fees'] : array(),
1963 1963
                 );
1964 1964
                 
1965
-                $cart_subtotal  += (float)($subtotal - $discount); // TODO
1966
-                $cart_discount  += (float)($discount);
1967
-                $cart_tax       += (float)($tax);
1965
+                $cart_subtotal  += (float) ($subtotal - $discount); // TODO
1966
+                $cart_discount  += (float) ($discount);
1967
+                $cart_tax       += (float) ($tax);
1968 1968
             }
1969
-            if ( $cart_subtotal < 0 ) {
1969
+            if ($cart_subtotal < 0) {
1970 1970
                 $cart_subtotal = 0;
1971 1971
             }
1972
-            if ( $cart_tax < 0 ) {
1972
+            if ($cart_tax < 0) {
1973 1973
                 $cart_tax = 0;
1974 1974
             }
1975
-            $this->subtotal = wpinv_round_amount( $cart_subtotal );
1976
-            $this->tax      = wpinv_round_amount( $cart_tax );
1977
-            $this->discount = wpinv_round_amount( $cart_discount );
1975
+            $this->subtotal = wpinv_round_amount($cart_subtotal);
1976
+            $this->tax      = wpinv_round_amount($cart_tax);
1977
+            $this->discount = wpinv_round_amount($cart_discount);
1978 1978
             
1979 1979
             $this->recalculate_total();
1980 1980
             
@@ -1986,197 +1986,197 @@  discard block
 block discarded – undo
1986 1986
     
1987 1987
     public function recalculate_totals($temp = false) {        
1988 1988
         $this->update_items($temp);
1989
-        $this->save( true );
1989
+        $this->save(true);
1990 1990
         
1991 1991
         return $this;
1992 1992
     }
1993 1993
     
1994 1994
     public function needs_payment() {
1995
-        $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'wpi-pending' ), $this );
1995
+        $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('wpi-pending'), $this);
1996 1996
 
1997
-        if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free() ) ) {
1997
+        if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free())) {
1998 1998
             $needs_payment = true;
1999 1999
         } else {
2000 2000
             $needs_payment = false;
2001 2001
         }
2002 2002
 
2003
-        return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses );
2003
+        return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses);
2004 2004
     }
2005 2005
     
2006
-    public function get_checkout_payment_url( $with_key = false, $secret = false ) {
2006
+    public function get_checkout_payment_url($with_key = false, $secret = false) {
2007 2007
         $pay_url = wpinv_get_checkout_uri();
2008 2008
 
2009
-        if ( is_ssl() ) {
2010
-            $pay_url = str_replace( 'http:', 'https:', $pay_url );
2009
+        if (is_ssl()) {
2010
+            $pay_url = str_replace('http:', 'https:', $pay_url);
2011 2011
         }
2012 2012
         
2013 2013
         $key = $this->get_key();
2014 2014
 
2015
-        if ( $with_key ) {
2016
-            $pay_url = add_query_arg( 'invoice_key', $key, $pay_url );
2015
+        if ($with_key) {
2016
+            $pay_url = add_query_arg('invoice_key', $key, $pay_url);
2017 2017
         } else {
2018
-            $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url );
2018
+            $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url);
2019 2019
         }
2020 2020
         
2021
-        if ( $secret ) {
2022
-            $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url );
2021
+        if ($secret) {
2022
+            $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url);
2023 2023
         }
2024 2024
 
2025
-        return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret );
2025
+        return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret);
2026 2026
     }
2027 2027
     
2028
-    public function get_view_url( $with_key = false ) {
2029
-        $invoice_url = get_permalink( $this->ID );
2028
+    public function get_view_url($with_key = false) {
2029
+        $invoice_url = get_permalink($this->ID);
2030 2030
 
2031
-        if ( $with_key ) {
2032
-            $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
2031
+        if ($with_key) {
2032
+            $invoice_url = add_query_arg('invoice_key', $this->get_key(), $invoice_url);
2033 2033
         }
2034 2034
 
2035
-        return apply_filters( 'wpinv_get_view_url', $invoice_url, $this, $with_key );
2035
+        return apply_filters('wpinv_get_view_url', $invoice_url, $this, $with_key);
2036 2036
     }
2037 2037
     
2038
-    public function generate_key( $string = '' ) {
2039
-        $auth_key  = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
2040
-        return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) );  // Unique key
2038
+    public function generate_key($string = '') {
2039
+        $auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
2040
+        return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key
2041 2041
     }
2042 2042
     
2043 2043
     public function is_recurring() {
2044
-        if ( empty( $this->cart_details ) ) {
2044
+        if (empty($this->cart_details)) {
2045 2045
             return false;
2046 2046
         }
2047 2047
         
2048 2048
         $has_subscription = false;
2049
-        foreach( $this->cart_details as $cart_item ) {
2050
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2049
+        foreach ($this->cart_details as $cart_item) {
2050
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2051 2051
                 $has_subscription = true;
2052 2052
                 break;
2053 2053
             }
2054 2054
         }
2055 2055
         
2056
-        if ( count( $this->cart_details ) > 1 ) {
2056
+        if (count($this->cart_details) > 1) {
2057 2057
             $has_subscription = false;
2058 2058
         }
2059 2059
 
2060
-        return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details );
2060
+        return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details);
2061 2061
     }
2062 2062
     
2063 2063
     public function is_free_trial() {
2064 2064
         $is_free_trial = false;
2065 2065
         
2066
-        if ( $this->is_parent() && $item = $this->get_recurring( true ) ) {
2067
-            if ( !empty( $item ) && $item->has_free_trial() ) {
2066
+        if ($this->is_parent() && $item = $this->get_recurring(true)) {
2067
+            if (!empty($item) && $item->has_free_trial()) {
2068 2068
                 $is_free_trial = true;
2069 2069
             }
2070 2070
         }
2071 2071
 
2072
-        return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details );
2072
+        return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details);
2073 2073
     }
2074 2074
     
2075 2075
     public function is_initial_free() {
2076 2076
         $is_initial_free = false;
2077 2077
         
2078
-        if ( ! ( (float)wpinv_round_amount( $this->get_total() ) > 0 ) && $this->is_parent() && $this->is_recurring() && ! $this->is_free_trial() && ! $this->is_free() ) {
2078
+        if (!((float) wpinv_round_amount($this->get_total()) > 0) && $this->is_parent() && $this->is_recurring() && !$this->is_free_trial() && !$this->is_free()) {
2079 2079
             $is_initial_free = true;
2080 2080
         }
2081 2081
 
2082
-        return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details );
2082
+        return apply_filters('wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details);
2083 2083
     }
2084 2084
     
2085
-    public function get_recurring( $object = false ) {
2085
+    public function get_recurring($object = false) {
2086 2086
         $item = NULL;
2087 2087
         
2088
-        if ( empty( $this->cart_details ) ) {
2088
+        if (empty($this->cart_details)) {
2089 2089
             return $item;
2090 2090
         }
2091 2091
         
2092
-        foreach( $this->cart_details as $cart_item ) {
2093
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2092
+        foreach ($this->cart_details as $cart_item) {
2093
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2094 2094
                 $item = $cart_item['id'];
2095 2095
                 break;
2096 2096
             }
2097 2097
         }
2098 2098
         
2099
-        if ( $object ) {
2100
-            $item = $item ? new WPInv_Item( $item ) : NULL;
2099
+        if ($object) {
2100
+            $item = $item ? new WPInv_Item($item) : NULL;
2101 2101
             
2102
-            apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this );
2102
+            apply_filters('wpinv_invoice_get_recurring_item', $item, $this);
2103 2103
         }
2104 2104
 
2105
-        return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this );
2105
+        return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this);
2106 2106
     }
2107 2107
     
2108 2108
     public function get_subscription_name() {
2109
-        $item = $this->get_recurring( true );
2109
+        $item = $this->get_recurring(true);
2110 2110
         
2111
-        if ( empty( $item ) ) {
2111
+        if (empty($item)) {
2112 2112
             return NULL;
2113 2113
         }
2114 2114
         
2115
-        if ( !($name = $item->get_name()) ) {
2115
+        if (!($name = $item->get_name())) {
2116 2116
             $name = $item->post_name;
2117 2117
         }
2118 2118
 
2119
-        return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this );
2119
+        return apply_filters('wpinv_invoice_get_subscription_name', $name, $this);
2120 2120
     }
2121 2121
     
2122 2122
     public function get_subscription_id() {
2123
-        $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true );
2123
+        $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true);
2124 2124
         
2125
-        if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) {
2126
-            $parent_invoice = wpinv_get_invoice( $this->parent_invoice );
2125
+        if (empty($subscription_id) && !empty($this->parent_invoice)) {
2126
+            $parent_invoice = wpinv_get_invoice($this->parent_invoice);
2127 2127
             
2128
-            $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true );
2128
+            $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true);
2129 2129
         }
2130 2130
         
2131 2131
         return $subscription_id;
2132 2132
     }
2133 2133
     
2134 2134
     public function is_parent() {
2135
-        $is_parent = empty( $this->parent_invoice ) ? true : false;
2135
+        $is_parent = empty($this->parent_invoice) ? true : false;
2136 2136
 
2137
-        return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this );
2137
+        return apply_filters('wpinv_invoice_is_parent', $is_parent, $this);
2138 2138
     }
2139 2139
     
2140 2140
     public function is_renewal() {
2141 2141
         $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false;
2142 2142
 
2143
-        return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this );
2143
+        return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this);
2144 2144
     }
2145 2145
     
2146 2146
     public function get_parent_payment() {
2147 2147
         $parent_payment = NULL;
2148 2148
         
2149
-        if ( $this->is_renewal() ) {
2150
-            $parent_payment = wpinv_get_invoice( $this->parent_invoice );
2149
+        if ($this->is_renewal()) {
2150
+            $parent_payment = wpinv_get_invoice($this->parent_invoice);
2151 2151
         }
2152 2152
         
2153 2153
         return $parent_payment;
2154 2154
     }
2155 2155
     
2156 2156
     public function is_paid() {
2157
-        $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) );
2157
+        $is_paid = $this->has_status(array('publish', 'wpi-processing', 'wpi-renewal'));
2158 2158
 
2159
-        return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this );
2159
+        return apply_filters('wpinv_invoice_is_paid', $is_paid, $this);
2160 2160
     }
2161 2161
     
2162 2162
     public function is_refunded() {
2163
-        $is_refunded = $this->has_status( array( 'wpi-refunded' ) );
2163
+        $is_refunded = $this->has_status(array('wpi-refunded'));
2164 2164
 
2165
-        return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this );
2165
+        return apply_filters('wpinv_invoice_is_refunded', $is_refunded, $this);
2166 2166
     }
2167 2167
     
2168 2168
     public function is_free() {
2169 2169
         $is_free = false;
2170 2170
         
2171
-        if ( !( (float)wpinv_round_amount( $this->get_total() ) > 0 ) ) {
2172
-            if ( $this->is_parent() && $this->is_recurring() ) {
2173
-                $is_free = (float)wpinv_round_amount( $this->get_recurring_details( 'total' ) ) > 0 ? false : true;
2171
+        if (!((float) wpinv_round_amount($this->get_total()) > 0)) {
2172
+            if ($this->is_parent() && $this->is_recurring()) {
2173
+                $is_free = (float) wpinv_round_amount($this->get_recurring_details('total')) > 0 ? false : true;
2174 2174
             } else {
2175 2175
                 $is_free = true;
2176 2176
             }
2177 2177
         }
2178 2178
         
2179
-        return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
2179
+        return apply_filters('wpinv_invoice_is_free', $is_free, $this);
2180 2180
     }
2181 2181
     
2182 2182
     public function has_vat() {
@@ -2184,41 +2184,41 @@  discard block
 block discarded – undo
2184 2184
         
2185 2185
         $requires_vat = false;
2186 2186
         
2187
-        if ( $this->country ) {
2187
+        if ($this->country) {
2188 2188
             $wpi_country        = $this->country;
2189 2189
             
2190
-            $requires_vat       = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) );
2190
+            $requires_vat       = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this));
2191 2191
         }
2192 2192
         
2193
-        return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2193
+        return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this);
2194 2194
     }
2195 2195
     
2196 2196
     public function refresh_item_ids() {
2197 2197
         $item_ids = array();
2198 2198
         
2199
-        if ( !empty( $this->cart_details ) ) {
2200
-            foreach ( $this->cart_details as $key => $item ) {
2201
-                if ( !empty( $item['id'] ) ) {
2199
+        if (!empty($this->cart_details)) {
2200
+            foreach ($this->cart_details as $key => $item) {
2201
+                if (!empty($item['id'])) {
2202 2202
                     $item_ids[] = $item['id'];
2203 2203
                 }
2204 2204
             }
2205 2205
         }
2206 2206
         
2207
-        $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : '';
2207
+        $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : '';
2208 2208
         
2209
-        update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids );
2209
+        update_post_meta($this->ID, '_wpinv_item_ids', $item_ids);
2210 2210
     }
2211 2211
     
2212
-    public function get_invoice_quote_type( $post_id ) {
2213
-        if ( empty( $post_id ) ) {
2212
+    public function get_invoice_quote_type($post_id) {
2213
+        if (empty($post_id)) {
2214 2214
             return '';
2215 2215
         }
2216 2216
 
2217
-        $type = get_post_type( $post_id );
2217
+        $type = get_post_type($post_id);
2218 2218
 
2219
-        if ( 'wpi_invoice' === $type ) {
2219
+        if ('wpi_invoice' === $type) {
2220 2220
             $post_type = __('Invoice', 'invoicing');
2221
-        } else{
2221
+        } else {
2222 2222
             $post_type = __('Quote', 'invoicing');
2223 2223
         }
2224 2224
 
Please login to merge, or discard this patch.
includes/wpinv-email-functions.php 1 patch
Spacing   +582 added lines, -582 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  discard block
 block discarded – undo
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_wpi-pending_to_wpi-processing',
17 17
         'wpinv_status_wpi-pending_to_publish',
18 18
         'wpinv_status_wpi-pending_to_wpi-cancelled',
@@ -30,381 +30,381 @@  discard block
 block discarded – undo
30 30
         'wpinv_fully_refunded',
31 31
         'wpinv_partially_refunded',
32 32
         'wpinv_new_invoice_note'
33
-    ) );
33
+    ));
34 34
 
35
-    foreach ( $email_actions as $action ) {
36
-        add_action( $action, 'wpinv_send_transactional_email', 10, 10 );
35
+    foreach ($email_actions as $action) {
36
+        add_action($action, 'wpinv_send_transactional_email', 10, 10);
37 37
     }
38 38
 }
39
-add_action( 'init', 'wpinv_init_transactional_emails' );
39
+add_action('init', 'wpinv_init_transactional_emails');
40 40
 
41 41
 // New invoice email
42
-add_action( 'wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_new_invoice_notification' );
43
-add_action( 'wpinv_status_wpi-pending_to_publish_notification', 'wpinv_new_invoice_notification' );
44
-add_action( 'wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_new_invoice_notification' );
45
-add_action( 'wpinv_status_wpi-failed_to_wpi-processing_notification', 'wpinv_new_invoice_notification' );
46
-add_action( 'wpinv_status_wpi-failed_to_publish_notification', 'wpinv_new_invoice_notification' );
47
-add_action( 'wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_new_invoice_notification' );
42
+add_action('wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_new_invoice_notification');
43
+add_action('wpinv_status_wpi-pending_to_publish_notification', 'wpinv_new_invoice_notification');
44
+add_action('wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_new_invoice_notification');
45
+add_action('wpinv_status_wpi-failed_to_wpi-processing_notification', 'wpinv_new_invoice_notification');
46
+add_action('wpinv_status_wpi-failed_to_publish_notification', 'wpinv_new_invoice_notification');
47
+add_action('wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_new_invoice_notification');
48 48
 
49 49
 // Cancelled invoice email
50
-add_action( 'wpinv_status_wpi-pending_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification' );
51
-add_action( 'wpinv_status_wpi-onhold_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification' );
50
+add_action('wpinv_status_wpi-pending_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification');
51
+add_action('wpinv_status_wpi-onhold_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification');
52 52
 
53 53
 // Failed invoice email
54
-add_action( 'wpinv_status_wpi-pending_to_wpi-failed_notification', 'wpinv_failed_invoice_notification' );
55
-add_action( 'wpinv_status_wpi-onhold_to_wpi-failed_notification', 'wpinv_failed_invoice_notification' );
54
+add_action('wpinv_status_wpi-pending_to_wpi-failed_notification', 'wpinv_failed_invoice_notification');
55
+add_action('wpinv_status_wpi-onhold_to_wpi-failed_notification', 'wpinv_failed_invoice_notification');
56 56
 
57 57
 // On hold invoice email
58
-add_action( 'wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification' );
59
-add_action( 'wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification' );
58
+add_action('wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification');
59
+add_action('wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification');
60 60
 
61 61
 // Processing invoice email
62
-add_action( 'wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_processing_invoice_notification' );
62
+add_action('wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_processing_invoice_notification');
63 63
 
64 64
 // Paid invoice email
65
-add_action( 'wpinv_status_publish_notification', 'wpinv_completed_invoice_notification' );
65
+add_action('wpinv_status_publish_notification', 'wpinv_completed_invoice_notification');
66 66
 
67 67
 // Refunded invoice email
68
-add_action( 'wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification' );
69
-add_action( 'wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification' );
70
-add_action( 'wpinv_status_publish_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification' );
71
-add_action( 'wpinv_status_wpi-processing_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification' );
68
+add_action('wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification');
69
+add_action('wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification');
70
+add_action('wpinv_status_publish_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification');
71
+add_action('wpinv_status_wpi-processing_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification');
72 72
 
73 73
 // Invoice note
74
-add_action( 'wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification' );
74
+add_action('wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification');
75 75
 
76
-add_action( 'wpinv_email_header', 'wpinv_email_header' );
77
-add_action( 'wpinv_email_footer', 'wpinv_email_footer' );
78
-add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 );
79
-add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 );
80
-add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 );
76
+add_action('wpinv_email_header', 'wpinv_email_header');
77
+add_action('wpinv_email_footer', 'wpinv_email_footer');
78
+add_action('wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3);
79
+add_action('wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3);
80
+add_action('wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3);
81 81
 
82 82
 function wpinv_send_transactional_email() {
83 83
     $args       = func_get_args();
84 84
     $function   = current_filter() . '_notification';
85
-    do_action_ref_array( $function, $args );
85
+    do_action_ref_array($function, $args);
86 86
 }
87 87
 
88
-function wpinv_new_invoice_notification( $invoice_id, $new_status = '' ) {
88
+function wpinv_new_invoice_notification($invoice_id, $new_status = '') {
89 89
     $email_type = 'new_invoice';
90
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
90
+    if (!wpinv_email_is_enabled($email_type)) {
91 91
         return false;
92 92
     }
93 93
 
94
-    $invoice = wpinv_get_invoice( $invoice_id );
95
-    if ( empty( $invoice ) ) {
94
+    $invoice = wpinv_get_invoice($invoice_id);
95
+    if (empty($invoice)) {
96 96
         return false;
97 97
     }
98 98
 
99
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
99
+    if (!("wpi_invoice" === $invoice->post_type)) {
100 100
         return false;
101 101
     }
102 102
 
103
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
104
-    if ( !is_email( $recipient ) ) {
103
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
104
+    if (!is_email($recipient)) {
105 105
         return false;
106 106
     }
107 107
 
108
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type, true );
108
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type, true);
109 109
 
110
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
111
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
112
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
113
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
114
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
110
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
111
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
112
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
113
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
114
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
115 115
 
116
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
116
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
117 117
             'invoice'       => $invoice,
118 118
             'email_type'    => $email_type,
119 119
             'email_heading' => $email_heading,
120 120
             'sent_to_admin' => true,
121 121
             'plain_text'    => false,
122 122
             'message_body'  => $message_body,
123
-        ) );
123
+        ));
124 124
 
125
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
125
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
126 126
 
127
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type, true );
127
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type, true);
128 128
 
129 129
     return $sent;
130 130
 }
131 131
 
132
-function wpinv_cancelled_invoice_notification( $invoice_id, $new_status = '' ) {
132
+function wpinv_cancelled_invoice_notification($invoice_id, $new_status = '') {
133 133
     $email_type = 'cancelled_invoice';
134
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
134
+    if (!wpinv_email_is_enabled($email_type)) {
135 135
         return false;
136 136
     }
137 137
 
138
-    $invoice = wpinv_get_invoice( $invoice_id );
139
-    if ( empty( $invoice ) ) {
138
+    $invoice = wpinv_get_invoice($invoice_id);
139
+    if (empty($invoice)) {
140 140
         return false;
141 141
     }
142 142
 
143
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
143
+    if (!("wpi_invoice" === $invoice->post_type)) {
144 144
         return false;
145 145
     }
146 146
 
147
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
148
-    if ( !is_email( $recipient ) ) {
147
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
148
+    if (!is_email($recipient)) {
149 149
         return false;
150 150
     }
151 151
 
152
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type, true );
152
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type, true);
153 153
 
154
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
155
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
156
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
157
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
158
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
154
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
155
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
156
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
157
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
158
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
159 159
 
160
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
160
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
161 161
             'invoice'       => $invoice,
162 162
             'email_type'    => $email_type,
163 163
             'email_heading' => $email_heading,
164 164
             'sent_to_admin' => true,
165 165
             'plain_text'    => false,
166 166
             'message_body'  => $message_body,
167
-        ) );
167
+        ));
168 168
 
169
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
169
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
170 170
 
171
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type, true );
171
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type, true);
172 172
 
173 173
     return $sent;
174 174
 }
175 175
 
176
-function wpinv_failed_invoice_notification( $invoice_id, $new_status = '' ) {
176
+function wpinv_failed_invoice_notification($invoice_id, $new_status = '') {
177 177
     $email_type = 'failed_invoice';
178
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
178
+    if (!wpinv_email_is_enabled($email_type)) {
179 179
         return false;
180 180
     }
181 181
     
182
-    $invoice = wpinv_get_invoice( $invoice_id );
183
-    if ( empty( $invoice ) ) {
182
+    $invoice = wpinv_get_invoice($invoice_id);
183
+    if (empty($invoice)) {
184 184
         return false;
185 185
     }
186 186
 
187
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
187
+    if (!("wpi_invoice" === $invoice->post_type)) {
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
 
196
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type, true );
196
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type, true);
197 197
 
198
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
199
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
200
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
201
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
202
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
198
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
199
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
200
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
201
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
202
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
203 203
     
204
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
204
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
205 205
             'invoice'       => $invoice,
206 206
             'email_type'    => $email_type,
207 207
             'email_heading' => $email_heading,
208 208
             'sent_to_admin' => true,
209 209
             'plain_text'    => false,
210 210
             'message_body'  => $message_body,
211
-        ) );
211
+        ));
212 212
 
213
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
213
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
214 214
 
215
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type, true );
215
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type, true);
216 216
 
217 217
     return $sent;
218 218
 }
219 219
 
220
-function wpinv_onhold_invoice_notification( $invoice_id, $new_status = '' ) {
220
+function wpinv_onhold_invoice_notification($invoice_id, $new_status = '') {
221 221
     $email_type = 'onhold_invoice';
222
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
222
+    if (!wpinv_email_is_enabled($email_type)) {
223 223
         return false;
224 224
     }
225 225
 
226
-    $invoice = wpinv_get_invoice( $invoice_id );
227
-    if ( empty( $invoice ) ) {
226
+    $invoice = wpinv_get_invoice($invoice_id);
227
+    if (empty($invoice)) {
228 228
         return false;
229 229
     }
230 230
 
231
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
231
+    if (!("wpi_invoice" === $invoice->post_type)) {
232 232
         return false;
233 233
     }
234 234
 
235
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
236
-    if ( !is_email( $recipient ) ) {
235
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
236
+    if (!is_email($recipient)) {
237 237
         return false;
238 238
     }
239 239
 
240
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
240
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
241 241
 
242
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
243
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
244
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
245
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
246
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
242
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
243
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
244
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
245
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
246
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
247 247
     
248
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
248
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
249 249
             'invoice'       => $invoice,
250 250
             'email_type'    => $email_type,
251 251
             'email_heading' => $email_heading,
252 252
             'sent_to_admin' => false,
253 253
             'plain_text'    => false,
254 254
             'message_body'  => $message_body,
255
-        ) );
255
+        ));
256 256
     
257
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
257
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
258 258
     
259
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
260
-        $recipient  = wpinv_get_admin_email();
261
-        $subject    .= ' - ADMIN BCC COPY';
262
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
259
+    if (wpinv_mail_admin_bcc_active($email_type)) {
260
+        $recipient = wpinv_get_admin_email();
261
+        $subject .= ' - ADMIN BCC COPY';
262
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
263 263
     }
264 264
 
265
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
265
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
266 266
 
267 267
     return $sent;
268 268
 }
269 269
 
270
-function wpinv_processing_invoice_notification( $invoice_id, $new_status = '' ) {
270
+function wpinv_processing_invoice_notification($invoice_id, $new_status = '') {
271 271
     $email_type = 'processing_invoice';
272
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
272
+    if (!wpinv_email_is_enabled($email_type)) {
273 273
         return false;
274 274
     }
275 275
 
276
-    $invoice = wpinv_get_invoice( $invoice_id );
277
-    if ( empty( $invoice ) ) {
276
+    $invoice = wpinv_get_invoice($invoice_id);
277
+    if (empty($invoice)) {
278 278
         return false;
279 279
     }
280 280
 
281
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
281
+    if (!("wpi_invoice" === $invoice->post_type)) {
282 282
         return false;
283 283
     }
284 284
 
285
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
286
-    if ( !is_email( $recipient ) ) {
285
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
286
+    if (!is_email($recipient)) {
287 287
         return false;
288 288
     }
289 289
 
290
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
290
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
291 291
 
292 292
     $search                     = array();
293 293
     $search['invoice_number']   = '{invoice_number}';
294 294
     $search['invoice_date']     = '{invoice_date}';
295 295
     $search['name']             = '{name}';
296 296
 
297
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
298
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
299
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
300
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
301
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
297
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
298
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
299
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
300
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
301
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
302 302
     
303
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
303
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
304 304
             'invoice'       => $invoice,
305 305
             'email_type'    => $email_type,
306 306
             'email_heading' => $email_heading,
307 307
             'sent_to_admin' => false,
308 308
             'plain_text'    => false,
309 309
             'message_body'  => $message_body,
310
-        ) );
310
+        ));
311 311
 
312
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
312
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
313 313
 
314
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
315
-        $recipient  = wpinv_get_admin_email();
316
-        $subject    .= ' - ADMIN BCC COPY';
317
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
314
+    if (wpinv_mail_admin_bcc_active($email_type)) {
315
+        $recipient = wpinv_get_admin_email();
316
+        $subject .= ' - ADMIN BCC COPY';
317
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
318 318
     }
319 319
 
320
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
320
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
321 321
 
322 322
     return $sent;
323 323
 }
324 324
 
325
-function wpinv_completed_invoice_notification( $invoice_id, $new_status = '' ) {
325
+function wpinv_completed_invoice_notification($invoice_id, $new_status = '') {
326 326
     $email_type = 'completed_invoice';
327
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
327
+    if (!wpinv_email_is_enabled($email_type)) {
328 328
         return false;
329 329
     }
330 330
 
331
-    $invoice = wpinv_get_invoice( $invoice_id );
332
-    if ( empty( $invoice ) ) {
331
+    $invoice = wpinv_get_invoice($invoice_id);
332
+    if (empty($invoice)) {
333 333
         return false;
334 334
     }
335 335
 
336
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
336
+    if (!("wpi_invoice" === $invoice->post_type)) {
337 337
         return false;
338 338
     }
339 339
 
340
-    if($invoice->is_renewal() && wpinv_email_is_enabled( 'completed_invoice_renewal' )){
340
+    if ($invoice->is_renewal() && wpinv_email_is_enabled('completed_invoice_renewal')) {
341 341
         return false;
342 342
     }
343 343
 
344
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
345
-    if ( !is_email( $recipient ) ) {
344
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
345
+    if (!is_email($recipient)) {
346 346
         return false;
347 347
     }
348 348
 
349
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
349
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
350 350
 
351
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
352
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
353
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
354
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
355
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
351
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
352
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
353
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
354
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
355
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
356 356
 
357
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
357
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
358 358
             'invoice'       => $invoice,
359 359
             'email_type'    => $email_type,
360 360
             'email_heading' => $email_heading,
361 361
             'sent_to_admin' => false,
362 362
             'plain_text'    => false,
363 363
             'message_body'  => $message_body,
364
-        ) );
364
+        ));
365 365
 
366
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
366
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
367 367
 
368
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
369
-        $recipient  = wpinv_get_admin_email();
370
-        $subject    .= ' - ADMIN BCC COPY';
371
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
368
+    if (wpinv_mail_admin_bcc_active($email_type)) {
369
+        $recipient = wpinv_get_admin_email();
370
+        $subject .= ' - ADMIN BCC COPY';
371
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
372 372
     }
373 373
 
374
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
374
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
375 375
 
376 376
     return $sent;
377 377
 }
378 378
 
379
-function wpinv_fully_refunded_notification( $invoice_id, $new_status = '' ) {
379
+function wpinv_fully_refunded_notification($invoice_id, $new_status = '') {
380 380
     $email_type = 'refunded_invoice';
381
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
381
+    if (!wpinv_email_is_enabled($email_type)) {
382 382
         return false;
383 383
     }
384 384
 
385
-    $invoice = wpinv_get_invoice( $invoice_id );
386
-    if ( empty( $invoice ) ) {
385
+    $invoice = wpinv_get_invoice($invoice_id);
386
+    if (empty($invoice)) {
387 387
         return false;
388 388
     }
389 389
 
390
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
390
+    if (!("wpi_invoice" === $invoice->post_type)) {
391 391
         return false;
392 392
     }
393 393
 
394
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
395
-    if ( !is_email( $recipient ) ) {
394
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
395
+    if (!is_email($recipient)) {
396 396
         return false;
397 397
     }
398 398
 
399
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
399
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
400 400
 
401
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
402
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
403
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
404
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
405
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
401
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
402
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
403
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
404
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
405
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
406 406
 
407
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
407
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
408 408
             'invoice'           => $invoice,
409 409
             'email_type'        => $email_type,
410 410
             'email_heading'     => $email_heading,
@@ -412,50 +412,50 @@  discard block
 block discarded – undo
412 412
             'plain_text'        => false,
413 413
             'partial_refund'    => false,
414 414
             'message_body'      => $message_body,
415
-        ) );
415
+        ));
416 416
 
417
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
417
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
418 418
 
419
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
420
-        $recipient  = wpinv_get_admin_email();
421
-        $subject    .= ' - ADMIN BCC COPY';
422
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
419
+    if (wpinv_mail_admin_bcc_active($email_type)) {
420
+        $recipient = wpinv_get_admin_email();
421
+        $subject .= ' - ADMIN BCC COPY';
422
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
423 423
     }
424 424
 
425
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
425
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
426 426
 
427 427
     return $sent;
428 428
 }
429 429
 
430
-function wpinv_partially_refunded_notification( $invoice_id, $new_status = '' ) {
430
+function wpinv_partially_refunded_notification($invoice_id, $new_status = '') {
431 431
     $email_type = 'refunded_invoice';
432
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
432
+    if (!wpinv_email_is_enabled($email_type)) {
433 433
         return false;
434 434
     }
435 435
 
436
-    $invoice = wpinv_get_invoice( $invoice_id );
437
-    if ( empty( $invoice ) ) {
436
+    $invoice = wpinv_get_invoice($invoice_id);
437
+    if (empty($invoice)) {
438 438
         return false;
439 439
     }
440 440
 
441
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
441
+    if (!("wpi_invoice" === $invoice->post_type)) {
442 442
         return false;
443 443
     }
444 444
 
445
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
446
-    if ( !is_email( $recipient ) ) {
445
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
446
+    if (!is_email($recipient)) {
447 447
         return false;
448 448
     }
449 449
 
450
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
450
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
451 451
 
452
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
453
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
454
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
455
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
456
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
452
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
453
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
454
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
455
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
456
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
457 457
 
458
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
458
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
459 459
             'invoice'           => $invoice,
460 460
             'email_type'        => $email_type,
461 461
             'email_heading'     => $email_heading,
@@ -463,95 +463,95 @@  discard block
 block discarded – undo
463 463
             'plain_text'        => false,
464 464
             'partial_refund'    => true,
465 465
             'message_body'      => $message_body,
466
-        ) );
466
+        ));
467 467
 
468
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
468
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
469 469
 
470
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
471
-        $recipient  = wpinv_get_admin_email();
472
-        $subject    .= ' - ADMIN BCC COPY';
473
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
470
+    if (wpinv_mail_admin_bcc_active($email_type)) {
471
+        $recipient = wpinv_get_admin_email();
472
+        $subject .= ' - ADMIN BCC COPY';
473
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
474 474
     }
475 475
 
476
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
476
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
477 477
 
478 478
     return $sent;
479 479
 }
480 480
 
481
-function wpinv_new_invoice_note_notification( $invoice_id, $new_status = '' ) {
481
+function wpinv_new_invoice_note_notification($invoice_id, $new_status = '') {
482 482
 }
483 483
 
484
-function wpinv_user_invoice_notification( $invoice_id ) {
484
+function wpinv_user_invoice_notification($invoice_id) {
485 485
     $email_type = 'user_invoice';
486
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
486
+    if (!wpinv_email_is_enabled($email_type)) {
487 487
         return -1;
488 488
     }
489 489
 
490
-    $invoice = wpinv_get_invoice( $invoice_id );
491
-    if ( empty( $invoice ) ) {
490
+    $invoice = wpinv_get_invoice($invoice_id);
491
+    if (empty($invoice)) {
492 492
         return false;
493 493
     }
494 494
 
495
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
495
+    if (!("wpi_invoice" === $invoice->post_type)) {
496 496
         return false;
497 497
     }
498 498
 
499
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
500
-    if ( !is_email( $recipient ) ) {
499
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
500
+    if (!is_email($recipient)) {
501 501
         return false;
502 502
     }
503 503
 
504
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
504
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
505 505
 
506
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
507
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
508
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
509
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
510
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
506
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
507
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
508
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
509
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
510
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
511 511
     
512
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
512
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
513 513
             'invoice'       => $invoice,
514 514
             'email_type'    => $email_type,
515 515
             'email_heading' => $email_heading,
516 516
             'sent_to_admin' => false,
517 517
             'plain_text'    => false,
518 518
             'message_body'  => $message_body,
519
-        ) );
519
+        ));
520 520
 
521
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
521
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
522 522
 
523
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
524
-        $recipient  = wpinv_get_admin_email();
525
-        $subject    .= ' - ADMIN BCC COPY';
526
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
523
+    if (wpinv_mail_admin_bcc_active($email_type)) {
524
+        $recipient = wpinv_get_admin_email();
525
+        $subject .= ' - ADMIN BCC COPY';
526
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
527 527
     }
528 528
 
529
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
529
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
530 530
 
531
-    if ( $sent ) {
532
-        $note = __( 'Invoice has been emailed to the user.', 'invoicing' );
531
+    if ($sent) {
532
+        $note = __('Invoice has been emailed to the user.', 'invoicing');
533 533
     } else {
534
-        $note = __( 'Fail to send invoice to the user!', 'invoicing' );
534
+        $note = __('Fail to send invoice to the user!', 'invoicing');
535 535
     }
536 536
 
537
-    $invoice->add_note( $note, '', '', true ); // Add system note.
537
+    $invoice->add_note($note, '', '', true); // Add system note.
538 538
 
539 539
     return $sent;
540 540
 }
541 541
 
542
-function wpinv_user_note_notification( $invoice_id, $args = array() ) {
542
+function wpinv_user_note_notification($invoice_id, $args = array()) {
543 543
     $email_type = 'user_note';
544
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
544
+    if (!wpinv_email_is_enabled($email_type)) {
545 545
         return false;
546 546
     }
547 547
 
548
-    $invoice = wpinv_get_invoice( $invoice_id );
549
-    if ( empty( $invoice ) ) {
548
+    $invoice = wpinv_get_invoice($invoice_id);
549
+    if (empty($invoice)) {
550 550
         return false;
551 551
     }
552 552
 
553
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
554
-    if ( !is_email( $recipient ) ) {
553
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
554
+    if (!is_email($recipient)) {
555 555
         return false;
556 556
     }
557 557
 
@@ -559,19 +559,19 @@  discard block
 block discarded – undo
559 559
         'user_note' => ''
560 560
     );
561 561
 
562
-    $args = wp_parse_args( $args, $defaults );
562
+    $args = wp_parse_args($args, $defaults);
563 563
 
564
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
564
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
565 565
 
566
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
567
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
568
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
569
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
570
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
566
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
567
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
568
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
569
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
570
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
571 571
 
572
-    $message_body   = str_replace( '{customer_note}', $args['user_note'], $message_body );
572
+    $message_body   = str_replace('{customer_note}', $args['user_note'], $message_body);
573 573
 
574
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
574
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
575 575
             'invoice'       => $invoice,
576 576
             'email_type'    => $email_type,
577 577
             'email_heading' => $email_heading,
@@ -579,36 +579,36 @@  discard block
 block discarded – undo
579 579
             'plain_text'    => false,
580 580
             'message_body'  => $message_body,
581 581
             'customer_note' => $args['user_note']
582
-        ) );
582
+        ));
583 583
 
584
-    $content        = wpinv_email_format_text( $content, $invoice );
584
+    $content = wpinv_email_format_text($content, $invoice);
585 585
 
586
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
586
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
587 587
 
588
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
588
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
589 589
 
590 590
     return $sent;
591 591
 }
592 592
 
593 593
 function wpinv_mail_get_from_address() {
594
-    $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from' ) );
595
-    return sanitize_email( $from_address );
594
+    $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from'));
595
+    return sanitize_email($from_address);
596 596
 }
597 597
 
598 598
 function wpinv_mail_get_from_name() {
599
-    $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name' ) );
600
-    return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES );
599
+    $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name'));
600
+    return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES);
601 601
 }
602 602
 
603
-function wpinv_mail_admin_bcc_active( $mail_type = '' ) {
604
-    $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) );
605
-    return ( $active ? true : false );
603
+function wpinv_mail_admin_bcc_active($mail_type = '') {
604
+    $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc'));
605
+    return ($active ? true : false);
606 606
 }
607 607
     
608
-function wpinv_mail_get_content_type(  $content_type = 'text/html', $email_type = 'html' ) {
609
-    $email_type = apply_filters( 'wpinv_mail_content_type', $email_type );
608
+function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') {
609
+    $email_type = apply_filters('wpinv_mail_content_type', $email_type);
610 610
 
611
-    switch ( $email_type ) {
611
+    switch ($email_type) {
612 612
         case 'html' :
613 613
             $content_type = 'text/html';
614 614
             break;
@@ -623,35 +623,35 @@  discard block
 block discarded – undo
623 623
     return $content_type;
624 624
 }
625 625
     
626
-function wpinv_mail_send( $to, $subject, $message, $headers, $attachments ) {
627
-    add_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
628
-    add_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
629
-    add_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
626
+function wpinv_mail_send($to, $subject, $message, $headers, $attachments) {
627
+    add_filter('wp_mail_from', 'wpinv_mail_get_from_address');
628
+    add_filter('wp_mail_from_name', 'wpinv_mail_get_from_name');
629
+    add_filter('wp_mail_content_type', 'wpinv_mail_get_content_type');
630 630
 
631
-    $message = wpinv_email_style_body( $message );
632
-    $message = apply_filters( 'wpinv_mail_content', $message );
631
+    $message = wpinv_email_style_body($message);
632
+    $message = apply_filters('wpinv_mail_content', $message);
633 633
 
634
-    $sent  = wp_mail( $to, $subject, $message, $headers, $attachments );
634
+    $sent = wp_mail($to, $subject, $message, $headers, $attachments);
635 635
 
636
-    if ( !$sent ) {
637
-        $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 );
638
-        wpinv_error_log( $log_message, __( "Email from Invoicing plugin failed to send", 'invoicing' ), __FILE__, __LINE__ );
636
+    if (!$sent) {
637
+        $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);
638
+        wpinv_error_log($log_message, __("Email from Invoicing plugin failed to send", 'invoicing'), __FILE__, __LINE__);
639 639
     }
640 640
 
641
-    remove_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
642
-    remove_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
643
-    remove_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
641
+    remove_filter('wp_mail_from', 'wpinv_mail_get_from_address');
642
+    remove_filter('wp_mail_from_name', 'wpinv_mail_get_from_name');
643
+    remove_filter('wp_mail_content_type', 'wpinv_mail_get_content_type');
644 644
 
645 645
     return $sent;
646 646
 }
647 647
     
648 648
 function wpinv_get_emails() {
649 649
     $overdue_days_options       = array();
650
-    $overdue_days_options[0]    = __( 'On the Due Date', 'invoicing' );
651
-    $overdue_days_options[1]    = __( '1 day after Due Date', 'invoicing' );
650
+    $overdue_days_options[0]    = __('On the Due Date', 'invoicing');
651
+    $overdue_days_options[1]    = __('1 day after Due Date', 'invoicing');
652 652
 
653
-    for ( $i = 2; $i <= 10; $i++ ) {
654
-        $overdue_days_options[$i]   = wp_sprintf( __( '%d days after Due Date', 'invoicing' ), $i );
653
+    for ($i = 2; $i <= 10; $i++) {
654
+        $overdue_days_options[$i] = wp_sprintf(__('%d days after Due Date', 'invoicing'), $i);
655 655
     }
656 656
 
657 657
     // Default, built-in gateways
@@ -659,39 +659,39 @@  discard block
 block discarded – undo
659 659
             'new_invoice' => array(
660 660
             'email_new_invoice_header' => array(
661 661
                 'id'   => 'email_new_invoice_header',
662
-                'name' => '<h3>' . __( 'New Invoice', 'invoicing' ) . '</h3>',
663
-                'desc' => __( 'New invoice emails are sent to admin when a new invoice is received.', 'invoicing' ),
662
+                'name' => '<h3>' . __('New Invoice', 'invoicing') . '</h3>',
663
+                'desc' => __('New invoice emails are sent to admin when a new invoice is received.', 'invoicing'),
664 664
                 'type' => 'header',
665 665
             ),
666 666
             'email_new_invoice_active' => array(
667 667
                 'id'   => 'email_new_invoice_active',
668
-                'name' => __( 'Enable/Disable', 'invoicing' ),
669
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
668
+                'name' => __('Enable/Disable', 'invoicing'),
669
+                'desc' => __('Enable this email notification', 'invoicing'),
670 670
                 'type' => 'checkbox',
671 671
                 'std'  => 1
672 672
             ),
673 673
             'email_new_invoice_subject' => array(
674 674
                 'id'   => 'email_new_invoice_subject',
675
-                'name' => __( 'Subject', 'invoicing' ),
676
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
675
+                'name' => __('Subject', 'invoicing'),
676
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
677 677
                 'type' => 'text',
678
-                'std'  => __( '[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing' ),
678
+                'std'  => __('[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing'),
679 679
                 'size' => 'large'
680 680
             ),
681 681
             'email_new_invoice_heading' => array(
682 682
                 'id'   => 'email_new_invoice_heading',
683
-                'name' => __( 'Email Heading', 'invoicing' ),
684
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
683
+                'name' => __('Email Heading', 'invoicing'),
684
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
685 685
                 'type' => 'text',
686
-                'std'  => __( 'New payment invoice', 'invoicing' ),
686
+                'std'  => __('New payment invoice', 'invoicing'),
687 687
                 'size' => 'large'
688 688
             ),
689 689
             'email_new_invoice_body' => array(
690 690
                 'id'   => 'email_new_invoice_body',
691
-                'name' => __( 'Email Content', 'invoicing' ),
692
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
691
+                'name' => __('Email Content', 'invoicing'),
692
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
693 693
                 'type' => 'rich_editor',
694
-                'std'  => __( '<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing' ),
694
+                'std'  => __('<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing'),
695 695
                 'class' => 'large',
696 696
                 'size' => '10'
697 697
             ),
@@ -699,39 +699,39 @@  discard block
 block discarded – undo
699 699
         'cancelled_invoice' => array(
700 700
             'email_cancelled_invoice_header' => array(
701 701
                 'id'   => 'email_cancelled_invoice_header',
702
-                'name' => '<h3>' . __( 'Cancelled Invoice', 'invoicing' ) . '</h3>',
703
-                'desc' => __( 'Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing' ),
702
+                'name' => '<h3>' . __('Cancelled Invoice', 'invoicing') . '</h3>',
703
+                'desc' => __('Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing'),
704 704
                 'type' => 'header',
705 705
             ),
706 706
             'email_cancelled_invoice_active' => array(
707 707
                 'id'   => 'email_cancelled_invoice_active',
708
-                'name' => __( 'Enable/Disable', 'invoicing' ),
709
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
708
+                'name' => __('Enable/Disable', 'invoicing'),
709
+                'desc' => __('Enable this email notification', 'invoicing'),
710 710
                 'type' => 'checkbox',
711 711
                 'std'  => 1
712 712
             ),
713 713
             'email_cancelled_invoice_subject' => array(
714 714
                 'id'   => 'email_cancelled_invoice_subject',
715
-                'name' => __( 'Subject', 'invoicing' ),
716
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
715
+                'name' => __('Subject', 'invoicing'),
716
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
717 717
                 'type' => 'text',
718
-                'std'  => __( '[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing' ),
718
+                'std'  => __('[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing'),
719 719
                 'size' => 'large'
720 720
             ),
721 721
             'email_cancelled_invoice_heading' => array(
722 722
                 'id'   => 'email_cancelled_invoice_heading',
723
-                'name' => __( 'Email Heading', 'invoicing' ),
724
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
723
+                'name' => __('Email Heading', 'invoicing'),
724
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
725 725
                 'type' => 'text',
726
-                'std'  => __( 'Cancelled invoice', 'invoicing' ),
726
+                'std'  => __('Cancelled invoice', 'invoicing'),
727 727
                 'size' => 'large'
728 728
             ),
729 729
             'email_cancelled_invoice_body' => array(
730 730
                 'id'   => 'email_cancelled_invoice_body',
731
-                'name' => __( 'Email Content', 'invoicing' ),
732
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
731
+                'name' => __('Email Content', 'invoicing'),
732
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
733 733
                 'type' => 'rich_editor',
734
-                'std'  => __( '<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing' ),
734
+                'std'  => __('<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing'),
735 735
                 'class' => 'large',
736 736
                 'size' => '10'
737 737
             ),
@@ -739,39 +739,39 @@  discard block
 block discarded – undo
739 739
         'failed_invoice' => array(
740 740
             'email_failed_invoice_header' => array(
741 741
                 'id'   => 'email_failed_invoice_header',
742
-                'name' => '<h3>' . __( 'Failed Invoice', 'invoicing' ) . '</h3>',
743
-                'desc' => __( 'Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing' ),
742
+                'name' => '<h3>' . __('Failed Invoice', 'invoicing') . '</h3>',
743
+                'desc' => __('Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing'),
744 744
                 'type' => 'header',
745 745
             ),
746 746
             'email_failed_invoice_active' => array(
747 747
                 'id'   => 'email_failed_invoice_active',
748
-                'name' => __( 'Enable/Disable', 'invoicing' ),
749
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
748
+                'name' => __('Enable/Disable', 'invoicing'),
749
+                'desc' => __('Enable this email notification', 'invoicing'),
750 750
                 'type' => 'checkbox',
751 751
                 'std'  => 1
752 752
             ),
753 753
             'email_failed_invoice_subject' => array(
754 754
                 'id'   => 'email_failed_invoice_subject',
755
-                'name' => __( 'Subject', 'invoicing' ),
756
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
755
+                'name' => __('Subject', 'invoicing'),
756
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
757 757
                 'type' => 'text',
758
-                'std'  => __( '[{site_title}] Failed invoice ({invoice_number})', 'invoicing' ),
758
+                'std'  => __('[{site_title}] Failed invoice ({invoice_number})', 'invoicing'),
759 759
                 'size' => 'large'
760 760
             ),
761 761
             'email_failed_invoice_heading' => array(
762 762
                 'id'   => 'email_failed_invoice_heading',
763
-                'name' => __( 'Email Heading', 'invoicing' ),
764
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
763
+                'name' => __('Email Heading', 'invoicing'),
764
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
765 765
                 'type' => 'text',
766
-                'std'  => __( 'Failed invoice', 'invoicing' ),
766
+                'std'  => __('Failed invoice', 'invoicing'),
767 767
                 'size' => 'large'
768 768
             ),
769 769
             'email_failed_invoice_body' => array(
770 770
                 'id'   => 'email_failed_invoice_body',
771
-                'name' => __( 'Email Content', 'invoicing' ),
772
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
771
+                'name' => __('Email Content', 'invoicing'),
772
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
773 773
                 'type' => 'rich_editor',
774
-                'std'  => __( '<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing' ),
774
+                'std'  => __('<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing'),
775 775
                 'class' => 'large',
776 776
                 'size' => '10'
777 777
             ),
@@ -779,46 +779,46 @@  discard block
 block discarded – undo
779 779
         'onhold_invoice' => array(
780 780
             'email_onhold_invoice_header' => array(
781 781
                 'id'   => 'email_onhold_invoice_header',
782
-                'name' => '<h3>' . __( 'On Hold Invoice', 'invoicing' ) . '</h3>',
783
-                'desc' => __( 'This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing' ),
782
+                'name' => '<h3>' . __('On Hold Invoice', 'invoicing') . '</h3>',
783
+                'desc' => __('This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing'),
784 784
                 'type' => 'header',
785 785
             ),
786 786
             'email_onhold_invoice_active' => array(
787 787
                 'id'   => 'email_onhold_invoice_active',
788
-                'name' => __( 'Enable/Disable', 'invoicing' ),
789
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
788
+                'name' => __('Enable/Disable', 'invoicing'),
789
+                'desc' => __('Enable this email notification', 'invoicing'),
790 790
                 'type' => 'checkbox',
791 791
                 'std'  => 1
792 792
             ),
793 793
             'email_onhold_invoice_subject' => array(
794 794
                 'id'   => 'email_onhold_invoice_subject',
795
-                'name' => __( 'Subject', 'invoicing' ),
796
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
795
+                'name' => __('Subject', 'invoicing'),
796
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
797 797
                 'type' => 'text',
798
-                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
798
+                'std'  => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'),
799 799
                 'size' => 'large'
800 800
             ),
801 801
             'email_onhold_invoice_heading' => array(
802 802
                 'id'   => 'email_onhold_invoice_heading',
803
-                'name' => __( 'Email Heading', 'invoicing' ),
804
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
803
+                'name' => __('Email Heading', 'invoicing'),
804
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
805 805
                 'type' => 'text',
806
-                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
806
+                'std'  => __('Thank you for your invoice', 'invoicing'),
807 807
                 'size' => 'large'
808 808
             ),
809 809
             'email_onhold_invoice_admin_bcc' => array(
810 810
                 'id'   => 'email_onhold_invoice_admin_bcc',
811
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
812
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
811
+                'name' => __('Enable Admin BCC', 'invoicing'),
812
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
813 813
                 'type' => 'checkbox',
814 814
                 'std'  => 1
815 815
             ),
816 816
             'email_onhold_invoice_body' => array(
817 817
                 'id'   => 'email_onhold_invoice_body',
818
-                'name' => __( 'Email Content', 'invoicing' ),
819
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
818
+                'name' => __('Email Content', 'invoicing'),
819
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
820 820
                 'type' => 'rich_editor',
821
-                'std'  => __( '<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing' ),
821
+                'std'  => __('<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing'),
822 822
                 'class' => 'large',
823 823
                 'size' => '10'
824 824
             ),
@@ -826,46 +826,46 @@  discard block
 block discarded – undo
826 826
         'processing_invoice' => array(
827 827
             'email_processing_invoice_header' => array(
828 828
                 'id'   => 'email_processing_invoice_header',
829
-                'name' => '<h3>' . __( 'Processing Invoice', 'invoicing' ) . '</h3>',
830
-                'desc' => __( 'This is an invoice notification sent to users containing invoice details after payment.', 'invoicing' ),
829
+                'name' => '<h3>' . __('Processing Invoice', 'invoicing') . '</h3>',
830
+                'desc' => __('This is an invoice notification sent to users containing invoice details after payment.', 'invoicing'),
831 831
                 'type' => 'header',
832 832
             ),
833 833
             'email_processing_invoice_active' => array(
834 834
                 'id'   => 'email_processing_invoice_active',
835
-                'name' => __( 'Enable/Disable', 'invoicing' ),
836
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
835
+                'name' => __('Enable/Disable', 'invoicing'),
836
+                'desc' => __('Enable this email notification', 'invoicing'),
837 837
                 'type' => 'checkbox',
838 838
                 'std'  => 1
839 839
             ),
840 840
             'email_processing_invoice_subject' => array(
841 841
                 'id'   => 'email_processing_invoice_subject',
842
-                'name' => __( 'Subject', 'invoicing' ),
843
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
842
+                'name' => __('Subject', 'invoicing'),
843
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
844 844
                 'type' => 'text',
845
-                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
845
+                'std'  => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'),
846 846
                 'size' => 'large'
847 847
             ),
848 848
             'email_processing_invoice_heading' => array(
849 849
                 'id'   => 'email_processing_invoice_heading',
850
-                'name' => __( 'Email Heading', 'invoicing' ),
851
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
850
+                'name' => __('Email Heading', 'invoicing'),
851
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
852 852
                 'type' => 'text',
853
-                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
853
+                'std'  => __('Thank you for your invoice', 'invoicing'),
854 854
                 'size' => 'large'
855 855
             ),
856 856
             'email_processing_invoice_admin_bcc' => array(
857 857
                 'id'   => 'email_processing_invoice_admin_bcc',
858
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
859
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
858
+                'name' => __('Enable Admin BCC', 'invoicing'),
859
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
860 860
                 'type' => 'checkbox',
861 861
                 'std'  => 1
862 862
             ),
863 863
             'email_processing_invoice_body' => array(
864 864
                 'id'   => 'email_processing_invoice_body',
865
-                'name' => __( 'Email Content', 'invoicing' ),
866
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
865
+                'name' => __('Email Content', 'invoicing'),
866
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
867 867
                 'type' => 'rich_editor',
868
-                'std'  => __( '<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing' ),
868
+                'std'  => __('<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing'),
869 869
                 'class' => 'large',
870 870
                 'size' => '10'
871 871
             ),
@@ -873,52 +873,52 @@  discard block
 block discarded – undo
873 873
         'completed_invoice' => array(
874 874
             'email_completed_invoice_header' => array(
875 875
                 'id'   => 'email_completed_invoice_header',
876
-                'name' => '<h3>' . __( 'Paid Invoice', 'invoicing' ) . '</h3>',
877
-                'desc' => __( 'Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing' ),
876
+                'name' => '<h3>' . __('Paid Invoice', 'invoicing') . '</h3>',
877
+                'desc' => __('Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing'),
878 878
                 'type' => 'header',
879 879
             ),
880 880
             'email_completed_invoice_active' => array(
881 881
                 'id'   => 'email_completed_invoice_active',
882
-                'name' => __( 'Enable/Disable', 'invoicing' ),
883
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
882
+                'name' => __('Enable/Disable', 'invoicing'),
883
+                'desc' => __('Enable this email notification', 'invoicing'),
884 884
                 'type' => 'checkbox',
885 885
                 'std'  => 1
886 886
             ),
887 887
             'email_completed_invoice_renewal_active' => array(
888 888
                 'id'   => 'email_completed_invoice_renewal_active',
889
-                'name' => __( 'Enable renewal notification', 'invoicing' ),
890
-                'desc' => __( 'Enable renewal invoice email notification. This notification will be sent on renewal.', 'invoicing' ),
889
+                'name' => __('Enable renewal notification', 'invoicing'),
890
+                'desc' => __('Enable renewal invoice email notification. This notification will be sent on renewal.', 'invoicing'),
891 891
                 'type' => 'checkbox',
892 892
                 'std'  => 0
893 893
             ),
894 894
             'email_completed_invoice_subject' => array(
895 895
                 'id'   => 'email_completed_invoice_subject',
896
-                'name' => __( 'Subject', 'invoicing' ),
897
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
896
+                'name' => __('Subject', 'invoicing'),
897
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
898 898
                 'type' => 'text',
899
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing' ),
899
+                'std'  => __('[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing'),
900 900
                 'size' => 'large'
901 901
             ),
902 902
             'email_completed_invoice_heading' => array(
903 903
                 'id'   => 'email_completed_invoice_heading',
904
-                'name' => __( 'Email Heading', 'invoicing' ),
905
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
904
+                'name' => __('Email Heading', 'invoicing'),
905
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
906 906
                 'type' => 'text',
907
-                'std'  => __( 'Your invoice has been paid', 'invoicing' ),
907
+                'std'  => __('Your invoice has been paid', 'invoicing'),
908 908
                 'size' => 'large'
909 909
             ),
910 910
             'email_completed_invoice_admin_bcc' => array(
911 911
                 'id'   => 'email_completed_invoice_admin_bcc',
912
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
913
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
912
+                'name' => __('Enable Admin BCC', 'invoicing'),
913
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
914 914
                 'type' => 'checkbox',
915 915
             ),
916 916
             'email_completed_invoice_body' => array(
917 917
                 'id'   => 'email_completed_invoice_body',
918
-                'name' => __( 'Email Content', 'invoicing' ),
919
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
918
+                'name' => __('Email Content', 'invoicing'),
919
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
920 920
                 'type' => 'rich_editor',
921
-                'std'  => __( '<p>Hi {name},</p><p>Your recent invoice on {site_title} has been paid.</p>', 'invoicing' ),
921
+                'std'  => __('<p>Hi {name},</p><p>Your recent invoice on {site_title} has been paid.</p>', 'invoicing'),
922 922
                 'class' => 'large',
923 923
                 'size' => '10'
924 924
             ),
@@ -927,46 +927,46 @@  discard block
 block discarded – undo
927 927
         'refunded_invoice' => array(
928 928
             'email_refunded_invoice_header' => array(
929 929
                 'id'   => 'email_refunded_invoice_header',
930
-                'name' => '<h3>' . __( 'Refunded Invoice', 'invoicing' ) . '</h3>',
931
-                'desc' => __( 'Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing' ),
930
+                'name' => '<h3>' . __('Refunded Invoice', 'invoicing') . '</h3>',
931
+                'desc' => __('Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing'),
932 932
                 'type' => 'header',
933 933
             ),
934 934
             'email_refunded_invoice_active' => array(
935 935
                 'id'   => 'email_refunded_invoice_active',
936
-                'name' => __( 'Enable/Disable', 'invoicing' ),
937
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
936
+                'name' => __('Enable/Disable', 'invoicing'),
937
+                'desc' => __('Enable this email notification', 'invoicing'),
938 938
                 'type' => 'checkbox',
939 939
                 'std'  => 1
940 940
             ),
941 941
             'email_refunded_invoice_subject' => array(
942 942
                 'id'   => 'email_refunded_invoice_subject',
943
-                'name' => __( 'Subject', 'invoicing' ),
944
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
943
+                'name' => __('Subject', 'invoicing'),
944
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
945 945
                 'type' => 'text',
946
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing' ),
946
+                'std'  => __('[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing'),
947 947
                 'size' => 'large'
948 948
             ),
949 949
             'email_refunded_invoice_heading' => array(
950 950
                 'id'   => 'email_refunded_invoice_heading',
951
-                'name' => __( 'Email Heading', 'invoicing' ),
952
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
951
+                'name' => __('Email Heading', 'invoicing'),
952
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
953 953
                 'type' => 'text',
954
-                'std'  => __( 'Your invoice has been refunded', 'invoicing' ),
954
+                'std'  => __('Your invoice has been refunded', 'invoicing'),
955 955
                 'size' => 'large'
956 956
             ),
957 957
             'email_refunded_invoice_admin_bcc' => array(
958 958
                 'id'   => 'email_refunded_invoice_admin_bcc',
959
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
960
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
959
+                'name' => __('Enable Admin BCC', 'invoicing'),
960
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
961 961
                 'type' => 'checkbox',
962 962
                 'std'  => 1
963 963
             ),
964 964
             'email_refunded_invoice_body' => array(
965 965
                 'id'   => 'email_refunded_invoice_body',
966
-                'name' => __( 'Email Content', 'invoicing' ),
967
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
966
+                'name' => __('Email Content', 'invoicing'),
967
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
968 968
                 'type' => 'rich_editor',
969
-                'std'  => __( '<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing' ),
969
+                'std'  => __('<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing'),
970 970
                 'class' => 'large',
971 971
                 'size' => '10'
972 972
             ),
@@ -974,46 +974,46 @@  discard block
 block discarded – undo
974 974
         'user_invoice' => array(
975 975
             'email_user_invoice_header' => array(
976 976
                 'id'   => 'email_user_invoice_header',
977
-                'name' => '<h3>' . __( 'Customer Invoice', 'invoicing' ) . '</h3>',
978
-                'desc' => __( 'Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing' ),
977
+                'name' => '<h3>' . __('Customer Invoice', 'invoicing') . '</h3>',
978
+                'desc' => __('Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing'),
979 979
                 'type' => 'header',
980 980
             ),
981 981
             'email_user_invoice_active' => array(
982 982
                 'id'   => 'email_user_invoice_active',
983
-                'name' => __( 'Enable/Disable', 'invoicing' ),
984
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
983
+                'name' => __('Enable/Disable', 'invoicing'),
984
+                'desc' => __('Enable this email notification', 'invoicing'),
985 985
                 'type' => 'checkbox',
986 986
                 'std'  => 1
987 987
             ),
988 988
             'email_user_invoice_subject' => array(
989 989
                 'id'   => 'email_user_invoice_subject',
990
-                'name' => __( 'Subject', 'invoicing' ),
991
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
990
+                'name' => __('Subject', 'invoicing'),
991
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
992 992
                 'type' => 'text',
993
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date}', 'invoicing' ),
993
+                'std'  => __('[{site_title}] Your invoice from {invoice_date}', 'invoicing'),
994 994
                 'size' => 'large'
995 995
             ),
996 996
             'email_user_invoice_heading' => array(
997 997
                 'id'   => 'email_user_invoice_heading',
998
-                'name' => __( 'Email Heading', 'invoicing' ),
999
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
998
+                'name' => __('Email Heading', 'invoicing'),
999
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
1000 1000
                 'type' => 'text',
1001
-                'std'  => __( 'Your invoice {invoice_number} details', 'invoicing' ),
1001
+                'std'  => __('Your invoice {invoice_number} details', 'invoicing'),
1002 1002
                 'size' => 'large'
1003 1003
             ),
1004 1004
             'email_user_invoice_admin_bcc' => array(
1005 1005
                 'id'   => 'email_user_invoice_admin_bcc',
1006
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
1007
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
1006
+                'name' => __('Enable Admin BCC', 'invoicing'),
1007
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
1008 1008
                 'type' => 'checkbox',
1009 1009
                 'std'  => 1
1010 1010
             ),
1011 1011
             'email_user_invoice_body' => array(
1012 1012
                 'id'   => 'email_user_invoice_body',
1013
-                'name' => __( 'Email Content', 'invoicing' ),
1014
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
1013
+                'name' => __('Email Content', 'invoicing'),
1014
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
1015 1015
                 'type' => 'rich_editor',
1016
-                'std'  => __( '<p>Hi {name},</p><p>An invoice has been created for you on {site_title}. To view / pay for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ),
1016
+                'std'  => __('<p>Hi {name},</p><p>An invoice has been created for you on {site_title}. To view / pay for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing'),
1017 1017
                 'class' => 'large',
1018 1018
                 'size' => '10'
1019 1019
             ),
@@ -1021,39 +1021,39 @@  discard block
 block discarded – undo
1021 1021
         'user_note' => array(
1022 1022
             'email_user_note_header' => array(
1023 1023
                 'id'   => 'email_user_note_header',
1024
-                'name' => '<h3>' . __( 'Customer Note', 'invoicing' ) . '</h3>',
1025
-                'desc' => __( 'Customer note emails are sent when you add a note to an invoice/quote.', 'invoicing' ),
1024
+                'name' => '<h3>' . __('Customer Note', 'invoicing') . '</h3>',
1025
+                'desc' => __('Customer note emails are sent when you add a note to an invoice/quote.', 'invoicing'),
1026 1026
                 'type' => 'header',
1027 1027
             ),
1028 1028
             'email_user_note_active' => array(
1029 1029
                 'id'   => 'email_user_note_active',
1030
-                'name' => __( 'Enable/Disable', 'invoicing' ),
1031
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
1030
+                'name' => __('Enable/Disable', 'invoicing'),
1031
+                'desc' => __('Enable this email notification', 'invoicing'),
1032 1032
                 'type' => 'checkbox',
1033 1033
                 'std'  => 1
1034 1034
             ),
1035 1035
             'email_user_note_subject' => array(
1036 1036
                 'id'   => 'email_user_note_subject',
1037
-                'name' => __( 'Subject', 'invoicing' ),
1038
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
1037
+                'name' => __('Subject', 'invoicing'),
1038
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
1039 1039
                 'type' => 'text',
1040
-                'std'  => __( '[{site_title}] Note added to your {invoice_label} #{invoice_number} from {invoice_date}', 'invoicing' ),
1040
+                'std'  => __('[{site_title}] Note added to your {invoice_label} #{invoice_number} from {invoice_date}', 'invoicing'),
1041 1041
                 'size' => 'large'
1042 1042
             ),
1043 1043
             'email_user_note_heading' => array(
1044 1044
                 'id'   => 'email_user_note_heading',
1045
-                'name' => __( 'Email Heading', 'invoicing' ),
1046
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
1045
+                'name' => __('Email Heading', 'invoicing'),
1046
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
1047 1047
                 'type' => 'text',
1048
-                'std'  => __( 'A note has been added to your {invoice_label}', 'invoicing' ),
1048
+                'std'  => __('A note has been added to your {invoice_label}', 'invoicing'),
1049 1049
                 'size' => 'large'
1050 1050
             ),
1051 1051
             'email_user_note_body' => array(
1052 1052
                 'id'   => 'email_user_note_body',
1053
-                'name' => __( 'Email Content', 'invoicing' ),
1054
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
1053
+                'name' => __('Email Content', 'invoicing'),
1054
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
1055 1055
                 'type' => 'rich_editor',
1056
-                'std'  => __( '<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing' ),
1056
+                'std'  => __('<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing'),
1057 1057
                 'class' => 'large',
1058 1058
                 'size' => '10'
1059 1059
             ),
@@ -1061,158 +1061,158 @@  discard block
 block discarded – undo
1061 1061
         'overdue' => array(
1062 1062
             'email_overdue_header' => array(
1063 1063
                 'id'   => 'email_overdue_header',
1064
-                'name' => '<h3>' . __( 'Payment Reminder', 'invoicing' ) . '</h3>',
1065
-                'desc' => __( 'Payment reminder emails are sent to user automatically.', 'invoicing' ),
1064
+                'name' => '<h3>' . __('Payment Reminder', 'invoicing') . '</h3>',
1065
+                'desc' => __('Payment reminder emails are sent to user automatically.', 'invoicing'),
1066 1066
                 'type' => 'header',
1067 1067
             ),
1068 1068
             'email_overdue_active' => array(
1069 1069
                 'id'   => 'email_overdue_active',
1070
-                'name' => __( 'Enable/Disable', 'invoicing' ),
1071
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
1070
+                'name' => __('Enable/Disable', 'invoicing'),
1071
+                'desc' => __('Enable this email notification', 'invoicing'),
1072 1072
                 'type' => 'checkbox',
1073 1073
                 'std'  => 1
1074 1074
             ),
1075 1075
             'email_due_reminder_days' => array(
1076 1076
                 'id'        => 'email_due_reminder_days',
1077
-                'name'      => __( 'When to Send', 'invoicing' ),
1078
-                'desc'      => __( 'Check when you would like payment reminders sent out.', 'invoicing' ),
1077
+                'name'      => __('When to Send', 'invoicing'),
1078
+                'desc'      => __('Check when you would like payment reminders sent out.', 'invoicing'),
1079 1079
                 'default'   => '',
1080 1080
                 'type'      => 'multicheck',
1081 1081
                 'options'   => $overdue_days_options,
1082 1082
             ),
1083 1083
             'email_overdue_subject' => array(
1084 1084
                 'id'   => 'email_overdue_subject',
1085
-                'name' => __( 'Subject', 'invoicing' ),
1086
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
1085
+                'name' => __('Subject', 'invoicing'),
1086
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
1087 1087
                 'type' => 'text',
1088
-                'std'  => __( '[{site_title}] Payment Reminder', 'invoicing' ),
1088
+                'std'  => __('[{site_title}] Payment Reminder', 'invoicing'),
1089 1089
                 'size' => 'large'
1090 1090
             ),
1091 1091
             'email_overdue_heading' => array(
1092 1092
                 'id'   => 'email_overdue_heading',
1093
-                'name' => __( 'Email Heading', 'invoicing' ),
1094
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
1093
+                'name' => __('Email Heading', 'invoicing'),
1094
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
1095 1095
                 'type' => 'text',
1096
-                'std'  => __( 'Payment reminder for your invoice', 'invoicing' ),
1096
+                'std'  => __('Payment reminder for your invoice', 'invoicing'),
1097 1097
                 'size' => 'large'
1098 1098
             ),
1099 1099
             'email_overdue_body' => array(
1100 1100
                 'id'   => 'email_overdue_body',
1101
-                'name' => __( 'Email Content', 'invoicing' ),
1102
-                'desc' => __( 'The content of the email.', 'invoicing' ),
1101
+                'name' => __('Email Content', 'invoicing'),
1102
+                'desc' => __('The content of the email.', 'invoicing'),
1103 1103
                 'type' => 'rich_editor',
1104
-                'std'  => __( '<p>Hi {full_name},</p><p>This is just a friendly reminder that 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 view / pay now for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ),
1104
+                'std'  => __('<p>Hi {full_name},</p><p>This is just a friendly reminder that 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 view / pay now for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing'),
1105 1105
                 'class' => 'large',
1106 1106
                 'size'  => 10,
1107 1107
             ),
1108 1108
         ),
1109 1109
     );
1110 1110
 
1111
-    return apply_filters( 'wpinv_get_emails', $emails );
1111
+    return apply_filters('wpinv_get_emails', $emails);
1112 1112
 }
1113 1113
 
1114
-function wpinv_settings_emails( $settings = array() ) {
1114
+function wpinv_settings_emails($settings = array()) {
1115 1115
     $emails = wpinv_get_emails();
1116 1116
 
1117
-    if ( !empty( $emails ) ) {
1118
-        foreach ( $emails as $key => $email ) {
1117
+    if (!empty($emails)) {
1118
+        foreach ($emails as $key => $email) {
1119 1119
             $settings[$key] = $email;
1120 1120
         }
1121 1121
     }
1122 1122
 
1123
-    return apply_filters( 'wpinv_settings_get_emails', $settings );
1123
+    return apply_filters('wpinv_settings_get_emails', $settings);
1124 1124
 }
1125
-add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 );
1125
+add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1);
1126 1126
 
1127
-function wpinv_settings_sections_emails( $settings ) {
1127
+function wpinv_settings_sections_emails($settings) {
1128 1128
     $emails = wpinv_get_emails();
1129 1129
 
1130 1130
     if (!empty($emails)) {
1131
-        foreach  ($emails as $key => $email) {
1132
-            $settings[$key] = !empty( $email['email_' . $key . '_header']['name'] ) ? strip_tags( $email['email_' . $key . '_header']['name'] ) : $key;
1131
+        foreach ($emails as $key => $email) {
1132
+            $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : $key;
1133 1133
         }
1134 1134
     }
1135 1135
 
1136 1136
     return $settings;    
1137 1137
 }
1138
-add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 );
1138
+add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1);
1139 1139
 
1140
-function wpinv_email_is_enabled( $email_type ) {
1140
+function wpinv_email_is_enabled($email_type) {
1141 1141
     $emails = wpinv_get_emails();
1142
-    $enabled = isset( $emails[$email_type] ) && wpinv_get_option( 'email_'. $email_type . '_active', 0 ) ? true : false;
1142
+    $enabled = isset($emails[$email_type]) && wpinv_get_option('email_' . $email_type . '_active', 0) ? true : false;
1143 1143
 
1144
-    return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type );
1144
+    return apply_filters('wpinv_email_is_enabled', $enabled, $email_type);
1145 1145
 }
1146 1146
 
1147
-function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1148
-    switch ( $email_type ) {
1147
+function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) {
1148
+    switch ($email_type) {
1149 1149
         case 'new_invoice':
1150 1150
         case 'cancelled_invoice':
1151 1151
         case 'failed_invoice':
1152 1152
             $recipient  = wpinv_get_admin_email();
1153 1153
         break;
1154 1154
         default:
1155
-            $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1156
-            $recipient  = !empty( $invoice ) ? $invoice->get_email() : '';
1155
+            $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
1156
+            $recipient  = !empty($invoice) ? $invoice->get_email() : '';
1157 1157
         break;
1158 1158
     }
1159 1159
 
1160
-    return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice );
1160
+    return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice);
1161 1161
 }
1162 1162
 
1163
-function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1164
-    $subject    = wpinv_get_option( 'email_' . $email_type . '_subject' );
1165
-    $subject    = __( $subject, 'invoicing' );
1163
+function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) {
1164
+    $subject    = wpinv_get_option('email_' . $email_type . '_subject');
1165
+    $subject    = __($subject, 'invoicing');
1166 1166
 
1167
-    $subject    = wpinv_email_format_text( $subject, $invoice );
1167
+    $subject    = wpinv_email_format_text($subject, $invoice);
1168 1168
 
1169
-    return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice );
1169
+    return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice);
1170 1170
 }
1171 1171
 
1172
-function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1173
-    $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' );
1174
-    $email_heading = __( $email_heading, 'invoicing' );
1172
+function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) {
1173
+    $email_heading = wpinv_get_option('email_' . $email_type . '_heading');
1174
+    $email_heading = __($email_heading, 'invoicing');
1175 1175
 
1176
-    $email_heading = wpinv_email_format_text( $email_heading, $invoice );
1176
+    $email_heading = wpinv_email_format_text($email_heading, $invoice);
1177 1177
 
1178
-    return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice );
1178
+    return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice);
1179 1179
 }
1180 1180
 
1181
-function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1182
-    $content    = wpinv_get_option( 'email_' . $email_type . '_body' );
1183
-    $content    = __( $content, 'invoicing' );
1181
+function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) {
1182
+    $content    = wpinv_get_option('email_' . $email_type . '_body');
1183
+    $content    = __($content, 'invoicing');
1184 1184
 
1185
-    $content    = wpinv_email_format_text( $content, $invoice );
1185
+    $content    = wpinv_email_format_text($content, $invoice);
1186 1186
 
1187
-    return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice );
1187
+    return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice);
1188 1188
 }
1189 1189
 
1190
-function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1190
+function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) {
1191 1191
     $from_name = wpinv_mail_get_from_address();
1192 1192
     $from_email = wpinv_mail_get_from_address();
1193 1193
     
1194
-    $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1194
+    $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
1195 1195
     
1196
-    $headers    = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n";
1197
-    $headers    .= "Reply-To: ". $from_email . "\r\n";
1196
+    $headers    = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n";
1197
+    $headers    .= "Reply-To: " . $from_email . "\r\n";
1198 1198
     $headers    .= "Content-Type: " . wpinv_mail_get_content_type() . "\r\n";
1199 1199
     
1200
-    return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice );
1200
+    return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice);
1201 1201
 }
1202 1202
 
1203
-function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1203
+function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) {
1204 1204
     $attachments = array();
1205 1205
     
1206
-    return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice );
1206
+    return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice);
1207 1207
 }
1208 1208
 
1209
-function wpinv_email_format_text( $content, $invoice ) {
1209
+function wpinv_email_format_text($content, $invoice) {
1210 1210
     $replace_array = array(
1211 1211
         '{site_title}'      => wpinv_get_blogname(),
1212
-        '{date}'            => date_i18n( get_option( 'date_format' ), (int) current_time( 'timestamp' ) ),
1212
+        '{date}'            => date_i18n(get_option('date_format'), (int) current_time('timestamp')),
1213 1213
     );
1214 1214
     
1215
-    if ( !empty( $invoice->ID ) ) {
1215
+    if (!empty($invoice->ID)) {
1216 1216
         $replace_array = array_merge(
1217 1217
             $replace_array, 
1218 1218
             array(
@@ -1222,65 +1222,65 @@  discard block
 block discarded – undo
1222 1222
                 '{last_name}'       => $invoice->get_last_name(),
1223 1223
                 '{email}'           => $invoice->get_email(),
1224 1224
                 '{invoice_number}'  => $invoice->get_number(),
1225
-                '{invoice_total}'   => $invoice->get_total( true ),
1226
-                '{invoice_link}'    => $invoice->get_view_url( true ),
1227
-                '{invoice_pay_link}'=> $invoice->get_view_url( true ),
1228
-                '{invoice_date}'    => $invoice->get_invoice_date( true ),
1229
-                '{invoice_due_date}'=> $invoice->get_due_date( true ),
1230
-                '{invoice_quote}'   => $invoice->get_invoice_quote_type( $invoice->ID ),
1231
-                '{invoice_label}'   => $invoice->get_invoice_quote_type( $invoice->ID ),
1232
-                '{is_was}'          => strtotime( $invoice->get_due_date() ) < strtotime( date_i18n( 'Y-m-d' ) ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
1225
+                '{invoice_total}'   => $invoice->get_total(true),
1226
+                '{invoice_link}'    => $invoice->get_view_url(true),
1227
+                '{invoice_pay_link}'=> $invoice->get_view_url(true),
1228
+                '{invoice_date}'    => $invoice->get_invoice_date(true),
1229
+                '{invoice_due_date}'=> $invoice->get_due_date(true),
1230
+                '{invoice_quote}'   => $invoice->get_invoice_quote_type($invoice->ID),
1231
+                '{invoice_label}'   => $invoice->get_invoice_quote_type($invoice->ID),
1232
+                '{is_was}'          => strtotime($invoice->get_due_date()) < strtotime(date_i18n('Y-m-d')) ? __('was', 'invoicing') : __('is', 'invoicing'),
1233 1233
             )
1234 1234
         );
1235 1235
     }
1236 1236
 
1237
-    $replace_array = apply_filters( 'wpinv_email_format_text', $replace_array, $content, $invoice );
1237
+    $replace_array = apply_filters('wpinv_email_format_text', $replace_array, $content, $invoice);
1238 1238
 
1239
-    foreach ( $replace_array as $key => $value ) {
1240
-        $content = str_replace( $key, $value, $content );
1239
+    foreach ($replace_array as $key => $value) {
1240
+        $content = str_replace($key, $value, $content);
1241 1241
     }
1242 1242
 
1243
-    return apply_filters( 'wpinv_email_content_replace', $content );
1243
+    return apply_filters('wpinv_email_content_replace', $content);
1244 1244
 }
1245 1245
 
1246
-function wpinv_email_style_body( $content ) {
1246
+function wpinv_email_style_body($content) {
1247 1247
     // make sure we only inline CSS for html emails
1248
-    if ( in_array( wpinv_mail_get_content_type(), array( 'text/html', 'multipart/alternative' ) ) && class_exists( 'DOMDocument' ) ) {
1248
+    if (in_array(wpinv_mail_get_content_type(), array('text/html', 'multipart/alternative')) && class_exists('DOMDocument')) {
1249 1249
         ob_start();
1250
-        wpinv_get_template( 'emails/wpinv-email-styles.php' );
1251
-        $css = apply_filters( 'wpinv_email_styles', ob_get_clean() );
1250
+        wpinv_get_template('emails/wpinv-email-styles.php');
1251
+        $css = apply_filters('wpinv_email_styles', ob_get_clean());
1252 1252
 
1253 1253
         // apply CSS styles inline for picky email clients
1254 1254
         try {
1255
-            $emogrifier = new Emogrifier( $content, $css );
1255
+            $emogrifier = new Emogrifier($content, $css);
1256 1256
             $content    = $emogrifier->emogrify();
1257
-        } catch ( Exception $e ) {
1258
-            wpinv_error_log( $e->getMessage(), 'emogrifier' );
1257
+        } catch (Exception $e) {
1258
+            wpinv_error_log($e->getMessage(), 'emogrifier');
1259 1259
         }
1260 1260
     }
1261 1261
     return $content;
1262 1262
 }
1263 1263
 
1264
-function wpinv_email_header( $email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1265
-    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 ) );
1264
+function wpinv_email_header($email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false) {
1265
+    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));
1266 1266
 }
1267 1267
 
1268 1268
 /**
1269 1269
  * Get the email footer.
1270 1270
  */
1271
-function wpinv_email_footer( $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1272
-    wpinv_get_template( 'emails/wpinv-email-footer.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1271
+function wpinv_email_footer($invoice = array(), $email_type = '', $sent_to_admin = false) {
1272
+    wpinv_get_template('emails/wpinv-email-footer.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1273 1273
 }
1274 1274
 
1275
-function wpinv_email_wrap_message( $message ) {
1275
+function wpinv_email_wrap_message($message) {
1276 1276
     // Buffer
1277 1277
     ob_start();
1278 1278
 
1279
-    do_action( 'wpinv_email_header' );
1279
+    do_action('wpinv_email_header');
1280 1280
 
1281
-    echo wpautop( wptexturize( $message ) );
1281
+    echo wpautop(wptexturize($message));
1282 1282
 
1283
-    do_action( 'wpinv_email_footer' );
1283
+    do_action('wpinv_email_footer');
1284 1284
 
1285 1285
     // Get contents
1286 1286
     $message = ob_get_clean();
@@ -1288,92 +1288,92 @@  discard block
 block discarded – undo
1288 1288
     return $message;
1289 1289
 }
1290 1290
 
1291
-function wpinv_email_invoice_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1292
-    wpinv_get_template( 'emails/wpinv-email-invoice-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1291
+function wpinv_email_invoice_details($invoice, $email_type = '', $sent_to_admin = false) {
1292
+    wpinv_get_template('emails/wpinv-email-invoice-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1293 1293
 }
1294 1294
 
1295
-function wpinv_email_invoice_items( $invoice, $email_type = '', $sent_to_admin = false ) {
1296
-    wpinv_get_template( 'emails/wpinv-email-invoice-items.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1295
+function wpinv_email_invoice_items($invoice, $email_type = '', $sent_to_admin = false) {
1296
+    wpinv_get_template('emails/wpinv-email-invoice-items.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1297 1297
 }
1298 1298
 
1299
-function wpinv_email_billing_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1300
-    wpinv_get_template( 'emails/wpinv-email-billing-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1299
+function wpinv_email_billing_details($invoice, $email_type = '', $sent_to_admin = false) {
1300
+    wpinv_get_template('emails/wpinv-email-billing-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1301 1301
 }
1302 1302
 
1303
-function wpinv_send_customer_invoice( $data = array() ) {
1304
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1303
+function wpinv_send_customer_invoice($data = array()) {
1304
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1305 1305
 
1306
-    if ( empty( $invoice_id ) ) {
1306
+    if (empty($invoice_id)) {
1307 1307
         return;
1308 1308
     }
1309 1309
 
1310
-    if ( !wpinv_current_user_can_manage_invoicing() ) {
1311
-        wp_die( __( 'You do not have permission to send invoice notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1310
+    if (!wpinv_current_user_can_manage_invoicing()) {
1311
+        wp_die(__('You do not have permission to send invoice notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
1312 1312
     }
1313 1313
     
1314
-    $sent = wpinv_user_invoice_notification( $invoice_id );
1314
+    $sent = wpinv_user_invoice_notification($invoice_id);
1315 1315
 
1316 1316
     if ( -1 === $sent ) {
1317 1317
         $status = 'email_disabled';
1318
-    } elseif ( $sent ) {
1318
+    } elseif ($sent) {
1319 1319
         $status = 'email_sent';
1320 1320
     } else {
1321 1321
         $status = 'email_fail';
1322 1322
     }
1323 1323
 
1324
-    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1325
-    wp_redirect( $redirect );
1324
+    $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false));
1325
+    wp_redirect($redirect);
1326 1326
     exit;
1327 1327
 }
1328
-add_action( 'wpinv_send_invoice', 'wpinv_send_customer_invoice' );
1328
+add_action('wpinv_send_invoice', 'wpinv_send_customer_invoice');
1329 1329
 
1330
-function wpinv_send_overdue_reminder( $data = array() ) {
1331
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1330
+function wpinv_send_overdue_reminder($data = array()) {
1331
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1332 1332
 
1333
-    if ( empty( $invoice_id ) ) {
1333
+    if (empty($invoice_id)) {
1334 1334
         return;
1335 1335
     }
1336 1336
 
1337
-    if ( !wpinv_current_user_can_manage_invoicing() ) {
1338
-        wp_die( __( 'You do not have permission to send reminder notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1337
+    if (!wpinv_current_user_can_manage_invoicing()) {
1338
+        wp_die(__('You do not have permission to send reminder notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
1339 1339
     }
1340 1340
 
1341
-    $sent = wpinv_send_payment_reminder_notification( $invoice_id );
1341
+    $sent = wpinv_send_payment_reminder_notification($invoice_id);
1342 1342
     
1343 1343
     $status = $sent ? 'email_sent' : 'email_fail';
1344 1344
 
1345
-    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1346
-    wp_redirect( $redirect );
1345
+    $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false));
1346
+    wp_redirect($redirect);
1347 1347
     exit;
1348 1348
 }
1349
-add_action( 'wpinv_send_reminder', 'wpinv_send_overdue_reminder' );
1349
+add_action('wpinv_send_reminder', 'wpinv_send_overdue_reminder');
1350 1350
 
1351
-function wpinv_send_customer_note_email( $data ) {
1352
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1351
+function wpinv_send_customer_note_email($data) {
1352
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1353 1353
 
1354
-    if ( empty( $invoice_id ) ) {
1354
+    if (empty($invoice_id)) {
1355 1355
         return;
1356 1356
     }
1357 1357
 
1358
-    $sent = wpinv_user_note_notification( $invoice_id, $data );
1358
+    $sent = wpinv_user_note_notification($invoice_id, $data);
1359 1359
 }
1360
-add_action( 'wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1 );
1360
+add_action('wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1);
1361 1361
 
1362
-function wpinv_add_notes_to_invoice_email( $invoice, $email_type, $sent_to_admin ) {
1363
-    if ( !empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->ID, true ) ) {
1364
-        $date_format = get_option( 'date_format' );
1365
-        $time_format = get_option( 'time_format' );
1362
+function wpinv_add_notes_to_invoice_email($invoice, $email_type, $sent_to_admin) {
1363
+    if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->ID, true)) {
1364
+        $date_format = get_option('date_format');
1365
+        $time_format = get_option('time_format');
1366 1366
         ?>
1367 1367
         <div id="wpinv-email-notes">
1368
-            <h3 class="wpinv-notes-t"><?php echo apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ); ?></h3>
1368
+            <h3 class="wpinv-notes-t"><?php echo apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing')); ?></h3>
1369 1369
             <ol class="wpinv-notes-lists">
1370 1370
         <?php
1371
-        foreach ( $invoice_notes as $note ) {
1372
-            $note_time = strtotime( $note->comment_date );
1371
+        foreach ($invoice_notes as $note) {
1372
+            $note_time = strtotime($note->comment_date);
1373 1373
             ?>
1374 1374
             <li class="comment wpinv-note">
1375
-            <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>
1376
-            <div class="wpinv-note-desc description"><?php echo wpautop( wptexturize( $note->comment_content ) ); ?></div>
1375
+            <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>
1376
+            <div class="wpinv-note-desc description"><?php echo wpautop(wptexturize($note->comment_content)); ?></div>
1377 1377
             </li>
1378 1378
             <?php
1379 1379
         }
@@ -1382,21 +1382,21 @@  discard block
 block discarded – undo
1382 1382
         <?php
1383 1383
     }
1384 1384
 }
1385
-add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 );
1385
+add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3);
1386 1386
 
1387 1387
 function wpinv_email_payment_reminders() {
1388 1388
     global $wpi_auto_reminder;
1389
-    if ( !wpinv_get_option( 'email_overdue_active' ) ) {
1389
+    if (!wpinv_get_option('email_overdue_active')) {
1390 1390
         return;
1391 1391
     }
1392 1392
 
1393
-    if ( $reminder_days = wpinv_get_option( 'email_due_reminder_days' ) ) {
1394
-        $reminder_days  = is_array( $reminder_days ) ? array_values( $reminder_days ) : '';
1393
+    if ($reminder_days = wpinv_get_option('email_due_reminder_days')) {
1394
+        $reminder_days  = is_array($reminder_days) ? array_values($reminder_days) : '';
1395 1395
 
1396
-        if ( empty( $reminder_days ) ) {
1396
+        if (empty($reminder_days)) {
1397 1397
             return;
1398 1398
         }
1399
-        $reminder_days  = array_unique( array_map( 'absint', $reminder_days ) );
1399
+        $reminder_days = array_unique(array_map('absint', $reminder_days));
1400 1400
 
1401 1401
         $args = array(
1402 1402
             'post_type'     => 'wpi_invoice',
@@ -1406,7 +1406,7 @@  discard block
 block discarded – undo
1406 1406
             'meta_query'    => array(
1407 1407
                 array(
1408 1408
                     'key'       =>  '_wpinv_due_date',
1409
-                    'value'     =>  array( '', 'none' ),
1409
+                    'value'     =>  array('', 'none'),
1410 1410
                     'compare'   =>  'NOT IN',
1411 1411
                 )
1412 1412
             ),
@@ -1415,143 +1415,143 @@  discard block
 block discarded – undo
1415 1415
             'order'         => 'ASC',
1416 1416
         );
1417 1417
 
1418
-        $invoices = get_posts( $args );
1418
+        $invoices = get_posts($args);
1419 1419
 
1420
-        if ( empty( $invoices ) ) {
1420
+        if (empty($invoices)) {
1421 1421
             return;
1422 1422
         }
1423 1423
 
1424
-        $date_to_send   = array();
1424
+        $date_to_send = array();
1425 1425
 
1426
-        foreach ( $invoices as $id ) {
1427
-            $due_date = get_post_meta( $id, '_wpinv_due_date', true );
1426
+        foreach ($invoices as $id) {
1427
+            $due_date = get_post_meta($id, '_wpinv_due_date', true);
1428 1428
 
1429
-            foreach ( $reminder_days as $key => $days ) {
1430
-                if ( $days !== '' ) {
1431
-                    $date_to_send[$id][] = date_i18n( 'Y-m-d', strtotime( $due_date ) + ( $days * DAY_IN_SECONDS ) );
1429
+            foreach ($reminder_days as $key => $days) {
1430
+                if ($days !== '') {
1431
+                    $date_to_send[$id][] = date_i18n('Y-m-d', strtotime($due_date) + ($days * DAY_IN_SECONDS));
1432 1432
                 }
1433 1433
             }
1434 1434
         }
1435 1435
 
1436
-        $today              = date_i18n( 'Y-m-d' );
1436
+        $today              = date_i18n('Y-m-d');
1437 1437
         $wpi_auto_reminder  = true;
1438 1438
 
1439
-        foreach ( $date_to_send as $id => $values ) {
1440
-            if ( in_array( $today, $values ) ) {
1441
-                $sent = get_post_meta( $id, '_wpinv_reminder_sent', true );
1439
+        foreach ($date_to_send as $id => $values) {
1440
+            if (in_array($today, $values)) {
1441
+                $sent = get_post_meta($id, '_wpinv_reminder_sent', true);
1442 1442
 
1443
-                if ( isset( $sent ) && !empty( $sent ) ) {
1444
-                    if ( !in_array( $today, $sent ) ) {
1445
-                        do_action( 'wpinv_send_payment_reminder_notification', $id );
1443
+                if (isset($sent) && !empty($sent)) {
1444
+                    if (!in_array($today, $sent)) {
1445
+                        do_action('wpinv_send_payment_reminder_notification', $id);
1446 1446
                     }
1447 1447
                 } else {
1448
-                    do_action( 'wpinv_send_payment_reminder_notification', $id );
1448
+                    do_action('wpinv_send_payment_reminder_notification', $id);
1449 1449
                 }
1450 1450
             }
1451 1451
         }
1452 1452
 
1453
-        $wpi_auto_reminder  = false;
1453
+        $wpi_auto_reminder = false;
1454 1454
     }
1455 1455
 }
1456 1456
 
1457
-function wpinv_send_payment_reminder_notification( $invoice_id ) {
1457
+function wpinv_send_payment_reminder_notification($invoice_id) {
1458 1458
     $email_type = 'overdue';
1459
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
1459
+    if (!wpinv_email_is_enabled($email_type)) {
1460 1460
         return false;
1461 1461
     }
1462 1462
 
1463
-    $invoice    = wpinv_get_invoice( $invoice_id );
1464
-    if ( empty( $invoice ) ) {
1463
+    $invoice = wpinv_get_invoice($invoice_id);
1464
+    if (empty($invoice)) {
1465 1465
         return false;
1466 1466
     }
1467 1467
 
1468
-    if ( !$invoice->needs_payment() ) {
1468
+    if (!$invoice->needs_payment()) {
1469 1469
         return false;
1470 1470
     }
1471 1471
 
1472
-    $recipient  = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
1473
-    if ( !is_email( $recipient ) ) {
1472
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
1473
+    if (!is_email($recipient)) {
1474 1474
         return false;
1475 1475
     }
1476 1476
 
1477
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
1477
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
1478 1478
 
1479
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
1480
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
1481
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
1482
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
1483
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
1479
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
1480
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
1481
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
1482
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
1483
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
1484 1484
 
1485
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
1485
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
1486 1486
             'invoice'       => $invoice,
1487 1487
             'email_type'    => $email_type,
1488 1488
             'email_heading' => $email_heading,
1489 1489
             'sent_to_admin' => false,
1490 1490
             'plain_text'    => false,
1491 1491
             'message_body'  => $message_body
1492
-        ) );
1492
+        ));
1493 1493
 
1494
-    $content        = wpinv_email_format_text( $content, $invoice );
1494
+    $content = wpinv_email_format_text($content, $invoice);
1495 1495
 
1496
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
1497
-    if ( $sent ) {
1498
-        do_action( 'wpinv_payment_reminder_sent', $invoice_id, $invoice );
1496
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
1497
+    if ($sent) {
1498
+        do_action('wpinv_payment_reminder_sent', $invoice_id, $invoice);
1499 1499
     }
1500 1500
 
1501
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
1501
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
1502 1502
 
1503 1503
     return $sent;
1504 1504
 }
1505
-add_action( 'wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1 );
1505
+add_action('wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1);
1506 1506
 
1507
-function wpinv_payment_reminder_sent( $invoice_id, $invoice ) {
1507
+function wpinv_payment_reminder_sent($invoice_id, $invoice) {
1508 1508
     global $wpi_auto_reminder;
1509 1509
 
1510
-    $sent = get_post_meta( $invoice_id, '_wpinv_reminder_sent', true );
1510
+    $sent = get_post_meta($invoice_id, '_wpinv_reminder_sent', true);
1511 1511
 
1512
-    if ( empty( $sent ) ) {
1512
+    if (empty($sent)) {
1513 1513
         $sent = array();
1514 1514
     }
1515
-    $sent[] = date_i18n( 'Y-m-d' );
1515
+    $sent[] = date_i18n('Y-m-d');
1516 1516
 
1517
-    update_post_meta( $invoice_id, '_wpinv_reminder_sent', $sent );
1517
+    update_post_meta($invoice_id, '_wpinv_reminder_sent', $sent);
1518 1518
 
1519
-    if ( $wpi_auto_reminder ) { // Auto reminder note.
1520
-        $note = __( 'Automated reminder sent to the user.', 'invoicing' );
1521
-        $invoice->add_note( $note, false, false, true );
1519
+    if ($wpi_auto_reminder) { // Auto reminder note.
1520
+        $note = __('Automated reminder sent to the user.', 'invoicing');
1521
+        $invoice->add_note($note, false, false, true);
1522 1522
     } else { // Menual reminder note.
1523
-        $note = __( 'Manual reminder sent to the user.', 'invoicing' );
1524
-        $invoice->add_note( $note );
1523
+        $note = __('Manual reminder sent to the user.', 'invoicing');
1524
+        $invoice->add_note($note);
1525 1525
     }
1526 1526
 }
1527
-add_action( 'wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2 );
1527
+add_action('wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2);
1528 1528
 
1529
-function wpinv_invoice_notification_set_locale( $invoice, $email_type, $site = false ) {
1530
-    if ( empty( $invoice ) ) {
1529
+function wpinv_invoice_notification_set_locale($invoice, $email_type, $site = false) {
1530
+    if (empty($invoice)) {
1531 1531
         return;
1532 1532
     }
1533 1533
 
1534
-    if ( is_int( $invoice ) ) {
1535
-        $invoice = wpinv_get_invoice( $invoice );
1534
+    if (is_int($invoice)) {
1535
+        $invoice = wpinv_get_invoice($invoice);
1536 1536
     }
1537 1537
 
1538
-    if ( ! empty( $invoice ) && is_object( $invoice ) ) {
1539
-        if ( ! $site && function_exists( 'get_user_locale' ) ) {
1540
-            $locale = get_user_locale( $invoice->get_user_id() );
1538
+    if (!empty($invoice) && is_object($invoice)) {
1539
+        if (!$site && function_exists('get_user_locale')) {
1540
+            $locale = get_user_locale($invoice->get_user_id());
1541 1541
         } else {
1542 1542
             $locale = get_locale();
1543 1543
         }
1544 1544
 
1545
-        wpinv_switch_to_locale( $locale );
1545
+        wpinv_switch_to_locale($locale);
1546 1546
     }
1547 1547
 }
1548
-add_action( 'wpinv_pre_send_invoice_notification', 'wpinv_invoice_notification_set_locale', 10, 3 );
1548
+add_action('wpinv_pre_send_invoice_notification', 'wpinv_invoice_notification_set_locale', 10, 3);
1549 1549
 
1550
-function wpinv_invoice_notification_restore_locale( $invoice, $email_type, $site = false ) {
1551
-    if ( empty( $invoice ) ) {
1550
+function wpinv_invoice_notification_restore_locale($invoice, $email_type, $site = false) {
1551
+    if (empty($invoice)) {
1552 1552
         return;
1553 1553
     }
1554 1554
 
1555 1555
     wpinv_restore_locale();
1556 1556
 }
1557
-add_action( 'wpinv_post_send_invoice_notification', 'wpinv_invoice_notification_restore_locale', 10, 3 );
1557
+add_action('wpinv_post_send_invoice_notification', 'wpinv_invoice_notification_restore_locale', 10, 3);
Please login to merge, or discard this patch.
includes/wpinv-helper-functions.php 1 patch
Spacing   +392 added lines, -392 removed lines patch added patch discarded remove patch
@@ -7,132 +7,132 @@  discard block
 block discarded – undo
7 7
  */
8 8
 
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_item_quantities_enabled() {
15
-    $ret = wpinv_get_option( 'item_quantities', true );
15
+    $ret = wpinv_get_option('item_quantities', true);
16 16
 
17
-    return (bool) apply_filters( 'wpinv_item_quantities_enabled', $ret );
17
+    return (bool) apply_filters('wpinv_item_quantities_enabled', $ret);
18 18
 }
19 19
 
20 20
 function wpinv_get_ip() {
21 21
     $ip = '127.0.0.1';
22 22
 
23
-    if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
24
-        $ip = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] );
25
-    } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
26
-        $ip = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] );
27
-    } elseif( !empty( $_SERVER['REMOTE_ADDR'] ) ) {
28
-        $ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] );
23
+    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
24
+        $ip = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']);
25
+    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
26
+        $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']);
27
+    } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
28
+        $ip = sanitize_text_field($_SERVER['REMOTE_ADDR']);
29 29
     }
30 30
 
31
-    return apply_filters( 'wpinv_get_ip', $ip );
31
+    return apply_filters('wpinv_get_ip', $ip);
32 32
 }
33 33
 
34 34
 function wpinv_get_user_agent() {
35
-    if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
36
-        $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
35
+    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
36
+        $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
37 37
     } else {
38 38
         $user_agent = '';
39 39
     }
40 40
 
41
-    return apply_filters( 'wpinv_get_user_agent', $user_agent );
41
+    return apply_filters('wpinv_get_user_agent', $user_agent);
42 42
 }
43 43
 
44
-function wpinv_sanitize_amount( $amount, $decimals = NULL ) {
44
+function wpinv_sanitize_amount($amount, $decimals = NULL) {
45 45
     $is_negative   = false;
46 46
     $thousands_sep = wpinv_thousands_separator();
47 47
     $decimal_sep   = wpinv_decimal_separator();
48
-    if ( $decimals === NULL ) {
48
+    if ($decimals === NULL) {
49 49
         $decimals = wpinv_decimals();
50 50
     }
51 51
 
52 52
     // Sanitize the amount
53
-    if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) {
54
-        if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
55
-            $amount = str_replace( $thousands_sep, '', $amount );
56
-        } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) {
57
-            $amount = str_replace( '.', '', $amount );
53
+    if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) {
54
+        if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) {
55
+            $amount = str_replace($thousands_sep, '', $amount);
56
+        } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) {
57
+            $amount = str_replace('.', '', $amount);
58 58
         }
59 59
 
60
-        $amount = str_replace( $decimal_sep, '.', $amount );
61
-    } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
62
-        $amount = str_replace( $thousands_sep, '', $amount );
60
+        $amount = str_replace($decimal_sep, '.', $amount);
61
+    } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
62
+        $amount = str_replace($thousands_sep, '', $amount);
63 63
     }
64 64
 
65
-    if( $amount < 0 ) {
65
+    if ($amount < 0) {
66 66
         $is_negative = true;
67 67
     }
68 68
 
69
-    $amount   = preg_replace( '/[^0-9\.]/', '', $amount );
69
+    $amount   = preg_replace('/[^0-9\.]/', '', $amount);
70 70
 
71
-    $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', absint( $decimals ), $amount );
72
-    $amount   = number_format( (double) $amount, absint( $decimals ), '.', '' );
71
+    $decimals = apply_filters('wpinv_sanitize_amount_decimals', absint($decimals), $amount);
72
+    $amount   = number_format((double) $amount, absint($decimals), '.', '');
73 73
 
74
-    if( $is_negative ) {
74
+    if ($is_negative) {
75 75
         $amount *= -1;
76 76
     }
77 77
 
78
-    return apply_filters( 'wpinv_sanitize_amount', $amount, $decimals );
78
+    return apply_filters('wpinv_sanitize_amount', $amount, $decimals);
79 79
 }
80
-add_filter( 'wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
80
+add_filter('wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1);
81 81
 
82
-function wpinv_round_amount( $amount, $decimals = NULL ) {
83
-    if ( $decimals === NULL ) {
82
+function wpinv_round_amount($amount, $decimals = NULL) {
83
+    if ($decimals === NULL) {
84 84
         $decimals = wpinv_decimals();
85 85
     }
86 86
     
87
-    $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) );
87
+    $amount = round((double) $amount, wpinv_currency_decimal_filter(absint($decimals)));
88 88
 
89
-    return apply_filters( 'wpinv_round_amount', $amount, $decimals );
89
+    return apply_filters('wpinv_round_amount', $amount, $decimals);
90 90
 }
91 91
 
92
-function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) {
92
+function wpinv_get_invoice_statuses($draft = false, $trashed = false, $invoice = false) {
93 93
     global $post;
94 94
 
95 95
     $invoice_statuses = array(
96
-        'wpi-pending' => __( 'Pending Payment', 'invoicing' ),
97
-        'publish' => __( 'Paid', 'invoicing'),
98
-        'wpi-processing' => __( 'Processing', 'invoicing' ),
99
-        'wpi-onhold' => __( 'On Hold', 'invoicing' ),
100
-        'wpi-refunded' => __( 'Refunded', 'invoicing' ),
101
-        'wpi-cancelled' => __( 'Cancelled', 'invoicing' ),
102
-        'wpi-failed' => __( 'Failed', 'invoicing' ),
103
-        'wpi-renewal' => __( 'Renewal Payment', 'invoicing' )
96
+        'wpi-pending' => __('Pending Payment', 'invoicing'),
97
+        'publish' => __('Paid', 'invoicing'),
98
+        'wpi-processing' => __('Processing', 'invoicing'),
99
+        'wpi-onhold' => __('On Hold', 'invoicing'),
100
+        'wpi-refunded' => __('Refunded', 'invoicing'),
101
+        'wpi-cancelled' => __('Cancelled', 'invoicing'),
102
+        'wpi-failed' => __('Failed', 'invoicing'),
103
+        'wpi-renewal' => __('Renewal Payment', 'invoicing')
104 104
     );
105 105
 
106
-    if ( $draft ) {
107
-        $invoice_statuses['draft'] = __( 'Draft', 'invoicing' );
106
+    if ($draft) {
107
+        $invoice_statuses['draft'] = __('Draft', 'invoicing');
108 108
     }
109 109
 
110
-    if ( $trashed ) {
111
-        $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
110
+    if ($trashed) {
111
+        $invoice_statuses['trash'] = __('Trash', 'invoicing');
112 112
     }
113 113
 
114
-    return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
114
+    return apply_filters('wpinv_statuses', $invoice_statuses, $invoice);
115 115
 }
116 116
 
117
-function wpinv_status_nicename( $status ) {
118
-    $statuses = wpinv_get_invoice_statuses( true, true );
119
-    $status   = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' );
117
+function wpinv_status_nicename($status) {
118
+    $statuses = wpinv_get_invoice_statuses(true, true);
119
+    $status   = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing');
120 120
 
121 121
     return $status;
122 122
 }
123 123
 
124 124
 function wpinv_get_currency() {
125
-    $currency = wpinv_get_option( 'currency', 'USD' );
125
+    $currency = wpinv_get_option('currency', 'USD');
126 126
     
127
-    return apply_filters( 'wpinv_currency', $currency );
127
+    return apply_filters('wpinv_currency', $currency);
128 128
 }
129 129
 
130
-function wpinv_currency_symbol( $currency = '' ) {
131
-    if ( empty( $currency ) ) {
130
+function wpinv_currency_symbol($currency = '') {
131
+    if (empty($currency)) {
132 132
         $currency = wpinv_get_currency();
133 133
     }
134 134
     
135
-    $symbols = apply_filters( 'wpinv_currency_symbols', array(
135
+    $symbols = apply_filters('wpinv_currency_symbols', array(
136 136
         'AED' => '&#x62f;.&#x625;',
137 137
         'AFN' => '&#x60b;',
138 138
         'ALL' => 'L',
@@ -295,209 +295,209 @@  discard block
 block discarded – undo
295 295
         'YER' => '&#xfdfc;',
296 296
         'ZAR' => '&#82;',
297 297
         'ZMW' => 'ZK',
298
-    ) );
298
+    ));
299 299
 
300
-    $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : $currency;
300
+    $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency;
301 301
 
302
-    return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
302
+    return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency);
303 303
 }
304 304
 
305 305
 function wpinv_currency_position() {
306
-    $position = wpinv_get_option( 'currency_position', 'left' );
306
+    $position = wpinv_get_option('currency_position', 'left');
307 307
     
308
-    return apply_filters( 'wpinv_currency_position', $position );
308
+    return apply_filters('wpinv_currency_position', $position);
309 309
 }
310 310
 
311 311
 function wpinv_thousands_separator() {
312
-    $thousand_sep = wpinv_get_option( 'thousands_separator', ',' );
312
+    $thousand_sep = wpinv_get_option('thousands_separator', ',');
313 313
     
314
-    return apply_filters( 'wpinv_thousands_separator', $thousand_sep );
314
+    return apply_filters('wpinv_thousands_separator', $thousand_sep);
315 315
 }
316 316
 
317 317
 function wpinv_decimal_separator() {
318
-    $decimal_sep = wpinv_get_option( 'decimal_separator', '.' );
318
+    $decimal_sep = wpinv_get_option('decimal_separator', '.');
319 319
     
320
-    return apply_filters( 'wpinv_decimal_separator', $decimal_sep );
320
+    return apply_filters('wpinv_decimal_separator', $decimal_sep);
321 321
 }
322 322
 
323 323
 function wpinv_decimals() {
324
-    $decimals = apply_filters( 'wpinv_decimals', wpinv_get_option( 'decimals', 2 ) );
324
+    $decimals = apply_filters('wpinv_decimals', wpinv_get_option('decimals', 2));
325 325
     
326
-    return absint( $decimals );
326
+    return absint($decimals);
327 327
 }
328 328
 
329 329
 function wpinv_get_currencies() {
330 330
     $currencies = array(
331
-        'USD' => __( 'US Dollar', 'invoicing' ),
332
-        'EUR' => __( 'Euro', 'invoicing' ),
333
-        'GBP' => __( 'Pound Sterling', 'invoicing' ),
334
-        'AED' => __( 'United Arab Emirates', 'invoicing' ),
335
-        'AFN' => __( 'Afghan Afghani', 'invoicing' ),
336
-        'ALL' => __( 'Albanian Lek', 'invoicing' ),
337
-        'AMD' => __( 'Armenian Dram', 'invoicing' ),
338
-        'ANG' => __( 'Netherlands Antillean Guilder', 'invoicing' ),
339
-        'AOA' => __( 'Angolan Kwanza', 'invoicing' ),
340
-        'ARS' => __( 'Argentine Peso', 'invoicing' ),
341
-        'AUD' => __( 'Australian Dollar', 'invoicing' ),
342
-        'AWG' => __( 'Aruban Florin', 'invoicing' ),
343
-        'AZN' => __( 'Azerbaijani Manat', 'invoicing' ),
344
-        'BAM' => __( 'Bosnia and Herzegovina Convertible Marka', 'invoicing' ),
345
-        'BBD' => __( 'Barbadian Dollar', 'invoicing' ),
346
-        'BDT' => __( 'Bangladeshi Taka', 'invoicing' ),
347
-        'BGN' => __( 'Bulgarian Lev', 'invoicing' ),
348
-        'BHD' => __( 'Bahraini Dinar', 'invoicing' ),
349
-        'BIF' => __( 'Burundian Franc', 'invoicing' ),
350
-        'BMD' => __( 'Bermudian Dollar', 'invoicing' ),
351
-        'BND' => __( 'Brunei Dollar', 'invoicing' ),
352
-        'BOB' => __( 'Bolivian Boliviano', 'invoicing' ),
353
-        'BRL' => __( 'Brazilian Real', 'invoicing' ),
354
-        'BSD' => __( 'Bahamian Dollar', 'invoicing' ),
355
-        'BTC' => __( 'Bitcoin', 'invoicing' ),
356
-        'BTN' => __( 'Bhutanese Ngultrum', 'invoicing' ),
357
-        'BWP' => __( 'Botswana Pula', 'invoicing' ),
358
-        'BYN' => __( 'Belarusian Ruble', 'invoicing' ),
359
-        'BZD' => __( 'Belize Dollar', 'invoicing' ),
360
-        'CAD' => __( 'Canadian Dollar', 'invoicing' ),
361
-        'CDF' => __( 'Congolese Franc', 'invoicing' ),
362
-        'CHF' => __( 'Swiss Franc', 'invoicing' ),
363
-        'CLP' => __( 'Chilean Peso', 'invoicing' ),
364
-        'CNY' => __( 'Chinese Yuan', 'invoicing' ),
365
-        'COP' => __( 'Colombian Peso', 'invoicing' ),
366
-        'CRC' => __( 'Costa Rican Colon', 'invoicing' ),
367
-        'CUC' => __( 'Cuban Convertible Peso', 'invoicing' ),
368
-        'CUP' => __( 'Cuban Peso', 'invoicing' ),
369
-        'CVE' => __( 'Cape Verdean escudo', 'invoicing' ),
370
-        'CZK' => __( 'Czech Koruna', 'invoicing' ),
371
-        'DJF' => __( 'Djiboutian Franc', 'invoicing' ),
372
-        'DKK' => __( 'Danish Krone', 'invoicing' ),
373
-        'DOP' => __( 'Dominican Peso', 'invoicing' ),
374
-        'DZD' => __( 'Algerian Dinar', 'invoicing' ),
375
-        'EGP' => __( 'Egyptian Pound', 'invoicing' ),
376
-        'ERN' => __( 'Eritrean Nakfa', 'invoicing' ),
377
-        'ETB' => __( 'Ethiopian Irr', 'invoicing' ),
378
-        'FJD' => __( 'Fijian Dollar', 'invoicing' ),
379
-        'FKP' => __( 'Falkland Islands Pound', 'invoicing' ),
380
-        'GEL' => __( 'Georgian Lari', 'invoicing' ),
381
-        'GGP' => __( 'Guernsey Pound', 'invoicing' ),
382
-        'GHS' => __( 'Ghana Cedi', 'invoicing' ),
383
-        'GIP' => __( 'Gibraltar Pound', 'invoicing' ),
384
-        'GMD' => __( 'Gambian Dalasi', 'invoicing' ),
385
-        'GNF' => __( 'Guinean Franc', 'invoicing' ),
386
-        'GTQ' => __( 'Guatemalan Quetzal', 'invoicing' ),
387
-        'GYD' => __( 'Guyanese Dollar', 'invoicing' ),
388
-        'HKD' => __( 'Hong Kong Dollar', 'invoicing' ),
389
-        'HNL' => __( 'Honduran Lempira', 'invoicing' ),
390
-        'HRK' => __( 'Croatian Kuna', 'invoicing' ),
391
-        'HTG' => __( 'Haitian Gourde', 'invoicing' ),
392
-        'HUF' => __( 'Hungarian Forint', 'invoicing' ),
393
-        'IDR' => __( 'Indonesian Rupiah', 'invoicing' ),
394
-        'ILS' => __( 'Israeli New Shekel', 'invoicing' ),
395
-        'IMP' => __( 'Manx Pound', 'invoicing' ),
396
-        'INR' => __( 'Indian Rupee', 'invoicing' ),
397
-        'IQD' => __( 'Iraqi Dinar', 'invoicing' ),
398
-        'IRR' => __( 'Iranian Rial', 'invoicing' ),
399
-        'IRT' => __( 'Iranian Toman', 'invoicing' ),
400
-        'ISK' => __( 'Icelandic Krona', 'invoicing' ),
401
-        'JEP' => __( 'Jersey Pound', 'invoicing' ),
402
-        'JMD' => __( 'Jamaican Dollar', 'invoicing' ),
403
-        'JOD' => __( 'Jordanian Dinar', 'invoicing' ),
404
-        'JPY' => __( 'Japanese Yen', 'invoicing' ),
405
-        'KES' => __( 'Kenyan Shilling', 'invoicing' ),
406
-        'KGS' => __( 'Kyrgyzstani Som', 'invoicing' ),
407
-        'KHR' => __( 'Cambodian Riel', 'invoicing' ),
408
-        'KMF' => __( 'Comorian Franc', 'invoicing' ),
409
-        'KPW' => __( 'North Korean Won', 'invoicing' ),
410
-        'KRW' => __( 'South Korean Won', 'invoicing' ),
411
-        'KWD' => __( 'Kuwaiti Dinar', 'invoicing' ),
412
-        'KYD' => __( 'Cayman Islands Dollar', 'invoicing' ),
413
-        'KZT' => __( 'Kazakhstani Tenge', 'invoicing' ),
414
-        'LAK' => __( 'Lao Kip', 'invoicing' ),
415
-        'LBP' => __( 'Lebanese Pound', 'invoicing' ),
416
-        'LKR' => __( 'Sri Lankan Rupee', 'invoicing' ),
417
-        'LRD' => __( 'Liberian Dollar', 'invoicing' ),
418
-        'LSL' => __( 'Lesotho Loti', 'invoicing' ),
419
-        'LYD' => __( 'Libyan Dinar', 'invoicing' ),
420
-        'MAD' => __( 'Moroccan Dirham', 'invoicing' ),
421
-        'MDL' => __( 'Moldovan Leu', 'invoicing' ),
422
-        'MGA' => __( 'Malagasy Ariary', 'invoicing' ),
423
-        'MKD' => __( 'Macedonian Denar', 'invoicing' ),
424
-        'MMK' => __( 'Burmese Kyat', 'invoicing' ),
425
-        'MNT' => __( 'Mongolian Tughrik', 'invoicing' ),
426
-        'MOP' => __( 'Macanese Pataca', 'invoicing' ),
427
-        'MRO' => __( 'Mauritanian Ouguiya', 'invoicing' ),
428
-        'MUR' => __( 'Mauritian Rupee', 'invoicing' ),
429
-        'MVR' => __( 'Maldivian Rufiyaa', 'invoicing' ),
430
-        'MWK' => __( 'Malawian Kwacha', 'invoicing' ),
431
-        'MXN' => __( 'Mexican Peso', 'invoicing' ),
432
-        'MYR' => __( 'Malaysian Ringgit', 'invoicing' ),
433
-        'MZN' => __( 'Mozambican Metical', 'invoicing' ),
434
-        'NAD' => __( 'Namibian Dollar', 'invoicing' ),
435
-        'NGN' => __( 'Nigerian Naira', 'invoicing' ),
436
-        'NIO' => __( 'Nicaraguan Cordoba', 'invoicing' ),
437
-        'NOK' => __( 'Norwegian Krone', 'invoicing' ),
438
-        'NPR' => __( 'Nepalese Rupee', 'invoicing' ),
439
-        'NZD' => __( 'New Zealand Dollar', 'invoicing' ),
440
-        'OMR' => __( 'Omani Rial', 'invoicing' ),
441
-        'PAB' => __( 'Panamanian Balboa', 'invoicing' ),
442
-        'PEN' => __( 'Peruvian Nuevo Sol', 'invoicing' ),
443
-        'PGK' => __( 'Papua New Guinean Kina', 'invoicing' ),
444
-        'PHP' => __( 'Philippine Peso', 'invoicing' ),
445
-        'PKR' => __( 'Pakistani Rupee', 'invoicing' ),
446
-        'PLN' => __( 'Polish Zloty', 'invoicing' ),
447
-        'PRB' => __( 'Transnistrian Ruble', 'invoicing' ),
448
-        'PYG' => __( 'Paraguayan Guarani', 'invoicing' ),
449
-        'QAR' => __( 'Qatari Riyal', 'invoicing' ),
450
-        'RON' => __( 'Romanian Leu', 'invoicing' ),
451
-        'RSD' => __( 'Serbian Dinar', 'invoicing' ),
452
-        'RUB' => __( 'Russian Ruble', 'invoicing' ),
453
-        'RWF' => __( 'Rwandan Franc', 'invoicing' ),
454
-        'SAR' => __( 'Saudi Riyal', 'invoicing' ),
455
-        'SBD' => __( 'Solomon Islands Dollar', 'invoicing' ),
456
-        'SCR' => __( 'Seychellois Rupee', 'invoicing' ),
457
-        'SDG' => __( 'Sudanese Pound', 'invoicing' ),
458
-        'SEK' => __( 'Swedish Krona', 'invoicing' ),
459
-        'SGD' => __( 'Singapore Dollar', 'invoicing' ),
460
-        'SHP' => __( 'Saint Helena Pound', 'invoicing' ),
461
-        'SLL' => __( 'Sierra Leonean Leone', 'invoicing' ),
462
-        'SOS' => __( 'Somali Shilling', 'invoicing' ),
463
-        'SRD' => __( 'Surinamese Dollar', 'invoicing' ),
464
-        'SSP' => __( 'South Sudanese Pound', 'invoicing' ),
465
-        'STD' => __( 'Sao Tomean Dobra', 'invoicing' ),
466
-        'SYP' => __( 'Syrian Pound', 'invoicing' ),
467
-        'SZL' => __( 'Swazi Lilangeni', 'invoicing' ),
468
-        'THB' => __( 'Thai Baht', 'invoicing' ),
469
-        'TJS' => __( 'Tajikistani Somoni', 'invoicing' ),
470
-        'TMT' => __( 'Turkmenistan Manat', 'invoicing' ),
471
-        'TND' => __( 'Tunisian Dinar', 'invoicing' ),
472
-        'TOP' => __( 'Tongan Pa&#x2bb;anga', 'invoicing' ),
473
-        'TRY' => __( 'Turkish Lira', 'invoicing' ),
474
-        'TTD' => __( 'Trinidad and Tobago Dollar', 'invoicing' ),
475
-        'TWD' => __( 'New Taiwan Dollar', 'invoicing' ),
476
-        'TZS' => __( 'Tanzanian Shilling', 'invoicing' ),
477
-        'UAH' => __( 'Ukrainian Hryvnia', 'invoicing' ),
478
-        'UGX' => __( 'Ugandan Shilling', 'invoicing' ),
479
-        'UYU' => __( 'Uruguayan Peso', 'invoicing' ),
480
-        'UZS' => __( 'Uzbekistani Som', 'invoicing' ),
481
-        'VEF' => __( 'Venezuelan Bol&iacute;var', 'invoicing' ),
482
-        'VND' => __( 'Vietnamese Dong', 'invoicing' ),
483
-        'VUV' => __( 'Vanuatu Vatu', 'invoicing' ),
484
-        'WST' => __( 'Samoan Tala', 'invoicing' ),
485
-        'XAF' => __( 'Central African CFA Franc', 'invoicing' ),
486
-        'XCD' => __( 'East Caribbean Dollar', 'invoicing' ),
487
-        'XOF' => __( 'West African CFA Franc', 'invoicing' ),
488
-        'XPF' => __( 'CFP Franc', 'invoicing' ),
489
-        'YER' => __( 'Yemeni Rial', 'invoicing' ),
490
-        'ZAR' => __( 'South African Rand', 'invoicing' ),
491
-        'ZMW' => __( 'Zambian Kwacha', 'invoicing' ),
331
+        'USD' => __('US Dollar', 'invoicing'),
332
+        'EUR' => __('Euro', 'invoicing'),
333
+        'GBP' => __('Pound Sterling', 'invoicing'),
334
+        'AED' => __('United Arab Emirates', 'invoicing'),
335
+        'AFN' => __('Afghan Afghani', 'invoicing'),
336
+        'ALL' => __('Albanian Lek', 'invoicing'),
337
+        'AMD' => __('Armenian Dram', 'invoicing'),
338
+        'ANG' => __('Netherlands Antillean Guilder', 'invoicing'),
339
+        'AOA' => __('Angolan Kwanza', 'invoicing'),
340
+        'ARS' => __('Argentine Peso', 'invoicing'),
341
+        'AUD' => __('Australian Dollar', 'invoicing'),
342
+        'AWG' => __('Aruban Florin', 'invoicing'),
343
+        'AZN' => __('Azerbaijani Manat', 'invoicing'),
344
+        'BAM' => __('Bosnia and Herzegovina Convertible Marka', 'invoicing'),
345
+        'BBD' => __('Barbadian Dollar', 'invoicing'),
346
+        'BDT' => __('Bangladeshi Taka', 'invoicing'),
347
+        'BGN' => __('Bulgarian Lev', 'invoicing'),
348
+        'BHD' => __('Bahraini Dinar', 'invoicing'),
349
+        'BIF' => __('Burundian Franc', 'invoicing'),
350
+        'BMD' => __('Bermudian Dollar', 'invoicing'),
351
+        'BND' => __('Brunei Dollar', 'invoicing'),
352
+        'BOB' => __('Bolivian Boliviano', 'invoicing'),
353
+        'BRL' => __('Brazilian Real', 'invoicing'),
354
+        'BSD' => __('Bahamian Dollar', 'invoicing'),
355
+        'BTC' => __('Bitcoin', 'invoicing'),
356
+        'BTN' => __('Bhutanese Ngultrum', 'invoicing'),
357
+        'BWP' => __('Botswana Pula', 'invoicing'),
358
+        'BYN' => __('Belarusian Ruble', 'invoicing'),
359
+        'BZD' => __('Belize Dollar', 'invoicing'),
360
+        'CAD' => __('Canadian Dollar', 'invoicing'),
361
+        'CDF' => __('Congolese Franc', 'invoicing'),
362
+        'CHF' => __('Swiss Franc', 'invoicing'),
363
+        'CLP' => __('Chilean Peso', 'invoicing'),
364
+        'CNY' => __('Chinese Yuan', 'invoicing'),
365
+        'COP' => __('Colombian Peso', 'invoicing'),
366
+        'CRC' => __('Costa Rican Colon', 'invoicing'),
367
+        'CUC' => __('Cuban Convertible Peso', 'invoicing'),
368
+        'CUP' => __('Cuban Peso', 'invoicing'),
369
+        'CVE' => __('Cape Verdean escudo', 'invoicing'),
370
+        'CZK' => __('Czech Koruna', 'invoicing'),
371
+        'DJF' => __('Djiboutian Franc', 'invoicing'),
372
+        'DKK' => __('Danish Krone', 'invoicing'),
373
+        'DOP' => __('Dominican Peso', 'invoicing'),
374
+        'DZD' => __('Algerian Dinar', 'invoicing'),
375
+        'EGP' => __('Egyptian Pound', 'invoicing'),
376
+        'ERN' => __('Eritrean Nakfa', 'invoicing'),
377
+        'ETB' => __('Ethiopian Irr', 'invoicing'),
378
+        'FJD' => __('Fijian Dollar', 'invoicing'),
379
+        'FKP' => __('Falkland Islands Pound', 'invoicing'),
380
+        'GEL' => __('Georgian Lari', 'invoicing'),
381
+        'GGP' => __('Guernsey Pound', 'invoicing'),
382
+        'GHS' => __('Ghana Cedi', 'invoicing'),
383
+        'GIP' => __('Gibraltar Pound', 'invoicing'),
384
+        'GMD' => __('Gambian Dalasi', 'invoicing'),
385
+        'GNF' => __('Guinean Franc', 'invoicing'),
386
+        'GTQ' => __('Guatemalan Quetzal', 'invoicing'),
387
+        'GYD' => __('Guyanese Dollar', 'invoicing'),
388
+        'HKD' => __('Hong Kong Dollar', 'invoicing'),
389
+        'HNL' => __('Honduran Lempira', 'invoicing'),
390
+        'HRK' => __('Croatian Kuna', 'invoicing'),
391
+        'HTG' => __('Haitian Gourde', 'invoicing'),
392
+        'HUF' => __('Hungarian Forint', 'invoicing'),
393
+        'IDR' => __('Indonesian Rupiah', 'invoicing'),
394
+        'ILS' => __('Israeli New Shekel', 'invoicing'),
395
+        'IMP' => __('Manx Pound', 'invoicing'),
396
+        'INR' => __('Indian Rupee', 'invoicing'),
397
+        'IQD' => __('Iraqi Dinar', 'invoicing'),
398
+        'IRR' => __('Iranian Rial', 'invoicing'),
399
+        'IRT' => __('Iranian Toman', 'invoicing'),
400
+        'ISK' => __('Icelandic Krona', 'invoicing'),
401
+        'JEP' => __('Jersey Pound', 'invoicing'),
402
+        'JMD' => __('Jamaican Dollar', 'invoicing'),
403
+        'JOD' => __('Jordanian Dinar', 'invoicing'),
404
+        'JPY' => __('Japanese Yen', 'invoicing'),
405
+        'KES' => __('Kenyan Shilling', 'invoicing'),
406
+        'KGS' => __('Kyrgyzstani Som', 'invoicing'),
407
+        'KHR' => __('Cambodian Riel', 'invoicing'),
408
+        'KMF' => __('Comorian Franc', 'invoicing'),
409
+        'KPW' => __('North Korean Won', 'invoicing'),
410
+        'KRW' => __('South Korean Won', 'invoicing'),
411
+        'KWD' => __('Kuwaiti Dinar', 'invoicing'),
412
+        'KYD' => __('Cayman Islands Dollar', 'invoicing'),
413
+        'KZT' => __('Kazakhstani Tenge', 'invoicing'),
414
+        'LAK' => __('Lao Kip', 'invoicing'),
415
+        'LBP' => __('Lebanese Pound', 'invoicing'),
416
+        'LKR' => __('Sri Lankan Rupee', 'invoicing'),
417
+        'LRD' => __('Liberian Dollar', 'invoicing'),
418
+        'LSL' => __('Lesotho Loti', 'invoicing'),
419
+        'LYD' => __('Libyan Dinar', 'invoicing'),
420
+        'MAD' => __('Moroccan Dirham', 'invoicing'),
421
+        'MDL' => __('Moldovan Leu', 'invoicing'),
422
+        'MGA' => __('Malagasy Ariary', 'invoicing'),
423
+        'MKD' => __('Macedonian Denar', 'invoicing'),
424
+        'MMK' => __('Burmese Kyat', 'invoicing'),
425
+        'MNT' => __('Mongolian Tughrik', 'invoicing'),
426
+        'MOP' => __('Macanese Pataca', 'invoicing'),
427
+        'MRO' => __('Mauritanian Ouguiya', 'invoicing'),
428
+        'MUR' => __('Mauritian Rupee', 'invoicing'),
429
+        'MVR' => __('Maldivian Rufiyaa', 'invoicing'),
430
+        'MWK' => __('Malawian Kwacha', 'invoicing'),
431
+        'MXN' => __('Mexican Peso', 'invoicing'),
432
+        'MYR' => __('Malaysian Ringgit', 'invoicing'),
433
+        'MZN' => __('Mozambican Metical', 'invoicing'),
434
+        'NAD' => __('Namibian Dollar', 'invoicing'),
435
+        'NGN' => __('Nigerian Naira', 'invoicing'),
436
+        'NIO' => __('Nicaraguan Cordoba', 'invoicing'),
437
+        'NOK' => __('Norwegian Krone', 'invoicing'),
438
+        'NPR' => __('Nepalese Rupee', 'invoicing'),
439
+        'NZD' => __('New Zealand Dollar', 'invoicing'),
440
+        'OMR' => __('Omani Rial', 'invoicing'),
441
+        'PAB' => __('Panamanian Balboa', 'invoicing'),
442
+        'PEN' => __('Peruvian Nuevo Sol', 'invoicing'),
443
+        'PGK' => __('Papua New Guinean Kina', 'invoicing'),
444
+        'PHP' => __('Philippine Peso', 'invoicing'),
445
+        'PKR' => __('Pakistani Rupee', 'invoicing'),
446
+        'PLN' => __('Polish Zloty', 'invoicing'),
447
+        'PRB' => __('Transnistrian Ruble', 'invoicing'),
448
+        'PYG' => __('Paraguayan Guarani', 'invoicing'),
449
+        'QAR' => __('Qatari Riyal', 'invoicing'),
450
+        'RON' => __('Romanian Leu', 'invoicing'),
451
+        'RSD' => __('Serbian Dinar', 'invoicing'),
452
+        'RUB' => __('Russian Ruble', 'invoicing'),
453
+        'RWF' => __('Rwandan Franc', 'invoicing'),
454
+        'SAR' => __('Saudi Riyal', 'invoicing'),
455
+        'SBD' => __('Solomon Islands Dollar', 'invoicing'),
456
+        'SCR' => __('Seychellois Rupee', 'invoicing'),
457
+        'SDG' => __('Sudanese Pound', 'invoicing'),
458
+        'SEK' => __('Swedish Krona', 'invoicing'),
459
+        'SGD' => __('Singapore Dollar', 'invoicing'),
460
+        'SHP' => __('Saint Helena Pound', 'invoicing'),
461
+        'SLL' => __('Sierra Leonean Leone', 'invoicing'),
462
+        'SOS' => __('Somali Shilling', 'invoicing'),
463
+        'SRD' => __('Surinamese Dollar', 'invoicing'),
464
+        'SSP' => __('South Sudanese Pound', 'invoicing'),
465
+        'STD' => __('Sao Tomean Dobra', 'invoicing'),
466
+        'SYP' => __('Syrian Pound', 'invoicing'),
467
+        'SZL' => __('Swazi Lilangeni', 'invoicing'),
468
+        'THB' => __('Thai Baht', 'invoicing'),
469
+        'TJS' => __('Tajikistani Somoni', 'invoicing'),
470
+        'TMT' => __('Turkmenistan Manat', 'invoicing'),
471
+        'TND' => __('Tunisian Dinar', 'invoicing'),
472
+        'TOP' => __('Tongan Pa&#x2bb;anga', 'invoicing'),
473
+        'TRY' => __('Turkish Lira', 'invoicing'),
474
+        'TTD' => __('Trinidad and Tobago Dollar', 'invoicing'),
475
+        'TWD' => __('New Taiwan Dollar', 'invoicing'),
476
+        'TZS' => __('Tanzanian Shilling', 'invoicing'),
477
+        'UAH' => __('Ukrainian Hryvnia', 'invoicing'),
478
+        'UGX' => __('Ugandan Shilling', 'invoicing'),
479
+        'UYU' => __('Uruguayan Peso', 'invoicing'),
480
+        'UZS' => __('Uzbekistani Som', 'invoicing'),
481
+        'VEF' => __('Venezuelan Bol&iacute;var', 'invoicing'),
482
+        'VND' => __('Vietnamese Dong', 'invoicing'),
483
+        'VUV' => __('Vanuatu Vatu', 'invoicing'),
484
+        'WST' => __('Samoan Tala', 'invoicing'),
485
+        'XAF' => __('Central African CFA Franc', 'invoicing'),
486
+        'XCD' => __('East Caribbean Dollar', 'invoicing'),
487
+        'XOF' => __('West African CFA Franc', 'invoicing'),
488
+        'XPF' => __('CFP Franc', 'invoicing'),
489
+        'YER' => __('Yemeni Rial', 'invoicing'),
490
+        'ZAR' => __('South African Rand', 'invoicing'),
491
+        'ZMW' => __('Zambian Kwacha', 'invoicing'),
492 492
     );
493 493
     
494 494
     //asort( $currencies ); // this
495 495
 
496
-    return apply_filters( 'wpinv_currencies', $currencies );
496
+    return apply_filters('wpinv_currencies', $currencies);
497 497
 }
498 498
 
499
-function wpinv_price( $amount = '', $currency = '' ) {
500
-    if( empty( $currency ) ) {
499
+function wpinv_price($amount = '', $currency = '') {
500
+    if (empty($currency)) {
501 501
         $currency = wpinv_get_currency();
502 502
     }
503 503
 
@@ -505,14 +505,14 @@  discard block
 block discarded – undo
505 505
 
506 506
     $negative = $amount < 0;
507 507
 
508
-    if ( $negative ) {
509
-        $amount = substr( $amount, 1 );
508
+    if ($negative) {
509
+        $amount = substr($amount, 1);
510 510
     }
511 511
 
512
-    $symbol = wpinv_currency_symbol( $currency );
512
+    $symbol = wpinv_currency_symbol($currency);
513 513
 
514
-    if ( $position == 'left' || $position == 'left_space' ) {
515
-        switch ( $currency ) {
514
+    if ($position == 'left' || $position == 'left_space') {
515
+        switch ($currency) {
516 516
             case "GBP" :
517 517
             case "BRL" :
518 518
             case "EUR" :
@@ -524,15 +524,15 @@  discard block
 block discarded – undo
524 524
             case "NZD" :
525 525
             case "SGD" :
526 526
             case "JPY" :
527
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
527
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
528 528
                 break;
529 529
             default :
530 530
                 //$price = $currency . ' ' . $amount;
531
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
531
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
532 532
                 break;
533 533
         }
534 534
     } else {
535
-        switch ( $currency ) {
535
+        switch ($currency) {
536 536
             case "GBP" :
537 537
             case "BRL" :
538 538
             case "EUR" :
@@ -543,83 +543,83 @@  discard block
 block discarded – undo
543 543
             case "MXN" :
544 544
             case "SGD" :
545 545
             case "JPY" :
546
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
546
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
547 547
                 break;
548 548
             default :
549 549
                 //$price = $amount . ' ' . $currency;
550
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
550
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
551 551
                 break;
552 552
         }
553 553
     }
554 554
     
555
-    if ( $negative ) {
555
+    if ($negative) {
556 556
         $price = '-' . $price;
557 557
     }
558 558
     
559
-    $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount );
559
+    $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount);
560 560
 
561 561
     return $price;
562 562
 }
563 563
 
564
-function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) {
564
+function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) {
565 565
     $thousands_sep = wpinv_thousands_separator();
566 566
     $decimal_sep   = wpinv_decimal_separator();
567 567
 
568
-    if ( $decimals === NULL ) {
568
+    if ($decimals === NULL) {
569 569
         $decimals = wpinv_decimals();
570 570
     }
571 571
 
572
-    if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) {
573
-        $whole = substr( $amount, 0, $sep_found );
574
-        $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) );
572
+    if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) {
573
+        $whole = substr($amount, 0, $sep_found);
574
+        $part = substr($amount, $sep_found + 1, (strlen($amount) - 1));
575 575
         $amount = $whole . '.' . $part;
576 576
     }
577 577
 
578
-    if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
579
-        $amount = str_replace( ',', '', $amount );
578
+    if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
579
+        $amount = str_replace(',', '', $amount);
580 580
     }
581 581
 
582
-    if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
583
-        $amount = str_replace( ' ', '', $amount );
582
+    if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) {
583
+        $amount = str_replace(' ', '', $amount);
584 584
     }
585 585
 
586
-    if ( empty( $amount ) ) {
586
+    if (empty($amount)) {
587 587
         $amount = 0;
588 588
     }
589 589
     
590
-    $decimals  = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate );
591
-    $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep );
590
+    $decimals  = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate);
591
+    $formatted = number_format((float) $amount, $decimals, $decimal_sep, $thousands_sep);
592 592
     
593
-    if ( $calculate ) {
594
-        if ( $thousands_sep === "," ) {
595
-            $formatted = str_replace( ",", "", $formatted );
593
+    if ($calculate) {
594
+        if ($thousands_sep === ",") {
595
+            $formatted = str_replace(",", "", $formatted);
596 596
         }
597 597
         
598
-        if ( $decimal_sep === "," ) {
599
-            $formatted = str_replace( ",", ".", $formatted );
598
+        if ($decimal_sep === ",") {
599
+            $formatted = str_replace(",", ".", $formatted);
600 600
         }
601 601
     }
602 602
 
603
-    return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate );
603
+    return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate);
604 604
 }
605
-add_filter( 'wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
605
+add_filter('wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1);
606 606
 
607
-function wpinv_sanitize_key( $key ) {
607
+function wpinv_sanitize_key($key) {
608 608
     $raw_key = $key;
609
-    $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
609
+    $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key);
610 610
 
611
-    return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
611
+    return apply_filters('wpinv_sanitize_key', $key, $raw_key);
612 612
 }
613 613
 
614
-function wpinv_get_file_extension( $str ) {
615
-    $parts = explode( '.', $str );
616
-    return end( $parts );
614
+function wpinv_get_file_extension($str) {
615
+    $parts = explode('.', $str);
616
+    return end($parts);
617 617
 }
618 618
 
619
-function wpinv_string_is_image_url( $str ) {
620
-    $ext = wpinv_get_file_extension( $str );
619
+function wpinv_string_is_image_url($str) {
620
+    $ext = wpinv_get_file_extension($str);
621 621
 
622
-    switch ( strtolower( $ext ) ) {
622
+    switch (strtolower($ext)) {
623 623
         case 'jpeg';
624 624
         case 'jpg';
625 625
             $return = true;
@@ -635,32 +635,32 @@  discard block
 block discarded – undo
635 635
             break;
636 636
     }
637 637
 
638
-    return (bool)apply_filters( 'wpinv_string_is_image', $return, $str );
638
+    return (bool) apply_filters('wpinv_string_is_image', $return, $str);
639 639
 }
640 640
 
641
-function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) {
642
-    $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG );
641
+function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) {
642
+    $should_log = apply_filters('wpinv_log_errors', WP_DEBUG);
643 643
     
644
-    if ( true === $should_log ) {
644
+    if (true === $should_log) {
645 645
         $label = '';
646
-        if ( $file && $file !== '' ) {
647
-            $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' );
646
+        if ($file && $file !== '') {
647
+            $label .= basename($file) . ($line ? '(' . $line . ')' : '');
648 648
         }
649 649
         
650
-        if ( $title && $title !== '' ) {
650
+        if ($title && $title !== '') {
651 651
             $label = $label !== '' ? $label . ' ' : '';
652 652
             $label .= $title . ' ';
653 653
         }
654 654
         
655
-        $label = $label !== '' ? trim( $label ) . ' : ' : '';
655
+        $label = $label !== '' ? trim($label) . ' : ' : '';
656 656
         
657
-        if ( is_array( $log ) || is_object( $log ) ) {
658
-            error_log( $label . print_r( $log, true ) );
657
+        if (is_array($log) || is_object($log)) {
658
+            error_log($label . print_r($log, true));
659 659
         } else {
660
-            error_log( $label . $log );
660
+            error_log($label . $log);
661 661
         }
662 662
         
663
-        if ( $exit ) {
663
+        if ($exit) {
664 664
             exit;
665 665
         }
666 666
     }
@@ -668,65 +668,65 @@  discard block
 block discarded – undo
668 668
 
669 669
 function wpinv_is_ajax_disabled() {
670 670
     $retval = false;
671
-    return apply_filters( 'wpinv_is_ajax_disabled', $retval );
671
+    return apply_filters('wpinv_is_ajax_disabled', $retval);
672 672
 }
673 673
 
674
-function wpinv_get_current_page_url( $nocache = false ) {
674
+function wpinv_get_current_page_url($nocache = false) {
675 675
     global $wp;
676 676
 
677
-    if ( get_option( 'permalink_structure' ) ) {
678
-        $base = trailingslashit( home_url( $wp->request ) );
677
+    if (get_option('permalink_structure')) {
678
+        $base = trailingslashit(home_url($wp->request));
679 679
     } else {
680
-        $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) );
681
-        $base = remove_query_arg( array( 'post_type', 'name' ), $base );
680
+        $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request)));
681
+        $base = remove_query_arg(array('post_type', 'name'), $base);
682 682
     }
683 683
 
684 684
     $scheme = is_ssl() ? 'https' : 'http';
685
-    $uri    = set_url_scheme( $base, $scheme );
685
+    $uri    = set_url_scheme($base, $scheme);
686 686
 
687
-    if ( is_front_page() ) {
688
-        $uri = home_url( '/' );
689
-    } elseif ( wpinv_is_checkout( array(), false ) ) {
687
+    if (is_front_page()) {
688
+        $uri = home_url('/');
689
+    } elseif (wpinv_is_checkout(array(), false)) {
690 690
         $uri = wpinv_get_checkout_uri();
691 691
     }
692 692
 
693
-    $uri = apply_filters( 'wpinv_get_current_page_url', $uri );
693
+    $uri = apply_filters('wpinv_get_current_page_url', $uri);
694 694
 
695
-    if ( $nocache ) {
696
-        $uri = wpinv_add_cache_busting( $uri );
695
+    if ($nocache) {
696
+        $uri = wpinv_add_cache_busting($uri);
697 697
     }
698 698
 
699 699
     return $uri;
700 700
 }
701 701
 
702 702
 function wpinv_get_php_arg_separator_output() {
703
-	return ini_get( 'arg_separator.output' );
703
+	return ini_get('arg_separator.output');
704 704
 }
705 705
 
706
-function wpinv_rgb_from_hex( $color ) {
707
-    $color = str_replace( '#', '', $color );
706
+function wpinv_rgb_from_hex($color) {
707
+    $color = str_replace('#', '', $color);
708 708
     // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
709
-    $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
709
+    $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
710 710
 
711 711
     $rgb      = array();
712
-    $rgb['R'] = hexdec( $color{0}.$color{1} );
713
-    $rgb['G'] = hexdec( $color{2}.$color{3} );
714
-    $rgb['B'] = hexdec( $color{4}.$color{5} );
712
+    $rgb['R'] = hexdec($color{0} . $color{1} );
713
+    $rgb['G'] = hexdec($color{2} . $color{3} );
714
+    $rgb['B'] = hexdec($color{4} . $color{5} );
715 715
 
716 716
     return $rgb;
717 717
 }
718 718
 
719
-function wpinv_hex_darker( $color, $factor = 30 ) {
720
-    $base  = wpinv_rgb_from_hex( $color );
719
+function wpinv_hex_darker($color, $factor = 30) {
720
+    $base  = wpinv_rgb_from_hex($color);
721 721
     $color = '#';
722 722
 
723
-    foreach ( $base as $k => $v ) {
723
+    foreach ($base as $k => $v) {
724 724
         $amount      = $v / 100;
725
-        $amount      = round( $amount * $factor );
725
+        $amount      = round($amount * $factor);
726 726
         $new_decimal = $v - $amount;
727 727
 
728
-        $new_hex_component = dechex( $new_decimal );
729
-        if ( strlen( $new_hex_component ) < 2 ) {
728
+        $new_hex_component = dechex($new_decimal);
729
+        if (strlen($new_hex_component) < 2) {
730 730
             $new_hex_component = "0" . $new_hex_component;
731 731
         }
732 732
         $color .= $new_hex_component;
@@ -735,18 +735,18 @@  discard block
 block discarded – undo
735 735
     return $color;
736 736
 }
737 737
 
738
-function wpinv_hex_lighter( $color, $factor = 30 ) {
739
-    $base  = wpinv_rgb_from_hex( $color );
738
+function wpinv_hex_lighter($color, $factor = 30) {
739
+    $base  = wpinv_rgb_from_hex($color);
740 740
     $color = '#';
741 741
 
742
-    foreach ( $base as $k => $v ) {
742
+    foreach ($base as $k => $v) {
743 743
         $amount      = 255 - $v;
744 744
         $amount      = $amount / 100;
745
-        $amount      = round( $amount * $factor );
745
+        $amount      = round($amount * $factor);
746 746
         $new_decimal = $v + $amount;
747 747
 
748
-        $new_hex_component = dechex( $new_decimal );
749
-        if ( strlen( $new_hex_component ) < 2 ) {
748
+        $new_hex_component = dechex($new_decimal);
749
+        if (strlen($new_hex_component) < 2) {
750 750
             $new_hex_component = "0" . $new_hex_component;
751 751
         }
752 752
         $color .= $new_hex_component;
@@ -755,22 +755,22 @@  discard block
 block discarded – undo
755 755
     return $color;
756 756
 }
757 757
 
758
-function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
759
-    $hex = str_replace( '#', '', $color );
758
+function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
759
+    $hex = str_replace('#', '', $color);
760 760
 
761
-    $c_r = hexdec( substr( $hex, 0, 2 ) );
762
-    $c_g = hexdec( substr( $hex, 2, 2 ) );
763
-    $c_b = hexdec( substr( $hex, 4, 2 ) );
761
+    $c_r = hexdec(substr($hex, 0, 2));
762
+    $c_g = hexdec(substr($hex, 2, 2));
763
+    $c_b = hexdec(substr($hex, 4, 2));
764 764
 
765
-    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
765
+    $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
766 766
 
767 767
     return $brightness > 155 ? $dark : $light;
768 768
 }
769 769
 
770
-function wpinv_format_hex( $hex ) {
771
-    $hex = trim( str_replace( '#', '', $hex ) );
770
+function wpinv_format_hex($hex) {
771
+    $hex = trim(str_replace('#', '', $hex));
772 772
 
773
-    if ( strlen( $hex ) == 3 ) {
773
+    if (strlen($hex) == 3) {
774 774
         $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
775 775
     }
776 776
 
@@ -790,12 +790,12 @@  discard block
 block discarded – undo
790 790
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
791 791
  * @return string
792 792
  */
793
-function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) {
794
-    if ( function_exists( 'mb_strimwidth' ) ) {
795
-        return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding );
793
+function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') {
794
+    if (function_exists('mb_strimwidth')) {
795
+        return mb_strimwidth($str, $start, $width, $trimmaker, $encoding);
796 796
     }
797 797
     
798
-    return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker;
798
+    return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker;
799 799
 }
800 800
 
801 801
 /**
@@ -807,28 +807,28 @@  discard block
 block discarded – undo
807 807
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
808 808
  * @return int Returns the number of characters in string.
809 809
  */
810
-function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) {
811
-    if ( function_exists( 'mb_strlen' ) ) {
812
-        return mb_strlen( $str, $encoding );
810
+function wpinv_utf8_strlen($str, $encoding = 'UTF-8') {
811
+    if (function_exists('mb_strlen')) {
812
+        return mb_strlen($str, $encoding);
813 813
     }
814 814
         
815
-    return strlen( $str );
815
+    return strlen($str);
816 816
 }
817 817
 
818
-function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
819
-    if ( function_exists( 'mb_strtolower' ) ) {
820
-        return mb_strtolower( $str, $encoding );
818
+function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') {
819
+    if (function_exists('mb_strtolower')) {
820
+        return mb_strtolower($str, $encoding);
821 821
     }
822 822
     
823
-    return strtolower( $str );
823
+    return strtolower($str);
824 824
 }
825 825
 
826
-function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
827
-    if ( function_exists( 'mb_strtoupper' ) ) {
828
-        return mb_strtoupper( $str, $encoding );
826
+function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') {
827
+    if (function_exists('mb_strtoupper')) {
828
+        return mb_strtoupper($str, $encoding);
829 829
     }
830 830
     
831
-    return strtoupper( $str );
831
+    return strtoupper($str);
832 832
 }
833 833
 
834 834
 /**
@@ -842,12 +842,12 @@  discard block
 block discarded – undo
842 842
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
843 843
  * @return int Returns the position of the first occurrence of search in the string.
844 844
  */
845
-function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
846
-    if ( function_exists( 'mb_strpos' ) ) {
847
-        return mb_strpos( $str, $find, $offset, $encoding );
845
+function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
846
+    if (function_exists('mb_strpos')) {
847
+        return mb_strpos($str, $find, $offset, $encoding);
848 848
     }
849 849
         
850
-    return strpos( $str, $find, $offset );
850
+    return strpos($str, $find, $offset);
851 851
 }
852 852
 
853 853
 /**
@@ -861,12 +861,12 @@  discard block
 block discarded – undo
861 861
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
862 862
  * @return int Returns the position of the last occurrence of search.
863 863
  */
864
-function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
865
-    if ( function_exists( 'mb_strrpos' ) ) {
866
-        return mb_strrpos( $str, $find, $offset, $encoding );
864
+function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
865
+    if (function_exists('mb_strrpos')) {
866
+        return mb_strrpos($str, $find, $offset, $encoding);
867 867
     }
868 868
         
869
-    return strrpos( $str, $find, $offset );
869
+    return strrpos($str, $find, $offset);
870 870
 }
871 871
 
872 872
 /**
@@ -881,16 +881,16 @@  discard block
 block discarded – undo
881 881
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
882 882
  * @return string
883 883
  */
884
-function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) {
885
-    if ( function_exists( 'mb_substr' ) ) {
886
-        if ( $length === null ) {
887
-            return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding );
884
+function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') {
885
+    if (function_exists('mb_substr')) {
886
+        if ($length === null) {
887
+            return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding);
888 888
         } else {
889
-            return mb_substr( $str, $start, $length, $encoding );
889
+            return mb_substr($str, $start, $length, $encoding);
890 890
         }
891 891
     }
892 892
         
893
-    return substr( $str, $start, $length );
893
+    return substr($str, $start, $length);
894 894
 }
895 895
 
896 896
 /**
@@ -902,48 +902,48 @@  discard block
 block discarded – undo
902 902
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
903 903
  * @return string The width of string.
904 904
  */
905
-function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
906
-    if ( function_exists( 'mb_strwidth' ) ) {
907
-        return mb_strwidth( $str, $encoding );
905
+function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') {
906
+    if (function_exists('mb_strwidth')) {
907
+        return mb_strwidth($str, $encoding);
908 908
     }
909 909
     
910
-    return wpinv_utf8_strlen( $str, $encoding );
910
+    return wpinv_utf8_strlen($str, $encoding);
911 911
 }
912 912
 
913
-function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) {
914
-    if ( function_exists( 'mb_strlen' ) ) {
915
-        $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding );
913
+function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') {
914
+    if (function_exists('mb_strlen')) {
915
+        $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding);
916 916
         $str_end = "";
917 917
         
918
-        if ( $lower_str_end ) {
919
-            $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding );
918
+        if ($lower_str_end) {
919
+            $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding);
920 920
         } else {
921
-            $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding );
921
+            $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding);
922 922
         }
923 923
 
924 924
         return $first_letter . $str_end;
925 925
     }
926 926
     
927
-    return ucfirst( $str );
927
+    return ucfirst($str);
928 928
 }
929 929
 
930
-function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) {
931
-    if ( function_exists( 'mb_convert_case' ) ) {
932
-        return mb_convert_case( $str, MB_CASE_TITLE, $encoding );
930
+function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') {
931
+    if (function_exists('mb_convert_case')) {
932
+        return mb_convert_case($str, MB_CASE_TITLE, $encoding);
933 933
     }
934 934
     
935
-    return ucwords( $str );
935
+    return ucwords($str);
936 936
 }
937 937
 
938
-function wpinv_period_in_days( $period, $unit ) {
939
-    $period = absint( $period );
938
+function wpinv_period_in_days($period, $unit) {
939
+    $period = absint($period);
940 940
     
941
-    if ( $period > 0 ) {
942
-        if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) {
941
+    if ($period > 0) {
942
+        if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) {
943 943
             $period = $period * 7;
944
-        } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) {
944
+        } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) {
945 945
             $period = $period * 30;
946
-        } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) {
946
+        } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) {
947 947
             $period = $period * 365;
948 948
         }
949 949
     }
@@ -951,14 +951,14 @@  discard block
 block discarded – undo
951 951
     return $period;
952 952
 }
953 953
 
954
-function wpinv_cal_days_in_month( $calendar, $month, $year ) {
955
-    if ( function_exists( 'cal_days_in_month' ) ) {
956
-        return cal_days_in_month( $calendar, $month, $year );
954
+function wpinv_cal_days_in_month($calendar, $month, $year) {
955
+    if (function_exists('cal_days_in_month')) {
956
+        return cal_days_in_month($calendar, $month, $year);
957 957
     }
958 958
 
959 959
     // Fallback in case the calendar extension is not loaded in PHP
960 960
     // Only supports Gregorian calendar
961
-    return date( 't', mktime( 0, 0, 0, $month, 1, $year ) );
961
+    return date('t', mktime(0, 0, 0, $month, 1, $year));
962 962
 }
963 963
 
964 964
 /**
@@ -969,11 +969,11 @@  discard block
 block discarded – undo
969 969
  *
970 970
  * @return string
971 971
  */
972
-function wpi_help_tip( $tip, $allow_html = false ) {
973
-    if ( $allow_html ) {
974
-        $tip = wpi_sanitize_tooltip( $tip );
972
+function wpi_help_tip($tip, $allow_html = false) {
973
+    if ($allow_html) {
974
+        $tip = wpi_sanitize_tooltip($tip);
975 975
     } else {
976
-        $tip = esc_attr( $tip );
976
+        $tip = esc_attr($tip);
977 977
     }
978 978
 
979 979
     return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
@@ -987,8 +987,8 @@  discard block
 block discarded – undo
987 987
  * @param string $var
988 988
  * @return string
989 989
  */
990
-function wpi_sanitize_tooltip( $var ) {
991
-    return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
990
+function wpi_sanitize_tooltip($var) {
991
+    return htmlspecialchars(wp_kses(html_entity_decode($var), array(
992 992
         'br'     => array(),
993 993
         'em'     => array(),
994 994
         'strong' => array(),
@@ -998,7 +998,7 @@  discard block
 block discarded – undo
998 998
         'li'     => array(),
999 999
         'ol'     => array(),
1000 1000
         'p'      => array(),
1001
-    ) ) );
1001
+    )));
1002 1002
 }
1003 1003
 
1004 1004
 /**
@@ -1008,7 +1008,7 @@  discard block
 block discarded – undo
1008 1008
  */
1009 1009
 function wpinv_get_screen_ids() {
1010 1010
 
1011
-    $screen_id = sanitize_title( __( 'Invoicing', 'invoicing' ) );
1011
+    $screen_id = sanitize_title(__('Invoicing', 'invoicing'));
1012 1012
 
1013 1013
     $screen_ids = array(
1014 1014
         'toplevel_page_' . $screen_id,
@@ -1026,7 +1026,7 @@  discard block
 block discarded – undo
1026 1026
         'invoicing_page_wpi-addons',
1027 1027
     );
1028 1028
 
1029
-    return apply_filters( 'wpinv_screen_ids', $screen_ids );
1029
+    return apply_filters('wpinv_screen_ids', $screen_ids);
1030 1030
 }
1031 1031
 
1032 1032
 /**
@@ -1037,9 +1037,9 @@  discard block
 block discarded – undo
1037 1037
  * @param array|string $list List of values.
1038 1038
  * @return array Sanitized array of values.
1039 1039
  */
1040
-function wpinv_parse_list( $list ) {
1041
-	if ( ! is_array( $list ) ) {
1042
-		return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
1040
+function wpinv_parse_list($list) {
1041
+	if (!is_array($list)) {
1042
+		return preg_split('/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY);
1043 1043
 	}
1044 1044
 
1045 1045
 	return $list;
Please login to merge, or discard this patch.
includes/wpinv-invoice-functions.php 1 patch
Spacing   +768 added lines, -768 removed lines patch added patch discarded remove patch
@@ -7,14 +7,14 @@  discard block
 block discarded – undo
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_get_invoice_cart_id() {
15 15
     $wpinv_checkout = wpinv_get_checkout_session();
16 16
     
17
-    if ( !empty( $wpinv_checkout['invoice_id'] ) ) {
17
+    if (!empty($wpinv_checkout['invoice_id'])) {
18 18
         return $wpinv_checkout['invoice_id'];
19 19
     }
20 20
     
@@ -28,43 +28,43 @@  discard block
 block discarded – undo
28 28
  * @param  bool          $wp_error       Whether to return false or WP_Error on failure.
29 29
  * @return mixed         The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
30 30
  */
31
-function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) {
32
-    if ( empty( $invoice_data ) ) {
31
+function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) {
32
+    if (empty($invoice_data)) {
33 33
         return false;
34 34
     }
35 35
     
36
-    if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) {
37
-        return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast one item.', 'invoicing' ) ) : 0;
36
+    if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) {
37
+        return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast one item.', 'invoicing')) : 0;
38 38
     }
39 39
     
40 40
     // If no user id is provided, default to the current user id
41
-    if ( empty( $invoice_data['user_id'] ) ) {
41
+    if (empty($invoice_data['user_id'])) {
42 42
         $invoice_data['user_id'] = get_current_user_id();
43 43
     }
44 44
     
45
-    $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0;
45
+    $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int) $invoice_data['invoice_id'] : 0;
46 46
     
47
-    if ( empty( $invoice_data['status'] ) ) {
47
+    if (empty($invoice_data['status'])) {
48 48
         $invoice_data['status'] = 'wpi-pending';
49 49
     }
50 50
     
51
-    if ( empty( $invoice_data['ip'] ) ) {
51
+    if (empty($invoice_data['ip'])) {
52 52
         $invoice_data['ip'] = wpinv_get_ip();
53 53
     }
54 54
 
55 55
     // default invoice args, note that status is checked for validity in wpinv_create_invoice()
56 56
     $default_args = array(
57
-        'invoice_id'    => (int)$invoice_data['invoice_id'],
58
-        'user_id'       => (int)$invoice_data['user_id'],
57
+        'invoice_id'    => (int) $invoice_data['invoice_id'],
58
+        'user_id'       => (int) $invoice_data['user_id'],
59 59
         'status'        => $invoice_data['status'],
60 60
     );
61 61
 
62
-    $invoice = wpinv_create_invoice( $default_args, $invoice_data, true );
63
-    if ( is_wp_error( $invoice ) ) {
62
+    $invoice = wpinv_create_invoice($default_args, $invoice_data, true);
63
+    if (is_wp_error($invoice)) {
64 64
         return $wp_error ? $invoice : 0;
65 65
     }
66 66
     
67
-    if ( empty( $invoice_data['invoice_id'] ) ) {
67
+    if (empty($invoice_data['invoice_id'])) {
68 68
         //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) );
69 69
     }
70 70
     
@@ -87,24 +87,24 @@  discard block
 block discarded – undo
87 87
         'discount'              => array(),
88 88
     );
89 89
 
90
-    if ( $user_id = (int)$invoice->get_user_id() ) {
91
-        if ( $user_address = wpinv_get_user_address( $user_id ) ) {
92
-            $default_user_info = wp_parse_args( $user_address, $default_user_info );
90
+    if ($user_id = (int) $invoice->get_user_id()) {
91
+        if ($user_address = wpinv_get_user_address($user_id)) {
92
+            $default_user_info = wp_parse_args($user_address, $default_user_info);
93 93
         }
94 94
     }
95 95
     
96
-    if ( empty( $invoice_data['user_info'] ) ) {
96
+    if (empty($invoice_data['user_info'])) {
97 97
         $invoice_data['user_info'] = array();
98 98
     }
99 99
     
100
-    $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info );
100
+    $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info);
101 101
     
102
-    if ( empty( $user_info['first_name'] ) ) {
102
+    if (empty($user_info['first_name'])) {
103 103
         $user_info['first_name'] = $default_user_info['first_name'];
104 104
         $user_info['last_name'] = $default_user_info['last_name'];
105 105
     }
106 106
     
107
-    if ( empty( $user_info['country'] ) ) {
107
+    if (empty($user_info['country'])) {
108 108
         $user_info['country'] = $default_user_info['country'];
109 109
         $user_info['state'] = $default_user_info['state'];
110 110
         $user_info['city'] = $default_user_info['city'];
@@ -113,13 +113,13 @@  discard block
 block discarded – undo
113 113
         $user_info['phone'] = $default_user_info['phone'];
114 114
     }
115 115
     
116
-    if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) {
117
-        $user_info['discount'] = (array)$user_info['discount'];
116
+    if (!empty($user_info['discount']) && !is_array($user_info['discount'])) {
117
+        $user_info['discount'] = (array) $user_info['discount'];
118 118
     }
119 119
 
120 120
     // Payment details
121 121
     $payment_details = array();
122
-    if ( !empty( $invoice_data['payment_details'] ) ) {
122
+    if (!empty($invoice_data['payment_details'])) {
123 123
         $default_payment_details = array(
124 124
             'gateway'           => 'manual',
125 125
             'gateway_title'     => '',
@@ -127,56 +127,56 @@  discard block
 block discarded – undo
127 127
             'transaction_id'    => '',
128 128
         );
129 129
         
130
-        $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details );
130
+        $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details);
131 131
         
132
-        if ( empty( $payment_details['gateway'] ) ) {
132
+        if (empty($payment_details['gateway'])) {
133 133
             $payment_details['gateway'] = 'manual';
134 134
         }
135 135
         
136
-        if ( empty( $payment_details['currency'] ) ) {
136
+        if (empty($payment_details['currency'])) {
137 137
             $payment_details['currency'] = wpinv_get_default_country();
138 138
         }
139 139
         
140
-        if ( empty( $payment_details['gateway_title'] ) ) {
141
-            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] );
140
+        if (empty($payment_details['gateway_title'])) {
141
+            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']);
142 142
         }
143 143
     }
144 144
     
145
-    $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'wpi-pending' ) );
146
-    
147
-    if ( !empty( $payment_details ) ) {
148
-        $invoice->set( 'currency', $payment_details['currency'] );
149
-        $invoice->set( 'gateway', $payment_details['gateway'] );
150
-        $invoice->set( 'gateway_title', $payment_details['gateway_title'] );
151
-        $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
152
-    }
153
-    
154
-    $invoice->set( 'user_info', $user_info );
155
-    $invoice->set( 'first_name', $user_info['first_name'] );
156
-    $invoice->set( 'last_name', $user_info['last_name'] );
157
-    $invoice->set( 'address', $user_info['address'] );
158
-    $invoice->set( 'company', $user_info['company'] );
159
-    $invoice->set( 'vat_number', $user_info['vat_number'] );
160
-    $invoice->set( 'phone', $user_info['phone'] );
161
-    $invoice->set( 'city', $user_info['city'] );
162
-    $invoice->set( 'country', $user_info['country'] );
163
-    $invoice->set( 'state', $user_info['state'] );
164
-    $invoice->set( 'zip', $user_info['zip'] );
165
-    $invoice->set( 'discounts', $user_info['discount'] );
166
-    $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) );
167
-    $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) );
168
-    $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) );
169
-    
170
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) {
171
-        foreach ( $invoice_data['cart_details'] as $key => $item ) {
172
-            $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
173
-            $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
174
-            $name           = !empty( $item['name'] ) ? $item['name'] : '';
175
-            $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : '';
145
+    $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'wpi-pending'));
146
+    
147
+    if (!empty($payment_details)) {
148
+        $invoice->set('currency', $payment_details['currency']);
149
+        $invoice->set('gateway', $payment_details['gateway']);
150
+        $invoice->set('gateway_title', $payment_details['gateway_title']);
151
+        $invoice->set('transaction_id', $payment_details['transaction_id']);
152
+    }
153
+    
154
+    $invoice->set('user_info', $user_info);
155
+    $invoice->set('first_name', $user_info['first_name']);
156
+    $invoice->set('last_name', $user_info['last_name']);
157
+    $invoice->set('address', $user_info['address']);
158
+    $invoice->set('company', $user_info['company']);
159
+    $invoice->set('vat_number', $user_info['vat_number']);
160
+    $invoice->set('phone', $user_info['phone']);
161
+    $invoice->set('city', $user_info['city']);
162
+    $invoice->set('country', $user_info['country']);
163
+    $invoice->set('state', $user_info['state']);
164
+    $invoice->set('zip', $user_info['zip']);
165
+    $invoice->set('discounts', $user_info['discount']);
166
+    $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip()));
167
+    $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live'));
168
+    $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : ''));
169
+    
170
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) {
171
+        foreach ($invoice_data['cart_details'] as $key => $item) {
172
+            $item_id        = !empty($item['id']) ? $item['id'] : 0;
173
+            $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
174
+            $name           = !empty($item['name']) ? $item['name'] : '';
175
+            $item_price     = isset($item['item_price']) ? $item['item_price'] : '';
176 176
             
177
-            $post_item  = new WPInv_Item( $item_id );
178
-            if ( !empty( $post_item ) ) {
179
-                $name       = !empty( $name ) ? $name : $post_item->get_name();
177
+            $post_item = new WPInv_Item($item_id);
178
+            if (!empty($post_item)) {
179
+                $name       = !empty($name) ? $name : $post_item->get_name();
180 180
                 $item_price = $item_price !== '' ? $item_price : $post_item->get_price();
181 181
             } else {
182 182
                 continue;
@@ -186,253 +186,253 @@  discard block
 block discarded – undo
186 186
                 'name'          => $name,
187 187
                 'quantity'      => $quantity,
188 188
                 'item_price'    => $item_price,
189
-                'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
190
-                'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0.00,
191
-                'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
192
-                'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
193
-                'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
189
+                'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
190
+                'tax'           => !empty($item['tax']) ? $item['tax'] : 0.00,
191
+                'discount'      => isset($item['discount']) ? $item['discount'] : 0,
192
+                'meta'          => isset($item['meta']) ? $item['meta'] : array(),
193
+                'fees'          => isset($item['fees']) ? $item['fees'] : array(),
194 194
             );
195 195
 
196
-            $invoice->add_item( $item_id, $args );
196
+            $invoice->add_item($item_id, $args);
197 197
         }
198 198
     }
199 199
 
200
-    $invoice->increase_tax( wpinv_get_cart_fee_tax() );
200
+    $invoice->increase_tax(wpinv_get_cart_fee_tax());
201 201
 
202
-    if ( isset( $invoice_data['post_date'] ) ) {
203
-        $invoice->set( 'date', $invoice_data['post_date'] );
202
+    if (isset($invoice_data['post_date'])) {
203
+        $invoice->set('date', $invoice_data['post_date']);
204 204
     }
205 205
     
206 206
     // Invoice due date
207
-    if ( isset( $invoice_data['due_date'] ) ) {
208
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
207
+    if (isset($invoice_data['due_date'])) {
208
+        $invoice->set('due_date', $invoice_data['due_date']);
209 209
     }
210 210
     
211 211
     $invoice->save();
212 212
     
213 213
     // Add notes
214
-    if ( !empty( $invoice_data['private_note'] ) ) {
215
-        $invoice->add_note( $invoice_data['private_note'] );
214
+    if (!empty($invoice_data['private_note'])) {
215
+        $invoice->add_note($invoice_data['private_note']);
216 216
     }
217
-    if ( !empty( $invoice_data['user_note'] ) ) {
218
-        $invoice->add_note( $invoice_data['user_note'], true );
217
+    if (!empty($invoice_data['user_note'])) {
218
+        $invoice->add_note($invoice_data['user_note'], true);
219 219
     }
220 220
     
221
-    do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data );
221
+    do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data);
222 222
 
223
-    if ( ! empty( $invoice->ID ) ) {
223
+    if (!empty($invoice->ID)) {
224 224
         global $wpi_userID, $wpinv_ip_address_country;
225 225
         
226 226
         $checkout_session = wpinv_get_checkout_session();
227 227
         
228 228
         $data_session                   = array();
229 229
         $data_session['invoice_id']     = $invoice->ID;
230
-        $data_session['cart_discounts'] = $invoice->get_discounts( true );
230
+        $data_session['cart_discounts'] = $invoice->get_discounts(true);
231 231
         
232
-        wpinv_set_checkout_session( $data_session );
232
+        wpinv_set_checkout_session($data_session);
233 233
         
234
-        $wpi_userID         = (int)$invoice->get_user_id();
234
+        $wpi_userID         = (int) $invoice->get_user_id();
235 235
         
236
-        $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
236
+        $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
237 237
         $_POST['state']     = $invoice->state;
238 238
 
239
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
240
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
239
+        $invoice->set('country', sanitize_text_field($_POST['country']));
240
+        $invoice->set('state', sanitize_text_field($_POST['state']));
241 241
         
242 242
         $wpinv_ip_address_country = $invoice->country;
243 243
         
244
-        $invoice = $invoice->recalculate_totals( true );
244
+        $invoice = $invoice->recalculate_totals(true);
245 245
         
246
-        wpinv_set_checkout_session( $checkout_session );
246
+        wpinv_set_checkout_session($checkout_session);
247 247
                     
248 248
         return $invoice;
249 249
     }
250 250
     
251
-    if ( $wp_error ) {
252
-        if ( is_wp_error( $invoice ) ) {
251
+    if ($wp_error) {
252
+        if (is_wp_error($invoice)) {
253 253
             return $invoice;
254 254
         } else {
255
-            return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) );
255
+            return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing'));
256 256
         }
257 257
     } else {
258 258
         return 0;
259 259
     }
260 260
 }
261 261
 
262
-function wpinv_update_invoice( $invoice_data = array(), $wp_error = false ) {
263
-    $invoice_ID = !empty( $invoice_data['ID'] ) ? absint( $invoice_data['ID'] ) : NULL;
262
+function wpinv_update_invoice($invoice_data = array(), $wp_error = false) {
263
+    $invoice_ID = !empty($invoice_data['ID']) ? absint($invoice_data['ID']) : NULL;
264 264
 
265
-    if ( !$invoice_ID ) {
266
-        if ( $wp_error ) {
267
-            return new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) );
265
+    if (!$invoice_ID) {
266
+        if ($wp_error) {
267
+            return new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing'));
268 268
         }
269 269
         return 0;
270 270
     }
271 271
 
272
-    $invoice = wpinv_get_invoice( $invoice_ID );
272
+    $invoice = wpinv_get_invoice($invoice_ID);
273 273
 
274
-    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring( true ) : NULL;
274
+    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring(true) : NULL;
275 275
 
276
-    if ( empty( $invoice->ID ) ) {
277
-        if ( $wp_error ) {
278
-            return new WP_Error( 'invalid_invoice', __( 'Invalid invoice.', 'invoicing' ) );
276
+    if (empty($invoice->ID)) {
277
+        if ($wp_error) {
278
+            return new WP_Error('invalid_invoice', __('Invalid invoice.', 'invoicing'));
279 279
         }
280 280
         return 0;
281 281
     }
282 282
 
283
-    if ( !$invoice->has_status( array( 'wpi-pending' ) ) ) {
284
-        if ( $wp_error ) {
285
-            return new WP_Error( 'invalid_invoice_status', __( 'Only invoice with pending payment is allowed to update.', 'invoicing' ) );
283
+    if (!$invoice->has_status(array('wpi-pending'))) {
284
+        if ($wp_error) {
285
+            return new WP_Error('invalid_invoice_status', __('Only invoice with pending payment is allowed to update.', 'invoicing'));
286 286
         }
287 287
         return 0;
288 288
     }
289 289
 
290 290
     // Invoice status
291
-    if ( !empty( $invoice_data['status'] ) ) {
292
-        $invoice->set( 'status', $invoice_data['status'] );
291
+    if (!empty($invoice_data['status'])) {
292
+        $invoice->set('status', $invoice_data['status']);
293 293
     }
294 294
 
295 295
     // Invoice date
296
-    if ( !empty( $invoice_data['post_date'] ) ) {
297
-        $invoice->set( 'date', $invoice_data['post_date'] );
296
+    if (!empty($invoice_data['post_date'])) {
297
+        $invoice->set('date', $invoice_data['post_date']);
298 298
     }
299 299
 
300 300
     // Invoice due date
301
-    if ( isset( $invoice_data['due_date'] ) ) {
302
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
301
+    if (isset($invoice_data['due_date'])) {
302
+        $invoice->set('due_date', $invoice_data['due_date']);
303 303
     }
304 304
 
305 305
     // Invoice IP address
306
-    if ( !empty( $invoice_data['ip'] ) ) {
307
-        $invoice->set( 'ip', $invoice_data['ip'] );
306
+    if (!empty($invoice_data['ip'])) {
307
+        $invoice->set('ip', $invoice_data['ip']);
308 308
     }
309 309
     
310 310
     // User info
311
-    if ( !empty( $invoice_data['user_info'] ) && is_array( $invoice_data['user_info'] ) ) {
312
-        $user_info = wp_parse_args( $invoice_data['user_info'], $invoice->user_info );
311
+    if (!empty($invoice_data['user_info']) && is_array($invoice_data['user_info'])) {
312
+        $user_info = wp_parse_args($invoice_data['user_info'], $invoice->user_info);
313 313
 
314
-        if ( $discounts = $invoice->get_discounts() ) {
314
+        if ($discounts = $invoice->get_discounts()) {
315 315
             $set_discount = $discounts;
316 316
         } else {
317 317
             $set_discount = '';
318 318
         }
319 319
 
320 320
         // Manage discount
321
-        if ( !empty( $invoice_data['user_info']['discount'] ) ) {
321
+        if (!empty($invoice_data['user_info']['discount'])) {
322 322
             // Remove discount
323
-            if ( $invoice_data['user_info']['discount'] == 'none' ) {
323
+            if ($invoice_data['user_info']['discount'] == 'none') {
324 324
                 $set_discount = '';
325 325
             } else {
326 326
                 $set_discount = $invoice_data['user_info']['discount'];
327 327
             }
328 328
 
329
-            $invoice->set( 'discounts', $set_discount );
329
+            $invoice->set('discounts', $set_discount);
330 330
         }
331 331
 
332 332
         $user_info['discount'] = $set_discount;
333 333
 
334
-        $invoice->set( 'user_info', $user_info );
334
+        $invoice->set('user_info', $user_info);
335 335
     }
336 336
 
337
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) && $cart_details = $invoice_data['cart_details'] ) {
338
-        $remove_items = !empty( $cart_details['remove_items'] ) && is_array( $cart_details['remove_items'] ) ? $cart_details['remove_items'] : array();
337
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']) && $cart_details = $invoice_data['cart_details']) {
338
+        $remove_items = !empty($cart_details['remove_items']) && is_array($cart_details['remove_items']) ? $cart_details['remove_items'] : array();
339 339
 
340
-        if ( !empty( $remove_items[0]['id'] ) ) {
341
-            foreach ( $remove_items as $item ) {
342
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
343
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
344
-                if ( empty( $item_id ) ) {
340
+        if (!empty($remove_items[0]['id'])) {
341
+            foreach ($remove_items as $item) {
342
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
343
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
344
+                if (empty($item_id)) {
345 345
                     continue;
346 346
                 }
347 347
 
348
-                foreach ( $invoice->cart_details as $cart_index => $cart_item ) {
349
-                    if ( $item_id == $cart_item['id'] ) {
348
+                foreach ($invoice->cart_details as $cart_index => $cart_item) {
349
+                    if ($item_id == $cart_item['id']) {
350 350
                         $args = array(
351 351
                             'id'         => $item_id,
352 352
                             'quantity'   => $quantity,
353 353
                             'cart_index' => $cart_index
354 354
                         );
355 355
 
356
-                        $invoice->remove_item( $item_id, $args );
356
+                        $invoice->remove_item($item_id, $args);
357 357
                         break;
358 358
                     }
359 359
                 }
360 360
             }
361 361
         }
362 362
 
363
-        $add_items = !empty( $cart_details['add_items'] ) && is_array( $cart_details['add_items'] ) ? $cart_details['add_items'] : array();
363
+        $add_items = !empty($cart_details['add_items']) && is_array($cart_details['add_items']) ? $cart_details['add_items'] : array();
364 364
 
365
-        if ( !empty( $add_items[0]['id'] ) ) {
366
-            foreach ( $add_items as $item ) {
367
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
368
-                $post_item      = new WPInv_Item( $item_id );
369
-                if ( empty( $post_item ) ) {
365
+        if (!empty($add_items[0]['id'])) {
366
+            foreach ($add_items as $item) {
367
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
368
+                $post_item      = new WPInv_Item($item_id);
369
+                if (empty($post_item)) {
370 370
                     continue;
371 371
                 }
372 372
 
373 373
                 $valid_item = true;
374
-                if ( !empty( $recurring_item ) ) {
375
-                    if ( $recurring_item->ID != $item_id ) {
374
+                if (!empty($recurring_item)) {
375
+                    if ($recurring_item->ID != $item_id) {
376 376
                         $valid_item = false;
377 377
                     }
378
-                } else if ( wpinv_is_recurring_item( $item_id ) ) {
378
+                } else if (wpinv_is_recurring_item($item_id)) {
379 379
                     $valid_item = false;
380 380
                 }
381 381
                 
382
-                if ( !$valid_item ) {
383
-                    if ( $wp_error ) {
384
-                        return new WP_Error( 'invalid_invoice_item', __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ) );
382
+                if (!$valid_item) {
383
+                    if ($wp_error) {
384
+                        return new WP_Error('invalid_invoice_item', __('You can not add item because recurring item must be paid individually!', 'invoicing'));
385 385
                     }
386 386
                     return 0;
387 387
                 }
388 388
 
389
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
390
-                $name           = !empty( $item['name'] ) ? $item['name'] : $post_item->get_name();
391
-                $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : $post_item->get_price();
389
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
390
+                $name           = !empty($item['name']) ? $item['name'] : $post_item->get_name();
391
+                $item_price     = isset($item['item_price']) ? $item['item_price'] : $post_item->get_price();
392 392
 
393 393
                 $args = array(
394 394
                     'name'          => $name,
395 395
                     'quantity'      => $quantity,
396 396
                     'item_price'    => $item_price,
397
-                    'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
398
-                    'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0,
399
-                    'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
400
-                    'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
401
-                    'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
397
+                    'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
398
+                    'tax'           => !empty($item['tax']) ? $item['tax'] : 0,
399
+                    'discount'      => isset($item['discount']) ? $item['discount'] : 0,
400
+                    'meta'          => isset($item['meta']) ? $item['meta'] : array(),
401
+                    'fees'          => isset($item['fees']) ? $item['fees'] : array(),
402 402
                 );
403 403
 
404
-                $invoice->add_item( $item_id, $args );
404
+                $invoice->add_item($item_id, $args);
405 405
             }
406 406
         }
407 407
     }
408 408
     
409 409
     // Payment details
410
-    if ( !empty( $invoice_data['payment_details'] ) && $payment_details = $invoice_data['payment_details'] ) {
411
-        if ( !empty( $payment_details['gateway'] ) ) {
412
-            $invoice->set( 'gateway', $payment_details['gateway'] );
410
+    if (!empty($invoice_data['payment_details']) && $payment_details = $invoice_data['payment_details']) {
411
+        if (!empty($payment_details['gateway'])) {
412
+            $invoice->set('gateway', $payment_details['gateway']);
413 413
         }
414 414
 
415
-        if ( !empty( $payment_details['transaction_id'] ) ) {
416
-            $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
415
+        if (!empty($payment_details['transaction_id'])) {
416
+            $invoice->set('transaction_id', $payment_details['transaction_id']);
417 417
         }
418 418
     }
419 419
 
420
-    do_action( 'wpinv_pre_update_invoice', $invoice->ID, $invoice_data );
420
+    do_action('wpinv_pre_update_invoice', $invoice->ID, $invoice_data);
421 421
 
422 422
     // Parent invoice
423
-    if ( !empty( $invoice_data['parent'] ) ) {
424
-        $invoice->set( 'parent_invoice', $invoice_data['parent'] );
423
+    if (!empty($invoice_data['parent'])) {
424
+        $invoice->set('parent_invoice', $invoice_data['parent']);
425 425
     }
426 426
 
427 427
     // Save invoice data.
428 428
     $invoice->save();
429 429
     
430
-    if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) {
431
-        if ( $wp_error ) {
432
-            if ( is_wp_error( $invoice ) ) {
430
+    if (empty($invoice->ID) || is_wp_error($invoice)) {
431
+        if ($wp_error) {
432
+            if (is_wp_error($invoice)) {
433 433
                 return $invoice;
434 434
             } else {
435
-                return new WP_Error( 'wpinv_update_invoice_error', __( 'Error in update invoice.', 'invoicing' ) );
435
+                return new WP_Error('wpinv_update_invoice_error', __('Error in update invoice.', 'invoicing'));
436 436
             }
437 437
         } else {
438 438
             return 0;
@@ -440,13 +440,13 @@  discard block
 block discarded – undo
440 440
     }
441 441
 
442 442
     // Add private note
443
-    if ( !empty( $invoice_data['private_note'] ) ) {
444
-        $invoice->add_note( $invoice_data['private_note'] );
443
+    if (!empty($invoice_data['private_note'])) {
444
+        $invoice->add_note($invoice_data['private_note']);
445 445
     }
446 446
 
447 447
     // Add user note
448
-    if ( !empty( $invoice_data['user_note'] ) ) {
449
-        $invoice->add_note( $invoice_data['user_note'], true );
448
+    if (!empty($invoice_data['user_note'])) {
449
+        $invoice->add_note($invoice_data['user_note'], true);
450 450
     }
451 451
 
452 452
     global $wpi_userID, $wpinv_ip_address_country;
@@ -455,450 +455,450 @@  discard block
 block discarded – undo
455 455
 
456 456
     $data_session                   = array();
457 457
     $data_session['invoice_id']     = $invoice->ID;
458
-    $data_session['cart_discounts'] = $invoice->get_discounts( true );
458
+    $data_session['cart_discounts'] = $invoice->get_discounts(true);
459 459
 
460
-    wpinv_set_checkout_session( $data_session );
460
+    wpinv_set_checkout_session($data_session);
461 461
 
462
-    $wpi_userID         = (int)$invoice->get_user_id();
462
+    $wpi_userID         = (int) $invoice->get_user_id();
463 463
 
464
-    $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
464
+    $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
465 465
     $_POST['state']     = $invoice->state;
466 466
 
467
-    $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
468
-    $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
467
+    $invoice->set('country', sanitize_text_field($_POST['country']));
468
+    $invoice->set('state', sanitize_text_field($_POST['state']));
469 469
 
470 470
     $wpinv_ip_address_country = $invoice->country;
471 471
 
472
-    $invoice = $invoice->recalculate_totals( true );
472
+    $invoice = $invoice->recalculate_totals(true);
473 473
 
474
-    do_action( 'wpinv_post_update_invoice', $invoice->ID, $invoice_data );
474
+    do_action('wpinv_post_update_invoice', $invoice->ID, $invoice_data);
475 475
 
476
-    wpinv_set_checkout_session( $checkout_session );
476
+    wpinv_set_checkout_session($checkout_session);
477 477
 
478 478
     return $invoice;
479 479
 }
480 480
 
481
-function wpinv_get_invoice( $invoice_id = 0, $cart = false ) {
482
-    if ( $cart && empty( $invoice_id ) ) {
483
-        $invoice_id = (int)wpinv_get_invoice_cart_id();
481
+function wpinv_get_invoice($invoice_id = 0, $cart = false) {
482
+    if ($cart && empty($invoice_id)) {
483
+        $invoice_id = (int) wpinv_get_invoice_cart_id();
484 484
     }
485 485
 
486
-    $invoice = new WPInv_Invoice( $invoice_id );
486
+    $invoice = new WPInv_Invoice($invoice_id);
487 487
 
488
-    if ( ! empty( $invoice ) && ! empty( $invoice->ID ) ) {
488
+    if (!empty($invoice) && !empty($invoice->ID)) {
489 489
         return $invoice;
490 490
     }
491 491
     
492 492
     return NULL;
493 493
 }
494 494
 
495
-function wpinv_get_invoice_cart( $invoice_id = 0 ) {
496
-    return wpinv_get_invoice( $invoice_id, true );
495
+function wpinv_get_invoice_cart($invoice_id = 0) {
496
+    return wpinv_get_invoice($invoice_id, true);
497 497
 }
498 498
 
499
-function wpinv_get_invoice_description( $invoice_id = 0 ) {
500
-    $invoice = new WPInv_Invoice( $invoice_id );
499
+function wpinv_get_invoice_description($invoice_id = 0) {
500
+    $invoice = new WPInv_Invoice($invoice_id);
501 501
     return $invoice->get_description();
502 502
 }
503 503
 
504
-function wpinv_get_invoice_currency_code( $invoice_id = 0 ) {
505
-    $invoice = new WPInv_Invoice( $invoice_id );
504
+function wpinv_get_invoice_currency_code($invoice_id = 0) {
505
+    $invoice = new WPInv_Invoice($invoice_id);
506 506
     return $invoice->get_currency();
507 507
 }
508 508
 
509
-function wpinv_get_payment_user_email( $invoice_id ) {
510
-    $invoice = new WPInv_Invoice( $invoice_id );
509
+function wpinv_get_payment_user_email($invoice_id) {
510
+    $invoice = new WPInv_Invoice($invoice_id);
511 511
     return $invoice->get_email();
512 512
 }
513 513
 
514
-function wpinv_get_user_id( $invoice_id ) {
515
-    $invoice = new WPInv_Invoice( $invoice_id );
514
+function wpinv_get_user_id($invoice_id) {
515
+    $invoice = new WPInv_Invoice($invoice_id);
516 516
     return $invoice->get_user_id();
517 517
 }
518 518
 
519
-function wpinv_get_invoice_status( $invoice_id, $return_label = false ) {
520
-    $invoice = new WPInv_Invoice( $invoice_id );
519
+function wpinv_get_invoice_status($invoice_id, $return_label = false) {
520
+    $invoice = new WPInv_Invoice($invoice_id);
521 521
     
522
-    return $invoice->get_status( $return_label );
522
+    return $invoice->get_status($return_label);
523 523
 }
524 524
 
525
-function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) {
526
-    $invoice = new WPInv_Invoice( $invoice_id );
525
+function wpinv_get_payment_gateway($invoice_id, $return_label = false) {
526
+    $invoice = new WPInv_Invoice($invoice_id);
527 527
     
528
-    return $invoice->get_gateway( $return_label );
528
+    return $invoice->get_gateway($return_label);
529 529
 }
530 530
 
531
-function wpinv_get_payment_gateway_name( $invoice_id ) {
532
-    $invoice = new WPInv_Invoice( $invoice_id );
531
+function wpinv_get_payment_gateway_name($invoice_id) {
532
+    $invoice = new WPInv_Invoice($invoice_id);
533 533
     
534 534
     return $invoice->get_gateway_title();
535 535
 }
536 536
 
537
-function wpinv_get_payment_transaction_id( $invoice_id ) {
538
-    $invoice = new WPInv_Invoice( $invoice_id );
537
+function wpinv_get_payment_transaction_id($invoice_id) {
538
+    $invoice = new WPInv_Invoice($invoice_id);
539 539
     
540 540
     return $invoice->get_transaction_id();
541 541
 }
542 542
 
543
-function wpinv_get_id_by_transaction_id( $key ) {
543
+function wpinv_get_id_by_transaction_id($key) {
544 544
     global $wpdb;
545 545
 
546
-    $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) );
546
+    $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key));
547 547
 
548
-    if ( $invoice_id != NULL )
548
+    if ($invoice_id != NULL)
549 549
         return $invoice_id;
550 550
 
551 551
     return 0;
552 552
 }
553 553
 
554
-function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) {
555
-    $invoice = new WPInv_Invoice( $invoice_id );
554
+function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) {
555
+    $invoice = new WPInv_Invoice($invoice_id);
556 556
 
557
-    return $invoice->get_meta( $meta_key, $single );
557
+    return $invoice->get_meta($meta_key, $single);
558 558
 }
559 559
 
560
-function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) {
561
-    $invoice = new WPInv_Invoice( $invoice_id );
560
+function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') {
561
+    $invoice = new WPInv_Invoice($invoice_id);
562 562
     
563
-    return $invoice->update_meta( $meta_key, $meta_value, $prev_value );
563
+    return $invoice->update_meta($meta_key, $meta_value, $prev_value);
564 564
 }
565 565
 
566
-function wpinv_get_items( $invoice_id = 0 ) {
567
-    $invoice            = wpinv_get_invoice( $invoice_id );
566
+function wpinv_get_items($invoice_id = 0) {
567
+    $invoice            = wpinv_get_invoice($invoice_id);
568 568
     
569 569
     $items              = $invoice->get_items();
570 570
     $invoice_currency   = $invoice->get_currency();
571 571
 
572
-    if ( !empty( $items ) && is_array( $items ) ) {
573
-        foreach ( $items as $key => $item ) {
572
+    if (!empty($items) && is_array($items)) {
573
+        foreach ($items as $key => $item) {
574 574
             $items[$key]['currency'] = $invoice_currency;
575 575
 
576
-            if ( !isset( $item['subtotal'] ) ) {
576
+            if (!isset($item['subtotal'])) {
577 577
                 $items[$key]['subtotal'] = $items[$key]['amount'] * 1;
578 578
             }
579 579
         }
580 580
     }
581 581
 
582
-    return apply_filters( 'wpinv_get_items', $items, $invoice_id );
582
+    return apply_filters('wpinv_get_items', $items, $invoice_id);
583 583
 }
584 584
 
585
-function wpinv_get_fees( $invoice_id = 0 ) {
586
-    $invoice           = wpinv_get_invoice( $invoice_id );
585
+function wpinv_get_fees($invoice_id = 0) {
586
+    $invoice           = wpinv_get_invoice($invoice_id);
587 587
     $fees              = $invoice->get_fees();
588 588
 
589
-    return apply_filters( 'wpinv_get_fees', $fees, $invoice_id );
589
+    return apply_filters('wpinv_get_fees', $fees, $invoice_id);
590 590
 }
591 591
 
592
-function wpinv_get_invoice_ip( $invoice_id ) {
593
-    $invoice = new WPInv_Invoice( $invoice_id );
592
+function wpinv_get_invoice_ip($invoice_id) {
593
+    $invoice = new WPInv_Invoice($invoice_id);
594 594
     return $invoice->get_ip();
595 595
 }
596 596
 
597
-function wpinv_get_invoice_user_info( $invoice_id ) {
598
-    $invoice = new WPInv_Invoice( $invoice_id );
597
+function wpinv_get_invoice_user_info($invoice_id) {
598
+    $invoice = new WPInv_Invoice($invoice_id);
599 599
     return $invoice->get_user_info();
600 600
 }
601 601
 
602
-function wpinv_subtotal( $invoice_id = 0, $currency = false ) {
603
-    $invoice = new WPInv_Invoice( $invoice_id );
602
+function wpinv_subtotal($invoice_id = 0, $currency = false) {
603
+    $invoice = new WPInv_Invoice($invoice_id);
604 604
 
605
-    return $invoice->get_subtotal( $currency );
605
+    return $invoice->get_subtotal($currency);
606 606
 }
607 607
 
608
-function wpinv_tax( $invoice_id = 0, $currency = false ) {
609
-    $invoice = new WPInv_Invoice( $invoice_id );
608
+function wpinv_tax($invoice_id = 0, $currency = false) {
609
+    $invoice = new WPInv_Invoice($invoice_id);
610 610
 
611
-    return $invoice->get_tax( $currency );
611
+    return $invoice->get_tax($currency);
612 612
 }
613 613
 
614
-function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) {
615
-    $invoice = wpinv_get_invoice( $invoice_id );
614
+function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) {
615
+    $invoice = wpinv_get_invoice($invoice_id);
616 616
 
617
-    return $invoice->get_discount( $currency, $dash );
617
+    return $invoice->get_discount($currency, $dash);
618 618
 }
619 619
 
620
-function wpinv_discount_code( $invoice_id = 0 ) {
621
-    $invoice = new WPInv_Invoice( $invoice_id );
620
+function wpinv_discount_code($invoice_id = 0) {
621
+    $invoice = new WPInv_Invoice($invoice_id);
622 622
 
623 623
     return $invoice->get_discount_code();
624 624
 }
625 625
 
626
-function wpinv_payment_total( $invoice_id = 0, $currency = false ) {
627
-    $invoice = new WPInv_Invoice( $invoice_id );
626
+function wpinv_payment_total($invoice_id = 0, $currency = false) {
627
+    $invoice = new WPInv_Invoice($invoice_id);
628 628
 
629
-    return $invoice->get_total( $currency );
629
+    return $invoice->get_total($currency);
630 630
 }
631 631
 
632
-function wpinv_get_date_created( $invoice_id = 0, $format = '' ) {
633
-    $invoice = new WPInv_Invoice( $invoice_id );
632
+function wpinv_get_date_created($invoice_id = 0, $format = '') {
633
+    $invoice = new WPInv_Invoice($invoice_id);
634 634
 
635
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
635
+    $format         = !empty($format) ? $format : get_option('date_format');
636 636
     $date_created   = $invoice->get_created_date();
637
-    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : '';
637
+    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : '';
638 638
 
639 639
     return $date_created;
640 640
 }
641 641
 
642
-function wpinv_get_invoice_date( $invoice_id = 0, $format = '', $default = true ) {
643
-    $invoice = new WPInv_Invoice( $invoice_id );
642
+function wpinv_get_invoice_date($invoice_id = 0, $format = '', $default = true) {
643
+    $invoice = new WPInv_Invoice($invoice_id);
644 644
     
645
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
645
+    $format         = !empty($format) ? $format : get_option('date_format');
646 646
     $date_completed = $invoice->get_completed_date();
647
-    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : '';
648
-    if ( $invoice_date == '' && $default ) {
649
-        $invoice_date   = wpinv_get_date_created( $invoice_id, $format );
647
+    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : '';
648
+    if ($invoice_date == '' && $default) {
649
+        $invoice_date = wpinv_get_date_created($invoice_id, $format);
650 650
     }
651 651
 
652 652
     return $invoice_date;
653 653
 }
654 654
 
655
-function wpinv_get_invoice_vat_number( $invoice_id = 0 ) {
656
-    $invoice = new WPInv_Invoice( $invoice_id );
655
+function wpinv_get_invoice_vat_number($invoice_id = 0) {
656
+    $invoice = new WPInv_Invoice($invoice_id);
657 657
     
658 658
     return $invoice->vat_number;
659 659
 }
660 660
 
661
-function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) {
662
-    $invoice = new WPInv_Invoice( $invoice_id );
661
+function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) {
662
+    $invoice = new WPInv_Invoice($invoice_id);
663 663
 
664
-    return $invoice->add_note( $note, $user_type, $added_by_user, $system );
664
+    return $invoice->add_note($note, $user_type, $added_by_user, $system);
665 665
 }
666 666
 
667
-function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) {
667
+function wpinv_get_invoice_notes($invoice_id = 0, $type = '') {
668 668
     global $invoicing;
669 669
     
670
-    if ( empty( $invoice_id ) ) {
670
+    if (empty($invoice_id)) {
671 671
         return NULL;
672 672
     }
673 673
     
674
-    $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type );
674
+    $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type);
675 675
     
676
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type );
676
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type);
677 677
 }
678 678
 
679
-function wpinv_get_payment_key( $invoice_id = 0 ) {
680
-	$invoice = new WPInv_Invoice( $invoice_id );
679
+function wpinv_get_payment_key($invoice_id = 0) {
680
+	$invoice = new WPInv_Invoice($invoice_id);
681 681
     return $invoice->get_key();
682 682
 }
683 683
 
684
-function wpinv_get_invoice_number( $invoice_id = 0 ) {
685
-    $invoice = new WPInv_Invoice( $invoice_id );
684
+function wpinv_get_invoice_number($invoice_id = 0) {
685
+    $invoice = new WPInv_Invoice($invoice_id);
686 686
     return $invoice->get_number();
687 687
 }
688 688
 
689
-function wpinv_get_cart_discountable_subtotal( $code_id ) {
689
+function wpinv_get_cart_discountable_subtotal($code_id) {
690 690
     $cart_items = wpinv_get_cart_content_details();
691 691
     $items      = array();
692 692
 
693
-    $excluded_items = wpinv_get_discount_excluded_items( $code_id );
693
+    $excluded_items = wpinv_get_discount_excluded_items($code_id);
694 694
 
695
-    if( $cart_items ) {
695
+    if ($cart_items) {
696 696
 
697
-        foreach( $cart_items as $item ) {
697
+        foreach ($cart_items as $item) {
698 698
 
699
-            if( ! in_array( $item['id'], $excluded_items ) ) {
700
-                $items[] =  $item;
699
+            if (!in_array($item['id'], $excluded_items)) {
700
+                $items[] = $item;
701 701
             }
702 702
         }
703 703
     }
704 704
 
705
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
705
+    $subtotal = wpinv_get_cart_items_subtotal($items);
706 706
 
707
-    return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal );
707
+    return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal);
708 708
 }
709 709
 
710
-function wpinv_get_cart_items_subtotal( $items ) {
710
+function wpinv_get_cart_items_subtotal($items) {
711 711
     $subtotal = 0.00;
712 712
 
713
-    if ( is_array( $items ) && ! empty( $items ) ) {
714
-        $prices = wp_list_pluck( $items, 'subtotal' );
713
+    if (is_array($items) && !empty($items)) {
714
+        $prices = wp_list_pluck($items, 'subtotal');
715 715
 
716
-        if( is_array( $prices ) ) {
717
-            $subtotal = array_sum( $prices );
716
+        if (is_array($prices)) {
717
+            $subtotal = array_sum($prices);
718 718
         } else {
719 719
             $subtotal = 0.00;
720 720
         }
721 721
 
722
-        if( $subtotal < 0 ) {
722
+        if ($subtotal < 0) {
723 723
             $subtotal = 0.00;
724 724
         }
725 725
     }
726 726
 
727
-    return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal );
727
+    return apply_filters('wpinv_get_cart_items_subtotal', $subtotal);
728 728
 }
729 729
 
730
-function wpinv_get_cart_subtotal( $items = array() ) {
731
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
732
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
730
+function wpinv_get_cart_subtotal($items = array()) {
731
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
732
+    $subtotal = wpinv_get_cart_items_subtotal($items);
733 733
 
734
-    return apply_filters( 'wpinv_get_cart_subtotal', $subtotal );
734
+    return apply_filters('wpinv_get_cart_subtotal', $subtotal);
735 735
 }
736 736
 
737
-function wpinv_cart_subtotal( $items = array() ) {
738
-    $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ) );
737
+function wpinv_cart_subtotal($items = array()) {
738
+    $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items)));
739 739
 
740 740
     return $price;
741 741
 }
742 742
 
743
-function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) {
744
-    $subtotal  = (float)wpinv_get_cart_subtotal( $items );
745
-    $discounts = (float)wpinv_get_cart_discounted_amount( $items );
746
-    $cart_tax  = (float)wpinv_get_cart_tax( $items );
747
-    $fees      = (float)wpinv_get_cart_fee_total();
748
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
743
+function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) {
744
+    $subtotal  = (float) wpinv_get_cart_subtotal($items);
745
+    $discounts = (float) wpinv_get_cart_discounted_amount($items);
746
+    $cart_tax  = (float) wpinv_get_cart_tax($items);
747
+    $fees      = (float) wpinv_get_cart_fee_total();
748
+    if (!empty($invoice) && $invoice->is_free_trial()) {
749 749
         $total = 0;
750 750
     } else {
751
-        $total     = $subtotal - $discounts + $cart_tax + $fees;
751
+        $total = $subtotal - $discounts + $cart_tax + $fees;
752 752
     }
753 753
 
754
-    if ( $total < 0 ) {
754
+    if ($total < 0) {
755 755
         $total = 0.00;
756 756
     }
757 757
     
758
-    $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items );
758
+    $total = (float) apply_filters('wpinv_get_cart_total', $total, $items);
759 759
 
760
-    return wpinv_sanitize_amount( $total );
760
+    return wpinv_sanitize_amount($total);
761 761
 }
762 762
 
763
-function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) {
763
+function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) {
764 764
     global $cart_total;
765
-    $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ) );
766
-    $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice );
765
+    $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice)));
766
+    $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice);
767 767
     
768 768
     $cart_total = $total;
769 769
 
770
-    if ( !$echo ) {
770
+    if (!$echo) {
771 771
         return $total;
772 772
     }
773 773
 
774 774
     echo $total;
775 775
 }
776 776
 
777
-function wpinv_get_cart_tax( $items = array() ) {
777
+function wpinv_get_cart_tax($items = array()) {
778 778
     $cart_tax = 0;
779
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
779
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
780 780
 
781
-    if ( $items ) {
782
-        $taxes = wp_list_pluck( $items, 'tax' );
781
+    if ($items) {
782
+        $taxes = wp_list_pluck($items, 'tax');
783 783
 
784
-        if( is_array( $taxes ) ) {
785
-            $cart_tax = array_sum( $taxes );
784
+        if (is_array($taxes)) {
785
+            $cart_tax = array_sum($taxes);
786 786
         }
787 787
     }
788 788
 
789 789
     $cart_tax += wpinv_get_cart_fee_tax();
790 790
 
791
-    return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) );
791
+    return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax));
792 792
 }
793 793
 
794
-function wpinv_cart_tax( $items = array(), $echo = false ) {
795
-    $cart_tax = wpinv_get_cart_tax( $items );
796
-    $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ) );
794
+function wpinv_cart_tax($items = array(), $echo = false) {
795
+    $cart_tax = wpinv_get_cart_tax($items);
796
+    $cart_tax = wpinv_price(wpinv_format_amount($cart_tax));
797 797
 
798
-    $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items );
798
+    $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items);
799 799
 
800
-    if ( !$echo ) {
800
+    if (!$echo) {
801 801
         return $tax;
802 802
     }
803 803
 
804 804
     echo $tax;
805 805
 }
806 806
 
807
-function wpinv_get_cart_discount_code( $items = array() ) {
807
+function wpinv_get_cart_discount_code($items = array()) {
808 808
     $invoice = wpinv_get_invoice_cart();
809
-    $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : '';
809
+    $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : '';
810 810
     
811
-    return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code );
811
+    return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code);
812 812
 }
813 813
 
814
-function wpinv_cart_discount_code( $items = array(), $echo = false ) {
815
-    $cart_discount_code = wpinv_get_cart_discount_code( $items );
814
+function wpinv_cart_discount_code($items = array(), $echo = false) {
815
+    $cart_discount_code = wpinv_get_cart_discount_code($items);
816 816
 
817
-    if ( $cart_discount_code != '' ) {
817
+    if ($cart_discount_code != '') {
818 818
         $cart_discount_code = ' (' . $cart_discount_code . ')';
819 819
     }
820 820
     
821
-    $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items );
821
+    $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items);
822 822
 
823
-    if ( !$echo ) {
823
+    if (!$echo) {
824 824
         return $discount_code;
825 825
     }
826 826
 
827 827
     echo $discount_code;
828 828
 }
829 829
 
830
-function wpinv_get_cart_discount( $items = array() ) {
830
+function wpinv_get_cart_discount($items = array()) {
831 831
     $invoice = wpinv_get_invoice_cart();
832
-    $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0;
832
+    $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0;
833 833
     
834
-    return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items );
834
+    return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items);
835 835
 }
836 836
 
837
-function wpinv_cart_discount( $items = array(), $echo = false ) {
838
-    $cart_discount = wpinv_get_cart_discount( $items );
839
-    $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) );
837
+function wpinv_cart_discount($items = array(), $echo = false) {
838
+    $cart_discount = wpinv_get_cart_discount($items);
839
+    $cart_discount = wpinv_price(wpinv_format_amount($cart_discount));
840 840
 
841
-    $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items );
841
+    $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items);
842 842
 
843
-    if ( !$echo ) {
843
+    if (!$echo) {
844 844
         return $discount;
845 845
     }
846 846
 
847 847
     echo $discount;
848 848
 }
849 849
 
850
-function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) {
851
-    $item = new WPInv_Item( $item_id );
850
+function wpinv_get_cart_fees($type = 'all', $item_id = 0) {
851
+    $item = new WPInv_Item($item_id);
852 852
     
853
-    return $item->get_fees( $type, $item_id );
853
+    return $item->get_fees($type, $item_id);
854 854
 }
855 855
 
856 856
 function wpinv_get_cart_fee_total() {
857
-    $total  = 0;
857
+    $total = 0;
858 858
     $fees = wpinv_get_cart_fees();
859 859
     
860
-    if ( $fees ) {
861
-        foreach ( $fees as $fee_id => $fee ) {
860
+    if ($fees) {
861
+        foreach ($fees as $fee_id => $fee) {
862 862
             $total += $fee['amount'];
863 863
         }
864 864
     }
865 865
 
866
-    return apply_filters( 'wpinv_get_cart_fee_total', $total );
866
+    return apply_filters('wpinv_get_cart_fee_total', $total);
867 867
 }
868 868
 
869 869
 function wpinv_get_cart_fee_tax() {
870 870
     $tax  = 0;
871 871
     $fees = wpinv_get_cart_fees();
872 872
 
873
-    if ( $fees ) {
874
-        foreach ( $fees as $fee_id => $fee ) {
875
-            if( ! empty( $fee['no_tax'] ) ) {
873
+    if ($fees) {
874
+        foreach ($fees as $fee_id => $fee) {
875
+            if (!empty($fee['no_tax'])) {
876 876
                 continue;
877 877
             }
878 878
 
879
-            $tax += wpinv_calculate_tax( $fee['amount'] );
879
+            $tax += wpinv_calculate_tax($fee['amount']);
880 880
         }
881 881
     }
882 882
 
883
-    return apply_filters( 'wpinv_get_cart_fee_tax', $tax );
883
+    return apply_filters('wpinv_get_cart_fee_tax', $tax);
884 884
 }
885 885
 
886 886
 function wpinv_cart_has_recurring_item() {
887 887
     $cart_items = wpinv_get_cart_contents();
888 888
     
889
-    if ( empty( $cart_items ) ) {
889
+    if (empty($cart_items)) {
890 890
         return false;
891 891
     }
892 892
     
893 893
     $has_subscription = false;
894
-    foreach( $cart_items as $cart_item ) {
895
-        if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
894
+    foreach ($cart_items as $cart_item) {
895
+        if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
896 896
             $has_subscription = true;
897 897
             break;
898 898
         }
899 899
     }
900 900
     
901
-    return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items );
901
+    return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items);
902 902
 }
903 903
 
904 904
 function wpinv_cart_has_free_trial() {
@@ -906,97 +906,97 @@  discard block
 block discarded – undo
906 906
     
907 907
     $free_trial = false;
908 908
     
909
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
909
+    if (!empty($invoice) && $invoice->is_free_trial()) {
910 910
         $free_trial = true;
911 911
     }
912 912
     
913
-    return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice );
913
+    return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice);
914 914
 }
915 915
 
916 916
 function wpinv_get_cart_contents() {
917 917
     $cart_details = wpinv_get_cart_details();
918 918
     
919
-    return apply_filters( 'wpinv_get_cart_contents', $cart_details );
919
+    return apply_filters('wpinv_get_cart_contents', $cart_details);
920 920
 }
921 921
 
922 922
 function wpinv_get_cart_content_details() {
923 923
     global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
924 924
     $cart_items = wpinv_get_cart_contents();
925 925
     
926
-    if ( empty( $cart_items ) ) {
926
+    if (empty($cart_items)) {
927 927
         return false;
928 928
     }
929 929
     $invoice = wpinv_get_invoice_cart();
930
-	if ( empty( $invoice ) ) {
930
+	if (empty($invoice)) {
931 931
         return false;
932 932
     }
933 933
 
934 934
     $details = array();
935
-    $length  = count( $cart_items ) - 1;
935
+    $length  = count($cart_items) - 1;
936 936
     
937
-    if ( empty( $_POST['country'] ) ) {
937
+    if (empty($_POST['country'])) {
938 938
         $_POST['country'] = $invoice->country;
939 939
     }
940
-    if ( !isset( $_POST['state'] ) ) {
940
+    if (!isset($_POST['state'])) {
941 941
         $_POST['state'] = $invoice->state;
942 942
     }
943 943
 
944
-    foreach( $cart_items as $key => $item ) {
945
-        $item_id            = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : '';
946
-        if ( empty( $item_id ) ) {
944
+    foreach ($cart_items as $key => $item) {
945
+        $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : '';
946
+        if (empty($item_id)) {
947 947
             continue;
948 948
         }
949 949
         
950 950
         $wpi_current_id         = $invoice->ID;
951 951
         $wpi_item_id            = $item_id;
952 952
         
953
-        if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) {
953
+        if (isset($item['custom_price']) && $item['custom_price'] !== '') {
954 954
             $item_price = $item['custom_price'];
955 955
         } else {
956
-            if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) {
956
+            if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) {
957 957
                 $item_price = $item['item_price'];
958 958
             } else {
959
-                $item_price = wpinv_get_item_price( $item_id );
959
+                $item_price = wpinv_get_item_price($item_id);
960 960
             }
961 961
         }
962
-        $discount           = wpinv_get_cart_item_discount_amount( $item );
963
-        $discount           = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item );
964
-        $quantity           = wpinv_get_cart_item_quantity( $item );
965
-        $fees               = wpinv_get_cart_fees( 'fee', $item_id );
962
+        $discount           = wpinv_get_cart_item_discount_amount($item);
963
+        $discount           = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item);
964
+        $quantity           = wpinv_get_cart_item_quantity($item);
965
+        $fees               = wpinv_get_cart_fees('fee', $item_id);
966 966
         
967 967
         $subtotal           = $item_price * $quantity;
968
-        $tax_rate           = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id );
969
-        $tax_class          = $wpinv_euvat->get_item_class( $item_id );
970
-        $tax                = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount );
968
+        $tax_rate           = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id);
969
+        $tax_class          = $wpinv_euvat->get_item_class($item_id);
970
+        $tax                = wpinv_get_cart_item_tax($item_id, $subtotal - $discount);
971 971
         
972
-        if ( wpinv_prices_include_tax() ) {
973
-            $subtotal -= wpinv_round_amount( $tax );
972
+        if (wpinv_prices_include_tax()) {
973
+            $subtotal -= wpinv_round_amount($tax);
974 974
         }
975 975
         
976
-        $total              = $subtotal - $discount + $tax;
976
+        $total = $subtotal - $discount + $tax;
977 977
         
978 978
         // Do not allow totals to go negatve
979
-        if( $total < 0 ) {
979
+        if ($total < 0) {
980 980
             $total = 0;
981 981
         }
982 982
         
983
-        $details[ $key ]  = array(
983
+        $details[$key] = array(
984 984
             'id'                => $item_id,
985
-            'name'              => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ),
986
-            'item_price'        => wpinv_round_amount( $item_price ),
987
-            'custom_price'      => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
985
+            'name'              => !empty($item['name']) ? $item['name'] : get_the_title($item_id),
986
+            'item_price'        => wpinv_round_amount($item_price),
987
+            'custom_price'      => isset($item['custom_price']) ? $item['custom_price'] : '',
988 988
             'quantity'          => $quantity,
989
-            'discount'          => wpinv_round_amount( $discount ),
990
-            'subtotal'          => wpinv_round_amount( $subtotal ),
991
-            'tax'               => wpinv_round_amount( $tax ),
992
-            'price'             => wpinv_round_amount( $total ),
989
+            'discount'          => wpinv_round_amount($discount),
990
+            'subtotal'          => wpinv_round_amount($subtotal),
991
+            'tax'               => wpinv_round_amount($tax),
992
+            'price'             => wpinv_round_amount($total),
993 993
             'vat_rates_class'   => $tax_class,
994 994
             'vat_rate'          => $tax_rate,
995
-            'meta'              => isset( $item['meta'] ) ? $item['meta'] : array(),
995
+            'meta'              => isset($item['meta']) ? $item['meta'] : array(),
996 996
             'fees'              => $fees,
997 997
         );
998 998
         
999
-        if ( $wpinv_is_last_cart_item ) {
999
+        if ($wpinv_is_last_cart_item) {
1000 1000
             $wpinv_is_last_cart_item   = false;
1001 1001
             $wpinv_flat_discount_total = 0.00;
1002 1002
         }
@@ -1005,67 +1005,67 @@  discard block
 block discarded – undo
1005 1005
     return $details;
1006 1006
 }
1007 1007
 
1008
-function wpinv_get_cart_details( $invoice_id = 0 ) {
1008
+function wpinv_get_cart_details($invoice_id = 0) {
1009 1009
     global $ajax_cart_details;
1010 1010
 
1011
-    $invoice      = wpinv_get_invoice_cart( $invoice_id );
1011
+    $invoice      = wpinv_get_invoice_cart($invoice_id);
1012 1012
     $cart_details = $ajax_cart_details;
1013
-    if ( empty( $cart_details ) && ! empty( $invoice->cart_details ) ) {
1013
+    if (empty($cart_details) && !empty($invoice->cart_details)) {
1014 1014
         $cart_details = $invoice->cart_details;
1015 1015
     }
1016 1016
 
1017
-    if ( ! empty( $cart_details ) && is_array( $cart_details ) ) {
1018
-        $invoice_currency = ! empty( $invoice->currency ) ? $invoice->currency : wpinv_get_default_country();
1017
+    if (!empty($cart_details) && is_array($cart_details)) {
1018
+        $invoice_currency = !empty($invoice->currency) ? $invoice->currency : wpinv_get_default_country();
1019 1019
 
1020
-        foreach ( $cart_details as $key => $cart_item ) {
1021
-            $cart_details[ $key ]['currency'] = $invoice_currency;
1020
+        foreach ($cart_details as $key => $cart_item) {
1021
+            $cart_details[$key]['currency'] = $invoice_currency;
1022 1022
 
1023
-            if ( ! isset( $cart_item['subtotal'] ) ) {
1024
-                $cart_details[ $key ]['subtotal'] = $cart_item['price'];
1023
+            if (!isset($cart_item['subtotal'])) {
1024
+                $cart_details[$key]['subtotal'] = $cart_item['price'];
1025 1025
             }
1026 1026
         }
1027 1027
     }
1028 1028
 
1029
-    return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id );
1029
+    return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id);
1030 1030
 }
1031 1031
 
1032
-function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) {
1033
-    if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) {
1032
+function wpinv_record_status_change($invoice_id, $new_status, $old_status) {
1033
+    if ('wpi_invoice' != get_post_type($invoice_id)) {
1034 1034
         return;
1035 1035
     }
1036 1036
 
1037
-    if ( ( $old_status == 'wpi-pending' && $new_status == 'draft' ) || ( $old_status == 'draft' && $new_status == 'wpi-pending' ) ) {
1037
+    if (($old_status == 'wpi-pending' && $new_status == 'draft') || ($old_status == 'draft' && $new_status == 'wpi-pending')) {
1038 1038
         return;
1039 1039
     }
1040 1040
 
1041
-    $invoice    = wpinv_get_invoice( $invoice_id );
1041
+    $invoice    = wpinv_get_invoice($invoice_id);
1042 1042
     
1043
-    $old_status = wpinv_status_nicename( $old_status );
1044
-    $new_status = wpinv_status_nicename( $new_status );
1043
+    $old_status = wpinv_status_nicename($old_status);
1044
+    $new_status = wpinv_status_nicename($new_status);
1045 1045
 
1046
-    $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status );
1046
+    $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status);
1047 1047
     
1048 1048
     // Add note
1049
-    return $invoice->add_note( $status_change, false, false, true );
1049
+    return $invoice->add_note($status_change, false, false, true);
1050 1050
 }
1051
-add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 );
1051
+add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3);
1052 1052
 
1053
-function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) {
1053
+function wpinv_complete_payment($invoice_id, $new_status, $old_status) {
1054 1054
     global $wpi_has_free_trial;
1055 1055
     
1056 1056
     $wpi_has_free_trial = false;
1057 1057
     
1058
-    if ( $old_status == 'publish' ) {
1058
+    if ($old_status == 'publish') {
1059 1059
         return; // Make sure that payments are only paid once
1060 1060
     }
1061 1061
 
1062 1062
     // Make sure the payment completion is only processed when new status is paid
1063
-    if ( $new_status != 'publish' ) {
1063
+    if ($new_status != 'publish') {
1064 1064
         return;
1065 1065
     }
1066 1066
 
1067
-    $invoice = new WPInv_Invoice( $invoice_id );
1068
-    if ( empty( $invoice ) ) {
1067
+    $invoice = new WPInv_Invoice($invoice_id);
1068
+    if (empty($invoice)) {
1069 1069
         return;
1070 1070
     }
1071 1071
 
@@ -1073,58 +1073,58 @@  discard block
 block discarded – undo
1073 1073
     $completed_date = $invoice->completed_date;
1074 1074
     $cart_details   = $invoice->cart_details;
1075 1075
 
1076
-    do_action( 'wpinv_pre_complete_payment', $invoice_id );
1076
+    do_action('wpinv_pre_complete_payment', $invoice_id);
1077 1077
 
1078
-    if ( is_array( $cart_details ) ) {
1078
+    if (is_array($cart_details)) {
1079 1079
         // Increase purchase count and earnings
1080
-        foreach ( $cart_details as $cart_index => $item ) {
1080
+        foreach ($cart_details as $cart_index => $item) {
1081 1081
             // Ensure these actions only run once, ever
1082
-            if ( empty( $completed_date ) ) {
1083
-                do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index );
1082
+            if (empty($completed_date)) {
1083
+                do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index);
1084 1084
             }
1085 1085
         }
1086 1086
     }
1087 1087
     
1088 1088
     // Check for discount codes and increment their use counts
1089
-    if ( $discounts = $invoice->get_discounts( true ) ) {
1090
-        if( ! empty( $discounts ) ) {
1091
-            foreach( $discounts as $code ) {
1092
-                wpinv_increase_discount_usage( $code );
1089
+    if ($discounts = $invoice->get_discounts(true)) {
1090
+        if (!empty($discounts)) {
1091
+            foreach ($discounts as $code) {
1092
+                wpinv_increase_discount_usage($code);
1093 1093
             }
1094 1094
         }
1095 1095
     }
1096 1096
     
1097 1097
     // Ensure this action only runs once ever
1098
-    if( empty( $completed_date ) ) {
1098
+    if (empty($completed_date)) {
1099 1099
         // Save the completed date
1100
-        $invoice->set( 'completed_date', current_time( 'mysql', 0 ) );
1100
+        $invoice->set('completed_date', current_time('mysql', 0));
1101 1101
         $invoice->save();
1102 1102
 
1103
-        do_action( 'wpinv_complete_payment', $invoice_id );
1103
+        do_action('wpinv_complete_payment', $invoice_id);
1104 1104
     }
1105 1105
 
1106 1106
     // Empty the shopping cart
1107 1107
     wpinv_empty_cart();
1108 1108
 }
1109
-add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 );
1109
+add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3);
1110 1110
 
1111
-function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) {    
1112
-    $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id );
1111
+function wpinv_update_payment_status($invoice_id, $new_status = 'publish') {    
1112
+    $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int) $invoice_id);
1113 1113
     
1114
-    if ( empty( $invoice ) ) {
1114
+    if (empty($invoice)) {
1115 1115
         return false;
1116 1116
     }
1117 1117
     
1118
-    return $invoice->update_status( $new_status );
1118
+    return $invoice->update_status($new_status);
1119 1119
 }
1120 1120
 
1121
-function wpinv_cart_has_fees( $type = 'all' ) {
1121
+function wpinv_cart_has_fees($type = 'all') {
1122 1122
     return false;
1123 1123
 }
1124 1124
 
1125 1125
 function wpinv_validate_checkout_fields() {    
1126 1126
     // Check if there is $_POST
1127
-    if ( empty( $_POST ) ) {
1127
+    if (empty($_POST)) {
1128 1128
         return false;
1129 1129
     }
1130 1130
     
@@ -1136,11 +1136,11 @@  discard block
 block discarded – undo
1136 1136
     );
1137 1137
     
1138 1138
     // Validate agree to terms
1139
-    $page = wpinv_get_option( 'tandc_page' );
1140
-    if(isset($page) && (int)$page > 0 && apply_filters( 'wpinv_checkout_show_terms', true )){
1139
+    $page = wpinv_get_option('tandc_page');
1140
+    if (isset($page) && (int) $page > 0 && apply_filters('wpinv_checkout_show_terms', true)) {
1141 1141
         // Validate agree to terms
1142
-        if ( ! isset( $_POST['wpi_terms'] ) || !$_POST['wpi_terms'] ) {
1143
-            wpinv_set_error( 'accept_terms', apply_filters( 'wpinv_accept_terms_error_text', __( 'You must accept terms and conditions', 'invoicing' ) ) );
1142
+        if (!isset($_POST['wpi_terms']) || !$_POST['wpi_terms']) {
1143
+            wpinv_set_error('accept_terms', apply_filters('wpinv_accept_terms_error_text', __('You must accept terms and conditions', 'invoicing')));
1144 1144
         }
1145 1145
     }
1146 1146
     
@@ -1156,26 +1156,26 @@  discard block
 block discarded – undo
1156 1156
     
1157 1157
     $invoice = wpinv_get_invoice_cart();
1158 1158
     $has_subscription = $invoice->is_recurring();
1159
-    if ( empty( $invoice ) ) {
1160
-        wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) );
1159
+    if (empty($invoice)) {
1160
+        wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing'));
1161 1161
         return $gateway;
1162 1162
     }
1163 1163
 
1164 1164
     // Check if a gateway value is present
1165
-    if ( !empty( $_REQUEST['wpi-gateway'] ) ) {
1166
-        $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] );
1165
+    if (!empty($_REQUEST['wpi-gateway'])) {
1166
+        $gateway = sanitize_text_field($_REQUEST['wpi-gateway']);
1167 1167
 
1168
-        if ( $invoice->is_free() ) {
1168
+        if ($invoice->is_free()) {
1169 1169
             $gateway = 'manual';
1170
-        } elseif ( !wpinv_is_gateway_active( $gateway ) ) {
1171
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) );
1172
-        } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) {
1173
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway doesnot support subscription payment', 'invoicing' ) );
1170
+        } elseif (!wpinv_is_gateway_active($gateway)) {
1171
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing'));
1172
+        } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) {
1173
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway doesnot support subscription payment', 'invoicing'));
1174 1174
         }
1175 1175
     }
1176 1176
 
1177
-    if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) {
1178
-        wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) );
1177
+    if ($has_subscription && count(wpinv_get_cart_contents()) > 1) {
1178
+        wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing'));
1179 1179
     }
1180 1180
 
1181 1181
     return $gateway;
@@ -1189,10 +1189,10 @@  discard block
 block discarded – undo
1189 1189
     
1190 1190
     $error = false;
1191 1191
     // If we have discounts, loop through them
1192
-    if ( ! empty( $discounts ) ) {
1193
-        foreach ( $discounts as $discount ) {
1192
+    if (!empty($discounts)) {
1193
+        foreach ($discounts as $discount) {
1194 1194
             // Check if valid
1195
-            if (  !wpinv_is_discount_valid( $discount, (int)$wpi_cart->get_user_id() ) ) {
1195
+            if (!wpinv_is_discount_valid($discount, (int) $wpi_cart->get_user_id())) {
1196 1196
                 // Discount is not valid
1197 1197
                 $error = true;
1198 1198
             }
@@ -1202,20 +1202,20 @@  discard block
 block discarded – undo
1202 1202
         return NULL;
1203 1203
     }
1204 1204
 
1205
-    if ( $error && !wpinv_get_errors() ) {
1206
-        wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) );
1205
+    if ($error && !wpinv_get_errors()) {
1206
+        wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing'));
1207 1207
     }
1208 1208
 
1209
-    return implode( ',', $discounts );
1209
+    return implode(',', $discounts);
1210 1210
 }
1211 1211
 
1212 1212
 function wpinv_checkout_validate_cc() {
1213 1213
     $card_data = wpinv_checkout_get_cc_info();
1214 1214
 
1215 1215
     // Validate the card zip
1216
-    if ( !empty( $card_data['wpinv_zip'] ) ) {
1217
-        if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) {
1218
-            wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) );
1216
+    if (!empty($card_data['wpinv_zip'])) {
1217
+        if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) {
1218
+            wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing'));
1219 1219
         }
1220 1220
     }
1221 1221
 
@@ -1225,28 +1225,28 @@  discard block
 block discarded – undo
1225 1225
 
1226 1226
 function wpinv_checkout_get_cc_info() {
1227 1227
 	$cc_info = array();
1228
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
1229
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
1230
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
1231
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
1232
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
1233
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
1234
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
1235
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
1236
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
1237
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
1228
+	$cc_info['card_name']      = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : '';
1229
+	$cc_info['card_number']    = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : '';
1230
+	$cc_info['card_cvc']       = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : '';
1231
+	$cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : '';
1232
+	$cc_info['card_exp_year']  = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : '';
1233
+	$cc_info['card_address']   = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : '';
1234
+	$cc_info['card_city']      = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : '';
1235
+	$cc_info['card_state']     = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : '';
1236
+	$cc_info['card_country']   = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : '';
1237
+	$cc_info['card_zip']       = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : '';
1238 1238
 
1239 1239
 	// Return cc info
1240 1240
 	return $cc_info;
1241 1241
 }
1242 1242
 
1243
-function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
1243
+function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') {
1244 1244
     $ret = false;
1245 1245
 
1246
-    if ( empty( $zip ) || empty( $country_code ) )
1246
+    if (empty($zip) || empty($country_code))
1247 1247
         return $ret;
1248 1248
 
1249
-    $country_code = strtoupper( $country_code );
1249
+    $country_code = strtoupper($country_code);
1250 1250
 
1251 1251
     $zip_regex = array(
1252 1252
         "AD" => "AD\d{3}",
@@ -1406,72 +1406,72 @@  discard block
 block discarded – undo
1406 1406
         "ZM" => "\d{5}"
1407 1407
     );
1408 1408
 
1409
-    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) )
1409
+    if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip))
1410 1410
         $ret = true;
1411 1411
 
1412
-    return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code );
1412
+    return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code);
1413 1413
 }
1414 1414
 
1415 1415
 function wpinv_checkout_validate_agree_to_terms() {
1416 1416
     // Validate agree to terms
1417
-    if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) {
1417
+    if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) {
1418 1418
         // User did not agree
1419
-        wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) );
1419
+        wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing')));
1420 1420
     }
1421 1421
 }
1422 1422
 
1423 1423
 function wpinv_checkout_validate_invoice_user() {
1424 1424
     global $wpi_cart, $user_ID;
1425 1425
 
1426
-    if(empty($wpi_cart)){
1426
+    if (empty($wpi_cart)) {
1427 1427
         $wpi_cart = wpinv_get_invoice_cart();
1428 1428
     }
1429 1429
 
1430
-    $invoice_user = (int)$wpi_cart->get_user_id();
1430
+    $invoice_user = (int) $wpi_cart->get_user_id();
1431 1431
     $valid_user_data = array(
1432 1432
         'user_id' => $invoice_user
1433 1433
     );
1434 1434
 
1435 1435
     // If guest checkout allowed
1436
-    if ( !wpinv_require_login_to_checkout() ) {
1436
+    if (!wpinv_require_login_to_checkout()) {
1437 1437
         return $valid_user_data;
1438 1438
     }
1439 1439
     
1440 1440
     // Verify there is a user_ID
1441
-    if ( $user_ID == $invoice_user ) {
1441
+    if ($user_ID == $invoice_user) {
1442 1442
         // Get the logged in user data
1443
-        $user_data = get_userdata( $user_ID );
1444
-        $required_fields  = wpinv_checkout_required_fields();
1443
+        $user_data = get_userdata($user_ID);
1444
+        $required_fields = wpinv_checkout_required_fields();
1445 1445
 
1446 1446
         // Loop through required fields and show error messages
1447
-         if ( !empty( $required_fields ) ) {
1448
-            foreach ( $required_fields as $field_name => $value ) {
1449
-                if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
1450
-                    wpinv_set_error( $value['error_id'], $value['error_message'] );
1447
+         if (!empty($required_fields)) {
1448
+            foreach ($required_fields as $field_name => $value) {
1449
+                if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) {
1450
+                    wpinv_set_error($value['error_id'], $value['error_message']);
1451 1451
                 }
1452 1452
             }
1453 1453
         }
1454 1454
 
1455 1455
         // Verify data
1456
-        if ( $user_data ) {
1456
+        if ($user_data) {
1457 1457
             // Collected logged in user data
1458 1458
             $valid_user_data = array(
1459 1459
                 'user_id'     => $user_ID,
1460
-                'email'       => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email,
1461
-                'first_name'  => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name,
1462
-                'last_name'   => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name']  ) ? sanitize_text_field( $_POST['wpinv_last_name']  ) : $user_data->last_name,
1460
+                'email'       => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email,
1461
+                'first_name'  => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name,
1462
+                'last_name'   => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name,
1463 1463
             );
1464 1464
 
1465
-            if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) {
1466
-                wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) );
1465
+            if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) {
1466
+                wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing'));
1467 1467
             }
1468 1468
         } else {
1469 1469
             // Set invalid user error
1470
-            wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) );
1470
+            wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing'));
1471 1471
         }
1472 1472
     } else {
1473 1473
         // Set invalid user error
1474
-        wpinv_set_error( 'invalid_user_id', __( 'The invalid invoice user id', 'invoicing' ) );
1474
+        wpinv_set_error('invalid_user_id', __('The invalid invoice user id', 'invoicing'));
1475 1475
     }
1476 1476
 
1477 1477
     // Return user data
@@ -1483,27 +1483,27 @@  discard block
 block discarded – undo
1483 1483
 
1484 1484
     $data = array();
1485 1485
     
1486
-    if ( is_user_logged_in() ) {
1487
-        if ( !wpinv_require_login_to_checkout() || ( wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id() ) ) {
1488
-            $data['user_id'] = (int)get_current_user_id();
1486
+    if (is_user_logged_in()) {
1487
+        if (!wpinv_require_login_to_checkout() || (wpinv_require_login_to_checkout() && (int) $wpi_cart->get_user_id() === (int) get_current_user_id())) {
1488
+            $data['user_id'] = (int) get_current_user_id();
1489 1489
         } else {
1490
-            wpinv_set_error( 'logged_in_only', __( 'You are not allowed to pay for this invoice', 'invoicing' ) );
1490
+            wpinv_set_error('logged_in_only', __('You are not allowed to pay for this invoice', 'invoicing'));
1491 1491
         }
1492 1492
     } else {
1493 1493
         // If guest checkout allowed
1494
-        if ( !wpinv_require_login_to_checkout() ) {
1494
+        if (!wpinv_require_login_to_checkout()) {
1495 1495
             $data['user_id'] = 0;
1496 1496
         } else {
1497
-            wpinv_set_error( 'logged_in_only', __( 'You must be logged in to pay for this invoice', 'invoicing' ) );
1497
+            wpinv_set_error('logged_in_only', __('You must be logged in to pay for this invoice', 'invoicing'));
1498 1498
         }
1499 1499
     }
1500 1500
 
1501 1501
     return $data;
1502 1502
 }
1503 1503
 
1504
-function wpinv_checkout_form_get_user( $valid_data = array() ) {
1504
+function wpinv_checkout_form_get_user($valid_data = array()) {
1505 1505
 
1506
-    if ( !empty( $valid_data['current_user']['user_id'] ) ) {
1506
+    if (!empty($valid_data['current_user']['user_id'])) {
1507 1507
         $user = $valid_data['current_user'];
1508 1508
     } else {
1509 1509
         // Set the valid invoice user
@@ -1511,7 +1511,7 @@  discard block
 block discarded – undo
1511 1511
     }
1512 1512
 
1513 1513
     // Verify invoice have an user
1514
-    if ( false === $user || empty( $user ) ) {
1514
+    if (false === $user || empty($user)) {
1515 1515
         return false;
1516 1516
     }
1517 1517
 
@@ -1528,11 +1528,11 @@  discard block
 block discarded – undo
1528 1528
         'zip',
1529 1529
     );
1530 1530
     
1531
-    foreach ( $address_fields as $field ) {
1532
-        $user[$field]  = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false;
1531
+    foreach ($address_fields as $field) {
1532
+        $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false;
1533 1533
         
1534
-        if ( !empty( $user['user_id'] ) && !empty( $valid_data['current_user']['user_id'] ) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id'] ) {
1535
-            update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] );
1534
+        if (!empty($user['user_id']) && !empty($valid_data['current_user']['user_id']) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id']) {
1535
+            update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]);
1536 1536
         }
1537 1537
     }
1538 1538
 
@@ -1540,28 +1540,28 @@  discard block
 block discarded – undo
1540 1540
     return $user;
1541 1541
 }
1542 1542
 
1543
-function wpinv_set_checkout_session( $invoice_data = array() ) {
1543
+function wpinv_set_checkout_session($invoice_data = array()) {
1544 1544
     global $wpi_session;
1545 1545
     
1546
-    return $wpi_session->set( 'wpinv_checkout', $invoice_data );
1546
+    return $wpi_session->set('wpinv_checkout', $invoice_data);
1547 1547
 }
1548 1548
 
1549 1549
 function wpinv_get_checkout_session() {
1550 1550
 	global $wpi_session;
1551 1551
     
1552
-    return $wpi_session->get( 'wpinv_checkout' );
1552
+    return $wpi_session->get('wpinv_checkout');
1553 1553
 }
1554 1554
 
1555 1555
 function wpinv_empty_cart() {
1556 1556
     global $wpi_session;
1557 1557
 
1558 1558
     // Remove cart contents
1559
-    $wpi_session->set( 'wpinv_checkout', NULL );
1559
+    $wpi_session->set('wpinv_checkout', NULL);
1560 1560
 
1561 1561
     // Remove all cart fees
1562
-    $wpi_session->set( 'wpi_cart_fees', NULL );
1562
+    $wpi_session->set('wpi_cart_fees', NULL);
1563 1563
 
1564
-    do_action( 'wpinv_empty_cart' );
1564
+    do_action('wpinv_empty_cart');
1565 1565
 }
1566 1566
 
1567 1567
 function wpinv_process_checkout() {
@@ -1570,7 +1570,7 @@  discard block
 block discarded – undo
1570 1570
     wpinv_clear_errors();
1571 1571
     
1572 1572
     $invoice = wpinv_get_invoice_cart();
1573
-    if ( empty( $invoice ) ) {
1573
+    if (empty($invoice)) {
1574 1574
         return false;
1575 1575
     }
1576 1576
     
@@ -1578,42 +1578,42 @@  discard block
 block discarded – undo
1578 1578
     
1579 1579
     $wpi_checkout_id = $invoice->ID;
1580 1580
     
1581
-    do_action( 'wpinv_pre_process_checkout' );
1581
+    do_action('wpinv_pre_process_checkout');
1582 1582
     
1583
-    if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty
1583
+    if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty
1584 1584
         $valid_data = false;
1585
-        wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) );
1585
+        wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing'));
1586 1586
     } else {
1587 1587
         // Validate the form $_POST data
1588 1588
         $valid_data = wpinv_validate_checkout_fields();
1589 1589
         
1590 1590
         // Allow themes and plugins to hook to errors
1591
-        do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST );
1591
+        do_action('wpinv_checkout_error_checks', $valid_data, $_POST);
1592 1592
     }
1593 1593
     
1594
-    $is_ajax    = defined( 'DOING_AJAX' ) && DOING_AJAX;
1594
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1595 1595
     
1596 1596
     // Validate the user
1597
-    $user = wpinv_checkout_form_get_user( $valid_data );
1597
+    $user = wpinv_checkout_form_get_user($valid_data);
1598 1598
 
1599 1599
     // Let extensions validate fields after user is logged in if user has used login/registration form
1600
-    do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST );
1600
+    do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST);
1601 1601
     
1602
-    if ( false === $valid_data || wpinv_get_errors() || ! $user ) {
1603
-        if ( $is_ajax ) {
1604
-            do_action( 'wpinv_ajax_checkout_errors' );
1602
+    if (false === $valid_data || wpinv_get_errors() || !$user) {
1603
+        if ($is_ajax) {
1604
+            do_action('wpinv_ajax_checkout_errors');
1605 1605
             die();
1606 1606
         } else {
1607 1607
             return false;
1608 1608
         }
1609 1609
     }
1610 1610
 
1611
-    if ( $is_ajax ) {
1611
+    if ($is_ajax) {
1612 1612
         // Save address fields.
1613
-        $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' );
1614
-        foreach ( $address_fields as $field ) {
1615
-            if ( isset( $user[$field] ) ) {
1616
-                $invoice->set( $field, $user[$field] );
1613
+        $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company');
1614
+        foreach ($address_fields as $field) {
1615
+            if (isset($user[$field])) {
1616
+                $invoice->set($field, $user[$field]);
1617 1617
             }
1618 1618
 
1619 1619
             $invoice->save();
@@ -1621,16 +1621,16 @@  discard block
 block discarded – undo
1621 1621
 
1622 1622
         $response['success']            = true;
1623 1623
         $response['data']['subtotal']   = $invoice->get_subtotal();
1624
-        $response['data']['subtotalf']  = $invoice->get_subtotal( true );
1624
+        $response['data']['subtotalf']  = $invoice->get_subtotal(true);
1625 1625
         $response['data']['discount']   = $invoice->get_discount();
1626
-        $response['data']['discountf']  = $invoice->get_discount( true );
1626
+        $response['data']['discountf']  = $invoice->get_discount(true);
1627 1627
         $response['data']['tax']        = $invoice->get_tax();
1628
-        $response['data']['taxf']       = $invoice->get_tax( true );
1628
+        $response['data']['taxf']       = $invoice->get_tax(true);
1629 1629
         $response['data']['total']      = $invoice->get_total();
1630
-        $response['data']['totalf']     = $invoice->get_total( true );
1631
-	    $response['data']['free']       = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false;
1630
+        $response['data']['totalf']     = $invoice->get_total(true);
1631
+	    $response['data']['free'] = $invoice->is_free() && (!((float) $response['data']['total'] > 0) || $invoice->is_free_trial()) ? true : false;
1632 1632
 
1633
-        wp_send_json( $response );
1633
+        wp_send_json($response);
1634 1634
     }
1635 1635
     
1636 1636
     $user_info = array(
@@ -1652,42 +1652,42 @@  discard block
 block discarded – undo
1652 1652
     
1653 1653
     // Setup invoice information
1654 1654
     $invoice_data = array(
1655
-        'invoice_id'        => !empty( $invoice ) ? $invoice->ID : 0,
1655
+        'invoice_id'        => !empty($invoice) ? $invoice->ID : 0,
1656 1656
         'items'             => $cart_items,
1657 1657
         'cart_discounts'    => $discounts,
1658
-        'fees'              => wpinv_get_cart_fees(),        // Any arbitrary fees that have been added to the cart
1659
-        'subtotal'          => wpinv_get_cart_subtotal( $cart_items ),    // Amount before taxes and discounts
1660
-        'discount'          => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount
1661
-        'tax'               => wpinv_get_cart_tax( $cart_items ),               // Taxed amount
1662
-        'price'             => wpinv_get_cart_total( $cart_items, $discounts ),    // Amount after taxes
1658
+        'fees'              => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart
1659
+        'subtotal'          => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts
1660
+        'discount'          => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount
1661
+        'tax'               => wpinv_get_cart_tax($cart_items), // Taxed amount
1662
+        'price'             => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes
1663 1663
         'invoice_key'       => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(),
1664 1664
         'user_email'        => $invoice->get_email(),
1665
-        'date'              => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
1666
-        'user_info'         => stripslashes_deep( $user_info ),
1665
+        'date'              => date('Y-m-d H:i:s', current_time('timestamp')),
1666
+        'user_info'         => stripslashes_deep($user_info),
1667 1667
         'post_data'         => $_POST,
1668 1668
         'cart_details'      => $cart_items,
1669 1669
         'gateway'           => $valid_data['gateway'],
1670 1670
         'card_info'         => $valid_data['cc_info']
1671 1671
     );
1672 1672
     
1673
-    $vat_info   = $wpinv_euvat->current_vat_data();
1674
-    if ( is_array( $vat_info ) ) {
1673
+    $vat_info = $wpinv_euvat->current_vat_data();
1674
+    if (is_array($vat_info)) {
1675 1675
         $invoice_data['user_info']['vat_number']        = $vat_info['number'];
1676 1676
         $invoice_data['user_info']['vat_rate']          = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']);
1677
-        $invoice_data['user_info']['adddress_confirmed']    = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1677
+        $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1678 1678
 
1679 1679
         // Add the VAT rate to each item in the cart
1680
-        foreach( $invoice_data['cart_details'] as $key => $item_data) {
1680
+        foreach ($invoice_data['cart_details'] as $key => $item_data) {
1681 1681
             $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']);
1682
-            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 );
1682
+            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4);
1683 1683
         }
1684 1684
     }
1685 1685
     
1686 1686
     // Save vat fields.
1687
-    $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' );
1688
-    foreach ( $address_fields as $field ) {
1689
-        if ( isset( $invoice_data['user_info'][$field] ) ) {
1690
-            $invoice->set( $field, $invoice_data['user_info'][$field] );
1687
+    $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed');
1688
+    foreach ($address_fields as $field) {
1689
+        if (isset($invoice_data['user_info'][$field])) {
1690
+            $invoice->set($field, $invoice_data['user_info'][$field]);
1691 1691
         }
1692 1692
 
1693 1693
         $invoice->save();
@@ -1697,55 +1697,55 @@  discard block
 block discarded – undo
1697 1697
     $valid_data['user'] = $user;
1698 1698
     
1699 1699
     // Allow themes and plugins to hook before the gateway
1700
-    do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data );
1700
+    do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data);
1701 1701
     
1702 1702
     // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice
1703
-    if ( !$invoice_data['price'] ) {
1703
+    if (!$invoice_data['price']) {
1704 1704
         // Revert to manual
1705 1705
         $invoice_data['gateway'] = 'manual';
1706 1706
         $_POST['wpi-gateway'] = 'manual';
1707 1707
     }
1708 1708
     
1709 1709
     // Allow the invoice data to be modified before it is sent to the gateway
1710
-    $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data );
1710
+    $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data);
1711 1711
     
1712
-    if ( $invoice_data['price'] && $invoice_data['gateway'] == 'manual' ) {
1712
+    if ($invoice_data['price'] && $invoice_data['gateway'] == 'manual') {
1713 1713
         $mode = 'test';
1714 1714
     } else {
1715
-        $mode = wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live';
1715
+        $mode = wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live';
1716 1716
     }
1717 1717
     
1718 1718
     // Setup the data we're storing in the purchase session
1719 1719
     $session_data = $invoice_data;
1720 1720
     // Make sure credit card numbers are never stored in sessions
1721
-    if ( !empty( $session_data['card_info']['card_number'] ) ) {
1722
-        unset( $session_data['card_info']['card_number'] );
1721
+    if (!empty($session_data['card_info']['card_number'])) {
1722
+        unset($session_data['card_info']['card_number']);
1723 1723
     }
1724 1724
     
1725 1725
     // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data.
1726
-    wpinv_set_checkout_session( $invoice_data );
1726
+    wpinv_set_checkout_session($invoice_data);
1727 1727
     
1728 1728
     // Set gateway
1729
-    $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] );
1730
-    $invoice->update_meta( '_wpinv_mode', $mode );
1731
-    $invoice->update_meta( '_wpinv_checkout', date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) ) );
1729
+    $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']);
1730
+    $invoice->update_meta('_wpinv_mode', $mode);
1731
+    $invoice->update_meta('_wpinv_checkout', date_i18n('Y-m-d H:i:s', current_time('timestamp')));
1732 1732
     
1733
-    do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data );
1733
+    do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data);
1734 1734
 
1735 1735
     // Send info to the gateway for payment processing
1736
-    wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data );
1736
+    wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data);
1737 1737
     die();
1738 1738
 }
1739
-add_action( 'wpinv_payment', 'wpinv_process_checkout' );
1739
+add_action('wpinv_payment', 'wpinv_process_checkout');
1740 1740
 
1741
-function wpinv_get_invoices( $args ) {
1742
-    $args = wp_parse_args( $args, array(
1743
-        'status'   => array_keys( wpinv_get_invoice_statuses() ),
1741
+function wpinv_get_invoices($args) {
1742
+    $args = wp_parse_args($args, array(
1743
+        'status'   => array_keys(wpinv_get_invoice_statuses()),
1744 1744
         'type'     => 'wpi_invoice',
1745 1745
         'parent'   => null,
1746 1746
         'user'     => null,
1747 1747
         'email'    => '',
1748
-        'limit'    => get_option( 'posts_per_page' ),
1748
+        'limit'    => get_option('posts_per_page'),
1749 1749
         'offset'   => null,
1750 1750
         'page'     => 1,
1751 1751
         'exclude'  => array(),
@@ -1753,7 +1753,7 @@  discard block
 block discarded – undo
1753 1753
         'order'    => 'DESC',
1754 1754
         'return'   => 'objects',
1755 1755
         'paginate' => false,
1756
-    ) );
1756
+    ));
1757 1757
     
1758 1758
     // Handle some BW compatibility arg names where wp_query args differ in naming.
1759 1759
     $map_legacy = array(
@@ -1766,18 +1766,18 @@  discard block
 block discarded – undo
1766 1766
         'paged'          => 'page',
1767 1767
     );
1768 1768
 
1769
-    foreach ( $map_legacy as $from => $to ) {
1770
-        if ( isset( $args[ $from ] ) ) {
1771
-            $args[ $to ] = $args[ $from ];
1769
+    foreach ($map_legacy as $from => $to) {
1770
+        if (isset($args[$from])) {
1771
+            $args[$to] = $args[$from];
1772 1772
         }
1773 1773
     }
1774 1774
 
1775
-    if ( get_query_var( 'paged' ) )
1775
+    if (get_query_var('paged'))
1776 1776
         $args['page'] = get_query_var('paged');
1777
-    else if ( get_query_var( 'page' ) )
1778
-        $args['page'] = get_query_var( 'page' );
1779
-    else if ( !empty( $args[ 'page' ] ) )
1780
-        $args['page'] = $args[ 'page' ];
1777
+    else if (get_query_var('page'))
1778
+        $args['page'] = get_query_var('page');
1779
+    else if (!empty($args['page']))
1780
+        $args['page'] = $args['page'];
1781 1781
     else
1782 1782
         $args['page'] = 1;
1783 1783
 
@@ -1790,48 +1790,48 @@  discard block
 block discarded – undo
1790 1790
         'post_status'    => $args['status'],
1791 1791
         'posts_per_page' => $args['limit'],
1792 1792
         'meta_query'     => array(),
1793
-        'date_query'     => !empty( $args['date_query'] ) ? $args['date_query'] : array(),
1793
+        'date_query'     => !empty($args['date_query']) ? $args['date_query'] : array(),
1794 1794
         'fields'         => 'ids',
1795 1795
         'orderby'        => $args['orderby'],
1796 1796
         'order'          => $args['order'],
1797 1797
     );
1798 1798
     
1799
-    if ( !empty( $args['user'] ) ) {
1800
-        $wp_query_args['author'] = absint( $args['user'] );
1799
+    if (!empty($args['user'])) {
1800
+        $wp_query_args['author'] = absint($args['user']);
1801 1801
     }
1802 1802
 
1803
-    if ( ! is_null( $args['parent'] ) ) {
1804
-        $wp_query_args['post_parent'] = absint( $args['parent'] );
1803
+    if (!is_null($args['parent'])) {
1804
+        $wp_query_args['post_parent'] = absint($args['parent']);
1805 1805
     }
1806 1806
 
1807
-    if ( ! is_null( $args['offset'] ) ) {
1808
-        $wp_query_args['offset'] = absint( $args['offset'] );
1807
+    if (!is_null($args['offset'])) {
1808
+        $wp_query_args['offset'] = absint($args['offset']);
1809 1809
     } else {
1810
-        $wp_query_args['paged'] = absint( $args['page'] );
1810
+        $wp_query_args['paged'] = absint($args['page']);
1811 1811
     }
1812 1812
 
1813
-    if ( ! empty( $args['exclude'] ) ) {
1814
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
1813
+    if (!empty($args['exclude'])) {
1814
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
1815 1815
     }
1816 1816
 
1817
-    if ( ! $args['paginate' ] ) {
1817
+    if (!$args['paginate']) {
1818 1818
         $wp_query_args['no_found_rows'] = true;
1819 1819
     }
1820 1820
 
1821 1821
     $wp_query_args = apply_filters('wpinv_get_invoices_args', $wp_query_args, $args);
1822 1822
 
1823 1823
     // Get results.
1824
-    $invoices = new WP_Query( $wp_query_args );
1824
+    $invoices = new WP_Query($wp_query_args);
1825 1825
 
1826
-    if ( 'objects' === $args['return'] ) {
1827
-        $return = array_map( 'wpinv_get_invoice', $invoices->posts );
1828
-    } elseif ( 'self' === $args['return'] ) {
1826
+    if ('objects' === $args['return']) {
1827
+        $return = array_map('wpinv_get_invoice', $invoices->posts);
1828
+    } elseif ('self' === $args['return']) {
1829 1829
         return $invoices;
1830 1830
     } else {
1831 1831
         $return = $invoices->posts;
1832 1832
     }
1833 1833
 
1834
-    if ( $args['paginate' ] ) {
1834
+    if ($args['paginate']) {
1835 1835
         return (object) array(
1836 1836
             'invoices'      => $return,
1837 1837
             'total'         => $invoices->found_posts,
@@ -1844,22 +1844,22 @@  discard block
 block discarded – undo
1844 1844
 
1845 1845
 function wpinv_get_user_invoices_columns() {
1846 1846
     $columns = array(
1847
-            'invoice-number'  => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ),
1848
-            'created-date'    => array( 'title' => __( 'Created Date', 'invoicing' ), 'class' => 'text-left' ),
1849
-            'payment-date'    => array( 'title' => __( 'Payment Date', 'invoicing' ), 'class' => 'text-left' ),
1850
-            'invoice-status'  => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ),
1851
-            'invoice-total'   => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ),
1852
-            'invoice-actions' => array( 'title' => '&nbsp;', 'class' => 'text-center' ),
1847
+            'invoice-number'  => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'),
1848
+            'created-date'    => array('title' => __('Created Date', 'invoicing'), 'class' => 'text-left'),
1849
+            'payment-date'    => array('title' => __('Payment Date', 'invoicing'), 'class' => 'text-left'),
1850
+            'invoice-status'  => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'),
1851
+            'invoice-total'   => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'),
1852
+            'invoice-actions' => array('title' => '&nbsp;', 'class' => 'text-center'),
1853 1853
         );
1854 1854
 
1855
-    return apply_filters( 'wpinv_user_invoices_columns', $columns );
1855
+    return apply_filters('wpinv_user_invoices_columns', $columns);
1856 1856
 }
1857 1857
 
1858
-function wpinv_payment_receipt( $atts, $content = null ) {
1858
+function wpinv_payment_receipt($atts, $content = null) {
1859 1859
     global $wpinv_receipt_args;
1860 1860
 
1861
-    $wpinv_receipt_args = shortcode_atts( array(
1862
-        'error'           => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ),
1861
+    $wpinv_receipt_args = shortcode_atts(array(
1862
+        'error'           => __('Sorry, trouble retrieving payment receipt.', 'invoicing'),
1863 1863
         'price'           => true,
1864 1864
         'discount'        => true,
1865 1865
         'items'           => true,
@@ -1868,197 +1868,197 @@  discard block
 block discarded – undo
1868 1868
         'invoice_key'     => false,
1869 1869
         'payment_method'  => true,
1870 1870
         'invoice_id'      => true
1871
-    ), $atts, 'wpinv_receipt' );
1871
+    ), $atts, 'wpinv_receipt');
1872 1872
 
1873 1873
     $session = wpinv_get_checkout_session();
1874
-    if ( isset( $_GET['invoice_key'] ) ) {
1875
-        $invoice_key = urldecode( $_GET['invoice_key'] );
1876
-    } else if ( $session && isset( $session['invoice_key'] ) ) {
1874
+    if (isset($_GET['invoice_key'])) {
1875
+        $invoice_key = urldecode($_GET['invoice_key']);
1876
+    } else if ($session && isset($session['invoice_key'])) {
1877 1877
         $invoice_key = $session['invoice_key'];
1878
-    } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) {
1878
+    } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) {
1879 1879
         $invoice_key = $wpinv_receipt_args['invoice_key'];
1880
-    } else if ( isset( $_GET['invoice-id'] ) ) {
1881
-        $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] );
1880
+    } else if (isset($_GET['invoice-id'])) {
1881
+        $invoice_key = wpinv_get_payment_key((int) $_GET['invoice-id']);
1882 1882
     }
1883 1883
 
1884 1884
     // No key found
1885
-    if ( ! isset( $invoice_key ) ) {
1885
+    if (!isset($invoice_key)) {
1886 1886
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1887 1887
     }
1888 1888
 
1889
-    $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1890
-    $user_can_view = wpinv_can_view_receipt( $invoice_key );
1891
-    if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1892
-        $invoice_id     = (int)$_GET['invoice-id'];
1893
-        $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1889
+    $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1890
+    $user_can_view = wpinv_can_view_receipt($invoice_key);
1891
+    if ($user_can_view && isset($_GET['invoice-id'])) {
1892
+        $invoice_id     = (int) $_GET['invoice-id'];
1893
+        $user_can_view  = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? true : false;
1894 1894
     }
1895 1895
 
1896 1896
     // Key was provided, but user is logged out. Offer them the ability to login and view the receipt
1897
-    if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) {
1897
+    if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) {
1898 1898
         // login redirect
1899
-        return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>';
1899
+        return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>';
1900 1900
     }
1901 1901
 
1902
-    if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) {
1902
+    if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) {
1903 1903
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1904 1904
     }
1905 1905
 
1906 1906
     ob_start();
1907 1907
 
1908
-    wpinv_get_template_part( 'wpinv-invoice-receipt' );
1908
+    wpinv_get_template_part('wpinv-invoice-receipt');
1909 1909
 
1910 1910
     $display = ob_get_clean();
1911 1911
 
1912 1912
     return $display;
1913 1913
 }
1914 1914
 
1915
-function wpinv_get_invoice_id_by_key( $key ) {
1915
+function wpinv_get_invoice_id_by_key($key) {
1916 1916
 	global $wpdb;
1917 1917
 
1918
-	$invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) );
1918
+	$invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key));
1919 1919
 
1920
-	if ( $invoice_id != NULL )
1920
+	if ($invoice_id != NULL)
1921 1921
 		return $invoice_id;
1922 1922
 
1923 1923
 	return 0;
1924 1924
 }
1925 1925
 
1926
-function wpinv_can_view_receipt( $invoice_key = '' ) {
1926
+function wpinv_can_view_receipt($invoice_key = '') {
1927 1927
 	$return = false;
1928 1928
 
1929
-	if ( empty( $invoice_key ) ) {
1929
+	if (empty($invoice_key)) {
1930 1930
 		return $return;
1931 1931
 	}
1932 1932
 
1933 1933
 	global $wpinv_receipt_args;
1934 1934
 
1935
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1936
-	if ( isset( $_GET['invoice-id'] ) ) {
1937
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1935
+	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key);
1936
+	if (isset($_GET['invoice-id'])) {
1937
+		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? (int) $_GET['invoice-id'] : 0;
1938 1938
 	}
1939 1939
 
1940
-	if ( empty( $wpinv_receipt_args['id'] ) ) {
1940
+	if (empty($wpinv_receipt_args['id'])) {
1941 1941
 		return $return;
1942 1942
 	}
1943 1943
 
1944
-	$invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] );
1945
-	if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) {
1944
+	$invoice = wpinv_get_invoice($wpinv_receipt_args['id']);
1945
+	if (!(!empty($invoice->ID) && $invoice->get_key() === $invoice_key)) {
1946 1946
 		return $return;
1947 1947
 	}
1948 1948
 
1949
-	if ( is_user_logged_in() ) {
1950
-		if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) {
1949
+	if (is_user_logged_in()) {
1950
+		if ((int) $invoice->get_user_id() === (int) get_current_user_id()) {
1951 1951
 			$return = true;
1952 1952
 		}
1953 1953
 	}
1954 1954
 
1955 1955
 	$session = wpinv_get_checkout_session();
1956
-	if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) {
1957
-		$check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key'];
1956
+	if (isset($_GET['invoice_key']) || ($session && isset($session['invoice_key']))) {
1957
+		$check_key = isset($_GET['invoice_key']) ? $_GET['invoice_key'] : $session['invoice_key'];
1958 1958
 
1959
-		if ( wpinv_require_login_to_checkout() ) {
1959
+		if (wpinv_require_login_to_checkout()) {
1960 1960
 			$return = $return && $check_key === $invoice_key;
1961 1961
 		} else {
1962 1962
 			$return = $check_key === $invoice_key;
1963 1963
 		}
1964 1964
 	}
1965 1965
 
1966
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1966
+	return (bool) apply_filters('wpinv_can_view_receipt', $return, $invoice_key);
1967 1967
 }
1968 1968
 
1969 1969
 function wpinv_pay_for_invoice() {
1970 1970
     global $wpinv_euvat;
1971 1971
     
1972
-    if ( isset( $_GET['invoice_key'] ) ) {
1972
+    if (isset($_GET['invoice_key'])) {
1973 1973
         $checkout_uri   = wpinv_get_checkout_uri();
1974
-        $invoice_key    = sanitize_text_field( $_GET['invoice_key'] );
1974
+        $invoice_key    = sanitize_text_field($_GET['invoice_key']);
1975 1975
         
1976
-        if ( empty( $invoice_key ) ) {
1977
-            wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) );
1978
-            wp_redirect( $checkout_uri );
1976
+        if (empty($invoice_key)) {
1977
+            wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing'));
1978
+            wp_redirect($checkout_uri);
1979 1979
             exit();
1980 1980
         }
1981 1981
         
1982
-        do_action( 'wpinv_check_pay_for_invoice', $invoice_key );
1982
+        do_action('wpinv_check_pay_for_invoice', $invoice_key);
1983 1983
 
1984
-        $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1985
-        $user_can_view = wpinv_can_view_receipt( $invoice_key );
1986
-        if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1987
-            $invoice_id     = (int)$_GET['invoice-id'];
1988
-            $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1984
+        $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1985
+        $user_can_view = wpinv_can_view_receipt($invoice_key);
1986
+        if ($user_can_view && isset($_GET['invoice-id'])) {
1987
+            $invoice_id     = (int) $_GET['invoice-id'];
1988
+            $user_can_view  = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? true : false;
1989 1989
         }
1990 1990
         
1991
-        if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) {
1992
-            if ( $invoice->needs_payment() ) {
1991
+        if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) {
1992
+            if ($invoice->needs_payment()) {
1993 1993
                 $data                   = array();
1994 1994
                 $data['invoice_id']     = $invoice_id;
1995
-                $data['cart_discounts'] = $invoice->get_discounts( true );
1995
+                $data['cart_discounts'] = $invoice->get_discounts(true);
1996 1996
                 
1997
-                wpinv_set_checkout_session( $data );
1997
+                wpinv_set_checkout_session($data);
1998 1998
                 
1999
-                if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1999
+                if (wpinv_get_option('vat_ip_country_default')) {
2000 2000
                     $_POST['country']   = $wpinv_euvat->get_country_by_ip();
2001 2001
                     $_POST['state']     = $_POST['country'] == $invoice->country ? $invoice->state : '';
2002 2002
                     
2003
-                    wpinv_recalculate_tax( true );
2003
+                    wpinv_recalculate_tax(true);
2004 2004
                 }
2005 2005
                 
2006 2006
             } else {
2007 2007
                 $checkout_uri = $invoice->get_view_url();
2008 2008
             }
2009 2009
         } else {
2010
-            wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) );
2010
+            wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing'));
2011 2011
             
2012
-            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
2012
+            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
2013 2013
         }
2014 2014
         
2015
-        if(wp_redirect( $checkout_uri )){
2015
+        if (wp_redirect($checkout_uri)) {
2016 2016
             exit;
2017 2017
         };
2018 2018
         wpinv_die();
2019 2019
     }
2020 2020
 }
2021
-add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' );
2021
+add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice');
2022 2022
 
2023
-function wpinv_handle_pay_via_invoice_link( $invoice_key ) {
2024
-    if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) {
2025
-        if ( $invoice = wpinv_get_invoice( $invoice_id ) ) {
2023
+function wpinv_handle_pay_via_invoice_link($invoice_key) {
2024
+    if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) {
2025
+        if ($invoice = wpinv_get_invoice($invoice_id)) {
2026 2026
             $user_id = $invoice->get_user_id();
2027
-            $secret = sanitize_text_field( $_GET['_wpipay'] );
2027
+            $secret = sanitize_text_field($_GET['_wpipay']);
2028 2028
             
2029
-            if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link
2030
-                $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
2029
+            if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link
2030
+                $redirect_to = remove_query_arg('_wpipay', get_permalink());
2031 2031
                 
2032
-                wpinv_guest_redirect( $redirect_to, $user_id );
2032
+                wpinv_guest_redirect($redirect_to, $user_id);
2033 2033
                 exit();
2034 2034
             }
2035 2035
         }
2036 2036
     }
2037 2037
 }
2038
-add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' );
2038
+add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link');
2039 2039
 
2040
-function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) {
2041
-    $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id;
2040
+function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') {
2041
+    $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id;
2042 2042
     
2043
-    if ( empty( $invoice_id ) && $invoice_id > 0 ) {
2043
+    if (empty($invoice_id) && $invoice_id > 0) {
2044 2044
         return false;
2045 2045
     }
2046 2046
     
2047
-    if ( empty( $transaction_id ) ) {
2047
+    if (empty($transaction_id)) {
2048 2048
         $transaction_id = $invoice_id;
2049 2049
     }
2050 2050
 
2051
-    $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id );
2051
+    $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id);
2052 2052
     
2053
-    return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id );
2053
+    return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id);
2054 2054
 }
2055 2055
 
2056
-function wpinv_invoice_status_label( $status, $status_display = '' ) {
2057
-    if ( empty( $status_display ) ) {
2058
-        $status_display = wpinv_status_nicename( $status );
2056
+function wpinv_invoice_status_label($status, $status_display = '') {
2057
+    if (empty($status_display)) {
2058
+        $status_display = wpinv_status_nicename($status);
2059 2059
     }
2060 2060
     
2061
-    switch ( $status ) {
2061
+    switch ($status) {
2062 2062
         case 'publish' :
2063 2063
         case 'wpi-renewal' :
2064 2064
             $class = 'label-success';
@@ -2083,201 +2083,201 @@  discard block
 block discarded – undo
2083 2083
     
2084 2084
     $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>';
2085 2085
     
2086
-    return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display );
2086
+    return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display);
2087 2087
 }
2088 2088
 
2089
-function wpinv_format_invoice_number( $number, $type = '' ) {
2090
-    $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type );
2091
-    if ( null !== $check ) {
2089
+function wpinv_format_invoice_number($number, $type = '') {
2090
+    $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type);
2091
+    if (null !== $check) {
2092 2092
         return $check;
2093 2093
     }
2094 2094
 
2095
-    if ( !empty( $number ) && !is_numeric( $number ) ) {
2095
+    if (!empty($number) && !is_numeric($number)) {
2096 2096
         return $number;
2097 2097
     }
2098 2098
 
2099
-    $padd  = wpinv_get_option( 'invoice_number_padd' );
2100
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2101
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2099
+    $padd = wpinv_get_option('invoice_number_padd');
2100
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2101
+    $postfix = wpinv_get_option('invoice_number_postfix');
2102 2102
     
2103
-    $padd = absint( $padd );
2104
-    $formatted_number = absint( $number );
2103
+    $padd = absint($padd);
2104
+    $formatted_number = absint($number);
2105 2105
     
2106
-    if ( $padd > 0 ) {
2107
-        $formatted_number = zeroise( $formatted_number, $padd );
2106
+    if ($padd > 0) {
2107
+        $formatted_number = zeroise($formatted_number, $padd);
2108 2108
     }    
2109 2109
 
2110 2110
     $formatted_number = $prefix . $formatted_number . $postfix;
2111 2111
 
2112
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
2112
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
2113 2113
 }
2114 2114
 
2115
-function wpinv_get_next_invoice_number( $type = '' ) {
2116
-    $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type );
2117
-    if ( null !== $check ) {
2115
+function wpinv_get_next_invoice_number($type = '') {
2116
+    $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type);
2117
+    if (null !== $check) {
2118 2118
         return $check;
2119 2119
     }
2120 2120
     
2121
-    if ( !wpinv_sequential_number_active() ) {
2121
+    if (!wpinv_sequential_number_active()) {
2122 2122
         return false;
2123 2123
     }
2124 2124
 
2125
-    $number = $last_number = get_option( 'wpinv_last_invoice_number', 0 );
2126
-    $start  = wpinv_get_option( 'invoice_sequence_start', 1 );
2127
-    if ( !absint( $start ) > 0 ) {
2125
+    $number = $last_number = get_option('wpinv_last_invoice_number', 0);
2126
+    $start  = wpinv_get_option('invoice_sequence_start', 1);
2127
+    if (!absint($start) > 0) {
2128 2128
         $start = 1;
2129 2129
     }
2130 2130
     $increment_number = true;
2131 2131
     $save_number = false;
2132 2132
 
2133
-    if ( !empty( $number ) && !is_numeric( $number ) && $number == wpinv_format_invoice_number( $number ) ) {
2134
-        $number = wpinv_clean_invoice_number( $number );
2133
+    if (!empty($number) && !is_numeric($number) && $number == wpinv_format_invoice_number($number)) {
2134
+        $number = wpinv_clean_invoice_number($number);
2135 2135
     }
2136 2136
 
2137
-    if ( empty( $number ) ) {
2138
-        if ( !( $last_number === 0 || $last_number === '0' ) ) {
2139
-            $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys( wpinv_get_invoice_statuses( true, true ) ) ) );
2137
+    if (empty($number)) {
2138
+        if (!($last_number === 0 || $last_number === '0')) {
2139
+            $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys(wpinv_get_invoice_statuses(true, true))));
2140 2140
 
2141
-            if ( !empty( $last_invoice[0] ) && $invoice_number = wpinv_get_invoice_number( $last_invoice[0] ) ) {
2142
-                if ( is_numeric( $invoice_number ) ) {
2141
+            if (!empty($last_invoice[0]) && $invoice_number = wpinv_get_invoice_number($last_invoice[0])) {
2142
+                if (is_numeric($invoice_number)) {
2143 2143
                     $number = $invoice_number;
2144 2144
                 } else {
2145
-                    $number = wpinv_clean_invoice_number( $invoice_number );
2145
+                    $number = wpinv_clean_invoice_number($invoice_number);
2146 2146
                 }
2147 2147
             }
2148 2148
 
2149
-            if ( empty( $number ) ) {
2149
+            if (empty($number)) {
2150 2150
                 $increment_number = false;
2151 2151
                 $number = $start;
2152
-                $save_number = ( $number - 1 );
2152
+                $save_number = ($number - 1);
2153 2153
             } else {
2154 2154
                 $save_number = $number;
2155 2155
             }
2156 2156
         }
2157 2157
     }
2158 2158
 
2159
-    if ( $start > $number ) {
2159
+    if ($start > $number) {
2160 2160
         $increment_number = false;
2161 2161
         $number = $start;
2162
-        $save_number = ( $number - 1 );
2162
+        $save_number = ($number - 1);
2163 2163
     }
2164 2164
 
2165
-    if ( $save_number !== false ) {
2166
-        update_option( 'wpinv_last_invoice_number', $save_number );
2165
+    if ($save_number !== false) {
2166
+        update_option('wpinv_last_invoice_number', $save_number);
2167 2167
     }
2168 2168
     
2169
-    $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number );
2169
+    $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number);
2170 2170
 
2171
-    if ( $increment_number ) {
2171
+    if ($increment_number) {
2172 2172
         $number++;
2173 2173
     }
2174 2174
 
2175
-    return apply_filters( 'wpinv_get_next_invoice_number', $number );
2175
+    return apply_filters('wpinv_get_next_invoice_number', $number);
2176 2176
 }
2177 2177
 
2178
-function wpinv_clean_invoice_number( $number, $type = '' ) {
2179
-    $check = apply_filters( 'wpinv_pre_clean_invoice_number', null, $number, $type );
2180
-    if ( null !== $check ) {
2178
+function wpinv_clean_invoice_number($number, $type = '') {
2179
+    $check = apply_filters('wpinv_pre_clean_invoice_number', null, $number, $type);
2180
+    if (null !== $check) {
2181 2181
         return $check;
2182 2182
     }
2183 2183
     
2184
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2185
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2184
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2185
+    $postfix = wpinv_get_option('invoice_number_postfix');
2186 2186
 
2187
-    $number = preg_replace( '/' . $prefix . '/', '', $number, 1 );
2187
+    $number = preg_replace('/' . $prefix . '/', '', $number, 1);
2188 2188
 
2189
-    $length      = strlen( $number );
2190
-    $postfix_pos = strrpos( $number, $postfix );
2189
+    $length      = strlen($number);
2190
+    $postfix_pos = strrpos($number, $postfix);
2191 2191
     
2192
-    if ( false !== $postfix_pos ) {
2193
-        $number      = substr_replace( $number, '', $postfix_pos, $length );
2192
+    if (false !== $postfix_pos) {
2193
+        $number = substr_replace($number, '', $postfix_pos, $length);
2194 2194
     }
2195 2195
 
2196
-    $number = intval( $number );
2196
+    $number = intval($number);
2197 2197
 
2198
-    return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix );
2198
+    return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix);
2199 2199
 }
2200 2200
 
2201
-function wpinv_save_number_post_saved( $post_ID, $post, $update ) {
2201
+function wpinv_save_number_post_saved($post_ID, $post, $update) {
2202 2202
     global $wpdb;
2203 2203
 
2204
-    if ( !$update && !get_post_meta( $post_ID, '_wpinv_number', true ) ) {
2205
-        wpinv_update_invoice_number( $post_ID, $post->post_status != 'auto-draft', $post->post_type );
2204
+    if (!$update && !get_post_meta($post_ID, '_wpinv_number', true)) {
2205
+        wpinv_update_invoice_number($post_ID, $post->post_status != 'auto-draft', $post->post_type);
2206 2206
     }
2207 2207
 
2208
-    if ( !$update ) {
2209
-        $wpdb->update( $wpdb->posts, array( 'post_name' => wpinv_generate_post_name( $post_ID ) ), array( 'ID' => $post_ID ) );
2210
-        clean_post_cache( $post_ID );
2208
+    if (!$update) {
2209
+        $wpdb->update($wpdb->posts, array('post_name' => wpinv_generate_post_name($post_ID)), array('ID' => $post_ID));
2210
+        clean_post_cache($post_ID);
2211 2211
     }
2212 2212
 }
2213
-add_action( 'save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3 );
2213
+add_action('save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3);
2214 2214
 
2215
-function wpinv_save_number_post_updated( $post_ID, $post_after, $post_before ) {
2216
-    if ( !empty( $post_after->post_type ) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status ) {
2217
-        wpinv_update_invoice_number( $post_ID, true, $post_after->post_type );
2215
+function wpinv_save_number_post_updated($post_ID, $post_after, $post_before) {
2216
+    if (!empty($post_after->post_type) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status) {
2217
+        wpinv_update_invoice_number($post_ID, true, $post_after->post_type);
2218 2218
     }
2219 2219
 }
2220
-add_action( 'post_updated', 'wpinv_save_number_post_updated', 1, 3 );
2220
+add_action('post_updated', 'wpinv_save_number_post_updated', 1, 3);
2221 2221
 
2222
-function wpinv_update_invoice_number( $post_ID, $save_sequential = false, $type = '' ) {
2222
+function wpinv_update_invoice_number($post_ID, $save_sequential = false, $type = '') {
2223 2223
     global $wpdb;
2224 2224
     
2225
-    $check = apply_filters( 'wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type );
2226
-    if ( null !== $check ) {
2225
+    $check = apply_filters('wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type);
2226
+    if (null !== $check) {
2227 2227
         return $check;
2228 2228
     }
2229 2229
 
2230
-    if ( wpinv_sequential_number_active() ) {
2230
+    if (wpinv_sequential_number_active()) {
2231 2231
         $number = wpinv_get_next_invoice_number();
2232 2232
 
2233
-        if ( $save_sequential ) {
2234
-            update_option( 'wpinv_last_invoice_number', $number );
2233
+        if ($save_sequential) {
2234
+            update_option('wpinv_last_invoice_number', $number);
2235 2235
         }
2236 2236
     } else {
2237 2237
         $number = $post_ID;
2238 2238
     }
2239 2239
 
2240
-    $number = wpinv_format_invoice_number( $number );
2240
+    $number = wpinv_format_invoice_number($number);
2241 2241
 
2242
-    update_post_meta( $post_ID, '_wpinv_number', $number );
2242
+    update_post_meta($post_ID, '_wpinv_number', $number);
2243 2243
 
2244
-    $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) );
2244
+    $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID));
2245 2245
 
2246
-    clean_post_cache( $post_ID );
2246
+    clean_post_cache($post_ID);
2247 2247
 
2248 2248
     return $number;
2249 2249
 }
2250 2250
 
2251
-function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) {
2252
-    return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type );
2251
+function wpinv_post_name_prefix($post_type = 'wpi_invoice') {
2252
+    return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type);
2253 2253
 }
2254 2254
 
2255
-function wpinv_generate_post_name( $post_ID ) {
2256
-    $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) );
2257
-    $post_name = sanitize_title( $prefix . $post_ID );
2255
+function wpinv_generate_post_name($post_ID) {
2256
+    $prefix = wpinv_post_name_prefix(get_post_type($post_ID));
2257
+    $post_name = sanitize_title($prefix . $post_ID);
2258 2258
 
2259
-    return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix );
2259
+    return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix);
2260 2260
 }
2261 2261
 
2262
-function wpinv_is_invoice_viewed( $invoice_id ) {
2263
-    if ( empty( $invoice_id ) ) {
2262
+function wpinv_is_invoice_viewed($invoice_id) {
2263
+    if (empty($invoice_id)) {
2264 2264
         return false;
2265 2265
     }
2266 2266
 
2267
-    $viewed_meta = get_post_meta( $invoice_id, '_wpinv_is_viewed', true );
2267
+    $viewed_meta = get_post_meta($invoice_id, '_wpinv_is_viewed', true);
2268 2268
 
2269
-    return apply_filters( 'wpinv_is_invoice_viewed', 1 === (int)$viewed_meta, $invoice_id );
2269
+    return apply_filters('wpinv_is_invoice_viewed', 1 === (int) $viewed_meta, $invoice_id);
2270 2270
 }
2271 2271
 
2272 2272
 function wpinv_mark_invoice_viewed() {
2273 2273
 
2274
-    if ( isset( $_GET['invoice_key'] ) || is_singular( 'wpi_invoice' ) || is_singular( 'wpi_quote' ) ) {
2275
-        $invoice_key = isset( $_GET['invoice_key'] ) ? urldecode($_GET['invoice_key']) : '';
2274
+    if (isset($_GET['invoice_key']) || is_singular('wpi_invoice') || is_singular('wpi_quote')) {
2275
+        $invoice_key = isset($_GET['invoice_key']) ? urldecode($_GET['invoice_key']) : '';
2276 2276
 	    global $post;
2277 2277
 
2278
-        if(!empty($invoice_key)){
2278
+        if (!empty($invoice_key)) {
2279 2279
 	        $invoice_id = wpinv_get_invoice_id_by_key($invoice_key);
2280
-        } else if(!empty( $post ) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) {
2280
+        } else if (!empty($post) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) {
2281 2281
 			$invoice_id = $post->ID;
2282 2282
         } else {
2283 2283
         	return;
@@ -2285,60 +2285,60 @@  discard block
 block discarded – undo
2285 2285
 
2286 2286
         $invoice = new WPInv_Invoice($invoice_id);
2287 2287
 
2288
-        if(!$invoice_id){
2288
+        if (!$invoice_id) {
2289 2289
             return;
2290 2290
         }
2291 2291
 
2292
-	    if ( is_user_logged_in() ) {
2293
-		    if ( (int)$invoice->get_user_id() === get_current_user_id() ) {
2294
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2295
-		    } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2296
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2292
+	    if (is_user_logged_in()) {
2293
+		    if ((int) $invoice->get_user_id() === get_current_user_id()) {
2294
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2295
+		    } else if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2296
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2297 2297
 		    }
2298 2298
 	    } else {
2299
-		    if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2300
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2299
+		    if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2300
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2301 2301
 		    }
2302 2302
 	    }
2303 2303
     }
2304 2304
 
2305 2305
 }
2306
-add_action( 'template_redirect', 'wpinv_mark_invoice_viewed' );
2306
+add_action('template_redirect', 'wpinv_mark_invoice_viewed');
2307 2307
 
2308
-function wpinv_get_subscription( $invoice, $by_parent = false ) {
2309
-    if ( empty( $invoice ) ) {
2308
+function wpinv_get_subscription($invoice, $by_parent = false) {
2309
+    if (empty($invoice)) {
2310 2310
         return false;
2311 2311
     }
2312 2312
     
2313
-    if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) {
2314
-        $invoice = wpinv_get_invoice( $invoice );
2313
+    if (!is_object($invoice) && is_scalar($invoice)) {
2314
+        $invoice = wpinv_get_invoice($invoice);
2315 2315
     }
2316 2316
     
2317
-    if ( !( is_object( $invoice ) && ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) {
2317
+    if (!(is_object($invoice) && !empty($invoice->ID) && $invoice->is_recurring())) {
2318 2318
         return false;
2319 2319
     }
2320 2320
     
2321
-    $invoice_id = ! $by_parent && ! empty( $invoice->parent_invoice ) ? $invoice->parent_invoice : $invoice->ID;
2321
+    $invoice_id = !$by_parent && !empty($invoice->parent_invoice) ? $invoice->parent_invoice : $invoice->ID;
2322 2322
     
2323 2323
     $subs_db    = new WPInv_Subscriptions_DB;
2324
-    $subs       = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice_id, 'number' => 1 ) );
2324
+    $subs       = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice_id, 'number' => 1));
2325 2325
     
2326
-    if ( ! empty( $subs ) ) {
2327
-        return reset( $subs );
2326
+    if (!empty($subs)) {
2327
+        return reset($subs);
2328 2328
     }
2329 2329
     
2330 2330
     return false;
2331 2331
 }
2332 2332
 
2333
-function wpinv_filter_posts_clauses( $clauses, $wp_query ) {
2333
+function wpinv_filter_posts_clauses($clauses, $wp_query) {
2334 2334
     global $wpdb;
2335 2335
 
2336
-    if ( ! empty( $wp_query->query_vars['orderby'] ) && $wp_query->query_vars['orderby'] == 'invoice_date' ) {
2337
-        if ( !empty( $clauses['join'] ) ) {
2336
+    if (!empty($wp_query->query_vars['orderby']) && $wp_query->query_vars['orderby'] == 'invoice_date') {
2337
+        if (!empty($clauses['join'])) {
2338 2338
             $clauses['join'] .= " ";
2339 2339
         }
2340 2340
 
2341
-        if ( !empty( $clauses['fields'] ) ) {
2341
+        if (!empty($clauses['fields'])) {
2342 2342
             $clauses['fields'] .= ", ";
2343 2343
         }
2344 2344
 
@@ -2349,4 +2349,4 @@  discard block
 block discarded – undo
2349 2349
 
2350 2350
     return $clauses;
2351 2351
 }
2352
-add_filter( 'posts_clauses', 'wpinv_filter_posts_clauses', 10, 2 );
2353 2352
\ No newline at end of file
2353
+add_filter('posts_clauses', 'wpinv_filter_posts_clauses', 10, 2);
2354 2354
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/wpinv-admin-functions.php 1 patch
Spacing   +228 added lines, -228 removed lines patch added patch discarded remove patch
@@ -7,245 +7,245 @@  discard block
 block discarded – undo
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
-function wpinv_columns( $columns ) {
14
+function wpinv_columns($columns) {
15 15
     $columns = array(
16 16
         'cb'                => $columns['cb'],
17
-        'number'            => __( 'Number', 'invoicing' ),
18
-        'customer'          => __( 'Customer', 'invoicing' ),
19
-        'amount'            => __( 'Amount', 'invoicing' ),
20
-        'invoice_date'      => __( 'Created Date', 'invoicing' ),
21
-        'payment_date'      => __( 'Payment Date', 'invoicing' ),
22
-        'status'            => __( 'Status', 'invoicing' ),
23
-        'ID'                => __( 'ID', 'invoicing' ),
24
-        'wpi_actions'       => __( 'Actions', 'invoicing' ),
17
+        'number'            => __('Number', 'invoicing'),
18
+        'customer'          => __('Customer', 'invoicing'),
19
+        'amount'            => __('Amount', 'invoicing'),
20
+        'invoice_date'      => __('Created Date', 'invoicing'),
21
+        'payment_date'      => __('Payment Date', 'invoicing'),
22
+        'status'            => __('Status', 'invoicing'),
23
+        'ID'                => __('ID', 'invoicing'),
24
+        'wpi_actions'       => __('Actions', 'invoicing'),
25 25
     );
26 26
 
27
-    return apply_filters( 'wpi_invoice_table_columns', $columns );
27
+    return apply_filters('wpi_invoice_table_columns', $columns);
28 28
 }
29
-add_filter( 'manage_wpi_invoice_posts_columns', 'wpinv_columns' );
29
+add_filter('manage_wpi_invoice_posts_columns', 'wpinv_columns');
30 30
 
31
-function wpinv_bulk_actions( $actions ) {
32
-    if ( isset( $actions['edit'] ) ) {
33
-        unset( $actions['edit'] );
31
+function wpinv_bulk_actions($actions) {
32
+    if (isset($actions['edit'])) {
33
+        unset($actions['edit']);
34 34
     }
35 35
 
36 36
     return $actions;
37 37
 }
38
-add_filter( 'bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions' );
39
-add_filter( 'bulk_actions-edit-wpi_item', 'wpinv_bulk_actions' );
38
+add_filter('bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions');
39
+add_filter('bulk_actions-edit-wpi_item', 'wpinv_bulk_actions');
40 40
 
41
-function wpinv_sortable_columns( $columns ) {
41
+function wpinv_sortable_columns($columns) {
42 42
     $columns = array(
43
-        'ID'            => array( 'ID', true ),
44
-        'number'        => array( 'number', false ),
45
-        'amount'        => array( 'amount', false ),
46
-        'invoice_date'  => array( 'date', false ),
47
-        'payment_date'  => array( 'payment_date', true ),
48
-        'customer'      => array( 'customer', false ),
49
-        'status'        => array( 'status', false ),
43
+        'ID'            => array('ID', true),
44
+        'number'        => array('number', false),
45
+        'amount'        => array('amount', false),
46
+        'invoice_date'  => array('date', false),
47
+        'payment_date'  => array('payment_date', true),
48
+        'customer'      => array('customer', false),
49
+        'status'        => array('status', false),
50 50
     );
51 51
     
52
-    return apply_filters( 'wpi_invoice_table_sortable_columns', $columns );
52
+    return apply_filters('wpi_invoice_table_sortable_columns', $columns);
53 53
 }
54
-add_filter( 'manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns' );
54
+add_filter('manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns');
55 55
 
56
-add_action( 'manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
57
-function wpinv_posts_custom_column( $column_name, $post_id = 0 ) {
56
+add_action('manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
57
+function wpinv_posts_custom_column($column_name, $post_id = 0) {
58 58
     global $post, $wpi_invoice;
59 59
     
60
-    if ( empty( $wpi_invoice ) || ( !empty( $wpi_invoice ) && $post->ID != $wpi_invoice->ID ) ) {
61
-        $wpi_invoice = new WPInv_Invoice( $post->ID );
60
+    if (empty($wpi_invoice) || (!empty($wpi_invoice) && $post->ID != $wpi_invoice->ID)) {
61
+        $wpi_invoice = new WPInv_Invoice($post->ID);
62 62
     }
63 63
 
64 64
     $value = NULL;
65 65
     
66
-    switch ( $column_name ) {
66
+    switch ($column_name) {
67 67
         case 'email' :
68
-            $value   = $wpi_invoice->get_email();
68
+            $value = $wpi_invoice->get_email();
69 69
             break;
70 70
         case 'customer' :
71 71
             $customer_name = $wpi_invoice->get_user_full_name();
72
-            $customer_name = $customer_name != '' ? $customer_name : __( 'Customer', 'invoicing' );
73
-            $value = '<a href="' . esc_url( get_edit_user_link( $wpi_invoice->get_user_id() ) ) . '">' . $customer_name . '</a>';
74
-            if ( $email = $wpi_invoice->get_email() ) {
72
+            $customer_name = $customer_name != '' ? $customer_name : __('Customer', 'invoicing');
73
+            $value = '<a href="' . esc_url(get_edit_user_link($wpi_invoice->get_user_id())) . '">' . $customer_name . '</a>';
74
+            if ($email = $wpi_invoice->get_email()) {
75 75
                 $value .= '<br><a class="email" href="mailto:' . $email . '">' . $email . '</a>';
76 76
             }
77 77
             break;
78 78
         case 'amount' :
79
-            echo $wpi_invoice->get_total( true );
79
+            echo $wpi_invoice->get_total(true);
80 80
             break;
81 81
         case 'invoice_date' :
82
-            $date_format = get_option( 'date_format' );
82
+            $date_format = get_option('date_format');
83 83
             
84 84
             $m_time = $post->post_date;
85
-            $h_time = mysql2date( $date_format, $m_time );
85
+            $h_time = mysql2date($date_format, $m_time);
86 86
             
87
-            $value   = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>';
87
+            $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>';
88 88
             break;
89 89
         case 'payment_date' :
90
-            if ( $date_completed = $wpi_invoice->get_meta( '_wpinv_completed_date', true ) ) {
91
-                $date_format = get_option( 'date_format' );
90
+            if ($date_completed = $wpi_invoice->get_meta('_wpinv_completed_date', true)) {
91
+                $date_format = get_option('date_format');
92 92
                 
93 93
                 $m_time = $date_completed;
94
-                $h_time = mysql2date( $date_format, $m_time );
94
+                $h_time = mysql2date($date_format, $m_time);
95 95
                 
96
-                $value   = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>';
96
+                $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>';
97 97
             } else {
98 98
                 $value = '-';
99 99
             }
100 100
             break;
101 101
         case 'status' :
102
-            $value   = $wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' );
103
-            $is_viewed = wpinv_is_invoice_viewed( $wpi_invoice->ID );
104
-	        $gateway_title = wpinv_get_gateway_admin_label( $wpi_invoice->get_gateway() );
102
+            $value = $wpi_invoice->get_status(true) . ($wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '');
103
+            $is_viewed = wpinv_is_invoice_viewed($wpi_invoice->ID);
104
+	        $gateway_title = wpinv_get_gateway_admin_label($wpi_invoice->get_gateway());
105 105
 	        $offline_gateways = apply_filters('wpinv_offline_payments', array('bank_transfer', 'cheque', 'cod'));
106 106
 	        $is_offline_payment = in_array($wpi_invoice->get_gateway(), $offline_gateways) ? true : false;
107 107
 
108
-            if ( 1 == $is_viewed ) {
109
-                $value .= '&nbsp;&nbsp;<i class="fa fa-eye" title="'.__( 'Viewed by Customer', 'invoicing' ).'"></i>';
108
+            if (1 == $is_viewed) {
109
+                $value .= '&nbsp;&nbsp;<i class="fa fa-eye" title="' . __('Viewed by Customer', 'invoicing') . '"></i>';
110 110
             }
111
-            if ( ( $wpi_invoice->is_paid() || $wpi_invoice->is_refunded() || $is_offline_payment ) && ( isset( $gateway_title ) ) ) {
112
-                $value .= '<br><small class="meta gateway">' . wp_sprintf( __( 'Via %s', 'invoicing' ), $gateway_title ) . '</small>';
111
+            if (($wpi_invoice->is_paid() || $wpi_invoice->is_refunded() || $is_offline_payment) && (isset($gateway_title))) {
112
+                $value .= '<br><small class="meta gateway">' . wp_sprintf(__('Via %s', 'invoicing'), $gateway_title) . '</small>';
113 113
             }
114 114
             break;
115 115
         case 'number' :
116
-            $edit_link = get_edit_post_link( $post->ID );
117
-            $value = '<a title="' . esc_attr__( 'View Invoice Details', 'invoicing' ) . '" href="' . esc_url( $edit_link ) . '">' . $wpi_invoice->get_number() . '</a>';
116
+            $edit_link = get_edit_post_link($post->ID);
117
+            $value = '<a title="' . esc_attr__('View Invoice Details', 'invoicing') . '" href="' . esc_url($edit_link) . '">' . $wpi_invoice->get_number() . '</a>';
118 118
             break;
119 119
         case 'wpi_actions' :
120 120
             $value = '';
121
-            if ( !empty( $post->post_name ) ) {
122
-                $value .= '<a title="' . esc_attr__( 'Print invoice', 'invoicing' ) . '" href="' . esc_url( get_permalink( $post->ID ) ) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>';
121
+            if (!empty($post->post_name)) {
122
+                $value .= '<a title="' . esc_attr__('Print invoice', 'invoicing') . '" href="' . esc_url(get_permalink($post->ID)) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>';
123 123
             }
124 124
             
125
-            if ( $email = $wpi_invoice->get_email() ) {
126
-                $value .= '<a title="' . esc_attr__( 'Send invoice to customer', 'invoicing' ) . '" href="' . esc_url( add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) ) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>';
125
+            if ($email = $wpi_invoice->get_email()) {
126
+                $value .= '<a title="' . esc_attr__('Send invoice to customer', 'invoicing') . '" href="' . esc_url(add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID))) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>';
127 127
             }
128 128
             
129 129
             break;
130 130
         default:
131
-            $value = isset( $post->$column_name ) ? $post->$column_name : '';
131
+            $value = isset($post->$column_name) ? $post->$column_name : '';
132 132
             break;
133 133
 
134 134
     }
135
-    $value = apply_filters( 'wpinv_payments_table_column', $value, $post->ID, $column_name );
135
+    $value = apply_filters('wpinv_payments_table_column', $value, $post->ID, $column_name);
136 136
     
137
-    if ( $value !== NULL ) {
137
+    if ($value !== NULL) {
138 138
         echo $value;
139 139
     }
140 140
 }
141 141
 
142
-function wpinv_admin_post_id( $id = 0 ) {
142
+function wpinv_admin_post_id($id = 0) {
143 143
     global $post;
144 144
 
145
-    if ( isset( $id ) && ! empty( $id ) ) {
146
-        return (int)$id;
147
-    } else if ( get_the_ID() ) {
145
+    if (isset($id) && !empty($id)) {
146
+        return (int) $id;
147
+    } else if (get_the_ID()) {
148 148
         return (int) get_the_ID();
149
-    } else if ( isset( $post->ID ) && !empty( $post->ID ) ) {
149
+    } else if (isset($post->ID) && !empty($post->ID)) {
150 150
         return (int) $post->ID;
151
-    } else if ( isset( $_GET['post'] ) && !empty( $_GET['post'] ) ) {
151
+    } else if (isset($_GET['post']) && !empty($_GET['post'])) {
152 152
         return (int) $_GET['post'];
153
-    } else if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) {
153
+    } else if (isset($_GET['id']) && !empty($_GET['id'])) {
154 154
         return (int) $_GET['id'];
155
-    } else if ( isset( $_POST['id'] ) && !empty( $_POST['id'] ) ) {
155
+    } else if (isset($_POST['id']) && !empty($_POST['id'])) {
156 156
         return (int) $_POST['id'];
157 157
     } 
158 158
 
159 159
     return null;
160 160
 }
161 161
     
162
-function wpinv_admin_post_type( $id = 0 ) {
163
-    if ( !$id ) {
162
+function wpinv_admin_post_type($id = 0) {
163
+    if (!$id) {
164 164
         $id = wpinv_admin_post_id();
165 165
     }
166 166
     
167
-    $type = get_post_type( $id );
167
+    $type = get_post_type($id);
168 168
     
169
-    if ( !$type ) {
170
-        $type = isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) ? $_GET['post_type'] : null;
169
+    if (!$type) {
170
+        $type = isset($_GET['post_type']) && !empty($_GET['post_type']) ? $_GET['post_type'] : null;
171 171
     }
172 172
     
173
-    return apply_filters( 'wpinv_admin_post_type', $type, $id );
173
+    return apply_filters('wpinv_admin_post_type', $type, $id);
174 174
 }
175 175
 
176 176
 function wpinv_admin_messages() {
177 177
 	global $wpinv_options, $pagenow, $post;
178 178
 
179
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
180
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' );
179
+	if (isset($_GET['wpinv-message']) && 'discount_added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
180
+		 add_settings_error('wpinv-notices', 'wpinv-discount-added', __('Discount code added.', 'invoicing'), 'updated');
181 181
 	}
182 182
 
183
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
184
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' );
183
+	if (isset($_GET['wpinv-message']) && 'discount_add_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
184
+		add_settings_error('wpinv-notices', 'wpinv-discount-add-fail', __('There was a problem adding your discount code, please try again.', 'invoicing'), 'error');
185 185
 	}
186 186
 
187
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
188
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' );
187
+	if (isset($_GET['wpinv-message']) && 'discount_exists' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
188
+		add_settings_error('wpinv-notices', 'wpinv-discount-exists', __('A discount with that code already exists, please use a different code.', 'invoicing'), 'error');
189 189
 	}
190 190
 
191
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
192
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' );
191
+	if (isset($_GET['wpinv-message']) && 'discount_updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
192
+		 add_settings_error('wpinv-notices', 'wpinv-discount-updated', __('Discount code updated.', 'invoicing'), 'updated');
193 193
 	}
194 194
 
195
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
196
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' );
195
+	if (isset($_GET['wpinv-message']) && 'discount_update_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
196
+		add_settings_error('wpinv-notices', 'wpinv-discount-updated-fail', __('There was a problem updating your discount code, please try again.', 'invoicing'), 'error');
197 197
 	}
198 198
 
199
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
200
-		add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' );
199
+	if (isset($_GET['wpinv-message']) && 'invoice_deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
200
+		add_settings_error('wpinv-notices', 'wpinv-deleted', __('The invoice has been deleted.', 'invoicing'), 'updated');
201 201
 	}
202 202
 
203
-	if ( isset( $_GET['wpinv-message'] ) && 'email_disabled' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
204
-		add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Email notification is disabled. Please check settings.', 'invoicing' ), 'error' );
203
+	if (isset($_GET['wpinv-message']) && 'email_disabled' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
204
+		add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Email notification is disabled. Please check settings.', 'invoicing'), 'error');
205 205
 	}
206 206
 
207
-	if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
208
-		add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' );
207
+	if (isset($_GET['wpinv-message']) && 'email_sent' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
208
+		add_settings_error('wpinv-notices', 'wpinv-sent', __('The email has been sent to customer.', 'invoicing'), 'updated');
209 209
     }
210 210
     
211
-    if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
212
-		add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' );
211
+    if (isset($_GET['wpinv-message']) && 'email_fail' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
212
+		add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Fail to send email to the customer.', 'invoicing'), 'error');
213 213
     }
214 214
 
215
-    if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
216
-        add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' );
215
+    if (isset($_GET['wpinv-message']) && 'invoice-note-deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
216
+        add_settings_error('wpinv-notices', 'wpinv-note-deleted', __('The invoice note has been deleted.', 'invoicing'), 'updated');
217 217
     }
218 218
 
219
-	if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
220
-		add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' );
219
+	if (isset($_GET['wpinv-message']) && 'settings-imported' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
220
+		add_settings_error('wpinv-notices', 'wpinv-settings-imported', __('The settings have been imported.', 'invoicing'), 'updated');
221 221
 	}
222 222
 
223
-	if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
224
-		add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' );
223
+	if (isset($_GET['wpinv-message']) && 'note-added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
224
+		add_settings_error('wpinv-notices', 'wpinv-note-added', __('The invoice note has been added successfully.', 'invoicing'), 'updated');
225 225
 	}
226 226
 
227
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
228
-		add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' );
227
+	if (isset($_GET['wpinv-message']) && 'invoice-updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
228
+		add_settings_error('wpinv-notices', 'wpinv-updated', __('The invoice has been successfully updated.', 'invoicing'), 'updated');
229 229
 	}
230 230
     
231
-	if ( $pagenow == 'post.php' && !empty( $post->post_type ) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable( $post ) ) {
232
-		$message = apply_filters( 'wpinv_item_non_editable_message', __( 'This item in not editable.', 'invoicing' ), $post->ID );
231
+	if ($pagenow == 'post.php' && !empty($post->post_type) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable($post)) {
232
+		$message = apply_filters('wpinv_item_non_editable_message', __('This item in not editable.', 'invoicing'), $post->ID);
233 233
 
234
-		if ( !empty( $message ) ) {
235
-			add_settings_error( 'wpinv-notices', 'wpinv-edit-n', $message, 'updated' );
234
+		if (!empty($message)) {
235
+			add_settings_error('wpinv-notices', 'wpinv-edit-n', $message, 'updated');
236 236
 		}
237 237
 	}
238 238
 
239
-	settings_errors( 'wpinv-notices' );
239
+	settings_errors('wpinv-notices');
240 240
 }
241
-add_action( 'admin_notices', 'wpinv_admin_messages' );
241
+add_action('admin_notices', 'wpinv_admin_messages');
242 242
 
243
-add_action( 'admin_init', 'wpinv_show_test_payment_gateway_notice' );
244
-function wpinv_show_test_payment_gateway_notice(){
245
-    add_action( 'admin_notices', 'wpinv_test_payment_gateway_messages' );
243
+add_action('admin_init', 'wpinv_show_test_payment_gateway_notice');
244
+function wpinv_show_test_payment_gateway_notice() {
245
+    add_action('admin_notices', 'wpinv_test_payment_gateway_messages');
246 246
 }
247 247
 
248
-function wpinv_test_payment_gateway_messages(){
248
+function wpinv_test_payment_gateway_messages() {
249 249
     $gateways = wpinv_get_enabled_payment_gateways();
250 250
     $name = array(); $test_gateways = '';
251 251
     if ($gateways) {
@@ -256,9 +256,9 @@  discard block
 block discarded – undo
256 256
         }
257 257
         $test_gateways = implode(', ', $name);
258 258
     }
259
-    if(isset($test_gateways) && !empty($test_gateways)){
259
+    if (isset($test_gateways) && !empty($test_gateways)) {
260 260
         $link = admin_url('admin.php?page=wpinv-settings&tab=gateways');
261
-        $notice = wp_sprintf( __('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link );
261
+        $notice = wp_sprintf(__('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link);
262 262
         ?>
263 263
         <div class="notice notice-warning is-dismissible">
264 264
             <p><?php echo $notice; ?></p>
@@ -267,29 +267,29 @@  discard block
 block discarded – undo
267 267
     }
268 268
 }
269 269
 
270
-function wpinv_items_columns( $existing_columns ) {
270
+function wpinv_items_columns($existing_columns) {
271 271
     global $wpinv_euvat;
272 272
     
273 273
     $columns                = array();
274 274
     $columns['cb']          = $existing_columns['cb'];
275
-    $columns['title']       = __( 'Title', 'invoicing' );
276
-    $columns['price']       = __( 'Price', 'invoicing' );
277
-    if ( $wpinv_euvat->allow_vat_rules() ) {
278
-        $columns['vat_rule']    = __( 'VAT rule type', 'invoicing' );
275
+    $columns['title']       = __('Title', 'invoicing');
276
+    $columns['price']       = __('Price', 'invoicing');
277
+    if ($wpinv_euvat->allow_vat_rules()) {
278
+        $columns['vat_rule']    = __('VAT rule type', 'invoicing');
279 279
     }
280
-    if ( $wpinv_euvat->allow_vat_classes() ) {
281
-        $columns['vat_class']   = __( 'VAT class', 'invoicing' );
280
+    if ($wpinv_euvat->allow_vat_classes()) {
281
+        $columns['vat_class']   = __('VAT class', 'invoicing');
282 282
     }
283
-    $columns['type']        = __( 'Type', 'invoicing' );
284
-    $columns['recurring']   = __( 'Recurring', 'invoicing' );
285
-    $columns['date']        = __( 'Date', 'invoicing' );
286
-    $columns['id']          = __( 'ID', 'invoicing' );
283
+    $columns['type']        = __('Type', 'invoicing');
284
+    $columns['recurring']   = __('Recurring', 'invoicing');
285
+    $columns['date']        = __('Date', 'invoicing');
286
+    $columns['id']          = __('ID', 'invoicing');
287 287
 
288
-    return apply_filters( 'wpinv_items_columns', $columns );
288
+    return apply_filters('wpinv_items_columns', $columns);
289 289
 }
290
-add_filter( 'manage_wpi_item_posts_columns', 'wpinv_items_columns' );
290
+add_filter('manage_wpi_item_posts_columns', 'wpinv_items_columns');
291 291
 
292
-function wpinv_items_sortable_columns( $columns ) {
292
+function wpinv_items_sortable_columns($columns) {
293 293
     $columns['price']       = 'price';
294 294
     $columns['vat_rule']    = 'vat_rule';
295 295
     $columns['vat_class']   = 'vat_class';
@@ -299,151 +299,151 @@  discard block
 block discarded – undo
299 299
 
300 300
     return $columns;
301 301
 }
302
-add_filter( 'manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns' );
302
+add_filter('manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns');
303 303
 
304
-function wpinv_items_table_custom_column( $column ) {
304
+function wpinv_items_table_custom_column($column) {
305 305
     global $wpinv_euvat, $post, $wpi_item;
306 306
     
307
-    if ( empty( $wpi_item ) || ( !empty( $wpi_item ) && $post->ID != $wpi_item->ID ) ) {
308
-        $wpi_item = new WPInv_Item( $post->ID );
307
+    if (empty($wpi_item) || (!empty($wpi_item) && $post->ID != $wpi_item->ID)) {
308
+        $wpi_item = new WPInv_Item($post->ID);
309 309
     }
310 310
 
311
-    switch ( $column ) {
311
+    switch ($column) {
312 312
         case 'price' :
313
-            echo wpinv_item_price( $post->ID );
313
+            echo wpinv_item_price($post->ID);
314 314
         break;
315 315
         case 'vat_rule' :
316
-            echo $wpinv_euvat->item_rule_label( $post->ID );
316
+            echo $wpinv_euvat->item_rule_label($post->ID);
317 317
         break;
318 318
         case 'vat_class' :
319
-            echo $wpinv_euvat->item_class_label( $post->ID );
319
+            echo $wpinv_euvat->item_class_label($post->ID);
320 320
         break;
321 321
         case 'type' :
322
-            echo wpinv_item_type( $post->ID ) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>';
322
+            echo wpinv_item_type($post->ID) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>';
323 323
         break;
324 324
         case 'recurring' :
325
-            echo ( wpinv_is_recurring_item( $post->ID ) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>' );
325
+            echo (wpinv_is_recurring_item($post->ID) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>');
326 326
         break;
327 327
         case 'id' :
328 328
            echo $post->ID;
329 329
            echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '">
330
-                    <div class="price">' . wpinv_get_item_price( $post->ID ) . '</div>';
331
-                    if ( $wpinv_euvat->allow_vat_rules() ) {
332
-                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule( $post->ID ) . '</div>';
330
+                    <div class="price">' . wpinv_get_item_price($post->ID) . '</div>';
331
+                    if ($wpinv_euvat->allow_vat_rules()) {
332
+                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule($post->ID) . '</div>';
333 333
                     }
334
-                    if ( $wpinv_euvat->allow_vat_classes() ) {
335
-                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class( $post->ID ) . '</div>';
334
+                    if ($wpinv_euvat->allow_vat_classes()) {
335
+                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class($post->ID) . '</div>';
336 336
                     }
337
-                    echo '<div class="type">' . wpinv_get_item_type( $post->ID ) . '</div>
337
+                    echo '<div class="type">' . wpinv_get_item_type($post->ID) . '</div>
338 338
                 </div>';
339 339
         break;
340 340
     }
341 341
     
342
-    do_action( 'wpinv_items_table_column_item_' . $column, $wpi_item, $post );
342
+    do_action('wpinv_items_table_column_item_' . $column, $wpi_item, $post);
343 343
 }
344
-add_action( 'manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column' );
344
+add_action('manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column');
345 345
 
346 346
 function wpinv_add_items_filters() {
347 347
     global $wpinv_euvat, $typenow;
348 348
 
349 349
     // Checks if the current post type is 'item'
350
-    if ( $typenow == 'wpi_item') {
351
-        if ( $wpinv_euvat->allow_vat_rules() ) {
352
-            echo wpinv_html_select( array(
353
-                    'options'          => array_merge( array( '' => __( 'All VAT rules', 'invoicing' ) ), $wpinv_euvat->get_rules() ),
350
+    if ($typenow == 'wpi_item') {
351
+        if ($wpinv_euvat->allow_vat_rules()) {
352
+            echo wpinv_html_select(array(
353
+                    'options'          => array_merge(array('' => __('All VAT rules', 'invoicing')), $wpinv_euvat->get_rules()),
354 354
                     'name'             => 'vat_rule',
355 355
                     'id'               => 'vat_rule',
356
-                    'selected'         => ( isset( $_GET['vat_rule'] ) ? $_GET['vat_rule'] : '' ),
356
+                    'selected'         => (isset($_GET['vat_rule']) ? $_GET['vat_rule'] : ''),
357 357
                     'show_option_all'  => false,
358 358
                     'show_option_none' => false,
359 359
                     'class'            => 'gdmbx2-text-medium wpi_select2',
360
-                ) );
360
+                ));
361 361
         }
362 362
         
363
-        if ( $wpinv_euvat->allow_vat_classes() ) {
364
-            echo wpinv_html_select( array(
365
-                    'options'          => array_merge( array( '' => __( 'All VAT classes', 'invoicing' ) ), $wpinv_euvat->get_all_classes() ),
363
+        if ($wpinv_euvat->allow_vat_classes()) {
364
+            echo wpinv_html_select(array(
365
+                    'options'          => array_merge(array('' => __('All VAT classes', 'invoicing')), $wpinv_euvat->get_all_classes()),
366 366
                     'name'             => 'vat_class',
367 367
                     'id'               => 'vat_class',
368
-                    'selected'         => ( isset( $_GET['vat_class'] ) ? $_GET['vat_class'] : '' ),
368
+                    'selected'         => (isset($_GET['vat_class']) ? $_GET['vat_class'] : ''),
369 369
                     'show_option_all'  => false,
370 370
                     'show_option_none' => false,
371 371
                     'class'            => 'gdmbx2-text-medium wpi_select2',
372
-                ) );
372
+                ));
373 373
         }
374 374
             
375
-        echo wpinv_html_select( array(
376
-                'options'          => array_merge( array( '' => __( 'All item types', 'invoicing' ) ), wpinv_get_item_types() ),
375
+        echo wpinv_html_select(array(
376
+                'options'          => array_merge(array('' => __('All item types', 'invoicing')), wpinv_get_item_types()),
377 377
                 'name'             => 'type',
378 378
                 'id'               => 'type',
379
-                'selected'         => ( isset( $_GET['type'] ) ? $_GET['type'] : '' ),
379
+                'selected'         => (isset($_GET['type']) ? $_GET['type'] : ''),
380 380
                 'show_option_all'  => false,
381 381
                 'show_option_none' => false,
382 382
                 'class'            => 'gdmbx2-text-medium',
383
-            ) );
383
+            ));
384 384
 
385
-        if ( isset( $_REQUEST['all_posts'] ) && '1' === $_REQUEST['all_posts'] ) {
385
+        if (isset($_REQUEST['all_posts']) && '1' === $_REQUEST['all_posts']) {
386 386
             echo '<input type="hidden" name="all_posts" value="1" />';
387 387
         }
388 388
     }
389 389
 }
390
-add_action( 'restrict_manage_posts', 'wpinv_add_items_filters', 100 );
390
+add_action('restrict_manage_posts', 'wpinv_add_items_filters', 100);
391 391
 
392
-function wpinv_send_invoice_after_save( $invoice ) {
393
-    if ( empty( $_POST['wpi_save_send'] ) ) {
392
+function wpinv_send_invoice_after_save($invoice) {
393
+    if (empty($_POST['wpi_save_send'])) {
394 394
         return;
395 395
     }
396 396
     
397
-    if ( !empty( $invoice->ID ) && !empty( $invoice->post_type ) && 'wpi_invoice' == $invoice->post_type ) {
398
-        wpinv_user_invoice_notification( $invoice->ID );
397
+    if (!empty($invoice->ID) && !empty($invoice->post_type) && 'wpi_invoice' == $invoice->post_type) {
398
+        wpinv_user_invoice_notification($invoice->ID);
399 399
     }
400 400
 }
401
-add_action( 'wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1 );
401
+add_action('wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1);
402 402
 
403
-function wpinv_send_register_new_user( $data, $postarr ) {
404
-    if ( wpinv_current_user_can_manage_invoicing() && !empty( $data['post_type'] ) && ( 'wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'] ) ) {
405
-        $is_new_user = !empty( $postarr['wpinv_new_user'] ) ? true : false;
406
-        $email = !empty( $postarr['wpinv_email'] ) && $postarr['wpinv_email'] && is_email( $postarr['wpinv_email'] ) ? $postarr['wpinv_email'] : NULL;
403
+function wpinv_send_register_new_user($data, $postarr) {
404
+    if (wpinv_current_user_can_manage_invoicing() && !empty($data['post_type']) && ('wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'])) {
405
+        $is_new_user = !empty($postarr['wpinv_new_user']) ? true : false;
406
+        $email = !empty($postarr['wpinv_email']) && $postarr['wpinv_email'] && is_email($postarr['wpinv_email']) ? $postarr['wpinv_email'] : NULL;
407 407
         
408
-        if ( $is_new_user && $email && !email_exists( $email ) ) {
409
-            $first_name = !empty( $postarr['wpinv_first_name'] ) ? sanitize_text_field( $postarr['wpinv_first_name'] ) : '';
410
-            $last_name = !empty( $postarr['wpinv_last_name'] ) ? sanitize_text_field( $postarr['wpinv_last_name'] ) : '';
411
-            $display_name = $first_name || $last_name ? trim( $first_name . ' ' . $last_name ) : '';
412
-            $user_nicename = $display_name ? trim( $display_name ) : $email;
413
-            $user_company = !empty( $postarr['wpinv_company'] ) ? sanitize_text_field( $postarr['wpinv_company'] ) : '';
408
+        if ($is_new_user && $email && !email_exists($email)) {
409
+            $first_name = !empty($postarr['wpinv_first_name']) ? sanitize_text_field($postarr['wpinv_first_name']) : '';
410
+            $last_name = !empty($postarr['wpinv_last_name']) ? sanitize_text_field($postarr['wpinv_last_name']) : '';
411
+            $display_name = $first_name || $last_name ? trim($first_name . ' ' . $last_name) : '';
412
+            $user_nicename = $display_name ? trim($display_name) : $email;
413
+            $user_company = !empty($postarr['wpinv_company']) ? sanitize_text_field($postarr['wpinv_company']) : '';
414 414
             
415
-            $user_login = sanitize_user( str_replace( ' ', '', $display_name ), true );
416
-            if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
415
+            $user_login = sanitize_user(str_replace(' ', '', $display_name), true);
416
+            if (!(validate_username($user_login) && !username_exists($user_login))) {
417 417
                 $new_user_login = strstr($email, '@', true);
418
-                if ( validate_username( $user_login ) && username_exists( $user_login ) ) {
419
-                    $user_login = sanitize_user($new_user_login, true );
418
+                if (validate_username($user_login) && username_exists($user_login)) {
419
+                    $user_login = sanitize_user($new_user_login, true);
420 420
                 }
421
-                if ( validate_username( $user_login ) && username_exists( $user_login ) ) {
422
-                    $user_append_text = rand(10,1000);
423
-                    $user_login = sanitize_user($new_user_login.$user_append_text, true );
421
+                if (validate_username($user_login) && username_exists($user_login)) {
422
+                    $user_append_text = rand(10, 1000);
423
+                    $user_login = sanitize_user($new_user_login . $user_append_text, true);
424 424
                 }
425 425
                 
426
-                if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
426
+                if (!(validate_username($user_login) && !username_exists($user_login))) {
427 427
                     $user_login = $email;
428 428
                 }
429 429
             }
430 430
             
431 431
             $userdata = array(
432 432
                 'user_login' => $user_login,
433
-                'user_pass' => wp_generate_password( 12, false ),
434
-                'user_email' => sanitize_text_field( $email ),
433
+                'user_pass' => wp_generate_password(12, false),
434
+                'user_email' => sanitize_text_field($email),
435 435
                 'first_name' => $first_name,
436 436
                 'last_name' => $last_name,
437
-                'user_nicename' => wpinv_utf8_substr( $user_nicename, 0, 50 ),
437
+                'user_nicename' => wpinv_utf8_substr($user_nicename, 0, 50),
438 438
                 'nickname' => $display_name,
439 439
                 'display_name' => $display_name,
440 440
             );
441 441
 
442
-            $userdata = apply_filters( 'wpinv_register_new_user_data', $userdata );
442
+            $userdata = apply_filters('wpinv_register_new_user_data', $userdata);
443 443
             
444
-            $new_user_id = wp_insert_user( $userdata );
444
+            $new_user_id = wp_insert_user($userdata);
445 445
             
446
-            if ( !is_wp_error( $new_user_id ) ) {
446
+            if (!is_wp_error($new_user_id)) {
447 447
                 $data['post_author'] = $new_user_id;
448 448
                 $_POST['post_author'] = $new_user_id;
449 449
                 $_POST['post_author_override'] = $new_user_id;
@@ -464,72 +464,72 @@  discard block
 block discarded – undo
464 464
                 
465 465
                 $meta = array();
466 466
                 ///$meta['_wpinv_user_id'] = $new_user_id;
467
-                foreach ( $meta_fields as $field ) {
468
-                    $meta['_wpinv_' . $field] = isset( $postarr['wpinv_' . $field] ) ? sanitize_text_field( $postarr['wpinv_' . $field] ) : '';
467
+                foreach ($meta_fields as $field) {
468
+                    $meta['_wpinv_' . $field] = isset($postarr['wpinv_' . $field]) ? sanitize_text_field($postarr['wpinv_' . $field]) : '';
469 469
                 }
470 470
                 
471
-                $meta = apply_filters( 'wpinv_register_new_user_meta', $meta, $new_user_id );
471
+                $meta = apply_filters('wpinv_register_new_user_meta', $meta, $new_user_id);
472 472
 
473 473
                 // Update user meta.
474
-                foreach ( $meta as $key => $value ) {
475
-                    update_user_meta( $new_user_id, $key, $value );
474
+                foreach ($meta as $key => $value) {
475
+                    update_user_meta($new_user_id, $key, $value);
476 476
                 }
477 477
                 
478
-                if ( function_exists( 'wp_send_new_user_notifications' ) ) {
478
+                if (function_exists('wp_send_new_user_notifications')) {
479 479
                     // Send email notifications related to the creation of new user.
480
-                    wp_send_new_user_notifications( $new_user_id, 'user' );
480
+                    wp_send_new_user_notifications($new_user_id, 'user');
481 481
                 }
482 482
             } else {
483
-                wpinv_error_log( $new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__ );
483
+                wpinv_error_log($new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__);
484 484
             }
485 485
         }
486 486
     }
487 487
     
488 488
     return $data;
489 489
 }
490
-add_filter( 'wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2 );
490
+add_filter('wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2);
491 491
 
492
-function wpinv_show_recurring_supported_gateways( $item_ID ) {
492
+function wpinv_show_recurring_supported_gateways($item_ID) {
493 493
     $all_gateways = wpinv_get_payment_gateways();
494 494
 
495
-    if ( !empty( $all_gateways ) ) {
495
+    if (!empty($all_gateways)) {
496 496
         $gateways = array();
497 497
 
498
-        foreach ( $all_gateways as $key => $gateway ) {
499
-            if ( wpinv_gateway_support_subscription( $key ) ) {
498
+        foreach ($all_gateways as $key => $gateway) {
499
+            if (wpinv_gateway_support_subscription($key)) {
500 500
                 $gateways[] = $gateway['admin_label'];
501 501
             }
502 502
         }
503 503
 
504
-        if ( !empty( $gateways ) ) {
504
+        if (!empty($gateways)) {
505 505
             ?>
506
-            <span class="description"><?php echo wp_sprintf( __( 'Recurring payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ); ?></span>
506
+            <span class="description"><?php echo wp_sprintf(__('Recurring payments only supported by: %s', 'invoicing'), implode(', ', $gateways)); ?></span>
507 507
             <?php
508 508
         }
509 509
     }
510 510
 }
511
-add_action( 'wpinv_item_price_field', 'wpinv_show_recurring_supported_gateways', -10, 1 );
511
+add_action('wpinv_item_price_field', 'wpinv_show_recurring_supported_gateways', -10, 1);
512 512
 
513
-function wpinv_post_updated_messages( $messages ) {
513
+function wpinv_post_updated_messages($messages) {
514 514
     global $post, $post_ID;
515 515
 
516 516
     $messages['wpi_discount'] = array(
517 517
         0   => '',
518
-        1   => __( 'Discount updated.', 'invoicing' ),
519
-        2   => __( 'Custom field updated.', 'invoicing' ),
520
-        3   => __( 'Custom field deleted.', 'invoicing' ),
521
-        4   => __( 'Discount updated.', 'invoicing' ),
522
-        5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
523
-        6   => __( 'Discount updated.', 'invoicing' ),
524
-        7   => __( 'Discount saved.', 'invoicing' ),
525
-        8   => __( 'Discount submitted.', 'invoicing' ),
526
-        9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
527
-        10  => __( 'Discount draft updated.', 'invoicing' ),
518
+        1   => __('Discount updated.', 'invoicing'),
519
+        2   => __('Custom field updated.', 'invoicing'),
520
+        3   => __('Custom field deleted.', 'invoicing'),
521
+        4   => __('Discount updated.', 'invoicing'),
522
+        5   => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
523
+        6   => __('Discount updated.', 'invoicing'),
524
+        7   => __('Discount saved.', 'invoicing'),
525
+        8   => __('Discount submitted.', 'invoicing'),
526
+        9   => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))),
527
+        10  => __('Discount draft updated.', 'invoicing'),
528 528
     );
529 529
 
530 530
     return $messages;
531 531
 }
532
-add_filter( 'post_updated_messages', 'wpinv_post_updated_messages', 10, 1 );
532
+add_filter('post_updated_messages', 'wpinv_post_updated_messages', 10, 1);
533 533
 
534 534
 add_action('admin_init', 'admin_init_example_type');
535 535
 
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
 function admin_init_example_type() {
540 540
     global $typenow;
541 541
 
542
-    if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote' ) {
542
+    if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote') {
543 543
         add_filter('posts_search', 'posts_search_example_type', 10, 2);
544 544
     }
545 545
 }
@@ -554,9 +554,9 @@  discard block
 block discarded – undo
554 554
     global $wpdb;
555 555
 
556 556
     if ($query->is_main_query() && !empty($query->query['s'])) {
557
-        $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql( $query->query['s'] ) . "%' )";
558
-        if ( ! empty( $search ) ) {
559
-            $search = preg_replace( '/^ AND /', '', $search );
557
+        $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql($query->query['s']) . "%' )";
558
+        if (!empty($search)) {
559
+            $search = preg_replace('/^ AND /', '', $search);
560 560
             $search = " AND ( {$search} OR ( {$conditions_str} ) )";
561 561
         } else {
562 562
             $search = " AND ( {$conditions_str} )";
@@ -566,9 +566,9 @@  discard block
 block discarded – undo
566 566
     return $search;
567 567
 }
568 568
 
569
-add_action( 'admin_init', 'wpinv_reset_invoice_count' );
570
-function wpinv_reset_invoice_count(){
571
-    if(isset($_GET['reset_invoice_count']) && 1 == $_GET['reset_invoice_count'] && isset($_GET['_nonce']) && wp_verify_nonce($_GET['_nonce'], 'reset_invoice_count')) {
569
+add_action('admin_init', 'wpinv_reset_invoice_count');
570
+function wpinv_reset_invoice_count() {
571
+    if (isset($_GET['reset_invoice_count']) && 1 == $_GET['reset_invoice_count'] && isset($_GET['_nonce']) && wp_verify_nonce($_GET['_nonce'], 'reset_invoice_count')) {
572 572
         wpinv_update_option('invoice_sequence_start', 1);
573 573
         delete_option('wpinv_last_invoice_number');
574 574
         $url = add_query_arg(array('reset_invoice_done' => 1));
@@ -579,8 +579,8 @@  discard block
 block discarded – undo
579 579
 }
580 580
 
581 581
 add_action('admin_notices', 'wpinv_invoice_count_reset_message');
582
-function wpinv_invoice_count_reset_message(){
583
-    if(isset($_GET['reset_invoice_done']) && 1 == $_GET['reset_invoice_done']) {
582
+function wpinv_invoice_count_reset_message() {
583
+    if (isset($_GET['reset_invoice_done']) && 1 == $_GET['reset_invoice_done']) {
584 584
         $notice = __('Invoice number sequence reset successfully.', 'invoicing');
585 585
         ?>
586 586
         <div class="notice notice-success is-dismissible">
Please login to merge, or discard this patch.