Passed
Push — master ( 799b8f...1a4515 )
by Stiofan
03:39
created
includes/libraries/wp-session/class-wp-session.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -48,7 +48,6 @@
 block discarded – undo
48 48
 	/**
49 49
 	 * Retrieve the current session instance.
50 50
 	 *
51
-	 * @param bool $session_id Session ID from which to populate data.
52 51
 	 *
53 52
 	 * @return bool|WP_Session
54 53
 	 */
Please login to merge, or discard this patch.
Indentation   +205 added lines, -205 removed lines patch added patch discarded remove patch
@@ -17,215 +17,215 @@
 block discarded – undo
17 17
  * @since   3.7.0
18 18
  */
19 19
 final class WP_Session extends Recursive_ArrayAccess {
20
-	/**
21
-	 * ID of the current session.
22
-	 *
23
-	 * @var string
24
-	 */
25
-	public $session_id;
26
-
27
-	/**
28
-	 * Unix timestamp when session expires.
29
-	 *
30
-	 * @var int
31
-	 */
32
-	protected $expires;
33
-
34
-	/**
35
-	 * Unix timestamp indicating when the expiration time needs to be reset.
36
-	 *
37
-	 * @var int
38
-	 */
39
-	protected $exp_variant;
40
-
41
-	/**
42
-	 * Singleton instance.
43
-	 *
44
-	 * @var bool|WP_Session
45
-	 */
46
-	private static $instance = false;
47
-
48
-	/**
49
-	 * Retrieve the current session instance.
50
-	 *
51
-	 * @param bool $session_id Session ID from which to populate data.
52
-	 *
53
-	 * @return bool|WP_Session
54
-	 */
55
-	public static function get_instance() {
56
-		if ( ! self::$instance ) {
57
-			self::$instance = new self();
58
-		}
59
-
60
-		return self::$instance;
61
-	}
62
-
63
-	/**
64
-	 * Default constructor.
65
-	 * Will rebuild the session collection from the given session ID if it exists. Otherwise, will
66
-	 * create a new session with that ID.
67
-	 *
68
-	 * @param $session_id
69
-	 * @uses apply_filters Calls `wp_session_expiration` to determine how long until sessions expire.
70
-	 */
71
-	protected function __construct() {
72
-		if ( isset( $_COOKIE[WP_SESSION_COOKIE] ) ) {
73
-			$cookie = stripslashes( $_COOKIE[WP_SESSION_COOKIE] );
74
-			$cookie_crumbs = explode( '||', $cookie );
20
+    /**
21
+     * ID of the current session.
22
+     *
23
+     * @var string
24
+     */
25
+    public $session_id;
26
+
27
+    /**
28
+     * Unix timestamp when session expires.
29
+     *
30
+     * @var int
31
+     */
32
+    protected $expires;
33
+
34
+    /**
35
+     * Unix timestamp indicating when the expiration time needs to be reset.
36
+     *
37
+     * @var int
38
+     */
39
+    protected $exp_variant;
40
+
41
+    /**
42
+     * Singleton instance.
43
+     *
44
+     * @var bool|WP_Session
45
+     */
46
+    private static $instance = false;
47
+
48
+    /**
49
+     * Retrieve the current session instance.
50
+     *
51
+     * @param bool $session_id Session ID from which to populate data.
52
+     *
53
+     * @return bool|WP_Session
54
+     */
55
+    public static function get_instance() {
56
+        if ( ! self::$instance ) {
57
+            self::$instance = new self();
58
+        }
59
+
60
+        return self::$instance;
61
+    }
62
+
63
+    /**
64
+     * Default constructor.
65
+     * Will rebuild the session collection from the given session ID if it exists. Otherwise, will
66
+     * create a new session with that ID.
67
+     *
68
+     * @param $session_id
69
+     * @uses apply_filters Calls `wp_session_expiration` to determine how long until sessions expire.
70
+     */
71
+    protected function __construct() {
72
+        if ( isset( $_COOKIE[WP_SESSION_COOKIE] ) ) {
73
+            $cookie = stripslashes( $_COOKIE[WP_SESSION_COOKIE] );
74
+            $cookie_crumbs = explode( '||', $cookie );
75 75
 
76 76
             $this->session_id = preg_replace("/[^A-Za-z0-9_]/", '', $cookie_crumbs[0] );
77 77
             $this->expires = absint( $cookie_crumbs[1] );
78 78
             $this->exp_variant = absint( $cookie_crumbs[2] );
79 79
 
80
-			// Update the session expiration if we're past the variant time
81
-			if ( time() > $this->exp_variant ) {
82
-				$this->set_expiration();
83
-				delete_option( "_wp_session_expires_{$this->session_id}" );
84
-				add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' );
85
-			}
86
-		} else {
87
-			$this->session_id = WP_Session_Utils::generate_id();
88
-			$this->set_expiration();
89
-		}
90
-
91
-		$this->read_data();
92
-
93
-		$this->set_cookie();
94
-
95
-	}
96
-
97
-	/**
98
-	 * Set both the expiration time and the expiration variant.
99
-	 *
100
-	 * If the current time is below the variant, we don't update the session's expiration time. If it's
101
-	 * greater than the variant, then we update the expiration time in the database.  This prevents
102
-	 * writing to the database on every page load for active sessions and only updates the expiration
103
-	 * time if we're nearing when the session actually expires.
104
-	 *
105
-	 * By default, the expiration time is set to 30 minutes.
106
-	 * By default, the expiration variant is set to 24 minutes.
107
-	 *
108
-	 * As a result, the session expiration time - at a maximum - will only be written to the database once
109
-	 * every 24 minutes.  After 30 minutes, the session will have been expired. No cookie will be sent by
110
-	 * the browser, and the old session will be queued for deletion by the garbage collector.
111
-	 *
112
-	 * @uses apply_filters Calls `wp_session_expiration_variant` to get the max update window for session data.
113
-	 * @uses apply_filters Calls `wp_session_expiration` to get the standard expiration time for sessions.
114
-	 */
115
-	protected function set_expiration() {
116
-		$this->exp_variant = time() + (int) apply_filters( 'wp_session_expiration_variant', 24 * 60 );
117
-		$this->expires = time() + (int) apply_filters( 'wp_session_expiration', 30 * 60 );
118
-	}
119
-
120
-	/**
121
-	* Set the session cookie
122
-	* @uses apply_filters Calls `wp_session_cookie_secure` to set the $secure parameter of setcookie()
123
-	* @uses apply_filters Calls `wp_session_cookie_httponly` to set the $httponly parameter of setcookie()
124
-	*/
125
-	protected function set_cookie() {
126
-		if ( !defined( 'WPI_TESTING_MODE' ) ) {
127
-			try {
128
-				$secure = apply_filters('wp_session_cookie_secure', false);
129
-				$httponly = apply_filters('wp_session_cookie_httponly', false);
130
-				setcookie( WP_SESSION_COOKIE, $this->session_id . '||' . $this->expires . '||' . $this->exp_variant , $this->expires, COOKIEPATH, COOKIE_DOMAIN, $secure, $httponly );
131
-			} catch(Exception $e) {
132
-				error_log( 'Set Cookie Error: ' . $e->getMessage() );
133
-			}
134
-		}
135
-	}
136
-
137
-	/**
138
-	 * Read data from a transient for the current session.
139
-	 *
140
-	 * Automatically resets the expiration time for the session transient to some time in the future.
141
-	 *
142
-	 * @return array
143
-	 */
144
-	protected function read_data() {
145
-		$this->container = get_option( "_wp_session_{$this->session_id}", array() );
146
-
147
-		return $this->container;
148
-	}
149
-
150
-	/**
151
-	 * Write the data from the current session to the data storage system.
152
-	 */
153
-	public function write_data() {
154
-		$option_key = "_wp_session_{$this->session_id}";
80
+            // Update the session expiration if we're past the variant time
81
+            if ( time() > $this->exp_variant ) {
82
+                $this->set_expiration();
83
+                delete_option( "_wp_session_expires_{$this->session_id}" );
84
+                add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' );
85
+            }
86
+        } else {
87
+            $this->session_id = WP_Session_Utils::generate_id();
88
+            $this->set_expiration();
89
+        }
90
+
91
+        $this->read_data();
92
+
93
+        $this->set_cookie();
94
+
95
+    }
96
+
97
+    /**
98
+     * Set both the expiration time and the expiration variant.
99
+     *
100
+     * If the current time is below the variant, we don't update the session's expiration time. If it's
101
+     * greater than the variant, then we update the expiration time in the database.  This prevents
102
+     * writing to the database on every page load for active sessions and only updates the expiration
103
+     * time if we're nearing when the session actually expires.
104
+     *
105
+     * By default, the expiration time is set to 30 minutes.
106
+     * By default, the expiration variant is set to 24 minutes.
107
+     *
108
+     * As a result, the session expiration time - at a maximum - will only be written to the database once
109
+     * every 24 minutes.  After 30 minutes, the session will have been expired. No cookie will be sent by
110
+     * the browser, and the old session will be queued for deletion by the garbage collector.
111
+     *
112
+     * @uses apply_filters Calls `wp_session_expiration_variant` to get the max update window for session data.
113
+     * @uses apply_filters Calls `wp_session_expiration` to get the standard expiration time for sessions.
114
+     */
115
+    protected function set_expiration() {
116
+        $this->exp_variant = time() + (int) apply_filters( 'wp_session_expiration_variant', 24 * 60 );
117
+        $this->expires = time() + (int) apply_filters( 'wp_session_expiration', 30 * 60 );
118
+    }
119
+
120
+    /**
121
+     * Set the session cookie
122
+     * @uses apply_filters Calls `wp_session_cookie_secure` to set the $secure parameter of setcookie()
123
+     * @uses apply_filters Calls `wp_session_cookie_httponly` to set the $httponly parameter of setcookie()
124
+     */
125
+    protected function set_cookie() {
126
+        if ( !defined( 'WPI_TESTING_MODE' ) ) {
127
+            try {
128
+                $secure = apply_filters('wp_session_cookie_secure', false);
129
+                $httponly = apply_filters('wp_session_cookie_httponly', false);
130
+                setcookie( WP_SESSION_COOKIE, $this->session_id . '||' . $this->expires . '||' . $this->exp_variant , $this->expires, COOKIEPATH, COOKIE_DOMAIN, $secure, $httponly );
131
+            } catch(Exception $e) {
132
+                error_log( 'Set Cookie Error: ' . $e->getMessage() );
133
+            }
134
+        }
135
+    }
136
+
137
+    /**
138
+     * Read data from a transient for the current session.
139
+     *
140
+     * Automatically resets the expiration time for the session transient to some time in the future.
141
+     *
142
+     * @return array
143
+     */
144
+    protected function read_data() {
145
+        $this->container = get_option( "_wp_session_{$this->session_id}", array() );
146
+
147
+        return $this->container;
148
+    }
149
+
150
+    /**
151
+     * Write the data from the current session to the data storage system.
152
+     */
153
+    public function write_data() {
154
+        $option_key = "_wp_session_{$this->session_id}";
155 155
 		
156
-		if ( false === get_option( $option_key ) ) {
157
-			add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' );
158
-			add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' );
159
-		} else {
160
-			delete_option( "_wp_session_{$this->session_id}" );
161
-			add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' );
162
-		}
163
-	}
164
-
165
-	/**
166
-	 * Output the current container contents as a JSON-encoded string.
167
-	 *
168
-	 * @return string
169
-	 */
170
-	public function json_out() {
171
-		return json_encode( $this->container );
172
-	}
173
-
174
-	/**
175
-	 * Decodes a JSON string and, if the object is an array, overwrites the session container with its contents.
176
-	 *
177
-	 * @param string $data
178
-	 *
179
-	 * @return bool
180
-	 */
181
-	public function json_in( $data ) {
182
-		$array = json_decode( $data );
183
-
184
-		if ( is_array( $array ) ) {
185
-			$this->container = $array;
186
-			return true;
187
-		}
188
-
189
-		return false;
190
-	}
191
-
192
-	/**
193
-	 * Regenerate the current session's ID.
194
-	 *
195
-	 * @param bool $delete_old Flag whether or not to delete the old session data from the server.
196
-	 */
197
-	public function regenerate_id( $delete_old = false ) {
198
-		if ( $delete_old ) {
199
-			delete_option( "_wp_session_{$this->session_id}" );
200
-		}
201
-
202
-		$this->session_id = WP_Session_Utils::generate_id();
203
-
204
-		$this->set_cookie();
205
-	}
206
-
207
-	/**
208
-	 * Check if a session has been initialized.
209
-	 *
210
-	 * @return bool
211
-	 */
212
-	public function session_started() {
213
-		return !!self::$instance;
214
-	}
215
-
216
-	/**
217
-	 * Return the read-only cache expiration value.
218
-	 *
219
-	 * @return int
220
-	 */
221
-	public function cache_expiration() {
222
-		return $this->expires;
223
-	}
224
-
225
-	/**
226
-	 * Flushes all session variables.
227
-	 */
228
-	public function reset() {
229
-		$this->container = array();
230
-	}
156
+        if ( false === get_option( $option_key ) ) {
157
+            add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' );
158
+            add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' );
159
+        } else {
160
+            delete_option( "_wp_session_{$this->session_id}" );
161
+            add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' );
162
+        }
163
+    }
164
+
165
+    /**
166
+     * Output the current container contents as a JSON-encoded string.
167
+     *
168
+     * @return string
169
+     */
170
+    public function json_out() {
171
+        return json_encode( $this->container );
172
+    }
173
+
174
+    /**
175
+     * Decodes a JSON string and, if the object is an array, overwrites the session container with its contents.
176
+     *
177
+     * @param string $data
178
+     *
179
+     * @return bool
180
+     */
181
+    public function json_in( $data ) {
182
+        $array = json_decode( $data );
183
+
184
+        if ( is_array( $array ) ) {
185
+            $this->container = $array;
186
+            return true;
187
+        }
188
+
189
+        return false;
190
+    }
191
+
192
+    /**
193
+     * Regenerate the current session's ID.
194
+     *
195
+     * @param bool $delete_old Flag whether or not to delete the old session data from the server.
196
+     */
197
+    public function regenerate_id( $delete_old = false ) {
198
+        if ( $delete_old ) {
199
+            delete_option( "_wp_session_{$this->session_id}" );
200
+        }
201
+
202
+        $this->session_id = WP_Session_Utils::generate_id();
203
+
204
+        $this->set_cookie();
205
+    }
206
+
207
+    /**
208
+     * Check if a session has been initialized.
209
+     *
210
+     * @return bool
211
+     */
212
+    public function session_started() {
213
+        return !!self::$instance;
214
+    }
215
+
216
+    /**
217
+     * Return the read-only cache expiration value.
218
+     *
219
+     * @return int
220
+     */
221
+    public function cache_expiration() {
222
+        return $this->expires;
223
+    }
224
+
225
+    /**
226
+     * Flushes all session variables.
227
+     */
228
+    public function reset() {
229
+        $this->container = array();
230
+    }
231 231
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 	 * @return bool|WP_Session
54 54
 	 */
55 55
 	public static function get_instance() {
56
-		if ( ! self::$instance ) {
56
+		if (!self::$instance) {
57 57
 			self::$instance = new self();
58 58
 		}
59 59
 
@@ -69,19 +69,19 @@  discard block
 block discarded – undo
69 69
 	 * @uses apply_filters Calls `wp_session_expiration` to determine how long until sessions expire.
70 70
 	 */
71 71
 	protected function __construct() {
72
-		if ( isset( $_COOKIE[WP_SESSION_COOKIE] ) ) {
73
-			$cookie = stripslashes( $_COOKIE[WP_SESSION_COOKIE] );
74
-			$cookie_crumbs = explode( '||', $cookie );
72
+		if (isset($_COOKIE[WP_SESSION_COOKIE])) {
73
+			$cookie = stripslashes($_COOKIE[WP_SESSION_COOKIE]);
74
+			$cookie_crumbs = explode('||', $cookie);
75 75
 
76
-            $this->session_id = preg_replace("/[^A-Za-z0-9_]/", '', $cookie_crumbs[0] );
77
-            $this->expires = absint( $cookie_crumbs[1] );
78
-            $this->exp_variant = absint( $cookie_crumbs[2] );
76
+            $this->session_id = preg_replace("/[^A-Za-z0-9_]/", '', $cookie_crumbs[0]);
77
+            $this->expires = absint($cookie_crumbs[1]);
78
+            $this->exp_variant = absint($cookie_crumbs[2]);
79 79
 
80 80
 			// Update the session expiration if we're past the variant time
81
-			if ( time() > $this->exp_variant ) {
81
+			if (time() > $this->exp_variant) {
82 82
 				$this->set_expiration();
83
-				delete_option( "_wp_session_expires_{$this->session_id}" );
84
-				add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' );
83
+				delete_option("_wp_session_expires_{$this->session_id}");
84
+				add_option("_wp_session_expires_{$this->session_id}", $this->expires, '', 'no');
85 85
 			}
86 86
 		} else {
87 87
 			$this->session_id = WP_Session_Utils::generate_id();
@@ -113,8 +113,8 @@  discard block
 block discarded – undo
113 113
 	 * @uses apply_filters Calls `wp_session_expiration` to get the standard expiration time for sessions.
114 114
 	 */
115 115
 	protected function set_expiration() {
116
-		$this->exp_variant = time() + (int) apply_filters( 'wp_session_expiration_variant', 24 * 60 );
117
-		$this->expires = time() + (int) apply_filters( 'wp_session_expiration', 30 * 60 );
116
+		$this->exp_variant = time() + (int)apply_filters('wp_session_expiration_variant', 24 * 60);
117
+		$this->expires = time() + (int)apply_filters('wp_session_expiration', 30 * 60);
118 118
 	}
119 119
 
120 120
 	/**
@@ -123,13 +123,13 @@  discard block
 block discarded – undo
123 123
 	* @uses apply_filters Calls `wp_session_cookie_httponly` to set the $httponly parameter of setcookie()
124 124
 	*/
125 125
 	protected function set_cookie() {
126
-		if ( !defined( 'WPI_TESTING_MODE' ) ) {
126
+		if (!defined('WPI_TESTING_MODE')) {
127 127
 			try {
128 128
 				$secure = apply_filters('wp_session_cookie_secure', false);
129 129
 				$httponly = apply_filters('wp_session_cookie_httponly', false);
130
-				setcookie( WP_SESSION_COOKIE, $this->session_id . '||' . $this->expires . '||' . $this->exp_variant , $this->expires, COOKIEPATH, COOKIE_DOMAIN, $secure, $httponly );
131
-			} catch(Exception $e) {
132
-				error_log( 'Set Cookie Error: ' . $e->getMessage() );
130
+				setcookie(WP_SESSION_COOKIE, $this->session_id . '||' . $this->expires . '||' . $this->exp_variant, $this->expires, COOKIEPATH, COOKIE_DOMAIN, $secure, $httponly);
131
+			} catch (Exception $e) {
132
+				error_log('Set Cookie Error: ' . $e->getMessage());
133 133
 			}
134 134
 		}
135 135
 	}
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 	 * @return array
143 143
 	 */
144 144
 	protected function read_data() {
145
-		$this->container = get_option( "_wp_session_{$this->session_id}", array() );
145
+		$this->container = get_option("_wp_session_{$this->session_id}", array());
146 146
 
147 147
 		return $this->container;
148 148
 	}
@@ -153,12 +153,12 @@  discard block
 block discarded – undo
153 153
 	public function write_data() {
154 154
 		$option_key = "_wp_session_{$this->session_id}";
155 155
 		
156
-		if ( false === get_option( $option_key ) ) {
157
-			add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' );
158
-			add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' );
156
+		if (false === get_option($option_key)) {
157
+			add_option("_wp_session_{$this->session_id}", $this->container, '', 'no');
158
+			add_option("_wp_session_expires_{$this->session_id}", $this->expires, '', 'no');
159 159
 		} else {
160
-			delete_option( "_wp_session_{$this->session_id}" );
161
-			add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' );
160
+			delete_option("_wp_session_{$this->session_id}");
161
+			add_option("_wp_session_{$this->session_id}", $this->container, '', 'no');
162 162
 		}
163 163
 	}
164 164
 
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 	 * @return string
169 169
 	 */
170 170
 	public function json_out() {
171
-		return json_encode( $this->container );
171
+		return json_encode($this->container);
172 172
 	}
173 173
 
174 174
 	/**
@@ -178,10 +178,10 @@  discard block
 block discarded – undo
178 178
 	 *
179 179
 	 * @return bool
180 180
 	 */
181
-	public function json_in( $data ) {
182
-		$array = json_decode( $data );
181
+	public function json_in($data) {
182
+		$array = json_decode($data);
183 183
 
184
-		if ( is_array( $array ) ) {
184
+		if (is_array($array)) {
185 185
 			$this->container = $array;
186 186
 			return true;
187 187
 		}
@@ -194,9 +194,9 @@  discard block
 block discarded – undo
194 194
 	 *
195 195
 	 * @param bool $delete_old Flag whether or not to delete the old session data from the server.
196 196
 	 */
197
-	public function regenerate_id( $delete_old = false ) {
198
-		if ( $delete_old ) {
199
-			delete_option( "_wp_session_{$this->session_id}" );
197
+	public function regenerate_id($delete_old = false) {
198
+		if ($delete_old) {
199
+			delete_option("_wp_session_{$this->session_id}");
200 200
 		}
201 201
 
202 202
 		$this->session_id = WP_Session_Utils::generate_id();
Please login to merge, or discard this patch.
includes/libraries/wpinv-euvat/class-wpinv-euvat.php 3 patches
Doc Comments   +10 added lines patch added patch discarded remove patch
@@ -407,6 +407,10 @@  discard block
 block discarded – undo
407 407
         exit;
408 408
     }
409 409
     
410
+    /**
411
+     * @param string $source_url
412
+     * @param string $destination_file
413
+     */
410 414
     public static function geoip2_download_file( $source_url, $destination_file ) {
411 415
         $success    = false;
412 416
         $message    = '';
@@ -1192,6 +1196,9 @@  discard block
 block discarded – undo
1192 1196
         return apply_filters( 'wpinv_response_euvatrates', $response, $group );
1193 1197
     }    
1194 1198
     
1199
+    /**
1200
+     * @param boolean $is_digital
1201
+     */
1195 1202
     public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) {
1196 1203
         global $wpi_item_id, $wpi_country;
1197 1204
         
@@ -1412,6 +1419,9 @@  discard block
 block discarded – undo
1412 1419
         return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state );
1413 1420
     }
1414 1421
     
1422
+    /**
1423
+     * @param string|null $state
1424
+     */
1415 1425
     public static function find_rate( $country, $state, $rate, $class ) {
1416 1426
         global $wpi_zero_tax;
1417 1427
 
Please login to merge, or discard this patch.
Braces   +9 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly.
3
-if (!defined( 'ABSPATH' ) ) exit;
3
+if (!defined( 'ABSPATH' ) ) {
4
+    exit;
5
+}
4 6
 
5 7
 class WPInv_EUVat {
6 8
     private static $is_ajax = false;
@@ -1445,16 +1447,18 @@  discard block
 block discarded – undo
1445 1447
 
1446 1448
         if ( !empty( $tax_rates ) ) {
1447 1449
             foreach ( $tax_rates as $key => $tax_rate ) {
1448
-                if ( $country != $tax_rate['country'] )
1449
-                    continue;
1450
+                if ( $country != $tax_rate['country'] ) {
1451
+                                    continue;
1452
+                }
1450 1453
 
1451 1454
                 if ( !empty( $tax_rate['global'] ) ) {
1452 1455
                     if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) {
1453 1456
                         $rate = number_format( $tax_rate['rate'], 4 );
1454 1457
                     }
1455 1458
                 } else {
1456
-                    if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) )
1457
-                        continue;
1459
+                    if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) {
1460
+                                            continue;
1461
+                    }
1458 1462
 
1459 1463
                     $state_rate = $tax_rate['rate'];
1460 1464
                     if ( 0 !== $state_rate || !empty( $state_rate ) ) {
Please login to merge, or discard this patch.
Spacing   +712 added lines, -712 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly.
3
-if (!defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5 5
 class WPInv_EUVat {
6 6
     private static $is_ajax = false;
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
     private static $instance = false;
9 9
     
10 10
     public static function get_instance() {
11
-        if ( !self::$instance ) {
11
+        if (!self::$instance) {
12 12
             self::$instance = new self();
13 13
             self::$instance->actions();
14 14
         }
@@ -17,138 +17,138 @@  discard block
 block discarded – undo
17 17
     }
18 18
     
19 19
     public function __construct() {
20
-        self::$is_ajax          = defined( 'DOING_AJAX' ) && DOING_AJAX;
20
+        self::$is_ajax          = defined('DOING_AJAX') && DOING_AJAX;
21 21
         self::$default_country  = wpinv_get_default_country();
22 22
     }
23 23
     
24 24
     public static function actions() {
25
-        if ( is_admin() ) {
26
-            add_action( 'admin_enqueue_scripts', array( self::$instance, 'enqueue_admin_scripts' ) );
27
-            add_action( 'wpinv_settings_sections_taxes', array( self::$instance, 'section_vat_settings' ) ); 
28
-            add_action( 'wpinv_settings_taxes', array( self::$instance, 'vat_settings' ) );
29
-            add_filter( 'wpinv_settings_taxes-vat_sanitize', array( self::$instance, 'sanitize_vat_settings' ) );
30
-            add_filter( 'wpinv_settings_taxes-vat_rates_sanitize', array( self::$instance, 'sanitize_vat_rates' ) );
31
-            add_action( 'wp_ajax_wpinv_add_vat_class', array( self::$instance, 'add_class' ) );
32
-            add_action( 'wp_ajax_nopriv_wpinv_add_vat_class', array( self::$instance, 'add_class' ) );
33
-            add_action( 'wp_ajax_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) );
34
-            add_action( 'wp_ajax_nopriv_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) );
35
-            add_action( 'wp_ajax_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) );
36
-            add_action( 'wp_ajax_nopriv_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) );
37
-            add_action( 'wp_ajax_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) );
38
-            add_action( 'wp_ajax_nopriv_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) );
39
-        }
40
-        
41
-        add_action( 'wp_enqueue_scripts', array( self::$instance, 'enqueue_vat_scripts' ) );
42
-        add_filter( 'wpinv_default_billing_country', array( self::$instance, 'get_user_country' ), 10 );
43
-        add_filter( 'wpinv_get_user_country', array( self::$instance, 'set_user_country' ), 10 );
44
-        add_action( 'wp_ajax_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) );
45
-        add_action( 'wp_ajax_nopriv_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) );
46
-        add_action( 'wp_ajax_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) );
47
-        add_action( 'wp_ajax_nopriv_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) );
48
-        add_action( 'wpinv_invoice_print_after_line_items', array( self::$instance, 'show_vat_notice' ), 999, 1 );
49
-        if ( wpinv_use_taxes() ) {
50
-            add_action( 'wpinv_after_billing_fields', array( self::$instance, 'checkout_vat_fields' ) );
51
-            if ( self::allow_vat_rules() ) {
52
-                add_action( 'wpinv_checkout_error_checks', array( self::$instance, 'checkout_vat_validate' ), 10, 2 );
53
-                add_filter( 'wpinv_tax_rate', array( self::$instance, 'get_rate' ), 10, 4 );
25
+        if (is_admin()) {
26
+            add_action('admin_enqueue_scripts', array(self::$instance, 'enqueue_admin_scripts'));
27
+            add_action('wpinv_settings_sections_taxes', array(self::$instance, 'section_vat_settings')); 
28
+            add_action('wpinv_settings_taxes', array(self::$instance, 'vat_settings'));
29
+            add_filter('wpinv_settings_taxes-vat_sanitize', array(self::$instance, 'sanitize_vat_settings'));
30
+            add_filter('wpinv_settings_taxes-vat_rates_sanitize', array(self::$instance, 'sanitize_vat_rates'));
31
+            add_action('wp_ajax_wpinv_add_vat_class', array(self::$instance, 'add_class'));
32
+            add_action('wp_ajax_nopriv_wpinv_add_vat_class', array(self::$instance, 'add_class'));
33
+            add_action('wp_ajax_wpinv_delete_vat_class', array(self::$instance, 'delete_class'));
34
+            add_action('wp_ajax_nopriv_wpinv_delete_vat_class', array(self::$instance, 'delete_class'));
35
+            add_action('wp_ajax_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates'));
36
+            add_action('wp_ajax_nopriv_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates'));
37
+            add_action('wp_ajax_wpinv_geoip2', array(self::$instance, 'geoip2_download_database'));
38
+            add_action('wp_ajax_nopriv_wpinv_geoip2', array(self::$instance, 'geoip2_download_database'));
39
+        }
40
+        
41
+        add_action('wp_enqueue_scripts', array(self::$instance, 'enqueue_vat_scripts'));
42
+        add_filter('wpinv_default_billing_country', array(self::$instance, 'get_user_country'), 10);
43
+        add_filter('wpinv_get_user_country', array(self::$instance, 'set_user_country'), 10);
44
+        add_action('wp_ajax_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate'));
45
+        add_action('wp_ajax_nopriv_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate'));
46
+        add_action('wp_ajax_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset'));
47
+        add_action('wp_ajax_nopriv_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset'));
48
+        add_action('wpinv_invoice_print_after_line_items', array(self::$instance, 'show_vat_notice'), 999, 1);
49
+        if (wpinv_use_taxes()) {
50
+            add_action('wpinv_after_billing_fields', array(self::$instance, 'checkout_vat_fields'));
51
+            if (self::allow_vat_rules()) {
52
+                add_action('wpinv_checkout_error_checks', array(self::$instance, 'checkout_vat_validate'), 10, 2);
53
+                add_filter('wpinv_tax_rate', array(self::$instance, 'get_rate'), 10, 4);
54 54
             }
55 55
         }
56 56
     }        
57 57
     
58
-    public static function get_eu_states( $sort = true ) {
59
-        $eu_states = array( 'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE' );
60
-        if ( $sort ) {
61
-            $sort = sort( $eu_states );
58
+    public static function get_eu_states($sort = true) {
59
+        $eu_states = array('AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE');
60
+        if ($sort) {
61
+            $sort = sort($eu_states);
62 62
         }
63 63
         
64
-        return apply_filters( 'wpinv_get_eu_states', $eu_states, $sort );
64
+        return apply_filters('wpinv_get_eu_states', $eu_states, $sort);
65 65
     }
66 66
     
67
-    public static function get_gst_countries( $sort = true ) {
68
-        $gst_countries  = array( 'AU', 'NZ', 'CA', 'CN' );
67
+    public static function get_gst_countries($sort = true) {
68
+        $gst_countries = array('AU', 'NZ', 'CA', 'CN');
69 69
         
70
-        if ( $sort ) {
71
-            $sort = sort( $gst_countries );
70
+        if ($sort) {
71
+            $sort = sort($gst_countries);
72 72
         }
73 73
         
74
-        return apply_filters( 'wpinv_get_gst_countries', $gst_countries, $sort );
74
+        return apply_filters('wpinv_get_gst_countries', $gst_countries, $sort);
75 75
     }
76 76
     
77
-    public static function is_eu_state( $country_code ) {
78
-        $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_eu_states() ) ? true : false;
77
+    public static function is_eu_state($country_code) {
78
+        $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_eu_states()) ? true : false;
79 79
                 
80
-        return apply_filters( 'wpinv_is_eu_state', $return, $country_code );
80
+        return apply_filters('wpinv_is_eu_state', $return, $country_code);
81 81
     }
82 82
     
83
-    public static function is_gst_country( $country_code ) {
84
-        $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_gst_countries() ) ? true : false;
83
+    public static function is_gst_country($country_code) {
84
+        $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_gst_countries()) ? true : false;
85 85
                 
86
-        return apply_filters( 'wpinv_is_gst_country', $return, $country_code );
86
+        return apply_filters('wpinv_is_gst_country', $return, $country_code);
87 87
     }
88 88
     
89 89
     public static function enqueue_vat_scripts() {
90
-        if( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ) {
90
+        if (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules')) {
91 91
             self::load_vat_scripts();
92 92
         }
93 93
     }
94 94
 
95
-    public static function load_vat_scripts(){
96
-        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
95
+    public static function load_vat_scripts() {
96
+        $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
97 97
 
98
-        wp_register_script( 'wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
99
-        wp_register_script( 'wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
98
+        wp_register_script('wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
99
+        wp_register_script('wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
100 100
 
101
-        $vat_name   = self::get_vat_name();
101
+        $vat_name = self::get_vat_name();
102 102
 
103 103
         $vars = array();
104 104
         $vars['UseTaxes'] = wpinv_use_taxes();
105 105
         $vars['EUStates'] = self::get_eu_states();
106
-        $vars['NoRateSet'] = __( 'You have not set a rate. Do you want to continue?', 'invoicing' );
107
-        $vars['EmptyCompany'] = __( 'Please enter your registered company name!', 'invoicing' );
108
-        $vars['EmptyVAT'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
109
-        $vars['TotalsRefreshed'] = wp_sprintf( __( 'The invoice totals will be refreshed to update the %s.', 'invoicing' ), $vat_name );
110
-        $vars['ErrValidateVAT'] = wp_sprintf( __( 'Fail to validate the %s number!', 'invoicing' ), $vat_name );
111
-        $vars['ErrResetVAT'] = wp_sprintf( __( 'Fail to reset the %s number!', 'invoicing' ), $vat_name );
112
-        $vars['ErrInvalidVat'] = wp_sprintf( __( 'The %s number supplied does not have a valid format!', 'invoicing' ), $vat_name );
113
-        $vars['ErrInvalidResponse'] = __( 'An invalid response has been received from the server!', 'invoicing' );
106
+        $vars['NoRateSet'] = __('You have not set a rate. Do you want to continue?', 'invoicing');
107
+        $vars['EmptyCompany'] = __('Please enter your registered company name!', 'invoicing');
108
+        $vars['EmptyVAT'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
109
+        $vars['TotalsRefreshed'] = wp_sprintf(__('The invoice totals will be refreshed to update the %s.', 'invoicing'), $vat_name);
110
+        $vars['ErrValidateVAT'] = wp_sprintf(__('Fail to validate the %s number!', 'invoicing'), $vat_name);
111
+        $vars['ErrResetVAT'] = wp_sprintf(__('Fail to reset the %s number!', 'invoicing'), $vat_name);
112
+        $vars['ErrInvalidVat'] = wp_sprintf(__('The %s number supplied does not have a valid format!', 'invoicing'), $vat_name);
113
+        $vars['ErrInvalidResponse'] = __('An invalid response has been received from the server!', 'invoicing');
114 114
         $vars['ApplyVATRules'] = $vars['UseTaxes'] ? self::allow_vat_rules() : false;
115 115
         $vars['HideVatFields'] = $vars['ApplyVATRules'] ? self::hide_vat_fields() : true;
116
-        $vars['ErrResponse'] = __( 'The request response is invalid!', 'invoicing' );
117
-        $vars['ErrRateResponse'] = __( 'The get rate request response is invalid', 'invoicing' );
118
-        $vars['PageRefresh'] = __( 'The page will be refreshed in 10 seconds to show the new options.', 'invoicing' );
119
-        $vars['RequestResponseNotValidJSON'] = __( 'The get rate request response is not valid JSON', 'invoicing' );
120
-        $vars['GetRateRequestFailed'] = __( 'The get rate request failed: ', 'invoicing' );
121
-        $vars['NoRateInformationInResponse'] = __( 'The get rate request response does not contain any rate information', 'invoicing' );
122
-        $vars['RatesUpdated'] = __( 'The rates have been updated. Press the save button to record these new rates.', 'invoicing' );
123
-        $vars['IPAddressInformation'] = __( 'IP Address Information', 'invoicing' );
124
-        $vars['VatValidating'] = wp_sprintf( __( 'Validating %s number...', 'invoicing' ), $vat_name );
125
-        $vars['VatReseting'] = __( 'Reseting...', 'invoicing' );
126
-        $vars['VatValidated'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
127
-        $vars['VatNotValidated'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
128
-        $vars['ConfirmDeleteClass'] = __( 'Are you sure you wish to delete this rates class?', 'invoicing' );
116
+        $vars['ErrResponse'] = __('The request response is invalid!', 'invoicing');
117
+        $vars['ErrRateResponse'] = __('The get rate request response is invalid', 'invoicing');
118
+        $vars['PageRefresh'] = __('The page will be refreshed in 10 seconds to show the new options.', 'invoicing');
119
+        $vars['RequestResponseNotValidJSON'] = __('The get rate request response is not valid JSON', 'invoicing');
120
+        $vars['GetRateRequestFailed'] = __('The get rate request failed: ', 'invoicing');
121
+        $vars['NoRateInformationInResponse'] = __('The get rate request response does not contain any rate information', 'invoicing');
122
+        $vars['RatesUpdated'] = __('The rates have been updated. Press the save button to record these new rates.', 'invoicing');
123
+        $vars['IPAddressInformation'] = __('IP Address Information', 'invoicing');
124
+        $vars['VatValidating'] = wp_sprintf(__('Validating %s number...', 'invoicing'), $vat_name);
125
+        $vars['VatReseting'] = __('Reseting...', 'invoicing');
126
+        $vars['VatValidated'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
127
+        $vars['VatNotValidated'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
128
+        $vars['ConfirmDeleteClass'] = __('Are you sure you wish to delete this rates class?', 'invoicing');
129 129
         $vars['isFront'] = is_admin() ? false : true;
130
-        $vars['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' );
130
+        $vars['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce');
131 131
         $vars['baseCountry'] = wpinv_get_default_country();
132
-        $vars['disableVATSameCountry'] = ( self::same_country_rule() == 'no' ? true : false );
133
-        $vars['disableVATSimpleCheck'] = wpinv_get_option( 'vat_offline_check' ) ? true : false;
132
+        $vars['disableVATSameCountry'] = (self::same_country_rule() == 'no' ? true : false);
133
+        $vars['disableVATSimpleCheck'] = wpinv_get_option('vat_offline_check') ? true : false;
134 134
 
135
-        wp_enqueue_script( 'wpinv-vat-validation-script' );
136
-        wp_enqueue_script( 'wpinv-vat-script' );
137
-        wp_localize_script( 'wpinv-vat-script', 'WPInv_VAT_Vars', $vars );
135
+        wp_enqueue_script('wpinv-vat-validation-script');
136
+        wp_enqueue_script('wpinv-vat-script');
137
+        wp_localize_script('wpinv-vat-script', 'WPInv_VAT_Vars', $vars);
138 138
     }
139 139
 
140 140
     public static function enqueue_admin_scripts() {
141
-        if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) {
141
+        if (isset($_GET['page']) && 'wpinv-settings' == $_GET['page']) {
142 142
             self::load_vat_scripts();
143 143
         }
144 144
     }
145 145
     
146
-    public static function section_vat_settings( $sections ) {
147
-        if ( !empty( $sections ) ) {
148
-            $sections['vat'] = __( 'EU VAT Settings', 'invoicing' );
146
+    public static function section_vat_settings($sections) {
147
+        if (!empty($sections)) {
148
+            $sections['vat'] = __('EU VAT Settings', 'invoicing');
149 149
             
150
-            if ( self::allow_vat_classes() ) {
151
-                $sections['vat_rates'] = __( 'EU VAT Rates', 'invoicing' );
150
+            if (self::allow_vat_classes()) {
151
+                $sections['vat_rates'] = __('EU VAT Rates', 'invoicing');
152 152
             }
153 153
         }
154 154
         return $sections;
@@ -157,51 +157,51 @@  discard block
 block discarded – undo
157 157
     public static function vat_rates_settings() {
158 158
         $vat_classes = self::get_rate_classes();
159 159
         $vat_rates = array();
160
-        $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_new';
161
-        $current_url = remove_query_arg( 'wpi_sub' );
160
+        $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_new';
161
+        $current_url = remove_query_arg('wpi_sub');
162 162
         
163 163
         $vat_rates['vat_rates_header'] = array(
164 164
             'id' => 'vat_rates_header',
165
-            'name' => '<h3>' . __( 'Manage VAT Rates', 'invoicing' ) . '</h3>',
165
+            'name' => '<h3>' . __('Manage VAT Rates', 'invoicing') . '</h3>',
166 166
             'desc' => '',
167 167
             'type' => 'header',
168 168
             'size' => 'regular'
169 169
         );
170 170
         $vat_rates['vat_rates_class'] = array(
171 171
             'id'          => 'vat_rates_class',
172
-            'name'        => __( 'Edit VAT Rates', 'invoicing' ),
173
-            'desc'        => __( 'The standard rate will apply where no explicit rate is provided.', 'invoicing' ),
172
+            'name'        => __('Edit VAT Rates', 'invoicing'),
173
+            'desc'        => __('The standard rate will apply where no explicit rate is provided.', 'invoicing'),
174 174
             'type'        => 'select',
175
-            'options'     => array_merge( $vat_classes, array( '_new' => __( 'Add New Rate Class', 'invoicing' ) ) ),
176
-            'placeholder' => __( 'Select a VAT Rate', 'invoicing' ),
175
+            'options'     => array_merge($vat_classes, array('_new' => __('Add New Rate Class', 'invoicing'))),
176
+            'placeholder' => __('Select a VAT Rate', 'invoicing'),
177 177
             'selected'    => $vat_class,
178 178
             'onchange'    => 'document.location.href="' . $current_url . '&wpi_sub=" + this.value;',
179 179
         );
180 180
         
181
-        if ( $vat_class != '_standard' && $vat_class != '_new' ) {
181
+        if ($vat_class != '_standard' && $vat_class != '_new') {
182 182
             $vat_rates['vat_rate_delete'] = array(
183 183
                 'id'   => 'vat_rate_delete',
184 184
                 'type' => 'vat_rate_delete',
185 185
             );
186 186
         }
187 187
                     
188
-        if ( $vat_class == '_new' ) {
188
+        if ($vat_class == '_new') {
189 189
             $vat_rates['vat_rates_settings'] = array(
190 190
                 'id' => 'vat_rates_settings',
191
-                'name' => '<h3>' . __( 'Add New Rate Class', 'invoicing' ) . '</h3>',
191
+                'name' => '<h3>' . __('Add New Rate Class', 'invoicing') . '</h3>',
192 192
                 'type' => 'header',
193 193
             );
194 194
             $vat_rates['vat_rate_name'] = array(
195 195
                 'id'   => 'vat_rate_name',
196
-                'name' => __( 'Name', 'invoicing' ),
197
-                'desc' => __( 'A short name for the new VAT Rate class', 'invoicing' ),
196
+                'name' => __('Name', 'invoicing'),
197
+                'desc' => __('A short name for the new VAT Rate class', 'invoicing'),
198 198
                 'type' => 'text',
199 199
                 'size' => 'regular',
200 200
             );
201 201
             $vat_rates['vat_rate_desc'] = array(
202 202
                 'id'   => 'vat_rate_desc',
203
-                'name' => __( 'Description', 'invoicing' ),
204
-                'desc' => __( 'Manage VAT Rate class', 'invoicing' ),
203
+                'name' => __('Description', 'invoicing'),
204
+                'desc' => __('Manage VAT Rate class', 'invoicing'),
205 205
                 'type' => 'text',
206 206
                 'size' => 'regular',
207 207
             );
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
             $vat_rates['vat_rates'] = array(
214 214
                 'id'   => 'vat_rates',
215 215
                 'name' => '<h3>' . $vat_classes[$vat_class] . '</h3>',
216
-                'desc' => self::get_class_desc( $vat_class ),
216
+                'desc' => self::get_class_desc($vat_class),
217 217
                 'type' => 'vat_rates',
218 218
             );
219 219
         }
@@ -221,12 +221,12 @@  discard block
 block discarded – undo
221 221
         return $vat_rates;
222 222
     }
223 223
     
224
-    public static function vat_settings( $settings ) {
225
-        if ( !empty( $settings ) ) {    
224
+    public static function vat_settings($settings) {
225
+        if (!empty($settings)) {    
226 226
             $vat_settings = array();
227 227
             $vat_settings['vat_company_title'] = array(
228 228
                 'id' => 'vat_company_title',
229
-                'name' => '<h3>' . __( 'Your Company Details', 'invoicing' ) . '</h3>',
229
+                'name' => '<h3>' . __('Your Company Details', 'invoicing') . '</h3>',
230 230
                 'desc' => '',
231 231
                 'type' => 'header',
232 232
                 'size' => 'regular'
@@ -234,22 +234,22 @@  discard block
 block discarded – undo
234 234
             
235 235
             $vat_settings['vat_company_name'] = array(
236 236
                 'id' => 'vat_company_name',
237
-                'name' => __( 'Your Company Name', 'invoicing' ),
238
-                'desc' => wp_sprintf(__( 'Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
237
+                'name' => __('Your Company Name', 'invoicing'),
238
+                'desc' => wp_sprintf(__('Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
239 239
                 'type' => 'text',
240 240
                 'size' => 'regular',
241 241
             );
242 242
             
243 243
             $vat_settings['vat_number'] = array(
244 244
                 'id'   => 'vat_number',
245
-                'name' => __( 'Your VAT Number', 'invoicing' ),
245
+                'name' => __('Your VAT Number', 'invoicing'),
246 246
                 'type' => 'vat_number',
247 247
                 'size' => 'regular',
248 248
             );
249 249
 
250 250
             $vat_settings['vat_settings_title'] = array(
251 251
                 'id' => 'vat_settings_title',
252
-                'name' => '<h3>' . __( 'Apply VAT Settings', 'invoicing' ) . '</h3>',
252
+                'name' => '<h3>' . __('Apply VAT Settings', 'invoicing') . '</h3>',
253 253
                 'desc' => '',
254 254
                 'type' => 'header',
255 255
                 'size' => 'regular'
@@ -257,8 +257,8 @@  discard block
 block discarded – undo
257 257
 
258 258
             $vat_settings['apply_vat_rules'] = array(
259 259
                 'id' => 'apply_vat_rules',
260
-                'name' => __( 'Enable VAT Rules', 'invoicing' ),
261
-                'desc' => __( 'Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable unless you know what you are doing.', 'invoicing' ) . '</font>',
260
+                'name' => __('Enable VAT Rules', 'invoicing'),
261
+                'desc' => __('Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable unless you know what you are doing.', 'invoicing') . '</font>',
262 262
                 'type' => 'checkbox',
263 263
                 'std' => '1'
264 264
             );
@@ -274,8 +274,8 @@  discard block
 block discarded – undo
274 274
 
275 275
             $vat_settings['vat_prevent_b2c_purchase'] = array(
276 276
                 'id' => 'vat_prevent_b2c_purchase',
277
-                'name' => __( 'Prevent EU B2C Sales', 'invoicing' ),
278
-                'desc' => __( 'Enable this option if you are not registered for VAT in the EU.', 'invoicing' ),
277
+                'name' => __('Prevent EU B2C Sales', 'invoicing'),
278
+                'desc' => __('Enable this option if you are not registered for VAT in the EU.', 'invoicing'),
279 279
                 'type' => 'checkbox'
280 280
             );
281 281
 
@@ -283,21 +283,21 @@  discard block
 block discarded – undo
283 283
 
284 284
             $vat_settings['vat_same_country_rule'] = array(
285 285
                 'id'          => 'vat_same_country_rule',
286
-                'name'        => __( 'Same Country Rule', 'invoicing' ),
287
-                'desc'        => __( 'Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing' ),
286
+                'name'        => __('Same Country Rule', 'invoicing'),
287
+                'desc'        => __('Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing'),
288 288
                 'type'        => 'select',
289 289
                 'options'     => array(
290
-                    ''          => __( 'Normal', 'invoicing' ),
291
-                    'no'        => __( 'No VAT', 'invoicing' ),
292
-                    'always'    => __( 'Always apply VAT', 'invoicing' ),
290
+                    ''          => __('Normal', 'invoicing'),
291
+                    'no'        => __('No VAT', 'invoicing'),
292
+                    'always'    => __('Always apply VAT', 'invoicing'),
293 293
                 ),
294
-                'placeholder' => __( 'Select an option', 'invoicing' ),
294
+                'placeholder' => __('Select an option', 'invoicing'),
295 295
                 'std'         => ''
296 296
             );
297 297
 
298 298
             $vat_settings['vat_checkout_title'] = array(
299 299
                 'id' => 'vat_checkout_title',
300
-                'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>',
300
+                'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>',
301 301
                 'desc' => '',
302 302
                 'type' => 'header',
303 303
                 'size' => 'regular'
@@ -305,14 +305,14 @@  discard block
 block discarded – undo
305 305
 
306 306
             $vat_settings['vat_disable_fields'] = array(
307 307
                 'id' => 'vat_disable_fields',
308
-                'name' => __( 'Disable VAT Fields', 'invoicing' ),
309
-                'desc' => __( 'Disable VAT fields if Invoicing is being used for GST.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing' ) . '</font>',
308
+                'name' => __('Disable VAT Fields', 'invoicing'),
309
+                'desc' => __('Disable VAT fields if Invoicing is being used for GST.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing') . '</font>',
310 310
                 'type' => 'checkbox'
311 311
             );
312 312
 
313 313
             $vat_settings['vat_ip_lookup'] = array(
314 314
                 'id'   => 'vat_ip_lookup',
315
-                'name' => __( 'IP Country Look-up', 'invoicing' ),
315
+                'name' => __('IP Country Look-up', 'invoicing'),
316 316
                 'type' => 'vat_ip_lookup',
317 317
                 'size' => 'regular',
318 318
                 'std' => 'default'
@@ -320,21 +320,21 @@  discard block
 block discarded – undo
320 320
 
321 321
             $vat_settings['hide_ip_address'] = array(
322 322
                 'id' => 'hide_ip_address',
323
-                'name' => __( 'Hide IP Info at Checkout', 'invoicing' ),
324
-                'desc' => __( 'Hide the user IP info at checkout.', 'invoicing' ),
323
+                'name' => __('Hide IP Info at Checkout', 'invoicing'),
324
+                'desc' => __('Hide the user IP info at checkout.', 'invoicing'),
325 325
                 'type' => 'checkbox'
326 326
             );
327 327
 
328 328
             $vat_settings['vat_ip_country_default'] = array(
329 329
                 'id' => 'vat_ip_country_default',
330
-                'name' => __( 'Enable IP Country as Default', 'invoicing' ),
331
-                'desc' => __( 'Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing' ),
330
+                'name' => __('Enable IP Country as Default', 'invoicing'),
331
+                'desc' => __('Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing'),
332 332
                 'type' => 'checkbox'
333 333
             );
334 334
 
335 335
             $vat_settings['vies_validation_title'] = array(
336 336
                 'id' => 'vies_validation_title',
337
-                'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>',
337
+                'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>',
338 338
                 'desc' => '',
339 339
                 'type' => 'header',
340 340
                 'size' => 'regular'
@@ -342,37 +342,37 @@  discard block
 block discarded – undo
342 342
 
343 343
             $vat_settings['vat_vies_check'] = array(
344 344
                 'id' => 'vat_vies_check',
345
-                'name' => __( 'Disable VIES VAT ID Check', 'invoicing' ),
346
-                'desc' => wp_sprintf( __( 'Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
345
+                'name' => __('Disable VIES VAT ID Check', 'invoicing'),
346
+                'desc' => wp_sprintf(__('Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
347 347
                 'type' => 'checkbox'
348 348
             );
349 349
 
350 350
             $vat_settings['vat_disable_company_name_check'] = array(
351 351
                 'id' => 'vat_disable_company_name_check',
352
-                'name' => __( 'Disable VIES Name Check', 'invoicing' ),
353
-                'desc' => wp_sprintf( __( 'Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
352
+                'name' => __('Disable VIES Name Check', 'invoicing'),
353
+                'desc' => wp_sprintf(__('Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
354 354
                 'type' => 'checkbox'
355 355
             );
356 356
 
357 357
             $vat_settings['vat_offline_check'] = array(
358 358
                 'id' => 'vat_offline_check',
359
-                'name' => __( 'Disable Basic Checks', 'invoicing' ),
360
-                'desc' => __( 'Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing' ),
359
+                'name' => __('Disable Basic Checks', 'invoicing'),
360
+                'desc' => __('Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing'),
361 361
                 'type' => 'checkbox'
362 362
             );
363 363
             
364 364
 
365 365
             $settings['vat'] = $vat_settings;
366 366
             
367
-            if ( self::allow_vat_classes() ) {
367
+            if (self::allow_vat_classes()) {
368 368
                 $settings['vat_rates'] = self::vat_rates_settings();
369 369
             }
370 370
             
371 371
             $eu_fallback_rate = array(
372 372
                 'id'   => 'eu_fallback_rate',
373
-                'name' => '<h3>' . __( 'VAT rate for EU member states', 'invoicing' ) . '</h3>',
373
+                'name' => '<h3>' . __('VAT rate for EU member states', 'invoicing') . '</h3>',
374 374
                 'type' => 'eu_fallback_rate',
375
-                'desc' => __( 'Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing' ),
375
+                'desc' => __('Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing'),
376 376
                 'std'  => '20',
377 377
                 'size' => 'small'
378 378
             );
@@ -388,11 +388,11 @@  discard block
 block discarded – undo
388 388
         $database_url       = 'http' . (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === 'on' ? 's' : '') . '://geolite.maxmind.com/download/geoip/database/';
389 389
         $destination_dir    = $upload_dir['basedir'] . '/invoicing';
390 390
         
391
-        if ( !is_dir( $destination_dir ) ) { 
392
-            mkdir( $destination_dir );
391
+        if (!is_dir($destination_dir)) { 
392
+            mkdir($destination_dir);
393 393
         }
394 394
         
395
-        $database_files     = array(
395
+        $database_files = array(
396 396
             'country'   => array(
397 397
                 'source'        => $database_url . 'GeoLite2-Country.mmdb.gz',
398 398
                 'destination'   => $destination_dir . '/GeoLite2-Country.mmdb',
@@ -403,57 +403,57 @@  discard block
 block discarded – undo
403 403
             )
404 404
         );
405 405
 
406
-        foreach( $database_files as $database => $files ) {
407
-            $result = self::geoip2_download_file( $files['source'], $files['destination'] );
406
+        foreach ($database_files as $database => $files) {
407
+            $result = self::geoip2_download_file($files['source'], $files['destination']);
408 408
             
409
-            if ( empty( $result['success'] ) ) {
409
+            if (empty($result['success'])) {
410 410
                 echo $result['message'];
411 411
                 exit;
412 412
             }
413 413
             
414
-            wpinv_update_option( 'wpinv_geoip2_date_updated', current_time( 'timestamp' ) );
415
-            echo sprintf(__( 'GeoIP2 %s database updated successfully.', 'invoicing' ), $database ) . ' ';
414
+            wpinv_update_option('wpinv_geoip2_date_updated', current_time('timestamp'));
415
+            echo sprintf(__('GeoIP2 %s database updated successfully.', 'invoicing'), $database) . ' ';
416 416
         }
417 417
         
418 418
         exit;
419 419
     }
420 420
     
421
-    public static function geoip2_download_file( $source_url, $destination_file ) {
421
+    public static function geoip2_download_file($source_url, $destination_file) {
422 422
         $success    = false;
423 423
         $message    = '';
424 424
         
425
-        if ( !function_exists( 'download_url' ) ) {
426
-            require_once( ABSPATH . 'wp-admin/includes/file.php' );
425
+        if (!function_exists('download_url')) {
426
+            require_once(ABSPATH . 'wp-admin/includes/file.php');
427 427
         }
428 428
 
429
-        $temp_file  = download_url( $source_url );
429
+        $temp_file = download_url($source_url);
430 430
         
431
-        if ( is_wp_error( $temp_file ) ) {
432
-            $message = sprintf( __( 'Error while downloading GeoIp2 database( %s ): %s', 'invoicing' ), $source_url, $temp_file->get_error_message() );
431
+        if (is_wp_error($temp_file)) {
432
+            $message = sprintf(__('Error while downloading GeoIp2 database( %s ): %s', 'invoicing'), $source_url, $temp_file->get_error_message());
433 433
         } else {
434
-            $handle = gzopen( $temp_file, 'rb' );
434
+            $handle = gzopen($temp_file, 'rb');
435 435
             
436
-            if ( $handle ) {
437
-                $fopen  = fopen( $destination_file, 'wb' );
438
-                if ( $fopen ) {
439
-                    while ( ( $data = gzread( $handle, 4096 ) ) != false ) {
440
-                        fwrite( $fopen, $data );
436
+            if ($handle) {
437
+                $fopen = fopen($destination_file, 'wb');
438
+                if ($fopen) {
439
+                    while (($data = gzread($handle, 4096)) != false) {
440
+                        fwrite($fopen, $data);
441 441
                     }
442 442
 
443
-                    gzclose( $handle );
444
-                    fclose( $fopen );
443
+                    gzclose($handle);
444
+                    fclose($fopen);
445 445
                         
446 446
                     $success = true;
447 447
                 } else {
448
-                    gzclose( $handle );
449
-                    $message = sprintf( __( 'Error could not open destination GeoIp2 database file for writing: %s', 'invoicing' ), $destination_file );
448
+                    gzclose($handle);
449
+                    $message = sprintf(__('Error could not open destination GeoIp2 database file for writing: %s', 'invoicing'), $destination_file);
450 450
                 }
451 451
             } else {
452
-                $message = sprintf( __( 'Error could not open GeoIp2 database file for reading: %s', 'invoicing' ), $temp_file );
452
+                $message = sprintf(__('Error could not open GeoIp2 database file for reading: %s', 'invoicing'), $temp_file);
453 453
             }
454 454
             
455
-            if ( file_exists( $temp_file ) ) {
456
-                unlink( $temp_file );
455
+            if (file_exists($temp_file)) {
456
+                unlink($temp_file);
457 457
             }
458 458
         }
459 459
         
@@ -465,11 +465,11 @@  discard block
 block discarded – undo
465 465
     }
466 466
     
467 467
     public static function load_geoip2() {
468
-        if ( defined( 'WPINV_GEOIP2_LODDED' ) ) {
468
+        if (defined('WPINV_GEOIP2_LODDED')) {
469 469
             return;
470 470
         }
471 471
         
472
-        if ( !class_exists( '\MaxMind\Db\Reader' ) ) {
472
+        if (!class_exists('\MaxMind\Db\Reader')) {
473 473
             $maxmind_db_files = array(
474 474
                 'Reader/Decoder.php',
475 475
                 'Reader/InvalidDatabaseException.php',
@@ -478,12 +478,12 @@  discard block
 block discarded – undo
478 478
                 'Reader.php',
479 479
             );
480 480
             
481
-            foreach ( $maxmind_db_files as $key => $file ) {
482
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file );
481
+            foreach ($maxmind_db_files as $key => $file) {
482
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file);
483 483
             }
484 484
         }
485 485
         
486
-        if ( !class_exists( '\GeoIp2\Database\Reader' ) ) {        
486
+        if (!class_exists('\GeoIp2\Database\Reader')) {        
487 487
             $geoip2_files = array(
488 488
                 'ProviderInterface.php',
489 489
                 'Compat/JsonSerializable.php',
@@ -517,23 +517,23 @@  discard block
 block discarded – undo
517 517
                 'WebService/Client.php',
518 518
             );
519 519
             
520
-            foreach ( $geoip2_files as $key => $file ) {
521
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file );
520
+            foreach ($geoip2_files as $key => $file) {
521
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file);
522 522
             }
523 523
         }
524 524
 
525
-        define( 'WPINV_GEOIP2_LODDED', true );
525
+        define('WPINV_GEOIP2_LODDED', true);
526 526
     }
527 527
 
528 528
     public static function geoip2_country_dbfile() {
529 529
         $upload_dir = wp_upload_dir();
530 530
 
531
-        if ( !isset( $upload_dir['basedir'] ) ) {
531
+        if (!isset($upload_dir['basedir'])) {
532 532
             return false;
533 533
         }
534 534
 
535 535
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-Country.mmdb';
536
-        if ( !file_exists( $filename ) ) {
536
+        if (!file_exists($filename)) {
537 537
             return false;
538 538
         }
539 539
         
@@ -543,12 +543,12 @@  discard block
 block discarded – undo
543 543
     public static function geoip2_city_dbfile() {
544 544
         $upload_dir = wp_upload_dir();
545 545
 
546
-        if ( !isset( $upload_dir['basedir'] ) ) {
546
+        if (!isset($upload_dir['basedir'])) {
547 547
             return false;
548 548
         }
549 549
 
550 550
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-City.mmdb';
551
-        if ( !file_exists( $filename ) ) {
551
+        if (!file_exists($filename)) {
552 552
             return false;
553 553
         }
554 554
         
@@ -559,10 +559,10 @@  discard block
 block discarded – undo
559 559
         try {
560 560
             self::load_geoip2();
561 561
 
562
-            if ( $filename = self::geoip2_country_dbfile() ) {
563
-                return new \GeoIp2\Database\Reader( $filename );
562
+            if ($filename = self::geoip2_country_dbfile()) {
563
+                return new \GeoIp2\Database\Reader($filename);
564 564
             }
565
-        } catch( Exception $e ) {
565
+        } catch (Exception $e) {
566 566
             return false;
567 567
         }
568 568
         
@@ -573,173 +573,173 @@  discard block
 block discarded – undo
573 573
         try {
574 574
             self::load_geoip2();
575 575
 
576
-            if ( $filename = self::geoip2_city_dbfile() ) {
577
-                return new \GeoIp2\Database\Reader( $filename );
576
+            if ($filename = self::geoip2_city_dbfile()) {
577
+                return new \GeoIp2\Database\Reader($filename);
578 578
             }
579
-        } catch( Exception $e ) {
579
+        } catch (Exception $e) {
580 580
             return false;
581 581
         }
582 582
         
583 583
         return false;
584 584
     }
585 585
 
586
-    public static function geoip2_country_record( $ip_address ) {
586
+    public static function geoip2_country_record($ip_address) {
587 587
         try {
588 588
             $reader = self::geoip2_country_reader();
589 589
 
590
-            if ( $reader ) {
591
-                $record = $reader->country( $ip_address );
590
+            if ($reader) {
591
+                $record = $reader->country($ip_address);
592 592
                 
593
-                if ( !empty( $record->country->isoCode ) ) {
593
+                if (!empty($record->country->isoCode)) {
594 594
                     return $record;
595 595
                 }
596 596
             }
597
-        } catch(\InvalidArgumentException $e) {
598
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
597
+        } catch (\InvalidArgumentException $e) {
598
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
599 599
             
600 600
             return false;
601
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
602
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
601
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
602
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
603 603
             
604 604
             return false;
605
-        } catch( Exception $e ) {
605
+        } catch (Exception $e) {
606 606
             return false;
607 607
         }
608 608
         
609 609
         return false;
610 610
     }
611 611
 
612
-    public static function geoip2_city_record( $ip_address ) {
612
+    public static function geoip2_city_record($ip_address) {
613 613
         try {
614 614
             $reader = self::geoip2_city_reader();
615 615
 
616
-            if ( $reader ) {
617
-                $record = $reader->city( $ip_address );
616
+            if ($reader) {
617
+                $record = $reader->city($ip_address);
618 618
                 
619
-                if ( !empty( $record->country->isoCode ) ) {
619
+                if (!empty($record->country->isoCode)) {
620 620
                     return $record;
621 621
                 }
622 622
             }
623
-        } catch(\InvalidArgumentException $e) {
624
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
623
+        } catch (\InvalidArgumentException $e) {
624
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
625 625
             
626 626
             return false;
627
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
628
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
627
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
628
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
629 629
             
630 630
             return false;
631
-        } catch( Exception $e ) {
631
+        } catch (Exception $e) {
632 632
             return false;
633 633
         }
634 634
         
635 635
         return false;
636 636
     }
637 637
 
638
-    public static function geoip2_country_code( $ip_address ) {
639
-        $record = self::geoip2_country_record( $ip_address );
640
-        return !empty( $record->country->isoCode ) ? $record->country->isoCode : wpinv_get_default_country();
638
+    public static function geoip2_country_code($ip_address) {
639
+        $record = self::geoip2_country_record($ip_address);
640
+        return !empty($record->country->isoCode) ? $record->country->isoCode : wpinv_get_default_country();
641 641
     }
642 642
 
643 643
     // Find country by IP address.
644
-    public static function get_country_by_ip( $ip = '' ) {
644
+    public static function get_country_by_ip($ip = '') {
645 645
         global $wpinv_ip_address_country;
646 646
         
647
-        if ( !empty( $wpinv_ip_address_country ) ) {
647
+        if (!empty($wpinv_ip_address_country)) {
648 648
             return $wpinv_ip_address_country;
649 649
         }
650 650
         
651
-        if ( empty( $ip ) ) {
651
+        if (empty($ip)) {
652 652
             $ip = wpinv_get_ip();
653 653
         }
654 654
 
655
-        $ip_country_service = wpinv_get_option( 'vat_ip_lookup' );
656
-        $is_default         = empty( $ip_country_service ) || $ip_country_service === 'default' ? true : false;
655
+        $ip_country_service = wpinv_get_option('vat_ip_lookup');
656
+        $is_default         = empty($ip_country_service) || $ip_country_service === 'default' ? true : false;
657 657
 
658
-        if ( !empty( $ip ) && $ip !== '127.0.0.1' ) { // For 127.0.0.1(localhost) use default country.
659
-            if ( function_exists( 'geoip_country_code_by_name') && ( $ip_country_service === 'geoip' || $is_default ) ) {
658
+        if (!empty($ip) && $ip !== '127.0.0.1') { // For 127.0.0.1(localhost) use default country.
659
+            if (function_exists('geoip_country_code_by_name') && ($ip_country_service === 'geoip' || $is_default)) {
660 660
                 try {
661
-                    $wpinv_ip_address_country = geoip_country_code_by_name( $ip );
662
-                } catch( Exception $e ) {
663
-                    wpinv_error_log( $e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )' );
661
+                    $wpinv_ip_address_country = geoip_country_code_by_name($ip);
662
+                } catch (Exception $e) {
663
+                    wpinv_error_log($e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )');
664 664
                 }
665
-            } else if ( self::geoip2_country_dbfile() && ( $ip_country_service === 'geoip2' || $is_default ) ) {
666
-                $wpinv_ip_address_country = self::geoip2_country_code( $ip );
667
-            } else if ( function_exists( 'simplexml_load_file' ) && ( $ip_country_service === 'geoplugin' || $is_default ) ) {
668
-                $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
665
+            } else if (self::geoip2_country_dbfile() && ($ip_country_service === 'geoip2' || $is_default)) {
666
+                $wpinv_ip_address_country = self::geoip2_country_code($ip);
667
+            } else if (function_exists('simplexml_load_file') && ($ip_country_service === 'geoplugin' || $is_default)) {
668
+                $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
669 669
                 
670
-                if ( !empty( $load_xml ) && !empty( $load_xml->geoplugin_countryCode ) ) {
670
+                if (!empty($load_xml) && !empty($load_xml->geoplugin_countryCode)) {
671 671
                     $wpinv_ip_address_country = (string)$load_xml->geoplugin_countryCode;
672 672
                 }
673 673
             }
674 674
         }
675 675
 
676
-        if ( empty( $wpinv_ip_address_country ) ) {
676
+        if (empty($wpinv_ip_address_country)) {
677 677
             $wpinv_ip_address_country = wpinv_get_default_country();
678 678
         }
679 679
 
680 680
         return $wpinv_ip_address_country;
681 681
     }
682 682
     
683
-    public static function sanitize_vat_settings( $input ) {
683
+    public static function sanitize_vat_settings($input) {
684 684
         global $wpinv_options;
685 685
         
686 686
         $valid      = false;
687 687
         $message    = '';
688 688
         
689
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
690
-            if ( empty( $wpinv_options['vat_offline_check'] ) ) {
691
-                $valid = self::offline_check( $input['vat_number'] );
689
+        if (!empty($wpinv_options['vat_vies_check'])) {
690
+            if (empty($wpinv_options['vat_offline_check'])) {
691
+                $valid = self::offline_check($input['vat_number']);
692 692
             } else {
693 693
                 $valid = true;
694 694
             }
695 695
             
696
-            $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' );
696
+            $message = $valid ? '' : __('VAT number not validated', 'invoicing');
697 697
         } else {
698
-            $result = self::check_vat( $input['vat_number'] );
698
+            $result = self::check_vat($input['vat_number']);
699 699
             
700
-            if ( empty( $result['valid'] ) ) {
700
+            if (empty($result['valid'])) {
701 701
                 $valid      = false;
702 702
                 $message    = $result['message'];
703 703
             } else {
704
-                $valid      = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] );
705
-                $message    = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' );
704
+                $valid      = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']);
705
+                $message    = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing');
706 706
             }
707 707
         }
708 708
 
709
-        if ( $message && self::is_vat_validated() != $valid ) {
710
-            add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) );
709
+        if ($message && self::is_vat_validated() != $valid) {
710
+            add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error'));
711 711
         }
712 712
 
713 713
         $input['vat_valid'] = $valid;
714 714
         return $input;
715 715
     }
716 716
     
717
-    public static function sanitize_vat_rates( $input ) {
718
-        if( !current_user_can( 'manage_options' ) ) {
719
-            add_settings_error( 'wpinv-notices', '', __( 'Your account does not have permission to add rate classes.', 'invoicing' ), 'error' );
717
+    public static function sanitize_vat_rates($input) {
718
+        if (!current_user_can('manage_options')) {
719
+            add_settings_error('wpinv-notices', '', __('Your account does not have permission to add rate classes.', 'invoicing'), 'error');
720 720
             return $input;
721 721
         }
722 722
         
723 723
         $vat_classes = self::get_rate_classes();
724
-        $vat_class = !empty( $_REQUEST['wpi_vat_class'] ) && isset( $vat_classes[$_REQUEST['wpi_vat_class']] )? sanitize_text_field( $_REQUEST['wpi_vat_class'] ) : '';
724
+        $vat_class = !empty($_REQUEST['wpi_vat_class']) && isset($vat_classes[$_REQUEST['wpi_vat_class']]) ? sanitize_text_field($_REQUEST['wpi_vat_class']) : '';
725 725
         
726
-        if ( empty( $vat_class ) ) {
727
-            add_settings_error( 'wpinv-notices', '', __( 'No valid VAT rates class contained in the request to save rates.', 'invoicing' ), 'error' );
726
+        if (empty($vat_class)) {
727
+            add_settings_error('wpinv-notices', '', __('No valid VAT rates class contained in the request to save rates.', 'invoicing'), 'error');
728 728
             
729 729
             return $input;
730 730
         }
731 731
 
732
-        $new_rates = ! empty( $_POST['vat_rates'] ) ? array_values( $_POST['vat_rates'] ) : array();
732
+        $new_rates = !empty($_POST['vat_rates']) ? array_values($_POST['vat_rates']) : array();
733 733
 
734
-        if ( $vat_class === '_standard' ) {
734
+        if ($vat_class === '_standard') {
735 735
             // Save the active rates in the invoice settings
736
-            update_option( 'wpinv_tax_rates', $new_rates );
736
+            update_option('wpinv_tax_rates', $new_rates);
737 737
         } else {
738 738
             // Get the existing set of rates
739 739
             $rates = self::get_non_standard_rates();
740 740
             $rates[$vat_class] = $new_rates;
741 741
 
742
-            update_option( 'wpinv_vat_rates', $rates );
742
+            update_option('wpinv_vat_rates', $rates);
743 743
         }
744 744
         
745 745
         return $input;
@@ -749,71 +749,71 @@  discard block
 block discarded – undo
749 749
         $response = array();
750 750
         $response['success'] = false;
751 751
         
752
-        if ( !current_user_can( 'manage_options' ) ) {
753
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
754
-            wp_send_json( $response );
752
+        if (!current_user_can('manage_options')) {
753
+            $response['error'] = __('Invalid access!', 'invoicing');
754
+            wp_send_json($response);
755 755
         }
756 756
         
757
-        $vat_class_name = !empty( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false;
758
-        $vat_class_desc = !empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : false;
757
+        $vat_class_name = !empty($_POST['name']) ? sanitize_text_field($_POST['name']) : false;
758
+        $vat_class_desc = !empty($_POST['desc']) ? sanitize_text_field($_POST['desc']) : false;
759 759
         
760
-        if ( empty( $vat_class_name ) ) {
761
-            $response['error'] = __( 'Select the VAT rate name', 'invoicing' );
762
-            wp_send_json( $response );
760
+        if (empty($vat_class_name)) {
761
+            $response['error'] = __('Select the VAT rate name', 'invoicing');
762
+            wp_send_json($response);
763 763
         }
764 764
         
765 765
         $vat_classes = (array)self::get_rate_classes();
766 766
 
767
-        if ( !empty( $vat_classes ) && in_array( strtolower( $vat_class_name ), array_map( 'strtolower', array_values( $vat_classes ) ) ) ) {
768
-            $response['error'] = wp_sprintf( __( 'A VAT Rate name "%s" already exists', 'invoicing' ), $vat_class_name );
769
-            wp_send_json( $response );
767
+        if (!empty($vat_classes) && in_array(strtolower($vat_class_name), array_map('strtolower', array_values($vat_classes)))) {
768
+            $response['error'] = wp_sprintf(__('A VAT Rate name "%s" already exists', 'invoicing'), $vat_class_name);
769
+            wp_send_json($response);
770 770
         }
771 771
         
772
-        $rate_class_key = normalize_whitespace( 'wpi-' . $vat_class_name );
773
-        $rate_class_key = sanitize_key( str_replace( " ", "-", $rate_class_key ) );
772
+        $rate_class_key = normalize_whitespace('wpi-' . $vat_class_name);
773
+        $rate_class_key = sanitize_key(str_replace(" ", "-", $rate_class_key));
774 774
         
775
-        $vat_classes = (array)self::get_rate_classes( true );
776
-        $vat_classes[$rate_class_key] = array( 'name' => $vat_class_name, 'desc' => $vat_class_desc );
775
+        $vat_classes = (array)self::get_rate_classes(true);
776
+        $vat_classes[$rate_class_key] = array('name' => $vat_class_name, 'desc' => $vat_class_desc);
777 777
         
778
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
778
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
779 779
         
780 780
         $response['success'] = true;
781
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key );
781
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key);
782 782
         
783
-        wp_send_json( $response );
783
+        wp_send_json($response);
784 784
     }
785 785
     
786 786
     public static function delete_class() {
787 787
         $response = array();
788 788
         $response['success'] = false;
789 789
         
790
-        if ( !current_user_can( 'manage_options' ) || !isset( $_POST['class'] ) ) {
791
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
792
-            wp_send_json( $response );
790
+        if (!current_user_can('manage_options') || !isset($_POST['class'])) {
791
+            $response['error'] = __('Invalid access!', 'invoicing');
792
+            wp_send_json($response);
793 793
         }
794 794
         
795
-        $vat_class = isset( $_POST['class'] ) && $_POST['class'] !== '' ? sanitize_text_field( $_POST['class'] ) : false;
795
+        $vat_class = isset($_POST['class']) && $_POST['class'] !== '' ? sanitize_text_field($_POST['class']) : false;
796 796
         $vat_classes = (array)self::get_rate_classes();
797 797
 
798
-        if ( !isset( $vat_classes[$vat_class] ) ) {
799
-            $response['error'] = __( 'Requested class does not exists', 'invoicing' );
800
-            wp_send_json( $response );
798
+        if (!isset($vat_classes[$vat_class])) {
799
+            $response['error'] = __('Requested class does not exists', 'invoicing');
800
+            wp_send_json($response);
801 801
         }
802 802
         
803
-        if ( $vat_class == '_new' || $vat_class == '_standard' ) {
804
-            $response['error'] = __( 'You can not delete standard rates class', 'invoicing' );
805
-            wp_send_json( $response );
803
+        if ($vat_class == '_new' || $vat_class == '_standard') {
804
+            $response['error'] = __('You can not delete standard rates class', 'invoicing');
805
+            wp_send_json($response);
806 806
         }
807 807
             
808
-        $vat_classes = (array)self::get_rate_classes( true );
809
-        unset( $vat_classes[$vat_class] );
808
+        $vat_classes = (array)self::get_rate_classes(true);
809
+        unset($vat_classes[$vat_class]);
810 810
         
811
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
811
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
812 812
         
813 813
         $response['success'] = true;
814
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new' );
814
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new');
815 815
         
816
-        wp_send_json( $response );
816
+        wp_send_json($response);
817 817
     }
818 818
     
819 819
     public static function update_eu_rates() {        
@@ -822,72 +822,72 @@  discard block
 block discarded – undo
822 822
         $response['error']      = null;
823 823
         $response['data']       = null;
824 824
         
825
-        if ( !current_user_can( 'manage_options' ) ) {
826
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
827
-            wp_send_json( $response );
825
+        if (!current_user_can('manage_options')) {
826
+            $response['error'] = __('Invalid access!', 'invoicing');
827
+            wp_send_json($response);
828 828
         }
829 829
         
830
-        $group      = !empty( $_POST['group'] ) ? sanitize_text_field( $_POST['group'] ) : '';
831
-        $euvatrates = self::request_euvatrates( $group );
830
+        $group      = !empty($_POST['group']) ? sanitize_text_field($_POST['group']) : '';
831
+        $euvatrates = self::request_euvatrates($group);
832 832
         
833
-        if ( !empty( $euvatrates ) ) {
834
-            if ( !empty( $euvatrates['success'] ) && !empty( $euvatrates['rates'] ) ) {
833
+        if (!empty($euvatrates)) {
834
+            if (!empty($euvatrates['success']) && !empty($euvatrates['rates'])) {
835 835
                 $response['success']        = true;
836 836
                 $response['data']['rates']  = $euvatrates['rates'];
837
-            } else if ( !empty( $euvatrates['error'] ) ) {
837
+            } else if (!empty($euvatrates['error'])) {
838 838
                 $response['error']          = $euvatrates['error'];
839 839
             }
840 840
         }
841 841
             
842
-        wp_send_json( $response );
842
+        wp_send_json($response);
843 843
     }
844 844
     
845 845
     public static function hide_vat_fields() {
846
-        $hide = wpinv_get_option( 'vat_disable_fields' );
846
+        $hide = wpinv_get_option('vat_disable_fields');
847 847
         
848
-        return apply_filters( 'wpinv_hide_vat_fields', $hide );
848
+        return apply_filters('wpinv_hide_vat_fields', $hide);
849 849
     }
850 850
     
851 851
     public static function same_country_rule() {
852
-        $same_country_rule = wpinv_get_option( 'vat_same_country_rule' );
852
+        $same_country_rule = wpinv_get_option('vat_same_country_rule');
853 853
         
854
-        return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule );
854
+        return apply_filters('wpinv_vat_same_country_rule', $same_country_rule);
855 855
     }
856 856
     
857 857
     public static function get_vat_name() {
858
-        $vat_name   = wpinv_get_option( 'vat_name' );
859
-        $vat_name   = !empty( $vat_name ) ? $vat_name : 'VAT';
858
+        $vat_name   = wpinv_get_option('vat_name');
859
+        $vat_name   = !empty($vat_name) ? $vat_name : 'VAT';
860 860
         
861
-        return apply_filters( 'wpinv_get_owner_vat_name', $vat_name );
861
+        return apply_filters('wpinv_get_owner_vat_name', $vat_name);
862 862
     }
863 863
     
864 864
     public static function get_company_name() {
865
-        $company_name = wpinv_get_option( 'vat_company_name' );
865
+        $company_name = wpinv_get_option('vat_company_name');
866 866
         
867
-        return apply_filters( 'wpinv_get_owner_company_name', $company_name );
867
+        return apply_filters('wpinv_get_owner_company_name', $company_name);
868 868
     }
869 869
     
870 870
     public static function get_vat_number() {
871
-        $vat_number = wpinv_get_option( 'vat_number' );
871
+        $vat_number = wpinv_get_option('vat_number');
872 872
         
873
-        return apply_filters( 'wpinv_get_owner_vat_number', $vat_number );
873
+        return apply_filters('wpinv_get_owner_vat_number', $vat_number);
874 874
     }
875 875
     
876 876
     public static function is_vat_validated() {
877
-        $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' );
877
+        $validated = self::get_vat_number() && wpinv_get_option('vat_valid');
878 878
         
879
-        return apply_filters( 'wpinv_is_owner_vat_validated', $validated );
879
+        return apply_filters('wpinv_is_owner_vat_validated', $validated);
880 880
     }
881 881
     
882
-    public static function sanitize_vat( $vat_number, $country_code = '' ) {        
883
-        $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) );
882
+    public static function sanitize_vat($vat_number, $country_code = '') {        
883
+        $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number)));
884 884
         
885
-        if ( empty( $country_code ) ) {
886
-            $country_code = substr( $vat_number, 0, 2 );
885
+        if (empty($country_code)) {
886
+            $country_code = substr($vat_number, 0, 2);
887 887
         }
888 888
         
889
-        if ( strpos( $vat_number , $country_code ) === 0 ) {
890
-            $vat = str_replace( $country_code, '', $vat_number );
889
+        if (strpos($vat_number, $country_code) === 0) {
890
+            $vat = str_replace($country_code, '', $vat_number);
891 891
         } else {
892 892
             $vat = $country_code . $vat_number;
893 893
         }
@@ -900,140 +900,140 @@  discard block
 block discarded – undo
900 900
         return $return;
901 901
     }
902 902
     
903
-    public static function offline_check( $vat_number, $country_code = '', $formatted = false ) {
904
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
903
+    public static function offline_check($vat_number, $country_code = '', $formatted = false) {
904
+        $vat            = self::sanitize_vat($vat_number, $country_code);
905 905
         $vat_number     = $vat['vat_number'];
906 906
         $country_code   = $vat['iso'];
907 907
         $regex          = array();
908 908
         
909
-        switch ( $country_code ) {
909
+        switch ($country_code) {
910 910
             case 'AT':
911
-                $regex[] = '/^(AT)U(\d{8})$/';                           // Austria
911
+                $regex[] = '/^(AT)U(\d{8})$/'; // Austria
912 912
                 break;
913 913
             case 'BE':
914
-                $regex[] = '/^(BE)(0?\d{9})$/';                          // Belgium
914
+                $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium
915 915
                 break;
916 916
             case 'BG':
917
-                $regex[] = '/^(BG)(\d{9,10})$/';                         // Bulgaria
917
+                $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria
918 918
                 break;
919 919
             case 'CH':
920 920
             case 'CHE':
921
-                $regex[] = '/^(CHE)(\d{9})MWST$/';                       // Switzerland (Not EU)
921
+                $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU)
922 922
                 break;
923 923
             case 'CY':
924
-                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/';                // Cyprus
924
+                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus
925 925
                 break;
926 926
             case 'CZ':
927
-                $regex[] = '/^(CZ)(\d{8,13})$/';                         // Czech Republic
927
+                $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic
928 928
                 break;
929 929
             case 'DE':
930
-                $regex[] = '/^(DE)([1-9]\d{8})$/';                       // Germany
930
+                $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany
931 931
                 break;
932 932
             case 'DK':
933
-                $regex[] = '/^(DK)(\d{8})$/';                            // Denmark
933
+                $regex[] = '/^(DK)(\d{8})$/'; // Denmark
934 934
                 break;
935 935
             case 'EE':
936
-                $regex[] = '/^(EE)(10\d{7})$/';                          // Estonia
936
+                $regex[] = '/^(EE)(10\d{7})$/'; // Estonia
937 937
                 break;
938 938
             case 'EL':
939
-                $regex[] = '/^(EL)(\d{9})$/';                            // Greece
939
+                $regex[] = '/^(EL)(\d{9})$/'; // Greece
940 940
                 break;
941 941
             case 'ES':
942
-                $regex[] = '/^(ES)([A-Z]\d{8})$/';                       // Spain (National juridical entities)
943
-                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/';            // Spain (Other juridical entities)
944
-                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/';              // Spain (Personal entities type 1)
945
-                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/';              // Spain (Personal entities type 2)
942
+                $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities)
943
+                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities)
944
+                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1)
945
+                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2)
946 946
                 break;
947 947
             case 'EU':
948
-                $regex[] = '/^(EU)(\d{9})$/';                            // EU-type
948
+                $regex[] = '/^(EU)(\d{9})$/'; // EU-type
949 949
                 break;
950 950
             case 'FI':
951
-                $regex[] = '/^(FI)(\d{8})$/';                            // Finland
951
+                $regex[] = '/^(FI)(\d{8})$/'; // Finland
952 952
                 break;
953 953
             case 'FR':
954
-                $regex[] = '/^(FR)(\d{11})$/';                           // France (1)
955
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/';        // France (2)
956
-                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/';       // France (3)
957
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/';      // France (4)
954
+                $regex[] = '/^(FR)(\d{11})$/'; // France (1)
955
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2)
956
+                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3)
957
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4)
958 958
                 break;
959 959
             case 'GB':
960
-                $regex[] = '/^(GB)?(\d{9})$/';                           // UK (Standard)
961
-                $regex[] = '/^(GB)?(\d{12})$/';                          // UK (Branches)
962
-                $regex[] = '/^(GB)?(GD\d{3})$/';                         // UK (Government)
963
-                $regex[] = '/^(GB)?(HA\d{3})$/';                         // UK (Health authority)
960
+                $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard)
961
+                $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches)
962
+                $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government)
963
+                $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority)
964 964
                 break;
965 965
             case 'GR':
966
-                $regex[] = '/^(GR)(\d{8,9})$/';                          // Greece
966
+                $regex[] = '/^(GR)(\d{8,9})$/'; // Greece
967 967
                 break;
968 968
             case 'HR':
969
-                $regex[] = '/^(HR)(\d{11})$/';                           // Croatia
969
+                $regex[] = '/^(HR)(\d{11})$/'; // Croatia
970 970
                 break;
971 971
             case 'HU':
972
-                $regex[] = '/^(HU)(\d{8})$/';                            // Hungary
972
+                $regex[] = '/^(HU)(\d{8})$/'; // Hungary
973 973
                 break;
974 974
             case 'IE':
975
-                $regex[] = '/^(IE)(\d{7}[A-W])$/';                       // Ireland (1)
976
-                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/';        // Ireland (2)
977
-                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/';                   // Ireland (3) (new format from 1 Jan 2013)
975
+                $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1)
976
+                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2)
977
+                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013)
978 978
                 break;
979 979
             case 'IT':
980
-                $regex[] = '/^(IT)(\d{11})$/';                           // Italy
980
+                $regex[] = '/^(IT)(\d{11})$/'; // Italy
981 981
                 break;
982 982
             case 'LV':
983
-                $regex[] = '/^(LV)(\d{11})$/';                           // Latvia
983
+                $regex[] = '/^(LV)(\d{11})$/'; // Latvia
984 984
                 break;
985 985
             case 'LT':
986
-                $regex[] = '/^(LT)(\d{9}|\d{12})$/';                     // Lithuania
986
+                $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania
987 987
                 break;
988 988
             case 'LU':
989
-                $regex[] = '/^(LU)(\d{8})$/';                            // Luxembourg
989
+                $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg
990 990
                 break;
991 991
             case 'MT':
992
-                $regex[] = '/^(MT)([1-9]\d{7})$/';                       // Malta
992
+                $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta
993 993
                 break;
994 994
             case 'NL':
995
-                $regex[] = '/^(NL)(\d{9})B\d{2}$/';                      // Netherlands
995
+                $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands
996 996
                 break;
997 997
             case 'NO':
998
-                $regex[] = '/^(NO)(\d{9})$/';                            // Norway (Not EU)
998
+                $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU)
999 999
                 break;
1000 1000
             case 'PL':
1001
-                $regex[] = '/^(PL)(\d{10})$/';                           // Poland
1001
+                $regex[] = '/^(PL)(\d{10})$/'; // Poland
1002 1002
                 break;
1003 1003
             case 'PT':
1004
-                $regex[] = '/^(PT)(\d{9})$/';                            // Portugal
1004
+                $regex[] = '/^(PT)(\d{9})$/'; // Portugal
1005 1005
                 break;
1006 1006
             case 'RO':
1007
-                $regex[] = '/^(RO)([1-9]\d{1,9})$/';                     // Romania
1007
+                $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania
1008 1008
                 break;
1009 1009
             case 'RS':
1010
-                $regex[] = '/^(RS)(\d{9})$/';                            // Serbia (Not EU)
1010
+                $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU)
1011 1011
                 break;
1012 1012
             case 'SI':
1013
-                $regex[] = '/^(SI)([1-9]\d{7})$/';                       // Slovenia
1013
+                $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia
1014 1014
                 break;
1015 1015
             case 'SK':
1016
-                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/';        // Slovakia Republic
1016
+                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic
1017 1017
                 break;
1018 1018
             case 'SE':
1019
-                $regex[] = '/^(SE)(\d{10}01)$/';                         // Sweden
1019
+                $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden
1020 1020
                 break;
1021 1021
             default:
1022 1022
                 $regex = array();
1023 1023
             break;
1024 1024
         }
1025 1025
         
1026
-        if ( empty( $regex ) ) {
1026
+        if (empty($regex)) {
1027 1027
             return false;
1028 1028
         }
1029 1029
         
1030
-        foreach ( $regex as $pattern ) {
1030
+        foreach ($regex as $pattern) {
1031 1031
             $matches = null;
1032
-            preg_match_all( $pattern, $vat_number, $matches );
1032
+            preg_match_all($pattern, $vat_number, $matches);
1033 1033
             
1034
-            if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) {
1035
-                if ( $formatted ) {
1036
-                    return array( 'code' => $matches[1][0], 'number' => $matches[2][0] );
1034
+            if (!empty($matches[1][0]) && !empty($matches[2][0])) {
1035
+                if ($formatted) {
1036
+                    return array('code' => $matches[1][0], 'number' => $matches[2][0]);
1037 1037
                 } else {
1038 1038
                     return true;
1039 1039
                 }
@@ -1043,75 +1043,75 @@  discard block
 block discarded – undo
1043 1043
         return false;
1044 1044
     }
1045 1045
     
1046
-    public static function vies_check( $vat_number, $country_code = '', $result = false ) {
1047
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
1046
+    public static function vies_check($vat_number, $country_code = '', $result = false) {
1047
+        $vat            = self::sanitize_vat($vat_number, $country_code);
1048 1048
         $vat_number     = $vat['vat'];
1049 1049
         $iso            = $vat['iso'];
1050 1050
         
1051
-        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number );
1051
+        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number);
1052 1052
         
1053
-        if ( ini_get( 'allow_url_fopen' ) ) {
1054
-            $response = file_get_contents( $url );
1055
-        } else if ( function_exists( 'curl_init' ) ) {
1053
+        if (ini_get('allow_url_fopen')) {
1054
+            $response = file_get_contents($url);
1055
+        } else if (function_exists('curl_init')) {
1056 1056
             $ch = curl_init();
1057 1057
             
1058
-            curl_setopt( $ch, CURLOPT_URL, $url );
1059
-            curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 );
1060
-            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
1061
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
1062
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
1058
+            curl_setopt($ch, CURLOPT_URL, $url);
1059
+            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
1060
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1061
+            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
1062
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
1063 1063
             
1064
-            $response = curl_exec( $ch );
1064
+            $response = curl_exec($ch);
1065 1065
             
1066
-            if ( curl_errno( $ch ) ) {
1067
-                wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' );
1066
+            if (curl_errno($ch)) {
1067
+                wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR');
1068 1068
                 $response = '';
1069 1069
             }
1070 1070
             
1071
-            curl_close( $ch );
1071
+            curl_close($ch);
1072 1072
         } else {
1073
-            wpinv_error_log( 'To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR' );
1073
+            wpinv_error_log('To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR');
1074 1074
         }
1075 1075
         
1076
-        if ( empty( $response ) ) {
1076
+        if (empty($response)) {
1077 1077
             return $result;
1078 1078
         }
1079 1079
 
1080
-        if ( preg_match( '/invalid VAT number/i', $response ) ) {
1080
+        if (preg_match('/invalid VAT number/i', $response)) {
1081 1081
             return false;
1082
-        } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) {
1083
-            $content = explode( "valid VAT number", htmlentities( $response ) );
1082
+        } else if (preg_match('/valid VAT number/i', $response, $matches)) {
1083
+            $content = explode("valid VAT number", htmlentities($response));
1084 1084
             
1085
-            if ( !empty( $content[1] ) ) {
1086
-                preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches );
1085
+            if (!empty($content[1])) {
1086
+                preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches);
1087 1087
                 
1088
-                if ( !empty( $matches[2] ) && $matches[3] ) {
1088
+                if (!empty($matches[2]) && $matches[3]) {
1089 1089
                     $return = array();
1090 1090
                     
1091
-                    foreach ( $matches[2] as $key => $label ) {
1092
-                        $label = trim( $label );
1091
+                    foreach ($matches[2] as $key => $label) {
1092
+                        $label = trim($label);
1093 1093
                         
1094
-                        switch ( strtolower( $label ) ) {
1094
+                        switch (strtolower($label)) {
1095 1095
                             case 'member state':
1096
-                                $return['state'] = trim( strip_tags( $matches[3][$key] ) );
1096
+                                $return['state'] = trim(strip_tags($matches[3][$key]));
1097 1097
                             break;
1098 1098
                             case 'vat number':
1099
-                                $return['number'] = trim( strip_tags( $matches[3][$key] ) );
1099
+                                $return['number'] = trim(strip_tags($matches[3][$key]));
1100 1100
                             break;
1101 1101
                             case 'name':
1102
-                                $return['company'] = trim( strip_tags( $matches[3][$key] ) );
1102
+                                $return['company'] = trim(strip_tags($matches[3][$key]));
1103 1103
                             break;
1104 1104
                             case 'address':
1105
-                                $address           = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) );
1106
-                                $return['address'] = trim( strip_tags( $address, '<br>' ) );
1105
+                                $address           = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key])));
1106
+                                $return['address'] = trim(strip_tags($address, '<br>'));
1107 1107
                             break;
1108 1108
                             case 'consultation number':
1109
-                                $return['consultation'] = trim( strip_tags( $matches[3][$key] ) );
1109
+                                $return['consultation'] = trim(strip_tags($matches[3][$key]));
1110 1110
                             break;
1111 1111
                         }
1112 1112
                     }
1113 1113
                     
1114
-                    if ( !empty( $return ) ) {
1114
+                    if (!empty($return)) {
1115 1115
                         return $return;
1116 1116
                     }
1117 1117
                 }
@@ -1123,55 +1123,55 @@  discard block
 block discarded – undo
1123 1123
         }
1124 1124
     }
1125 1125
     
1126
-    public static function check_vat( $vat_number, $country_code = '' ) {        
1126
+    public static function check_vat($vat_number, $country_code = '') {        
1127 1127
         $vat_name           = self::get_vat_name();
1128 1128
         
1129 1129
         $return             = array();
1130 1130
         $return['valid']    = false;
1131
-        $return['message']  = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1131
+        $return['message']  = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1132 1132
                 
1133
-        if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) {
1133
+        if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) {
1134 1134
             return $return;
1135 1135
         }
1136 1136
             
1137
-        $response = self::vies_check( $vat_number, $country_code );
1137
+        $response = self::vies_check($vat_number, $country_code);
1138 1138
         
1139
-        if ( $response ) {
1140
-            $return['valid']    = true;
1139
+        if ($response) {
1140
+            $return['valid'] = true;
1141 1141
             
1142
-            if ( is_array( $response ) ) {
1143
-                $return['company'] = isset( $response['company'] ) ? $response['company'] : '';
1144
-                $return['address'] = isset( $response['address'] ) ? $response['address'] : '';
1142
+            if (is_array($response)) {
1143
+                $return['company'] = isset($response['company']) ? $response['company'] : '';
1144
+                $return['address'] = isset($response['address']) ? $response['address'] : '';
1145 1145
                 $return['message'] = $return['company'] . '<br/>' . $return['address'];
1146 1146
             }
1147 1147
         } else {
1148 1148
             $return['valid']    = false;
1149
-            $return['message']  = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
1149
+            $return['message']  = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
1150 1150
         }
1151 1151
         
1152 1152
         return $return;
1153 1153
     }
1154 1154
     
1155
-    public static function request_euvatrates( $group ) {
1155
+    public static function request_euvatrates($group) {
1156 1156
         $response               = array();
1157 1157
         $response['success']    = false;
1158 1158
         $response['error']      = null;
1159 1159
         $response['eurates']    = null;
1160 1160
         
1161 1161
         $euvatrates_url = 'https://euvatrates.com/rates.json';
1162
-        $euvatrates_url = apply_filters( 'wpinv_euvatrates_url', $euvatrates_url );
1163
-        $api_response   = wp_remote_get( $euvatrates_url );
1162
+        $euvatrates_url = apply_filters('wpinv_euvatrates_url', $euvatrates_url);
1163
+        $api_response   = wp_remote_get($euvatrates_url);
1164 1164
     
1165 1165
         try {
1166
-            if ( is_wp_error( $api_response ) ) {
1167
-                $response['error']      = __( $api_response->get_error_message(), 'invoicing' );
1166
+            if (is_wp_error($api_response)) {
1167
+                $response['error'] = __($api_response->get_error_message(), 'invoicing');
1168 1168
             } else {
1169
-                $body = json_decode( $api_response['body'] );
1169
+                $body = json_decode($api_response['body']);
1170 1170
                 
1171
-                if ( isset( $body->rates ) ) {
1171
+                if (isset($body->rates)) {
1172 1172
                     $rates = array();
1173 1173
                     
1174
-                    foreach ( $body->rates as $country_code => $rate ) {
1174
+                    foreach ($body->rates as $country_code => $rate) {
1175 1175
                         $vat_rate = array();
1176 1176
                         $vat_rate['country']        = $rate->country;
1177 1177
                         $vat_rate['standard']       = (float)$rate->standard_rate;
@@ -1179,7 +1179,7 @@  discard block
 block discarded – undo
1179 1179
                         $vat_rate['superreduced']   = (float)$rate->super_reduced_rate;
1180 1180
                         $vat_rate['parking']        = (float)$rate->parking_rate;
1181 1181
                         
1182
-                        if ( $group !== '' && in_array( $group, array( 'standard', 'reduced', 'superreduced', 'parking' ) ) ) {
1182
+                        if ($group !== '' && in_array($group, array('standard', 'reduced', 'superreduced', 'parking'))) {
1183 1183
                             $vat_rate_group = array();
1184 1184
                             $vat_rate_group['country'] = $rate->country;
1185 1185
                             $vat_rate_group[$group]    = $vat_rate[$group];
@@ -1191,79 +1191,79 @@  discard block
 block discarded – undo
1191 1191
                     }
1192 1192
                     
1193 1193
                     $response['success']    = true;                                
1194
-                    $response['rates']      = apply_filters( 'wpinv_process_euvatrates', $rates, $api_response, $group );
1194
+                    $response['rates']      = apply_filters('wpinv_process_euvatrates', $rates, $api_response, $group);
1195 1195
                 } else {
1196
-                    $response['error']      = __( 'No EU rates found!', 'invoicing' );
1196
+                    $response['error']      = __('No EU rates found!', 'invoicing');
1197 1197
                 }
1198 1198
             }
1199
-        } catch ( Exception $e ) {
1200
-            $response['error'] = __( $e->getMessage(), 'invoicing' );
1199
+        } catch (Exception $e) {
1200
+            $response['error'] = __($e->getMessage(), 'invoicing');
1201 1201
         }
1202 1202
         
1203
-        return apply_filters( 'wpinv_response_euvatrates', $response, $group );
1203
+        return apply_filters('wpinv_response_euvatrates', $response, $group);
1204 1204
     }    
1205 1205
     
1206
-    public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) {
1206
+    public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) {
1207 1207
         global $wpi_item_id, $wpi_country;
1208 1208
         
1209
-        if ( !empty( $_POST['wpinv_country'] ) ) {
1210
-            $country_code = trim( $_POST['wpinv_country'] );
1211
-        } else if ( !empty( $_POST['country'] ) ) {
1212
-            $country_code = trim( $_POST['country'] );
1213
-        } else if ( !empty( $wpi_country ) ) {
1209
+        if (!empty($_POST['wpinv_country'])) {
1210
+            $country_code = trim($_POST['wpinv_country']);
1211
+        } else if (!empty($_POST['country'])) {
1212
+            $country_code = trim($_POST['country']);
1213
+        } else if (!empty($wpi_country)) {
1214 1214
             $country_code = $wpi_country;
1215 1215
         } else {
1216
-            $country_code = self::get_user_country( '', $user_id );
1216
+            $country_code = self::get_user_country('', $user_id);
1217 1217
         }
1218 1218
         
1219
-        if ( $is_digital === null && $wpi_item_id ) {
1220
-            $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules();
1219
+        if ($is_digital === null && $wpi_item_id) {
1220
+            $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules();
1221 1221
         }
1222 1222
         
1223
-        if ( !empty( $country_code ) ) {
1224
-            $requires_vat = ( self::is_eu_state( $country_code ) && ( self::is_eu_state( self::$default_country ) || $is_digital ) ) || ( self::is_gst_country( $country_code ) && self::is_gst_country( self::$default_country ) );
1223
+        if (!empty($country_code)) {
1224
+            $requires_vat = (self::is_eu_state($country_code) && (self::is_eu_state(self::$default_country) || $is_digital)) || (self::is_gst_country($country_code) && self::is_gst_country(self::$default_country));
1225 1225
         }
1226 1226
         
1227
-        return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id );
1227
+        return apply_filters('wpinv_requires_vat', $requires_vat, $user_id);
1228 1228
     }
1229 1229
     
1230
-    public static function tax_label( $label = '' ) {
1230
+    public static function tax_label($label = '') {
1231 1231
         global $wpi_requires_vat;
1232 1232
         
1233
-        if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) {
1234
-            $wpi_requires_vat = self::requires_vat( 0, false );
1233
+        if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) {
1234
+            $wpi_requires_vat = self::requires_vat(0, false);
1235 1235
         }
1236 1236
         
1237
-        return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) );
1237
+        return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing'));
1238 1238
     }
1239 1239
     
1240 1240
     public static function standard_rates_label() {
1241
-        return __( 'Standard Rates', 'invoicing' );
1241
+        return __('Standard Rates', 'invoicing');
1242 1242
     }
1243 1243
     
1244
-    public static function get_rate_classes( $with_desc = false ) {        
1245
-        $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true );
1246
-        $classes = maybe_unserialize( $rate_classes_option );
1244
+    public static function get_rate_classes($with_desc = false) {        
1245
+        $rate_classes_option = get_option('_wpinv_vat_rate_classes', true);
1246
+        $classes = maybe_unserialize($rate_classes_option);
1247 1247
         
1248
-        if ( empty( $classes ) || !is_array( $classes ) ) {
1248
+        if (empty($classes) || !is_array($classes)) {
1249 1249
             $classes = array();
1250 1250
         }
1251 1251
 
1252 1252
         $rate_classes = array();
1253
-        if ( !array_key_exists( '_standard', $classes ) ) {
1254
-            if ( $with_desc ) {
1255
-                $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) );
1253
+        if (!array_key_exists('_standard', $classes)) {
1254
+            if ($with_desc) {
1255
+                $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing'));
1256 1256
             } else {
1257 1257
                 $rate_classes['_standard'] = self::standard_rates_label();
1258 1258
             }
1259 1259
         }
1260 1260
         
1261
-        foreach ( $classes as $key => $class ) {
1262
-            $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key;
1263
-            $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : '';
1261
+        foreach ($classes as $key => $class) {
1262
+            $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key;
1263
+            $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : '';
1264 1264
             
1265
-            if ( $with_desc ) {
1266
-                $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc );
1265
+            if ($with_desc) {
1266
+                $rate_classes[$key] = array('name' => $name, 'desc' => $desc);
1267 1267
             } else {
1268 1268
                 $rate_classes[$key] = $name;
1269 1269
             }
@@ -1274,15 +1274,15 @@  discard block
 block discarded – undo
1274 1274
     
1275 1275
     public static function get_all_classes() {        
1276 1276
         $classes            = self::get_rate_classes();
1277
-        $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' );
1277
+        $classes['_exempt'] = __('Exempt (0%)', 'invoicing');
1278 1278
         
1279
-        return apply_filters( 'wpinv_vat_get_all_classes', $classes );
1279
+        return apply_filters('wpinv_vat_get_all_classes', $classes);
1280 1280
     }
1281 1281
     
1282
-    public static function get_class_desc( $rate_class ) {        
1283
-        $rate_classes = self::get_rate_classes( true );
1282
+    public static function get_class_desc($rate_class) {        
1283
+        $rate_classes = self::get_rate_classes(true);
1284 1284
 
1285
-        if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) {
1285
+        if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) {
1286 1286
             return $rate_classes[$rate_class]['desc'];
1287 1287
         }
1288 1288
         
@@ -1298,106 +1298,106 @@  discard block
 block discarded – undo
1298 1298
             'increased'     => 'Increased'
1299 1299
         );
1300 1300
         
1301
-        return apply_filters( 'wpinv_get_vat_groups', $vat_groups );
1301
+        return apply_filters('wpinv_get_vat_groups', $vat_groups);
1302 1302
     }
1303 1303
 
1304 1304
     public static function get_rules() {
1305 1305
         $vat_rules = array(
1306
-            'digital' => __( 'Digital Product', 'invoicing' ),
1307
-            'physical' => __( 'Physical Product', 'invoicing' )
1306
+            'digital' => __('Digital Product', 'invoicing'),
1307
+            'physical' => __('Physical Product', 'invoicing')
1308 1308
         );
1309
-        return apply_filters( 'wpinv_get_vat_rules', $vat_rules );
1309
+        return apply_filters('wpinv_get_vat_rules', $vat_rules);
1310 1310
     }
1311 1311
 
1312
-    public static function get_vat_rates( $class ) {
1313
-        if ( $class === '_standard' ) {
1312
+    public static function get_vat_rates($class) {
1313
+        if ($class === '_standard') {
1314 1314
             return wpinv_get_tax_rates();
1315 1315
         }
1316 1316
 
1317 1317
         $rates = self::get_non_standard_rates();
1318 1318
 
1319
-        return array_key_exists( $class, $rates ) ? $rates[$class] : array();
1319
+        return array_key_exists($class, $rates) ? $rates[$class] : array();
1320 1320
     }
1321 1321
 
1322 1322
     public static function get_non_standard_rates() {
1323
-        $option = get_option( 'wpinv_vat_rates', array());
1324
-        return is_array( $option ) ? $option : array();
1323
+        $option = get_option('wpinv_vat_rates', array());
1324
+        return is_array($option) ? $option : array();
1325 1325
     }
1326 1326
     
1327 1327
     public static function allow_vat_rules() {
1328
-        return ( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ? true : false );
1328
+        return (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules') ? true : false);
1329 1329
     }
1330 1330
     
1331 1331
     public static function allow_vat_classes() {
1332 1332
         return false; // TODO
1333
-        return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false );
1333
+        return (wpinv_get_option('vat_allow_classes') ? true : false);
1334 1334
     }
1335 1335
     
1336
-    public static function get_item_class( $postID ) {
1337
-        $class = get_post_meta( $postID, '_wpinv_vat_class', true );
1336
+    public static function get_item_class($postID) {
1337
+        $class = get_post_meta($postID, '_wpinv_vat_class', true);
1338 1338
 
1339
-        if ( empty( $class ) ) {
1339
+        if (empty($class)) {
1340 1340
             $class = '_standard';
1341 1341
         }
1342 1342
         
1343
-        return apply_filters( 'wpinv_get_item_vat_class', $class, $postID );
1343
+        return apply_filters('wpinv_get_item_vat_class', $class, $postID);
1344 1344
     }
1345 1345
     
1346
-    public static function item_class_label( $postID ) {        
1346
+    public static function item_class_label($postID) {        
1347 1347
         $vat_classes = self::get_all_classes();
1348 1348
         
1349
-        $class = self::get_item_class( $postID );
1350
-        $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' );
1349
+        $class = self::get_item_class($postID);
1350
+        $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing');
1351 1351
         
1352
-        return apply_filters( 'wpinv_item_class_label', $class, $postID );
1352
+        return apply_filters('wpinv_item_class_label', $class, $postID);
1353 1353
     }
1354 1354
     
1355
-    public static function get_item_rule( $postID ) {        
1356
-        $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true );
1355
+    public static function get_item_rule($postID) {        
1356
+        $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true);
1357 1357
         
1358
-        if ( empty( $rule_type ) ) {        
1358
+        if (empty($rule_type)) {        
1359 1359
             $rule_type = self::allow_vat_rules() ? 'digital' : 'physical';
1360 1360
         }
1361 1361
         
1362
-        return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID );
1362
+        return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID);
1363 1363
     }
1364 1364
     
1365
-    public static function item_rule_label( $postID ) {
1365
+    public static function item_rule_label($postID) {
1366 1366
         $vat_rules  = self::get_rules();
1367
-        $vat_rule   = self::get_item_rule( $postID );
1368
-        $vat_rule   = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule;
1367
+        $vat_rule   = self::get_item_rule($postID);
1368
+        $vat_rule   = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule;
1369 1369
         
1370
-        return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID );
1370
+        return apply_filters('wpinv_item_rule_label', $vat_rule, $postID);
1371 1371
     }
1372 1372
     
1373
-    public static function item_has_digital_rule( $item_id = 0 ) {        
1374
-        return self::get_item_rule( $item_id ) == 'digital' ? true : false;
1373
+    public static function item_has_digital_rule($item_id = 0) {        
1374
+        return self::get_item_rule($item_id) == 'digital' ? true : false;
1375 1375
     }
1376 1376
     
1377
-    public static function invoice_has_digital_rule( $invoice = 0 ) {        
1378
-        if ( !self::allow_vat_rules() ) {
1377
+    public static function invoice_has_digital_rule($invoice = 0) {        
1378
+        if (!self::allow_vat_rules()) {
1379 1379
             return false;
1380 1380
         }
1381 1381
         
1382
-        if ( empty( $invoice ) ) {
1382
+        if (empty($invoice)) {
1383 1383
             return true;
1384 1384
         }
1385 1385
         
1386
-        if ( is_int( $invoice ) ) {
1387
-            $invoice = new WPInv_Invoice( $invoice );
1386
+        if (is_int($invoice)) {
1387
+            $invoice = new WPInv_Invoice($invoice);
1388 1388
         }
1389 1389
         
1390
-        if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) {
1390
+        if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) {
1391 1391
             return true;
1392 1392
         }
1393 1393
         
1394
-        $cart_items  = $invoice->get_cart_details();
1394
+        $cart_items = $invoice->get_cart_details();
1395 1395
         
1396
-        if ( !empty( $cart_items ) ) {
1396
+        if (!empty($cart_items)) {
1397 1397
             $has_digital_rule = false;
1398 1398
             
1399
-            foreach ( $cart_items as $key => $item ) {
1400
-                if ( self::item_has_digital_rule( $item['id'] ) ) {
1399
+            foreach ($cart_items as $key => $item) {
1400
+                if (self::item_has_digital_rule($item['id'])) {
1401 1401
                     $has_digital_rule = true;
1402 1402
                     break;
1403 1403
                 }
@@ -1409,67 +1409,67 @@  discard block
 block discarded – undo
1409 1409
         return $has_digital_rule;
1410 1410
     }
1411 1411
     
1412
-    public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) {        
1413
-        if ( !wpinv_use_taxes() ) {
1412
+    public static function item_is_taxable($item_id = 0, $country = false, $state = false) {        
1413
+        if (!wpinv_use_taxes()) {
1414 1414
             return false;
1415 1415
         }
1416 1416
         
1417 1417
         $is_taxable = true;
1418 1418
 
1419
-        if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) {
1419
+        if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') {
1420 1420
             $is_taxable = false;
1421 1421
         }
1422 1422
         
1423
-        return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state );
1423
+        return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state);
1424 1424
     }
1425 1425
     
1426
-    public static function find_rate( $country, $state, $rate, $class ) {
1426
+    public static function find_rate($country, $state, $rate, $class) {
1427 1427
         global $wpi_zero_tax;
1428 1428
 
1429
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1429
+        if ($class === '_exempt' || $wpi_zero_tax) {
1430 1430
             return 0;
1431 1431
         }
1432 1432
 
1433
-        $tax_rates   = wpinv_get_tax_rates();
1433
+        $tax_rates = wpinv_get_tax_rates();
1434 1434
         
1435
-        if ( $class !== '_standard' ) {
1436
-            $class_rates = self::get_vat_rates( $class );
1435
+        if ($class !== '_standard') {
1436
+            $class_rates = self::get_vat_rates($class);
1437 1437
             
1438
-            if ( is_array( $class_rates ) ) {
1438
+            if (is_array($class_rates)) {
1439 1439
                 $indexed_class_rates = array();
1440 1440
                 
1441
-                foreach ( $class_rates as $key => $cr ) {
1441
+                foreach ($class_rates as $key => $cr) {
1442 1442
                     $indexed_class_rates[$cr['country']] = $cr;
1443 1443
                 }
1444 1444
 
1445
-                $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) {
1445
+                $tax_rates = array_map(function($tr) use($indexed_class_rates) {
1446 1446
                     $tr_country = $tr['country'];
1447
-                    if ( !isset( $indexed_class_rates[$tr_country] ) ) {
1447
+                    if (!isset($indexed_class_rates[$tr_country])) {
1448 1448
                         return $tr;
1449 1449
                     }
1450 1450
                     $icr = $indexed_class_rates[$tr_country];
1451
-                    return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr;
1451
+                    return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr;
1452 1452
 
1453
-                }, $tax_rates, $class_rates );
1453
+                }, $tax_rates, $class_rates);
1454 1454
             }
1455 1455
         }
1456 1456
 
1457
-        if ( !empty( $tax_rates ) ) {
1458
-            foreach ( $tax_rates as $key => $tax_rate ) {
1459
-                if ( $country != $tax_rate['country'] )
1457
+        if (!empty($tax_rates)) {
1458
+            foreach ($tax_rates as $key => $tax_rate) {
1459
+                if ($country != $tax_rate['country'])
1460 1460
                     continue;
1461 1461
 
1462
-                if ( !empty( $tax_rate['global'] ) ) {
1463
-                    if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) {
1464
-                        $rate = number_format( $tax_rate['rate'], 4 );
1462
+                if (!empty($tax_rate['global'])) {
1463
+                    if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) {
1464
+                        $rate = number_format($tax_rate['rate'], 4);
1465 1465
                     }
1466 1466
                 } else {
1467
-                    if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) )
1467
+                    if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state']))
1468 1468
                         continue;
1469 1469
 
1470 1470
                     $state_rate = $tax_rate['rate'];
1471
-                    if ( 0 !== $state_rate || !empty( $state_rate ) ) {
1472
-                        $rate = number_format( $state_rate, 4 );
1471
+                    if (0 !== $state_rate || !empty($state_rate)) {
1472
+                        $rate = number_format($state_rate, 4);
1473 1473
                     }
1474 1474
                 }
1475 1475
             }
@@ -1478,84 +1478,84 @@  discard block
 block discarded – undo
1478 1478
         return $rate;
1479 1479
     }
1480 1480
     
1481
-    public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) {
1481
+    public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) {
1482 1482
         global $wpinv_options, $wpi_session, $wpi_item_id, $wpi_zero_tax;
1483 1483
         
1484 1484
         $item_id = $item_id > 0 ? $item_id : $wpi_item_id;
1485 1485
         $allow_vat_classes = self::allow_vat_classes();
1486
-        $class = $item_id ? self::get_item_class( $item_id ) : '_standard';
1486
+        $class = $item_id ? self::get_item_class($item_id) : '_standard';
1487 1487
 
1488
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1488
+        if ($class === '_exempt' || $wpi_zero_tax) {
1489 1489
             return 0;
1490
-        } else if ( !$allow_vat_classes ) {
1490
+        } else if (!$allow_vat_classes) {
1491 1491
             $class = '_standard';
1492 1492
         }
1493 1493
 
1494
-        if( !empty( $_POST['wpinv_country'] ) ) {
1494
+        if (!empty($_POST['wpinv_country'])) {
1495 1495
             $post_country = $_POST['wpinv_country'];
1496
-        } elseif( !empty( $_POST['wpinv_country'] ) ) {
1496
+        } elseif (!empty($_POST['wpinv_country'])) {
1497 1497
             $post_country = $_POST['wpinv_country'];
1498
-        } elseif( !empty( $_POST['country'] ) ) {
1498
+        } elseif (!empty($_POST['country'])) {
1499 1499
             $post_country = $_POST['country'];
1500 1500
         } else {
1501 1501
             $post_country = '';
1502 1502
         }
1503 1503
 
1504
-        $country        = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country );
1505
-        $base_country   = wpinv_is_base_country( $country );
1504
+        $country        = !empty($post_country) ? $post_country : wpinv_default_billing_country($country);
1505
+        $base_country   = wpinv_is_base_country($country);
1506 1506
         
1507
-        $requires_vat   = self::requires_vat( 0, false );
1508
-        $is_digital     = self::get_item_rule( $item_id ) == 'digital' ;
1509
-        $rate           = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate;
1507
+        $requires_vat   = self::requires_vat(0, false);
1508
+        $is_digital     = self::get_item_rule($item_id) == 'digital';
1509
+        $rate           = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate;
1510 1510
           
1511
-        if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country
1511
+        if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country
1512 1512
             $rate = 0;
1513
-        } else if ( $requires_vat ) {
1514
-            $vat_number = self::get_user_vat_number( '', 0, true );
1513
+        } else if ($requires_vat) {
1514
+            $vat_number = self::get_user_vat_number('', 0, true);
1515 1515
             $vat_info   = self::current_vat_data();
1516 1516
             
1517
-            if ( is_array( $vat_info ) ) {
1518
-                $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : "";
1517
+            if (is_array($vat_info)) {
1518
+                $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : "";
1519 1519
             }
1520 1520
             
1521
-            if ( $country == 'UK' ) {
1521
+            if ($country == 'UK') {
1522 1522
                 $country = 'GB';
1523 1523
             }
1524 1524
 
1525
-            if ( !empty( $vat_number ) ) {
1525
+            if (!empty($vat_number)) {
1526 1526
                 $rate = 0;
1527 1527
             } else {
1528
-                $rate = self::find_rate( $country, $state, $rate, $class ); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate
1528
+                $rate = self::find_rate($country, $state, $rate, $class); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate
1529 1529
             }
1530 1530
 
1531
-            if ( empty( $vat_number ) && !$is_digital ) {
1532
-                if ( $base_country ) {
1533
-                    $rate = self::find_rate( $country, null, $rate, $class );
1531
+            if (empty($vat_number) && !$is_digital) {
1532
+                if ($base_country) {
1533
+                    $rate = self::find_rate($country, null, $rate, $class);
1534 1534
                 } else {
1535
-                    if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1535
+                    if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1536 1536
                         $rate = $wpinv_options['eu_fallback_rate'];
1537
-                    } else if( !empty( $country ) ) {
1538
-                        $rate = self::find_rate( $country, $state, $rate, $class );
1537
+                    } else if (!empty($country)) {
1538
+                        $rate = self::find_rate($country, $state, $rate, $class);
1539 1539
                     }
1540 1540
                 }
1541
-            } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) {
1542
-                if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1541
+            } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) {
1542
+                if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1543 1543
                     $rate = $wpinv_options['eu_fallback_rate'];
1544
-                } else if( !empty( $country ) ) {
1545
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1544
+                } else if (!empty($country)) {
1545
+                    $rate = self::find_rate($country, $state, $rate, $class);
1546 1546
                 }
1547 1547
             }
1548 1548
         } else {
1549
-            if ( $is_digital ) {
1549
+            if ($is_digital) {
1550 1550
                 $ip_country_code = self::get_country_by_ip();
1551 1551
                 
1552
-                if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) {
1553
-                    $rate = self::find_rate( $ip_country_code, '', 0, $class );
1552
+                if ($ip_country_code && self::is_eu_state($ip_country_code)) {
1553
+                    $rate = self::find_rate($ip_country_code, '', 0, $class);
1554 1554
                 } else {
1555
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1555
+                    $rate = self::find_rate($country, $state, $rate, $class);
1556 1556
                 }
1557 1557
             } else {
1558
-                $rate = self::find_rate( $country, $state, $rate, $class );
1558
+                $rate = self::find_rate($country, $state, $rate, $class);
1559 1559
             }
1560 1560
         }
1561 1561
 
@@ -1565,48 +1565,48 @@  discard block
 block discarded – undo
1565 1565
     public static function current_vat_data() {
1566 1566
         global $wpi_session;
1567 1567
         
1568
-        return $wpi_session->get( 'user_vat_data' );
1568
+        return $wpi_session->get('user_vat_data');
1569 1569
     }
1570 1570
     
1571
-    public static function get_user_country( $country = '', $user_id = 0 ) {
1572
-        $user_address = wpinv_get_user_address( $user_id, false );
1571
+    public static function get_user_country($country = '', $user_id = 0) {
1572
+        $user_address = wpinv_get_user_address($user_id, false);
1573 1573
         
1574
-        if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1574
+        if (wpinv_get_option('vat_ip_country_default')) {
1575 1575
             $country = '';
1576 1576
         }
1577 1577
         
1578
-        $country    = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country'];
1579
-        $result     = apply_filters( 'wpinv_get_user_country', $country, $user_id );
1578
+        $country    = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country'];
1579
+        $result     = apply_filters('wpinv_get_user_country', $country, $user_id);
1580 1580
 
1581
-        if ( empty( $result ) ) {
1581
+        if (empty($result)) {
1582 1582
             $result = self::get_country_by_ip();
1583 1583
         }
1584 1584
 
1585 1585
         return $result;
1586 1586
     }
1587 1587
     
1588
-    public static function set_user_country( $country = '', $user_id = 0 ) {
1588
+    public static function set_user_country($country = '', $user_id = 0) {
1589 1589
         global $wpi_userID;
1590 1590
         
1591
-        if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) {
1591
+        if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) {
1592 1592
             $country = wpinv_get_default_country();
1593 1593
         }
1594 1594
         
1595 1595
         return $country;
1596 1596
     }
1597 1597
     
1598
-    public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) {
1598
+    public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) {
1599 1599
         global $wpi_current_id, $wpi_userID;
1600 1600
         
1601
-        if ( !empty( $_POST['new_user'] ) ) {
1601
+        if (!empty($_POST['new_user'])) {
1602 1602
             return '';
1603 1603
         }
1604 1604
         
1605
-        if ( empty( $user_id ) ) {
1606
-            $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() );
1605
+        if (empty($user_id)) {
1606
+            $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id());
1607 1607
         }
1608 1608
 
1609
-        $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true );
1609
+        $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true);
1610 1610
         
1611 1611
         /* TODO
1612 1612
         if ( $is_valid && $vat_number ) {
@@ -1617,38 +1617,38 @@  discard block
 block discarded – undo
1617 1617
         }
1618 1618
         */
1619 1619
 
1620
-        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid );
1620
+        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid);
1621 1621
     }
1622 1622
     
1623
-    public static function get_user_company( $company = '', $user_id = 0 ) {
1623
+    public static function get_user_company($company = '', $user_id = 0) {
1624 1624
         global $wpi_current_id, $wpi_userID;
1625 1625
         
1626
-        if ( empty( $user_id ) ) {
1627
-            $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() );
1626
+        if (empty($user_id)) {
1627
+            $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id());
1628 1628
         }
1629 1629
 
1630
-        $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true );
1630
+        $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true);
1631 1631
 
1632
-        return apply_filters( 'wpinv_user_company', $company, $user_id );
1632
+        return apply_filters('wpinv_user_company', $company, $user_id);
1633 1633
     }
1634 1634
     
1635
-    public static function save_user_vat_details( $company = '', $vat_number = '' ) {
1636
-        $save = apply_filters( 'wpinv_allow_save_user_vat_details', true );
1635
+    public static function save_user_vat_details($company = '', $vat_number = '') {
1636
+        $save = apply_filters('wpinv_allow_save_user_vat_details', true);
1637 1637
 
1638
-        if ( is_user_logged_in() && $save ) {
1638
+        if (is_user_logged_in() && $save) {
1639 1639
             $user_id = get_current_user_id();
1640 1640
 
1641
-            if ( !empty( $vat_number ) ) {
1642
-                update_user_meta( $user_id, '_wpinv_vat_number', $vat_number );
1641
+            if (!empty($vat_number)) {
1642
+                update_user_meta($user_id, '_wpinv_vat_number', $vat_number);
1643 1643
             } else {
1644
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1644
+                delete_user_meta($user_id, '_wpinv_vat_number');
1645 1645
             }
1646 1646
 
1647
-            if ( !empty( $company ) ) {
1648
-                update_user_meta( $user_id, '_wpinv_company', $company );
1647
+            if (!empty($company)) {
1648
+                update_user_meta($user_id, '_wpinv_company', $company);
1649 1649
             } else {
1650
-                delete_user_meta( $user_id, '_wpinv_company');
1651
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1650
+                delete_user_meta($user_id, '_wpinv_company');
1651
+                delete_user_meta($user_id, '_wpinv_vat_number');
1652 1652
             }
1653 1653
         }
1654 1654
 
@@ -1658,113 +1658,113 @@  discard block
 block discarded – undo
1658 1658
     public static function ajax_vat_validate() {
1659 1659
         global $wpinv_options, $wpi_session;
1660 1660
         
1661
-        $is_checkout            = ( !empty( $_POST['source'] ) && $_POST['source'] == 'checkout' ) ? true : false;
1661
+        $is_checkout            = (!empty($_POST['source']) && $_POST['source'] == 'checkout') ? true : false;
1662 1662
         $response               = array();
1663 1663
         $response['success']    = false;
1664 1664
         
1665
-        if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) {
1666
-            $response['error'] = __( 'Invalid security nonce', 'invoicing' );
1667
-            wp_send_json( $response );
1665
+        if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) {
1666
+            $response['error'] = __('Invalid security nonce', 'invoicing');
1667
+            wp_send_json($response);
1668 1668
         }
1669 1669
         
1670
-        $vat_name   = self::get_vat_name();
1670
+        $vat_name = self::get_vat_name();
1671 1671
         
1672
-        if ( $is_checkout ) {
1672
+        if ($is_checkout) {
1673 1673
             $invoice = wpinv_get_invoice_cart();
1674 1674
             
1675
-            if ( !self::requires_vat( false, 0, self::invoice_has_digital_rule( $invoice ) ) ) {
1675
+            if (!self::requires_vat(false, 0, self::invoice_has_digital_rule($invoice))) {
1676 1676
                 $vat_info = array();
1677
-                $wpi_session->set( 'user_vat_data', $vat_info );
1677
+                $wpi_session->set('user_vat_data', $vat_info);
1678 1678
 
1679 1679
                 self::save_user_vat_details();
1680 1680
                 
1681 1681
                 $response['success'] = true;
1682
-                $response['message'] = wp_sprintf( __( 'Ignore %s', 'invoicing' ), $vat_name );
1683
-                wp_send_json( $response );
1682
+                $response['message'] = wp_sprintf(__('Ignore %s', 'invoicing'), $vat_name);
1683
+                wp_send_json($response);
1684 1684
             }
1685 1685
         }
1686 1686
         
1687
-        $company    = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : '';
1688
-        $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : '';
1687
+        $company    = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : '';
1688
+        $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : '';
1689 1689
         
1690
-        $vat_info = $wpi_session->get( 'user_vat_data' );
1691
-        if ( !is_array( $vat_info ) || empty( $vat_info ) ) {
1692
-            $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true );
1690
+        $vat_info = $wpi_session->get('user_vat_data');
1691
+        if (!is_array($vat_info) || empty($vat_info)) {
1692
+            $vat_info = array('company'=> $company, 'number' => '', 'valid' => true);
1693 1693
         }
1694 1694
         
1695
-        if ( empty( $vat_number ) ) {
1696
-            if ( $is_checkout ) {
1695
+        if (empty($vat_number)) {
1696
+            if ($is_checkout) {
1697 1697
                 $response['success'] = true;
1698
-                $response['message'] = wp_sprintf( __( 'No %s number has been applied. %s will be added to invoice totals', 'invoicing' ), $vat_name, $vat_name );
1698
+                $response['message'] = wp_sprintf(__('No %s number has been applied. %s will be added to invoice totals', 'invoicing'), $vat_name, $vat_name);
1699 1699
                 
1700
-                $vat_info = $wpi_session->get( 'user_vat_data' );
1700
+                $vat_info = $wpi_session->get('user_vat_data');
1701 1701
                 $vat_info['number'] = "";
1702 1702
                 $vat_info['valid'] = true;
1703 1703
                 
1704
-                self::save_user_vat_details( $company );
1704
+                self::save_user_vat_details($company);
1705 1705
             } else {
1706
-                $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
1706
+                $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
1707 1707
                 
1708 1708
                 $vat_info['valid'] = false;
1709 1709
             }
1710 1710
 
1711
-            $wpi_session->set( 'user_vat_data', $vat_info );
1712
-            wp_send_json( $response );
1711
+            $wpi_session->set('user_vat_data', $vat_info);
1712
+            wp_send_json($response);
1713 1713
         }
1714 1714
         
1715
-        if ( empty( $company ) ) {
1715
+        if (empty($company)) {
1716 1716
             $vat_info['valid'] = false;
1717
-            $wpi_session->set( 'user_vat_data', $vat_info );
1717
+            $wpi_session->set('user_vat_data', $vat_info);
1718 1718
             
1719
-            $response['error'] = __( 'Please enter your registered company name!', 'invoicing' );
1720
-            wp_send_json( $response );
1719
+            $response['error'] = __('Please enter your registered company name!', 'invoicing');
1720
+            wp_send_json($response);
1721 1721
         }
1722 1722
         
1723
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
1724
-            if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1723
+        if (!empty($wpinv_options['vat_vies_check'])) {
1724
+            if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1725 1725
                 $vat_info['valid'] = false;
1726
-                $wpi_session->set( 'user_vat_data', $vat_info );
1726
+                $wpi_session->set('user_vat_data', $vat_info);
1727 1727
                 
1728
-                $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1729
-                wp_send_json( $response );
1728
+                $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1729
+                wp_send_json($response);
1730 1730
             }
1731 1731
             
1732 1732
             $response['success'] = true;
1733
-            $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1733
+            $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1734 1734
         } else {
1735
-            $result = self::check_vat( $vat_number );
1735
+            $result = self::check_vat($vat_number);
1736 1736
             
1737
-            if ( empty( $result['valid'] ) ) {
1737
+            if (empty($result['valid'])) {
1738 1738
                 $response['error'] = $result['message'];
1739
-                wp_send_json( $response );
1739
+                wp_send_json($response);
1740 1740
             }
1741 1741
             
1742
-            $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1743
-            $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1742
+            $vies_company = !empty($result['company']) ? $result['company'] : '';
1743
+            $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1744 1744
             
1745
-            $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1745
+            $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1746 1746
 
1747
-            if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) {
1747
+            if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) {
1748 1748
                 $response['success'] = true;
1749
-                $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1749
+                $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1750 1750
             } else {           
1751 1751
                 $vat_info['valid'] = false;
1752
-                $wpi_session->set( 'user_vat_data', $vat_info );
1752
+                $wpi_session->set('user_vat_data', $vat_info);
1753 1753
                 
1754 1754
                 $response['success'] = false;
1755
-                $response['message'] = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name );
1756
-                wp_send_json( $response );
1755
+                $response['message'] = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name);
1756
+                wp_send_json($response);
1757 1757
             }
1758 1758
         }
1759 1759
         
1760
-        if ( $is_checkout ) {
1761
-            self::save_user_vat_details( $company, $vat_number );
1760
+        if ($is_checkout) {
1761
+            self::save_user_vat_details($company, $vat_number);
1762 1762
 
1763
-            $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true );
1764
-            $wpi_session->set( 'user_vat_data', $vat_info );
1763
+            $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true);
1764
+            $wpi_session->set('user_vat_data', $vat_info);
1765 1765
         }
1766 1766
 
1767
-        wp_send_json( $response );
1767
+        wp_send_json($response);
1768 1768
     }
1769 1769
     
1770 1770
     public static function ajax_vat_reset() {
@@ -1773,161 +1773,161 @@  discard block
 block discarded – undo
1773 1773
         $company    = is_user_logged_in() ? self::get_user_company() : '';
1774 1774
         $vat_number = self::get_user_vat_number();
1775 1775
         
1776
-        $vat_info   = array('company' => $company, 'number' => $vat_number, 'valid' => false );
1777
-        $wpi_session->set( 'user_vat_data', $vat_info );
1776
+        $vat_info   = array('company' => $company, 'number' => $vat_number, 'valid' => false);
1777
+        $wpi_session->set('user_vat_data', $vat_info);
1778 1778
         
1779 1779
         $response                       = array();
1780 1780
         $response['success']            = true;
1781 1781
         $response['data']['company']    = $company;
1782 1782
         $response['data']['number']     = $vat_number;
1783 1783
         
1784
-        wp_send_json( $response );
1784
+        wp_send_json($response);
1785 1785
     }
1786 1786
     
1787
-    public static function checkout_vat_validate( $valid_data, $post ) {
1787
+    public static function checkout_vat_validate($valid_data, $post) {
1788 1788
         global $wpinv_options, $wpi_session;
1789 1789
         
1790
-        $vat_name  = __( self::get_vat_name(), 'invoicing' );
1790
+        $vat_name = __(self::get_vat_name(), 'invoicing');
1791 1791
         
1792
-        if ( !isset( $_POST['_wpi_nonce'] ) || !wp_verify_nonce( $_POST['_wpi_nonce'], 'vat_validation' ) ) {
1793
-            wpinv_set_error( 'vat_validation', wp_sprintf( __( "Invalid %s validation request.", 'invoicing' ), $vat_name ) );
1792
+        if (!isset($_POST['_wpi_nonce']) || !wp_verify_nonce($_POST['_wpi_nonce'], 'vat_validation')) {
1793
+            wpinv_set_error('vat_validation', wp_sprintf(__("Invalid %s validation request.", 'invoicing'), $vat_name));
1794 1794
             return;
1795 1795
         }
1796 1796
         
1797
-        $vat_saved = $wpi_session->get( 'user_vat_data' );
1798
-        $wpi_session->set( 'user_vat_data', null );
1797
+        $vat_saved = $wpi_session->get('user_vat_data');
1798
+        $wpi_session->set('user_vat_data', null);
1799 1799
         
1800 1800
         $invoice        = wpinv_get_invoice_cart();
1801 1801
         $amount         = $invoice->get_total();
1802
-        $is_digital     = self::invoice_has_digital_rule( $invoice );
1803
-        $no_vat         = !self::requires_vat( 0, false, $is_digital );
1802
+        $is_digital     = self::invoice_has_digital_rule($invoice);
1803
+        $no_vat         = !self::requires_vat(0, false, $is_digital);
1804 1804
         
1805
-        $company        = !empty( $_POST['wpinv_company'] ) ? $_POST['wpinv_company'] : null;
1806
-        $vat_number     = !empty( $_POST['wpinv_vat_number'] ) ? $_POST['wpinv_vat_number'] : null;
1807
-        $country        = !empty( $_POST['wpinv_country'] ) ? $_POST['wpinv_country'] : $invoice->country;
1808
-        if ( empty( $country ) ) {
1805
+        $company        = !empty($_POST['wpinv_company']) ? $_POST['wpinv_company'] : null;
1806
+        $vat_number     = !empty($_POST['wpinv_vat_number']) ? $_POST['wpinv_vat_number'] : null;
1807
+        $country        = !empty($_POST['wpinv_country']) ? $_POST['wpinv_country'] : $invoice->country;
1808
+        if (empty($country)) {
1809 1809
             $country = wpinv_default_billing_country();
1810 1810
         }
1811 1811
         
1812
-        if ( !$is_digital && $no_vat ) {
1812
+        if (!$is_digital && $no_vat) {
1813 1813
             return;
1814 1814
         }
1815 1815
             
1816
-        $vat_data           = array( 'company' => '', 'number' => '', 'valid' => false );
1816
+        $vat_data           = array('company' => '', 'number' => '', 'valid' => false);
1817 1817
         
1818 1818
         $ip_country_code    = self::get_country_by_ip();
1819
-        $is_eu_state        = self::is_eu_state( $country );
1820
-        $is_eu_state_ip     = self::is_eu_state( $ip_country_code );
1819
+        $is_eu_state        = self::is_eu_state($country);
1820
+        $is_eu_state_ip     = self::is_eu_state($ip_country_code);
1821 1821
         $is_non_eu_user     = !$is_eu_state && !$is_eu_state_ip;
1822 1822
         
1823
-        if ( $is_digital && !$is_non_eu_user && empty( $vat_number ) && apply_filters( 'wpinv_checkout_requires_country', true, $amount ) ) {
1823
+        if ($is_digital && !$is_non_eu_user && empty($vat_number) && apply_filters('wpinv_checkout_requires_country', true, $amount)) {
1824 1824
             $vat_data['adddress_confirmed'] = false;
1825 1825
             
1826
-            if ( !isset( $_POST['wpinv_adddress_confirmed'] ) ) {
1827
-                if ( $ip_country_code != $country ) {
1828
-                    wpinv_set_error( 'vat_validation', sprintf( __( 'The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing' ), '<a href="#wpinv_adddress_confirm">', '</a>' ) );
1826
+            if (!isset($_POST['wpinv_adddress_confirmed'])) {
1827
+                if ($ip_country_code != $country) {
1828
+                    wpinv_set_error('vat_validation', sprintf(__('The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing'), '<a href="#wpinv_adddress_confirm">', '</a>'));
1829 1829
                 }
1830 1830
             } else {
1831 1831
                 $vat_data['adddress_confirmed'] = true;
1832 1832
             }
1833 1833
         }
1834 1834
         
1835
-        if ( !empty( $wpinv_options['vat_prevent_b2c_purchase'] ) && !$is_non_eu_user && ( empty( $vat_number ) || $no_vat ) ) {
1836
-            if ( $is_eu_state ) {
1837
-                wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing' ), $vat_name ) );
1838
-            } else if ( $is_digital && $is_eu_state_ip ) {
1839
-                wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing' ), $vat_name ) );
1835
+        if (!empty($wpinv_options['vat_prevent_b2c_purchase']) && !$is_non_eu_user && (empty($vat_number) || $no_vat)) {
1836
+            if ($is_eu_state) {
1837
+                wpinv_set_error('vat_validation', wp_sprintf(__('Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing'), $vat_name));
1838
+            } else if ($is_digital && $is_eu_state_ip) {
1839
+                wpinv_set_error('vat_validation', wp_sprintf(__('Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing'), $vat_name));
1840 1840
             }
1841 1841
         }
1842 1842
         
1843
-        if ( !$is_eu_state || $no_vat || empty( $vat_number ) ) {
1843
+        if (!$is_eu_state || $no_vat || empty($vat_number)) {
1844 1844
             return;
1845 1845
         }
1846 1846
 
1847
-        if ( !empty( $vat_saved ) && isset( $vat_saved['valid'] ) ) {
1848
-            $vat_data['valid']  = $vat_saved['valid'];
1847
+        if (!empty($vat_saved) && isset($vat_saved['valid'])) {
1848
+            $vat_data['valid'] = $vat_saved['valid'];
1849 1849
         }
1850 1850
             
1851
-        if ( $company !== null ) {
1851
+        if ($company !== null) {
1852 1852
             $vat_data['company'] = $company;
1853 1853
         }
1854 1854
 
1855 1855
         $message = '';
1856
-        if ( $vat_number !== null ) {
1856
+        if ($vat_number !== null) {
1857 1857
             $vat_data['number'] = $vat_number;
1858 1858
             
1859
-            if ( !$vat_data['valid'] || ( $vat_saved['number'] !== $vat_data['number'] ) || ( $vat_saved['company'] !== $vat_data['company'] ) ) {
1860
-                if ( !empty( $wpinv_options['vat_vies_check'] ) ) {            
1861
-                    if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1859
+            if (!$vat_data['valid'] || ($vat_saved['number'] !== $vat_data['number']) || ($vat_saved['company'] !== $vat_data['company'])) {
1860
+                if (!empty($wpinv_options['vat_vies_check'])) {            
1861
+                    if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1862 1862
                         $vat_data['valid'] = false;
1863 1863
                     }
1864 1864
                 } else {
1865
-                    $result = self::check_vat( $vat_number );
1865
+                    $result = self::check_vat($vat_number);
1866 1866
                     
1867
-                    if ( !empty( $result['valid'] ) ) {                
1867
+                    if (!empty($result['valid'])) {                
1868 1868
                         $vat_data['valid'] = true;
1869
-                        $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1870
-                        $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1869
+                        $vies_company = !empty($result['company']) ? $result['company'] : '';
1870
+                        $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1871 1871
                     
1872
-                        $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1872
+                        $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1873 1873
 
1874
-                        if ( !( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) ) {         
1874
+                        if (!(!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company)) {         
1875 1875
                             $vat_data['valid'] = false;
1876 1876
                             
1877
-                            $message = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name );
1877
+                            $message = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name);
1878 1878
                         }
1879 1879
                     } else {
1880
-                        $message = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
1880
+                        $message = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
1881 1881
                     }
1882 1882
                 }
1883 1883
                 
1884
-                if ( !$vat_data['valid'] ) {
1885
-                    $error = wp_sprintf( __( 'The %s %s number %s you have entered has not been validated', 'invoicing' ), '<a href="#wpi-vat-details">', $vat_name, '</a>' ) . ( $message ? ' ( ' . $message . ' )' : '' );
1886
-                    wpinv_set_error( 'vat_validation', $error );
1884
+                if (!$vat_data['valid']) {
1885
+                    $error = wp_sprintf(__('The %s %s number %s you have entered has not been validated', 'invoicing'), '<a href="#wpi-vat-details">', $vat_name, '</a>') . ($message ? ' ( ' . $message . ' )' : '');
1886
+                    wpinv_set_error('vat_validation', $error);
1887 1887
                 }
1888 1888
             }
1889 1889
         }
1890 1890
 
1891
-        $wpi_session->set( 'user_vat_data', $vat_data );
1891
+        $wpi_session->set('user_vat_data', $vat_data);
1892 1892
     }
1893 1893
     
1894
-    public static function checkout_vat_fields( $billing_details ) {
1894
+    public static function checkout_vat_fields($billing_details) {
1895 1895
         global $wpi_session, $wpinv_options, $wpi_country, $wpi_requires_vat;
1896 1896
         
1897 1897
         $ip_address         = wpinv_get_ip();
1898 1898
         $ip_country_code    = self::get_country_by_ip();
1899 1899
         
1900
-        $tax_label          = __( self::get_vat_name(), 'invoicing' );
1900
+        $tax_label          = __(self::get_vat_name(), 'invoicing');
1901 1901
         $invoice            = wpinv_get_invoice_cart();
1902
-        $is_digital         = self::invoice_has_digital_rule( $invoice );
1902
+        $is_digital         = self::invoice_has_digital_rule($invoice);
1903 1903
         $wpi_country        = $invoice->country;
1904 1904
         
1905
-        $requires_vat       = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat( 0, false, $is_digital );
1905
+        $requires_vat       = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat(0, false, $is_digital);
1906 1906
         $wpi_requires_vat   = $requires_vat;
1907 1907
         
1908 1908
         $company            = self::get_user_company();
1909 1909
         $vat_number         = self::get_user_vat_number();
1910 1910
         
1911
-        $validated          = $vat_number ? self::get_user_vat_number( '', 0, true ) : 1;
1912
-        $vat_info           = $wpi_session->get( 'user_vat_data' );
1911
+        $validated          = $vat_number ? self::get_user_vat_number('', 0, true) : 1;
1912
+        $vat_info           = $wpi_session->get('user_vat_data');
1913 1913
 
1914
-        if ( is_array( $vat_info ) ) {
1915
-            $company    = isset( $vat_info['company'] ) ? $vat_info['company'] : '';
1916
-            $vat_number = isset( $vat_info['number'] ) ? $vat_info['number'] : '';
1917
-            $validated  = isset( $vat_info['valid'] ) ? $vat_info['valid'] : false;
1914
+        if (is_array($vat_info)) {
1915
+            $company    = isset($vat_info['company']) ? $vat_info['company'] : '';
1916
+            $vat_number = isset($vat_info['number']) ? $vat_info['number'] : '';
1917
+            $validated  = isset($vat_info['valid']) ? $vat_info['valid'] : false;
1918 1918
         }
1919 1919
         
1920 1920
         $selected_country = $invoice->country ? $invoice->country : wpinv_default_billing_country();
1921 1921
 
1922
-        if ( $ip_country_code == 'UK' ) {
1922
+        if ($ip_country_code == 'UK') {
1923 1923
             $ip_country_code = 'GB';
1924 1924
         }
1925 1925
         
1926
-        if ( $selected_country == 'UK' ) {
1926
+        if ($selected_country == 'UK') {
1927 1927
             $selected_country = 'GB';
1928 1928
         }
1929 1929
         
1930
-        if ( $requires_vat && ( self::same_country_rule() == 'no' && wpinv_is_base_country( $selected_country ) || !self::allow_vat_rules() ) ) {
1930
+        if ($requires_vat && (self::same_country_rule() == 'no' && wpinv_is_base_country($selected_country) || !self::allow_vat_rules())) {
1931 1931
             $requires_vat = false;
1932 1932
         }
1933 1933
 
@@ -1935,52 +1935,52 @@  discard block
 block discarded – undo
1935 1935
         $display_validate_btn   = 'none';
1936 1936
         $display_reset_btn      = 'none';
1937 1937
         
1938
-        if ( !empty( $vat_number ) && $validated ) {
1939
-            $vat_vailidated_text    = wp_sprintf( __( '%s number validated', 'invoicing' ), $tax_label );
1938
+        if (!empty($vat_number) && $validated) {
1939
+            $vat_vailidated_text    = wp_sprintf(__('%s number validated', 'invoicing'), $tax_label);
1940 1940
             $vat_vailidated_class   = 'wpinv-vat-stat-1';
1941 1941
             $display_reset_btn      = 'block';
1942 1942
         } else {
1943
-            $vat_vailidated_text    = empty( $vat_number ) ? '' : wp_sprintf( __( '%s number not validated', 'invoicing' ), $tax_label );
1944
-            $vat_vailidated_class   = empty( $vat_number ) ? '' : 'wpinv-vat-stat-0';
1943
+            $vat_vailidated_text    = empty($vat_number) ? '' : wp_sprintf(__('%s number not validated', 'invoicing'), $tax_label);
1944
+            $vat_vailidated_class   = empty($vat_number) ? '' : 'wpinv-vat-stat-0';
1945 1945
             $display_validate_btn   = 'block';
1946 1946
         }
1947 1947
         
1948
-        $show_ip_country        = $is_digital && ( empty( $vat_number ) || !$requires_vat ) && $ip_country_code != $selected_country ? 'block' : 'none';
1948
+        $show_ip_country = $is_digital && (empty($vat_number) || !$requires_vat) && $ip_country_code != $selected_country ? 'block' : 'none';
1949 1949
         ?>
1950 1950
         <div id="wpi-vat-details" class="wpi-vat-details clearfix" style="display:<?php echo $display_vat_details; ?>">
1951 1951
             <div id="wpi_vat_info" class="clearfix panel panel-default">
1952
-                <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf( __( '%s Details', 'invoicing' ), $tax_label );?></h3></div>
1952
+                <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf(__('%s Details', 'invoicing'), $tax_label); ?></h3></div>
1953 1953
                 <div id="wpinv-fields-box" class="panel-body">
1954 1954
                     <p id="wpi_show_vat_note">
1955
-                        <?php echo wp_sprintf( __( 'Validate your registered %s number to exclude tax.', 'invoicing' ), $tax_label ); ?>
1955
+                        <?php echo wp_sprintf(__('Validate your registered %s number to exclude tax.', 'invoicing'), $tax_label); ?>
1956 1956
                     </p>
1957 1957
                     <div id="wpi_vat_fields" class="wpi_vat_info">
1958 1958
                         <p class="wpi-cart-field wpi-col2 wpi-colf">
1959
-                            <label for="wpinv_company" class="wpi-label"><?php _e( 'Company Name', 'invoicing' );?></label>
1959
+                            <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label>
1960 1960
                             <?php
1961
-                            echo wpinv_html_text( array(
1961
+                            echo wpinv_html_text(array(
1962 1962
                                     'id'            => 'wpinv_company',
1963 1963
                                     'name'          => 'wpinv_company',
1964 1964
                                     'value'         => $company,
1965 1965
                                     'class'         => 'wpi-input form-control',
1966
-                                    'placeholder'   => __( 'Company name', 'invoicing' ),
1967
-                                ) );
1966
+                                    'placeholder'   => __('Company name', 'invoicing'),
1967
+                                ));
1968 1968
                             ?>
1969 1969
                         </p>
1970 1970
                         <p class="wpi-cart-field wpi-col2 wpi-coll wpi-cart-field-vat">
1971
-                            <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf( __( '%s Number', 'invoicing' ), $tax_label );?></label>
1971
+                            <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf(__('%s Number', 'invoicing'), $tax_label); ?></label>
1972 1972
                             <span id="wpinv_vat_number-wrap">
1973 1973
                                 <label for="wpinv_vat_number" class="wpinv-label"></label>
1974
-                                <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr( wp_sprintf( __( '%s number', 'invoicing' ), $tax_label ) );?>" value="<?php esc_attr_e( $vat_number );?>" id="wpinv_vat_number" name="wpinv_vat_number">
1975
-                                <span class="wpinv-vat-stat <?php echo $vat_vailidated_class;?>"><i class="fa"></i>&nbsp;<font><?php echo $vat_vailidated_text;?></font></span>
1974
+                                <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr(wp_sprintf(__('%s number', 'invoicing'), $tax_label)); ?>" value="<?php esc_attr_e($vat_number); ?>" id="wpinv_vat_number" name="wpinv_vat_number">
1975
+                                <span class="wpinv-vat-stat <?php echo $vat_vailidated_class; ?>"><i class="fa"></i>&nbsp;<font><?php echo $vat_vailidated_text; ?></font></span>
1976 1976
                             </span>
1977 1977
                         </p>
1978 1978
                         <p class="wpi-cart-field wpi-col wpi-colf wpi-cart-field-actions">
1979
-                            <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf( __("Validate %s Number", 'invoicing'), $tax_label ); ?></button>
1980
-                            <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf( __("Reset %s", 'invoicing'), $tax_label ); ?></button>
1979
+                            <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf(__("Validate %s Number", 'invoicing'), $tax_label); ?></button>
1980
+                            <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf(__("Reset %s", 'invoicing'), $tax_label); ?></button>
1981 1981
                             <span class="wpi-vat-box wpi-vat-box-info"><span id="text"></span></span>
1982 1982
                             <span class="wpi-vat-box wpi-vat-box-error"><span id="text"></span></span>
1983
-                            <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce( 'vat_validation' ) ?>" />
1983
+                            <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce('vat_validation') ?>" />
1984 1984
                         </p>
1985 1985
                     </div>
1986 1986
                 </div>
@@ -1994,32 +1994,32 @@  discard block
 block discarded – undo
1994 1994
                 </span>
1995 1995
             </div>
1996 1996
         </div>
1997
-        <?php if ( empty( $wpinv_options['hide_ip_address'] ) ) { 
1998
-            $ip_link = '<a title="' . esc_attr( __( 'View more details on map', 'invoicing' ) ) . '" target="_blank" href="' . esc_url( admin_url( 'admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address ) ) . '" class="wpi-ip-address-link">' . $ip_address . '&nbsp;&nbsp;<i class="fa fa-external-link-square" aria-hidden="true"></i></a>';
1997
+        <?php if (empty($wpinv_options['hide_ip_address'])) { 
1998
+            $ip_link = '<a title="' . esc_attr(__('View more details on map', 'invoicing')) . '" target="_blank" href="' . esc_url(admin_url('admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address)) . '" class="wpi-ip-address-link">' . $ip_address . '&nbsp;&nbsp;<i class="fa fa-external-link-square" aria-hidden="true"></i></a>';
1999 1999
         ?>
2000 2000
         <div class="wpi-ip-info clearfix panel panel-info">
2001 2001
             <div id="wpinv-fields-box" class="panel-body">
2002
-                <span><?php echo wp_sprintf( __( "Your IP address is: %s", 'invoicing' ), $ip_link ); ?></span>
2002
+                <span><?php echo wp_sprintf(__("Your IP address is: %s", 'invoicing'), $ip_link); ?></span>
2003 2003
             </div>
2004 2004
         </div>
2005 2005
         <?php }
2006 2006
     }
2007 2007
     
2008
-    public static function show_vat_notice( $invoice ) {
2009
-        if ( empty( $invoice ) ) {
2008
+    public static function show_vat_notice($invoice) {
2009
+        if (empty($invoice)) {
2010 2010
             return NULL;
2011 2011
         }
2012 2012
         
2013
-        $label      = wpinv_get_option( 'vat_invoice_notice_label' );
2014
-        $notice     = wpinv_get_option( 'vat_invoice_notice' );
2015
-        if ( $label || $notice ) {
2013
+        $label      = wpinv_get_option('vat_invoice_notice_label');
2014
+        $notice     = wpinv_get_option('vat_invoice_notice');
2015
+        if ($label || $notice) {
2016 2016
         ?>
2017 2017
         <div class="row wpinv-vat-notice">
2018 2018
             <div class="col-sm-12">
2019
-                <?php if ( $label ) { ?>
2020
-                <strong><?php _e( $label, 'invoicing' ); ?></strong>
2021
-                <?php } if ( $notice ) { ?>
2022
-                <?php echo wpautop( wptexturize( __( $notice, 'invoicing' ) ) ) ?>
2019
+                <?php if ($label) { ?>
2020
+                <strong><?php _e($label, 'invoicing'); ?></strong>
2021
+                <?php } if ($notice) { ?>
2022
+                <?php echo wpautop(wptexturize(__($notice, 'invoicing'))) ?>
2023 2023
                 <?php } ?>
2024 2024
             </div>
2025 2025
         </div>
Please login to merge, or discard this patch.
includes/wpinv-discount-functions.php 3 patches
Doc Comments   +18 added lines patch added patch discarded remove patch
@@ -324,12 +324,18 @@  discard block
 block discarded – undo
324 324
     return apply_filters( 'wpinv_get_discount_code', $code, $code_id );
325 325
 }
326 326
 
327
+/**
328
+ * @return string
329
+ */
327 330
 function wpinv_get_discount_start_date( $code_id = null ) {
328 331
     $start_date = get_post_meta( $code_id, '_wpi_discount_start', true );
329 332
 
330 333
     return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id );
331 334
 }
332 335
 
336
+/**
337
+ * @return string
338
+ */
333 339
 function wpinv_get_discount_expiration( $code_id = null ) {
334 340
     $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true );
335 341
 
@@ -652,6 +658,9 @@  discard block
 block discarded – undo
652 658
     return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition );
653 659
 }
654 660
 
661
+/**
662
+ * @param string $code
663
+ */
655 664
 function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) {
656 665
     global $wpi_checkout_id;
657 666
     
@@ -817,6 +826,9 @@  discard block
 block discarded – undo
817 826
 
818 827
 }
819 828
 
829
+/**
830
+ * @param double $amount
831
+ */
820 832
 function wpinv_format_discount_rate( $type, $amount ) {
821 833
     if ( $type == 'flat' ) {
822 834
         return wpinv_price( wpinv_format_amount( $amount ) );
@@ -861,6 +873,9 @@  discard block
 block discarded – undo
861 873
     return $discounts;
862 874
 }
863 875
 
876
+/**
877
+ * @return boolean
878
+ */
864 879
 function wpinv_unset_cart_discount( $code = '' ) {    
865 880
     $discounts = wpinv_get_cart_discounts();
866 881
 
@@ -1175,6 +1190,9 @@  discard block
 block discarded – undo
1175 1190
 }
1176 1191
 //add_action( 'init', 'wpinv_apply_preset_discount', 999 );
1177 1192
 
1193
+/**
1194
+ * @param integer $code
1195
+ */
1178 1196
 function wpinv_get_discount_label( $code, $echo = true ) {
1179 1197
     $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) );
1180 1198
     $label = apply_filters( 'wpinv_get_discount_label', $label, $code );
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -887,8 +887,8 @@
 block discarded – undo
887 887
     if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) {
888 888
         unset( $data['cart_discounts'] );
889 889
         
890
-         wpinv_set_checkout_session( $data );
891
-         return true;
890
+            wpinv_set_checkout_session( $data );
891
+            return true;
892 892
     }
893 893
     
894 894
     return false;
Please login to merge, or discard this patch.
Spacing   +470 added lines, -470 removed lines patch added patch discarded remove patch
@@ -7,90 +7,90 @@  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_discount_types() {
15 15
     $discount_types = array(
16
-                        'percent'   => __( 'Percentage', 'invoicing' ),
17
-                        'flat'     => __( 'Flat Amount', 'invoicing' ),
16
+                        'percent'   => __('Percentage', 'invoicing'),
17
+                        'flat'     => __('Flat Amount', 'invoicing'),
18 18
                     );
19
-    return (array)apply_filters( 'wpinv_discount_types', $discount_types );
19
+    return (array)apply_filters('wpinv_discount_types', $discount_types);
20 20
 }
21 21
 
22
-function wpinv_get_discount_type_name( $type = '' ) {
22
+function wpinv_get_discount_type_name($type = '') {
23 23
     $types = wpinv_get_discount_types();
24
-    return isset( $types[ $type ] ) ? $types[ $type ] : '';
24
+    return isset($types[$type]) ? $types[$type] : '';
25 25
 }
26 26
 
27
-function wpinv_delete_discount( $data ) {
28
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
29
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
27
+function wpinv_delete_discount($data) {
28
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
29
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
30 30
     }
31 31
 
32
-    if( ! current_user_can( 'manage_options' ) ) {
33
-        wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
32
+    if (!current_user_can('manage_options')) {
33
+        wp_die(__('You do not have permission to delete discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
34 34
     }
35 35
 
36 36
     $discount_id = $data['discount'];
37
-    wpinv_remove_discount( $discount_id );
37
+    wpinv_remove_discount($discount_id);
38 38
 }
39
-add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' );
39
+add_action('wpinv_delete_discount', 'wpinv_delete_discount');
40 40
 
41
-function wpinv_activate_discount( $data ) {
42
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
43
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
41
+function wpinv_activate_discount($data) {
42
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
43
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
44 44
     }
45 45
 
46
-    if( ! current_user_can( 'manage_options' ) ) {
47
-        wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
46
+    if (!current_user_can('manage_options')) {
47
+        wp_die(__('You do not have permission to edit discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
48 48
     }
49 49
 
50
-    $id = absint( $data['discount'] );
51
-    wpinv_update_discount_status( $id, 'publish' );
50
+    $id = absint($data['discount']);
51
+    wpinv_update_discount_status($id, 'publish');
52 52
 }
53
-add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' );
53
+add_action('wpinv_activate_discount', 'wpinv_activate_discount');
54 54
 
55
-function wpinv_deactivate_discount( $data ) {
56
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
57
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
55
+function wpinv_deactivate_discount($data) {
56
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
57
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
58 58
     }
59 59
 
60
-    if( ! current_user_can( 'manage_options' ) ) {
61
-        wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) );
60
+    if (!current_user_can('manage_options')) {
61
+        wp_die(__('You do not have permission to create discount codes', 'invoicing'), array('response' => 403));
62 62
     }
63 63
 
64
-    $id = absint( $data['discount'] );
65
-    wpinv_update_discount_status( $id, 'pending' );
64
+    $id = absint($data['discount']);
65
+    wpinv_update_discount_status($id, 'pending');
66 66
 }
67
-add_action( 'wpinv_deactivate_discount', 'wpinv_deactivate_discount' );
67
+add_action('wpinv_deactivate_discount', 'wpinv_deactivate_discount');
68 68
 
69
-function wpinv_get_discounts( $args = array() ) {
69
+function wpinv_get_discounts($args = array()) {
70 70
     $defaults = array(
71 71
         'post_type'      => 'wpi_discount',
72 72
         'posts_per_page' => 20,
73 73
         'paged'          => null,
74
-        'post_status'    => array( 'publish', 'pending', 'draft', 'expired' )
74
+        'post_status'    => array('publish', 'pending', 'draft', 'expired')
75 75
     );
76 76
 
77
-    $args = wp_parse_args( $args, $defaults );
77
+    $args = wp_parse_args($args, $defaults);
78 78
 
79
-    $discounts = get_posts( $args );
79
+    $discounts = get_posts($args);
80 80
 
81
-    if ( $discounts ) {
81
+    if ($discounts) {
82 82
         return $discounts;
83 83
     }
84 84
 
85
-    if( ! $discounts && ! empty( $args['s'] ) ) {
85
+    if (!$discounts && !empty($args['s'])) {
86 86
         $args['meta_key']     = '_wpi_discount_code';
87 87
         $args['meta_value']   = $args['s'];
88 88
         $args['meta_compare'] = 'LIKE';
89
-        unset( $args['s'] );
90
-        $discounts = get_posts( $args );
89
+        unset($args['s']);
90
+        $discounts = get_posts($args);
91 91
     }
92 92
 
93
-    if( $discounts ) {
93
+    if ($discounts) {
94 94
         return $discounts;
95 95
     }
96 96
 
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
 
103 103
     $discounts  = wpinv_get_discounts();
104 104
 
105
-    if ( $discounts) {
106
-        foreach ( $discounts as $discount ) {
107
-            if ( wpinv_is_discount_active( $discount->ID ) ) {
105
+    if ($discounts) {
106
+        foreach ($discounts as $discount) {
107
+            if (wpinv_is_discount_active($discount->ID)) {
108 108
                 $has_active = true;
109 109
                 break;
110 110
             }
@@ -113,38 +113,38 @@  discard block
 block discarded – undo
113 113
     return $has_active;
114 114
 }
115 115
 
116
-function wpinv_get_discount( $discount_id = 0 ) {
117
-    if( empty( $discount_id ) ) {
116
+function wpinv_get_discount($discount_id = 0) {
117
+    if (empty($discount_id)) {
118 118
         return false;
119 119
     }
120 120
     
121
-    if ( get_post_type( $discount_id ) != 'wpi_discount' ) {
121
+    if (get_post_type($discount_id) != 'wpi_discount') {
122 122
         return false;
123 123
     }
124 124
 
125
-    $discount = get_post( $discount_id );
125
+    $discount = get_post($discount_id);
126 126
 
127 127
     return $discount;
128 128
 }
129 129
 
130
-function wpinv_get_discount_by_code( $code = '' ) {
131
-    if( empty( $code ) || ! is_string( $code ) ) {
130
+function wpinv_get_discount_by_code($code = '') {
131
+    if (empty($code) || !is_string($code)) {
132 132
         return false;
133 133
     }
134 134
 
135
-    return wpinv_get_discount_by( 'code', $code );
135
+    return wpinv_get_discount_by('code', $code);
136 136
 }
137 137
 
138
-function wpinv_get_discount_by( $field = '', $value = '' ) {
139
-    if( empty( $field ) || empty( $value ) ) {
138
+function wpinv_get_discount_by($field = '', $value = '') {
139
+    if (empty($field) || empty($value)) {
140 140
         return false;
141 141
     }
142 142
 
143
-    if( ! is_string( $field ) ) {
143
+    if (!is_string($field)) {
144 144
         return false;
145 145
     }
146 146
 
147
-    switch( strtolower( $field ) ) {
147
+    switch (strtolower($field)) {
148 148
 
149 149
         case 'code':
150 150
             $meta_query     = array();
@@ -154,32 +154,32 @@  discard block
 block discarded – undo
154 154
                 'compare' => '='
155 155
             );
156 156
             
157
-            $discount = wpinv_get_discounts( array(
157
+            $discount = wpinv_get_discounts(array(
158 158
                 'posts_per_page' => 1,
159 159
                 'post_status'    => 'any',
160 160
                 'meta_query'     => $meta_query,
161
-            ) );
161
+            ));
162 162
             
163
-            if( $discount ) {
163
+            if ($discount) {
164 164
                 $discount = $discount[0];
165 165
             }
166 166
 
167 167
             break;
168 168
 
169 169
         case 'id':
170
-            $discount = wpinv_get_discount( $value );
170
+            $discount = wpinv_get_discount($value);
171 171
 
172 172
             break;
173 173
 
174 174
         case 'name':
175
-            $discount = get_posts( array(
175
+            $discount = get_posts(array(
176 176
                 'post_type'      => 'wpi_discount',
177 177
                 'name'           => $value,
178 178
                 'posts_per_page' => 1,
179 179
                 'post_status'    => 'any'
180
-            ) );
180
+            ));
181 181
 
182
-            if( $discount ) {
182
+            if ($discount) {
183 183
                 $discount = $discount[0];
184 184
             }
185 185
 
@@ -189,96 +189,96 @@  discard block
 block discarded – undo
189 189
             return false;
190 190
     }
191 191
 
192
-    if( ! empty( $discount ) ) {
192
+    if (!empty($discount)) {
193 193
         return $discount;
194 194
     }
195 195
 
196 196
     return false;
197 197
 }
198 198
 
199
-function wpinv_store_discount( $post_id, $data, $post, $update = false ) {
199
+function wpinv_store_discount($post_id, $data, $post, $update = false) {
200 200
     $meta = array(
201
-        'code'              => isset( $data['code'] )             ? sanitize_text_field( $data['code'] )              : '',
202
-        'type'              => isset( $data['type'] )             ? sanitize_text_field( $data['type'] )              : 'percent',
203
-        'amount'            => isset( $data['amount'] )           ? wpinv_sanitize_amount( $data['amount'] )          : '',
204
-        'start'             => isset( $data['start'] )            ? sanitize_text_field( $data['start'] )             : '',
205
-        'expiration'        => isset( $data['expiration'] )       ? sanitize_text_field( $data['expiration'] )        : '',
206
-        'min_total'         => isset( $data['min_total'] )        ? wpinv_sanitize_amount( $data['min_total'] )       : '',
207
-        'max_total'         => isset( $data['max_total'] )        ? wpinv_sanitize_amount( $data['max_total'] )       : '',
208
-        'max_uses'          => isset( $data['max_uses'] )         ? absint( $data['max_uses'] )                       : '',
209
-        'items'             => isset( $data['items'] )            ? $data['items']                                    : array(),
210
-        'excluded_items'    => isset( $data['excluded_items'] )   ? $data['excluded_items']                           : array(),
211
-        'is_recurring'      => isset( $data['recurring'] )        ? (bool)$data['recurring']                          : false,
212
-        'is_single_use'     => isset( $data['single_use'] )       ? (bool)$data['single_use']                         : false,
213
-        'uses'              => isset( $data['uses'] )             ? (int)$data['uses']                                : false,
201
+        'code'              => isset($data['code']) ? sanitize_text_field($data['code']) : '',
202
+        'type'              => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent',
203
+        'amount'            => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '',
204
+        'start'             => isset($data['start']) ? sanitize_text_field($data['start']) : '',
205
+        'expiration'        => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '',
206
+        'min_total'         => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '',
207
+        'max_total'         => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '',
208
+        'max_uses'          => isset($data['max_uses']) ? absint($data['max_uses']) : '',
209
+        'items'             => isset($data['items']) ? $data['items'] : array(),
210
+        'excluded_items'    => isset($data['excluded_items']) ? $data['excluded_items'] : array(),
211
+        'is_recurring'      => isset($data['recurring']) ? (bool)$data['recurring'] : false,
212
+        'is_single_use'     => isset($data['single_use']) ? (bool)$data['single_use'] : false,
213
+        'uses'              => isset($data['uses']) ? (int)$data['uses'] : false,
214 214
     );
215 215
 
216
-    if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) {
216
+    if ($meta['type'] == 'percent' && (float)$meta['amount'] > 100) {
217 217
         $meta['amount'] = 100;
218 218
     }
219 219
 
220
-    if ( !empty( $meta['start'] ) ) {
221
-        $meta['start']      = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['start'] ) );
220
+    if (!empty($meta['start'])) {
221
+        $meta['start'] = date_i18n('Y-m-d H:i:s', strtotime($meta['start']));
222 222
     }
223 223
 
224
-    if ( !empty( $meta['expiration'] ) ) {
225
-        $meta['expiration'] = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['expiration'] ) );
224
+    if (!empty($meta['expiration'])) {
225
+        $meta['expiration'] = date_i18n('Y-m-d H:i:s', strtotime($meta['expiration']));
226 226
 
227
-        if ( !empty( $meta['start'] ) && strtotime( $meta['start'] ) > strtotime( $meta['expiration'] ) ) {
227
+        if (!empty($meta['start']) && strtotime($meta['start']) > strtotime($meta['expiration'])) {
228 228
             $meta['expiration'] = $meta['start'];
229 229
         }
230 230
     }
231 231
     
232
-    if ( $meta['uses'] === false ) {
233
-        unset( $meta['uses'] );
232
+    if ($meta['uses'] === false) {
233
+        unset($meta['uses']);
234 234
     }
235 235
     
236
-    if ( ! empty( $meta['items'] ) ) {
237
-        foreach ( $meta['items'] as $key => $item ) {
238
-            if ( 0 === intval( $item ) ) {
239
-                unset( $meta['items'][ $key ] );
236
+    if (!empty($meta['items'])) {
237
+        foreach ($meta['items'] as $key => $item) {
238
+            if (0 === intval($item)) {
239
+                unset($meta['items'][$key]);
240 240
             }
241 241
         }
242 242
     }
243 243
     
244
-    if ( ! empty( $meta['excluded_items'] ) ) {
245
-        foreach ( $meta['excluded_items'] as $key => $item ) {
246
-            if ( 0 === intval( $item ) ) {
247
-                unset( $meta['excluded_items'][ $key ] );
244
+    if (!empty($meta['excluded_items'])) {
245
+        foreach ($meta['excluded_items'] as $key => $item) {
246
+            if (0 === intval($item)) {
247
+                unset($meta['excluded_items'][$key]);
248 248
             }
249 249
         }
250 250
     }
251 251
     
252
-    $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post );
252
+    $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post);
253 253
     
254
-    do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post );
254
+    do_action('wpinv_pre_update_discount', $meta, $post_id, $post);
255 255
     
256
-    foreach( $meta as $key => $value ) {
257
-        update_post_meta( $post_id, '_wpi_discount_' . $key, $value );
256
+    foreach ($meta as $key => $value) {
257
+        update_post_meta($post_id, '_wpi_discount_' . $key, $value);
258 258
     }
259 259
     
260
-    do_action( 'wpinv_post_update_discount', $meta, $post_id, $post );
260
+    do_action('wpinv_post_update_discount', $meta, $post_id, $post);
261 261
     
262 262
     return $post_id;
263 263
 }
264 264
 
265
-function wpinv_remove_discount( $discount_id = 0 ) {
266
-    do_action( 'wpinv_pre_delete_discount', $discount_id );
265
+function wpinv_remove_discount($discount_id = 0) {
266
+    do_action('wpinv_pre_delete_discount', $discount_id);
267 267
 
268
-    wp_delete_post( $discount_id, true );
268
+    wp_delete_post($discount_id, true);
269 269
 
270
-    do_action( 'wpinv_post_delete_discount', $discount_id );
270
+    do_action('wpinv_post_delete_discount', $discount_id);
271 271
 }
272 272
 
273
-function wpinv_update_discount_status( $code_id = 0, $new_status = 'publish' ) {
274
-    $discount = wpinv_get_discount(  $code_id );
273
+function wpinv_update_discount_status($code_id = 0, $new_status = 'publish') {
274
+    $discount = wpinv_get_discount($code_id);
275 275
 
276
-    if ( $discount ) {
277
-        do_action( 'wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status );
276
+    if ($discount) {
277
+        do_action('wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status);
278 278
 
279
-        wp_update_post( array( 'ID' => $code_id, 'post_status' => $new_status ) );
279
+        wp_update_post(array('ID' => $code_id, 'post_status' => $new_status));
280 280
 
281
-        do_action( 'wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status );
281
+        do_action('wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status);
282 282
 
283 283
         return true;
284 284
     }
@@ -286,173 +286,173 @@  discard block
 block discarded – undo
286 286
     return false;
287 287
 }
288 288
 
289
-function wpinv_discount_exists( $code_id ) {
290
-    if ( wpinv_get_discount(  $code_id ) ) {
289
+function wpinv_discount_exists($code_id) {
290
+    if (wpinv_get_discount($code_id)) {
291 291
         return true;
292 292
     }
293 293
 
294 294
     return false;
295 295
 }
296 296
 
297
-function wpinv_is_discount_active( $code_id = null ) {
298
-    $discount = wpinv_get_discount(  $code_id );
297
+function wpinv_is_discount_active($code_id = null) {
298
+    $discount = wpinv_get_discount($code_id);
299 299
     $return   = false;
300 300
 
301
-    if ( $discount ) {
302
-        if ( wpinv_is_discount_expired( $code_id ) ) {
303
-            if( defined( 'DOING_AJAX' ) ) {
304
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) );
301
+    if ($discount) {
302
+        if (wpinv_is_discount_expired($code_id)) {
303
+            if (defined('DOING_AJAX')) {
304
+                wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing'));
305 305
             }
306
-        } elseif ( $discount->post_status == 'publish' ) {
306
+        } elseif ($discount->post_status == 'publish') {
307 307
             $return = true;
308 308
         } else {
309
-            if( defined( 'DOING_AJAX' ) ) {
310
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) );
309
+            if (defined('DOING_AJAX')) {
310
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing'));
311 311
             }
312 312
         }
313 313
     }
314 314
 
315
-    return apply_filters( 'wpinv_is_discount_active', $return, $code_id );
315
+    return apply_filters('wpinv_is_discount_active', $return, $code_id);
316 316
 }
317 317
 
318
-function wpinv_get_discount_code( $code_id = null ) {
319
-    $code = get_post_meta( $code_id, '_wpi_discount_code', true );
318
+function wpinv_get_discount_code($code_id = null) {
319
+    $code = get_post_meta($code_id, '_wpi_discount_code', true);
320 320
 
321
-    return apply_filters( 'wpinv_get_discount_code', $code, $code_id );
321
+    return apply_filters('wpinv_get_discount_code', $code, $code_id);
322 322
 }
323 323
 
324
-function wpinv_get_discount_start_date( $code_id = null ) {
325
-    $start_date = get_post_meta( $code_id, '_wpi_discount_start', true );
324
+function wpinv_get_discount_start_date($code_id = null) {
325
+    $start_date = get_post_meta($code_id, '_wpi_discount_start', true);
326 326
 
327
-    return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id );
327
+    return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id);
328 328
 }
329 329
 
330
-function wpinv_get_discount_expiration( $code_id = null ) {
331
-    $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true );
330
+function wpinv_get_discount_expiration($code_id = null) {
331
+    $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true);
332 332
 
333
-    return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id );
333
+    return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id);
334 334
 }
335 335
 
336
-function wpinv_get_discount_max_uses( $code_id = null ) {
337
-    $max_uses = get_post_meta( $code_id, '_wpi_discount_max_uses', true );
336
+function wpinv_get_discount_max_uses($code_id = null) {
337
+    $max_uses = get_post_meta($code_id, '_wpi_discount_max_uses', true);
338 338
 
339
-    return (int) apply_filters( 'wpinv_get_discount_max_uses', $max_uses, $code_id );
339
+    return (int)apply_filters('wpinv_get_discount_max_uses', $max_uses, $code_id);
340 340
 }
341 341
 
342
-function wpinv_get_discount_uses( $code_id = null ) {
343
-    $uses = get_post_meta( $code_id, '_wpi_discount_uses', true );
342
+function wpinv_get_discount_uses($code_id = null) {
343
+    $uses = get_post_meta($code_id, '_wpi_discount_uses', true);
344 344
 
345
-    return (int) apply_filters( 'wpinv_get_discount_uses', $uses, $code_id );
345
+    return (int)apply_filters('wpinv_get_discount_uses', $uses, $code_id);
346 346
 }
347 347
 
348
-function wpinv_get_discount_min_total( $code_id = null ) {
349
-    $min_total = get_post_meta( $code_id, '_wpi_discount_min_total', true );
348
+function wpinv_get_discount_min_total($code_id = null) {
349
+    $min_total = get_post_meta($code_id, '_wpi_discount_min_total', true);
350 350
 
351
-    return (float) apply_filters( 'wpinv_get_discount_min_total', $min_total, $code_id );
351
+    return (float)apply_filters('wpinv_get_discount_min_total', $min_total, $code_id);
352 352
 }
353 353
 
354
-function wpinv_get_discount_max_total( $code_id = null ) {
355
-    $max_total = get_post_meta( $code_id, '_wpi_discount_max_total', true );
354
+function wpinv_get_discount_max_total($code_id = null) {
355
+    $max_total = get_post_meta($code_id, '_wpi_discount_max_total', true);
356 356
 
357
-    return (float) apply_filters( 'wpinv_get_discount_max_total', $max_total, $code_id );
357
+    return (float)apply_filters('wpinv_get_discount_max_total', $max_total, $code_id);
358 358
 }
359 359
 
360
-function wpinv_get_discount_amount( $code_id = null ) {
361
-    $amount = get_post_meta( $code_id, '_wpi_discount_amount', true );
360
+function wpinv_get_discount_amount($code_id = null) {
361
+    $amount = get_post_meta($code_id, '_wpi_discount_amount', true);
362 362
 
363
-    return (float) apply_filters( 'wpinv_get_discount_amount', $amount, $code_id );
363
+    return (float)apply_filters('wpinv_get_discount_amount', $amount, $code_id);
364 364
 }
365 365
 
366
-function wpinv_get_discount_type( $code_id = null, $name = false ) {
367
-    $type = strtolower( get_post_meta( $code_id, '_wpi_discount_type', true ) );
366
+function wpinv_get_discount_type($code_id = null, $name = false) {
367
+    $type = strtolower(get_post_meta($code_id, '_wpi_discount_type', true));
368 368
     
369
-    if ( $name ) {
370
-        $name = wpinv_get_discount_type_name( $type );
369
+    if ($name) {
370
+        $name = wpinv_get_discount_type_name($type);
371 371
         
372
-        return apply_filters( 'wpinv_get_discount_type_name', $name, $code_id );
372
+        return apply_filters('wpinv_get_discount_type_name', $name, $code_id);
373 373
     }
374 374
 
375
-    return apply_filters( 'wpinv_get_discount_type', $type, $code_id );
375
+    return apply_filters('wpinv_get_discount_type', $type, $code_id);
376 376
 }
377 377
 
378
-function wpinv_discount_status( $status ) {
379
-    switch( $status ){
378
+function wpinv_discount_status($status) {
379
+    switch ($status) {
380 380
         case 'expired' :
381
-            $name = __( 'Expired', 'invoicing' );
381
+            $name = __('Expired', 'invoicing');
382 382
             break;
383 383
         case 'publish' :
384 384
         case 'active' :
385
-            $name = __( 'Active', 'invoicing' );
385
+            $name = __('Active', 'invoicing');
386 386
             break;
387 387
         default :
388
-            $name = __( 'Inactive', 'invoicing' );
388
+            $name = __('Inactive', 'invoicing');
389 389
             break;
390 390
     }
391 391
     return $name;
392 392
 }
393 393
 
394
-function wpinv_get_discount_excluded_items( $code_id = null ) {
395
-    $excluded_items = get_post_meta( $code_id, '_wpi_discount_excluded_items', true );
394
+function wpinv_get_discount_excluded_items($code_id = null) {
395
+    $excluded_items = get_post_meta($code_id, '_wpi_discount_excluded_items', true);
396 396
 
397
-    if ( empty( $excluded_items ) || ! is_array( $excluded_items ) ) {
397
+    if (empty($excluded_items) || !is_array($excluded_items)) {
398 398
         $excluded_items = array();
399 399
     }
400 400
 
401
-    return (array) apply_filters( 'wpinv_get_discount_excluded_items', $excluded_items, $code_id );
401
+    return (array)apply_filters('wpinv_get_discount_excluded_items', $excluded_items, $code_id);
402 402
 }
403 403
 
404
-function wpinv_get_discount_item_reqs( $code_id = null ) {
405
-    $item_reqs = get_post_meta( $code_id, '_wpi_discount_items', true );
404
+function wpinv_get_discount_item_reqs($code_id = null) {
405
+    $item_reqs = get_post_meta($code_id, '_wpi_discount_items', true);
406 406
 
407
-    if ( empty( $item_reqs ) || ! is_array( $item_reqs ) ) {
407
+    if (empty($item_reqs) || !is_array($item_reqs)) {
408 408
         $item_reqs = array();
409 409
     }
410 410
 
411
-    return (array) apply_filters( 'wpinv_get_discount_item_reqs', $item_reqs, $code_id );
411
+    return (array)apply_filters('wpinv_get_discount_item_reqs', $item_reqs, $code_id);
412 412
 }
413 413
 
414
-function wpinv_get_discount_item_condition( $code_id = 0 ) {
415
-    return get_post_meta( $code_id, '_wpi_discount_item_condition', true );
414
+function wpinv_get_discount_item_condition($code_id = 0) {
415
+    return get_post_meta($code_id, '_wpi_discount_item_condition', true);
416 416
 }
417 417
 
418
-function wpinv_is_discount_not_global( $code_id = 0 ) {
419
-    return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true );
418
+function wpinv_is_discount_not_global($code_id = 0) {
419
+    return (bool)get_post_meta($code_id, '_wpi_discount_is_not_global', true);
420 420
 }
421 421
 
422
-function wpinv_is_discount_expired( $code_id = null ) {
423
-    $discount = wpinv_get_discount(  $code_id );
422
+function wpinv_is_discount_expired($code_id = null) {
423
+    $discount = wpinv_get_discount($code_id);
424 424
     $return   = false;
425 425
 
426
-    if ( $discount ) {
427
-        $expiration = wpinv_get_discount_expiration( $code_id );
428
-        if ( $expiration ) {
429
-            $expiration = strtotime( $expiration );
430
-            if ( $expiration < current_time( 'timestamp' ) ) {
426
+    if ($discount) {
427
+        $expiration = wpinv_get_discount_expiration($code_id);
428
+        if ($expiration) {
429
+            $expiration = strtotime($expiration);
430
+            if ($expiration < current_time('timestamp')) {
431 431
                 // Discount is expired
432
-                wpinv_update_discount_status( $code_id, 'pending' );
432
+                wpinv_update_discount_status($code_id, 'pending');
433 433
                 $return = true;
434 434
             }
435 435
         }
436 436
     }
437 437
 
438
-    return apply_filters( 'wpinv_is_discount_expired', $return, $code_id );
438
+    return apply_filters('wpinv_is_discount_expired', $return, $code_id);
439 439
 }
440 440
 
441
-function wpinv_is_discount_started( $code_id = null ) {
442
-    $discount = wpinv_get_discount(  $code_id );
441
+function wpinv_is_discount_started($code_id = null) {
442
+    $discount = wpinv_get_discount($code_id);
443 443
     $return   = false;
444 444
 
445
-    if ( $discount ) {
446
-        $start_date = wpinv_get_discount_start_date( $code_id );
445
+    if ($discount) {
446
+        $start_date = wpinv_get_discount_start_date($code_id);
447 447
 
448
-        if ( $start_date ) {
449
-            $start_date = strtotime( $start_date );
448
+        if ($start_date) {
449
+            $start_date = strtotime($start_date);
450 450
 
451
-            if ( $start_date < current_time( 'timestamp' ) ) {
451
+            if ($start_date < current_time('timestamp')) {
452 452
                 // Discount has past the start date
453 453
                 $return = true;
454 454
             } else {
455
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
455
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
456 456
             }
457 457
         } else {
458 458
             // No start date for this discount, so has to be true
@@ -460,159 +460,159 @@  discard block
 block discarded – undo
460 460
         }
461 461
     }
462 462
 
463
-    return apply_filters( 'wpinv_is_discount_started', $return, $code_id );
463
+    return apply_filters('wpinv_is_discount_started', $return, $code_id);
464 464
 }
465 465
 
466
-function wpinv_check_discount_dates( $code_id = null ) {
467
-    $discount = wpinv_get_discount(  $code_id );
466
+function wpinv_check_discount_dates($code_id = null) {
467
+    $discount = wpinv_get_discount($code_id);
468 468
     $return   = false;
469 469
 
470
-    if ( $discount ) {
471
-        $start_date = wpinv_get_discount_start_date( $code_id );
470
+    if ($discount) {
471
+        $start_date = wpinv_get_discount_start_date($code_id);
472 472
 
473
-        if ( $start_date ) {
474
-            $start_date = strtotime( $start_date );
473
+        if ($start_date) {
474
+            $start_date = strtotime($start_date);
475 475
 
476
-            if ( $start_date < current_time( 'timestamp' ) ) {
476
+            if ($start_date < current_time('timestamp')) {
477 477
                 // Discount has past the start date
478 478
                 $return = true;
479 479
             } else {
480
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
480
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
481 481
             }
482 482
         } else {
483 483
             // No start date for this discount, so has to be true
484 484
             $return = true;
485 485
         }
486 486
         
487
-        if ( $return ) {
488
-            $expiration = wpinv_get_discount_expiration( $code_id );
487
+        if ($return) {
488
+            $expiration = wpinv_get_discount_expiration($code_id);
489 489
             
490
-            if ( $expiration ) {
491
-                $expiration = strtotime( $expiration );
492
-                if ( $expiration < current_time( 'timestamp' ) ) {
490
+            if ($expiration) {
491
+                $expiration = strtotime($expiration);
492
+                if ($expiration < current_time('timestamp')) {
493 493
                     // Discount is expired
494
-                    wpinv_update_discount_status( $code_id, 'pending' );
494
+                    wpinv_update_discount_status($code_id, 'pending');
495 495
                     $return = true;
496 496
                 }
497 497
             }
498 498
         }
499 499
     }
500 500
     
501
-    return apply_filters( 'wpinv_check_discount_dates', $return, $code_id );
501
+    return apply_filters('wpinv_check_discount_dates', $return, $code_id);
502 502
 }
503 503
 
504
-function wpinv_is_discount_maxed_out( $code_id = null ) {
505
-    $discount = wpinv_get_discount(  $code_id );
504
+function wpinv_is_discount_maxed_out($code_id = null) {
505
+    $discount = wpinv_get_discount($code_id);
506 506
     $return   = false;
507 507
 
508
-    if ( $discount ) {
509
-        $uses = wpinv_get_discount_uses( $code_id );
508
+    if ($discount) {
509
+        $uses = wpinv_get_discount_uses($code_id);
510 510
         // Large number that will never be reached
511
-        $max_uses = wpinv_get_discount_max_uses( $code_id );
511
+        $max_uses = wpinv_get_discount_max_uses($code_id);
512 512
         // Should never be greater than, but just in case
513
-        if ( $uses >= $max_uses && ! empty( $max_uses ) ) {
513
+        if ($uses >= $max_uses && !empty($max_uses)) {
514 514
             // Discount is maxed out
515
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) );
515
+            wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing'));
516 516
             $return = true;
517 517
         }
518 518
     }
519 519
 
520
-    return apply_filters( 'wpinv_is_discount_maxed_out', $return, $code_id );
520
+    return apply_filters('wpinv_is_discount_maxed_out', $return, $code_id);
521 521
 }
522 522
 
523
-function wpinv_discount_is_min_met( $code_id = null ) {
524
-    $discount = wpinv_get_discount( $code_id );
523
+function wpinv_discount_is_min_met($code_id = null) {
524
+    $discount = wpinv_get_discount($code_id);
525 525
     $return   = false;
526 526
 
527
-    if ( $discount ) {
528
-        $min         = (float)wpinv_get_discount_min_total( $code_id );
529
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
527
+    if ($discount) {
528
+        $min         = (float)wpinv_get_discount_min_total($code_id);
529
+        $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id);
530 530
 
531
-        if ( !$min > 0 || $cart_amount >= $min ) {
531
+        if (!$min > 0 || $cart_amount >= $min) {
532 532
             // Minimum has been met
533 533
             $return = true;
534 534
         } else {
535
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $min ) ) ) );
535
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($min))));
536 536
         }
537 537
     }
538 538
 
539
-    return apply_filters( 'wpinv_is_discount_min_met', $return, $code_id );
539
+    return apply_filters('wpinv_is_discount_min_met', $return, $code_id);
540 540
 }
541 541
 
542
-function wpinv_discount_is_max_met( $code_id = null ) {
543
-    $discount = wpinv_get_discount( $code_id );
542
+function wpinv_discount_is_max_met($code_id = null) {
543
+    $discount = wpinv_get_discount($code_id);
544 544
     $return   = false;
545 545
 
546
-    if ( $discount ) {
547
-        $max         = (float)wpinv_get_discount_max_total( $code_id );
548
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
546
+    if ($discount) {
547
+        $max         = (float)wpinv_get_discount_max_total($code_id);
548
+        $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id);
549 549
 
550
-        if ( !$max > 0 || $cart_amount <= $max ) {
550
+        if (!$max > 0 || $cart_amount <= $max) {
551 551
             // Minimum has been met
552 552
             $return = true;
553 553
         } else {
554
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $max ) ) ) );
554
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($max))));
555 555
         }
556 556
     }
557 557
 
558
-    return apply_filters( 'wpinv_is_discount_max_met', $return, $code_id );
558
+    return apply_filters('wpinv_is_discount_max_met', $return, $code_id);
559 559
 }
560 560
 
561
-function wpinv_discount_is_single_use( $code_id = 0 ) {
562
-    $single_use = get_post_meta( $code_id, '_wpi_discount_is_single_use', true );
563
-    return (bool) apply_filters( 'wpinv_is_discount_single_use', $single_use, $code_id );
561
+function wpinv_discount_is_single_use($code_id = 0) {
562
+    $single_use = get_post_meta($code_id, '_wpi_discount_is_single_use', true);
563
+    return (bool)apply_filters('wpinv_is_discount_single_use', $single_use, $code_id);
564 564
 }
565 565
 
566
-function wpinv_discount_is_recurring( $code_id = 0, $code = false ) {
567
-    if ( $code ) {
568
-        $discount = wpinv_get_discount_by_code( $code_id );
566
+function wpinv_discount_is_recurring($code_id = 0, $code = false) {
567
+    if ($code) {
568
+        $discount = wpinv_get_discount_by_code($code_id);
569 569
         
570
-        if ( !empty( $discount ) ) {
570
+        if (!empty($discount)) {
571 571
             $code_id = $discount->ID;
572 572
         }
573 573
     }
574 574
     
575
-    $recurring = get_post_meta( $code_id, '_wpi_discount_is_recurring', true );
575
+    $recurring = get_post_meta($code_id, '_wpi_discount_is_recurring', true);
576 576
     
577
-    return (bool) apply_filters( 'wpinv_is_discount_recurring', $recurring, $code_id, $code );
577
+    return (bool)apply_filters('wpinv_is_discount_recurring', $recurring, $code_id, $code);
578 578
 }
579 579
 
580
-function wpinv_discount_item_reqs_met( $code_id = null ) {
581
-    $item_reqs    = wpinv_get_discount_item_reqs( $code_id );
582
-    $condition    = wpinv_get_discount_item_condition( $code_id );
583
-    $excluded_ps  = wpinv_get_discount_excluded_items( $code_id );
580
+function wpinv_discount_item_reqs_met($code_id = null) {
581
+    $item_reqs    = wpinv_get_discount_item_reqs($code_id);
582
+    $condition    = wpinv_get_discount_item_condition($code_id);
583
+    $excluded_ps  = wpinv_get_discount_excluded_items($code_id);
584 584
     $cart_items   = wpinv_get_cart_contents();
585
-    $cart_ids     = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null;
585
+    $cart_ids     = $cart_items ? wp_list_pluck($cart_items, 'id') : null;
586 586
     $ret          = false;
587 587
 
588
-    if ( empty( $item_reqs ) && empty( $excluded_ps ) ) {
588
+    if (empty($item_reqs) && empty($excluded_ps)) {
589 589
         $ret = true;
590 590
     }
591 591
 
592 592
     // Normalize our data for item requirements, exclusions and cart data
593 593
     // First absint the items, then sort, and reset the array keys
594
-    $item_reqs = array_map( 'absint', $item_reqs );
595
-    asort( $item_reqs );
596
-    $item_reqs = array_values( $item_reqs );
594
+    $item_reqs = array_map('absint', $item_reqs);
595
+    asort($item_reqs);
596
+    $item_reqs = array_values($item_reqs);
597 597
 
598
-    $excluded_ps  = array_map( 'absint', $excluded_ps );
599
-    asort( $excluded_ps );
600
-    $excluded_ps  = array_values( $excluded_ps );
598
+    $excluded_ps  = array_map('absint', $excluded_ps);
599
+    asort($excluded_ps);
600
+    $excluded_ps  = array_values($excluded_ps);
601 601
 
602
-    $cart_ids     = array_map( 'absint', $cart_ids );
603
-    asort( $cart_ids );
604
-    $cart_ids     = array_values( $cart_ids );
602
+    $cart_ids     = array_map('absint', $cart_ids);
603
+    asort($cart_ids);
604
+    $cart_ids     = array_values($cart_ids);
605 605
 
606 606
     // Ensure we have requirements before proceeding
607
-    if ( !$ret && ! empty( $item_reqs ) ) {
608
-        switch( $condition ) {
607
+    if (!$ret && !empty($item_reqs)) {
608
+        switch ($condition) {
609 609
             case 'all' :
610 610
                 // Default back to true
611 611
                 $ret = true;
612 612
 
613
-                foreach ( $item_reqs as $item_id ) {
614
-                    if ( !wpinv_item_in_cart( $item_id ) ) {
615
-                        wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
613
+                foreach ($item_reqs as $item_id) {
614
+                    if (!wpinv_item_in_cart($item_id)) {
615
+                        wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
616 616
                         $ret = false;
617 617
                         break;
618 618
                     }
@@ -621,15 +621,15 @@  discard block
 block discarded – undo
621 621
                 break;
622 622
 
623 623
             default : // Any
624
-                foreach ( $item_reqs as $item_id ) {
625
-                    if ( wpinv_item_in_cart( $item_id ) ) {
624
+                foreach ($item_reqs as $item_id) {
625
+                    if (wpinv_item_in_cart($item_id)) {
626 626
                         $ret = true;
627 627
                         break;
628 628
                     }
629 629
                 }
630 630
 
631
-                if( ! $ret ) {
632
-                    wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
631
+                if (!$ret) {
632
+                    wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
633 633
                 }
634 634
 
635 635
                 break;
@@ -638,70 +638,70 @@  discard block
 block discarded – undo
638 638
         $ret = true;
639 639
     }
640 640
 
641
-    if( ! empty( $excluded_ps ) ) {
641
+    if (!empty($excluded_ps)) {
642 642
         // Check that there are items other than excluded ones in the cart
643
-        if( $cart_ids == $excluded_ps ) {
644
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) );
643
+        if ($cart_ids == $excluded_ps) {
644
+            wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing'));
645 645
             $ret = false;
646 646
         }
647 647
     }
648 648
 
649
-    return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition );
649
+    return (bool)apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition);
650 650
 }
651 651
 
652
-function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) {
652
+function wpinv_is_discount_used($code = null, $user = '', $code_id = 0) {
653 653
     global $wpi_checkout_id;
654 654
     
655 655
     $return = false;
656 656
 
657
-    if ( empty( $code_id ) ) {
658
-        $code_id = wpinv_get_discount_id_by_code( $code );
657
+    if (empty($code_id)) {
658
+        $code_id = wpinv_get_discount_id_by_code($code);
659 659
         
660
-        if( empty( $code_id ) ) {
660
+        if (empty($code_id)) {
661 661
             return false; // No discount was found
662 662
         }
663 663
     }
664 664
 
665
-    if ( wpinv_discount_is_single_use( $code_id ) ) {
665
+    if (wpinv_discount_is_single_use($code_id)) {
666 666
         $payments = array();
667 667
 
668 668
         $user_id = 0;
669
-        if ( is_int( $user ) ) {
670
-            $user_id = absint( $user );
671
-        } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) {
669
+        if (is_int($user)) {
670
+            $user_id = absint($user);
671
+        } else if (is_email($user) && $user_data = get_user_by('email', $user)) {
672 672
             $user_id = $user_data->ID;
673
-        } else if ( $user_data = get_user_by( 'login', $user ) ) {
673
+        } else if ($user_data = get_user_by('login', $user)) {
674 674
             $user_id = $user_data->ID;
675
-        } else if ( absint( $user ) > 0 ) {
676
-            $user_id = absint( $user );
675
+        } else if (absint($user) > 0) {
676
+            $user_id = absint($user);
677 677
         }
678 678
 
679
-        if ( !empty( $user_id ) ) {
680
-            $query    = array( 'user' => $user_id, 'limit' => false );
681
-            $payments = wpinv_get_invoices( $query ); // Get all payments with matching user id
679
+        if (!empty($user_id)) {
680
+            $query    = array('user' => $user_id, 'limit' => false);
681
+            $payments = wpinv_get_invoices($query); // Get all payments with matching user id
682 682
         }
683 683
 
684
-        if ( $payments ) {
685
-            foreach ( $payments as $payment ) {
684
+        if ($payments) {
685
+            foreach ($payments as $payment) {
686 686
                 // Don't count discount used for current invoice chekcout.
687
-                if ( !empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) {
687
+                if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) {
688 688
                     continue;
689 689
                 }
690 690
                 
691
-                if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) {
691
+                if ($payment->has_status(array('wpi-cancelled', 'wpi-failed'))) {
692 692
                     continue;
693 693
                 }
694 694
 
695
-                $discounts = $payment->get_discounts( true );
696
-                if ( empty( $discounts ) ) {
695
+                $discounts = $payment->get_discounts(true);
696
+                if (empty($discounts)) {
697 697
                     continue;
698 698
                 }
699 699
 
700
-                $discounts = $discounts && !is_array( $discounts ) ? explode( ',', $discounts ) : $discounts;
700
+                $discounts = $discounts && !is_array($discounts) ? explode(',', $discounts) : $discounts;
701 701
 
702
-                if ( !empty( $discounts ) && is_array( $discounts ) ) {
703
-                    if ( in_array( strtolower( $code ), array_map( 'strtolower', $discounts ) ) ) {
704
-                        wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) );
702
+                if (!empty($discounts) && is_array($discounts)) {
703
+                    if (in_array(strtolower($code), array_map('strtolower', $discounts))) {
704
+                        wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing'));
705 705
                         $return = true;
706 706
                         break;
707 707
                     }
@@ -710,61 +710,61 @@  discard block
 block discarded – undo
710 710
         }
711 711
     }
712 712
 
713
-    return apply_filters( 'wpinv_is_discount_used', $return, $code, $user );
713
+    return apply_filters('wpinv_is_discount_used', $return, $code, $user);
714 714
 }
715 715
 
716
-function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) {
716
+function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) {
717 717
     $return      = false;
718
-    $discount_id = wpinv_get_discount_id_by_code( $code );
719
-    $user        = trim( $user );
718
+    $discount_id = wpinv_get_discount_id_by_code($code);
719
+    $user        = trim($user);
720 720
 
721
-    if ( wpinv_get_cart_contents() ) {
722
-        if ( $discount_id ) {
721
+    if (wpinv_get_cart_contents()) {
722
+        if ($discount_id) {
723 723
             if (
724
-                wpinv_is_discount_active( $discount_id ) &&
725
-                wpinv_check_discount_dates( $discount_id ) &&
726
-                !wpinv_is_discount_maxed_out( $discount_id ) &&
727
-                !wpinv_is_discount_used( $code, $user, $discount_id ) &&
728
-                wpinv_discount_is_min_met( $discount_id ) &&
729
-                wpinv_discount_is_max_met( $discount_id ) &&
730
-                wpinv_discount_item_reqs_met( $discount_id )
724
+                wpinv_is_discount_active($discount_id) &&
725
+                wpinv_check_discount_dates($discount_id) &&
726
+                !wpinv_is_discount_maxed_out($discount_id) &&
727
+                !wpinv_is_discount_used($code, $user, $discount_id) &&
728
+                wpinv_discount_is_min_met($discount_id) &&
729
+                wpinv_discount_is_max_met($discount_id) &&
730
+                wpinv_discount_item_reqs_met($discount_id)
731 731
             ) {
732 732
                 $return = true;
733 733
             }
734
-        } elseif( $set_error ) {
735
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) );
734
+        } elseif ($set_error) {
735
+            wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing'));
736 736
         }
737 737
     }
738 738
 
739
-    return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user );
739
+    return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user);
740 740
 }
741 741
 
742
-function wpinv_get_discount_id_by_code( $code ) {
743
-    $discount = wpinv_get_discount_by_code( $code );
744
-    if( $discount ) {
742
+function wpinv_get_discount_id_by_code($code) {
743
+    $discount = wpinv_get_discount_by_code($code);
744
+    if ($discount) {
745 745
         return $discount->ID;
746 746
     }
747 747
     return false;
748 748
 }
749 749
 
750
-function wpinv_get_discounted_amount( $code, $base_price ) {
750
+function wpinv_get_discounted_amount($code, $base_price) {
751 751
     $amount      = $base_price;
752
-    $discount_id = wpinv_get_discount_id_by_code( $code );
752
+    $discount_id = wpinv_get_discount_id_by_code($code);
753 753
 
754
-    if( $discount_id ) {
755
-        $type        = wpinv_get_discount_type( $discount_id );
756
-        $rate        = wpinv_get_discount_amount( $discount_id );
754
+    if ($discount_id) {
755
+        $type        = wpinv_get_discount_type($discount_id);
756
+        $rate        = wpinv_get_discount_amount($discount_id);
757 757
 
758
-        if ( $type == 'flat' ) {
758
+        if ($type == 'flat') {
759 759
             // Set amount
760 760
             $amount = $base_price - $rate;
761
-            if ( $amount < 0 ) {
761
+            if ($amount < 0) {
762 762
                 $amount = 0;
763 763
             }
764 764
 
765 765
         } else {
766 766
             // Percentage discount
767
-            $amount = $base_price - ( $base_price * ( $rate / 100 ) );
767
+            $amount = $base_price - ($base_price * ($rate / 100));
768 768
         }
769 769
 
770 770
     } else {
@@ -773,108 +773,108 @@  discard block
 block discarded – undo
773 773
 
774 774
     }
775 775
 
776
-    return apply_filters( 'wpinv_discounted_amount', $amount );
776
+    return apply_filters('wpinv_discounted_amount', $amount);
777 777
 }
778 778
 
779
-function wpinv_increase_discount_usage( $code ) {
779
+function wpinv_increase_discount_usage($code) {
780 780
 
781
-    $id   = wpinv_get_discount_id_by_code( $code );
782
-    $uses = wpinv_get_discount_uses( $id );
781
+    $id   = wpinv_get_discount_id_by_code($code);
782
+    $uses = wpinv_get_discount_uses($id);
783 783
 
784
-    if ( $uses ) {
784
+    if ($uses) {
785 785
         $uses++;
786 786
     } else {
787 787
         $uses = 1;
788 788
     }
789 789
 
790
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
790
+    update_post_meta($id, '_wpi_discount_uses', $uses);
791 791
 
792
-    do_action( 'wpinv_discount_increase_use_count', $uses, $id, $code );
792
+    do_action('wpinv_discount_increase_use_count', $uses, $id, $code);
793 793
 
794 794
     return $uses;
795 795
 
796 796
 }
797 797
 
798
-function wpinv_decrease_discount_usage( $code ) {
798
+function wpinv_decrease_discount_usage($code) {
799 799
 
800
-    $id   = wpinv_get_discount_id_by_code( $code );
801
-    $uses = wpinv_get_discount_uses( $id );
800
+    $id   = wpinv_get_discount_id_by_code($code);
801
+    $uses = wpinv_get_discount_uses($id);
802 802
 
803
-    if ( $uses ) {
803
+    if ($uses) {
804 804
         $uses--;
805 805
     }
806 806
 
807
-    if ( $uses < 0 ) {
807
+    if ($uses < 0) {
808 808
         $uses = 0;
809 809
     }
810 810
 
811
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
811
+    update_post_meta($id, '_wpi_discount_uses', $uses);
812 812
 
813
-    do_action( 'wpinv_discount_decrease_use_count', $uses, $id, $code );
813
+    do_action('wpinv_discount_decrease_use_count', $uses, $id, $code);
814 814
 
815 815
     return $uses;
816 816
 
817 817
 }
818 818
 
819
-function wpinv_format_discount_rate( $type, $amount ) {
820
-    if ( $type == 'flat' ) {
821
-        return wpinv_price( wpinv_format_amount( $amount ) );
819
+function wpinv_format_discount_rate($type, $amount) {
820
+    if ($type == 'flat') {
821
+        return wpinv_price(wpinv_format_amount($amount));
822 822
     } else {
823 823
         return $amount . '%';
824 824
     }
825 825
 }
826 826
 
827
-function wpinv_set_cart_discount( $code = '' ) {    
828
-    if ( wpinv_multiple_discounts_allowed() ) {
827
+function wpinv_set_cart_discount($code = '') {    
828
+    if (wpinv_multiple_discounts_allowed()) {
829 829
         // Get all active cart discounts
830 830
         $discounts = wpinv_get_cart_discounts();
831 831
     } else {
832 832
         $discounts = false; // Only one discount allowed per purchase, so override any existing
833 833
     }
834 834
 
835
-    if ( $discounts ) {
836
-        $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) );
837
-        if( false !== $key ) {
838
-            unset( $discounts[ $key ] ); // Can't set the same discount more than once
835
+    if ($discounts) {
836
+        $key = array_search(strtolower($code), array_map('strtolower', $discounts));
837
+        if (false !== $key) {
838
+            unset($discounts[$key]); // Can't set the same discount more than once
839 839
         }
840 840
         $discounts[] = $code;
841 841
     } else {
842 842
         $discounts = array();
843 843
         $discounts[] = $code;
844 844
     }
845
-    $discounts = array_values( $discounts );
845
+    $discounts = array_values($discounts);
846 846
     
847 847
     $data = wpinv_get_checkout_session();
848
-    if ( empty( $data ) ) {
848
+    if (empty($data)) {
849 849
         $data = array();
850 850
     } else {
851
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
852
-            $payment_meta['user_info']['discount']  = implode( ',', $discounts );
853
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
851
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
852
+            $payment_meta['user_info']['discount'] = implode(',', $discounts);
853
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
854 854
         }
855 855
     }
856 856
     $data['cart_discounts'] = $discounts;
857 857
     
858
-    wpinv_set_checkout_session( $data );
858
+    wpinv_set_checkout_session($data);
859 859
     
860 860
     return $discounts;
861 861
 }
862 862
 
863
-function wpinv_unset_cart_discount( $code = '' ) {    
863
+function wpinv_unset_cart_discount($code = '') {    
864 864
     $discounts = wpinv_get_cart_discounts();
865 865
 
866
-    if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) {
867
-        $key = array_search( $code, $discounts );
868
-        unset( $discounts[ $key ] );
866
+    if ($code && !empty($discounts) && in_array($code, $discounts)) {
867
+        $key = array_search($code, $discounts);
868
+        unset($discounts[$key]);
869 869
             
870 870
         $data = wpinv_get_checkout_session();
871 871
         $data['cart_discounts'] = $discounts;
872
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
873
-            $payment_meta['user_info']['discount']  = !empty( $discounts ) ? implode( ',', $discounts ) : '';
874
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
872
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
873
+            $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : '';
874
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
875 875
         }
876 876
         
877
-        wpinv_set_checkout_session( $data );
877
+        wpinv_set_checkout_session($data);
878 878
     }
879 879
 
880 880
     return $discounts;
@@ -883,27 +883,27 @@  discard block
 block discarded – undo
883 883
 function wpinv_unset_all_cart_discounts() {
884 884
     $data = wpinv_get_checkout_session();
885 885
     
886
-    if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) {
887
-        unset( $data['cart_discounts'] );
886
+    if (!empty($data) && isset($data['cart_discounts'])) {
887
+        unset($data['cart_discounts']);
888 888
         
889
-         wpinv_set_checkout_session( $data );
889
+         wpinv_set_checkout_session($data);
890 890
          return true;
891 891
     }
892 892
     
893 893
     return false;
894 894
 }
895 895
 
896
-function wpinv_get_cart_discounts( $items = array() ) {
896
+function wpinv_get_cart_discounts($items = array()) {
897 897
     $session = wpinv_get_checkout_session();
898 898
     
899
-    $discounts = !empty( $session['cart_discounts'] ) ? $session['cart_discounts'] : false;
899
+    $discounts = !empty($session['cart_discounts']) ? $session['cart_discounts'] : false;
900 900
     return $discounts;
901 901
 }
902 902
 
903
-function wpinv_cart_has_discounts( $items = array() ) {
903
+function wpinv_cart_has_discounts($items = array()) {
904 904
     $ret = false;
905 905
 
906
-    if ( wpinv_get_cart_discounts( $items ) ) {
906
+    if (wpinv_get_cart_discounts($items)) {
907 907
         $ret = true;
908 908
     }
909 909
     
@@ -914,131 +914,131 @@  discard block
 block discarded – undo
914 914
     }
915 915
     */
916 916
 
917
-    return apply_filters( 'wpinv_cart_has_discounts', $ret );
917
+    return apply_filters('wpinv_cart_has_discounts', $ret);
918 918
 }
919 919
 
920
-function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) {
920
+function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) {
921 921
     $amount = 0.00;
922
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
922
+    $items  = !empty($items) ? $items : wpinv_get_cart_content_details();
923 923
 
924
-    if ( $items ) {
925
-        $discounts = wp_list_pluck( $items, 'discount' );
924
+    if ($items) {
925
+        $discounts = wp_list_pluck($items, 'discount');
926 926
 
927
-        if ( is_array( $discounts ) ) {
928
-            $discounts = array_map( 'floatval', $discounts );
929
-            $amount    = array_sum( $discounts );
927
+        if (is_array($discounts)) {
928
+            $discounts = array_map('floatval', $discounts);
929
+            $amount    = array_sum($discounts);
930 930
         }
931 931
     }
932 932
 
933
-    return apply_filters( 'wpinv_get_cart_discounted_amount', $amount );
933
+    return apply_filters('wpinv_get_cart_discounted_amount', $amount);
934 934
 }
935 935
 
936
-function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) {
937
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
936
+function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) {
937
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
938 938
     
939
-    if ( empty( $discount ) || empty( $items ) ) {
939
+    if (empty($discount) || empty($items)) {
940 940
         return 0;
941 941
     }
942 942
 
943 943
     $amount = 0;
944 944
     
945
-    foreach ( $items as $item ) {
946
-        $amount += wpinv_get_cart_item_discount_amount( $item, $discount );
945
+    foreach ($items as $item) {
946
+        $amount += wpinv_get_cart_item_discount_amount($item, $discount);
947 947
     }
948 948
     
949
-    $amount = wpinv_round_amount( $amount );
949
+    $amount = wpinv_round_amount($amount);
950 950
 
951 951
     return $amount;
952 952
 }
953 953
 
954
-function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) {
954
+function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) {
955 955
     global $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
956 956
     
957 957
     $amount = 0;
958 958
 
959
-    if ( empty( $item ) || empty( $item['id'] ) ) {
959
+    if (empty($item) || empty($item['id'])) {
960 960
         return $amount;
961 961
     }
962 962
 
963
-    if ( empty( $item['quantity'] ) ) {
963
+    if (empty($item['quantity'])) {
964 964
         return $amount;
965 965
     }
966 966
 
967
-    if ( empty( $item['options'] ) ) {
967
+    if (empty($item['options'])) {
968 968
         $item['options'] = array();
969 969
     }
970 970
 
971
-    $price            = wpinv_get_cart_item_price( $item['id'], $item, $item['options'] );
971
+    $price            = wpinv_get_cart_item_price($item['id'], $item, $item['options']);
972 972
     $discounted_price = $price;
973 973
 
974 974
     $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount;
975
-    if ( empty( $discounts ) ) {
975
+    if (empty($discounts)) {
976 976
         return $amount;
977 977
     }
978 978
 
979
-    if ( $discounts ) {
980
-        if ( is_array( $discounts ) ) {
981
-            $discounts = array_values( $discounts );
979
+    if ($discounts) {
980
+        if (is_array($discounts)) {
981
+            $discounts = array_values($discounts);
982 982
         } else {
983
-            $discounts = explode( ',', $discounts );
983
+            $discounts = explode(',', $discounts);
984 984
         }
985 985
     }
986 986
 
987
-    if( $discounts ) {
988
-        foreach ( $discounts as $discount ) {
989
-            $code_id = wpinv_get_discount_id_by_code( $discount );
987
+    if ($discounts) {
988
+        foreach ($discounts as $discount) {
989
+            $code_id = wpinv_get_discount_id_by_code($discount);
990 990
 
991 991
             // Check discount exists
992
-            if( ! $code_id ) {
992
+            if (!$code_id) {
993 993
                 continue;
994 994
             }
995 995
 
996
-            $reqs           = wpinv_get_discount_item_reqs( $code_id );
997
-            $excluded_items = wpinv_get_discount_excluded_items( $code_id );
996
+            $reqs           = wpinv_get_discount_item_reqs($code_id);
997
+            $excluded_items = wpinv_get_discount_excluded_items($code_id);
998 998
 
999 999
             // Make sure requirements are set and that this discount shouldn't apply to the whole cart
1000
-            if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) {
1001
-                foreach ( $reqs as $item_id ) {
1002
-                    if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) {
1003
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1000
+            if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) {
1001
+                foreach ($reqs as $item_id) {
1002
+                    if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) {
1003
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1004 1004
                     }
1005 1005
                 }
1006 1006
             } else {
1007 1007
                 // This is a global cart discount
1008
-                if ( !in_array( $item['id'], $excluded_items ) ) {
1009
-                    if ( 'flat' === wpinv_get_discount_type( $code_id ) ) {
1008
+                if (!in_array($item['id'], $excluded_items)) {
1009
+                    if ('flat' === wpinv_get_discount_type($code_id)) {
1010 1010
                         $items_subtotal    = 0.00;
1011 1011
                         $cart_items        = wpinv_get_cart_contents();
1012 1012
                         
1013
-                        foreach ( $cart_items as $cart_item ) {
1014
-                            if ( ! in_array( $cart_item['id'], $excluded_items ) ) {
1015
-                                $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array();
1016
-                                $item_price      = wpinv_get_cart_item_price( $cart_item['id'], $cart_item, $options );
1013
+                        foreach ($cart_items as $cart_item) {
1014
+                            if (!in_array($cart_item['id'], $excluded_items)) {
1015
+                                $options = !empty($cart_item['options']) ? $cart_item['options'] : array();
1016
+                                $item_price      = wpinv_get_cart_item_price($cart_item['id'], $cart_item, $options);
1017 1017
                                 $items_subtotal += $item_price * $cart_item['quantity'];
1018 1018
                             }
1019 1019
                         }
1020 1020
 
1021
-                        $subtotal_percent  = ( ( $price * $item['quantity'] ) / $items_subtotal );
1022
-                        $code_amount       = wpinv_get_discount_amount( $code_id );
1021
+                        $subtotal_percent  = (($price * $item['quantity']) / $items_subtotal);
1022
+                        $code_amount       = wpinv_get_discount_amount($code_id);
1023 1023
                         $discounted_amount = $code_amount * $subtotal_percent;
1024 1024
                         $discounted_price -= $discounted_amount;
1025 1025
 
1026
-                        $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() );
1026
+                        $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter());
1027 1027
 
1028
-                        if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) {
1028
+                        if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) {
1029 1029
                             $adjustment = $code_amount - $wpinv_flat_discount_total;
1030 1030
                             $discounted_price -= $adjustment;
1031 1031
                         }
1032 1032
                     } else {
1033
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1033
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1034 1034
                     }
1035 1035
                 }
1036 1036
             }
1037 1037
         }
1038 1038
 
1039
-        $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) );
1039
+        $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price));
1040 1040
 
1041
-        if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) {
1041
+        if ('flat' !== wpinv_get_discount_type($code_id)) {
1042 1042
             $amount = $amount * $item['quantity'];
1043 1043
         }
1044 1044
     }
@@ -1046,59 +1046,59 @@  discard block
 block discarded – undo
1046 1046
     return $amount;
1047 1047
 }
1048 1048
 
1049
-function wpinv_cart_discounts_html( $items = array() ) {
1050
-    echo wpinv_get_cart_discounts_html( $items );
1049
+function wpinv_cart_discounts_html($items = array()) {
1050
+    echo wpinv_get_cart_discounts_html($items);
1051 1051
 }
1052 1052
 
1053
-function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) {
1053
+function wpinv_get_cart_discounts_html($items = array(), $discounts = false) {
1054 1054
     global $wpi_cart_columns;
1055 1055
     
1056
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
1056
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
1057 1057
     
1058
-    if ( !$discounts ) {
1059
-        $discounts = wpinv_get_cart_discounts( $items );
1058
+    if (!$discounts) {
1059
+        $discounts = wpinv_get_cart_discounts($items);
1060 1060
     }
1061 1061
 
1062
-    if ( !$discounts ) {
1062
+    if (!$discounts) {
1063 1063
         return;
1064 1064
     }
1065 1065
     
1066
-    $discounts = is_array( $discounts ) ? $discounts : array( $discounts );
1066
+    $discounts = is_array($discounts) ? $discounts : array($discounts);
1067 1067
     
1068 1068
     $html = '';
1069 1069
 
1070
-    foreach ( $discounts as $discount ) {
1071
-        $discount_id    = wpinv_get_discount_id_by_code( $discount );
1072
-        $discount_value = wpinv_get_discount_amount( $discount_id );
1073
-        $rate           = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value );
1074
-        $amount         = wpinv_get_cart_items_discount_amount( $items, $discount );
1075
-        $remove_btn     = '<a title="' . esc_attr__( 'Remove discount', 'invoicing' ) . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> ';
1070
+    foreach ($discounts as $discount) {
1071
+        $discount_id    = wpinv_get_discount_id_by_code($discount);
1072
+        $discount_value = wpinv_get_discount_amount($discount_id);
1073
+        $rate           = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value);
1074
+        $amount         = wpinv_get_cart_items_discount_amount($items, $discount);
1075
+        $remove_btn     = '<a title="' . esc_attr__('Remove discount', 'invoicing') . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> ';
1076 1076
         
1077 1077
         $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">';
1078 1078
         ob_start();
1079
-        do_action( 'wpinv_checkout_table_discount_first', $items );
1079
+        do_action('wpinv_checkout_table_discount_first', $items);
1080 1080
         $html .= ob_get_clean();
1081
-        $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label( $discount, $rate, false ) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">&ndash;' . wpinv_price( wpinv_format_amount( $amount ) ) . '</span></td>';
1081
+        $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label($discount, $rate, false) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">&ndash;' . wpinv_price(wpinv_format_amount($amount)) . '</span></td>';
1082 1082
         ob_start();
1083
-        do_action( 'wpinv_checkout_table_discount_last', $items );
1083
+        do_action('wpinv_checkout_table_discount_last', $items);
1084 1084
         $html .= ob_get_clean();
1085 1085
         $html .= '</tr>';
1086 1086
     }
1087 1087
 
1088
-    return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate );
1088
+    return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate);
1089 1089
 }
1090 1090
 
1091
-function wpinv_display_cart_discount( $formatted = false, $echo = false ) {
1091
+function wpinv_display_cart_discount($formatted = false, $echo = false) {
1092 1092
     $discounts = wpinv_get_cart_discounts();
1093 1093
 
1094
-    if ( empty( $discounts ) ) {
1094
+    if (empty($discounts)) {
1095 1095
         return false;
1096 1096
     }
1097 1097
 
1098
-    $discount_id  = wpinv_get_discount_id_by_code( $discounts[0] );
1099
-    $amount       = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) );
1098
+    $discount_id  = wpinv_get_discount_id_by_code($discounts[0]);
1099
+    $amount       = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id));
1100 1100
 
1101
-    if ( $echo ) {
1101
+    if ($echo) {
1102 1102
         echo $amount;
1103 1103
     }
1104 1104
 
@@ -1106,135 +1106,135 @@  discard block
 block discarded – undo
1106 1106
 }
1107 1107
 
1108 1108
 function wpinv_remove_cart_discount() {
1109
-    if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) {
1109
+    if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) {
1110 1110
         return;
1111 1111
     }
1112 1112
 
1113
-    do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) );
1113
+    do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id']));
1114 1114
 
1115
-    wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) );
1115
+    wpinv_unset_cart_discount(urldecode($_GET['discount_code']));
1116 1116
 
1117
-    do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) );
1117
+    do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id']));
1118 1118
 
1119
-    wp_redirect( wpinv_get_checkout_uri() ); wpinv_die();
1119
+    wp_redirect(wpinv_get_checkout_uri()); wpinv_die();
1120 1120
 }
1121
-add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' );
1121
+add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount');
1122 1122
 
1123
-function wpinv_maybe_remove_cart_discount( $cart_key = 0 ) {
1123
+function wpinv_maybe_remove_cart_discount($cart_key = 0) {
1124 1124
     $discounts = wpinv_get_cart_discounts();
1125 1125
 
1126
-    if ( !$discounts ) {
1126
+    if (!$discounts) {
1127 1127
         return;
1128 1128
     }
1129 1129
 
1130
-    foreach ( $discounts as $discount ) {
1131
-        if ( !wpinv_is_discount_valid( $discount ) ) {
1132
-            wpinv_unset_cart_discount( $discount );
1130
+    foreach ($discounts as $discount) {
1131
+        if (!wpinv_is_discount_valid($discount)) {
1132
+            wpinv_unset_cart_discount($discount);
1133 1133
         }
1134 1134
     }
1135 1135
 }
1136
-add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' );
1136
+add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount');
1137 1137
 
1138 1138
 function wpinv_multiple_discounts_allowed() {
1139
-    $ret = wpinv_get_option( 'allow_multiple_discounts', false );
1140
-    return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret );
1139
+    $ret = wpinv_get_option('allow_multiple_discounts', false);
1140
+    return (bool)apply_filters('wpinv_multiple_discounts_allowed', $ret);
1141 1141
 }
1142 1142
 
1143 1143
 function wpinv_listen_for_cart_discount() {
1144 1144
     global $wpi_session;
1145 1145
     
1146
-    if ( empty( $_REQUEST['discount'] ) || is_array( $_REQUEST['discount'] ) ) {
1146
+    if (empty($_REQUEST['discount']) || is_array($_REQUEST['discount'])) {
1147 1147
         return;
1148 1148
     }
1149 1149
 
1150
-    $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount'] );
1150
+    $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount']);
1151 1151
 
1152
-    $wpi_session->set( 'preset_discount', $code );
1152
+    $wpi_session->set('preset_discount', $code);
1153 1153
 }
1154 1154
 //add_action( 'init', 'wpinv_listen_for_cart_discount', 0 );
1155 1155
 
1156 1156
 function wpinv_apply_preset_discount() {
1157 1157
     global $wpi_session;
1158 1158
     
1159
-    $code = $wpi_session->get( 'preset_discount' );
1159
+    $code = $wpi_session->get('preset_discount');
1160 1160
 
1161
-    if ( !$code ) {
1161
+    if (!$code) {
1162 1162
         return;
1163 1163
     }
1164 1164
 
1165
-    if ( !wpinv_is_discount_valid( $code, '', false ) ) {
1165
+    if (!wpinv_is_discount_valid($code, '', false)) {
1166 1166
         return;
1167 1167
     }
1168 1168
     
1169
-    $code = apply_filters( 'wpinv_apply_preset_discount', $code );
1169
+    $code = apply_filters('wpinv_apply_preset_discount', $code);
1170 1170
 
1171
-    wpinv_set_cart_discount( $code );
1171
+    wpinv_set_cart_discount($code);
1172 1172
 
1173
-    $wpi_session->set( 'preset_discount', null );
1173
+    $wpi_session->set('preset_discount', null);
1174 1174
 }
1175 1175
 //add_action( 'init', 'wpinv_apply_preset_discount', 999 );
1176 1176
 
1177
-function wpinv_get_discount_label( $code, $echo = true ) {
1178
-    $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) );
1179
-    $label = apply_filters( 'wpinv_get_discount_label', $label, $code );
1177
+function wpinv_get_discount_label($code, $echo = true) {
1178
+    $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : ''));
1179
+    $label = apply_filters('wpinv_get_discount_label', $label, $code);
1180 1180
 
1181
-    if ( $echo ) {
1181
+    if ($echo) {
1182 1182
         echo $label;
1183 1183
     } else {
1184 1184
         return $label;
1185 1185
     }
1186 1186
 }
1187 1187
 
1188
-function wpinv_cart_discount_label( $code, $rate, $echo = true ) {
1189
-    $label = wp_sprintf( __( '%1$s Discount: %2$s', 'invoicing' ), $rate, $code );
1190
-    $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate );
1188
+function wpinv_cart_discount_label($code, $rate, $echo = true) {
1189
+    $label = wp_sprintf(__('%1$s Discount: %2$s', 'invoicing'), $rate, $code);
1190
+    $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate);
1191 1191
 
1192
-    if ( $echo ) {
1192
+    if ($echo) {
1193 1193
         echo $label;
1194 1194
     } else {
1195 1195
         return $label;
1196 1196
     }
1197 1197
 }
1198 1198
 
1199
-function wpinv_check_delete_discount( $check, $post, $force_delete ) {
1200
-    if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) {
1199
+function wpinv_check_delete_discount($check, $post, $force_delete) {
1200
+    if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) {
1201 1201
         return true;
1202 1202
     }
1203 1203
     
1204 1204
     return $check;
1205 1205
 }
1206
-add_filter( 'pre_delete_post', 'wpinv_check_delete_discount', 10, 3 );
1206
+add_filter('pre_delete_post', 'wpinv_check_delete_discount', 10, 3);
1207 1207
 
1208 1208
 function wpinv_checkout_form_validate_discounts() {
1209 1209
     global $wpi_checkout_id;
1210 1210
     
1211 1211
     $discounts = wpinv_get_cart_discounts();
1212 1212
     
1213
-    if ( !empty( $discounts ) ) {
1213
+    if (!empty($discounts)) {
1214 1214
         $invalid = false;
1215 1215
         
1216
-        foreach ( $discounts as $key => $code ) {
1217
-            if ( !wpinv_is_discount_valid( $code, (int)wpinv_get_user_id( $wpi_checkout_id ) ) ) {
1216
+        foreach ($discounts as $key => $code) {
1217
+            if (!wpinv_is_discount_valid($code, (int)wpinv_get_user_id($wpi_checkout_id))) {
1218 1218
                 $invalid = true;
1219 1219
                 
1220
-                wpinv_unset_cart_discount( $code );
1220
+                wpinv_unset_cart_discount($code);
1221 1221
             }
1222 1222
         }
1223 1223
         
1224
-        if ( $invalid ) {
1224
+        if ($invalid) {
1225 1225
             $errors = wpinv_get_errors();
1226
-            $error  = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : '';
1227
-            $error  .= __( 'The discount has been removed from cart.', 'invoicing' );
1228
-            wpinv_set_error( 'wpinv-discount-error', $error );
1226
+            $error  = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : '';
1227
+            $error .= __('The discount has been removed from cart.', 'invoicing');
1228
+            wpinv_set_error('wpinv-discount-error', $error);
1229 1229
             
1230
-            wpinv_recalculate_tax( true );
1230
+            wpinv_recalculate_tax(true);
1231 1231
         }
1232 1232
     }
1233 1233
 }
1234
-add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 );
1234
+add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10);
1235 1235
 
1236 1236
 function wpinv_discount_amount() {
1237 1237
     $output = 0.00;
1238 1238
     
1239
-    return apply_filters( 'wpinv_discount_amount', $output );
1239
+    return apply_filters('wpinv_discount_amount', $output);
1240 1240
 }
1241 1241
\ No newline at end of file
Please login to merge, or discard this patch.
templates/wpinv-checkout-cart.php 2 patches
Braces   +8 added lines, -2 removed lines patch added patch discarded remove patch
@@ -103,7 +103,10 @@  discard block
 block discarded – undo
103 103
         <?php } ?>
104 104
 
105 105
         <?php if ( $use_taxes && !wpinv_prices_include_tax() ) { ?>
106
-            <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row"<?php if ( !wpinv_is_cart_taxed() ) echo ' style="display:none;"'; ?>>
106
+            <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row"<?php if ( !wpinv_is_cart_taxed() ) {
107
+    echo ' style="display:none;"';
108
+}
109
+?>>
107 110
                 <?php do_action( 'wpinv_checkout_table_subtotal_first', $cart_items ); ?>
108 111
                 <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_subtotal_label text-right">
109 112
                     <strong><?php _e( 'Sub-Total', 'invoicing' ); ?>:</strong>
@@ -118,7 +121,10 @@  discard block
 block discarded – undo
118 121
         <?php $wpi_cart_columns = $cart_columns - 1; wpinv_cart_discounts_html( $cart_items ); ?>
119 122
 
120 123
         <?php if ( $use_taxes ) { ?>
121
-            <tr class="wpinv_cart_footer_row wpinv_cart_tax_row"<?php if( !wpinv_is_cart_taxed() ) echo ' style="display:none;"'; ?>>
124
+            <tr class="wpinv_cart_footer_row wpinv_cart_tax_row"<?php if( !wpinv_is_cart_taxed() ) {
125
+    echo ' style="display:none;"';
126
+}
127
+?>>
122 128
                 <?php do_action( 'wpinv_checkout_table_tax_first' ); ?>
123 129
                 <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_tax_label text-right">
124 130
                     <strong><?php echo $tax_label; ?>:</strong>
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -5,138 +5,138 @@
 block discarded – undo
5 5
 
6 6
 global $wpinv_euvat, $post, $ajax_cart_details, $wpi_cart_columns, $wpi_session;
7 7
 $invoice            = wpinv_get_invoice_cart();
8
-$cart_items         = !empty( $ajax_cart_details ) ? $ajax_cart_details : wpinv_get_cart_content_details();
8
+$cart_items         = !empty($ajax_cart_details) ? $ajax_cart_details : wpinv_get_cart_content_details();
9 9
 $quantities_enabled = wpinv_item_quantities_enabled();
10 10
 $use_taxes          = wpinv_use_taxes();
11 11
 $tax_label          = $wpinv_euvat->tax_label();
12
-$tax_title          = $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
12
+$tax_title          = $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
13 13
 ?>
14 14
 <table id="wpinv_checkout_cart" class="table table-bordered table-hover">
15 15
     <thead>
16 16
         <tr class="wpinv_cart_header_row">
17
-            <?php do_action( 'wpinv_checkout_table_header_first' ); ?>
18
-            <th class="wpinv_cart_item_name text-left"><?php _e( 'Item Name', 'invoicing' ); ?></th>
19
-            <th class="wpinv_cart_item_price text-right"><?php _e( 'Item Price', 'invoicing' ); ?></th>
20
-            <?php if ( $quantities_enabled ) { ?>
21
-            <th class="wpinv_cart_item_qty text-right"><?php _e( 'Qty', 'invoicing' ); ?></th>
17
+            <?php do_action('wpinv_checkout_table_header_first'); ?>
18
+            <th class="wpinv_cart_item_name text-left"><?php _e('Item Name', 'invoicing'); ?></th>
19
+            <th class="wpinv_cart_item_price text-right"><?php _e('Item Price', 'invoicing'); ?></th>
20
+            <?php if ($quantities_enabled) { ?>
21
+            <th class="wpinv_cart_item_qty text-right"><?php _e('Qty', 'invoicing'); ?></th>
22 22
             <?php } ?>
23
-            <?php if ( $use_taxes ) { ?>
23
+            <?php if ($use_taxes) { ?>
24 24
             <th class="wpinv_cart_item_tax text-right"><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></th>
25 25
             <?php } ?>
26
-            <th class="wpinv_cart_item_subtotal text-right"><?php echo __( 'Item Total', 'invoicing' ) . ' <span class="normal small">' . $tax_title . '<span>'; ?></th>
27
-            <?php do_action( 'wpinv_checkout_table_header_last' ); ?>
26
+            <th class="wpinv_cart_item_subtotal text-right"><?php echo __('Item Total', 'invoicing') . ' <span class="normal small">' . $tax_title . '<span>'; ?></th>
27
+            <?php do_action('wpinv_checkout_table_header_last'); ?>
28 28
         </tr>
29 29
     </thead>
30 30
     <tbody>
31 31
         <?php
32
-            do_action( 'wpinv_cart_items_before' );
32
+            do_action('wpinv_cart_items_before');
33 33
             
34
-            if ( $cart_items ) {
35
-                foreach ( $cart_items as $key => $item ) {
36
-                    $wpi_item = !empty( $item['id'] ) ? new WPInv_Item( $item['id'] ) : NULL;
34
+            if ($cart_items) {
35
+                foreach ($cart_items as $key => $item) {
36
+                    $wpi_item = !empty($item['id']) ? new WPInv_Item($item['id']) : NULL;
37 37
                 ?>
38
-                <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr( $key ) . '_' . esc_attr( $item['id'] ); ?>" data-item-id="<?php echo esc_attr( $item['id'] ); ?>">
39
-                    <?php do_action( 'wpinv_checkout_table_body_first', $item ); ?>
38
+                <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr($key) . '_' . esc_attr($item['id']); ?>" data-item-id="<?php echo esc_attr($item['id']); ?>">
39
+                    <?php do_action('wpinv_checkout_table_body_first', $item); ?>
40 40
                     <td class="wpinv_cart_item_name text-left">
41 41
                         <?php
42
-                            if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $item['id'] ) ) {
42
+                            if (current_theme_supports('post-thumbnails') && has_post_thumbnail($item['id'])) {
43 43
                                 echo '<div class="wpinv_cart_item_image">';
44
-                                    echo get_the_post_thumbnail( $item['id'], apply_filters( 'wpinv_checkout_image_size', array( 25,25 ) ) );
44
+                                    echo get_the_post_thumbnail($item['id'], apply_filters('wpinv_checkout_image_size', array(25, 25)));
45 45
                                 echo '</div>';
46 46
                             }
47
-                            $item_title = esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $wpi_item );
47
+                            $item_title = esc_html(wpinv_get_cart_item_name($item)) . wpinv_get_item_suffix($wpi_item);
48 48
                             echo '<span class="wpinv_checkout_cart_item_title">' . $item_title . '</span>';
49
-                            $summary = apply_filters( 'wpinv_checkout_cart_line_item_summary', '', $item, $wpi_item, $invoice );
50
-                            if ( !empty( $summary ) ) {
49
+                            $summary = apply_filters('wpinv_checkout_cart_line_item_summary', '', $item, $wpi_item, $invoice);
50
+                            if (!empty($summary)) {
51 51
                                 echo $summary;
52 52
                             }
53 53
                         ?>
54 54
                     </td>
55 55
                     <td class="wpinv_cart_item_price text-right">
56 56
                         <?php 
57
-                        echo wpinv_cart_item_price( $item );
58
-                        do_action( 'wpinv_checkout_cart_item_price_after', $item, $key );
57
+                        echo wpinv_cart_item_price($item);
58
+                        do_action('wpinv_checkout_cart_item_price_after', $item, $key);
59 59
                         ?>
60 60
                     </td>
61
-                    <?php if ( $quantities_enabled ) { ?>
61
+                    <?php if ($quantities_enabled) { ?>
62 62
                     <td class="wpinv_cart_item_qty text-right">
63 63
                         <?php
64
-                        echo wpinv_get_cart_item_quantity( $item );
65
-                        do_action( 'wpinv_cart_item_quantitiy', $item, $key );
64
+                        echo wpinv_get_cart_item_quantity($item);
65
+                        do_action('wpinv_cart_item_quantitiy', $item, $key);
66 66
                         ?>
67 67
                     </td>
68 68
                     <?php } ?>
69
-                    <?php if ( $use_taxes ) { ?>
69
+                    <?php if ($use_taxes) { ?>
70 70
                     <td class="wpinv_cart_item_tax text-right">
71 71
                         <?php
72
-                        echo wpinv_cart_item_tax( $item );
72
+                        echo wpinv_cart_item_tax($item);
73 73
                         //echo wpinv_get_cart_item_tax( $wpi_item->ID, $subtotal = '', $options = array() );
74
-                        do_action( 'wpinv_cart_item_tax', $item, $key );
74
+                        do_action('wpinv_cart_item_tax', $item, $key);
75 75
                         ?>
76 76
                     </td>
77 77
                     <?php } ?>
78 78
                     <td class="wpinv_cart_item_subtotal text-right">
79 79
                         <?php
80
-                        echo wpinv_cart_item_subtotal( $item );
81
-                        do_action( 'wpinv_cart_item_subtotal', $item, $key );
80
+                        echo wpinv_cart_item_subtotal($item);
81
+                        do_action('wpinv_cart_item_subtotal', $item, $key);
82 82
                         ?>
83 83
                     </td>
84
-                    <?php do_action( 'wpinv_checkout_table_body_last', $item, $key ); ?>
84
+                    <?php do_action('wpinv_checkout_table_body_last', $item, $key); ?>
85 85
                 </tr>
86 86
             <?php } ?>
87 87
         <?php } ?>
88
-        <?php do_action( 'wpinv_cart_items_middle' ); ?>
89
-        <?php do_action( 'wpinv_cart_items_after' ); ?>
88
+        <?php do_action('wpinv_cart_items_middle'); ?>
89
+        <?php do_action('wpinv_cart_items_after'); ?>
90 90
     </tbody>
91 91
     <tfoot>
92 92
         <?php $cart_columns = wpinv_checkout_cart_columns(); ?>
93
-        <?php if ( has_action( 'wpinv_cart_footer_buttons' ) ) { ?>
93
+        <?php if (has_action('wpinv_cart_footer_buttons')) { ?>
94 94
             <tr class="wpinv_cart_footer_row">
95
-                <?php do_action( 'wpinv_checkout_table_buttons_first', $cart_items ); ?>
96
-                <td colspan="<?php echo ( $cart_columns ); ?>">
97
-                    <?php do_action( 'wpinv_cart_footer_buttons' ); ?>
95
+                <?php do_action('wpinv_checkout_table_buttons_first', $cart_items); ?>
96
+                <td colspan="<?php echo ($cart_columns); ?>">
97
+                    <?php do_action('wpinv_cart_footer_buttons'); ?>
98 98
                 </td>
99
-                <?php do_action( 'wpinv_checkout_table_buttons_first', $cart_items ); ?>
99
+                <?php do_action('wpinv_checkout_table_buttons_first', $cart_items); ?>
100 100
             </tr>
101 101
         <?php } ?>
102 102
 
103
-        <?php if ( $use_taxes && !wpinv_prices_include_tax() ) { ?>
104
-            <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row"<?php if ( !wpinv_is_cart_taxed() ) echo ' style="display:none;"'; ?>>
105
-                <?php do_action( 'wpinv_checkout_table_subtotal_first', $cart_items ); ?>
106
-                <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_subtotal_label text-right">
107
-                    <strong><?php _e( 'Sub-Total', 'invoicing' ); ?>:</strong>
103
+        <?php if ($use_taxes && !wpinv_prices_include_tax()) { ?>
104
+            <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row"<?php if (!wpinv_is_cart_taxed()) echo ' style="display:none;"'; ?>>
105
+                <?php do_action('wpinv_checkout_table_subtotal_first', $cart_items); ?>
106
+                <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_subtotal_label text-right">
107
+                    <strong><?php _e('Sub-Total', 'invoicing'); ?>:</strong>
108 108
                 </td>
109 109
                 <td class="wpinv_cart_subtotal text-right">
110
-                    <span class="wpinv_cart_subtotal_amount bold"><?php echo wpinv_cart_subtotal( $cart_items ); ?></span>
110
+                    <span class="wpinv_cart_subtotal_amount bold"><?php echo wpinv_cart_subtotal($cart_items); ?></span>
111 111
                 </td>
112
-                <?php do_action( 'wpinv_checkout_table_subtotal_last', $cart_items ); ?>
112
+                <?php do_action('wpinv_checkout_table_subtotal_last', $cart_items); ?>
113 113
             </tr>
114 114
         <?php } ?>
115 115
         
116
-        <?php $wpi_cart_columns = $cart_columns - 1; wpinv_cart_discounts_html( $cart_items ); ?>
116
+        <?php $wpi_cart_columns = $cart_columns - 1; wpinv_cart_discounts_html($cart_items); ?>
117 117
 
118
-        <?php if ( $use_taxes ) { ?>
119
-            <tr class="wpinv_cart_footer_row wpinv_cart_tax_row"<?php if( !wpinv_is_cart_taxed() ) echo ' style="display:none;"'; ?>>
120
-                <?php do_action( 'wpinv_checkout_table_tax_first' ); ?>
121
-                <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_tax_label text-right">
118
+        <?php if ($use_taxes) { ?>
119
+            <tr class="wpinv_cart_footer_row wpinv_cart_tax_row"<?php if (!wpinv_is_cart_taxed()) echo ' style="display:none;"'; ?>>
120
+                <?php do_action('wpinv_checkout_table_tax_first'); ?>
121
+                <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_tax_label text-right">
122 122
                     <strong><?php echo $tax_label; ?>:</strong>
123 123
                 </td>
124 124
                 <td class="wpinv_cart_tax text-right">
125
-                    <span class="wpinv_cart_tax_amount" data-tax="<?php echo wpinv_get_cart_tax( $cart_items ); ?>"><?php echo esc_html( wpinv_cart_tax( $cart_items ) ); ?></span>
125
+                    <span class="wpinv_cart_tax_amount" data-tax="<?php echo wpinv_get_cart_tax($cart_items); ?>"><?php echo esc_html(wpinv_cart_tax($cart_items)); ?></span>
126 126
                 </td>
127
-                <?php do_action( 'wpinv_checkout_table_tax_last' ); ?>
127
+                <?php do_action('wpinv_checkout_table_tax_last'); ?>
128 128
             </tr>
129 129
         <?php } ?>
130 130
 
131 131
         <tr class="wpinv_cart_footer_row wpinv_cart_total_row">
132
-            <?php do_action( 'wpinv_checkout_table_footer_first' ); ?>
133
-            <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_total_label text-right">
134
-                <?php echo apply_filters( 'wpinv_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?>
132
+            <?php do_action('wpinv_checkout_table_footer_first'); ?>
133
+            <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_total_label text-right">
134
+                <?php echo apply_filters('wpinv_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?>
135 135
             </td>
136 136
             <td class="wpinv_cart_total text-right">
137
-                <span class="wpinv_cart_amount bold" data-subtotal="<?php echo wpinv_get_cart_total( $cart_items ); ?>" data-total="<?php echo wpinv_get_cart_total( NULL, NULL, $invoice ); ?>"><?php wpinv_cart_total( $cart_items, true, $invoice ); ?></span>
137
+                <span class="wpinv_cart_amount bold" data-subtotal="<?php echo wpinv_get_cart_total($cart_items); ?>" data-total="<?php echo wpinv_get_cart_total(NULL, NULL, $invoice); ?>"><?php wpinv_cart_total($cart_items, true, $invoice); ?></span>
138 138
             </td>
139
-            <?php do_action( 'wpinv_checkout_table_footer_last' ); ?>
139
+            <?php do_action('wpinv_checkout_table_footer_last'); ?>
140 140
         </tr>
141 141
     </tfoot>
142 142
 </table>
Please login to merge, or discard this patch.
templates/emails/wpinv-email-footer.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6
-$email_footer = apply_filters( 'wpinv_email_footer_text', wpinv_get_option( 'email_footer_text' ) );
7
-$email_footer = $email_footer ? wpautop( wp_kses_post( wptexturize( $email_footer ) ) ) : '';
6
+$email_footer = apply_filters('wpinv_email_footer_text', wpinv_get_option('email_footer_text'));
7
+$email_footer = $email_footer ? wpautop(wp_kses_post(wptexturize($email_footer))) : '';
8 8
 ?>
9 9
                                                             </div>
10 10
                                                         </td>
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if ( !defined('ABSPATH') ) {
4 4
     die('-1');
5
+}
5 6
 
6 7
 $email_footer = apply_filters( 'wpinv_email_footer_text', wpinv_get_option( 'email_footer_text' ) );
7 8
 $email_footer = $email_footer ? wpautop( wp_kses_post( wptexturize( $email_footer ) ) ) : '';
Please login to merge, or discard this patch.
templates/emails/wpinv-email-header.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6
-if ( !isset( $email_heading ) ) {
6
+if (!isset($email_heading)) {
7 7
     global $email_heading;
8 8
 }
9 9
 ?>
10 10
 <!DOCTYPE html>
11 11
 <html dir="<?php echo is_rtl() ? 'rtl' : 'ltr'?>">
12 12
     <head>
13
-        <meta http-equiv="Content-Type" content="text/html; charset=<?php bloginfo( 'charset' ); ?>" />
13
+        <meta http-equiv="Content-Type" content="text/html; charset=<?php bloginfo('charset'); ?>" />
14 14
         <meta name="viewport" content="width=device-width, initial-scale=1">
15 15
         <meta name="robots" content="noindex,nofollow">
16 16
         <title><?php echo wpinv_get_blogname(); ?></title>
@@ -22,13 +22,13 @@  discard block
 block discarded – undo
22 22
                     <td align="center" valign="top">
23 23
                         <div id="template_header_image">
24 24
                         <?php
25
-                            if ( $img = wpinv_get_option( 'email_header_image' ) ) {
26
-                                echo '<p style="margin-top:0;"><img style="max-width:100%" src="' . esc_url( $img ) . '" alt="' . esc_attr( wpinv_get_blogname() ) . '" /></p>';
25
+                            if ($img = wpinv_get_option('email_header_image')) {
26
+                                echo '<p style="margin-top:0;"><img style="max-width:100%" src="' . esc_url($img) . '" alt="' . esc_attr(wpinv_get_blogname()) . '" /></p>';
27 27
                             }
28 28
                         ?>
29 29
                         </div>
30 30
                         <table border="0" cellpadding="0" cellspacing="0" width="100%" id="template_container">
31
-                            <?php if ( !empty( $email_heading ) ) { ?>
31
+                            <?php if (!empty($email_heading)) { ?>
32 32
                             <tr>
33 33
                                 <td align="center" valign="top">
34 34
                                     <!-- Header -->
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if ( !defined('ABSPATH') ) {
4 4
     die('-1');
5
+}
5 6
 
6 7
 if ( !isset( $email_heading ) ) {
7 8
     global $email_heading;
Please login to merge, or discard this patch.
templates/emails/wpinv-email-user_invoice.php 2 patches
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if ( !defined('ABSPATH') ) {
4 4
     die('-1');
5
+}
5 6
 
6 7
 do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
7 8
 
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,18 +1,18 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
6
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
7 7
 
8
-if ( ! empty( $message_body ) ) {
9
-    echo wpautop( wptexturize( $message_body ) );
8
+if (!empty($message_body)) {
9
+    echo wpautop(wptexturize($message_body));
10 10
 }
11 11
 
12
-do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin );
12
+do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin);
13 13
 
14
-do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin );
14
+do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin);
15 15
 
16
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
16
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
17 17
 
18
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
19 18
\ No newline at end of file
19
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
20 20
\ No newline at end of file
Please login to merge, or discard this patch.
templates/emails/wpinv-email-styles.php 2 patches
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if ( !defined('ABSPATH') ) {
4 4
     die('-1');
5
+}
5 6
 
6 7
 // Load colours
7 8
 $bg              = wpinv_get_option( 'email_background_color', '#f5f5f5' );
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -1,25 +1,25 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6 6
 // Load colours
7
-$bg              = wpinv_get_option( 'email_background_color', '#f5f5f5' );
8
-$body            = wpinv_get_option( 'email_body_background_color', '#fdfdfd' );
9
-$base            = wpinv_get_option( 'email_base_color', '#557da2' );
10
-$base_text       = wpinv_light_or_dark( $base, '#202020', '#ffffff' );
11
-$text            = wpinv_get_option( 'email_text_color', '#505050' );
7
+$bg              = wpinv_get_option('email_background_color', '#f5f5f5');
8
+$body            = wpinv_get_option('email_body_background_color', '#fdfdfd');
9
+$base            = wpinv_get_option('email_base_color', '#557da2');
10
+$base_text       = wpinv_light_or_dark($base, '#202020', '#ffffff');
11
+$text            = wpinv_get_option('email_text_color', '#505050');
12 12
 
13
-$bg_darker_10    = wpinv_hex_darker( $bg, 10 );
14
-$body_darker_10  = wpinv_hex_darker( $body, 10 );
15
-$base_lighter_20 = wpinv_hex_lighter( $base, 20 );
16
-$base_lighter_40 = wpinv_hex_lighter( $base, 40 );
17
-$text_lighter_20 = wpinv_hex_lighter( $text, 20 );
13
+$bg_darker_10    = wpinv_hex_darker($bg, 10);
14
+$body_darker_10  = wpinv_hex_darker($body, 10);
15
+$base_lighter_20 = wpinv_hex_lighter($base, 20);
16
+$base_lighter_40 = wpinv_hex_lighter($base, 40);
17
+$text_lighter_20 = wpinv_hex_lighter($text, 20);
18 18
 
19 19
 // !important; is a gmail hack to prevent styles being stripped if it doesn't like something.
20 20
 ?>
21 21
 #wrapper {
22
-    background-color: <?php echo esc_attr( $bg ); ?>;
22
+    background-color: <?php echo esc_attr($bg); ?>;
23 23
     margin: 0;
24 24
     -webkit-text-size-adjust: none !important;
25 25
     padding: 3%;
@@ -40,15 +40,15 @@  discard block
 block discarded – undo
40 40
 
41 41
 #template_container {
42 42
     box-shadow: 0 1px 4px rgba(0,0,0,0.1) !important;
43
-    background-color: <?php echo esc_attr( $body ); ?>;
44
-    border: 1px solid <?php echo esc_attr( $bg_darker_10 ); ?>;
43
+    background-color: <?php echo esc_attr($body); ?>;
44
+    border: 1px solid <?php echo esc_attr($bg_darker_10); ?>;
45 45
     border-radius: 3px !important;
46 46
 }
47 47
 
48 48
 #template_header {
49
-    background-color: <?php echo esc_attr( $base ); ?>;
49
+    background-color: <?php echo esc_attr($base); ?>;
50 50
     border-radius: 3px 3px 0 0 !important;
51
-    color: <?php echo esc_attr( $base_text ); ?>;
51
+    color: <?php echo esc_attr($base_text); ?>;
52 52
     border-bottom: 0;
53 53
     font-weight: bold;
54 54
     line-height: 100%;
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 }
62 62
 
63 63
 #template_header h1 {
64
-    color: <?php echo esc_attr( $base_text ); ?>;
64
+    color: <?php echo esc_attr($base_text); ?>;
65 65
 }
66 66
 
67 67
 #template_footer td {
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 
73 73
 #template_footer #credit {
74 74
     border:0;
75
-    color: <?php echo esc_attr( $base_lighter_40 ); ?>;
75
+    color: <?php echo esc_attr($base_lighter_40); ?>;
76 76
     font-family: Arial;
77 77
     font-size:12px;
78 78
     line-height:125%;
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 }
82 82
 
83 83
 #body_content {
84
-    background-color: <?php echo esc_attr( $body ); ?>;
84
+    background-color: <?php echo esc_attr($body); ?>;
85 85
 }
86 86
 
87 87
 #body_content table td {
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 }
102 102
 
103 103
 #body_content_inner {
104
-    color: <?php echo esc_attr( $text_lighter_20 ); ?>;
104
+    color: <?php echo esc_attr($text_lighter_20); ?>;
105 105
     font-family: Arial,Helvetica,sans-serif;
106 106
     font-size: 14px;
107 107
     line-height: 150%;
@@ -109,17 +109,17 @@  discard block
 block discarded – undo
109 109
 }
110 110
 
111 111
 .td {
112
-    color: <?php echo esc_attr( $text_lighter_20 ); ?>;
113
-    border: 1px solid <?php echo esc_attr( $body_darker_10 ); ?>;
112
+    color: <?php echo esc_attr($text_lighter_20); ?>;
113
+    border: 1px solid <?php echo esc_attr($body_darker_10); ?>;
114 114
 }
115 115
 
116 116
 .text {
117
-    color: <?php echo esc_attr( $text ); ?>;
117
+    color: <?php echo esc_attr($text); ?>;
118 118
     font-family: Arial,Helvetica,sans-serif;
119 119
 }
120 120
 
121 121
 .link {
122
-    color: <?php echo esc_attr( $base ); ?>;
122
+    color: <?php echo esc_attr($base); ?>;
123 123
 }
124 124
 
125 125
 #header_wrapper {
@@ -128,19 +128,19 @@  discard block
 block discarded – undo
128 128
 }
129 129
 
130 130
 h1 {
131
-    color: <?php echo esc_attr( $base ); ?>;
131
+    color: <?php echo esc_attr($base); ?>;
132 132
     font-family: Arial,Helvetica,sans-serif;
133 133
     font-size: 30px;
134 134
     font-weight: 300;
135 135
     line-height: 150%;
136 136
     margin: 0;
137 137
     text-align: <?php echo is_rtl() ? 'right' : 'left'; ?>;
138
-    text-shadow: 0 1px 0 <?php echo esc_attr( $base_lighter_20 ); ?>;
138
+    text-shadow: 0 1px 0 <?php echo esc_attr($base_lighter_20); ?>;
139 139
     -webkit-font-smoothing: antialiased;
140 140
 }
141 141
 
142 142
 h2 {
143
-    color: <?php echo esc_attr( $base ); ?>;
143
+    color: <?php echo esc_attr($base); ?>;
144 144
     display: block;
145 145
     font-family: Arial,Helvetica,sans-serif;
146 146
     font-size: 18px;
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 }
152 152
 
153 153
 h3 {
154
-    color: <?php echo esc_attr( $base ); ?>;
154
+    color: <?php echo esc_attr($base); ?>;
155 155
     display: block;
156 156
     font-family: Arial,Helvetica,sans-serif;
157 157
     font-size: 16px;
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 }
163 163
 
164 164
 a {
165
-    color: <?php echo esc_attr( $base ); ?>;
165
+    color: <?php echo esc_attr($base); ?>;
166 166
     font-weight: normal;
167 167
     text-decoration: underline;
168 168
 }
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 }
181 181
 
182 182
 .table-bordered {
183
-    border: 1px solid <?php echo esc_attr( $body_darker_10 ); ?>;
183
+    border: 1px solid <?php echo esc_attr($body_darker_10); ?>;
184 184
     border-collapse: collapse;
185 185
     border-spacing: 0;
186 186
     width: 100%;
@@ -188,8 +188,8 @@  discard block
 block discarded – undo
188 188
 
189 189
 .table-bordered th,
190 190
 .table-bordered td {
191
-    border: 1px solid <?php echo esc_attr( $body_darker_10 ); ?>;
192
-    color: <?php echo esc_attr( $text_lighter_20 ); ?>;
191
+    border: 1px solid <?php echo esc_attr($body_darker_10); ?>;
192
+    color: <?php echo esc_attr($text_lighter_20); ?>;
193 193
     font-size: 14px;
194 194
 }
195 195
 .small {
@@ -288,9 +288,9 @@  discard block
 block discarded – undo
288 288
   text-decoration: none;
289 289
 }
290 290
 .btn-default {
291
-    color: <?php echo esc_attr( $base_text ); ?>;
292
-    background-color: <?php echo esc_attr( $base ); ?>;
293
-    border-color: <?php echo esc_attr( $base ); ?>;
291
+    color: <?php echo esc_attr($base_text); ?>;
292
+    background-color: <?php echo esc_attr($base); ?>;
293
+    border-color: <?php echo esc_attr($base); ?>;
294 294
 }
295 295
 .btn-primary {
296 296
   color: #fff;
Please login to merge, or discard this patch.
templates/emails/wpinv-email-billing-details.php 2 patches
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -1,67 +1,67 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6
-do_action( 'wpinv_email_before_billing_details', $invoice ); ?>
6
+do_action('wpinv_email_before_billing_details', $invoice); ?>
7 7
 <div id="wpinv-email-billing">
8
-    <h3 class="wpinv-address-t"><?php echo apply_filters( 'wpinv_email_billing_title', __( 'Billing Details', 'invoicing' ) ); ?></h3>
8
+    <h3 class="wpinv-address-t"><?php echo apply_filters('wpinv_email_billing_title', __('Billing Details', 'invoicing')); ?></h3>
9 9
     <?php 
10 10
     $address_row = '';
11
-    if ( $address = $invoice->get_address() ) {
12
-        $address_row .= wpautop( wp_kses_post( $address ) );
11
+    if ($address = $invoice->get_address()) {
12
+        $address_row .= wpautop(wp_kses_post($address));
13 13
     }
14 14
     
15 15
     $address_fields = array();
16
-    if ( !empty( $invoice->city ) ) {
16
+    if (!empty($invoice->city)) {
17 17
         $address_fields[] = $invoice->city;
18 18
     }
19 19
     
20
-    $country_code = !empty( $invoice->country ) ? $invoice->country : '';
21
-    if ( !empty( $invoice->state ) ) {
22
-        $address_fields[] = wpinv_state_name( $invoice->state, $country_code );
20
+    $country_code = !empty($invoice->country) ? $invoice->country : '';
21
+    if (!empty($invoice->state)) {
22
+        $address_fields[] = wpinv_state_name($invoice->state, $country_code);
23 23
     }
24 24
     
25
-    if ( !empty( $address_fields ) ) {
26
-        $address_fields = implode( ", ", $address_fields );
27
-        $address_row .= wpautop( wp_kses_post( $address_fields ) );
25
+    if (!empty($address_fields)) {
26
+        $address_fields = implode(", ", $address_fields);
27
+        $address_row .= wpautop(wp_kses_post($address_fields));
28 28
     }
29 29
     
30
-    if ( !empty( $country_code ) ) {
31
-        $country = wpinv_country_name( $country_code );
32
-        $address_row .= wpautop( wp_kses_post( trim( $country . '(' . $country_code . ')' . ' ' . $invoice->zip ) ) );
30
+    if (!empty($country_code)) {
31
+        $country = wpinv_country_name($country_code);
32
+        $address_row .= wpautop(wp_kses_post(trim($country . '(' . $country_code . ')' . ' ' . $invoice->zip)));
33 33
     }
34 34
     
35 35
     ?>
36 36
     <table class="table table-bordered table-sm wpi-billing-details">
37 37
         <tbody>
38
-            <?php do_action( 'wpinv_email_billing_fields_first', $invoice ); ?>
38
+            <?php do_action('wpinv_email_billing_fields_first', $invoice); ?>
39 39
             <tr class="wpi-receipt-name">
40
-                <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th>
41
-                <td><?php if ( $sent_to_admin && $invoice->user_id ) { ?><a href="<?php echo esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), self_admin_url( 'user-edit.php' ) ) ) ;?>"><?php echo esc_html( $invoice->get_user_full_name() ); ?></a><?php } else { echo esc_html( $invoice->get_user_full_name() ); } ?></td>
40
+                <th class="text-left"><?php _e('Name', 'invoicing'); ?></th>
41
+                <td><?php if ($sent_to_admin && $invoice->user_id) { ?><a href="<?php echo esc_url(add_query_arg('user_id', $invoice->get_user_id(), self_admin_url('user-edit.php'))); ?>"><?php echo esc_html($invoice->get_user_full_name()); ?></a><?php } else { echo esc_html($invoice->get_user_full_name()); } ?></td>
42 42
             </tr>
43 43
             <tr class="wpi-receipt-email">
44
-                <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th>
45
-                <td><?php echo $invoice->get_email() ;?></td>
44
+                <th class="text-left"><?php _e('Email', 'invoicing'); ?></th>
45
+                <td><?php echo $invoice->get_email(); ?></td>
46 46
             </tr>
47
-            <?php if ( $invoice->company ) { ?>
47
+            <?php if ($invoice->company) { ?>
48 48
             <tr class="wpi-receipt-company">
49
-                <th class="text-left"><?php _e( 'Company', 'invoicing' ); ?></th>
50
-                <td><?php echo esc_html( $invoice->company ) ;?></td>
49
+                <th class="text-left"><?php _e('Company', 'invoicing'); ?></th>
50
+                <td><?php echo esc_html($invoice->company); ?></td>
51 51
             </tr>
52 52
             <?php } ?>
53 53
             <tr class="wpi-receipt-address">
54
-                <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th>
55
-                <td><?php echo $address_row ;?></td>
54
+                <th class="text-left"><?php _e('Address', 'invoicing'); ?></th>
55
+                <td><?php echo $address_row; ?></td>
56 56
             </tr>
57
-            <?php if ( $invoice->phone ) { ?>
57
+            <?php if ($invoice->phone) { ?>
58 58
             <tr class="wpi-receipt-phone">
59
-                <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th>
60
-                <td><?php echo esc_html( $invoice->phone ) ;?></td>
59
+                <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th>
60
+                <td><?php echo esc_html($invoice->phone); ?></td>
61 61
             </tr>
62 62
             <?php } ?>
63
-            <?php do_action( 'wpinv_email_billing_fields_last', $invoice ); ?>
63
+            <?php do_action('wpinv_email_billing_fields_last', $invoice); ?>
64 64
         </tbody>
65 65
     </table>
66 66
 </div>
67
-<?php do_action( 'wpinv_email_after_billing_details', $invoice ); ?>
68 67
\ No newline at end of file
68
+<?php do_action('wpinv_email_after_billing_details', $invoice); ?>
69 69
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if ( !defined('ABSPATH') ) {
4 4
     die('-1');
5
+}
5 6
 
6 7
 do_action( 'wpinv_email_before_billing_details', $invoice ); ?>
7 8
 <div id="wpinv-email-billing">
Please login to merge, or discard this patch.