Completed
Push — master ( 3ff0dd...85f73b )
by Stiofan
15s
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.
Braces   +9 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly.
3
-if (!defined( 'ABSPATH' ) ) exit;
3
+if (!defined( 'ABSPATH' ) ) {
4
+    exit;
5
+}
4 6
 
5 7
 class WPInv_EUVat {
6 8
     private static $is_ajax = false;
@@ -1445,16 +1447,18 @@  discard block
 block discarded – undo
1445 1447
 
1446 1448
         if ( !empty( $tax_rates ) ) {
1447 1449
             foreach ( $tax_rates as $key => $tax_rate ) {
1448
-                if ( $country != $tax_rate['country'] )
1449
-                    continue;
1450
+                if ( $country != $tax_rate['country'] ) {
1451
+                                    continue;
1452
+                }
1450 1453
 
1451 1454
                 if ( !empty( $tax_rate['global'] ) ) {
1452 1455
                     if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) {
1453 1456
                         $rate = number_format( $tax_rate['rate'], 4 );
1454 1457
                     }
1455 1458
                 } else {
1456
-                    if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) )
1457
-                        continue;
1459
+                    if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) {
1460
+                                            continue;
1461
+                    }
1458 1462
 
1459 1463
                     $state_rate = $tax_rate['rate'];
1460 1464
                     if ( 0 !== $state_rate || !empty( $state_rate ) ) {
Please login to merge, or discard this patch.
Spacing   +709 added lines, -709 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,132 +17,132 @@  discard block
 block discarded – undo
17 17
     }
18 18
     
19 19
     public function __construct() {
20
-        self::$is_ajax          = defined( 'DOING_AJAX' ) && DOING_AJAX;
20
+        self::$is_ajax          = defined('DOING_AJAX') && DOING_AJAX;
21 21
         self::$default_country  = wpinv_get_default_country();
22 22
     }
23 23
     
24 24
     public static function actions() {
25
-        if ( is_admin() ) {
26
-            add_action( 'admin_enqueue_scripts', array( self::$instance, 'enqueue_admin_scripts' ) );
27
-            add_action( 'wpinv_settings_sections_taxes', array( self::$instance, 'section_vat_settings' ) ); 
28
-            add_action( 'wpinv_settings_taxes', array( self::$instance, 'vat_settings' ) );
29
-            add_filter( 'wpinv_settings_taxes-vat_sanitize', array( self::$instance, 'sanitize_vat_settings' ) );
30
-            add_filter( 'wpinv_settings_taxes-vat_rates_sanitize', array( self::$instance, 'sanitize_vat_rates' ) );
31
-            add_action( 'wp_ajax_wpinv_add_vat_class', array( self::$instance, 'add_class' ) );
32
-            add_action( 'wp_ajax_nopriv_wpinv_add_vat_class', array( self::$instance, 'add_class' ) );
33
-            add_action( 'wp_ajax_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) );
34
-            add_action( 'wp_ajax_nopriv_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) );
35
-            add_action( 'wp_ajax_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) );
36
-            add_action( 'wp_ajax_nopriv_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) );
37
-            add_action( 'wp_ajax_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) );
38
-            add_action( 'wp_ajax_nopriv_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) );
39
-        }
40
-        
41
-        add_action( 'wp_enqueue_scripts', array( self::$instance, 'enqueue_vat_scripts' ) );
42
-        add_filter( 'wpinv_default_billing_country', array( self::$instance, 'get_user_country' ), 10 );
43
-        add_filter( 'wpinv_get_user_country', array( self::$instance, 'set_user_country' ), 10 );
44
-        add_action( 'wp_ajax_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) );
45
-        add_action( 'wp_ajax_nopriv_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) );
46
-        add_action( 'wp_ajax_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) );
47
-        add_action( 'wp_ajax_nopriv_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) );
48
-        add_action( 'wpinv_invoice_print_after_line_items', array( self::$instance, 'show_vat_notice' ), 999, 1 );
49
-        if ( wpinv_use_taxes() ) {
50
-            add_action( 'wpinv_after_billing_fields', array( self::$instance, 'checkout_vat_fields' ) );
51
-            if ( self::allow_vat_rules() ) {
52
-                add_action( 'wpinv_checkout_error_checks', array( self::$instance, 'checkout_vat_validate' ), 10, 2 );
53
-                add_filter( 'wpinv_tax_rate', array( self::$instance, 'get_rate' ), 10, 4 );
25
+        if (is_admin()) {
26
+            add_action('admin_enqueue_scripts', array(self::$instance, 'enqueue_admin_scripts'));
27
+            add_action('wpinv_settings_sections_taxes', array(self::$instance, 'section_vat_settings')); 
28
+            add_action('wpinv_settings_taxes', array(self::$instance, 'vat_settings'));
29
+            add_filter('wpinv_settings_taxes-vat_sanitize', array(self::$instance, 'sanitize_vat_settings'));
30
+            add_filter('wpinv_settings_taxes-vat_rates_sanitize', array(self::$instance, 'sanitize_vat_rates'));
31
+            add_action('wp_ajax_wpinv_add_vat_class', array(self::$instance, 'add_class'));
32
+            add_action('wp_ajax_nopriv_wpinv_add_vat_class', array(self::$instance, 'add_class'));
33
+            add_action('wp_ajax_wpinv_delete_vat_class', array(self::$instance, 'delete_class'));
34
+            add_action('wp_ajax_nopriv_wpinv_delete_vat_class', array(self::$instance, 'delete_class'));
35
+            add_action('wp_ajax_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates'));
36
+            add_action('wp_ajax_nopriv_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates'));
37
+            add_action('wp_ajax_wpinv_geoip2', array(self::$instance, 'geoip2_download_database'));
38
+            add_action('wp_ajax_nopriv_wpinv_geoip2', array(self::$instance, 'geoip2_download_database'));
39
+        }
40
+        
41
+        add_action('wp_enqueue_scripts', array(self::$instance, 'enqueue_vat_scripts'));
42
+        add_filter('wpinv_default_billing_country', array(self::$instance, 'get_user_country'), 10);
43
+        add_filter('wpinv_get_user_country', array(self::$instance, 'set_user_country'), 10);
44
+        add_action('wp_ajax_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate'));
45
+        add_action('wp_ajax_nopriv_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate'));
46
+        add_action('wp_ajax_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset'));
47
+        add_action('wp_ajax_nopriv_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset'));
48
+        add_action('wpinv_invoice_print_after_line_items', array(self::$instance, 'show_vat_notice'), 999, 1);
49
+        if (wpinv_use_taxes()) {
50
+            add_action('wpinv_after_billing_fields', array(self::$instance, 'checkout_vat_fields'));
51
+            if (self::allow_vat_rules()) {
52
+                add_action('wpinv_checkout_error_checks', array(self::$instance, 'checkout_vat_validate'), 10, 2);
53
+                add_filter('wpinv_tax_rate', array(self::$instance, 'get_rate'), 10, 4);
54 54
             }
55 55
         }
56 56
     }        
57 57
     
58
-    public static function get_eu_states( $sort = true ) {
59
-        $eu_states = array( 'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE' );
60
-        if ( $sort ) {
61
-            $sort = sort( $eu_states );
58
+    public static function get_eu_states($sort = true) {
59
+        $eu_states = array('AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE');
60
+        if ($sort) {
61
+            $sort = sort($eu_states);
62 62
         }
63 63
         
64
-        return apply_filters( 'wpinv_get_eu_states', $eu_states, $sort );
64
+        return apply_filters('wpinv_get_eu_states', $eu_states, $sort);
65 65
     }
66 66
     
67
-    public static function get_gst_countries( $sort = true ) {
68
-        $gst_countries  = array( 'AU', 'NZ', 'CA', 'CN' );
67
+    public static function get_gst_countries($sort = true) {
68
+        $gst_countries = array('AU', 'NZ', 'CA', 'CN');
69 69
         
70
-        if ( $sort ) {
71
-            $sort = sort( $gst_countries );
70
+        if ($sort) {
71
+            $sort = sort($gst_countries);
72 72
         }
73 73
         
74
-        return apply_filters( 'wpinv_get_gst_countries', $gst_countries, $sort );
74
+        return apply_filters('wpinv_get_gst_countries', $gst_countries, $sort);
75 75
     }
76 76
     
77
-    public static function is_eu_state( $country_code ) {
78
-        $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_eu_states() ) ? true : false;
77
+    public static function is_eu_state($country_code) {
78
+        $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_eu_states()) ? true : false;
79 79
                 
80
-        return apply_filters( 'wpinv_is_eu_state', $return, $country_code );
80
+        return apply_filters('wpinv_is_eu_state', $return, $country_code);
81 81
     }
82 82
     
83
-    public static function is_gst_country( $country_code ) {
84
-        $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_gst_countries() ) ? true : false;
83
+    public static function is_gst_country($country_code) {
84
+        $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_gst_countries()) ? true : false;
85 85
                 
86
-        return apply_filters( 'wpinv_is_gst_country', $return, $country_code );
86
+        return apply_filters('wpinv_is_gst_country', $return, $country_code);
87 87
     }
88 88
     
89 89
     public static function enqueue_vat_scripts() {
90
-        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
90
+        $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
91 91
         
92
-        wp_register_script( 'wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
93
-        wp_register_script( 'wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
92
+        wp_register_script('wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
93
+        wp_register_script('wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
94 94
         
95
-        $vat_name   = self::get_vat_name();
95
+        $vat_name = self::get_vat_name();
96 96
         
97 97
         $vars = array();
98 98
         $vars['UseTaxes'] = wpinv_use_taxes();
99 99
         $vars['EUStates'] = self::get_eu_states();
100
-        $vars['NoRateSet'] = __( 'You have not set a rate. Do you want to continue?', 'invoicing' );
101
-        $vars['EmptyCompany'] = __( 'Please enter your registered company name!', 'invoicing' );
102
-        $vars['EmptyVAT'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
103
-        $vars['TotalsRefreshed'] = wp_sprintf( __( 'The invoice totals will be refreshed to update the %s.', 'invoicing' ), $vat_name );
104
-        $vars['ErrValidateVAT'] = wp_sprintf( __( 'Fail to validate the %s number!', 'invoicing' ), $vat_name );
105
-        $vars['ErrResetVAT'] = wp_sprintf( __( 'Fail to reset the %s number!', 'invoicing' ), $vat_name );
106
-        $vars['ErrInvalidVat'] = wp_sprintf( __( 'The %s number supplied does not have a valid format!', 'invoicing' ), $vat_name );
107
-        $vars['ErrInvalidResponse'] = __( 'An invalid response has been received from the server!', 'invoicing' );
100
+        $vars['NoRateSet'] = __('You have not set a rate. Do you want to continue?', 'invoicing');
101
+        $vars['EmptyCompany'] = __('Please enter your registered company name!', 'invoicing');
102
+        $vars['EmptyVAT'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
103
+        $vars['TotalsRefreshed'] = wp_sprintf(__('The invoice totals will be refreshed to update the %s.', 'invoicing'), $vat_name);
104
+        $vars['ErrValidateVAT'] = wp_sprintf(__('Fail to validate the %s number!', 'invoicing'), $vat_name);
105
+        $vars['ErrResetVAT'] = wp_sprintf(__('Fail to reset the %s number!', 'invoicing'), $vat_name);
106
+        $vars['ErrInvalidVat'] = wp_sprintf(__('The %s number supplied does not have a valid format!', 'invoicing'), $vat_name);
107
+        $vars['ErrInvalidResponse'] = __('An invalid response has been received from the server!', 'invoicing');
108 108
         $vars['ApplyVATRules'] = $vars['UseTaxes'] ? self::allow_vat_rules() : false;
109 109
         $vars['HideVatFields'] = $vars['ApplyVATRules'] ? self::hide_vat_fields() : true;
110
-        $vars['ErrResponse'] = __( 'The request response is invalid!', 'invoicing' );
111
-        $vars['ErrRateResponse'] = __( 'The get rate request response is invalid', 'invoicing' );
112
-        $vars['PageRefresh'] = __( 'The page will be refreshed in 10 seconds to show the new options.', 'invoicing' );
113
-        $vars['RequestResponseNotValidJSON'] = __( 'The get rate request response is not valid JSON', 'invoicing' );
114
-        $vars['GetRateRequestFailed'] = __( 'The get rate request failed: ', 'invoicing' );
115
-        $vars['NoRateInformationInResponse'] = __( 'The get rate request response does not contain any rate information', 'invoicing' );
116
-        $vars['RatesUpdated'] = __( 'The rates have been updated. Press the save button to record these new rates.', 'invoicing' );
117
-        $vars['IPAddressInformation'] = __( 'IP Address Information', 'invoicing' );
118
-        $vars['VatValidating'] = wp_sprintf( __( 'Validating %s number...', 'invoicing' ), $vat_name );
119
-        $vars['VatReseting'] = __( 'Reseting...', 'invoicing' );
120
-        $vars['VatValidated'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
121
-        $vars['VatNotValidated'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
122
-        $vars['ConfirmDeleteClass'] = __( 'Are you sure you wish to delete this rates class?', 'invoicing' );
110
+        $vars['ErrResponse'] = __('The request response is invalid!', 'invoicing');
111
+        $vars['ErrRateResponse'] = __('The get rate request response is invalid', 'invoicing');
112
+        $vars['PageRefresh'] = __('The page will be refreshed in 10 seconds to show the new options.', 'invoicing');
113
+        $vars['RequestResponseNotValidJSON'] = __('The get rate request response is not valid JSON', 'invoicing');
114
+        $vars['GetRateRequestFailed'] = __('The get rate request failed: ', 'invoicing');
115
+        $vars['NoRateInformationInResponse'] = __('The get rate request response does not contain any rate information', 'invoicing');
116
+        $vars['RatesUpdated'] = __('The rates have been updated. Press the save button to record these new rates.', 'invoicing');
117
+        $vars['IPAddressInformation'] = __('IP Address Information', 'invoicing');
118
+        $vars['VatValidating'] = wp_sprintf(__('Validating %s number...', 'invoicing'), $vat_name);
119
+        $vars['VatReseting'] = __('Reseting...', 'invoicing');
120
+        $vars['VatValidated'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
121
+        $vars['VatNotValidated'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
122
+        $vars['ConfirmDeleteClass'] = __('Are you sure you wish to delete this rates class?', 'invoicing');
123 123
         $vars['isFront'] = is_admin() ? false : true;
124
-        $vars['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' );
124
+        $vars['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce');
125 125
         $vars['baseCountry'] = wpinv_get_default_country();
126
-        $vars['disableVATSameCountry'] = ( self::same_country_rule() == 'no' ? true : false );
127
-        $vars['disableVATSimpleCheck'] = wpinv_get_option( 'vat_offline_check' ) ? true : false;
126
+        $vars['disableVATSameCountry'] = (self::same_country_rule() == 'no' ? true : false);
127
+        $vars['disableVATSimpleCheck'] = wpinv_get_option('vat_offline_check') ? true : false;
128 128
         
129
-        wp_enqueue_script( 'wpinv-vat-validation-script' );
130
-        wp_enqueue_script( 'wpinv-vat-script' );
131
-        wp_localize_script( 'wpinv-vat-script', 'WPInv_VAT_Vars', $vars );
129
+        wp_enqueue_script('wpinv-vat-validation-script');
130
+        wp_enqueue_script('wpinv-vat-script');
131
+        wp_localize_script('wpinv-vat-script', 'WPInv_VAT_Vars', $vars);
132 132
     }
133 133
 
134 134
     public static function enqueue_admin_scripts() {
135
-        if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) {
135
+        if (isset($_GET['page']) && 'wpinv-settings' == $_GET['page']) {
136 136
             self::enqueue_vat_scripts();
137 137
         }
138 138
     }
139 139
     
140
-    public static function section_vat_settings( $sections ) {
141
-        if ( !empty( $sections ) ) {
142
-            $sections['vat'] = __( 'EU VAT Settings', 'invoicing' );
140
+    public static function section_vat_settings($sections) {
141
+        if (!empty($sections)) {
142
+            $sections['vat'] = __('EU VAT Settings', 'invoicing');
143 143
             
144
-            if ( self::allow_vat_classes() ) {
145
-                $sections['vat_rates'] = __( 'EU VAT Rates', 'invoicing' );
144
+            if (self::allow_vat_classes()) {
145
+                $sections['vat_rates'] = __('EU VAT Rates', 'invoicing');
146 146
             }
147 147
         }
148 148
         return $sections;
@@ -151,52 +151,52 @@  discard block
 block discarded – undo
151 151
     public static function vat_rates_settings() {
152 152
         $vat_classes = self::get_rate_classes();
153 153
         $vat_rates = array();
154
-        $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_new';
155
-        $current_url = remove_query_arg( 'wpi_sub' );
154
+        $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_new';
155
+        $current_url = remove_query_arg('wpi_sub');
156 156
         
157 157
         $vat_rates['vat_rates_header'] = array(
158 158
             'id' => 'vat_rates_header',
159
-            'name' => '<h3>' . __( 'Manage VAT Rates', 'invoicing' ) . '</h3>',
159
+            'name' => '<h3>' . __('Manage VAT Rates', 'invoicing') . '</h3>',
160 160
             'desc' => '',
161 161
             'type' => 'header',
162 162
             'size' => 'regular'
163 163
         );
164 164
         $vat_rates['vat_rates_class'] = array(
165 165
             'id'          => 'vat_rates_class',
166
-            'name'        => __( 'Edit VAT Rates', 'invoicing' ),
167
-            'desc'        => __( 'The standard rate will apply where no explicit rate is provided.', 'invoicing' ),
166
+            'name'        => __('Edit VAT Rates', 'invoicing'),
167
+            'desc'        => __('The standard rate will apply where no explicit rate is provided.', 'invoicing'),
168 168
             'type'        => 'select',
169
-            'options'     => array_merge( $vat_classes, array( '_new' => __( 'Add New Rate Class', 'invoicing' ) ) ),
169
+            'options'     => array_merge($vat_classes, array('_new' => __('Add New Rate Class', 'invoicing'))),
170 170
             'chosen'      => true,
171
-            'placeholder' => __( 'Select a VAT Rate', 'invoicing' ),
171
+            'placeholder' => __('Select a VAT Rate', 'invoicing'),
172 172
             'selected'    => $vat_class,
173 173
             'onchange'    => 'document.location.href="' . $current_url . '&wpi_sub=" + this.value;',
174 174
         );
175 175
         
176
-        if ( $vat_class != '_standard' && $vat_class != '_new' ) {
176
+        if ($vat_class != '_standard' && $vat_class != '_new') {
177 177
             $vat_rates['vat_rate_delete'] = array(
178 178
                 'id'   => 'vat_rate_delete',
179 179
                 'type' => 'vat_rate_delete',
180 180
             );
181 181
         }
182 182
                     
183
-        if ( $vat_class == '_new' ) {
183
+        if ($vat_class == '_new') {
184 184
             $vat_rates['vat_rates_settings'] = array(
185 185
                 'id' => 'vat_rates_settings',
186
-                'name' => '<h3>' . __( 'Add New Rate Class', 'invoicing' ) . '</h3>',
186
+                'name' => '<h3>' . __('Add New Rate Class', 'invoicing') . '</h3>',
187 187
                 'type' => 'header',
188 188
             );
189 189
             $vat_rates['vat_rate_name'] = array(
190 190
                 'id'   => 'vat_rate_name',
191
-                'name' => __( 'Name', 'invoicing' ),
192
-                'desc' => __( 'A short name for the new VAT Rate class', 'invoicing' ),
191
+                'name' => __('Name', 'invoicing'),
192
+                'desc' => __('A short name for the new VAT Rate class', 'invoicing'),
193 193
                 'type' => 'text',
194 194
                 'size' => 'regular',
195 195
             );
196 196
             $vat_rates['vat_rate_desc'] = array(
197 197
                 'id'   => 'vat_rate_desc',
198
-                'name' => __( 'Description', 'invoicing' ),
199
-                'desc' => __( 'Manage VAT Rate class', 'invoicing' ),
198
+                'name' => __('Description', 'invoicing'),
199
+                'desc' => __('Manage VAT Rate class', 'invoicing'),
200 200
                 'type' => 'text',
201 201
                 'size' => 'regular',
202 202
             );
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
             $vat_rates['vat_rates'] = array(
209 209
                 'id'   => 'vat_rates',
210 210
                 'name' => '<h3>' . $vat_classes[$vat_class] . '</h3>',
211
-                'desc' => self::get_class_desc( $vat_class ),
211
+                'desc' => self::get_class_desc($vat_class),
212 212
                 'type' => 'vat_rates',
213 213
             );
214 214
         }
@@ -216,12 +216,12 @@  discard block
 block discarded – undo
216 216
         return $vat_rates;
217 217
     }
218 218
     
219
-    public static function vat_settings( $settings ) {
220
-        if ( !empty( $settings ) ) {    
219
+    public static function vat_settings($settings) {
220
+        if (!empty($settings)) {    
221 221
             $vat_settings = array();
222 222
             $vat_settings['vat_company_title'] = array(
223 223
                 'id' => 'vat_company_title',
224
-                'name' => '<h3>' . __( 'Your Company Details', 'invoicing' ) . '</h3>',
224
+                'name' => '<h3>' . __('Your Company Details', 'invoicing') . '</h3>',
225 225
                 'desc' => '',
226 226
                 'type' => 'header',
227 227
                 'size' => 'regular'
@@ -229,22 +229,22 @@  discard block
 block discarded – undo
229 229
             
230 230
             $vat_settings['vat_company_name'] = array(
231 231
                 'id' => 'vat_company_name',
232
-                'name' => __( 'Your Company Name', 'invoicing' ),
233
-                '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>' ),
232
+                'name' => __('Your Company Name', 'invoicing'),
233
+                '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>'),
234 234
                 'type' => 'text',
235 235
                 'size' => 'regular',
236 236
             );
237 237
             
238 238
             $vat_settings['vat_number'] = array(
239 239
                 'id'   => 'vat_number',
240
-                'name' => __( 'Your VAT Number', 'invoicing' ),
240
+                'name' => __('Your VAT Number', 'invoicing'),
241 241
                 'type' => 'vat_number',
242 242
                 'size' => 'regular',
243 243
             );
244 244
 
245 245
             $vat_settings['vat_settings_title'] = array(
246 246
                 'id' => 'vat_settings_title',
247
-                'name' => '<h3>' . __( 'Apply VAT Settings', 'invoicing' ) . '</h3>',
247
+                'name' => '<h3>' . __('Apply VAT Settings', 'invoicing') . '</h3>',
248 248
                 'desc' => '',
249 249
                 'type' => 'header',
250 250
                 'size' => 'regular'
@@ -252,8 +252,8 @@  discard block
 block discarded – undo
252 252
 
253 253
             $vat_settings['apply_vat_rules'] = array(
254 254
                 'id' => 'apply_vat_rules',
255
-                'name' => __( 'Enable VAT rules', 'invoicing' ),
256
-                '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>',
255
+                'name' => __('Enable VAT rules', 'invoicing'),
256
+                '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>',
257 257
                 'type' => 'checkbox',
258 258
                 'std' => '1'
259 259
             );
@@ -269,8 +269,8 @@  discard block
 block discarded – undo
269 269
 
270 270
             $vat_settings['vat_prevent_b2c_purchase'] = array(
271 271
                 'id' => 'vat_prevent_b2c_purchase',
272
-                'name' => __( 'Prevent EU B2C sales', 'invoicing' ),
273
-                'desc' => __( 'Enable this option if you are not registered for VAT in the EU.', 'invoicing' ),
272
+                'name' => __('Prevent EU B2C sales', 'invoicing'),
273
+                'desc' => __('Enable this option if you are not registered for VAT in the EU.', 'invoicing'),
274 274
                 'type' => 'checkbox'
275 275
             );
276 276
 
@@ -278,21 +278,21 @@  discard block
 block discarded – undo
278 278
 
279 279
             $vat_settings['vat_same_country_rule'] = array(
280 280
                 'id'          => 'vat_same_country_rule',
281
-                'name'        => __( 'Same country rule', 'invoicing' ),
282
-                'desc'        => __( 'Select how you want handle VAT charge if sales are in the same country as the base country.', 'invoicing' ),
281
+                'name'        => __('Same country rule', 'invoicing'),
282
+                'desc'        => __('Select how you want handle VAT charge if sales are in the same country as the base country.', 'invoicing'),
283 283
                 'type'        => 'select',
284 284
                 'options'     => array(
285
-                    ''          => __( 'Normal', 'invoicing' ),
286
-                    'no'        => __( 'No VAT', 'invoicing' ),
287
-                    'always'    => __( 'Always apply VAT', 'invoicing' ),
285
+                    ''          => __('Normal', 'invoicing'),
286
+                    'no'        => __('No VAT', 'invoicing'),
287
+                    'always'    => __('Always apply VAT', 'invoicing'),
288 288
                 ),
289
-                'placeholder' => __( 'Select a option', 'invoicing' ),
289
+                'placeholder' => __('Select a option', 'invoicing'),
290 290
                 'std'         => ''
291 291
             );
292 292
 
293 293
             $vat_settings['vat_checkout_title'] = array(
294 294
                 'id' => 'vat_checkout_title',
295
-                'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>',
295
+                'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>',
296 296
                 'desc' => '',
297 297
                 'type' => 'header',
298 298
                 'size' => 'regular'
@@ -300,14 +300,14 @@  discard block
 block discarded – undo
300 300
 
301 301
             $vat_settings['vat_disable_fields'] = array(
302 302
                 'id' => 'vat_disable_fields',
303
-                'name' => __( 'Disable VAT fields', 'invoicing' ),
304
-                'desc' => __( 'Disable VAT fields if Invoicing is being used for GST.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing' ) . '</font>',
303
+                'name' => __('Disable VAT fields', 'invoicing'),
304
+                'desc' => __('Disable VAT fields if Invoicing is being used for GST.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing') . '</font>',
305 305
                 'type' => 'checkbox'
306 306
             );
307 307
 
308 308
             $vat_settings['vat_ip_lookup'] = array(
309 309
                 'id'   => 'vat_ip_lookup',
310
-                'name' => __( 'IP Country lookup', 'invoicing' ),
310
+                'name' => __('IP Country lookup', 'invoicing'),
311 311
                 'type' => 'vat_ip_lookup',
312 312
                 'size' => 'regular',
313 313
                 'std' => 'default'
@@ -315,21 +315,21 @@  discard block
 block discarded – undo
315 315
 
316 316
             $vat_settings['hide_ip_address'] = array(
317 317
                 'id' => 'hide_ip_address',
318
-                'name' => __( 'Hide IP info at checkout', 'invoicing' ),
319
-                'desc' => __( 'Hide the user IP info at checkout.', 'invoicing' ),
318
+                'name' => __('Hide IP info at checkout', 'invoicing'),
319
+                'desc' => __('Hide the user IP info at checkout.', 'invoicing'),
320 320
                 'type' => 'checkbox'
321 321
             );
322 322
 
323 323
             $vat_settings['vat_ip_country_default'] = array(
324 324
                 'id' => 'vat_ip_country_default',
325
-                'name' => __( 'Enable IP Country as Default', 'invoicing' ),
326
-                'desc' => __( 'Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing' ),
325
+                'name' => __('Enable IP Country as Default', 'invoicing'),
326
+                'desc' => __('Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing'),
327 327
                 'type' => 'checkbox'
328 328
             );
329 329
 
330 330
             $vat_settings['vies_validation_title'] = array(
331 331
                 'id' => 'vies_validation_title',
332
-                'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>',
332
+                'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>',
333 333
                 'desc' => '',
334 334
                 'type' => 'header',
335 335
                 'size' => 'regular'
@@ -337,37 +337,37 @@  discard block
 block discarded – undo
337 337
 
338 338
             $vat_settings['vat_vies_check'] = array(
339 339
                 'id' => 'vat_vies_check',
340
-                'name' => __( 'Disable VIES VAT ID check', 'invoicing' ),
341
-                '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>' ),
340
+                'name' => __('Disable VIES VAT ID check', 'invoicing'),
341
+                '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>'),
342 342
                 'type' => 'checkbox'
343 343
             );
344 344
 
345 345
             $vat_settings['vat_disable_company_name_check'] = array(
346 346
                 'id' => 'vat_disable_company_name_check',
347
-                'name' => __( 'Disable VIES name check', 'invoicing' ),
348
-                '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>' ),
347
+                'name' => __('Disable VIES name check', 'invoicing'),
348
+                '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>'),
349 349
                 'type' => 'checkbox'
350 350
             );
351 351
 
352 352
             $vat_settings['vat_offline_check'] = array(
353 353
                 'id' => 'vat_offline_check',
354
-                'name' => __( 'Disable basic checks', 'invoicing' ),
355
-                'desc' => __( 'This will disable basic JS correct format validation attempts, it is very rare this should need to be disabled.', 'invoicing' ),
354
+                'name' => __('Disable basic checks', 'invoicing'),
355
+                'desc' => __('This will disable basic JS correct format validation attempts, it is very rare this should need to be disabled.', 'invoicing'),
356 356
                 'type' => 'checkbox'
357 357
             );
358 358
             
359 359
 
360 360
             $settings['vat'] = $vat_settings;
361 361
             
362
-            if ( self::allow_vat_classes() ) {
362
+            if (self::allow_vat_classes()) {
363 363
                 $settings['vat_rates'] = self::vat_rates_settings();
364 364
             }
365 365
             
366 366
             $eu_fallback_rate = array(
367 367
                 'id'   => 'eu_fallback_rate',
368
-                'name' => '<h3>' . __( 'VAT rate for EU member states', 'invoicing' ) . '</h3>',
368
+                'name' => '<h3>' . __('VAT rate for EU member states', 'invoicing') . '</h3>',
369 369
                 'type' => 'eu_fallback_rate',
370
-                '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' ),
370
+                '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'),
371 371
                 'std'  => '20',
372 372
                 'size' => 'small'
373 373
             );
@@ -383,11 +383,11 @@  discard block
 block discarded – undo
383 383
         $database_url       = 'http' . (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === 'on' ? 's' : '') . '://geolite.maxmind.com/download/geoip/database/';
384 384
         $destination_dir    = $upload_dir['basedir'] . '/invoicing';
385 385
         
386
-        if ( !is_dir( $destination_dir ) ) { 
387
-            mkdir( $destination_dir );
386
+        if (!is_dir($destination_dir)) { 
387
+            mkdir($destination_dir);
388 388
         }
389 389
         
390
-        $database_files     = array(
390
+        $database_files = array(
391 391
             'country'   => array(
392 392
                 'source'        => $database_url . 'GeoLite2-Country.mmdb.gz',
393 393
                 'destination'   => $destination_dir . '/GeoLite2-Country.mmdb',
@@ -398,57 +398,57 @@  discard block
 block discarded – undo
398 398
             )
399 399
         );
400 400
 
401
-        foreach( $database_files as $database => $files ) {
402
-            $result = self::geoip2_download_file( $files['source'], $files['destination'] );
401
+        foreach ($database_files as $database => $files) {
402
+            $result = self::geoip2_download_file($files['source'], $files['destination']);
403 403
             
404
-            if ( empty( $result['success'] ) ) {
404
+            if (empty($result['success'])) {
405 405
                 echo $result['message'];
406 406
                 exit;
407 407
             }
408 408
             
409
-            wpinv_update_option( 'wpinv_geoip2_date_updated', current_time( 'timestamp' ) );
410
-            echo sprintf(__( 'GeoIp2 %s database updated successfully.', 'invoicing' ), $database ) . ' ';
409
+            wpinv_update_option('wpinv_geoip2_date_updated', current_time('timestamp'));
410
+            echo sprintf(__('GeoIp2 %s database updated successfully.', 'invoicing'), $database) . ' ';
411 411
         }
412 412
         
413 413
         exit;
414 414
     }
415 415
     
416
-    public static function geoip2_download_file( $source_url, $destination_file ) {
416
+    public static function geoip2_download_file($source_url, $destination_file) {
417 417
         $success    = false;
418 418
         $message    = '';
419 419
         
420
-        if ( !function_exists( 'download_url' ) ) {
421
-            require_once( ABSPATH . 'wp-admin/includes/file.php' );
420
+        if (!function_exists('download_url')) {
421
+            require_once(ABSPATH . 'wp-admin/includes/file.php');
422 422
         }
423 423
 
424
-        $temp_file  = download_url( $source_url );
424
+        $temp_file = download_url($source_url);
425 425
         
426
-        if ( is_wp_error( $temp_file ) ) {
427
-            $message = sprintf( __( 'Error while downloading GeoIp2 database( %s ): %s', 'invoicing' ), $source_url, $temp_file->get_error_message() );
426
+        if (is_wp_error($temp_file)) {
427
+            $message = sprintf(__('Error while downloading GeoIp2 database( %s ): %s', 'invoicing'), $source_url, $temp_file->get_error_message());
428 428
         } else {
429
-            $handle = gzopen( $temp_file, 'rb' );
429
+            $handle = gzopen($temp_file, 'rb');
430 430
             
431
-            if ( $handle ) {
432
-                $fopen  = fopen( $destination_file, 'wb' );
433
-                if ( $fopen ) {
434
-                    while ( ( $data = gzread( $handle, 4096 ) ) != false ) {
435
-                        fwrite( $fopen, $data );
431
+            if ($handle) {
432
+                $fopen = fopen($destination_file, 'wb');
433
+                if ($fopen) {
434
+                    while (($data = gzread($handle, 4096)) != false) {
435
+                        fwrite($fopen, $data);
436 436
                     }
437 437
 
438
-                    gzclose( $handle );
439
-                    fclose( $fopen );
438
+                    gzclose($handle);
439
+                    fclose($fopen);
440 440
                         
441 441
                     $success = true;
442 442
                 } else {
443
-                    gzclose( $handle );
444
-                    $message = sprintf( __( 'Error could not open destination GeoIp2 database file for writing: %s', 'invoicing' ), $destination_file );
443
+                    gzclose($handle);
444
+                    $message = sprintf(__('Error could not open destination GeoIp2 database file for writing: %s', 'invoicing'), $destination_file);
445 445
                 }
446 446
             } else {
447
-                $message = sprintf( __( 'Error could not open GeoIp2 database file for reading: %s', 'invoicing' ), $temp_file );
447
+                $message = sprintf(__('Error could not open GeoIp2 database file for reading: %s', 'invoicing'), $temp_file);
448 448
             }
449 449
             
450
-            if ( file_exists( $temp_file ) ) {
451
-                unlink( $temp_file );
450
+            if (file_exists($temp_file)) {
451
+                unlink($temp_file);
452 452
             }
453 453
         }
454 454
         
@@ -460,11 +460,11 @@  discard block
 block discarded – undo
460 460
     }
461 461
     
462 462
     public static function load_geoip2() {
463
-        if ( defined( 'WPINV_GEOIP2_LODDED' ) ) {
463
+        if (defined('WPINV_GEOIP2_LODDED')) {
464 464
             return;
465 465
         }
466 466
         
467
-        if ( !class_exists( '\MaxMind\Db\Reader' ) ) {
467
+        if (!class_exists('\MaxMind\Db\Reader')) {
468 468
             $maxmind_db_files = array(
469 469
                 'Reader/Decoder.php',
470 470
                 'Reader/InvalidDatabaseException.php',
@@ -473,12 +473,12 @@  discard block
 block discarded – undo
473 473
                 'Reader.php',
474 474
             );
475 475
             
476
-            foreach ( $maxmind_db_files as $key => $file ) {
477
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file );
476
+            foreach ($maxmind_db_files as $key => $file) {
477
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file);
478 478
             }
479 479
         }
480 480
         
481
-        if ( !class_exists( '\GeoIp2\Database\Reader' ) ) {        
481
+        if (!class_exists('\GeoIp2\Database\Reader')) {        
482 482
             $geoip2_files = array(
483 483
                 'ProviderInterface.php',
484 484
                 'Compat/JsonSerializable.php',
@@ -512,23 +512,23 @@  discard block
 block discarded – undo
512 512
                 'WebService/Client.php',
513 513
             );
514 514
             
515
-            foreach ( $geoip2_files as $key => $file ) {
516
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file );
515
+            foreach ($geoip2_files as $key => $file) {
516
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file);
517 517
             }
518 518
         }
519 519
 
520
-        define( 'WPINV_GEOIP2_LODDED', true );
520
+        define('WPINV_GEOIP2_LODDED', true);
521 521
     }
522 522
 
523 523
     public static function geoip2_country_dbfile() {
524 524
         $upload_dir = wp_upload_dir();
525 525
 
526
-        if ( !isset( $upload_dir['basedir'] ) ) {
526
+        if (!isset($upload_dir['basedir'])) {
527 527
             return false;
528 528
         }
529 529
 
530 530
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-Country.mmdb';
531
-        if ( !file_exists( $filename ) ) {
531
+        if (!file_exists($filename)) {
532 532
             return false;
533 533
         }
534 534
         
@@ -538,12 +538,12 @@  discard block
 block discarded – undo
538 538
     public static function geoip2_city_dbfile() {
539 539
         $upload_dir = wp_upload_dir();
540 540
 
541
-        if ( !isset( $upload_dir['basedir'] ) ) {
541
+        if (!isset($upload_dir['basedir'])) {
542 542
             return false;
543 543
         }
544 544
 
545 545
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-City.mmdb';
546
-        if ( !file_exists( $filename ) ) {
546
+        if (!file_exists($filename)) {
547 547
             return false;
548 548
         }
549 549
         
@@ -554,10 +554,10 @@  discard block
 block discarded – undo
554 554
         try {
555 555
             self::load_geoip2();
556 556
 
557
-            if ( $filename = self::geoip2_country_dbfile() ) {
558
-                return new \GeoIp2\Database\Reader( $filename );
557
+            if ($filename = self::geoip2_country_dbfile()) {
558
+                return new \GeoIp2\Database\Reader($filename);
559 559
             }
560
-        } catch( Exception $e ) {
560
+        } catch (Exception $e) {
561 561
             return false;
562 562
         }
563 563
         
@@ -568,173 +568,173 @@  discard block
 block discarded – undo
568 568
         try {
569 569
             self::load_geoip2();
570 570
 
571
-            if ( $filename = self::geoip2_city_dbfile() ) {
572
-                return new \GeoIp2\Database\Reader( $filename );
571
+            if ($filename = self::geoip2_city_dbfile()) {
572
+                return new \GeoIp2\Database\Reader($filename);
573 573
             }
574
-        } catch( Exception $e ) {
574
+        } catch (Exception $e) {
575 575
             return false;
576 576
         }
577 577
         
578 578
         return false;
579 579
     }
580 580
 
581
-    public static function geoip2_country_record( $ip_address ) {
581
+    public static function geoip2_country_record($ip_address) {
582 582
         try {
583 583
             $reader = self::geoip2_country_reader();
584 584
 
585
-            if ( $reader ) {
586
-                $record = $reader->country( $ip_address );
585
+            if ($reader) {
586
+                $record = $reader->country($ip_address);
587 587
                 
588
-                if ( !empty( $record->country->isoCode ) ) {
588
+                if (!empty($record->country->isoCode)) {
589 589
                     return $record;
590 590
                 }
591 591
             }
592
-        } catch(\InvalidArgumentException $e) {
593
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
592
+        } catch (\InvalidArgumentException $e) {
593
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
594 594
             
595 595
             return false;
596
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
597
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
596
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
597
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
598 598
             
599 599
             return false;
600
-        } catch( Exception $e ) {
600
+        } catch (Exception $e) {
601 601
             return false;
602 602
         }
603 603
         
604 604
         return false;
605 605
     }
606 606
 
607
-    public static function geoip2_city_record( $ip_address ) {
607
+    public static function geoip2_city_record($ip_address) {
608 608
         try {
609 609
             $reader = self::geoip2_city_reader();
610 610
 
611
-            if ( $reader ) {
612
-                $record = $reader->city( $ip_address );
611
+            if ($reader) {
612
+                $record = $reader->city($ip_address);
613 613
                 
614
-                if ( !empty( $record->country->isoCode ) ) {
614
+                if (!empty($record->country->isoCode)) {
615 615
                     return $record;
616 616
                 }
617 617
             }
618
-        } catch(\InvalidArgumentException $e) {
619
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
618
+        } catch (\InvalidArgumentException $e) {
619
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
620 620
             
621 621
             return false;
622
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
623
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
622
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
623
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
624 624
             
625 625
             return false;
626
-        } catch( Exception $e ) {
626
+        } catch (Exception $e) {
627 627
             return false;
628 628
         }
629 629
         
630 630
         return false;
631 631
     }
632 632
 
633
-    public static function geoip2_country_code( $ip_address ) {
634
-        $record = self::geoip2_country_record( $ip_address );
635
-        return !empty( $record->country->isoCode ) ? $record->country->isoCode : wpinv_get_default_country();
633
+    public static function geoip2_country_code($ip_address) {
634
+        $record = self::geoip2_country_record($ip_address);
635
+        return !empty($record->country->isoCode) ? $record->country->isoCode : wpinv_get_default_country();
636 636
     }
637 637
 
638 638
     // Find country by IP address.
639
-    public static function get_country_by_ip( $ip = '' ) {
639
+    public static function get_country_by_ip($ip = '') {
640 640
         global $wpinv_ip_address_country;
641 641
         
642
-        if ( !empty( $wpinv_ip_address_country ) ) {
642
+        if (!empty($wpinv_ip_address_country)) {
643 643
             return $wpinv_ip_address_country;
644 644
         }
645 645
         
646
-        if ( empty( $ip ) ) {
646
+        if (empty($ip)) {
647 647
             $ip = wpinv_get_ip();
648 648
         }
649 649
 
650
-        $ip_country_service = wpinv_get_option( 'vat_ip_lookup' );
651
-        $is_default         = empty( $ip_country_service ) || $ip_country_service === 'default' ? true : false;
650
+        $ip_country_service = wpinv_get_option('vat_ip_lookup');
651
+        $is_default         = empty($ip_country_service) || $ip_country_service === 'default' ? true : false;
652 652
 
653
-        if ( !empty( $ip ) && $ip !== '127.0.0.1' ) { // For 127.0.0.1(localhost) use default country.
654
-            if ( function_exists( 'geoip_country_code_by_name') && ( $ip_country_service === 'geoip' || $is_default ) ) {
653
+        if (!empty($ip) && $ip !== '127.0.0.1') { // For 127.0.0.1(localhost) use default country.
654
+            if (function_exists('geoip_country_code_by_name') && ($ip_country_service === 'geoip' || $is_default)) {
655 655
                 try {
656
-                    $wpinv_ip_address_country = geoip_country_code_by_name( $ip );
657
-                } catch( Exception $e ) {
658
-                    wpinv_error_log( $e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )' );
656
+                    $wpinv_ip_address_country = geoip_country_code_by_name($ip);
657
+                } catch (Exception $e) {
658
+                    wpinv_error_log($e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )');
659 659
                 }
660
-            } else if ( self::geoip2_country_dbfile() && ( $ip_country_service === 'geoip2' || $is_default ) ) {
661
-                $wpinv_ip_address_country = self::geoip2_country_code( $ip );
662
-            } else if ( function_exists( 'simplexml_load_file' ) && ( $ip_country_service === 'geoplugin' || $is_default ) ) {
663
-                $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
660
+            } else if (self::geoip2_country_dbfile() && ($ip_country_service === 'geoip2' || $is_default)) {
661
+                $wpinv_ip_address_country = self::geoip2_country_code($ip);
662
+            } else if (function_exists('simplexml_load_file') && ($ip_country_service === 'geoplugin' || $is_default)) {
663
+                $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
664 664
                 
665
-                if ( !empty( $load_xml ) && !empty( $load_xml->geoplugin_countryCode ) ) {
665
+                if (!empty($load_xml) && !empty($load_xml->geoplugin_countryCode)) {
666 666
                     $wpinv_ip_address_country = (string)$load_xml->geoplugin_countryCode;
667 667
                 }
668 668
             }
669 669
         }
670 670
 
671
-        if ( empty( $wpinv_ip_address_country ) ) {
671
+        if (empty($wpinv_ip_address_country)) {
672 672
             $wpinv_ip_address_country = wpinv_get_default_country();
673 673
         }
674 674
 
675 675
         return $wpinv_ip_address_country;
676 676
     }
677 677
     
678
-    public static function sanitize_vat_settings( $input ) {
678
+    public static function sanitize_vat_settings($input) {
679 679
         global $wpinv_options;
680 680
         
681 681
         $valid      = false;
682 682
         $message    = '';
683 683
         
684
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
685
-            if ( empty( $wpinv_options['vat_offline_check'] ) ) {
686
-                $valid = self::offline_check( $input['vat_number'] );
684
+        if (!empty($wpinv_options['vat_vies_check'])) {
685
+            if (empty($wpinv_options['vat_offline_check'])) {
686
+                $valid = self::offline_check($input['vat_number']);
687 687
             } else {
688 688
                 $valid = true;
689 689
             }
690 690
             
691
-            $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' );
691
+            $message = $valid ? '' : __('VAT number not validated', 'invoicing');
692 692
         } else {
693
-            $result = self::check_vat( $input['vat_number'] );
693
+            $result = self::check_vat($input['vat_number']);
694 694
             
695
-            if ( empty( $result['valid'] ) ) {
695
+            if (empty($result['valid'])) {
696 696
                 $valid      = false;
697 697
                 $message    = $result['message'];
698 698
             } else {
699
-                $valid      = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] );
700
-                $message    = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' );
699
+                $valid      = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']);
700
+                $message    = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing');
701 701
             }
702 702
         }
703 703
 
704
-        if ( $message && self::is_vat_validated() != $valid ) {
705
-            add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) );
704
+        if ($message && self::is_vat_validated() != $valid) {
705
+            add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error'));
706 706
         }
707 707
 
708 708
         $input['vat_valid'] = $valid;
709 709
         return $input;
710 710
     }
711 711
     
712
-    public static function sanitize_vat_rates( $input ) {
713
-        if( !current_user_can( 'manage_options' ) ) {
714
-            add_settings_error( 'wpinv-notices', '', __( 'Your account does not have permission to add rate classes.', 'invoicing' ), 'error' );
712
+    public static function sanitize_vat_rates($input) {
713
+        if (!current_user_can('manage_options')) {
714
+            add_settings_error('wpinv-notices', '', __('Your account does not have permission to add rate classes.', 'invoicing'), 'error');
715 715
             return $input;
716 716
         }
717 717
         
718 718
         $vat_classes = self::get_rate_classes();
719
-        $vat_class = !empty( $_REQUEST['wpi_vat_class'] ) && isset( $vat_classes[$_REQUEST['wpi_vat_class']] )? sanitize_text_field( $_REQUEST['wpi_vat_class'] ) : '';
719
+        $vat_class = !empty($_REQUEST['wpi_vat_class']) && isset($vat_classes[$_REQUEST['wpi_vat_class']]) ? sanitize_text_field($_REQUEST['wpi_vat_class']) : '';
720 720
         
721
-        if ( empty( $vat_class ) ) {
722
-            add_settings_error( 'wpinv-notices', '', __( 'No valid VAT rates class contained in the request to save rates.', 'invoicing' ), 'error' );
721
+        if (empty($vat_class)) {
722
+            add_settings_error('wpinv-notices', '', __('No valid VAT rates class contained in the request to save rates.', 'invoicing'), 'error');
723 723
             
724 724
             return $input;
725 725
         }
726 726
 
727
-        $new_rates = ! empty( $_POST['vat_rates'] ) ? array_values( $_POST['vat_rates'] ) : array();
727
+        $new_rates = !empty($_POST['vat_rates']) ? array_values($_POST['vat_rates']) : array();
728 728
 
729
-        if ( $vat_class === '_standard' ) {
729
+        if ($vat_class === '_standard') {
730 730
             // Save the active rates in the invoice settings
731
-            update_option( 'wpinv_tax_rates', $new_rates );
731
+            update_option('wpinv_tax_rates', $new_rates);
732 732
         } else {
733 733
             // Get the existing set of rates
734 734
             $rates = self::get_non_standard_rates();
735 735
             $rates[$vat_class] = $new_rates;
736 736
 
737
-            update_option( 'wpinv_vat_rates', $rates );
737
+            update_option('wpinv_vat_rates', $rates);
738 738
         }
739 739
         
740 740
         return $input;
@@ -744,71 +744,71 @@  discard block
 block discarded – undo
744 744
         $response = array();
745 745
         $response['success'] = false;
746 746
         
747
-        if ( !current_user_can( 'manage_options' ) ) {
748
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
749
-            wp_send_json( $response );
747
+        if (!current_user_can('manage_options')) {
748
+            $response['error'] = __('Invalid access!', 'invoicing');
749
+            wp_send_json($response);
750 750
         }
751 751
         
752
-        $vat_class_name = !empty( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false;
753
-        $vat_class_desc = !empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : false;
752
+        $vat_class_name = !empty($_POST['name']) ? sanitize_text_field($_POST['name']) : false;
753
+        $vat_class_desc = !empty($_POST['desc']) ? sanitize_text_field($_POST['desc']) : false;
754 754
         
755
-        if ( empty( $vat_class_name ) ) {
756
-            $response['error'] = __( 'Select the VAT rate name', 'invoicing' );
757
-            wp_send_json( $response );
755
+        if (empty($vat_class_name)) {
756
+            $response['error'] = __('Select the VAT rate name', 'invoicing');
757
+            wp_send_json($response);
758 758
         }
759 759
         
760 760
         $vat_classes = (array)self::get_rate_classes();
761 761
 
762
-        if ( !empty( $vat_classes ) && in_array( strtolower( $vat_class_name ), array_map( 'strtolower', array_values( $vat_classes ) ) ) ) {
763
-            $response['error'] = wp_sprintf( __( 'A VAT Rate name "%s" already exists', 'invoicing' ), $vat_class_name );
764
-            wp_send_json( $response );
762
+        if (!empty($vat_classes) && in_array(strtolower($vat_class_name), array_map('strtolower', array_values($vat_classes)))) {
763
+            $response['error'] = wp_sprintf(__('A VAT Rate name "%s" already exists', 'invoicing'), $vat_class_name);
764
+            wp_send_json($response);
765 765
         }
766 766
         
767
-        $rate_class_key = normalize_whitespace( 'wpi-' . $vat_class_name );
768
-        $rate_class_key = sanitize_key( str_replace( " ", "-", $rate_class_key ) );
767
+        $rate_class_key = normalize_whitespace('wpi-' . $vat_class_name);
768
+        $rate_class_key = sanitize_key(str_replace(" ", "-", $rate_class_key));
769 769
         
770
-        $vat_classes = (array)self::get_rate_classes( true );
771
-        $vat_classes[$rate_class_key] = array( 'name' => $vat_class_name, 'desc' => $vat_class_desc );
770
+        $vat_classes = (array)self::get_rate_classes(true);
771
+        $vat_classes[$rate_class_key] = array('name' => $vat_class_name, 'desc' => $vat_class_desc);
772 772
         
773
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
773
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
774 774
         
775 775
         $response['success'] = true;
776
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key );
776
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key);
777 777
         
778
-        wp_send_json( $response );
778
+        wp_send_json($response);
779 779
     }
780 780
     
781 781
     public static function delete_class() {
782 782
         $response = array();
783 783
         $response['success'] = false;
784 784
         
785
-        if ( !current_user_can( 'manage_options' ) || !isset( $_POST['class'] ) ) {
786
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
787
-            wp_send_json( $response );
785
+        if (!current_user_can('manage_options') || !isset($_POST['class'])) {
786
+            $response['error'] = __('Invalid access!', 'invoicing');
787
+            wp_send_json($response);
788 788
         }
789 789
         
790
-        $vat_class = isset( $_POST['class'] ) && $_POST['class'] !== '' ? sanitize_text_field( $_POST['class'] ) : false;
790
+        $vat_class = isset($_POST['class']) && $_POST['class'] !== '' ? sanitize_text_field($_POST['class']) : false;
791 791
         $vat_classes = (array)self::get_rate_classes();
792 792
 
793
-        if ( !isset( $vat_classes[$vat_class] ) ) {
794
-            $response['error'] = __( 'Requested class does not exists', 'invoicing' );
795
-            wp_send_json( $response );
793
+        if (!isset($vat_classes[$vat_class])) {
794
+            $response['error'] = __('Requested class does not exists', 'invoicing');
795
+            wp_send_json($response);
796 796
         }
797 797
         
798
-        if ( $vat_class == '_new' || $vat_class == '_standard' ) {
799
-            $response['error'] = __( 'You can not delete standard rates class', 'invoicing' );
800
-            wp_send_json( $response );
798
+        if ($vat_class == '_new' || $vat_class == '_standard') {
799
+            $response['error'] = __('You can not delete standard rates class', 'invoicing');
800
+            wp_send_json($response);
801 801
         }
802 802
             
803
-        $vat_classes = (array)self::get_rate_classes( true );
804
-        unset( $vat_classes[$vat_class] );
803
+        $vat_classes = (array)self::get_rate_classes(true);
804
+        unset($vat_classes[$vat_class]);
805 805
         
806
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
806
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
807 807
         
808 808
         $response['success'] = true;
809
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new' );
809
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new');
810 810
         
811
-        wp_send_json( $response );
811
+        wp_send_json($response);
812 812
     }
813 813
     
814 814
     public static function update_eu_rates() {        
@@ -817,72 +817,72 @@  discard block
 block discarded – undo
817 817
         $response['error']      = null;
818 818
         $response['data']       = null;
819 819
         
820
-        if ( !current_user_can( 'manage_options' ) ) {
821
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
822
-            wp_send_json( $response );
820
+        if (!current_user_can('manage_options')) {
821
+            $response['error'] = __('Invalid access!', 'invoicing');
822
+            wp_send_json($response);
823 823
         }
824 824
         
825
-        $group      = !empty( $_POST['group'] ) ? sanitize_text_field( $_POST['group'] ) : '';
826
-        $euvatrates = self::request_euvatrates( $group );
825
+        $group      = !empty($_POST['group']) ? sanitize_text_field($_POST['group']) : '';
826
+        $euvatrates = self::request_euvatrates($group);
827 827
         
828
-        if ( !empty( $euvatrates ) ) {
829
-            if ( !empty( $euvatrates['success'] ) && !empty( $euvatrates['rates'] ) ) {
828
+        if (!empty($euvatrates)) {
829
+            if (!empty($euvatrates['success']) && !empty($euvatrates['rates'])) {
830 830
                 $response['success']        = true;
831 831
                 $response['data']['rates']  = $euvatrates['rates'];
832
-            } else if ( !empty( $euvatrates['error'] ) ) {
832
+            } else if (!empty($euvatrates['error'])) {
833 833
                 $response['error']          = $euvatrates['error'];
834 834
             }
835 835
         }
836 836
             
837
-        wp_send_json( $response );
837
+        wp_send_json($response);
838 838
     }
839 839
     
840 840
     public static function hide_vat_fields() {
841
-        $hide = wpinv_get_option( 'vat_disable_fields' );
841
+        $hide = wpinv_get_option('vat_disable_fields');
842 842
         
843
-        return apply_filters( 'wpinv_hide_vat_fields', $hide );
843
+        return apply_filters('wpinv_hide_vat_fields', $hide);
844 844
     }
845 845
     
846 846
     public static function same_country_rule() {
847
-        $same_country_rule = wpinv_get_option( 'vat_same_country_rule' );
847
+        $same_country_rule = wpinv_get_option('vat_same_country_rule');
848 848
         
849
-        return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule );
849
+        return apply_filters('wpinv_vat_same_country_rule', $same_country_rule);
850 850
     }
851 851
     
852 852
     public static function get_vat_name() {
853
-        $vat_name   = wpinv_get_option( 'vat_name' );
854
-        $vat_name   = !empty( $vat_name ) ? $vat_name : 'VAT';
853
+        $vat_name   = wpinv_get_option('vat_name');
854
+        $vat_name   = !empty($vat_name) ? $vat_name : 'VAT';
855 855
         
856
-        return apply_filters( 'wpinv_get_owner_vat_name', $vat_name );
856
+        return apply_filters('wpinv_get_owner_vat_name', $vat_name);
857 857
     }
858 858
     
859 859
     public static function get_company_name() {
860
-        $company_name = wpinv_get_option( 'vat_company_name' );
860
+        $company_name = wpinv_get_option('vat_company_name');
861 861
         
862
-        return apply_filters( 'wpinv_get_owner_company_name', $company_name );
862
+        return apply_filters('wpinv_get_owner_company_name', $company_name);
863 863
     }
864 864
     
865 865
     public static function get_vat_number() {
866
-        $vat_number = wpinv_get_option( 'vat_number' );
866
+        $vat_number = wpinv_get_option('vat_number');
867 867
         
868
-        return apply_filters( 'wpinv_get_owner_vat_number', $vat_number );
868
+        return apply_filters('wpinv_get_owner_vat_number', $vat_number);
869 869
     }
870 870
     
871 871
     public static function is_vat_validated() {
872
-        $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' );
872
+        $validated = self::get_vat_number() && wpinv_get_option('vat_valid');
873 873
         
874
-        return apply_filters( 'wpinv_is_owner_vat_validated', $validated );
874
+        return apply_filters('wpinv_is_owner_vat_validated', $validated);
875 875
     }
876 876
     
877
-    public static function sanitize_vat( $vat_number, $country_code = '' ) {        
878
-        $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) );
877
+    public static function sanitize_vat($vat_number, $country_code = '') {        
878
+        $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number)));
879 879
         
880
-        if ( empty( $country_code ) ) {
881
-            $country_code = substr( $vat_number, 0, 2 );
880
+        if (empty($country_code)) {
881
+            $country_code = substr($vat_number, 0, 2);
882 882
         }
883 883
         
884
-        if ( strpos( $vat_number , $country_code ) === 0 ) {
885
-            $vat = str_replace( $country_code, '', $vat_number );
884
+        if (strpos($vat_number, $country_code) === 0) {
885
+            $vat = str_replace($country_code, '', $vat_number);
886 886
         } else {
887 887
             $vat = $country_code . $vat_number;
888 888
         }
@@ -895,140 +895,140 @@  discard block
 block discarded – undo
895 895
         return $return;
896 896
     }
897 897
     
898
-    public static function offline_check( $vat_number, $country_code = '', $formatted = false ) {
899
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
898
+    public static function offline_check($vat_number, $country_code = '', $formatted = false) {
899
+        $vat            = self::sanitize_vat($vat_number, $country_code);
900 900
         $vat_number     = $vat['vat_number'];
901 901
         $country_code   = $vat['iso'];
902 902
         $regex          = array();
903 903
         
904
-        switch ( $country_code ) {
904
+        switch ($country_code) {
905 905
             case 'AT':
906
-                $regex[] = '/^(AT)U(\d{8})$/';                           // Austria
906
+                $regex[] = '/^(AT)U(\d{8})$/'; // Austria
907 907
                 break;
908 908
             case 'BE':
909
-                $regex[] = '/^(BE)(0?\d{9})$/';                          // Belgium
909
+                $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium
910 910
                 break;
911 911
             case 'BG':
912
-                $regex[] = '/^(BG)(\d{9,10})$/';                         // Bulgaria
912
+                $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria
913 913
                 break;
914 914
             case 'CH':
915 915
             case 'CHE':
916
-                $regex[] = '/^(CHE)(\d{9})MWST$/';                       // Switzerland (Not EU)
916
+                $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU)
917 917
                 break;
918 918
             case 'CY':
919
-                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/';                // Cyprus
919
+                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus
920 920
                 break;
921 921
             case 'CZ':
922
-                $regex[] = '/^(CZ)(\d{8,13})$/';                         // Czech Republic
922
+                $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic
923 923
                 break;
924 924
             case 'DE':
925
-                $regex[] = '/^(DE)([1-9]\d{8})$/';                       // Germany
925
+                $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany
926 926
                 break;
927 927
             case 'DK':
928
-                $regex[] = '/^(DK)(\d{8})$/';                            // Denmark
928
+                $regex[] = '/^(DK)(\d{8})$/'; // Denmark
929 929
                 break;
930 930
             case 'EE':
931
-                $regex[] = '/^(EE)(10\d{7})$/';                          // Estonia
931
+                $regex[] = '/^(EE)(10\d{7})$/'; // Estonia
932 932
                 break;
933 933
             case 'EL':
934
-                $regex[] = '/^(EL)(\d{9})$/';                            // Greece
934
+                $regex[] = '/^(EL)(\d{9})$/'; // Greece
935 935
                 break;
936 936
             case 'ES':
937
-                $regex[] = '/^(ES)([A-Z]\d{8})$/';                       // Spain (National juridical entities)
938
-                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/';            // Spain (Other juridical entities)
939
-                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/';              // Spain (Personal entities type 1)
940
-                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/';              // Spain (Personal entities type 2)
937
+                $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities)
938
+                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities)
939
+                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1)
940
+                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2)
941 941
                 break;
942 942
             case 'EU':
943
-                $regex[] = '/^(EU)(\d{9})$/';                            // EU-type
943
+                $regex[] = '/^(EU)(\d{9})$/'; // EU-type
944 944
                 break;
945 945
             case 'FI':
946
-                $regex[] = '/^(FI)(\d{8})$/';                            // Finland
946
+                $regex[] = '/^(FI)(\d{8})$/'; // Finland
947 947
                 break;
948 948
             case 'FR':
949
-                $regex[] = '/^(FR)(\d{11})$/';                           // France (1)
950
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/';        // France (2)
951
-                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/';       // France (3)
952
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/';      // France (4)
949
+                $regex[] = '/^(FR)(\d{11})$/'; // France (1)
950
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2)
951
+                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3)
952
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4)
953 953
                 break;
954 954
             case 'GB':
955
-                $regex[] = '/^(GB)?(\d{9})$/';                           // UK (Standard)
956
-                $regex[] = '/^(GB)?(\d{12})$/';                          // UK (Branches)
957
-                $regex[] = '/^(GB)?(GD\d{3})$/';                         // UK (Government)
958
-                $regex[] = '/^(GB)?(HA\d{3})$/';                         // UK (Health authority)
955
+                $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard)
956
+                $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches)
957
+                $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government)
958
+                $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority)
959 959
                 break;
960 960
             case 'GR':
961
-                $regex[] = '/^(GR)(\d{8,9})$/';                          // Greece
961
+                $regex[] = '/^(GR)(\d{8,9})$/'; // Greece
962 962
                 break;
963 963
             case 'HR':
964
-                $regex[] = '/^(HR)(\d{11})$/';                           // Croatia
964
+                $regex[] = '/^(HR)(\d{11})$/'; // Croatia
965 965
                 break;
966 966
             case 'HU':
967
-                $regex[] = '/^(HU)(\d{8})$/';                            // Hungary
967
+                $regex[] = '/^(HU)(\d{8})$/'; // Hungary
968 968
                 break;
969 969
             case 'IE':
970
-                $regex[] = '/^(IE)(\d{7}[A-W])$/';                       // Ireland (1)
971
-                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/';        // Ireland (2)
972
-                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/';                   // Ireland (3) (new format from 1 Jan 2013)
970
+                $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1)
971
+                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2)
972
+                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013)
973 973
                 break;
974 974
             case 'IT':
975
-                $regex[] = '/^(IT)(\d{11})$/';                           // Italy
975
+                $regex[] = '/^(IT)(\d{11})$/'; // Italy
976 976
                 break;
977 977
             case 'LV':
978
-                $regex[] = '/^(LV)(\d{11})$/';                           // Latvia
978
+                $regex[] = '/^(LV)(\d{11})$/'; // Latvia
979 979
                 break;
980 980
             case 'LT':
981
-                $regex[] = '/^(LT)(\d{9}|\d{12})$/';                     // Lithuania
981
+                $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania
982 982
                 break;
983 983
             case 'LU':
984
-                $regex[] = '/^(LU)(\d{8})$/';                            // Luxembourg
984
+                $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg
985 985
                 break;
986 986
             case 'MT':
987
-                $regex[] = '/^(MT)([1-9]\d{7})$/';                       // Malta
987
+                $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta
988 988
                 break;
989 989
             case 'NL':
990
-                $regex[] = '/^(NL)(\d{9})B\d{2}$/';                      // Netherlands
990
+                $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands
991 991
                 break;
992 992
             case 'NO':
993
-                $regex[] = '/^(NO)(\d{9})$/';                            // Norway (Not EU)
993
+                $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU)
994 994
                 break;
995 995
             case 'PL':
996
-                $regex[] = '/^(PL)(\d{10})$/';                           // Poland
996
+                $regex[] = '/^(PL)(\d{10})$/'; // Poland
997 997
                 break;
998 998
             case 'PT':
999
-                $regex[] = '/^(PT)(\d{9})$/';                            // Portugal
999
+                $regex[] = '/^(PT)(\d{9})$/'; // Portugal
1000 1000
                 break;
1001 1001
             case 'RO':
1002
-                $regex[] = '/^(RO)([1-9]\d{1,9})$/';                     // Romania
1002
+                $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania
1003 1003
                 break;
1004 1004
             case 'RS':
1005
-                $regex[] = '/^(RS)(\d{9})$/';                            // Serbia (Not EU)
1005
+                $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU)
1006 1006
                 break;
1007 1007
             case 'SI':
1008
-                $regex[] = '/^(SI)([1-9]\d{7})$/';                       // Slovenia
1008
+                $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia
1009 1009
                 break;
1010 1010
             case 'SK':
1011
-                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/';        // Slovakia Republic
1011
+                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic
1012 1012
                 break;
1013 1013
             case 'SE':
1014
-                $regex[] = '/^(SE)(\d{10}01)$/';                         // Sweden
1014
+                $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden
1015 1015
                 break;
1016 1016
             default:
1017 1017
                 $regex = array();
1018 1018
             break;
1019 1019
         }
1020 1020
         
1021
-        if ( empty( $regex ) ) {
1021
+        if (empty($regex)) {
1022 1022
             return false;
1023 1023
         }
1024 1024
         
1025
-        foreach ( $regex as $pattern ) {
1025
+        foreach ($regex as $pattern) {
1026 1026
             $matches = null;
1027
-            preg_match_all( $pattern, $vat_number, $matches );
1027
+            preg_match_all($pattern, $vat_number, $matches);
1028 1028
             
1029
-            if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) {
1030
-                if ( $formatted ) {
1031
-                    return array( 'code' => $matches[1][0], 'number' => $matches[2][0] );
1029
+            if (!empty($matches[1][0]) && !empty($matches[2][0])) {
1030
+                if ($formatted) {
1031
+                    return array('code' => $matches[1][0], 'number' => $matches[2][0]);
1032 1032
                 } else {
1033 1033
                     return true;
1034 1034
                 }
@@ -1038,75 +1038,75 @@  discard block
 block discarded – undo
1038 1038
         return false;
1039 1039
     }
1040 1040
     
1041
-    public static function vies_check( $vat_number, $country_code = '', $result = false ) {
1042
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
1041
+    public static function vies_check($vat_number, $country_code = '', $result = false) {
1042
+        $vat            = self::sanitize_vat($vat_number, $country_code);
1043 1043
         $vat_number     = $vat['vat'];
1044 1044
         $iso            = $vat['iso'];
1045 1045
         
1046
-        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number );
1046
+        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number);
1047 1047
         
1048
-        if ( ini_get( 'allow_url_fopen' ) ) {
1049
-            $response = file_get_contents( $url );
1050
-        } else if ( function_exists( 'curl_init' ) ) {
1048
+        if (ini_get('allow_url_fopen')) {
1049
+            $response = file_get_contents($url);
1050
+        } else if (function_exists('curl_init')) {
1051 1051
             $ch = curl_init();
1052 1052
             
1053
-            curl_setopt( $ch, CURLOPT_URL, $url );
1054
-            curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 );
1055
-            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
1056
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
1057
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
1053
+            curl_setopt($ch, CURLOPT_URL, $url);
1054
+            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
1055
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1056
+            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
1057
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
1058 1058
             
1059
-            $response = curl_exec( $ch );
1059
+            $response = curl_exec($ch);
1060 1060
             
1061
-            if ( curl_errno( $ch ) ) {
1062
-                wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' );
1061
+            if (curl_errno($ch)) {
1062
+                wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR');
1063 1063
                 $response = '';
1064 1064
             }
1065 1065
             
1066
-            curl_close( $ch );
1066
+            curl_close($ch);
1067 1067
         } else {
1068
-            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' );
1068
+            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');
1069 1069
         }
1070 1070
         
1071
-        if ( empty( $response ) ) {
1071
+        if (empty($response)) {
1072 1072
             return $result;
1073 1073
         }
1074 1074
 
1075
-        if ( preg_match( '/invalid VAT number/i', $response ) ) {
1075
+        if (preg_match('/invalid VAT number/i', $response)) {
1076 1076
             return false;
1077
-        } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) {
1078
-            $content = explode( "valid VAT number", htmlentities( $response ) );
1077
+        } else if (preg_match('/valid VAT number/i', $response, $matches)) {
1078
+            $content = explode("valid VAT number", htmlentities($response));
1079 1079
             
1080
-            if ( !empty( $content[1] ) ) {
1081
-                preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches );
1080
+            if (!empty($content[1])) {
1081
+                preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches);
1082 1082
                 
1083
-                if ( !empty( $matches[2] ) && $matches[3] ) {
1083
+                if (!empty($matches[2]) && $matches[3]) {
1084 1084
                     $return = array();
1085 1085
                     
1086
-                    foreach ( $matches[2] as $key => $label ) {
1087
-                        $label = trim( $label );
1086
+                    foreach ($matches[2] as $key => $label) {
1087
+                        $label = trim($label);
1088 1088
                         
1089
-                        switch ( strtolower( $label ) ) {
1089
+                        switch (strtolower($label)) {
1090 1090
                             case 'member state':
1091
-                                $return['state'] = trim( strip_tags( $matches[3][$key] ) );
1091
+                                $return['state'] = trim(strip_tags($matches[3][$key]));
1092 1092
                             break;
1093 1093
                             case 'vat number':
1094
-                                $return['number'] = trim( strip_tags( $matches[3][$key] ) );
1094
+                                $return['number'] = trim(strip_tags($matches[3][$key]));
1095 1095
                             break;
1096 1096
                             case 'name':
1097
-                                $return['company'] = trim( strip_tags( $matches[3][$key] ) );
1097
+                                $return['company'] = trim(strip_tags($matches[3][$key]));
1098 1098
                             break;
1099 1099
                             case 'address':
1100
-                                $address           = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) );
1101
-                                $return['address'] = trim( strip_tags( $address, '<br>' ) );
1100
+                                $address           = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key])));
1101
+                                $return['address'] = trim(strip_tags($address, '<br>'));
1102 1102
                             break;
1103 1103
                             case 'consultation number':
1104
-                                $return['consultation'] = trim( strip_tags( $matches[3][$key] ) );
1104
+                                $return['consultation'] = trim(strip_tags($matches[3][$key]));
1105 1105
                             break;
1106 1106
                         }
1107 1107
                     }
1108 1108
                     
1109
-                    if ( !empty( $return ) ) {
1109
+                    if (!empty($return)) {
1110 1110
                         return $return;
1111 1111
                     }
1112 1112
                 }
@@ -1118,55 +1118,55 @@  discard block
 block discarded – undo
1118 1118
         }
1119 1119
     }
1120 1120
     
1121
-    public static function check_vat( $vat_number, $country_code = '' ) {        
1121
+    public static function check_vat($vat_number, $country_code = '') {        
1122 1122
         $vat_name           = self::get_vat_name();
1123 1123
         
1124 1124
         $return             = array();
1125 1125
         $return['valid']    = false;
1126
-        $return['message']  = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1126
+        $return['message']  = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1127 1127
                 
1128
-        if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) {
1128
+        if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) {
1129 1129
             return $return;
1130 1130
         }
1131 1131
             
1132
-        $response = self::vies_check( $vat_number, $country_code );
1132
+        $response = self::vies_check($vat_number, $country_code);
1133 1133
         
1134
-        if ( $response ) {
1135
-            $return['valid']    = true;
1134
+        if ($response) {
1135
+            $return['valid'] = true;
1136 1136
             
1137
-            if ( is_array( $response ) ) {
1138
-                $return['company'] = isset( $response['company'] ) ? $response['company'] : '';
1139
-                $return['address'] = isset( $response['address'] ) ? $response['address'] : '';
1137
+            if (is_array($response)) {
1138
+                $return['company'] = isset($response['company']) ? $response['company'] : '';
1139
+                $return['address'] = isset($response['address']) ? $response['address'] : '';
1140 1140
                 $return['message'] = $return['company'] . '<br/>' . $return['address'];
1141 1141
             }
1142 1142
         } else {
1143 1143
             $return['valid']    = false;
1144
-            $return['message']  = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
1144
+            $return['message']  = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
1145 1145
         }
1146 1146
         
1147 1147
         return $return;
1148 1148
     }
1149 1149
     
1150
-    public static function request_euvatrates( $group ) {
1150
+    public static function request_euvatrates($group) {
1151 1151
         $response               = array();
1152 1152
         $response['success']    = false;
1153 1153
         $response['error']      = null;
1154 1154
         $response['eurates']    = null;
1155 1155
         
1156 1156
         $euvatrates_url = 'https://euvatrates.com/rates.json';
1157
-        $euvatrates_url = apply_filters( 'wpinv_euvatrates_url', $euvatrates_url );
1158
-        $api_response   = wp_remote_get( $euvatrates_url );
1157
+        $euvatrates_url = apply_filters('wpinv_euvatrates_url', $euvatrates_url);
1158
+        $api_response   = wp_remote_get($euvatrates_url);
1159 1159
     
1160 1160
         try {
1161
-            if ( is_wp_error( $api_response ) ) {
1162
-                $response['error']      = __( $api_response->get_error_message(), 'invoicing' );
1161
+            if (is_wp_error($api_response)) {
1162
+                $response['error'] = __($api_response->get_error_message(), 'invoicing');
1163 1163
             } else {
1164
-                $body = json_decode( $api_response['body'] );
1164
+                $body = json_decode($api_response['body']);
1165 1165
                 
1166
-                if ( isset( $body->rates ) ) {
1166
+                if (isset($body->rates)) {
1167 1167
                     $rates = array();
1168 1168
                     
1169
-                    foreach ( $body->rates as $country_code => $rate ) {
1169
+                    foreach ($body->rates as $country_code => $rate) {
1170 1170
                         $vat_rate = array();
1171 1171
                         $vat_rate['country']        = $rate->country;
1172 1172
                         $vat_rate['standard']       = (float)$rate->standard_rate;
@@ -1174,7 +1174,7 @@  discard block
 block discarded – undo
1174 1174
                         $vat_rate['superreduced']   = (float)$rate->super_reduced_rate;
1175 1175
                         $vat_rate['parking']        = (float)$rate->parking_rate;
1176 1176
                         
1177
-                        if ( $group !== '' && in_array( $group, array( 'standard', 'reduced', 'superreduced', 'parking' ) ) ) {
1177
+                        if ($group !== '' && in_array($group, array('standard', 'reduced', 'superreduced', 'parking'))) {
1178 1178
                             $vat_rate_group = array();
1179 1179
                             $vat_rate_group['country'] = $rate->country;
1180 1180
                             $vat_rate_group[$group]    = $vat_rate[$group];
@@ -1186,79 +1186,79 @@  discard block
 block discarded – undo
1186 1186
                     }
1187 1187
                     
1188 1188
                     $response['success']    = true;                                
1189
-                    $response['rates']      = apply_filters( 'wpinv_process_euvatrates', $rates, $api_response, $group );
1189
+                    $response['rates']      = apply_filters('wpinv_process_euvatrates', $rates, $api_response, $group);
1190 1190
                 } else {
1191
-                    $response['error']      = __( 'No EU rates found!', 'invoicing' );
1191
+                    $response['error']      = __('No EU rates found!', 'invoicing');
1192 1192
                 }
1193 1193
             }
1194
-        } catch ( Exception $e ) {
1195
-            $response['error'] = __( $e->getMessage(), 'invoicing' );
1194
+        } catch (Exception $e) {
1195
+            $response['error'] = __($e->getMessage(), 'invoicing');
1196 1196
         }
1197 1197
         
1198
-        return apply_filters( 'wpinv_response_euvatrates', $response, $group );
1198
+        return apply_filters('wpinv_response_euvatrates', $response, $group);
1199 1199
     }    
1200 1200
     
1201
-    public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) {
1201
+    public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) {
1202 1202
         global $wpi_item_id, $wpi_country;
1203 1203
         
1204
-        if ( !empty( $_POST['wpinv_country'] ) ) {
1205
-            $country_code = trim( $_POST['wpinv_country'] );
1206
-        } else if ( !empty( $_POST['country'] ) ) {
1207
-            $country_code = trim( $_POST['country'] );
1208
-        } else if ( !empty( $wpi_country ) ) {
1204
+        if (!empty($_POST['wpinv_country'])) {
1205
+            $country_code = trim($_POST['wpinv_country']);
1206
+        } else if (!empty($_POST['country'])) {
1207
+            $country_code = trim($_POST['country']);
1208
+        } else if (!empty($wpi_country)) {
1209 1209
             $country_code = $wpi_country;
1210 1210
         } else {
1211
-            $country_code = self::get_user_country( '', $user_id );
1211
+            $country_code = self::get_user_country('', $user_id);
1212 1212
         }
1213 1213
         
1214
-        if ( $is_digital === null && $wpi_item_id ) {
1215
-            $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules();
1214
+        if ($is_digital === null && $wpi_item_id) {
1215
+            $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules();
1216 1216
         }
1217 1217
         
1218
-        if ( !empty( $country_code ) ) {
1219
-            $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 ) );
1218
+        if (!empty($country_code)) {
1219
+            $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));
1220 1220
         }
1221 1221
         
1222
-        return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id );
1222
+        return apply_filters('wpinv_requires_vat', $requires_vat, $user_id);
1223 1223
     }
1224 1224
     
1225
-    public static function tax_label( $label = '' ) {
1225
+    public static function tax_label($label = '') {
1226 1226
         global $wpi_requires_vat;
1227 1227
         
1228
-        if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) {
1229
-            $wpi_requires_vat = self::requires_vat( 0, false );
1228
+        if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) {
1229
+            $wpi_requires_vat = self::requires_vat(0, false);
1230 1230
         }
1231 1231
         
1232
-        return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) );
1232
+        return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing'));
1233 1233
     }
1234 1234
     
1235 1235
     public static function standard_rates_label() {
1236
-        return __( 'Standard Rates', 'invoicing' );
1236
+        return __('Standard Rates', 'invoicing');
1237 1237
     }
1238 1238
     
1239
-    public static function get_rate_classes( $with_desc = false ) {        
1240
-        $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true );
1241
-        $classes = maybe_unserialize( $rate_classes_option );
1239
+    public static function get_rate_classes($with_desc = false) {        
1240
+        $rate_classes_option = get_option('_wpinv_vat_rate_classes', true);
1241
+        $classes = maybe_unserialize($rate_classes_option);
1242 1242
         
1243
-        if ( empty( $classes ) || !is_array( $classes ) ) {
1243
+        if (empty($classes) || !is_array($classes)) {
1244 1244
             $classes = array();
1245 1245
         }
1246 1246
 
1247 1247
         $rate_classes = array();
1248
-        if ( !array_key_exists( '_standard', $classes ) ) {
1249
-            if ( $with_desc ) {
1250
-                $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) );
1248
+        if (!array_key_exists('_standard', $classes)) {
1249
+            if ($with_desc) {
1250
+                $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing'));
1251 1251
             } else {
1252 1252
                 $rate_classes['_standard'] = self::standard_rates_label();
1253 1253
             }
1254 1254
         }
1255 1255
         
1256
-        foreach ( $classes as $key => $class ) {
1257
-            $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key;
1258
-            $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : '';
1256
+        foreach ($classes as $key => $class) {
1257
+            $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key;
1258
+            $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : '';
1259 1259
             
1260
-            if ( $with_desc ) {
1261
-                $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc );
1260
+            if ($with_desc) {
1261
+                $rate_classes[$key] = array('name' => $name, 'desc' => $desc);
1262 1262
             } else {
1263 1263
                 $rate_classes[$key] = $name;
1264 1264
             }
@@ -1269,15 +1269,15 @@  discard block
 block discarded – undo
1269 1269
     
1270 1270
     public static function get_all_classes() {        
1271 1271
         $classes            = self::get_rate_classes();
1272
-        $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' );
1272
+        $classes['_exempt'] = __('Exempt (0%)', 'invoicing');
1273 1273
         
1274
-        return apply_filters( 'wpinv_vat_get_all_classes', $classes );
1274
+        return apply_filters('wpinv_vat_get_all_classes', $classes);
1275 1275
     }
1276 1276
     
1277
-    public static function get_class_desc( $rate_class ) {        
1278
-        $rate_classes = self::get_rate_classes( true );
1277
+    public static function get_class_desc($rate_class) {        
1278
+        $rate_classes = self::get_rate_classes(true);
1279 1279
 
1280
-        if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) {
1280
+        if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) {
1281 1281
             return $rate_classes[$rate_class]['desc'];
1282 1282
         }
1283 1283
         
@@ -1293,106 +1293,106 @@  discard block
 block discarded – undo
1293 1293
             'increased'     => 'Increased'
1294 1294
         );
1295 1295
         
1296
-        return apply_filters( 'wpinv_get_vat_groups', $vat_groups );
1296
+        return apply_filters('wpinv_get_vat_groups', $vat_groups);
1297 1297
     }
1298 1298
 
1299 1299
     public static function get_rules() {
1300 1300
         $vat_rules = array(
1301
-            'digital' => __( 'Digital Product', 'invoicing' ),
1302
-            'physical' => __( 'Physical Product', 'invoicing' )
1301
+            'digital' => __('Digital Product', 'invoicing'),
1302
+            'physical' => __('Physical Product', 'invoicing')
1303 1303
         );
1304
-        return apply_filters( 'wpinv_get_vat_rules', $vat_rules );
1304
+        return apply_filters('wpinv_get_vat_rules', $vat_rules);
1305 1305
     }
1306 1306
 
1307
-    public static function get_vat_rates( $class ) {
1308
-        if ( $class === '_standard' ) {
1307
+    public static function get_vat_rates($class) {
1308
+        if ($class === '_standard') {
1309 1309
             return wpinv_get_tax_rates();
1310 1310
         }
1311 1311
 
1312 1312
         $rates = self::get_non_standard_rates();
1313 1313
 
1314
-        return array_key_exists( $class, $rates ) ? $rates[$class] : array();
1314
+        return array_key_exists($class, $rates) ? $rates[$class] : array();
1315 1315
     }
1316 1316
 
1317 1317
     public static function get_non_standard_rates() {
1318
-        $option = get_option( 'wpinv_vat_rates', array());
1319
-        return is_array( $option ) ? $option : array();
1318
+        $option = get_option('wpinv_vat_rates', array());
1319
+        return is_array($option) ? $option : array();
1320 1320
     }
1321 1321
     
1322 1322
     public static function allow_vat_rules() {
1323
-        return ( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ? true : false );
1323
+        return (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules') ? true : false);
1324 1324
     }
1325 1325
     
1326 1326
     public static function allow_vat_classes() {
1327 1327
         return false; // TODO
1328
-        return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false );
1328
+        return (wpinv_get_option('vat_allow_classes') ? true : false);
1329 1329
     }
1330 1330
     
1331
-    public static function get_item_class( $postID ) {
1332
-        $class = get_post_meta( $postID, '_wpinv_vat_class', true );
1331
+    public static function get_item_class($postID) {
1332
+        $class = get_post_meta($postID, '_wpinv_vat_class', true);
1333 1333
 
1334
-        if ( empty( $class ) ) {
1334
+        if (empty($class)) {
1335 1335
             $class = '_standard';
1336 1336
         }
1337 1337
         
1338
-        return apply_filters( 'wpinv_get_item_vat_class', $class, $postID );
1338
+        return apply_filters('wpinv_get_item_vat_class', $class, $postID);
1339 1339
     }
1340 1340
     
1341
-    public static function item_class_label( $postID ) {        
1341
+    public static function item_class_label($postID) {        
1342 1342
         $vat_classes = self::get_all_classes();
1343 1343
         
1344
-        $class = self::get_item_class( $postID );
1345
-        $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' );
1344
+        $class = self::get_item_class($postID);
1345
+        $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing');
1346 1346
         
1347
-        return apply_filters( 'wpinv_item_class_label', $class, $postID );
1347
+        return apply_filters('wpinv_item_class_label', $class, $postID);
1348 1348
     }
1349 1349
     
1350
-    public static function get_item_rule( $postID ) {        
1351
-        $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true );
1350
+    public static function get_item_rule($postID) {        
1351
+        $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true);
1352 1352
         
1353
-        if ( empty( $rule_type ) ) {        
1353
+        if (empty($rule_type)) {        
1354 1354
             $rule_type = self::allow_vat_rules() ? 'digital' : 'physical';
1355 1355
         }
1356 1356
         
1357
-        return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID );
1357
+        return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID);
1358 1358
     }
1359 1359
     
1360
-    public static function item_rule_label( $postID ) {
1360
+    public static function item_rule_label($postID) {
1361 1361
         $vat_rules  = self::get_rules();
1362
-        $vat_rule   = self::get_item_rule( $postID );
1363
-        $vat_rule   = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule;
1362
+        $vat_rule   = self::get_item_rule($postID);
1363
+        $vat_rule   = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule;
1364 1364
         
1365
-        return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID );
1365
+        return apply_filters('wpinv_item_rule_label', $vat_rule, $postID);
1366 1366
     }
1367 1367
     
1368
-    public static function item_has_digital_rule( $item_id = 0 ) {        
1369
-        return self::get_item_rule( $item_id ) == 'digital' ? true : false;
1368
+    public static function item_has_digital_rule($item_id = 0) {        
1369
+        return self::get_item_rule($item_id) == 'digital' ? true : false;
1370 1370
     }
1371 1371
     
1372
-    public static function invoice_has_digital_rule( $invoice = 0 ) {        
1373
-        if ( !self::allow_vat_rules() ) {
1372
+    public static function invoice_has_digital_rule($invoice = 0) {        
1373
+        if (!self::allow_vat_rules()) {
1374 1374
             return false;
1375 1375
         }
1376 1376
         
1377
-        if ( empty( $invoice ) ) {
1377
+        if (empty($invoice)) {
1378 1378
             return true;
1379 1379
         }
1380 1380
         
1381
-        if ( is_int( $invoice ) ) {
1382
-            $invoice = new WPInv_Invoice( $invoice );
1381
+        if (is_int($invoice)) {
1382
+            $invoice = new WPInv_Invoice($invoice);
1383 1383
         }
1384 1384
         
1385
-        if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) {
1385
+        if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) {
1386 1386
             return true;
1387 1387
         }
1388 1388
         
1389
-        $cart_items  = $invoice->get_cart_details();
1389
+        $cart_items = $invoice->get_cart_details();
1390 1390
         
1391
-        if ( !empty( $cart_items ) ) {
1391
+        if (!empty($cart_items)) {
1392 1392
             $has_digital_rule = false;
1393 1393
             
1394
-            foreach ( $cart_items as $key => $item ) {
1395
-                if ( self::item_has_digital_rule( $item['id'] ) ) {
1394
+            foreach ($cart_items as $key => $item) {
1395
+                if (self::item_has_digital_rule($item['id'])) {
1396 1396
                     $has_digital_rule = true;
1397 1397
                     break;
1398 1398
                 }
@@ -1404,67 +1404,67 @@  discard block
 block discarded – undo
1404 1404
         return $has_digital_rule;
1405 1405
     }
1406 1406
     
1407
-    public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) {        
1408
-        if ( !wpinv_use_taxes() ) {
1407
+    public static function item_is_taxable($item_id = 0, $country = false, $state = false) {        
1408
+        if (!wpinv_use_taxes()) {
1409 1409
             return false;
1410 1410
         }
1411 1411
         
1412 1412
         $is_taxable = true;
1413 1413
 
1414
-        if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) {
1414
+        if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') {
1415 1415
             $is_taxable = false;
1416 1416
         }
1417 1417
         
1418
-        return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state );
1418
+        return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state);
1419 1419
     }
1420 1420
     
1421
-    public static function find_rate( $country, $state, $rate, $class ) {
1421
+    public static function find_rate($country, $state, $rate, $class) {
1422 1422
         global $wpi_zero_tax;
1423 1423
 
1424
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1424
+        if ($class === '_exempt' || $wpi_zero_tax) {
1425 1425
             return 0;
1426 1426
         }
1427 1427
 
1428
-        $tax_rates   = wpinv_get_tax_rates();
1428
+        $tax_rates = wpinv_get_tax_rates();
1429 1429
         
1430
-        if ( $class !== '_standard' ) {
1431
-            $class_rates = self::get_vat_rates( $class );
1430
+        if ($class !== '_standard') {
1431
+            $class_rates = self::get_vat_rates($class);
1432 1432
             
1433
-            if ( is_array( $class_rates ) ) {
1433
+            if (is_array($class_rates)) {
1434 1434
                 $indexed_class_rates = array();
1435 1435
                 
1436
-                foreach ( $class_rates as $key => $cr ) {
1436
+                foreach ($class_rates as $key => $cr) {
1437 1437
                     $indexed_class_rates[$cr['country']] = $cr;
1438 1438
                 }
1439 1439
 
1440
-                $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) {
1440
+                $tax_rates = array_map(function($tr) use($indexed_class_rates) {
1441 1441
                     $tr_country = $tr['country'];
1442
-                    if ( !isset( $indexed_class_rates[$tr_country] ) ) {
1442
+                    if (!isset($indexed_class_rates[$tr_country])) {
1443 1443
                         return $tr;
1444 1444
                     }
1445 1445
                     $icr = $indexed_class_rates[$tr_country];
1446
-                    return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr;
1446
+                    return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr;
1447 1447
 
1448
-                }, $tax_rates, $class_rates );
1448
+                }, $tax_rates, $class_rates);
1449 1449
             }
1450 1450
         }
1451 1451
 
1452
-        if ( !empty( $tax_rates ) ) {
1453
-            foreach ( $tax_rates as $key => $tax_rate ) {
1454
-                if ( $country != $tax_rate['country'] )
1452
+        if (!empty($tax_rates)) {
1453
+            foreach ($tax_rates as $key => $tax_rate) {
1454
+                if ($country != $tax_rate['country'])
1455 1455
                     continue;
1456 1456
 
1457
-                if ( !empty( $tax_rate['global'] ) ) {
1458
-                    if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) {
1459
-                        $rate = number_format( $tax_rate['rate'], 4 );
1457
+                if (!empty($tax_rate['global'])) {
1458
+                    if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) {
1459
+                        $rate = number_format($tax_rate['rate'], 4);
1460 1460
                     }
1461 1461
                 } else {
1462
-                    if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) )
1462
+                    if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state']))
1463 1463
                         continue;
1464 1464
 
1465 1465
                     $state_rate = $tax_rate['rate'];
1466
-                    if ( 0 !== $state_rate || !empty( $state_rate ) ) {
1467
-                        $rate = number_format( $state_rate, 4 );
1466
+                    if (0 !== $state_rate || !empty($state_rate)) {
1467
+                        $rate = number_format($state_rate, 4);
1468 1468
                     }
1469 1469
                 }
1470 1470
             }
@@ -1473,84 +1473,84 @@  discard block
 block discarded – undo
1473 1473
         return $rate;
1474 1474
     }
1475 1475
     
1476
-    public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) {
1476
+    public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) {
1477 1477
         global $wpinv_options, $wpi_session, $wpi_item_id, $wpi_zero_tax;
1478 1478
         
1479 1479
         $item_id = $item_id > 0 ? $item_id : $wpi_item_id;
1480 1480
         $allow_vat_classes = self::allow_vat_classes();
1481
-        $class = $item_id ? self::get_item_class( $item_id ) : '_standard';
1481
+        $class = $item_id ? self::get_item_class($item_id) : '_standard';
1482 1482
 
1483
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1483
+        if ($class === '_exempt' || $wpi_zero_tax) {
1484 1484
             return 0;
1485
-        } else if ( !$allow_vat_classes ) {
1485
+        } else if (!$allow_vat_classes) {
1486 1486
             $class = '_standard';
1487 1487
         }
1488 1488
 
1489
-        if( !empty( $_POST['wpinv_country'] ) ) {
1489
+        if (!empty($_POST['wpinv_country'])) {
1490 1490
             $post_country = $_POST['wpinv_country'];
1491
-        } elseif( !empty( $_POST['wpinv_country'] ) ) {
1491
+        } elseif (!empty($_POST['wpinv_country'])) {
1492 1492
             $post_country = $_POST['wpinv_country'];
1493
-        } elseif( !empty( $_POST['country'] ) ) {
1493
+        } elseif (!empty($_POST['country'])) {
1494 1494
             $post_country = $_POST['country'];
1495 1495
         } else {
1496 1496
             $post_country = '';
1497 1497
         }
1498 1498
 
1499
-        $country        = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country );
1500
-        $base_country   = wpinv_is_base_country( $country );
1499
+        $country        = !empty($post_country) ? $post_country : wpinv_default_billing_country($country);
1500
+        $base_country   = wpinv_is_base_country($country);
1501 1501
         
1502
-        $requires_vat   = self::requires_vat( 0, false );
1503
-        $is_digital     = self::get_item_rule( $item_id ) == 'digital' ;
1504
-        $rate           = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate;
1502
+        $requires_vat   = self::requires_vat(0, false);
1503
+        $is_digital     = self::get_item_rule($item_id) == 'digital';
1504
+        $rate           = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate;
1505 1505
           
1506
-        if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country
1506
+        if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country
1507 1507
             $rate = 0;
1508
-        } else if ( $requires_vat ) {
1509
-            $vat_number = self::get_user_vat_number( '', 0, true );
1508
+        } else if ($requires_vat) {
1509
+            $vat_number = self::get_user_vat_number('', 0, true);
1510 1510
             $vat_info   = self::current_vat_data();
1511 1511
             
1512
-            if ( is_array( $vat_info ) ) {
1513
-                $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : "";
1512
+            if (is_array($vat_info)) {
1513
+                $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : "";
1514 1514
             }
1515 1515
             
1516
-            if ( $country == 'UK' ) {
1516
+            if ($country == 'UK') {
1517 1517
                 $country = 'GB';
1518 1518
             }
1519 1519
 
1520
-            if ( !empty( $vat_number ) ) {
1520
+            if (!empty($vat_number)) {
1521 1521
                 $rate = 0;
1522 1522
             } else {
1523
-                $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
1523
+                $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
1524 1524
             }
1525 1525
 
1526
-            if ( empty( $vat_number ) && !$is_digital ) {
1527
-                if ( $base_country ) {
1528
-                    $rate = self::find_rate( $country, null, $rate, $class );
1526
+            if (empty($vat_number) && !$is_digital) {
1527
+                if ($base_country) {
1528
+                    $rate = self::find_rate($country, null, $rate, $class);
1529 1529
                 } else {
1530
-                    if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1530
+                    if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1531 1531
                         $rate = $wpinv_options['eu_fallback_rate'];
1532
-                    } else if( !empty( $country ) ) {
1533
-                        $rate = self::find_rate( $country, $state, $rate, $class );
1532
+                    } else if (!empty($country)) {
1533
+                        $rate = self::find_rate($country, $state, $rate, $class);
1534 1534
                     }
1535 1535
                 }
1536
-            } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) {
1537
-                if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1536
+            } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) {
1537
+                if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1538 1538
                     $rate = $wpinv_options['eu_fallback_rate'];
1539
-                } else if( !empty( $country ) ) {
1540
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1539
+                } else if (!empty($country)) {
1540
+                    $rate = self::find_rate($country, $state, $rate, $class);
1541 1541
                 }
1542 1542
             }
1543 1543
         } else {
1544
-            if ( $is_digital ) {
1544
+            if ($is_digital) {
1545 1545
                 $ip_country_code = self::get_country_by_ip();
1546 1546
                 
1547
-                if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) {
1548
-                    $rate = self::find_rate( $ip_country_code, '', 0, $class );
1547
+                if ($ip_country_code && self::is_eu_state($ip_country_code)) {
1548
+                    $rate = self::find_rate($ip_country_code, '', 0, $class);
1549 1549
                 } else {
1550
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1550
+                    $rate = self::find_rate($country, $state, $rate, $class);
1551 1551
                 }
1552 1552
             } else {
1553
-                $rate = self::find_rate( $country, $state, $rate, $class );
1553
+                $rate = self::find_rate($country, $state, $rate, $class);
1554 1554
             }
1555 1555
         }
1556 1556
 
@@ -1560,48 +1560,48 @@  discard block
 block discarded – undo
1560 1560
     public static function current_vat_data() {
1561 1561
         global $wpi_session;
1562 1562
         
1563
-        return $wpi_session->get( 'user_vat_data' );
1563
+        return $wpi_session->get('user_vat_data');
1564 1564
     }
1565 1565
     
1566
-    public static function get_user_country( $country = '', $user_id = 0 ) {
1567
-        $user_address = wpinv_get_user_address( $user_id, false );
1566
+    public static function get_user_country($country = '', $user_id = 0) {
1567
+        $user_address = wpinv_get_user_address($user_id, false);
1568 1568
         
1569
-        if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1569
+        if (wpinv_get_option('vat_ip_country_default')) {
1570 1570
             $country = '';
1571 1571
         }
1572 1572
         
1573
-        $country    = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country'];
1574
-        $result     = apply_filters( 'wpinv_get_user_country', $country, $user_id );
1573
+        $country    = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country'];
1574
+        $result     = apply_filters('wpinv_get_user_country', $country, $user_id);
1575 1575
 
1576
-        if ( empty( $result ) ) {
1576
+        if (empty($result)) {
1577 1577
             $result = self::get_country_by_ip();
1578 1578
         }
1579 1579
 
1580 1580
         return $result;
1581 1581
     }
1582 1582
     
1583
-    public static function set_user_country( $country = '', $user_id = 0 ) {
1583
+    public static function set_user_country($country = '', $user_id = 0) {
1584 1584
         global $wpi_userID;
1585 1585
         
1586
-        if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) {
1586
+        if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) {
1587 1587
             $country = wpinv_get_default_country();
1588 1588
         }
1589 1589
         
1590 1590
         return $country;
1591 1591
     }
1592 1592
     
1593
-    public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) {
1593
+    public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) {
1594 1594
         global $wpi_current_id, $wpi_userID;
1595 1595
         
1596
-        if ( !empty( $_POST['new_user'] ) ) {
1596
+        if (!empty($_POST['new_user'])) {
1597 1597
             return '';
1598 1598
         }
1599 1599
         
1600
-        if ( empty( $user_id ) ) {
1601
-            $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() );
1600
+        if (empty($user_id)) {
1601
+            $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id());
1602 1602
         }
1603 1603
 
1604
-        $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true );
1604
+        $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true);
1605 1605
         
1606 1606
         /* TODO
1607 1607
         if ( $is_valid && $vat_number ) {
@@ -1612,36 +1612,36 @@  discard block
 block discarded – undo
1612 1612
         }
1613 1613
         */
1614 1614
 
1615
-        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid );
1615
+        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid);
1616 1616
     }
1617 1617
     
1618
-    public static function get_user_company( $company = '', $user_id = 0 ) {
1619
-        if ( empty( $user_id ) ) {
1618
+    public static function get_user_company($company = '', $user_id = 0) {
1619
+        if (empty($user_id)) {
1620 1620
             $user_id = get_current_user_id();
1621 1621
         }
1622 1622
 
1623
-        $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true );
1623
+        $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true);
1624 1624
 
1625
-        return apply_filters( 'wpinv_user_company', $company, $user_id );
1625
+        return apply_filters('wpinv_user_company', $company, $user_id);
1626 1626
     }
1627 1627
     
1628
-    public static function save_user_vat_details( $company = '', $vat_number = '' ) {
1629
-        $save = apply_filters( 'wpinv_allow_save_user_vat_details', true );
1628
+    public static function save_user_vat_details($company = '', $vat_number = '') {
1629
+        $save = apply_filters('wpinv_allow_save_user_vat_details', true);
1630 1630
 
1631
-        if ( is_user_logged_in() && $save ) {
1631
+        if (is_user_logged_in() && $save) {
1632 1632
             $user_id = get_current_user_id();
1633 1633
 
1634
-            if ( !empty( $vat_number ) ) {
1635
-                update_user_meta( $user_id, '_wpinv_vat_number', $vat_number );
1634
+            if (!empty($vat_number)) {
1635
+                update_user_meta($user_id, '_wpinv_vat_number', $vat_number);
1636 1636
             } else {
1637
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1637
+                delete_user_meta($user_id, '_wpinv_vat_number');
1638 1638
             }
1639 1639
 
1640
-            if ( !empty( $company ) ) {
1641
-                update_user_meta( $user_id, '_wpinv_company', $company );
1640
+            if (!empty($company)) {
1641
+                update_user_meta($user_id, '_wpinv_company', $company);
1642 1642
             } else {
1643
-                delete_user_meta( $user_id, '_wpinv_company');
1644
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1643
+                delete_user_meta($user_id, '_wpinv_company');
1644
+                delete_user_meta($user_id, '_wpinv_vat_number');
1645 1645
             }
1646 1646
         }
1647 1647
 
@@ -1651,113 +1651,113 @@  discard block
 block discarded – undo
1651 1651
     public static function ajax_vat_validate() {
1652 1652
         global $wpinv_options, $wpi_session;
1653 1653
         
1654
-        $is_checkout            = ( !empty( $_POST['source'] ) && $_POST['source'] == 'checkout' ) ? true : false;
1654
+        $is_checkout            = (!empty($_POST['source']) && $_POST['source'] == 'checkout') ? true : false;
1655 1655
         $response               = array();
1656 1656
         $response['success']    = false;
1657 1657
         
1658
-        if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) {
1659
-            $response['error'] = __( 'Invalid security nonce', 'invoicing' );
1660
-            wp_send_json( $response );
1658
+        if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) {
1659
+            $response['error'] = __('Invalid security nonce', 'invoicing');
1660
+            wp_send_json($response);
1661 1661
         }
1662 1662
         
1663
-        $vat_name   = self::get_vat_name();
1663
+        $vat_name = self::get_vat_name();
1664 1664
         
1665
-        if ( $is_checkout ) {
1665
+        if ($is_checkout) {
1666 1666
             $invoice = wpinv_get_invoice_cart();
1667 1667
             
1668
-            if ( !self::requires_vat( false, 0, self::invoice_has_digital_rule( $invoice ) ) ) {
1668
+            if (!self::requires_vat(false, 0, self::invoice_has_digital_rule($invoice))) {
1669 1669
                 $vat_info = array();
1670
-                $wpi_session->set( 'user_vat_data', $vat_info );
1670
+                $wpi_session->set('user_vat_data', $vat_info);
1671 1671
 
1672 1672
                 self::save_user_vat_details();
1673 1673
                 
1674 1674
                 $response['success'] = true;
1675
-                $response['message'] = wp_sprintf( __( 'Ignore %s', 'invoicing' ), $vat_name );
1676
-                wp_send_json( $response );
1675
+                $response['message'] = wp_sprintf(__('Ignore %s', 'invoicing'), $vat_name);
1676
+                wp_send_json($response);
1677 1677
             }
1678 1678
         }
1679 1679
         
1680
-        $company    = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : '';
1681
-        $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : '';
1680
+        $company    = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : '';
1681
+        $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : '';
1682 1682
         
1683
-        $vat_info = $wpi_session->get( 'user_vat_data' );
1684
-        if ( !is_array( $vat_info ) || empty( $vat_info ) ) {
1685
-            $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true );
1683
+        $vat_info = $wpi_session->get('user_vat_data');
1684
+        if (!is_array($vat_info) || empty($vat_info)) {
1685
+            $vat_info = array('company'=> $company, 'number' => '', 'valid' => true);
1686 1686
         }
1687 1687
         
1688
-        if ( empty( $vat_number ) ) {
1689
-            if ( $is_checkout ) {
1688
+        if (empty($vat_number)) {
1689
+            if ($is_checkout) {
1690 1690
                 $response['success'] = true;
1691
-                $response['message'] = wp_sprintf( __( 'No %s number has been applied. %s will be added to invoice totals', 'invoicing' ), $vat_name, $vat_name );
1691
+                $response['message'] = wp_sprintf(__('No %s number has been applied. %s will be added to invoice totals', 'invoicing'), $vat_name, $vat_name);
1692 1692
                 
1693
-                $vat_info = $wpi_session->get( 'user_vat_data' );
1693
+                $vat_info = $wpi_session->get('user_vat_data');
1694 1694
                 $vat_info['number'] = "";
1695 1695
                 $vat_info['valid'] = true;
1696 1696
                 
1697
-                self::save_user_vat_details( $company );
1697
+                self::save_user_vat_details($company);
1698 1698
             } else {
1699
-                $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
1699
+                $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
1700 1700
                 
1701 1701
                 $vat_info['valid'] = false;
1702 1702
             }
1703 1703
 
1704
-            $wpi_session->set( 'user_vat_data', $vat_info );
1705
-            wp_send_json( $response );
1704
+            $wpi_session->set('user_vat_data', $vat_info);
1705
+            wp_send_json($response);
1706 1706
         }
1707 1707
         
1708
-        if ( empty( $company ) ) {
1708
+        if (empty($company)) {
1709 1709
             $vat_info['valid'] = false;
1710
-            $wpi_session->set( 'user_vat_data', $vat_info );
1710
+            $wpi_session->set('user_vat_data', $vat_info);
1711 1711
             
1712
-            $response['error'] = __( 'Please enter your registered company name!', 'invoicing' );
1713
-            wp_send_json( $response );
1712
+            $response['error'] = __('Please enter your registered company name!', 'invoicing');
1713
+            wp_send_json($response);
1714 1714
         }
1715 1715
         
1716
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
1717
-            if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1716
+        if (!empty($wpinv_options['vat_vies_check'])) {
1717
+            if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1718 1718
                 $vat_info['valid'] = false;
1719
-                $wpi_session->set( 'user_vat_data', $vat_info );
1719
+                $wpi_session->set('user_vat_data', $vat_info);
1720 1720
                 
1721
-                $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1722
-                wp_send_json( $response );
1721
+                $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1722
+                wp_send_json($response);
1723 1723
             }
1724 1724
             
1725 1725
             $response['success'] = true;
1726
-            $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1726
+            $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1727 1727
         } else {
1728
-            $result = self::check_vat( $vat_number );
1728
+            $result = self::check_vat($vat_number);
1729 1729
             
1730
-            if ( empty( $result['valid'] ) ) {
1730
+            if (empty($result['valid'])) {
1731 1731
                 $response['error'] = $result['message'];
1732
-                wp_send_json( $response );
1732
+                wp_send_json($response);
1733 1733
             }
1734 1734
             
1735
-            $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1736
-            $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1735
+            $vies_company = !empty($result['company']) ? $result['company'] : '';
1736
+            $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1737 1737
             
1738
-            $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1738
+            $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1739 1739
 
1740
-            if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) {
1740
+            if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) {
1741 1741
                 $response['success'] = true;
1742
-                $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1742
+                $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1743 1743
             } else {           
1744 1744
                 $vat_info['valid'] = false;
1745
-                $wpi_session->set( 'user_vat_data', $vat_info );
1745
+                $wpi_session->set('user_vat_data', $vat_info);
1746 1746
                 
1747 1747
                 $response['success'] = false;
1748
-                $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 );
1749
-                wp_send_json( $response );
1748
+                $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);
1749
+                wp_send_json($response);
1750 1750
             }
1751 1751
         }
1752 1752
         
1753
-        if ( $is_checkout ) {
1754
-            self::save_user_vat_details( $company, $vat_number );
1753
+        if ($is_checkout) {
1754
+            self::save_user_vat_details($company, $vat_number);
1755 1755
 
1756
-            $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true );
1757
-            $wpi_session->set( 'user_vat_data', $vat_info );
1756
+            $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true);
1757
+            $wpi_session->set('user_vat_data', $vat_info);
1758 1758
         }
1759 1759
 
1760
-        wp_send_json( $response );
1760
+        wp_send_json($response);
1761 1761
     }
1762 1762
     
1763 1763
     public static function ajax_vat_reset() {
@@ -1766,161 +1766,161 @@  discard block
 block discarded – undo
1766 1766
         $company    = is_user_logged_in() ? self::get_user_company() : '';
1767 1767
         $vat_number = self::get_user_vat_number();
1768 1768
         
1769
-        $vat_info   = array('company' => $company, 'number' => $vat_number, 'valid' => false );
1770
-        $wpi_session->set( 'user_vat_data', $vat_info );
1769
+        $vat_info   = array('company' => $company, 'number' => $vat_number, 'valid' => false);
1770
+        $wpi_session->set('user_vat_data', $vat_info);
1771 1771
         
1772 1772
         $response                       = array();
1773 1773
         $response['success']            = true;
1774 1774
         $response['data']['company']    = $company;
1775 1775
         $response['data']['number']     = $vat_number;
1776 1776
         
1777
-        wp_send_json( $response );
1777
+        wp_send_json($response);
1778 1778
     }
1779 1779
     
1780
-    public static function checkout_vat_validate( $valid_data, $post ) {
1780
+    public static function checkout_vat_validate($valid_data, $post) {
1781 1781
         global $wpinv_options, $wpi_session;
1782 1782
         
1783
-        $vat_name  = __( self::get_vat_name(), 'invoicing' );
1783
+        $vat_name = __(self::get_vat_name(), 'invoicing');
1784 1784
         
1785
-        if ( !isset( $_POST['_wpi_nonce'] ) || !wp_verify_nonce( $_POST['_wpi_nonce'], 'vat_validation' ) ) {
1786
-            wpinv_set_error( 'vat_validation', wp_sprintf( __( "Invalid %s validation request.", 'invoicing' ), $vat_name ) );
1785
+        if (!isset($_POST['_wpi_nonce']) || !wp_verify_nonce($_POST['_wpi_nonce'], 'vat_validation')) {
1786
+            wpinv_set_error('vat_validation', wp_sprintf(__("Invalid %s validation request.", 'invoicing'), $vat_name));
1787 1787
             return;
1788 1788
         }
1789 1789
         
1790
-        $vat_saved = $wpi_session->get( 'user_vat_data' );
1791
-        $wpi_session->set( 'user_vat_data', null );
1790
+        $vat_saved = $wpi_session->get('user_vat_data');
1791
+        $wpi_session->set('user_vat_data', null);
1792 1792
         
1793 1793
         $invoice        = wpinv_get_invoice_cart();
1794 1794
         $amount         = $invoice->get_total();
1795
-        $is_digital     = self::invoice_has_digital_rule( $invoice );
1796
-        $no_vat         = !self::requires_vat( 0, false, $is_digital );
1795
+        $is_digital     = self::invoice_has_digital_rule($invoice);
1796
+        $no_vat         = !self::requires_vat(0, false, $is_digital);
1797 1797
         
1798
-        $company        = !empty( $_POST['wpinv_company'] ) ? $_POST['wpinv_company'] : null;
1799
-        $vat_number     = !empty( $_POST['wpinv_vat_number'] ) ? $_POST['wpinv_vat_number'] : null;
1800
-        $country        = !empty( $_POST['wpinv_country'] ) ? $_POST['wpinv_country'] : $invoice->country;
1801
-        if ( empty( $country ) ) {
1798
+        $company        = !empty($_POST['wpinv_company']) ? $_POST['wpinv_company'] : null;
1799
+        $vat_number     = !empty($_POST['wpinv_vat_number']) ? $_POST['wpinv_vat_number'] : null;
1800
+        $country        = !empty($_POST['wpinv_country']) ? $_POST['wpinv_country'] : $invoice->country;
1801
+        if (empty($country)) {
1802 1802
             $country = wpinv_default_billing_country();
1803 1803
         }
1804 1804
         
1805
-        if ( !$is_digital && $no_vat ) {
1805
+        if (!$is_digital && $no_vat) {
1806 1806
             return;
1807 1807
         }
1808 1808
             
1809
-        $vat_data           = array( 'company' => '', 'number' => '', 'valid' => false );
1809
+        $vat_data           = array('company' => '', 'number' => '', 'valid' => false);
1810 1810
         
1811 1811
         $ip_country_code    = self::get_country_by_ip();
1812
-        $is_eu_state        = self::is_eu_state( $country );
1813
-        $is_eu_state_ip     = self::is_eu_state( $ip_country_code );
1812
+        $is_eu_state        = self::is_eu_state($country);
1813
+        $is_eu_state_ip     = self::is_eu_state($ip_country_code);
1814 1814
         $is_non_eu_user     = !$is_eu_state && !$is_eu_state_ip;
1815 1815
         
1816
-        if ( $is_digital && !$is_non_eu_user && empty( $vat_number ) && apply_filters( 'wpinv_checkout_requires_country', true, $amount ) ) {
1816
+        if ($is_digital && !$is_non_eu_user && empty($vat_number) && apply_filters('wpinv_checkout_requires_country', true, $amount)) {
1817 1817
             $vat_data['adddress_confirmed'] = false;
1818 1818
             
1819
-            if ( !isset( $_POST['wpinv_adddress_confirmed'] ) ) {
1820
-                if ( $ip_country_code != $country ) {
1821
-                    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>' ) );
1819
+            if (!isset($_POST['wpinv_adddress_confirmed'])) {
1820
+                if ($ip_country_code != $country) {
1821
+                    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>'));
1822 1822
                 }
1823 1823
             } else {
1824 1824
                 $vat_data['adddress_confirmed'] = true;
1825 1825
             }
1826 1826
         }
1827 1827
         
1828
-        if ( !empty( $wpinv_options['vat_prevent_b2c_purchase'] ) && !$is_non_eu_user && ( empty( $vat_number ) || $no_vat ) ) {
1829
-            if ( $is_eu_state ) {
1830
-                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 ) );
1831
-            } else if ( $is_digital && $is_eu_state_ip ) {
1832
-                wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing' ), $vat_name ) );
1828
+        if (!empty($wpinv_options['vat_prevent_b2c_purchase']) && !$is_non_eu_user && (empty($vat_number) || $no_vat)) {
1829
+            if ($is_eu_state) {
1830
+                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));
1831
+            } else if ($is_digital && $is_eu_state_ip) {
1832
+                wpinv_set_error('vat_validation', wp_sprintf(__('Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing'), $vat_name));
1833 1833
             }
1834 1834
         }
1835 1835
         
1836
-        if ( !$is_eu_state || $no_vat || empty( $vat_number ) ) {
1836
+        if (!$is_eu_state || $no_vat || empty($vat_number)) {
1837 1837
             return;
1838 1838
         }
1839 1839
 
1840
-        if ( !empty( $vat_saved ) && isset( $vat_saved['valid'] ) ) {
1841
-            $vat_data['valid']  = $vat_saved['valid'];
1840
+        if (!empty($vat_saved) && isset($vat_saved['valid'])) {
1841
+            $vat_data['valid'] = $vat_saved['valid'];
1842 1842
         }
1843 1843
             
1844
-        if ( $company !== null ) {
1844
+        if ($company !== null) {
1845 1845
             $vat_data['company'] = $company;
1846 1846
         }
1847 1847
 
1848 1848
         $message = '';
1849
-        if ( $vat_number !== null ) {
1849
+        if ($vat_number !== null) {
1850 1850
             $vat_data['number'] = $vat_number;
1851 1851
             
1852
-            if ( !$vat_data['valid'] || ( $vat_saved['number'] !== $vat_data['number'] ) || ( $vat_saved['company'] !== $vat_data['company'] ) ) {
1853
-                if ( !empty( $wpinv_options['vat_vies_check'] ) ) {            
1854
-                    if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1852
+            if (!$vat_data['valid'] || ($vat_saved['number'] !== $vat_data['number']) || ($vat_saved['company'] !== $vat_data['company'])) {
1853
+                if (!empty($wpinv_options['vat_vies_check'])) {            
1854
+                    if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1855 1855
                         $vat_data['valid'] = false;
1856 1856
                     }
1857 1857
                 } else {
1858
-                    $result = self::check_vat( $vat_number );
1858
+                    $result = self::check_vat($vat_number);
1859 1859
                     
1860
-                    if ( !empty( $result['valid'] ) ) {                
1860
+                    if (!empty($result['valid'])) {                
1861 1861
                         $vat_data['valid'] = true;
1862
-                        $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1863
-                        $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1862
+                        $vies_company = !empty($result['company']) ? $result['company'] : '';
1863
+                        $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1864 1864
                     
1865
-                        $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1865
+                        $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1866 1866
 
1867
-                        if ( !( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) ) {         
1867
+                        if (!(!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company)) {         
1868 1868
                             $vat_data['valid'] = false;
1869 1869
                             
1870
-                            $message = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name );
1870
+                            $message = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name);
1871 1871
                         }
1872 1872
                     } else {
1873
-                        $message = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
1873
+                        $message = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
1874 1874
                     }
1875 1875
                 }
1876 1876
                 
1877
-                if ( !$vat_data['valid'] ) {
1878
-                    $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 . ' )' : '' );
1879
-                    wpinv_set_error( 'vat_validation', $error );
1877
+                if (!$vat_data['valid']) {
1878
+                    $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 . ' )' : '');
1879
+                    wpinv_set_error('vat_validation', $error);
1880 1880
                 }
1881 1881
             }
1882 1882
         }
1883 1883
 
1884
-        $wpi_session->set( 'user_vat_data', $vat_data );
1884
+        $wpi_session->set('user_vat_data', $vat_data);
1885 1885
     }
1886 1886
     
1887
-    public static function checkout_vat_fields( $billing_details ) {
1887
+    public static function checkout_vat_fields($billing_details) {
1888 1888
         global $wpi_session, $wpinv_options, $wpi_country, $wpi_requires_vat;
1889 1889
         
1890 1890
         $ip_address         = wpinv_get_ip();
1891 1891
         $ip_country_code    = self::get_country_by_ip();
1892 1892
         
1893
-        $tax_label          = __( self::get_vat_name(), 'invoicing' );
1893
+        $tax_label          = __(self::get_vat_name(), 'invoicing');
1894 1894
         $invoice            = wpinv_get_invoice_cart();
1895
-        $is_digital         = self::invoice_has_digital_rule( $invoice );
1895
+        $is_digital         = self::invoice_has_digital_rule($invoice);
1896 1896
         $wpi_country        = $invoice->country;
1897 1897
         
1898
-        $requires_vat       = !self::hide_vat_fields() && $invoice->get_total() > 0 && self::requires_vat( 0, false, $is_digital );
1898
+        $requires_vat       = !self::hide_vat_fields() && $invoice->get_total() > 0 && self::requires_vat(0, false, $is_digital);
1899 1899
         $wpi_requires_vat   = $requires_vat;
1900 1900
         
1901 1901
         $company            = is_user_logged_in() ? self::get_user_company() : '';
1902 1902
         $vat_number         = self::get_user_vat_number();
1903 1903
         
1904
-        $validated          = $vat_number ? self::get_user_vat_number( '', 0, true ) : 1;
1905
-        $vat_info           = $wpi_session->get( 'user_vat_data' );
1904
+        $validated          = $vat_number ? self::get_user_vat_number('', 0, true) : 1;
1905
+        $vat_info           = $wpi_session->get('user_vat_data');
1906 1906
 
1907
-        if ( is_array( $vat_info ) ) {
1908
-            $company    = isset( $vat_info['company'] ) ? $vat_info['company'] : '';
1909
-            $vat_number = isset( $vat_info['number'] ) ? $vat_info['number'] : '';
1910
-            $validated  = isset( $vat_info['valid'] ) ? $vat_info['valid'] : false;
1907
+        if (is_array($vat_info)) {
1908
+            $company    = isset($vat_info['company']) ? $vat_info['company'] : '';
1909
+            $vat_number = isset($vat_info['number']) ? $vat_info['number'] : '';
1910
+            $validated  = isset($vat_info['valid']) ? $vat_info['valid'] : false;
1911 1911
         }
1912 1912
         
1913 1913
         $selected_country = $invoice->country ? $invoice->country : wpinv_default_billing_country();
1914 1914
 
1915
-        if ( $ip_country_code == 'UK' ) {
1915
+        if ($ip_country_code == 'UK') {
1916 1916
             $ip_country_code = 'GB';
1917 1917
         }
1918 1918
         
1919
-        if ( $selected_country == 'UK' ) {
1919
+        if ($selected_country == 'UK') {
1920 1920
             $selected_country = 'GB';
1921 1921
         }
1922 1922
         
1923
-        if ( $requires_vat && ( self::same_country_rule() == 'no' && wpinv_is_base_country( $selected_country ) || !self::allow_vat_rules() ) ) {
1923
+        if ($requires_vat && (self::same_country_rule() == 'no' && wpinv_is_base_country($selected_country) || !self::allow_vat_rules())) {
1924 1924
             $requires_vat = false;
1925 1925
         }
1926 1926
 
@@ -1928,52 +1928,52 @@  discard block
 block discarded – undo
1928 1928
         $display_validate_btn   = 'none';
1929 1929
         $display_reset_btn      = 'none';
1930 1930
         
1931
-        if ( !empty( $vat_number ) && $validated ) {
1932
-            $vat_vailidated_text    = wp_sprintf( __( '%s number validated', 'invoicing' ), $tax_label );
1931
+        if (!empty($vat_number) && $validated) {
1932
+            $vat_vailidated_text    = wp_sprintf(__('%s number validated', 'invoicing'), $tax_label);
1933 1933
             $vat_vailidated_class   = 'wpinv-vat-stat-1';
1934 1934
             $display_reset_btn      = 'block';
1935 1935
         } else {
1936
-            $vat_vailidated_text    = empty( $vat_number ) ? '' : wp_sprintf( __( '%s number not validated', 'invoicing' ), $tax_label );
1937
-            $vat_vailidated_class   = empty( $vat_number ) ? '' : 'wpinv-vat-stat-0';
1936
+            $vat_vailidated_text    = empty($vat_number) ? '' : wp_sprintf(__('%s number not validated', 'invoicing'), $tax_label);
1937
+            $vat_vailidated_class   = empty($vat_number) ? '' : 'wpinv-vat-stat-0';
1938 1938
             $display_validate_btn   = 'block';
1939 1939
         }
1940 1940
         
1941
-        $show_ip_country        = $is_digital && ( empty( $vat_number ) || !$requires_vat ) && $ip_country_code != $selected_country ? 'block' : 'none';
1941
+        $show_ip_country = $is_digital && (empty($vat_number) || !$requires_vat) && $ip_country_code != $selected_country ? 'block' : 'none';
1942 1942
         ?>
1943 1943
         <div id="wpi-vat-details" class="wpi-vat-details clearfix" style="display:<?php echo $display_vat_details; ?>">
1944 1944
             <div id="wpi_vat_info" class="clearfix panel panel-default">
1945
-                <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf( __( '%s Details', 'invoicing' ), $tax_label );?></h3></div>
1945
+                <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf(__('%s Details', 'invoicing'), $tax_label); ?></h3></div>
1946 1946
                 <div id="wpinv-fields-box" class="panel-body">
1947 1947
                     <p id="wpi_show_vat_note">
1948
-                        <?php echo wp_sprintf( __( 'Validate your registered %s number to exclude tax.', 'invoicing' ), $tax_label ); ?>
1948
+                        <?php echo wp_sprintf(__('Validate your registered %s number to exclude tax.', 'invoicing'), $tax_label); ?>
1949 1949
                     </p>
1950 1950
                     <div id="wpi_vat_fields" class="wpi_vat_info">
1951 1951
                         <p class="wpi-cart-field wpi-col2 wpi-colf">
1952
-                            <label for="wpinv_company" class="wpi-label"><?php _e( 'Company Name', 'invoicing' );?></label>
1952
+                            <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label>
1953 1953
                             <?php
1954
-                            echo wpinv_html_text( array(
1954
+                            echo wpinv_html_text(array(
1955 1955
                                     'id'            => 'wpinv_company',
1956 1956
                                     'name'          => 'wpinv_company',
1957 1957
                                     'value'         => $company,
1958 1958
                                     'class'         => 'wpi-input form-control',
1959
-                                    'placeholder'   => __( 'Company name', 'invoicing' ),
1960
-                                ) );
1959
+                                    'placeholder'   => __('Company name', 'invoicing'),
1960
+                                ));
1961 1961
                             ?>
1962 1962
                         </p>
1963 1963
                         <p class="wpi-cart-field wpi-col2 wpi-coll wpi-cart-field-vat">
1964
-                            <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf( __( '%s Number', 'invoicing' ), $tax_label );?></label>
1964
+                            <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf(__('%s Number', 'invoicing'), $tax_label); ?></label>
1965 1965
                             <span id="wpinv_vat_number-wrap">
1966 1966
                                 <label for="wpinv_vat_number" class="wpinv-label"></label>
1967
-                                <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">
1968
-                                <span class="wpinv-vat-stat <?php echo $vat_vailidated_class;?>"><i class="fa"></i>&nbsp;<font><?php echo $vat_vailidated_text;?></font></span>
1967
+                                <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">
1968
+                                <span class="wpinv-vat-stat <?php echo $vat_vailidated_class; ?>"><i class="fa"></i>&nbsp;<font><?php echo $vat_vailidated_text; ?></font></span>
1969 1969
                             </span>
1970 1970
                         </p>
1971 1971
                         <p class="wpi-cart-field wpi-col wpi-colf wpi-cart-field-actions">
1972
-                            <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>
1973
-                            <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>
1972
+                            <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>
1973
+                            <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>
1974 1974
                             <span class="wpi-vat-box wpi-vat-box-info"><span id="text"></span></span>
1975 1975
                             <span class="wpi-vat-box wpi-vat-box-error"><span id="text"></span></span>
1976
-                            <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce( 'vat_validation' ) ?>" />
1976
+                            <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce('vat_validation') ?>" />
1977 1977
                         </p>
1978 1978
                     </div>
1979 1979
                 </div>
@@ -1987,32 +1987,32 @@  discard block
 block discarded – undo
1987 1987
                 </span>
1988 1988
             </div>
1989 1989
         </div>
1990
-        <?php if ( empty( $wpinv_options['hide_ip_address'] ) ) { 
1991
-            $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>';
1990
+        <?php if (empty($wpinv_options['hide_ip_address'])) { 
1991
+            $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>';
1992 1992
         ?>
1993 1993
         <div class="wpi-ip-info clearfix panel panel-info">
1994 1994
             <div id="wpinv-fields-box" class="panel-body">
1995
-                <span><?php echo wp_sprintf( __( "Your IP address is: %s", 'invoicing' ), $ip_link ); ?></span>
1995
+                <span><?php echo wp_sprintf(__("Your IP address is: %s", 'invoicing'), $ip_link); ?></span>
1996 1996
             </div>
1997 1997
         </div>
1998 1998
         <?php }
1999 1999
     }
2000 2000
     
2001
-    public static function show_vat_notice( $invoice ) {
2002
-        if ( empty( $invoice ) ) {
2001
+    public static function show_vat_notice($invoice) {
2002
+        if (empty($invoice)) {
2003 2003
             return NULL;
2004 2004
         }
2005 2005
         
2006
-        $label      = wpinv_get_option( 'vat_invoice_notice_label' );
2007
-        $notice     = wpinv_get_option( 'vat_invoice_notice' );
2008
-        if ( $label || $notice ) {
2006
+        $label      = wpinv_get_option('vat_invoice_notice_label');
2007
+        $notice     = wpinv_get_option('vat_invoice_notice');
2008
+        if ($label || $notice) {
2009 2009
         ?>
2010 2010
         <div class="row wpinv-vat-notice">
2011 2011
             <div class="col-sm-12">
2012
-                <?php if ( $label ) { ?>
2013
-                <strong><?php _e( $label, 'invoicing' ); ?></strong>
2014
-                <?php } if ( $notice ) { ?>
2015
-                <?php echo wpautop( wptexturize( __( $notice, 'invoicing' ) ) ) ?>
2012
+                <?php if ($label) { ?>
2013
+                <strong><?php _e($label, 'invoicing'); ?></strong>
2014
+                <?php } if ($notice) { ?>
2015
+                <?php echo wpautop(wptexturize(__($notice, 'invoicing'))) ?>
2016 2016
                 <?php } ?>
2017 2017
             </div>
2018 2018
         </div>
Please login to merge, or discard this patch.
includes/wpinv-discount-functions.php 3 patches
Doc Comments   +18 added lines patch added patch discarded remove patch
@@ -324,12 +324,18 @@  discard block
 block discarded – undo
324 324
     return apply_filters( 'wpinv_get_discount_code', $code, $code_id );
325 325
 }
326 326
 
327
+/**
328
+ * @return string
329
+ */
327 330
 function wpinv_get_discount_start_date( $code_id = null ) {
328 331
     $start_date = get_post_meta( $code_id, '_wpi_discount_start', true );
329 332
 
330 333
     return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id );
331 334
 }
332 335
 
336
+/**
337
+ * @return string
338
+ */
333 339
 function wpinv_get_discount_expiration( $code_id = null ) {
334 340
     $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true );
335 341
 
@@ -652,6 +658,9 @@  discard block
 block discarded – undo
652 658
     return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition );
653 659
 }
654 660
 
661
+/**
662
+ * @param string $code
663
+ */
655 664
 function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) {
656 665
     global $wpi_checkout_id;
657 666
     
@@ -817,6 +826,9 @@  discard block
 block discarded – undo
817 826
 
818 827
 }
819 828
 
829
+/**
830
+ * @param double $amount
831
+ */
820 832
 function wpinv_format_discount_rate( $type, $amount ) {
821 833
     if ( $type == 'flat' ) {
822 834
         return wpinv_price( wpinv_format_amount( $amount ) );
@@ -861,6 +873,9 @@  discard block
 block discarded – undo
861 873
     return $discounts;
862 874
 }
863 875
 
876
+/**
877
+ * @return boolean
878
+ */
864 879
 function wpinv_unset_cart_discount( $code = '' ) {    
865 880
     $discounts = wpinv_get_cart_discounts();
866 881
 
@@ -1175,6 +1190,9 @@  discard block
 block discarded – undo
1175 1190
 }
1176 1191
 //add_action( 'init', 'wpinv_apply_preset_discount', 999 );
1177 1192
 
1193
+/**
1194
+ * @param integer $code
1195
+ */
1178 1196
 function wpinv_get_discount_label( $code, $echo = true ) {
1179 1197
     $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) );
1180 1198
     $label = apply_filters( 'wpinv_get_discount_label', $label, $code );
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -887,8 +887,8 @@
 block discarded – undo
887 887
     if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) {
888 888
         unset( $data['cart_discounts'] );
889 889
         
890
-         wpinv_set_checkout_session( $data );
891
-         return true;
890
+            wpinv_set_checkout_session( $data );
891
+            return true;
892 892
     }
893 893
     
894 894
     return false;
Please login to merge, or discard this patch.
Spacing   +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( 'wpi-cancelled', 'wpi-failed' ) ) ) {
685
+        if ($payments) {
686
+            foreach ($payments as $payment) {
687
+                if ($payment->has_status(array('wpi-cancelled', 'wpi-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_round_amount( $amount );
950
+    $amount = wpinv_round_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( wpinv_format_amount( $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(wpinv_format_amount($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   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -688,8 +688,8 @@
 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(
691
+    // Default, built-in gateways
692
+    $emails = array(
693 693
             'new_invoice' => array(
694 694
             'email_new_invoice_header' => array(
695 695
                 'id'   => 'email_new_invoice_header',
Please login to merge, or discard this patch.
Spacing   +507 added lines, -507 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,79 +28,79 @@  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 );
77
-add_action( 'wpinv_email_before_note_details', 'wpinv_email_before_note_details', 10, 4 );
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
+add_action('wpinv_email_before_note_details', 'wpinv_email_before_note_details', 10, 4);
78 78
 
79 79
 function wpinv_send_transactional_email() {
80 80
     $args       = func_get_args();
81 81
     $function   = current_filter() . '_notification';
82
-    do_action_ref_array( $function, $args );
82
+    do_action_ref_array($function, $args);
83 83
 }
84 84
     
85
-function wpinv_new_invoice_notification( $invoice_id, $new_status = '' ) {
85
+function wpinv_new_invoice_notification($invoice_id, $new_status = '') {
86 86
     global $wpinv_email_search, $wpinv_email_replace;
87 87
     
88 88
     $email_type = 'new_invoice';
89
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
89
+    if (!wpinv_email_is_enabled($email_type)) {
90 90
         return false;
91 91
     }
92 92
     
93
-    $invoice = wpinv_get_invoice( $invoice_id );
94
-    if ( empty( $invoice ) ) {
93
+    $invoice = wpinv_get_invoice($invoice_id);
94
+    if (empty($invoice)) {
95 95
         return false;
96 96
     }
97 97
 
98
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
98
+    if (!("wpi_invoice" === $invoice->post_type)) {
99 99
         return false;
100 100
     }
101 101
     
102
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
103
-    if ( !is_email( $recipient ) ) {
102
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
103
+    if (!is_email($recipient)) {
104 104
         return false;
105 105
     }
106 106
         
@@ -117,41 +117,41 @@  discard block
 block discarded – undo
117 117
     $wpinv_email_search     = $search;
118 118
     $wpinv_email_replace    = $replace;
119 119
     
120
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
121
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
122
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
123
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
120
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
121
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
122
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
123
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
124 124
     
125
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
125
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
126 126
             'invoice'       => $invoice,
127 127
             'email_type'    => $email_type,
128 128
             'email_heading' => $email_heading,
129 129
             'sent_to_admin' => true,
130 130
             'plain_text'    => false,
131
-        ) );
131
+        ));
132 132
     
133
-    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
133
+    return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
134 134
 }
135 135
 
136
-function wpinv_cancelled_invoice_notification( $invoice_id, $new_status = '' ) {
136
+function wpinv_cancelled_invoice_notification($invoice_id, $new_status = '') {
137 137
     global $wpinv_email_search, $wpinv_email_replace;
138 138
     
139 139
     $email_type = 'cancelled_invoice';
140
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
140
+    if (!wpinv_email_is_enabled($email_type)) {
141 141
         return false;
142 142
     }
143 143
     
144
-    $invoice = wpinv_get_invoice( $invoice_id );
145
-    if ( empty( $invoice ) ) {
144
+    $invoice = wpinv_get_invoice($invoice_id);
145
+    if (empty($invoice)) {
146 146
         return false;
147 147
     }
148 148
 
149
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
149
+    if (!("wpi_invoice" === $invoice->post_type)) {
150 150
         return false;
151 151
     }
152 152
     
153
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
154
-    if ( !is_email( $recipient ) ) {
153
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
154
+    if (!is_email($recipient)) {
155 155
         return false;
156 156
     }
157 157
         
@@ -168,41 +168,41 @@  discard block
 block discarded – undo
168 168
     $wpinv_email_search     = $search;
169 169
     $wpinv_email_replace    = $replace;
170 170
     
171
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
172
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
173
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
174
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
171
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
172
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
173
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
174
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
175 175
     
176
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
176
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
177 177
             'invoice'       => $invoice,
178 178
             'email_type'    => $email_type,
179 179
             'email_heading' => $email_heading,
180 180
             'sent_to_admin' => true,
181 181
             'plain_text'    => false,
182
-        ) );
182
+        ));
183 183
     
184
-    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
184
+    return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
185 185
 }
186 186
 
187
-function wpinv_failed_invoice_notification( $invoice_id, $new_status = '' ) {
187
+function wpinv_failed_invoice_notification($invoice_id, $new_status = '') {
188 188
     global $wpinv_email_search, $wpinv_email_replace;
189 189
     
190 190
     $email_type = 'failed_invoice';
191
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
191
+    if (!wpinv_email_is_enabled($email_type)) {
192 192
         return false;
193 193
     }
194 194
     
195
-    $invoice = wpinv_get_invoice( $invoice_id );
196
-    if ( empty( $invoice ) ) {
195
+    $invoice = wpinv_get_invoice($invoice_id);
196
+    if (empty($invoice)) {
197 197
         return false;
198 198
     }
199 199
 
200
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
200
+    if (!("wpi_invoice" === $invoice->post_type)) {
201 201
         return false;
202 202
     }
203 203
     
204
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
205
-    if ( !is_email( $recipient ) ) {
204
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
205
+    if (!is_email($recipient)) {
206 206
         return false;
207 207
     }
208 208
         
@@ -219,41 +219,41 @@  discard block
 block discarded – undo
219 219
     $wpinv_email_search     = $search;
220 220
     $wpinv_email_replace    = $replace;
221 221
     
222
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
223
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
224
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
225
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
222
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
223
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
224
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
225
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
226 226
     
227
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
227
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
228 228
             'invoice'       => $invoice,
229 229
             'email_type'    => $email_type,
230 230
             'email_heading' => $email_heading,
231 231
             'sent_to_admin' => true,
232 232
             'plain_text'    => false,
233
-        ) );
233
+        ));
234 234
     
235
-    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
235
+    return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
236 236
 }
237 237
 
238
-function wpinv_onhold_invoice_notification( $invoice_id, $new_status = '' ) {
238
+function wpinv_onhold_invoice_notification($invoice_id, $new_status = '') {
239 239
     global $wpinv_email_search, $wpinv_email_replace;
240 240
     
241 241
     $email_type = 'onhold_invoice';
242
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
242
+    if (!wpinv_email_is_enabled($email_type)) {
243 243
         return false;
244 244
     }
245 245
     
246
-    $invoice = wpinv_get_invoice( $invoice_id );
247
-    if ( empty( $invoice ) ) {
246
+    $invoice = wpinv_get_invoice($invoice_id);
247
+    if (empty($invoice)) {
248 248
         return false;
249 249
     }
250 250
 
251
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
251
+    if (!("wpi_invoice" === $invoice->post_type)) {
252 252
         return false;
253 253
     }
254 254
     
255
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
256
-    if ( !is_email( $recipient ) ) {
255
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
256
+    if (!is_email($recipient)) {
257 257
         return false;
258 258
     }
259 259
         
@@ -270,49 +270,49 @@  discard block
 block discarded – undo
270 270
     $wpinv_email_search     = $search;
271 271
     $wpinv_email_replace    = $replace;
272 272
     
273
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
274
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
275
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
276
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
273
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
274
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
275
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
276
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
277 277
     
278
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
278
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
279 279
             'invoice'       => $invoice,
280 280
             'email_type'    => $email_type,
281 281
             'email_heading' => $email_heading,
282 282
             'sent_to_admin' => false,
283 283
             'plain_text'    => false,
284
-        ) );
284
+        ));
285 285
     
286
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
286
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
287 287
     
288
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
289
-        $recipient  = wpinv_get_admin_email();
290
-        $subject    .= ' - ADMIN BCC COPY';
291
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
288
+    if (wpinv_mail_admin_bcc_active($email_type)) {
289
+        $recipient = wpinv_get_admin_email();
290
+        $subject .= ' - ADMIN BCC COPY';
291
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
292 292
     }
293 293
     
294 294
     return $sent;
295 295
 }
296 296
 
297
-function wpinv_processing_invoice_notification( $invoice_id, $new_status = '' ) {
297
+function wpinv_processing_invoice_notification($invoice_id, $new_status = '') {
298 298
     global $wpinv_email_search, $wpinv_email_replace;
299 299
     
300 300
     $email_type = 'processing_invoice';
301
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
301
+    if (!wpinv_email_is_enabled($email_type)) {
302 302
         return false;
303 303
     }
304 304
     
305
-    $invoice = wpinv_get_invoice( $invoice_id );
306
-    if ( empty( $invoice ) ) {
305
+    $invoice = wpinv_get_invoice($invoice_id);
306
+    if (empty($invoice)) {
307 307
         return false;
308 308
     }
309 309
 
310
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
310
+    if (!("wpi_invoice" === $invoice->post_type)) {
311 311
         return false;
312 312
     }
313 313
     
314
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
315
-    if ( !is_email( $recipient ) ) {
314
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
315
+    if (!is_email($recipient)) {
316 316
         return false;
317 317
     }
318 318
         
@@ -329,49 +329,49 @@  discard block
 block discarded – undo
329 329
     $wpinv_email_search     = $search;
330 330
     $wpinv_email_replace    = $replace;
331 331
     
332
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
333
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
334
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
335
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
332
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
333
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
334
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
335
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
336 336
     
337
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
337
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
338 338
             'invoice'       => $invoice,
339 339
             'email_type'    => $email_type,
340 340
             'email_heading' => $email_heading,
341 341
             'sent_to_admin' => false,
342 342
             'plain_text'    => false,
343
-        ) );
343
+        ));
344 344
     
345
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
345
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
346 346
     
347
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
348
-        $recipient  = wpinv_get_admin_email();
349
-        $subject    .= ' - ADMIN BCC COPY';
350
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
347
+    if (wpinv_mail_admin_bcc_active($email_type)) {
348
+        $recipient = wpinv_get_admin_email();
349
+        $subject .= ' - ADMIN BCC COPY';
350
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
351 351
     }
352 352
     
353 353
     return $sent;
354 354
 }
355 355
 
356
-function wpinv_completed_invoice_notification( $invoice_id, $new_status = '' ) {
356
+function wpinv_completed_invoice_notification($invoice_id, $new_status = '') {
357 357
     global $wpinv_email_search, $wpinv_email_replace;
358 358
     
359 359
     $email_type = 'completed_invoice';
360
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
360
+    if (!wpinv_email_is_enabled($email_type)) {
361 361
         return false;
362 362
     }
363 363
     
364
-    $invoice = wpinv_get_invoice( $invoice_id );
365
-    if ( empty( $invoice ) ) {
364
+    $invoice = wpinv_get_invoice($invoice_id);
365
+    if (empty($invoice)) {
366 366
         return false;
367 367
     }
368 368
 
369
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
369
+    if (!("wpi_invoice" === $invoice->post_type)) {
370 370
         return false;
371 371
     }
372 372
     
373
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
374
-    if ( !is_email( $recipient ) ) {
373
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
374
+    if (!is_email($recipient)) {
375 375
         return false;
376 376
     }
377 377
         
@@ -388,49 +388,49 @@  discard block
 block discarded – undo
388 388
     $wpinv_email_search     = $search;
389 389
     $wpinv_email_replace    = $replace;
390 390
     
391
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
392
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
393
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
394
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
391
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
392
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
393
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
394
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
395 395
     
396
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
396
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
397 397
             'invoice'       => $invoice,
398 398
             'email_type'    => $email_type,
399 399
             'email_heading' => $email_heading,
400 400
             'sent_to_admin' => false,
401 401
             'plain_text'    => false,
402
-        ) );
402
+        ));
403 403
     
404
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
404
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
405 405
     
406
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
407
-        $recipient  = wpinv_get_admin_email();
408
-        $subject    .= ' - ADMIN BCC COPY';
409
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
406
+    if (wpinv_mail_admin_bcc_active($email_type)) {
407
+        $recipient = wpinv_get_admin_email();
408
+        $subject .= ' - ADMIN BCC COPY';
409
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
410 410
     }
411 411
     
412 412
     return $sent;
413 413
 }
414 414
 
415
-function wpinv_fully_refunded_notification( $invoice_id, $new_status = '' ) {
415
+function wpinv_fully_refunded_notification($invoice_id, $new_status = '') {
416 416
     global $wpinv_email_search, $wpinv_email_replace;
417 417
     
418 418
     $email_type = 'refunded_invoice';
419
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
419
+    if (!wpinv_email_is_enabled($email_type)) {
420 420
         return false;
421 421
     }
422 422
     
423
-    $invoice = wpinv_get_invoice( $invoice_id );
424
-    if ( empty( $invoice ) ) {
423
+    $invoice = wpinv_get_invoice($invoice_id);
424
+    if (empty($invoice)) {
425 425
         return false;
426 426
     }
427 427
 
428
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
428
+    if (!("wpi_invoice" === $invoice->post_type)) {
429 429
         return false;
430 430
     }
431 431
     
432
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
433
-    if ( !is_email( $recipient ) ) {
432
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
433
+    if (!is_email($recipient)) {
434 434
         return false;
435 435
     }
436 436
         
@@ -447,50 +447,50 @@  discard block
 block discarded – undo
447 447
     $wpinv_email_search     = $search;
448 448
     $wpinv_email_replace    = $replace;
449 449
     
450
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
451
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
452
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
453
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
450
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
451
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
452
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
453
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
454 454
     
455
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
455
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
456 456
             'invoice'           => $invoice,
457 457
             'email_type'        => $email_type,
458 458
             'email_heading'     => $email_heading,
459 459
             'sent_to_admin'     => false,
460 460
             'plain_text'        => false,
461 461
             'partial_refund'    => false
462
-        ) );
462
+        ));
463 463
     
464
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
464
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
465 465
     
466
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
467
-        $recipient  = wpinv_get_admin_email();
468
-        $subject    .= ' - ADMIN BCC COPY';
469
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
466
+    if (wpinv_mail_admin_bcc_active($email_type)) {
467
+        $recipient = wpinv_get_admin_email();
468
+        $subject .= ' - ADMIN BCC COPY';
469
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
470 470
     }
471 471
     
472 472
     return $sent;
473 473
 }
474 474
 
475
-function wpinv_partially_refunded_notification( $invoice_id, $new_status = '' ) {
475
+function wpinv_partially_refunded_notification($invoice_id, $new_status = '') {
476 476
     global $wpinv_email_search, $wpinv_email_replace;
477 477
     
478 478
     $email_type = 'refunded_invoice';
479
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
479
+    if (!wpinv_email_is_enabled($email_type)) {
480 480
         return false;
481 481
     }
482 482
     
483
-    $invoice = wpinv_get_invoice( $invoice_id );
484
-    if ( empty( $invoice ) ) {
483
+    $invoice = wpinv_get_invoice($invoice_id);
484
+    if (empty($invoice)) {
485 485
         return false;
486 486
     }
487 487
 
488
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
488
+    if (!("wpi_invoice" === $invoice->post_type)) {
489 489
         return false;
490 490
     }
491 491
     
492
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
493
-    if ( !is_email( $recipient ) ) {
492
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
493
+    if (!is_email($recipient)) {
494 494
         return false;
495 495
     }
496 496
         
@@ -507,53 +507,53 @@  discard block
 block discarded – undo
507 507
     $wpinv_email_search     = $search;
508 508
     $wpinv_email_replace    = $replace;
509 509
     
510
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
511
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
512
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
513
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
510
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
511
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
512
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
513
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
514 514
     
515
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
515
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
516 516
             'invoice'           => $invoice,
517 517
             'email_type'        => $email_type,
518 518
             'email_heading'     => $email_heading,
519 519
             'sent_to_admin'     => false,
520 520
             'plain_text'        => false,
521 521
             'partial_refund'    => true
522
-        ) );
522
+        ));
523 523
     
524
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
524
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
525 525
     
526
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
527
-        $recipient  = wpinv_get_admin_email();
528
-        $subject    .= ' - ADMIN BCC COPY';
529
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
526
+    if (wpinv_mail_admin_bcc_active($email_type)) {
527
+        $recipient = wpinv_get_admin_email();
528
+        $subject .= ' - ADMIN BCC COPY';
529
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
530 530
     }
531 531
     
532 532
     return $sent;
533 533
 }
534 534
 
535
-function wpinv_new_invoice_note_notification( $invoice_id, $new_status = '' ) {
535
+function wpinv_new_invoice_note_notification($invoice_id, $new_status = '') {
536 536
 }
537 537
 
538
-function wpinv_user_invoice_notification( $invoice_id ) {
538
+function wpinv_user_invoice_notification($invoice_id) {
539 539
     global $wpinv_email_search, $wpinv_email_replace;
540 540
     
541 541
     $email_type = 'user_invoice';
542
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
542
+    if (!wpinv_email_is_enabled($email_type)) {
543 543
         return false;
544 544
     }
545 545
     
546
-    $invoice = wpinv_get_invoice( $invoice_id );
547
-    if ( empty( $invoice ) ) {
546
+    $invoice = wpinv_get_invoice($invoice_id);
547
+    if (empty($invoice)) {
548 548
         return false;
549 549
     }
550 550
 
551
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
551
+    if (!("wpi_invoice" === $invoice->post_type)) {
552 552
         return false;
553 553
     }
554 554
     
555
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
556
-    if ( !is_email( $recipient ) ) {
555
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
556
+    if (!is_email($recipient)) {
557 557
         return false;
558 558
     }
559 559
         
@@ -570,52 +570,52 @@  discard block
 block discarded – undo
570 570
     $wpinv_email_search     = $search;
571 571
     $wpinv_email_replace    = $replace;
572 572
     
573
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
574
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
575
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
576
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
573
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
574
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
575
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
576
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
577 577
     
578
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
578
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
579 579
             'invoice'       => $invoice,
580 580
             'email_type'    => $email_type,
581 581
             'email_heading' => $email_heading,
582 582
             'sent_to_admin' => false,
583 583
             'plain_text'    => false,
584
-        ) );
584
+        ));
585 585
     
586
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
586
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
587 587
     
588
-    if ( $sent ) {
589
-        $note = __( 'Invoice has been emailed to the user.', 'invoicing' );
588
+    if ($sent) {
589
+        $note = __('Invoice has been emailed to the user.', 'invoicing');
590 590
     } else {
591
-        $note = __( 'Fail to send invoice to the user!', 'invoicing' );
591
+        $note = __('Fail to send invoice to the user!', 'invoicing');
592 592
     }
593
-    $invoice->add_note( $note, '', '', true ); // Add private note.
593
+    $invoice->add_note($note, '', '', true); // Add private note.
594 594
     
595
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
596
-        $recipient  = wpinv_get_admin_email();
597
-        $subject    .= ' - ADMIN BCC COPY';
598
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
595
+    if (wpinv_mail_admin_bcc_active($email_type)) {
596
+        $recipient = wpinv_get_admin_email();
597
+        $subject .= ' - ADMIN BCC COPY';
598
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
599 599
     }
600 600
     
601 601
     return $sent;
602 602
 }
603 603
 
604
-function wpinv_user_note_notification( $invoice_id, $args = array() ) {
604
+function wpinv_user_note_notification($invoice_id, $args = array()) {
605 605
     global $wpinv_email_search, $wpinv_email_replace;
606 606
     
607 607
     $email_type = 'user_note';
608
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
608
+    if (!wpinv_email_is_enabled($email_type)) {
609 609
         return false;
610 610
     }
611 611
     
612
-    $invoice = wpinv_get_invoice( $invoice_id );
613
-    if ( empty( $invoice ) ) {
612
+    $invoice = wpinv_get_invoice($invoice_id);
613
+    if (empty($invoice)) {
614 614
         return false;
615 615
     }
616 616
     
617
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
618
-    if ( !is_email( $recipient ) ) {
617
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
618
+    if (!is_email($recipient)) {
619 619
         return false;
620 620
     }
621 621
     
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
         'user_note' => ''
624 624
     );
625 625
 
626
-    $args = wp_parse_args( $args, $defaults );
626
+    $args = wp_parse_args($args, $defaults);
627 627
         
628 628
     $search                     = array();
629 629
     $search['invoice_number']   = '{invoice_number}';
@@ -642,46 +642,46 @@  discard block
 block discarded – undo
642 642
     $wpinv_email_search     = $search;
643 643
     $wpinv_email_replace    = $replace;
644 644
     
645
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
646
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
647
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
648
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
645
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
646
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
647
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
648
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
649 649
     
650
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
650
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
651 651
             'invoice'       => $invoice,
652 652
             'email_type'    => $email_type,
653 653
             'email_heading' => $email_heading,
654 654
             'sent_to_admin' => false,
655 655
             'plain_text'    => false,
656 656
             'customer_note' => $args['user_note']
657
-        ) );
657
+        ));
658 658
         
659
-    $content        = wpinv_email_format_text( $content );
659
+    $content = wpinv_email_format_text($content);
660 660
     
661
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
661
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
662 662
         
663 663
     return $sent;
664 664
 }
665 665
 
666 666
 function wpinv_mail_get_from_address() {
667
-    $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from' ) );
668
-    return sanitize_email( $from_address );
667
+    $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from'));
668
+    return sanitize_email($from_address);
669 669
 }
670 670
 
671 671
 function wpinv_mail_get_from_name() {
672
-    $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name' ) );
673
-    return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES );
672
+    $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name'));
673
+    return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES);
674 674
 }
675 675
 
676
-function wpinv_mail_admin_bcc_active( $mail_type = '' ) {
677
-    $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) );
678
-    return ( $active ? true : false );
676
+function wpinv_mail_admin_bcc_active($mail_type = '') {
677
+    $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc'));
678
+    return ($active ? true : false);
679 679
 }
680 680
     
681
-function wpinv_mail_get_content_type(  $content_type = 'text/html', $email_type = 'html' ) {
682
-    $email_type = apply_filters( 'wpinv_mail_content_type', $email_type );
681
+function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') {
682
+    $email_type = apply_filters('wpinv_mail_content_type', $email_type);
683 683
     
684
-    switch ( $email_type ) {
684
+    switch ($email_type) {
685 685
         case 'html' :
686 686
             $content_type = 'text/html';
687 687
             break;
@@ -696,35 +696,35 @@  discard block
 block discarded – undo
696 696
     return $content_type;
697 697
 }
698 698
     
699
-function wpinv_mail_send( $to, $subject, $message, $headers, $attachments ) {
700
-    add_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
701
-    add_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
702
-    add_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
699
+function wpinv_mail_send($to, $subject, $message, $headers, $attachments) {
700
+    add_filter('wp_mail_from', 'wpinv_mail_get_from_address');
701
+    add_filter('wp_mail_from_name', 'wpinv_mail_get_from_name');
702
+    add_filter('wp_mail_content_type', 'wpinv_mail_get_content_type');
703 703
 
704
-    $message = wpinv_email_style_body( $message );
705
-    $message = apply_filters( 'wpinv_mail_content', $message );
704
+    $message = wpinv_email_style_body($message);
705
+    $message = apply_filters('wpinv_mail_content', $message);
706 706
     
707
-    $sent  = wp_mail( $to, $subject, $message, $headers, $attachments );
707
+    $sent = wp_mail($to, $subject, $message, $headers, $attachments);
708 708
     
709
-    if ( !$sent ) {
710
-        $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 );
711
-        wpinv_error_log( $log_message, __( "Email from Invoicing plugin failed to send", 'invoicing' ), __FILE__, __LINE__ );
709
+    if (!$sent) {
710
+        $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);
711
+        wpinv_error_log($log_message, __("Email from Invoicing plugin failed to send", 'invoicing'), __FILE__, __LINE__);
712 712
     }
713 713
 
714
-    remove_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
715
-    remove_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
716
-    remove_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
714
+    remove_filter('wp_mail_from', 'wpinv_mail_get_from_address');
715
+    remove_filter('wp_mail_from_name', 'wpinv_mail_get_from_name');
716
+    remove_filter('wp_mail_content_type', 'wpinv_mail_get_content_type');
717 717
 
718 718
     return $sent;
719 719
 }
720 720
     
721 721
 function wpinv_get_emails() {
722 722
     $overdue_days_options       = array();
723
-    $overdue_days_options[0]    = __( 'On the Due Date', 'invoicing' );
724
-    $overdue_days_options[1]    = __( '1 day after Due Date', 'invoicing' );
723
+    $overdue_days_options[0]    = __('On the Due Date', 'invoicing');
724
+    $overdue_days_options[1]    = __('1 day after Due Date', 'invoicing');
725 725
     
726
-    for ( $i = 2; $i <= 10; $i++ ) {
727
-        $overdue_days_options[$i]   = wp_sprintf( __( '%d days after Due Date', 'invoicing' ), $i );
726
+    for ($i = 2; $i <= 10; $i++) {
727
+        $overdue_days_options[$i] = wp_sprintf(__('%d days after Due Date', 'invoicing'), $i);
728 728
     }
729 729
 
730 730
 	// Default, built-in gateways
@@ -732,130 +732,130 @@  discard block
 block discarded – undo
732 732
             'new_invoice' => array(
733 733
             'email_new_invoice_header' => array(
734 734
                 'id'   => 'email_new_invoice_header',
735
-                'name' => '<h3>' . __( 'New Invoice', 'invoicing' ) . '</h3>',
736
-                'desc' => __( 'New invoice emails are sent to admin when a new invoice is received.', 'invoicing' ),
735
+                'name' => '<h3>' . __('New Invoice', 'invoicing') . '</h3>',
736
+                'desc' => __('New invoice emails are sent to admin when a new invoice is received.', 'invoicing'),
737 737
                 'type' => 'header',
738 738
             ),
739 739
             'email_new_invoice_active' => array(
740 740
                 'id'   => 'email_new_invoice_active',
741
-                'name' => __( 'Enable/Disable', 'invoicing' ),
742
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
741
+                'name' => __('Enable/Disable', 'invoicing'),
742
+                'desc' => __('Enable this email notification', 'invoicing'),
743 743
                 'type' => 'checkbox',
744 744
                 'std'  => 1
745 745
             ),
746 746
             'email_new_invoice_subject' => array(
747 747
                 'id'   => 'email_new_invoice_subject',
748
-                'name' => __( 'Subject', 'invoicing' ),
749
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
748
+                'name' => __('Subject', 'invoicing'),
749
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
750 750
                 'type' => 'text',
751
-                'std'  => __( '[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing' ),
751
+                'std'  => __('[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing'),
752 752
                 'size' => 'large'
753 753
             ),
754 754
             'email_new_invoice_heading' => array(
755 755
                 'id'   => 'email_new_invoice_heading',
756
-                'name' => __( 'Email Heading', 'invoicing' ),
757
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
756
+                'name' => __('Email Heading', 'invoicing'),
757
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
758 758
                 'type' => 'text',
759
-                'std'  => __( 'New payment invoice', 'invoicing' ),
759
+                'std'  => __('New payment invoice', 'invoicing'),
760 760
                 'size' => 'large'
761 761
             ),
762 762
         ),
763 763
         'cancelled_invoice' => array(
764 764
             'email_cancelled_invoice_header' => array(
765 765
                 'id'   => 'email_cancelled_invoice_header',
766
-                'name' => '<h3>' . __( 'Cancelled Invoice', 'invoicing' ) . '</h3>',
767
-                'desc' => __( 'Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing' ),
766
+                'name' => '<h3>' . __('Cancelled Invoice', 'invoicing') . '</h3>',
767
+                'desc' => __('Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing'),
768 768
                 'type' => 'header',
769 769
             ),
770 770
             'email_cancelled_invoice_active' => array(
771 771
                 'id'   => 'email_cancelled_invoice_active',
772
-                'name' => __( 'Enable/Disable', 'invoicing' ),
773
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
772
+                'name' => __('Enable/Disable', 'invoicing'),
773
+                'desc' => __('Enable this email notification', 'invoicing'),
774 774
                 'type' => 'checkbox',
775 775
                 'std'  => 1
776 776
             ),
777 777
             'email_cancelled_invoice_subject' => array(
778 778
                 'id'   => 'email_cancelled_invoice_subject',
779
-                'name' => __( 'Subject', 'invoicing' ),
780
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
779
+                'name' => __('Subject', 'invoicing'),
780
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
781 781
                 'type' => 'text',
782
-                'std'  => __( '[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing' ),
782
+                'std'  => __('[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing'),
783 783
                 'size' => 'large'
784 784
             ),
785 785
             'email_cancelled_invoice_heading' => array(
786 786
                 'id'   => 'email_cancelled_invoice_heading',
787
-                'name' => __( 'Email Heading', 'invoicing' ),
788
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
787
+                'name' => __('Email Heading', 'invoicing'),
788
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
789 789
                 'type' => 'text',
790
-                'std'  => __( 'Cancelled invoice', 'invoicing' ),
790
+                'std'  => __('Cancelled invoice', 'invoicing'),
791 791
                 'size' => 'large'
792 792
             ),
793 793
         ),
794 794
         'failed_invoice' => array(
795 795
             'email_failed_invoice_header' => array(
796 796
                 'id'   => 'email_failed_invoice_header',
797
-                'name' => '<h3>' . __( 'Failed Invoice', 'invoicing' ) . '</h3>',
798
-                'desc' => __( 'Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing' ),
797
+                'name' => '<h3>' . __('Failed Invoice', 'invoicing') . '</h3>',
798
+                'desc' => __('Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing'),
799 799
                 'type' => 'header',
800 800
             ),
801 801
             'email_failed_invoice_active' => array(
802 802
                 'id'   => 'email_failed_invoice_active',
803
-                'name' => __( 'Enable/Disable', 'invoicing' ),
804
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
803
+                'name' => __('Enable/Disable', 'invoicing'),
804
+                'desc' => __('Enable this email notification', 'invoicing'),
805 805
                 'type' => 'checkbox',
806 806
                 'std'  => 1
807 807
             ),
808 808
             'email_failed_invoice_subject' => array(
809 809
                 'id'   => 'email_failed_invoice_subject',
810
-                'name' => __( 'Subject', 'invoicing' ),
811
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
810
+                'name' => __('Subject', 'invoicing'),
811
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
812 812
                 'type' => 'text',
813
-                'std'  => __( '[{site_title}] Failed invoice ({invoice_number})', 'invoicing' ),
813
+                'std'  => __('[{site_title}] Failed invoice ({invoice_number})', 'invoicing'),
814 814
                 'size' => 'large'
815 815
             ),
816 816
             'email_failed_invoice_heading' => array(
817 817
                 'id'   => 'email_failed_invoice_heading',
818
-                'name' => __( 'Email Heading', 'invoicing' ),
819
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
818
+                'name' => __('Email Heading', 'invoicing'),
819
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
820 820
                 'type' => 'text',
821
-                'std'  => __( 'Failed invoice', 'invoicing' ),
821
+                'std'  => __('Failed invoice', 'invoicing'),
822 822
                 'size' => 'large'
823 823
             )
824 824
         ),
825 825
         'onhold_invoice' => array(
826 826
             'email_onhold_invoice_header' => array(
827 827
                 'id'   => 'email_onhold_invoice_header',
828
-                'name' => '<h3>' . __( 'On Hold Invoice', 'invoicing' ) . '</h3>',
829
-                'desc' => __( 'This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing' ),
828
+                'name' => '<h3>' . __('On Hold Invoice', 'invoicing') . '</h3>',
829
+                'desc' => __('This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing'),
830 830
                 'type' => 'header',
831 831
             ),
832 832
             'email_onhold_invoice_active' => array(
833 833
                 'id'   => 'email_onhold_invoice_active',
834
-                'name' => __( 'Enable/Disable', 'invoicing' ),
835
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
834
+                'name' => __('Enable/Disable', 'invoicing'),
835
+                'desc' => __('Enable this email notification', 'invoicing'),
836 836
                 'type' => 'checkbox',
837 837
                 'std'  => 1
838 838
             ),
839 839
             'email_onhold_invoice_subject' => array(
840 840
                 'id'   => 'email_onhold_invoice_subject',
841
-                'name' => __( 'Subject', 'invoicing' ),
842
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
841
+                'name' => __('Subject', 'invoicing'),
842
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
843 843
                 'type' => 'text',
844
-                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
844
+                'std'  => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'),
845 845
                 'size' => 'large'
846 846
             ),
847 847
             'email_onhold_invoice_heading' => array(
848 848
                 'id'   => 'email_onhold_invoice_heading',
849
-                'name' => __( 'Email Heading', 'invoicing' ),
850
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
849
+                'name' => __('Email Heading', 'invoicing'),
850
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
851 851
                 'type' => 'text',
852
-                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
852
+                'std'  => __('Thank you for your invoice', 'invoicing'),
853 853
                 'size' => 'large'
854 854
             ),
855 855
             'email_onhold_invoice_admin_bcc' => array(
856 856
                 'id'   => 'email_onhold_invoice_admin_bcc',
857
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
858
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
857
+                'name' => __('Enable Admin BCC', 'invoicing'),
858
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
859 859
                 'type' => 'checkbox',
860 860
                 'std'  => 1
861 861
             ),
@@ -863,37 +863,37 @@  discard block
 block discarded – undo
863 863
         'processing_invoice' => array(
864 864
             'email_processing_invoice_header' => array(
865 865
                 'id'   => 'email_processing_invoice_header',
866
-                'name' => '<h3>' . __( 'Processing Invoice', 'invoicing' ) . '</h3>',
867
-                'desc' => __( 'This is an invoice notification sent to users containing invoice details after payment.', 'invoicing' ),
866
+                'name' => '<h3>' . __('Processing Invoice', 'invoicing') . '</h3>',
867
+                'desc' => __('This is an invoice notification sent to users containing invoice details after payment.', 'invoicing'),
868 868
                 'type' => 'header',
869 869
             ),
870 870
             'email_processing_invoice_active' => array(
871 871
                 'id'   => 'email_processing_invoice_active',
872
-                'name' => __( 'Enable/Disable', 'invoicing' ),
873
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
872
+                'name' => __('Enable/Disable', 'invoicing'),
873
+                'desc' => __('Enable this email notification', 'invoicing'),
874 874
                 'type' => 'checkbox',
875 875
                 'std'  => 1
876 876
             ),
877 877
             'email_processing_invoice_subject' => array(
878 878
                 'id'   => 'email_processing_invoice_subject',
879
-                'name' => __( 'Subject', 'invoicing' ),
880
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
879
+                'name' => __('Subject', 'invoicing'),
880
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
881 881
                 'type' => 'text',
882
-                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
882
+                'std'  => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'),
883 883
                 'size' => 'large'
884 884
             ),
885 885
             'email_processing_invoice_heading' => array(
886 886
                 'id'   => 'email_processing_invoice_heading',
887
-                'name' => __( 'Email Heading', 'invoicing' ),
888
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
887
+                'name' => __('Email Heading', 'invoicing'),
888
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
889 889
                 'type' => 'text',
890
-                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
890
+                'std'  => __('Thank you for your invoice', 'invoicing'),
891 891
                 'size' => 'large'
892 892
             ),
893 893
             'email_processing_invoice_admin_bcc' => array(
894 894
                 'id'   => 'email_processing_invoice_admin_bcc',
895
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
896
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
895
+                'name' => __('Enable Admin BCC', 'invoicing'),
896
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
897 897
                 'type' => 'checkbox',
898 898
                 'std'  => 1
899 899
             ),
@@ -901,37 +901,37 @@  discard block
 block discarded – undo
901 901
         'completed_invoice' => array(
902 902
             'email_completed_invoice_header' => array(
903 903
                 'id'   => 'email_completed_invoice_header',
904
-                'name' => '<h3>' . __( 'Paid Invoice', 'invoicing' ) . '</h3>',
905
-                'desc' => __( 'Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing' ),
904
+                'name' => '<h3>' . __('Paid Invoice', 'invoicing') . '</h3>',
905
+                'desc' => __('Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing'),
906 906
                 'type' => 'header',
907 907
             ),
908 908
             'email_completed_invoice_active' => array(
909 909
                 'id'   => 'email_completed_invoice_active',
910
-                'name' => __( 'Enable/Disable', 'invoicing' ),
911
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
910
+                'name' => __('Enable/Disable', 'invoicing'),
911
+                'desc' => __('Enable this email notification', 'invoicing'),
912 912
                 'type' => 'checkbox',
913 913
                 'std'  => 1
914 914
             ),
915 915
             'email_completed_invoice_subject' => array(
916 916
                 'id'   => 'email_completed_invoice_subject',
917
-                'name' => __( 'Subject', 'invoicing' ),
918
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
917
+                'name' => __('Subject', 'invoicing'),
918
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
919 919
                 'type' => 'text',
920
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing' ),
920
+                'std'  => __('[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing'),
921 921
                 'size' => 'large'
922 922
             ),
923 923
             'email_completed_invoice_heading' => array(
924 924
                 'id'   => 'email_completed_invoice_heading',
925
-                'name' => __( 'Email Heading', 'invoicing' ),
926
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
925
+                'name' => __('Email Heading', 'invoicing'),
926
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
927 927
                 'type' => 'text',
928
-                'std'  => __( 'Your invoice has been paid', 'invoicing' ),
928
+                'std'  => __('Your invoice has been paid', 'invoicing'),
929 929
                 'size' => 'large'
930 930
             ),
931 931
             'email_completed_invoice_admin_bcc' => array(
932 932
                 'id'   => 'email_completed_invoice_admin_bcc',
933
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
934
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
933
+                'name' => __('Enable Admin BCC', 'invoicing'),
934
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
935 935
                 'type' => 'checkbox',
936 936
             ),
937 937
             'std'  => 1
@@ -939,37 +939,37 @@  discard block
 block discarded – undo
939 939
         'refunded_invoice' => array(
940 940
             'email_refunded_invoice_header' => array(
941 941
                 'id'   => 'email_refunded_invoice_header',
942
-                'name' => '<h3>' . __( 'Refunded Invoice', 'invoicing' ) . '</h3>',
943
-                'desc' => __( 'Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing' ),
942
+                'name' => '<h3>' . __('Refunded Invoice', 'invoicing') . '</h3>',
943
+                'desc' => __('Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing'),
944 944
                 'type' => 'header',
945 945
             ),
946 946
             'email_refunded_invoice_active' => array(
947 947
                 'id'   => 'email_refunded_invoice_active',
948
-                'name' => __( 'Enable/Disable', 'invoicing' ),
949
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
948
+                'name' => __('Enable/Disable', 'invoicing'),
949
+                'desc' => __('Enable this email notification', 'invoicing'),
950 950
                 'type' => 'checkbox',
951 951
                 'std'  => 1
952 952
             ),
953 953
             'email_refunded_invoice_subject' => array(
954 954
                 'id'   => 'email_refunded_invoice_subject',
955
-                'name' => __( 'Subject', 'invoicing' ),
956
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
955
+                'name' => __('Subject', 'invoicing'),
956
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
957 957
                 'type' => 'text',
958
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing' ),
958
+                'std'  => __('[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing'),
959 959
                 'size' => 'large'
960 960
             ),
961 961
             'email_refunded_invoice_heading' => array(
962 962
                 'id'   => 'email_refunded_invoice_heading',
963
-                'name' => __( 'Email Heading', 'invoicing' ),
964
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
963
+                'name' => __('Email Heading', 'invoicing'),
964
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
965 965
                 'type' => 'text',
966
-                'std'  => __( 'Your invoice has been refunded', 'invoicing' ),
966
+                'std'  => __('Your invoice has been refunded', 'invoicing'),
967 967
                 'size' => 'large'
968 968
             ),
969 969
             'email_refunded_invoice_admin_bcc' => array(
970 970
                 'id'   => 'email_refunded_invoice_admin_bcc',
971
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
972
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
971
+                'name' => __('Enable Admin BCC', 'invoicing'),
972
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
973 973
                 'type' => 'checkbox',
974 974
                 'std'  => 1
975 975
             ),
@@ -977,37 +977,37 @@  discard block
 block discarded – undo
977 977
         'user_invoice' => array(
978 978
             'email_user_invoice_header' => array(
979 979
                 'id'   => 'email_user_invoice_header',
980
-                'name' => '<h3>' . __( 'Customer Invoice', 'invoicing' ) . '</h3>',
981
-                'desc' => __( 'Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing' ),
980
+                'name' => '<h3>' . __('Customer Invoice', 'invoicing') . '</h3>',
981
+                'desc' => __('Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing'),
982 982
                 'type' => 'header',
983 983
             ),
984 984
             'email_user_invoice_active' => array(
985 985
                 'id'   => 'email_user_invoice_active',
986
-                'name' => __( 'Enable/Disable', 'invoicing' ),
987
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
986
+                'name' => __('Enable/Disable', 'invoicing'),
987
+                'desc' => __('Enable this email notification', 'invoicing'),
988 988
                 'type' => 'checkbox',
989 989
                 'std'  => 1
990 990
             ),
991 991
             'email_user_invoice_subject' => array(
992 992
                 'id'   => 'email_user_invoice_subject',
993
-                'name' => __( 'Subject', 'invoicing' ),
994
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
993
+                'name' => __('Subject', 'invoicing'),
994
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
995 995
                 'type' => 'text',
996
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date}', 'invoicing' ),
996
+                'std'  => __('[{site_title}] Your invoice from {invoice_date}', 'invoicing'),
997 997
                 'size' => 'large'
998 998
             ),
999 999
             'email_user_invoice_heading' => array(
1000 1000
                 'id'   => 'email_user_invoice_heading',
1001
-                'name' => __( 'Email Heading', 'invoicing' ),
1002
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
1001
+                'name' => __('Email Heading', 'invoicing'),
1002
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
1003 1003
                 'type' => 'text',
1004
-                'std'  => __( 'Your invoice {invoice_number} details', 'invoicing' ),
1004
+                'std'  => __('Your invoice {invoice_number} details', 'invoicing'),
1005 1005
                 'size' => 'large'
1006 1006
             ),
1007 1007
             'email_user_invoice_admin_bcc' => array(
1008 1008
                 'id'   => 'email_user_invoice_admin_bcc',
1009
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
1010
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
1009
+                'name' => __('Enable Admin BCC', 'invoicing'),
1010
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
1011 1011
                 'type' => 'checkbox',
1012 1012
                 'std'  => 1
1013 1013
             ),
@@ -1015,177 +1015,177 @@  discard block
 block discarded – undo
1015 1015
         'user_note' => array(
1016 1016
             'email_user_note_header' => array(
1017 1017
                 'id'   => 'email_user_note_header',
1018
-                'name' => '<h3>' . __( 'Customer Note', 'invoicing' ) . '</h3>',
1019
-                'desc' => __( 'Customer note emails are sent when you add a note to an invoice.', 'invoicing' ),
1018
+                'name' => '<h3>' . __('Customer Note', 'invoicing') . '</h3>',
1019
+                'desc' => __('Customer note emails are sent when you add a note to an invoice.', 'invoicing'),
1020 1020
                 'type' => 'header',
1021 1021
             ),
1022 1022
             'email_user_note_active' => array(
1023 1023
                 'id'   => 'email_user_note_active',
1024
-                'name' => __( 'Enable/Disable', 'invoicing' ),
1025
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
1024
+                'name' => __('Enable/Disable', 'invoicing'),
1025
+                'desc' => __('Enable this email notification', 'invoicing'),
1026 1026
                 'type' => 'checkbox',
1027 1027
                 'std'  => 1
1028 1028
             ),
1029 1029
             'email_user_note_subject' => array(
1030 1030
                 'id'   => 'email_user_note_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}] Note added to your invoice #{invoice_number} from {invoice_date}', 'invoicing' ),
1034
+                'std'  => __('[{site_title}] Note added to your invoice #{invoice_number} from {invoice_date}', 'invoicing'),
1035 1035
                 'size' => 'large'
1036 1036
             ),
1037 1037
             'email_user_note_heading' => array(
1038 1038
                 'id'   => 'email_user_note_heading',
1039
-                'name' => __( 'Email Heading', 'invoicing' ),
1040
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
1039
+                'name' => __('Email Heading', 'invoicing'),
1040
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
1041 1041
                 'type' => 'text',
1042
-                'std'  => __( 'A note has been added to your invoice', 'invoicing' ),
1042
+                'std'  => __('A note has been added to your invoice', 'invoicing'),
1043 1043
                 'size' => 'large'
1044 1044
             ),
1045 1045
         ),
1046 1046
         'overdue' => array(
1047 1047
             'email_overdue_header' => array(
1048 1048
                 'id'   => 'email_overdue_header',
1049
-                'name' => '<h3>' . __( 'Payment Reminder', 'invoicing' ) . '</h3>',
1050
-                'desc' => __( 'Payment reminder emails are sent to user automatically.', 'invoicing' ),
1049
+                'name' => '<h3>' . __('Payment Reminder', 'invoicing') . '</h3>',
1050
+                'desc' => __('Payment reminder emails are sent to user automatically.', 'invoicing'),
1051 1051
                 'type' => 'header',
1052 1052
             ),
1053 1053
             'email_overdue_active' => array(
1054 1054
                 'id'   => 'email_overdue_active',
1055
-                'name' => __( 'Enable/Disable', 'invoicing' ),
1056
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
1055
+                'name' => __('Enable/Disable', 'invoicing'),
1056
+                'desc' => __('Enable this email notification', 'invoicing'),
1057 1057
                 'type' => 'checkbox',
1058 1058
                 'std'  => 1
1059 1059
             ),
1060 1060
             'email_due_reminder_days' => array(
1061 1061
                 'id'        => 'email_due_reminder_days',
1062
-                'name'      => __( 'When to Send', 'sliced-invoices' ),
1063
-                'desc'      => __( 'Check when you would like payment reminders sent out.', 'invoicing' ),
1062
+                'name'      => __('When to Send', 'sliced-invoices'),
1063
+                'desc'      => __('Check when you would like payment reminders sent out.', 'invoicing'),
1064 1064
                 'default'   => '',
1065 1065
                 'type'      => 'multicheck',
1066 1066
                 'options'   => $overdue_days_options,
1067 1067
             ),
1068 1068
             'email_overdue_subject' => array(
1069 1069
                 'id'   => 'email_overdue_subject',
1070
-                'name' => __( 'Subject', 'invoicing' ),
1071
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
1070
+                'name' => __('Subject', 'invoicing'),
1071
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
1072 1072
                 'type' => 'text',
1073
-                'std'  => __( '[{site_title}] Payment Reminder', 'invoicing' ),
1073
+                'std'  => __('[{site_title}] Payment Reminder', 'invoicing'),
1074 1074
                 'size' => 'large'
1075 1075
             ),
1076 1076
             'email_overdue_heading' => array(
1077 1077
                 'id'   => 'email_overdue_heading',
1078
-                'name' => __( 'Email Heading', 'invoicing' ),
1079
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
1078
+                'name' => __('Email Heading', 'invoicing'),
1079
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
1080 1080
                 'type' => 'text',
1081
-                'std'  => __( 'Payment reminder for your invoice', 'invoicing' ),
1081
+                'std'  => __('Payment reminder for your invoice', 'invoicing'),
1082 1082
                 'size' => 'large'
1083 1083
             ),
1084 1084
             'email_overdue_body' => array(
1085 1085
                 'id'   => 'email_overdue_body',
1086
-                'name' => __( 'Email Content', 'invoicing' ),
1087
-                'desc' => __( 'The content of the email.', 'invoicing' ),
1086
+                'name' => __('Email Content', 'invoicing'),
1087
+                'desc' => __('The content of the email.', 'invoicing'),
1088 1088
                 'type' => 'rich_editor',
1089
-                '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' ),
1089
+                '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'),
1090 1090
                 'class' => 'large',
1091 1091
                 'size'  => 10,
1092 1092
             ),
1093 1093
         ),
1094 1094
     );
1095 1095
 
1096
-    return apply_filters( 'wpinv_get_emails', $emails );
1096
+    return apply_filters('wpinv_get_emails', $emails);
1097 1097
 }
1098 1098
 
1099
-function wpinv_settings_emails( $settings = array() ) {
1099
+function wpinv_settings_emails($settings = array()) {
1100 1100
     $emails = wpinv_get_emails();
1101 1101
     
1102
-    if ( !empty( $emails ) ) {
1103
-        foreach ( $emails as $key => $email ) {
1102
+    if (!empty($emails)) {
1103
+        foreach ($emails as $key => $email) {
1104 1104
             $settings[$key] = $email;
1105 1105
         }
1106 1106
     }
1107 1107
     
1108
-    return apply_filters( 'wpinv_settings_get_emails', $settings );
1108
+    return apply_filters('wpinv_settings_get_emails', $settings);
1109 1109
 }
1110
-add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 );
1110
+add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1);
1111 1111
 
1112
-function wpinv_settings_sections_emails( $settings ) {
1112
+function wpinv_settings_sections_emails($settings) {
1113 1113
     $emails = wpinv_get_emails();
1114 1114
     
1115 1115
     if (!empty($emails)) {
1116
-        foreach  ($emails as $key => $email) {
1117
-            $settings[$key] = !empty( $email['email_' . $key . '_header']['name'] ) ? strip_tags( $email['email_' . $key . '_header']['name'] ) : $key;
1116
+        foreach ($emails as $key => $email) {
1117
+            $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : $key;
1118 1118
         }
1119 1119
     }
1120 1120
     
1121 1121
     return $settings;    
1122 1122
 }
1123
-add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 );
1123
+add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1);
1124 1124
 
1125
-function wpinv_email_is_enabled( $email_type ) {
1125
+function wpinv_email_is_enabled($email_type) {
1126 1126
     $emails = wpinv_get_emails();
1127
-    $enabled = isset( $emails[$email_type] ) && wpinv_get_option( $email_type . '_active', 1 ) ? true : false;
1127
+    $enabled = isset($emails[$email_type]) && wpinv_get_option($email_type . '_active', 1) ? true : false;
1128 1128
 
1129
-    return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type );
1129
+    return apply_filters('wpinv_email_is_enabled', $enabled, $email_type);
1130 1130
 }
1131 1131
 
1132
-function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1133
-    switch ( $email_type ) {
1132
+function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) {
1133
+    switch ($email_type) {
1134 1134
         case 'new_invoice':
1135 1135
         case 'cancelled_invoice':
1136 1136
         case 'failed_invoice':
1137 1137
             $recipient  = wpinv_get_admin_email();
1138 1138
         break;
1139 1139
         default:
1140
-            $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1141
-            $recipient  = !empty( $invoice ) ? $invoice->get_email() : '';
1140
+            $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
1141
+            $recipient  = !empty($invoice) ? $invoice->get_email() : '';
1142 1142
         break;
1143 1143
     }
1144 1144
     
1145
-    return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice );
1145
+    return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice);
1146 1146
 }
1147 1147
 
1148
-function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1149
-    $subject    = wpinv_get_option( 'email_' . $email_type . '_subject' );
1148
+function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) {
1149
+    $subject    = wpinv_get_option('email_' . $email_type . '_subject');
1150 1150
     
1151
-    $subject    = wpinv_email_format_text( $subject );
1151
+    $subject    = wpinv_email_format_text($subject);
1152 1152
     
1153
-    return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice );
1153
+    return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice);
1154 1154
 }
1155 1155
 
1156
-function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1157
-    $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' );
1156
+function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) {
1157
+    $email_heading = wpinv_get_option('email_' . $email_type . '_heading');
1158 1158
     
1159
-    $email_heading = wpinv_email_format_text( $email_heading );
1159
+    $email_heading = wpinv_email_format_text($email_heading);
1160 1160
     
1161
-    return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice );
1161
+    return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice);
1162 1162
 }
1163 1163
 
1164
-function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1165
-    $content    = wpinv_get_option( 'email_' . $email_type . '_body' );
1164
+function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) {
1165
+    $content    = wpinv_get_option('email_' . $email_type . '_body');
1166 1166
     
1167
-    $content    = wpinv_email_format_text( $content );
1167
+    $content    = wpinv_email_format_text($content);
1168 1168
     
1169
-    return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice );
1169
+    return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice);
1170 1170
 }
1171 1171
 
1172
-function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1172
+function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) {
1173 1173
     $from_name = wpinv_mail_get_from_address();
1174 1174
     $from_email = wpinv_mail_get_from_address();
1175 1175
     
1176
-    $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1176
+    $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
1177 1177
     
1178
-    $headers    = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n";
1179
-    $headers    .= "Reply-To: ". $from_email . "\r\n";
1178
+    $headers    = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n";
1179
+    $headers    .= "Reply-To: " . $from_email . "\r\n";
1180 1180
     $headers    .= "Content-Type: " . wpinv_mail_get_content_type() . "\r\n";
1181 1181
     
1182
-    return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice );
1182
+    return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice);
1183 1183
 }
1184 1184
 
1185
-function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1185
+function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) {
1186 1186
     $attachments = array();
1187 1187
     
1188
-    return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice );
1188
+    return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice);
1189 1189
 }
1190 1190
 
1191 1191
 function wpinv_email_global_vars() {
@@ -1202,73 +1202,73 @@  discard block
 block discarded – undo
1202 1202
     $replace['sitename']    = $blogname;
1203 1203
     $replace['site-title']  = $blogname;
1204 1204
     
1205
-    return apply_filters( 'wpinv_email_global_vars', array( $search, $replace ) );
1205
+    return apply_filters('wpinv_email_global_vars', array($search, $replace));
1206 1206
 }
1207 1207
 
1208
-function wpinv_email_format_text( $content ) {
1208
+function wpinv_email_format_text($content) {
1209 1209
     global $wpinv_email_search, $wpinv_email_replace;
1210 1210
     
1211
-    if ( empty( $wpinv_email_search ) ) {
1211
+    if (empty($wpinv_email_search)) {
1212 1212
         $wpinv_email_search = array();
1213 1213
     }
1214 1214
     
1215
-    if ( empty( $wpinv_email_replace ) ) {
1215
+    if (empty($wpinv_email_replace)) {
1216 1216
         $wpinv_email_replace = array();
1217 1217
     }
1218 1218
     
1219
-    $wpinv_email_search     = (array)apply_filters( 'wpinv_email_format_text_search', $wpinv_email_search );
1220
-    $wpinv_email_replace    = (array)apply_filters( 'wpinv_email_format_text_replace', $wpinv_email_replace );
1219
+    $wpinv_email_search     = (array)apply_filters('wpinv_email_format_text_search', $wpinv_email_search);
1220
+    $wpinv_email_replace    = (array)apply_filters('wpinv_email_format_text_replace', $wpinv_email_replace);
1221 1221
     
1222 1222
     $global_vars    = wpinv_email_global_vars();
1223 1223
     
1224
-    $search         = array_merge( $global_vars[0], $wpinv_email_search );
1225
-    $replace        = array_merge( $global_vars[1], $wpinv_email_replace );
1224
+    $search         = array_merge($global_vars[0], $wpinv_email_search);
1225
+    $replace        = array_merge($global_vars[1], $wpinv_email_replace);
1226 1226
     
1227
-    if ( empty( $search ) || empty( $replace ) || !is_array( $search ) || !is_array( $replace ) ) {
1227
+    if (empty($search) || empty($replace) || !is_array($search) || !is_array($replace)) {
1228 1228
         return  $content;
1229 1229
     }
1230 1230
         
1231
-    return str_replace( $search, $replace, $content );
1231
+    return str_replace($search, $replace, $content);
1232 1232
 }
1233 1233
 
1234
-function wpinv_email_style_body( $content ) {
1234
+function wpinv_email_style_body($content) {
1235 1235
     // make sure we only inline CSS for html emails
1236
-    if ( in_array( wpinv_mail_get_content_type(), array( 'text/html', 'multipart/alternative' ) ) && class_exists( 'DOMDocument' ) ) {
1236
+    if (in_array(wpinv_mail_get_content_type(), array('text/html', 'multipart/alternative')) && class_exists('DOMDocument')) {
1237 1237
         ob_start();
1238
-        wpinv_get_template( 'emails/wpinv-email-styles.php' );
1239
-        $css = apply_filters( 'wpinv_email_styles', ob_get_clean() );
1238
+        wpinv_get_template('emails/wpinv-email-styles.php');
1239
+        $css = apply_filters('wpinv_email_styles', ob_get_clean());
1240 1240
         
1241 1241
         // apply CSS styles inline for picky email clients
1242 1242
         try {
1243
-            $emogrifier = new Emogrifier( $content, $css );
1243
+            $emogrifier = new Emogrifier($content, $css);
1244 1244
             $content    = $emogrifier->emogrify();
1245
-        } catch ( Exception $e ) {
1246
-            wpinv_error_log( $e->getMessage(), 'emogrifier' );
1245
+        } catch (Exception $e) {
1246
+            wpinv_error_log($e->getMessage(), 'emogrifier');
1247 1247
         }
1248 1248
     }
1249 1249
     return $content;
1250 1250
 }
1251 1251
 
1252
-function wpinv_email_header( $email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1253
-    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 ) );
1252
+function wpinv_email_header($email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false) {
1253
+    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));
1254 1254
 }
1255 1255
 
1256 1256
 /**
1257 1257
  * Get the email footer.
1258 1258
  */
1259
-function wpinv_email_footer( $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1260
-    wpinv_get_template( 'emails/wpinv-email-footer.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1259
+function wpinv_email_footer($invoice = array(), $email_type = '', $sent_to_admin = false) {
1260
+    wpinv_get_template('emails/wpinv-email-footer.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1261 1261
 }
1262 1262
 
1263
-function wpinv_email_wrap_message( $message ) {
1263
+function wpinv_email_wrap_message($message) {
1264 1264
     // Buffer
1265 1265
     ob_start();
1266 1266
 
1267
-    do_action( 'wpinv_email_header' );
1267
+    do_action('wpinv_email_header');
1268 1268
 
1269
-    echo wpautop( wptexturize( $message ) );
1269
+    echo wpautop(wptexturize($message));
1270 1270
 
1271
-    do_action( 'wpinv_email_footer' );
1271
+    do_action('wpinv_email_footer');
1272 1272
 
1273 1273
     // Get contents
1274 1274
     $message = ob_get_clean();
@@ -1276,86 +1276,86 @@  discard block
 block discarded – undo
1276 1276
     return $message;
1277 1277
 }
1278 1278
 
1279
-function wpinv_email_invoice_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1280
-    wpinv_get_template( 'emails/wpinv-email-invoice-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1279
+function wpinv_email_invoice_details($invoice, $email_type = '', $sent_to_admin = false) {
1280
+    wpinv_get_template('emails/wpinv-email-invoice-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1281 1281
 }
1282 1282
 
1283
-function wpinv_email_invoice_items( $invoice, $email_type = '', $sent_to_admin = false ) {
1284
-    wpinv_get_template( 'emails/wpinv-email-invoice-items.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1283
+function wpinv_email_invoice_items($invoice, $email_type = '', $sent_to_admin = false) {
1284
+    wpinv_get_template('emails/wpinv-email-invoice-items.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1285 1285
 }
1286 1286
 
1287
-function wpinv_email_billing_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1288
-    wpinv_get_template( 'emails/wpinv-email-billing-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1287
+function wpinv_email_billing_details($invoice, $email_type = '', $sent_to_admin = false) {
1288
+    wpinv_get_template('emails/wpinv-email-billing-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1289 1289
 }
1290 1290
 
1291
-function wpinv_send_customer_invoice( $data = array() ) {
1292
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1291
+function wpinv_send_customer_invoice($data = array()) {
1292
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1293 1293
     
1294
-    if ( empty( $invoice_id ) ) {
1294
+    if (empty($invoice_id)) {
1295 1295
         return;
1296 1296
     }
1297 1297
 
1298
-    if ( !current_user_can( 'manage_options' ) ) {
1299
-        wp_die( __( 'You do not have permission to send invoice notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1298
+    if (!current_user_can('manage_options')) {
1299
+        wp_die(__('You do not have permission to send invoice notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
1300 1300
     }
1301 1301
     
1302
-    $sent = wpinv_user_invoice_notification( $invoice_id );
1302
+    $sent = wpinv_user_invoice_notification($invoice_id);
1303 1303
     
1304 1304
     $status = $sent ? 'email_sent' : 'email_fail';
1305 1305
     
1306
-    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1307
-    wp_redirect( $redirect );
1306
+    $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false));
1307
+    wp_redirect($redirect);
1308 1308
     exit;
1309 1309
 }
1310
-add_action( 'wpinv_send_invoice', 'wpinv_send_customer_invoice' );
1310
+add_action('wpinv_send_invoice', 'wpinv_send_customer_invoice');
1311 1311
 
1312
-function wpinv_send_overdue_reminder( $data = array() ) {
1313
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1312
+function wpinv_send_overdue_reminder($data = array()) {
1313
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1314 1314
     
1315
-    if ( empty( $invoice_id ) ) {
1315
+    if (empty($invoice_id)) {
1316 1316
         return;
1317 1317
     }
1318 1318
 
1319
-    if ( !current_user_can( 'manage_options' ) ) {
1320
-        wp_die( __( 'You do not have permission to send reminder notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1319
+    if (!current_user_can('manage_options')) {
1320
+        wp_die(__('You do not have permission to send reminder notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
1321 1321
     }
1322 1322
     
1323
-    $sent = wpinv_send_payment_reminder_notification( $invoice_id );
1323
+    $sent = wpinv_send_payment_reminder_notification($invoice_id);
1324 1324
     
1325 1325
     $status = $sent ? 'email_sent' : 'email_fail';
1326 1326
     
1327
-    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1328
-    wp_redirect( $redirect );
1327
+    $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false));
1328
+    wp_redirect($redirect);
1329 1329
     exit;
1330 1330
 }
1331
-add_action( 'wpinv_send_reminder', 'wpinv_send_overdue_reminder' );
1331
+add_action('wpinv_send_reminder', 'wpinv_send_overdue_reminder');
1332 1332
 
1333
-function wpinv_send_customer_note_email( $data ) {
1334
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1333
+function wpinv_send_customer_note_email($data) {
1334
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1335 1335
     
1336
-    if ( empty( $invoice_id ) ) {
1336
+    if (empty($invoice_id)) {
1337 1337
         return;
1338 1338
     }
1339 1339
     
1340
-    $sent = wpinv_user_note_notification( $invoice_id, $data );
1340
+    $sent = wpinv_user_note_notification($invoice_id, $data);
1341 1341
 }
1342
-add_action( 'wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1 );
1342
+add_action('wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1);
1343 1343
 
1344
-function wpinv_add_notes_to_invoice_email( $invoice, $email_type, $sent_to_admin ) {
1345
-    if ( !empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->ID, true ) ) {
1346
-        $date_format = get_option( 'date_format' );
1347
-        $time_format = get_option( 'time_format' );
1344
+function wpinv_add_notes_to_invoice_email($invoice, $email_type, $sent_to_admin) {
1345
+    if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->ID, true)) {
1346
+        $date_format = get_option('date_format');
1347
+        $time_format = get_option('time_format');
1348 1348
         ?>
1349 1349
         <div id="wpinv-email-notes">
1350
-            <h3 class="wpinv-notes-t"><?php echo apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ); ?></h3>
1350
+            <h3 class="wpinv-notes-t"><?php echo apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing')); ?></h3>
1351 1351
             <ol class="wpinv-notes-lists">
1352 1352
         <?php
1353
-        foreach ( $invoice_notes as $note ) {
1354
-            $note_time = strtotime( $note->comment_date );
1353
+        foreach ($invoice_notes as $note) {
1354
+            $note_time = strtotime($note->comment_date);
1355 1355
             ?>
1356 1356
             <li class="comment wpinv-note">
1357
-            <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>
1358
-            <div class="wpinv-note-desc description"><?php echo wpautop( wptexturize( $note->comment_content ) ); ?></div>
1357
+            <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>
1358
+            <div class="wpinv-note-desc description"><?php echo wpautop(wptexturize($note->comment_content)); ?></div>
1359 1359
             </li>
1360 1360
             <?php
1361 1361
         }
@@ -1364,21 +1364,21 @@  discard block
 block discarded – undo
1364 1364
         <?php
1365 1365
     }
1366 1366
 }
1367
-add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 );
1367
+add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3);
1368 1368
 
1369 1369
 function wpinv_email_payment_reminders() {    
1370 1370
     global $wpi_auto_reminder;
1371
-    if ( !wpinv_get_option( 'email_overdue_active' ) ) {
1371
+    if (!wpinv_get_option('email_overdue_active')) {
1372 1372
         return;
1373 1373
     }
1374 1374
     
1375
-    if ( $reminder_days = wpinv_get_option( 'email_due_reminder_days' ) ) {
1376
-        $reminder_days  = is_array( $reminder_days ) ? array_values( $reminder_days ) : '';
1375
+    if ($reminder_days = wpinv_get_option('email_due_reminder_days')) {
1376
+        $reminder_days  = is_array($reminder_days) ? array_values($reminder_days) : '';
1377 1377
         
1378
-        if ( empty( $reminder_days ) ) {
1378
+        if (empty($reminder_days)) {
1379 1379
             return;
1380 1380
         }
1381
-        $reminder_days  = array_unique( array_map( 'absint', $reminder_days ) );
1381
+        $reminder_days = array_unique(array_map('absint', $reminder_days));
1382 1382
         
1383 1383
         $args = array(
1384 1384
             'post_type'     => 'wpi_invoice',
@@ -1388,7 +1388,7 @@  discard block
 block discarded – undo
1388 1388
             'meta_query'    => array(
1389 1389
                 array(
1390 1390
                     'key'       =>  '_wpinv_due_date',
1391
-                    'value'     =>  array( '', 'none' ),
1391
+                    'value'     =>  array('', 'none'),
1392 1392
                     'compare'   =>  'NOT IN',
1393 1393
                 )
1394 1394
             ),
@@ -1397,64 +1397,64 @@  discard block
 block discarded – undo
1397 1397
             'order'         => 'ASC',
1398 1398
         );
1399 1399
         
1400
-        $invoices = get_posts( $args );
1400
+        $invoices = get_posts($args);
1401 1401
         
1402
-        if ( empty( $invoices ) ) {
1402
+        if (empty($invoices)) {
1403 1403
             return;
1404 1404
         }
1405 1405
         
1406
-        $date_to_send   = array();
1406
+        $date_to_send = array();
1407 1407
         
1408
-        foreach ( $invoices as $id ) {
1409
-            $due_date = get_post_meta( $id, '_wpinv_due_date', true );
1408
+        foreach ($invoices as $id) {
1409
+            $due_date = get_post_meta($id, '_wpinv_due_date', true);
1410 1410
             
1411
-            foreach ( $reminder_days as $key => $days ) {
1412
-                if ( $days !== '' ) {
1413
-                    $date_to_send[$id][] = date_i18n( 'Y-m-d', strtotime( $due_date ) + ( $days * DAY_IN_SECONDS ) );
1411
+            foreach ($reminder_days as $key => $days) {
1412
+                if ($days !== '') {
1413
+                    $date_to_send[$id][] = date_i18n('Y-m-d', strtotime($due_date) + ($days * DAY_IN_SECONDS));
1414 1414
                 }
1415 1415
             }
1416 1416
         }
1417 1417
 
1418
-        $today              = date_i18n( 'Y-m-d' );
1418
+        $today              = date_i18n('Y-m-d');
1419 1419
         $wpi_auto_reminder  = true;
1420 1420
 
1421
-        foreach ( $date_to_send as $id => $values ) {
1422
-            if ( in_array( $today, $values ) ) {
1423
-                $sent = get_post_meta( $id, '_wpinv_reminder_sent', true );
1421
+        foreach ($date_to_send as $id => $values) {
1422
+            if (in_array($today, $values)) {
1423
+                $sent = get_post_meta($id, '_wpinv_reminder_sent', true);
1424 1424
 
1425
-                if ( isset( $sent ) && !empty( $sent ) ) {
1426
-                    if ( !in_array( $today, $sent ) ) {
1427
-                        do_action( 'wpinv_send_payment_reminder_notification', $id );
1425
+                if (isset($sent) && !empty($sent)) {
1426
+                    if (!in_array($today, $sent)) {
1427
+                        do_action('wpinv_send_payment_reminder_notification', $id);
1428 1428
                     }
1429 1429
                 } else {
1430
-                    do_action( 'wpinv_send_payment_reminder_notification', $id );
1430
+                    do_action('wpinv_send_payment_reminder_notification', $id);
1431 1431
                 }
1432 1432
             }
1433 1433
         }
1434 1434
         
1435
-        $wpi_auto_reminder  = false;
1435
+        $wpi_auto_reminder = false;
1436 1436
     }
1437 1437
 }
1438 1438
 
1439
-function wpinv_send_payment_reminder_notification( $invoice_id ) {
1439
+function wpinv_send_payment_reminder_notification($invoice_id) {
1440 1440
     global $wpinv_email_search, $wpinv_email_replace;
1441 1441
     
1442 1442
     $email_type = 'overdue';
1443
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
1443
+    if (!wpinv_email_is_enabled($email_type)) {
1444 1444
         return false;
1445 1445
     }
1446 1446
     
1447
-    $invoice    = wpinv_get_invoice( $invoice_id );
1448
-    if ( empty( $invoice ) ) {
1447
+    $invoice = wpinv_get_invoice($invoice_id);
1448
+    if (empty($invoice)) {
1449 1449
         return false;
1450 1450
     }
1451 1451
     
1452
-    if ( !$invoice->needs_payment() ) {
1452
+    if (!$invoice->needs_payment()) {
1453 1453
         return false;
1454 1454
     }
1455 1455
     
1456
-    $recipient  = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
1457
-    if ( !is_email( $recipient ) ) {
1456
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
1457
+    if (!is_email($recipient)) {
1458 1458
         return false;
1459 1459
     }
1460 1460
         
@@ -1470,70 +1470,70 @@  discard block
 block discarded – undo
1470 1470
     $replace                    = array();
1471 1471
     $replace['full_name']       = $invoice->get_user_full_name();
1472 1472
     $replace['invoice_number']  = $invoice->get_number();
1473
-    $replace['invoice_due_date']= $invoice->get_due_date( true );
1474
-    $replace['invoice_total']   = $invoice->get_total( true );
1475
-    $replace['invoice_link']    = $invoice->get_view_url( true );
1476
-    $replace['invoice_pay_link']= $invoice->get_checkout_payment_url( false, true );
1477
-    $replace['is_was']          = strtotime( $invoice->get_due_date() ) < strtotime( date_i18n( 'Y-m-d' ) ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' );
1473
+    $replace['invoice_due_date'] = $invoice->get_due_date(true);
1474
+    $replace['invoice_total']   = $invoice->get_total(true);
1475
+    $replace['invoice_link']    = $invoice->get_view_url(true);
1476
+    $replace['invoice_pay_link'] = $invoice->get_checkout_payment_url(false, true);
1477
+    $replace['is_was']          = strtotime($invoice->get_due_date()) < strtotime(date_i18n('Y-m-d')) ? __('was', 'invoicing') : __('is', 'invoicing');
1478 1478
 
1479 1479
     $wpinv_email_search         = $search;
1480 1480
     $wpinv_email_replace        = $replace;
1481 1481
     
1482
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
1483
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
1484
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
1485
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
1482
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
1483
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
1484
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
1485
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
1486 1486
     
1487
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
1487
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
1488 1488
     
1489
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
1489
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
1490 1490
             'invoice'       => $invoice,
1491 1491
             'email_type'    => $email_type,
1492 1492
             'email_heading' => $email_heading,
1493 1493
             'sent_to_admin' => false,
1494 1494
             'plain_text'    => false,
1495 1495
             'message_body'  => $message_body
1496
-        ) );
1496
+        ));
1497 1497
         
1498
-    $content        = wpinv_email_format_text( $content );
1498
+    $content = wpinv_email_format_text($content);
1499 1499
 
1500
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
1501
-    if ( $sent ) {
1502
-        do_action( 'wpinv_payment_reminder_sent', $invoice_id, $invoice );
1500
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
1501
+    if ($sent) {
1502
+        do_action('wpinv_payment_reminder_sent', $invoice_id, $invoice);
1503 1503
     }
1504 1504
         
1505 1505
     return $sent;
1506 1506
 }
1507
-add_action( 'wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1 );
1507
+add_action('wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1);
1508 1508
 
1509
-function wpinv_payment_reminder_sent( $invoice_id, $invoice ) {
1509
+function wpinv_payment_reminder_sent($invoice_id, $invoice) {
1510 1510
     global $wpi_auto_reminder;
1511 1511
     
1512
-    $sent = get_post_meta( $invoice_id, '_wpinv_reminder_sent', true );
1512
+    $sent = get_post_meta($invoice_id, '_wpinv_reminder_sent', true);
1513 1513
     
1514
-    if ( empty( $sent ) ) {
1514
+    if (empty($sent)) {
1515 1515
         $sent = array();
1516 1516
     }
1517
-    $sent[] = date_i18n( 'Y-m-d' );
1517
+    $sent[] = date_i18n('Y-m-d');
1518 1518
     
1519
-    update_post_meta( $invoice_id, '_wpinv_reminder_sent', $sent );
1519
+    update_post_meta($invoice_id, '_wpinv_reminder_sent', $sent);
1520 1520
     
1521
-    if ( $wpi_auto_reminder ) { // Auto reminder note.
1522
-        $note = __( 'Manual reminder sent to the user.', 'invoicing' );
1523
-        $invoice->add_note( $note, false, false, true );
1521
+    if ($wpi_auto_reminder) { // Auto reminder note.
1522
+        $note = __('Manual reminder sent to the user.', 'invoicing');
1523
+        $invoice->add_note($note, false, false, true);
1524 1524
     } else { // Menual reminder note.
1525
-        $note = __( 'Manual reminder sent to the user.', 'invoicing' );
1526
-        $invoice->add_note( $note );
1525
+        $note = __('Manual reminder sent to the user.', 'invoicing');
1526
+        $invoice->add_note($note);
1527 1527
     }
1528 1528
 }
1529
-add_action( 'wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2 );
1529
+add_action('wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2);
1530 1530
 
1531
-function wpinv_email_before_note_details( $invoice, $email_type, $sent_to_admin, $customer_note ) {
1532
-    if("wpi_invoice" === $invoice->post_type && !empty($customer_note)){
1531
+function wpinv_email_before_note_details($invoice, $email_type, $sent_to_admin, $customer_note) {
1532
+    if ("wpi_invoice" === $invoice->post_type && !empty($customer_note)) {
1533 1533
         $before_note = '';
1534
-        $before_note .= __( 'Hello, a note has just been added to your invoice:', 'invoicing' );
1535
-        $before_note .= '<blockquote class="wpinv-note">'.wpautop( wptexturize( $customer_note ) ).'</blockquote>';
1536
-        $before_note .= __( 'For your reference, your invoice details are shown below.', 'invoicing' );
1534
+        $before_note .= __('Hello, a note has just been added to your invoice:', 'invoicing');
1535
+        $before_note .= '<blockquote class="wpinv-note">' . wpautop(wptexturize($customer_note)) . '</blockquote>';
1536
+        $before_note .= __('For your reference, your invoice details are shown below.', 'invoicing');
1537 1537
         echo $before_note;
1538 1538
     }
1539 1539
 }
1540 1540
\ 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
@@ -976,67 +976,67 @@
 block discarded – undo
976 976
 function wpinv_tool_merge_fix_taxes() {
977 977
     global $wpdb;
978 978
     
979
-	$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'";
980
-	$items = $wpdb->get_results( $sql );
979
+    $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'";
980
+    $items = $wpdb->get_results( $sql );
981 981
 	
982
-	if ( !empty( $items ) ) {
983
-		foreach ( $items as $item ) {
984
-			if ( get_post_meta( $item->ID, '_wpinv_vat_class', true ) == '_exempt' ) {
985
-				update_post_meta( $item->ID, '_wpinv_vat_class', '_standard' );
986
-			}
987
-		}
988
-	}
982
+    if ( !empty( $items ) ) {
983
+        foreach ( $items as $item ) {
984
+            if ( get_post_meta( $item->ID, '_wpinv_vat_class', true ) == '_exempt' ) {
985
+                update_post_meta( $item->ID, '_wpinv_vat_class', '_standard' );
986
+            }
987
+        }
988
+    }
989 989
 		
990 990
     $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', 'wpi-processing', 'wpi-renewal' ) ORDER BY `gdi`.`id` ASC";
991 991
     $items = $wpdb->get_results( $sql );
992 992
 	
993
-	if ( !empty( $items ) ) {
994
-		$success = false;
993
+    if ( !empty( $items ) ) {
994
+        $success = false;
995 995
         $message = __( 'Taxes fixed for non-paid merged GD invoices.', 'invoicing' );
996 996
 		
997
-		global $wpi_userID, $wpinv_ip_address_country, $wpi_tax_rates;
997
+        global $wpi_userID, $wpinv_ip_address_country, $wpi_tax_rates;
998 998
 		
999
-		foreach ( $items as $item ) {
1000
-			$wpi_tax_rates = NULL;               
1001
-			$data = wpinv_get_invoice($item->ID);
999
+        foreach ( $items as $item ) {
1000
+            $wpi_tax_rates = NULL;               
1001
+            $data = wpinv_get_invoice($item->ID);
1002 1002
 
1003
-			if ( empty( $data ) ) {
1004
-				continue;
1005
-			}
1003
+            if ( empty( $data ) ) {
1004
+                continue;
1005
+            }
1006 1006
 			
1007
-			$checkout_session = wpinv_get_checkout_session();
1007
+            $checkout_session = wpinv_get_checkout_session();
1008 1008
 			
1009
-			$data_session                   = array();
1010
-			$data_session['invoice_id']     = $data->ID;
1011
-			$data_session['cart_discounts'] = $data->get_discounts( true );
1009
+            $data_session                   = array();
1010
+            $data_session['invoice_id']     = $data->ID;
1011
+            $data_session['cart_discounts'] = $data->get_discounts( true );
1012 1012
 			
1013
-			wpinv_set_checkout_session( $data_session );
1013
+            wpinv_set_checkout_session( $data_session );
1014 1014
 			
1015
-			$wpi_userID         = (int)$data->get_user_id();
1016
-			$_POST['country']   = !empty($data->country) ? $data->country : wpinv_get_default_country();
1015
+            $wpi_userID         = (int)$data->get_user_id();
1016
+            $_POST['country']   = !empty($data->country) ? $data->country : wpinv_get_default_country();
1017 1017
 				
1018
-			$data->country      = sanitize_text_field( $_POST['country'] );
1019
-			$data->set( 'country', sanitize_text_field( $_POST['country'] ) );
1018
+            $data->country      = sanitize_text_field( $_POST['country'] );
1019
+            $data->set( 'country', sanitize_text_field( $_POST['country'] ) );
1020 1020
 			
1021
-			$wpinv_ip_address_country = $data->country;
1021
+            $wpinv_ip_address_country = $data->country;
1022 1022
 			
1023
-			$data->recalculate_totals(true);
1023
+            $data->recalculate_totals(true);
1024 1024
 			
1025
-			wpinv_set_checkout_session( $checkout_session );
1025
+            wpinv_set_checkout_session( $checkout_session );
1026 1026
 			
1027
-			$update_data = array();
1028
-			$update_data['tax_amount'] = $data->get_tax();
1029
-			$update_data['paied_amount'] = $data->get_total();
1030
-			$update_data['invoice_id'] = $data->ID;
1027
+            $update_data = array();
1028
+            $update_data['tax_amount'] = $data->get_tax();
1029
+            $update_data['paied_amount'] = $data->get_total();
1030
+            $update_data['invoice_id'] = $data->ID;
1031 1031
 			
1032
-			$wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $item->gdp_id ) );
1033
-		}
1034
-	} else {
1032
+            $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $item->gdp_id ) );
1033
+        }
1034
+    } else {
1035 1035
         $success = false;
1036 1036
         $message = __( 'No invoices found to fix taxes!', 'invoicing' );
1037 1037
     }
1038 1038
 	
1039
-	$response = array();
1039
+    $response = array();
1040 1040
     $response['success'] = $success;
1041 1041
     $response['data']['message'] = $message;
1042 1042
     wp_send_json( $response );
Please login to merge, or discard this patch.
Spacing   +341 added lines, -341 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_round_amount( $package->amount );
114
+    $meta['price']              = wpinv_round_amount($package->amount);
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', 'wpi-processing', 'wpi-renewal' ) ) ) {
235
+            if ($wpi_gdp_inv_merge && in_array($status, array('publish', 'wpi-processing', 'wpi-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 'wpi-processing':
429 429
         case 'wpi-renewal':
@@ -434,102 +434,102 @@  discard block
 block discarded – undo
434 434
     return $inv_status;
435 435
 }
436 436
 
437
-function wpinv_wpi_to_gdp_id( $invoice_id ) {
437
+function wpinv_wpi_to_gdp_id($invoice_id) {
438 438
     global $wpdb;
439 439
     
440
-    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 ) ) );
440
+    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 441
 }
442 442
 
443
-function wpinv_gdp_to_wpi_id( $invoice_id ) {
444
-    $invoice = geodir_get_invoice( $invoice_id );    
445
-    return ( empty( $invoice->invoice_id ) ? $invoice->invoice_id : false);
443
+function wpinv_gdp_to_wpi_id($invoice_id) {
444
+    $invoice = geodir_get_invoice($invoice_id);    
445
+    return (empty($invoice->invoice_id) ? $invoice->invoice_id : false);
446 446
 }
447 447
 
448
-function wpinv_to_gdp_recalculate_total( $invoice, $wpi_nosave ) {
448
+function wpinv_to_gdp_recalculate_total($invoice, $wpi_nosave) {
449 449
     global $wpdb;
450 450
     
451
-    if ( !empty( $wpi_nosave ) ) {
451
+    if (!empty($wpi_nosave)) {
452 452
         return;
453 453
     }
454 454
     
455
-    $gdp_invoice_id = wpinv_wpi_to_gdp_id( $invoice->ID );
455
+    $gdp_invoice_id = wpinv_wpi_to_gdp_id($invoice->ID);
456 456
     
457
-    if ( $gdp_invoice_id > 0 ) {
457
+    if ($gdp_invoice_id > 0) {
458 458
         $update_data = array();
459 459
         $update_data['tax_amount']      = $invoice->tax;
460 460
         $update_data['paied_amount']    = $invoice->total;
461 461
         $update_data['discount']        = $invoice->discount;
462 462
         $update_data['coupon_code']     = $invoice->discount_code;
463 463
         
464
-        $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $gdp_invoice_id ) );
464
+        $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $gdp_invoice_id));
465 465
     }
466 466
     
467 467
     return;
468 468
 }
469 469
 //add_action( 'wpinv_invoice_recalculate_total', 'wpinv_to_gdp_recalculate_total', 10, 2 );
470 470
 
471
-function wpinv_gdp_to_wpi_invoice( $invoice_id ) {
472
-    $invoice = geodir_get_invoice( $invoice_id );
473
-    if ( empty( $invoice->invoice_id ) ) {
471
+function wpinv_gdp_to_wpi_invoice($invoice_id) {
472
+    $invoice = geodir_get_invoice($invoice_id);
473
+    if (empty($invoice->invoice_id)) {
474 474
         return false;
475 475
     }
476 476
     
477
-    return wpinv_get_invoice( $invoice->invoice_id );
477
+    return wpinv_get_invoice($invoice->invoice_id);
478 478
 }
479 479
 
480
-function wpinv_payment_set_coupon_code( $status, $invoice_id, $coupon_code ) {
481
-    $invoice = wpinv_gdp_to_wpi_invoice( $invoice_id );
482
-    if ( empty( $invoice ) ) {
480
+function wpinv_payment_set_coupon_code($status, $invoice_id, $coupon_code) {
481
+    $invoice = wpinv_gdp_to_wpi_invoice($invoice_id);
482
+    if (empty($invoice)) {
483 483
         return $status;
484 484
     }
485 485
 
486
-    if ( $status === 1 || $status === 0 ) {
487
-        if ( $status === 1 ) {
488
-            $discount = geodir_get_discount_amount( $coupon_code, $invoice->get_subtotal() );
486
+    if ($status === 1 || $status === 0) {
487
+        if ($status === 1) {
488
+            $discount = geodir_get_discount_amount($coupon_code, $invoice->get_subtotal());
489 489
         } else {
490 490
             $discount = '';
491 491
             $coupon_code = '';
492 492
         }
493 493
         
494
-        $invoice->set( 'discount', $discount );
495
-        $invoice->set( 'discount_code', $coupon_code );
494
+        $invoice->set('discount', $discount);
495
+        $invoice->set('discount_code', $coupon_code);
496 496
         $invoice->save();
497 497
         $invoice->recalculate_total();
498 498
     }
499 499
     
500 500
     return $status;
501 501
 }
502
-add_filter( 'geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3 );
502
+add_filter('geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3);
503 503
 
504
-function wpinv_insert_invoice( $invoice_data = array() ) {
505
-    if ( empty( $invoice_data ) ) {
504
+function wpinv_insert_invoice($invoice_data = array()) {
505
+    if (empty($invoice_data)) {
506 506
         return false;
507 507
     }
508 508
     
509
-    if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) {
510
-        return new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast on item.', 'invoicing' ) );
509
+    if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) {
510
+        return new WP_Error('wpinv_invalid_items', __('Invoice must have atleast on item.', 'invoicing'));
511 511
     }
512 512
 
513 513
     // default invoice args, note that status is checked for validity in wpinv_create_invoice()
514 514
     $default_args = array(
515
-        'status'        => !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'pending',
516
-        'user_note'     => !empty( $invoice_data['note'] ) ? $invoice_data['note'] : null,
517
-        'invoice_id'    => !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0,
518
-        'user_id'       => !empty( $invoice_data['user_id'] ) ? (int)$invoice_data['user_id'] : get_current_user_id(),
515
+        'status'        => !empty($invoice_data['status']) ? $invoice_data['status'] : 'pending',
516
+        'user_note'     => !empty($invoice_data['note']) ? $invoice_data['note'] : null,
517
+        'invoice_id'    => !empty($invoice_data['invoice_id']) ? (int)$invoice_data['invoice_id'] : 0,
518
+        'user_id'       => !empty($invoice_data['user_id']) ? (int)$invoice_data['user_id'] : get_current_user_id(),
519 519
     );
520 520
 
521
-    $invoice = wpinv_create_invoice( $default_args, $invoice_data );
522
-    if ( is_wp_error( $invoice ) ) {
521
+    $invoice = wpinv_create_invoice($default_args, $invoice_data);
522
+    if (is_wp_error($invoice)) {
523 523
         return $invoice;
524 524
     }
525 525
 
526
-    $gateway = !empty( $invoice_data['gateway'] ) ? $invoice_data['gateway'] : '';
527
-    $gateway = empty( $gateway ) && isset( $_POST['gateway'] ) ? $_POST['gateway'] : $gateway;
526
+    $gateway = !empty($invoice_data['gateway']) ? $invoice_data['gateway'] : '';
527
+    $gateway = empty($gateway) && isset($_POST['gateway']) ? $_POST['gateway'] : $gateway;
528 528
     
529
-    if ( !empty( $gateway ) ) {
530
-        $gateway = wpinv_gdp_to_wpi_gateway( $gateway );
529
+    if (!empty($gateway)) {
530
+        $gateway = wpinv_gdp_to_wpi_gateway($gateway);
531 531
         $invoice_data['payment_details']['gateway'] = $gateway;
532
-        $invoice_data['payment_details']['gateway_title'] = wpinv_gdp_to_wpi_gateway_title( $gateway );
532
+        $invoice_data['payment_details']['gateway_title'] = wpinv_gdp_to_wpi_gateway_title($gateway);
533 533
     }
534 534
     
535 535
     $user_info = array(
@@ -550,67 +550,67 @@  discard block
 block discarded – undo
550 550
         'discount'       => array(),
551 551
     );
552 552
     
553
-    $user_info    = wp_parse_args( $invoice_data['user_info'], $user_info );
553
+    $user_info = wp_parse_args($invoice_data['user_info'], $user_info);
554 554
     
555 555
     $payment_details = array();
556
-    if ( !empty( $invoice_data['payment_details'] ) ) {
556
+    if (!empty($invoice_data['payment_details'])) {
557 557
         $payment_details = array(
558 558
             'gateway'           => 'manual',
559
-            'gateway_title'     => __( 'Manual Payment', 'invoicing' ),
559
+            'gateway_title'     => __('Manual Payment', 'invoicing'),
560 560
             'currency'          => geodir_get_currency_type(),
561 561
             'paid'              => false,
562 562
             'transaction_id'    => '',
563 563
         );
564
-        $payment_details = wp_parse_args( $invoice_data['payment_details'], $payment_details );
564
+        $payment_details = wp_parse_args($invoice_data['payment_details'], $payment_details);
565 565
     }
566
-    $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'pending' ) );
567
-    if ( !empty( $payment_details ) ) {
568
-        $invoice->set( 'currency', $payment_details['currency'] );
569
-        $invoice->set( 'gateway', $payment_details['gateway'] );
570
-        $invoice->set( 'gateway_title', $payment_details['gateway_title'] );
571
-        $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
566
+    $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'pending'));
567
+    if (!empty($payment_details)) {
568
+        $invoice->set('currency', $payment_details['currency']);
569
+        $invoice->set('gateway', $payment_details['gateway']);
570
+        $invoice->set('gateway_title', $payment_details['gateway_title']);
571
+        $invoice->set('transaction_id', $payment_details['transaction_id']);
572 572
     }
573 573
 
574
-    $invoice->set( 'user_info', $user_info );
574
+    $invoice->set('user_info', $user_info);
575 575
     ///$invoice->set( 'user_id', $user_info['user_id'] );
576 576
     ///$invoice->set( 'email', $user_info['email'] );
577
-    $invoice->set( 'first_name', $user_info['first_name'] );
578
-    $invoice->set( 'last_name', $user_info['last_name'] );
579
-    $invoice->set( 'address', $user_info['address'] );
580
-    $invoice->set( 'company', $user_info['company'] );
581
-    $invoice->set( 'vat_number', $user_info['vat_number'] );
582
-    $invoice->set( 'phone', $user_info['phone'] );
583
-    $invoice->set( 'city', $user_info['city'] );
584
-    $invoice->set( 'country', $user_info['country'] );
585
-    $invoice->set( 'state', $user_info['state'] );
586
-    $invoice->set( 'zip', $user_info['zip'] );
587
-    $invoice->set( 'discounts', ( !empty( $user_info['discount'] ) ? $user_info['discount'] : array() ) );
588
-    $invoice->set( 'ip', wpinv_get_ip() );
589
-    if ( !empty( $invoice_data['invoice_key'] ) ) {
590
-        $invoice->set( 'key', $invoice_data['invoice_key'] );
577
+    $invoice->set('first_name', $user_info['first_name']);
578
+    $invoice->set('last_name', $user_info['last_name']);
579
+    $invoice->set('address', $user_info['address']);
580
+    $invoice->set('company', $user_info['company']);
581
+    $invoice->set('vat_number', $user_info['vat_number']);
582
+    $invoice->set('phone', $user_info['phone']);
583
+    $invoice->set('city', $user_info['city']);
584
+    $invoice->set('country', $user_info['country']);
585
+    $invoice->set('state', $user_info['state']);
586
+    $invoice->set('zip', $user_info['zip']);
587
+    $invoice->set('discounts', (!empty($user_info['discount']) ? $user_info['discount'] : array()));
588
+    $invoice->set('ip', wpinv_get_ip());
589
+    if (!empty($invoice_data['invoice_key'])) {
590
+        $invoice->set('key', $invoice_data['invoice_key']);
591 591
     }
592
-    $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) );
593
-    $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) );
592
+    $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live'));
593
+    $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : ''));
594 594
     
595 595
     // Add note
596
-    if ( !empty( $invoice_data['user_note'] ) ) {
597
-        $invoice->add_note( $invoice_data['user_note'], true );
596
+    if (!empty($invoice_data['user_note'])) {
597
+        $invoice->add_note($invoice_data['user_note'], true);
598 598
     }
599 599
     
600
-    if ( !empty( $invoice_data['private_note'] ) ) {
601
-        $invoice->add_note( $invoice_data['private_note'] );
600
+    if (!empty($invoice_data['private_note'])) {
601
+        $invoice->add_note($invoice_data['private_note']);
602 602
     }
603 603
     
604
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) {
605
-        foreach ( $invoice_data['cart_details'] as $key => $item ) {
606
-            $item_id    = !empty( $item['id'] ) ? $item['id'] : 0;
607
-            $quantity   = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
608
-            $name       = !empty( $item['name'] ) ? $item['name'] : '';
609
-            $item_price = isset( $item['item_price'] ) ? $item['item_price'] : '';
604
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) {
605
+        foreach ($invoice_data['cart_details'] as $key => $item) {
606
+            $item_id    = !empty($item['id']) ? $item['id'] : 0;
607
+            $quantity   = !empty($item['quantity']) ? $item['quantity'] : 1;
608
+            $name       = !empty($item['name']) ? $item['name'] : '';
609
+            $item_price = isset($item['item_price']) ? $item['item_price'] : '';
610 610
             
611
-            $post_item  = new WPInv_Item( $item_id );
612
-            if ( !empty( $post_item ) ) {
613
-                $name       = !empty( $name ) ? $name : $post_item->get_name();
611
+            $post_item  = new WPInv_Item($item_id);
612
+            if (!empty($post_item)) {
613
+                $name       = !empty($name) ? $name : $post_item->get_name();
614 614
                 $item_price = $item_price !== '' ? $item_price : $post_item->get_price();
615 615
             } else {
616 616
                 continue;
@@ -620,33 +620,33 @@  discard block
 block discarded – undo
620 620
                 'name'          => $name,
621 621
                 'quantity'      => $quantity,
622 622
                 'item_price'    => $item_price,
623
-                'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0.00,
624
-                'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
625
-                'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
626
-                'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
623
+                'tax'           => !empty($item['tax']) ? $item['tax'] : 0.00,
624
+                'discount'      => isset($item['discount']) ? $item['discount'] : 0,
625
+                'meta'          => isset($item['meta']) ? $item['meta'] : array(),
626
+                'fees'          => isset($item['fees']) ? $item['fees'] : array(),
627 627
             );
628 628
 
629
-            $invoice->add_item( $item_id, $args );
629
+            $invoice->add_item($item_id, $args);
630 630
         }
631 631
     }
632 632
 
633
-    $invoice->increase_tax( wpinv_get_cart_fee_tax() );
633
+    $invoice->increase_tax(wpinv_get_cart_fee_tax());
634 634
 
635
-    if ( isset( $invoice_data['post_date'] ) ) {
636
-        $invoice->set( 'date', $invoice_data['post_date'] );
635
+    if (isset($invoice_data['post_date'])) {
636
+        $invoice->set('date', $invoice_data['post_date']);
637 637
     }
638 638
 
639
-    $number = wpinv_format_invoice_number( $invoice->ID );
640
-    $invoice->set( 'number', $number );
641
-    update_option( 'wpinv_last_invoice_number', $number );
639
+    $number = wpinv_format_invoice_number($invoice->ID);
640
+    $invoice->set('number', $number);
641
+    update_option('wpinv_last_invoice_number', $number);
642 642
     
643 643
     $invoice->save();
644 644
     
645
-    do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data );
645
+    do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data);
646 646
 
647
-    if ( ! empty( $invoice->ID ) ) {
647
+    if (!empty($invoice->ID)) {
648 648
         // payment method (and payment_complete() if `paid` == true)
649
-        if ( !empty( $payment_details['paid'] ) ) {
649
+        if (!empty($payment_details['paid'])) {
650 650
             //$invoice->payment_complete( !empty( $payment_details['transaction_id'] ) ? $payment_details['transaction_id'] : $invoice->ID );
651 651
         }
652 652
             
@@ -663,158 +663,158 @@  discard block
 block discarded – undo
663 663
     }
664 664
     ?>
665 665
     <tr>
666
-        <td><?php _e( 'Merge Price Packages', 'invoicing' ); ?></td>
667
-        <td><p><?php _e( 'Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing' ); ?></p></td>
668
-        <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
666
+        <td><?php _e('Merge Price Packages', 'invoicing'); ?></td>
667
+        <td><p><?php _e('Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing'); ?></p></td>
668
+        <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
669 669
     </tr>
670 670
     <tr>
671
-        <td><?php _e( 'Merge Invoices', 'invoicing' ); ?></td>
672
-        <td><p><?php _e( 'Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing' ); ?></p></td>
673
-        <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
671
+        <td><?php _e('Merge Invoices', 'invoicing'); ?></td>
672
+        <td><p><?php _e('Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing'); ?></p></td>
673
+        <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
674 674
     </tr>
675 675
 	<tr>
676
-        <td><?php _e( 'Fix Taxes for Merged Invoices', 'invoicing' ); ?></td>
677
-        <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>
678
-        <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
676
+        <td><?php _e('Fix Taxes for Merged Invoices', 'invoicing'); ?></td>
677
+        <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>
678
+        <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
679 679
     </tr>
680 680
     <tr>
681
-        <td><?php _e( 'Merge Coupons', 'invoicing' ); ?></td>
682
-        <td><p><?php _e( 'Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing' ); ?></p></td>
683
-        <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
681
+        <td><?php _e('Merge Coupons', 'invoicing'); ?></td>
682
+        <td><p><?php _e('Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing'); ?></p></td>
683
+        <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
684 684
     </tr>
685 685
     <?php
686 686
 }
687
-add_action( 'wpinv_tools_row', 'wpinv_merge_gd_invoices', 10 );
687
+add_action('wpinv_tools_row', 'wpinv_merge_gd_invoices', 10);
688 688
 
689 689
 function wpinv_tool_merge_packages() {
690 690
     $packages = geodir_package_list_info();
691 691
     
692 692
     $count = 0;
693 693
     
694
-    if ( !empty( $packages ) ) {
694
+    if (!empty($packages)) {
695 695
         $success = true;
696 696
         
697
-        foreach ( $packages as $key => $package ) {
697
+        foreach ($packages as $key => $package) {
698 698
             $item = wpinv_get_item_by('package_id', $package->pid);
699
-            if ( !empty( $item ) ) {
699
+            if (!empty($item)) {
700 700
                 continue;
701 701
             }
702 702
             
703
-            $merged = wpinv_merge_gd_package_to_item( $package->pid, false, $package );
703
+            $merged = wpinv_merge_gd_package_to_item($package->pid, false, $package);
704 704
             
705
-            if ( !empty( $merged ) ) {
706
-                wpinv_error_log( 'Package merge S : ' . $package->pid );
705
+            if (!empty($merged)) {
706
+                wpinv_error_log('Package merge S : ' . $package->pid);
707 707
                 $count++;
708 708
             } else {
709
-                wpinv_error_log( 'Package merge F : ' . $package->pid );
709
+                wpinv_error_log('Package merge F : ' . $package->pid);
710 710
             }
711 711
         }
712 712
         
713
-        if ( $count > 0 ) {
714
-            $message = sprintf( _n( 'Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing' ), $count );
713
+        if ($count > 0) {
714
+            $message = sprintf(_n('Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing'), $count);
715 715
         } else {
716
-            $message = __( 'No price packages merged.', 'invoicing' );
716
+            $message = __('No price packages merged.', 'invoicing');
717 717
         }
718 718
     } else {
719 719
         $success = false;
720
-        $message = __( 'No price packages found to merge!', 'invoicing' );
720
+        $message = __('No price packages found to merge!', 'invoicing');
721 721
     }
722 722
     
723 723
     $response = array();
724 724
     $response['success'] = $success;
725 725
     $response['data']['message'] = $message;
726
-    wp_send_json( $response );
726
+    wp_send_json($response);
727 727
 }
728
-add_action( 'wpinv_tool_merge_packages', 'wpinv_tool_merge_packages' );
728
+add_action('wpinv_tool_merge_packages', 'wpinv_tool_merge_packages');
729 729
 
730 730
 function wpinv_tool_merge_invoices() {
731 731
     global $wpdb, $wpi_gdp_inv_merge, $wpi_tax_rates;
732 732
     
733 733
     $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";
734
-    $items = $wpdb->get_results( $sql );
734
+    $items = $wpdb->get_results($sql);
735 735
     
736 736
     $count = 0;
737 737
     
738
-    if ( !empty( $items ) ) {
738
+    if (!empty($items)) {
739 739
         $success = true;
740 740
         $wpi_gdp_inv_merge = true;
741 741
         
742
-        foreach ( $items as $item ) {
742
+        foreach ($items as $item) {
743 743
             $wpi_tax_rates = NULL;
744 744
             
745
-            $wpdb->query( "UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'" );
745
+            $wpdb->query("UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'");
746 746
             
747
-            $merged = wpinv_cpt_save( $item->id );
747
+            $merged = wpinv_cpt_save($item->id);
748 748
             
749
-            if ( !empty( $merged ) && !empty( $merged->ID ) ) {
749
+            if (!empty($merged) && !empty($merged->ID)) {
750 750
                 $count++;
751 751
                 
752 752
                 //$wpdb->query( "UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = '" . $merged->ID . "' WHERE id = '" . $item->id . "'" );
753 753
                 
754
-                $post_date = !empty( $item->date ) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time( 'mysql' );
755
-                $post_date_gmt = get_gmt_from_date( $post_date );
756
-                $post_modified = !empty( $item->date_updated ) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date;
757
-                $post_modified_gmt = get_gmt_from_date( $post_modified );
754
+                $post_date = !empty($item->date) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time('mysql');
755
+                $post_date_gmt = get_gmt_from_date($post_date);
756
+                $post_modified = !empty($item->date_updated) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date;
757
+                $post_modified_gmt = get_gmt_from_date($post_modified);
758 758
                 
759
-                $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 ) );
759
+                $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));
760 760
                 
761
-                if ( $merged->is_paid() ) {
762
-                    update_post_meta( $merged->ID, '_wpinv_completed_date', $post_modified );
761
+                if ($merged->is_paid()) {
762
+                    update_post_meta($merged->ID, '_wpinv_completed_date', $post_modified);
763 763
                 }
764 764
                 
765
-                clean_post_cache( $merged->ID );
765
+                clean_post_cache($merged->ID);
766 766
                 
767
-                wpinv_error_log( 'Invoice merge S : ' . $item->id . ' => ' . $merged->ID );
767
+                wpinv_error_log('Invoice merge S : ' . $item->id . ' => ' . $merged->ID);
768 768
             } else {
769
-                wpinv_error_log( 'Invoice merge F : ' . $item->id );
769
+                wpinv_error_log('Invoice merge F : ' . $item->id);
770 770
             }
771 771
         }
772 772
         
773 773
         $wpi_gdp_inv_merge = false;
774 774
         
775
-        if ( $count > 0 ) {
776
-            $message = sprintf( _n( 'Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing' ), $count );
775
+        if ($count > 0) {
776
+            $message = sprintf(_n('Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing'), $count);
777 777
         } else {
778
-            $message = __( 'No invoices merged.', 'invoicing' );
778
+            $message = __('No invoices merged.', 'invoicing');
779 779
         }
780 780
     } else {
781 781
         $success = false;
782
-        $message = __( 'No invoices found to merge!', 'invoicing' );
782
+        $message = __('No invoices found to merge!', 'invoicing');
783 783
     }
784 784
     
785 785
     $response = array();
786 786
     $response['success'] = $success;
787 787
     $response['data']['message'] = $message;
788
-    wp_send_json( $response );
788
+    wp_send_json($response);
789 789
 }
790
-add_action( 'wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices' );
790
+add_action('wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices');
791 791
 
792 792
 function wpinv_tool_merge_coupons() {
793 793
     global $wpdb;
794 794
     
795 795
     $sql = "SELECT * FROM `" . COUPON_TABLE . "` WHERE `coupon_code` IS NOT NULL AND `coupon_code` != '' ORDER BY `cid` ASC";
796
-    $items = $wpdb->get_results( $sql );
796
+    $items = $wpdb->get_results($sql);
797 797
     $count = 0;
798 798
     
799
-    if ( !empty( $items ) ) {
799
+    if (!empty($items)) {
800 800
         $success = true;
801 801
         
802
-        foreach ( $items as $item ) {
803
-            if ( wpinv_get_discount_by_code( $item->coupon_code ) ) {
802
+        foreach ($items as $item) {
803
+            if (wpinv_get_discount_by_code($item->coupon_code)) {
804 804
                 continue;
805 805
             }
806 806
             
807 807
             $args = array(
808 808
                 'post_type'   => 'wpi_discount',
809 809
                 'post_title'  => $item->coupon_code,
810
-                'post_status' => !empty( $item->status ) ? 'publish' : 'pending'
810
+                'post_status' => !empty($item->status) ? 'publish' : 'pending'
811 811
             );
812 812
 
813
-            $merged = wp_insert_post( $args );
813
+            $merged = wp_insert_post($args);
814 814
             
815 815
             $item_id = $item->cid;
816 816
             
817
-            if ( $merged ) {
817
+            if ($merged) {
818 818
                 $meta = array(
819 819
                     'code'              => $item->coupon_code,
820 820
                     'type'              => $item->discount_type != 'per' ? 'flat' : 'percent',
@@ -822,65 +822,65 @@  discard block
 block discarded – undo
822 822
                     'max_uses'          => (int)$item->usage_limit,
823 823
                     'uses'              => (int)$item->usage_count,
824 824
                 );
825
-                wpinv_store_discount( $merged, $meta, get_post( $merged ) );
825
+                wpinv_store_discount($merged, $meta, get_post($merged));
826 826
                 
827 827
                 $count++;
828 828
                 
829
-                wpinv_error_log( 'Coupon merge S : ' . $item_id . ' => ' . $merged );
829
+                wpinv_error_log('Coupon merge S : ' . $item_id . ' => ' . $merged);
830 830
             } else {
831
-                wpinv_error_log( 'Coupon merge F : ' . $item_id );
831
+                wpinv_error_log('Coupon merge F : ' . $item_id);
832 832
             }
833 833
         }
834 834
         
835
-        if ( $count > 0 ) {
836
-            $message = sprintf( _n( 'Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing' ), $count );
835
+        if ($count > 0) {
836
+            $message = sprintf(_n('Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing'), $count);
837 837
         } else {
838
-            $message = __( 'No coupons merged.', 'invoicing' );
838
+            $message = __('No coupons merged.', 'invoicing');
839 839
         }
840 840
     } else {
841 841
         $success = false;
842
-        $message = __( 'No coupons found to merge!', 'invoicing' );
842
+        $message = __('No coupons found to merge!', 'invoicing');
843 843
     }
844 844
     
845 845
     $response = array();
846 846
     $response['success'] = $success;
847 847
     $response['data']['message'] = $message;
848
-    wp_send_json( $response );
848
+    wp_send_json($response);
849 849
 }
850
-add_action( 'wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons' );
850
+add_action('wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons');
851 851
 
852
-function wpinv_gdp_to_wpi_currency( $value, $option = '' ) {
852
+function wpinv_gdp_to_wpi_currency($value, $option = '') {
853 853
     return wpinv_get_currency();
854 854
 }
855
-add_filter( 'pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2 );
855
+add_filter('pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2);
856 856
 
857
-function wpinv_gdp_to_wpi_currency_sign( $value, $option = '' ) {
857
+function wpinv_gdp_to_wpi_currency_sign($value, $option = '') {
858 858
     return wpinv_currency_symbol();
859 859
 }
860
-add_filter( 'pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2 );
860
+add_filter('pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2);
861 861
 
862
-function wpinv_gdp_to_wpi_display_price( $price, $amount, $display = true , $decimal_sep, $thousand_sep ) {
863
-    if ( !$display ) {
864
-        $price = wpinv_round_amount( $amount );
862
+function wpinv_gdp_to_wpi_display_price($price, $amount, $display = true, $decimal_sep, $thousand_sep) {
863
+    if (!$display) {
864
+        $price = wpinv_round_amount($amount);
865 865
     } else {
866
-        $price = wpinv_price( wpinv_format_amount( $amount ) );
866
+        $price = wpinv_price(wpinv_format_amount($amount));
867 867
     }
868 868
     
869 869
     return $price;
870 870
 }
871
-add_filter( 'geodir_payment_price' , 'wpinv_gdp_to_wpi_display_price', 10000, 5 );
871
+add_filter('geodir_payment_price', 'wpinv_gdp_to_wpi_display_price', 10000, 5);
872 872
 
873
-function wpinv_gdp_to_inv_checkout_redirect( $redirect_url ) {
873
+function wpinv_gdp_to_inv_checkout_redirect($redirect_url) {
874 874
     $invoice_id         = geodir_payment_cart_id();
875
-    $invoice_info       = geodir_get_invoice( $invoice_id );
876
-    $wpi_invoice        = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL;
875
+    $invoice_info       = geodir_get_invoice($invoice_id);
876
+    $wpi_invoice        = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL;
877 877
     
878
-    if ( !( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) ) {
879
-        $wpi_invoice_id = wpinv_cpt_save( $invoice_id );
880
-        $wpi_invoice    = wpinv_get_invoice( $wpi_invoice_id );
878
+    if (!(!empty($wpi_invoice) && !empty($wpi_invoice->ID))) {
879
+        $wpi_invoice_id = wpinv_cpt_save($invoice_id);
880
+        $wpi_invoice    = wpinv_get_invoice($wpi_invoice_id);
881 881
     }
882 882
     
883
-    if ( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) {
883
+    if (!empty($wpi_invoice) && !empty($wpi_invoice->ID)) {
884 884
         
885 885
         // Clear cart
886 886
         geodir_payment_clear_cart();
@@ -890,121 +890,121 @@  discard block
 block discarded – undo
890 890
     
891 891
     return $redirect_url;
892 892
 }
893
-add_filter( 'geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1 );
893
+add_filter('geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1);
894 894
 
895
-function wpinv_gdp_dashboard_invoice_history_link( $dashboard_links ) {    
896
-    if ( get_current_user_id() ) {        
897
-        $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
+function wpinv_gdp_dashboard_invoice_history_link($dashboard_links) {    
896
+    if (get_current_user_id()) {        
897
+        $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>';
898 898
     }
899 899
 
900 900
     return $dashboard_links;
901 901
 }
902
-add_action( 'geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link' );
903
-remove_action( 'geodir_dashboard_links', 'geodir_payment_invoices_list_page_link' );
902
+add_action('geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link');
903
+remove_action('geodir_dashboard_links', 'geodir_payment_invoices_list_page_link');
904 904
 
905
-function wpinv_wpi_to_gdp_update_status( $invoice_id, $new_status, $old_status ) {
905
+function wpinv_wpi_to_gdp_update_status($invoice_id, $new_status, $old_status) {
906 906
     if (!defined('GEODIRPAYMENT_VERSION')) {
907 907
         return false;
908 908
     }
909 909
     
910
-    $invoice    = wpinv_get_invoice( $invoice_id );
911
-    if ( empty( $invoice ) ) {
910
+    $invoice = wpinv_get_invoice($invoice_id);
911
+    if (empty($invoice)) {
912 912
         return false;
913 913
     }
914 914
     
915
-    remove_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 );
915
+    remove_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4);
916 916
     
917
-    $invoice_id = wpinv_wpi_to_gdp_id( $invoice_id );
918
-    $new_status = wpinv_wpi_to_gdp_status( $new_status );
917
+    $invoice_id = wpinv_wpi_to_gdp_id($invoice_id);
918
+    $new_status = wpinv_wpi_to_gdp_status($new_status);
919 919
     
920
-    geodir_update_invoice_status( $invoice_id, $new_status, $invoice->is_recurring() );
920
+    geodir_update_invoice_status($invoice_id, $new_status, $invoice->is_recurring());
921 921
 }
922
-add_action( 'wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3 );
922
+add_action('wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3);
923 923
 
924
-function wpinv_gdp_to_wpi_delete_package( $gd_package_id ) {
925
-    $item = wpinv_get_item_by( 'package_id', $gd_package_id );
924
+function wpinv_gdp_to_wpi_delete_package($gd_package_id) {
925
+    $item = wpinv_get_item_by('package_id', $gd_package_id);
926 926
     
927
-    if ( !empty( $item ) ) {
928
-        wpinv_remove_item( $item, true );
927
+    if (!empty($item)) {
928
+        wpinv_remove_item($item, true);
929 929
     }
930 930
 }
931
-add_action( 'geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1 ) ;
931
+add_action('geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1);
932 932
 
933
-function wpinv_can_delete_package_item( $return, $post_id ) {
934
-    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 ) ) {
935
-        $gd_package = geodir_get_package_info_by_id( $package_id, '' );
933
+function wpinv_can_delete_package_item($return, $post_id) {
934
+    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)) {
935
+        $gd_package = geodir_get_package_info_by_id($package_id, '');
936 936
         
937
-        if ( !empty( $gd_package ) ) {
937
+        if (!empty($gd_package)) {
938 938
             $return = false;
939 939
         }
940 940
     }
941 941
 
942 942
     return $return;
943 943
 }
944
-add_filter( 'wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2 );
944
+add_filter('wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2);
945 945
 
946
-function wpinv_package_item_classes( $classes, $class, $post_id ) {
946
+function wpinv_package_item_classes($classes, $class, $post_id) {
947 947
     global $typenow;
948 948
 
949
-    if ( $typenow == 'wpi_item' && in_array( 'wpi-gd-package', $classes ) ) {
950
-        if ( wpinv_item_in_use( $post_id ) ) {
949
+    if ($typenow == 'wpi_item' && in_array('wpi-gd-package', $classes)) {
950
+        if (wpinv_item_in_use($post_id)) {
951 951
             $classes[] = 'wpi-inuse-pkg';
952
-        } 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 ), '' ) ) ) {
952
+        } 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), ''))) {
953 953
             $classes[] = 'wpi-delete-pkg';
954 954
         }
955 955
     }
956 956
 
957 957
     return $classes;
958 958
 }
959
-add_filter( 'post_class', 'wpinv_package_item_classes', 10, 3 );
959
+add_filter('post_class', 'wpinv_package_item_classes', 10, 3);
960 960
 
961
-function wpinv_gdp_package_type_info( $post ) {
962
-    if ( wpinv_pm_active() ) {
963
-        ?><p class="wpi-m0"><?php _e( 'Package: GeoDirectory price packages items.', 'invoicing' );?></p>
961
+function wpinv_gdp_package_type_info($post) {
962
+    if (wpinv_pm_active()) {
963
+        ?><p class="wpi-m0"><?php _e('Package: GeoDirectory price packages items.', 'invoicing'); ?></p>
964 964
         <?php
965 965
     }
966 966
 }
967
-add_action( 'wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1 ) ;
967
+add_action('wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1);
968 968
 
969
-function wpinv_gdp_to_gdi_set_zero_tax( $is_taxable, $item_id, $country , $state ) {
969
+function wpinv_gdp_to_gdi_set_zero_tax($is_taxable, $item_id, $country, $state) {
970 970
     global $wpi_zero_tax;
971 971
 
972
-    if ( $wpi_zero_tax ) {
972
+    if ($wpi_zero_tax) {
973 973
         $is_taxable = false;
974 974
     }
975 975
 
976 976
     return $is_taxable;
977 977
 }
978
-add_action( 'wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4 ) ;
978
+add_action('wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4);
979 979
 
980 980
 function wpinv_tool_merge_fix_taxes() {
981 981
     global $wpdb;
982 982
     
983 983
 	$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'";
984
-	$items = $wpdb->get_results( $sql );
984
+	$items = $wpdb->get_results($sql);
985 985
 	
986
-	if ( !empty( $items ) ) {
987
-		foreach ( $items as $item ) {
988
-			if ( get_post_meta( $item->ID, '_wpinv_vat_class', true ) == '_exempt' ) {
989
-				update_post_meta( $item->ID, '_wpinv_vat_class', '_standard' );
986
+	if (!empty($items)) {
987
+		foreach ($items as $item) {
988
+			if (get_post_meta($item->ID, '_wpinv_vat_class', true) == '_exempt') {
989
+				update_post_meta($item->ID, '_wpinv_vat_class', '_standard');
990 990
 			}
991 991
 		}
992 992
 	}
993 993
 		
994 994
     $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', 'wpi-processing', 'wpi-renewal' ) ORDER BY `gdi`.`id` ASC";
995
-    $items = $wpdb->get_results( $sql );
995
+    $items = $wpdb->get_results($sql);
996 996
 	
997
-	if ( !empty( $items ) ) {
997
+	if (!empty($items)) {
998 998
 		$success = false;
999
-        $message = __( 'Taxes fixed for non-paid merged GD invoices.', 'invoicing' );
999
+        $message = __('Taxes fixed for non-paid merged GD invoices.', 'invoicing');
1000 1000
 		
1001 1001
 		global $wpi_userID, $wpinv_ip_address_country, $wpi_tax_rates;
1002 1002
 		
1003
-		foreach ( $items as $item ) {
1003
+		foreach ($items as $item) {
1004 1004
 			$wpi_tax_rates = NULL;               
1005 1005
 			$data = wpinv_get_invoice($item->ID);
1006 1006
 
1007
-			if ( empty( $data ) ) {
1007
+			if (empty($data)) {
1008 1008
 				continue;
1009 1009
 			}
1010 1010
 			
@@ -1012,51 +1012,51 @@  discard block
 block discarded – undo
1012 1012
 			
1013 1013
 			$data_session                   = array();
1014 1014
 			$data_session['invoice_id']     = $data->ID;
1015
-			$data_session['cart_discounts'] = $data->get_discounts( true );
1015
+			$data_session['cart_discounts'] = $data->get_discounts(true);
1016 1016
 			
1017
-			wpinv_set_checkout_session( $data_session );
1017
+			wpinv_set_checkout_session($data_session);
1018 1018
 			
1019 1019
 			$wpi_userID         = (int)$data->get_user_id();
1020 1020
 			$_POST['country']   = !empty($data->country) ? $data->country : wpinv_get_default_country();
1021 1021
 				
1022
-			$data->country      = sanitize_text_field( $_POST['country'] );
1023
-			$data->set( 'country', sanitize_text_field( $_POST['country'] ) );
1022
+			$data->country      = sanitize_text_field($_POST['country']);
1023
+			$data->set('country', sanitize_text_field($_POST['country']));
1024 1024
 			
1025 1025
 			$wpinv_ip_address_country = $data->country;
1026 1026
 			
1027 1027
 			$data->recalculate_totals(true);
1028 1028
 			
1029
-			wpinv_set_checkout_session( $checkout_session );
1029
+			wpinv_set_checkout_session($checkout_session);
1030 1030
 			
1031 1031
 			$update_data = array();
1032 1032
 			$update_data['tax_amount'] = $data->get_tax();
1033 1033
 			$update_data['paied_amount'] = $data->get_total();
1034 1034
 			$update_data['invoice_id'] = $data->ID;
1035 1035
 			
1036
-			$wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $item->gdp_id ) );
1036
+			$wpdb->update(INVOICE_TABLE, $update_data, array('id' => $item->gdp_id));
1037 1037
 		}
1038 1038
 	} else {
1039 1039
         $success = false;
1040
-        $message = __( 'No invoices found to fix taxes!', 'invoicing' );
1040
+        $message = __('No invoices found to fix taxes!', 'invoicing');
1041 1041
     }
1042 1042
 	
1043 1043
 	$response = array();
1044 1044
     $response['success'] = $success;
1045 1045
     $response['data']['message'] = $message;
1046
-    wp_send_json( $response );
1046
+    wp_send_json($response);
1047 1047
 }
1048
-add_action( 'wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes' );
1049
-remove_action( 'geodir_before_detail_fields' , 'geodir_build_coupon', 2 );
1048
+add_action('wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes');
1049
+remove_action('geodir_before_detail_fields', 'geodir_build_coupon', 2);
1050 1050
 
1051
-function wpinv_wpi_to_gdp_handle_subscription_cancel( $invoice_id, $invoice ) {
1052
-    if ( wpinv_pm_active() && !empty( $invoice ) && $invoice->is_recurring() ) {
1053
-        if ( $invoice->is_renewal() ) {
1051
+function wpinv_wpi_to_gdp_handle_subscription_cancel($invoice_id, $invoice) {
1052
+    if (wpinv_pm_active() && !empty($invoice) && $invoice->is_recurring()) {
1053
+        if ($invoice->is_renewal()) {
1054 1054
             $invoice = $invoice->get_parent_payment();
1055 1055
         }
1056 1056
         
1057
-        if ( !empty( $invoice ) ) {
1058
-            wpinv_wpi_to_gdp_update_status( $invoice->ID, 'wpi-cancelled', $invoice->get_status() );
1057
+        if (!empty($invoice)) {
1058
+            wpinv_wpi_to_gdp_update_status($invoice->ID, 'wpi-cancelled', $invoice->get_status());
1059 1059
         }
1060 1060
     }
1061 1061
 }
1062
-add_action( 'wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2 );
1063 1062
\ No newline at end of file
1063
+add_action('wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2);
1064 1064
\ No newline at end of file
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   +472 added lines, -472 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_round_amount( $tax );
503
+        if (wpinv_prices_include_tax()) {
504
+            $subtotal -= wpinv_round_amount($tax);
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_round_amount( $item_price ),
516
+            'name'              => !empty($item['name']) ? $item['name'] : get_the_title($item_id),
517
+            'item_price'        => wpinv_round_amount($item_price),
518 518
             'quantity'          => $quantity,
519
-            'discount'          => wpinv_round_amount( $discount ),
520
-            'subtotal'          => wpinv_round_amount( $subtotal ),
521
-            'tax'               => wpinv_round_amount( $tax ),
522
-            'price'             => wpinv_round_amount( $total ),
519
+            'discount'          => wpinv_round_amount($discount),
520
+            'subtotal'          => wpinv_round_amount($subtotal),
521
+            'tax'               => wpinv_round_amount($tax),
522
+            'price'             => wpinv_round_amount($total),
523 523
             'vat_rates_class'   => $tax_class,
524
-            'vat_rate'          => wpinv_round_amount( $tax_rate ),
525
-            'meta'              => isset( $item['meta'] ) ? $item['meta'] : array(),
524
+            'vat_rate'          => wpinv_round_amount($tax_rate),
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,60 +535,60 @@  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
-    if('wpi_invoice' != get_post_type($invoice_id)){
559
+function wpinv_record_status_change($invoice_id, $new_status, $old_status) {
560
+    if ('wpi_invoice' != get_post_type($invoice_id)) {
561 561
         return;
562 562
     }
563 563
 
564
-    $invoice    = wpinv_get_invoice( $invoice_id );
564
+    $invoice    = wpinv_get_invoice($invoice_id);
565 565
     
566
-    $old_status = wpinv_status_nicename( $old_status );
567
-    $new_status = wpinv_status_nicename( $new_status );
566
+    $old_status = wpinv_status_nicename($old_status);
567
+    $new_status = wpinv_status_nicename($new_status);
568 568
 
569
-    $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status );
569
+    $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status);
570 570
     
571 571
     // Add note
572
-    return $invoice->add_note( $status_change, false, false, true );
572
+    return $invoice->add_note($status_change, false, false, true);
573 573
 }
574
-add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 );
574
+add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3);
575 575
 
576
-function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) {
576
+function wpinv_complete_payment($invoice_id, $new_status, $old_status) {
577 577
     global $wpi_has_free_trial;
578 578
     
579 579
     $wpi_has_free_trial = false;
580 580
     
581
-    if ( $old_status == 'publish' ) {
581
+    if ($old_status == 'publish') {
582 582
         return; // Make sure that payments are only paid once
583 583
     }
584 584
 
585 585
     // Make sure the payment completion is only processed when new status is paid
586
-    if ( $new_status != 'publish' ) {
586
+    if ($new_status != 'publish') {
587 587
         return;
588 588
     }
589 589
 
590
-    $invoice = new WPInv_Invoice( $invoice_id );
591
-    if ( empty( $invoice ) ) {
590
+    $invoice = new WPInv_Invoice($invoice_id);
591
+    if (empty($invoice)) {
592 592
         return;
593 593
     }
594 594
 
@@ -596,58 +596,58 @@  discard block
 block discarded – undo
596 596
     $completed_date = $invoice->completed_date;
597 597
     $cart_details   = $invoice->cart_details;
598 598
 
599
-    do_action( 'wpinv_pre_complete_payment', $invoice_id );
599
+    do_action('wpinv_pre_complete_payment', $invoice_id);
600 600
 
601
-    if ( is_array( $cart_details ) ) {
601
+    if (is_array($cart_details)) {
602 602
         // Increase purchase count and earnings
603
-        foreach ( $cart_details as $cart_index => $item ) {
603
+        foreach ($cart_details as $cart_index => $item) {
604 604
             // Ensure these actions only run once, ever
605
-            if ( empty( $completed_date ) ) {
606
-                do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index );
605
+            if (empty($completed_date)) {
606
+                do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index);
607 607
             }
608 608
         }
609 609
     }
610 610
     
611 611
     // Check for discount codes and increment their use counts
612
-    if ( $discounts = $invoice->get_discounts( true ) ) {
613
-        if( ! empty( $discounts ) ) {
614
-            foreach( $discounts as $code ) {
615
-                wpinv_increase_discount_usage( $code );
612
+    if ($discounts = $invoice->get_discounts(true)) {
613
+        if (!empty($discounts)) {
614
+            foreach ($discounts as $code) {
615
+                wpinv_increase_discount_usage($code);
616 616
             }
617 617
         }
618 618
     }
619 619
     
620 620
     // Ensure this action only runs once ever
621
-    if( empty( $completed_date ) ) {
621
+    if (empty($completed_date)) {
622 622
         // Save the completed date
623
-        $invoice->set( 'completed_date', current_time( 'mysql', 0 ) );
623
+        $invoice->set('completed_date', current_time('mysql', 0));
624 624
         $invoice->save();
625 625
 
626
-        do_action( 'wpinv_complete_payment', $invoice_id );
626
+        do_action('wpinv_complete_payment', $invoice_id);
627 627
     }
628 628
 
629 629
     // Empty the shopping cart
630 630
     wpinv_empty_cart();
631 631
 }
632
-add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 );
632
+add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3);
633 633
 
634
-function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) {    
635
-    $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id );
634
+function wpinv_update_payment_status($invoice_id, $new_status = 'publish') {    
635
+    $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int)$invoice_id);
636 636
     
637
-    if ( empty( $invoice ) ) {
637
+    if (empty($invoice)) {
638 638
         return false;
639 639
     }
640 640
     
641
-    return $invoice->update_status( $new_status );
641
+    return $invoice->update_status($new_status);
642 642
 }
643 643
 
644
-function wpinv_cart_has_fees( $type = 'all' ) {
644
+function wpinv_cart_has_fees($type = 'all') {
645 645
     return false;
646 646
 }
647 647
 
648 648
 function wpinv_validate_checkout_fields() {    
649 649
     // Check if there is $_POST
650
-    if ( empty( $_POST ) ) {
650
+    if (empty($_POST)) {
651 651
         return false;
652 652
     }
653 653
     
@@ -659,11 +659,11 @@  discard block
 block discarded – undo
659 659
     );
660 660
     
661 661
     // Validate agree to terms
662
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
662
+    if (wpinv_get_option('show_agree_to_terms', false)) {
663 663
         wpinv_checkout_validate_agree_to_terms();
664 664
     }
665 665
     
666
-    $valid_data['logged_in_user']   = wpinv_checkout_validate_logged_in_user();
666
+    $valid_data['logged_in_user'] = wpinv_checkout_validate_logged_in_user();
667 667
     
668 668
     // Return collected data
669 669
     return $valid_data;
@@ -674,26 +674,26 @@  discard block
 block discarded – undo
674 674
     
675 675
     $invoice = wpinv_get_invoice_cart();
676 676
     $has_subscription = $invoice->is_recurring();
677
-    if ( empty( $invoice ) ) {
678
-        wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) );
677
+    if (empty($invoice)) {
678
+        wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing'));
679 679
         return $gateway;
680 680
     }
681 681
 
682 682
     // Check if a gateway value is present
683
-    if ( !empty( $_REQUEST['wpi-gateway'] ) ) {
684
-        $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] );
683
+    if (!empty($_REQUEST['wpi-gateway'])) {
684
+        $gateway = sanitize_text_field($_REQUEST['wpi-gateway']);
685 685
 
686
-        if ( $invoice->is_free() ) {
686
+        if ($invoice->is_free()) {
687 687
             $gateway = 'manual';
688
-        } elseif ( !wpinv_is_gateway_active( $gateway ) ) {
689
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) );
690
-        } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) {
691
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway doesnot support subscription payment', 'invoicing' ) );
688
+        } elseif (!wpinv_is_gateway_active($gateway)) {
689
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing'));
690
+        } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) {
691
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway doesnot support subscription payment', 'invoicing'));
692 692
         }
693 693
     }
694 694
 
695
-    if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) {
696
-        wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) );
695
+    if ($has_subscription && count(wpinv_get_cart_contents()) > 1) {
696
+        wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing'));
697 697
     }
698 698
 
699 699
     return $gateway;
@@ -705,10 +705,10 @@  discard block
 block discarded – undo
705 705
     
706 706
     $error = false;
707 707
     // If we have discounts, loop through them
708
-    if ( ! empty( $discounts ) ) {
709
-        foreach ( $discounts as $discount ) {
708
+    if (!empty($discounts)) {
709
+        foreach ($discounts as $discount) {
710 710
             // Check if valid
711
-            if (  !wpinv_is_discount_valid( $discount, get_current_user_id() ) ) {
711
+            if (!wpinv_is_discount_valid($discount, get_current_user_id())) {
712 712
                 // Discount is not valid
713 713
                 $error = true;
714 714
             }
@@ -718,20 +718,20 @@  discard block
 block discarded – undo
718 718
         return NULL;
719 719
     }
720 720
 
721
-    if ( $error && !wpinv_get_errors() ) {
722
-        wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) );
721
+    if ($error && !wpinv_get_errors()) {
722
+        wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing'));
723 723
     }
724 724
 
725
-    return implode( ',', $discounts );
725
+    return implode(',', $discounts);
726 726
 }
727 727
 
728 728
 function wpinv_checkout_validate_cc() {
729 729
     $card_data = wpinv_checkout_get_cc_info();
730 730
 
731 731
     // Validate the card zip
732
-    if ( !empty( $card_data['wpinv_zip'] ) ) {
733
-        if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) {
734
-            wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) );
732
+    if (!empty($card_data['wpinv_zip'])) {
733
+        if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) {
734
+            wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing'));
735 735
         }
736 736
     }
737 737
 
@@ -741,28 +741,28 @@  discard block
 block discarded – undo
741 741
 
742 742
 function wpinv_checkout_get_cc_info() {
743 743
 	$cc_info = array();
744
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
745
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
746
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
747
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
748
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
749
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
750
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
751
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
752
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
753
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
744
+	$cc_info['card_name']      = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : '';
745
+	$cc_info['card_number']    = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : '';
746
+	$cc_info['card_cvc']       = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : '';
747
+	$cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : '';
748
+	$cc_info['card_exp_year']  = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : '';
749
+	$cc_info['card_address']   = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : '';
750
+	$cc_info['card_city']      = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : '';
751
+	$cc_info['card_state']     = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : '';
752
+	$cc_info['card_country']   = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : '';
753
+	$cc_info['card_zip']       = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : '';
754 754
 
755 755
 	// Return cc info
756 756
 	return $cc_info;
757 757
 }
758 758
 
759
-function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
759
+function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') {
760 760
     $ret = false;
761 761
 
762
-    if ( empty( $zip ) || empty( $country_code ) )
762
+    if (empty($zip) || empty($country_code))
763 763
         return $ret;
764 764
 
765
-    $country_code = strtoupper( $country_code );
765
+    $country_code = strtoupper($country_code);
766 766
 
767 767
     $zip_regex = array(
768 768
         "AD" => "AD\d{3}",
@@ -922,17 +922,17 @@  discard block
 block discarded – undo
922 922
         "ZM" => "\d{5}"
923 923
     );
924 924
 
925
-    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) )
925
+    if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip))
926 926
         $ret = true;
927 927
 
928
-    return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code );
928
+    return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code);
929 929
 }
930 930
 
931 931
 function wpinv_checkout_validate_agree_to_terms() {
932 932
     // Validate agree to terms
933
-    if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) {
933
+    if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) {
934 934
         // User did not agree
935
-        wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) );
935
+        wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing')));
936 936
     }
937 937
 }
938 938
 
@@ -945,36 +945,36 @@  discard block
 block discarded – undo
945 945
     );
946 946
     
947 947
     // Verify there is a user_ID
948
-    if ( $user_ID > 0 ) {
948
+    if ($user_ID > 0) {
949 949
         // Get the logged in user data
950
-        $user_data = get_userdata( $user_ID );
951
-        $required_fields  = wpinv_checkout_required_fields();
950
+        $user_data = get_userdata($user_ID);
951
+        $required_fields = wpinv_checkout_required_fields();
952 952
 
953 953
         // Loop through required fields and show error messages
954
-         if ( !empty( $required_fields ) ) {
955
-            foreach ( $required_fields as $field_name => $value ) {
956
-                if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
957
-                    wpinv_set_error( $value['error_id'], $value['error_message'] );
954
+         if (!empty($required_fields)) {
955
+            foreach ($required_fields as $field_name => $value) {
956
+                if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) {
957
+                    wpinv_set_error($value['error_id'], $value['error_message']);
958 958
                 }
959 959
             }
960 960
         }
961 961
 
962 962
         // Verify data
963
-        if ( $user_data ) {
963
+        if ($user_data) {
964 964
             // Collected logged in user data
965 965
             $valid_user_data = array(
966 966
                 'user_id'     => $user_ID,
967
-                'email'       => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email,
968
-                'first_name'  => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name,
969
-                'last_name'   => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name']  ) ? sanitize_text_field( $_POST['wpinv_last_name']  ) : $user_data->last_name,
967
+                'email'       => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email,
968
+                'first_name'  => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name,
969
+                'last_name'   => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name,
970 970
             );
971 971
 
972
-            if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) {
973
-                wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) );
972
+            if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) {
973
+                wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing'));
974 974
             }
975 975
         } else {
976 976
             // Set invalid user error
977
-            wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) );
977
+            wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing'));
978 978
         }
979 979
     }
980 980
 
@@ -982,21 +982,21 @@  discard block
 block discarded – undo
982 982
     return $valid_user_data;
983 983
 }
984 984
 
985
-function wpinv_checkout_form_get_user( $valid_data = array() ) {
985
+function wpinv_checkout_form_get_user($valid_data = array()) {
986 986
     // Initialize user
987 987
     $user    = false;
988
-    $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
988
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
989 989
 
990 990
     /*if ( $is_ajax ) {
991 991
         // Do not create or login the user during the ajax submission (check for errors only)
992 992
         return true;
993
-    } else */if ( is_user_logged_in() ) {
993
+    } else */if (is_user_logged_in()) {
994 994
         // Set the valid user as the logged in collected data
995 995
         $user = $valid_data['logged_in_user'];
996 996
     }
997 997
 
998 998
     // Verify we have an user
999
-    if ( false === $user || empty( $user ) ) {
999
+    if (false === $user || empty($user)) {
1000 1000
         // Return false
1001 1001
         return false;
1002 1002
     }
@@ -1015,11 +1015,11 @@  discard block
 block discarded – undo
1015 1015
         'zip',
1016 1016
     );
1017 1017
     
1018
-    foreach ( $address_fields as $field ) {
1019
-        $user[$field]  = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false;
1018
+    foreach ($address_fields as $field) {
1019
+        $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false;
1020 1020
         
1021
-        if ( !empty( $user['user_id'] ) ) {
1022
-            update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] );
1021
+        if (!empty($user['user_id'])) {
1022
+            update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]);
1023 1023
         }
1024 1024
     }
1025 1025
 
@@ -1027,28 +1027,28 @@  discard block
 block discarded – undo
1027 1027
     return $user;
1028 1028
 }
1029 1029
 
1030
-function wpinv_set_checkout_session( $invoice_data = array() ) {
1030
+function wpinv_set_checkout_session($invoice_data = array()) {
1031 1031
     global $wpi_session;
1032 1032
     
1033
-    return $wpi_session->set( 'wpinv_checkout', $invoice_data );
1033
+    return $wpi_session->set('wpinv_checkout', $invoice_data);
1034 1034
 }
1035 1035
 
1036 1036
 function wpinv_get_checkout_session() {
1037 1037
 	global $wpi_session;
1038 1038
     
1039
-    return $wpi_session->get( 'wpinv_checkout' );
1039
+    return $wpi_session->get('wpinv_checkout');
1040 1040
 }
1041 1041
 
1042 1042
 function wpinv_empty_cart() {
1043 1043
     global $wpi_session;
1044 1044
 
1045 1045
     // Remove cart contents
1046
-    $wpi_session->set( 'wpinv_checkout', NULL );
1046
+    $wpi_session->set('wpinv_checkout', NULL);
1047 1047
 
1048 1048
     // Remove all cart fees
1049
-    $wpi_session->set( 'wpi_cart_fees', NULL );
1049
+    $wpi_session->set('wpi_cart_fees', NULL);
1050 1050
 
1051
-    do_action( 'wpinv_empty_cart' );
1051
+    do_action('wpinv_empty_cart');
1052 1052
 }
1053 1053
 
1054 1054
 function wpinv_process_checkout() {
@@ -1060,42 +1060,42 @@  discard block
 block discarded – undo
1060 1060
     
1061 1061
     $wpi_checkout_id = $invoice->ID;
1062 1062
     
1063
-    do_action( 'wpinv_pre_process_checkout' );
1063
+    do_action('wpinv_pre_process_checkout');
1064 1064
     
1065
-    if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty
1065
+    if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty
1066 1066
         $valid_data = false;
1067
-        wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) );
1067
+        wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing'));
1068 1068
     } else {
1069 1069
         // Validate the form $_POST data
1070 1070
         $valid_data = wpinv_validate_checkout_fields();
1071 1071
         
1072 1072
         // Allow themes and plugins to hook to errors
1073
-        do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST );
1073
+        do_action('wpinv_checkout_error_checks', $valid_data, $_POST);
1074 1074
     }
1075 1075
     
1076
-    $is_ajax    = defined( 'DOING_AJAX' ) && DOING_AJAX;
1076
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1077 1077
     
1078 1078
     // Validate the user
1079
-    $user = wpinv_checkout_form_get_user( $valid_data );
1079
+    $user = wpinv_checkout_form_get_user($valid_data);
1080 1080
 
1081 1081
     // Let extensions validate fields after user is logged in if user has used login/registration form
1082
-    do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST );
1082
+    do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST);
1083 1083
     
1084
-    if ( false === $valid_data || wpinv_get_errors() || ! $user ) {
1085
-        if ( $is_ajax ) {
1086
-            do_action( 'wpinv_ajax_checkout_errors' );
1084
+    if (false === $valid_data || wpinv_get_errors() || !$user) {
1085
+        if ($is_ajax) {
1086
+            do_action('wpinv_ajax_checkout_errors');
1087 1087
             die();
1088 1088
         } else {
1089 1089
             return false;
1090 1090
         }
1091 1091
     }
1092 1092
 
1093
-    if ( $is_ajax ) {
1093
+    if ($is_ajax) {
1094 1094
         // Save address fields.
1095
-        $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' );
1096
-        foreach ( $address_fields as $field ) {
1097
-            if ( isset( $user[$field] ) ) {
1098
-                $invoice->set( $field, $user[$field] );
1095
+        $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company');
1096
+        foreach ($address_fields as $field) {
1097
+            if (isset($user[$field])) {
1098
+                $invoice->set($field, $user[$field]);
1099 1099
             }
1100 1100
             
1101 1101
             $invoice->save();
@@ -1103,15 +1103,15 @@  discard block
 block discarded – undo
1103 1103
 
1104 1104
         $response['success']            = true;
1105 1105
         $response['data']['subtotal']   = $invoice->get_subtotal();
1106
-        $response['data']['subtotalf']  = $invoice->get_subtotal( true );
1106
+        $response['data']['subtotalf']  = $invoice->get_subtotal(true);
1107 1107
         $response['data']['discount']   = $invoice->get_discount();
1108
-        $response['data']['discountf']  = $invoice->get_discount( true );
1108
+        $response['data']['discountf']  = $invoice->get_discount(true);
1109 1109
         $response['data']['tax']        = $invoice->get_tax();
1110
-        $response['data']['taxf']       = $invoice->get_tax( true );
1110
+        $response['data']['taxf']       = $invoice->get_tax(true);
1111 1111
         $response['data']['total']      = $invoice->get_total();
1112
-        $response['data']['totalf']     = $invoice->get_total( true );
1112
+        $response['data']['totalf']     = $invoice->get_total(true);
1113 1113
         
1114
-        wp_send_json( $response );
1114
+        wp_send_json($response);
1115 1115
     }
1116 1116
     
1117 1117
     $user_info = array(
@@ -1133,42 +1133,42 @@  discard block
 block discarded – undo
1133 1133
     
1134 1134
     // Setup invoice information
1135 1135
     $invoice_data = array(
1136
-        'invoice_id'        => !empty( $invoice ) ? $invoice->ID : 0,
1136
+        'invoice_id'        => !empty($invoice) ? $invoice->ID : 0,
1137 1137
         'items'             => $cart_items,
1138 1138
         'cart_discounts'    => $discounts,
1139
-        'fees'              => wpinv_get_cart_fees(),        // Any arbitrary fees that have been added to the cart
1140
-        'subtotal'          => wpinv_get_cart_subtotal( $cart_items ),    // Amount before taxes and discounts
1141
-        'discount'          => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount
1142
-        'tax'               => wpinv_get_cart_tax( $cart_items ),               // Taxed amount
1143
-        'price'             => wpinv_get_cart_total( $cart_items, $discounts ),    // Amount after taxes
1139
+        'fees'              => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart
1140
+        'subtotal'          => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts
1141
+        'discount'          => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount
1142
+        'tax'               => wpinv_get_cart_tax($cart_items), // Taxed amount
1143
+        'price'             => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes
1144 1144
         'invoice_key'       => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(),
1145 1145
         'user_email'        => $user['email'],
1146
-        'date'              => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
1147
-        'user_info'         => stripslashes_deep( $user_info ),
1146
+        'date'              => date('Y-m-d H:i:s', current_time('timestamp')),
1147
+        'user_info'         => stripslashes_deep($user_info),
1148 1148
         'post_data'         => $_POST,
1149 1149
         'cart_details'      => $cart_items,
1150 1150
         'gateway'           => $valid_data['gateway'],
1151 1151
         'card_info'         => $valid_data['cc_info']
1152 1152
     );
1153 1153
     
1154
-    $vat_info   = $wpinv_euvat->current_vat_data();
1155
-    if ( is_array( $vat_info ) ) {
1154
+    $vat_info = $wpinv_euvat->current_vat_data();
1155
+    if (is_array($vat_info)) {
1156 1156
         $invoice_data['user_info']['vat_number']        = $vat_info['number'];
1157 1157
         $invoice_data['user_info']['vat_rate']          = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']);
1158
-        $invoice_data['user_info']['adddress_confirmed']    = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1158
+        $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1159 1159
 
1160 1160
         // Add the VAT rate to each item in the cart
1161
-        foreach( $invoice_data['cart_details'] as $key => $item_data) {
1161
+        foreach ($invoice_data['cart_details'] as $key => $item_data) {
1162 1162
             $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']);
1163
-            $invoice_data['cart_details'][$key]['vat_rate'] = round( $rate, 3 );
1163
+            $invoice_data['cart_details'][$key]['vat_rate'] = round($rate, 3);
1164 1164
         }
1165 1165
     }
1166 1166
     
1167 1167
     // Save vat fields.
1168
-    $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' );
1169
-    foreach ( $address_fields as $field ) {
1170
-        if ( isset( $invoice_data['user_info'][$field] ) ) {
1171
-            $invoice->set( $field, $invoice_data['user_info'][$field] );
1168
+    $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed');
1169
+    foreach ($address_fields as $field) {
1170
+        if (isset($invoice_data['user_info'][$field])) {
1171
+            $invoice->set($field, $invoice_data['user_info'][$field]);
1172 1172
         }
1173 1173
         
1174 1174
         $invoice->save();
@@ -1178,49 +1178,49 @@  discard block
 block discarded – undo
1178 1178
     $valid_data['user'] = $user;
1179 1179
     
1180 1180
     // Allow themes and plugins to hook before the gateway
1181
-    do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data );
1181
+    do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data);
1182 1182
     
1183 1183
     // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice
1184
-    if ( !$invoice_data['price'] ) {
1184
+    if (!$invoice_data['price']) {
1185 1185
         // Revert to manual
1186 1186
         $invoice_data['gateway'] = 'manual';
1187 1187
         $_POST['wpi-gateway'] = 'manual';
1188 1188
     }
1189 1189
     
1190 1190
     // Allow the invoice data to be modified before it is sent to the gateway
1191
-    $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data );
1191
+    $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data);
1192 1192
     
1193 1193
     // Setup the data we're storing in the purchase session
1194 1194
     $session_data = $invoice_data;
1195 1195
     // Make sure credit card numbers are never stored in sessions
1196
-    if ( !empty( $session_data['card_info']['card_number'] ) ) {
1197
-        unset( $session_data['card_info']['card_number'] );
1196
+    if (!empty($session_data['card_info']['card_number'])) {
1197
+        unset($session_data['card_info']['card_number']);
1198 1198
     }
1199 1199
     
1200 1200
     // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data.
1201
-    wpinv_set_checkout_session( $invoice_data );
1201
+    wpinv_set_checkout_session($invoice_data);
1202 1202
     
1203 1203
     // Set gateway
1204
-    $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] );
1205
-    $invoice->update_meta( '_wpinv_mode', ( wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live' ) );
1206
-    $invoice->update_meta( '_wpinv_checkout', true );
1204
+    $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']);
1205
+    $invoice->update_meta('_wpinv_mode', (wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live'));
1206
+    $invoice->update_meta('_wpinv_checkout', true);
1207 1207
     
1208
-    do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data );
1208
+    do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data);
1209 1209
 
1210 1210
     // Send info to the gateway for payment processing
1211
-    wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data );
1211
+    wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data);
1212 1212
     die();
1213 1213
 }
1214
-add_action( 'wpinv_payment', 'wpinv_process_checkout' );
1214
+add_action('wpinv_payment', 'wpinv_process_checkout');
1215 1215
 
1216
-function wpinv_get_invoices( $args ) {
1217
-    $args = wp_parse_args( $args, array(
1218
-        'status'   => array_keys( wpinv_get_invoice_statuses() ),
1216
+function wpinv_get_invoices($args) {
1217
+    $args = wp_parse_args($args, array(
1218
+        'status'   => array_keys(wpinv_get_invoice_statuses()),
1219 1219
         'type'     => 'wpi_invoice',
1220 1220
         'parent'   => null,
1221 1221
         'user'     => null,
1222 1222
         'email'    => '',
1223
-        'limit'    => get_option( 'posts_per_page' ),
1223
+        'limit'    => get_option('posts_per_page'),
1224 1224
         'offset'   => null,
1225 1225
         'page'     => 1,
1226 1226
         'exclude'  => array(),
@@ -1228,7 +1228,7 @@  discard block
 block discarded – undo
1228 1228
         'order'    => 'DESC',
1229 1229
         'return'   => 'objects',
1230 1230
         'paginate' => false,
1231
-    ) );
1231
+    ));
1232 1232
     
1233 1233
     // Handle some BW compatibility arg names where wp_query args differ in naming.
1234 1234
     $map_legacy = array(
@@ -1241,20 +1241,20 @@  discard block
 block discarded – undo
1241 1241
         'paged'          => 'page',
1242 1242
     );
1243 1243
 
1244
-    foreach ( $map_legacy as $from => $to ) {
1245
-        if ( isset( $args[ $from ] ) ) {
1246
-            $args[ $to ] = $args[ $from ];
1244
+    foreach ($map_legacy as $from => $to) {
1245
+        if (isset($args[$from])) {
1246
+            $args[$to] = $args[$from];
1247 1247
         }
1248 1248
     }
1249 1249
 
1250
-    $wpinv_cpt = $_REQUEST[ 'wpinv-cpt' ];
1250
+    $wpinv_cpt = $_REQUEST['wpinv-cpt'];
1251 1251
 
1252
-    if ( get_query_var( 'paged' ) && 'wpi_invoice' == $wpinv_cpt )
1252
+    if (get_query_var('paged') && 'wpi_invoice' == $wpinv_cpt)
1253 1253
         $args['page'] = get_query_var('paged');
1254
-    else if ( get_query_var( 'page' )  && 'wpi_invoice' == $wpinv_cpt )
1255
-        $args['page'] = get_query_var( 'page' );
1256
-    else if ( !empty( $args[ 'page' ] ) )
1257
-        $args['page'] = $args[ 'page' ];
1254
+    else if (get_query_var('page') && 'wpi_invoice' == $wpinv_cpt)
1255
+        $args['page'] = get_query_var('page');
1256
+    else if (!empty($args['page']))
1257
+        $args['page'] = $args['page'];
1258 1258
     else
1259 1259
         $args['page'] = 1;
1260 1260
 
@@ -1267,47 +1267,47 @@  discard block
 block discarded – undo
1267 1267
         'post_status'    => $args['status'],
1268 1268
         'posts_per_page' => $args['limit'],
1269 1269
         'meta_query'     => array(),
1270
-        'date_query'     => !empty( $args['date_query'] ) ? $args['date_query'] : array(),
1270
+        'date_query'     => !empty($args['date_query']) ? $args['date_query'] : array(),
1271 1271
         'fields'         => 'ids',
1272 1272
         'orderby'        => $args['orderby'],
1273 1273
         'order'          => $args['order'],
1274 1274
     );
1275 1275
     
1276
-    if ( !empty( $args['user'] ) ) {
1277
-        $wp_query_args['author'] = absint( $args['user'] );
1276
+    if (!empty($args['user'])) {
1277
+        $wp_query_args['author'] = absint($args['user']);
1278 1278
     }
1279 1279
 
1280
-    if ( ! is_null( $args['parent'] ) ) {
1281
-        $wp_query_args['post_parent'] = absint( $args['parent'] );
1280
+    if (!is_null($args['parent'])) {
1281
+        $wp_query_args['post_parent'] = absint($args['parent']);
1282 1282
     }
1283 1283
 
1284
-    if ( ! is_null( $args['offset'] ) ) {
1285
-        $wp_query_args['offset'] = absint( $args['offset'] );
1284
+    if (!is_null($args['offset'])) {
1285
+        $wp_query_args['offset'] = absint($args['offset']);
1286 1286
     } else {
1287
-        $wp_query_args['paged'] = absint( $args['page'] );
1287
+        $wp_query_args['paged'] = absint($args['page']);
1288 1288
     }
1289 1289
 
1290
-    if ( ! empty( $args['exclude'] ) ) {
1291
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
1290
+    if (!empty($args['exclude'])) {
1291
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
1292 1292
     }
1293 1293
 
1294
-    if ( ! $args['paginate' ] ) {
1294
+    if (!$args['paginate']) {
1295 1295
         $wp_query_args['no_found_rows'] = true;
1296 1296
     }
1297 1297
 
1298 1298
     // Get results.
1299
-    $invoices = new WP_Query( $wp_query_args );
1299
+    $invoices = new WP_Query($wp_query_args);
1300 1300
 
1301
-    if ( 'objects' === $args['return'] ) {
1302
-        $return = array_map( 'wpinv_get_invoice', $invoices->posts );
1303
-    } elseif ( 'self' === $args['return'] ) {
1301
+    if ('objects' === $args['return']) {
1302
+        $return = array_map('wpinv_get_invoice', $invoices->posts);
1303
+    } elseif ('self' === $args['return']) {
1304 1304
         return $invoices;
1305 1305
     } else {
1306 1306
         $return = $invoices->posts;
1307 1307
     }
1308 1308
 
1309
-    if ( $args['paginate' ] ) {
1310
-        return (object) array(
1309
+    if ($args['paginate']) {
1310
+        return (object)array(
1311 1311
             'invoices'      => $return,
1312 1312
             'total'         => $invoices->found_posts,
1313 1313
             'max_num_pages' => $invoices->max_num_pages,
@@ -1319,21 +1319,21 @@  discard block
 block discarded – undo
1319 1319
 
1320 1320
 function wpinv_get_user_invoices_columns() {
1321 1321
     $columns = array(
1322
-            'invoice-number'  => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ),
1323
-            'invoice-date'    => array( 'title' => __( 'Date', 'invoicing' ), 'class' => 'text-left' ),
1324
-            'invoice-status'  => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ),
1325
-            'invoice-total'   => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ),
1326
-            'invoice-actions' => array( 'title' => '&nbsp;', 'class' => 'text-center' ),
1322
+            'invoice-number'  => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'),
1323
+            'invoice-date'    => array('title' => __('Date', 'invoicing'), 'class' => 'text-left'),
1324
+            'invoice-status'  => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'),
1325
+            'invoice-total'   => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'),
1326
+            'invoice-actions' => array('title' => '&nbsp;', 'class' => 'text-center'),
1327 1327
         );
1328 1328
 
1329
-    return apply_filters( 'wpinv_user_invoices_columns', $columns );
1329
+    return apply_filters('wpinv_user_invoices_columns', $columns);
1330 1330
 }
1331 1331
 
1332
-function wpinv_payment_receipt( $atts, $content = null ) {
1332
+function wpinv_payment_receipt($atts, $content = null) {
1333 1333
     global $wpinv_receipt_args;
1334 1334
 
1335
-    $wpinv_receipt_args = shortcode_atts( array(
1336
-        'error'           => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ),
1335
+    $wpinv_receipt_args = shortcode_atts(array(
1336
+        'error'           => __('Sorry, trouble retrieving payment receipt.', 'invoicing'),
1337 1337
         'price'           => true,
1338 1338
         'discount'        => true,
1339 1339
         'items'           => true,
@@ -1342,185 +1342,185 @@  discard block
 block discarded – undo
1342 1342
         'invoice_key'     => false,
1343 1343
         'payment_method'  => true,
1344 1344
         'invoice_id'      => true
1345
-    ), $atts, 'wpinv_receipt' );
1345
+    ), $atts, 'wpinv_receipt');
1346 1346
 
1347 1347
     $session = wpinv_get_checkout_session();
1348
-    if ( isset( $_GET['invoice_key'] ) ) {
1349
-        $invoice_key = urldecode( $_GET['invoice_key'] );
1350
-    } else if ( $session && isset( $session['invoice_key'] ) ) {
1348
+    if (isset($_GET['invoice_key'])) {
1349
+        $invoice_key = urldecode($_GET['invoice_key']);
1350
+    } else if ($session && isset($session['invoice_key'])) {
1351 1351
         $invoice_key = $session['invoice_key'];
1352
-    } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) {
1352
+    } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) {
1353 1353
         $invoice_key = $wpinv_receipt_args['invoice_key'];
1354
-    } else if ( isset( $_GET['invoice-id'] ) ) {
1355
-        $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] );
1354
+    } else if (isset($_GET['invoice-id'])) {
1355
+        $invoice_key = wpinv_get_payment_key((int)$_GET['invoice-id']);
1356 1356
     }
1357 1357
 
1358 1358
     // No key found
1359
-    if ( ! isset( $invoice_key ) ) {
1359
+    if (!isset($invoice_key)) {
1360 1360
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1361 1361
     }
1362 1362
 
1363
-    $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1364
-    $user_can_view = wpinv_can_view_receipt( $invoice_key );
1365
-    if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1363
+    $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1364
+    $user_can_view = wpinv_can_view_receipt($invoice_key);
1365
+    if ($user_can_view && isset($_GET['invoice-id'])) {
1366 1366
         $invoice_id     = (int)$_GET['invoice-id'];
1367
-        $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1367
+        $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1368 1368
     }
1369 1369
 
1370 1370
     // Key was provided, but user is logged out. Offer them the ability to login and view the receipt
1371
-    if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) {
1371
+    if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) {
1372 1372
         // login redirect
1373
-        return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>';
1373
+        return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>';
1374 1374
     }
1375 1375
 
1376
-    if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) {
1376
+    if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) {
1377 1377
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1378 1378
     }
1379 1379
 
1380 1380
     ob_start();
1381 1381
 
1382
-    wpinv_get_template_part( 'wpinv-invoice-receipt' );
1382
+    wpinv_get_template_part('wpinv-invoice-receipt');
1383 1383
 
1384 1384
     $display = ob_get_clean();
1385 1385
 
1386 1386
     return $display;
1387 1387
 }
1388 1388
 
1389
-function wpinv_get_invoice_id_by_key( $key ) {
1389
+function wpinv_get_invoice_id_by_key($key) {
1390 1390
 	global $wpdb;
1391 1391
 
1392
-	$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 ) );
1392
+	$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));
1393 1393
 
1394
-	if ( $invoice_id != NULL )
1394
+	if ($invoice_id != NULL)
1395 1395
 		return $invoice_id;
1396 1396
 
1397 1397
 	return 0;
1398 1398
 }
1399 1399
 
1400
-function wpinv_can_view_receipt( $invoice_key = '' ) {
1400
+function wpinv_can_view_receipt($invoice_key = '') {
1401 1401
 	$return = false;
1402 1402
 
1403
-	if ( empty( $invoice_key ) ) {
1403
+	if (empty($invoice_key)) {
1404 1404
 		return $return;
1405 1405
 	}
1406 1406
 
1407 1407
 	global $wpinv_receipt_args;
1408 1408
 
1409
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1410
-	if ( isset( $_GET['invoice-id'] ) ) {
1411
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1409
+	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key);
1410
+	if (isset($_GET['invoice-id'])) {
1411
+		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? (int)$_GET['invoice-id'] : 0;
1412 1412
 	}
1413 1413
 
1414
-	$user_id = (int) wpinv_get_user_id( $wpinv_receipt_args['id'] );
1415
-    $invoice_meta = wpinv_get_invoice_meta( $wpinv_receipt_args['id'] );
1414
+	$user_id = (int)wpinv_get_user_id($wpinv_receipt_args['id']);
1415
+    $invoice_meta = wpinv_get_invoice_meta($wpinv_receipt_args['id']);
1416 1416
 
1417
-	if ( is_user_logged_in() ) {
1418
-		if ( $user_id === (int) get_current_user_id() ) {
1417
+	if (is_user_logged_in()) {
1418
+		if ($user_id === (int)get_current_user_id()) {
1419 1419
 			$return = true;
1420 1420
 		}
1421 1421
 	}
1422 1422
 
1423 1423
 	$session = wpinv_get_checkout_session();
1424
-	if ( ! empty( $session ) && ! is_user_logged_in() ) {
1425
-		if ( $session['invoice_key'] === $invoice_meta['key'] ) {
1424
+	if (!empty($session) && !is_user_logged_in()) {
1425
+		if ($session['invoice_key'] === $invoice_meta['key']) {
1426 1426
 			$return = true;
1427 1427
 		}
1428 1428
 	}
1429 1429
 
1430
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1430
+	return (bool)apply_filters('wpinv_can_view_receipt', $return, $invoice_key);
1431 1431
 }
1432 1432
 
1433 1433
 function wpinv_pay_for_invoice() {
1434 1434
     global $wpinv_euvat;
1435 1435
     
1436
-    if ( isset( $_GET['invoice_key'] ) ) {
1436
+    if (isset($_GET['invoice_key'])) {
1437 1437
         $checkout_uri   = wpinv_get_checkout_uri();
1438
-        $invoice_key    = sanitize_text_field( $_GET['invoice_key'] );
1438
+        $invoice_key    = sanitize_text_field($_GET['invoice_key']);
1439 1439
         
1440
-        if ( empty( $invoice_key ) ) {
1441
-            wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) );
1442
-            wp_redirect( $checkout_uri );
1440
+        if (empty($invoice_key)) {
1441
+            wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing'));
1442
+            wp_redirect($checkout_uri);
1443 1443
             wpinv_die();
1444 1444
         }
1445 1445
         
1446
-        do_action( 'wpinv_check_pay_for_invoice', $invoice_key );
1446
+        do_action('wpinv_check_pay_for_invoice', $invoice_key);
1447 1447
 
1448
-        $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1449
-        $user_can_view = wpinv_can_view_receipt( $invoice_key );
1450
-        if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1448
+        $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1449
+        $user_can_view = wpinv_can_view_receipt($invoice_key);
1450
+        if ($user_can_view && isset($_GET['invoice-id'])) {
1451 1451
             $invoice_id     = (int)$_GET['invoice-id'];
1452
-            $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1452
+            $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1453 1453
         }
1454 1454
         
1455
-        if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) {
1456
-            if ( $invoice->needs_payment() ) {
1455
+        if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) {
1456
+            if ($invoice->needs_payment()) {
1457 1457
                 $data                   = array();
1458 1458
                 $data['invoice_id']     = $invoice_id;
1459
-                $data['cart_discounts'] = $invoice->get_discounts( true );
1459
+                $data['cart_discounts'] = $invoice->get_discounts(true);
1460 1460
                 
1461
-                wpinv_set_checkout_session( $data );
1461
+                wpinv_set_checkout_session($data);
1462 1462
                 
1463
-                if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1463
+                if (wpinv_get_option('vat_ip_country_default')) {
1464 1464
                     $_POST['country']   = $wpinv_euvat->get_country_by_ip();
1465 1465
                     $_POST['state']     = $_POST['country'] == $invoice->country ? $invoice->state : '';
1466 1466
                     
1467
-                    wpinv_recalculate_tax( true );
1467
+                    wpinv_recalculate_tax(true);
1468 1468
                 }
1469 1469
                 
1470 1470
             } else {
1471 1471
                 $checkout_uri = $invoice->get_view_url();
1472 1472
             }
1473 1473
         } else {
1474
-            wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) );
1474
+            wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing'));
1475 1475
             
1476
-            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
1476
+            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
1477 1477
         }
1478 1478
         
1479
-        wp_redirect( $checkout_uri );
1479
+        wp_redirect($checkout_uri);
1480 1480
         wpinv_die();
1481 1481
     }
1482 1482
 }
1483
-add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' );
1483
+add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice');
1484 1484
 
1485
-function wpinv_handle_pay_via_invoice_link( $invoice_key ) {
1486
-    if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) {
1487
-        if ( $invoice = wpinv_get_invoice( $invoice_id ) ) {
1485
+function wpinv_handle_pay_via_invoice_link($invoice_key) {
1486
+    if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) {
1487
+        if ($invoice = wpinv_get_invoice($invoice_id)) {
1488 1488
             $user_id = $invoice->get_user_id();
1489
-            $secret = sanitize_text_field( $_GET['_wpipay'] );
1489
+            $secret = sanitize_text_field($_GET['_wpipay']);
1490 1490
             
1491
-            if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link
1492
-                $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
1491
+            if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link
1492
+                $redirect_to = remove_query_arg('_wpipay', get_permalink());
1493 1493
                 
1494
-                wpinv_guest_redirect( $redirect_to, $user_id );
1494
+                wpinv_guest_redirect($redirect_to, $user_id);
1495 1495
                 wpinv_die();
1496 1496
             }
1497 1497
         }
1498 1498
     }
1499 1499
 }
1500
-add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' );
1500
+add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link');
1501 1501
 
1502
-function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) {
1503
-    $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id;
1502
+function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') {
1503
+    $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id;
1504 1504
     
1505
-    if ( empty( $invoice_id ) && $invoice_id > 0 ) {
1505
+    if (empty($invoice_id) && $invoice_id > 0) {
1506 1506
         return false;
1507 1507
     }
1508 1508
     
1509
-    if ( empty( $transaction_id ) ) {
1509
+    if (empty($transaction_id)) {
1510 1510
         $transaction_id = $invoice_id;
1511 1511
     }
1512 1512
 
1513
-    $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id );
1513
+    $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id);
1514 1514
     
1515
-    return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id );
1515
+    return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id);
1516 1516
 }
1517 1517
 
1518
-function wpinv_invoice_status_label( $status, $status_display = '' ) {
1519
-    if ( empty( $status_display ) ) {
1520
-        $status_display = wpinv_status_nicename( $status );
1518
+function wpinv_invoice_status_label($status, $status_display = '') {
1519
+    if (empty($status_display)) {
1520
+        $status_display = wpinv_status_nicename($status);
1521 1521
     }
1522 1522
     
1523
-    switch ( $status ) {
1523
+    switch ($status) {
1524 1524
         case 'publish' :
1525 1525
         case 'wpi-renewal' :
1526 1526
             $class = 'label-success';
@@ -1545,28 +1545,28 @@  discard block
 block discarded – undo
1545 1545
     
1546 1546
     $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>';
1547 1547
     
1548
-    return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display );
1548
+    return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display);
1549 1549
 }
1550 1550
 
1551
-function wpinv_format_invoice_number( $number ) {
1552
-    $padd  = wpinv_get_option( 'invoice_number_padd' );
1551
+function wpinv_format_invoice_number($number) {
1552
+    $padd = wpinv_get_option('invoice_number_padd');
1553 1553
     
1554 1554
     // TODO maintain old invoice numbers if invoice number settings not saved. Should be removed before stable release.
1555
-    if ( $padd === '' || $padd === false || $padd === NULL ) {
1556
-        return wp_sprintf( __( 'WPINV-%d', 'invoicing' ), $number );
1555
+    if ($padd === '' || $padd === false || $padd === NULL) {
1556
+        return wp_sprintf(__('WPINV-%d', 'invoicing'), $number);
1557 1557
     }
1558 1558
     
1559
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
1560
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
1559
+    $prefix  = wpinv_get_option('invoice_number_prefix');
1560
+    $postfix = wpinv_get_option('invoice_number_postfix');
1561 1561
     
1562
-    $padd = absint( $padd );
1563
-    $formatted_number = absint( $number );
1562
+    $padd = absint($padd);
1563
+    $formatted_number = absint($number);
1564 1564
     
1565
-    if ( $padd > 0 ) {
1566
-        $formatted_number = zeroise( $formatted_number, $padd );
1565
+    if ($padd > 0) {
1566
+        $formatted_number = zeroise($formatted_number, $padd);
1567 1567
     }    
1568 1568
 
1569 1569
     $formatted_number = $prefix . $formatted_number . $postfix;
1570 1570
 
1571
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
1571
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
1572 1572
 }
1573 1573
\ 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
 }
@@ -759,8 +760,9 @@  discard block
 block discarded – undo
759 760
 function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
760 761
     $ret = false;
761 762
 
762
-    if ( empty( $zip ) || empty( $country_code ) )
763
-        return $ret;
763
+    if ( empty( $zip ) || empty( $country_code ) ) {
764
+            return $ret;
765
+    }
764 766
 
765 767
     $country_code = strtoupper( $country_code );
766 768
 
@@ -922,8 +924,9 @@  discard block
 block discarded – undo
922 924
         "ZM" => "\d{5}"
923 925
     );
924 926
 
925
-    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) )
926
-        $ret = true;
927
+    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) {
928
+            $ret = true;
929
+    }
927 930
 
928 931
     return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code );
929 932
 }
@@ -1249,14 +1252,15 @@  discard block
 block discarded – undo
1249 1252
 
1250 1253
     $wpinv_cpt = $_REQUEST[ 'wpinv-cpt' ];
1251 1254
 
1252
-    if ( get_query_var( 'paged' ) && 'wpi_invoice' == $wpinv_cpt )
1253
-        $args['page'] = get_query_var('paged');
1254
-    else if ( get_query_var( 'page' )  && 'wpi_invoice' == $wpinv_cpt )
1255
-        $args['page'] = get_query_var( 'page' );
1256
-    else if ( !empty( $args[ 'page' ] ) )
1257
-        $args['page'] = $args[ 'page' ];
1258
-    else
1259
-        $args['page'] = 1;
1255
+    if ( get_query_var( 'paged' ) && 'wpi_invoice' == $wpinv_cpt ) {
1256
+            $args['page'] = get_query_var('paged');
1257
+    } else if ( get_query_var( 'page' )  && 'wpi_invoice' == $wpinv_cpt ) {
1258
+            $args['page'] = get_query_var( 'page' );
1259
+    } else if ( !empty( $args[ 'page' ] ) ) {
1260
+            $args['page'] = $args[ 'page' ];
1261
+    } else {
1262
+            $args['page'] = 1;
1263
+    }
1260 1264
 
1261 1265
     /**
1262 1266
      * Generate WP_Query args. This logic will change if orders are moved to
@@ -1391,8 +1395,9 @@  discard block
 block discarded – undo
1391 1395
 
1392 1396
 	$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 ) );
1393 1397
 
1394
-	if ( $invoice_id != NULL )
1395
-		return $invoice_id;
1398
+	if ( $invoice_id != NULL ) {
1399
+			return $invoice_id;
1400
+	}
1396 1401
 
1397 1402
 	return 0;
1398 1403
 }
Please login to merge, or discard this patch.
includes/wpinv-item-functions.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -529,6 +529,9 @@
 block discarded – undo
529 529
     return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item );
530 530
 }
531 531
 
532
+/**
533
+ * @return string
534
+ */
532 535
 function wpinv_get_cart_item_name( $item = array() ) {
533 536
     $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] );
534 537
 
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
 function wpinv_get_item_by( $field = '', $value = '', $type = '' ) {
6 8
     if( empty( $field ) || empty( $value ) ) {
@@ -118,8 +120,9 @@  discard block
 block discarded – undo
118 120
 function wpinv_get_item( $item = 0 ) {
119 121
     if ( is_numeric( $item ) ) {
120 122
         $item = get_post( $item );
121
-        if ( ! $item || 'wpi_item' !== $item->post_type )
122
-            return null;
123
+        if ( ! $item || 'wpi_item' !== $item->post_type ) {
124
+                    return null;
125
+        }
123 126
         return $item;
124 127
     }
125 128
 
@@ -283,8 +286,9 @@  discard block
 block discarded – undo
283 286
 }
284 287
 
285 288
 function wpinv_remove_item_logs_on_delete( $item_id = 0 ) {
286
-    if ( 'wpi_item' !== get_post_type( $item_id ) )
287
-        return;
289
+    if ( 'wpi_item' !== get_post_type( $item_id ) ) {
290
+            return;
291
+    }
288 292
 
289 293
     global $wpinv_logs;
290 294
     
Please login to merge, or discard this patch.
Spacing   +252 added lines, -252 removed lines patch added patch discarded remove patch
@@ -1,19 +1,19 @@  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
-function wpinv_get_item_by( $field = '', $value = '', $type = '' ) {
6
-    if( empty( $field ) || empty( $value ) ) {
5
+function wpinv_get_item_by($field = '', $value = '', $type = '') {
6
+    if (empty($field) || empty($value)) {
7 7
         return false;
8 8
     }
9 9
     
10 10
     $posts = array();
11 11
 
12
-    switch( strtolower( $field ) ) {
12
+    switch (strtolower($field)) {
13 13
         case 'id':
14
-            $item = get_post( $value );
14
+            $item = get_post($value);
15 15
 
16
-            if( get_post_type( $item ) != 'wpi_item' ) {
16
+            if (get_post_type($item) != 'wpi_item') {
17 17
                 return false;
18 18
             }
19 19
 
@@ -21,16 +21,16 @@  discard block
 block discarded – undo
21 21
 
22 22
         case 'slug':
23 23
         case 'name':
24
-            $posts = get_posts( array(
24
+            $posts = get_posts(array(
25 25
                 'post_type'      => 'wpi_item',
26 26
                 'name'           => $value,
27 27
                 'posts_per_page' => 1,
28 28
                 'post_status'    => 'any'
29
-            ) );
29
+            ));
30 30
 
31 31
             break;
32 32
         case 'package_id':
33
-            $posts = get_posts( array(
33
+            $posts = get_posts(array(
34 34
                 'post_type'      => 'wpi_item',
35 35
                 'posts_per_page' => 1,
36 36
                 'post_status'    => 'any',
@@ -46,11 +46,11 @@  discard block
 block discarded – undo
46 46
                         'value' => 'package',
47 47
                     )
48 48
                 )
49
-            ) );
49
+            ));
50 50
             
51 51
             break;
52 52
         case 'item_id':
53
-            if ( empty( $value ) ) {
53
+            if (empty($value)) {
54 54
                 return false;
55 55
             }
56 56
             
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
                 'key'   => '_wpinv_post_id',
60 60
                 'value' => $value,
61 61
             );
62
-            if ( !empty( $type ) ) {
62
+            if (!empty($type)) {
63 63
                 $meta_query[] = array(
64 64
                     'key'   => '_wpinv_type',
65 65
                     'value' => $type,
@@ -72,14 +72,14 @@  discard block
 block discarded – undo
72 72
                 'post_status'    => 'any',
73 73
                 'orderby'        => 'ID',
74 74
                 'order'          => 'ASC',
75
-                'meta_query'     => array( $meta_query )
75
+                'meta_query'     => array($meta_query)
76 76
             );
77 77
             
78
-            $posts = get_posts( $args );
78
+            $posts = get_posts($args);
79 79
 
80 80
             break;
81 81
         case 'custom':
82
-            if ( empty( $value ) || empty( $type ) ) {
82
+            if (empty($value) || empty($type)) {
83 83
                 return false;
84 84
             }
85 85
             
@@ -99,10 +99,10 @@  discard block
 block discarded – undo
99 99
                 'post_status'    => 'any',
100 100
                 'orderby'        => 'ID',
101 101
                 'order'          => 'ASC',
102
-                'meta_query'     => array( $meta_query )
102
+                'meta_query'     => array($meta_query)
103 103
             );
104 104
             
105
-            $posts = get_posts( $args );
105
+            $posts = get_posts($args);
106 106
 
107 107
             break;
108 108
 
@@ -110,17 +110,17 @@  discard block
 block discarded – undo
110 110
             return false;
111 111
     }
112 112
     
113
-    if ( !empty( $posts[0] ) ) {
114
-        return new WPInv_Item( $posts[0]->ID );
113
+    if (!empty($posts[0])) {
114
+        return new WPInv_Item($posts[0]->ID);
115 115
     }
116 116
 
117 117
     return false;
118 118
 }
119 119
 
120
-function wpinv_get_item( $item = 0 ) {
121
-    if ( is_numeric( $item ) ) {
122
-        $item = get_post( $item );
123
-        if ( ! $item || 'wpi_item' !== $item->post_type )
120
+function wpinv_get_item($item = 0) {
121
+    if (is_numeric($item)) {
122
+        $item = get_post($item);
123
+        if (!$item || 'wpi_item' !== $item->post_type)
124 124
             return null;
125 125
         return $item;
126 126
     }
@@ -133,136 +133,136 @@  discard block
 block discarded – undo
133 133
 
134 134
     $item = get_posts($args);
135 135
 
136
-    if ( $item ) {
136
+    if ($item) {
137 137
         return $item[0];
138 138
     }
139 139
 
140 140
     return null;
141 141
 }
142 142
 
143
-function wpinv_is_free_item( $item_id = 0 ) {
144
-    if( empty( $item_id ) ) {
143
+function wpinv_is_free_item($item_id = 0) {
144
+    if (empty($item_id)) {
145 145
         return false;
146 146
     }
147 147
 
148
-    $item = new WPInv_Item( $item_id );
148
+    $item = new WPInv_Item($item_id);
149 149
     
150 150
     return $item->is_free();
151 151
 }
152 152
 
153
-function wpinv_get_item_price( $item_id = 0 ) {
154
-    if( empty( $item_id ) ) {
153
+function wpinv_get_item_price($item_id = 0) {
154
+    if (empty($item_id)) {
155 155
         return false;
156 156
     }
157 157
 
158
-    $item = new WPInv_Item( $item_id );
158
+    $item = new WPInv_Item($item_id);
159 159
     
160 160
     return $item->get_price();
161 161
 }
162 162
 
163
-function wpinv_is_recurring_item( $item_id = 0 ) {
164
-    if( empty( $item_id ) ) {
163
+function wpinv_is_recurring_item($item_id = 0) {
164
+    if (empty($item_id)) {
165 165
         return false;
166 166
     }
167 167
 
168
-    $item = new WPInv_Item( $item_id );
168
+    $item = new WPInv_Item($item_id);
169 169
     
170 170
     return $item->is_recurring();
171 171
 }
172 172
 
173
-function wpinv_item_price( $item_id = 0 ) {
174
-    if( empty( $item_id ) ) {
173
+function wpinv_item_price($item_id = 0) {
174
+    if (empty($item_id)) {
175 175
         return false;
176 176
     }
177 177
 
178
-    $price = wpinv_get_item_price( $item_id );
179
-    $price = wpinv_price( wpinv_format_amount( $price ) );
178
+    $price = wpinv_get_item_price($item_id);
179
+    $price = wpinv_price(wpinv_format_amount($price));
180 180
     
181
-    return apply_filters( 'wpinv_item_price', $price, $item_id );
181
+    return apply_filters('wpinv_item_price', $price, $item_id);
182 182
 }
183 183
 
184
-function wpinv_item_show_price( $item_id = 0, $echo = true ) {
185
-    if ( empty( $item_id ) ) {
184
+function wpinv_item_show_price($item_id = 0, $echo = true) {
185
+    if (empty($item_id)) {
186 186
         $item_id = get_the_ID();
187 187
     }
188 188
 
189
-    $price = wpinv_item_price( $item_id );
189
+    $price = wpinv_item_price($item_id);
190 190
 
191
-    $price           = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id );
191
+    $price           = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id);
192 192
     $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>';
193
-    $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price );
193
+    $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price);
194 194
 
195
-    if ( $echo ) {
195
+    if ($echo) {
196 196
         echo $formatted_price;
197 197
     } else {
198 198
         return $formatted_price;
199 199
     }
200 200
 }
201 201
 
202
-function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) {
203
-    if ( is_null( $amount_override ) ) {
204
-        $original_price = get_post_meta( $item_id, '_wpinv_price', true );
202
+function wpinv_get_item_final_price($item_id = 0, $amount_override = null) {
203
+    if (is_null($amount_override)) {
204
+        $original_price = get_post_meta($item_id, '_wpinv_price', true);
205 205
     } else {
206 206
         $original_price = $amount_override;
207 207
     }
208 208
     
209 209
     $price = $original_price;
210 210
 
211
-    return apply_filters( 'wpinv_get_item_final_price', $price, $item_id );
211
+    return apply_filters('wpinv_get_item_final_price', $price, $item_id);
212 212
 }
213 213
 
214
-function wpinv_item_cpt_singular_name( $item_id ) {
215
-    if( empty( $item_id ) ) {
214
+function wpinv_item_cpt_singular_name($item_id) {
215
+    if (empty($item_id)) {
216 216
         return false;
217 217
     }
218 218
 
219
-    $item = new WPInv_Item( $item_id );
219
+    $item = new WPInv_Item($item_id);
220 220
     
221 221
     return $item->get_cpt_singular_name();
222 222
 }
223 223
 
224 224
 function wpinv_get_item_types() {
225 225
     $item_types = array(
226
-            'custom'    => __( 'Standard', 'invoicing' ),
227
-            'fee'       => __( 'Fee', 'invoicing' ),
226
+            'custom'    => __('Standard', 'invoicing'),
227
+            'fee'       => __('Fee', 'invoicing'),
228 228
         );
229
-    return apply_filters( 'wpinv_get_item_types', $item_types );
229
+    return apply_filters('wpinv_get_item_types', $item_types);
230 230
 }
231 231
 
232 232
 function wpinv_item_types() {
233 233
     $item_types = wpinv_get_item_types();
234 234
     
235
-    return ( !empty( $item_types ) ? array_keys( $item_types ) : array() );
235
+    return (!empty($item_types) ? array_keys($item_types) : array());
236 236
 }
237 237
 
238
-function wpinv_get_item_type( $item_id ) {
239
-    if( empty( $item_id ) ) {
238
+function wpinv_get_item_type($item_id) {
239
+    if (empty($item_id)) {
240 240
         return false;
241 241
     }
242 242
 
243
-    $item = new WPInv_Item( $item_id );
243
+    $item = new WPInv_Item($item_id);
244 244
     
245 245
     return $item->get_type();
246 246
 }
247 247
 
248
-function wpinv_item_type( $item_id ) {
248
+function wpinv_item_type($item_id) {
249 249
     $item_types = wpinv_get_item_types();
250 250
     
251
-    $item_type = wpinv_get_item_type( $item_id );
251
+    $item_type = wpinv_get_item_type($item_id);
252 252
     
253
-    if ( empty( $item_type ) ) {
253
+    if (empty($item_type)) {
254 254
         $item_type = '-';
255 255
     }
256 256
     
257
-    $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' );
257
+    $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing');
258 258
 
259
-    return apply_filters( 'wpinv_item_type', $item_type, $item_id );
259
+    return apply_filters('wpinv_item_type', $item_type, $item_id);
260 260
 }
261 261
 
262
-function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) {
262
+function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) {
263 263
     global $wpinv_logs;
264 264
     
265
-    if ( empty( $wpinv_logs ) ) {
265
+    if (empty($wpinv_logs)) {
266 266
         return false;
267 267
     }
268 268
 
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
         'log_type'		=> 'wpi_item'
272 272
     );
273 273
 
274
-    $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1;
274
+    $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1;
275 275
 
276 276
     $log_meta = array(
277 277
         'user_info'	=> $user_info,
@@ -281,247 +281,247 @@  discard block
 block discarded – undo
281 281
         'invoice_id'=> $invoice_id,
282 282
     );
283 283
 
284
-    $wpinv_logs->insert_log( $log_data, $log_meta );
284
+    $wpinv_logs->insert_log($log_data, $log_meta);
285 285
 }
286 286
 
287
-function wpinv_remove_item_logs_on_delete( $item_id = 0 ) {
288
-    if ( 'wpi_item' !== get_post_type( $item_id ) )
287
+function wpinv_remove_item_logs_on_delete($item_id = 0) {
288
+    if ('wpi_item' !== get_post_type($item_id))
289 289
         return;
290 290
 
291 291
     global $wpinv_logs;
292 292
     
293
-    if ( empty( $wpinv_logs ) ) {
293
+    if (empty($wpinv_logs)) {
294 294
         return false;
295 295
     }
296 296
 
297 297
     // Remove all log entries related to this item
298
-    $wpinv_logs->delete_logs( $item_id );
298
+    $wpinv_logs->delete_logs($item_id);
299 299
 }
300
-add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' );
300
+add_action('delete_post', 'wpinv_remove_item_logs_on_delete');
301 301
 
302
-function wpinv_get_random_item( $post_ids = true ) {
303
-    wpinv_get_random_items( 1, $post_ids );
302
+function wpinv_get_random_item($post_ids = true) {
303
+    wpinv_get_random_items(1, $post_ids);
304 304
 }
305 305
 
306
-function wpinv_get_random_items( $num = 3, $post_ids = true ) {
307
-    if ( $post_ids ) {
308
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' );
306
+function wpinv_get_random_items($num = 3, $post_ids = true) {
307
+    if ($post_ids) {
308
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids');
309 309
     } else {
310
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num );
310
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num);
311 311
     }
312 312
     
313
-    $args  = apply_filters( 'wpinv_get_random_items', $args );
313
+    $args = apply_filters('wpinv_get_random_items', $args);
314 314
     
315
-    return get_posts( $args );
315
+    return get_posts($args);
316 316
 }
317 317
 
318
-function wpinv_get_item_token( $url = '' ) {
318
+function wpinv_get_item_token($url = '') {
319 319
     $args    = array();
320
-    $hash    = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' );
321
-    $secret  = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) );
320
+    $hash    = apply_filters('wpinv_get_url_token_algorithm', 'sha256');
321
+    $secret  = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt()));
322 322
 
323
-    $parts   = parse_url( $url );
323
+    $parts   = parse_url($url);
324 324
     $options = array();
325 325
 
326
-    if ( isset( $parts['query'] ) ) {
327
-        wp_parse_str( $parts['query'], $query_args );
326
+    if (isset($parts['query'])) {
327
+        wp_parse_str($parts['query'], $query_args);
328 328
 
329
-        if ( ! empty( $query_args['o'] ) ) {
330
-            $options = explode( ':', rawurldecode( $query_args['o'] ) );
329
+        if (!empty($query_args['o'])) {
330
+            $options = explode(':', rawurldecode($query_args['o']));
331 331
 
332
-            if ( in_array( 'ip', $options ) ) {
332
+            if (in_array('ip', $options)) {
333 333
                 $args['ip'] = wpinv_get_ip();
334 334
             }
335 335
 
336
-            if ( in_array( 'ua', $options ) ) {
336
+            if (in_array('ua', $options)) {
337 337
                 $ua = wpinv_get_user_agent();
338
-                $args['user_agent'] = rawurlencode( $ua );
338
+                $args['user_agent'] = rawurlencode($ua);
339 339
             }
340 340
         }
341 341
     }
342 342
 
343
-    $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options );
343
+    $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options);
344 344
 
345 345
     $args['secret'] = $secret;
346 346
     $args['token']  = false;
347 347
 
348
-    $url   = add_query_arg( $args, $url );
349
-    $parts = parse_url( $url );
348
+    $url   = add_query_arg($args, $url);
349
+    $parts = parse_url($url);
350 350
 
351
-    if ( ! isset( $parts['path'] ) ) {
351
+    if (!isset($parts['path'])) {
352 352
         $parts['path'] = '';
353 353
     }
354 354
 
355
-    $token = md5( $parts['path'] . '?' . $parts['query'] );
355
+    $token = md5($parts['path'] . '?' . $parts['query']);
356 356
 
357 357
     return $token;
358 358
 }
359 359
 
360
-function wpinv_validate_url_token( $url = '' ) {
360
+function wpinv_validate_url_token($url = '') {
361 361
     $ret   = false;
362
-    $parts = parse_url( $url );
362
+    $parts = parse_url($url);
363 363
 
364
-    if ( isset( $parts['query'] ) ) {
365
-        wp_parse_str( $parts['query'], $query_args );
364
+    if (isset($parts['query'])) {
365
+        wp_parse_str($parts['query'], $query_args);
366 366
 
367
-        $allowed = apply_filters( 'wpinv_url_token_allowed_params', array(
367
+        $allowed = apply_filters('wpinv_url_token_allowed_params', array(
368 368
             'item',
369 369
             'ttl',
370 370
             'token'
371
-        ) );
371
+        ));
372 372
 
373 373
         $remove = array();
374 374
 
375
-        foreach( $query_args as $key => $value ) {
376
-            if( false === in_array( $key, $allowed ) ) {
375
+        foreach ($query_args as $key => $value) {
376
+            if (false === in_array($key, $allowed)) {
377 377
                 $remove[] = $key;
378 378
             }
379 379
         }
380 380
 
381
-        if( ! empty( $remove ) ) {
382
-            $url = remove_query_arg( $remove, $url );
381
+        if (!empty($remove)) {
382
+            $url = remove_query_arg($remove, $url);
383 383
         }
384 384
 
385
-        if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) {
386
-            wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
385
+        if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) {
386
+            wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403));
387 387
         }
388 388
 
389
-        if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) {
389
+        if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) {
390 390
             $ret = true;
391 391
         }
392 392
 
393 393
     }
394 394
 
395
-    return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args );
395
+    return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args);
396 396
 }
397 397
 
398
-function wpinv_item_in_cart( $item_id = 0, $options = array() ) {
398
+function wpinv_item_in_cart($item_id = 0, $options = array()) {
399 399
     $cart_items = wpinv_get_cart_contents();
400 400
 
401 401
     $ret = false;
402 402
 
403
-    if ( is_array( $cart_items ) ) {
404
-        foreach ( $cart_items as $item ) {
405
-            if ( $item['id'] == $item_id ) {
403
+    if (is_array($cart_items)) {
404
+        foreach ($cart_items as $item) {
405
+            if ($item['id'] == $item_id) {
406 406
                 $ret = true;
407 407
                 break;
408 408
             }
409 409
         }
410 410
     }
411 411
 
412
-    return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options );
412
+    return (bool)apply_filters('wpinv_item_in_cart', $ret, $item_id, $options);
413 413
 }
414 414
 
415
-function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) {
415
+function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) {
416 416
     $tax = 0;
417
-    if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) {
418
-        $country = !empty( $_POST['country'] ) ? $_POST['country'] : false;
419
-        $state   = isset( $_POST['state'] ) ? $_POST['state'] : '';
417
+    if (!wpinv_item_is_tax_exclusive($item_id)) {
418
+        $country = !empty($_POST['country']) ? $_POST['country'] : false;
419
+        $state   = isset($_POST['state']) ? $_POST['state'] : '';
420 420
 
421
-        $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id );
421
+        $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id);
422 422
     }
423 423
 
424
-    return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options );
424
+    return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options);
425 425
 }
426 426
 
427
-function wpinv_cart_item_price( $item ) {
427
+function wpinv_cart_item_price($item) {
428 428
     $use_taxes  = wpinv_use_taxes();
429
-    $item_id    = isset( $item['id'] ) ? $item['id'] : 0;
430
-    $price      = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0;
431
-    $options    = isset( $item['options'] ) ? $item['options'] : array();
432
-    $price_id   = isset( $options['price_id'] ) ? $options['price_id'] : false;
433
-    $tax        = wpinv_price( wpinv_format_amount( $item['tax'] ) );
434
-    
435
-    if ( !wpinv_is_free_item( $item_id, $price_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) {
436
-        if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) {
429
+    $item_id    = isset($item['id']) ? $item['id'] : 0;
430
+    $price      = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0;
431
+    $options    = isset($item['options']) ? $item['options'] : array();
432
+    $price_id   = isset($options['price_id']) ? $options['price_id'] : false;
433
+    $tax        = wpinv_price(wpinv_format_amount($item['tax']));
434
+    
435
+    if (!wpinv_is_free_item($item_id, $price_id) && !wpinv_item_is_tax_exclusive($item_id)) {
436
+        if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) {
437 437
             $price += $tax;
438 438
         }
439 439
         
440
-        if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) {
440
+        if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) {
441 441
             $price -= $tax;
442 442
         }        
443 443
     }
444 444
 
445
-    $price = wpinv_price( wpinv_format_amount( $price ) );
445
+    $price = wpinv_price(wpinv_format_amount($price));
446 446
 
447
-    return apply_filters( 'wpinv_cart_item_price_label', $price, $item );
447
+    return apply_filters('wpinv_cart_item_price_label', $price, $item);
448 448
 }
449 449
 
450
-function wpinv_cart_item_subtotal( $item ) {
451
-    $subtotal   = isset( $item['subtotal'] ) ? $item['subtotal'] : 0;
452
-    $subtotal   = wpinv_price( wpinv_format_amount( $subtotal ) );
450
+function wpinv_cart_item_subtotal($item) {
451
+    $subtotal   = isset($item['subtotal']) ? $item['subtotal'] : 0;
452
+    $subtotal   = wpinv_price(wpinv_format_amount($subtotal));
453 453
 
454
-    return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item );
454
+    return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item);
455 455
 }
456 456
 
457
-function wpinv_cart_item_tax( $item ) {
457
+function wpinv_cart_item_tax($item) {
458 458
     $tax        = '';
459 459
     $tax_rate   = '';
460 460
     
461
-    if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) {
462
-        $tax      = wpinv_price( wpinv_format_amount( $item['tax'] ) );
463
-        $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100;
464
-        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate ) : '';
461
+    if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) {
462
+        $tax      = wpinv_price(wpinv_format_amount($item['tax']));
463
+        $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100;
464
+        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate) : '';
465 465
         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : '';
466 466
     }
467 467
     
468
-    $tax        = $tax . $tax_rate;
468
+    $tax = $tax . $tax_rate;
469 469
     
470
-    if ( $tax === '' ) {
470
+    if ($tax === '') {
471 471
         $tax = 0; // Zero tax
472 472
     }
473 473
 
474
-    return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item );
474
+    return apply_filters('wpinv_cart_item_tax_label', $tax, $item);
475 475
 }
476 476
 
477
-function wpinv_get_cart_item_price( $item_id = 0, $options = array(), $remove_tax_from_inclusive = false ) {
477
+function wpinv_get_cart_item_price($item_id = 0, $options = array(), $remove_tax_from_inclusive = false) {
478 478
     $price = 0;
479
-    $variable_prices = wpinv_has_variable_prices( $item_id );
479
+    $variable_prices = wpinv_has_variable_prices($item_id);
480 480
 
481
-    if ( $variable_prices ) {
482
-        $prices = wpinv_get_variable_prices( $item_id );
481
+    if ($variable_prices) {
482
+        $prices = wpinv_get_variable_prices($item_id);
483 483
 
484
-        if ( $prices ) {
485
-            if( ! empty( $options ) ) {
486
-                $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false;
484
+        if ($prices) {
485
+            if (!empty($options)) {
486
+                $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false;
487 487
             } else {
488 488
                 $price = false;
489 489
             }
490 490
         }
491 491
     }
492 492
 
493
-    if( ! $variable_prices || false === $price ) {
493
+    if (!$variable_prices || false === $price) {
494 494
         // Get the standard Item price if not using variable prices
495
-        $price = wpinv_get_item_price( $item_id );
495
+        $price = wpinv_get_item_price($item_id);
496 496
     }
497 497
 
498
-    if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) {
499
-        $price -= wpinv_get_cart_item_tax( $item_id, $price, $options );
498
+    if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) {
499
+        $price -= wpinv_get_cart_item_tax($item_id, $price, $options);
500 500
     }
501 501
 
502
-    return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $options );
502
+    return apply_filters('wpinv_cart_item_price', $price, $item_id, $options);
503 503
 }
504 504
 
505
-function wpinv_get_cart_item_price_id( $item = array() ) {
506
-    if( isset( $item['item_number'] ) ) {
507
-        $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null;
505
+function wpinv_get_cart_item_price_id($item = array()) {
506
+    if (isset($item['item_number'])) {
507
+        $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null;
508 508
     } else {
509
-        $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null;
509
+        $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null;
510 510
     }
511 511
     return $price_id;
512 512
 }
513 513
 
514
-function wpinv_get_cart_item_price_name( $item = array() ) {
515
-    $price_id = (int)wpinv_get_cart_item_price_id( $item );
516
-    $prices   = wpinv_get_variable_prices( $item['id'] );
517
-    $name     = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : '';
518
-    return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item );
514
+function wpinv_get_cart_item_price_name($item = array()) {
515
+    $price_id = (int)wpinv_get_cart_item_price_id($item);
516
+    $prices   = wpinv_get_variable_prices($item['id']);
517
+    $name     = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : '';
518
+    return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item);
519 519
 }
520 520
 
521
-function wpinv_get_cart_item_name( $item = array() ) {
522
-    $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] );
521
+function wpinv_get_cart_item_name($item = array()) {
522
+    $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']);
523 523
 
524
-    if ( empty( $item_title ) ) {
524
+    if (empty($item_title)) {
525 525
         $item_title = $item['id'];
526 526
     }
527 527
 
@@ -531,23 +531,23 @@  discard block
 block discarded – undo
531 531
     }
532 532
     */
533 533
 
534
-    return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item );
534
+    return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item);
535 535
 }
536 536
 
537
-function wpinv_has_variable_prices( $item_id = 0 ) {
537
+function wpinv_has_variable_prices($item_id = 0) {
538 538
     return false;
539 539
 }
540 540
 
541
-function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) {
541
+function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) {
542 542
     $cart_items = wpinv_get_cart_contents();
543 543
 
544
-    if ( !is_array( $cart_items ) ) {
544
+    if (!is_array($cart_items)) {
545 545
         return false; // Empty cart
546 546
     } else {
547
-        foreach ( $cart_items as $position => $item ) {
548
-            if ( $item['id'] == $item_id ) {
549
-                if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) {
550
-                    if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) {
547
+        foreach ($cart_items as $position => $item) {
548
+            if ($item['id'] == $item_id) {
549
+                if (isset($options['price_id']) && isset($item['options']['price_id'])) {
550
+                    if ((int)$options['price_id'] == (int)$item['options']['price_id']) {
551 551
                         return $position;
552 552
                     }
553 553
                 } else {
@@ -560,80 +560,80 @@  discard block
 block discarded – undo
560 560
     return false; // Not found
561 561
 }
562 562
 
563
-function wpinv_get_cart_item_quantity( $item ) {
564
-    if ( wpinv_item_quantities_enabled() ) {
565
-        $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
563
+function wpinv_get_cart_item_quantity($item) {
564
+    if (wpinv_item_quantities_enabled()) {
565
+        $quantity = !empty($item['quantity']) && (int)$item['quantity'] > 0 ? absint($item['quantity']) : 1;
566 566
     } else {
567 567
         $quantity = 1;
568 568
     }
569 569
     
570
-    if ( $quantity < 1 ) {
570
+    if ($quantity < 1) {
571 571
         $quantity = 1;
572 572
     }
573 573
     
574
-    return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item );
574
+    return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item);
575 575
 }
576 576
 
577
-function wpinv_get_item_suffix( $item, $html = true ) {
578
-    if ( empty( $item ) ) {
577
+function wpinv_get_item_suffix($item, $html = true) {
578
+    if (empty($item)) {
579 579
         return NULL;
580 580
     }
581 581
     
582
-    if ( is_int( $item ) ) {
583
-        $item = new WPInv_Item( $item );
582
+    if (is_int($item)) {
583
+        $item = new WPInv_Item($item);
584 584
     }
585 585
     
586
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
586
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
587 587
         return NULL;
588 588
     }
589 589
     
590
-    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '';
590
+    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '';
591 591
     
592
-    if ( !$html && $suffix ) {
593
-        $suffix = strip_tags( $suffix );
592
+    if (!$html && $suffix) {
593
+        $suffix = strip_tags($suffix);
594 594
     }
595 595
     
596
-    return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html );
596
+    return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html);
597 597
 }
598 598
 
599
-function wpinv_remove_item( $item = 0, $force_delete = false ) {
600
-    if ( empty( $item ) ) {
599
+function wpinv_remove_item($item = 0, $force_delete = false) {
600
+    if (empty($item)) {
601 601
         return NULL;
602 602
     }
603 603
     
604
-    if ( is_int( $item ) ) {
605
-        $item = new WPInv_Item( $item );
604
+    if (is_int($item)) {
605
+        $item = new WPInv_Item($item);
606 606
     }
607 607
     
608
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
608
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
609 609
         return NULL;
610 610
     }
611 611
     
612
-    do_action( 'wpinv_pre_delete_item', $item );
612
+    do_action('wpinv_pre_delete_item', $item);
613 613
 
614
-    wp_delete_post( $item->ID, $force_delete );
614
+    wp_delete_post($item->ID, $force_delete);
615 615
 
616
-    do_action( 'wpinv_post_delete_item', $item );
616
+    do_action('wpinv_post_delete_item', $item);
617 617
 }
618 618
 
619
-function wpinv_can_delete_item( $post_id ) {
620
-    $return = current_user_can( 'manage_options' ) ? true : false;
619
+function wpinv_can_delete_item($post_id) {
620
+    $return = current_user_can('manage_options') ? true : false;
621 621
     
622
-    if ( $return && wpinv_item_in_use( $post_id ) ) {
622
+    if ($return && wpinv_item_in_use($post_id)) {
623 623
         $return = false; // Don't delete item already use in invoices.
624 624
     }
625 625
     
626
-    return apply_filters( 'wpinv_can_delete_item', $return, $post_id );
626
+    return apply_filters('wpinv_can_delete_item', $return, $post_id);
627 627
 }
628 628
 
629 629
 function wpinv_admin_action_delete() {
630 630
     $screen = get_current_screen();
631 631
     
632
-    if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) {
632
+    if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) {
633 633
         $post_ids = array();
634 634
         
635
-        foreach ( $_REQUEST['post'] as $post_id ) {
636
-            if ( !wpinv_can_delete_item( $post_id ) ) {
635
+        foreach ($_REQUEST['post'] as $post_id) {
636
+            if (!wpinv_can_delete_item($post_id)) {
637 637
                 continue;
638 638
             }
639 639
             
@@ -643,83 +643,83 @@  discard block
 block discarded – undo
643 643
         $_REQUEST['post'] = $post_ids;
644 644
     }
645 645
 }
646
-add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 );
647
-add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 );
646
+add_action('admin_action_trash', 'wpinv_admin_action_delete', -10);
647
+add_action('admin_action_delete', 'wpinv_admin_action_delete', -10);
648 648
 
649
-function wpinv_check_delete_item( $check, $post, $force_delete ) {
650
-    if ( $post->post_type == 'wpi_item' ) {
651
-        if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) {
649
+function wpinv_check_delete_item($check, $post, $force_delete) {
650
+    if ($post->post_type == 'wpi_item') {
651
+        if ($force_delete && !wpinv_can_delete_item($post->ID)) {
652 652
             return true;
653 653
         }
654 654
     }
655 655
     
656 656
     return $check;
657 657
 }
658
-add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 );
658
+add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3);
659 659
 
660
-function wpinv_item_in_use( $item_id ) {
660
+function wpinv_item_in_use($item_id) {
661 661
     global $wpdb, $wpi_items_in_use;
662 662
     
663
-    if ( !$item_id > 0 ) {
663
+    if (!$item_id > 0) {
664 664
         return false;
665 665
     }
666 666
     
667
-    if ( !empty( $wpi_items_in_use ) ) {
668
-        if ( isset( $wpi_items_in_use[$item_id] ) ) {
667
+    if (!empty($wpi_items_in_use)) {
668
+        if (isset($wpi_items_in_use[$item_id])) {
669 669
             return $wpi_items_in_use[$item_id];
670 670
         }
671 671
     } else {
672 672
         $wpi_items_in_use = array();
673 673
     }
674 674
     
675
-    $statuses   = array_keys( wpinv_get_invoice_statuses( true ) );
675
+    $statuses = array_keys(wpinv_get_invoice_statuses(true));
676 676
     
677
-    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )";
678
-    $in_use = $wpdb->get_var( $query ) > 0 ? true : false;
677
+    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )";
678
+    $in_use = $wpdb->get_var($query) > 0 ? true : false;
679 679
     
680 680
     $wpi_items_in_use[$item_id] = $in_use;
681 681
     
682 682
     return $in_use;
683 683
 }
684 684
 
685
-function wpinv_create_item( $args = array(), $wp_error = false, $force_update = false ) {
685
+function wpinv_create_item($args = array(), $wp_error = false, $force_update = false) {
686 686
     // Set some defaults
687 687
     $defaults = array(
688
-        'type'               => 'custom',                                                // Optional. Item type. Default 'custom'.
689
-        'item_id'            => 0,                                                       // Required. Any integer number. Must be unique within item type.
690
-        'title'              => '',                                                      // Required. Item title.
691
-        'price'              => '0.00',                                                  // Optional. Item price. Default '0.00'.
692
-        'status'             => 'pending',                                               // Optional. pending, publish
693
-        'vat_rule'           => 'digital',                                               // Optional. digital => Digital item, physical => Physical item
694
-        'cpt_singular_name'  => '',                                                      // Optional. Sub title for item. Should be singular.
695
-        'cpt_name'           => '',                                                      // Optional. Sub title for item. Should be plural.
696
-        'is_recurring'       => 0,                                                       // Optional. 1 => Allow recurring or 0 => Don't allow recurring
697
-        'recurring_period'   => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
698
-        'recurring_interval' => 0,                                                       // Optional. Integer value between 1 - 90.
699
-        'recurring_limit'    => 0,                                                       // Optional. Any integer number. 0 for recurring forever until cancelled.
700
-        'free_trial'         => 0,                                                       // Optional. 1 => Allow free trial or 0 => Don't free trial
701
-        'trial_period'       => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
702
-        'trial_interval'     => 0,                                                       // Optional. Any integer number.
703
-        'excerpt'            => '',                                                      // Optional. Item short description
688
+        'type'               => 'custom', // Optional. Item type. Default 'custom'.
689
+        'item_id'            => 0, // Required. Any integer number. Must be unique within item type.
690
+        'title'              => '', // Required. Item title.
691
+        'price'              => '0.00', // Optional. Item price. Default '0.00'.
692
+        'status'             => 'pending', // Optional. pending, publish
693
+        'vat_rule'           => 'digital', // Optional. digital => Digital item, physical => Physical item
694
+        'cpt_singular_name'  => '', // Optional. Sub title for item. Should be singular.
695
+        'cpt_name'           => '', // Optional. Sub title for item. Should be plural.
696
+        'is_recurring'       => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring
697
+        'recurring_period'   => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
698
+        'recurring_interval' => 0, // Optional. Integer value between 1 - 90.
699
+        'recurring_limit'    => 0, // Optional. Any integer number. 0 for recurring forever until cancelled.
700
+        'free_trial'         => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial
701
+        'trial_period'       => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
702
+        'trial_interval'     => 0, // Optional. Any integer number.
703
+        'excerpt'            => '', // Optional. Item short description
704 704
     );
705 705
     
706
-    $data = wp_parse_args( $args, $defaults );
706
+    $data = wp_parse_args($args, $defaults);
707 707
     
708
-    if ( empty( $data['item_id'] ) ) {
709
-        if ( $wp_error ) {
710
-            return new WP_Error( 'invalid_item_id', __( 'Invalid item ID.' ) );
708
+    if (empty($data['item_id'])) {
709
+        if ($wp_error) {
710
+            return new WP_Error('invalid_item_id', __('Invalid item ID.'));
711 711
         } else {
712 712
             return false;
713 713
         }
714 714
     }
715 715
     
716
-    if ( empty( $data['type'] ) ) {
716
+    if (empty($data['type'])) {
717 717
         $data['type'] = 'custom';
718 718
     }
719 719
     
720
-    $item = wpinv_get_item_by( 'item_id', $data['item_id'], $data['type'] );
720
+    $item = wpinv_get_item_by('item_id', $data['item_id'], $data['type']);
721 721
         
722
-    if ( !$force_update && !empty( $item ) ) {
722
+    if (!$force_update && !empty($item)) {
723 723
         return $item;
724 724
     }
725 725
         
@@ -728,18 +728,18 @@  discard block
 block discarded – undo
728 728
     $meta['post_id']            = $data['item_id'];
729 729
     $meta['cpt_singular_name']  = $data['cpt_singular_name'];
730 730
     $meta['cpt_name']           = $data['cpt_name'];
731
-    $meta['price']              = wpinv_round_amount( $data['price'] );
731
+    $meta['price']              = wpinv_round_amount($data['price']);
732 732
     $meta['vat_rule']           = $data['vat_rule'];
733 733
     $meta['vat_class']          = '_standard';
734 734
     
735
-    if ( !empty( $data['is_recurring'] ) ) {
735
+    if (!empty($data['is_recurring'])) {
736 736
         $meta['is_recurring']       = $data['is_recurring'];
737 737
         $meta['recurring_period']   = $data['recurring_period'];
738
-        $meta['recurring_interval'] = absint( $data['recurring_interval'] );
739
-        $meta['recurring_limit']    = absint( $data['recurring_limit'] );
738
+        $meta['recurring_interval'] = absint($data['recurring_interval']);
739
+        $meta['recurring_limit']    = absint($data['recurring_limit']);
740 740
         $meta['free_trial']         = $data['free_trial'];
741 741
         $meta['trial_period']       = $data['trial_period'];
742
-        $meta['trial_interval']     = absint( $data['trial_interval'] );
742
+        $meta['trial_interval']     = absint($data['trial_interval']);
743 743
     } else {
744 744
         $meta['is_recurring']       = 0;
745 745
         $meta['recurring_period']   = '';
@@ -750,18 +750,18 @@  discard block
 block discarded – undo
750 750
         $meta['trial_interval']     = '';
751 751
     }
752 752
     
753
-    $post_data  = array( 
753
+    $post_data = array( 
754 754
         'post_title'    => $data['title'],
755 755
         'post_excerpt'  => $data['excerpt'],
756 756
         'post_status'   => $data['status'],
757 757
         'meta'          => $meta
758 758
     );
759 759
 
760
-    if ( !empty( $item ) ) {
761
-        $item->update( $post_data, $wp_error );
760
+    if (!empty($item)) {
761
+        $item->update($post_data, $wp_error);
762 762
     } else {
763 763
         $item = new WPInv_Item();
764
-        $item->create( $post_data, $wp_error );
764
+        $item->create($post_data, $wp_error);
765 765
     }
766 766
     
767 767
     return $item;
Please login to merge, or discard this patch.