Passed
Pull Request — master (#217)
by Patrik
03:42 queued 13s
created
includes/abstracts/abstract-wpinv-session.php 1 patch
Indentation   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  */
5 5
 
6 6
 if ( ! defined( 'ABSPATH' ) ) {
7
-	exit;
7
+    exit;
8 8
 }
9 9
 
10 10
 /**
@@ -12,112 +12,112 @@  discard block
 block discarded – undo
12 12
  */
13 13
 abstract class WPInv_Session {
14 14
 
15
-	/**
16
-	 * Customer ID.
17
-	 *
18
-	 * @var int $_customer_id Customer ID.
19
-	 */
20
-	protected $_customer_id;
15
+    /**
16
+     * Customer ID.
17
+     *
18
+     * @var int $_customer_id Customer ID.
19
+     */
20
+    protected $_customer_id;
21 21
 
22
-	/**
23
-	 * Session Data.
24
-	 *
25
-	 * @var array $_data Data array.
26
-	 */
27
-	protected $_data = array();
22
+    /**
23
+     * Session Data.
24
+     *
25
+     * @var array $_data Data array.
26
+     */
27
+    protected $_data = array();
28 28
 
29
-	/**
30
-	 * Dirty when the session needs saving.
31
-	 *
32
-	 * @var bool $_dirty When something changes
33
-	 */
34
-	protected $_dirty = false;
29
+    /**
30
+     * Dirty when the session needs saving.
31
+     *
32
+     * @var bool $_dirty When something changes
33
+     */
34
+    protected $_dirty = false;
35 35
 
36
-	/**
37
-	 * Init hooks and session data. Extended by child classes.
38
-	 *
39
-	 * @since 3.3.0
40
-	 */
41
-	public function init() {}
36
+    /**
37
+     * Init hooks and session data. Extended by child classes.
38
+     *
39
+     * @since 3.3.0
40
+     */
41
+    public function init() {}
42 42
 
43
-	/**
44
-	 * Cleanup session data. Extended by child classes.
45
-	 */
46
-	public function cleanup_sessions() {}
43
+    /**
44
+     * Cleanup session data. Extended by child classes.
45
+     */
46
+    public function cleanup_sessions() {}
47 47
 
48
-	/**
49
-	 * Magic get method.
50
-	 *
51
-	 * @param mixed $key Key to get.
52
-	 * @return mixed
53
-	 */
54
-	public function __get( $key ) {
55
-		return $this->get( $key );
56
-	}
48
+    /**
49
+     * Magic get method.
50
+     *
51
+     * @param mixed $key Key to get.
52
+     * @return mixed
53
+     */
54
+    public function __get( $key ) {
55
+        return $this->get( $key );
56
+    }
57 57
 
58
-	/**
59
-	 * Magic set method.
60
-	 *
61
-	 * @param mixed $key Key to set.
62
-	 * @param mixed $value Value to set.
63
-	 */
64
-	public function __set( $key, $value ) {
65
-		$this->set( $key, $value );
66
-	}
58
+    /**
59
+     * Magic set method.
60
+     *
61
+     * @param mixed $key Key to set.
62
+     * @param mixed $value Value to set.
63
+     */
64
+    public function __set( $key, $value ) {
65
+        $this->set( $key, $value );
66
+    }
67 67
 
68
-	/**
69
-	 * Magic isset method.
70
-	 *
71
-	 * @param mixed $key Key to check.
72
-	 * @return bool
73
-	 */
74
-	public function __isset( $key ) {
75
-		return isset( $this->_data[ sanitize_title( $key ) ] );
76
-	}
68
+    /**
69
+     * Magic isset method.
70
+     *
71
+     * @param mixed $key Key to check.
72
+     * @return bool
73
+     */
74
+    public function __isset( $key ) {
75
+        return isset( $this->_data[ sanitize_title( $key ) ] );
76
+    }
77 77
 
78
-	/**
79
-	 * Magic unset method.
80
-	 *
81
-	 * @param mixed $key Key to unset.
82
-	 */
83
-	public function __unset( $key ) {
84
-		if ( isset( $this->_data[ $key ] ) ) {
85
-			unset( $this->_data[ $key ] );
86
-			$this->_dirty = true;
87
-		}
88
-	}
78
+    /**
79
+     * Magic unset method.
80
+     *
81
+     * @param mixed $key Key to unset.
82
+     */
83
+    public function __unset( $key ) {
84
+        if ( isset( $this->_data[ $key ] ) ) {
85
+            unset( $this->_data[ $key ] );
86
+            $this->_dirty = true;
87
+        }
88
+    }
89 89
 
90
-	/**
91
-	 * Get a session variable.
92
-	 *
93
-	 * @param string $key Key to get.
94
-	 * @param mixed  $default used if the session variable isn't set.
95
-	 * @return array|string value of session variable
96
-	 */
97
-	public function get( $key, $default = null ) {
98
-		$key = sanitize_key( $key );
99
-		return isset( $this->_data[ $key ] ) ? maybe_unserialize( $this->_data[ $key ] ) : $default;
100
-	}
90
+    /**
91
+     * Get a session variable.
92
+     *
93
+     * @param string $key Key to get.
94
+     * @param mixed  $default used if the session variable isn't set.
95
+     * @return array|string value of session variable
96
+     */
97
+    public function get( $key, $default = null ) {
98
+        $key = sanitize_key( $key );
99
+        return isset( $this->_data[ $key ] ) ? maybe_unserialize( $this->_data[ $key ] ) : $default;
100
+    }
101 101
 
102
-	/**
103
-	 * Set a session variable.
104
-	 *
105
-	 * @param string $key Key to set.
106
-	 * @param mixed  $value Value to set.
107
-	 */
108
-	public function set( $key, $value ) {
109
-		if ( $value !== $this->get( $key ) ) {
110
-			$this->_data[ sanitize_key( $key ) ] = maybe_serialize( $value );
111
-			$this->_dirty                        = true;
112
-		}
113
-	}
102
+    /**
103
+     * Set a session variable.
104
+     *
105
+     * @param string $key Key to set.
106
+     * @param mixed  $value Value to set.
107
+     */
108
+    public function set( $key, $value ) {
109
+        if ( $value !== $this->get( $key ) ) {
110
+            $this->_data[ sanitize_key( $key ) ] = maybe_serialize( $value );
111
+            $this->_dirty                        = true;
112
+        }
113
+    }
114 114
 
115
-	/**
116
-	 * Get customer ID.
117
-	 *
118
-	 * @return int
119
-	 */
120
-	public function get_customer_id() {
121
-		return $this->_customer_id;
122
-	}
115
+    /**
116
+     * Get customer ID.
117
+     *
118
+     * @return int
119
+     */
120
+    public function get_customer_id() {
121
+        return $this->_customer_id;
122
+    }
123 123
 }
Please login to merge, or discard this patch.
includes/class-wpinv-session-handler.php 1 patch
Indentation   +277 added lines, -277 removed lines patch added patch discarded remove patch
@@ -12,125 +12,125 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class WPInv_Session_Handler extends WPInv_Session {
14 14
 
15
-	/**
16
-	 * Cookie name used for the session.
17
-	 *
18
-	 * @var string cookie name
19
-	 */
20
-	protected $_cookie;
21
-
22
-	/**
23
-	 * Stores session expiry.
24
-	 *
25
-	 * @var int session due to expire timestamp
26
-	 */
27
-	protected $_session_expiring;
28
-
29
-	/**
30
-	 * Stores session due to expire timestamp.
31
-	 *
32
-	 * @var string session expiration timestamp
33
-	 */
34
-	protected $_session_expiration;
35
-
36
-	/**
37
-	 * True when the cookie exists.
38
-	 *
39
-	 * @var bool Based on whether a cookie exists.
40
-	 */
41
-	protected $_has_cookie = false;
42
-
43
-	/**
44
-	 * Table name for session data.
45
-	 *
46
-	 * @var string Custom session table name
47
-	 */
48
-	protected $_table;
49
-
50
-	/**
51
-	 * Constructor for the session class.
52
-	 */
53
-	public function __construct() {
54
-
55
-	    $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH );
15
+    /**
16
+     * Cookie name used for the session.
17
+     *
18
+     * @var string cookie name
19
+     */
20
+    protected $_cookie;
21
+
22
+    /**
23
+     * Stores session expiry.
24
+     *
25
+     * @var int session due to expire timestamp
26
+     */
27
+    protected $_session_expiring;
28
+
29
+    /**
30
+     * Stores session due to expire timestamp.
31
+     *
32
+     * @var string session expiration timestamp
33
+     */
34
+    protected $_session_expiration;
35
+
36
+    /**
37
+     * True when the cookie exists.
38
+     *
39
+     * @var bool Based on whether a cookie exists.
40
+     */
41
+    protected $_has_cookie = false;
42
+
43
+    /**
44
+     * Table name for session data.
45
+     *
46
+     * @var string Custom session table name
47
+     */
48
+    protected $_table;
49
+
50
+    /**
51
+     * Constructor for the session class.
52
+     */
53
+    public function __construct() {
54
+
55
+        $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH );
56 56
         add_action( 'init', array( $this, 'init' ), -1 );
57
-	}
58
-
59
-	/**
60
-	 * Init hooks and session data.
61
-	 *
62
-	 * @since 3.3.0
63
-	 */
64
-	public function init() {
65
-		$this->init_session_cookie();
66
-
67
-		add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 );
68
-		add_action( 'shutdown', array( $this, 'save_data' ), 20 );
69
-		add_action( 'wp_logout', array( $this, 'destroy_session' ) );
70
-
71
-		if ( ! is_user_logged_in() ) {
72
-			add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) );
73
-		}
74
-	}
75
-
76
-	/**
77
-	 * Setup cookie and customer ID.
78
-	 *
79
-	 * @since 3.6.0
80
-	 */
81
-	public function init_session_cookie() {
82
-		$cookie = $this->get_session_cookie();
83
-
84
-		if ( $cookie ) {
85
-			$this->_customer_id        = $cookie[0];
86
-			$this->_session_expiration = $cookie[1];
87
-			$this->_session_expiring   = $cookie[2];
88
-			$this->_has_cookie         = true;
89
-			$this->_data               = $this->get_session_data();
90
-
91
-			// If the user logs in, update session.
92
-			if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) {
93
-				$this->_customer_id = get_current_user_id();
94
-				$this->_dirty       = true;
95
-				$this->save_data();
96
-				$this->set_customer_session_cookie( true );
97
-			}
98
-
99
-			// Update session if its close to expiring.
100
-			if ( time() > $this->_session_expiring ) {
101
-				$this->set_session_expiration();
102
-				$this->update_session_timestamp( $this->_customer_id, $this->_session_expiration );
103
-			}
104
-		} else {
105
-			$this->set_session_expiration();
106
-			$this->_customer_id = $this->generate_customer_id();
107
-			$this->_data        = $this->get_session_data();
108
-		}
109
-	}
110
-
111
-	/**
112
-	 * Sets the session cookie on-demand (usually after adding an item to the cart).
113
-	 *
114
-	 * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set.
115
-	 *
116
-	 * Warning: Cookies will only be set if this is called before the headers are sent.
117
-	 *
118
-	 * @param bool $set Should the session cookie be set.
119
-	 */
120
-	public function set_customer_session_cookie( $set ) {
121
-		if ( $set ) {
122
-			$to_hash           = $this->_customer_id . '|' . $this->_session_expiration;
123
-			$cookie_hash       = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
124
-			$cookie_value      = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash;
125
-			$this->_has_cookie = true;
126
-
127
-			if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) {
128
-				$this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true );
129
-			}
130
-		}
131
-	}
132
-
133
-	public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false){
57
+    }
58
+
59
+    /**
60
+     * Init hooks and session data.
61
+     *
62
+     * @since 3.3.0
63
+     */
64
+    public function init() {
65
+        $this->init_session_cookie();
66
+
67
+        add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 );
68
+        add_action( 'shutdown', array( $this, 'save_data' ), 20 );
69
+        add_action( 'wp_logout', array( $this, 'destroy_session' ) );
70
+
71
+        if ( ! is_user_logged_in() ) {
72
+            add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) );
73
+        }
74
+    }
75
+
76
+    /**
77
+     * Setup cookie and customer ID.
78
+     *
79
+     * @since 3.6.0
80
+     */
81
+    public function init_session_cookie() {
82
+        $cookie = $this->get_session_cookie();
83
+
84
+        if ( $cookie ) {
85
+            $this->_customer_id        = $cookie[0];
86
+            $this->_session_expiration = $cookie[1];
87
+            $this->_session_expiring   = $cookie[2];
88
+            $this->_has_cookie         = true;
89
+            $this->_data               = $this->get_session_data();
90
+
91
+            // If the user logs in, update session.
92
+            if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) {
93
+                $this->_customer_id = get_current_user_id();
94
+                $this->_dirty       = true;
95
+                $this->save_data();
96
+                $this->set_customer_session_cookie( true );
97
+            }
98
+
99
+            // Update session if its close to expiring.
100
+            if ( time() > $this->_session_expiring ) {
101
+                $this->set_session_expiration();
102
+                $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration );
103
+            }
104
+        } else {
105
+            $this->set_session_expiration();
106
+            $this->_customer_id = $this->generate_customer_id();
107
+            $this->_data        = $this->get_session_data();
108
+        }
109
+    }
110
+
111
+    /**
112
+     * Sets the session cookie on-demand (usually after adding an item to the cart).
113
+     *
114
+     * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set.
115
+     *
116
+     * Warning: Cookies will only be set if this is called before the headers are sent.
117
+     *
118
+     * @param bool $set Should the session cookie be set.
119
+     */
120
+    public function set_customer_session_cookie( $set ) {
121
+        if ( $set ) {
122
+            $to_hash           = $this->_customer_id . '|' . $this->_session_expiration;
123
+            $cookie_hash       = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
124
+            $cookie_value      = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash;
125
+            $this->_has_cookie = true;
126
+
127
+            if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) {
128
+                $this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true );
129
+            }
130
+        }
131
+    }
132
+
133
+    public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false){
134 134
         if ( ! headers_sent() ) {
135 135
             setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters( 'wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure ) );
136 136
         } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
@@ -139,96 +139,96 @@  discard block
 block discarded – undo
139 139
         }
140 140
     }
141 141
 
142
-	/**
143
-	 * Should the session cookie be secure?
144
-	 *
145
-	 * @since 3.6.0
146
-	 * @return bool
147
-	 */
148
-	protected function use_secure_cookie() {
142
+    /**
143
+     * Should the session cookie be secure?
144
+     *
145
+     * @since 3.6.0
146
+     * @return bool
147
+     */
148
+    protected function use_secure_cookie() {
149 149
         $is_https = false !== strstr( get_option( 'home' ), 'https:' );
150
-		return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() );
151
-	}
152
-
153
-	/**
154
-	 * Return true if the current user has an active session, i.e. a cookie to retrieve values.
155
-	 *
156
-	 * @return bool
157
-	 */
158
-	public function has_session() {
159
-		return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine.
160
-	}
161
-
162
-	/**
163
-	 * Set session expiration.
164
-	 */
165
-	public function set_session_expiration() {
166
-		$this->_session_expiring   = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours.
167
-		$this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours.
168
-	}
169
-
170
-	/**
171
-	 * Generate a unique customer ID for guests, or return user ID if logged in.
172
-	 *
173
-	 * Uses Portable PHP password hashing framework to generate a unique cryptographically strong ID.
174
-	 *
175
-	 * @return string
176
-	 */
177
-	public function generate_customer_id() {
178
-		$customer_id = '';
179
-
180
-		if ( is_user_logged_in() ) {
181
-			$customer_id = get_current_user_id();
182
-		}
183
-
184
-		if ( empty( $customer_id ) ) {
150
+        return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() );
151
+    }
152
+
153
+    /**
154
+     * Return true if the current user has an active session, i.e. a cookie to retrieve values.
155
+     *
156
+     * @return bool
157
+     */
158
+    public function has_session() {
159
+        return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine.
160
+    }
161
+
162
+    /**
163
+     * Set session expiration.
164
+     */
165
+    public function set_session_expiration() {
166
+        $this->_session_expiring   = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours.
167
+        $this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours.
168
+    }
169
+
170
+    /**
171
+     * Generate a unique customer ID for guests, or return user ID if logged in.
172
+     *
173
+     * Uses Portable PHP password hashing framework to generate a unique cryptographically strong ID.
174
+     *
175
+     * @return string
176
+     */
177
+    public function generate_customer_id() {
178
+        $customer_id = '';
179
+
180
+        if ( is_user_logged_in() ) {
181
+            $customer_id = get_current_user_id();
182
+        }
183
+
184
+        if ( empty( $customer_id ) ) {
185 185
             $customer_id = wp_create_nonce('wpinv-session-customer-id');
186
-		}
187
-
188
-		return $customer_id;
189
-	}
190
-
191
-	/**
192
-	 * Get the session cookie, if set. Otherwise return false.
193
-	 *
194
-	 * Session cookies without a customer ID are invalid.
195
-	 *
196
-	 * @return bool|array
197
-	 */
198
-	public function get_session_cookie() {
199
-		$cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine.
200
-
201
-		if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) {
202
-			return false;
203
-		}
204
-
205
-		list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value );
206
-
207
-		if ( empty( $customer_id ) ) {
208
-			return false;
209
-		}
210
-
211
-		// Validate hash.
212
-		$to_hash = $customer_id . '|' . $session_expiration;
213
-		$hash    = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
214
-
215
-		if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) {
216
-			return false;
217
-		}
218
-
219
-		return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash );
220
-	}
221
-
222
-	/**
223
-	 * Get session data.
224
-	 *
225
-	 * @return array
226
-	 */
227
-	public function get_session_data() {
228
-		return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array();
229
-	}
230
-
231
-	public function generate_key($customer_id){
186
+        }
187
+
188
+        return $customer_id;
189
+    }
190
+
191
+    /**
192
+     * Get the session cookie, if set. Otherwise return false.
193
+     *
194
+     * Session cookies without a customer ID are invalid.
195
+     *
196
+     * @return bool|array
197
+     */
198
+    public function get_session_cookie() {
199
+        $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine.
200
+
201
+        if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) {
202
+            return false;
203
+        }
204
+
205
+        list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value );
206
+
207
+        if ( empty( $customer_id ) ) {
208
+            return false;
209
+        }
210
+
211
+        // Validate hash.
212
+        $to_hash = $customer_id . '|' . $session_expiration;
213
+        $hash    = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
214
+
215
+        if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) {
216
+            return false;
217
+        }
218
+
219
+        return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash );
220
+    }
221
+
222
+    /**
223
+     * Get session data.
224
+     *
225
+     * @return array
226
+     */
227
+    public function get_session_data() {
228
+        return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array();
229
+    }
230
+
231
+    public function generate_key($customer_id){
232 232
         if(!$customer_id){
233 233
             return;
234 234
         }
@@ -236,62 +236,62 @@  discard block
 block discarded – undo
236 236
         return 'wpi_trans_'.$customer_id;
237 237
     }
238 238
 
239
-	/**
240
-	 * Save data.
241
-	 */
242
-	public function save_data() {
243
-		// Dirty if something changed - prevents saving nothing new.
244
-		if ( $this->_dirty && $this->has_session() ) {
239
+    /**
240
+     * Save data.
241
+     */
242
+    public function save_data() {
243
+        // Dirty if something changed - prevents saving nothing new.
244
+        if ( $this->_dirty && $this->has_session() ) {
245 245
 
246 246
             set_transient( $this->generate_key($this->_customer_id), $this->_data, $this->_session_expiration);
247 247
 
248
-			$this->_dirty = false;
249
-		}
250
-	}
251
-
252
-	/**
253
-	 * Destroy all session data.
254
-	 */
255
-	public function destroy_session() {
256
-		$this->delete_session( $this->_customer_id );
257
-		$this->forget_session();
258
-	}
259
-
260
-	/**
261
-	 * Forget all session data without destroying it.
262
-	 */
263
-	public function forget_session() {
264
-		$this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true );
265
-
266
-		wpinv_empty_cart();
267
-
268
-		$this->_data        = array();
269
-		$this->_dirty       = false;
270
-		$this->_customer_id = $this->generate_customer_id();
271
-	}
272
-
273
-	/**
274
-	 * When a user is logged out, ensure they have a unique nonce by using the customer/session ID.
275
-	 *
276
-	 * @param int $uid User ID.
277
-	 * @return string
278
-	 */
279
-	public function nonce_user_logged_out( $uid ) {
280
-		return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid;
281
-	}
282
-
283
-	/**
284
-	 * Returns the session.
285
-	 *
286
-	 * @param string $customer_id Customer ID.
287
-	 * @param mixed  $default Default session value.
288
-	 * @return string|array
289
-	 */
290
-	public function get_session( $customer_id, $default = false ) {
291
-
292
-		if ( defined( 'WP_SETUP_CONFIG' ) ) {
293
-			return array();
294
-		}
248
+            $this->_dirty = false;
249
+        }
250
+    }
251
+
252
+    /**
253
+     * Destroy all session data.
254
+     */
255
+    public function destroy_session() {
256
+        $this->delete_session( $this->_customer_id );
257
+        $this->forget_session();
258
+    }
259
+
260
+    /**
261
+     * Forget all session data without destroying it.
262
+     */
263
+    public function forget_session() {
264
+        $this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true );
265
+
266
+        wpinv_empty_cart();
267
+
268
+        $this->_data        = array();
269
+        $this->_dirty       = false;
270
+        $this->_customer_id = $this->generate_customer_id();
271
+    }
272
+
273
+    /**
274
+     * When a user is logged out, ensure they have a unique nonce by using the customer/session ID.
275
+     *
276
+     * @param int $uid User ID.
277
+     * @return string
278
+     */
279
+    public function nonce_user_logged_out( $uid ) {
280
+        return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid;
281
+    }
282
+
283
+    /**
284
+     * Returns the session.
285
+     *
286
+     * @param string $customer_id Customer ID.
287
+     * @param mixed  $default Default session value.
288
+     * @return string|array
289
+     */
290
+    public function get_session( $customer_id, $default = false ) {
291
+
292
+        if ( defined( 'WP_SETUP_CONFIG' ) ) {
293
+            return array();
294
+        }
295 295
 
296 296
         if ( !is_user_logged_in() ) {
297 297
             if(!wp_verify_nonce( $customer_id, 'wpinv-session-customer-id' )){
@@ -306,32 +306,32 @@  discard block
 block discarded – undo
306 306
             $value = $default;
307 307
         }
308 308
 
309
-		return maybe_unserialize( $value );
310
-	}
309
+        return maybe_unserialize( $value );
310
+    }
311 311
 
312
-	/**
313
-	 * Delete the session from the cache and database.
314
-	 *
315
-	 * @param int $customer_id Customer ID.
316
-	 */
317
-	public function delete_session( $customer_id ) {
312
+    /**
313
+     * Delete the session from the cache and database.
314
+     *
315
+     * @param int $customer_id Customer ID.
316
+     */
317
+    public function delete_session( $customer_id ) {
318 318
 
319 319
         $key = $this->generate_key($customer_id);
320 320
 
321
-		delete_transient($key);
322
-	}
321
+        delete_transient($key);
322
+    }
323 323
 
324
-	/**
325
-	 * Update the session expiry timestamp.
326
-	 *
327
-	 * @param string $customer_id Customer ID.
328
-	 * @param int    $timestamp Timestamp to expire the cookie.
329
-	 */
330
-	public function update_session_timestamp( $customer_id, $timestamp ) {
324
+    /**
325
+     * Update the session expiry timestamp.
326
+     *
327
+     * @param string $customer_id Customer ID.
328
+     * @param int    $timestamp Timestamp to expire the cookie.
329
+     */
330
+    public function update_session_timestamp( $customer_id, $timestamp ) {
331 331
 
332 332
         set_transient( $this->generate_key($customer_id), maybe_serialize( $this->_data ), $timestamp);
333 333
 
334
-	}
334
+    }
335 335
 }
336 336
 
337 337
 global $wpi_session;
Please login to merge, or discard this patch.
includes/class-wpinv-invoice.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1355,10 +1355,10 @@
 block discarded – undo
1355 1355
                         $data['cart_details'][$key]['price']      = wpinv_round_amount( $item_total );
1356 1356
                     }
1357 1357
 
1358
-	                $total = $data['subtotal'] - $data['discount'] + $data['tax'];
1359
-	                if ( $total < 0 ) {
1360
-		                $total = 0;
1361
-	                }
1358
+                    $total = $data['subtotal'] - $data['discount'] + $data['tax'];
1359
+                    if ( $total < 0 ) {
1360
+                        $total = 0;
1361
+                    }
1362 1362
 
1363 1363
                     $data['subtotal'] = wpinv_round_amount( $cart_subtotal );
1364 1364
                     $data['discount'] = wpinv_round_amount( $cart_discount );
Please login to merge, or discard this patch.
includes/wpinv-template-functions.php 1 patch
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -103,29 +103,29 @@  discard block
 block discarded – undo
103 103
 
104 104
 function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
105 105
     if ( ! empty( $args ) && is_array( $args ) ) {
106
-		extract( $args );
107
-	}
106
+        extract( $args );
107
+    }
108 108
 
109
-	$located = wpinv_locate_template( $template_name, $template_path, $default_path );
110
-	// Allow 3rd party plugin filter template file from their plugin.
111
-	$located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path );
109
+    $located = wpinv_locate_template( $template_name, $template_path, $default_path );
110
+    // Allow 3rd party plugin filter template file from their plugin.
111
+    $located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path );
112 112
 
113
-	if ( ! file_exists( $located ) ) {
113
+    if ( ! file_exists( $located ) ) {
114 114
         _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
115
-		return;
116
-	}
115
+        return;
116
+    }
117 117
 
118
-	do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args );
118
+    do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args );
119 119
 
120
-	include( $located );
120
+    include( $located );
121 121
 
122
-	do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args );
122
+    do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args );
123 123
 }
124 124
 
125 125
 function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
126
-	ob_start();
127
-	wpinv_get_template( $template_name, $args, $template_path, $default_path );
128
-	return ob_get_clean();
126
+    ob_start();
127
+    wpinv_get_template( $template_name, $args, $template_path, $default_path );
128
+    return ob_get_clean();
129 129
 }
130 130
 
131 131
 function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) {
@@ -155,126 +155,126 @@  discard block
 block discarded – undo
155 155
 }
156 156
 
157 157
 function wpinv_get_template_part( $slug, $name = null, $load = true ) {
158
-	do_action( 'get_template_part_' . $slug, $slug, $name );
158
+    do_action( 'get_template_part_' . $slug, $slug, $name );
159 159
 
160
-	// Setup possible parts
161
-	$templates = array();
162
-	if ( isset( $name ) )
163
-		$templates[] = $slug . '-' . $name . '.php';
164
-	$templates[] = $slug . '.php';
160
+    // Setup possible parts
161
+    $templates = array();
162
+    if ( isset( $name ) )
163
+        $templates[] = $slug . '-' . $name . '.php';
164
+    $templates[] = $slug . '.php';
165 165
 
166
-	// Allow template parts to be filtered
167
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
166
+    // Allow template parts to be filtered
167
+    $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
168 168
 
169
-	// Return the part that is found
170
-	return wpinv_locate_tmpl( $templates, $load, false );
169
+    // Return the part that is found
170
+    return wpinv_locate_tmpl( $templates, $load, false );
171 171
 }
172 172
 
173 173
 function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
174
-	// No file found yet
175
-	$located = false;
174
+    // No file found yet
175
+    $located = false;
176 176
 
177
-	// Try to find a template file
178
-	foreach ( (array)$template_names as $template_name ) {
177
+    // Try to find a template file
178
+    foreach ( (array)$template_names as $template_name ) {
179 179
 
180
-		// Continue if template is empty
181
-		if ( empty( $template_name ) )
182
-			continue;
180
+        // Continue if template is empty
181
+        if ( empty( $template_name ) )
182
+            continue;
183 183
 
184
-		// Trim off any slashes from the template name
185
-		$template_name = ltrim( $template_name, '/' );
184
+        // Trim off any slashes from the template name
185
+        $template_name = ltrim( $template_name, '/' );
186 186
 
187
-		// try locating this template file by looping through the template paths
188
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
187
+        // try locating this template file by looping through the template paths
188
+        foreach( wpinv_get_theme_template_paths() as $template_path ) {
189 189
 
190
-			if( file_exists( $template_path . $template_name ) ) {
191
-				$located = $template_path . $template_name;
192
-				break;
193
-			}
194
-		}
190
+            if( file_exists( $template_path . $template_name ) ) {
191
+                $located = $template_path . $template_name;
192
+                break;
193
+            }
194
+        }
195 195
 
196
-		if( !empty( $located ) ) {
197
-			break;
198
-		}
199
-	}
196
+        if( !empty( $located ) ) {
197
+            break;
198
+        }
199
+    }
200 200
 
201
-	if ( ( true == $load ) && ! empty( $located ) )
202
-		load_template( $located, $require_once );
201
+    if ( ( true == $load ) && ! empty( $located ) )
202
+        load_template( $located, $require_once );
203 203
 
204
-	return $located;
204
+    return $located;
205 205
 }
206 206
 
207 207
 function wpinv_get_theme_template_paths() {
208
-	$template_dir = wpinv_get_theme_template_dir_name();
208
+    $template_dir = wpinv_get_theme_template_dir_name();
209 209
 
210
-	$file_paths = array(
211
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
212
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
213
-		100 => wpinv_get_templates_dir()
214
-	);
210
+    $file_paths = array(
211
+        1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
212
+        10 => trailingslashit( get_template_directory() ) . $template_dir,
213
+        100 => wpinv_get_templates_dir()
214
+    );
215 215
 
216
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
216
+    $file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
217 217
 
218
-	// sort the file paths based on priority
219
-	ksort( $file_paths, SORT_NUMERIC );
218
+    // sort the file paths based on priority
219
+    ksort( $file_paths, SORT_NUMERIC );
220 220
 
221
-	return array_map( 'trailingslashit', $file_paths );
221
+    return array_map( 'trailingslashit', $file_paths );
222 222
 }
223 223
 
224 224
 function wpinv_get_theme_template_dir_name() {
225
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
225
+    return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
226 226
 }
227 227
 
228 228
 function wpinv_checkout_meta_tags() {
229 229
 
230
-	$pages   = array();
231
-	$pages[] = wpinv_get_option( 'success_page' );
232
-	$pages[] = wpinv_get_option( 'failure_page' );
233
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
234
-	$pages[] = wpinv_get_option( 'invoice_subscription_page' );
230
+    $pages   = array();
231
+    $pages[] = wpinv_get_option( 'success_page' );
232
+    $pages[] = wpinv_get_option( 'failure_page' );
233
+    $pages[] = wpinv_get_option( 'invoice_history_page' );
234
+    $pages[] = wpinv_get_option( 'invoice_subscription_page' );
235 235
 
236
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
237
-		return;
238
-	}
236
+    if( !wpinv_is_checkout() && !is_page( $pages ) ) {
237
+        return;
238
+    }
239 239
 
240
-	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
240
+    echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
241 241
 }
242 242
 add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
243 243
 
244 244
 function wpinv_add_body_classes( $class ) {
245
-	$classes = (array)$class;
245
+    $classes = (array)$class;
246 246
 
247
-	if( wpinv_is_checkout() ) {
248
-		$classes[] = 'wpinv-checkout';
249
-		$classes[] = 'wpinv-page';
250
-	}
247
+    if( wpinv_is_checkout() ) {
248
+        $classes[] = 'wpinv-checkout';
249
+        $classes[] = 'wpinv-page';
250
+    }
251 251
 
252
-	if( wpinv_is_success_page() ) {
253
-		$classes[] = 'wpinv-success';
254
-		$classes[] = 'wpinv-page';
255
-	}
252
+    if( wpinv_is_success_page() ) {
253
+        $classes[] = 'wpinv-success';
254
+        $classes[] = 'wpinv-page';
255
+    }
256 256
 
257
-	if( wpinv_is_failed_transaction_page() ) {
258
-		$classes[] = 'wpinv-failed-transaction';
259
-		$classes[] = 'wpinv-page';
260
-	}
257
+    if( wpinv_is_failed_transaction_page() ) {
258
+        $classes[] = 'wpinv-failed-transaction';
259
+        $classes[] = 'wpinv-page';
260
+    }
261 261
 
262
-	if( wpinv_is_invoice_history_page() ) {
263
-		$classes[] = 'wpinv-history';
264
-		$classes[] = 'wpinv-page';
265
-	}
262
+    if( wpinv_is_invoice_history_page() ) {
263
+        $classes[] = 'wpinv-history';
264
+        $classes[] = 'wpinv-page';
265
+    }
266 266
 
267
-	if( wpinv_is_subscriptions_history_page() ) {
268
-		$classes[] = 'wpinv-subscription';
269
-		$classes[] = 'wpinv-page';
270
-	}
267
+    if( wpinv_is_subscriptions_history_page() ) {
268
+        $classes[] = 'wpinv-subscription';
269
+        $classes[] = 'wpinv-page';
270
+    }
271 271
 
272
-	if( wpinv_is_test_mode() ) {
273
-		$classes[] = 'wpinv-test-mode';
274
-		$classes[] = 'wpinv-page';
275
-	}
272
+    if( wpinv_is_test_mode() ) {
273
+        $classes[] = 'wpinv-test-mode';
274
+        $classes[] = 'wpinv-page';
275
+    }
276 276
 
277
-	return array_unique( $classes );
277
+    return array_unique( $classes );
278 278
 }
279 279
 add_filter( 'body_class', 'wpinv_add_body_classes' );
280 280
 
@@ -1030,7 +1030,7 @@  discard block
 block discarded – undo
1030 1030
 
1031 1031
                     $item       = $item_id ? new WPInv_Item( $item_id ) : NULL;
1032 1032
                     $summary    = '';
1033
-	                $item_name    = '';
1033
+                    $item_name    = '';
1034 1034
                     $cols       = 3;
1035 1035
                     if ( !empty($item) ) {
1036 1036
                         $item_name  = $item->get_name();
@@ -1410,7 +1410,7 @@  discard block
 block discarded – undo
1410 1410
 add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 );
1411 1411
 
1412 1412
 function wpinv_empty_cart_message() {
1413
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1413
+    return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1414 1414
 }
1415 1415
 
1416 1416
 /**
@@ -1420,7 +1420,7 @@  discard block
 block discarded – undo
1420 1420
  * @return void
1421 1421
  */
1422 1422
 function wpinv_empty_checkout_cart() {
1423
-	echo wpinv_empty_cart_message();
1423
+    echo wpinv_empty_cart_message();
1424 1424
 }
1425 1425
 add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1426 1426
 
Please login to merge, or discard this patch.
includes/wpinv-invoice-functions.php 1 patch
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -669,7 +669,7 @@  discard block
 block discarded – undo
669 669
 }
670 670
 
671 671
 function wpinv_get_payment_key( $invoice_id = 0 ) {
672
-	$invoice = new WPInv_Invoice( $invoice_id );
672
+    $invoice = new WPInv_Invoice( $invoice_id );
673 673
     return $invoice->get_key();
674 674
 }
675 675
 
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
         return false;
920 920
     }
921 921
     $invoice = wpinv_get_invoice_cart();
922
-	if ( empty( $invoice ) ) {
922
+    if ( empty( $invoice ) ) {
923 923
         return false;
924 924
     }
925 925
 
@@ -1216,20 +1216,20 @@  discard block
 block discarded – undo
1216 1216
 }
1217 1217
 
1218 1218
 function wpinv_checkout_get_cc_info() {
1219
-	$cc_info = array();
1220
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
1221
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
1222
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
1223
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
1224
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
1225
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
1226
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
1227
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
1228
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
1229
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
1230
-
1231
-	// Return cc info
1232
-	return $cc_info;
1219
+    $cc_info = array();
1220
+    $cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
1221
+    $cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
1222
+    $cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
1223
+    $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
1224
+    $cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
1225
+    $cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
1226
+    $cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
1227
+    $cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
1228
+    $cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
1229
+    $cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
1230
+
1231
+    // Return cc info
1232
+    return $cc_info;
1233 1233
 }
1234 1234
 
1235 1235
 function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
@@ -1436,7 +1436,7 @@  discard block
 block discarded – undo
1436 1436
         $required_fields  = wpinv_checkout_required_fields();
1437 1437
 
1438 1438
         // Loop through required fields and show error messages
1439
-         if ( !empty( $required_fields ) ) {
1439
+            if ( !empty( $required_fields ) ) {
1440 1440
             foreach ( $required_fields as $field_name => $value ) {
1441 1441
                 if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
1442 1442
                     wpinv_set_error( $value['error_id'], $value['error_message'] );
@@ -1539,7 +1539,7 @@  discard block
 block discarded – undo
1539 1539
 }
1540 1540
 
1541 1541
 function wpinv_get_checkout_session() {
1542
-	global $wpi_session;
1542
+    global $wpi_session;
1543 1543
     
1544 1544
     return $wpi_session->get( 'wpinv_checkout' );
1545 1545
 }
@@ -1620,7 +1620,7 @@  discard block
 block discarded – undo
1620 1620
         $response['data']['taxf']       = $invoice->get_tax( true );
1621 1621
         $response['data']['total']      = $invoice->get_total();
1622 1622
         $response['data']['totalf']     = $invoice->get_total( true );
1623
-	    $response['data']['free']       = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false;
1623
+        $response['data']['free']       = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false;
1624 1624
 
1625 1625
         wp_send_json( $response );
1626 1626
     }
@@ -1905,57 +1905,57 @@  discard block
 block discarded – undo
1905 1905
 }
1906 1906
 
1907 1907
 function wpinv_get_invoice_id_by_key( $key ) {
1908
-	global $wpdb;
1908
+    global $wpdb;
1909 1909
 
1910
-	$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 ) );
1910
+    $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 ) );
1911 1911
 
1912
-	if ( $invoice_id != NULL )
1913
-		return $invoice_id;
1912
+    if ( $invoice_id != NULL )
1913
+        return $invoice_id;
1914 1914
 
1915
-	return 0;
1915
+    return 0;
1916 1916
 }
1917 1917
 
1918 1918
 function wpinv_can_view_receipt( $invoice_key = '' ) {
1919
-	$return = false;
1919
+    $return = false;
1920 1920
 
1921
-	if ( empty( $invoice_key ) ) {
1922
-		return $return;
1923
-	}
1921
+    if ( empty( $invoice_key ) ) {
1922
+        return $return;
1923
+    }
1924 1924
 
1925
-	global $wpinv_receipt_args;
1925
+    global $wpinv_receipt_args;
1926 1926
 
1927
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1928
-	if ( isset( $_GET['invoice-id'] ) ) {
1929
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1930
-	}
1927
+    $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1928
+    if ( isset( $_GET['invoice-id'] ) ) {
1929
+        $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1930
+    }
1931 1931
 
1932
-	if ( empty( $wpinv_receipt_args['id'] ) ) {
1933
-		return $return;
1934
-	}
1932
+    if ( empty( $wpinv_receipt_args['id'] ) ) {
1933
+        return $return;
1934
+    }
1935 1935
 
1936
-	$invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] );
1937
-	if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) {
1938
-		return $return;
1939
-	}
1936
+    $invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] );
1937
+    if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) {
1938
+        return $return;
1939
+    }
1940 1940
 
1941
-	if ( is_user_logged_in() ) {
1942
-		if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) {
1943
-			$return = true;
1944
-		}
1945
-	}
1941
+    if ( is_user_logged_in() ) {
1942
+        if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) {
1943
+            $return = true;
1944
+        }
1945
+    }
1946 1946
 
1947
-	$session = wpinv_get_checkout_session();
1948
-	if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) {
1949
-		$check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key'];
1947
+    $session = wpinv_get_checkout_session();
1948
+    if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) {
1949
+        $check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key'];
1950 1950
 
1951
-		if ( wpinv_require_login_to_checkout() ) {
1952
-			$return = $return && $check_key === $invoice_key;
1953
-		} else {
1954
-			$return = $check_key === $invoice_key;
1955
-		}
1956
-	}
1951
+        if ( wpinv_require_login_to_checkout() ) {
1952
+            $return = $return && $check_key === $invoice_key;
1953
+        } else {
1954
+            $return = $check_key === $invoice_key;
1955
+        }
1956
+    }
1957 1957
 
1958
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1958
+    return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1959 1959
 }
1960 1960
 
1961 1961
 function wpinv_pay_for_invoice() {
@@ -2263,14 +2263,14 @@  discard block
 block discarded – undo
2263 2263
 
2264 2264
     if ( isset( $_GET['invoice_key'] ) || is_singular( 'wpi_invoice' ) || is_singular( 'wpi_quote' ) ) {
2265 2265
         $invoice_key = isset( $_GET['invoice_key'] ) ? urldecode($_GET['invoice_key']) : '';
2266
-	    global $post;
2266
+        global $post;
2267 2267
 
2268 2268
         if(!empty($invoice_key)){
2269
-	        $invoice_id = wpinv_get_invoice_id_by_key($invoice_key);
2269
+            $invoice_id = wpinv_get_invoice_id_by_key($invoice_key);
2270 2270
         } else if(!empty( $post ) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) {
2271
-			$invoice_id = $post->ID;
2271
+            $invoice_id = $post->ID;
2272 2272
         } else {
2273
-        	return;
2273
+            return;
2274 2274
         }
2275 2275
 
2276 2276
         $invoice = new WPInv_Invoice($invoice_id);
@@ -2279,17 +2279,17 @@  discard block
 block discarded – undo
2279 2279
             return;
2280 2280
         }
2281 2281
 
2282
-	    if ( is_user_logged_in() ) {
2283
-		    if ( (int)$invoice->get_user_id() === get_current_user_id() ) {
2284
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2285
-		    } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2286
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2287
-		    }
2288
-	    } else {
2289
-		    if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2290
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2291
-		    }
2292
-	    }
2282
+        if ( is_user_logged_in() ) {
2283
+            if ( (int)$invoice->get_user_id() === get_current_user_id() ) {
2284
+                update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2285
+            } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2286
+                update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2287
+            }
2288
+        } else {
2289
+            if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2290
+                update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2291
+            }
2292
+        }
2293 2293
     }
2294 2294
 
2295 2295
 }
Please login to merge, or discard this patch.
includes/admin/admin-meta-boxes.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@
 block discarded – undo
29 29
     add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high' );
30 30
     add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' );
31 31
 
32
-	remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal');
32
+    remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal');
33 33
 }
34 34
 add_action( 'add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2 );
35 35
 
Please login to merge, or discard this patch.