Completed
Branch master (d48fb4)
by Stiofan
03:49
created
includes/libraries/MaxMind/Db/Reader.php 1 patch
Doc Comments   +13 added lines patch added patch discarded remove patch
@@ -115,6 +115,9 @@  discard block
 block discarded – undo
115 115
         return $this->resolveDataPointer($pointer);
116 116
     }
117 117
 
118
+    /**
119
+     * @param string $ipAddress
120
+     */
118 121
     private function findAddressInTree($ipAddress)
119 122
     {
120 123
         // XXX - could simplify. Done as a byte array to ease porting
@@ -146,6 +149,9 @@  discard block
 block discarded – undo
146 149
     }
147 150
 
148 151
 
152
+    /**
153
+     * @param integer $length
154
+     */
149 155
     private function startNode($length)
150 156
     {
151 157
         // Check if we are looking up an IPv4 address in an IPv6 tree. If this
@@ -178,6 +184,9 @@  discard block
 block discarded – undo
178 184
         return $node;
179 185
     }
180 186
 
187
+    /**
188
+     * @param integer $index
189
+     */
181 190
     private function readNode($nodeNumber, $index)
182 191
     {
183 192
         $baseOffset = $nodeNumber * $this->metadata->nodeByteSize;
@@ -230,6 +239,10 @@  discard block
 block discarded – undo
230 239
      * are much faster algorithms (e.g., Boyer-Moore) for this if speed is ever
231 240
      * an issue, but I suspect it won't be.
232 241
      */
242
+
243
+    /**
244
+     * @param string $filename
245
+     */
233 246
     private function findMetadataStart($filename)
234 247
     {
235 248
         $handle = $this->fileHandle;
Please login to merge, or discard this patch.
includes/libraries/wp-session/class-recursive-arrayaccess.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -104,7 +104,6 @@
 block discarded – undo
104 104
 	 * @link http://php.net/manual/en/arrayaccess.offsetset.php
105 105
 	 *
106 106
 	 * @param mixed $offset The offset to assign the value to.
107
-	 * @param mixed $value  The value to set.
108 107
 	 *
109 108
 	 * @return void
110 109
 	 */
Please login to merge, or discard this patch.
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -17,197 +17,197 @@
 block discarded – undo
17 17
  * @since 3.7.0
18 18
  */
19 19
 class Recursive_ArrayAccess implements ArrayAccess, Iterator, Countable {
20
-	/**
21
-	 * Internal data collection.
22
-	 *
23
-	 * @var array
24
-	 */
25
-	protected $container = array();
26
-
27
-	/**
28
-	 * Flag whether or not the internal collection has been changed.
29
-	 *
30
-	 * @var bool
31
-	 */
32
-	protected $dirty = false;
33
-
34
-	/**
35
-	 * Default object constructor.
36
-	 *
37
-	 * @param array $data
38
-	 */
39
-	protected function __construct( $data = array() ) {
40
-		foreach ( $data as $key => $value ) {
41
-			$this[ $key ] = $value;
42
-		}
43
-	}
44
-
45
-	/**
46
-	 * Allow deep copies of objects
47
-	 */
48
-	public function __clone() {
49
-		foreach ( $this->container as $key => $value ) {
50
-			if ( $value instanceof self ) {
51
-				$this[ $key ] = clone $value;
52
-			}
53
-		}
54
-	}
55
-
56
-	/**
57
-	 * Output the data container as a multidimensional array.
58
-	 *
59
-	 * @return array
60
-	 */
61
-	public function toArray() {
62
-		$data = $this->container;
63
-		foreach ( $data as $key => $value ) {
64
-			if ( $value instanceof self ) {
65
-				$data[ $key ] = $value->toArray();
66
-			}
67
-		}
68
-		return $data;
69
-	}
70
-
71
-	/*****************************************************************/
72
-	/*                   ArrayAccess Implementation                  */
73
-	/*****************************************************************/
74
-
75
-	/**
76
-	 * Whether a offset exists
77
-	 *
78
-	 * @link http://php.net/manual/en/arrayaccess.offsetexists.php
79
-	 *
80
-	 * @param mixed $offset An offset to check for.
81
-	 *
82
-	 * @return boolean true on success or false on failure.
83
-	 */
84
-	public function offsetExists( $offset ) {
85
-		return isset( $this->container[ $offset ]) ;
86
-	}
87
-
88
-	/**
89
-	 * Offset to retrieve
90
-	 *
91
-	 * @link http://php.net/manual/en/arrayaccess.offsetget.php
92
-	 *
93
-	 * @param mixed $offset The offset to retrieve.
94
-	 *
95
-	 * @return mixed Can return all value types.
96
-	 */
97
-	public function offsetGet( $offset ) {
98
-		return isset( $this->container[ $offset ] ) ? $this->container[ $offset ] : null;
99
-	}
100
-
101
-	/**
102
-	 * Offset to set
103
-	 *
104
-	 * @link http://php.net/manual/en/arrayaccess.offsetset.php
105
-	 *
106
-	 * @param mixed $offset The offset to assign the value to.
107
-	 * @param mixed $value  The value to set.
108
-	 *
109
-	 * @return void
110
-	 */
111
-	public function offsetSet( $offset, $data ) {
112
-		if ( is_array( $data ) ) {
113
-			$data = new self( $data );
114
-		}
115
-		if ( $offset === null ) { // don't forget this!
116
-			$this->container[] = $data;
117
-		} else {
118
-			$this->container[ $offset ] = $data;
119
-		}
120
-
121
-		$this->dirty = true;
122
-	}
123
-
124
-	/**
125
-	 * Offset to unset
126
-	 *
127
-	 * @link http://php.net/manual/en/arrayaccess.offsetunset.php
128
-	 *
129
-	 * @param mixed $offset The offset to unset.
130
-	 *
131
-	 * @return void
132
-	 */
133
-	public function offsetUnset( $offset ) {
134
-		unset( $this->container[ $offset ] );
135
-
136
-		$this->dirty = true;
137
-	}
20
+    /**
21
+     * Internal data collection.
22
+     *
23
+     * @var array
24
+     */
25
+    protected $container = array();
26
+
27
+    /**
28
+     * Flag whether or not the internal collection has been changed.
29
+     *
30
+     * @var bool
31
+     */
32
+    protected $dirty = false;
33
+
34
+    /**
35
+     * Default object constructor.
36
+     *
37
+     * @param array $data
38
+     */
39
+    protected function __construct( $data = array() ) {
40
+        foreach ( $data as $key => $value ) {
41
+            $this[ $key ] = $value;
42
+        }
43
+    }
44
+
45
+    /**
46
+     * Allow deep copies of objects
47
+     */
48
+    public function __clone() {
49
+        foreach ( $this->container as $key => $value ) {
50
+            if ( $value instanceof self ) {
51
+                $this[ $key ] = clone $value;
52
+            }
53
+        }
54
+    }
55
+
56
+    /**
57
+     * Output the data container as a multidimensional array.
58
+     *
59
+     * @return array
60
+     */
61
+    public function toArray() {
62
+        $data = $this->container;
63
+        foreach ( $data as $key => $value ) {
64
+            if ( $value instanceof self ) {
65
+                $data[ $key ] = $value->toArray();
66
+            }
67
+        }
68
+        return $data;
69
+    }
70
+
71
+    /*****************************************************************/
72
+    /*                   ArrayAccess Implementation                  */
73
+    /*****************************************************************/
74
+
75
+    /**
76
+     * Whether a offset exists
77
+     *
78
+     * @link http://php.net/manual/en/arrayaccess.offsetexists.php
79
+     *
80
+     * @param mixed $offset An offset to check for.
81
+     *
82
+     * @return boolean true on success or false on failure.
83
+     */
84
+    public function offsetExists( $offset ) {
85
+        return isset( $this->container[ $offset ]) ;
86
+    }
87
+
88
+    /**
89
+     * Offset to retrieve
90
+     *
91
+     * @link http://php.net/manual/en/arrayaccess.offsetget.php
92
+     *
93
+     * @param mixed $offset The offset to retrieve.
94
+     *
95
+     * @return mixed Can return all value types.
96
+     */
97
+    public function offsetGet( $offset ) {
98
+        return isset( $this->container[ $offset ] ) ? $this->container[ $offset ] : null;
99
+    }
100
+
101
+    /**
102
+     * Offset to set
103
+     *
104
+     * @link http://php.net/manual/en/arrayaccess.offsetset.php
105
+     *
106
+     * @param mixed $offset The offset to assign the value to.
107
+     * @param mixed $value  The value to set.
108
+     *
109
+     * @return void
110
+     */
111
+    public function offsetSet( $offset, $data ) {
112
+        if ( is_array( $data ) ) {
113
+            $data = new self( $data );
114
+        }
115
+        if ( $offset === null ) { // don't forget this!
116
+            $this->container[] = $data;
117
+        } else {
118
+            $this->container[ $offset ] = $data;
119
+        }
120
+
121
+        $this->dirty = true;
122
+    }
123
+
124
+    /**
125
+     * Offset to unset
126
+     *
127
+     * @link http://php.net/manual/en/arrayaccess.offsetunset.php
128
+     *
129
+     * @param mixed $offset The offset to unset.
130
+     *
131
+     * @return void
132
+     */
133
+    public function offsetUnset( $offset ) {
134
+        unset( $this->container[ $offset ] );
135
+
136
+        $this->dirty = true;
137
+    }
138 138
 	
139 139
 	
140
-	/*****************************************************************/
141
-	/*                     Iterator Implementation                   */
142
-	/*****************************************************************/
143
-
144
-	/**
145
-	 * Current position of the array.
146
-	 *
147
-	 * @link http://php.net/manual/en/iterator.current.php
148
-	 *
149
-	 * @return mixed
150
-	 */
151
-	public function current() {
152
-		return current( $this->container );
153
-	}
154
-
155
-	/**
156
-	 * Key of the current element.
157
-	 *
158
-	 * @link http://php.net/manual/en/iterator.key.php
159
-	 *
160
-	 * @return mixed
161
-	 */
162
-	public function key() {
163
-		return key( $this->container );
164
-	}
165
-
166
-	/**
167
-	 * Move the internal point of the container array to the next item
168
-	 *
169
-	 * @link http://php.net/manual/en/iterator.next.php
170
-	 *
171
-	 * @return void
172
-	 */
173
-	public function next() {
174
-		next( $this->container );
175
-	}
176
-
177
-	/**
178
-	 * Rewind the internal point of the container array.
179
-	 *
180
-	 * @link http://php.net/manual/en/iterator.rewind.php
181
-	 *
182
-	 * @return void
183
-	 */
184
-	public function rewind() {
185
-		reset( $this->container );
186
-	}
187
-
188
-	/**
189
-	 * Is the current key valid?
190
-	 *
191
-	 * @link http://php.net/manual/en/iterator.rewind.php
192
-	 *
193
-	 * @return bool
194
-	 */
195
-	public function valid() {
196
-		return $this->offsetExists( $this->key() );
197
-	}
198
-
199
-	/*****************************************************************/
200
-	/*                    Countable Implementation                   */
201
-	/*****************************************************************/
202
-
203
-	/**
204
-	 * Get the count of elements in the container array.
205
-	 *
206
-	 * @link http://php.net/manual/en/countable.count.php
207
-	 *
208
-	 * @return int
209
-	 */
210
-	public function count() {
211
-		return count( $this->container );
212
-	}
140
+    /*****************************************************************/
141
+    /*                     Iterator Implementation                   */
142
+    /*****************************************************************/
143
+
144
+    /**
145
+     * Current position of the array.
146
+     *
147
+     * @link http://php.net/manual/en/iterator.current.php
148
+     *
149
+     * @return mixed
150
+     */
151
+    public function current() {
152
+        return current( $this->container );
153
+    }
154
+
155
+    /**
156
+     * Key of the current element.
157
+     *
158
+     * @link http://php.net/manual/en/iterator.key.php
159
+     *
160
+     * @return mixed
161
+     */
162
+    public function key() {
163
+        return key( $this->container );
164
+    }
165
+
166
+    /**
167
+     * Move the internal point of the container array to the next item
168
+     *
169
+     * @link http://php.net/manual/en/iterator.next.php
170
+     *
171
+     * @return void
172
+     */
173
+    public function next() {
174
+        next( $this->container );
175
+    }
176
+
177
+    /**
178
+     * Rewind the internal point of the container array.
179
+     *
180
+     * @link http://php.net/manual/en/iterator.rewind.php
181
+     *
182
+     * @return void
183
+     */
184
+    public function rewind() {
185
+        reset( $this->container );
186
+    }
187
+
188
+    /**
189
+     * Is the current key valid?
190
+     *
191
+     * @link http://php.net/manual/en/iterator.rewind.php
192
+     *
193
+     * @return bool
194
+     */
195
+    public function valid() {
196
+        return $this->offsetExists( $this->key() );
197
+    }
198
+
199
+    /*****************************************************************/
200
+    /*                    Countable Implementation                   */
201
+    /*****************************************************************/
202
+
203
+    /**
204
+     * Get the count of elements in the container array.
205
+     *
206
+     * @link http://php.net/manual/en/countable.count.php
207
+     *
208
+     * @return int
209
+     */
210
+    public function count() {
211
+        return count( $this->container );
212
+    }
213 213
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
 	 *
37 37
 	 * @param array $data
38 38
 	 */
39
-	protected function __construct( $data = array() ) {
40
-		foreach ( $data as $key => $value ) {
41
-			$this[ $key ] = $value;
39
+	protected function __construct($data = array()) {
40
+		foreach ($data as $key => $value) {
41
+			$this[$key] = $value;
42 42
 		}
43 43
 	}
44 44
 
@@ -46,9 +46,9 @@  discard block
 block discarded – undo
46 46
 	 * Allow deep copies of objects
47 47
 	 */
48 48
 	public function __clone() {
49
-		foreach ( $this->container as $key => $value ) {
50
-			if ( $value instanceof self ) {
51
-				$this[ $key ] = clone $value;
49
+		foreach ($this->container as $key => $value) {
50
+			if ($value instanceof self) {
51
+				$this[$key] = clone $value;
52 52
 			}
53 53
 		}
54 54
 	}
@@ -60,9 +60,9 @@  discard block
 block discarded – undo
60 60
 	 */
61 61
 	public function toArray() {
62 62
 		$data = $this->container;
63
-		foreach ( $data as $key => $value ) {
64
-			if ( $value instanceof self ) {
65
-				$data[ $key ] = $value->toArray();
63
+		foreach ($data as $key => $value) {
64
+			if ($value instanceof self) {
65
+				$data[$key] = $value->toArray();
66 66
 			}
67 67
 		}
68 68
 		return $data;
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
 	 *
82 82
 	 * @return boolean true on success or false on failure.
83 83
 	 */
84
-	public function offsetExists( $offset ) {
85
-		return isset( $this->container[ $offset ]) ;
84
+	public function offsetExists($offset) {
85
+		return isset($this->container[$offset]);
86 86
 	}
87 87
 
88 88
 	/**
@@ -94,8 +94,8 @@  discard block
 block discarded – undo
94 94
 	 *
95 95
 	 * @return mixed Can return all value types.
96 96
 	 */
97
-	public function offsetGet( $offset ) {
98
-		return isset( $this->container[ $offset ] ) ? $this->container[ $offset ] : null;
97
+	public function offsetGet($offset) {
98
+		return isset($this->container[$offset]) ? $this->container[$offset] : null;
99 99
 	}
100 100
 
101 101
 	/**
@@ -108,14 +108,14 @@  discard block
 block discarded – undo
108 108
 	 *
109 109
 	 * @return void
110 110
 	 */
111
-	public function offsetSet( $offset, $data ) {
112
-		if ( is_array( $data ) ) {
113
-			$data = new self( $data );
111
+	public function offsetSet($offset, $data) {
112
+		if (is_array($data)) {
113
+			$data = new self($data);
114 114
 		}
115
-		if ( $offset === null ) { // don't forget this!
115
+		if ($offset === null) { // don't forget this!
116 116
 			$this->container[] = $data;
117 117
 		} else {
118
-			$this->container[ $offset ] = $data;
118
+			$this->container[$offset] = $data;
119 119
 		}
120 120
 
121 121
 		$this->dirty = true;
@@ -130,8 +130,8 @@  discard block
 block discarded – undo
130 130
 	 *
131 131
 	 * @return void
132 132
 	 */
133
-	public function offsetUnset( $offset ) {
134
-		unset( $this->container[ $offset ] );
133
+	public function offsetUnset($offset) {
134
+		unset($this->container[$offset]);
135 135
 
136 136
 		$this->dirty = true;
137 137
 	}
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 	 * @return mixed
150 150
 	 */
151 151
 	public function current() {
152
-		return current( $this->container );
152
+		return current($this->container);
153 153
 	}
154 154
 
155 155
 	/**
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 	 * @return mixed
161 161
 	 */
162 162
 	public function key() {
163
-		return key( $this->container );
163
+		return key($this->container);
164 164
 	}
165 165
 
166 166
 	/**
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 	 * @return void
172 172
 	 */
173 173
 	public function next() {
174
-		next( $this->container );
174
+		next($this->container);
175 175
 	}
176 176
 
177 177
 	/**
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 	 * @return void
183 183
 	 */
184 184
 	public function rewind() {
185
-		reset( $this->container );
185
+		reset($this->container);
186 186
 	}
187 187
 
188 188
 	/**
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 	 * @return bool
194 194
 	 */
195 195
 	public function valid() {
196
-		return $this->offsetExists( $this->key() );
196
+		return $this->offsetExists($this->key());
197 197
 	}
198 198
 
199 199
 	/*****************************************************************/
@@ -208,6 +208,6 @@  discard block
 block discarded – undo
208 208
 	 * @return int
209 209
 	 */
210 210
 	public function count() {
211
-		return count( $this->container );
211
+		return count($this->container);
212 212
 	}
213 213
 }
Please login to merge, or discard this patch.
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.
Spacing   +707 added lines, -707 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,126 +17,126 @@  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_filter( 'wpinv_tax_rate', array( self::$instance, 'get_rate' ), 10, 4 );
45
-        add_action( 'wp_ajax_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) );
46
-        add_action( 'wp_ajax_nopriv_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) );
47
-        add_action( 'wp_ajax_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) );
48
-        add_action( 'wp_ajax_nopriv_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) );
49
-        add_action( 'wpinv_checkout_error_checks', array( self::$instance, 'checkout_vat_validate' ), 10, 2 );
50
-        add_action( 'wpinv_after_billing_fields', array( self::$instance, 'checkout_vat_fields' ) );
51
-        add_action( 'wpinv_invoice_print_after_line_items', array( self::$instance, 'show_vat_notice' ), 999, 1 );
25
+        if (is_admin()) {
26
+            add_action('admin_enqueue_scripts', array(self::$instance, 'enqueue_admin_scripts'));
27
+            add_action('wpinv_settings_sections_taxes', array(self::$instance, 'section_vat_settings')); 
28
+            add_action('wpinv_settings_taxes', array(self::$instance, 'vat_settings'));
29
+            add_filter('wpinv_settings_taxes-vat_sanitize', array(self::$instance, 'sanitize_vat_settings'));
30
+            add_filter('wpinv_settings_taxes-vat_rates_sanitize', array(self::$instance, 'sanitize_vat_rates'));
31
+            add_action('wp_ajax_wpinv_add_vat_class', array(self::$instance, 'add_class'));
32
+            add_action('wp_ajax_nopriv_wpinv_add_vat_class', array(self::$instance, 'add_class'));
33
+            add_action('wp_ajax_wpinv_delete_vat_class', array(self::$instance, 'delete_class'));
34
+            add_action('wp_ajax_nopriv_wpinv_delete_vat_class', array(self::$instance, 'delete_class'));
35
+            add_action('wp_ajax_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates'));
36
+            add_action('wp_ajax_nopriv_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates'));
37
+            add_action('wp_ajax_wpinv_geoip2', array(self::$instance, 'geoip2_download_database'));
38
+            add_action('wp_ajax_nopriv_wpinv_geoip2', array(self::$instance, 'geoip2_download_database'));
39
+        }
40
+        
41
+        add_action('wp_enqueue_scripts', array(self::$instance, 'enqueue_vat_scripts'));
42
+        add_filter('wpinv_default_billing_country', array(self::$instance, 'get_user_country'), 10);
43
+        add_filter('wpinv_get_user_country', array(self::$instance, 'set_user_country'), 10);
44
+        add_filter('wpinv_tax_rate', array(self::$instance, 'get_rate'), 10, 4);
45
+        add_action('wp_ajax_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate'));
46
+        add_action('wp_ajax_nopriv_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate'));
47
+        add_action('wp_ajax_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset'));
48
+        add_action('wp_ajax_nopriv_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset'));
49
+        add_action('wpinv_checkout_error_checks', array(self::$instance, 'checkout_vat_validate'), 10, 2);
50
+        add_action('wpinv_after_billing_fields', array(self::$instance, 'checkout_vat_fields'));
51
+        add_action('wpinv_invoice_print_after_line_items', array(self::$instance, 'show_vat_notice'), 999, 1);
52 52
     }        
53 53
     
54
-    public static function get_eu_states( $sort = true ) {
55
-        $eu_states = array( 'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE' );
56
-        if ( $sort ) {
57
-            $sort = sort( $eu_states );
54
+    public static function get_eu_states($sort = true) {
55
+        $eu_states = array('AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE');
56
+        if ($sort) {
57
+            $sort = sort($eu_states);
58 58
         }
59 59
         
60
-        return apply_filters( 'wpinv_get_eu_states', $eu_states, $sort );
60
+        return apply_filters('wpinv_get_eu_states', $eu_states, $sort);
61 61
     }
62 62
     
63
-    public static function get_gst_countries( $sort = true ) {
64
-        $gst_countries  = array( 'AU', 'NZ', 'CA', 'CN' );
63
+    public static function get_gst_countries($sort = true) {
64
+        $gst_countries = array('AU', 'NZ', 'CA', 'CN');
65 65
         
66
-        if ( $sort ) {
67
-            $sort = sort( $gst_countries );
66
+        if ($sort) {
67
+            $sort = sort($gst_countries);
68 68
         }
69 69
         
70
-        return apply_filters( 'wpinv_get_gst_countries', $gst_countries, $sort );
70
+        return apply_filters('wpinv_get_gst_countries', $gst_countries, $sort);
71 71
     }
72 72
     
73
-    public static function is_eu_state( $country_code ) {
74
-        $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_eu_states() ) ? true : false;
73
+    public static function is_eu_state($country_code) {
74
+        $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_eu_states()) ? true : false;
75 75
                 
76
-        return apply_filters( 'wpinv_is_eu_state', $return, $country_code );
76
+        return apply_filters('wpinv_is_eu_state', $return, $country_code);
77 77
     }
78 78
     
79
-    public static function is_gst_country( $country_code ) {
80
-        $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_gst_countries() ) ? true : false;
79
+    public static function is_gst_country($country_code) {
80
+        $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_gst_countries()) ? true : false;
81 81
                 
82
-        return apply_filters( 'wpinv_is_gst_country', $return, $country_code );
82
+        return apply_filters('wpinv_is_gst_country', $return, $country_code);
83 83
     }
84 84
     
85 85
     public static function enqueue_vat_scripts() {
86
-        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
86
+        $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
87 87
         
88
-        wp_register_script( 'wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
89
-        wp_register_script( 'wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
88
+        wp_register_script('wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
89
+        wp_register_script('wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
90 90
         
91
-        $vat_name   = self::get_vat_name();
91
+        $vat_name = self::get_vat_name();
92 92
         
93 93
         $vars = array();
94 94
         $vars['EUStates'] = self::get_eu_states();
95
-        $vars['NoRateSet'] = __( 'You have not set a rate. Do you want to continue?', 'invoicing' );
96
-        $vars['EmptyCompany'] = __( 'Please enter your registered company name!', 'invoicing' );
97
-        $vars['EmptyVAT'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
98
-        $vars['TotalsRefreshed'] = wp_sprintf( __( 'The invoice totals will be refreshed to update the %s.', 'invoicing' ), $vat_name );
99
-        $vars['ErrValidateVAT'] = wp_sprintf( __( 'Fail to validate the %s number!', 'invoicing' ), $vat_name );
100
-        $vars['ErrResetVAT'] = wp_sprintf( __( 'Fail to reset the %s number!', 'invoicing' ), $vat_name );
101
-        $vars['ErrInvalidVat'] = wp_sprintf( __( 'The %s number supplied does not have a valid format!', 'invoicing' ), $vat_name );
102
-        $vars['ErrInvalidResponse'] = __( 'An invalid response has been received from the server!', 'invoicing' );
95
+        $vars['NoRateSet'] = __('You have not set a rate. Do you want to continue?', 'invoicing');
96
+        $vars['EmptyCompany'] = __('Please enter your registered company name!', 'invoicing');
97
+        $vars['EmptyVAT'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
98
+        $vars['TotalsRefreshed'] = wp_sprintf(__('The invoice totals will be refreshed to update the %s.', 'invoicing'), $vat_name);
99
+        $vars['ErrValidateVAT'] = wp_sprintf(__('Fail to validate the %s number!', 'invoicing'), $vat_name);
100
+        $vars['ErrResetVAT'] = wp_sprintf(__('Fail to reset the %s number!', 'invoicing'), $vat_name);
101
+        $vars['ErrInvalidVat'] = wp_sprintf(__('The %s number supplied does not have a valid format!', 'invoicing'), $vat_name);
102
+        $vars['ErrInvalidResponse'] = __('An invalid response has been received from the server!', 'invoicing');
103 103
         $vars['ApplyVATRules'] = self::allow_vat_rules();
104
-        $vars['ErrResponse'] = __( 'The request response is invalid!', 'invoicing' );
105
-        $vars['ErrRateResponse'] = __( 'The get rate request response is invalid', 'invoicing' );
106
-        $vars['PageRefresh'] = __( 'The page will be refreshed in 10 seconds to show the new options.', 'invoicing' );
107
-        $vars['RequestResponseNotValidJSON'] = __( 'The get rate request response is not valid JSON', 'invoicing' );
108
-        $vars['GetRateRequestFailed'] = __( 'The get rate request failed: ', 'invoicing' );
109
-        $vars['NoRateInformationInResponse'] = __( 'The get rate request response does not contain any rate information', 'invoicing' );
110
-        $vars['RatesUpdated'] = __( 'The rates have been updated. Press the save button to record these new rates.', 'invoicing' );
111
-        $vars['IPAddressInformation'] = __( 'IP Address Information', 'invoicing' );
112
-        $vars['VatValidating'] = wp_sprintf( __( 'Validating %s number...', 'invoicing' ), $vat_name );
113
-        $vars['VatReseting'] = __( 'Reseting...', 'invoicing' );
114
-        $vars['VatValidated'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
115
-        $vars['VatNotValidated'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
116
-        $vars['ConfirmDeleteClass'] = __( 'Are you sure you wish to delete this rates class?', 'invoicing' );
104
+        $vars['ErrResponse'] = __('The request response is invalid!', 'invoicing');
105
+        $vars['ErrRateResponse'] = __('The get rate request response is invalid', 'invoicing');
106
+        $vars['PageRefresh'] = __('The page will be refreshed in 10 seconds to show the new options.', 'invoicing');
107
+        $vars['RequestResponseNotValidJSON'] = __('The get rate request response is not valid JSON', 'invoicing');
108
+        $vars['GetRateRequestFailed'] = __('The get rate request failed: ', 'invoicing');
109
+        $vars['NoRateInformationInResponse'] = __('The get rate request response does not contain any rate information', 'invoicing');
110
+        $vars['RatesUpdated'] = __('The rates have been updated. Press the save button to record these new rates.', 'invoicing');
111
+        $vars['IPAddressInformation'] = __('IP Address Information', 'invoicing');
112
+        $vars['VatValidating'] = wp_sprintf(__('Validating %s number...', 'invoicing'), $vat_name);
113
+        $vars['VatReseting'] = __('Reseting...', 'invoicing');
114
+        $vars['VatValidated'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
115
+        $vars['VatNotValidated'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
116
+        $vars['ConfirmDeleteClass'] = __('Are you sure you wish to delete this rates class?', 'invoicing');
117 117
         $vars['isFront'] = is_admin() ? false : true;
118
-        $vars['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' );
118
+        $vars['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce');
119 119
         $vars['baseCountry'] = wpinv_get_default_country();
120
-        $vars['disableVATSameCountry'] = ( self::same_country_rule() == 'no' ? true : false );
121
-        $vars['disableVATSimpleCheck'] = wpinv_get_option( 'vat_offline_check' ) ? true : false;
120
+        $vars['disableVATSameCountry'] = (self::same_country_rule() == 'no' ? true : false);
121
+        $vars['disableVATSimpleCheck'] = wpinv_get_option('vat_offline_check') ? true : false;
122 122
         
123
-        wp_enqueue_script( 'wpinv-vat-validation-script' );
124
-        wp_enqueue_script( 'wpinv-vat-script' );
125
-        wp_localize_script( 'wpinv-vat-script', 'WPInv_VAT_Vars', $vars );
123
+        wp_enqueue_script('wpinv-vat-validation-script');
124
+        wp_enqueue_script('wpinv-vat-script');
125
+        wp_localize_script('wpinv-vat-script', 'WPInv_VAT_Vars', $vars);
126 126
     }
127 127
 
128 128
     public static function enqueue_admin_scripts() {
129
-        if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) {
129
+        if (isset($_GET['page']) && 'wpinv-settings' == $_GET['page']) {
130 130
             self::enqueue_vat_scripts();
131 131
         }
132 132
     }
133 133
     
134
-    public static function section_vat_settings( $sections ) {
135
-        if ( !empty( $sections ) ) {
136
-            $sections['vat'] = __( 'EU VAT Settings', 'invoicing' );
134
+    public static function section_vat_settings($sections) {
135
+        if (!empty($sections)) {
136
+            $sections['vat'] = __('EU VAT Settings', 'invoicing');
137 137
             
138
-            if ( self::allow_vat_classes() ) {
139
-                $sections['vat_rates'] = __( 'EU VAT Rates', 'invoicing' );
138
+            if (self::allow_vat_classes()) {
139
+                $sections['vat_rates'] = __('EU VAT Rates', 'invoicing');
140 140
             }
141 141
         }
142 142
         return $sections;
@@ -145,52 +145,52 @@  discard block
 block discarded – undo
145 145
     public static function vat_rates_settings() {
146 146
         $vat_classes = self::get_rate_classes();
147 147
         $vat_rates = array();
148
-        $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_new';
149
-        $current_url = remove_query_arg( 'wpi_sub' );
148
+        $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_new';
149
+        $current_url = remove_query_arg('wpi_sub');
150 150
         
151 151
         $vat_rates['vat_rates_header'] = array(
152 152
             'id' => 'vat_rates_header',
153
-            'name' => '<h3>' . __( 'Manage VAT Rates', 'invoicing' ) . '</h3>',
153
+            'name' => '<h3>' . __('Manage VAT Rates', 'invoicing') . '</h3>',
154 154
             'desc' => '',
155 155
             'type' => 'header',
156 156
             'size' => 'regular'
157 157
         );
158 158
         $vat_rates['vat_rates_class'] = array(
159 159
             'id'          => 'vat_rates_class',
160
-            'name'        => __( 'Edit VAT Rates', 'invoicing' ),
161
-            'desc'        => __( 'The standard rate will apply where no explicit rate is provided.', 'invoicing' ),
160
+            'name'        => __('Edit VAT Rates', 'invoicing'),
161
+            'desc'        => __('The standard rate will apply where no explicit rate is provided.', 'invoicing'),
162 162
             'type'        => 'select',
163
-            'options'     => array_merge( $vat_classes, array( '_new' => __( 'Add New Rate Class', 'invoicing' ) ) ),
163
+            'options'     => array_merge($vat_classes, array('_new' => __('Add New Rate Class', 'invoicing'))),
164 164
             'chosen'      => true,
165
-            'placeholder' => __( 'Select a VAT Rate', 'invoicing' ),
165
+            'placeholder' => __('Select a VAT Rate', 'invoicing'),
166 166
             'selected'    => $vat_class,
167 167
             'onchange'    => 'document.location.href="' . $current_url . '&wpi_sub=" + this.value;',
168 168
         );
169 169
         
170
-        if ( $vat_class != '_standard' && $vat_class != '_new' ) {
170
+        if ($vat_class != '_standard' && $vat_class != '_new') {
171 171
             $vat_rates['vat_rate_delete'] = array(
172 172
                 'id'   => 'vat_rate_delete',
173 173
                 'type' => 'vat_rate_delete',
174 174
             );
175 175
         }
176 176
                     
177
-        if ( $vat_class == '_new' ) {
177
+        if ($vat_class == '_new') {
178 178
             $vat_rates['vat_rates_settings'] = array(
179 179
                 'id' => 'vat_rates_settings',
180
-                'name' => '<h3>' . __( 'Add New Rate Class', 'invoicing' ) . '</h3>',
180
+                'name' => '<h3>' . __('Add New Rate Class', 'invoicing') . '</h3>',
181 181
                 'type' => 'header',
182 182
             );
183 183
             $vat_rates['vat_rate_name'] = array(
184 184
                 'id'   => 'vat_rate_name',
185
-                'name' => __( 'Name', 'invoicing' ),
186
-                'desc' => __( 'A short name for the new VAT Rate class', 'invoicing' ),
185
+                'name' => __('Name', 'invoicing'),
186
+                'desc' => __('A short name for the new VAT Rate class', 'invoicing'),
187 187
                 'type' => 'text',
188 188
                 'size' => 'regular',
189 189
             );
190 190
             $vat_rates['vat_rate_desc'] = array(
191 191
                 'id'   => 'vat_rate_desc',
192
-                'name' => __( 'Description', 'invoicing' ),
193
-                'desc' => __( 'Manage VAT Rate class', 'invoicing' ),
192
+                'name' => __('Description', 'invoicing'),
193
+                'desc' => __('Manage VAT Rate class', 'invoicing'),
194 194
                 'type' => 'text',
195 195
                 'size' => 'regular',
196 196
             );
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
             $vat_rates['vat_rates'] = array(
203 203
                 'id'   => 'vat_rates',
204 204
                 'name' => '<h3>' . $vat_classes[$vat_class] . '</h3>',
205
-                'desc' => self::get_class_desc( $vat_class ),
205
+                'desc' => self::get_class_desc($vat_class),
206 206
                 'type' => 'vat_rates',
207 207
             );
208 208
         }
@@ -210,12 +210,12 @@  discard block
 block discarded – undo
210 210
         return $vat_rates;
211 211
     }
212 212
     
213
-    public static function vat_settings( $settings ) {
214
-        if ( !empty( $settings ) ) {    
213
+    public static function vat_settings($settings) {
214
+        if (!empty($settings)) {    
215 215
             $vat_settings = array();
216 216
             $vat_settings['vat_company_title'] = array(
217 217
                 'id' => 'vat_company_title',
218
-                'name' => '<h3>' . __( 'Your Company Details', 'invoicing' ) . '</h3>',
218
+                'name' => '<h3>' . __('Your Company Details', 'invoicing') . '</h3>',
219 219
                 'desc' => '',
220 220
                 'type' => 'header',
221 221
                 'size' => 'regular'
@@ -223,22 +223,22 @@  discard block
 block discarded – undo
223 223
             
224 224
             $vat_settings['vat_company_name'] = array(
225 225
                 'id' => 'vat_company_name',
226
-                'name' => __( 'Your Company Name', 'invoicing' ),
227
-                'desc' => wp_sprintf(__( 'Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
226
+                'name' => __('Your Company Name', 'invoicing'),
227
+                'desc' => wp_sprintf(__('Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
228 228
                 'type' => 'text',
229 229
                 'size' => 'regular',
230 230
             );
231 231
             
232 232
             $vat_settings['vat_number'] = array(
233 233
                 'id'   => 'vat_number',
234
-                'name' => __( 'Your VAT Number', 'invoicing' ),
234
+                'name' => __('Your VAT Number', 'invoicing'),
235 235
                 'type' => 'vat_number',
236 236
                 'size' => 'regular',
237 237
             );
238 238
 
239 239
             $vat_settings['vat_settings_title'] = array(
240 240
                 'id' => 'vat_settings_title',
241
-                'name' => '<h3>' . __( 'Apply VAT Settings', 'invoicing' ) . '</h3>',
241
+                'name' => '<h3>' . __('Apply VAT Settings', 'invoicing') . '</h3>',
242 242
                 'desc' => '',
243 243
                 'type' => 'header',
244 244
                 'size' => 'regular'
@@ -246,8 +246,8 @@  discard block
 block discarded – undo
246 246
 
247 247
             $vat_settings['apply_vat_rules'] = array(
248 248
                 'id' => 'apply_vat_rules',
249
-                'name' => __( 'Enable VAT rules', 'invoicing' ),
250
-                'desc' => __( 'Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable unless you know what you are doing.', 'invoicing' ) . '</font>',
249
+                'name' => __('Enable VAT rules', 'invoicing'),
250
+                'desc' => __('Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable unless you know what you are doing.', 'invoicing') . '</font>',
251 251
                 'type' => 'checkbox',
252 252
                 'std' => '1'
253 253
             );
@@ -263,8 +263,8 @@  discard block
 block discarded – undo
263 263
 
264 264
             $vat_settings['vat_prevent_b2c_purchase'] = array(
265 265
                 'id' => 'vat_prevent_b2c_purchase',
266
-                'name' => __( 'Prevent EU B2C sales', 'invoicing' ),
267
-                'desc' => __( 'Enable this option if you are not registered for VAT in the EU.', 'invoicing' ),
266
+                'name' => __('Prevent EU B2C sales', 'invoicing'),
267
+                'desc' => __('Enable this option if you are not registered for VAT in the EU.', 'invoicing'),
268 268
                 'type' => 'checkbox'
269 269
             );
270 270
 
@@ -272,21 +272,21 @@  discard block
 block discarded – undo
272 272
 
273 273
             $vat_settings['vat_same_country_rule'] = array(
274 274
                 'id'          => 'vat_same_country_rule',
275
-                'name'        => __( 'Same country rule', 'invoicing' ),
276
-                'desc'        => __( 'Select how you want handle VAT charge if sales are in the same country as the base country.', 'invoicing' ),
275
+                'name'        => __('Same country rule', 'invoicing'),
276
+                'desc'        => __('Select how you want handle VAT charge if sales are in the same country as the base country.', 'invoicing'),
277 277
                 'type'        => 'select',
278 278
                 'options'     => array(
279
-                    ''          => __( 'Normal', 'invoicing' ),
280
-                    'no'        => __( 'No VAT', 'invoicing' ),
281
-                    'always'    => __( 'Always apply VAT', 'invoicing' ),
279
+                    ''          => __('Normal', 'invoicing'),
280
+                    'no'        => __('No VAT', 'invoicing'),
281
+                    'always'    => __('Always apply VAT', 'invoicing'),
282 282
                 ),
283
-                'placeholder' => __( 'Select a option', 'invoicing' ),
283
+                'placeholder' => __('Select a option', 'invoicing'),
284 284
                 'std'         => ''
285 285
             );
286 286
 
287 287
             $vat_settings['vat_checkout_title'] = array(
288 288
                 'id' => 'vat_checkout_title',
289
-                'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>',
289
+                'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>',
290 290
                 'desc' => '',
291 291
                 'type' => 'header',
292 292
                 'size' => 'regular'
@@ -294,14 +294,14 @@  discard block
 block discarded – undo
294 294
 
295 295
             $vat_settings['vat_disable_fields'] = array(
296 296
                 'id' => 'vat_disable_fields',
297
-                'name' => __( 'Disable VAT fields', 'invoicing' ),
298
-                'desc' => __( 'Disable VAT fields if Invoicing is being used for GST.', 'invoicing' ),
297
+                'name' => __('Disable VAT fields', 'invoicing'),
298
+                'desc' => __('Disable VAT fields if Invoicing is being used for GST.', 'invoicing'),
299 299
                 'type' => 'checkbox'
300 300
             );
301 301
 
302 302
             $vat_settings['vat_ip_lookup'] = array(
303 303
                 'id'   => 'vat_ip_lookup',
304
-                'name' => __( 'IP Country lookup', 'invoicing' ),
304
+                'name' => __('IP Country lookup', 'invoicing'),
305 305
                 'type' => 'vat_ip_lookup',
306 306
                 'size' => 'regular',
307 307
                 'std' => 'default'
@@ -309,21 +309,21 @@  discard block
 block discarded – undo
309 309
 
310 310
             $vat_settings['hide_ip_address'] = array(
311 311
                 'id' => 'hide_ip_address',
312
-                'name' => __( 'Hide IP info at checkout', 'invoicing' ),
313
-                'desc' => __( 'Hide the user IP info at checkout.', 'invoicing' ),
312
+                'name' => __('Hide IP info at checkout', 'invoicing'),
313
+                'desc' => __('Hide the user IP info at checkout.', 'invoicing'),
314 314
                 'type' => 'checkbox'
315 315
             );
316 316
 
317 317
             $vat_settings['vat_ip_country_default'] = array(
318 318
                 'id' => 'vat_ip_country_default',
319
-                'name' => __( 'Enable IP Country as Default', 'invoicing' ),
320
-                'desc' => __( 'Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing' ),
319
+                'name' => __('Enable IP Country as Default', 'invoicing'),
320
+                'desc' => __('Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing'),
321 321
                 'type' => 'checkbox'
322 322
             );
323 323
 
324 324
             $vat_settings['vies_validation_title'] = array(
325 325
                 'id' => 'vies_validation_title',
326
-                'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>',
326
+                'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>',
327 327
                 'desc' => '',
328 328
                 'type' => 'header',
329 329
                 'size' => 'regular'
@@ -331,37 +331,37 @@  discard block
 block discarded – undo
331 331
 
332 332
             $vat_settings['vat_vies_check'] = array(
333 333
                 'id' => 'vat_vies_check',
334
-                'name' => __( 'Disable VIES VAT ID check', 'invoicing' ),
335
-                'desc' => wp_sprintf( __( 'Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
334
+                'name' => __('Disable VIES VAT ID check', 'invoicing'),
335
+                'desc' => wp_sprintf(__('Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
336 336
                 'type' => 'checkbox'
337 337
             );
338 338
 
339 339
             $vat_settings['vat_disable_company_name_check'] = array(
340 340
                 'id' => 'vat_disable_company_name_check',
341
-                'name' => __( 'Disable VIES name check', 'invoicing' ),
342
-                'desc' => wp_sprintf( __( 'Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
341
+                'name' => __('Disable VIES name check', 'invoicing'),
342
+                'desc' => wp_sprintf(__('Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
343 343
                 'type' => 'checkbox'
344 344
             );
345 345
 
346 346
             $vat_settings['vat_offline_check'] = array(
347 347
                 'id' => 'vat_offline_check',
348
-                'name' => __( 'Disable basic checks', 'invoicing' ),
349
-                'desc' => __( 'This will disable basic JS correct format validation attempts, it is very rare this should need to be disabled.', 'invoicing' ),
348
+                'name' => __('Disable basic checks', 'invoicing'),
349
+                'desc' => __('This will disable basic JS correct format validation attempts, it is very rare this should need to be disabled.', 'invoicing'),
350 350
                 'type' => 'checkbox'
351 351
             );
352 352
             
353 353
 
354 354
             $settings['vat'] = $vat_settings;
355 355
             
356
-            if ( self::allow_vat_classes() ) {
356
+            if (self::allow_vat_classes()) {
357 357
                 $settings['vat_rates'] = self::vat_rates_settings();
358 358
             }
359 359
             
360 360
             $eu_fallback_rate = array(
361 361
                 'id'   => 'eu_fallback_rate',
362
-                'name' => '<h3>' . __( 'VAT rate for EU member states', 'invoicing' ) . '</h3>',
362
+                'name' => '<h3>' . __('VAT rate for EU member states', 'invoicing') . '</h3>',
363 363
                 'type' => 'eu_fallback_rate',
364
-                'desc' => __( 'Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing' ),
364
+                'desc' => __('Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing'),
365 365
                 'std'  => '20',
366 366
                 'size' => 'small'
367 367
             );
@@ -377,11 +377,11 @@  discard block
 block discarded – undo
377 377
         $database_url       = 'http' . (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === 'on' ? 's' : '') . '://geolite.maxmind.com/download/geoip/database/';
378 378
         $destination_dir    = $upload_dir['basedir'] . '/invoicing';
379 379
         
380
-        if ( !is_dir( $destination_dir ) ) { 
381
-            mkdir( $destination_dir );
380
+        if (!is_dir($destination_dir)) { 
381
+            mkdir($destination_dir);
382 382
         }
383 383
         
384
-        $database_files     = array(
384
+        $database_files = array(
385 385
             'country'   => array(
386 386
                 'source'        => $database_url . 'GeoLite2-Country.mmdb.gz',
387 387
                 'destination'   => $destination_dir . '/GeoLite2-Country.mmdb',
@@ -392,57 +392,57 @@  discard block
 block discarded – undo
392 392
             )
393 393
         );
394 394
 
395
-        foreach( $database_files as $database => $files ) {
396
-            $result = self::geoip2_download_file( $files['source'], $files['destination'] );
395
+        foreach ($database_files as $database => $files) {
396
+            $result = self::geoip2_download_file($files['source'], $files['destination']);
397 397
             
398
-            if ( empty( $result['success'] ) ) {
398
+            if (empty($result['success'])) {
399 399
                 echo $result['message'];
400 400
                 exit;
401 401
             }
402 402
             
403
-            wpinv_update_option( 'wpinv_geoip2_date_updated', current_time( 'timestamp' ) );
404
-            echo sprintf(__( 'GeoIp2 %s database updated successfully.', 'invoicing' ), $database ) . ' ';
403
+            wpinv_update_option('wpinv_geoip2_date_updated', current_time('timestamp'));
404
+            echo sprintf(__('GeoIp2 %s database updated successfully.', 'invoicing'), $database) . ' ';
405 405
         }
406 406
         
407 407
         exit;
408 408
     }
409 409
     
410
-    public static function geoip2_download_file( $source_url, $destination_file ) {
410
+    public static function geoip2_download_file($source_url, $destination_file) {
411 411
         $success    = false;
412 412
         $message    = '';
413 413
         
414
-        if ( !function_exists( 'download_url' ) ) {
415
-            require_once( ABSPATH . 'wp-admin/includes/file.php' );
414
+        if (!function_exists('download_url')) {
415
+            require_once(ABSPATH . 'wp-admin/includes/file.php');
416 416
         }
417 417
 
418
-        $temp_file  = download_url( $source_url );
418
+        $temp_file = download_url($source_url);
419 419
         
420
-        if ( is_wp_error( $temp_file ) ) {
421
-            $message = sprintf( __( 'Error while downloading GeoIp2 database( %s ): %s', 'invoicing' ), $source_url, $temp_file->get_error_message() );
420
+        if (is_wp_error($temp_file)) {
421
+            $message = sprintf(__('Error while downloading GeoIp2 database( %s ): %s', 'invoicing'), $source_url, $temp_file->get_error_message());
422 422
         } else {
423
-            $handle = gzopen( $temp_file, 'rb' );
423
+            $handle = gzopen($temp_file, 'rb');
424 424
             
425
-            if ( $handle ) {
426
-                $fopen  = fopen( $destination_file, 'wb' );
427
-                if ( $fopen ) {
428
-                    while ( ( $data = gzread( $handle, 4096 ) ) != false ) {
429
-                        fwrite( $fopen, $data );
425
+            if ($handle) {
426
+                $fopen = fopen($destination_file, 'wb');
427
+                if ($fopen) {
428
+                    while (($data = gzread($handle, 4096)) != false) {
429
+                        fwrite($fopen, $data);
430 430
                     }
431 431
 
432
-                    gzclose( $handle );
433
-                    fclose( $fopen );
432
+                    gzclose($handle);
433
+                    fclose($fopen);
434 434
                         
435 435
                     $success = true;
436 436
                 } else {
437
-                    gzclose( $handle );
438
-                    $message = sprintf( __( 'Error could not open destination GeoIp2 database file for writing: %s', 'invoicing' ), $destination_file );
437
+                    gzclose($handle);
438
+                    $message = sprintf(__('Error could not open destination GeoIp2 database file for writing: %s', 'invoicing'), $destination_file);
439 439
                 }
440 440
             } else {
441
-                $message = sprintf( __( 'Error could not open GeoIp2 database file for reading: %s', 'invoicing' ), $temp_file );
441
+                $message = sprintf(__('Error could not open GeoIp2 database file for reading: %s', 'invoicing'), $temp_file);
442 442
             }
443 443
             
444
-            if ( file_exists( $temp_file ) ) {
445
-                unlink( $temp_file );
444
+            if (file_exists($temp_file)) {
445
+                unlink($temp_file);
446 446
             }
447 447
         }
448 448
         
@@ -454,11 +454,11 @@  discard block
 block discarded – undo
454 454
     }
455 455
     
456 456
     public static function load_geoip2() {
457
-        if ( defined( 'WPINV_GEOIP2_LODDED' ) ) {
457
+        if (defined('WPINV_GEOIP2_LODDED')) {
458 458
             return;
459 459
         }
460 460
         
461
-        if ( !class_exists( '\MaxMind\Db\Reader' ) ) {
461
+        if (!class_exists('\MaxMind\Db\Reader')) {
462 462
             $maxmind_db_files = array(
463 463
                 'Reader/Decoder.php',
464 464
                 'Reader/InvalidDatabaseException.php',
@@ -467,12 +467,12 @@  discard block
 block discarded – undo
467 467
                 'Reader.php',
468 468
             );
469 469
             
470
-            foreach ( $maxmind_db_files as $key => $file ) {
471
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file );
470
+            foreach ($maxmind_db_files as $key => $file) {
471
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file);
472 472
             }
473 473
         }
474 474
         
475
-        if ( !class_exists( '\GeoIp2\Database\Reader' ) ) {        
475
+        if (!class_exists('\GeoIp2\Database\Reader')) {        
476 476
             $geoip2_files = array(
477 477
                 'ProviderInterface.php',
478 478
                 'Compat/JsonSerializable.php',
@@ -506,23 +506,23 @@  discard block
 block discarded – undo
506 506
                 'WebService/Client.php',
507 507
             );
508 508
             
509
-            foreach ( $geoip2_files as $key => $file ) {
510
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file );
509
+            foreach ($geoip2_files as $key => $file) {
510
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file);
511 511
             }
512 512
         }
513 513
 
514
-        define( 'WPINV_GEOIP2_LODDED', true );
514
+        define('WPINV_GEOIP2_LODDED', true);
515 515
     }
516 516
 
517 517
     public static function geoip2_country_dbfile() {
518 518
         $upload_dir = wp_upload_dir();
519 519
 
520
-        if ( !isset( $upload_dir['basedir'] ) ) {
520
+        if (!isset($upload_dir['basedir'])) {
521 521
             return false;
522 522
         }
523 523
 
524 524
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-Country.mmdb';
525
-        if ( !file_exists( $filename ) ) {
525
+        if (!file_exists($filename)) {
526 526
             return false;
527 527
         }
528 528
         
@@ -532,12 +532,12 @@  discard block
 block discarded – undo
532 532
     public static function geoip2_city_dbfile() {
533 533
         $upload_dir = wp_upload_dir();
534 534
 
535
-        if ( !isset( $upload_dir['basedir'] ) ) {
535
+        if (!isset($upload_dir['basedir'])) {
536 536
             return false;
537 537
         }
538 538
 
539 539
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-City.mmdb';
540
-        if ( !file_exists( $filename ) ) {
540
+        if (!file_exists($filename)) {
541 541
             return false;
542 542
         }
543 543
         
@@ -548,10 +548,10 @@  discard block
 block discarded – undo
548 548
         try {
549 549
             self::load_geoip2();
550 550
 
551
-            if ( $filename = self::geoip2_country_dbfile() ) {
552
-                return new \GeoIp2\Database\Reader( $filename );
551
+            if ($filename = self::geoip2_country_dbfile()) {
552
+                return new \GeoIp2\Database\Reader($filename);
553 553
             }
554
-        } catch( Exception $e ) {
554
+        } catch (Exception $e) {
555 555
             return false;
556 556
         }
557 557
         
@@ -562,173 +562,173 @@  discard block
 block discarded – undo
562 562
         try {
563 563
             self::load_geoip2();
564 564
 
565
-            if ( $filename = self::geoip2_city_dbfile() ) {
566
-                return new \GeoIp2\Database\Reader( $filename );
565
+            if ($filename = self::geoip2_city_dbfile()) {
566
+                return new \GeoIp2\Database\Reader($filename);
567 567
             }
568
-        } catch( Exception $e ) {
568
+        } catch (Exception $e) {
569 569
             return false;
570 570
         }
571 571
         
572 572
         return false;
573 573
     }
574 574
 
575
-    public static function geoip2_country_record( $ip_address ) {
575
+    public static function geoip2_country_record($ip_address) {
576 576
         try {
577 577
             $reader = self::geoip2_country_reader();
578 578
 
579
-            if ( $reader ) {
580
-                $record = $reader->country( $ip_address );
579
+            if ($reader) {
580
+                $record = $reader->country($ip_address);
581 581
                 
582
-                if ( !empty( $record->country->isoCode ) ) {
582
+                if (!empty($record->country->isoCode)) {
583 583
                     return $record;
584 584
                 }
585 585
             }
586
-        } catch(\InvalidArgumentException $e) {
587
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
586
+        } catch (\InvalidArgumentException $e) {
587
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
588 588
             
589 589
             return false;
590
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
591
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
590
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
591
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
592 592
             
593 593
             return false;
594
-        } catch( Exception $e ) {
594
+        } catch (Exception $e) {
595 595
             return false;
596 596
         }
597 597
         
598 598
         return false;
599 599
     }
600 600
 
601
-    public static function geoip2_city_record( $ip_address ) {
601
+    public static function geoip2_city_record($ip_address) {
602 602
         try {
603 603
             $reader = self::geoip2_city_reader();
604 604
 
605
-            if ( $reader ) {
606
-                $record = $reader->city( $ip_address );
605
+            if ($reader) {
606
+                $record = $reader->city($ip_address);
607 607
                 
608
-                if ( !empty( $record->country->isoCode ) ) {
608
+                if (!empty($record->country->isoCode)) {
609 609
                     return $record;
610 610
                 }
611 611
             }
612
-        } catch(\InvalidArgumentException $e) {
613
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
612
+        } catch (\InvalidArgumentException $e) {
613
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
614 614
             
615 615
             return false;
616
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
617
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
616
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
617
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
618 618
             
619 619
             return false;
620
-        } catch( Exception $e ) {
620
+        } catch (Exception $e) {
621 621
             return false;
622 622
         }
623 623
         
624 624
         return false;
625 625
     }
626 626
 
627
-    public static function geoip2_country_code( $ip_address ) {
628
-        $record = self::geoip2_country_record( $ip_address );
629
-        return !empty( $record->country->isoCode ) ? $record->country->isoCode : wpinv_get_default_country();
627
+    public static function geoip2_country_code($ip_address) {
628
+        $record = self::geoip2_country_record($ip_address);
629
+        return !empty($record->country->isoCode) ? $record->country->isoCode : wpinv_get_default_country();
630 630
     }
631 631
 
632 632
     // Find country by IP address.
633
-    public static function get_country_by_ip( $ip = '' ) {
633
+    public static function get_country_by_ip($ip = '') {
634 634
         global $wpinv_ip_address_country;
635 635
         
636
-        if ( !empty( $wpinv_ip_address_country ) ) {
636
+        if (!empty($wpinv_ip_address_country)) {
637 637
             return $wpinv_ip_address_country;
638 638
         }
639 639
         
640
-        if ( empty( $ip ) ) {
640
+        if (empty($ip)) {
641 641
             $ip = wpinv_get_ip();
642 642
         }
643 643
 
644
-        $ip_country_service = wpinv_get_option( 'vat_ip_lookup' );
645
-        $is_default         = empty( $ip_country_service ) || $ip_country_service === 'default' ? true : false;
644
+        $ip_country_service = wpinv_get_option('vat_ip_lookup');
645
+        $is_default         = empty($ip_country_service) || $ip_country_service === 'default' ? true : false;
646 646
 
647
-        if ( !empty( $ip ) && $ip !== '127.0.0.1' ) { // For 127.0.0.1(localhost) use default country.
648
-            if ( function_exists( 'geoip_country_code_by_name') && ( $ip_country_service === 'geoip' || $is_default ) ) {
647
+        if (!empty($ip) && $ip !== '127.0.0.1') { // For 127.0.0.1(localhost) use default country.
648
+            if (function_exists('geoip_country_code_by_name') && ($ip_country_service === 'geoip' || $is_default)) {
649 649
                 try {
650
-                    $wpinv_ip_address_country = geoip_country_code_by_name( $ip );
651
-                } catch( Exception $e ) {
652
-                    wpinv_error_log( $e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )' );
650
+                    $wpinv_ip_address_country = geoip_country_code_by_name($ip);
651
+                } catch (Exception $e) {
652
+                    wpinv_error_log($e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )');
653 653
                 }
654
-            } else if ( self::geoip2_country_dbfile() && ( $ip_country_service === 'geoip2' || $is_default ) ) {
655
-                $wpinv_ip_address_country = self::geoip2_country_code( $ip );
656
-            } else if ( function_exists( 'simplexml_load_file' ) && ( $ip_country_service === 'geoplugin' || $is_default ) ) {
657
-                $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
654
+            } else if (self::geoip2_country_dbfile() && ($ip_country_service === 'geoip2' || $is_default)) {
655
+                $wpinv_ip_address_country = self::geoip2_country_code($ip);
656
+            } else if (function_exists('simplexml_load_file') && ($ip_country_service === 'geoplugin' || $is_default)) {
657
+                $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
658 658
                 
659
-                if ( !empty( $load_xml ) && !empty( $load_xml->geoplugin_countryCode ) ) {
659
+                if (!empty($load_xml) && !empty($load_xml->geoplugin_countryCode)) {
660 660
                     $wpinv_ip_address_country = (string)$load_xml->geoplugin_countryCode;
661 661
                 }
662 662
             }
663 663
         }
664 664
 
665
-        if ( empty( $wpinv_ip_address_country ) ) {
665
+        if (empty($wpinv_ip_address_country)) {
666 666
             $wpinv_ip_address_country = wpinv_get_default_country();
667 667
         }
668 668
 
669 669
         return $wpinv_ip_address_country;
670 670
     }
671 671
     
672
-    public static function sanitize_vat_settings( $input ) {
672
+    public static function sanitize_vat_settings($input) {
673 673
         global $wpinv_options;
674 674
         
675 675
         $valid      = false;
676 676
         $message    = '';
677 677
         
678
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
679
-            if ( empty( $wpinv_options['vat_offline_check'] ) ) {
680
-                $valid = self::offline_check( $input['vat_number'] );
678
+        if (!empty($wpinv_options['vat_vies_check'])) {
679
+            if (empty($wpinv_options['vat_offline_check'])) {
680
+                $valid = self::offline_check($input['vat_number']);
681 681
             } else {
682 682
                 $valid = true;
683 683
             }
684 684
             
685
-            $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' );
685
+            $message = $valid ? '' : __('VAT number not validated', 'invoicing');
686 686
         } else {
687
-            $result = self::check_vat( $input['vat_number'] );
687
+            $result = self::check_vat($input['vat_number']);
688 688
             
689
-            if ( empty( $result['valid'] ) ) {
689
+            if (empty($result['valid'])) {
690 690
                 $valid      = false;
691 691
                 $message    = $result['message'];
692 692
             } else {
693
-                $valid      = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] );
694
-                $message    = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' );
693
+                $valid      = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']);
694
+                $message    = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing');
695 695
             }
696 696
         }
697 697
 
698
-        if ( $message && self::is_vat_validated() != $valid ) {
699
-            add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) );
698
+        if ($message && self::is_vat_validated() != $valid) {
699
+            add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error'));
700 700
         }
701 701
 
702 702
         $input['vat_valid'] = $valid;
703 703
         return $input;
704 704
     }
705 705
     
706
-    public static function sanitize_vat_rates( $input ) {
707
-        if( !current_user_can( 'manage_options' ) ) {
708
-            add_settings_error( 'wpinv-notices', '', __( 'Your account does not have permission to add rate classes.', 'invoicing' ), 'error' );
706
+    public static function sanitize_vat_rates($input) {
707
+        if (!current_user_can('manage_options')) {
708
+            add_settings_error('wpinv-notices', '', __('Your account does not have permission to add rate classes.', 'invoicing'), 'error');
709 709
             return $input;
710 710
         }
711 711
         
712 712
         $vat_classes = self::get_rate_classes();
713
-        $vat_class = !empty( $_REQUEST['wpi_vat_class'] ) && isset( $vat_classes[$_REQUEST['wpi_vat_class']] )? sanitize_text_field( $_REQUEST['wpi_vat_class'] ) : '';
713
+        $vat_class = !empty($_REQUEST['wpi_vat_class']) && isset($vat_classes[$_REQUEST['wpi_vat_class']]) ? sanitize_text_field($_REQUEST['wpi_vat_class']) : '';
714 714
         
715
-        if ( empty( $vat_class ) ) {
716
-            add_settings_error( 'wpinv-notices', '', __( 'No valid VAT rates class contained in the request to save rates.', 'invoicing' ), 'error' );
715
+        if (empty($vat_class)) {
716
+            add_settings_error('wpinv-notices', '', __('No valid VAT rates class contained in the request to save rates.', 'invoicing'), 'error');
717 717
             
718 718
             return $input;
719 719
         }
720 720
 
721
-        $new_rates = ! empty( $_POST['vat_rates'] ) ? array_values( $_POST['vat_rates'] ) : array();
721
+        $new_rates = !empty($_POST['vat_rates']) ? array_values($_POST['vat_rates']) : array();
722 722
 
723
-        if ( $vat_class === '_standard' ) {
723
+        if ($vat_class === '_standard') {
724 724
             // Save the active rates in the invoice settings
725
-            update_option( 'wpinv_tax_rates', $new_rates );
725
+            update_option('wpinv_tax_rates', $new_rates);
726 726
         } else {
727 727
             // Get the existing set of rates
728 728
             $rates = self::get_non_standard_rates();
729 729
             $rates[$vat_class] = $new_rates;
730 730
 
731
-            update_option( 'wpinv_vat_rates', $rates );
731
+            update_option('wpinv_vat_rates', $rates);
732 732
         }
733 733
         
734 734
         return $input;
@@ -738,71 +738,71 @@  discard block
 block discarded – undo
738 738
         $response = array();
739 739
         $response['success'] = false;
740 740
         
741
-        if ( !current_user_can( 'manage_options' ) ) {
742
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
743
-            wp_send_json( $response );
741
+        if (!current_user_can('manage_options')) {
742
+            $response['error'] = __('Invalid access!', 'invoicing');
743
+            wp_send_json($response);
744 744
         }
745 745
         
746
-        $vat_class_name = !empty( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false;
747
-        $vat_class_desc = !empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : false;
746
+        $vat_class_name = !empty($_POST['name']) ? sanitize_text_field($_POST['name']) : false;
747
+        $vat_class_desc = !empty($_POST['desc']) ? sanitize_text_field($_POST['desc']) : false;
748 748
         
749
-        if ( empty( $vat_class_name ) ) {
750
-            $response['error'] = __( 'Select the VAT rate name', 'invoicing' );
751
-            wp_send_json( $response );
749
+        if (empty($vat_class_name)) {
750
+            $response['error'] = __('Select the VAT rate name', 'invoicing');
751
+            wp_send_json($response);
752 752
         }
753 753
         
754 754
         $vat_classes = (array)self::get_rate_classes();
755 755
 
756
-        if ( !empty( $vat_classes ) && in_array( strtolower( $vat_class_name ), array_map( 'strtolower', array_values( $vat_classes ) ) ) ) {
757
-            $response['error'] = wp_sprintf( __( 'A VAT Rate name "%s" already exists', 'invoicing' ), $vat_class_name );
758
-            wp_send_json( $response );
756
+        if (!empty($vat_classes) && in_array(strtolower($vat_class_name), array_map('strtolower', array_values($vat_classes)))) {
757
+            $response['error'] = wp_sprintf(__('A VAT Rate name "%s" already exists', 'invoicing'), $vat_class_name);
758
+            wp_send_json($response);
759 759
         }
760 760
         
761
-        $rate_class_key = normalize_whitespace( 'wpi-' . $vat_class_name );
762
-        $rate_class_key = sanitize_key( str_replace( " ", "-", $rate_class_key ) );
761
+        $rate_class_key = normalize_whitespace('wpi-' . $vat_class_name);
762
+        $rate_class_key = sanitize_key(str_replace(" ", "-", $rate_class_key));
763 763
         
764
-        $vat_classes = (array)self::get_rate_classes( true );
765
-        $vat_classes[$rate_class_key] = array( 'name' => $vat_class_name, 'desc' => $vat_class_desc );
764
+        $vat_classes = (array)self::get_rate_classes(true);
765
+        $vat_classes[$rate_class_key] = array('name' => $vat_class_name, 'desc' => $vat_class_desc);
766 766
         
767
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
767
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
768 768
         
769 769
         $response['success'] = true;
770
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key );
770
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key);
771 771
         
772
-        wp_send_json( $response );
772
+        wp_send_json($response);
773 773
     }
774 774
     
775 775
     public static function delete_class() {
776 776
         $response = array();
777 777
         $response['success'] = false;
778 778
         
779
-        if ( !current_user_can( 'manage_options' ) || !isset( $_POST['class'] ) ) {
780
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
781
-            wp_send_json( $response );
779
+        if (!current_user_can('manage_options') || !isset($_POST['class'])) {
780
+            $response['error'] = __('Invalid access!', 'invoicing');
781
+            wp_send_json($response);
782 782
         }
783 783
         
784
-        $vat_class = isset( $_POST['class'] ) && $_POST['class'] !== '' ? sanitize_text_field( $_POST['class'] ) : false;
784
+        $vat_class = isset($_POST['class']) && $_POST['class'] !== '' ? sanitize_text_field($_POST['class']) : false;
785 785
         $vat_classes = (array)self::get_rate_classes();
786 786
 
787
-        if ( !isset( $vat_classes[$vat_class] ) ) {
788
-            $response['error'] = __( 'Requested class does not exists', 'invoicing' );
789
-            wp_send_json( $response );
787
+        if (!isset($vat_classes[$vat_class])) {
788
+            $response['error'] = __('Requested class does not exists', 'invoicing');
789
+            wp_send_json($response);
790 790
         }
791 791
         
792
-        if ( $vat_class == '_new' || $vat_class == '_standard' ) {
793
-            $response['error'] = __( 'You can not delete standard rates class', 'invoicing' );
794
-            wp_send_json( $response );
792
+        if ($vat_class == '_new' || $vat_class == '_standard') {
793
+            $response['error'] = __('You can not delete standard rates class', 'invoicing');
794
+            wp_send_json($response);
795 795
         }
796 796
             
797
-        $vat_classes = (array)self::get_rate_classes( true );
798
-        unset( $vat_classes[$vat_class] );
797
+        $vat_classes = (array)self::get_rate_classes(true);
798
+        unset($vat_classes[$vat_class]);
799 799
         
800
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
800
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
801 801
         
802 802
         $response['success'] = true;
803
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new' );
803
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new');
804 804
         
805
-        wp_send_json( $response );
805
+        wp_send_json($response);
806 806
     }
807 807
     
808 808
     public static function update_eu_rates() {        
@@ -811,72 +811,72 @@  discard block
 block discarded – undo
811 811
         $response['error']      = null;
812 812
         $response['data']       = null;
813 813
         
814
-        if ( !current_user_can( 'manage_options' ) ) {
815
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
816
-            wp_send_json( $response );
814
+        if (!current_user_can('manage_options')) {
815
+            $response['error'] = __('Invalid access!', 'invoicing');
816
+            wp_send_json($response);
817 817
         }
818 818
         
819
-        $group      = !empty( $_POST['group'] ) ? sanitize_text_field( $_POST['group'] ) : '';
820
-        $euvatrates = self::request_euvatrates( $group );
819
+        $group      = !empty($_POST['group']) ? sanitize_text_field($_POST['group']) : '';
820
+        $euvatrates = self::request_euvatrates($group);
821 821
         
822
-        if ( !empty( $euvatrates ) ) {
823
-            if ( !empty( $euvatrates['success'] ) && !empty( $euvatrates['rates'] ) ) {
822
+        if (!empty($euvatrates)) {
823
+            if (!empty($euvatrates['success']) && !empty($euvatrates['rates'])) {
824 824
                 $response['success']        = true;
825 825
                 $response['data']['rates']  = $euvatrates['rates'];
826
-            } else if ( !empty( $euvatrates['error'] ) ) {
826
+            } else if (!empty($euvatrates['error'])) {
827 827
                 $response['error']          = $euvatrates['error'];
828 828
             }
829 829
         }
830 830
             
831
-        wp_send_json( $response );
831
+        wp_send_json($response);
832 832
     }
833 833
     
834 834
     public static function hide_vat_fields() {
835
-        $hide = wpinv_get_option( 'vat_disable_fields' );
835
+        $hide = wpinv_get_option('vat_disable_fields');
836 836
         
837
-        return apply_filters( 'wpinv_hide_vat_fields', $hide );
837
+        return apply_filters('wpinv_hide_vat_fields', $hide);
838 838
     }
839 839
     
840 840
     public static function same_country_rule() {
841
-        $same_country_rule = wpinv_get_option( 'vat_same_country_rule' );
841
+        $same_country_rule = wpinv_get_option('vat_same_country_rule');
842 842
         
843
-        return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule );
843
+        return apply_filters('wpinv_vat_same_country_rule', $same_country_rule);
844 844
     }
845 845
     
846 846
     public static function get_vat_name() {
847
-        $vat_name   = wpinv_get_option( 'vat_name' );
848
-        $vat_name   = !empty( $vat_name ) ? $vat_name : 'VAT';
847
+        $vat_name   = wpinv_get_option('vat_name');
848
+        $vat_name   = !empty($vat_name) ? $vat_name : 'VAT';
849 849
         
850
-        return apply_filters( 'wpinv_get_owner_vat_name', $vat_name );
850
+        return apply_filters('wpinv_get_owner_vat_name', $vat_name);
851 851
     }
852 852
     
853 853
     public static function get_company_name() {
854
-        $company_name = wpinv_get_option( 'vat_company_name' );
854
+        $company_name = wpinv_get_option('vat_company_name');
855 855
         
856
-        return apply_filters( 'wpinv_get_owner_company_name', $company_name );
856
+        return apply_filters('wpinv_get_owner_company_name', $company_name);
857 857
     }
858 858
     
859 859
     public static function get_vat_number() {
860
-        $vat_number = wpinv_get_option( 'vat_number' );
860
+        $vat_number = wpinv_get_option('vat_number');
861 861
         
862
-        return apply_filters( 'wpinv_get_owner_vat_number', $vat_number );
862
+        return apply_filters('wpinv_get_owner_vat_number', $vat_number);
863 863
     }
864 864
     
865 865
     public static function is_vat_validated() {
866
-        $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' );
866
+        $validated = self::get_vat_number() && wpinv_get_option('vat_valid');
867 867
         
868
-        return apply_filters( 'wpinv_is_owner_vat_validated', $validated );
868
+        return apply_filters('wpinv_is_owner_vat_validated', $validated);
869 869
     }
870 870
     
871
-    public static function sanitize_vat( $vat_number, $country_code = '' ) {        
872
-        $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) );
871
+    public static function sanitize_vat($vat_number, $country_code = '') {        
872
+        $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number)));
873 873
         
874
-        if ( empty( $country_code ) ) {
875
-            $country_code = substr( $vat_number, 0, 2 );
874
+        if (empty($country_code)) {
875
+            $country_code = substr($vat_number, 0, 2);
876 876
         }
877 877
         
878
-        if ( strpos( $vat_number , $country_code ) === 0 ) {
879
-            $vat = str_replace( $country_code, '', $vat_number );
878
+        if (strpos($vat_number, $country_code) === 0) {
879
+            $vat = str_replace($country_code, '', $vat_number);
880 880
         } else {
881 881
             $vat = $country_code . $vat_number;
882 882
         }
@@ -889,140 +889,140 @@  discard block
 block discarded – undo
889 889
         return $return;
890 890
     }
891 891
     
892
-    public static function offline_check( $vat_number, $country_code = '', $formatted = false ) {
893
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
892
+    public static function offline_check($vat_number, $country_code = '', $formatted = false) {
893
+        $vat            = self::sanitize_vat($vat_number, $country_code);
894 894
         $vat_number     = $vat['vat_number'];
895 895
         $country_code   = $vat['iso'];
896 896
         $regex          = array();
897 897
         
898
-        switch ( $country_code ) {
898
+        switch ($country_code) {
899 899
             case 'AT':
900
-                $regex[] = '/^(AT)U(\d{8})$/';                           // Austria
900
+                $regex[] = '/^(AT)U(\d{8})$/'; // Austria
901 901
                 break;
902 902
             case 'BE':
903
-                $regex[] = '/^(BE)(0?\d{9})$/';                          // Belgium
903
+                $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium
904 904
                 break;
905 905
             case 'BG':
906
-                $regex[] = '/^(BG)(\d{9,10})$/';                         // Bulgaria
906
+                $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria
907 907
                 break;
908 908
             case 'CH':
909 909
             case 'CHE':
910
-                $regex[] = '/^(CHE)(\d{9})MWST$/';                       // Switzerland (Not EU)
910
+                $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU)
911 911
                 break;
912 912
             case 'CY':
913
-                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/';                // Cyprus
913
+                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus
914 914
                 break;
915 915
             case 'CZ':
916
-                $regex[] = '/^(CZ)(\d{8,13})$/';                         // Czech Republic
916
+                $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic
917 917
                 break;
918 918
             case 'DE':
919
-                $regex[] = '/^(DE)([1-9]\d{8})$/';                       // Germany
919
+                $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany
920 920
                 break;
921 921
             case 'DK':
922
-                $regex[] = '/^(DK)(\d{8})$/';                            // Denmark
922
+                $regex[] = '/^(DK)(\d{8})$/'; // Denmark
923 923
                 break;
924 924
             case 'EE':
925
-                $regex[] = '/^(EE)(10\d{7})$/';                          // Estonia
925
+                $regex[] = '/^(EE)(10\d{7})$/'; // Estonia
926 926
                 break;
927 927
             case 'EL':
928
-                $regex[] = '/^(EL)(\d{9})$/';                            // Greece
928
+                $regex[] = '/^(EL)(\d{9})$/'; // Greece
929 929
                 break;
930 930
             case 'ES':
931
-                $regex[] = '/^(ES)([A-Z]\d{8})$/';                       // Spain (National juridical entities)
932
-                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/';            // Spain (Other juridical entities)
933
-                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/';              // Spain (Personal entities type 1)
934
-                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/';              // Spain (Personal entities type 2)
931
+                $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities)
932
+                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities)
933
+                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1)
934
+                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2)
935 935
                 break;
936 936
             case 'EU':
937
-                $regex[] = '/^(EU)(\d{9})$/';                            // EU-type
937
+                $regex[] = '/^(EU)(\d{9})$/'; // EU-type
938 938
                 break;
939 939
             case 'FI':
940
-                $regex[] = '/^(FI)(\d{8})$/';                            // Finland
940
+                $regex[] = '/^(FI)(\d{8})$/'; // Finland
941 941
                 break;
942 942
             case 'FR':
943
-                $regex[] = '/^(FR)(\d{11})$/';                           // France (1)
944
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/';        // France (2)
945
-                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/';       // France (3)
946
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/';      // France (4)
943
+                $regex[] = '/^(FR)(\d{11})$/'; // France (1)
944
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2)
945
+                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3)
946
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4)
947 947
                 break;
948 948
             case 'GB':
949
-                $regex[] = '/^(GB)?(\d{9})$/';                           // UK (Standard)
950
-                $regex[] = '/^(GB)?(\d{12})$/';                          // UK (Branches)
951
-                $regex[] = '/^(GB)?(GD\d{3})$/';                         // UK (Government)
952
-                $regex[] = '/^(GB)?(HA\d{3})$/';                         // UK (Health authority)
949
+                $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard)
950
+                $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches)
951
+                $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government)
952
+                $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority)
953 953
                 break;
954 954
             case 'GR':
955
-                $regex[] = '/^(GR)(\d{8,9})$/';                          // Greece
955
+                $regex[] = '/^(GR)(\d{8,9})$/'; // Greece
956 956
                 break;
957 957
             case 'HR':
958
-                $regex[] = '/^(HR)(\d{11})$/';                           // Croatia
958
+                $regex[] = '/^(HR)(\d{11})$/'; // Croatia
959 959
                 break;
960 960
             case 'HU':
961
-                $regex[] = '/^(HU)(\d{8})$/';                            // Hungary
961
+                $regex[] = '/^(HU)(\d{8})$/'; // Hungary
962 962
                 break;
963 963
             case 'IE':
964
-                $regex[] = '/^(IE)(\d{7}[A-W])$/';                       // Ireland (1)
965
-                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/';        // Ireland (2)
966
-                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/';                   // Ireland (3) (new format from 1 Jan 2013)
964
+                $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1)
965
+                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2)
966
+                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013)
967 967
                 break;
968 968
             case 'IT':
969
-                $regex[] = '/^(IT)(\d{11})$/';                           // Italy
969
+                $regex[] = '/^(IT)(\d{11})$/'; // Italy
970 970
                 break;
971 971
             case 'LV':
972
-                $regex[] = '/^(LV)(\d{11})$/';                           // Latvia
972
+                $regex[] = '/^(LV)(\d{11})$/'; // Latvia
973 973
                 break;
974 974
             case 'LT':
975
-                $regex[] = '/^(LT)(\d{9}|\d{12})$/';                     // Lithuania
975
+                $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania
976 976
                 break;
977 977
             case 'LU':
978
-                $regex[] = '/^(LU)(\d{8})$/';                            // Luxembourg
978
+                $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg
979 979
                 break;
980 980
             case 'MT':
981
-                $regex[] = '/^(MT)([1-9]\d{7})$/';                       // Malta
981
+                $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta
982 982
                 break;
983 983
             case 'NL':
984
-                $regex[] = '/^(NL)(\d{9})B\d{2}$/';                      // Netherlands
984
+                $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands
985 985
                 break;
986 986
             case 'NO':
987
-                $regex[] = '/^(NO)(\d{9})$/';                            // Norway (Not EU)
987
+                $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU)
988 988
                 break;
989 989
             case 'PL':
990
-                $regex[] = '/^(PL)(\d{10})$/';                           // Poland
990
+                $regex[] = '/^(PL)(\d{10})$/'; // Poland
991 991
                 break;
992 992
             case 'PT':
993
-                $regex[] = '/^(PT)(\d{9})$/';                            // Portugal
993
+                $regex[] = '/^(PT)(\d{9})$/'; // Portugal
994 994
                 break;
995 995
             case 'RO':
996
-                $regex[] = '/^(RO)([1-9]\d{1,9})$/';                     // Romania
996
+                $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania
997 997
                 break;
998 998
             case 'RS':
999
-                $regex[] = '/^(RS)(\d{9})$/';                            // Serbia (Not EU)
999
+                $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU)
1000 1000
                 break;
1001 1001
             case 'SI':
1002
-                $regex[] = '/^(SI)([1-9]\d{7})$/';                       // Slovenia
1002
+                $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia
1003 1003
                 break;
1004 1004
             case 'SK':
1005
-                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/';        // Slovakia Republic
1005
+                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic
1006 1006
                 break;
1007 1007
             case 'SE':
1008
-                $regex[] = '/^(SE)(\d{10}01)$/';                         // Sweden
1008
+                $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden
1009 1009
                 break;
1010 1010
             default:
1011 1011
                 $regex = array();
1012 1012
             break;
1013 1013
         }
1014 1014
         
1015
-        if ( empty( $regex ) ) {
1015
+        if (empty($regex)) {
1016 1016
             return false;
1017 1017
         }
1018 1018
         
1019
-        foreach ( $regex as $pattern ) {
1019
+        foreach ($regex as $pattern) {
1020 1020
             $matches = null;
1021
-            preg_match_all( $pattern, $vat_number, $matches );
1021
+            preg_match_all($pattern, $vat_number, $matches);
1022 1022
             
1023
-            if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) {
1024
-                if ( $formatted ) {
1025
-                    return array( 'code' => $matches[1][0], 'number' => $matches[2][0] );
1023
+            if (!empty($matches[1][0]) && !empty($matches[2][0])) {
1024
+                if ($formatted) {
1025
+                    return array('code' => $matches[1][0], 'number' => $matches[2][0]);
1026 1026
                 } else {
1027 1027
                     return true;
1028 1028
                 }
@@ -1032,75 +1032,75 @@  discard block
 block discarded – undo
1032 1032
         return false;
1033 1033
     }
1034 1034
     
1035
-    public static function vies_check( $vat_number, $country_code = '', $result = false ) {
1036
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
1035
+    public static function vies_check($vat_number, $country_code = '', $result = false) {
1036
+        $vat            = self::sanitize_vat($vat_number, $country_code);
1037 1037
         $vat_number     = $vat['vat'];
1038 1038
         $iso            = $vat['iso'];
1039 1039
         
1040
-        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number );
1040
+        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number);
1041 1041
         
1042
-        if ( ini_get( 'allow_url_fopen' ) ) {
1043
-            $response = file_get_contents( $url );
1044
-        } else if ( function_exists( 'curl_init' ) ) {
1042
+        if (ini_get('allow_url_fopen')) {
1043
+            $response = file_get_contents($url);
1044
+        } else if (function_exists('curl_init')) {
1045 1045
             $ch = curl_init();
1046 1046
             
1047
-            curl_setopt( $ch, CURLOPT_URL, $url );
1048
-            curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 );
1049
-            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
1050
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
1051
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
1047
+            curl_setopt($ch, CURLOPT_URL, $url);
1048
+            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
1049
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1050
+            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
1051
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
1052 1052
             
1053
-            $response = curl_exec( $ch );
1053
+            $response = curl_exec($ch);
1054 1054
             
1055
-            if ( curl_errno( $ch ) ) {
1056
-                wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' );
1055
+            if (curl_errno($ch)) {
1056
+                wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR');
1057 1057
                 $response = '';
1058 1058
             }
1059 1059
             
1060
-            curl_close( $ch );
1060
+            curl_close($ch);
1061 1061
         } else {
1062
-            wpinv_error_log( 'To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR' );
1062
+            wpinv_error_log('To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR');
1063 1063
         }
1064 1064
         
1065
-        if ( empty( $response ) ) {
1065
+        if (empty($response)) {
1066 1066
             return $result;
1067 1067
         }
1068 1068
 
1069
-        if ( preg_match( '/invalid VAT number/i', $response ) ) {
1069
+        if (preg_match('/invalid VAT number/i', $response)) {
1070 1070
             return false;
1071
-        } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) {
1072
-            $content = explode( "valid VAT number", htmlentities( $response ) );
1071
+        } else if (preg_match('/valid VAT number/i', $response, $matches)) {
1072
+            $content = explode("valid VAT number", htmlentities($response));
1073 1073
             
1074
-            if ( !empty( $content[1] ) ) {
1075
-                preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches );
1074
+            if (!empty($content[1])) {
1075
+                preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches);
1076 1076
                 
1077
-                if ( !empty( $matches[2] ) && $matches[3] ) {
1077
+                if (!empty($matches[2]) && $matches[3]) {
1078 1078
                     $return = array();
1079 1079
                     
1080
-                    foreach ( $matches[2] as $key => $label ) {
1081
-                        $label = trim( $label );
1080
+                    foreach ($matches[2] as $key => $label) {
1081
+                        $label = trim($label);
1082 1082
                         
1083
-                        switch ( strtolower( $label ) ) {
1083
+                        switch (strtolower($label)) {
1084 1084
                             case 'member state':
1085
-                                $return['state'] = trim( strip_tags( $matches[3][$key] ) );
1085
+                                $return['state'] = trim(strip_tags($matches[3][$key]));
1086 1086
                             break;
1087 1087
                             case 'vat number':
1088
-                                $return['number'] = trim( strip_tags( $matches[3][$key] ) );
1088
+                                $return['number'] = trim(strip_tags($matches[3][$key]));
1089 1089
                             break;
1090 1090
                             case 'name':
1091
-                                $return['company'] = trim( strip_tags( $matches[3][$key] ) );
1091
+                                $return['company'] = trim(strip_tags($matches[3][$key]));
1092 1092
                             break;
1093 1093
                             case 'address':
1094
-                                $address           = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) );
1095
-                                $return['address'] = trim( strip_tags( $address, '<br>' ) );
1094
+                                $address           = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key])));
1095
+                                $return['address'] = trim(strip_tags($address, '<br>'));
1096 1096
                             break;
1097 1097
                             case 'consultation number':
1098
-                                $return['consultation'] = trim( strip_tags( $matches[3][$key] ) );
1098
+                                $return['consultation'] = trim(strip_tags($matches[3][$key]));
1099 1099
                             break;
1100 1100
                         }
1101 1101
                     }
1102 1102
                     
1103
-                    if ( !empty( $return ) ) {
1103
+                    if (!empty($return)) {
1104 1104
                         return $return;
1105 1105
                     }
1106 1106
                 }
@@ -1112,55 +1112,55 @@  discard block
 block discarded – undo
1112 1112
         }
1113 1113
     }
1114 1114
     
1115
-    public static function check_vat( $vat_number, $country_code = '' ) {        
1115
+    public static function check_vat($vat_number, $country_code = '') {        
1116 1116
         $vat_name           = self::get_vat_name();
1117 1117
         
1118 1118
         $return             = array();
1119 1119
         $return['valid']    = false;
1120
-        $return['message']  = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1120
+        $return['message']  = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1121 1121
                 
1122
-        if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) {
1122
+        if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) {
1123 1123
             return $return;
1124 1124
         }
1125 1125
             
1126
-        $response = self::vies_check( $vat_number, $country_code );
1126
+        $response = self::vies_check($vat_number, $country_code);
1127 1127
         
1128
-        if ( $response ) {
1129
-            $return['valid']    = true;
1128
+        if ($response) {
1129
+            $return['valid'] = true;
1130 1130
             
1131
-            if ( is_array( $response ) ) {
1132
-                $return['company'] = isset( $response['company'] ) ? $response['company'] : '';
1133
-                $return['address'] = isset( $response['address'] ) ? $response['address'] : '';
1131
+            if (is_array($response)) {
1132
+                $return['company'] = isset($response['company']) ? $response['company'] : '';
1133
+                $return['address'] = isset($response['address']) ? $response['address'] : '';
1134 1134
                 $return['message'] = $return['company'] . '<br/>' . $return['address'];
1135 1135
             }
1136 1136
         } else {
1137 1137
             $return['valid']    = false;
1138
-            $return['message']  = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
1138
+            $return['message']  = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
1139 1139
         }
1140 1140
         
1141 1141
         return $return;
1142 1142
     }
1143 1143
     
1144
-    public static function request_euvatrates( $group ) {
1144
+    public static function request_euvatrates($group) {
1145 1145
         $response               = array();
1146 1146
         $response['success']    = false;
1147 1147
         $response['error']      = null;
1148 1148
         $response['eurates']    = null;
1149 1149
         
1150 1150
         $euvatrates_url = 'https://euvatrates.com/rates.json';
1151
-        $euvatrates_url = apply_filters( 'wpinv_euvatrates_url', $euvatrates_url );
1152
-        $api_response   = wp_remote_get( $euvatrates_url );
1151
+        $euvatrates_url = apply_filters('wpinv_euvatrates_url', $euvatrates_url);
1152
+        $api_response   = wp_remote_get($euvatrates_url);
1153 1153
     
1154 1154
         try {
1155
-            if ( is_wp_error( $api_response ) ) {
1156
-                $response['error']      = __( $api_response->get_error_message(), 'invoicing' );
1155
+            if (is_wp_error($api_response)) {
1156
+                $response['error'] = __($api_response->get_error_message(), 'invoicing');
1157 1157
             } else {
1158
-                $body = json_decode( $api_response['body'] );
1158
+                $body = json_decode($api_response['body']);
1159 1159
                 
1160
-                if ( isset( $body->rates ) ) {
1160
+                if (isset($body->rates)) {
1161 1161
                     $rates = array();
1162 1162
                     
1163
-                    foreach ( $body->rates as $country_code => $rate ) {
1163
+                    foreach ($body->rates as $country_code => $rate) {
1164 1164
                         $vat_rate = array();
1165 1165
                         $vat_rate['country']        = $rate->country;
1166 1166
                         $vat_rate['standard']       = (float)$rate->standard_rate;
@@ -1168,7 +1168,7 @@  discard block
 block discarded – undo
1168 1168
                         $vat_rate['superreduced']   = (float)$rate->super_reduced_rate;
1169 1169
                         $vat_rate['parking']        = (float)$rate->parking_rate;
1170 1170
                         
1171
-                        if ( $group !== '' && in_array( $group, array( 'standard', 'reduced', 'superreduced', 'parking' ) ) ) {
1171
+                        if ($group !== '' && in_array($group, array('standard', 'reduced', 'superreduced', 'parking'))) {
1172 1172
                             $vat_rate_group = array();
1173 1173
                             $vat_rate_group['country'] = $rate->country;
1174 1174
                             $vat_rate_group[$group]    = $vat_rate[$group];
@@ -1180,79 +1180,79 @@  discard block
 block discarded – undo
1180 1180
                     }
1181 1181
                     
1182 1182
                     $response['success']    = true;                                
1183
-                    $response['rates']      = apply_filters( 'wpinv_process_euvatrates', $rates, $api_response, $group );
1183
+                    $response['rates']      = apply_filters('wpinv_process_euvatrates', $rates, $api_response, $group);
1184 1184
                 } else {
1185
-                    $response['error']      = __( 'No EU rates found!', 'invoicing' );
1185
+                    $response['error']      = __('No EU rates found!', 'invoicing');
1186 1186
                 }
1187 1187
             }
1188
-        } catch ( Exception $e ) {
1189
-            $response['error'] = __( $e->getMessage(), 'invoicing' );
1188
+        } catch (Exception $e) {
1189
+            $response['error'] = __($e->getMessage(), 'invoicing');
1190 1190
         }
1191 1191
         
1192
-        return apply_filters( 'wpinv_response_euvatrates', $response, $group );
1192
+        return apply_filters('wpinv_response_euvatrates', $response, $group);
1193 1193
     }    
1194 1194
     
1195
-    public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) {
1195
+    public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) {
1196 1196
         global $wpi_item_id, $wpi_country;
1197 1197
         
1198
-        if ( !empty( $_POST['wpinv_country'] ) ) {
1199
-            $country_code = trim( $_POST['wpinv_country'] );
1200
-        } else if ( !empty( $_POST['country'] ) ) {
1201
-            $country_code = trim( $_POST['country'] );
1202
-        } else if ( !empty( $wpi_country ) ) {
1198
+        if (!empty($_POST['wpinv_country'])) {
1199
+            $country_code = trim($_POST['wpinv_country']);
1200
+        } else if (!empty($_POST['country'])) {
1201
+            $country_code = trim($_POST['country']);
1202
+        } else if (!empty($wpi_country)) {
1203 1203
             $country_code = $wpi_country;
1204 1204
         } else {
1205
-            $country_code = self::get_user_country( '', $user_id );
1205
+            $country_code = self::get_user_country('', $user_id);
1206 1206
         }
1207 1207
         
1208
-        if ( $is_digital === null && $wpi_item_id ) {
1209
-            $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules();
1208
+        if ($is_digital === null && $wpi_item_id) {
1209
+            $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules();
1210 1210
         }
1211 1211
         
1212
-        if ( !empty( $country_code ) ) {
1213
-            $requires_vat = ( self::is_eu_state( $country_code ) && ( self::is_eu_state( self::$default_country ) || $is_digital ) ) || ( self::is_gst_country( $country_code ) && self::is_gst_country( self::$default_country ) );
1212
+        if (!empty($country_code)) {
1213
+            $requires_vat = (self::is_eu_state($country_code) && (self::is_eu_state(self::$default_country) || $is_digital)) || (self::is_gst_country($country_code) && self::is_gst_country(self::$default_country));
1214 1214
         }
1215 1215
         
1216
-        return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id );
1216
+        return apply_filters('wpinv_requires_vat', $requires_vat, $user_id);
1217 1217
     }
1218 1218
     
1219
-    public static function tax_label( $label = '' ) {
1219
+    public static function tax_label($label = '') {
1220 1220
         global $wpi_requires_vat;
1221 1221
         
1222
-        if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) {
1223
-            $wpi_requires_vat = self::requires_vat( 0, false );
1222
+        if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) {
1223
+            $wpi_requires_vat = self::requires_vat(0, false);
1224 1224
         }
1225 1225
         
1226
-        return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) );
1226
+        return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing'));
1227 1227
     }
1228 1228
     
1229 1229
     public static function standard_rates_label() {
1230
-        return __( 'Standard Rates', 'invoicing' );
1230
+        return __('Standard Rates', 'invoicing');
1231 1231
     }
1232 1232
     
1233
-    public static function get_rate_classes( $with_desc = false ) {        
1234
-        $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true );
1235
-        $classes = maybe_unserialize( $rate_classes_option );
1233
+    public static function get_rate_classes($with_desc = false) {        
1234
+        $rate_classes_option = get_option('_wpinv_vat_rate_classes', true);
1235
+        $classes = maybe_unserialize($rate_classes_option);
1236 1236
         
1237
-        if ( empty( $classes ) || !is_array( $classes ) ) {
1237
+        if (empty($classes) || !is_array($classes)) {
1238 1238
             $classes = array();
1239 1239
         }
1240 1240
 
1241 1241
         $rate_classes = array();
1242
-        if ( !array_key_exists( '_standard', $classes ) ) {
1243
-            if ( $with_desc ) {
1244
-                $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) );
1242
+        if (!array_key_exists('_standard', $classes)) {
1243
+            if ($with_desc) {
1244
+                $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing'));
1245 1245
             } else {
1246 1246
                 $rate_classes['_standard'] = self::standard_rates_label();
1247 1247
             }
1248 1248
         }
1249 1249
         
1250
-        foreach ( $classes as $key => $class ) {
1251
-            $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key;
1252
-            $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : '';
1250
+        foreach ($classes as $key => $class) {
1251
+            $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key;
1252
+            $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : '';
1253 1253
             
1254
-            if ( $with_desc ) {
1255
-                $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc );
1254
+            if ($with_desc) {
1255
+                $rate_classes[$key] = array('name' => $name, 'desc' => $desc);
1256 1256
             } else {
1257 1257
                 $rate_classes[$key] = $name;
1258 1258
             }
@@ -1263,15 +1263,15 @@  discard block
 block discarded – undo
1263 1263
     
1264 1264
     public static function get_all_classes() {        
1265 1265
         $classes            = self::get_rate_classes();
1266
-        $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' );
1266
+        $classes['_exempt'] = __('Exempt (0%)', 'invoicing');
1267 1267
         
1268
-        return apply_filters( 'wpinv_vat_get_all_classes', $classes );
1268
+        return apply_filters('wpinv_vat_get_all_classes', $classes);
1269 1269
     }
1270 1270
     
1271
-    public static function get_class_desc( $rate_class ) {        
1272
-        $rate_classes = self::get_rate_classes( true );
1271
+    public static function get_class_desc($rate_class) {        
1272
+        $rate_classes = self::get_rate_classes(true);
1273 1273
 
1274
-        if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) {
1274
+        if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) {
1275 1275
             return $rate_classes[$rate_class]['desc'];
1276 1276
         }
1277 1277
         
@@ -1287,106 +1287,106 @@  discard block
 block discarded – undo
1287 1287
             'increased'     => 'Increased'
1288 1288
         );
1289 1289
         
1290
-        return apply_filters( 'wpinv_get_vat_groups', $vat_groups );
1290
+        return apply_filters('wpinv_get_vat_groups', $vat_groups);
1291 1291
     }
1292 1292
 
1293 1293
     public static function get_rules() {
1294 1294
         $vat_rules = array(
1295
-            'digital' => __( 'Digital Product', 'invoicing' ),
1296
-            'physical' => __( 'Physical Product', 'invoicing' )
1295
+            'digital' => __('Digital Product', 'invoicing'),
1296
+            'physical' => __('Physical Product', 'invoicing')
1297 1297
         );
1298
-        return apply_filters( 'wpinv_get_vat_rules', $vat_rules );
1298
+        return apply_filters('wpinv_get_vat_rules', $vat_rules);
1299 1299
     }
1300 1300
 
1301
-    public static function get_vat_rates( $class ) {
1302
-        if ( $class === '_standard' ) {
1301
+    public static function get_vat_rates($class) {
1302
+        if ($class === '_standard') {
1303 1303
             return wpinv_get_tax_rates();
1304 1304
         }
1305 1305
 
1306 1306
         $rates = self::get_non_standard_rates();
1307 1307
 
1308
-        return array_key_exists( $class, $rates ) ? $rates[$class] : array();
1308
+        return array_key_exists($class, $rates) ? $rates[$class] : array();
1309 1309
     }
1310 1310
 
1311 1311
     public static function get_non_standard_rates() {
1312
-        $option = get_option( 'wpinv_vat_rates', array());
1313
-        return is_array( $option ) ? $option : array();
1312
+        $option = get_option('wpinv_vat_rates', array());
1313
+        return is_array($option) ? $option : array();
1314 1314
     }
1315 1315
     
1316 1316
     public static function allow_vat_rules() {
1317
-        return ( wpinv_get_option( 'apply_vat_rules' ) ? true : false );
1317
+        return (wpinv_get_option('apply_vat_rules') ? true : false);
1318 1318
     }
1319 1319
     
1320 1320
     public static function allow_vat_classes() {
1321 1321
         return false; // TODO
1322
-        return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false );
1322
+        return (wpinv_get_option('vat_allow_classes') ? true : false);
1323 1323
     }
1324 1324
     
1325
-    public static function get_item_class( $postID ) {
1326
-        $class = get_post_meta( $postID, '_wpinv_vat_class', true );
1325
+    public static function get_item_class($postID) {
1326
+        $class = get_post_meta($postID, '_wpinv_vat_class', true);
1327 1327
 
1328
-        if ( empty( $class ) ) {
1328
+        if (empty($class)) {
1329 1329
             $class = '_standard';
1330 1330
         }
1331 1331
         
1332
-        return apply_filters( 'wpinv_get_item_vat_class', $class, $postID );
1332
+        return apply_filters('wpinv_get_item_vat_class', $class, $postID);
1333 1333
     }
1334 1334
     
1335
-    public static function item_class_label( $postID ) {        
1335
+    public static function item_class_label($postID) {        
1336 1336
         $vat_classes = self::get_all_classes();
1337 1337
         
1338
-        $class = self::get_item_class( $postID );
1339
-        $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' );
1338
+        $class = self::get_item_class($postID);
1339
+        $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing');
1340 1340
         
1341
-        return apply_filters( 'wpinv_item_class_label', $class, $postID );
1341
+        return apply_filters('wpinv_item_class_label', $class, $postID);
1342 1342
     }
1343 1343
     
1344
-    public static function get_item_rule( $postID ) {        
1345
-        $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true );
1344
+    public static function get_item_rule($postID) {        
1345
+        $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true);
1346 1346
         
1347
-        if ( empty( $rule_type ) ) {        
1347
+        if (empty($rule_type)) {        
1348 1348
             $rule_type = self::allow_vat_rules() ? 'digital' : 'physical';
1349 1349
         }
1350 1350
         
1351
-        return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID );
1351
+        return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID);
1352 1352
     }
1353 1353
     
1354
-    public static function item_rule_label( $postID ) {
1354
+    public static function item_rule_label($postID) {
1355 1355
         $vat_rules  = self::get_rules();
1356
-        $vat_rule   = self::get_item_rule( $postID );
1357
-        $vat_rule   = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule;
1356
+        $vat_rule   = self::get_item_rule($postID);
1357
+        $vat_rule   = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule;
1358 1358
         
1359
-        return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID );
1359
+        return apply_filters('wpinv_item_rule_label', $vat_rule, $postID);
1360 1360
     }
1361 1361
     
1362
-    public static function item_has_digital_rule( $item_id = 0 ) {        
1363
-        return self::get_item_rule( $item_id ) == 'digital' ? true : false;
1362
+    public static function item_has_digital_rule($item_id = 0) {        
1363
+        return self::get_item_rule($item_id) == 'digital' ? true : false;
1364 1364
     }
1365 1365
     
1366
-    public static function invoice_has_digital_rule( $invoice = 0 ) {        
1367
-        if ( !self::allow_vat_rules() ) {
1366
+    public static function invoice_has_digital_rule($invoice = 0) {        
1367
+        if (!self::allow_vat_rules()) {
1368 1368
             return false;
1369 1369
         }
1370 1370
         
1371
-        if ( empty( $invoice ) ) {
1371
+        if (empty($invoice)) {
1372 1372
             return true;
1373 1373
         }
1374 1374
         
1375
-        if ( is_int( $invoice ) ) {
1376
-            $invoice = new WPInv_Invoice( $invoice );
1375
+        if (is_int($invoice)) {
1376
+            $invoice = new WPInv_Invoice($invoice);
1377 1377
         }
1378 1378
         
1379
-        if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) {
1379
+        if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) {
1380 1380
             return true;
1381 1381
         }
1382 1382
         
1383
-        $cart_items  = $invoice->get_cart_details();
1383
+        $cart_items = $invoice->get_cart_details();
1384 1384
         
1385
-        if ( !empty( $cart_items ) ) {
1385
+        if (!empty($cart_items)) {
1386 1386
             $has_digital_rule = false;
1387 1387
             
1388
-            foreach ( $cart_items as $key => $item ) {
1389
-                if ( self::item_has_digital_rule( $item['id'] ) ) {
1388
+            foreach ($cart_items as $key => $item) {
1389
+                if (self::item_has_digital_rule($item['id'])) {
1390 1390
                     $has_digital_rule = true;
1391 1391
                     break;
1392 1392
                 }
@@ -1398,67 +1398,67 @@  discard block
 block discarded – undo
1398 1398
         return $has_digital_rule;
1399 1399
     }
1400 1400
     
1401
-    public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) {        
1402
-        if ( !wpinv_use_taxes() ) {
1401
+    public static function item_is_taxable($item_id = 0, $country = false, $state = false) {        
1402
+        if (!wpinv_use_taxes()) {
1403 1403
             return false;
1404 1404
         }
1405 1405
         
1406 1406
         $is_taxable = true;
1407 1407
 
1408
-        if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) {
1408
+        if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') {
1409 1409
             $is_taxable = false;
1410 1410
         }
1411 1411
         
1412
-        return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state );
1412
+        return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state);
1413 1413
     }
1414 1414
     
1415
-    public static function find_rate( $country, $state, $rate, $class ) {
1415
+    public static function find_rate($country, $state, $rate, $class) {
1416 1416
         global $wpi_zero_tax;
1417 1417
 
1418
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1418
+        if ($class === '_exempt' || $wpi_zero_tax) {
1419 1419
             return 0;
1420 1420
         }
1421 1421
 
1422
-        $tax_rates   = wpinv_get_tax_rates();
1422
+        $tax_rates = wpinv_get_tax_rates();
1423 1423
         
1424
-        if ( $class !== '_standard' ) {
1425
-            $class_rates = self::get_vat_rates( $class );
1424
+        if ($class !== '_standard') {
1425
+            $class_rates = self::get_vat_rates($class);
1426 1426
             
1427
-            if ( is_array( $class_rates ) ) {
1427
+            if (is_array($class_rates)) {
1428 1428
                 $indexed_class_rates = array();
1429 1429
                 
1430
-                foreach ( $class_rates as $key => $cr ) {
1430
+                foreach ($class_rates as $key => $cr) {
1431 1431
                     $indexed_class_rates[$cr['country']] = $cr;
1432 1432
                 }
1433 1433
 
1434
-                $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) {
1434
+                $tax_rates = array_map(function($tr) use($indexed_class_rates) {
1435 1435
                     $tr_country = $tr['country'];
1436
-                    if ( !isset( $indexed_class_rates[$tr_country] ) ) {
1436
+                    if (!isset($indexed_class_rates[$tr_country])) {
1437 1437
                         return $tr;
1438 1438
                     }
1439 1439
                     $icr = $indexed_class_rates[$tr_country];
1440
-                    return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr;
1440
+                    return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr;
1441 1441
 
1442
-                }, $tax_rates, $class_rates );
1442
+                }, $tax_rates, $class_rates);
1443 1443
             }
1444 1444
         }
1445 1445
 
1446
-        if ( !empty( $tax_rates ) ) {
1447
-            foreach ( $tax_rates as $key => $tax_rate ) {
1448
-                if ( $country != $tax_rate['country'] )
1446
+        if (!empty($tax_rates)) {
1447
+            foreach ($tax_rates as $key => $tax_rate) {
1448
+                if ($country != $tax_rate['country'])
1449 1449
                     continue;
1450 1450
 
1451
-                if ( !empty( $tax_rate['global'] ) ) {
1452
-                    if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) {
1453
-                        $rate = number_format( $tax_rate['rate'], 4 );
1451
+                if (!empty($tax_rate['global'])) {
1452
+                    if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) {
1453
+                        $rate = number_format($tax_rate['rate'], 4);
1454 1454
                     }
1455 1455
                 } else {
1456
-                    if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) )
1456
+                    if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state']))
1457 1457
                         continue;
1458 1458
 
1459 1459
                     $state_rate = $tax_rate['rate'];
1460
-                    if ( 0 !== $state_rate || !empty( $state_rate ) ) {
1461
-                        $rate = number_format( $state_rate, 4 );
1460
+                    if (0 !== $state_rate || !empty($state_rate)) {
1461
+                        $rate = number_format($state_rate, 4);
1462 1462
                     }
1463 1463
                 }
1464 1464
             }
@@ -1467,84 +1467,84 @@  discard block
 block discarded – undo
1467 1467
         return $rate;
1468 1468
     }
1469 1469
     
1470
-    public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) {
1470
+    public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) {
1471 1471
         global $wpinv_options, $wpi_session, $wpi_item_id, $wpi_zero_tax;
1472 1472
         
1473 1473
         $item_id = $item_id > 0 ? $item_id : $wpi_item_id;
1474 1474
         $allow_vat_classes = self::allow_vat_classes();
1475
-        $class = $item_id ? self::get_item_class( $item_id ) : '_standard';
1475
+        $class = $item_id ? self::get_item_class($item_id) : '_standard';
1476 1476
 
1477
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1477
+        if ($class === '_exempt' || $wpi_zero_tax) {
1478 1478
             return 0;
1479
-        } else if ( !$allow_vat_classes ) {
1479
+        } else if (!$allow_vat_classes) {
1480 1480
             $class = '_standard';
1481 1481
         }
1482 1482
 
1483
-        if( !empty( $_POST['wpinv_country'] ) ) {
1483
+        if (!empty($_POST['wpinv_country'])) {
1484 1484
             $post_country = $_POST['wpinv_country'];
1485
-        } elseif( !empty( $_POST['wpinv_country'] ) ) {
1485
+        } elseif (!empty($_POST['wpinv_country'])) {
1486 1486
             $post_country = $_POST['wpinv_country'];
1487
-        } elseif( !empty( $_POST['country'] ) ) {
1487
+        } elseif (!empty($_POST['country'])) {
1488 1488
             $post_country = $_POST['country'];
1489 1489
         } else {
1490 1490
             $post_country = '';
1491 1491
         }
1492 1492
 
1493
-        $country        = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country );
1494
-        $base_country   = wpinv_is_base_country( $country );
1493
+        $country        = !empty($post_country) ? $post_country : wpinv_default_billing_country($country);
1494
+        $base_country   = wpinv_is_base_country($country);
1495 1495
         
1496
-        $requires_vat   = self::requires_vat( 0, false );
1497
-        $is_digital     = self::get_item_rule( $item_id ) == 'digital' ;
1498
-        $rate           = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate;
1496
+        $requires_vat   = self::requires_vat(0, false);
1497
+        $is_digital     = self::get_item_rule($item_id) == 'digital';
1498
+        $rate           = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate;
1499 1499
           
1500
-        if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country
1500
+        if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country
1501 1501
             $rate = 0;
1502
-        } else if ( $requires_vat ) {
1503
-            $vat_number = self::get_user_vat_number( '', 0, true );
1502
+        } else if ($requires_vat) {
1503
+            $vat_number = self::get_user_vat_number('', 0, true);
1504 1504
             $vat_info   = self::current_vat_data();
1505 1505
             
1506
-            if ( is_array( $vat_info ) ) {
1507
-                $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : "";
1506
+            if (is_array($vat_info)) {
1507
+                $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : "";
1508 1508
             }
1509 1509
             
1510
-            if ( $country == 'UK' ) {
1510
+            if ($country == 'UK') {
1511 1511
                 $country = 'GB';
1512 1512
             }
1513 1513
 
1514
-            if ( !empty( $vat_number ) ) {
1514
+            if (!empty($vat_number)) {
1515 1515
                 $rate = 0;
1516 1516
             } else {
1517
-                $rate = self::find_rate( $country, $state, $rate, $class ); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate
1517
+                $rate = self::find_rate($country, $state, $rate, $class); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate
1518 1518
             }
1519 1519
 
1520
-            if ( empty( $vat_number ) && !$is_digital ) {
1521
-                if ( $base_country ) {
1522
-                    $rate = self::find_rate( $country, null, $rate, $class );
1520
+            if (empty($vat_number) && !$is_digital) {
1521
+                if ($base_country) {
1522
+                    $rate = self::find_rate($country, null, $rate, $class);
1523 1523
                 } else {
1524
-                    if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1524
+                    if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1525 1525
                         $rate = $wpinv_options['eu_fallback_rate'];
1526
-                    } else if( !empty( $country ) ) {
1527
-                        $rate = self::find_rate( $country, $state, $rate, $class );
1526
+                    } else if (!empty($country)) {
1527
+                        $rate = self::find_rate($country, $state, $rate, $class);
1528 1528
                     }
1529 1529
                 }
1530
-            } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) {
1531
-                if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1530
+            } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) {
1531
+                if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1532 1532
                     $rate = $wpinv_options['eu_fallback_rate'];
1533
-                } else if( !empty( $country ) ) {
1534
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1533
+                } else if (!empty($country)) {
1534
+                    $rate = self::find_rate($country, $state, $rate, $class);
1535 1535
                 }
1536 1536
             }
1537 1537
         } else {
1538
-            if ( $is_digital ) {
1538
+            if ($is_digital) {
1539 1539
                 $ip_country_code = self::get_country_by_ip();
1540 1540
                 
1541
-                if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) {
1542
-                    $rate = self::find_rate( $ip_country_code, '', 0, $class );
1541
+                if ($ip_country_code && self::is_eu_state($ip_country_code)) {
1542
+                    $rate = self::find_rate($ip_country_code, '', 0, $class);
1543 1543
                 } else {
1544
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1544
+                    $rate = self::find_rate($country, $state, $rate, $class);
1545 1545
                 }
1546 1546
             } else {
1547
-                $rate = self::find_rate( $country, $state, $rate, $class );
1547
+                $rate = self::find_rate($country, $state, $rate, $class);
1548 1548
             }
1549 1549
         }
1550 1550
 
@@ -1554,48 +1554,48 @@  discard block
 block discarded – undo
1554 1554
     public static function current_vat_data() {
1555 1555
         global $wpi_session;
1556 1556
         
1557
-        return $wpi_session->get( 'user_vat_data' );
1557
+        return $wpi_session->get('user_vat_data');
1558 1558
     }
1559 1559
     
1560
-    public static function get_user_country( $country = '', $user_id = 0 ) {
1561
-        $user_address = wpinv_get_user_address( $user_id, false );
1560
+    public static function get_user_country($country = '', $user_id = 0) {
1561
+        $user_address = wpinv_get_user_address($user_id, false);
1562 1562
         
1563
-        if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1563
+        if (wpinv_get_option('vat_ip_country_default')) {
1564 1564
             $country = '';
1565 1565
         }
1566 1566
         
1567
-        $country    = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country'];
1568
-        $result     = apply_filters( 'wpinv_get_user_country', $country, $user_id );
1567
+        $country    = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country'];
1568
+        $result     = apply_filters('wpinv_get_user_country', $country, $user_id);
1569 1569
 
1570
-        if ( empty( $result ) ) {
1570
+        if (empty($result)) {
1571 1571
             $result = self::get_country_by_ip();
1572 1572
         }
1573 1573
 
1574 1574
         return $result;
1575 1575
     }
1576 1576
     
1577
-    public static function set_user_country( $country = '', $user_id = 0 ) {
1577
+    public static function set_user_country($country = '', $user_id = 0) {
1578 1578
         global $wpi_userID;
1579 1579
         
1580
-        if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) {
1580
+        if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) {
1581 1581
             $country = wpinv_get_default_country();
1582 1582
         }
1583 1583
         
1584 1584
         return $country;
1585 1585
     }
1586 1586
     
1587
-    public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) {
1587
+    public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) {
1588 1588
         global $wpi_current_id, $wpi_userID;
1589 1589
         
1590
-        if ( !empty( $_POST['new_user'] ) ) {
1590
+        if (!empty($_POST['new_user'])) {
1591 1591
             return '';
1592 1592
         }
1593 1593
         
1594
-        if ( empty( $user_id ) ) {
1595
-            $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() );
1594
+        if (empty($user_id)) {
1595
+            $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id());
1596 1596
         }
1597 1597
 
1598
-        $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true );
1598
+        $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true);
1599 1599
         
1600 1600
         /* TODO
1601 1601
         if ( $is_valid && $vat_number ) {
@@ -1606,36 +1606,36 @@  discard block
 block discarded – undo
1606 1606
         }
1607 1607
         */
1608 1608
 
1609
-        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid );
1609
+        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid);
1610 1610
     }
1611 1611
     
1612
-    public static function get_user_company( $company = '', $user_id = 0 ) {
1613
-        if ( empty( $user_id ) ) {
1612
+    public static function get_user_company($company = '', $user_id = 0) {
1613
+        if (empty($user_id)) {
1614 1614
             $user_id = get_current_user_id();
1615 1615
         }
1616 1616
 
1617
-        $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true );
1617
+        $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true);
1618 1618
 
1619
-        return apply_filters( 'wpinv_user_company', $company, $user_id );
1619
+        return apply_filters('wpinv_user_company', $company, $user_id);
1620 1620
     }
1621 1621
     
1622
-    public static function save_user_vat_details( $company = '', $vat_number = '' ) {
1623
-        $save = apply_filters( 'wpinv_allow_save_user_vat_details', true );
1622
+    public static function save_user_vat_details($company = '', $vat_number = '') {
1623
+        $save = apply_filters('wpinv_allow_save_user_vat_details', true);
1624 1624
 
1625
-        if ( is_user_logged_in() && $save ) {
1625
+        if (is_user_logged_in() && $save) {
1626 1626
             $user_id = get_current_user_id();
1627 1627
 
1628
-            if ( !empty( $vat_number ) ) {
1629
-                update_user_meta( $user_id, '_wpinv_vat_number', $vat_number );
1628
+            if (!empty($vat_number)) {
1629
+                update_user_meta($user_id, '_wpinv_vat_number', $vat_number);
1630 1630
             } else {
1631
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1631
+                delete_user_meta($user_id, '_wpinv_vat_number');
1632 1632
             }
1633 1633
 
1634
-            if ( !empty( $company ) ) {
1635
-                update_user_meta( $user_id, '_wpinv_company', $company );
1634
+            if (!empty($company)) {
1635
+                update_user_meta($user_id, '_wpinv_company', $company);
1636 1636
             } else {
1637
-                delete_user_meta( $user_id, '_wpinv_company');
1638
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1637
+                delete_user_meta($user_id, '_wpinv_company');
1638
+                delete_user_meta($user_id, '_wpinv_vat_number');
1639 1639
             }
1640 1640
         }
1641 1641
 
@@ -1645,113 +1645,113 @@  discard block
 block discarded – undo
1645 1645
     public static function ajax_vat_validate() {
1646 1646
         global $wpinv_options, $wpi_session;
1647 1647
         
1648
-        $is_checkout            = ( !empty( $_POST['source'] ) && $_POST['source'] == 'checkout' ) ? true : false;
1648
+        $is_checkout            = (!empty($_POST['source']) && $_POST['source'] == 'checkout') ? true : false;
1649 1649
         $response               = array();
1650 1650
         $response['success']    = false;
1651 1651
         
1652
-        if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) {
1653
-            $response['error'] = __( 'Invalid security nonce', 'invoicing' );
1654
-            wp_send_json( $response );
1652
+        if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) {
1653
+            $response['error'] = __('Invalid security nonce', 'invoicing');
1654
+            wp_send_json($response);
1655 1655
         }
1656 1656
         
1657
-        $vat_name   = self::get_vat_name();
1657
+        $vat_name = self::get_vat_name();
1658 1658
         
1659
-        if ( $is_checkout ) {
1659
+        if ($is_checkout) {
1660 1660
             $invoice = wpinv_get_invoice_cart();
1661 1661
             
1662
-            if ( !self::requires_vat( false, 0, self::invoice_has_digital_rule( $invoice ) ) ) {
1662
+            if (!self::requires_vat(false, 0, self::invoice_has_digital_rule($invoice))) {
1663 1663
                 $vat_info = array();
1664
-                $wpi_session->set( 'user_vat_data', $vat_info );
1664
+                $wpi_session->set('user_vat_data', $vat_info);
1665 1665
 
1666 1666
                 self::save_user_vat_details();
1667 1667
                 
1668 1668
                 $response['success'] = true;
1669
-                $response['message'] = wp_sprintf( __( 'Ignore %s', 'invoicing' ), $vat_name );
1670
-                wp_send_json( $response );
1669
+                $response['message'] = wp_sprintf(__('Ignore %s', 'invoicing'), $vat_name);
1670
+                wp_send_json($response);
1671 1671
             }
1672 1672
         }
1673 1673
         
1674
-        $company    = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : '';
1675
-        $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : '';
1674
+        $company    = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : '';
1675
+        $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : '';
1676 1676
         
1677
-        $vat_info = $wpi_session->get( 'user_vat_data' );
1678
-        if ( !is_array( $vat_info ) || empty( $vat_info ) ) {
1679
-            $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true );
1677
+        $vat_info = $wpi_session->get('user_vat_data');
1678
+        if (!is_array($vat_info) || empty($vat_info)) {
1679
+            $vat_info = array('company'=> $company, 'number' => '', 'valid' => true);
1680 1680
         }
1681 1681
         
1682
-        if ( empty( $vat_number ) ) {
1683
-            if ( $is_checkout ) {
1682
+        if (empty($vat_number)) {
1683
+            if ($is_checkout) {
1684 1684
                 $response['success'] = true;
1685
-                $response['message'] = wp_sprintf( __( 'No %s number has been applied. %s will be added to invoice totals', 'invoicing' ), $vat_name, $vat_name );
1685
+                $response['message'] = wp_sprintf(__('No %s number has been applied. %s will be added to invoice totals', 'invoicing'), $vat_name, $vat_name);
1686 1686
                 
1687
-                $vat_info = $wpi_session->get( 'user_vat_data' );
1687
+                $vat_info = $wpi_session->get('user_vat_data');
1688 1688
                 $vat_info['number'] = "";
1689 1689
                 $vat_info['valid'] = true;
1690 1690
                 
1691
-                self::save_user_vat_details( $company );
1691
+                self::save_user_vat_details($company);
1692 1692
             } else {
1693
-                $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
1693
+                $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
1694 1694
                 
1695 1695
                 $vat_info['valid'] = false;
1696 1696
             }
1697 1697
 
1698
-            $wpi_session->set( 'user_vat_data', $vat_info );
1699
-            wp_send_json( $response );
1698
+            $wpi_session->set('user_vat_data', $vat_info);
1699
+            wp_send_json($response);
1700 1700
         }
1701 1701
         
1702
-        if ( empty( $company ) ) {
1702
+        if (empty($company)) {
1703 1703
             $vat_info['valid'] = false;
1704
-            $wpi_session->set( 'user_vat_data', $vat_info );
1704
+            $wpi_session->set('user_vat_data', $vat_info);
1705 1705
             
1706
-            $response['error'] = __( 'Please enter your registered company name!', 'invoicing' );
1707
-            wp_send_json( $response );
1706
+            $response['error'] = __('Please enter your registered company name!', 'invoicing');
1707
+            wp_send_json($response);
1708 1708
         }
1709 1709
         
1710
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
1711
-            if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1710
+        if (!empty($wpinv_options['vat_vies_check'])) {
1711
+            if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1712 1712
                 $vat_info['valid'] = false;
1713
-                $wpi_session->set( 'user_vat_data', $vat_info );
1713
+                $wpi_session->set('user_vat_data', $vat_info);
1714 1714
                 
1715
-                $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1716
-                wp_send_json( $response );
1715
+                $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1716
+                wp_send_json($response);
1717 1717
             }
1718 1718
             
1719 1719
             $response['success'] = true;
1720
-            $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1720
+            $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1721 1721
         } else {
1722
-            $result = self::check_vat( $vat_number );
1722
+            $result = self::check_vat($vat_number);
1723 1723
             
1724
-            if ( empty( $result['valid'] ) ) {
1724
+            if (empty($result['valid'])) {
1725 1725
                 $response['error'] = $result['message'];
1726
-                wp_send_json( $response );
1726
+                wp_send_json($response);
1727 1727
             }
1728 1728
             
1729
-            $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1730
-            $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1729
+            $vies_company = !empty($result['company']) ? $result['company'] : '';
1730
+            $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1731 1731
             
1732
-            $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1732
+            $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1733 1733
 
1734
-            if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) {
1734
+            if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) {
1735 1735
                 $response['success'] = true;
1736
-                $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1736
+                $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1737 1737
             } else {           
1738 1738
                 $vat_info['valid'] = false;
1739
-                $wpi_session->set( 'user_vat_data', $vat_info );
1739
+                $wpi_session->set('user_vat_data', $vat_info);
1740 1740
                 
1741 1741
                 $response['success'] = false;
1742
-                $response['message'] = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name );
1743
-                wp_send_json( $response );
1742
+                $response['message'] = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name);
1743
+                wp_send_json($response);
1744 1744
             }
1745 1745
         }
1746 1746
         
1747
-        if ( $is_checkout ) {
1748
-            self::save_user_vat_details( $company, $vat_number );
1747
+        if ($is_checkout) {
1748
+            self::save_user_vat_details($company, $vat_number);
1749 1749
 
1750
-            $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true );
1751
-            $wpi_session->set( 'user_vat_data', $vat_info );
1750
+            $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true);
1751
+            $wpi_session->set('user_vat_data', $vat_info);
1752 1752
         }
1753 1753
 
1754
-        wp_send_json( $response );
1754
+        wp_send_json($response);
1755 1755
     }
1756 1756
     
1757 1757
     public static function ajax_vat_reset() {
@@ -1760,161 +1760,161 @@  discard block
 block discarded – undo
1760 1760
         $company    = is_user_logged_in() ? self::get_user_company() : '';
1761 1761
         $vat_number = self::get_user_vat_number();
1762 1762
         
1763
-        $vat_info   = array('company' => $company, 'number' => $vat_number, 'valid' => false );
1764
-        $wpi_session->set( 'user_vat_data', $vat_info );
1763
+        $vat_info   = array('company' => $company, 'number' => $vat_number, 'valid' => false);
1764
+        $wpi_session->set('user_vat_data', $vat_info);
1765 1765
         
1766 1766
         $response                       = array();
1767 1767
         $response['success']            = true;
1768 1768
         $response['data']['company']    = $company;
1769 1769
         $response['data']['number']     = $vat_number;
1770 1770
         
1771
-        wp_send_json( $response );
1771
+        wp_send_json($response);
1772 1772
     }
1773 1773
     
1774
-    public static function checkout_vat_validate( $valid_data, $post ) {
1774
+    public static function checkout_vat_validate($valid_data, $post) {
1775 1775
         global $wpinv_options, $wpi_session;
1776 1776
         
1777
-        $vat_name  = __( self::get_vat_name(), 'invoicing' );
1777
+        $vat_name = __(self::get_vat_name(), 'invoicing');
1778 1778
         
1779
-        if ( !isset( $_POST['_wpi_nonce'] ) || !wp_verify_nonce( $_POST['_wpi_nonce'], 'vat_validation' ) ) {
1780
-            wpinv_set_error( 'vat_validation', wp_sprintf( __( "Invalid %s validation request.", 'invoicing' ), $vat_name ) );
1779
+        if (!isset($_POST['_wpi_nonce']) || !wp_verify_nonce($_POST['_wpi_nonce'], 'vat_validation')) {
1780
+            wpinv_set_error('vat_validation', wp_sprintf(__("Invalid %s validation request.", 'invoicing'), $vat_name));
1781 1781
             return;
1782 1782
         }
1783 1783
         
1784
-        $vat_saved = $wpi_session->get( 'user_vat_data' );
1785
-        $wpi_session->set( 'user_vat_data', null );
1784
+        $vat_saved = $wpi_session->get('user_vat_data');
1785
+        $wpi_session->set('user_vat_data', null);
1786 1786
         
1787 1787
         $invoice        = wpinv_get_invoice_cart();
1788 1788
         $amount         = $invoice->get_total();
1789
-        $is_digital     = self::invoice_has_digital_rule( $invoice );
1790
-        $no_vat         = !self::requires_vat( 0, false, $is_digital );
1789
+        $is_digital     = self::invoice_has_digital_rule($invoice);
1790
+        $no_vat         = !self::requires_vat(0, false, $is_digital);
1791 1791
         
1792
-        $company        = !empty( $_POST['wpinv_company'] ) ? $_POST['wpinv_company'] : null;
1793
-        $vat_number     = !empty( $_POST['wpinv_vat_number'] ) ? $_POST['wpinv_vat_number'] : null;
1794
-        $country        = !empty( $_POST['wpinv_country'] ) ? $_POST['wpinv_country'] : $invoice->country;
1795
-        if ( empty( $country ) ) {
1792
+        $company        = !empty($_POST['wpinv_company']) ? $_POST['wpinv_company'] : null;
1793
+        $vat_number     = !empty($_POST['wpinv_vat_number']) ? $_POST['wpinv_vat_number'] : null;
1794
+        $country        = !empty($_POST['wpinv_country']) ? $_POST['wpinv_country'] : $invoice->country;
1795
+        if (empty($country)) {
1796 1796
             $country = wpinv_default_billing_country();
1797 1797
         }
1798 1798
         
1799
-        if ( !$is_digital && $no_vat ) {
1799
+        if (!$is_digital && $no_vat) {
1800 1800
             return;
1801 1801
         }
1802 1802
             
1803
-        $vat_data           = array( 'company' => '', 'number' => '', 'valid' => false );
1803
+        $vat_data           = array('company' => '', 'number' => '', 'valid' => false);
1804 1804
         
1805 1805
         $ip_country_code    = self::get_country_by_ip();
1806
-        $is_eu_state        = self::is_eu_state( $country );
1807
-        $is_eu_state_ip     = self::is_eu_state( $ip_country_code );
1806
+        $is_eu_state        = self::is_eu_state($country);
1807
+        $is_eu_state_ip     = self::is_eu_state($ip_country_code);
1808 1808
         $is_non_eu_user     = !$is_eu_state && !$is_eu_state_ip;
1809 1809
         
1810
-        if ( $is_digital && !$is_non_eu_user && empty( $vat_number ) && apply_filters( 'wpinv_checkout_requires_country', true, $amount ) ) {
1810
+        if ($is_digital && !$is_non_eu_user && empty($vat_number) && apply_filters('wpinv_checkout_requires_country', true, $amount)) {
1811 1811
             $vat_data['adddress_confirmed'] = false;
1812 1812
             
1813
-            if ( !isset( $_POST['wpinv_adddress_confirmed'] ) ) {
1814
-                if ( $ip_country_code != $country ) {
1815
-                    wpinv_set_error( 'vat_validation', sprintf( __( 'The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing' ), '<a href="#wpinv_adddress_confirm">', '</a>' ) );
1813
+            if (!isset($_POST['wpinv_adddress_confirmed'])) {
1814
+                if ($ip_country_code != $country) {
1815
+                    wpinv_set_error('vat_validation', sprintf(__('The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing'), '<a href="#wpinv_adddress_confirm">', '</a>'));
1816 1816
                 }
1817 1817
             } else {
1818 1818
                 $vat_data['adddress_confirmed'] = true;
1819 1819
             }
1820 1820
         }
1821 1821
         
1822
-        if ( !empty( $wpinv_options['vat_prevent_b2c_purchase'] ) && !$is_non_eu_user && ( empty( $vat_number ) || $no_vat ) ) {
1823
-            if ( $is_eu_state ) {
1824
-                wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing' ), $vat_name ) );
1825
-            } else if ( $is_digital && $is_eu_state_ip ) {
1826
-                wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing' ), $vat_name ) );
1822
+        if (!empty($wpinv_options['vat_prevent_b2c_purchase']) && !$is_non_eu_user && (empty($vat_number) || $no_vat)) {
1823
+            if ($is_eu_state) {
1824
+                wpinv_set_error('vat_validation', wp_sprintf(__('Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing'), $vat_name));
1825
+            } else if ($is_digital && $is_eu_state_ip) {
1826
+                wpinv_set_error('vat_validation', wp_sprintf(__('Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing'), $vat_name));
1827 1827
             }
1828 1828
         }
1829 1829
         
1830
-        if ( !$is_eu_state || $no_vat || empty( $vat_number ) ) {
1830
+        if (!$is_eu_state || $no_vat || empty($vat_number)) {
1831 1831
             return;
1832 1832
         }
1833 1833
 
1834
-        if ( !empty( $vat_saved ) && isset( $vat_saved['valid'] ) ) {
1835
-            $vat_data['valid']  = $vat_saved['valid'];
1834
+        if (!empty($vat_saved) && isset($vat_saved['valid'])) {
1835
+            $vat_data['valid'] = $vat_saved['valid'];
1836 1836
         }
1837 1837
             
1838
-        if ( $company !== null ) {
1838
+        if ($company !== null) {
1839 1839
             $vat_data['company'] = $company;
1840 1840
         }
1841 1841
 
1842 1842
         $message = '';
1843
-        if ( $vat_number !== null ) {
1843
+        if ($vat_number !== null) {
1844 1844
             $vat_data['number'] = $vat_number;
1845 1845
             
1846
-            if ( !$vat_data['valid'] || ( $vat_saved['number'] !== $vat_data['number'] ) || ( $vat_saved['company'] !== $vat_data['company'] ) ) {
1847
-                if ( !empty( $wpinv_options['vat_vies_check'] ) ) {            
1848
-                    if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1846
+            if (!$vat_data['valid'] || ($vat_saved['number'] !== $vat_data['number']) || ($vat_saved['company'] !== $vat_data['company'])) {
1847
+                if (!empty($wpinv_options['vat_vies_check'])) {            
1848
+                    if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1849 1849
                         $vat_data['valid'] = false;
1850 1850
                     }
1851 1851
                 } else {
1852
-                    $result = self::check_vat( $vat_number );
1852
+                    $result = self::check_vat($vat_number);
1853 1853
                     
1854
-                    if ( !empty( $result['valid'] ) ) {                
1854
+                    if (!empty($result['valid'])) {                
1855 1855
                         $vat_data['valid'] = true;
1856
-                        $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1857
-                        $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1856
+                        $vies_company = !empty($result['company']) ? $result['company'] : '';
1857
+                        $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1858 1858
                     
1859
-                        $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1859
+                        $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1860 1860
 
1861
-                        if ( !( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) ) {         
1861
+                        if (!(!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company)) {         
1862 1862
                             $vat_data['valid'] = false;
1863 1863
                             
1864
-                            $message = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name );
1864
+                            $message = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name);
1865 1865
                         }
1866 1866
                     } else {
1867
-                        $message = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
1867
+                        $message = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
1868 1868
                     }
1869 1869
                 }
1870 1870
                 
1871
-                if ( !$vat_data['valid'] ) {
1872
-                    $error = wp_sprintf( __( 'The %s %s number %s you have entered has not been validated', 'invoicing' ), '<a href="#wpi-vat-details">', $vat_name, '</a>' ) . ( $message ? ' ( ' . $message . ' )' : '' );
1873
-                    wpinv_set_error( 'vat_validation', $error );
1871
+                if (!$vat_data['valid']) {
1872
+                    $error = wp_sprintf(__('The %s %s number %s you have entered has not been validated', 'invoicing'), '<a href="#wpi-vat-details">', $vat_name, '</a>') . ($message ? ' ( ' . $message . ' )' : '');
1873
+                    wpinv_set_error('vat_validation', $error);
1874 1874
                 }
1875 1875
             }
1876 1876
         }
1877 1877
 
1878
-        $wpi_session->set( 'user_vat_data', $vat_data );
1878
+        $wpi_session->set('user_vat_data', $vat_data);
1879 1879
     }
1880 1880
     
1881
-    public static function checkout_vat_fields( $billing_details ) {
1881
+    public static function checkout_vat_fields($billing_details) {
1882 1882
         global $wpi_session, $wpinv_options, $wpi_country, $wpi_requires_vat;
1883 1883
         
1884 1884
         $ip_address         = wpinv_get_ip();
1885 1885
         $ip_country_code    = self::get_country_by_ip();
1886 1886
         
1887
-        $tax_label          = __( self::get_vat_name(), 'invoicing' );
1887
+        $tax_label          = __(self::get_vat_name(), 'invoicing');
1888 1888
         $invoice            = wpinv_get_invoice_cart();
1889
-        $is_digital         = self::invoice_has_digital_rule( $invoice );
1889
+        $is_digital         = self::invoice_has_digital_rule($invoice);
1890 1890
         $wpi_country        = $invoice->country;
1891 1891
         
1892
-        $requires_vat       = !self::hide_vat_fields() && $invoice->get_total() > 0 && self::requires_vat( 0, false, $is_digital );
1892
+        $requires_vat       = !self::hide_vat_fields() && $invoice->get_total() > 0 && self::requires_vat(0, false, $is_digital);
1893 1893
         $wpi_requires_vat   = $requires_vat;
1894 1894
         
1895 1895
         $company            = is_user_logged_in() ? self::get_user_company() : '';
1896 1896
         $vat_number         = self::get_user_vat_number();
1897 1897
         
1898
-        $validated          = $vat_number ? self::get_user_vat_number( '', 0, true ) : 1;
1899
-        $vat_info           = $wpi_session->get( 'user_vat_data' );
1898
+        $validated          = $vat_number ? self::get_user_vat_number('', 0, true) : 1;
1899
+        $vat_info           = $wpi_session->get('user_vat_data');
1900 1900
 
1901
-        if ( is_array( $vat_info ) ) {
1902
-            $company    = isset( $vat_info['company'] ) ? $vat_info['company'] : '';
1903
-            $vat_number = isset( $vat_info['number'] ) ? $vat_info['number'] : '';
1904
-            $validated  = isset( $vat_info['valid'] ) ? $vat_info['valid'] : false;
1901
+        if (is_array($vat_info)) {
1902
+            $company    = isset($vat_info['company']) ? $vat_info['company'] : '';
1903
+            $vat_number = isset($vat_info['number']) ? $vat_info['number'] : '';
1904
+            $validated  = isset($vat_info['valid']) ? $vat_info['valid'] : false;
1905 1905
         }
1906 1906
         
1907 1907
         $selected_country = $invoice->country ? $invoice->country : wpinv_default_billing_country();
1908 1908
 
1909
-        if ( $ip_country_code == 'UK' ) {
1909
+        if ($ip_country_code == 'UK') {
1910 1910
             $ip_country_code = 'GB';
1911 1911
         }
1912 1912
         
1913
-        if ( $selected_country == 'UK' ) {
1913
+        if ($selected_country == 'UK') {
1914 1914
             $selected_country = 'GB';
1915 1915
         }
1916 1916
         
1917
-        if ( self::same_country_rule() == 'no' && wpinv_is_base_country( $selected_country ) ) {
1917
+        if (self::same_country_rule() == 'no' && wpinv_is_base_country($selected_country)) {
1918 1918
             $requires_vat       = false;
1919 1919
         }
1920 1920
 
@@ -1922,52 +1922,52 @@  discard block
 block discarded – undo
1922 1922
         $display_validate_btn   = 'none';
1923 1923
         $display_reset_btn      = 'none';
1924 1924
         
1925
-        if ( !empty( $vat_number ) && $validated ) {
1926
-            $vat_vailidated_text    = wp_sprintf( __( '%s number validated', 'invoicing' ), $tax_label );
1925
+        if (!empty($vat_number) && $validated) {
1926
+            $vat_vailidated_text    = wp_sprintf(__('%s number validated', 'invoicing'), $tax_label);
1927 1927
             $vat_vailidated_class   = 'wpinv-vat-stat-1';
1928 1928
             $display_reset_btn      = 'block';
1929 1929
         } else {
1930
-            $vat_vailidated_text    = empty( $vat_number ) ? '' : wp_sprintf( __( '%s number not validated', 'invoicing' ), $tax_label );
1931
-            $vat_vailidated_class   = empty( $vat_number ) ? '' : 'wpinv-vat-stat-0';
1930
+            $vat_vailidated_text    = empty($vat_number) ? '' : wp_sprintf(__('%s number not validated', 'invoicing'), $tax_label);
1931
+            $vat_vailidated_class   = empty($vat_number) ? '' : 'wpinv-vat-stat-0';
1932 1932
             $display_validate_btn   = 'block';
1933 1933
         }
1934 1934
         
1935
-        $show_ip_country        = $is_digital && ( empty( $vat_number ) || !$requires_vat ) && $ip_country_code != $selected_country ? 'block' : 'none';
1935
+        $show_ip_country = $is_digital && (empty($vat_number) || !$requires_vat) && $ip_country_code != $selected_country ? 'block' : 'none';
1936 1936
         ?>
1937 1937
         <div id="wpi-vat-details" class="wpi-vat-details clearfix" style="display:<?php echo $display_vat_details; ?>">
1938 1938
             <div id="wpi_vat_info" class="clearfix panel panel-default">
1939
-                <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf( __( '%s Details', 'invoicing' ), $tax_label );?></h3></div>
1939
+                <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf(__('%s Details', 'invoicing'), $tax_label); ?></h3></div>
1940 1940
                 <div id="wpinv-fields-box" class="panel-body">
1941 1941
                     <p id="wpi_show_vat_note">
1942
-                        <?php echo wp_sprintf( __( 'Validate your registered %s number to exclude tax.', 'invoicing' ), $tax_label ); ?>
1942
+                        <?php echo wp_sprintf(__('Validate your registered %s number to exclude tax.', 'invoicing'), $tax_label); ?>
1943 1943
                     </p>
1944 1944
                     <div id="wpi_vat_fields" class="wpi_vat_info">
1945 1945
                         <p class="wpi-cart-field wpi-col2 wpi-colf">
1946
-                            <label for="wpinv_company" class="wpi-label"><?php _e( 'Company Name', 'invoicing' );?></label>
1946
+                            <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label>
1947 1947
                             <?php
1948
-                            echo wpinv_html_text( array(
1948
+                            echo wpinv_html_text(array(
1949 1949
                                     'id'            => 'wpinv_company',
1950 1950
                                     'name'          => 'wpinv_company',
1951 1951
                                     'value'         => $company,
1952 1952
                                     'class'         => 'wpi-input form-control',
1953
-                                    'placeholder'   => __( 'Company name', 'invoicing' ),
1954
-                                ) );
1953
+                                    'placeholder'   => __('Company name', 'invoicing'),
1954
+                                ));
1955 1955
                             ?>
1956 1956
                         </p>
1957 1957
                         <p class="wpi-cart-field wpi-col2 wpi-coll wpi-cart-field-vat">
1958
-                            <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf( __( '%s Number', 'invoicing' ), $tax_label );?></label>
1958
+                            <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf(__('%s Number', 'invoicing'), $tax_label); ?></label>
1959 1959
                             <span id="wpinv_vat_number-wrap">
1960 1960
                                 <label for="wpinv_vat_number" class="wpinv-label"></label>
1961
-                                <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr( wp_sprintf( __( '%s number', 'invoicing' ), $tax_label ) );?>" value="<?php esc_attr_e( $vat_number );?>" id="wpinv_vat_number" name="wpinv_vat_number">
1962
-                                <span class="wpinv-vat-stat <?php echo $vat_vailidated_class;?>"><i class="fa"></i>&nbsp;<font><?php echo $vat_vailidated_text;?></font></span>
1961
+                                <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr(wp_sprintf(__('%s number', 'invoicing'), $tax_label)); ?>" value="<?php esc_attr_e($vat_number); ?>" id="wpinv_vat_number" name="wpinv_vat_number">
1962
+                                <span class="wpinv-vat-stat <?php echo $vat_vailidated_class; ?>"><i class="fa"></i>&nbsp;<font><?php echo $vat_vailidated_text; ?></font></span>
1963 1963
                             </span>
1964 1964
                         </p>
1965 1965
                         <p class="wpi-cart-field wpi-col wpi-colf wpi-cart-field-actions">
1966
-                            <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf( __("Validate %s Number", 'invoicing'), $tax_label ); ?></button>
1967
-                            <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf( __("Reset %s", 'invoicing'), $tax_label ); ?></button>
1966
+                            <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf(__("Validate %s Number", 'invoicing'), $tax_label); ?></button>
1967
+                            <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf(__("Reset %s", 'invoicing'), $tax_label); ?></button>
1968 1968
                             <span class="wpi-vat-box wpi-vat-box-info"><span id="text"></span></span>
1969 1969
                             <span class="wpi-vat-box wpi-vat-box-error"><span id="text"></span></span>
1970
-                            <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce( 'vat_validation' ) ?>" />
1970
+                            <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce('vat_validation') ?>" />
1971 1971
                         </p>
1972 1972
                     </div>
1973 1973
                 </div>
@@ -1981,32 +1981,32 @@  discard block
 block discarded – undo
1981 1981
                 </span>
1982 1982
             </div>
1983 1983
         </div>
1984
-        <?php if ( empty( $wpinv_options['hide_ip_address'] ) ) { 
1985
-            $ip_link = '<a title="' . esc_attr( __( 'View more details on map', 'invoicing' ) ) . '" target="_blank" href="' . esc_url( admin_url( 'admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address ) ) . '" class="wpi-ip-address-link">' . $ip_address . '&nbsp;&nbsp;<i class="fa fa-external-link-square" aria-hidden="true"></i></a>';
1984
+        <?php if (empty($wpinv_options['hide_ip_address'])) { 
1985
+            $ip_link = '<a title="' . esc_attr(__('View more details on map', 'invoicing')) . '" target="_blank" href="' . esc_url(admin_url('admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address)) . '" class="wpi-ip-address-link">' . $ip_address . '&nbsp;&nbsp;<i class="fa fa-external-link-square" aria-hidden="true"></i></a>';
1986 1986
         ?>
1987 1987
         <div class="wpi-ip-info clearfix panel panel-info">
1988 1988
             <div id="wpinv-fields-box" class="panel-body">
1989
-                <span><?php echo wp_sprintf( __( "Your IP address is: %s", 'invoicing' ), $ip_link ); ?></span>
1989
+                <span><?php echo wp_sprintf(__("Your IP address is: %s", 'invoicing'), $ip_link); ?></span>
1990 1990
             </div>
1991 1991
         </div>
1992 1992
         <?php }
1993 1993
     }
1994 1994
     
1995
-    public static function show_vat_notice( $invoice ) {
1996
-        if ( empty( $invoice ) ) {
1995
+    public static function show_vat_notice($invoice) {
1996
+        if (empty($invoice)) {
1997 1997
             return NULL;
1998 1998
         }
1999 1999
         
2000
-        $label      = wpinv_get_option( 'vat_invoice_notice_label' );
2001
-        $notice     = wpinv_get_option( 'vat_invoice_notice' );
2002
-        if ( $label || $notice ) {
2000
+        $label      = wpinv_get_option('vat_invoice_notice_label');
2001
+        $notice     = wpinv_get_option('vat_invoice_notice');
2002
+        if ($label || $notice) {
2003 2003
         ?>
2004 2004
         <div class="row wpinv-vat-notice">
2005 2005
             <div class="col-sm-12">
2006
-                <?php if ( $label ) { ?>
2007
-                <strong><?php _e( $label, 'invoicing' ); ?></strong>
2008
-                <?php } if ( $notice ) { ?>
2009
-                <?php echo wpautop( wptexturize( __( $notice, 'invoicing' ) ) ) ?>
2006
+                <?php if ($label) { ?>
2007
+                <strong><?php _e($label, 'invoicing'); ?></strong>
2008
+                <?php } if ($notice) { ?>
2009
+                <?php echo wpautop(wptexturize(__($notice, 'invoicing'))) ?>
2010 2010
                 <?php } ?>
2011 2011
             </div>
2012 2012
         </div>
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.
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   +469 added lines, -469 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']     = 'gd_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,99 +189,99 @@  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
-    $start_timestamp        = strtotime( $meta['start'] );
216
+    $start_timestamp        = strtotime($meta['start']);
217 217
 
218
-    if ( !empty( $meta['start'] ) ) {
219
-        $meta['start']      = date( 'Y-m-d H:i:s', $start_timestamp );
218
+    if (!empty($meta['start'])) {
219
+        $meta['start']      = date('Y-m-d H:i:s', $start_timestamp);
220 220
     }
221 221
         
222
-    if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) {
222
+    if ($meta['type'] == 'percent' && (float)$meta['amount'] > 100) {
223 223
         $meta['amount'] = 100;
224 224
     }
225 225
 
226
-    if ( !empty( $meta['expiration'] ) ) {
227
-        $meta['expiration'] = date( 'Y-m-d H:i:s', strtotime( date( 'Y-m-d', strtotime( $meta['expiration'] ) ) . ' 23:59:59' ) );
228
-        $end_timestamp      = strtotime( $meta['expiration'] );
226
+    if (!empty($meta['expiration'])) {
227
+        $meta['expiration'] = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime($meta['expiration'])) . ' 23:59:59'));
228
+        $end_timestamp      = strtotime($meta['expiration']);
229 229
 
230
-        if ( !empty( $meta['start'] ) && $start_timestamp > $end_timestamp ) {
230
+        if (!empty($meta['start']) && $start_timestamp > $end_timestamp) {
231 231
             $meta['expiration'] = $meta['start']; // Set the expiration date to the start date if start is later than expiration date.
232 232
         }
233 233
     }
234 234
     
235
-    if ( $meta['uses'] === false ) {
236
-        unset( $meta['uses'] );
235
+    if ($meta['uses'] === false) {
236
+        unset($meta['uses']);
237 237
     }
238 238
     
239
-    if ( ! empty( $meta['items'] ) ) {
240
-        foreach ( $meta['items'] as $key => $item ) {
241
-            if ( 0 === intval( $item ) ) {
242
-                unset( $meta['items'][ $key ] );
239
+    if (!empty($meta['items'])) {
240
+        foreach ($meta['items'] as $key => $item) {
241
+            if (0 === intval($item)) {
242
+                unset($meta['items'][$key]);
243 243
             }
244 244
         }
245 245
     }
246 246
     
247
-    if ( ! empty( $meta['excluded_items'] ) ) {
248
-        foreach ( $meta['excluded_items'] as $key => $item ) {
249
-            if ( 0 === intval( $item ) ) {
250
-                unset( $meta['excluded_items'][ $key ] );
247
+    if (!empty($meta['excluded_items'])) {
248
+        foreach ($meta['excluded_items'] as $key => $item) {
249
+            if (0 === intval($item)) {
250
+                unset($meta['excluded_items'][$key]);
251 251
             }
252 252
         }
253 253
     }
254 254
     
255
-    $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post );
255
+    $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post);
256 256
     
257
-    do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post );
257
+    do_action('wpinv_pre_update_discount', $meta, $post_id, $post);
258 258
     
259
-    foreach( $meta as $key => $value ) {
260
-        update_post_meta( $post_id, '_wpi_discount_' . $key, $value );
259
+    foreach ($meta as $key => $value) {
260
+        update_post_meta($post_id, '_wpi_discount_' . $key, $value);
261 261
     }
262 262
     
263
-    do_action( 'wpinv_post_update_discount', $meta, $post_id, $post );
263
+    do_action('wpinv_post_update_discount', $meta, $post_id, $post);
264 264
     
265 265
     return $post_id;
266 266
 }
267 267
 
268
-function wpinv_remove_discount( $discount_id = 0 ) {
269
-    do_action( 'wpinv_pre_delete_discount', $discount_id );
268
+function wpinv_remove_discount($discount_id = 0) {
269
+    do_action('wpinv_pre_delete_discount', $discount_id);
270 270
 
271
-    wp_delete_post( $discount_id, true );
271
+    wp_delete_post($discount_id, true);
272 272
 
273
-    do_action( 'wpinv_post_delete_discount', $discount_id );
273
+    do_action('wpinv_post_delete_discount', $discount_id);
274 274
 }
275 275
 
276
-function wpinv_update_discount_status( $code_id = 0, $new_status = 'publish' ) {
277
-    $discount = wpinv_get_discount(  $code_id );
276
+function wpinv_update_discount_status($code_id = 0, $new_status = 'publish') {
277
+    $discount = wpinv_get_discount($code_id);
278 278
 
279
-    if ( $discount ) {
280
-        do_action( 'wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status );
279
+    if ($discount) {
280
+        do_action('wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status);
281 281
 
282
-        wp_update_post( array( 'ID' => $code_id, 'post_status' => $new_status ) );
282
+        wp_update_post(array('ID' => $code_id, 'post_status' => $new_status));
283 283
 
284
-        do_action( 'wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status );
284
+        do_action('wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status);
285 285
 
286 286
         return true;
287 287
     }
@@ -289,173 +289,173 @@  discard block
 block discarded – undo
289 289
     return false;
290 290
 }
291 291
 
292
-function wpinv_discount_exists( $code_id ) {
293
-    if ( wpinv_get_discount(  $code_id ) ) {
292
+function wpinv_discount_exists($code_id) {
293
+    if (wpinv_get_discount($code_id)) {
294 294
         return true;
295 295
     }
296 296
 
297 297
     return false;
298 298
 }
299 299
 
300
-function wpinv_is_discount_active( $code_id = null ) {
301
-    $discount = wpinv_get_discount(  $code_id );
300
+function wpinv_is_discount_active($code_id = null) {
301
+    $discount = wpinv_get_discount($code_id);
302 302
     $return   = false;
303 303
 
304
-    if ( $discount ) {
305
-        if ( wpinv_is_discount_expired( $code_id ) ) {
306
-            if( defined( 'DOING_AJAX' ) ) {
307
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) );
304
+    if ($discount) {
305
+        if (wpinv_is_discount_expired($code_id)) {
306
+            if (defined('DOING_AJAX')) {
307
+                wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing'));
308 308
             }
309
-        } elseif ( $discount->post_status == 'publish' ) {
309
+        } elseif ($discount->post_status == 'publish') {
310 310
             $return = true;
311 311
         } else {
312
-            if( defined( 'DOING_AJAX' ) ) {
313
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) );
312
+            if (defined('DOING_AJAX')) {
313
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing'));
314 314
             }
315 315
         }
316 316
     }
317 317
 
318
-    return apply_filters( 'wpinv_is_discount_active', $return, $code_id );
318
+    return apply_filters('wpinv_is_discount_active', $return, $code_id);
319 319
 }
320 320
 
321
-function wpinv_get_discount_code( $code_id = null ) {
322
-    $code = get_post_meta( $code_id, '_wpi_discount_code', true );
321
+function wpinv_get_discount_code($code_id = null) {
322
+    $code = get_post_meta($code_id, '_wpi_discount_code', true);
323 323
 
324
-    return apply_filters( 'wpinv_get_discount_code', $code, $code_id );
324
+    return apply_filters('wpinv_get_discount_code', $code, $code_id);
325 325
 }
326 326
 
327
-function wpinv_get_discount_start_date( $code_id = null ) {
328
-    $start_date = get_post_meta( $code_id, '_wpi_discount_start', true );
327
+function wpinv_get_discount_start_date($code_id = null) {
328
+    $start_date = get_post_meta($code_id, '_wpi_discount_start', true);
329 329
 
330
-    return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id );
330
+    return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id);
331 331
 }
332 332
 
333
-function wpinv_get_discount_expiration( $code_id = null ) {
334
-    $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true );
333
+function wpinv_get_discount_expiration($code_id = null) {
334
+    $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true);
335 335
 
336
-    return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id );
336
+    return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id);
337 337
 }
338 338
 
339
-function wpinv_get_discount_max_uses( $code_id = null ) {
340
-    $max_uses = get_post_meta( $code_id, '_wpi_discount_max_uses', true );
339
+function wpinv_get_discount_max_uses($code_id = null) {
340
+    $max_uses = get_post_meta($code_id, '_wpi_discount_max_uses', true);
341 341
 
342
-    return (int) apply_filters( 'wpinv_get_discount_max_uses', $max_uses, $code_id );
342
+    return (int)apply_filters('wpinv_get_discount_max_uses', $max_uses, $code_id);
343 343
 }
344 344
 
345
-function wpinv_get_discount_uses( $code_id = null ) {
346
-    $uses = get_post_meta( $code_id, '_wpi_discount_uses', true );
345
+function wpinv_get_discount_uses($code_id = null) {
346
+    $uses = get_post_meta($code_id, '_wpi_discount_uses', true);
347 347
 
348
-    return (int) apply_filters( 'wpinv_get_discount_uses', $uses, $code_id );
348
+    return (int)apply_filters('wpinv_get_discount_uses', $uses, $code_id);
349 349
 }
350 350
 
351
-function wpinv_get_discount_min_total( $code_id = null ) {
352
-    $min_total = get_post_meta( $code_id, '_wpi_discount_min_total', true );
351
+function wpinv_get_discount_min_total($code_id = null) {
352
+    $min_total = get_post_meta($code_id, '_wpi_discount_min_total', true);
353 353
 
354
-    return (float) apply_filters( 'wpinv_get_discount_min_total', $min_total, $code_id );
354
+    return (float)apply_filters('wpinv_get_discount_min_total', $min_total, $code_id);
355 355
 }
356 356
 
357
-function wpinv_get_discount_max_total( $code_id = null ) {
358
-    $max_total = get_post_meta( $code_id, '_wpi_discount_max_total', true );
357
+function wpinv_get_discount_max_total($code_id = null) {
358
+    $max_total = get_post_meta($code_id, '_wpi_discount_max_total', true);
359 359
 
360
-    return (float) apply_filters( 'wpinv_get_discount_max_total', $max_total, $code_id );
360
+    return (float)apply_filters('wpinv_get_discount_max_total', $max_total, $code_id);
361 361
 }
362 362
 
363
-function wpinv_get_discount_amount( $code_id = null ) {
364
-    $amount = get_post_meta( $code_id, '_wpi_discount_amount', true );
363
+function wpinv_get_discount_amount($code_id = null) {
364
+    $amount = get_post_meta($code_id, '_wpi_discount_amount', true);
365 365
 
366
-    return (float) apply_filters( 'wpinv_get_discount_amount', $amount, $code_id );
366
+    return (float)apply_filters('wpinv_get_discount_amount', $amount, $code_id);
367 367
 }
368 368
 
369
-function wpinv_get_discount_type( $code_id = null, $name = false ) {
370
-    $type = strtolower( get_post_meta( $code_id, '_wpi_discount_type', true ) );
369
+function wpinv_get_discount_type($code_id = null, $name = false) {
370
+    $type = strtolower(get_post_meta($code_id, '_wpi_discount_type', true));
371 371
     
372
-    if ( $name ) {
373
-        $name = wpinv_get_discount_type_name( $type );
372
+    if ($name) {
373
+        $name = wpinv_get_discount_type_name($type);
374 374
         
375
-        return apply_filters( 'wpinv_get_discount_type_name', $name, $code_id );
375
+        return apply_filters('wpinv_get_discount_type_name', $name, $code_id);
376 376
     }
377 377
 
378
-    return apply_filters( 'wpinv_get_discount_type', $type, $code_id );
378
+    return apply_filters('wpinv_get_discount_type', $type, $code_id);
379 379
 }
380 380
 
381
-function wpinv_discount_status( $status ) {
382
-    switch( $status ){
381
+function wpinv_discount_status($status) {
382
+    switch ($status) {
383 383
         case 'expired' :
384
-            $name = __( 'Expired', 'invoicing' );
384
+            $name = __('Expired', 'invoicing');
385 385
             break;
386 386
         case 'publish' :
387 387
         case 'active' :
388
-            $name = __( 'Active', 'invoicing' );
388
+            $name = __('Active', 'invoicing');
389 389
             break;
390 390
         default :
391
-            $name = __( 'Inactive', 'invoicing' );
391
+            $name = __('Inactive', 'invoicing');
392 392
             break;
393 393
     }
394 394
     return $name;
395 395
 }
396 396
 
397
-function wpinv_get_discount_excluded_items( $code_id = null ) {
398
-    $excluded_items = get_post_meta( $code_id, '_wpi_discount_excluded_items', true );
397
+function wpinv_get_discount_excluded_items($code_id = null) {
398
+    $excluded_items = get_post_meta($code_id, '_wpi_discount_excluded_items', true);
399 399
 
400
-    if ( empty( $excluded_items ) || ! is_array( $excluded_items ) ) {
400
+    if (empty($excluded_items) || !is_array($excluded_items)) {
401 401
         $excluded_items = array();
402 402
     }
403 403
 
404
-    return (array) apply_filters( 'wpinv_get_discount_excluded_items', $excluded_items, $code_id );
404
+    return (array)apply_filters('wpinv_get_discount_excluded_items', $excluded_items, $code_id);
405 405
 }
406 406
 
407
-function wpinv_get_discount_item_reqs( $code_id = null ) {
408
-    $item_reqs = get_post_meta( $code_id, '_wpi_discount_items', true );
407
+function wpinv_get_discount_item_reqs($code_id = null) {
408
+    $item_reqs = get_post_meta($code_id, '_wpi_discount_items', true);
409 409
 
410
-    if ( empty( $item_reqs ) || ! is_array( $item_reqs ) ) {
410
+    if (empty($item_reqs) || !is_array($item_reqs)) {
411 411
         $item_reqs = array();
412 412
     }
413 413
 
414
-    return (array) apply_filters( 'wpinv_get_discount_item_reqs', $item_reqs, $code_id );
414
+    return (array)apply_filters('wpinv_get_discount_item_reqs', $item_reqs, $code_id);
415 415
 }
416 416
 
417
-function wpinv_get_discount_item_condition( $code_id = 0 ) {
418
-    return get_post_meta( $code_id, '_wpi_discount_item_condition', true );
417
+function wpinv_get_discount_item_condition($code_id = 0) {
418
+    return get_post_meta($code_id, '_wpi_discount_item_condition', true);
419 419
 }
420 420
 
421
-function wpinv_is_discount_not_global( $code_id = 0 ) {
422
-    return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true );
421
+function wpinv_is_discount_not_global($code_id = 0) {
422
+    return (bool)get_post_meta($code_id, '_wpi_discount_is_not_global', true);
423 423
 }
424 424
 
425
-function wpinv_is_discount_expired( $code_id = null ) {
426
-    $discount = wpinv_get_discount(  $code_id );
425
+function wpinv_is_discount_expired($code_id = null) {
426
+    $discount = wpinv_get_discount($code_id);
427 427
     $return   = false;
428 428
 
429
-    if ( $discount ) {
430
-        $expiration = wpinv_get_discount_expiration( $code_id );
431
-        if ( $expiration ) {
432
-            $expiration = strtotime( $expiration );
433
-            if ( $expiration < current_time( 'timestamp' ) ) {
429
+    if ($discount) {
430
+        $expiration = wpinv_get_discount_expiration($code_id);
431
+        if ($expiration) {
432
+            $expiration = strtotime($expiration);
433
+            if ($expiration < current_time('timestamp')) {
434 434
                 // Discount is expired
435
-                wpinv_update_discount_status( $code_id, 'pending' );
435
+                wpinv_update_discount_status($code_id, 'pending');
436 436
                 $return = true;
437 437
             }
438 438
         }
439 439
     }
440 440
 
441
-    return apply_filters( 'wpinv_is_discount_expired', $return, $code_id );
441
+    return apply_filters('wpinv_is_discount_expired', $return, $code_id);
442 442
 }
443 443
 
444
-function wpinv_is_discount_started( $code_id = null ) {
445
-    $discount = wpinv_get_discount(  $code_id );
444
+function wpinv_is_discount_started($code_id = null) {
445
+    $discount = wpinv_get_discount($code_id);
446 446
     $return   = false;
447 447
 
448
-    if ( $discount ) {
449
-        $start_date = wpinv_get_discount_start_date( $code_id );
448
+    if ($discount) {
449
+        $start_date = wpinv_get_discount_start_date($code_id);
450 450
 
451
-        if ( $start_date ) {
452
-            $start_date = strtotime( $start_date );
451
+        if ($start_date) {
452
+            $start_date = strtotime($start_date);
453 453
 
454
-            if ( $start_date < current_time( 'timestamp' ) ) {
454
+            if ($start_date < current_time('timestamp')) {
455 455
                 // Discount has past the start date
456 456
                 $return = true;
457 457
             } else {
458
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
458
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
459 459
             }
460 460
         } else {
461 461
             // No start date for this discount, so has to be true
@@ -463,159 +463,159 @@  discard block
 block discarded – undo
463 463
         }
464 464
     }
465 465
 
466
-    return apply_filters( 'wpinv_is_discount_started', $return, $code_id );
466
+    return apply_filters('wpinv_is_discount_started', $return, $code_id);
467 467
 }
468 468
 
469
-function wpinv_check_discount_dates( $code_id = null ) {
470
-    $discount = wpinv_get_discount(  $code_id );
469
+function wpinv_check_discount_dates($code_id = null) {
470
+    $discount = wpinv_get_discount($code_id);
471 471
     $return   = false;
472 472
 
473
-    if ( $discount ) {
474
-        $start_date = wpinv_get_discount_start_date( $code_id );
473
+    if ($discount) {
474
+        $start_date = wpinv_get_discount_start_date($code_id);
475 475
 
476
-        if ( $start_date ) {
477
-            $start_date = strtotime( $start_date );
476
+        if ($start_date) {
477
+            $start_date = strtotime($start_date);
478 478
 
479
-            if ( $start_date < current_time( 'timestamp' ) ) {
479
+            if ($start_date < current_time('timestamp')) {
480 480
                 // Discount has past the start date
481 481
                 $return = true;
482 482
             } else {
483
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
483
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
484 484
             }
485 485
         } else {
486 486
             // No start date for this discount, so has to be true
487 487
             $return = true;
488 488
         }
489 489
         
490
-        if ( $return ) {
491
-            $expiration = wpinv_get_discount_expiration( $code_id );
490
+        if ($return) {
491
+            $expiration = wpinv_get_discount_expiration($code_id);
492 492
             
493
-            if ( $expiration ) {
494
-                $expiration = strtotime( $expiration );
495
-                if ( $expiration < current_time( 'timestamp' ) ) {
493
+            if ($expiration) {
494
+                $expiration = strtotime($expiration);
495
+                if ($expiration < current_time('timestamp')) {
496 496
                     // Discount is expired
497
-                    wpinv_update_discount_status( $code_id, 'pending' );
497
+                    wpinv_update_discount_status($code_id, 'pending');
498 498
                     $return = true;
499 499
                 }
500 500
             }
501 501
         }
502 502
     }
503 503
     
504
-    return apply_filters( 'wpinv_check_discount_dates', $return, $code_id );
504
+    return apply_filters('wpinv_check_discount_dates', $return, $code_id);
505 505
 }
506 506
 
507
-function wpinv_is_discount_maxed_out( $code_id = null ) {
508
-    $discount = wpinv_get_discount(  $code_id );
507
+function wpinv_is_discount_maxed_out($code_id = null) {
508
+    $discount = wpinv_get_discount($code_id);
509 509
     $return   = false;
510 510
 
511
-    if ( $discount ) {
512
-        $uses = wpinv_get_discount_uses( $code_id );
511
+    if ($discount) {
512
+        $uses = wpinv_get_discount_uses($code_id);
513 513
         // Large number that will never be reached
514
-        $max_uses = wpinv_get_discount_max_uses( $code_id );
514
+        $max_uses = wpinv_get_discount_max_uses($code_id);
515 515
         // Should never be greater than, but just in case
516
-        if ( $uses >= $max_uses && ! empty( $max_uses ) ) {
516
+        if ($uses >= $max_uses && !empty($max_uses)) {
517 517
             // Discount is maxed out
518
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) );
518
+            wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing'));
519 519
             $return = true;
520 520
         }
521 521
     }
522 522
 
523
-    return apply_filters( 'wpinv_is_discount_maxed_out', $return, $code_id );
523
+    return apply_filters('wpinv_is_discount_maxed_out', $return, $code_id);
524 524
 }
525 525
 
526
-function wpinv_discount_is_min_met( $code_id = null ) {
527
-    $discount = wpinv_get_discount( $code_id );
526
+function wpinv_discount_is_min_met($code_id = null) {
527
+    $discount = wpinv_get_discount($code_id);
528 528
     $return   = false;
529 529
 
530
-    if ( $discount ) {
531
-        $min         = (float)wpinv_get_discount_min_total( $code_id );
532
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
530
+    if ($discount) {
531
+        $min         = (float)wpinv_get_discount_min_total($code_id);
532
+        $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id);
533 533
 
534
-        if ( !$min > 0 || $cart_amount >= $min ) {
534
+        if (!$min > 0 || $cart_amount >= $min) {
535 535
             // Minimum has been met
536 536
             $return = true;
537 537
         } else {
538
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $min ) ) ) );
538
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($min))));
539 539
         }
540 540
     }
541 541
 
542
-    return apply_filters( 'wpinv_is_discount_min_met', $return, $code_id );
542
+    return apply_filters('wpinv_is_discount_min_met', $return, $code_id);
543 543
 }
544 544
 
545
-function wpinv_discount_is_max_met( $code_id = null ) {
546
-    $discount = wpinv_get_discount( $code_id );
545
+function wpinv_discount_is_max_met($code_id = null) {
546
+    $discount = wpinv_get_discount($code_id);
547 547
     $return   = false;
548 548
 
549
-    if ( $discount ) {
550
-        $max         = (float)wpinv_get_discount_max_total( $code_id );
551
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
549
+    if ($discount) {
550
+        $max         = (float)wpinv_get_discount_max_total($code_id);
551
+        $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id);
552 552
 
553
-        if ( !$max > 0 || $cart_amount <= $max ) {
553
+        if (!$max > 0 || $cart_amount <= $max) {
554 554
             // Minimum has been met
555 555
             $return = true;
556 556
         } else {
557
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $max ) ) ) );
557
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($max))));
558 558
         }
559 559
     }
560 560
 
561
-    return apply_filters( 'wpinv_is_discount_max_met', $return, $code_id );
561
+    return apply_filters('wpinv_is_discount_max_met', $return, $code_id);
562 562
 }
563 563
 
564
-function wpinv_discount_is_single_use( $code_id = 0 ) {
565
-    $single_use = get_post_meta( $code_id, '_wpi_discount_is_single_use', true );
566
-    return (bool) apply_filters( 'wpinv_is_discount_single_use', $single_use, $code_id );
564
+function wpinv_discount_is_single_use($code_id = 0) {
565
+    $single_use = get_post_meta($code_id, '_wpi_discount_is_single_use', true);
566
+    return (bool)apply_filters('wpinv_is_discount_single_use', $single_use, $code_id);
567 567
 }
568 568
 
569
-function wpinv_discount_is_recurring( $code_id = 0, $code = false ) {
570
-    if ( $code ) {
571
-        $discount = wpinv_get_discount_by_code( $code_id );
569
+function wpinv_discount_is_recurring($code_id = 0, $code = false) {
570
+    if ($code) {
571
+        $discount = wpinv_get_discount_by_code($code_id);
572 572
         
573
-        if ( !empty( $discount ) ) {
573
+        if (!empty($discount)) {
574 574
             $code_id = $discount->ID;
575 575
         }
576 576
     }
577 577
     
578
-    $recurring = get_post_meta( $code_id, '_wpi_discount_is_recurring', true );
578
+    $recurring = get_post_meta($code_id, '_wpi_discount_is_recurring', true);
579 579
     
580
-    return (bool) apply_filters( 'wpinv_is_discount_recurring', $recurring, $code_id, $code );
580
+    return (bool)apply_filters('wpinv_is_discount_recurring', $recurring, $code_id, $code);
581 581
 }
582 582
 
583
-function wpinv_discount_item_reqs_met( $code_id = null ) {
584
-    $item_reqs    = wpinv_get_discount_item_reqs( $code_id );
585
-    $condition    = wpinv_get_discount_item_condition( $code_id );
586
-    $excluded_ps  = wpinv_get_discount_excluded_items( $code_id );
583
+function wpinv_discount_item_reqs_met($code_id = null) {
584
+    $item_reqs    = wpinv_get_discount_item_reqs($code_id);
585
+    $condition    = wpinv_get_discount_item_condition($code_id);
586
+    $excluded_ps  = wpinv_get_discount_excluded_items($code_id);
587 587
     $cart_items   = wpinv_get_cart_contents();
588
-    $cart_ids     = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null;
588
+    $cart_ids     = $cart_items ? wp_list_pluck($cart_items, 'id') : null;
589 589
     $ret          = false;
590 590
 
591
-    if ( empty( $item_reqs ) && empty( $excluded_ps ) ) {
591
+    if (empty($item_reqs) && empty($excluded_ps)) {
592 592
         $ret = true;
593 593
     }
594 594
 
595 595
     // Normalize our data for item requirements, exclusions and cart data
596 596
     // First absint the items, then sort, and reset the array keys
597
-    $item_reqs = array_map( 'absint', $item_reqs );
598
-    asort( $item_reqs );
599
-    $item_reqs = array_values( $item_reqs );
597
+    $item_reqs = array_map('absint', $item_reqs);
598
+    asort($item_reqs);
599
+    $item_reqs = array_values($item_reqs);
600 600
 
601
-    $excluded_ps  = array_map( 'absint', $excluded_ps );
602
-    asort( $excluded_ps );
603
-    $excluded_ps  = array_values( $excluded_ps );
601
+    $excluded_ps  = array_map('absint', $excluded_ps);
602
+    asort($excluded_ps);
603
+    $excluded_ps  = array_values($excluded_ps);
604 604
 
605
-    $cart_ids     = array_map( 'absint', $cart_ids );
606
-    asort( $cart_ids );
607
-    $cart_ids     = array_values( $cart_ids );
605
+    $cart_ids     = array_map('absint', $cart_ids);
606
+    asort($cart_ids);
607
+    $cart_ids     = array_values($cart_ids);
608 608
 
609 609
     // Ensure we have requirements before proceeding
610
-    if ( !$ret && ! empty( $item_reqs ) ) {
611
-        switch( $condition ) {
610
+    if (!$ret && !empty($item_reqs)) {
611
+        switch ($condition) {
612 612
             case 'all' :
613 613
                 // Default back to true
614 614
                 $ret = true;
615 615
 
616
-                foreach ( $item_reqs as $item_id ) {
617
-                    if ( !wpinv_item_in_cart( $item_id ) ) {
618
-                        wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
616
+                foreach ($item_reqs as $item_id) {
617
+                    if (!wpinv_item_in_cart($item_id)) {
618
+                        wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
619 619
                         $ret = false;
620 620
                         break;
621 621
                     }
@@ -624,15 +624,15 @@  discard block
 block discarded – undo
624 624
                 break;
625 625
 
626 626
             default : // Any
627
-                foreach ( $item_reqs as $item_id ) {
628
-                    if ( wpinv_item_in_cart( $item_id ) ) {
627
+                foreach ($item_reqs as $item_id) {
628
+                    if (wpinv_item_in_cart($item_id)) {
629 629
                         $ret = true;
630 630
                         break;
631 631
                     }
632 632
                 }
633 633
 
634
-                if( ! $ret ) {
635
-                    wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
634
+                if (!$ret) {
635
+                    wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
636 636
                 }
637 637
 
638 638
                 break;
@@ -641,68 +641,68 @@  discard block
 block discarded – undo
641 641
         $ret = true;
642 642
     }
643 643
 
644
-    if( ! empty( $excluded_ps ) ) {
644
+    if (!empty($excluded_ps)) {
645 645
         // Check that there are items other than excluded ones in the cart
646
-        if( $cart_ids == $excluded_ps ) {
647
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) );
646
+        if ($cart_ids == $excluded_ps) {
647
+            wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing'));
648 648
             $ret = false;
649 649
         }
650 650
     }
651 651
 
652
-    return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition );
652
+    return (bool)apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition);
653 653
 }
654 654
 
655
-function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) {
655
+function wpinv_is_discount_used($code = null, $user = '', $code_id = 0) {
656 656
     global $wpi_checkout_id;
657 657
     
658 658
     $return = false;
659 659
 
660
-    if ( empty( $code_id ) ) {
661
-        $code_id = wpinv_get_discount_id_by_code( $code );
660
+    if (empty($code_id)) {
661
+        $code_id = wpinv_get_discount_id_by_code($code);
662 662
         
663
-        if( empty( $code_id ) ) {
663
+        if (empty($code_id)) {
664 664
             return false; // No discount was found
665 665
         }
666 666
     }
667 667
 
668
-    if ( wpinv_discount_is_single_use( $code_id ) ) {
668
+    if (wpinv_discount_is_single_use($code_id)) {
669 669
         $payments = array();
670 670
 
671 671
         $user_id = 0;
672
-        if ( is_int( $user ) ) {
672
+        if (is_int($user)) {
673 673
             $user_id = $user;
674
-        } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) {
674
+        } else if (is_email($user) && $user_data = get_user_by('email', $user)) {
675 675
             $user_id = $user_data->ID;
676
-        } else if ( $user_data = get_user_by( 'login', $user ) ) {
676
+        } else if ($user_data = get_user_by('login', $user)) {
677 677
             $user_id = $user_data->ID;
678 678
         }
679 679
 
680
-        if ( !$user_id ) {
681
-            $query    = array( 'user' => $user_id, 'limit' => false );
682
-            $payments = wpinv_get_invoices( $query ); // Get all payments with matching email
680
+        if (!$user_id) {
681
+            $query    = array('user' => $user_id, 'limit' => false);
682
+            $payments = wpinv_get_invoices($query); // Get all payments with matching email
683 683
         }
684 684
 
685
-        if ( $payments ) {
686
-            foreach ( $payments as $payment ) {
687
-                if ( $payment->has_status( array( 'cancelled', 'failed' ) ) ) {
685
+        if ($payments) {
686
+            foreach ($payments as $payment) {
687
+                if ($payment->has_status(array('cancelled', 'failed'))) {
688 688
                     continue;
689 689
                 }
690 690
 
691 691
                 // Don't count discount used for current invoice chekcout.
692
-                if ( !empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) {
692
+                if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) {
693 693
                     continue;
694 694
                 }
695 695
 
696
-                $discounts = $payment->get_discounts( true );
697
-                if ( empty( $discounts ) ) {
696
+                $discounts = $payment->get_discounts(true);
697
+                if (empty($discounts)) {
698 698
                     continue;
699 699
                 }
700 700
 
701
-                $discounts = $discounts && !is_array( $discounts ) ? explode( ',', $discounts ) : $discounts;
701
+                $discounts = $discounts && !is_array($discounts) ? explode(',', $discounts) : $discounts;
702 702
 
703
-                if ( !empty( $discounts ) && is_array( $discounts ) ) {
704
-                    if ( in_array( strtolower( $code ), array_map( 'strtolower', $discounts ) ) ) {
705
-                        wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) );
703
+                if (!empty($discounts) && is_array($discounts)) {
704
+                    if (in_array(strtolower($code), array_map('strtolower', $discounts))) {
705
+                        wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing'));
706 706
                         $return = true;
707 707
                         break;
708 708
                     }
@@ -711,61 +711,61 @@  discard block
 block discarded – undo
711 711
         }
712 712
     }
713 713
 
714
-    return apply_filters( 'wpinv_is_discount_used', $return, $code, $user );
714
+    return apply_filters('wpinv_is_discount_used', $return, $code, $user);
715 715
 }
716 716
 
717
-function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) {
717
+function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) {
718 718
     $return      = false;
719
-    $discount_id = wpinv_get_discount_id_by_code( $code );
720
-    $user        = trim( $user );
719
+    $discount_id = wpinv_get_discount_id_by_code($code);
720
+    $user        = trim($user);
721 721
 
722
-    if ( wpinv_get_cart_contents() ) {
723
-        if ( $discount_id ) {
722
+    if (wpinv_get_cart_contents()) {
723
+        if ($discount_id) {
724 724
             if (
725
-                wpinv_is_discount_active( $discount_id ) &&
726
-                wpinv_check_discount_dates( $discount_id ) &&
727
-                !wpinv_is_discount_maxed_out( $discount_id ) &&
728
-                !wpinv_is_discount_used( $code, $user, $discount_id ) &&
729
-                wpinv_discount_is_min_met( $discount_id ) &&
730
-                wpinv_discount_is_max_met( $discount_id ) &&
731
-                wpinv_discount_item_reqs_met( $discount_id )
725
+                wpinv_is_discount_active($discount_id) &&
726
+                wpinv_check_discount_dates($discount_id) &&
727
+                !wpinv_is_discount_maxed_out($discount_id) &&
728
+                !wpinv_is_discount_used($code, $user, $discount_id) &&
729
+                wpinv_discount_is_min_met($discount_id) &&
730
+                wpinv_discount_is_max_met($discount_id) &&
731
+                wpinv_discount_item_reqs_met($discount_id)
732 732
             ) {
733 733
                 $return = true;
734 734
             }
735
-        } elseif( $set_error ) {
736
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) );
735
+        } elseif ($set_error) {
736
+            wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing'));
737 737
         }
738 738
     }
739 739
 
740
-    return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user );
740
+    return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user);
741 741
 }
742 742
 
743
-function wpinv_get_discount_id_by_code( $code ) {
744
-    $discount = wpinv_get_discount_by_code( $code );
745
-    if( $discount ) {
743
+function wpinv_get_discount_id_by_code($code) {
744
+    $discount = wpinv_get_discount_by_code($code);
745
+    if ($discount) {
746 746
         return $discount->ID;
747 747
     }
748 748
     return false;
749 749
 }
750 750
 
751
-function wpinv_get_discounted_amount( $code, $base_price ) {
751
+function wpinv_get_discounted_amount($code, $base_price) {
752 752
     $amount      = $base_price;
753
-    $discount_id = wpinv_get_discount_id_by_code( $code );
753
+    $discount_id = wpinv_get_discount_id_by_code($code);
754 754
 
755
-    if( $discount_id ) {
756
-        $type        = wpinv_get_discount_type( $discount_id );
757
-        $rate        = wpinv_get_discount_amount( $discount_id );
755
+    if ($discount_id) {
756
+        $type        = wpinv_get_discount_type($discount_id);
757
+        $rate        = wpinv_get_discount_amount($discount_id);
758 758
 
759
-        if ( $type == 'flat' ) {
759
+        if ($type == 'flat') {
760 760
             // Set amount
761 761
             $amount = $base_price - $rate;
762
-            if ( $amount < 0 ) {
762
+            if ($amount < 0) {
763 763
                 $amount = 0;
764 764
             }
765 765
 
766 766
         } else {
767 767
             // Percentage discount
768
-            $amount = $base_price - ( $base_price * ( $rate / 100 ) );
768
+            $amount = $base_price - ($base_price * ($rate / 100));
769 769
         }
770 770
 
771 771
     } else {
@@ -774,108 +774,108 @@  discard block
 block discarded – undo
774 774
 
775 775
     }
776 776
 
777
-    return apply_filters( 'wpinv_discounted_amount', $amount );
777
+    return apply_filters('wpinv_discounted_amount', $amount);
778 778
 }
779 779
 
780
-function wpinv_increase_discount_usage( $code ) {
780
+function wpinv_increase_discount_usage($code) {
781 781
 
782
-    $id   = wpinv_get_discount_id_by_code( $code );
783
-    $uses = wpinv_get_discount_uses( $id );
782
+    $id   = wpinv_get_discount_id_by_code($code);
783
+    $uses = wpinv_get_discount_uses($id);
784 784
 
785
-    if ( $uses ) {
785
+    if ($uses) {
786 786
         $uses++;
787 787
     } else {
788 788
         $uses = 1;
789 789
     }
790 790
 
791
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
791
+    update_post_meta($id, '_wpi_discount_uses', $uses);
792 792
 
793
-    do_action( 'wpinv_discount_increase_use_count', $uses, $id, $code );
793
+    do_action('wpinv_discount_increase_use_count', $uses, $id, $code);
794 794
 
795 795
     return $uses;
796 796
 
797 797
 }
798 798
 
799
-function wpinv_decrease_discount_usage( $code ) {
799
+function wpinv_decrease_discount_usage($code) {
800 800
 
801
-    $id   = wpinv_get_discount_id_by_code( $code );
802
-    $uses = wpinv_get_discount_uses( $id );
801
+    $id   = wpinv_get_discount_id_by_code($code);
802
+    $uses = wpinv_get_discount_uses($id);
803 803
 
804
-    if ( $uses ) {
804
+    if ($uses) {
805 805
         $uses--;
806 806
     }
807 807
 
808
-    if ( $uses < 0 ) {
808
+    if ($uses < 0) {
809 809
         $uses = 0;
810 810
     }
811 811
 
812
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
812
+    update_post_meta($id, '_wpi_discount_uses', $uses);
813 813
 
814
-    do_action( 'wpinv_discount_decrease_use_count', $uses, $id, $code );
814
+    do_action('wpinv_discount_decrease_use_count', $uses, $id, $code);
815 815
 
816 816
     return $uses;
817 817
 
818 818
 }
819 819
 
820
-function wpinv_format_discount_rate( $type, $amount ) {
821
-    if ( $type == 'flat' ) {
822
-        return wpinv_price( wpinv_format_amount( $amount ) );
820
+function wpinv_format_discount_rate($type, $amount) {
821
+    if ($type == 'flat') {
822
+        return wpinv_price(wpinv_format_amount($amount));
823 823
     } else {
824 824
         return $amount . '%';
825 825
     }
826 826
 }
827 827
 
828
-function wpinv_set_cart_discount( $code = '' ) {    
829
-    if ( wpinv_multiple_discounts_allowed() ) {
828
+function wpinv_set_cart_discount($code = '') {    
829
+    if (wpinv_multiple_discounts_allowed()) {
830 830
         // Get all active cart discounts
831 831
         $discounts = wpinv_get_cart_discounts();
832 832
     } else {
833 833
         $discounts = false; // Only one discount allowed per purchase, so override any existing
834 834
     }
835 835
 
836
-    if ( $discounts ) {
837
-        $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) );
838
-        if( false !== $key ) {
839
-            unset( $discounts[ $key ] ); // Can't set the same discount more than once
836
+    if ($discounts) {
837
+        $key = array_search(strtolower($code), array_map('strtolower', $discounts));
838
+        if (false !== $key) {
839
+            unset($discounts[$key]); // Can't set the same discount more than once
840 840
         }
841 841
         $discounts[] = $code;
842 842
     } else {
843 843
         $discounts = array();
844 844
         $discounts[] = $code;
845 845
     }
846
-    $discounts = array_values( $discounts );
846
+    $discounts = array_values($discounts);
847 847
     
848 848
     $data = wpinv_get_checkout_session();
849
-    if ( empty( $data ) ) {
849
+    if (empty($data)) {
850 850
         $data = array();
851 851
     } else {
852
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
853
-            $payment_meta['user_info']['discount']  = implode( ',', $discounts );
854
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
852
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
853
+            $payment_meta['user_info']['discount'] = implode(',', $discounts);
854
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
855 855
         }
856 856
     }
857 857
     $data['cart_discounts'] = $discounts;
858 858
     
859
-    wpinv_set_checkout_session( $data );
859
+    wpinv_set_checkout_session($data);
860 860
     
861 861
     return $discounts;
862 862
 }
863 863
 
864
-function wpinv_unset_cart_discount( $code = '' ) {    
864
+function wpinv_unset_cart_discount($code = '') {    
865 865
     $discounts = wpinv_get_cart_discounts();
866 866
 
867
-    if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) {
868
-        $key = array_search( $code, $discounts );
869
-        unset( $discounts[ $key ] );
867
+    if ($code && !empty($discounts) && in_array($code, $discounts)) {
868
+        $key = array_search($code, $discounts);
869
+        unset($discounts[$key]);
870 870
             
871 871
         $data = wpinv_get_checkout_session();
872 872
         $data['cart_discounts'] = $discounts;
873
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
874
-            $payment_meta['user_info']['discount']  = !empty( $discounts ) ? implode( ',', $discounts ) : '';
875
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
873
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
874
+            $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : '';
875
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
876 876
         }
877 877
         
878
-        wpinv_set_checkout_session( $data );
878
+        wpinv_set_checkout_session($data);
879 879
     }
880 880
 
881 881
     return $discounts;
@@ -884,27 +884,27 @@  discard block
 block discarded – undo
884 884
 function wpinv_unset_all_cart_discounts() {
885 885
     $data = wpinv_get_checkout_session();
886 886
     
887
-    if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) {
888
-        unset( $data['cart_discounts'] );
887
+    if (!empty($data) && isset($data['cart_discounts'])) {
888
+        unset($data['cart_discounts']);
889 889
         
890
-         wpinv_set_checkout_session( $data );
890
+         wpinv_set_checkout_session($data);
891 891
          return true;
892 892
     }
893 893
     
894 894
     return false;
895 895
 }
896 896
 
897
-function wpinv_get_cart_discounts( $items = array() ) {
897
+function wpinv_get_cart_discounts($items = array()) {
898 898
     $session = wpinv_get_checkout_session();
899 899
     
900
-    $discounts = !empty( $session['cart_discounts'] ) ? $session['cart_discounts'] : false;
900
+    $discounts = !empty($session['cart_discounts']) ? $session['cart_discounts'] : false;
901 901
     return $discounts;
902 902
 }
903 903
 
904
-function wpinv_cart_has_discounts( $items = array() ) {
904
+function wpinv_cart_has_discounts($items = array()) {
905 905
     $ret = false;
906 906
 
907
-    if ( wpinv_get_cart_discounts( $items ) ) {
907
+    if (wpinv_get_cart_discounts($items)) {
908 908
         $ret = true;
909 909
     }
910 910
     
@@ -915,131 +915,131 @@  discard block
 block discarded – undo
915 915
     }
916 916
     */
917 917
 
918
-    return apply_filters( 'wpinv_cart_has_discounts', $ret );
918
+    return apply_filters('wpinv_cart_has_discounts', $ret);
919 919
 }
920 920
 
921
-function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) {
921
+function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) {
922 922
     $amount = 0.00;
923
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
923
+    $items  = !empty($items) ? $items : wpinv_get_cart_content_details();
924 924
 
925
-    if ( $items ) {
926
-        $discounts = wp_list_pluck( $items, 'discount' );
925
+    if ($items) {
926
+        $discounts = wp_list_pluck($items, 'discount');
927 927
 
928
-        if ( is_array( $discounts ) ) {
929
-            $discounts = array_map( 'floatval', $discounts );
930
-            $amount    = array_sum( $discounts );
928
+        if (is_array($discounts)) {
929
+            $discounts = array_map('floatval', $discounts);
930
+            $amount    = array_sum($discounts);
931 931
         }
932 932
     }
933 933
 
934
-    return apply_filters( 'wpinv_get_cart_discounted_amount', $amount );
934
+    return apply_filters('wpinv_get_cart_discounted_amount', $amount);
935 935
 }
936 936
 
937
-function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) {
938
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
937
+function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) {
938
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
939 939
     
940
-    if ( empty( $discount ) || empty( $items ) ) {
940
+    if (empty($discount) || empty($items)) {
941 941
         return 0;
942 942
     }
943 943
 
944 944
     $amount = 0;
945 945
     
946
-    foreach ( $items as $item ) {
947
-        $amount += wpinv_get_cart_item_discount_amount( $item, $discount );
946
+    foreach ($items as $item) {
947
+        $amount += wpinv_get_cart_item_discount_amount($item, $discount);
948 948
     }
949 949
     
950
-    $amount = wpinv_format_amount( $amount );
950
+    $amount = wpinv_format_amount($amount);
951 951
 
952 952
     return $amount;
953 953
 }
954 954
 
955
-function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) {
955
+function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) {
956 956
     global $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
957 957
     
958 958
     $amount = 0;
959 959
 
960
-    if ( empty( $item ) || empty( $item['id'] ) ) {
960
+    if (empty($item) || empty($item['id'])) {
961 961
         return $amount;
962 962
     }
963 963
 
964
-    if ( empty( $item['quantity'] ) ) {
964
+    if (empty($item['quantity'])) {
965 965
         return $amount;
966 966
     }
967 967
 
968
-    if ( empty( $item['options'] ) ) {
968
+    if (empty($item['options'])) {
969 969
         $item['options'] = array();
970 970
     }
971 971
 
972
-    $price            = wpinv_get_cart_item_price( $item['id'], $item['options'] );
972
+    $price            = wpinv_get_cart_item_price($item['id'], $item['options']);
973 973
     $discounted_price = $price;
974 974
 
975 975
     $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount;
976
-    if ( empty( $discounts ) ) {
976
+    if (empty($discounts)) {
977 977
         return $amount;
978 978
     }
979 979
 
980
-    if ( $discounts ) {
981
-        if ( is_array( $discounts ) ) {
982
-            $discounts = array_values( $discounts );
980
+    if ($discounts) {
981
+        if (is_array($discounts)) {
982
+            $discounts = array_values($discounts);
983 983
         } else {
984
-            $discounts = explode( ',', $discounts );
984
+            $discounts = explode(',', $discounts);
985 985
         }
986 986
     }
987 987
 
988
-    if( $discounts ) {
989
-        foreach ( $discounts as $discount ) {
990
-            $code_id = wpinv_get_discount_id_by_code( $discount );
988
+    if ($discounts) {
989
+        foreach ($discounts as $discount) {
990
+            $code_id = wpinv_get_discount_id_by_code($discount);
991 991
 
992 992
             // Check discount exists
993
-            if( ! $code_id ) {
993
+            if (!$code_id) {
994 994
                 continue;
995 995
             }
996 996
 
997
-            $reqs           = wpinv_get_discount_item_reqs( $code_id );
998
-            $excluded_items = wpinv_get_discount_excluded_items( $code_id );
997
+            $reqs           = wpinv_get_discount_item_reqs($code_id);
998
+            $excluded_items = wpinv_get_discount_excluded_items($code_id);
999 999
 
1000 1000
             // Make sure requirements are set and that this discount shouldn't apply to the whole cart
1001
-            if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) {
1002
-                foreach ( $reqs as $item_id ) {
1003
-                    if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) {
1004
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1001
+            if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) {
1002
+                foreach ($reqs as $item_id) {
1003
+                    if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) {
1004
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1005 1005
                     }
1006 1006
                 }
1007 1007
             } else {
1008 1008
                 // This is a global cart discount
1009
-                if ( !in_array( $item['id'], $excluded_items ) ) {
1010
-                    if ( 'flat' === wpinv_get_discount_type( $code_id ) ) {
1009
+                if (!in_array($item['id'], $excluded_items)) {
1010
+                    if ('flat' === wpinv_get_discount_type($code_id)) {
1011 1011
                         $items_subtotal    = 0.00;
1012 1012
                         $cart_items        = wpinv_get_cart_contents();
1013 1013
                         
1014
-                        foreach ( $cart_items as $cart_item ) {
1015
-                            if ( ! in_array( $cart_item['id'], $excluded_items ) ) {
1016
-                                $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array();
1017
-                                $item_price      = wpinv_get_cart_item_price( $cart_item['id'], $options );
1014
+                        foreach ($cart_items as $cart_item) {
1015
+                            if (!in_array($cart_item['id'], $excluded_items)) {
1016
+                                $options = !empty($cart_item['options']) ? $cart_item['options'] : array();
1017
+                                $item_price      = wpinv_get_cart_item_price($cart_item['id'], $options);
1018 1018
                                 $items_subtotal += $item_price * $cart_item['quantity'];
1019 1019
                             }
1020 1020
                         }
1021 1021
 
1022
-                        $subtotal_percent  = ( ( $price * $item['quantity'] ) / $items_subtotal );
1023
-                        $code_amount       = wpinv_get_discount_amount( $code_id );
1022
+                        $subtotal_percent  = (($price * $item['quantity']) / $items_subtotal);
1023
+                        $code_amount       = wpinv_get_discount_amount($code_id);
1024 1024
                         $discounted_amount = $code_amount * $subtotal_percent;
1025 1025
                         $discounted_price -= $discounted_amount;
1026 1026
 
1027
-                        $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() );
1027
+                        $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter());
1028 1028
 
1029
-                        if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) {
1029
+                        if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) {
1030 1030
                             $adjustment = $code_amount - $wpinv_flat_discount_total;
1031 1031
                             $discounted_price -= $adjustment;
1032 1032
                         }
1033 1033
                     } else {
1034
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1034
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1035 1035
                     }
1036 1036
                 }
1037 1037
             }
1038 1038
         }
1039 1039
 
1040
-        $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) );
1040
+        $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price));
1041 1041
 
1042
-        if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) {
1042
+        if ('flat' !== wpinv_get_discount_type($code_id)) {
1043 1043
             $amount = $amount * $item['quantity'];
1044 1044
         }
1045 1045
     }
@@ -1047,59 +1047,59 @@  discard block
 block discarded – undo
1047 1047
     return $amount;
1048 1048
 }
1049 1049
 
1050
-function wpinv_cart_discounts_html( $items = array() ) {
1051
-    echo wpinv_get_cart_discounts_html( $items );
1050
+function wpinv_cart_discounts_html($items = array()) {
1051
+    echo wpinv_get_cart_discounts_html($items);
1052 1052
 }
1053 1053
 
1054
-function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) {
1054
+function wpinv_get_cart_discounts_html($items = array(), $discounts = false) {
1055 1055
     global $wpi_cart_columns;
1056 1056
     
1057
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
1057
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
1058 1058
     
1059
-    if ( !$discounts ) {
1060
-        $discounts = wpinv_get_cart_discounts( $items );
1059
+    if (!$discounts) {
1060
+        $discounts = wpinv_get_cart_discounts($items);
1061 1061
     }
1062 1062
 
1063
-    if ( !$discounts ) {
1063
+    if (!$discounts) {
1064 1064
         return;
1065 1065
     }
1066 1066
     
1067
-    $discounts = is_array( $discounts ) ? $discounts : array( $discounts );
1067
+    $discounts = is_array($discounts) ? $discounts : array($discounts);
1068 1068
     
1069 1069
     $html = '';
1070 1070
 
1071
-    foreach ( $discounts as $discount ) {
1072
-        $discount_id    = wpinv_get_discount_id_by_code( $discount );
1073
-        $discount_value = wpinv_get_discount_amount( $discount_id );
1074
-        $rate           = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value );
1075
-        $amount         = wpinv_get_cart_items_discount_amount( $items, $discount );
1076
-        $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> ';
1071
+    foreach ($discounts as $discount) {
1072
+        $discount_id    = wpinv_get_discount_id_by_code($discount);
1073
+        $discount_value = wpinv_get_discount_amount($discount_id);
1074
+        $rate           = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value);
1075
+        $amount         = wpinv_get_cart_items_discount_amount($items, $discount);
1076
+        $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> ';
1077 1077
         
1078 1078
         $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">';
1079 1079
         ob_start();
1080
-        do_action( 'wpinv_checkout_table_discount_first', $items );
1080
+        do_action('wpinv_checkout_table_discount_first', $items);
1081 1081
         $html .= ob_get_clean();
1082
-        $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( $amount ) . '</span></td>';
1082
+        $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($amount) . '</span></td>';
1083 1083
         ob_start();
1084
-        do_action( 'wpinv_checkout_table_discount_last', $items );
1084
+        do_action('wpinv_checkout_table_discount_last', $items);
1085 1085
         $html .= ob_get_clean();
1086 1086
         $html .= '</tr>';
1087 1087
     }
1088 1088
 
1089
-    return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate );
1089
+    return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate);
1090 1090
 }
1091 1091
 
1092
-function wpinv_display_cart_discount( $formatted = false, $echo = false ) {
1092
+function wpinv_display_cart_discount($formatted = false, $echo = false) {
1093 1093
     $discounts = wpinv_get_cart_discounts();
1094 1094
 
1095
-    if ( empty( $discounts ) ) {
1095
+    if (empty($discounts)) {
1096 1096
         return false;
1097 1097
     }
1098 1098
 
1099
-    $discount_id  = wpinv_get_discount_id_by_code( $discounts[0] );
1100
-    $amount       = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) );
1099
+    $discount_id  = wpinv_get_discount_id_by_code($discounts[0]);
1100
+    $amount       = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id));
1101 1101
 
1102
-    if ( $echo ) {
1102
+    if ($echo) {
1103 1103
         echo $amount;
1104 1104
     }
1105 1105
 
@@ -1107,133 +1107,133 @@  discard block
 block discarded – undo
1107 1107
 }
1108 1108
 
1109 1109
 function wpinv_remove_cart_discount() {
1110
-    if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) {
1110
+    if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) {
1111 1111
         return;
1112 1112
     }
1113 1113
 
1114
-    do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) );
1114
+    do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id']));
1115 1115
 
1116
-    wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) );
1116
+    wpinv_unset_cart_discount(urldecode($_GET['discount_code']));
1117 1117
 
1118
-    do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) );
1118
+    do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id']));
1119 1119
 
1120
-    wp_redirect( wpinv_get_checkout_uri() ); wpinv_die();
1120
+    wp_redirect(wpinv_get_checkout_uri()); wpinv_die();
1121 1121
 }
1122
-add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' );
1122
+add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount');
1123 1123
 
1124
-function wpinv_maybe_remove_cart_discount( $cart_key = 0 ) {
1124
+function wpinv_maybe_remove_cart_discount($cart_key = 0) {
1125 1125
     $discounts = wpinv_get_cart_discounts();
1126 1126
 
1127
-    if ( !$discounts ) {
1127
+    if (!$discounts) {
1128 1128
         return;
1129 1129
     }
1130 1130
 
1131
-    foreach ( $discounts as $discount ) {
1132
-        if ( !wpinv_is_discount_valid( $discount ) ) {
1133
-            wpinv_unset_cart_discount( $discount );
1131
+    foreach ($discounts as $discount) {
1132
+        if (!wpinv_is_discount_valid($discount)) {
1133
+            wpinv_unset_cart_discount($discount);
1134 1134
         }
1135 1135
     }
1136 1136
 }
1137
-add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' );
1137
+add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount');
1138 1138
 
1139 1139
 function wpinv_multiple_discounts_allowed() {
1140
-    $ret = wpinv_get_option( 'allow_multiple_discounts', false );
1141
-    return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret );
1140
+    $ret = wpinv_get_option('allow_multiple_discounts', false);
1141
+    return (bool)apply_filters('wpinv_multiple_discounts_allowed', $ret);
1142 1142
 }
1143 1143
 
1144 1144
 function wpinv_listen_for_cart_discount() {
1145 1145
     global $wpi_session;
1146 1146
     
1147
-    if ( empty( $_REQUEST['discount'] ) || is_array( $_REQUEST['discount'] ) ) {
1147
+    if (empty($_REQUEST['discount']) || is_array($_REQUEST['discount'])) {
1148 1148
         return;
1149 1149
     }
1150 1150
 
1151
-    $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount'] );
1151
+    $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount']);
1152 1152
 
1153
-    $wpi_session->set( 'preset_discount', $code );
1153
+    $wpi_session->set('preset_discount', $code);
1154 1154
 }
1155 1155
 //add_action( 'init', 'wpinv_listen_for_cart_discount', 0 );
1156 1156
 
1157 1157
 function wpinv_apply_preset_discount() {
1158 1158
     global $wpi_session;
1159 1159
     
1160
-    $code = $wpi_session->get( 'preset_discount' );
1160
+    $code = $wpi_session->get('preset_discount');
1161 1161
 
1162
-    if ( !$code ) {
1162
+    if (!$code) {
1163 1163
         return;
1164 1164
     }
1165 1165
 
1166
-    if ( !wpinv_is_discount_valid( $code, '', false ) ) {
1166
+    if (!wpinv_is_discount_valid($code, '', false)) {
1167 1167
         return;
1168 1168
     }
1169 1169
     
1170
-    $code = apply_filters( 'wpinv_apply_preset_discount', $code );
1170
+    $code = apply_filters('wpinv_apply_preset_discount', $code);
1171 1171
 
1172
-    wpinv_set_cart_discount( $code );
1172
+    wpinv_set_cart_discount($code);
1173 1173
 
1174
-    $wpi_session->set( 'preset_discount', null );
1174
+    $wpi_session->set('preset_discount', null);
1175 1175
 }
1176 1176
 //add_action( 'init', 'wpinv_apply_preset_discount', 999 );
1177 1177
 
1178
-function wpinv_get_discount_label( $code, $echo = true ) {
1179
-    $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) );
1180
-    $label = apply_filters( 'wpinv_get_discount_label', $label, $code );
1178
+function wpinv_get_discount_label($code, $echo = true) {
1179
+    $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : ''));
1180
+    $label = apply_filters('wpinv_get_discount_label', $label, $code);
1181 1181
 
1182
-    if ( $echo ) {
1182
+    if ($echo) {
1183 1183
         echo $label;
1184 1184
     } else {
1185 1185
         return $label;
1186 1186
     }
1187 1187
 }
1188 1188
 
1189
-function wpinv_cart_discount_label( $code, $rate, $echo = true ) {
1190
-    $label = wp_sprintf( __( '%1$s Discount: %2$s', 'invoicing' ), $rate, $code );
1191
-    $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate );
1189
+function wpinv_cart_discount_label($code, $rate, $echo = true) {
1190
+    $label = wp_sprintf(__('%1$s Discount: %2$s', 'invoicing'), $rate, $code);
1191
+    $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate);
1192 1192
 
1193
-    if ( $echo ) {
1193
+    if ($echo) {
1194 1194
         echo $label;
1195 1195
     } else {
1196 1196
         return $label;
1197 1197
     }
1198 1198
 }
1199 1199
 
1200
-function wpinv_check_delete_discount( $check, $post, $force_delete ) {
1201
-    if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) {
1200
+function wpinv_check_delete_discount($check, $post, $force_delete) {
1201
+    if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) {
1202 1202
         return true;
1203 1203
     }
1204 1204
     
1205 1205
     return $check;
1206 1206
 }
1207
-add_filter( 'pre_delete_post', 'wpinv_check_delete_discount', 10, 3 );
1207
+add_filter('pre_delete_post', 'wpinv_check_delete_discount', 10, 3);
1208 1208
 
1209 1209
 function wpinv_checkout_form_validate_discounts() {
1210 1210
     $discounts = wpinv_get_cart_discounts();
1211 1211
     
1212
-    if ( !empty( $discounts ) ) {
1212
+    if (!empty($discounts)) {
1213 1213
         $invalid = false;
1214 1214
         
1215
-        foreach ( $discounts as $key => $code ) {
1216
-            if ( !wpinv_is_discount_valid( $code, get_current_user_id() ) ) {
1215
+        foreach ($discounts as $key => $code) {
1216
+            if (!wpinv_is_discount_valid($code, get_current_user_id())) {
1217 1217
                 $invalid = true;
1218 1218
                 
1219
-                wpinv_unset_cart_discount( $code );
1219
+                wpinv_unset_cart_discount($code);
1220 1220
             }
1221 1221
         }
1222 1222
         
1223
-        if ( $invalid ) {
1223
+        if ($invalid) {
1224 1224
             $errors = wpinv_get_errors();
1225
-            $error  = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : '';
1226
-            $error  .= __( 'The discount has been removed from cart.', 'invoicing' );
1227
-            wpinv_set_error( 'wpinv-discount-error', $error );
1225
+            $error  = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : '';
1226
+            $error .= __('The discount has been removed from cart.', 'invoicing');
1227
+            wpinv_set_error('wpinv-discount-error', $error);
1228 1228
             
1229
-            wpinv_recalculate_tax( true );
1229
+            wpinv_recalculate_tax(true);
1230 1230
         }
1231 1231
     }
1232 1232
 }
1233
-add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 );
1233
+add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10);
1234 1234
 
1235 1235
 function wpinv_discount_amount() {
1236 1236
     $output = 0.00;
1237 1237
     
1238
-    return apply_filters( 'wpinv_discount_amount', $output );
1238
+    return apply_filters('wpinv_discount_amount', $output);
1239 1239
 }
1240 1240
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-email-functions.php 3 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -624,6 +624,9 @@  discard block
 block discarded – undo
624 624
     return $sent;
625 625
 }
626 626
 
627
+/**
628
+ * @return string
629
+ */
627 630
 function wpinv_mail_get_from_address() {
628 631
     $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from' ) );
629 632
     return sanitize_email( $from_address );
@@ -1083,6 +1086,9 @@  discard block
 block discarded – undo
1083 1086
 }
1084 1087
 add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 );
1085 1088
 
1089
+/**
1090
+ * @param string $email_type
1091
+ */
1086 1092
 function wpinv_email_is_enabled( $email_type ) {
1087 1093
     $emails = wpinv_get_emails();
1088 1094
     $enabled = isset( $emails[$email_type] ) && wpinv_get_option( $email_type . '_active', 1 ) ? true : false;
Please login to merge, or discard this patch.
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -688,9 +688,9 @@
 block discarded – undo
688 688
         $overdue_days_options[$i]   = wp_sprintf( __( '%d days after Due Date', 'invoicing' ), $i );
689 689
     }
690 690
 
691
-	// Default, built-in gateways
692
-	$emails = array(
693
-		'new_invoice' => array(
691
+    // Default, built-in gateways
692
+    $emails = array(
693
+        'new_invoice' => array(
694 694
             'email_new_invoice_header' => array(
695 695
                 'id'   => 'email_new_invoice_header',
696 696
                 'name' => '<h3>' . __( 'New Invoice', 'invoicing' ) . '</h3>',
Please login to merge, or discard this patch.
Spacing   +492 added lines, -492 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_init_transactional_emails() {
15
-    $email_actions = apply_filters( 'wpinv_email_actions', array(
15
+    $email_actions = apply_filters('wpinv_email_actions', array(
16 16
         'wpinv_status_pending_to_processing',
17 17
         'wpinv_status_pending_to_publish',
18 18
         'wpinv_status_pending_to_cancelled',
@@ -28,74 +28,74 @@  discard block
 block discarded – undo
28 28
         'wpinv_fully_refunded',
29 29
         'wpinv_partially_refunded',
30 30
         'wpinv_new_invoice_note'
31
-    ) );
31
+    ));
32 32
 
33
-    foreach ( $email_actions as $action ) {
34
-        add_action( $action, 'wpinv_send_transactional_email', 10, 10 );
33
+    foreach ($email_actions as $action) {
34
+        add_action($action, 'wpinv_send_transactional_email', 10, 10);
35 35
     }
36 36
 }
37
-add_action( 'init', 'wpinv_init_transactional_emails' );
37
+add_action('init', 'wpinv_init_transactional_emails');
38 38
 
39 39
 // New invoice email
40
-add_action( 'wpinv_status_pending_to_processing_notification', 'wpinv_new_invoice_notification' );
41
-add_action( 'wpinv_status_pending_to_publish_notification', 'wpinv_new_invoice_notification' );
42
-add_action( 'wpinv_status_pending_to_onhold_notification', 'wpinv_new_invoice_notification' );
43
-add_action( 'wpinv_status_failed_to_processing_notification', 'wpinv_new_invoice_notification' );
44
-add_action( 'wpinv_status_failed_to_publish_notification', 'wpinv_new_invoice_notification' );
45
-add_action( 'wpinv_status_failed_to_onhold_notification', 'wpinv_new_invoice_notification' );
40
+add_action('wpinv_status_pending_to_processing_notification', 'wpinv_new_invoice_notification');
41
+add_action('wpinv_status_pending_to_publish_notification', 'wpinv_new_invoice_notification');
42
+add_action('wpinv_status_pending_to_onhold_notification', 'wpinv_new_invoice_notification');
43
+add_action('wpinv_status_failed_to_processing_notification', 'wpinv_new_invoice_notification');
44
+add_action('wpinv_status_failed_to_publish_notification', 'wpinv_new_invoice_notification');
45
+add_action('wpinv_status_failed_to_onhold_notification', 'wpinv_new_invoice_notification');
46 46
 
47 47
 // Cancelled invoice email
48
-add_action( 'wpinv_status_pending_to_cancelled_notification', 'wpinv_cancelled_invoice_notification' );
49
-add_action( 'wpinv_status_onhold_to_cancelled_notification', 'wpinv_cancelled_invoice_notification' );
48
+add_action('wpinv_status_pending_to_cancelled_notification', 'wpinv_cancelled_invoice_notification');
49
+add_action('wpinv_status_onhold_to_cancelled_notification', 'wpinv_cancelled_invoice_notification');
50 50
 
51 51
 // Failed invoice email
52
-add_action( 'wpinv_status_pending_to_failed_notification', 'wpinv_failed_invoice_notification' );
53
-add_action( 'wpinv_status_onhold_to_failed_notification', 'wpinv_failed_invoice_notification' );
52
+add_action('wpinv_status_pending_to_failed_notification', 'wpinv_failed_invoice_notification');
53
+add_action('wpinv_status_onhold_to_failed_notification', 'wpinv_failed_invoice_notification');
54 54
 
55 55
 // On hold invoice email
56
-add_action( 'wpinv_status_pending_to_onhold_notification', 'wpinv_onhold_invoice_notification' );
57
-add_action( 'wpinv_status_failed_to_onhold_notification', 'wpinv_onhold_invoice_notification' );
56
+add_action('wpinv_status_pending_to_onhold_notification', 'wpinv_onhold_invoice_notification');
57
+add_action('wpinv_status_failed_to_onhold_notification', 'wpinv_onhold_invoice_notification');
58 58
 
59 59
 // Processing invoice email
60
-add_action( 'wpinv_status_pending_to_processing_notification', 'wpinv_processing_invoice_notification' );
60
+add_action('wpinv_status_pending_to_processing_notification', 'wpinv_processing_invoice_notification');
61 61
 
62 62
 // Paid invoice email
63
-add_action( 'wpinv_status_publish_notification', 'wpinv_completed_invoice_notification' );
63
+add_action('wpinv_status_publish_notification', 'wpinv_completed_invoice_notification');
64 64
 
65 65
 // Refunded invoice email
66
-add_action( 'wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification' );
67
-add_action( 'wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification' );
66
+add_action('wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification');
67
+add_action('wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification');
68 68
 
69 69
 // Invoice note
70
-add_action( 'wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification' );
70
+add_action('wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification');
71 71
 
72
-add_action( 'wpinv_email_header', 'wpinv_email_header' );
73
-add_action( 'wpinv_email_footer', 'wpinv_email_footer' );
74
-add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 );
75
-add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 );
76
-add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 );
72
+add_action('wpinv_email_header', 'wpinv_email_header');
73
+add_action('wpinv_email_footer', 'wpinv_email_footer');
74
+add_action('wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3);
75
+add_action('wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3);
76
+add_action('wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3);
77 77
 
78 78
 function wpinv_send_transactional_email() {
79 79
     $args       = func_get_args();
80 80
     $function   = current_filter() . '_notification';
81
-    do_action_ref_array( $function, $args );
81
+    do_action_ref_array($function, $args);
82 82
 }
83 83
     
84
-function wpinv_new_invoice_notification( $invoice_id, $new_status = '' ) {
84
+function wpinv_new_invoice_notification($invoice_id, $new_status = '') {
85 85
     global $wpinv_email_search, $wpinv_email_replace;
86 86
     
87 87
     $email_type = 'new_invoice';
88
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
88
+    if (!wpinv_email_is_enabled($email_type)) {
89 89
         return false;
90 90
     }
91 91
     
92
-    $invoice = wpinv_get_invoice( $invoice_id );
93
-    if ( empty( $invoice ) ) {
92
+    $invoice = wpinv_get_invoice($invoice_id);
93
+    if (empty($invoice)) {
94 94
         return false;
95 95
     }
96 96
     
97
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
98
-    if ( !is_email( $recipient ) ) {
97
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
98
+    if (!is_email($recipient)) {
99 99
         return false;
100 100
     }
101 101
         
@@ -112,37 +112,37 @@  discard block
 block discarded – undo
112 112
     $wpinv_email_search     = $search;
113 113
     $wpinv_email_replace    = $replace;
114 114
     
115
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
116
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
117
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
118
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
115
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
116
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
117
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
118
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
119 119
     
120
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
120
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
121 121
             'invoice'       => $invoice,
122 122
             'email_type'    => $email_type,
123 123
             'email_heading' => $email_heading,
124 124
             'sent_to_admin' => true,
125 125
             'plain_text'    => false,
126
-        ) );
126
+        ));
127 127
     
128
-    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
128
+    return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
129 129
 }
130 130
 
131
-function wpinv_cancelled_invoice_notification( $invoice_id, $new_status = '' ) {
131
+function wpinv_cancelled_invoice_notification($invoice_id, $new_status = '') {
132 132
     global $wpinv_email_search, $wpinv_email_replace;
133 133
     
134 134
     $email_type = 'cancelled_invoice';
135
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
135
+    if (!wpinv_email_is_enabled($email_type)) {
136 136
         return false;
137 137
     }
138 138
     
139
-    $invoice = wpinv_get_invoice( $invoice_id );
140
-    if ( empty( $invoice ) ) {
139
+    $invoice = wpinv_get_invoice($invoice_id);
140
+    if (empty($invoice)) {
141 141
         return false;
142 142
     }
143 143
     
144
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
145
-    if ( !is_email( $recipient ) ) {
144
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
145
+    if (!is_email($recipient)) {
146 146
         return false;
147 147
     }
148 148
         
@@ -159,37 +159,37 @@  discard block
 block discarded – undo
159 159
     $wpinv_email_search     = $search;
160 160
     $wpinv_email_replace    = $replace;
161 161
     
162
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
163
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
164
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
165
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
162
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
163
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
164
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
165
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
166 166
     
167
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
167
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
168 168
             'invoice'       => $invoice,
169 169
             'email_type'    => $email_type,
170 170
             'email_heading' => $email_heading,
171 171
             'sent_to_admin' => true,
172 172
             'plain_text'    => false,
173
-        ) );
173
+        ));
174 174
     
175
-    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
175
+    return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
176 176
 }
177 177
 
178
-function wpinv_failed_invoice_notification( $invoice_id, $new_status = '' ) {
178
+function wpinv_failed_invoice_notification($invoice_id, $new_status = '') {
179 179
     global $wpinv_email_search, $wpinv_email_replace;
180 180
     
181 181
     $email_type = 'failed_invoice';
182
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
182
+    if (!wpinv_email_is_enabled($email_type)) {
183 183
         return false;
184 184
     }
185 185
     
186
-    $invoice = wpinv_get_invoice( $invoice_id );
187
-    if ( empty( $invoice ) ) {
186
+    $invoice = wpinv_get_invoice($invoice_id);
187
+    if (empty($invoice)) {
188 188
         return false;
189 189
     }
190 190
     
191
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
192
-    if ( !is_email( $recipient ) ) {
191
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
192
+    if (!is_email($recipient)) {
193 193
         return false;
194 194
     }
195 195
         
@@ -206,37 +206,37 @@  discard block
 block discarded – undo
206 206
     $wpinv_email_search     = $search;
207 207
     $wpinv_email_replace    = $replace;
208 208
     
209
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
210
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
211
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
212
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
209
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
210
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
211
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
212
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
213 213
     
214
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
214
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
215 215
             'invoice'       => $invoice,
216 216
             'email_type'    => $email_type,
217 217
             'email_heading' => $email_heading,
218 218
             'sent_to_admin' => true,
219 219
             'plain_text'    => false,
220
-        ) );
220
+        ));
221 221
     
222
-    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
222
+    return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
223 223
 }
224 224
 
225
-function wpinv_onhold_invoice_notification( $invoice_id, $new_status = '' ) {
225
+function wpinv_onhold_invoice_notification($invoice_id, $new_status = '') {
226 226
     global $wpinv_email_search, $wpinv_email_replace;
227 227
     
228 228
     $email_type = 'onhold_invoice';
229
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
229
+    if (!wpinv_email_is_enabled($email_type)) {
230 230
         return false;
231 231
     }
232 232
     
233
-    $invoice = wpinv_get_invoice( $invoice_id );
234
-    if ( empty( $invoice ) ) {
233
+    $invoice = wpinv_get_invoice($invoice_id);
234
+    if (empty($invoice)) {
235 235
         return false;
236 236
     }
237 237
     
238
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
239
-    if ( !is_email( $recipient ) ) {
238
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
239
+    if (!is_email($recipient)) {
240 240
         return false;
241 241
     }
242 242
         
@@ -253,45 +253,45 @@  discard block
 block discarded – undo
253 253
     $wpinv_email_search     = $search;
254 254
     $wpinv_email_replace    = $replace;
255 255
     
256
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
257
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
258
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
259
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
256
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
257
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
258
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
259
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
260 260
     
261
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
261
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
262 262
             'invoice'       => $invoice,
263 263
             'email_type'    => $email_type,
264 264
             'email_heading' => $email_heading,
265 265
             'sent_to_admin' => false,
266 266
             'plain_text'    => false,
267
-        ) );
267
+        ));
268 268
     
269
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
269
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
270 270
     
271
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
272
-        $recipient  = wpinv_get_admin_email();
273
-        $subject    .= ' - ADMIN BCC COPY';
274
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
271
+    if (wpinv_mail_admin_bcc_active($email_type)) {
272
+        $recipient = wpinv_get_admin_email();
273
+        $subject .= ' - ADMIN BCC COPY';
274
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
275 275
     }
276 276
     
277 277
     return $sent;
278 278
 }
279 279
 
280
-function wpinv_processing_invoice_notification( $invoice_id, $new_status = '' ) {
280
+function wpinv_processing_invoice_notification($invoice_id, $new_status = '') {
281 281
     global $wpinv_email_search, $wpinv_email_replace;
282 282
     
283 283
     $email_type = 'processing_invoice';
284
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
284
+    if (!wpinv_email_is_enabled($email_type)) {
285 285
         return false;
286 286
     }
287 287
     
288
-    $invoice = wpinv_get_invoice( $invoice_id );
289
-    if ( empty( $invoice ) ) {
288
+    $invoice = wpinv_get_invoice($invoice_id);
289
+    if (empty($invoice)) {
290 290
         return false;
291 291
     }
292 292
     
293
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
294
-    if ( !is_email( $recipient ) ) {
293
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
294
+    if (!is_email($recipient)) {
295 295
         return false;
296 296
     }
297 297
         
@@ -308,45 +308,45 @@  discard block
 block discarded – undo
308 308
     $wpinv_email_search     = $search;
309 309
     $wpinv_email_replace    = $replace;
310 310
     
311
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
312
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
313
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
314
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
311
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
312
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
313
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
314
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
315 315
     
316
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
316
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
317 317
             'invoice'       => $invoice,
318 318
             'email_type'    => $email_type,
319 319
             'email_heading' => $email_heading,
320 320
             'sent_to_admin' => false,
321 321
             'plain_text'    => false,
322
-        ) );
322
+        ));
323 323
     
324
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
324
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
325 325
     
326
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
327
-        $recipient  = wpinv_get_admin_email();
328
-        $subject    .= ' - ADMIN BCC COPY';
329
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
326
+    if (wpinv_mail_admin_bcc_active($email_type)) {
327
+        $recipient = wpinv_get_admin_email();
328
+        $subject .= ' - ADMIN BCC COPY';
329
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
330 330
     }
331 331
     
332 332
     return $sent;
333 333
 }
334 334
 
335
-function wpinv_completed_invoice_notification( $invoice_id, $new_status = '' ) {
335
+function wpinv_completed_invoice_notification($invoice_id, $new_status = '') {
336 336
     global $wpinv_email_search, $wpinv_email_replace;
337 337
     
338 338
     $email_type = 'completed_invoice';
339
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
339
+    if (!wpinv_email_is_enabled($email_type)) {
340 340
         return false;
341 341
     }
342 342
     
343
-    $invoice = wpinv_get_invoice( $invoice_id );
344
-    if ( empty( $invoice ) ) {
343
+    $invoice = wpinv_get_invoice($invoice_id);
344
+    if (empty($invoice)) {
345 345
         return false;
346 346
     }
347 347
     
348
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
349
-    if ( !is_email( $recipient ) ) {
348
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
349
+    if (!is_email($recipient)) {
350 350
         return false;
351 351
     }
352 352
         
@@ -363,45 +363,45 @@  discard block
 block discarded – undo
363 363
     $wpinv_email_search     = $search;
364 364
     $wpinv_email_replace    = $replace;
365 365
     
366
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
367
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
368
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
369
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
366
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
367
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
368
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
369
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
370 370
     
371
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
371
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
372 372
             'invoice'       => $invoice,
373 373
             'email_type'    => $email_type,
374 374
             'email_heading' => $email_heading,
375 375
             'sent_to_admin' => false,
376 376
             'plain_text'    => false,
377
-        ) );
377
+        ));
378 378
     
379
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
379
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
380 380
     
381
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
382
-        $recipient  = wpinv_get_admin_email();
383
-        $subject    .= ' - ADMIN BCC COPY';
384
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
381
+    if (wpinv_mail_admin_bcc_active($email_type)) {
382
+        $recipient = wpinv_get_admin_email();
383
+        $subject .= ' - ADMIN BCC COPY';
384
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
385 385
     }
386 386
     
387 387
     return $sent;
388 388
 }
389 389
 
390
-function wpinv_fully_refunded_notification( $invoice_id, $new_status = '' ) {
390
+function wpinv_fully_refunded_notification($invoice_id, $new_status = '') {
391 391
     global $wpinv_email_search, $wpinv_email_replace;
392 392
     
393 393
     $email_type = 'refunded_invoice';
394
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
394
+    if (!wpinv_email_is_enabled($email_type)) {
395 395
         return false;
396 396
     }
397 397
     
398
-    $invoice = wpinv_get_invoice( $invoice_id );
399
-    if ( empty( $invoice ) ) {
398
+    $invoice = wpinv_get_invoice($invoice_id);
399
+    if (empty($invoice)) {
400 400
         return false;
401 401
     }
402 402
     
403
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
404
-    if ( !is_email( $recipient ) ) {
403
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
404
+    if (!is_email($recipient)) {
405 405
         return false;
406 406
     }
407 407
         
@@ -418,46 +418,46 @@  discard block
 block discarded – undo
418 418
     $wpinv_email_search     = $search;
419 419
     $wpinv_email_replace    = $replace;
420 420
     
421
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
422
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
423
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
424
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
421
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
422
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
423
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
424
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
425 425
     
426
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
426
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
427 427
             'invoice'           => $invoice,
428 428
             'email_type'        => $email_type,
429 429
             'email_heading'     => $email_heading,
430 430
             'sent_to_admin'     => false,
431 431
             'plain_text'        => false,
432 432
             'partial_refund'    => false
433
-        ) );
433
+        ));
434 434
     
435
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
435
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
436 436
     
437
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
438
-        $recipient  = wpinv_get_admin_email();
439
-        $subject    .= ' - ADMIN BCC COPY';
440
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
437
+    if (wpinv_mail_admin_bcc_active($email_type)) {
438
+        $recipient = wpinv_get_admin_email();
439
+        $subject .= ' - ADMIN BCC COPY';
440
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
441 441
     }
442 442
     
443 443
     return $sent;
444 444
 }
445 445
 
446
-function wpinv_partially_refunded_notification( $invoice_id, $new_status = '' ) {
446
+function wpinv_partially_refunded_notification($invoice_id, $new_status = '') {
447 447
     global $wpinv_email_search, $wpinv_email_replace;
448 448
     
449 449
     $email_type = 'refunded_invoice';
450
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
450
+    if (!wpinv_email_is_enabled($email_type)) {
451 451
         return false;
452 452
     }
453 453
     
454
-    $invoice = wpinv_get_invoice( $invoice_id );
455
-    if ( empty( $invoice ) ) {
454
+    $invoice = wpinv_get_invoice($invoice_id);
455
+    if (empty($invoice)) {
456 456
         return false;
457 457
     }
458 458
     
459
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
460
-    if ( !is_email( $recipient ) ) {
459
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
460
+    if (!is_email($recipient)) {
461 461
         return false;
462 462
     }
463 463
         
@@ -474,49 +474,49 @@  discard block
 block discarded – undo
474 474
     $wpinv_email_search     = $search;
475 475
     $wpinv_email_replace    = $replace;
476 476
     
477
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
478
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
479
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
480
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
477
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
478
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
479
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
480
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
481 481
     
482
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
482
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
483 483
             'invoice'           => $invoice,
484 484
             'email_type'        => $email_type,
485 485
             'email_heading'     => $email_heading,
486 486
             'sent_to_admin'     => false,
487 487
             'plain_text'        => false,
488 488
             'partial_refund'    => true
489
-        ) );
489
+        ));
490 490
     
491
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
491
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
492 492
     
493
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
494
-        $recipient  = wpinv_get_admin_email();
495
-        $subject    .= ' - ADMIN BCC COPY';
496
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
493
+    if (wpinv_mail_admin_bcc_active($email_type)) {
494
+        $recipient = wpinv_get_admin_email();
495
+        $subject .= ' - ADMIN BCC COPY';
496
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
497 497
     }
498 498
     
499 499
     return $sent;
500 500
 }
501 501
 
502
-function wpinv_new_invoice_note_notification( $invoice_id, $new_status = '' ) {
502
+function wpinv_new_invoice_note_notification($invoice_id, $new_status = '') {
503 503
 }
504 504
 
505
-function wpinv_user_invoice_notification( $invoice_id ) {
505
+function wpinv_user_invoice_notification($invoice_id) {
506 506
     global $wpinv_email_search, $wpinv_email_replace;
507 507
     
508 508
     $email_type = 'user_invoice';
509
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
509
+    if (!wpinv_email_is_enabled($email_type)) {
510 510
         return false;
511 511
     }
512 512
     
513
-    $invoice = wpinv_get_invoice( $invoice_id );
514
-    if ( empty( $invoice ) ) {
513
+    $invoice = wpinv_get_invoice($invoice_id);
514
+    if (empty($invoice)) {
515 515
         return false;
516 516
     }
517 517
     
518
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
519
-    if ( !is_email( $recipient ) ) {
518
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
519
+    if (!is_email($recipient)) {
520 520
         return false;
521 521
     }
522 522
         
@@ -533,52 +533,52 @@  discard block
 block discarded – undo
533 533
     $wpinv_email_search     = $search;
534 534
     $wpinv_email_replace    = $replace;
535 535
     
536
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
537
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
538
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
539
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
536
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
537
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
538
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
539
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
540 540
     
541
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
541
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
542 542
             'invoice'       => $invoice,
543 543
             'email_type'    => $email_type,
544 544
             'email_heading' => $email_heading,
545 545
             'sent_to_admin' => false,
546 546
             'plain_text'    => false,
547
-        ) );
547
+        ));
548 548
     
549
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
549
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
550 550
     
551
-    if ( $sent ) {
552
-        $note = __( 'Invoice has been emailed to the user.', 'invoicing' );
551
+    if ($sent) {
552
+        $note = __('Invoice has been emailed to the user.', 'invoicing');
553 553
     } else {
554
-        $note = __( 'Fail to send invoice to the user!', 'invoicing' );
554
+        $note = __('Fail to send invoice to the user!', 'invoicing');
555 555
     }
556
-    $invoice->add_note( $note ); // Add private note.
556
+    $invoice->add_note($note); // Add private note.
557 557
     
558
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
559
-        $recipient  = wpinv_get_admin_email();
560
-        $subject    .= ' - ADMIN BCC COPY';
561
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
558
+    if (wpinv_mail_admin_bcc_active($email_type)) {
559
+        $recipient = wpinv_get_admin_email();
560
+        $subject .= ' - ADMIN BCC COPY';
561
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
562 562
     }
563 563
     
564 564
     return $sent;
565 565
 }
566 566
 
567
-function wpinv_user_note_notification( $invoice_id, $args = array() ) {
567
+function wpinv_user_note_notification($invoice_id, $args = array()) {
568 568
     global $wpinv_email_search, $wpinv_email_replace;
569 569
     
570 570
     $email_type = 'user_note';
571
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
571
+    if (!wpinv_email_is_enabled($email_type)) {
572 572
         return false;
573 573
     }
574 574
     
575
-    $invoice = wpinv_get_invoice( $invoice_id );
576
-    if ( empty( $invoice ) ) {
575
+    $invoice = wpinv_get_invoice($invoice_id);
576
+    if (empty($invoice)) {
577 577
         return false;
578 578
     }
579 579
     
580
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
581
-    if ( !is_email( $recipient ) ) {
580
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
581
+    if (!is_email($recipient)) {
582 582
         return false;
583 583
     }
584 584
     
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
         'user_note' => ''
587 587
     );
588 588
 
589
-    $args = wp_parse_args( $args, $defaults );
589
+    $args = wp_parse_args($args, $defaults);
590 590
         
591 591
     $search                     = array();
592 592
     $search['invoice_number']   = '{invoice_number}';
@@ -603,46 +603,46 @@  discard block
 block discarded – undo
603 603
     $wpinv_email_search     = $search;
604 604
     $wpinv_email_replace    = $replace;
605 605
     
606
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
607
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
608
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
609
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
606
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
607
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
608
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
609
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
610 610
     
611
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
611
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
612 612
             'invoice'       => $invoice,
613 613
             'email_type'    => $email_type,
614 614
             'email_heading' => $email_heading,
615 615
             'sent_to_admin' => false,
616 616
             'plain_text'    => false,
617 617
             'customer_note' => $args['user_note']
618
-        ) );
618
+        ));
619 619
         
620
-    $content        = wpinv_email_format_text( $content );
620
+    $content = wpinv_email_format_text($content);
621 621
     
622
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
622
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
623 623
         
624 624
     return $sent;
625 625
 }
626 626
 
627 627
 function wpinv_mail_get_from_address() {
628
-    $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from' ) );
629
-    return sanitize_email( $from_address );
628
+    $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from'));
629
+    return sanitize_email($from_address);
630 630
 }
631 631
 
632 632
 function wpinv_mail_get_from_name() {
633
-    $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name' ) );
634
-    return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES );
633
+    $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name'));
634
+    return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES);
635 635
 }
636 636
 
637
-function wpinv_mail_admin_bcc_active( $mail_type = '' ) {
638
-    $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) );
639
-    return ( $active ? true : false );
637
+function wpinv_mail_admin_bcc_active($mail_type = '') {
638
+    $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc'));
639
+    return ($active ? true : false);
640 640
 }
641 641
     
642
-function wpinv_mail_get_content_type(  $content_type = 'text/html', $email_type = 'html' ) {
643
-    $email_type = apply_filters( 'wpinv_mail_content_type', $email_type );
642
+function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') {
643
+    $email_type = apply_filters('wpinv_mail_content_type', $email_type);
644 644
     
645
-    switch ( $email_type ) {
645
+    switch ($email_type) {
646 646
         case 'html' :
647 647
             $content_type = 'text/html';
648 648
             break;
@@ -657,35 +657,35 @@  discard block
 block discarded – undo
657 657
     return $content_type;
658 658
 }
659 659
     
660
-function wpinv_mail_send( $to, $subject, $message, $headers, $attachments ) {
661
-    add_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
662
-    add_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
663
-    add_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
660
+function wpinv_mail_send($to, $subject, $message, $headers, $attachments) {
661
+    add_filter('wp_mail_from', 'wpinv_mail_get_from_address');
662
+    add_filter('wp_mail_from_name', 'wpinv_mail_get_from_name');
663
+    add_filter('wp_mail_content_type', 'wpinv_mail_get_content_type');
664 664
 
665
-    $message = wpinv_email_style_body( $message );
666
-    $message = apply_filters( 'wpinv_mail_content', $message );
665
+    $message = wpinv_email_style_body($message);
666
+    $message = apply_filters('wpinv_mail_content', $message);
667 667
     
668
-    $sent  = wp_mail( $to, $subject, $message, $headers, $attachments );
668
+    $sent = wp_mail($to, $subject, $message, $headers, $attachments);
669 669
     
670
-    if ( !$sent ) {
671
-        $log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), ( is_array( $to ) ? implode( ', ', $to ) : $to ), $subject );
672
-        wpinv_error_log( $log_message, __( "Email from Invoicing plugin failed to send", 'invoicing' ), __FILE__, __LINE__ );
670
+    if (!$sent) {
671
+        $log_message = wp_sprintf(__("\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing'), date_i18n('F j Y H:i:s', current_time('timestamp')), (is_array($to) ? implode(', ', $to) : $to), $subject);
672
+        wpinv_error_log($log_message, __("Email from Invoicing plugin failed to send", 'invoicing'), __FILE__, __LINE__);
673 673
     }
674 674
 
675
-    remove_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
676
-    remove_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
677
-    remove_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
675
+    remove_filter('wp_mail_from', 'wpinv_mail_get_from_address');
676
+    remove_filter('wp_mail_from_name', 'wpinv_mail_get_from_name');
677
+    remove_filter('wp_mail_content_type', 'wpinv_mail_get_content_type');
678 678
 
679 679
     return $sent;
680 680
 }
681 681
     
682 682
 function wpinv_get_emails() {
683 683
     $overdue_days_options       = array();
684
-    $overdue_days_options[0]    = __( 'On the Due Date', 'invoicing' );
685
-    $overdue_days_options[1]    = __( '1 day after Due Date', 'invoicing' );
684
+    $overdue_days_options[0]    = __('On the Due Date', 'invoicing');
685
+    $overdue_days_options[1]    = __('1 day after Due Date', 'invoicing');
686 686
     
687
-    for ( $i = 2; $i <= 10; $i++ ) {
688
-        $overdue_days_options[$i]   = wp_sprintf( __( '%d days after Due Date', 'invoicing' ), $i );
687
+    for ($i = 2; $i <= 10; $i++) {
688
+        $overdue_days_options[$i] = wp_sprintf(__('%d days after Due Date', 'invoicing'), $i);
689 689
     }
690 690
 
691 691
 	// Default, built-in gateways
@@ -693,130 +693,130 @@  discard block
 block discarded – undo
693 693
 		'new_invoice' => array(
694 694
             'email_new_invoice_header' => array(
695 695
                 'id'   => 'email_new_invoice_header',
696
-                'name' => '<h3>' . __( 'New Invoice', 'invoicing' ) . '</h3>',
697
-                'desc' => __( 'New invoice emails are sent to admin when a new invoice is received.', 'invoicing' ),
696
+                'name' => '<h3>' . __('New Invoice', 'invoicing') . '</h3>',
697
+                'desc' => __('New invoice emails are sent to admin when a new invoice is received.', 'invoicing'),
698 698
                 'type' => 'header',
699 699
             ),
700 700
             'email_new_invoice_active' => array(
701 701
                 'id'   => 'email_new_invoice_active',
702
-                'name' => __( 'Enable/Disable', 'invoicing' ),
703
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
702
+                'name' => __('Enable/Disable', 'invoicing'),
703
+                'desc' => __('Enable this email notification', 'invoicing'),
704 704
                 'type' => 'checkbox',
705 705
                 'std'  => 1
706 706
             ),
707 707
             'email_new_invoice_subject' => array(
708 708
                 'id'   => 'email_new_invoice_subject',
709
-                'name' => __( 'Subject', 'invoicing' ),
710
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
709
+                'name' => __('Subject', 'invoicing'),
710
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
711 711
                 'type' => 'text',
712
-                'std'  => __( '[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing' ),
712
+                'std'  => __('[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing'),
713 713
                 'size' => 'large'
714 714
             ),
715 715
             'email_new_invoice_heading' => array(
716 716
                 'id'   => 'email_new_invoice_heading',
717
-                'name' => __( 'Email Heading', 'invoicing' ),
718
-                'desc' => __( 'Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
717
+                'name' => __('Email Heading', 'invoicing'),
718
+                'desc' => __('Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
719 719
                 'type' => 'text',
720
-                'std'  => __( 'New payment invoice', 'invoicing' ),
720
+                'std'  => __('New payment invoice', 'invoicing'),
721 721
                 'size' => 'large'
722 722
             ),
723 723
         ),
724 724
         'cancelled_invoice' => array(
725 725
             'email_cancelled_invoice_header' => array(
726 726
                 'id'   => 'email_cancelled_invoice_header',
727
-                'name' => '<h3>' . __( 'Cancelled Invoice', 'invoicing' ) . '</h3>',
728
-                'desc' => __( 'Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing' ),
727
+                'name' => '<h3>' . __('Cancelled Invoice', 'invoicing') . '</h3>',
728
+                'desc' => __('Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing'),
729 729
                 'type' => 'header',
730 730
             ),
731 731
             'email_cancelled_invoice_active' => array(
732 732
                 'id'   => 'email_cancelled_invoice_active',
733
-                'name' => __( 'Enable/Disable', 'invoicing' ),
734
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
733
+                'name' => __('Enable/Disable', 'invoicing'),
734
+                'desc' => __('Enable this email notification', 'invoicing'),
735 735
                 'type' => 'checkbox',
736 736
                 'std'  => 1
737 737
             ),
738 738
             'email_cancelled_invoice_subject' => array(
739 739
                 'id'   => 'email_cancelled_invoice_subject',
740
-                'name' => __( 'Subject', 'invoicing' ),
741
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
740
+                'name' => __('Subject', 'invoicing'),
741
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
742 742
                 'type' => 'text',
743
-                'std'  => __( '[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing' ),
743
+                'std'  => __('[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing'),
744 744
                 'size' => 'large'
745 745
             ),
746 746
             'email_cancelled_invoice_heading' => array(
747 747
                 'id'   => 'email_cancelled_invoice_heading',
748
-                'name' => __( 'Email Heading', 'invoicing' ),
749
-                'desc' => __( 'Enter the the main heading contained within the email notification.', 'invoicing' ),
748
+                'name' => __('Email Heading', 'invoicing'),
749
+                'desc' => __('Enter the the main heading contained within the email notification.', 'invoicing'),
750 750
                 'type' => 'text',
751
-                'std'  => __( 'Cancelled invoice', 'invoicing' ),
751
+                'std'  => __('Cancelled invoice', 'invoicing'),
752 752
                 'size' => 'large'
753 753
             ),
754 754
         ),
755 755
         'failed_invoice' => array(
756 756
             'email_failed_invoice_header' => array(
757 757
                 'id'   => 'email_failed_invoice_header',
758
-                'name' => '<h3>' . __( 'Failed Invoice', 'invoicing' ) . '</h3>',
759
-                'desc' => __( 'Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing' ),
758
+                'name' => '<h3>' . __('Failed Invoice', 'invoicing') . '</h3>',
759
+                'desc' => __('Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing'),
760 760
                 'type' => 'header',
761 761
             ),
762 762
             'email_failed_invoice_active' => array(
763 763
                 'id'   => 'email_failed_invoice_active',
764
-                'name' => __( 'Enable/Disable', 'invoicing' ),
765
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
764
+                'name' => __('Enable/Disable', 'invoicing'),
765
+                'desc' => __('Enable this email notification', 'invoicing'),
766 766
                 'type' => 'checkbox',
767 767
                 'std'  => 1
768 768
             ),
769 769
             'email_failed_invoice_subject' => array(
770 770
                 'id'   => 'email_failed_invoice_subject',
771
-                'name' => __( 'Subject', 'invoicing' ),
772
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
771
+                'name' => __('Subject', 'invoicing'),
772
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
773 773
                 'type' => 'text',
774
-                'std'  => __( '[{site_title}] Failed invoice ({invoice_number})', 'invoicing' ),
774
+                'std'  => __('[{site_title}] Failed invoice ({invoice_number})', 'invoicing'),
775 775
                 'size' => 'large'
776 776
             ),
777 777
             'email_failed_invoice_heading' => array(
778 778
                 'id'   => 'email_failed_invoice_heading',
779
-                'name' => __( 'Email Heading', 'invoicing' ),
780
-                'desc' => __( 'Enter the the main heading contained within the email notification.', 'invoicing' ),
779
+                'name' => __('Email Heading', 'invoicing'),
780
+                'desc' => __('Enter the the main heading contained within the email notification.', 'invoicing'),
781 781
                 'type' => 'text',
782
-                'std'  => __( 'Failed invoice', 'invoicing' ),
782
+                'std'  => __('Failed invoice', 'invoicing'),
783 783
                 'size' => 'large'
784 784
             )
785 785
         ),
786 786
         'onhold_invoice' => array(
787 787
             'email_onhold_invoice_header' => array(
788 788
                 'id'   => 'email_onhold_invoice_header',
789
-                'name' => '<h3>' . __( 'On Hold Invoice', 'invoicing' ) . '</h3>',
790
-                'desc' => __( 'This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing' ),
789
+                'name' => '<h3>' . __('On Hold Invoice', 'invoicing') . '</h3>',
790
+                'desc' => __('This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing'),
791 791
                 'type' => 'header',
792 792
             ),
793 793
             'email_onhold_invoice_active' => array(
794 794
                 'id'   => 'email_onhold_invoice_active',
795
-                'name' => __( 'Enable/Disable', 'invoicing' ),
796
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
795
+                'name' => __('Enable/Disable', 'invoicing'),
796
+                'desc' => __('Enable this email notification', 'invoicing'),
797 797
                 'type' => 'checkbox',
798 798
                 'std'  => 1
799 799
             ),
800 800
             'email_onhold_invoice_subject' => array(
801 801
                 'id'   => 'email_onhold_invoice_subject',
802
-                'name' => __( 'Subject', 'invoicing' ),
803
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
802
+                'name' => __('Subject', 'invoicing'),
803
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
804 804
                 'type' => 'text',
805
-                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
805
+                'std'  => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'),
806 806
                 'size' => 'large'
807 807
             ),
808 808
             'email_onhold_invoice_heading' => array(
809 809
                 'id'   => 'email_onhold_invoice_heading',
810
-                'name' => __( 'Email Heading', 'invoicing' ),
811
-                'desc' => __( 'Enter the the main heading contained within the email notification.', 'invoicing' ),
810
+                'name' => __('Email Heading', 'invoicing'),
811
+                'desc' => __('Enter the the main heading contained within the email notification.', 'invoicing'),
812 812
                 'type' => 'text',
813
-                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
813
+                'std'  => __('Thank you for your invoice', 'invoicing'),
814 814
                 'size' => 'large'
815 815
             ),
816 816
             'email_onhold_invoice_admin_bcc' => array(
817 817
                 'id'   => 'email_onhold_invoice_admin_bcc',
818
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
819
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
818
+                'name' => __('Enable Admin BCC', 'invoicing'),
819
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
820 820
                 'type' => 'checkbox',
821 821
                 'std'  => 1
822 822
             ),
@@ -824,37 +824,37 @@  discard block
 block discarded – undo
824 824
         'processing_invoice' => array(
825 825
             'email_processing_invoice_header' => array(
826 826
                 'id'   => 'email_processing_invoice_header',
827
-                'name' => '<h3>' . __( 'Processing Invoice', 'invoicing' ) . '</h3>',
828
-                'desc' => __( 'This is an invoice notification sent to users containing invoice details after payment.', 'invoicing' ),
827
+                'name' => '<h3>' . __('Processing Invoice', 'invoicing') . '</h3>',
828
+                'desc' => __('This is an invoice notification sent to users containing invoice details after payment.', 'invoicing'),
829 829
                 'type' => 'header',
830 830
             ),
831 831
             'email_processing_invoice_active' => array(
832 832
                 'id'   => 'email_processing_invoice_active',
833
-                'name' => __( 'Enable/Disable', 'invoicing' ),
834
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
833
+                'name' => __('Enable/Disable', 'invoicing'),
834
+                'desc' => __('Enable this email notification', 'invoicing'),
835 835
                 'type' => 'checkbox',
836 836
                 'std'  => 1
837 837
             ),
838 838
             'email_processing_invoice_subject' => array(
839 839
                 'id'   => 'email_processing_invoice_subject',
840
-                'name' => __( 'Subject', 'invoicing' ),
841
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
840
+                'name' => __('Subject', 'invoicing'),
841
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
842 842
                 'type' => 'text',
843
-                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
843
+                'std'  => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'),
844 844
                 'size' => 'large'
845 845
             ),
846 846
             'email_processing_invoice_heading' => array(
847 847
                 'id'   => 'email_processing_invoice_heading',
848
-                'name' => __( 'Email Heading', 'invoicing' ),
849
-                'desc' => __( 'Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
848
+                'name' => __('Email Heading', 'invoicing'),
849
+                'desc' => __('Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
850 850
                 'type' => 'text',
851
-                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
851
+                'std'  => __('Thank you for your invoice', 'invoicing'),
852 852
                 'size' => 'large'
853 853
             ),
854 854
             'email_processing_invoice_admin_bcc' => array(
855 855
                 'id'   => 'email_processing_invoice_admin_bcc',
856
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
857
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
856
+                'name' => __('Enable Admin BCC', 'invoicing'),
857
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
858 858
                 'type' => 'checkbox',
859 859
                 'std'  => 1
860 860
             ),
@@ -862,37 +862,37 @@  discard block
 block discarded – undo
862 862
         'completed_invoice' => array(
863 863
             'email_completed_invoice_header' => array(
864 864
                 'id'   => 'email_completed_invoice_header',
865
-                'name' => '<h3>' . __( 'Paid Invoice', 'invoicing' ) . '</h3>',
866
-                'desc' => __( 'Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing' ),
865
+                'name' => '<h3>' . __('Paid Invoice', 'invoicing') . '</h3>',
866
+                'desc' => __('Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing'),
867 867
                 'type' => 'header',
868 868
             ),
869 869
             'email_completed_invoice_active' => array(
870 870
                 'id'   => 'email_completed_invoice_active',
871
-                'name' => __( 'Enable/Disable', 'invoicing' ),
872
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
871
+                'name' => __('Enable/Disable', 'invoicing'),
872
+                'desc' => __('Enable this email notification', 'invoicing'),
873 873
                 'type' => 'checkbox',
874 874
                 'std'  => 1
875 875
             ),
876 876
             'email_completed_invoice_subject' => array(
877 877
                 'id'   => 'email_completed_invoice_subject',
878
-                'name' => __( 'Subject', 'invoicing' ),
879
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
878
+                'name' => __('Subject', 'invoicing'),
879
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
880 880
                 'type' => 'text',
881
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing' ),
881
+                'std'  => __('[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing'),
882 882
                 'size' => 'large'
883 883
             ),
884 884
             'email_completed_invoice_heading' => array(
885 885
                 'id'   => 'email_completed_invoice_heading',
886
-                'name' => __( 'Email Heading', 'invoicing' ),
887
-                'desc' => __( 'Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
886
+                'name' => __('Email Heading', 'invoicing'),
887
+                'desc' => __('Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
888 888
                 'type' => 'text',
889
-                'std'  => __( 'Your invoice has been paid', 'invoicing' ),
889
+                'std'  => __('Your invoice has been paid', 'invoicing'),
890 890
                 'size' => 'large'
891 891
             ),
892 892
             'email_completed_invoice_admin_bcc' => array(
893 893
                 'id'   => 'email_completed_invoice_admin_bcc',
894
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
895
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
894
+                'name' => __('Enable Admin BCC', 'invoicing'),
895
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
896 896
                 'type' => 'checkbox',
897 897
             ),
898 898
             'std'  => 1
@@ -900,37 +900,37 @@  discard block
 block discarded – undo
900 900
         'refunded_invoice' => array(
901 901
             'email_refunded_invoice_header' => array(
902 902
                 'id'   => 'email_refunded_invoice_header',
903
-                'name' => '<h3>' . __( 'Refunded Invoice', 'invoicing' ) . '</h3>',
904
-                'desc' => __( 'Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing' ),
903
+                'name' => '<h3>' . __('Refunded Invoice', 'invoicing') . '</h3>',
904
+                'desc' => __('Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing'),
905 905
                 'type' => 'header',
906 906
             ),
907 907
             'email_refunded_invoice_active' => array(
908 908
                 'id'   => 'email_refunded_invoice_active',
909
-                'name' => __( 'Enable/Disable', 'invoicing' ),
910
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
909
+                'name' => __('Enable/Disable', 'invoicing'),
910
+                'desc' => __('Enable this email notification', 'invoicing'),
911 911
                 'type' => 'checkbox',
912 912
                 'std'  => 1
913 913
             ),
914 914
             'email_refunded_invoice_subject' => array(
915 915
                 'id'   => 'email_refunded_invoice_subject',
916
-                'name' => __( 'Subject', 'invoicing' ),
917
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
916
+                'name' => __('Subject', 'invoicing'),
917
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
918 918
                 'type' => 'text',
919
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing' ),
919
+                'std'  => __('[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing'),
920 920
                 'size' => 'large'
921 921
             ),
922 922
             'email_refunded_invoice_heading' => array(
923 923
                 'id'   => 'email_refunded_invoice_heading',
924
-                'name' => __( 'Email Heading', 'invoicing' ),
925
-                'desc' => __( 'Enter the the main heading contained within the email notification.', 'invoicing' ),
924
+                'name' => __('Email Heading', 'invoicing'),
925
+                'desc' => __('Enter the the main heading contained within the email notification.', 'invoicing'),
926 926
                 'type' => 'text',
927
-                'std'  => __( 'Your invoice has been refunded', 'invoicing' ),
927
+                'std'  => __('Your invoice has been refunded', 'invoicing'),
928 928
                 'size' => 'large'
929 929
             ),
930 930
             'email_refunded_invoice_admin_bcc' => array(
931 931
                 'id'   => 'email_refunded_invoice_admin_bcc',
932
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
933
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
932
+                'name' => __('Enable Admin BCC', 'invoicing'),
933
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
934 934
                 'type' => 'checkbox',
935 935
                 'std'  => 1
936 936
             ),
@@ -938,37 +938,37 @@  discard block
 block discarded – undo
938 938
         'user_invoice' => array(
939 939
             'email_user_invoice_header' => array(
940 940
                 'id'   => 'email_user_invoice_header',
941
-                'name' => '<h3>' . __( 'Customer Invoice', 'invoicing' ) . '</h3>',
942
-                'desc' => __( 'Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing' ),
941
+                'name' => '<h3>' . __('Customer Invoice', 'invoicing') . '</h3>',
942
+                'desc' => __('Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing'),
943 943
                 'type' => 'header',
944 944
             ),
945 945
             'email_user_invoice_active' => array(
946 946
                 'id'   => 'email_user_invoice_active',
947
-                'name' => __( 'Enable/Disable', 'invoicing' ),
948
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
947
+                'name' => __('Enable/Disable', 'invoicing'),
948
+                'desc' => __('Enable this email notification', 'invoicing'),
949 949
                 'type' => 'checkbox',
950 950
                 'std'  => 1
951 951
             ),
952 952
             'email_user_invoice_subject' => array(
953 953
                 'id'   => 'email_user_invoice_subject',
954
-                'name' => __( 'Subject', 'invoicing' ),
955
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
954
+                'name' => __('Subject', 'invoicing'),
955
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
956 956
                 'type' => 'text',
957
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date}', 'invoicing' ),
957
+                'std'  => __('[{site_title}] Your invoice from {invoice_date}', 'invoicing'),
958 958
                 'size' => 'large'
959 959
             ),
960 960
             'email_user_invoice_heading' => array(
961 961
                 'id'   => 'email_user_invoice_heading',
962
-                'name' => __( 'Email Heading', 'invoicing' ),
963
-                'desc' => __( 'Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
962
+                'name' => __('Email Heading', 'invoicing'),
963
+                'desc' => __('Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
964 964
                 'type' => 'text',
965
-                'std'  => __( 'Your invoice {invoice_number} details', 'invoicing' ),
965
+                'std'  => __('Your invoice {invoice_number} details', 'invoicing'),
966 966
                 'size' => 'large'
967 967
             ),
968 968
             'email_user_invoice_admin_bcc' => array(
969 969
                 'id'   => 'email_user_invoice_admin_bcc',
970
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
971
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
970
+                'name' => __('Enable Admin BCC', 'invoicing'),
971
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
972 972
                 'type' => 'checkbox',
973 973
                 'std'  => 1
974 974
             ),
@@ -976,177 +976,177 @@  discard block
 block discarded – undo
976 976
         'user_note' => array(
977 977
             'email_user_note_header' => array(
978 978
                 'id'   => 'email_user_note_header',
979
-                'name' => '<h3>' . __( 'Customer Note', 'invoicing' ) . '</h3>',
980
-                'desc' => __( 'Customer note emails are sent when you add a note to an invoice.', 'invoicing' ),
979
+                'name' => '<h3>' . __('Customer Note', 'invoicing') . '</h3>',
980
+                'desc' => __('Customer note emails are sent when you add a note to an invoice.', 'invoicing'),
981 981
                 'type' => 'header',
982 982
             ),
983 983
             'email_user_note_active' => array(
984 984
                 'id'   => 'email_user_note_active',
985
-                'name' => __( 'Enable/Disable', 'invoicing' ),
986
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
985
+                'name' => __('Enable/Disable', 'invoicing'),
986
+                'desc' => __('Enable this email notification', 'invoicing'),
987 987
                 'type' => 'checkbox',
988 988
                 'std'  => 1
989 989
             ),
990 990
             'email_user_note_subject' => array(
991 991
                 'id'   => 'email_user_note_subject',
992
-                'name' => __( 'Subject', 'invoicing' ),
993
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
992
+                'name' => __('Subject', 'invoicing'),
993
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
994 994
                 'type' => 'text',
995
-                'std'  => __( '[{site_title}] Note added to your invoice #{invoice_number} from {invoice_date}', 'invoicing' ),
995
+                'std'  => __('[{site_title}] Note added to your invoice #{invoice_number} from {invoice_date}', 'invoicing'),
996 996
                 'size' => 'large'
997 997
             ),
998 998
             'email_user_note_heading' => array(
999 999
                 'id'   => 'email_user_note_heading',
1000
-                'name' => __( 'Email Heading', 'invoicing' ),
1001
-                'desc' => __( 'Enter the the main heading contained within the email notification.', 'invoicing' ),
1000
+                'name' => __('Email Heading', 'invoicing'),
1001
+                'desc' => __('Enter the the main heading contained within the email notification.', 'invoicing'),
1002 1002
                 'type' => 'text',
1003
-                'std'  => __( 'A note has been added to your invoice', 'invoicing' ),
1003
+                'std'  => __('A note has been added to your invoice', 'invoicing'),
1004 1004
                 'size' => 'large'
1005 1005
             ),
1006 1006
         ),
1007 1007
         'overdue' => array(
1008 1008
             'email_overdue_header' => array(
1009 1009
                 'id'   => 'email_overdue_header',
1010
-                'name' => '<h3>' . __( 'Payment Reminder', 'invoicing' ) . '</h3>',
1011
-                'desc' => __( 'Payment reminder emails are sent to user automatically.', 'invoicing' ),
1010
+                'name' => '<h3>' . __('Payment Reminder', 'invoicing') . '</h3>',
1011
+                'desc' => __('Payment reminder emails are sent to user automatically.', 'invoicing'),
1012 1012
                 'type' => 'header',
1013 1013
             ),
1014 1014
             'email_overdue_active' => array(
1015 1015
                 'id'   => 'email_overdue_active',
1016
-                'name' => __( 'Enable/Disable', 'invoicing' ),
1017
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
1016
+                'name' => __('Enable/Disable', 'invoicing'),
1017
+                'desc' => __('Enable this email notification', 'invoicing'),
1018 1018
                 'type' => 'checkbox',
1019 1019
                 'std'  => 1
1020 1020
             ),
1021 1021
             'email_due_reminder_days' => array(
1022 1022
                 'id'        => 'email_due_reminder_days',
1023
-                'name'      => __( 'When to Send', 'sliced-invoices' ),
1024
-                'desc'      => __( 'Check when you would like payment reminders sent out.', 'invoicing' ),
1023
+                'name'      => __('When to Send', 'sliced-invoices'),
1024
+                'desc'      => __('Check when you would like payment reminders sent out.', 'invoicing'),
1025 1025
                 'default'   => '',
1026 1026
                 'type'      => 'multicheck',
1027 1027
                 'options'   => $overdue_days_options,
1028 1028
             ),
1029 1029
             'email_overdue_subject' => array(
1030 1030
                 'id'   => 'email_overdue_subject',
1031
-                'name' => __( 'Subject', 'invoicing' ),
1032
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
1031
+                'name' => __('Subject', 'invoicing'),
1032
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
1033 1033
                 'type' => 'text',
1034
-                'std'  => __( '[{site_title}] Payment Reminder', 'invoicing' ),
1034
+                'std'  => __('[{site_title}] Payment Reminder', 'invoicing'),
1035 1035
                 'size' => 'large'
1036 1036
             ),
1037 1037
             'email_overdue_heading' => array(
1038 1038
                 'id'   => 'email_overdue_heading',
1039
-                'name' => __( 'Email Heading', 'invoicing' ),
1040
-                'desc' => __( 'Enter the the main heading contained within the email notification.', 'invoicing' ),
1039
+                'name' => __('Email Heading', 'invoicing'),
1040
+                'desc' => __('Enter the the main heading contained within the email notification.', 'invoicing'),
1041 1041
                 'type' => 'text',
1042
-                'std'  => __( 'Payment reminder for your invoice', 'invoicing' ),
1042
+                'std'  => __('Payment reminder for your invoice', 'invoicing'),
1043 1043
                 'size' => 'large'
1044 1044
             ),
1045 1045
             'email_overdue_body' => array(
1046 1046
                 'id'   => 'email_overdue_body',
1047
-                'name' => __( 'Email Content', 'invoicing' ),
1048
-                'desc' => __( 'The content of the email.', 'invoicing' ),
1047
+                'name' => __('Email Content', 'invoicing'),
1048
+                'desc' => __('The content of the email.', 'invoicing'),
1049 1049
                 'type' => 'rich_editor',
1050
-                'std'  => __( '<p>Hi {full_name},</p><p>This is just a friendly reminder your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To pay now for this invoice please use the following link: <a href="{invoice_pay_link}">Pay Now</a></p>', 'invoicing' ),
1050
+                'std'  => __('<p>Hi {full_name},</p><p>This is just a friendly reminder your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To pay now for this invoice please use the following link: <a href="{invoice_pay_link}">Pay Now</a></p>', 'invoicing'),
1051 1051
                 'class' => 'large',
1052 1052
                 'size'  => 10,
1053 1053
             ),
1054 1054
         ),
1055 1055
     );
1056 1056
 
1057
-    return apply_filters( 'wpinv_get_emails', $emails );
1057
+    return apply_filters('wpinv_get_emails', $emails);
1058 1058
 }
1059 1059
 
1060
-function wpinv_settings_emails( $settings = array() ) {
1060
+function wpinv_settings_emails($settings = array()) {
1061 1061
     $emails = wpinv_get_emails();
1062 1062
     
1063
-    if ( !empty( $emails ) ) {
1064
-        foreach ( $emails as $key => $email ) {
1063
+    if (!empty($emails)) {
1064
+        foreach ($emails as $key => $email) {
1065 1065
             $settings[$key] = $email;
1066 1066
         }
1067 1067
     }
1068 1068
     
1069
-    return apply_filters( 'wpinv_settings_get_emails', $settings );
1069
+    return apply_filters('wpinv_settings_get_emails', $settings);
1070 1070
 }
1071
-add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 );
1071
+add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1);
1072 1072
 
1073
-function wpinv_settings_sections_emails( $settings ) {
1073
+function wpinv_settings_sections_emails($settings) {
1074 1074
     $emails = wpinv_get_emails();
1075 1075
     
1076 1076
     if (!empty($emails)) {
1077
-        foreach  ($emails as $key => $email) {
1078
-            $settings[$key] = !empty( $email['email_' . $key . '_header']['name'] ) ? strip_tags( $email['email_' . $key . '_header']['name'] ) : $key;
1077
+        foreach ($emails as $key => $email) {
1078
+            $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : $key;
1079 1079
         }
1080 1080
     }
1081 1081
     
1082 1082
     return $settings;    
1083 1083
 }
1084
-add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 );
1084
+add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1);
1085 1085
 
1086
-function wpinv_email_is_enabled( $email_type ) {
1086
+function wpinv_email_is_enabled($email_type) {
1087 1087
     $emails = wpinv_get_emails();
1088
-    $enabled = isset( $emails[$email_type] ) && wpinv_get_option( $email_type . '_active', 1 ) ? true : false;
1088
+    $enabled = isset($emails[$email_type]) && wpinv_get_option($email_type . '_active', 1) ? true : false;
1089 1089
 
1090
-    return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type );
1090
+    return apply_filters('wpinv_email_is_enabled', $enabled, $email_type);
1091 1091
 }
1092 1092
 
1093
-function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1094
-    switch ( $email_type ) {
1093
+function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) {
1094
+    switch ($email_type) {
1095 1095
         case 'new_invoice':
1096 1096
         case 'cancelled_invoice':
1097 1097
         case 'failed_invoice':
1098 1098
             $recipient  = wpinv_get_admin_email();
1099 1099
         break;
1100 1100
         default:
1101
-            $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1102
-            $recipient  = !empty( $invoice ) ? $invoice->get_email() : '';
1101
+            $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
1102
+            $recipient  = !empty($invoice) ? $invoice->get_email() : '';
1103 1103
         break;
1104 1104
     }
1105 1105
     
1106
-    return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice );
1106
+    return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice);
1107 1107
 }
1108 1108
 
1109
-function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1110
-    $subject    = wpinv_get_option( 'email_' . $email_type . '_subject' );
1109
+function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) {
1110
+    $subject    = wpinv_get_option('email_' . $email_type . '_subject');
1111 1111
     
1112
-    $subject    = wpinv_email_format_text( $subject );
1112
+    $subject    = wpinv_email_format_text($subject);
1113 1113
     
1114
-    return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice );
1114
+    return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice);
1115 1115
 }
1116 1116
 
1117
-function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1118
-    $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' );
1117
+function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) {
1118
+    $email_heading = wpinv_get_option('email_' . $email_type . '_heading');
1119 1119
     
1120
-    $email_heading = wpinv_email_format_text( $email_heading );
1120
+    $email_heading = wpinv_email_format_text($email_heading);
1121 1121
     
1122
-    return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice );
1122
+    return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice);
1123 1123
 }
1124 1124
 
1125
-function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1126
-    $content    = wpinv_get_option( 'email_' . $email_type . '_body' );
1125
+function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) {
1126
+    $content    = wpinv_get_option('email_' . $email_type . '_body');
1127 1127
     
1128
-    $content    = wpinv_email_format_text( $content );
1128
+    $content    = wpinv_email_format_text($content);
1129 1129
     
1130
-    return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice );
1130
+    return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice);
1131 1131
 }
1132 1132
 
1133
-function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1133
+function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) {
1134 1134
     $from_name = wpinv_mail_get_from_address();
1135 1135
     $from_email = wpinv_mail_get_from_address();
1136 1136
     
1137
-    $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1137
+    $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
1138 1138
     
1139
-    $headers    = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n";
1140
-    $headers    .= "Reply-To: ". $from_email . "\r\n";
1139
+    $headers    = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n";
1140
+    $headers    .= "Reply-To: " . $from_email . "\r\n";
1141 1141
     $headers    .= "Content-Type: " . wpinv_mail_get_content_type() . "\r\n";
1142 1142
     
1143
-    return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice );
1143
+    return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice);
1144 1144
 }
1145 1145
 
1146
-function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1146
+function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) {
1147 1147
     $attachments = array();
1148 1148
     
1149
-    return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice );
1149
+    return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice);
1150 1150
 }
1151 1151
 
1152 1152
 function wpinv_email_global_vars() {
@@ -1163,73 +1163,73 @@  discard block
 block discarded – undo
1163 1163
     $replace['sitename']    = $blogname;
1164 1164
     $replace['site-title']  = $blogname;
1165 1165
     
1166
-    return apply_filters( 'wpinv_email_global_vars', array( $search, $replace ) );
1166
+    return apply_filters('wpinv_email_global_vars', array($search, $replace));
1167 1167
 }
1168 1168
 
1169
-function wpinv_email_format_text( $content ) {
1169
+function wpinv_email_format_text($content) {
1170 1170
     global $wpinv_email_search, $wpinv_email_replace;
1171 1171
     
1172
-    if ( empty( $wpinv_email_search ) ) {
1172
+    if (empty($wpinv_email_search)) {
1173 1173
         $wpinv_email_search = array();
1174 1174
     }
1175 1175
     
1176
-    if ( empty( $wpinv_email_replace ) ) {
1176
+    if (empty($wpinv_email_replace)) {
1177 1177
         $wpinv_email_replace = array();
1178 1178
     }
1179 1179
     
1180
-    $wpinv_email_search     = (array)apply_filters( 'wpinv_email_format_text_search', $wpinv_email_search );
1181
-    $wpinv_email_replace    = (array)apply_filters( 'wpinv_email_format_text_replace', $wpinv_email_replace );
1180
+    $wpinv_email_search     = (array)apply_filters('wpinv_email_format_text_search', $wpinv_email_search);
1181
+    $wpinv_email_replace    = (array)apply_filters('wpinv_email_format_text_replace', $wpinv_email_replace);
1182 1182
     
1183 1183
     $global_vars    = wpinv_email_global_vars();
1184 1184
     
1185
-    $search         = array_merge( $global_vars[0], $wpinv_email_search );
1186
-    $replace        = array_merge( $global_vars[1], $wpinv_email_replace );
1185
+    $search         = array_merge($global_vars[0], $wpinv_email_search);
1186
+    $replace        = array_merge($global_vars[1], $wpinv_email_replace);
1187 1187
     
1188
-    if ( empty( $search ) || empty( $replace ) || !is_array( $search ) || !is_array( $replace ) ) {
1188
+    if (empty($search) || empty($replace) || !is_array($search) || !is_array($replace)) {
1189 1189
         return  $content;
1190 1190
     }
1191 1191
         
1192
-    return str_replace( $search, $replace, $content );
1192
+    return str_replace($search, $replace, $content);
1193 1193
 }
1194 1194
 
1195
-function wpinv_email_style_body( $content ) {
1195
+function wpinv_email_style_body($content) {
1196 1196
     // make sure we only inline CSS for html emails
1197
-    if ( in_array( wpinv_mail_get_content_type(), array( 'text/html', 'multipart/alternative' ) ) && class_exists( 'DOMDocument' ) ) {
1197
+    if (in_array(wpinv_mail_get_content_type(), array('text/html', 'multipart/alternative')) && class_exists('DOMDocument')) {
1198 1198
         ob_start();
1199
-        wpinv_get_template( 'emails/wpinv-email-styles.php' );
1200
-        $css = apply_filters( 'wpinv_email_styles', ob_get_clean() );
1199
+        wpinv_get_template('emails/wpinv-email-styles.php');
1200
+        $css = apply_filters('wpinv_email_styles', ob_get_clean());
1201 1201
         
1202 1202
         // apply CSS styles inline for picky email clients
1203 1203
         try {
1204
-            $emogrifier = new Emogrifier( $content, $css );
1204
+            $emogrifier = new Emogrifier($content, $css);
1205 1205
             $content    = $emogrifier->emogrify();
1206
-        } catch ( Exception $e ) {
1207
-            wpinv_error_log( $e->getMessage(), 'emogrifier' );
1206
+        } catch (Exception $e) {
1207
+            wpinv_error_log($e->getMessage(), 'emogrifier');
1208 1208
         }
1209 1209
     }
1210 1210
     return $content;
1211 1211
 }
1212 1212
 
1213
-function wpinv_email_header( $email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1214
-    wpinv_get_template( 'emails/wpinv-email-header.php', array( 'email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1213
+function wpinv_email_header($email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false) {
1214
+    wpinv_get_template('emails/wpinv-email-header.php', array('email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1215 1215
 }
1216 1216
 
1217 1217
 /**
1218 1218
  * Get the email footer.
1219 1219
  */
1220
-function wpinv_email_footer( $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1221
-    wpinv_get_template( 'emails/wpinv-email-footer.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1220
+function wpinv_email_footer($invoice = array(), $email_type = '', $sent_to_admin = false) {
1221
+    wpinv_get_template('emails/wpinv-email-footer.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1222 1222
 }
1223 1223
 
1224
-function wpinv_email_wrap_message( $message ) {
1224
+function wpinv_email_wrap_message($message) {
1225 1225
     // Buffer
1226 1226
     ob_start();
1227 1227
 
1228
-    do_action( 'wpinv_email_header' );
1228
+    do_action('wpinv_email_header');
1229 1229
 
1230
-    echo wpautop( wptexturize( $message ) );
1230
+    echo wpautop(wptexturize($message));
1231 1231
 
1232
-    do_action( 'wpinv_email_footer' );
1232
+    do_action('wpinv_email_footer');
1233 1233
 
1234 1234
     // Get contents
1235 1235
     $message = ob_get_clean();
@@ -1237,86 +1237,86 @@  discard block
 block discarded – undo
1237 1237
     return $message;
1238 1238
 }
1239 1239
 
1240
-function wpinv_email_invoice_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1241
-    wpinv_get_template( 'emails/wpinv-email-invoice-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1240
+function wpinv_email_invoice_details($invoice, $email_type = '', $sent_to_admin = false) {
1241
+    wpinv_get_template('emails/wpinv-email-invoice-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1242 1242
 }
1243 1243
 
1244
-function wpinv_email_invoice_items( $invoice, $email_type = '', $sent_to_admin = false ) {
1245
-    wpinv_get_template( 'emails/wpinv-email-invoice-items.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1244
+function wpinv_email_invoice_items($invoice, $email_type = '', $sent_to_admin = false) {
1245
+    wpinv_get_template('emails/wpinv-email-invoice-items.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1246 1246
 }
1247 1247
 
1248
-function wpinv_email_billing_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1249
-    wpinv_get_template( 'emails/wpinv-email-billing-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1248
+function wpinv_email_billing_details($invoice, $email_type = '', $sent_to_admin = false) {
1249
+    wpinv_get_template('emails/wpinv-email-billing-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1250 1250
 }
1251 1251
 
1252
-function wpinv_send_customer_invoice( $data = array() ) {
1253
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1252
+function wpinv_send_customer_invoice($data = array()) {
1253
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1254 1254
     
1255
-    if ( empty( $invoice_id ) ) {
1255
+    if (empty($invoice_id)) {
1256 1256
         return;
1257 1257
     }
1258 1258
 
1259
-    if ( !current_user_can( 'manage_options' ) ) {
1260
-        wp_die( __( 'You do not have permission to send invoice notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1259
+    if (!current_user_can('manage_options')) {
1260
+        wp_die(__('You do not have permission to send invoice notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
1261 1261
     }
1262 1262
     
1263
-    $sent = wpinv_user_invoice_notification( $invoice_id );
1263
+    $sent = wpinv_user_invoice_notification($invoice_id);
1264 1264
     
1265 1265
     $status = $sent ? 'email_sent' : 'email_fail';
1266 1266
     
1267
-    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1268
-    wp_redirect( $redirect );
1267
+    $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false));
1268
+    wp_redirect($redirect);
1269 1269
     exit;
1270 1270
 }
1271
-add_action( 'wpinv_send_invoice', 'wpinv_send_customer_invoice' );
1271
+add_action('wpinv_send_invoice', 'wpinv_send_customer_invoice');
1272 1272
 
1273
-function wpinv_send_overdue_reminder( $data = array() ) {
1274
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1273
+function wpinv_send_overdue_reminder($data = array()) {
1274
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1275 1275
     
1276
-    if ( empty( $invoice_id ) ) {
1276
+    if (empty($invoice_id)) {
1277 1277
         return;
1278 1278
     }
1279 1279
 
1280
-    if ( !current_user_can( 'manage_options' ) ) {
1281
-        wp_die( __( 'You do not have permission to send reminder notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1280
+    if (!current_user_can('manage_options')) {
1281
+        wp_die(__('You do not have permission to send reminder notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
1282 1282
     }
1283 1283
     
1284
-    $sent = wpinv_send_payment_reminder_notification( $invoice_id );
1284
+    $sent = wpinv_send_payment_reminder_notification($invoice_id);
1285 1285
     
1286 1286
     $status = $sent ? 'email_sent' : 'email_fail';
1287 1287
     
1288
-    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1289
-    wp_redirect( $redirect );
1288
+    $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false));
1289
+    wp_redirect($redirect);
1290 1290
     exit;
1291 1291
 }
1292
-add_action( 'wpinv_send_reminder', 'wpinv_send_overdue_reminder' );
1292
+add_action('wpinv_send_reminder', 'wpinv_send_overdue_reminder');
1293 1293
 
1294
-function wpinv_send_customer_note_email( $data ) {
1295
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1294
+function wpinv_send_customer_note_email($data) {
1295
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1296 1296
     
1297
-    if ( empty( $invoice_id ) ) {
1297
+    if (empty($invoice_id)) {
1298 1298
         return;
1299 1299
     }
1300 1300
     
1301
-    $sent = wpinv_user_note_notification( $invoice_id, $data );
1301
+    $sent = wpinv_user_note_notification($invoice_id, $data);
1302 1302
 }
1303
-add_action( 'wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1 );
1303
+add_action('wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1);
1304 1304
 
1305
-function wpinv_add_notes_to_invoice_email( $invoice, $email_type, $sent_to_admin ) {
1306
-    if ( !empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->ID, true ) ) {
1307
-        $date_format = get_option( 'date_format' );
1308
-        $time_format = get_option( 'time_format' );
1305
+function wpinv_add_notes_to_invoice_email($invoice, $email_type, $sent_to_admin) {
1306
+    if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->ID, true)) {
1307
+        $date_format = get_option('date_format');
1308
+        $time_format = get_option('time_format');
1309 1309
         ?>
1310 1310
         <div id="wpinv-email-notes">
1311
-            <h3 class="wpinv-notes-t"><?php echo apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ); ?></h3>
1311
+            <h3 class="wpinv-notes-t"><?php echo apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing')); ?></h3>
1312 1312
             <ol class="wpinv-notes-lists">
1313 1313
         <?php
1314
-        foreach ( $invoice_notes as $note ) {
1315
-            $note_time = strtotime( $note->comment_date );
1314
+        foreach ($invoice_notes as $note) {
1315
+            $note_time = strtotime($note->comment_date);
1316 1316
             ?>
1317 1317
             <li class="comment wpinv-note">
1318
-            <p class="wpinv-note-date meta"><?php printf( __( '%2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( $date_format, $note_time ), date_i18n( $time_format, $note_time ), $note_time ); ?></p>
1319
-            <div class="wpinv-note-desc description"><?php echo wpautop( wptexturize( $note->comment_content ) ); ?></div>
1318
+            <p class="wpinv-note-date meta"><?php printf(__('%2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n($date_format, $note_time), date_i18n($time_format, $note_time), $note_time); ?></p>
1319
+            <div class="wpinv-note-desc description"><?php echo wpautop(wptexturize($note->comment_content)); ?></div>
1320 1320
             </li>
1321 1321
             <?php
1322 1322
         }
@@ -1325,21 +1325,21 @@  discard block
 block discarded – undo
1325 1325
         <?php
1326 1326
     }
1327 1327
 }
1328
-add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 );
1328
+add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3);
1329 1329
 
1330 1330
 function wpinv_email_payment_reminders() {    
1331 1331
     global $wpi_auto_reminder;
1332
-    if ( !wpinv_get_option( 'email_overdue_active' ) ) {
1332
+    if (!wpinv_get_option('email_overdue_active')) {
1333 1333
         return;
1334 1334
     }
1335 1335
     
1336
-    if ( $reminder_days = wpinv_get_option( 'email_due_reminder_days' ) ) {
1337
-        $reminder_days  = is_array( $reminder_days ) ? array_values( $reminder_days ) : '';
1336
+    if ($reminder_days = wpinv_get_option('email_due_reminder_days')) {
1337
+        $reminder_days  = is_array($reminder_days) ? array_values($reminder_days) : '';
1338 1338
         
1339
-        if ( empty( $reminder_days ) ) {
1339
+        if (empty($reminder_days)) {
1340 1340
             return;
1341 1341
         }
1342
-        $reminder_days  = array_unique( array_map( 'absint', $reminder_days ) );
1342
+        $reminder_days = array_unique(array_map('absint', $reminder_days));
1343 1343
         
1344 1344
         $args = array(
1345 1345
             'post_type'     => 'wpi_invoice',
@@ -1349,7 +1349,7 @@  discard block
 block discarded – undo
1349 1349
             'meta_query'    => array(
1350 1350
                 array(
1351 1351
                     'key'       =>  '_wpinv_due_date',
1352
-                    'value'     =>  array( '', 'none' ),
1352
+                    'value'     =>  array('', 'none'),
1353 1353
                     'compare'   =>  'NOT IN',
1354 1354
                 )
1355 1355
             ),
@@ -1358,64 +1358,64 @@  discard block
 block discarded – undo
1358 1358
             'order'         => 'ASC',
1359 1359
         );
1360 1360
         
1361
-        $invoices = get_posts( $args );
1361
+        $invoices = get_posts($args);
1362 1362
         
1363
-        if ( empty( $invoices ) ) {
1363
+        if (empty($invoices)) {
1364 1364
             return;
1365 1365
         }
1366 1366
         
1367
-        $date_to_send   = array();
1367
+        $date_to_send = array();
1368 1368
         
1369
-        foreach ( $invoices as $id ) {
1370
-            $due_date = get_post_meta( $id, '_wpinv_due_date', true );
1369
+        foreach ($invoices as $id) {
1370
+            $due_date = get_post_meta($id, '_wpinv_due_date', true);
1371 1371
             
1372
-            foreach ( $reminder_days as $key => $days ) {
1373
-                if ( $days !== '' ) {
1374
-                    $date_to_send[$id][] = date_i18n( 'Y-m-d', strtotime( $due_date ) + ( $days * DAY_IN_SECONDS ) );
1372
+            foreach ($reminder_days as $key => $days) {
1373
+                if ($days !== '') {
1374
+                    $date_to_send[$id][] = date_i18n('Y-m-d', strtotime($due_date) + ($days * DAY_IN_SECONDS));
1375 1375
                 }
1376 1376
             }
1377 1377
         }
1378 1378
 
1379
-        $today              = date_i18n( 'Y-m-d' );
1379
+        $today              = date_i18n('Y-m-d');
1380 1380
         $wpi_auto_reminder  = true;
1381 1381
 
1382
-        foreach ( $date_to_send as $id => $values ) {
1383
-            if ( in_array( $today, $values ) ) {
1384
-                $sent = get_post_meta( $id, '_wpinv_reminder_sent', true );
1382
+        foreach ($date_to_send as $id => $values) {
1383
+            if (in_array($today, $values)) {
1384
+                $sent = get_post_meta($id, '_wpinv_reminder_sent', true);
1385 1385
 
1386
-                if ( isset( $sent ) && !empty( $sent ) ) {
1387
-                    if ( !in_array( $today, $sent ) ) {
1388
-                        do_action( 'wpinv_send_payment_reminder_notification', $id );
1386
+                if (isset($sent) && !empty($sent)) {
1387
+                    if (!in_array($today, $sent)) {
1388
+                        do_action('wpinv_send_payment_reminder_notification', $id);
1389 1389
                     }
1390 1390
                 } else {
1391
-                    do_action( 'wpinv_send_payment_reminder_notification', $id );
1391
+                    do_action('wpinv_send_payment_reminder_notification', $id);
1392 1392
                 }
1393 1393
             }
1394 1394
         }
1395 1395
         
1396
-        $wpi_auto_reminder  = false;
1396
+        $wpi_auto_reminder = false;
1397 1397
     }
1398 1398
 }
1399 1399
 
1400
-function wpinv_send_payment_reminder_notification( $invoice_id ) {
1400
+function wpinv_send_payment_reminder_notification($invoice_id) {
1401 1401
     global $wpinv_email_search, $wpinv_email_replace;
1402 1402
     
1403 1403
     $email_type = 'overdue';
1404
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
1404
+    if (!wpinv_email_is_enabled($email_type)) {
1405 1405
         return false;
1406 1406
     }
1407 1407
     
1408
-    $invoice    = wpinv_get_invoice( $invoice_id );
1409
-    if ( empty( $invoice ) ) {
1408
+    $invoice = wpinv_get_invoice($invoice_id);
1409
+    if (empty($invoice)) {
1410 1410
         return false;
1411 1411
     }
1412 1412
     
1413
-    if ( !$invoice->needs_payment() ) {
1413
+    if (!$invoice->needs_payment()) {
1414 1414
         return false;
1415 1415
     }
1416 1416
     
1417
-    $recipient  = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
1418
-    if ( !is_email( $recipient ) ) {
1417
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
1418
+    if (!is_email($recipient)) {
1419 1419
         return false;
1420 1420
     }
1421 1421
         
@@ -1431,60 +1431,60 @@  discard block
 block discarded – undo
1431 1431
     $replace                    = array();
1432 1432
     $replace['full_name']       = $invoice->get_user_full_name();
1433 1433
     $replace['invoice_number']  = $invoice->get_number();
1434
-    $replace['invoice_due_date']= $invoice->get_due_date( true );
1435
-    $replace['invoice_total']   = $invoice->get_total( true );
1436
-    $replace['invoice_link']    = $invoice->get_view_url( true );
1437
-    $replace['invoice_pay_link']= $invoice->get_checkout_payment_url( false, true );
1438
-    $replace['is_was']          = strtotime( $invoice->get_due_date() ) < strtotime( date_i18n( 'Y-m-d' ) ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' );
1434
+    $replace['invoice_due_date'] = $invoice->get_due_date(true);
1435
+    $replace['invoice_total']   = $invoice->get_total(true);
1436
+    $replace['invoice_link']    = $invoice->get_view_url(true);
1437
+    $replace['invoice_pay_link'] = $invoice->get_checkout_payment_url(false, true);
1438
+    $replace['is_was']          = strtotime($invoice->get_due_date()) < strtotime(date_i18n('Y-m-d')) ? __('was', 'invoicing') : __('is', 'invoicing');
1439 1439
 
1440 1440
     $wpinv_email_search         = $search;
1441 1441
     $wpinv_email_replace        = $replace;
1442 1442
     
1443
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
1444
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
1445
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
1446
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
1443
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
1444
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
1445
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
1446
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
1447 1447
     
1448
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
1448
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
1449 1449
     
1450
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
1450
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
1451 1451
             'invoice'       => $invoice,
1452 1452
             'email_type'    => $email_type,
1453 1453
             'email_heading' => $email_heading,
1454 1454
             'sent_to_admin' => false,
1455 1455
             'plain_text'    => false,
1456 1456
             'message_body'  => $message_body
1457
-        ) );
1457
+        ));
1458 1458
         
1459
-    $content        = wpinv_email_format_text( $content );
1459
+    $content = wpinv_email_format_text($content);
1460 1460
 
1461
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
1462
-    if ( $sent ) {
1463
-        do_action( 'wpinv_payment_reminder_sent', $invoice_id, $invoice );
1461
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
1462
+    if ($sent) {
1463
+        do_action('wpinv_payment_reminder_sent', $invoice_id, $invoice);
1464 1464
     }
1465 1465
         
1466 1466
     return $sent;
1467 1467
 }
1468
-add_action( 'wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1 );
1468
+add_action('wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1);
1469 1469
 
1470
-function wpinv_payment_reminder_sent( $invoice_id, $invoice ) {
1470
+function wpinv_payment_reminder_sent($invoice_id, $invoice) {
1471 1471
     global $wpi_auto_reminder;
1472 1472
     
1473
-    $sent = get_post_meta( $invoice_id, '_wpinv_reminder_sent', true );
1473
+    $sent = get_post_meta($invoice_id, '_wpinv_reminder_sent', true);
1474 1474
     
1475
-    if ( empty( $sent ) ) {
1475
+    if (empty($sent)) {
1476 1476
         $sent = array();
1477 1477
     }
1478
-    $sent[] = date_i18n( 'Y-m-d' );
1478
+    $sent[] = date_i18n('Y-m-d');
1479 1479
     
1480
-    update_post_meta( $invoice_id, '_wpinv_reminder_sent', $sent );
1480
+    update_post_meta($invoice_id, '_wpinv_reminder_sent', $sent);
1481 1481
     
1482
-    if ( $wpi_auto_reminder ) { // Auto reminder note.
1483
-        $note = __( 'Manual reminder sent to the user.', 'invoicing' );
1484
-        $invoice->add_note( $note, false, false, true );
1482
+    if ($wpi_auto_reminder) { // Auto reminder note.
1483
+        $note = __('Manual reminder sent to the user.', 'invoicing');
1484
+        $invoice->add_note($note, false, false, true);
1485 1485
     } else { // Menual reminder note.
1486
-        $note = __( 'Manual reminder sent to the user.', 'invoicing' );
1487
-        $invoice->add_note( $note );
1486
+        $note = __('Manual reminder sent to the user.', 'invoicing');
1487
+        $invoice->add_note($note);
1488 1488
     }
1489 1489
 }
1490
-add_action( 'wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2 );
1491 1490
\ No newline at end of file
1491
+add_action('wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2);
1492 1492
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-gd-functions.php 3 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -183,6 +183,9 @@  discard block
 block discarded – undo
183 183
 }
184 184
 add_action( 'geodir_checkout_page_content', 'wpinv_print_checkout_errors', -10 );
185 185
 
186
+/**
187
+ * @return integer
188
+ */
186 189
 function wpinv_cpt_save( $invoice_id, $update = false, $pre_status = NULL ) {
187 190
     global $wpi_nosave, $wpi_zero_tax, $wpi_gdp_inv_merge;
188 191
     
@@ -899,6 +902,9 @@  discard block
 block discarded – undo
899 902
 add_action( 'geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link' );
900 903
 remove_action( 'geodir_dashboard_links', 'geodir_payment_invoices_list_page_link' );
901 904
 
905
+/**
906
+ * @param string $new_status
907
+ */
902 908
 function wpinv_wpi_to_gdp_update_status( $invoice_id, $new_status, $old_status ) {
903 909
     if (!defined('GEODIRPAYMENT_VERSION')) {
904 910
         return false;
Please login to merge, or discard this patch.
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -977,67 +977,67 @@
 block discarded – undo
977 977
 function wpinv_tool_merge_fix_taxes() {
978 978
     global $wpdb;
979 979
     
980
-	$sql = "SELECT DISTINCT p.ID FROM `" . $wpdb->posts . "` AS p LEFT JOIN " . $wpdb->postmeta . " AS pm ON pm.post_id = p.ID WHERE p.post_type = 'wpi_item' AND pm.meta_key = '_wpinv_type' AND pm.meta_value = 'package'";
981
-	$items = $wpdb->get_results( $sql );
980
+    $sql = "SELECT DISTINCT p.ID FROM `" . $wpdb->posts . "` AS p LEFT JOIN " . $wpdb->postmeta . " AS pm ON pm.post_id = p.ID WHERE p.post_type = 'wpi_item' AND pm.meta_key = '_wpinv_type' AND pm.meta_value = 'package'";
981
+    $items = $wpdb->get_results( $sql );
982 982
 	
983
-	if ( !empty( $items ) ) {
984
-		foreach ( $items as $item ) {
985
-			if ( get_post_meta( $item->ID, '_wpinv_vat_class', true ) == '_exempt' ) {
986
-				update_post_meta( $item->ID, '_wpinv_vat_class', '_standard' );
987
-			}
988
-		}
989
-	}
983
+    if ( !empty( $items ) ) {
984
+        foreach ( $items as $item ) {
985
+            if ( get_post_meta( $item->ID, '_wpinv_vat_class', true ) == '_exempt' ) {
986
+                update_post_meta( $item->ID, '_wpinv_vat_class', '_standard' );
987
+            }
988
+        }
989
+    }
990 990
 		
991 991
     $sql = "SELECT `p`.`ID`, gdi.id AS gdp_id FROM `" . INVOICE_TABLE . "` AS gdi LEFT JOIN `" . $wpdb->posts . "` AS p ON `p`.`ID` = `gdi`.`invoice_id` AND `p`.`post_type` = 'wpi_invoice' WHERE `p`.`ID` IS NOT NULL AND p.post_status NOT IN( 'publish', 'complete', 'processing', 'renewal' ) ORDER BY `gdi`.`id` ASC";
992 992
     $items = $wpdb->get_results( $sql );
993 993
 	
994
-	if ( !empty( $items ) ) {
995
-		$success = false;
994
+    if ( !empty( $items ) ) {
995
+        $success = false;
996 996
         $message = __( 'Taxes fixed for non-paid merged GD invoices.', 'invoicing' );
997 997
 		
998
-		global $wpi_userID, $wpinv_ip_address_country, $wpi_tax_rates;
998
+        global $wpi_userID, $wpinv_ip_address_country, $wpi_tax_rates;
999 999
 		
1000
-		foreach ( $items as $item ) {
1001
-			$wpi_tax_rates = NULL;               
1002
-			$data = wpinv_get_invoice($item->ID);
1000
+        foreach ( $items as $item ) {
1001
+            $wpi_tax_rates = NULL;               
1002
+            $data = wpinv_get_invoice($item->ID);
1003 1003
 
1004
-			if ( empty( $data ) ) {
1005
-				continue;
1006
-			}
1004
+            if ( empty( $data ) ) {
1005
+                continue;
1006
+            }
1007 1007
 			
1008
-			$checkout_session = wpinv_get_checkout_session();
1008
+            $checkout_session = wpinv_get_checkout_session();
1009 1009
 			
1010
-			$data_session                   = array();
1011
-			$data_session['invoice_id']     = $data->ID;
1012
-			$data_session['cart_discounts'] = $data->get_discounts( true );
1010
+            $data_session                   = array();
1011
+            $data_session['invoice_id']     = $data->ID;
1012
+            $data_session['cart_discounts'] = $data->get_discounts( true );
1013 1013
 			
1014
-			wpinv_set_checkout_session( $data_session );
1014
+            wpinv_set_checkout_session( $data_session );
1015 1015
 			
1016
-			$wpi_userID         = (int)$data->get_user_id();
1017
-			$_POST['country']   = !empty($data->country) ? $data->country : wpinv_get_default_country();
1016
+            $wpi_userID         = (int)$data->get_user_id();
1017
+            $_POST['country']   = !empty($data->country) ? $data->country : wpinv_get_default_country();
1018 1018
 				
1019
-			$data->country      = sanitize_text_field( $_POST['country'] );
1020
-			$data->set( 'country', sanitize_text_field( $_POST['country'] ) );
1019
+            $data->country      = sanitize_text_field( $_POST['country'] );
1020
+            $data->set( 'country', sanitize_text_field( $_POST['country'] ) );
1021 1021
 			
1022
-			$wpinv_ip_address_country = $data->country;
1022
+            $wpinv_ip_address_country = $data->country;
1023 1023
 			
1024
-			$data->recalculate_totals(true);
1024
+            $data->recalculate_totals(true);
1025 1025
 			
1026
-			wpinv_set_checkout_session( $checkout_session );
1026
+            wpinv_set_checkout_session( $checkout_session );
1027 1027
 			
1028
-			$update_data = array();
1029
-			$update_data['tax_amount'] = $data->get_tax();
1030
-			$update_data['paied_amount'] = $data->get_total();
1031
-			$update_data['invoice_id'] = $data->ID;
1028
+            $update_data = array();
1029
+            $update_data['tax_amount'] = $data->get_tax();
1030
+            $update_data['paied_amount'] = $data->get_total();
1031
+            $update_data['invoice_id'] = $data->ID;
1032 1032
 			
1033
-			$wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $item->gdp_id ) );
1034
-		}
1035
-	} else {
1033
+            $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $item->gdp_id ) );
1034
+        }
1035
+    } else {
1036 1036
         $success = false;
1037 1037
         $message = __( 'No invoices found to fix taxes!', 'invoicing' );
1038 1038
     }
1039 1039
 	
1040
-	$response = array();
1040
+    $response = array();
1041 1041
     $response['success'] = $success;
1042 1042
     $response['data']['message'] = $message;
1043 1043
     wp_send_json( $response );
Please login to merge, or discard this patch.
Spacing   +339 added lines, -339 removed lines patch added patch discarded remove patch
@@ -1,23 +1,23 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 function wpinv_gd_active() {
8
-    return (bool)defined( 'GEODIRECTORY_VERSION' );
8
+    return (bool)defined('GEODIRECTORY_VERSION');
9 9
 }
10 10
 
11 11
 function wpinv_pm_active() {
12
-    return (bool)wpinv_gd_active() && (bool)defined( 'GEODIRPAYMENT_VERSION' );
12
+    return (bool)wpinv_gd_active() && (bool)defined('GEODIRPAYMENT_VERSION');
13 13
 }
14 14
 
15
-function wpinv_is_gd_post_type( $post_type ) {
15
+function wpinv_is_gd_post_type($post_type) {
16 16
     global $gd_posttypes;
17 17
     
18
-    $gd_posttypes = !empty( $gd_posttypes ) && is_array( $gd_posttypes ) ? $gd_posttypes : geodir_get_posttypes();
18
+    $gd_posttypes = !empty($gd_posttypes) && is_array($gd_posttypes) ? $gd_posttypes : geodir_get_posttypes();
19 19
     
20
-    if ( !empty( $post_type ) && !empty( $gd_posttypes ) && in_array( $post_type, $gd_posttypes ) ) {
20
+    if (!empty($post_type) && !empty($gd_posttypes) && in_array($post_type, $gd_posttypes)) {
21 21
         return true;
22 22
     }
23 23
     
@@ -29,10 +29,10 @@  discard block
 block discarded – undo
29 29
         return;
30 30
     }
31 31
     
32
-    if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
32
+    if (!(defined('DOING_AJAX') && DOING_AJAX)) {
33 33
         // Add  fields for force upgrade
34
-        if ( defined('INVOICE_TABLE') && !get_option('wpinv_gdp_column') ) {
35
-            geodir_add_column_if_not_exist( INVOICE_TABLE, 'invoice_id', 'INT( 11 ) NOT NULL DEFAULT 0' );
34
+        if (defined('INVOICE_TABLE') && !get_option('wpinv_gdp_column')) {
35
+            geodir_add_column_if_not_exist(INVOICE_TABLE, 'invoice_id', 'INT( 11 ) NOT NULL DEFAULT 0');
36 36
             
37 37
             update_option('wpinv_gdp_column', '1');
38 38
         }
@@ -40,39 +40,39 @@  discard block
 block discarded – undo
40 40
         wpinv_merge_gd_packages_to_items();
41 41
     }
42 42
 }
43
-add_action( 'admin_init', 'wpinv_geodir_integration' );
43
+add_action('admin_init', 'wpinv_geodir_integration');
44 44
 
45
-function wpinv_get_gdp_package_type( $item_types ) {
46
-    if ( wpinv_pm_active() ) {
47
-        $item_types['package'] = __( 'Package', 'invoicing' );
45
+function wpinv_get_gdp_package_type($item_types) {
46
+    if (wpinv_pm_active()) {
47
+        $item_types['package'] = __('Package', 'invoicing');
48 48
     }
49 49
         
50 50
     return $item_types;
51 51
 }
52
-add_filter( 'wpinv_get_item_types', 'wpinv_get_gdp_package_type', 10, 1 );
52
+add_filter('wpinv_get_item_types', 'wpinv_get_gdp_package_type', 10, 1);
53 53
 
54 54
 function wpinv_update_package_item($package_id) {
55 55
     return wpinv_merge_gd_package_to_item($package_id, true);
56 56
 }
57 57
 add_action('geodir_after_save_package', 'wpinv_update_package_item', 10, 1);
58 58
 
59
-function wpinv_merge_gd_packages_to_items( $force = false ) {    
60
-    if ( $merged = get_option( 'wpinv_merge_gd_packages' ) && !$force ) {
59
+function wpinv_merge_gd_packages_to_items($force = false) {    
60
+    if ($merged = get_option('wpinv_merge_gd_packages') && !$force) {
61 61
         return true;
62 62
     }
63 63
 
64
-    if(!function_exists('geodir_package_list_info')){
64
+    if (!function_exists('geodir_package_list_info')) {
65 65
         return false;
66 66
     }
67 67
     
68 68
     $packages = geodir_package_list_info();
69 69
     
70
-    foreach ( $packages as $key => $package ) {
71
-        wpinv_merge_gd_package_to_item( $package->pid, $force, $package );
70
+    foreach ($packages as $key => $package) {
71
+        wpinv_merge_gd_package_to_item($package->pid, $force, $package);
72 72
     }
73 73
     
74
-    if ( !$merged ) {
75
-        update_option( 'wpinv_merge_gd_packages', 1 );
74
+    if (!$merged) {
75
+        update_option('wpinv_merge_gd_packages', 1);
76 76
     }
77 77
     
78 78
     return true;
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 
102 102
     $package = empty($package) ? geodir_get_package_info_by_id($package_id, '') : $package;
103 103
 
104
-    if ( empty($package) || !wpinv_is_gd_post_type( $package->post_type ) ) {
104
+    if (empty($package) || !wpinv_is_gd_post_type($package->post_type)) {
105 105
         return false;
106 106
     }
107 107
         
@@ -111,17 +111,17 @@  discard block
 block discarded – undo
111 111
     $meta['post_type']          = $package->post_type;
112 112
     $meta['cpt_singular_name']  = get_post_type_singular_label($package->post_type);
113 113
     $meta['cpt_name']           = get_post_type_plural_label($package->post_type);
114
-    $meta['price']              = wpinv_format_amount( $package->amount, NULL, true );
114
+    $meta['price']              = wpinv_format_amount($package->amount, NULL, true);
115 115
     $meta['vat_rule']           = 'digital';
116 116
     $meta['vat_class']          = '_standard';
117 117
     
118
-    if ( !empty( $package->sub_active ) ) {
119
-        $sub_num_trial_days = absint( $package->sub_num_trial_days );
118
+    if (!empty($package->sub_active)) {
119
+        $sub_num_trial_days = absint($package->sub_num_trial_days);
120 120
         
121 121
         $meta['is_recurring']       = 1;
122 122
         $meta['recurring_period']   = $package->sub_units;
123
-        $meta['recurring_interval'] = absint( $package->sub_units_num );
124
-        $meta['recurring_limit']    = absint( $package->sub_units_num_times );
123
+        $meta['recurring_interval'] = absint($package->sub_units_num);
124
+        $meta['recurring_limit']    = absint($package->sub_units_num_times);
125 125
         $meta['free_trial']         = $sub_num_trial_days > 0 ? 1 : 0;
126 126
         $meta['trial_period']       = $package->sub_num_trial_units;
127 127
         $meta['trial_interval']     = $sub_num_trial_days;
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
         $meta['trial_interval']     = '';
136 136
     }
137 137
     
138
-    $data  = array( 
138
+    $data = array( 
139 139
         'post_title'    => $package->title,
140 140
         'post_excerpt'  => $package->title_desc,
141 141
         'post_status'   => $package->status == 1 ? 'publish' : 'pending',
@@ -152,48 +152,48 @@  discard block
 block discarded – undo
152 152
     return $item;
153 153
 }
154 154
 
155
-function wpinv_gdp_to_wpi_gateway( $payment_method ) {
156
-    switch( $payment_method ) {
155
+function wpinv_gdp_to_wpi_gateway($payment_method) {
156
+    switch ($payment_method) {
157 157
         case 'prebanktransfer':
158 158
             $gateway = 'bank_transfer';
159 159
         break;
160 160
         default:
161
-            $gateway = empty( $payment_method ) ? 'manual' : $payment_method;
161
+            $gateway = empty($payment_method) ? 'manual' : $payment_method;
162 162
         break;
163 163
     }
164 164
     
165
-    return apply_filters( 'wpinv_gdp_to_wpi_gateway', $gateway, $payment_method );
165
+    return apply_filters('wpinv_gdp_to_wpi_gateway', $gateway, $payment_method);
166 166
 }
167 167
 
168
-function wpinv_gdp_to_wpi_gateway_title( $payment_method ) {
169
-    $gateway = wpinv_gdp_to_wpi_gateway( $payment_method );
168
+function wpinv_gdp_to_wpi_gateway_title($payment_method) {
169
+    $gateway = wpinv_gdp_to_wpi_gateway($payment_method);
170 170
     
171
-    $gateway_title = wpinv_get_gateway_checkout_label( $gateway );
171
+    $gateway_title = wpinv_get_gateway_checkout_label($gateway);
172 172
     
173
-    if ( $gateway == $gateway_title ) {
174
-        $gateway_title = geodir_payment_method_title( $gateway );
173
+    if ($gateway == $gateway_title) {
174
+        $gateway_title = geodir_payment_method_title($gateway);
175 175
     }
176 176
     
177
-    return apply_filters( 'wpinv_gdp_to_wpi_gateway_title', $gateway_title, $payment_method );
177
+    return apply_filters('wpinv_gdp_to_wpi_gateway_title', $gateway_title, $payment_method);
178 178
 }
179 179
 
180 180
 function wpinv_print_checkout_errors() {
181 181
     global $wpi_session;
182 182
     wpinv_print_errors();
183 183
 }
184
-add_action( 'geodir_checkout_page_content', 'wpinv_print_checkout_errors', -10 );
184
+add_action('geodir_checkout_page_content', 'wpinv_print_checkout_errors', -10);
185 185
 
186
-function wpinv_cpt_save( $invoice_id, $update = false, $pre_status = NULL ) {
186
+function wpinv_cpt_save($invoice_id, $update = false, $pre_status = NULL) {
187 187
     global $wpi_nosave, $wpi_zero_tax, $wpi_gdp_inv_merge;
188 188
     
189
-    $invoice_info = geodir_get_invoice( $invoice_id );
189
+    $invoice_info = geodir_get_invoice($invoice_id);
190 190
     
191
-    $wpi_invoice_id  = !empty( $invoice_info->invoice_id ) ? $invoice_info->invoice_id : 0;
191
+    $wpi_invoice_id  = !empty($invoice_info->invoice_id) ? $invoice_info->invoice_id : 0;
192 192
     
193 193
     if (!empty($invoice_info)) {
194
-        $wpi_invoice = $wpi_invoice_id > 0 ? wpinv_get_invoice( $wpi_invoice_id ) : NULL;
194
+        $wpi_invoice = $wpi_invoice_id > 0 ? wpinv_get_invoice($wpi_invoice_id) : NULL;
195 195
         
196
-        if ( !empty( $wpi_invoice ) ) { // update invoice
196
+        if (!empty($wpi_invoice)) { // update invoice
197 197
             $save = false;
198 198
             if ($invoice_info->coupon_code !== $wpi_invoice->discount_code || (float)$invoice_info->discount < (float)$wpi_invoice->discount || (float)$invoice_info->discount > (float)$wpi_invoice->discount) {
199 199
                 $save = true;
@@ -203,16 +203,16 @@  discard block
 block discarded – undo
203 203
             
204 204
             if ($invoice_info->paymentmethod !== $wpi_invoice->gateway) {
205 205
                 $save = true;
206
-                $gateway = !empty( $invoice_info->paymentmethod ) ? $invoice_info->paymentmethod : '';
207
-                $gateway = wpinv_gdp_to_wpi_gateway( $gateway );
208
-                $gateway_title = wpinv_gdp_to_wpi_gateway_title( $gateway );
209
-                $wpi_invoice->set('gateway', $gateway );
210
-                $wpi_invoice->set('gateway_title', $gateway_title );
206
+                $gateway = !empty($invoice_info->paymentmethod) ? $invoice_info->paymentmethod : '';
207
+                $gateway = wpinv_gdp_to_wpi_gateway($gateway);
208
+                $gateway_title = wpinv_gdp_to_wpi_gateway_title($gateway);
209
+                $wpi_invoice->set('gateway', $gateway);
210
+                $wpi_invoice->set('gateway_title', $gateway_title);
211 211
             }
212 212
             
213
-            if ( ( $status = wpinv_gdp_to_wpi_status( $invoice_info->status ) ) !== $wpi_invoice->status ) {
213
+            if (($status = wpinv_gdp_to_wpi_status($invoice_info->status)) !== $wpi_invoice->status) {
214 214
                 $save = true;
215
-                $wpi_invoice->set( 'status', $status );
215
+                $wpi_invoice->set('status', $status);
216 216
             }
217 217
             
218 218
             if ($save) {
@@ -223,37 +223,37 @@  discard block
 block discarded – undo
223 223
             
224 224
             return $wpi_invoice;
225 225
         } else { // create invoice
226
-            $user_info = get_userdata( $invoice_info->user_id );
226
+            $user_info = get_userdata($invoice_info->user_id);
227 227
             
228
-            if ( !empty( $pre_status ) ) {
228
+            if (!empty($pre_status)) {
229 229
                 $invoice_info->status = $pre_status;
230 230
             }
231
-            $status = wpinv_gdp_to_wpi_status( $invoice_info->status );
231
+            $status = wpinv_gdp_to_wpi_status($invoice_info->status);
232 232
             
233 233
             $wpi_zero_tax = false;
234 234
             
235
-            if ( $wpi_gdp_inv_merge && in_array( $status, array( 'publish', 'complete', 'processing', 'renewal' ) ) ) {
235
+            if ($wpi_gdp_inv_merge && in_array($status, array('publish', 'complete', 'processing', 'renewal'))) {
236 236
                 $wpi_zero_tax = true;
237 237
             }
238 238
             
239 239
             $invoice_data                   = array();
240 240
             $invoice_data['invoice_id']     = $wpi_invoice_id;
241 241
             $invoice_data['status']         = $status;
242
-            if ( $update ) {
242
+            if ($update) {
243 243
                 //$invoice_data['private_note']   = __( 'Invoice was updated.', 'invoicing' );
244 244
             } else {
245
-                $invoice_data['private_note']   = wp_sprintf( __( 'Invoice was created with status %s.', 'invoicing' ), wpinv_status_nicename( $status ) );
245
+                $invoice_data['private_note'] = wp_sprintf(__('Invoice was created with status %s.', 'invoicing'), wpinv_status_nicename($status));
246 246
             }
247 247
             $invoice_data['user_id']        = $invoice_info->user_id;
248 248
             $invoice_data['created_via']    = 'API';
249 249
             
250
-            if ( !empty( $invoice_info->date ) ) {
251
-                $invoice_data['created_date']   = $invoice_info->date;
250
+            if (!empty($invoice_info->date)) {
251
+                $invoice_data['created_date'] = $invoice_info->date;
252 252
             }
253 253
             
254
-            $paymentmethod = !empty( $invoice_info->paymentmethod ) ? $invoice_info->paymentmethod : '';
255
-            $paymentmethod = wpinv_gdp_to_wpi_gateway( $paymentmethod );
256
-            $payment_method_title = wpinv_gdp_to_wpi_gateway_title( $paymentmethod );
254
+            $paymentmethod = !empty($invoice_info->paymentmethod) ? $invoice_info->paymentmethod : '';
255
+            $paymentmethod = wpinv_gdp_to_wpi_gateway($paymentmethod);
256
+            $payment_method_title = wpinv_gdp_to_wpi_gateway_title($paymentmethod);
257 257
             
258 258
             $invoice_data['payment_details'] = array( 
259 259
                 'gateway'           => $paymentmethod, 
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
                 'paid'              => $status === 'publish' ? true : false
263 263
             );
264 264
             
265
-            $user_address = wpinv_get_user_address( $invoice_info->user_id, false );
265
+            $user_address = wpinv_get_user_address($invoice_info->user_id, false);
266 266
             
267 267
             $invoice_data['user_info'] = array( 
268 268
                 'user_id'       => $invoice_info->user_id, 
@@ -285,8 +285,8 @@  discard block
 block discarded – undo
285 285
             
286 286
             $post_item = wpinv_get_gd_package_item($invoice_info->package_id);
287 287
             
288
-            if ( !empty( $post_item ) ) {
289
-                $cart_details  = array();
288
+            if (!empty($post_item)) {
289
+                $cart_details = array();
290 290
                 $cart_details[] = array(
291 291
                     'id'                => $post_item->ID,
292 292
                     'name'              => $post_item->get_name(),
@@ -299,19 +299,19 @@  discard block
 block discarded – undo
299 299
                                         ),
300 300
                 );
301 301
                 
302
-                $invoice_data['cart_details']  = $cart_details;
302
+                $invoice_data['cart_details'] = $cart_details;
303 303
             }
304 304
 
305
-            $data = array( 'invoice' => $invoice_data );
305
+            $data = array('invoice' => $invoice_data);
306 306
 
307 307
             $wpinv_api = new WPInv_API();
308
-            $data = $wpinv_api->insert_invoice( $data );
308
+            $data = $wpinv_api->insert_invoice($data);
309 309
             
310
-            if ( is_wp_error( $data ) ) {
311
-                wpinv_error_log( 'WPInv_Invoice: ' . $data->get_error_message() );
310
+            if (is_wp_error($data)) {
311
+                wpinv_error_log('WPInv_Invoice: ' . $data->get_error_message());
312 312
             } else {
313
-                if ( !empty( $data ) ) {
314
-                    update_post_meta( $data->ID, '_wpinv_gdp_id', $invoice_id );
313
+                if (!empty($data)) {
314
+                    update_post_meta($data->ID, '_wpinv_gdp_id', $invoice_id);
315 315
 
316 316
                     global $wpi_userID, $wpinv_ip_address_country;
317 317
                     
@@ -319,21 +319,21 @@  discard block
 block discarded – undo
319 319
                     
320 320
                     $data_session                   = array();
321 321
                     $data_session['invoice_id']     = $data->ID;
322
-                    $data_session['cart_discounts'] = $data->get_discounts( true );
322
+                    $data_session['cart_discounts'] = $data->get_discounts(true);
323 323
                     
324
-                    wpinv_set_checkout_session( $data_session );
324
+                    wpinv_set_checkout_session($data_session);
325 325
                     
326 326
                     $wpi_userID         = (int)$data->get_user_id();
327 327
                     $_POST['country']   = !empty($data->country) ? $data->country : wpinv_get_default_country();
328 328
                         
329
-                    $data->country      = sanitize_text_field( $_POST['country'] );
330
-                    $data->set( 'country', sanitize_text_field( $_POST['country'] ) );
329
+                    $data->country      = sanitize_text_field($_POST['country']);
330
+                    $data->set('country', sanitize_text_field($_POST['country']));
331 331
                     
332 332
                     $wpinv_ip_address_country = $data->country;
333 333
                     
334 334
                     $data = $data->recalculate_totals(true);
335 335
                     
336
-                    wpinv_set_checkout_session( $checkout_session );
336
+                    wpinv_set_checkout_session($checkout_session);
337 337
                     
338 338
                     $update_data = array();
339 339
                     $update_data['tax_amount'] = $data->get_tax();
@@ -341,14 +341,14 @@  discard block
 block discarded – undo
341 341
                     $update_data['invoice_id'] = $data->ID;
342 342
                     
343 343
                     global $wpdb;
344
-                    $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $invoice_id ) );
344
+                    $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $invoice_id));
345 345
                     
346 346
                     return $data;
347 347
                 } else {
348
-                    if ( $update ) {
349
-                        wpinv_error_log( 'WPInv_Invoice: ' . __( 'Fail to update invoice.', 'invoicing' ) );
348
+                    if ($update) {
349
+                        wpinv_error_log('WPInv_Invoice: ' . __('Fail to update invoice.', 'invoicing'));
350 350
                     } else {
351
-                        wpinv_error_log( 'WPInv_Invoice: ' . __( 'Fail to create invoice.', 'invoicing' ) );
351
+                        wpinv_error_log('WPInv_Invoice: ' . __('Fail to create invoice.', 'invoicing'));
352 352
                     }
353 353
                 }
354 354
             }
@@ -359,59 +359,59 @@  discard block
 block discarded – undo
359 359
 }
360 360
 add_action('geodir_payment_invoice_created', 'wpinv_cpt_save', 11, 3);
361 361
 
362
-function wpinv_cpt_update( $invoice_id ) {
363
-    return wpinv_cpt_save( $invoice_id, true );
362
+function wpinv_cpt_update($invoice_id) {
363
+    return wpinv_cpt_save($invoice_id, true);
364 364
 }
365 365
 add_action('geodir_payment_invoice_updated', 'wpinv_cpt_update', 11, 1);
366 366
 
367
-function wpinv_payment_status_changed( $invoice_id, $new_status, $old_status = 'pending', $subscription = false ) {
368
-    $invoice_info = geodir_get_invoice( $invoice_id );
369
-    if ( empty( $invoice_info ) ) {
367
+function wpinv_payment_status_changed($invoice_id, $new_status, $old_status = 'pending', $subscription = false) {
368
+    $invoice_info = geodir_get_invoice($invoice_id);
369
+    if (empty($invoice_info)) {
370 370
         return false;
371 371
     }
372 372
 
373
-    $invoice = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL;
374
-    if ( !empty( $invoice ) ) {
373
+    $invoice = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL;
374
+    if (!empty($invoice)) {
375 375
         $new_status = wpinv_gdp_to_wpi_status($new_status);
376
-        $invoice    = wpinv_update_payment_status( $invoice->ID, $new_status );
376
+        $invoice    = wpinv_update_payment_status($invoice->ID, $new_status);
377 377
     } else {
378
-        $invoice = wpinv_cpt_save( $invoice_id );
378
+        $invoice = wpinv_cpt_save($invoice_id);
379 379
     }
380 380
     
381 381
     return $invoice;
382 382
 }
383
-add_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 );
383
+add_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4);
384 384
 
385
-function wpinv_transaction_details_note( $invoice_id, $html ) {
386
-    $invoice_info = geodir_get_invoice( $invoice_id );
387
-    if ( empty( $invoice_info ) ) {
385
+function wpinv_transaction_details_note($invoice_id, $html) {
386
+    $invoice_info = geodir_get_invoice($invoice_id);
387
+    if (empty($invoice_info)) {
388 388
         return false;
389 389
     }
390 390
 
391
-    $wpi_invoice_id = !empty( $invoice_info->invoice_id ) ? $invoice_info->invoice_id : NULL;
391
+    $wpi_invoice_id = !empty($invoice_info->invoice_id) ? $invoice_info->invoice_id : NULL;
392 392
     
393
-    if ( !$wpi_invoice_id ) {
394
-        $invoice = wpinv_cpt_save( $invoice_id, false, $old_status );
393
+    if (!$wpi_invoice_id) {
394
+        $invoice = wpinv_cpt_save($invoice_id, false, $old_status);
395 395
         
396
-        if ( !empty( $invoice ) ) {
396
+        if (!empty($invoice)) {
397 397
             $wpi_invoice_id = $invoice->ID;
398 398
         }
399 399
     }
400 400
 
401
-    $invoice = wpinv_get_invoice( $wpi_invoice_id );
401
+    $invoice = wpinv_get_invoice($wpi_invoice_id);
402 402
     
403
-    if ( empty( $invoice ) ) {
403
+    if (empty($invoice)) {
404 404
         return false;
405 405
     }
406 406
     
407
-    return $invoice->add_note( $html, true );
407
+    return $invoice->add_note($html, true);
408 408
 }
409
-add_action( 'geodir_payment_invoice_transaction_details_changed', 'wpinv_transaction_details_note', 11, 2 );
409
+add_action('geodir_payment_invoice_transaction_details_changed', 'wpinv_transaction_details_note', 11, 2);
410 410
 
411
-function wpinv_gdp_to_wpi_status( $status ) {
411
+function wpinv_gdp_to_wpi_status($status) {
412 412
     $inv_status = $status ? $status : 'pending';
413 413
     
414
-    switch ( $status ) {
414
+    switch ($status) {
415 415
         case 'confirmed':
416 416
             $inv_status = 'publish';
417 417
         break;
@@ -420,10 +420,10 @@  discard block
 block discarded – undo
420 420
     return $inv_status;
421 421
 }
422 422
 
423
-function wpinv_wpi_to_gdp_status( $status ) {
423
+function wpinv_wpi_to_gdp_status($status) {
424 424
     $inv_status = $status ? $status : 'pending';
425 425
     
426
-    switch ( $status ) {
426
+    switch ($status) {
427 427
         case 'publish':
428 428
         case 'complete':
429 429
         case 'processing':
@@ -435,98 +435,98 @@  discard block
 block discarded – undo
435 435
     return $inv_status;
436 436
 }
437 437
 
438
-function wpinv_wpi_to_gdp_id( $invoice_id ) {
438
+function wpinv_wpi_to_gdp_id($invoice_id) {
439 439
     global $wpdb;
440 440
     
441
-    return $wpdb->get_var( $wpdb->prepare( "SELECT `id` FROM `" . INVOICE_TABLE . "` WHERE `invoice_id` = %d AND `invoice_id` > 0 ORDER BY id DESC LIMIT 1", array( (int)$invoice_id ) ) );
441
+    return $wpdb->get_var($wpdb->prepare("SELECT `id` FROM `" . INVOICE_TABLE . "` WHERE `invoice_id` = %d AND `invoice_id` > 0 ORDER BY id DESC LIMIT 1", array((int)$invoice_id)));
442 442
 }
443 443
 
444
-function wpinv_gdp_to_wpi_id( $invoice_id ) {
445
-    $invoice = geodir_get_invoice( $invoice_id );    
446
-    return ( empty( $invoice->invoice_id ) ? $invoice->invoice_id : false);
444
+function wpinv_gdp_to_wpi_id($invoice_id) {
445
+    $invoice = geodir_get_invoice($invoice_id);    
446
+    return (empty($invoice->invoice_id) ? $invoice->invoice_id : false);
447 447
 }
448 448
 
449
-function wpinv_to_gdp_recalculate_total( $invoice, $wpi_nosave ) {
449
+function wpinv_to_gdp_recalculate_total($invoice, $wpi_nosave) {
450 450
     global $wpdb;
451 451
     
452
-    if ( !empty( $wpi_nosave ) ) {
452
+    if (!empty($wpi_nosave)) {
453 453
         return;
454 454
     }
455 455
     
456
-    $gdp_invoice_id = wpinv_wpi_to_gdp_id( $invoice->ID );
456
+    $gdp_invoice_id = wpinv_wpi_to_gdp_id($invoice->ID);
457 457
     
458
-    if ( $gdp_invoice_id > 0 ) {
458
+    if ($gdp_invoice_id > 0) {
459 459
         $update_data = array();
460 460
         $update_data['tax_amount']      = $invoice->tax;
461 461
         $update_data['paied_amount']    = $invoice->total;
462 462
         $update_data['discount']        = $invoice->discount;
463 463
         $update_data['coupon_code']     = $invoice->discount_code;
464 464
         
465
-        $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $gdp_invoice_id ) );
465
+        $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $gdp_invoice_id));
466 466
     }
467 467
     
468 468
     return;
469 469
 }
470 470
 //add_action( 'wpinv_invoice_recalculate_total', 'wpinv_to_gdp_recalculate_total', 10, 2 );
471 471
 
472
-function wpinv_gdp_to_wpi_invoice( $invoice_id ) {
473
-    $invoice = geodir_get_invoice( $invoice_id );
474
-    if ( empty( $invoice->invoice_id ) ) {
472
+function wpinv_gdp_to_wpi_invoice($invoice_id) {
473
+    $invoice = geodir_get_invoice($invoice_id);
474
+    if (empty($invoice->invoice_id)) {
475 475
         return false;
476 476
     }
477 477
     
478
-    return wpinv_get_invoice( $invoice->invoice_id );
478
+    return wpinv_get_invoice($invoice->invoice_id);
479 479
 }
480 480
 
481
-function wpinv_payment_set_coupon_code( $status, $invoice_id, $coupon_code ) {
482
-    $invoice = wpinv_gdp_to_wpi_invoice( $invoice_id );
483
-    if ( empty( $invoice ) ) {
481
+function wpinv_payment_set_coupon_code($status, $invoice_id, $coupon_code) {
482
+    $invoice = wpinv_gdp_to_wpi_invoice($invoice_id);
483
+    if (empty($invoice)) {
484 484
         return $status;
485 485
     }
486 486
 
487
-    if ( $status === 1 || $status === 0 ) {
488
-        if ( $status === 1 ) {
489
-            $discount = geodir_get_discount_amount( $coupon_code, $invoice->get_subtotal() );
487
+    if ($status === 1 || $status === 0) {
488
+        if ($status === 1) {
489
+            $discount = geodir_get_discount_amount($coupon_code, $invoice->get_subtotal());
490 490
         } else {
491 491
             $discount = '';
492 492
             $coupon_code = '';
493 493
         }
494 494
         
495
-        $invoice->set( 'discount', $discount );
496
-        $invoice->set( 'discount_code', $coupon_code );
495
+        $invoice->set('discount', $discount);
496
+        $invoice->set('discount_code', $coupon_code);
497 497
         $invoice->save();
498 498
         $invoice->recalculate_total();
499 499
     }
500 500
     
501 501
     return $status;
502 502
 }
503
-add_filter( 'geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3 );
503
+add_filter('geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3);
504 504
 
505
-function wpinv_insert_invoice( $invoice_data = array() ) {
506
-    if ( empty( $invoice_data ) ) {
505
+function wpinv_insert_invoice($invoice_data = array()) {
506
+    if (empty($invoice_data)) {
507 507
         return false;
508 508
     }
509 509
 
510 510
     // default invoice args, note that status is checked for validity in wpinv_create_invoice()
511 511
     $default_args = array(
512
-        'status'        => !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'pending',
513
-        'user_note'     => !empty( $invoice_data['note'] ) ? $invoice_data['note'] : null,
514
-        'invoice_id'    => !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0,
515
-        'user_id'       => !empty( $invoice_data['user_id'] ) ? (int)$invoice_data['user_id'] : get_current_user_id(),
512
+        'status'        => !empty($invoice_data['status']) ? $invoice_data['status'] : 'pending',
513
+        'user_note'     => !empty($invoice_data['note']) ? $invoice_data['note'] : null,
514
+        'invoice_id'    => !empty($invoice_data['invoice_id']) ? (int)$invoice_data['invoice_id'] : 0,
515
+        'user_id'       => !empty($invoice_data['user_id']) ? (int)$invoice_data['user_id'] : get_current_user_id(),
516 516
     );
517 517
 
518
-    $invoice = wpinv_create_invoice( $default_args, $invoice_data );
519
-    if ( is_wp_error( $invoice ) ) {
518
+    $invoice = wpinv_create_invoice($default_args, $invoice_data);
519
+    if (is_wp_error($invoice)) {
520 520
         return $invoice;
521 521
     }
522 522
 
523
-    $gateway = !empty( $invoice_data['gateway'] ) ? $invoice_data['gateway'] : '';
524
-    $gateway = empty( $gateway ) && isset( $_POST['gateway'] ) ? $_POST['gateway'] : $gateway;
523
+    $gateway = !empty($invoice_data['gateway']) ? $invoice_data['gateway'] : '';
524
+    $gateway = empty($gateway) && isset($_POST['gateway']) ? $_POST['gateway'] : $gateway;
525 525
     
526
-    if ( !empty( $gateway ) ) {
527
-        $gateway = wpinv_gdp_to_wpi_gateway( $gateway );
526
+    if (!empty($gateway)) {
527
+        $gateway = wpinv_gdp_to_wpi_gateway($gateway);
528 528
         $invoice_data['payment_details']['gateway'] = $gateway;
529
-        $invoice_data['payment_details']['gateway_title'] = wpinv_gdp_to_wpi_gateway_title( $gateway );
529
+        $invoice_data['payment_details']['gateway_title'] = wpinv_gdp_to_wpi_gateway_title($gateway);
530 530
     }
531 531
     
532 532
     $user_info = array(
@@ -547,67 +547,67 @@  discard block
 block discarded – undo
547 547
         'discount'       => array(),
548 548
     );
549 549
     
550
-    $user_info    = wp_parse_args( $invoice_data['user_info'], $user_info );
550
+    $user_info = wp_parse_args($invoice_data['user_info'], $user_info);
551 551
     
552 552
     $payment_details = array();
553
-    if ( !empty( $invoice_data['payment_details'] ) ) {
553
+    if (!empty($invoice_data['payment_details'])) {
554 554
         $payment_details = array(
555 555
             'gateway'           => 'manual',
556
-            'gateway_title'     => __( 'Manual Payment', 'invoicing' ),
556
+            'gateway_title'     => __('Manual Payment', 'invoicing'),
557 557
             'currency'          => geodir_get_currency_type(),
558 558
             'paid'              => false,
559 559
             'transaction_id'    => '',
560 560
         );
561
-        $payment_details = wp_parse_args( $invoice_data['payment_details'], $payment_details );
561
+        $payment_details = wp_parse_args($invoice_data['payment_details'], $payment_details);
562 562
     }
563
-    $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'pending' ) );
564
-    if ( !empty( $payment_details ) ) {
565
-        $invoice->set( 'currency', $payment_details['currency'] );
566
-        $invoice->set( 'gateway', $payment_details['gateway'] );
567
-        $invoice->set( 'gateway_title', $payment_details['gateway_title'] );
568
-        $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
563
+    $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'pending'));
564
+    if (!empty($payment_details)) {
565
+        $invoice->set('currency', $payment_details['currency']);
566
+        $invoice->set('gateway', $payment_details['gateway']);
567
+        $invoice->set('gateway_title', $payment_details['gateway_title']);
568
+        $invoice->set('transaction_id', $payment_details['transaction_id']);
569 569
     }
570 570
 
571
-    $invoice->set( 'user_info', $user_info );
571
+    $invoice->set('user_info', $user_info);
572 572
     ///$invoice->set( 'user_id', $user_info['user_id'] );
573 573
     ///$invoice->set( 'email', $user_info['email'] );
574
-    $invoice->set( 'first_name', $user_info['first_name'] );
575
-    $invoice->set( 'last_name', $user_info['last_name'] );
576
-    $invoice->set( 'address', $user_info['address'] );
577
-    $invoice->set( 'company', $user_info['company'] );
578
-    $invoice->set( 'vat_number', $user_info['vat_number'] );
579
-    $invoice->set( 'phone', $user_info['phone'] );
580
-    $invoice->set( 'city', $user_info['city'] );
581
-    $invoice->set( 'country', $user_info['country'] );
582
-    $invoice->set( 'state', $user_info['state'] );
583
-    $invoice->set( 'zip', $user_info['zip'] );
584
-    $invoice->set( 'discounts', ( !empty( $user_info['discount'] ) ? $user_info['discount'] : array() ) );
585
-    $invoice->set( 'ip', wpinv_get_ip() );
586
-    if ( !empty( $invoice_data['invoice_key'] ) ) {
587
-        $invoice->set( 'key', $invoice_data['invoice_key'] );
574
+    $invoice->set('first_name', $user_info['first_name']);
575
+    $invoice->set('last_name', $user_info['last_name']);
576
+    $invoice->set('address', $user_info['address']);
577
+    $invoice->set('company', $user_info['company']);
578
+    $invoice->set('vat_number', $user_info['vat_number']);
579
+    $invoice->set('phone', $user_info['phone']);
580
+    $invoice->set('city', $user_info['city']);
581
+    $invoice->set('country', $user_info['country']);
582
+    $invoice->set('state', $user_info['state']);
583
+    $invoice->set('zip', $user_info['zip']);
584
+    $invoice->set('discounts', (!empty($user_info['discount']) ? $user_info['discount'] : array()));
585
+    $invoice->set('ip', wpinv_get_ip());
586
+    if (!empty($invoice_data['invoice_key'])) {
587
+        $invoice->set('key', $invoice_data['invoice_key']);
588 588
     }
589
-    $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) );
590
-    $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) );
589
+    $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live'));
590
+    $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : ''));
591 591
     
592 592
     // Add note
593
-    if ( !empty( $invoice_data['user_note'] ) ) {
594
-        $invoice->add_note( $invoice_data['user_note'], true );
593
+    if (!empty($invoice_data['user_note'])) {
594
+        $invoice->add_note($invoice_data['user_note'], true);
595 595
     }
596 596
     
597
-    if ( !empty( $invoice_data['private_note'] ) ) {
598
-        $invoice->add_note( $invoice_data['private_note'] );
597
+    if (!empty($invoice_data['private_note'])) {
598
+        $invoice->add_note($invoice_data['private_note']);
599 599
     }
600 600
     
601
-    if ( is_array( $invoice_data['cart_details'] ) && !empty( $invoice_data['cart_details'] ) ) {
602
-        foreach ( $invoice_data['cart_details'] as $key => $item ) {
603
-            $item_id    = !empty( $item['id'] ) ? $item['id'] : 0;
604
-            $quantity   = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
605
-            $name       = !empty( $item['name'] ) ? $item['name'] : '';
606
-            $item_price = isset( $item['item_price'] ) ? $item['item_price'] : '';
601
+    if (is_array($invoice_data['cart_details']) && !empty($invoice_data['cart_details'])) {
602
+        foreach ($invoice_data['cart_details'] as $key => $item) {
603
+            $item_id    = !empty($item['id']) ? $item['id'] : 0;
604
+            $quantity   = !empty($item['quantity']) ? $item['quantity'] : 1;
605
+            $name       = !empty($item['name']) ? $item['name'] : '';
606
+            $item_price = isset($item['item_price']) ? $item['item_price'] : '';
607 607
             
608
-            $post_item  = new WPInv_Item( $item_id );
609
-            if ( !empty( $post_item ) ) {
610
-                $name       = !empty( $name ) ? $name : $post_item->get_name();
608
+            $post_item  = new WPInv_Item($item_id);
609
+            if (!empty($post_item)) {
610
+                $name       = !empty($name) ? $name : $post_item->get_name();
611 611
                 $item_price = $item_price !== '' ? $item_price : $post_item->get_price();
612 612
             } else {
613 613
                 continue;
@@ -617,33 +617,33 @@  discard block
 block discarded – undo
617 617
                 'name'          => $name,
618 618
                 'quantity'      => $quantity,
619 619
                 'item_price'    => $item_price,
620
-                'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0.00,
621
-                'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
622
-                'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
623
-                'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
620
+                'tax'           => !empty($item['tax']) ? $item['tax'] : 0.00,
621
+                'discount'      => isset($item['discount']) ? $item['discount'] : 0,
622
+                'meta'          => isset($item['meta']) ? $item['meta'] : array(),
623
+                'fees'          => isset($item['fees']) ? $item['fees'] : array(),
624 624
             );
625 625
 
626
-            $invoice->add_item( $item_id, $args );
626
+            $invoice->add_item($item_id, $args);
627 627
         }
628 628
     }
629 629
 
630
-    $invoice->increase_tax( wpinv_get_cart_fee_tax() );
630
+    $invoice->increase_tax(wpinv_get_cart_fee_tax());
631 631
 
632
-    if ( isset( $invoice_data['post_date'] ) ) {
633
-        $invoice->set( 'date', $invoice_data['post_date'] );
632
+    if (isset($invoice_data['post_date'])) {
633
+        $invoice->set('date', $invoice_data['post_date']);
634 634
     }
635 635
 
636
-    $number = wpinv_format_invoice_number( $invoice->ID );
637
-    $invoice->set( 'number', $number );
638
-    update_option( 'wpinv_last_invoice_number', $number );
636
+    $number = wpinv_format_invoice_number($invoice->ID);
637
+    $invoice->set('number', $number);
638
+    update_option('wpinv_last_invoice_number', $number);
639 639
     
640 640
     $invoice->save();
641 641
     
642
-    do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data );
642
+    do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data);
643 643
 
644
-    if ( ! empty( $invoice->ID ) ) {
644
+    if (!empty($invoice->ID)) {
645 645
         // payment method (and payment_complete() if `paid` == true)
646
-        if ( !empty( $payment_details['paid'] ) ) {
646
+        if (!empty($payment_details['paid'])) {
647 647
             //$invoice->payment_complete( !empty( $payment_details['transaction_id'] ) ? $payment_details['transaction_id'] : $invoice->ID );
648 648
         }
649 649
             
@@ -660,158 +660,158 @@  discard block
 block discarded – undo
660 660
     }
661 661
     ?>
662 662
     <tr>
663
-        <td><?php _e( 'Merge Price Packages', 'invoicing' ); ?></td>
664
-        <td><p><?php _e( 'Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing' ); ?></p></td>
665
-        <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
663
+        <td><?php _e('Merge Price Packages', 'invoicing'); ?></td>
664
+        <td><p><?php _e('Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing'); ?></p></td>
665
+        <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
666 666
     </tr>
667 667
     <tr>
668
-        <td><?php _e( 'Merge Invoices', 'invoicing' ); ?></td>
669
-        <td><p><?php _e( 'Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing' ); ?></p></td>
670
-        <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
668
+        <td><?php _e('Merge Invoices', 'invoicing'); ?></td>
669
+        <td><p><?php _e('Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing'); ?></p></td>
670
+        <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
671 671
     </tr>
672 672
 	<tr>
673
-        <td><?php _e( 'Fix Taxes for Merged Invoices', 'invoicing' ); ?></td>
674
-        <td><p><?php _e( 'Fix taxes for NON-PAID invoices which are merged before, from GeoDirectory Payment Manager invoices to Invoicing. This will recalculate taxes for non-paid merged invoices.', 'invoicing' ); ?></p></td>
675
-        <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
673
+        <td><?php _e('Fix Taxes for Merged Invoices', 'invoicing'); ?></td>
674
+        <td><p><?php _e('Fix taxes for NON-PAID invoices which are merged before, from GeoDirectory Payment Manager invoices to Invoicing. This will recalculate taxes for non-paid merged invoices.', 'invoicing'); ?></p></td>
675
+        <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
676 676
     </tr>
677 677
     <tr>
678
-        <td><?php _e( 'Merge Coupons', 'invoicing' ); ?></td>
679
-        <td><p><?php _e( 'Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing' ); ?></p></td>
680
-        <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
678
+        <td><?php _e('Merge Coupons', 'invoicing'); ?></td>
679
+        <td><p><?php _e('Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing'); ?></p></td>
680
+        <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
681 681
     </tr>
682 682
     <?php
683 683
 }
684
-add_action( 'wpinv_tools_row', 'wpinv_merge_gd_invoices', 10 );
684
+add_action('wpinv_tools_row', 'wpinv_merge_gd_invoices', 10);
685 685
 
686 686
 function wpinv_tool_merge_packages() {
687 687
     $packages = geodir_package_list_info();
688 688
     
689 689
     $count = 0;
690 690
     
691
-    if ( !empty( $packages ) ) {
691
+    if (!empty($packages)) {
692 692
         $success = true;
693 693
         
694
-        foreach ( $packages as $key => $package ) {
694
+        foreach ($packages as $key => $package) {
695 695
             $item = wpinv_get_item_by('package_id', $package->pid);
696
-            if ( !empty( $item ) ) {
696
+            if (!empty($item)) {
697 697
                 continue;
698 698
             }
699 699
             
700
-            $merged = wpinv_merge_gd_package_to_item( $package->pid, false, $package );
700
+            $merged = wpinv_merge_gd_package_to_item($package->pid, false, $package);
701 701
             
702
-            if ( !empty( $merged ) ) {
703
-                wpinv_error_log( 'Package merge S : ' . $package->pid );
702
+            if (!empty($merged)) {
703
+                wpinv_error_log('Package merge S : ' . $package->pid);
704 704
                 $count++;
705 705
             } else {
706
-                wpinv_error_log( 'Package merge F : ' . $package->pid );
706
+                wpinv_error_log('Package merge F : ' . $package->pid);
707 707
             }
708 708
         }
709 709
         
710
-        if ( $count > 0 ) {
711
-            $message = sprintf( _n( 'Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing' ), $count );
710
+        if ($count > 0) {
711
+            $message = sprintf(_n('Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing'), $count);
712 712
         } else {
713
-            $message = __( 'No price packages merged.', 'invoicing' );
713
+            $message = __('No price packages merged.', 'invoicing');
714 714
         }
715 715
     } else {
716 716
         $success = false;
717
-        $message = __( 'No price packages found to merge!', 'invoicing' );
717
+        $message = __('No price packages found to merge!', 'invoicing');
718 718
     }
719 719
     
720 720
     $response = array();
721 721
     $response['success'] = $success;
722 722
     $response['data']['message'] = $message;
723
-    wp_send_json( $response );
723
+    wp_send_json($response);
724 724
 }
725
-add_action( 'wpinv_tool_merge_packages', 'wpinv_tool_merge_packages' );
725
+add_action('wpinv_tool_merge_packages', 'wpinv_tool_merge_packages');
726 726
 
727 727
 function wpinv_tool_merge_invoices() {
728 728
     global $wpdb, $wpi_gdp_inv_merge, $wpi_tax_rates;
729 729
     
730 730
     $sql = "SELECT `gdi`.`id`, `gdi`.`date`, `gdi`.`date_updated` FROM `" . INVOICE_TABLE . "` AS gdi LEFT JOIN `" . $wpdb->posts . "` AS p ON `p`.`ID` = `gdi`.`invoice_id` AND `p`.`post_type` = 'wpi_invoice' WHERE `p`.`ID` IS NULL ORDER BY `gdi`.`id` ASC";
731
-    $items = $wpdb->get_results( $sql );
731
+    $items = $wpdb->get_results($sql);
732 732
     
733 733
     $count = 0;
734 734
     
735
-    if ( !empty( $items ) ) {
735
+    if (!empty($items)) {
736 736
         $success = true;
737 737
         $wpi_gdp_inv_merge = true;
738 738
         
739
-        foreach ( $items as $item ) {
739
+        foreach ($items as $item) {
740 740
             $wpi_tax_rates = NULL;
741 741
             
742
-            $wpdb->query( "UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'" );
742
+            $wpdb->query("UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'");
743 743
             
744
-            $merged = wpinv_cpt_save( $item->id );
744
+            $merged = wpinv_cpt_save($item->id);
745 745
             
746
-            if ( !empty( $merged ) && !empty( $merged->ID ) ) {
746
+            if (!empty($merged) && !empty($merged->ID)) {
747 747
                 $count++;
748 748
                 
749 749
                 //$wpdb->query( "UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = '" . $merged->ID . "' WHERE id = '" . $item->id . "'" );
750 750
                 
751
-                $post_date = !empty( $item->date ) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time( 'mysql' );
752
-                $post_date_gmt = get_gmt_from_date( $post_date );
753
-                $post_modified = !empty( $item->date_updated ) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date;
754
-                $post_modified_gmt = get_gmt_from_date( $post_modified );
751
+                $post_date = !empty($item->date) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time('mysql');
752
+                $post_date_gmt = get_gmt_from_date($post_date);
753
+                $post_modified = !empty($item->date_updated) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date;
754
+                $post_modified_gmt = get_gmt_from_date($post_modified);
755 755
                 
756
-                $wpdb->update( $wpdb->posts, array( 'post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_modified' => $post_modified, 'post_modified_gmt' => $post_modified_gmt ), array( 'ID' => $merged->ID ) );
756
+                $wpdb->update($wpdb->posts, array('post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_modified' => $post_modified, 'post_modified_gmt' => $post_modified_gmt), array('ID' => $merged->ID));
757 757
                 
758
-                if ( $merged->is_paid() ) {
759
-                    update_post_meta( $merged->ID, '_wpinv_completed_date', $post_modified );
758
+                if ($merged->is_paid()) {
759
+                    update_post_meta($merged->ID, '_wpinv_completed_date', $post_modified);
760 760
                 }
761 761
                 
762
-                clean_post_cache( $merged->ID );
762
+                clean_post_cache($merged->ID);
763 763
                 
764
-                wpinv_error_log( 'Invoice merge S : ' . $item->id . ' => ' . $merged->ID );
764
+                wpinv_error_log('Invoice merge S : ' . $item->id . ' => ' . $merged->ID);
765 765
             } else {
766
-                wpinv_error_log( 'Invoice merge F : ' . $item->id );
766
+                wpinv_error_log('Invoice merge F : ' . $item->id);
767 767
             }
768 768
         }
769 769
         
770 770
         $wpi_gdp_inv_merge = false;
771 771
         
772
-        if ( $count > 0 ) {
773
-            $message = sprintf( _n( 'Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing' ), $count );
772
+        if ($count > 0) {
773
+            $message = sprintf(_n('Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing'), $count);
774 774
         } else {
775
-            $message = __( 'No invoices merged.', 'invoicing' );
775
+            $message = __('No invoices merged.', 'invoicing');
776 776
         }
777 777
     } else {
778 778
         $success = false;
779
-        $message = __( 'No invoices found to merge!', 'invoicing' );
779
+        $message = __('No invoices found to merge!', 'invoicing');
780 780
     }
781 781
     
782 782
     $response = array();
783 783
     $response['success'] = $success;
784 784
     $response['data']['message'] = $message;
785
-    wp_send_json( $response );
785
+    wp_send_json($response);
786 786
 }
787
-add_action( 'wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices' );
787
+add_action('wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices');
788 788
 
789 789
 function wpinv_tool_merge_coupons() {
790 790
     global $wpdb;
791 791
     
792 792
     $sql = "SELECT * FROM `" . COUPON_TABLE . "` WHERE `coupon_code` IS NOT NULL AND `coupon_code` != '' ORDER BY `cid` ASC";
793
-    $items = $wpdb->get_results( $sql );
793
+    $items = $wpdb->get_results($sql);
794 794
     $count = 0;
795 795
     
796
-    if ( !empty( $items ) ) {
796
+    if (!empty($items)) {
797 797
         $success = true;
798 798
         
799
-        foreach ( $items as $item ) {
800
-            if ( wpinv_get_discount_by_code( $item->coupon_code ) ) {
799
+        foreach ($items as $item) {
800
+            if (wpinv_get_discount_by_code($item->coupon_code)) {
801 801
                 continue;
802 802
             }
803 803
             
804 804
             $args = array(
805 805
                 'post_type'   => 'wpi_discount',
806 806
                 'post_title'  => $item->coupon_code,
807
-                'post_status' => !empty( $item->status ) ? 'publish' : 'pending'
807
+                'post_status' => !empty($item->status) ? 'publish' : 'pending'
808 808
             );
809 809
 
810
-            $merged = wp_insert_post( $args );
810
+            $merged = wp_insert_post($args);
811 811
             
812 812
             $item_id = $item->cid;
813 813
             
814
-            if ( $merged ) {
814
+            if ($merged) {
815 815
                 $meta = array(
816 816
                     'code'              => $item->coupon_code,
817 817
                     'type'              => $item->discount_type != 'per' ? 'flat' : 'percent',
@@ -819,65 +819,65 @@  discard block
 block discarded – undo
819 819
                     'max_uses'          => (int)$item->usage_limit,
820 820
                     'uses'              => (int)$item->usage_count,
821 821
                 );
822
-                wpinv_store_discount( $merged, $meta, get_post( $merged ) );
822
+                wpinv_store_discount($merged, $meta, get_post($merged));
823 823
                 
824 824
                 $count++;
825 825
                 
826
-                wpinv_error_log( 'Coupon merge S : ' . $item_id . ' => ' . $merged );
826
+                wpinv_error_log('Coupon merge S : ' . $item_id . ' => ' . $merged);
827 827
             } else {
828
-                wpinv_error_log( 'Coupon merge F : ' . $item_id );
828
+                wpinv_error_log('Coupon merge F : ' . $item_id);
829 829
             }
830 830
         }
831 831
         
832
-        if ( $count > 0 ) {
833
-            $message = sprintf( _n( 'Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing' ), $count );
832
+        if ($count > 0) {
833
+            $message = sprintf(_n('Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing'), $count);
834 834
         } else {
835
-            $message = __( 'No coupons merged.', 'invoicing' );
835
+            $message = __('No coupons merged.', 'invoicing');
836 836
         }
837 837
     } else {
838 838
         $success = false;
839
-        $message = __( 'No coupons found to merge!', 'invoicing' );
839
+        $message = __('No coupons found to merge!', 'invoicing');
840 840
     }
841 841
     
842 842
     $response = array();
843 843
     $response['success'] = $success;
844 844
     $response['data']['message'] = $message;
845
-    wp_send_json( $response );
845
+    wp_send_json($response);
846 846
 }
847
-add_action( 'wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons' );
847
+add_action('wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons');
848 848
 
849
-function wpinv_gdp_to_wpi_currency( $value, $option = '' ) {
849
+function wpinv_gdp_to_wpi_currency($value, $option = '') {
850 850
     return wpinv_get_currency();
851 851
 }
852
-add_filter( 'pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2 );
852
+add_filter('pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2);
853 853
 
854
-function wpinv_gdp_to_wpi_currency_sign( $value, $option = '' ) {
854
+function wpinv_gdp_to_wpi_currency_sign($value, $option = '') {
855 855
     return wpinv_currency_symbol();
856 856
 }
857
-add_filter( 'pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2 );
857
+add_filter('pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2);
858 858
 
859
-function wpinv_gdp_to_wpi_display_price( $price, $amount, $display = true , $decimal_sep, $thousand_sep ) {
860
-    if ( !$display ) {
861
-        $price = wpinv_format_amount( $amount, NULL, true );
859
+function wpinv_gdp_to_wpi_display_price($price, $amount, $display = true, $decimal_sep, $thousand_sep) {
860
+    if (!$display) {
861
+        $price = wpinv_format_amount($amount, NULL, true);
862 862
     } else {
863
-        $price = wpinv_price( wpinv_format_amount( $amount ) );
863
+        $price = wpinv_price(wpinv_format_amount($amount));
864 864
     }
865 865
     
866 866
     return $price;
867 867
 }
868
-add_filter( 'geodir_payment_price' , 'wpinv_gdp_to_wpi_display_price', 10000, 5 );
868
+add_filter('geodir_payment_price', 'wpinv_gdp_to_wpi_display_price', 10000, 5);
869 869
 
870
-function wpinv_gdp_to_inv_checkout_redirect( $redirect_url ) {
870
+function wpinv_gdp_to_inv_checkout_redirect($redirect_url) {
871 871
     $invoice_id         = geodir_payment_cart_id();
872
-    $invoice_info       = geodir_get_invoice( $invoice_id );
873
-    $wpi_invoice        = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL;
872
+    $invoice_info       = geodir_get_invoice($invoice_id);
873
+    $wpi_invoice        = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL;
874 874
     
875
-    if ( !( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) ) {
876
-        $wpi_invoice_id = wpinv_cpt_save( $invoice_id );
877
-        $wpi_invoice    = wpinv_get_invoice( $wpi_invoice_id );
875
+    if (!(!empty($wpi_invoice) && !empty($wpi_invoice->ID))) {
876
+        $wpi_invoice_id = wpinv_cpt_save($invoice_id);
877
+        $wpi_invoice    = wpinv_get_invoice($wpi_invoice_id);
878 878
     }
879 879
     
880
-    if ( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) {
880
+    if (!empty($wpi_invoice) && !empty($wpi_invoice->ID)) {
881 881
         
882 882
         // Clear cart
883 883
         geodir_payment_clear_cart();
@@ -887,121 +887,121 @@  discard block
 block discarded – undo
887 887
     
888 888
     return $redirect_url;
889 889
 }
890
-add_filter( 'geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1 );
890
+add_filter('geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1);
891 891
 
892
-function wpinv_gdp_dashboard_invoice_history_link( $dashboard_links ) {    
893
-    if ( get_current_user_id() ) {        
894
-        $dashboard_links .= '<li><i class="fa fa-shopping-cart"></i><a class="gd-invoice-link" href="' . esc_url( wpinv_get_history_page_uri() ) . '">' . __( 'My Invoice History', 'invoicing' ) . '</a></li>';
892
+function wpinv_gdp_dashboard_invoice_history_link($dashboard_links) {    
893
+    if (get_current_user_id()) {        
894
+        $dashboard_links .= '<li><i class="fa fa-shopping-cart"></i><a class="gd-invoice-link" href="' . esc_url(wpinv_get_history_page_uri()) . '">' . __('My Invoice History', 'invoicing') . '</a></li>';
895 895
     }
896 896
 
897 897
     return $dashboard_links;
898 898
 }
899
-add_action( 'geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link' );
900
-remove_action( 'geodir_dashboard_links', 'geodir_payment_invoices_list_page_link' );
899
+add_action('geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link');
900
+remove_action('geodir_dashboard_links', 'geodir_payment_invoices_list_page_link');
901 901
 
902
-function wpinv_wpi_to_gdp_update_status( $invoice_id, $new_status, $old_status ) {
902
+function wpinv_wpi_to_gdp_update_status($invoice_id, $new_status, $old_status) {
903 903
     if (!defined('GEODIRPAYMENT_VERSION')) {
904 904
         return false;
905 905
     }
906 906
     
907
-    $invoice    = wpinv_get_invoice( $invoice_id );
908
-    if ( empty( $invoice ) ) {
907
+    $invoice = wpinv_get_invoice($invoice_id);
908
+    if (empty($invoice)) {
909 909
         return false;
910 910
     }
911 911
     
912
-    remove_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 );
912
+    remove_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4);
913 913
     
914
-    $invoice_id = wpinv_wpi_to_gdp_id( $invoice_id );
915
-    $new_status = wpinv_wpi_to_gdp_status( $new_status );
914
+    $invoice_id = wpinv_wpi_to_gdp_id($invoice_id);
915
+    $new_status = wpinv_wpi_to_gdp_status($new_status);
916 916
     
917
-    geodir_update_invoice_status( $invoice_id, $new_status, $invoice->is_recurring() );
917
+    geodir_update_invoice_status($invoice_id, $new_status, $invoice->is_recurring());
918 918
 }
919
-add_action( 'wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3 );
919
+add_action('wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3);
920 920
 
921
-function wpinv_gdp_to_wpi_delete_package( $gd_package_id ) {
922
-    $item = wpinv_get_item_by( 'package_id', $gd_package_id );
921
+function wpinv_gdp_to_wpi_delete_package($gd_package_id) {
922
+    $item = wpinv_get_item_by('package_id', $gd_package_id);
923 923
     
924
-    if ( !empty( $item ) ) {
925
-        wpinv_remove_item( $item, true );
924
+    if (!empty($item)) {
925
+        wpinv_remove_item($item, true);
926 926
     }
927 927
 }
928
-add_action( 'geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1 ) ;
928
+add_action('geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1);
929 929
 
930
-function wpinv_can_delete_package_item( $return, $post_id ) {
931
-    if ( $return && function_exists( 'geodir_get_package_info_by_id' ) && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' && $package_id = get_post_meta( $post_id, '_wpinv_package_id', true ) ) {
932
-        $gd_package = geodir_get_package_info_by_id( $package_id, '' );
930
+function wpinv_can_delete_package_item($return, $post_id) {
931
+    if ($return && function_exists('geodir_get_package_info_by_id') && get_post_meta($post_id, '_wpinv_type', true) == 'package' && $package_id = get_post_meta($post_id, '_wpinv_package_id', true)) {
932
+        $gd_package = geodir_get_package_info_by_id($package_id, '');
933 933
         
934
-        if ( !empty( $gd_package ) ) {
934
+        if (!empty($gd_package)) {
935 935
             $return = false;
936 936
         }
937 937
     }
938 938
 
939 939
     return $return;
940 940
 }
941
-add_filter( 'wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2 );
941
+add_filter('wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2);
942 942
 
943
-function wpinv_package_item_classes( $classes, $class, $post_id ) {
943
+function wpinv_package_item_classes($classes, $class, $post_id) {
944 944
     global $typenow;
945 945
 
946
-    if ( $typenow == 'wpi_item' && in_array( 'wpi-gd-package', $classes ) ) {
947
-        if ( wpinv_item_in_use( $post_id ) ) {
946
+    if ($typenow == 'wpi_item' && in_array('wpi-gd-package', $classes)) {
947
+        if (wpinv_item_in_use($post_id)) {
948 948
             $classes[] = 'wpi-inuse-pkg';
949
-        } else if ( !( function_exists( 'geodir_get_package_info_by_id' ) && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' && geodir_get_package_info_by_id( (int)get_post_meta( $post_id, '_wpinv_package_id', true ), '' ) ) ) {
949
+        } else if (!(function_exists('geodir_get_package_info_by_id') && get_post_meta($post_id, '_wpinv_type', true) == 'package' && geodir_get_package_info_by_id((int)get_post_meta($post_id, '_wpinv_package_id', true), ''))) {
950 950
             $classes[] = 'wpi-delete-pkg';
951 951
         }
952 952
     }
953 953
 
954 954
     return $classes;
955 955
 }
956
-add_filter( 'post_class', 'wpinv_package_item_classes', 10, 3 );
956
+add_filter('post_class', 'wpinv_package_item_classes', 10, 3);
957 957
 
958
-function wpinv_gdp_package_type_info( $post ) {
959
-    if ( wpinv_pm_active() ) {
960
-        ?><p class="wpi-m0"><?php _e( 'Package: GeoDirectory price packages items.', 'invoicing' );?></p>
958
+function wpinv_gdp_package_type_info($post) {
959
+    if (wpinv_pm_active()) {
960
+        ?><p class="wpi-m0"><?php _e('Package: GeoDirectory price packages items.', 'invoicing'); ?></p>
961 961
         <?php
962 962
     }
963 963
 }
964
-add_action( 'wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1 ) ;
964
+add_action('wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1);
965 965
 
966
-function wpinv_gdp_to_gdi_set_zero_tax( $is_taxable, $item_id, $country , $state ) {
966
+function wpinv_gdp_to_gdi_set_zero_tax($is_taxable, $item_id, $country, $state) {
967 967
     global $wpi_zero_tax;
968 968
 
969
-    if ( $wpi_zero_tax ) {
969
+    if ($wpi_zero_tax) {
970 970
         $is_taxable = false;
971 971
     }
972 972
 
973 973
     return $is_taxable;
974 974
 }
975
-add_action( 'wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4 ) ;
975
+add_action('wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4);
976 976
 
977 977
 function wpinv_tool_merge_fix_taxes() {
978 978
     global $wpdb;
979 979
     
980 980
 	$sql = "SELECT DISTINCT p.ID FROM `" . $wpdb->posts . "` AS p LEFT JOIN " . $wpdb->postmeta . " AS pm ON pm.post_id = p.ID WHERE p.post_type = 'wpi_item' AND pm.meta_key = '_wpinv_type' AND pm.meta_value = 'package'";
981
-	$items = $wpdb->get_results( $sql );
981
+	$items = $wpdb->get_results($sql);
982 982
 	
983
-	if ( !empty( $items ) ) {
984
-		foreach ( $items as $item ) {
985
-			if ( get_post_meta( $item->ID, '_wpinv_vat_class', true ) == '_exempt' ) {
986
-				update_post_meta( $item->ID, '_wpinv_vat_class', '_standard' );
983
+	if (!empty($items)) {
984
+		foreach ($items as $item) {
985
+			if (get_post_meta($item->ID, '_wpinv_vat_class', true) == '_exempt') {
986
+				update_post_meta($item->ID, '_wpinv_vat_class', '_standard');
987 987
 			}
988 988
 		}
989 989
 	}
990 990
 		
991 991
     $sql = "SELECT `p`.`ID`, gdi.id AS gdp_id FROM `" . INVOICE_TABLE . "` AS gdi LEFT JOIN `" . $wpdb->posts . "` AS p ON `p`.`ID` = `gdi`.`invoice_id` AND `p`.`post_type` = 'wpi_invoice' WHERE `p`.`ID` IS NOT NULL AND p.post_status NOT IN( 'publish', 'complete', 'processing', 'renewal' ) ORDER BY `gdi`.`id` ASC";
992
-    $items = $wpdb->get_results( $sql );
992
+    $items = $wpdb->get_results($sql);
993 993
 	
994
-	if ( !empty( $items ) ) {
994
+	if (!empty($items)) {
995 995
 		$success = false;
996
-        $message = __( 'Taxes fixed for non-paid merged GD invoices.', 'invoicing' );
996
+        $message = __('Taxes fixed for non-paid merged GD invoices.', 'invoicing');
997 997
 		
998 998
 		global $wpi_userID, $wpinv_ip_address_country, $wpi_tax_rates;
999 999
 		
1000
-		foreach ( $items as $item ) {
1000
+		foreach ($items as $item) {
1001 1001
 			$wpi_tax_rates = NULL;               
1002 1002
 			$data = wpinv_get_invoice($item->ID);
1003 1003
 
1004
-			if ( empty( $data ) ) {
1004
+			if (empty($data)) {
1005 1005
 				continue;
1006 1006
 			}
1007 1007
 			
@@ -1009,51 +1009,51 @@  discard block
 block discarded – undo
1009 1009
 			
1010 1010
 			$data_session                   = array();
1011 1011
 			$data_session['invoice_id']     = $data->ID;
1012
-			$data_session['cart_discounts'] = $data->get_discounts( true );
1012
+			$data_session['cart_discounts'] = $data->get_discounts(true);
1013 1013
 			
1014
-			wpinv_set_checkout_session( $data_session );
1014
+			wpinv_set_checkout_session($data_session);
1015 1015
 			
1016 1016
 			$wpi_userID         = (int)$data->get_user_id();
1017 1017
 			$_POST['country']   = !empty($data->country) ? $data->country : wpinv_get_default_country();
1018 1018
 				
1019
-			$data->country      = sanitize_text_field( $_POST['country'] );
1020
-			$data->set( 'country', sanitize_text_field( $_POST['country'] ) );
1019
+			$data->country      = sanitize_text_field($_POST['country']);
1020
+			$data->set('country', sanitize_text_field($_POST['country']));
1021 1021
 			
1022 1022
 			$wpinv_ip_address_country = $data->country;
1023 1023
 			
1024 1024
 			$data->recalculate_totals(true);
1025 1025
 			
1026
-			wpinv_set_checkout_session( $checkout_session );
1026
+			wpinv_set_checkout_session($checkout_session);
1027 1027
 			
1028 1028
 			$update_data = array();
1029 1029
 			$update_data['tax_amount'] = $data->get_tax();
1030 1030
 			$update_data['paied_amount'] = $data->get_total();
1031 1031
 			$update_data['invoice_id'] = $data->ID;
1032 1032
 			
1033
-			$wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $item->gdp_id ) );
1033
+			$wpdb->update(INVOICE_TABLE, $update_data, array('id' => $item->gdp_id));
1034 1034
 		}
1035 1035
 	} else {
1036 1036
         $success = false;
1037
-        $message = __( 'No invoices found to fix taxes!', 'invoicing' );
1037
+        $message = __('No invoices found to fix taxes!', 'invoicing');
1038 1038
     }
1039 1039
 	
1040 1040
 	$response = array();
1041 1041
     $response['success'] = $success;
1042 1042
     $response['data']['message'] = $message;
1043
-    wp_send_json( $response );
1043
+    wp_send_json($response);
1044 1044
 }
1045
-add_action( 'wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes' );
1046
-remove_action( 'geodir_before_detail_fields' , 'geodir_build_coupon', 2 );
1045
+add_action('wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes');
1046
+remove_action('geodir_before_detail_fields', 'geodir_build_coupon', 2);
1047 1047
 
1048
-function wpinv_wpi_to_gdp_handle_subscription_cancel( $invoice_id, $invoice ) {
1049
-    if ( wpinv_pm_active() && !empty( $invoice ) && $invoice->is_recurring() ) {
1050
-        if ( $invoice->is_renewal() ) {
1048
+function wpinv_wpi_to_gdp_handle_subscription_cancel($invoice_id, $invoice) {
1049
+    if (wpinv_pm_active() && !empty($invoice) && $invoice->is_recurring()) {
1050
+        if ($invoice->is_renewal()) {
1051 1051
             $invoice = $invoice->get_parent_payment();
1052 1052
         }
1053 1053
         
1054
-        if ( !empty( $invoice ) ) {
1055
-            wpinv_wpi_to_gdp_update_status( $invoice->ID, 'cancelled', $invoice->get_status() );
1054
+        if (!empty($invoice)) {
1055
+            wpinv_wpi_to_gdp_update_status($invoice->ID, 'cancelled', $invoice->get_status());
1056 1056
         }
1057 1057
     }
1058 1058
 }
1059
-add_action( 'wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2 );
1060 1059
\ No newline at end of file
1060
+add_action('wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2);
1061 1061
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-helper-functions.php 3 patches
Doc Comments   +22 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,6 +31,9 @@  discard block
 block discarded – undo
31 31
     return apply_filters( 'wpinv_get_ip', $ip );
32 32
 }
33 33
 
34
+/**
35
+ * @return string
36
+ */
34 37
 function wpinv_get_user_agent() {
35 38
     if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
36 39
         $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
@@ -101,6 +104,9 @@  discard block
 block discarded – undo
101 104
     return $status;
102 105
 }
103 106
 
107
+/**
108
+ * @return string
109
+ */
104 110
 function wpinv_get_currency() {
105 111
     $currency = wpinv_get_option( 'currency', 'USD' );
106 112
     
@@ -171,6 +177,9 @@  discard block
 block discarded – undo
171 177
     return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
172 178
 }
173 179
 
180
+/**
181
+ * @return string
182
+ */
174 183
 function wpinv_currency_position() {
175 184
     $position = wpinv_get_option( 'currency_position', 'left' );
176 185
     
@@ -299,6 +308,9 @@  discard block
 block discarded – undo
299 308
     return $price;
300 309
 }
301 310
 
311
+/**
312
+ * @param integer $decimals
313
+ */
302 314
 function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) {
303 315
     $thousands_sep = wpinv_thousands_seperator();
304 316
     $decimal_sep   = wpinv_decimal_seperator();
@@ -348,6 +360,9 @@  discard block
 block discarded – undo
348 360
     return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
349 361
 }
350 362
 
363
+/**
364
+ * @return string
365
+ */
351 366
 function wpinv_get_file_extension( $str ) {
352 367
     $parts = explode( '.', $str );
353 368
     return end( $parts );
@@ -552,6 +567,9 @@  discard block
 block discarded – undo
552 567
     return strlen( $str );
553 568
 }
554 569
 
570
+/**
571
+ * @param string $str
572
+ */
555 573
 function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
556 574
     if ( function_exists( 'mb_strtolower' ) ) {
557 575
         return mb_strtolower( $str, $encoding );
@@ -560,6 +578,9 @@  discard block
 block discarded – undo
560 578
     return strtolower( $str );
561 579
 }
562 580
 
581
+/**
582
+ * @param string $str
583
+ */
563 584
 function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
564 585
     if ( function_exists( 'mb_strtoupper' ) ) {
565 586
         return mb_strtoupper( $str, $encoding );
@@ -637,7 +658,7 @@  discard block
 block discarded – undo
637 658
  *
638 659
  * @param string $str The string being decoded.
639 660
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
640
- * @return string The width of string.
661
+ * @return integer The width of string.
641 662
  */
642 663
 function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
643 664
     if ( function_exists( 'mb_strwidth' ) ) {
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -437,7 +437,7 @@
 block discarded – undo
437 437
 }
438 438
 
439 439
 function wpinv_get_php_arg_separator_output() {
440
-	return ini_get( 'arg_separator.output' );
440
+    return ini_get( 'arg_separator.output' );
441 441
 }
442 442
 
443 443
 function wpinv_rgb_from_hex( $color ) {
Please login to merge, or discard this patch.
Spacing   +236 added lines, -236 removed lines patch added patch discarded remove patch
@@ -7,112 +7,112 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_item_quantities_enabled() {
15
-    $ret = wpinv_get_option( 'item_quantities', true );
15
+    $ret = wpinv_get_option('item_quantities', true);
16 16
     
17
-    return (bool) apply_filters( 'wpinv_item_quantities_enabled', $ret );
17
+    return (bool)apply_filters('wpinv_item_quantities_enabled', $ret);
18 18
 }
19 19
 
20 20
 function wpinv_get_ip() {
21 21
     $ip = '127.0.0.1';
22 22
 
23
-    if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
24
-        $ip = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] );
25
-    } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
26
-        $ip = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] );
27
-    } elseif( !empty( $_SERVER['REMOTE_ADDR'] ) ) {
28
-        $ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] );
23
+    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
24
+        $ip = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']);
25
+    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
26
+        $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']);
27
+    } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
28
+        $ip = sanitize_text_field($_SERVER['REMOTE_ADDR']);
29 29
     }
30 30
     
31
-    return apply_filters( 'wpinv_get_ip', $ip );
31
+    return apply_filters('wpinv_get_ip', $ip);
32 32
 }
33 33
 
34 34
 function wpinv_get_user_agent() {
35
-    if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
36
-        $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
35
+    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
36
+        $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
37 37
     } else {
38 38
         $user_agent = '';
39 39
     }
40 40
     
41
-    return apply_filters( 'wpinv_get_user_agent', $user_agent );
41
+    return apply_filters('wpinv_get_user_agent', $user_agent);
42 42
 }
43 43
 
44
-function wpinv_sanitize_amount( $amount ) {
44
+function wpinv_sanitize_amount($amount) {
45 45
     $is_negative   = false;
46 46
     $thousands_sep = wpinv_thousands_seperator();
47 47
     $decimal_sep   = wpinv_decimal_seperator();
48 48
 
49 49
     // Sanitize the amount
50
-    if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) {
51
-        if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
52
-            $amount = str_replace( $thousands_sep, '', $amount );
53
-        } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) {
54
-            $amount = str_replace( '.', '', $amount );
50
+    if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) {
51
+        if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) {
52
+            $amount = str_replace($thousands_sep, '', $amount);
53
+        } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) {
54
+            $amount = str_replace('.', '', $amount);
55 55
         }
56 56
 
57
-        $amount = str_replace( $decimal_sep, '.', $amount );
58
-    } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
59
-        $amount = str_replace( $thousands_sep, '', $amount );
57
+        $amount = str_replace($decimal_sep, '.', $amount);
58
+    } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
59
+        $amount = str_replace($thousands_sep, '', $amount);
60 60
     }
61 61
 
62
-    if( $amount < 0 ) {
62
+    if ($amount < 0) {
63 63
         $is_negative = true;
64 64
     }
65 65
 
66
-    $amount   = preg_replace( '/[^0-9\.]/', '', $amount );
66
+    $amount   = preg_replace('/[^0-9\.]/', '', $amount);
67 67
 
68
-    $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', 2, $amount );
69
-    $amount   = number_format( (double) $amount, $decimals, '.', '' );
68
+    $decimals = apply_filters('wpinv_sanitize_amount_decimals', 2, $amount);
69
+    $amount   = number_format((double)$amount, $decimals, '.', '');
70 70
 
71
-    if( $is_negative ) {
71
+    if ($is_negative) {
72 72
         $amount *= -1;
73 73
     }
74 74
 
75
-    return apply_filters( 'wpinv_sanitize_amount', $amount );
75
+    return apply_filters('wpinv_sanitize_amount', $amount);
76 76
 }
77 77
 
78
-function wpinv_get_invoice_statuses( $trashed = false ) {
78
+function wpinv_get_invoice_statuses($trashed = false) {
79 79
     $invoice_statuses = array(
80
-        'pending'       => __( 'Pending Payment', 'invoicing' ),
81
-        'publish'       => __( 'Paid', 'invoicing' ),
82
-        'processing'    => __( 'Processing', 'invoicing' ),
83
-        'onhold'        => __( 'On Hold', 'invoicing' ),
84
-        'refunded'      => __( 'Refunded', 'invoicing' ),
85
-        'cancelled'     => __( 'Cancelled', 'invoicing' ),
86
-        'failed'        => __( 'Failed', 'invoicing' ),
87
-        'renewal'       => __( 'Renewal Payment', 'invoicing' )
80
+        'pending'       => __('Pending Payment', 'invoicing'),
81
+        'publish'       => __('Paid', 'invoicing'),
82
+        'processing'    => __('Processing', 'invoicing'),
83
+        'onhold'        => __('On Hold', 'invoicing'),
84
+        'refunded'      => __('Refunded', 'invoicing'),
85
+        'cancelled'     => __('Cancelled', 'invoicing'),
86
+        'failed'        => __('Failed', 'invoicing'),
87
+        'renewal'       => __('Renewal Payment', 'invoicing')
88 88
     );
89 89
     
90
-    if ( $trashed ) {
91
-        $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
90
+    if ($trashed) {
91
+        $invoice_statuses['trash'] = __('Trash', 'invoicing');
92 92
     }
93 93
 
94
-    return apply_filters( 'wpinv_statuses', $invoice_statuses );
94
+    return apply_filters('wpinv_statuses', $invoice_statuses);
95 95
 }
96 96
 
97
-function wpinv_status_nicename( $status ) {
97
+function wpinv_status_nicename($status) {
98 98
     $statuses = wpinv_get_invoice_statuses();
99
-    $status   = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' );
99
+    $status   = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing');
100 100
 
101 101
     return $status;
102 102
 }
103 103
 
104 104
 function wpinv_get_currency() {
105
-    $currency = wpinv_get_option( 'currency', 'USD' );
105
+    $currency = wpinv_get_option('currency', 'USD');
106 106
     
107
-    return apply_filters( 'wpinv_currency', $currency );
107
+    return apply_filters('wpinv_currency', $currency);
108 108
 }
109 109
 
110
-function wpinv_currency_symbol( $currency = '' ) {
111
-    if ( empty( $currency ) ) {
110
+function wpinv_currency_symbol($currency = '') {
111
+    if (empty($currency)) {
112 112
         $currency = wpinv_get_currency();
113 113
     }
114 114
     
115
-    $symbols = apply_filters( 'wpinv_currency_symbols', array(
115
+    $symbols = apply_filters('wpinv_currency_symbols', array(
116 116
         'AED' => 'د.إ',
117 117
         'ARS' => '&#36;',
118 118
         'AUD' => '&#36;',
@@ -164,78 +164,78 @@  discard block
 block discarded – undo
164 164
         'USD' => '&#36;',
165 165
         'VND' => '&#8363;',
166 166
         'ZAR' => '&#82;',
167
-    ) );
167
+    ));
168 168
 
169
-    $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : '&#36;';
169
+    $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : '&#36;';
170 170
 
171
-    return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
171
+    return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency);
172 172
 }
173 173
 
174 174
 function wpinv_currency_position() {
175
-    $position = wpinv_get_option( 'currency_position', 'left' );
175
+    $position = wpinv_get_option('currency_position', 'left');
176 176
     
177
-    return apply_filters( 'wpinv_currency_position', $position );
177
+    return apply_filters('wpinv_currency_position', $position);
178 178
 }
179 179
 
180 180
 function wpinv_thousands_seperator() {
181
-    $thousand_sep = wpinv_get_option( 'thousands_seperator', ',' );
181
+    $thousand_sep = wpinv_get_option('thousands_seperator', ',');
182 182
     
183
-    return apply_filters( 'wpinv_thousands_seperator', $thousand_sep );
183
+    return apply_filters('wpinv_thousands_seperator', $thousand_sep);
184 184
 }
185 185
 
186 186
 function wpinv_decimal_seperator() {
187
-    $decimal_sep = wpinv_get_option( 'decimal_seperator', '.' );
187
+    $decimal_sep = wpinv_get_option('decimal_seperator', '.');
188 188
     
189
-    return apply_filters( 'wpinv_decimal_seperator', $decimal_sep );
189
+    return apply_filters('wpinv_decimal_seperator', $decimal_sep);
190 190
 }
191 191
 
192 192
 function wpinv_decimals() {
193
-    $decimals = wpinv_get_option( 'decimals', 2 );
193
+    $decimals = wpinv_get_option('decimals', 2);
194 194
     
195
-    return apply_filters( 'wpinv_decimals', $decimals );
195
+    return apply_filters('wpinv_decimals', $decimals);
196 196
 }
197 197
 
198 198
 function wpinv_get_currencies() {
199 199
     $currencies = array(
200
-        'USD'  => __( 'US Dollars (&#36;)', 'invoicing' ),
201
-        'EUR'  => __( 'Euros (&euro;)', 'invoicing' ),
202
-        'GBP'  => __( 'Pounds Sterling (&pound;)', 'invoicing' ),
203
-        'AUD'  => __( 'Australian Dollars (&#36;)', 'invoicing' ),
204
-        'BRL'  => __( 'Brazilian Real (R&#36;)', 'invoicing' ),
205
-        'CAD'  => __( 'Canadian Dollars (&#36;)', 'invoicing' ),
206
-        'CLP'  => __( 'Chilean Peso (&#36;)', 'invoicing' ),
207
-        'CNY'  => __( 'Chinese Yuan (&yen;)', 'invoicing' ),
208
-        'CZK'  => __( 'Czech Koruna (&#75;&#269;)', 'invoicing' ),
209
-        'DKK'  => __( 'Danish Krone (DKK)', 'invoicing' ),
210
-        'HKD'  => __( 'Hong Kong Dollar (&#36;)', 'invoicing' ),
211
-        'HUF'  => __( 'Hungarian Forint (&#70;&#116;)', 'invoicing' ),
212
-        'INR'  => __( 'Indian Rupee (&#8377;)', 'invoicing' ),
213
-        'ILS'  => __( 'Israeli Shekel (&#8362;)', 'invoicing' ),
214
-        'JPY'  => __( 'Japanese Yen (&yen;)', 'invoicing' ),
215
-        'MYR'  => __( 'Malaysian Ringgit (&#82;&#77;)', 'invoicing' ),
216
-        'MXN'  => __( 'Mexican Peso (&#36;)', 'invoicing' ),
217
-        'NZD'  => __( 'New Zealand Dollar (&#36;)', 'invoicing' ),
218
-        'NOK'  => __( 'Norwegian Krone (&#107;&#114;)', 'invoicing' ),
219
-        'PHP'  => __( 'Philippine Peso (&#8369;)', 'invoicing' ),
220
-        'PLN'  => __( 'Polish Zloty (&#122;&#322;)', 'invoicing' ),
221
-        'SGD'  => __( 'Singapore Dollar (&#36;)', 'invoicing' ),
222
-        'SEK'  => __( 'Swedish Krona (&#107;&#114;)', 'invoicing' ),
223
-        'CHF'  => __( 'Swiss Franc (&#67;&#72;&#70;)', 'invoicing' ),
224
-        'TWD'  => __( 'Taiwan New Dollar (&#78;&#84;&#36;)', 'invoicing' ),
225
-        'THB'  => __( 'Thai Baht (&#3647;)', 'invoicing' ),
226
-        'TRY'  => __( 'Turkish Lira (&#8378;)', 'invoicing' ),
227
-        'RIAL' => __( 'Iranian Rial (&#65020;)', 'invoicing' ),
228
-        'RUB'  => __( 'Russian Ruble (&#8381;)', 'invoicing' ),
229
-        'ZAR'  => __( 'South African Rand (&#82;)', 'invoicing' )
200
+        'USD'  => __('US Dollars (&#36;)', 'invoicing'),
201
+        'EUR'  => __('Euros (&euro;)', 'invoicing'),
202
+        'GBP'  => __('Pounds Sterling (&pound;)', 'invoicing'),
203
+        'AUD'  => __('Australian Dollars (&#36;)', 'invoicing'),
204
+        'BRL'  => __('Brazilian Real (R&#36;)', 'invoicing'),
205
+        'CAD'  => __('Canadian Dollars (&#36;)', 'invoicing'),
206
+        'CLP'  => __('Chilean Peso (&#36;)', 'invoicing'),
207
+        'CNY'  => __('Chinese Yuan (&yen;)', 'invoicing'),
208
+        'CZK'  => __('Czech Koruna (&#75;&#269;)', 'invoicing'),
209
+        'DKK'  => __('Danish Krone (DKK)', 'invoicing'),
210
+        'HKD'  => __('Hong Kong Dollar (&#36;)', 'invoicing'),
211
+        'HUF'  => __('Hungarian Forint (&#70;&#116;)', 'invoicing'),
212
+        'INR'  => __('Indian Rupee (&#8377;)', 'invoicing'),
213
+        'ILS'  => __('Israeli Shekel (&#8362;)', 'invoicing'),
214
+        'JPY'  => __('Japanese Yen (&yen;)', 'invoicing'),
215
+        'MYR'  => __('Malaysian Ringgit (&#82;&#77;)', 'invoicing'),
216
+        'MXN'  => __('Mexican Peso (&#36;)', 'invoicing'),
217
+        'NZD'  => __('New Zealand Dollar (&#36;)', 'invoicing'),
218
+        'NOK'  => __('Norwegian Krone (&#107;&#114;)', 'invoicing'),
219
+        'PHP'  => __('Philippine Peso (&#8369;)', 'invoicing'),
220
+        'PLN'  => __('Polish Zloty (&#122;&#322;)', 'invoicing'),
221
+        'SGD'  => __('Singapore Dollar (&#36;)', 'invoicing'),
222
+        'SEK'  => __('Swedish Krona (&#107;&#114;)', 'invoicing'),
223
+        'CHF'  => __('Swiss Franc (&#67;&#72;&#70;)', 'invoicing'),
224
+        'TWD'  => __('Taiwan New Dollar (&#78;&#84;&#36;)', 'invoicing'),
225
+        'THB'  => __('Thai Baht (&#3647;)', 'invoicing'),
226
+        'TRY'  => __('Turkish Lira (&#8378;)', 'invoicing'),
227
+        'RIAL' => __('Iranian Rial (&#65020;)', 'invoicing'),
228
+        'RUB'  => __('Russian Ruble (&#8381;)', 'invoicing'),
229
+        'ZAR'  => __('South African Rand (&#82;)', 'invoicing')
230 230
     );
231 231
     
232
-    asort( $currencies );
232
+    asort($currencies);
233 233
 
234
-    return apply_filters( 'wpinv_currencies', $currencies );
234
+    return apply_filters('wpinv_currencies', $currencies);
235 235
 }
236 236
 
237
-function wpinv_price( $amount = '', $currency = '' ) {
238
-    if( empty( $currency ) ) {
237
+function wpinv_price($amount = '', $currency = '') {
238
+    if (empty($currency)) {
239 239
         $currency = wpinv_get_currency();
240 240
     }
241 241
 
@@ -243,14 +243,14 @@  discard block
 block discarded – undo
243 243
 
244 244
     $negative = $amount < 0;
245 245
 
246
-    if ( $negative ) {
247
-        $amount = substr( $amount, 1 );
246
+    if ($negative) {
247
+        $amount = substr($amount, 1);
248 248
     }
249 249
 
250
-    $symbol = wpinv_currency_symbol( $currency );
250
+    $symbol = wpinv_currency_symbol($currency);
251 251
 
252
-    if ( $position == 'left' || $position == 'left_space' ) {
253
-        switch ( $currency ) {
252
+    if ($position == 'left' || $position == 'left_space') {
253
+        switch ($currency) {
254 254
             case "GBP" :
255 255
             case "BRL" :
256 256
             case "EUR" :
@@ -262,15 +262,15 @@  discard block
 block discarded – undo
262 262
             case "NZD" :
263 263
             case "SGD" :
264 264
             case "JPY" :
265
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
265
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
266 266
                 break;
267 267
             default :
268 268
                 //$price = $currency . ' ' . $amount;
269
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
269
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
270 270
                 break;
271 271
         }
272 272
     } else {
273
-        switch ( $currency ) {
273
+        switch ($currency) {
274 274
             case "GBP" :
275 275
             case "BRL" :
276 276
             case "EUR" :
@@ -281,82 +281,82 @@  discard block
 block discarded – undo
281 281
             case "MXN" :
282 282
             case "SGD" :
283 283
             case "JPY" :
284
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
284
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
285 285
                 break;
286 286
             default :
287 287
                 //$price = $amount . ' ' . $currency;
288
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
288
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
289 289
                 break;
290 290
         }
291 291
     }
292 292
     
293
-    if ( $negative ) {
293
+    if ($negative) {
294 294
         $price = '-' . $price;
295 295
     }
296 296
     
297
-    $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount );
297
+    $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount);
298 298
 
299 299
     return $price;
300 300
 }
301 301
 
302
-function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) {
302
+function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) {
303 303
     $thousands_sep = wpinv_thousands_seperator();
304 304
     $decimal_sep   = wpinv_decimal_seperator();
305 305
 
306
-    if ( $decimals === NULL ) {
306
+    if ($decimals === NULL) {
307 307
         $decimals = wpinv_decimals();
308 308
     }
309 309
 
310
-    if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) {
311
-        $whole = substr( $amount, 0, $sep_found );
312
-        $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) );
310
+    if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) {
311
+        $whole = substr($amount, 0, $sep_found);
312
+        $part = substr($amount, $sep_found + 1, (strlen($amount) - 1));
313 313
         $amount = $whole . '.' . $part;
314 314
     }
315 315
 
316
-    if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
317
-        $amount = str_replace( ',', '', $amount );
316
+    if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
317
+        $amount = str_replace(',', '', $amount);
318 318
     }
319 319
 
320
-    if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
321
-        $amount = str_replace( ' ', '', $amount );
320
+    if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) {
321
+        $amount = str_replace(' ', '', $amount);
322 322
     }
323 323
 
324
-    if ( empty( $amount ) ) {
324
+    if (empty($amount)) {
325 325
         $amount = 0;
326 326
     }
327 327
     
328
-    $decimals  = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate );
329
-    $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep );
328
+    $decimals  = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate);
329
+    $formatted = number_format((float)$amount, $decimals, $decimal_sep, $thousands_sep);
330 330
     
331
-    if ( $calculate ) {
332
-        if ( $thousands_sep === "," ) {
333
-            $formatted = str_replace( ",", "", $formatted );
331
+    if ($calculate) {
332
+        if ($thousands_sep === ",") {
333
+            $formatted = str_replace(",", "", $formatted);
334 334
         }
335 335
         
336
-        if ( $decimal_sep === "," ) {
337
-            $formatted = str_replace( ",", ".", $formatted );
336
+        if ($decimal_sep === ",") {
337
+            $formatted = str_replace(",", ".", $formatted);
338 338
         }
339 339
     }
340 340
 
341
-    return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate );
341
+    return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate);
342 342
 }
343 343
 
344
-function wpinv_sanitize_key( $key ) {
344
+function wpinv_sanitize_key($key) {
345 345
     $raw_key = $key;
346
-    $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
346
+    $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key);
347 347
 
348
-    return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
348
+    return apply_filters('wpinv_sanitize_key', $key, $raw_key);
349 349
 }
350 350
 
351
-function wpinv_get_file_extension( $str ) {
352
-    $parts = explode( '.', $str );
353
-    return end( $parts );
351
+function wpinv_get_file_extension($str) {
352
+    $parts = explode('.', $str);
353
+    return end($parts);
354 354
 }
355 355
 
356
-function wpinv_string_is_image_url( $str ) {
357
-    $ext = wpinv_get_file_extension( $str );
356
+function wpinv_string_is_image_url($str) {
357
+    $ext = wpinv_get_file_extension($str);
358 358
 
359
-    switch ( strtolower( $ext ) ) {
359
+    switch (strtolower($ext)) {
360 360
         case 'jpeg';
361 361
         case 'jpg';
362 362
             $return = true;
@@ -372,32 +372,32 @@  discard block
 block discarded – undo
372 372
             break;
373 373
     }
374 374
 
375
-    return (bool)apply_filters( 'wpinv_string_is_image', $return, $str );
375
+    return (bool)apply_filters('wpinv_string_is_image', $return, $str);
376 376
 }
377 377
 
378
-function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) {
379
-    $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG );
378
+function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) {
379
+    $should_log = apply_filters('wpinv_log_errors', WP_DEBUG);
380 380
     
381
-    if ( true === $should_log ) {
381
+    if (true === $should_log) {
382 382
         $label = '';
383
-        if ( $file && $file !== '' ) {
384
-            $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' );
383
+        if ($file && $file !== '') {
384
+            $label .= basename($file) . ($line ? '(' . $line . ')' : '');
385 385
         }
386 386
         
387
-        if ( $title && $title !== '' ) {
387
+        if ($title && $title !== '') {
388 388
             $label = $label !== '' ? $label . ' ' : '';
389 389
             $label .= $title . ' ';
390 390
         }
391 391
         
392
-        $label = $label !== '' ? trim( $label ) . ' : ' : '';
392
+        $label = $label !== '' ? trim($label) . ' : ' : '';
393 393
         
394
-        if ( is_array( $log ) || is_object( $log ) ) {
395
-            error_log( $label . print_r( $log, true ) );
394
+        if (is_array($log) || is_object($log)) {
395
+            error_log($label . print_r($log, true));
396 396
         } else {
397
-            error_log( $label . $log );
397
+            error_log($label . $log);
398 398
         }
399 399
         
400
-        if ( $exit ) {
400
+        if ($exit) {
401 401
             exit;
402 402
         }
403 403
     }
@@ -405,65 +405,65 @@  discard block
 block discarded – undo
405 405
 
406 406
 function wpinv_is_ajax_disabled() {
407 407
     $retval = false;
408
-    return apply_filters( 'wpinv_is_ajax_disabled', $retval );
408
+    return apply_filters('wpinv_is_ajax_disabled', $retval);
409 409
 }
410 410
 
411
-function wpinv_get_current_page_url( $nocache = false ) {
411
+function wpinv_get_current_page_url($nocache = false) {
412 412
     global $wp;
413 413
 
414
-    if ( get_option( 'permalink_structure' ) ) {
415
-        $base = trailingslashit( home_url( $wp->request ) );
414
+    if (get_option('permalink_structure')) {
415
+        $base = trailingslashit(home_url($wp->request));
416 416
     } else {
417
-        $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) );
418
-        $base = remove_query_arg( array( 'post_type', 'name' ), $base );
417
+        $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request)));
418
+        $base = remove_query_arg(array('post_type', 'name'), $base);
419 419
     }
420 420
 
421 421
     $scheme = is_ssl() ? 'https' : 'http';
422
-    $uri    = set_url_scheme( $base, $scheme );
422
+    $uri    = set_url_scheme($base, $scheme);
423 423
 
424
-    if ( is_front_page() ) {
425
-        $uri = home_url( '/' );
426
-    } elseif ( wpinv_is_checkout( array(), false ) ) {
424
+    if (is_front_page()) {
425
+        $uri = home_url('/');
426
+    } elseif (wpinv_is_checkout(array(), false)) {
427 427
         $uri = wpinv_get_checkout_uri();
428 428
     }
429 429
 
430
-    $uri = apply_filters( 'wpinv_get_current_page_url', $uri );
430
+    $uri = apply_filters('wpinv_get_current_page_url', $uri);
431 431
 
432
-    if ( $nocache ) {
433
-        $uri = wpinv_add_cache_busting( $uri );
432
+    if ($nocache) {
433
+        $uri = wpinv_add_cache_busting($uri);
434 434
     }
435 435
 
436 436
     return $uri;
437 437
 }
438 438
 
439 439
 function wpinv_get_php_arg_separator_output() {
440
-	return ini_get( 'arg_separator.output' );
440
+	return ini_get('arg_separator.output');
441 441
 }
442 442
 
443
-function wpinv_rgb_from_hex( $color ) {
444
-    $color = str_replace( '#', '', $color );
443
+function wpinv_rgb_from_hex($color) {
444
+    $color = str_replace('#', '', $color);
445 445
     // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
446
-    $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
446
+    $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
447 447
 
448 448
     $rgb      = array();
449
-    $rgb['R'] = hexdec( $color{0}.$color{1} );
450
-    $rgb['G'] = hexdec( $color{2}.$color{3} );
451
-    $rgb['B'] = hexdec( $color{4}.$color{5} );
449
+    $rgb['R'] = hexdec($color{0} . $color{1} );
450
+    $rgb['G'] = hexdec($color{2} . $color{3} );
451
+    $rgb['B'] = hexdec($color{4} . $color{5} );
452 452
 
453 453
     return $rgb;
454 454
 }
455 455
 
456
-function wpinv_hex_darker( $color, $factor = 30 ) {
457
-    $base  = wpinv_rgb_from_hex( $color );
456
+function wpinv_hex_darker($color, $factor = 30) {
457
+    $base  = wpinv_rgb_from_hex($color);
458 458
     $color = '#';
459 459
 
460
-    foreach ( $base as $k => $v ) {
460
+    foreach ($base as $k => $v) {
461 461
         $amount      = $v / 100;
462
-        $amount      = round( $amount * $factor );
462
+        $amount      = round($amount * $factor);
463 463
         $new_decimal = $v - $amount;
464 464
 
465
-        $new_hex_component = dechex( $new_decimal );
466
-        if ( strlen( $new_hex_component ) < 2 ) {
465
+        $new_hex_component = dechex($new_decimal);
466
+        if (strlen($new_hex_component) < 2) {
467 467
             $new_hex_component = "0" . $new_hex_component;
468 468
         }
469 469
         $color .= $new_hex_component;
@@ -472,18 +472,18 @@  discard block
 block discarded – undo
472 472
     return $color;
473 473
 }
474 474
 
475
-function wpinv_hex_lighter( $color, $factor = 30 ) {
476
-    $base  = wpinv_rgb_from_hex( $color );
475
+function wpinv_hex_lighter($color, $factor = 30) {
476
+    $base  = wpinv_rgb_from_hex($color);
477 477
     $color = '#';
478 478
 
479
-    foreach ( $base as $k => $v ) {
479
+    foreach ($base as $k => $v) {
480 480
         $amount      = 255 - $v;
481 481
         $amount      = $amount / 100;
482
-        $amount      = round( $amount * $factor );
482
+        $amount      = round($amount * $factor);
483 483
         $new_decimal = $v + $amount;
484 484
 
485
-        $new_hex_component = dechex( $new_decimal );
486
-        if ( strlen( $new_hex_component ) < 2 ) {
485
+        $new_hex_component = dechex($new_decimal);
486
+        if (strlen($new_hex_component) < 2) {
487 487
             $new_hex_component = "0" . $new_hex_component;
488 488
         }
489 489
         $color .= $new_hex_component;
@@ -492,22 +492,22 @@  discard block
 block discarded – undo
492 492
     return $color;
493 493
 }
494 494
 
495
-function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
496
-    $hex = str_replace( '#', '', $color );
495
+function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
496
+    $hex = str_replace('#', '', $color);
497 497
 
498
-    $c_r = hexdec( substr( $hex, 0, 2 ) );
499
-    $c_g = hexdec( substr( $hex, 2, 2 ) );
500
-    $c_b = hexdec( substr( $hex, 4, 2 ) );
498
+    $c_r = hexdec(substr($hex, 0, 2));
499
+    $c_g = hexdec(substr($hex, 2, 2));
500
+    $c_b = hexdec(substr($hex, 4, 2));
501 501
 
502
-    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
502
+    $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
503 503
 
504 504
     return $brightness > 155 ? $dark : $light;
505 505
 }
506 506
 
507
-function wpinv_format_hex( $hex ) {
508
-    $hex = trim( str_replace( '#', '', $hex ) );
507
+function wpinv_format_hex($hex) {
508
+    $hex = trim(str_replace('#', '', $hex));
509 509
 
510
-    if ( strlen( $hex ) == 3 ) {
510
+    if (strlen($hex) == 3) {
511 511
         $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
512 512
     }
513 513
 
@@ -527,12 +527,12 @@  discard block
 block discarded – undo
527 527
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
528 528
  * @return string
529 529
  */
530
-function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) {
531
-    if ( function_exists( 'mb_strimwidth' ) ) {
532
-        return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding );
530
+function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') {
531
+    if (function_exists('mb_strimwidth')) {
532
+        return mb_strimwidth($str, $start, $width, $trimmaker, $encoding);
533 533
     }
534 534
     
535
-    return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker;
535
+    return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker;
536 536
 }
537 537
 
538 538
 /**
@@ -544,28 +544,28 @@  discard block
 block discarded – undo
544 544
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
545 545
  * @return int Returns the number of characters in string.
546 546
  */
547
-function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) {
548
-    if ( function_exists( 'mb_strlen' ) ) {
549
-        return mb_strlen( $str, $encoding );
547
+function wpinv_utf8_strlen($str, $encoding = 'UTF-8') {
548
+    if (function_exists('mb_strlen')) {
549
+        return mb_strlen($str, $encoding);
550 550
     }
551 551
         
552
-    return strlen( $str );
552
+    return strlen($str);
553 553
 }
554 554
 
555
-function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
556
-    if ( function_exists( 'mb_strtolower' ) ) {
557
-        return mb_strtolower( $str, $encoding );
555
+function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') {
556
+    if (function_exists('mb_strtolower')) {
557
+        return mb_strtolower($str, $encoding);
558 558
     }
559 559
     
560
-    return strtolower( $str );
560
+    return strtolower($str);
561 561
 }
562 562
 
563
-function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
564
-    if ( function_exists( 'mb_strtoupper' ) ) {
565
-        return mb_strtoupper( $str, $encoding );
563
+function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') {
564
+    if (function_exists('mb_strtoupper')) {
565
+        return mb_strtoupper($str, $encoding);
566 566
     }
567 567
     
568
-    return strtoupper( $str );
568
+    return strtoupper($str);
569 569
 }
570 570
 
571 571
 /**
@@ -579,12 +579,12 @@  discard block
 block discarded – undo
579 579
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
580 580
  * @return int Returns the position of the first occurrence of search in the string.
581 581
  */
582
-function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
583
-    if ( function_exists( 'mb_strpos' ) ) {
584
-        return mb_strpos( $str, $find, $offset, $encoding );
582
+function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
583
+    if (function_exists('mb_strpos')) {
584
+        return mb_strpos($str, $find, $offset, $encoding);
585 585
     }
586 586
         
587
-    return strpos( $str, $find, $offset );
587
+    return strpos($str, $find, $offset);
588 588
 }
589 589
 
590 590
 /**
@@ -598,12 +598,12 @@  discard block
 block discarded – undo
598 598
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
599 599
  * @return int Returns the position of the last occurrence of search.
600 600
  */
601
-function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
602
-    if ( function_exists( 'mb_strrpos' ) ) {
603
-        return mb_strrpos( $str, $find, $offset, $encoding );
601
+function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
602
+    if (function_exists('mb_strrpos')) {
603
+        return mb_strrpos($str, $find, $offset, $encoding);
604 604
     }
605 605
         
606
-    return strrpos( $str, $find, $offset );
606
+    return strrpos($str, $find, $offset);
607 607
 }
608 608
 
609 609
 /**
@@ -618,16 +618,16 @@  discard block
 block discarded – undo
618 618
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
619 619
  * @return string
620 620
  */
621
-function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) {
622
-    if ( function_exists( 'mb_substr' ) ) {
623
-        if ( $length === null ) {
624
-            return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding );
621
+function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') {
622
+    if (function_exists('mb_substr')) {
623
+        if ($length === null) {
624
+            return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding);
625 625
         } else {
626
-            return mb_substr( $str, $start, $length, $encoding );
626
+            return mb_substr($str, $start, $length, $encoding);
627 627
         }
628 628
     }
629 629
         
630
-    return substr( $str, $start, $length );
630
+    return substr($str, $start, $length);
631 631
 }
632 632
 
633 633
 /**
@@ -639,48 +639,48 @@  discard block
 block discarded – undo
639 639
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
640 640
  * @return string The width of string.
641 641
  */
642
-function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
643
-    if ( function_exists( 'mb_strwidth' ) ) {
644
-        return mb_strwidth( $str, $encoding );
642
+function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') {
643
+    if (function_exists('mb_strwidth')) {
644
+        return mb_strwidth($str, $encoding);
645 645
     }
646 646
     
647
-    return wpinv_utf8_strlen( $str, $encoding );
647
+    return wpinv_utf8_strlen($str, $encoding);
648 648
 }
649 649
 
650
-function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) {
651
-    if ( function_exists( 'mb_strlen' ) ) {
652
-        $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding );
650
+function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') {
651
+    if (function_exists('mb_strlen')) {
652
+        $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding);
653 653
         $str_end = "";
654 654
         
655
-        if ( $lower_str_end ) {
656
-            $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding );
655
+        if ($lower_str_end) {
656
+            $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding);
657 657
         } else {
658
-            $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding );
658
+            $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding);
659 659
         }
660 660
 
661 661
         return $first_letter . $str_end;
662 662
     }
663 663
     
664
-    return ucfirst( $str );
664
+    return ucfirst($str);
665 665
 }
666 666
 
667
-function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) {
668
-    if ( function_exists( 'mb_convert_case' ) ) {
669
-        return mb_convert_case( $str, MB_CASE_TITLE, $encoding );
667
+function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') {
668
+    if (function_exists('mb_convert_case')) {
669
+        return mb_convert_case($str, MB_CASE_TITLE, $encoding);
670 670
     }
671 671
     
672
-    return ucwords( $str );
672
+    return ucwords($str);
673 673
 }
674 674
 
675
-function wpinv_period_in_days( $period, $unit ) {
676
-    $period = absint( $period );
675
+function wpinv_period_in_days($period, $unit) {
676
+    $period = absint($period);
677 677
     
678
-    if ( $period > 0 ) {
679
-        if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) {
678
+    if ($period > 0) {
679
+        if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) {
680 680
             $period = $period * 7;
681
-        } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) {
681
+        } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) {
682 682
             $period = $period * 30;
683
-        } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) {
683
+        } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) {
684 684
             $period = $period * 365;
685 685
         }
686 686
     }
Please login to merge, or discard this patch.
includes/wpinv-invoice-functions.php 4 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -176,6 +176,9 @@  discard block
 block discarded – undo
176 176
     return $date_created;
177 177
 }
178 178
 
179
+/**
180
+ * @return string
181
+ */
179 182
 function wpinv_get_invoice_date( $invoice_id = 0, $format = '' ) {
180 183
     $invoice = new WPInv_Invoice( $invoice_id );
181 184
     
@@ -1375,6 +1378,9 @@  discard block
 block discarded – undo
1375 1378
     return $display;
1376 1379
 }
1377 1380
 
1381
+/**
1382
+ * @return integer
1383
+ */
1378 1384
 function wpinv_get_invoice_id_by_key( $key ) {
1379 1385
 	global $wpdb;
1380 1386
 
Please login to merge, or discard this patch.
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 }
216 216
 
217 217
 function wpinv_get_payment_key( $invoice_id = 0 ) {
218
-	$invoice = new WPInv_Invoice( $invoice_id );
218
+    $invoice = new WPInv_Invoice( $invoice_id );
219 219
     return $invoice->get_key();
220 220
 }
221 221
 
@@ -731,20 +731,20 @@  discard block
 block discarded – undo
731 731
 }
732 732
 
733 733
 function wpinv_checkout_get_cc_info() {
734
-	$cc_info = array();
735
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
736
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
737
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
738
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
739
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
740
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
741
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
742
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
743
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
744
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
745
-
746
-	// Return cc info
747
-	return $cc_info;
734
+    $cc_info = array();
735
+    $cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
736
+    $cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
737
+    $cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
738
+    $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
739
+    $cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
740
+    $cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
741
+    $cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
742
+    $cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
743
+    $cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
744
+    $cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
745
+
746
+    // Return cc info
747
+    return $cc_info;
748 748
 }
749 749
 
750 750
 function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
@@ -942,7 +942,7 @@  discard block
 block discarded – undo
942 942
         $required_fields  = wpinv_checkout_required_fields();
943 943
 
944 944
         // Loop through required fields and show error messages
945
-         if ( !empty( $required_fields ) ) {
945
+            if ( !empty( $required_fields ) ) {
946 946
             foreach ( $required_fields as $field_name => $value ) {
947 947
                 if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
948 948
                     wpinv_set_error( $value['error_id'], $value['error_message'] );
@@ -1025,7 +1025,7 @@  discard block
 block discarded – undo
1025 1025
 }
1026 1026
 
1027 1027
 function wpinv_get_checkout_session() {
1028
-	global $wpi_session;
1028
+    global $wpi_session;
1029 1029
     
1030 1030
     return $wpi_session->get( 'wpinv_checkout' );
1031 1031
 }
@@ -1376,47 +1376,47 @@  discard block
 block discarded – undo
1376 1376
 }
1377 1377
 
1378 1378
 function wpinv_get_invoice_id_by_key( $key ) {
1379
-	global $wpdb;
1379
+    global $wpdb;
1380 1380
 
1381
-	$invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) );
1381
+    $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) );
1382 1382
 
1383
-	if ( $invoice_id != NULL )
1384
-		return $invoice_id;
1383
+    if ( $invoice_id != NULL )
1384
+        return $invoice_id;
1385 1385
 
1386
-	return 0;
1386
+    return 0;
1387 1387
 }
1388 1388
 
1389 1389
 function wpinv_can_view_receipt( $invoice_key = '' ) {
1390
-	$return = false;
1390
+    $return = false;
1391 1391
 
1392
-	if ( empty( $invoice_key ) ) {
1393
-		return $return;
1394
-	}
1392
+    if ( empty( $invoice_key ) ) {
1393
+        return $return;
1394
+    }
1395 1395
 
1396
-	global $wpinv_receipt_args;
1396
+    global $wpinv_receipt_args;
1397 1397
 
1398
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1399
-	if ( isset( $_GET['invoice-id'] ) ) {
1400
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1401
-	}
1398
+    $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1399
+    if ( isset( $_GET['invoice-id'] ) ) {
1400
+        $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1401
+    }
1402 1402
 
1403
-	$user_id = (int) wpinv_get_user_id( $wpinv_receipt_args['id'] );
1403
+    $user_id = (int) wpinv_get_user_id( $wpinv_receipt_args['id'] );
1404 1404
     $invoice_meta = wpinv_get_invoice_meta( $wpinv_receipt_args['id'] );
1405 1405
 
1406
-	if ( is_user_logged_in() ) {
1407
-		if ( $user_id === (int) get_current_user_id() ) {
1408
-			$return = true;
1409
-		}
1410
-	}
1406
+    if ( is_user_logged_in() ) {
1407
+        if ( $user_id === (int) get_current_user_id() ) {
1408
+            $return = true;
1409
+        }
1410
+    }
1411 1411
 
1412
-	$session = wpinv_get_checkout_session();
1413
-	if ( ! empty( $session ) && ! is_user_logged_in() ) {
1414
-		if ( $session['invoice_key'] === $invoice_meta['key'] ) {
1415
-			$return = true;
1416
-		}
1417
-	}
1412
+    $session = wpinv_get_checkout_session();
1413
+    if ( ! empty( $session ) && ! is_user_logged_in() ) {
1414
+        if ( $session['invoice_key'] === $invoice_meta['key'] ) {
1415
+            $return = true;
1416
+        }
1417
+    }
1418 1418
 
1419
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1419
+    return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1420 1420
 }
1421 1421
 
1422 1422
 function wpinv_pay_for_invoice() {
Please login to merge, or discard this patch.
Spacing   +468 added lines, -468 removed lines patch added patch discarded remove patch
@@ -7,440 +7,440 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_get_invoice_cart_id() {
15 15
     $wpinv_checkout = wpinv_get_checkout_session();
16 16
     
17
-    if ( !empty( $wpinv_checkout['invoice_id'] ) ) {
17
+    if (!empty($wpinv_checkout['invoice_id'])) {
18 18
         return $wpinv_checkout['invoice_id'];
19 19
     }
20 20
     
21 21
     return NULL;
22 22
 }
23 23
 
24
-function wpinv_get_invoice( $invoice_id = 0, $cart = false ) {
25
-    if ( $cart && empty( $invoice_id ) ) {
24
+function wpinv_get_invoice($invoice_id = 0, $cart = false) {
25
+    if ($cart && empty($invoice_id)) {
26 26
         $invoice_id = (int)wpinv_get_invoice_cart_id();
27 27
     }
28 28
 
29
-    $invoice = new WPInv_Invoice( $invoice_id );
29
+    $invoice = new WPInv_Invoice($invoice_id);
30 30
     return $invoice;
31 31
 }
32 32
 
33
-function wpinv_get_invoice_cart( $invoice_id = 0 ) {
34
-    return wpinv_get_invoice( $invoice_id, true );
33
+function wpinv_get_invoice_cart($invoice_id = 0) {
34
+    return wpinv_get_invoice($invoice_id, true);
35 35
 }
36 36
 
37
-function wpinv_get_invoice_description( $invoice_id = 0 ) {
38
-    $invoice = new WPInv_Invoice( $invoice_id );
37
+function wpinv_get_invoice_description($invoice_id = 0) {
38
+    $invoice = new WPInv_Invoice($invoice_id);
39 39
     return $invoice->get_description();
40 40
 }
41 41
 
42
-function wpinv_get_invoice_currency_code( $invoice_id = 0 ) {
43
-    $invoice = new WPInv_Invoice( $invoice_id );
42
+function wpinv_get_invoice_currency_code($invoice_id = 0) {
43
+    $invoice = new WPInv_Invoice($invoice_id);
44 44
     return $invoice->get_currency();
45 45
 }
46 46
 
47
-function wpinv_get_payment_user_email( $invoice_id ) {
48
-    $invoice = new WPInv_Invoice( $invoice_id );
47
+function wpinv_get_payment_user_email($invoice_id) {
48
+    $invoice = new WPInv_Invoice($invoice_id);
49 49
     return $invoice->get_email();
50 50
 }
51 51
 
52
-function wpinv_get_user_id( $invoice_id ) {
53
-    $invoice = new WPInv_Invoice( $invoice_id );
52
+function wpinv_get_user_id($invoice_id) {
53
+    $invoice = new WPInv_Invoice($invoice_id);
54 54
     return $invoice->get_user_id();
55 55
 }
56 56
 
57
-function wpinv_get_invoice_status( $invoice_id, $return_label = false ) {
58
-    $invoice = new WPInv_Invoice( $invoice_id );
57
+function wpinv_get_invoice_status($invoice_id, $return_label = false) {
58
+    $invoice = new WPInv_Invoice($invoice_id);
59 59
     
60
-    return $invoice->get_status( $return_label );
60
+    return $invoice->get_status($return_label);
61 61
 }
62 62
 
63
-function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) {
64
-    $invoice = new WPInv_Invoice( $invoice_id );
63
+function wpinv_get_payment_gateway($invoice_id, $return_label = false) {
64
+    $invoice = new WPInv_Invoice($invoice_id);
65 65
     
66
-    return $invoice->get_gateway( $return_label );
66
+    return $invoice->get_gateway($return_label);
67 67
 }
68 68
 
69
-function wpinv_get_payment_gateway_name( $invoice_id ) {
70
-    $invoice = new WPInv_Invoice( $invoice_id );
69
+function wpinv_get_payment_gateway_name($invoice_id) {
70
+    $invoice = new WPInv_Invoice($invoice_id);
71 71
     
72 72
     return $invoice->get_gateway_title();
73 73
 }
74 74
 
75
-function wpinv_get_payment_transaction_id( $invoice_id ) {
76
-    $invoice = new WPInv_Invoice( $invoice_id );
75
+function wpinv_get_payment_transaction_id($invoice_id) {
76
+    $invoice = new WPInv_Invoice($invoice_id);
77 77
     
78 78
     return $invoice->get_transaction_id();
79 79
 }
80 80
 
81
-function wpinv_get_id_by_transaction_id( $key ) {
81
+function wpinv_get_id_by_transaction_id($key) {
82 82
     global $wpdb;
83 83
 
84
-    $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) );
84
+    $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key));
85 85
 
86
-    if ( $invoice_id != NULL )
86
+    if ($invoice_id != NULL)
87 87
         return $invoice_id;
88 88
 
89 89
     return 0;
90 90
 }
91 91
 
92
-function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) {
93
-    $invoice = new WPInv_Invoice( $invoice_id );
92
+function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) {
93
+    $invoice = new WPInv_Invoice($invoice_id);
94 94
 
95
-    return $invoice->get_meta( $meta_key, $single );
95
+    return $invoice->get_meta($meta_key, $single);
96 96
 }
97 97
 
98
-function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) {
99
-    $invoice = new WPInv_Invoice( $invoice_id );
98
+function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') {
99
+    $invoice = new WPInv_Invoice($invoice_id);
100 100
     
101
-    return $invoice->update_meta( $meta_key, $meta_value, $prev_value );
101
+    return $invoice->update_meta($meta_key, $meta_value, $prev_value);
102 102
 }
103 103
 
104
-function wpinv_get_items( $invoice_id = 0 ) {
105
-    $invoice            = wpinv_get_invoice( $invoice_id );
104
+function wpinv_get_items($invoice_id = 0) {
105
+    $invoice            = wpinv_get_invoice($invoice_id);
106 106
     
107 107
     $items              = $invoice->get_items();
108 108
     $invoice_currency   = $invoice->get_currency();
109 109
 
110
-    if ( !empty( $items ) && is_array( $items ) ) {
111
-        foreach ( $items as $key => $item ) {
110
+    if (!empty($items) && is_array($items)) {
111
+        foreach ($items as $key => $item) {
112 112
             $items[$key]['currency'] = $invoice_currency;
113 113
 
114
-            if ( !isset( $cart_item['subtotal'] ) ) {
114
+            if (!isset($cart_item['subtotal'])) {
115 115
                 $items[$key]['subtotal'] = $items[$key]['amount'] * 1;
116 116
             }
117 117
         }
118 118
     }
119 119
 
120
-    return apply_filters( 'wpinv_get_items', $items, $invoice_id );
120
+    return apply_filters('wpinv_get_items', $items, $invoice_id);
121 121
 }
122 122
 
123
-function wpinv_get_fees( $invoice_id = 0 ) {
124
-    $invoice           = wpinv_get_invoice( $invoice_id );
123
+function wpinv_get_fees($invoice_id = 0) {
124
+    $invoice           = wpinv_get_invoice($invoice_id);
125 125
     $fees              = $invoice->get_fees();
126 126
 
127
-    return apply_filters( 'wpinv_get_fees', $fees, $invoice_id );
127
+    return apply_filters('wpinv_get_fees', $fees, $invoice_id);
128 128
 }
129 129
 
130
-function wpinv_get_invoice_ip( $invoice_id ) {
131
-    $invoice = new WPInv_Invoice( $invoice_id );
130
+function wpinv_get_invoice_ip($invoice_id) {
131
+    $invoice = new WPInv_Invoice($invoice_id);
132 132
     return $invoice->get_ip();
133 133
 }
134 134
 
135
-function wpinv_get_invoice_user_info( $invoice_id ) {
136
-    $invoice = new WPInv_Invoice( $invoice_id );
135
+function wpinv_get_invoice_user_info($invoice_id) {
136
+    $invoice = new WPInv_Invoice($invoice_id);
137 137
     return $invoice->get_user_info();
138 138
 }
139 139
 
140
-function wpinv_subtotal( $invoice_id = 0, $currency = false ) {
141
-    $invoice = new WPInv_Invoice( $invoice_id );
140
+function wpinv_subtotal($invoice_id = 0, $currency = false) {
141
+    $invoice = new WPInv_Invoice($invoice_id);
142 142
 
143
-    return $invoice->get_subtotal( $currency );
143
+    return $invoice->get_subtotal($currency);
144 144
 }
145 145
 
146
-function wpinv_tax( $invoice_id = 0, $currency = false ) {
147
-    $invoice = new WPInv_Invoice( $invoice_id );
146
+function wpinv_tax($invoice_id = 0, $currency = false) {
147
+    $invoice = new WPInv_Invoice($invoice_id);
148 148
 
149
-    return $invoice->get_tax( $currency );
149
+    return $invoice->get_tax($currency);
150 150
 }
151 151
 
152
-function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) {
153
-    $invoice = wpinv_get_invoice( $invoice_id );
152
+function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) {
153
+    $invoice = wpinv_get_invoice($invoice_id);
154 154
 
155
-    return $invoice->get_discount( $currency, $dash );
155
+    return $invoice->get_discount($currency, $dash);
156 156
 }
157 157
 
158
-function wpinv_discount_code( $invoice_id = 0 ) {
159
-    $invoice = new WPInv_Invoice( $invoice_id );
158
+function wpinv_discount_code($invoice_id = 0) {
159
+    $invoice = new WPInv_Invoice($invoice_id);
160 160
 
161 161
     return $invoice->get_discount_code();
162 162
 }
163 163
 
164
-function wpinv_payment_total( $invoice_id = 0, $currency = false ) {
165
-    $invoice = new WPInv_Invoice( $invoice_id );
164
+function wpinv_payment_total($invoice_id = 0, $currency = false) {
165
+    $invoice = new WPInv_Invoice($invoice_id);
166 166
 
167
-    return $invoice->get_total( $currency );
167
+    return $invoice->get_total($currency);
168 168
 }
169 169
 
170
-function wpinv_get_date_created( $invoice_id = 0 ) {
171
-    $invoice = new WPInv_Invoice( $invoice_id );
170
+function wpinv_get_date_created($invoice_id = 0) {
171
+    $invoice = new WPInv_Invoice($invoice_id);
172 172
     
173 173
     $date_created   = $invoice->get_created_date();
174
-    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ), strtotime( $date_created ) ) : '';
174
+    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format'), strtotime($date_created)) : '';
175 175
 
176 176
     return $date_created;
177 177
 }
178 178
 
179
-function wpinv_get_invoice_date( $invoice_id = 0, $format = '' ) {
180
-    $invoice = new WPInv_Invoice( $invoice_id );
179
+function wpinv_get_invoice_date($invoice_id = 0, $format = '') {
180
+    $invoice = new WPInv_Invoice($invoice_id);
181 181
     
182
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
182
+    $format         = !empty($format) ? $format : get_option('date_format');
183 183
     $date_completed = $invoice->get_completed_date();
184
-    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : '';
185
-    if ( $invoice_date == '' ) {
184
+    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : '';
185
+    if ($invoice_date == '') {
186 186
         $date_created   = $invoice->get_created_date();
187
-        $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : '';
187
+        $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : '';
188 188
     }
189 189
 
190 190
     return $invoice_date;
191 191
 }
192 192
 
193
-function wpinv_get_invoice_vat_number( $invoice_id = 0 ) {
194
-    $invoice = new WPInv_Invoice( $invoice_id );
193
+function wpinv_get_invoice_vat_number($invoice_id = 0) {
194
+    $invoice = new WPInv_Invoice($invoice_id);
195 195
     
196 196
     return $invoice->vat_number;
197 197
 }
198 198
 
199
-function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false ) {
200
-    $invoice = new WPInv_Invoice( $invoice_id );
199
+function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false) {
200
+    $invoice = new WPInv_Invoice($invoice_id);
201 201
 
202
-    return $invoice->add_note( $note, $user_type, $added_by_user );
202
+    return $invoice->add_note($note, $user_type, $added_by_user);
203 203
 }
204 204
 
205
-function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) {
205
+function wpinv_get_invoice_notes($invoice_id = 0, $type = '') {
206 206
     global $invoicing;
207 207
     
208
-    if ( empty( $invoice_id ) ) {
208
+    if (empty($invoice_id)) {
209 209
         return NULL;
210 210
     }
211 211
     
212
-    $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type );
212
+    $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type);
213 213
     
214
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type );
214
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type);
215 215
 }
216 216
 
217
-function wpinv_get_payment_key( $invoice_id = 0 ) {
218
-	$invoice = new WPInv_Invoice( $invoice_id );
217
+function wpinv_get_payment_key($invoice_id = 0) {
218
+	$invoice = new WPInv_Invoice($invoice_id);
219 219
     return $invoice->get_key();
220 220
 }
221 221
 
222
-function wpinv_get_invoice_number( $invoice_id = 0 ) {
223
-    $invoice = new WPInv_Invoice( $invoice_id );
222
+function wpinv_get_invoice_number($invoice_id = 0) {
223
+    $invoice = new WPInv_Invoice($invoice_id);
224 224
     return $invoice->get_number();
225 225
 }
226 226
 
227
-function wpinv_get_cart_discountable_subtotal( $code_id ) {
227
+function wpinv_get_cart_discountable_subtotal($code_id) {
228 228
     $cart_items = wpinv_get_cart_content_details();
229 229
     $items      = array();
230 230
 
231
-    $excluded_items = wpinv_get_discount_excluded_items( $code_id );
231
+    $excluded_items = wpinv_get_discount_excluded_items($code_id);
232 232
 
233
-    if( $cart_items ) {
233
+    if ($cart_items) {
234 234
 
235
-        foreach( $cart_items as $item ) {
235
+        foreach ($cart_items as $item) {
236 236
 
237
-            if( ! in_array( $item['id'], $excluded_items ) ) {
238
-                $items[] =  $item;
237
+            if (!in_array($item['id'], $excluded_items)) {
238
+                $items[] = $item;
239 239
             }
240 240
         }
241 241
     }
242 242
 
243
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
243
+    $subtotal = wpinv_get_cart_items_subtotal($items);
244 244
 
245
-    return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal );
245
+    return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal);
246 246
 }
247 247
 
248
-function wpinv_get_cart_items_subtotal( $items ) {
248
+function wpinv_get_cart_items_subtotal($items) {
249 249
     $subtotal = 0.00;
250 250
 
251
-    if ( is_array( $items ) && ! empty( $items ) ) {
252
-        $prices = wp_list_pluck( $items, 'subtotal' );
251
+    if (is_array($items) && !empty($items)) {
252
+        $prices = wp_list_pluck($items, 'subtotal');
253 253
 
254
-        if( is_array( $prices ) ) {
255
-            $subtotal = array_sum( $prices );
254
+        if (is_array($prices)) {
255
+            $subtotal = array_sum($prices);
256 256
         } else {
257 257
             $subtotal = 0.00;
258 258
         }
259 259
 
260
-        if( $subtotal < 0 ) {
260
+        if ($subtotal < 0) {
261 261
             $subtotal = 0.00;
262 262
         }
263 263
     }
264 264
 
265
-    return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal );
265
+    return apply_filters('wpinv_get_cart_items_subtotal', $subtotal);
266 266
 }
267 267
 
268
-function wpinv_get_cart_subtotal( $items = array() ) {
269
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
270
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
268
+function wpinv_get_cart_subtotal($items = array()) {
269
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
270
+    $subtotal = wpinv_get_cart_items_subtotal($items);
271 271
 
272
-    return apply_filters( 'wpinv_get_cart_subtotal', $subtotal );
272
+    return apply_filters('wpinv_get_cart_subtotal', $subtotal);
273 273
 }
274 274
 
275
-function wpinv_cart_subtotal( $items = array() ) {
276
-    $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ) );
275
+function wpinv_cart_subtotal($items = array()) {
276
+    $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items)));
277 277
 
278 278
     // Todo - Show tax labels here (if needed)
279 279
 
280 280
     return $price;
281 281
 }
282 282
 
283
-function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) {
284
-    $subtotal  = (float)wpinv_get_cart_subtotal( $items );
285
-    $discounts = (float)wpinv_get_cart_discounted_amount( $items );
286
-    $cart_tax  = (float)wpinv_get_cart_tax( $items );
283
+function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) {
284
+    $subtotal  = (float)wpinv_get_cart_subtotal($items);
285
+    $discounts = (float)wpinv_get_cart_discounted_amount($items);
286
+    $cart_tax  = (float)wpinv_get_cart_tax($items);
287 287
     $fees      = (float)wpinv_get_cart_fee_total();
288
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
288
+    if (!empty($invoice) && $invoice->is_free_trial()) {
289 289
         $total = 0;
290 290
     } else {
291
-        $total     = $subtotal - $discounts + $cart_tax + $fees;
291
+        $total = $subtotal - $discounts + $cart_tax + $fees;
292 292
     }
293 293
 
294
-    if ( $total < 0 ) {
294
+    if ($total < 0) {
295 295
         $total = 0.00;
296 296
     }
297 297
     
298
-    $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items );
298
+    $total = (float)apply_filters('wpinv_get_cart_total', $total, $items);
299 299
 
300
-    return wpinv_sanitize_amount( $total );
300
+    return wpinv_sanitize_amount($total);
301 301
 }
302 302
 
303
-function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) {
303
+function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) {
304 304
     global $cart_total;
305
-    $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ) );
306
-    $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice );
305
+    $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice)));
306
+    $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice);
307 307
 
308 308
     // Todo - Show tax labels here (if needed)
309 309
     
310 310
     $cart_total = $total;
311 311
 
312
-    if ( !$echo ) {
312
+    if (!$echo) {
313 313
         return $total;
314 314
     }
315 315
 
316 316
     echo $total;
317 317
 }
318 318
 
319
-function wpinv_get_cart_tax( $items = array() ) {
319
+function wpinv_get_cart_tax($items = array()) {
320 320
     $cart_tax = 0;
321
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
321
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
322 322
 
323
-    if ( $items ) {
324
-        $taxes = wp_list_pluck( $items, 'tax' );
323
+    if ($items) {
324
+        $taxes = wp_list_pluck($items, 'tax');
325 325
 
326
-        if( is_array( $taxes ) ) {
327
-            $cart_tax = array_sum( $taxes );
326
+        if (is_array($taxes)) {
327
+            $cart_tax = array_sum($taxes);
328 328
         }
329 329
     }
330 330
 
331 331
     $cart_tax += wpinv_get_cart_fee_tax();
332 332
 
333
-    return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) );
333
+    return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax));
334 334
 }
335 335
 
336
-function wpinv_cart_tax( $items = array(), $echo = false ) {
337
-    $cart_tax = wpinv_get_cart_tax( $items );
338
-    $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ) );
336
+function wpinv_cart_tax($items = array(), $echo = false) {
337
+    $cart_tax = wpinv_get_cart_tax($items);
338
+    $cart_tax = wpinv_price(wpinv_format_amount($cart_tax));
339 339
 
340
-    $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items );
340
+    $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items);
341 341
 
342
-    if ( !$echo ) {
342
+    if (!$echo) {
343 343
         return $tax;
344 344
     }
345 345
 
346 346
     echo $tax;
347 347
 }
348 348
 
349
-function wpinv_get_cart_discount_code( $items = array() ) {
349
+function wpinv_get_cart_discount_code($items = array()) {
350 350
     $invoice = wpinv_get_invoice_cart();
351
-    $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : '';
351
+    $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : '';
352 352
     
353
-    return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code );
353
+    return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code);
354 354
 }
355 355
 
356
-function wpinv_cart_discount_code( $items = array(), $echo = false ) {
357
-    $cart_discount_code = wpinv_get_cart_discount_code( $items );
356
+function wpinv_cart_discount_code($items = array(), $echo = false) {
357
+    $cart_discount_code = wpinv_get_cart_discount_code($items);
358 358
 
359
-    if ( $cart_discount_code != '' ) {
359
+    if ($cart_discount_code != '') {
360 360
         $cart_discount_code = ' (' . $cart_discount_code . ')';
361 361
     }
362 362
     
363
-    $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items );
363
+    $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items);
364 364
 
365
-    if ( !$echo ) {
365
+    if (!$echo) {
366 366
         return $discount_code;
367 367
     }
368 368
 
369 369
     echo $discount_code;
370 370
 }
371 371
 
372
-function wpinv_get_cart_discount( $items = array() ) {
372
+function wpinv_get_cart_discount($items = array()) {
373 373
     $invoice = wpinv_get_invoice_cart();
374
-    $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0;
374
+    $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0;
375 375
     
376
-    return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items );
376
+    return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items);
377 377
 }
378 378
 
379
-function wpinv_cart_discount( $items = array(), $echo = false ) {
380
-    $cart_discount = wpinv_get_cart_discount( $items );
381
-    $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) );
379
+function wpinv_cart_discount($items = array(), $echo = false) {
380
+    $cart_discount = wpinv_get_cart_discount($items);
381
+    $cart_discount = wpinv_price(wpinv_format_amount($cart_discount));
382 382
 
383
-    $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items );
383
+    $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items);
384 384
 
385
-    if ( !$echo ) {
385
+    if (!$echo) {
386 386
         return $discount;
387 387
     }
388 388
 
389 389
     echo $discount;
390 390
 }
391 391
 
392
-function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) {
393
-    $item = new WPInv_Item( $item_id );
392
+function wpinv_get_cart_fees($type = 'all', $item_id = 0) {
393
+    $item = new WPInv_Item($item_id);
394 394
     
395
-    return $item->get_fees( $type, $item_id );
395
+    return $item->get_fees($type, $item_id);
396 396
 }
397 397
 
398 398
 function wpinv_get_cart_fee_total() {
399
-    $total  = 0;
399
+    $total = 0;
400 400
     $fees = wpinv_get_cart_fees();
401 401
     
402
-    if ( $fees ) {
403
-        foreach ( $fees as $fee_id => $fee ) {
402
+    if ($fees) {
403
+        foreach ($fees as $fee_id => $fee) {
404 404
             $total += $fee['amount'];
405 405
         }
406 406
     }
407 407
 
408
-    return apply_filters( 'wpinv_get_cart_fee_total', $total );
408
+    return apply_filters('wpinv_get_cart_fee_total', $total);
409 409
 }
410 410
 
411 411
 function wpinv_get_cart_fee_tax() {
412 412
     $tax  = 0;
413 413
     $fees = wpinv_get_cart_fees();
414 414
 
415
-    if ( $fees ) {
416
-        foreach ( $fees as $fee_id => $fee ) {
417
-            if( ! empty( $fee['no_tax'] ) ) {
415
+    if ($fees) {
416
+        foreach ($fees as $fee_id => $fee) {
417
+            if (!empty($fee['no_tax'])) {
418 418
                 continue;
419 419
             }
420 420
 
421
-            $tax += wpinv_calculate_tax( $fee['amount'] );
421
+            $tax += wpinv_calculate_tax($fee['amount']);
422 422
         }
423 423
     }
424 424
 
425
-    return apply_filters( 'wpinv_get_cart_fee_tax', $tax );
425
+    return apply_filters('wpinv_get_cart_fee_tax', $tax);
426 426
 }
427 427
 
428 428
 function wpinv_cart_has_recurring_item() {
429 429
     $cart_items = wpinv_get_cart_contents();
430 430
     
431
-    if ( empty( $cart_items ) ) {
431
+    if (empty($cart_items)) {
432 432
         return false;
433 433
     }
434 434
     
435 435
     $has_subscription = false;
436
-    foreach( $cart_items as $cart_item ) {
437
-        if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
436
+    foreach ($cart_items as $cart_item) {
437
+        if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
438 438
             $has_subscription = true;
439 439
             break;
440 440
         }
441 441
     }
442 442
     
443
-    return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items );
443
+    return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items);
444 444
 }
445 445
 
446 446
 function wpinv_cart_has_free_trial() {
@@ -448,85 +448,85 @@  discard block
 block discarded – undo
448 448
     
449 449
     $free_trial = false;
450 450
     
451
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
451
+    if (!empty($invoice) && $invoice->is_free_trial()) {
452 452
         $free_trial = true;
453 453
     }
454 454
     
455
-    return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice );
455
+    return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice);
456 456
 }
457 457
 
458 458
 function wpinv_get_cart_contents() {
459 459
     $cart_details = wpinv_get_cart_details();
460 460
     
461
-    return apply_filters( 'wpinv_get_cart_contents', $cart_details );
461
+    return apply_filters('wpinv_get_cart_contents', $cart_details);
462 462
 }
463 463
 
464 464
 function wpinv_get_cart_content_details() {
465 465
     global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
466 466
     $cart_items = wpinv_get_cart_contents();
467 467
     
468
-    if ( empty( $cart_items ) ) {
468
+    if (empty($cart_items)) {
469 469
         return false;
470 470
     }
471 471
     $invoice = wpinv_get_invoice_cart();
472 472
 
473 473
     $details = array();
474
-    $length  = count( $cart_items ) - 1;
474
+    $length  = count($cart_items) - 1;
475 475
     
476
-    if ( empty( $_POST['country'] ) ) {
476
+    if (empty($_POST['country'])) {
477 477
         $_POST['country'] = $invoice->country;
478 478
     }
479
-    if ( !isset( $_POST['state'] ) ) {
479
+    if (!isset($_POST['state'])) {
480 480
         $_POST['state'] = $invoice->state;
481 481
     }
482 482
 
483
-    foreach( $cart_items as $key => $item ) {
484
-        $item_id            = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : '';
485
-        if ( empty( $item_id ) ) {
483
+    foreach ($cart_items as $key => $item) {
484
+        $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : '';
485
+        if (empty($item_id)) {
486 486
             continue;
487 487
         }
488 488
         
489 489
         $wpi_current_id         = $invoice->ID;
490 490
         $wpi_item_id            = $item_id;
491 491
         
492
-        $item_price         = wpinv_get_item_price( $item_id );
493
-        $discount           = wpinv_get_cart_item_discount_amount( $item );
494
-        $discount           = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item );
495
-        $quantity           = wpinv_get_cart_item_quantity( $item );
496
-        $fees               = wpinv_get_cart_fees( 'fee', $item_id );
492
+        $item_price         = wpinv_get_item_price($item_id);
493
+        $discount           = wpinv_get_cart_item_discount_amount($item);
494
+        $discount           = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item);
495
+        $quantity           = wpinv_get_cart_item_quantity($item);
496
+        $fees               = wpinv_get_cart_fees('fee', $item_id);
497 497
         
498 498
         $subtotal           = $item_price * $quantity;
499
-        $tax_rate           = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id );
500
-        $tax_class          = $wpinv_euvat->get_item_class( $item_id );
501
-        $tax                = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount );
499
+        $tax_rate           = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id);
500
+        $tax_class          = $wpinv_euvat->get_item_class($item_id);
501
+        $tax                = wpinv_get_cart_item_tax($item_id, $subtotal - $discount);
502 502
         
503
-        if ( wpinv_prices_include_tax() ) {
504
-            $subtotal -= wpinv_format_amount( $tax, NULL, true );
503
+        if (wpinv_prices_include_tax()) {
504
+            $subtotal -= wpinv_format_amount($tax, NULL, true);
505 505
         }
506 506
         
507
-        $total              = $subtotal - $discount + $tax;
507
+        $total = $subtotal - $discount + $tax;
508 508
         
509 509
         // Do not allow totals to go negatve
510
-        if( $total < 0 ) {
510
+        if ($total < 0) {
511 511
             $total = 0;
512 512
         }
513 513
         
514
-        $details[ $key ]  = array(
514
+        $details[$key] = array(
515 515
             'id'                => $item_id,
516
-            'name'              => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ),
517
-            'item_price'        => wpinv_format_amount( $item_price, NULL, true ),
516
+            'name'              => !empty($item['name']) ? $item['name'] : get_the_title($item_id),
517
+            'item_price'        => wpinv_format_amount($item_price, NULL, true),
518 518
             'quantity'          => $quantity,
519
-            'discount'          => wpinv_format_amount( $discount, NULL, true ),
520
-            'subtotal'          => wpinv_format_amount( $subtotal, NULL, true ),
521
-            'tax'               => wpinv_format_amount( $tax, NULL, true ),
522
-            'price'             => wpinv_format_amount( $total, NULL, true ),
519
+            'discount'          => wpinv_format_amount($discount, NULL, true),
520
+            'subtotal'          => wpinv_format_amount($subtotal, NULL, true),
521
+            'tax'               => wpinv_format_amount($tax, NULL, true),
522
+            'price'             => wpinv_format_amount($total, NULL, true),
523 523
             'vat_rates_class'   => $tax_class,
524
-            'vat_rate'          => wpinv_format_amount( $tax_rate, NULL, true ),
525
-            'meta'              => isset( $item['meta'] ) ? $item['meta'] : array(),
524
+            'vat_rate'          => wpinv_format_amount($tax_rate, NULL, true),
525
+            'meta'              => isset($item['meta']) ? $item['meta'] : array(),
526 526
             'fees'              => $fees,
527 527
         );
528 528
         
529
-        if ( $wpinv_is_last_cart_item ) {
529
+        if ($wpinv_is_last_cart_item) {
530 530
             $wpinv_is_last_cart_item   = false;
531 531
             $wpinv_flat_discount_total = 0.00;
532 532
         }
@@ -535,56 +535,56 @@  discard block
 block discarded – undo
535 535
     return $details;
536 536
 }
537 537
 
538
-function wpinv_get_cart_details( $invoice_id = 0 ) {
538
+function wpinv_get_cart_details($invoice_id = 0) {
539 539
     global $ajax_cart_details;
540 540
 
541
-    $invoice      = wpinv_get_invoice_cart( $invoice_id );
542
-    $cart_details = !empty( $ajax_cart_details ) ? $ajax_cart_details : $invoice->cart_details;
541
+    $invoice      = wpinv_get_invoice_cart($invoice_id);
542
+    $cart_details = !empty($ajax_cart_details) ? $ajax_cart_details : $invoice->cart_details;
543 543
 
544 544
     $invoice_currency = $invoice->currency;
545 545
 
546
-    if ( ! empty( $cart_details ) && is_array( $cart_details ) ) {
547
-        foreach ( $cart_details as $key => $cart_item ) {
548
-            $cart_details[ $key ]['currency'] = $invoice_currency;
546
+    if (!empty($cart_details) && is_array($cart_details)) {
547
+        foreach ($cart_details as $key => $cart_item) {
548
+            $cart_details[$key]['currency'] = $invoice_currency;
549 549
 
550
-            if ( ! isset( $cart_item['subtotal'] ) ) {
551
-                $cart_details[ $key ]['subtotal'] = $cart_item['price'];
550
+            if (!isset($cart_item['subtotal'])) {
551
+                $cart_details[$key]['subtotal'] = $cart_item['price'];
552 552
             }
553 553
         }
554 554
     }
555 555
 
556
-    return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id );
556
+    return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id);
557 557
 }
558 558
 
559
-function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) {
560
-    $invoice    = wpinv_get_invoice( $invoice_id );
559
+function wpinv_record_status_change($invoice_id, $new_status, $old_status) {
560
+    $invoice    = wpinv_get_invoice($invoice_id);
561 561
     
562
-    $old_status = wpinv_status_nicename( $old_status );
563
-    $new_status = wpinv_status_nicename( $new_status );
562
+    $old_status = wpinv_status_nicename($old_status);
563
+    $new_status = wpinv_status_nicename($new_status);
564 564
 
565
-    $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status );
565
+    $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status);
566 566
     
567 567
     // Add note
568
-    return $invoice->add_note( $status_change, 0 );
568
+    return $invoice->add_note($status_change, 0);
569 569
 }
570
-add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 );
570
+add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3);
571 571
 
572
-function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) {
572
+function wpinv_complete_payment($invoice_id, $new_status, $old_status) {
573 573
     global $wpi_has_free_trial;
574 574
     
575 575
     $wpi_has_free_trial = false;
576 576
     
577
-    if ( $old_status == 'publish' || $old_status == 'complete' ) {
577
+    if ($old_status == 'publish' || $old_status == 'complete') {
578 578
         return; // Make sure that payments are only paid once
579 579
     }
580 580
 
581 581
     // Make sure the payment completion is only processed when new status is paid
582
-    if ( $new_status != 'publish' && $new_status != 'complete' ) {
582
+    if ($new_status != 'publish' && $new_status != 'complete') {
583 583
         return;
584 584
     }
585 585
 
586
-    $invoice = new WPInv_Invoice( $invoice_id );
587
-    if ( empty( $invoice ) ) {
586
+    $invoice = new WPInv_Invoice($invoice_id);
587
+    if (empty($invoice)) {
588 588
         return;
589 589
     }
590 590
 
@@ -592,58 +592,58 @@  discard block
 block discarded – undo
592 592
     $completed_date = $invoice->completed_date;
593 593
     $cart_details   = $invoice->cart_details;
594 594
 
595
-    do_action( 'wpinv_pre_complete_payment', $invoice_id );
595
+    do_action('wpinv_pre_complete_payment', $invoice_id);
596 596
 
597
-    if ( is_array( $cart_details ) ) {
597
+    if (is_array($cart_details)) {
598 598
         // Increase purchase count and earnings
599
-        foreach ( $cart_details as $cart_index => $item ) {
599
+        foreach ($cart_details as $cart_index => $item) {
600 600
             // Ensure these actions only run once, ever
601
-            if ( empty( $completed_date ) ) {
602
-                do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index );
601
+            if (empty($completed_date)) {
602
+                do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index);
603 603
             }
604 604
         }
605 605
     }
606 606
     
607 607
     // Check for discount codes and increment their use counts
608
-    if ( $discounts = $invoice->get_discounts( true ) ) {
609
-        if( ! empty( $discounts ) ) {
610
-            foreach( $discounts as $code ) {
611
-                wpinv_increase_discount_usage( $code );
608
+    if ($discounts = $invoice->get_discounts(true)) {
609
+        if (!empty($discounts)) {
610
+            foreach ($discounts as $code) {
611
+                wpinv_increase_discount_usage($code);
612 612
             }
613 613
         }
614 614
     }
615 615
     
616 616
     // Ensure this action only runs once ever
617
-    if( empty( $completed_date ) ) {
617
+    if (empty($completed_date)) {
618 618
         // Save the completed date
619
-        $invoice->set( 'completed_date', current_time( 'mysql', 0 ) );
619
+        $invoice->set('completed_date', current_time('mysql', 0));
620 620
         $invoice->save();
621 621
 
622
-        do_action( 'wpinv_complete_payment', $invoice_id );
622
+        do_action('wpinv_complete_payment', $invoice_id);
623 623
     }
624 624
 
625 625
     // Empty the shopping cart
626 626
     wpinv_empty_cart();
627 627
 }
628
-add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 );
628
+add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3);
629 629
 
630
-function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) {    
631
-    $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id );
630
+function wpinv_update_payment_status($invoice_id, $new_status = 'publish') {    
631
+    $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int)$invoice_id);
632 632
     
633
-    if ( empty( $invoice ) ) {
633
+    if (empty($invoice)) {
634 634
         return false;
635 635
     }
636 636
     
637
-    return $invoice->update_status( $new_status );
637
+    return $invoice->update_status($new_status);
638 638
 }
639 639
 
640
-function wpinv_cart_has_fees( $type = 'all' ) {
640
+function wpinv_cart_has_fees($type = 'all') {
641 641
     return false;
642 642
 }
643 643
 
644 644
 function wpinv_validate_checkout_fields() {    
645 645
     // Check if there is $_POST
646
-    if ( empty( $_POST ) ) {
646
+    if (empty($_POST)) {
647 647
         return false;
648 648
     }
649 649
     
@@ -655,11 +655,11 @@  discard block
 block discarded – undo
655 655
     );
656 656
     
657 657
     // Validate agree to terms
658
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
658
+    if (wpinv_get_option('show_agree_to_terms', false)) {
659 659
         wpinv_checkout_validate_agree_to_terms();
660 660
     }
661 661
     
662
-    $valid_data['logged_in_user']   = wpinv_checkout_validate_logged_in_user();
662
+    $valid_data['logged_in_user'] = wpinv_checkout_validate_logged_in_user();
663 663
     
664 664
     // Return collected data
665 665
     return $valid_data;
@@ -671,20 +671,20 @@  discard block
 block discarded – undo
671 671
     $has_subscription = wpinv_cart_has_recurring_item();
672 672
 
673 673
     // Check if a gateway value is present
674
-    if ( !empty( $_REQUEST['wpi-gateway'] ) ) {
675
-        $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] );
674
+    if (!empty($_REQUEST['wpi-gateway'])) {
675
+        $gateway = sanitize_text_field($_REQUEST['wpi-gateway']);
676 676
 
677
-        if ( '0.00' == wpinv_get_cart_total() ) {
677
+        if ('0.00' == wpinv_get_cart_total()) {
678 678
             $gateway = 'manual';
679
-        } elseif ( !wpinv_is_gateway_active( $gateway ) ) {
680
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) );
681
-        } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) {
682
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway doesnot support subscription payment', 'invoicing' ) );
679
+        } elseif (!wpinv_is_gateway_active($gateway)) {
680
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing'));
681
+        } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) {
682
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway doesnot support subscription payment', 'invoicing'));
683 683
         }
684 684
     }
685 685
 
686
-    if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) {
687
-        wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) );
686
+    if ($has_subscription && count(wpinv_get_cart_contents()) > 1) {
687
+        wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing'));
688 688
     }
689 689
 
690 690
     return $gateway;
@@ -696,10 +696,10 @@  discard block
 block discarded – undo
696 696
     
697 697
     $error = false;
698 698
     // If we have discounts, loop through them
699
-    if ( ! empty( $discounts ) ) {
700
-        foreach ( $discounts as $discount ) {
699
+    if (!empty($discounts)) {
700
+        foreach ($discounts as $discount) {
701 701
             // Check if valid
702
-            if (  !wpinv_is_discount_valid( $discount, get_current_user_id() ) ) {
702
+            if (!wpinv_is_discount_valid($discount, get_current_user_id())) {
703 703
                 // Discount is not valid
704 704
                 $error = true;
705 705
             }
@@ -709,20 +709,20 @@  discard block
 block discarded – undo
709 709
         return NULL;
710 710
     }
711 711
 
712
-    if ( $error && !wpinv_get_errors() ) {
713
-        wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) );
712
+    if ($error && !wpinv_get_errors()) {
713
+        wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing'));
714 714
     }
715 715
 
716
-    return implode( ',', $discounts );
716
+    return implode(',', $discounts);
717 717
 }
718 718
 
719 719
 function wpinv_checkout_validate_cc() {
720 720
     $card_data = wpinv_checkout_get_cc_info();
721 721
 
722 722
     // Validate the card zip
723
-    if ( !empty( $card_data['wpinv_zip'] ) ) {
724
-        if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) {
725
-            wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) );
723
+    if (!empty($card_data['wpinv_zip'])) {
724
+        if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) {
725
+            wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing'));
726 726
         }
727 727
     }
728 728
 
@@ -732,28 +732,28 @@  discard block
 block discarded – undo
732 732
 
733 733
 function wpinv_checkout_get_cc_info() {
734 734
 	$cc_info = array();
735
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
736
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
737
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
738
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
739
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
740
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
741
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
742
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
743
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
744
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
735
+	$cc_info['card_name']      = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : '';
736
+	$cc_info['card_number']    = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : '';
737
+	$cc_info['card_cvc']       = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : '';
738
+	$cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : '';
739
+	$cc_info['card_exp_year']  = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : '';
740
+	$cc_info['card_address']   = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : '';
741
+	$cc_info['card_city']      = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : '';
742
+	$cc_info['card_state']     = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : '';
743
+	$cc_info['card_country']   = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : '';
744
+	$cc_info['card_zip']       = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : '';
745 745
 
746 746
 	// Return cc info
747 747
 	return $cc_info;
748 748
 }
749 749
 
750
-function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
750
+function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') {
751 751
     $ret = false;
752 752
 
753
-    if ( empty( $zip ) || empty( $country_code ) )
753
+    if (empty($zip) || empty($country_code))
754 754
         return $ret;
755 755
 
756
-    $country_code = strtoupper( $country_code );
756
+    $country_code = strtoupper($country_code);
757 757
 
758 758
     $zip_regex = array(
759 759
         "AD" => "AD\d{3}",
@@ -913,17 +913,17 @@  discard block
 block discarded – undo
913 913
         "ZM" => "\d{5}"
914 914
     );
915 915
 
916
-    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) )
916
+    if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip))
917 917
         $ret = true;
918 918
 
919
-    return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code );
919
+    return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code);
920 920
 }
921 921
 
922 922
 function wpinv_checkout_validate_agree_to_terms() {
923 923
     // Validate agree to terms
924
-    if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) {
924
+    if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) {
925 925
         // User did not agree
926
-        wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) );
926
+        wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing')));
927 927
     }
928 928
 }
929 929
 
@@ -936,36 +936,36 @@  discard block
 block discarded – undo
936 936
     );
937 937
     
938 938
     // Verify there is a user_ID
939
-    if ( $user_ID > 0 ) {
939
+    if ($user_ID > 0) {
940 940
         // Get the logged in user data
941
-        $user_data = get_userdata( $user_ID );
942
-        $required_fields  = wpinv_checkout_required_fields();
941
+        $user_data = get_userdata($user_ID);
942
+        $required_fields = wpinv_checkout_required_fields();
943 943
 
944 944
         // Loop through required fields and show error messages
945
-         if ( !empty( $required_fields ) ) {
946
-            foreach ( $required_fields as $field_name => $value ) {
947
-                if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
948
-                    wpinv_set_error( $value['error_id'], $value['error_message'] );
945
+         if (!empty($required_fields)) {
946
+            foreach ($required_fields as $field_name => $value) {
947
+                if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) {
948
+                    wpinv_set_error($value['error_id'], $value['error_message']);
949 949
                 }
950 950
             }
951 951
         }
952 952
 
953 953
         // Verify data
954
-        if ( $user_data ) {
954
+        if ($user_data) {
955 955
             // Collected logged in user data
956 956
             $valid_user_data = array(
957 957
                 'user_id'     => $user_ID,
958
-                'email'       => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email,
959
-                'first_name'  => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name,
960
-                'last_name'   => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name']  ) ? sanitize_text_field( $_POST['wpinv_last_name']  ) : $user_data->last_name,
958
+                'email'       => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email,
959
+                'first_name'  => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name,
960
+                'last_name'   => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name,
961 961
             );
962 962
 
963
-            if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) {
964
-                wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) );
963
+            if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) {
964
+                wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing'));
965 965
             }
966 966
         } else {
967 967
             // Set invalid user error
968
-            wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) );
968
+            wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing'));
969 969
         }
970 970
     }
971 971
 
@@ -973,21 +973,21 @@  discard block
 block discarded – undo
973 973
     return $valid_user_data;
974 974
 }
975 975
 
976
-function wpinv_checkout_form_get_user( $valid_data = array() ) {
976
+function wpinv_checkout_form_get_user($valid_data = array()) {
977 977
     // Initialize user
978 978
     $user    = false;
979
-    $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
979
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
980 980
 
981 981
     /*if ( $is_ajax ) {
982 982
         // Do not create or login the user during the ajax submission (check for errors only)
983 983
         return true;
984
-    } else */if ( is_user_logged_in() ) {
984
+    } else */if (is_user_logged_in()) {
985 985
         // Set the valid user as the logged in collected data
986 986
         $user = $valid_data['logged_in_user'];
987 987
     }
988 988
 
989 989
     // Verify we have an user
990
-    if ( false === $user || empty( $user ) ) {
990
+    if (false === $user || empty($user)) {
991 991
         // Return false
992 992
         return false;
993 993
     }
@@ -1006,11 +1006,11 @@  discard block
 block discarded – undo
1006 1006
         'zip',
1007 1007
     );
1008 1008
     
1009
-    foreach ( $address_fields as $field ) {
1010
-        $user[$field]  = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false;
1009
+    foreach ($address_fields as $field) {
1010
+        $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false;
1011 1011
         
1012
-        if ( !empty( $user['user_id'] ) ) {
1013
-            update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] );
1012
+        if (!empty($user['user_id'])) {
1013
+            update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]);
1014 1014
         }
1015 1015
     }
1016 1016
 
@@ -1018,28 +1018,28 @@  discard block
 block discarded – undo
1018 1018
     return $user;
1019 1019
 }
1020 1020
 
1021
-function wpinv_set_checkout_session( $invoice_data = array() ) {
1021
+function wpinv_set_checkout_session($invoice_data = array()) {
1022 1022
     global $wpi_session;
1023 1023
     
1024
-    return $wpi_session->set( 'wpinv_checkout', $invoice_data );
1024
+    return $wpi_session->set('wpinv_checkout', $invoice_data);
1025 1025
 }
1026 1026
 
1027 1027
 function wpinv_get_checkout_session() {
1028 1028
 	global $wpi_session;
1029 1029
     
1030
-    return $wpi_session->get( 'wpinv_checkout' );
1030
+    return $wpi_session->get('wpinv_checkout');
1031 1031
 }
1032 1032
 
1033 1033
 function wpinv_empty_cart() {
1034 1034
     global $wpi_session;
1035 1035
 
1036 1036
     // Remove cart contents
1037
-    $wpi_session->set( 'wpinv_checkout', NULL );
1037
+    $wpi_session->set('wpinv_checkout', NULL);
1038 1038
 
1039 1039
     // Remove all cart fees
1040
-    $wpi_session->set( 'wpi_cart_fees', NULL );
1040
+    $wpi_session->set('wpi_cart_fees', NULL);
1041 1041
 
1042
-    do_action( 'wpinv_empty_cart' );
1042
+    do_action('wpinv_empty_cart');
1043 1043
 }
1044 1044
 
1045 1045
 function wpinv_process_checkout() {
@@ -1051,42 +1051,42 @@  discard block
 block discarded – undo
1051 1051
     
1052 1052
     $wpi_checkout_id = $invoice->ID;
1053 1053
     
1054
-    do_action( 'wpinv_pre_process_checkout' );
1054
+    do_action('wpinv_pre_process_checkout');
1055 1055
     
1056
-    if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty
1056
+    if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty
1057 1057
         $valid_data = false;
1058
-        wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) );
1058
+        wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing'));
1059 1059
     } else {
1060 1060
         // Validate the form $_POST data
1061 1061
         $valid_data = wpinv_validate_checkout_fields();
1062 1062
         
1063 1063
         // Allow themes and plugins to hook to errors
1064
-        do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST );
1064
+        do_action('wpinv_checkout_error_checks', $valid_data, $_POST);
1065 1065
     }
1066 1066
     
1067
-    $is_ajax    = defined( 'DOING_AJAX' ) && DOING_AJAX;
1067
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1068 1068
     
1069 1069
     // Validate the user
1070
-    $user = wpinv_checkout_form_get_user( $valid_data );
1070
+    $user = wpinv_checkout_form_get_user($valid_data);
1071 1071
 
1072 1072
     // Let extensions validate fields after user is logged in if user has used login/registration form
1073
-    do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST );
1073
+    do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST);
1074 1074
     
1075
-    if ( false === $valid_data || wpinv_get_errors() || ! $user ) {
1076
-        if ( $is_ajax ) {
1077
-            do_action( 'wpinv_ajax_checkout_errors' );
1075
+    if (false === $valid_data || wpinv_get_errors() || !$user) {
1076
+        if ($is_ajax) {
1077
+            do_action('wpinv_ajax_checkout_errors');
1078 1078
             die();
1079 1079
         } else {
1080 1080
             return false;
1081 1081
         }
1082 1082
     }
1083 1083
 
1084
-    if ( $is_ajax ) {
1084
+    if ($is_ajax) {
1085 1085
         // Save address fields.
1086
-        $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' );
1087
-        foreach ( $address_fields as $field ) {
1088
-            if ( isset( $user[$field] ) ) {
1089
-                $invoice->set( $field, $user[$field] );
1086
+        $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company');
1087
+        foreach ($address_fields as $field) {
1088
+            if (isset($user[$field])) {
1089
+                $invoice->set($field, $user[$field]);
1090 1090
             }
1091 1091
             
1092 1092
             $invoice->save();
@@ -1094,15 +1094,15 @@  discard block
 block discarded – undo
1094 1094
 
1095 1095
         $response['success']            = true;
1096 1096
         $response['data']['subtotal']   = $invoice->get_subtotal();
1097
-        $response['data']['subtotalf']  = $invoice->get_subtotal( true );
1097
+        $response['data']['subtotalf']  = $invoice->get_subtotal(true);
1098 1098
         $response['data']['discount']   = $invoice->get_discount();
1099
-        $response['data']['discountf']  = $invoice->get_discount( true );
1099
+        $response['data']['discountf']  = $invoice->get_discount(true);
1100 1100
         $response['data']['tax']        = $invoice->get_tax();
1101
-        $response['data']['taxf']       = $invoice->get_tax( true );
1101
+        $response['data']['taxf']       = $invoice->get_tax(true);
1102 1102
         $response['data']['total']      = $invoice->get_total();
1103
-        $response['data']['totalf']     = $invoice->get_total( true );
1103
+        $response['data']['totalf']     = $invoice->get_total(true);
1104 1104
         
1105
-        wp_send_json( $response );
1105
+        wp_send_json($response);
1106 1106
     }
1107 1107
     
1108 1108
     $user_info = array(
@@ -1124,42 +1124,42 @@  discard block
 block discarded – undo
1124 1124
     
1125 1125
     // Setup invoice information
1126 1126
     $invoice_data = array(
1127
-        'invoice_id'        => !empty( $invoice ) ? $invoice->ID : 0,
1127
+        'invoice_id'        => !empty($invoice) ? $invoice->ID : 0,
1128 1128
         'items'             => $cart_items,
1129 1129
         'cart_discounts'    => $discounts,
1130
-        'fees'              => wpinv_get_cart_fees(),        // Any arbitrary fees that have been added to the cart
1131
-        'subtotal'          => wpinv_get_cart_subtotal( $cart_items ),    // Amount before taxes and discounts
1132
-        'discount'          => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount
1133
-        'tax'               => wpinv_get_cart_tax( $cart_items ),               // Taxed amount
1134
-        'price'             => wpinv_get_cart_total( $cart_items, $discounts ),    // Amount after taxes
1130
+        'fees'              => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart
1131
+        'subtotal'          => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts
1132
+        'discount'          => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount
1133
+        'tax'               => wpinv_get_cart_tax($cart_items), // Taxed amount
1134
+        'price'             => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes
1135 1135
         'invoice_key'       => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(),
1136 1136
         'user_email'        => $user['email'],
1137
-        'date'              => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
1138
-        'user_info'         => stripslashes_deep( $user_info ),
1137
+        'date'              => date('Y-m-d H:i:s', current_time('timestamp')),
1138
+        'user_info'         => stripslashes_deep($user_info),
1139 1139
         'post_data'         => $_POST,
1140 1140
         'cart_details'      => $cart_items,
1141 1141
         'gateway'           => $valid_data['gateway'],
1142 1142
         'card_info'         => $valid_data['cc_info']
1143 1143
     );
1144 1144
     
1145
-    $vat_info   = $wpinv_euvat->current_vat_data();
1146
-    if ( is_array( $vat_info ) ) {
1145
+    $vat_info = $wpinv_euvat->current_vat_data();
1146
+    if (is_array($vat_info)) {
1147 1147
         $invoice_data['user_info']['vat_number']        = $vat_info['number'];
1148 1148
         $invoice_data['user_info']['vat_rate']          = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']);
1149
-        $invoice_data['user_info']['adddress_confirmed']    = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1149
+        $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1150 1150
 
1151 1151
         // Add the VAT rate to each item in the cart
1152
-        foreach( $invoice_data['cart_details'] as $key => $item_data) {
1152
+        foreach ($invoice_data['cart_details'] as $key => $item_data) {
1153 1153
             $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']);
1154
-            $invoice_data['cart_details'][$key]['vat_rate'] = round( $rate, 3 );
1154
+            $invoice_data['cart_details'][$key]['vat_rate'] = round($rate, 3);
1155 1155
         }
1156 1156
     }
1157 1157
     
1158 1158
     // Save vat fields.
1159
-    $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' );
1160
-    foreach ( $address_fields as $field ) {
1161
-        if ( isset( $invoice_data['user_info'][$field] ) ) {
1162
-            $invoice->set( $field, $invoice_data['user_info'][$field] );
1159
+    $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed');
1160
+    foreach ($address_fields as $field) {
1161
+        if (isset($invoice_data['user_info'][$field])) {
1162
+            $invoice->set($field, $invoice_data['user_info'][$field]);
1163 1163
         }
1164 1164
         
1165 1165
         $invoice->save();
@@ -1169,49 +1169,49 @@  discard block
 block discarded – undo
1169 1169
     $valid_data['user'] = $user;
1170 1170
     
1171 1171
     // Allow themes and plugins to hook before the gateway
1172
-    do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data );
1172
+    do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data);
1173 1173
     
1174 1174
     // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice
1175
-    if ( !$invoice_data['price'] ) {
1175
+    if (!$invoice_data['price']) {
1176 1176
         // Revert to manual
1177 1177
         $invoice_data['gateway'] = 'manual';
1178 1178
         $_POST['wpi-gateway'] = 'manual';
1179 1179
     }
1180 1180
     
1181 1181
     // Allow the invoice data to be modified before it is sent to the gateway
1182
-    $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data );
1182
+    $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data);
1183 1183
     
1184 1184
     // Setup the data we're storing in the purchase session
1185 1185
     $session_data = $invoice_data;
1186 1186
     // Make sure credit card numbers are never stored in sessions
1187
-    if ( !empty( $session_data['card_info']['card_number'] ) ) {
1188
-        unset( $session_data['card_info']['card_number'] );
1187
+    if (!empty($session_data['card_info']['card_number'])) {
1188
+        unset($session_data['card_info']['card_number']);
1189 1189
     }
1190 1190
     
1191 1191
     // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data.
1192
-    wpinv_set_checkout_session( $invoice_data );
1192
+    wpinv_set_checkout_session($invoice_data);
1193 1193
     
1194 1194
     // Set gateway
1195
-    $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] );
1196
-    $invoice->update_meta( '_wpinv_mode', ( wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live' ) );
1197
-    $invoice->update_meta( '_wpinv_checkout', true );
1195
+    $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']);
1196
+    $invoice->update_meta('_wpinv_mode', (wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live'));
1197
+    $invoice->update_meta('_wpinv_checkout', true);
1198 1198
     
1199
-    do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data );
1199
+    do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data);
1200 1200
 
1201 1201
     // Send info to the gateway for payment processing
1202
-    wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data );
1202
+    wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data);
1203 1203
     die();
1204 1204
 }
1205
-add_action( 'wpinv_payment', 'wpinv_process_checkout' );
1205
+add_action('wpinv_payment', 'wpinv_process_checkout');
1206 1206
 
1207
-function wpinv_get_invoices( $args ) {
1208
-    $args = wp_parse_args( $args, array(
1209
-        'status'   => array_keys( wpinv_get_invoice_statuses() ),
1207
+function wpinv_get_invoices($args) {
1208
+    $args = wp_parse_args($args, array(
1209
+        'status'   => array_keys(wpinv_get_invoice_statuses()),
1210 1210
         'type'     => 'wpi_invoice',
1211 1211
         'parent'   => null,
1212 1212
         'user'     => null,
1213 1213
         'email'    => '',
1214
-        'limit'    => get_option( 'posts_per_page' ),
1214
+        'limit'    => get_option('posts_per_page'),
1215 1215
         'offset'   => null,
1216 1216
         'page'     => 1,
1217 1217
         'exclude'  => array(),
@@ -1219,7 +1219,7 @@  discard block
 block discarded – undo
1219 1219
         'order'    => 'DESC',
1220 1220
         'return'   => 'objects',
1221 1221
         'paginate' => false,
1222
-    ) );
1222
+    ));
1223 1223
     
1224 1224
     // Handle some BW compatibility arg names where wp_query args differ in naming.
1225 1225
     $map_legacy = array(
@@ -1232,18 +1232,18 @@  discard block
 block discarded – undo
1232 1232
         'paged'          => 'page',
1233 1233
     );
1234 1234
 
1235
-    foreach ( $map_legacy as $from => $to ) {
1236
-        if ( isset( $args[ $from ] ) ) {
1237
-            $args[ $to ] = $args[ $from ];
1235
+    foreach ($map_legacy as $from => $to) {
1236
+        if (isset($args[$from])) {
1237
+            $args[$to] = $args[$from];
1238 1238
         }
1239 1239
     }
1240 1240
     
1241
-    if ( get_query_var( 'paged' ) )
1241
+    if (get_query_var('paged'))
1242 1242
         $args['page'] = get_query_var('paged');
1243
-    else if ( get_query_var( 'page' ) )
1244
-        $args['page'] = get_query_var( 'page' );
1245
-    else if ( !empty( $args[ 'page' ] ) )
1246
-        $args['page'] = $args[ 'page' ];
1243
+    else if (get_query_var('page'))
1244
+        $args['page'] = get_query_var('page');
1245
+    else if (!empty($args['page']))
1246
+        $args['page'] = $args['page'];
1247 1247
     else
1248 1248
         $args['page'] = 1;
1249 1249
 
@@ -1256,47 +1256,47 @@  discard block
 block discarded – undo
1256 1256
         'post_status'    => $args['status'],
1257 1257
         'posts_per_page' => $args['limit'],
1258 1258
         'meta_query'     => array(),
1259
-        'date_query'     => !empty( $args['date_query'] ) ? $args['date_query'] : array(),
1259
+        'date_query'     => !empty($args['date_query']) ? $args['date_query'] : array(),
1260 1260
         'fields'         => 'ids',
1261 1261
         'orderby'        => $args['orderby'],
1262 1262
         'order'          => $args['order'],
1263 1263
     );
1264 1264
     
1265
-    if ( !empty( $args['user'] ) ) {
1266
-        $wp_query_args['author'] = absint( $args['user'] );
1265
+    if (!empty($args['user'])) {
1266
+        $wp_query_args['author'] = absint($args['user']);
1267 1267
     }
1268 1268
 
1269
-    if ( ! is_null( $args['parent'] ) ) {
1270
-        $wp_query_args['post_parent'] = absint( $args['parent'] );
1269
+    if (!is_null($args['parent'])) {
1270
+        $wp_query_args['post_parent'] = absint($args['parent']);
1271 1271
     }
1272 1272
 
1273
-    if ( ! is_null( $args['offset'] ) ) {
1274
-        $wp_query_args['offset'] = absint( $args['offset'] );
1273
+    if (!is_null($args['offset'])) {
1274
+        $wp_query_args['offset'] = absint($args['offset']);
1275 1275
     } else {
1276
-        $wp_query_args['paged'] = absint( $args['page'] );
1276
+        $wp_query_args['paged'] = absint($args['page']);
1277 1277
     }
1278 1278
 
1279
-    if ( ! empty( $args['exclude'] ) ) {
1280
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
1279
+    if (!empty($args['exclude'])) {
1280
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
1281 1281
     }
1282 1282
 
1283
-    if ( ! $args['paginate' ] ) {
1283
+    if (!$args['paginate']) {
1284 1284
         $wp_query_args['no_found_rows'] = true;
1285 1285
     }
1286 1286
 
1287 1287
     // Get results.
1288
-    $invoices = new WP_Query( $wp_query_args );
1288
+    $invoices = new WP_Query($wp_query_args);
1289 1289
 
1290
-    if ( 'objects' === $args['return'] ) {
1291
-        $return = array_map( 'wpinv_get_invoice', $invoices->posts );
1292
-    } elseif ( 'self' === $args['return'] ) {
1290
+    if ('objects' === $args['return']) {
1291
+        $return = array_map('wpinv_get_invoice', $invoices->posts);
1292
+    } elseif ('self' === $args['return']) {
1293 1293
         return $invoices;
1294 1294
     } else {
1295 1295
         $return = $invoices->posts;
1296 1296
     }
1297 1297
 
1298
-    if ( $args['paginate' ] ) {
1299
-        return (object) array(
1298
+    if ($args['paginate']) {
1299
+        return (object)array(
1300 1300
             'invoices'      => $return,
1301 1301
             'total'         => $invoices->found_posts,
1302 1302
             'max_num_pages' => $invoices->max_num_pages,
@@ -1308,21 +1308,21 @@  discard block
 block discarded – undo
1308 1308
 
1309 1309
 function wpinv_get_user_invoices_columns() {
1310 1310
     $columns = array(
1311
-            'invoice-number'  => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ),
1312
-            'invoice-date'    => array( 'title' => __( 'Date', 'invoicing' ), 'class' => 'text-left' ),
1313
-            'invoice-status'  => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ),
1314
-            'invoice-total'   => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ),
1315
-            'invoice-actions' => array( 'title' => '&nbsp;', 'class' => 'text-center' ),
1311
+            'invoice-number'  => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'),
1312
+            'invoice-date'    => array('title' => __('Date', 'invoicing'), 'class' => 'text-left'),
1313
+            'invoice-status'  => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'),
1314
+            'invoice-total'   => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'),
1315
+            'invoice-actions' => array('title' => '&nbsp;', 'class' => 'text-center'),
1316 1316
         );
1317 1317
 
1318
-    return apply_filters( 'wpinv_user_invoices_columns', $columns );
1318
+    return apply_filters('wpinv_user_invoices_columns', $columns);
1319 1319
 }
1320 1320
 
1321
-function wpinv_payment_receipt( $atts, $content = null ) {
1321
+function wpinv_payment_receipt($atts, $content = null) {
1322 1322
     global $wpinv_receipt_args;
1323 1323
 
1324
-    $wpinv_receipt_args = shortcode_atts( array(
1325
-        'error'           => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ),
1324
+    $wpinv_receipt_args = shortcode_atts(array(
1325
+        'error'           => __('Sorry, trouble retrieving payment receipt.', 'invoicing'),
1326 1326
         'price'           => true,
1327 1327
         'discount'        => true,
1328 1328
         'items'           => true,
@@ -1331,185 +1331,185 @@  discard block
 block discarded – undo
1331 1331
         'invoice_key'     => false,
1332 1332
         'payment_method'  => true,
1333 1333
         'invoice_id'      => true
1334
-    ), $atts, 'wpinv_receipt' );
1334
+    ), $atts, 'wpinv_receipt');
1335 1335
 
1336 1336
     $session = wpinv_get_checkout_session();
1337
-    if ( isset( $_GET['invoice_key'] ) ) {
1338
-        $invoice_key = urldecode( $_GET['invoice_key'] );
1339
-    } else if ( $session && isset( $session['invoice_key'] ) ) {
1337
+    if (isset($_GET['invoice_key'])) {
1338
+        $invoice_key = urldecode($_GET['invoice_key']);
1339
+    } else if ($session && isset($session['invoice_key'])) {
1340 1340
         $invoice_key = $session['invoice_key'];
1341
-    } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) {
1341
+    } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) {
1342 1342
         $invoice_key = $wpinv_receipt_args['invoice_key'];
1343
-    } else if ( isset( $_GET['invoice-id'] ) ) {
1344
-        $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] );
1343
+    } else if (isset($_GET['invoice-id'])) {
1344
+        $invoice_key = wpinv_get_payment_key((int)$_GET['invoice-id']);
1345 1345
     }
1346 1346
 
1347 1347
     // No key found
1348
-    if ( ! isset( $invoice_key ) ) {
1348
+    if (!isset($invoice_key)) {
1349 1349
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1350 1350
     }
1351 1351
 
1352
-    $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1353
-    $user_can_view = wpinv_can_view_receipt( $invoice_key );
1354
-    if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1352
+    $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1353
+    $user_can_view = wpinv_can_view_receipt($invoice_key);
1354
+    if ($user_can_view && isset($_GET['invoice-id'])) {
1355 1355
         $invoice_id     = (int)$_GET['invoice-id'];
1356
-        $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1356
+        $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1357 1357
     }
1358 1358
 
1359 1359
     // Key was provided, but user is logged out. Offer them the ability to login and view the receipt
1360
-    if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) {
1360
+    if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) {
1361 1361
         // login redirect
1362
-        return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>';
1362
+        return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>';
1363 1363
     }
1364 1364
 
1365
-    if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) {
1365
+    if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) {
1366 1366
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1367 1367
     }
1368 1368
 
1369 1369
     ob_start();
1370 1370
 
1371
-    wpinv_get_template_part( 'wpinv-invoice-receipt' );
1371
+    wpinv_get_template_part('wpinv-invoice-receipt');
1372 1372
 
1373 1373
     $display = ob_get_clean();
1374 1374
 
1375 1375
     return $display;
1376 1376
 }
1377 1377
 
1378
-function wpinv_get_invoice_id_by_key( $key ) {
1378
+function wpinv_get_invoice_id_by_key($key) {
1379 1379
 	global $wpdb;
1380 1380
 
1381
-	$invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) );
1381
+	$invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key));
1382 1382
 
1383
-	if ( $invoice_id != NULL )
1383
+	if ($invoice_id != NULL)
1384 1384
 		return $invoice_id;
1385 1385
 
1386 1386
 	return 0;
1387 1387
 }
1388 1388
 
1389
-function wpinv_can_view_receipt( $invoice_key = '' ) {
1389
+function wpinv_can_view_receipt($invoice_key = '') {
1390 1390
 	$return = false;
1391 1391
 
1392
-	if ( empty( $invoice_key ) ) {
1392
+	if (empty($invoice_key)) {
1393 1393
 		return $return;
1394 1394
 	}
1395 1395
 
1396 1396
 	global $wpinv_receipt_args;
1397 1397
 
1398
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1399
-	if ( isset( $_GET['invoice-id'] ) ) {
1400
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1398
+	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key);
1399
+	if (isset($_GET['invoice-id'])) {
1400
+		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? (int)$_GET['invoice-id'] : 0;
1401 1401
 	}
1402 1402
 
1403
-	$user_id = (int) wpinv_get_user_id( $wpinv_receipt_args['id'] );
1404
-    $invoice_meta = wpinv_get_invoice_meta( $wpinv_receipt_args['id'] );
1403
+	$user_id = (int)wpinv_get_user_id($wpinv_receipt_args['id']);
1404
+    $invoice_meta = wpinv_get_invoice_meta($wpinv_receipt_args['id']);
1405 1405
 
1406
-	if ( is_user_logged_in() ) {
1407
-		if ( $user_id === (int) get_current_user_id() ) {
1406
+	if (is_user_logged_in()) {
1407
+		if ($user_id === (int)get_current_user_id()) {
1408 1408
 			$return = true;
1409 1409
 		}
1410 1410
 	}
1411 1411
 
1412 1412
 	$session = wpinv_get_checkout_session();
1413
-	if ( ! empty( $session ) && ! is_user_logged_in() ) {
1414
-		if ( $session['invoice_key'] === $invoice_meta['key'] ) {
1413
+	if (!empty($session) && !is_user_logged_in()) {
1414
+		if ($session['invoice_key'] === $invoice_meta['key']) {
1415 1415
 			$return = true;
1416 1416
 		}
1417 1417
 	}
1418 1418
 
1419
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1419
+	return (bool)apply_filters('wpinv_can_view_receipt', $return, $invoice_key);
1420 1420
 }
1421 1421
 
1422 1422
 function wpinv_pay_for_invoice() {
1423 1423
     global $wpinv_euvat;
1424 1424
     
1425
-    if ( isset( $_GET['invoice_key'] ) ) {
1425
+    if (isset($_GET['invoice_key'])) {
1426 1426
         $checkout_uri   = wpinv_get_checkout_uri();
1427
-        $invoice_key    = sanitize_text_field( $_GET['invoice_key'] );
1427
+        $invoice_key    = sanitize_text_field($_GET['invoice_key']);
1428 1428
         
1429
-        if ( empty( $invoice_key ) ) {
1430
-            wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) );
1431
-            wp_redirect( $checkout_uri );
1429
+        if (empty($invoice_key)) {
1430
+            wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing'));
1431
+            wp_redirect($checkout_uri);
1432 1432
             wpinv_die();
1433 1433
         }
1434 1434
         
1435
-        do_action( 'wpinv_check_pay_for_invoice', $invoice_key );
1435
+        do_action('wpinv_check_pay_for_invoice', $invoice_key);
1436 1436
 
1437
-        $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1438
-        $user_can_view = wpinv_can_view_receipt( $invoice_key );
1439
-        if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1437
+        $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1438
+        $user_can_view = wpinv_can_view_receipt($invoice_key);
1439
+        if ($user_can_view && isset($_GET['invoice-id'])) {
1440 1440
             $invoice_id     = (int)$_GET['invoice-id'];
1441
-            $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1441
+            $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1442 1442
         }
1443 1443
         
1444
-        if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) {
1445
-            if ( $invoice->needs_payment() ) {
1444
+        if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) {
1445
+            if ($invoice->needs_payment()) {
1446 1446
                 $data                   = array();
1447 1447
                 $data['invoice_id']     = $invoice_id;
1448
-                $data['cart_discounts'] = $invoice->get_discounts( true );
1448
+                $data['cart_discounts'] = $invoice->get_discounts(true);
1449 1449
                 
1450
-                wpinv_set_checkout_session( $data );
1450
+                wpinv_set_checkout_session($data);
1451 1451
                 
1452
-                if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1452
+                if (wpinv_get_option('vat_ip_country_default')) {
1453 1453
                     $_POST['country']   = $wpinv_euvat->get_country_by_ip();
1454 1454
                     $_POST['state']     = $_POST['country'] == $invoice->country ? $invoice->state : '';
1455 1455
                     
1456
-                    wpinv_recalculate_tax( true );
1456
+                    wpinv_recalculate_tax(true);
1457 1457
                 }
1458 1458
                 
1459 1459
             } else {
1460 1460
                 $checkout_uri = $invoice->get_view_url();
1461 1461
             }
1462 1462
         } else {
1463
-            wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) );
1463
+            wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing'));
1464 1464
             
1465
-            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
1465
+            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
1466 1466
         }
1467 1467
         
1468
-        wp_redirect( $checkout_uri );
1468
+        wp_redirect($checkout_uri);
1469 1469
         wpinv_die();
1470 1470
     }
1471 1471
 }
1472
-add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' );
1472
+add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice');
1473 1473
 
1474
-function wpinv_handle_pay_via_invoice_link( $invoice_key ) {
1475
-    if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) {
1476
-        if ( $invoice = wpinv_get_invoice( $invoice_id ) ) {
1474
+function wpinv_handle_pay_via_invoice_link($invoice_key) {
1475
+    if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) {
1476
+        if ($invoice = wpinv_get_invoice($invoice_id)) {
1477 1477
             $user_id = $invoice->get_user_id();
1478
-            $secret = sanitize_text_field( $_GET['_wpipay'] );
1478
+            $secret = sanitize_text_field($_GET['_wpipay']);
1479 1479
             
1480
-            if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link
1481
-                $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
1480
+            if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link
1481
+                $redirect_to = remove_query_arg('_wpipay', get_permalink());
1482 1482
                 
1483
-                wpinv_guest_redirect( $redirect_to, $user_id );
1483
+                wpinv_guest_redirect($redirect_to, $user_id);
1484 1484
                 wpinv_die();
1485 1485
             }
1486 1486
         }
1487 1487
     }
1488 1488
 }
1489
-add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' );
1489
+add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link');
1490 1490
 
1491
-function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) {
1492
-    $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id;
1491
+function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') {
1492
+    $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id;
1493 1493
     
1494
-    if ( empty( $invoice_id ) && $invoice_id > 0 ) {
1494
+    if (empty($invoice_id) && $invoice_id > 0) {
1495 1495
         return false;
1496 1496
     }
1497 1497
     
1498
-    if ( empty( $transaction_id ) ) {
1498
+    if (empty($transaction_id)) {
1499 1499
         $transaction_id = $invoice_id;
1500 1500
     }
1501 1501
 
1502
-    $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id );
1502
+    $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id);
1503 1503
     
1504
-    return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id );
1504
+    return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id);
1505 1505
 }
1506 1506
 
1507
-function wpinv_invoice_status_label( $status, $status_display = '' ) {
1508
-    if ( empty( $status_display ) ) {
1509
-        $status_display = wpinv_status_nicename( $status );
1507
+function wpinv_invoice_status_label($status, $status_display = '') {
1508
+    if (empty($status_display)) {
1509
+        $status_display = wpinv_status_nicename($status);
1510 1510
     }
1511 1511
     
1512
-    switch ( $status ) {
1512
+    switch ($status) {
1513 1513
         case 'publish' :
1514 1514
         case 'complete' :
1515 1515
         case 'renewal' :
@@ -1535,28 +1535,28 @@  discard block
 block discarded – undo
1535 1535
     
1536 1536
     $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>';
1537 1537
     
1538
-    return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display );
1538
+    return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display);
1539 1539
 }
1540 1540
 
1541
-function wpinv_format_invoice_number( $number ) {
1542
-    $padd  = wpinv_get_option( 'invoice_number_padd' );
1541
+function wpinv_format_invoice_number($number) {
1542
+    $padd = wpinv_get_option('invoice_number_padd');
1543 1543
     
1544 1544
     // TODO maintain old invoice numbers if invoice number settings not saved. Should be removed before stable release.
1545
-    if ( $padd === '' || $padd === false || $padd === NULL ) {
1546
-        return wp_sprintf( __( 'WPINV-%d', 'invoicing' ), $number );
1545
+    if ($padd === '' || $padd === false || $padd === NULL) {
1546
+        return wp_sprintf(__('WPINV-%d', 'invoicing'), $number);
1547 1547
     }
1548 1548
     
1549
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
1550
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
1549
+    $prefix  = wpinv_get_option('invoice_number_prefix');
1550
+    $postfix = wpinv_get_option('invoice_number_postfix');
1551 1551
     
1552
-    $padd = absint( $padd );
1553
-    $formatted_number = absint( $number );
1552
+    $padd = absint($padd);
1553
+    $formatted_number = absint($number);
1554 1554
     
1555
-    if ( $padd > 0 ) {
1556
-        $formatted_number = zeroise( $formatted_number, $padd );
1555
+    if ($padd > 0) {
1556
+        $formatted_number = zeroise($formatted_number, $padd);
1557 1557
     }    
1558 1558
 
1559 1559
     $formatted_number = $prefix . $formatted_number . $postfix;
1560 1560
 
1561
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
1561
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
1562 1562
 }
1563 1563
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +21 added lines, -16 removed lines patch added patch discarded remove patch
@@ -83,8 +83,9 @@  discard block
 block discarded – undo
83 83
 
84 84
     $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) );
85 85
 
86
-    if ( $invoice_id != NULL )
87
-        return $invoice_id;
86
+    if ( $invoice_id != NULL ) {
87
+            return $invoice_id;
88
+    }
88 89
 
89 90
     return 0;
90 91
 }
@@ -750,8 +751,9 @@  discard block
 block discarded – undo
750 751
 function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
751 752
     $ret = false;
752 753
 
753
-    if ( empty( $zip ) || empty( $country_code ) )
754
-        return $ret;
754
+    if ( empty( $zip ) || empty( $country_code ) ) {
755
+            return $ret;
756
+    }
755 757
 
756 758
     $country_code = strtoupper( $country_code );
757 759
 
@@ -913,8 +915,9 @@  discard block
 block discarded – undo
913 915
         "ZM" => "\d{5}"
914 916
     );
915 917
 
916
-    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) )
917
-        $ret = true;
918
+    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) {
919
+            $ret = true;
920
+    }
918 921
 
919 922
     return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code );
920 923
 }
@@ -1238,14 +1241,15 @@  discard block
 block discarded – undo
1238 1241
         }
1239 1242
     }
1240 1243
     
1241
-    if ( get_query_var( 'paged' ) )
1242
-        $args['page'] = get_query_var('paged');
1243
-    else if ( get_query_var( 'page' ) )
1244
-        $args['page'] = get_query_var( 'page' );
1245
-    else if ( !empty( $args[ 'page' ] ) )
1246
-        $args['page'] = $args[ 'page' ];
1247
-    else
1248
-        $args['page'] = 1;
1244
+    if ( get_query_var( 'paged' ) ) {
1245
+            $args['page'] = get_query_var('paged');
1246
+    } else if ( get_query_var( 'page' ) ) {
1247
+            $args['page'] = get_query_var( 'page' );
1248
+    } else if ( !empty( $args[ 'page' ] ) ) {
1249
+            $args['page'] = $args[ 'page' ];
1250
+    } else {
1251
+            $args['page'] = 1;
1252
+    }
1249 1253
 
1250 1254
     /**
1251 1255
      * Generate WP_Query args. This logic will change if orders are moved to
@@ -1380,8 +1384,9 @@  discard block
 block discarded – undo
1380 1384
 
1381 1385
 	$invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) );
1382 1386
 
1383
-	if ( $invoice_id != NULL )
1384
-		return $invoice_id;
1387
+	if ( $invoice_id != NULL ) {
1388
+			return $invoice_id;
1389
+	}
1385 1390
 
1386 1391
 	return 0;
1387 1392
 }
Please login to merge, or discard this patch.