@@ -130,6 +130,10 @@ discard block |
||
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
133 | + /** |
|
134 | + * @param string $name |
|
135 | + * @param string $value |
|
136 | + */ |
|
133 | 137 | public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false){ |
134 | 138 | if ( ! headers_sent() ) { |
135 | 139 | setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters( 'wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure ) ); |
@@ -274,7 +278,7 @@ discard block |
||
274 | 278 | * When a user is logged out, ensure they have a unique nonce by using the customer/session ID. |
275 | 279 | * |
276 | 280 | * @param int $uid User ID. |
277 | - * @return string |
|
281 | + * @return integer |
|
278 | 282 | */ |
279 | 283 | public function nonce_user_logged_out( $uid ) { |
280 | 284 | return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid; |
@@ -12,125 +12,125 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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; |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Session handler class. |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public function __construct() { |
54 | 54 | |
55 | - $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH ); |
|
56 | - add_action( 'init', array( $this, 'init' ), -1 ); |
|
55 | + $this->_cookie = apply_filters('wpinv_cookie', 'wpinv_session_' . COOKIEHASH); |
|
56 | + add_action('init', array($this, 'init'), -1); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -64,12 +64,12 @@ discard block |
||
64 | 64 | public function init() { |
65 | 65 | $this->init_session_cookie(); |
66 | 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' ) ); |
|
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 | 70 | |
71 | - if ( ! is_user_logged_in() ) { |
|
72 | - add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) ); |
|
71 | + if (!is_user_logged_in()) { |
|
72 | + add_filter('nonce_user_logged_out', array($this, 'nonce_user_logged_out')); |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | public function init_session_cookie() { |
82 | 82 | $cookie = $this->get_session_cookie(); |
83 | 83 | |
84 | - if ( $cookie ) { |
|
84 | + if ($cookie) { |
|
85 | 85 | $this->_customer_id = $cookie[0]; |
86 | 86 | $this->_session_expiration = $cookie[1]; |
87 | 87 | $this->_session_expiring = $cookie[2]; |
@@ -89,17 +89,17 @@ discard block |
||
89 | 89 | $this->_data = $this->get_session_data(); |
90 | 90 | |
91 | 91 | // If the user logs in, update session. |
92 | - if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) { |
|
92 | + if (is_user_logged_in() && get_current_user_id() != $this->_customer_id) { |
|
93 | 93 | $this->_customer_id = get_current_user_id(); |
94 | 94 | $this->_dirty = true; |
95 | 95 | $this->save_data(); |
96 | - $this->set_customer_session_cookie( true ); |
|
96 | + $this->set_customer_session_cookie(true); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | // Update session if its close to expiring. |
100 | - if ( time() > $this->_session_expiring ) { |
|
100 | + if (time() > $this->_session_expiring) { |
|
101 | 101 | $this->set_session_expiration(); |
102 | - $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration ); |
|
102 | + $this->update_session_timestamp($this->_customer_id, $this->_session_expiration); |
|
103 | 103 | } |
104 | 104 | } else { |
105 | 105 | $this->set_session_expiration(); |
@@ -117,25 +117,25 @@ discard block |
||
117 | 117 | * |
118 | 118 | * @param bool $set Should the session cookie be set. |
119 | 119 | */ |
120 | - public function set_customer_session_cookie( $set ) { |
|
121 | - if ( $set ) { |
|
120 | + public function set_customer_session_cookie($set) { |
|
121 | + if ($set) { |
|
122 | 122 | $to_hash = $this->_customer_id . '|' . $this->_session_expiration; |
123 | - $cookie_hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
123 | + $cookie_hash = hash_hmac('md5', $to_hash, wp_hash($to_hash)); |
|
124 | 124 | $cookie_value = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash; |
125 | 125 | $this->_has_cookie = true; |
126 | 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 ); |
|
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 | 129 | } |
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
133 | - public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false){ |
|
134 | - if ( ! headers_sent() ) { |
|
135 | - setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters( 'wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure ) ); |
|
136 | - } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
137 | - headers_sent( $file, $line ); |
|
138 | - trigger_error( "{$name} cookie cannot be set - headers already sent by {$file} on line {$line}", E_USER_NOTICE ); // @codingStandardsIgnoreLine |
|
133 | + public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false) { |
|
134 | + if (!headers_sent()) { |
|
135 | + setcookie($name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters('wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure)); |
|
136 | + } elseif (defined('WP_DEBUG') && WP_DEBUG) { |
|
137 | + headers_sent($file, $line); |
|
138 | + trigger_error("{$name} cookie cannot be set - headers already sent by {$file} on line {$line}", E_USER_NOTICE); // @codingStandardsIgnoreLine |
|
139 | 139 | } |
140 | 140 | } |
141 | 141 | |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | * @return bool |
147 | 147 | */ |
148 | 148 | protected function use_secure_cookie() { |
149 | - $is_https = false !== strstr( get_option( 'home' ), 'https:' ); |
|
150 | - return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() ); |
|
149 | + $is_https = false !== strstr(get_option('home'), 'https:'); |
|
150 | + return apply_filters('wpinv_session_use_secure_cookie', $is_https && is_ssl()); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -156,15 +156,15 @@ discard block |
||
156 | 156 | * @return bool |
157 | 157 | */ |
158 | 158 | public function has_session() { |
159 | - return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine. |
|
159 | + return isset($_COOKIE[$this->_cookie]) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine. |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
163 | 163 | * Set session expiration. |
164 | 164 | */ |
165 | 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. |
|
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 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -177,11 +177,11 @@ discard block |
||
177 | 177 | public function generate_customer_id() { |
178 | 178 | $customer_id = ''; |
179 | 179 | |
180 | - if ( is_user_logged_in() ) { |
|
180 | + if (is_user_logged_in()) { |
|
181 | 181 | $customer_id = get_current_user_id(); |
182 | 182 | } |
183 | 183 | |
184 | - if ( empty( $customer_id ) ) { |
|
184 | + if (empty($customer_id)) { |
|
185 | 185 | $customer_id = wp_create_nonce('wpinv-session-customer-id'); |
186 | 186 | } |
187 | 187 | |
@@ -196,27 +196,27 @@ discard block |
||
196 | 196 | * @return bool|array |
197 | 197 | */ |
198 | 198 | public function get_session_cookie() { |
199 | - $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine. |
|
199 | + $cookie_value = isset($_COOKIE[$this->_cookie]) ? wp_unslash($_COOKIE[$this->_cookie]) : false; // @codingStandardsIgnoreLine. |
|
200 | 200 | |
201 | - if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) { |
|
201 | + if (empty($cookie_value) || !is_string($cookie_value)) { |
|
202 | 202 | return false; |
203 | 203 | } |
204 | 204 | |
205 | - list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value ); |
|
205 | + list($customer_id, $session_expiration, $session_expiring, $cookie_hash) = explode('||', $cookie_value); |
|
206 | 206 | |
207 | - if ( empty( $customer_id ) ) { |
|
207 | + if (empty($customer_id)) { |
|
208 | 208 | return false; |
209 | 209 | } |
210 | 210 | |
211 | 211 | // Validate hash. |
212 | 212 | $to_hash = $customer_id . '|' . $session_expiration; |
213 | - $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
213 | + $hash = hash_hmac('md5', $to_hash, wp_hash($to_hash)); |
|
214 | 214 | |
215 | - if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) { |
|
215 | + if (empty($cookie_hash) || !hash_equals($hash, $cookie_hash)) { |
|
216 | 216 | return false; |
217 | 217 | } |
218 | 218 | |
219 | - return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash ); |
|
219 | + return array($customer_id, $session_expiration, $session_expiring, $cookie_hash); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -225,15 +225,15 @@ discard block |
||
225 | 225 | * @return array |
226 | 226 | */ |
227 | 227 | public function get_session_data() { |
228 | - return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array(); |
|
228 | + return $this->has_session() ? (array)$this->get_session($this->_customer_id) : array(); |
|
229 | 229 | } |
230 | 230 | |
231 | - public function generate_key($customer_id){ |
|
232 | - if(!$customer_id){ |
|
231 | + public function generate_key($customer_id) { |
|
232 | + if (!$customer_id) { |
|
233 | 233 | return; |
234 | 234 | } |
235 | 235 | |
236 | - return 'wpi_trans_'.$customer_id; |
|
236 | + return 'wpi_trans_' . $customer_id; |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
@@ -241,9 +241,9 @@ discard block |
||
241 | 241 | */ |
242 | 242 | public function save_data() { |
243 | 243 | // Dirty if something changed - prevents saving nothing new. |
244 | - if ( $this->_dirty && $this->has_session() ) { |
|
244 | + if ($this->_dirty && $this->has_session()) { |
|
245 | 245 | |
246 | - set_transient( $this->generate_key($this->_customer_id), $this->_data, $this->_session_expiration); |
|
246 | + set_transient($this->generate_key($this->_customer_id), $this->_data, $this->_session_expiration); |
|
247 | 247 | |
248 | 248 | $this->_dirty = false; |
249 | 249 | } |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * Destroy all session data. |
254 | 254 | */ |
255 | 255 | public function destroy_session() { |
256 | - $this->delete_session( $this->_customer_id ); |
|
256 | + $this->delete_session($this->_customer_id); |
|
257 | 257 | $this->forget_session(); |
258 | 258 | } |
259 | 259 | |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | * Forget all session data without destroying it. |
262 | 262 | */ |
263 | 263 | public function forget_session() { |
264 | - $this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true ); |
|
264 | + $this->setcookie($this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true); |
|
265 | 265 | |
266 | 266 | wpinv_empty_cart(); |
267 | 267 | |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | * @param int $uid User ID. |
277 | 277 | * @return string |
278 | 278 | */ |
279 | - public function nonce_user_logged_out( $uid ) { |
|
279 | + public function nonce_user_logged_out($uid) { |
|
280 | 280 | return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid; |
281 | 281 | } |
282 | 282 | |
@@ -287,14 +287,14 @@ discard block |
||
287 | 287 | * @param mixed $default Default session value. |
288 | 288 | * @return string|array |
289 | 289 | */ |
290 | - public function get_session( $customer_id, $default = false ) { |
|
290 | + public function get_session($customer_id, $default = false) { |
|
291 | 291 | |
292 | - if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
292 | + if (defined('WP_SETUP_CONFIG')) { |
|
293 | 293 | return array(); |
294 | 294 | } |
295 | 295 | |
296 | - if ( !is_user_logged_in() ) { |
|
297 | - if(!wp_verify_nonce( $customer_id, 'wpinv-session-customer-id' )){ |
|
296 | + if (!is_user_logged_in()) { |
|
297 | + if (!wp_verify_nonce($customer_id, 'wpinv-session-customer-id')) { |
|
298 | 298 | return array(); |
299 | 299 | } |
300 | 300 | } |
@@ -302,11 +302,11 @@ discard block |
||
302 | 302 | $key = $this->generate_key($customer_id); |
303 | 303 | $value = get_transient($key); |
304 | 304 | |
305 | - if ( !$value ) { |
|
305 | + if (!$value) { |
|
306 | 306 | $value = $default; |
307 | 307 | } |
308 | 308 | |
309 | - return maybe_unserialize( $value ); |
|
309 | + return maybe_unserialize($value); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | /** |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | * |
315 | 315 | * @param int $customer_id Customer ID. |
316 | 316 | */ |
317 | - public function delete_session( $customer_id ) { |
|
317 | + public function delete_session($customer_id) { |
|
318 | 318 | |
319 | 319 | $key = $this->generate_key($customer_id); |
320 | 320 | |
@@ -327,9 +327,9 @@ discard block |
||
327 | 327 | * @param string $customer_id Customer ID. |
328 | 328 | * @param int $timestamp Timestamp to expire the cookie. |
329 | 329 | */ |
330 | - public function update_session_timestamp( $customer_id, $timestamp ) { |
|
330 | + public function update_session_timestamp($customer_id, $timestamp) { |
|
331 | 331 | |
332 | - set_transient( $this->generate_key($customer_id), maybe_serialize( $this->_data ), $timestamp); |
|
332 | + set_transient($this->generate_key($customer_id), maybe_serialize($this->_data), $timestamp); |
|
333 | 333 | |
334 | 334 | } |
335 | 335 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Abstract privacy class. |
4 | 4 | */ |
5 | 5 | |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * Abstract class that is intended to be extended by |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @param string $name Plugin identifier. |
40 | 40 | */ |
41 | - public function __construct( $name = '' ) { |
|
41 | + public function __construct($name = '') { |
|
42 | 42 | $this->name = $name; |
43 | 43 | $this->init(); |
44 | 44 | } |
@@ -47,22 +47,22 @@ discard block |
||
47 | 47 | * Hook in events. |
48 | 48 | */ |
49 | 49 | protected function init() { |
50 | - add_action( 'admin_init', array( $this, 'add_privacy_message' ) ); |
|
50 | + add_action('admin_init', array($this, 'add_privacy_message')); |
|
51 | 51 | // Register data exporters |
52 | - add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'register_exporters' ), 10 ); |
|
52 | + add_filter('wp_privacy_personal_data_exporters', array($this, 'register_exporters'), 10); |
|
53 | 53 | // Register data erasers |
54 | - add_filter( 'wp_privacy_personal_data_erasers', array( $this, 'register_erasers' ) ); |
|
54 | + add_filter('wp_privacy_personal_data_erasers', array($this, 'register_erasers')); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | 58 | * Adds the privacy message on invoicing privacy page. |
59 | 59 | */ |
60 | 60 | public function add_privacy_message() { |
61 | - if ( function_exists( 'wp_add_privacy_policy_content' ) ) { |
|
61 | + if (function_exists('wp_add_privacy_policy_content')) { |
|
62 | 62 | $content = $this->get_privacy_message(); |
63 | 63 | |
64 | - if ( $content ) { |
|
65 | - wp_add_privacy_policy_content( $this->name, $this->get_privacy_message() ); |
|
64 | + if ($content) { |
|
65 | + wp_add_privacy_policy_content($this->name, $this->get_privacy_message()); |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 | } |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | * @param array $exporters List of exporter callbacks. |
84 | 84 | * @return array |
85 | 85 | */ |
86 | - public function register_exporters( $exporters = array() ) { |
|
87 | - foreach ( $this->exporters as $id => $exporter ) { |
|
88 | - $exporters[ $id ] = $exporter; |
|
86 | + public function register_exporters($exporters = array()) { |
|
87 | + foreach ($this->exporters as $id => $exporter) { |
|
88 | + $exporters[$id] = $exporter; |
|
89 | 89 | } |
90 | 90 | return $exporters; |
91 | 91 | } |
@@ -96,9 +96,9 @@ discard block |
||
96 | 96 | * @param array $erasers List of eraser callbacks. |
97 | 97 | * @return array |
98 | 98 | */ |
99 | - public function register_erasers( $erasers = array() ) { |
|
100 | - foreach ( $this->erasers as $id => $eraser ) { |
|
101 | - $erasers[ $id ] = $eraser; |
|
99 | + public function register_erasers($erasers = array()) { |
|
100 | + foreach ($this->erasers as $id => $eraser) { |
|
101 | + $erasers[$id] = $eraser; |
|
102 | 102 | } |
103 | 103 | return $erasers; |
104 | 104 | } |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | * |
113 | 113 | * @return array |
114 | 114 | */ |
115 | - public function add_exporter( $id, $name, $callback ) { |
|
116 | - $this->exporters[ $id ] = array( |
|
115 | + public function add_exporter($id, $name, $callback) { |
|
116 | + $this->exporters[$id] = array( |
|
117 | 117 | 'exporter_friendly_name' => $name, |
118 | 118 | 'callback' => $callback, |
119 | 119 | ); |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | * |
130 | 130 | * @return array |
131 | 131 | */ |
132 | - public function add_eraser( $id, $name, $callback ) { |
|
133 | - $this->erasers[ $id ] = array( |
|
132 | + public function add_eraser($id, $name, $callback) { |
|
133 | + $this->erasers[$id] = array( |
|
134 | 134 | 'eraser_friendly_name' => $name, |
135 | 135 | 'callback' => $callback, |
136 | 136 | ); |
@@ -4,7 +4,7 @@ discard block |
||
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 |
||
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 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Handle data for the current customer session |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | * @param mixed $key Key to get. |
52 | 52 | * @return mixed |
53 | 53 | */ |
54 | - public function __get( $key ) { |
|
55 | - return $this->get( $key ); |
|
54 | + public function __get($key) { |
|
55 | + return $this->get($key); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | * @param mixed $key Key to set. |
62 | 62 | * @param mixed $value Value to set. |
63 | 63 | */ |
64 | - public function __set( $key, $value ) { |
|
65 | - $this->set( $key, $value ); |
|
64 | + public function __set($key, $value) { |
|
65 | + $this->set($key, $value); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | * @param mixed $key Key to check. |
72 | 72 | * @return bool |
73 | 73 | */ |
74 | - public function __isset( $key ) { |
|
75 | - return isset( $this->_data[ sanitize_title( $key ) ] ); |
|
74 | + public function __isset($key) { |
|
75 | + return isset($this->_data[sanitize_title($key)]); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -80,9 +80,9 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @param mixed $key Key to unset. |
82 | 82 | */ |
83 | - public function __unset( $key ) { |
|
84 | - if ( isset( $this->_data[ $key ] ) ) { |
|
85 | - unset( $this->_data[ $key ] ); |
|
83 | + public function __unset($key) { |
|
84 | + if (isset($this->_data[$key])) { |
|
85 | + unset($this->_data[$key]); |
|
86 | 86 | $this->_dirty = true; |
87 | 87 | } |
88 | 88 | } |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | * @param mixed $default used if the session variable isn't set. |
95 | 95 | * @return array|string value of session variable |
96 | 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; |
|
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 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | * @param string $key Key to set. |
106 | 106 | * @param mixed $value Value to set. |
107 | 107 | */ |
108 | - public function set( $key, $value ) { |
|
109 | - if ( $value !== $this->get( $key ) ) { |
|
110 | - $this->_data[ sanitize_key( $key ) ] = maybe_serialize( $value ); |
|
108 | + public function set($key, $value) { |
|
109 | + if ($value !== $this->get($key)) { |
|
110 | + $this->_data[sanitize_key($key)] = maybe_serialize($value); |
|
111 | 111 | $this->_dirty = true; |
112 | 112 | } |
113 | 113 | } |
@@ -7,15 +7,15 @@ discard block |
||
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 | class WPInv_Plugin { |
15 | 15 | private static $instance; |
16 | 16 | |
17 | 17 | public static function run() { |
18 | - if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) { |
|
18 | + if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) { |
|
19 | 19 | self::$instance = new WPInv_Plugin; |
20 | 20 | self::$instance->includes(); |
21 | 21 | self::$instance->actions(); |
@@ -31,31 +31,31 @@ discard block |
||
31 | 31 | } |
32 | 32 | |
33 | 33 | public function define_constants() { |
34 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
35 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
34 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
35 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | private function actions() { |
39 | 39 | /* Internationalize the text strings used. */ |
40 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
40 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
41 | 41 | |
42 | 42 | /* Perform actions on admin initialization. */ |
43 | - add_action( 'admin_init', array( &$this, 'admin_init') ); |
|
44 | - add_action( 'init', array( &$this, 'init' ), 3 ); |
|
45 | - add_action( 'init', array( 'WPInv_Shortcodes', 'init' ) ); |
|
46 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
43 | + add_action('admin_init', array(&$this, 'admin_init')); |
|
44 | + add_action('init', array(&$this, 'init'), 3); |
|
45 | + add_action('init', array('WPInv_Shortcodes', 'init')); |
|
46 | + add_action('init', array(&$this, 'wpinv_actions')); |
|
47 | 47 | |
48 | - if ( class_exists( 'BuddyPress' ) ) { |
|
49 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
48 | + if (class_exists('BuddyPress')) { |
|
49 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
50 | 50 | } |
51 | 51 | |
52 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
52 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
53 | 53 | |
54 | - if ( is_admin() ) { |
|
55 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
|
56 | - add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
|
54 | + if (is_admin()) { |
|
55 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts')); |
|
56 | + add_action('admin_body_class', array(&$this, 'admin_body_class')); |
|
57 | 57 | } else { |
58 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
58 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -65,16 +65,16 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference. |
67 | 67 | */ |
68 | - do_action_ref_array( 'wpinv_actions', array( &$this ) ); |
|
68 | + do_action_ref_array('wpinv_actions', array(&$this)); |
|
69 | 69 | |
70 | - add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
|
70 | + add_action('admin_init', array(&$this, 'activation_redirect')); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | public function plugins_loaded() { |
74 | 74 | /* Internationalize the text strings used. */ |
75 | 75 | $this->load_textdomain(); |
76 | 76 | |
77 | - do_action( 'wpinv_loaded' ); |
|
77 | + do_action('wpinv_loaded'); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -82,217 +82,217 @@ discard block |
||
82 | 82 | * |
83 | 83 | * @since 1.0 |
84 | 84 | */ |
85 | - public function load_textdomain( $locale = NULL ) { |
|
86 | - if ( empty( $locale ) ) { |
|
87 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
85 | + public function load_textdomain($locale = NULL) { |
|
86 | + if (empty($locale)) { |
|
87 | + $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
|
88 | 88 | } |
89 | 89 | |
90 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
90 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
91 | 91 | |
92 | - unload_textdomain( 'invoicing' ); |
|
93 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
94 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
92 | + unload_textdomain('invoicing'); |
|
93 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
94 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
95 | 95 | |
96 | 96 | /** |
97 | 97 | * Define language constants. |
98 | 98 | */ |
99 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
99 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | public function includes() { |
103 | 103 | global $wpinv_options; |
104 | 104 | |
105 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
105 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
106 | 106 | $wpinv_options = wpinv_get_settings(); |
107 | 107 | |
108 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' ); |
|
109 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
110 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
111 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
112 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
113 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
114 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
115 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' ); |
|
116 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
117 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
118 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
119 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
120 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
121 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' ); |
|
122 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' ); |
|
123 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' ); |
|
124 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' ); |
|
125 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
126 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
127 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
128 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
129 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
130 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' ); |
|
131 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
132 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
133 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
134 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
135 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' ); |
|
136 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
137 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' ); |
|
138 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
139 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
140 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
141 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
142 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
108 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php'); |
|
109 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
110 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
111 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
112 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
113 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
114 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
115 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php'); |
|
116 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
117 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
118 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
119 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
120 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
121 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php'); |
|
122 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php'); |
|
123 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php'); |
|
124 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php'); |
|
125 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'); |
|
126 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'); |
|
127 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
128 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
129 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
130 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php'); |
|
131 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'); |
|
132 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'); |
|
133 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'); |
|
134 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'); |
|
135 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php'); |
|
136 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'); |
|
137 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php'); |
|
138 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'); |
|
139 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'); |
|
140 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'); |
|
141 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'); |
|
142 | + require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php'); |
|
143 | 143 | |
144 | - if ( !class_exists( 'WPInv_EUVat' ) ) { |
|
145 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
144 | + if (!class_exists('WPInv_EUVat')) { |
|
145 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
146 | 146 | } |
147 | 147 | |
148 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
149 | - if ( !empty( $gateways ) ) { |
|
150 | - foreach ( $gateways as $gateway ) { |
|
151 | - if ( $gateway == 'manual' ) { |
|
148 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
149 | + if (!empty($gateways)) { |
|
150 | + foreach ($gateways as $gateway) { |
|
151 | + if ($gateway == 'manual') { |
|
152 | 152 | continue; |
153 | 153 | } |
154 | 154 | |
155 | 155 | $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
156 | 156 | |
157 | - if ( file_exists( $gateway_file ) ) { |
|
158 | - require_once( $gateway_file ); |
|
157 | + if (file_exists($gateway_file)) { |
|
158 | + require_once($gateway_file); |
|
159 | 159 | } |
160 | 160 | } |
161 | 161 | } |
162 | - require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' ); |
|
162 | + require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php'); |
|
163 | 163 | |
164 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
165 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
166 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
167 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' ); |
|
164 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
165 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php'); |
|
166 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
167 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php'); |
|
168 | 168 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
169 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' ); |
|
170 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' ); |
|
171 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
172 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' ); |
|
173 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
174 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
175 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
169 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php'); |
|
170 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php'); |
|
171 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
172 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php'); |
|
173 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
174 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'); |
|
175 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'); |
|
176 | 176 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
177 | 177 | // load the user class only on the users.php page |
178 | 178 | global $pagenow; |
179 | - if($pagenow=='users.php'){ |
|
179 | + if ($pagenow == 'users.php') { |
|
180 | 180 | new WPInv_Admin_Users(); |
181 | 181 | } |
182 | 182 | } |
183 | 183 | |
184 | 184 | // include css inliner |
185 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
186 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
185 | + if (!class_exists('Emogrifier') && class_exists('DOMDocument')) { |
|
186 | + include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'); |
|
187 | 187 | } |
188 | 188 | |
189 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
189 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | public function init() { |
193 | 193 | } |
194 | 194 | |
195 | 195 | public function admin_init() { |
196 | - add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
|
196 | + add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php')); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | public function activation_redirect() { |
200 | 200 | // Bail if no activation redirect |
201 | - if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
|
201 | + if (!get_transient('_wpinv_activation_redirect')) { |
|
202 | 202 | return; |
203 | 203 | } |
204 | 204 | |
205 | 205 | // Delete the redirect transient |
206 | - delete_transient( '_wpinv_activation_redirect' ); |
|
206 | + delete_transient('_wpinv_activation_redirect'); |
|
207 | 207 | |
208 | 208 | // Bail if activating from network, or bulk |
209 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
209 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
210 | 210 | return; |
211 | 211 | } |
212 | 212 | |
213 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
213 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
214 | 214 | exit; |
215 | 215 | } |
216 | 216 | |
217 | 217 | public function enqueue_scripts() { |
218 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
218 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
219 | 219 | |
220 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION ); |
|
221 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
220 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION); |
|
221 | + wp_enqueue_style('wpinv_front_style'); |
|
222 | 222 | |
223 | 223 | // Register scripts |
224 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
225 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), WPINV_VERSION ); |
|
224 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
225 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array('jquery'), WPINV_VERSION); |
|
226 | 226 | |
227 | 227 | $localize = array(); |
228 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
229 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
228 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
229 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
230 | 230 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
231 | 231 | $localize['currency_pos'] = wpinv_currency_position(); |
232 | 232 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
233 | 233 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
234 | 234 | $localize['decimals'] = wpinv_decimals(); |
235 | - $localize['txtComplete'] = __( 'Complete', 'invoicing' ); |
|
235 | + $localize['txtComplete'] = __('Complete', 'invoicing'); |
|
236 | 236 | $localize['UseTaxes'] = wpinv_use_taxes(); |
237 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
237 | + $localize['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce'); |
|
238 | 238 | |
239 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
239 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
240 | 240 | |
241 | - wp_enqueue_script( 'jquery-blockui' ); |
|
241 | + wp_enqueue_script('jquery-blockui'); |
|
242 | 242 | $autofill_api = wpinv_get_option('address_autofill_api'); |
243 | 243 | $autofill_active = wpinv_get_option('address_autofill_active'); |
244 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
245 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
246 | - wp_dequeue_script( 'google-maps-api' ); |
|
244 | + if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) { |
|
245 | + if (wp_script_is('google-maps-api', 'enqueued')) { |
|
246 | + wp_dequeue_script('google-maps-api'); |
|
247 | 247 | } |
248 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
249 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
248 | + wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false); |
|
249 | + wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true); |
|
250 | 250 | } |
251 | 251 | |
252 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
253 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
252 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all'); |
|
253 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
254 | 254 | |
255 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
256 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
255 | + wp_enqueue_script('wpinv-front-script'); |
|
256 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | public function admin_enqueue_scripts() { |
260 | 260 | global $post, $pagenow; |
261 | 261 | |
262 | 262 | $post_type = wpinv_admin_post_type(); |
263 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
264 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : ''; |
|
263 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
264 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : ''; |
|
265 | 265 | |
266 | 266 | $jquery_ui_css = false; |
267 | - if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
267 | + if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
268 | 268 | $jquery_ui_css = true; |
269 | - } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) { |
|
269 | + } else if ($page == 'wpinv-settings' || $page == 'wpinv-reports') { |
|
270 | 270 | $jquery_ui_css = true; |
271 | 271 | } |
272 | - if ( $jquery_ui_css ) { |
|
273 | - wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
|
274 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
272 | + if ($jquery_ui_css) { |
|
273 | + wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16'); |
|
274 | + wp_enqueue_style('jquery-ui-css'); |
|
275 | 275 | } |
276 | 276 | |
277 | - wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
278 | - wp_enqueue_style( 'wpinv_meta_box_style' ); |
|
277 | + wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
278 | + wp_enqueue_style('wpinv_meta_box_style'); |
|
279 | 279 | |
280 | - wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION ); |
|
281 | - wp_enqueue_style( 'wpinv_admin_style' ); |
|
280 | + wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION); |
|
281 | + wp_enqueue_style('wpinv_admin_style'); |
|
282 | 282 | |
283 | - $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ); |
|
284 | - if ( $page == 'wpinv-subscriptions' ) { |
|
285 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
283 | + $enqueue = ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')); |
|
284 | + if ($page == 'wpinv-subscriptions') { |
|
285 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
286 | 286 | } |
287 | 287 | |
288 | - if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) { |
|
289 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
288 | + if ($enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue)) { |
|
289 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
290 | 290 | } |
291 | 291 | |
292 | - wp_enqueue_style( 'wp-color-picker' ); |
|
293 | - wp_enqueue_script( 'wp-color-picker' ); |
|
292 | + wp_enqueue_style('wp-color-picker'); |
|
293 | + wp_enqueue_script('wp-color-picker'); |
|
294 | 294 | |
295 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
295 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
296 | 296 | |
297 | 297 | if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
298 | 298 | $autofill_api = wpinv_get_option('address_autofill_api'); |
@@ -303,20 +303,20 @@ discard block |
||
303 | 303 | } |
304 | 304 | } |
305 | 305 | |
306 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
307 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
306 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all'); |
|
307 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
308 | 308 | |
309 | - wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ), WPINV_VERSION ); |
|
310 | - wp_enqueue_script( 'wpinv-admin-script' ); |
|
309 | + wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), WPINV_VERSION); |
|
310 | + wp_enqueue_script('wpinv-admin-script'); |
|
311 | 311 | |
312 | 312 | $localize = array(); |
313 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
314 | - $localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
|
315 | - $localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
316 | - $localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
|
317 | - $localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
|
318 | - $localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
|
319 | - $localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
|
313 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
314 | + $localize['post_ID'] = isset($post->ID) ? $post->ID : ''; |
|
315 | + $localize['wpinv_nonce'] = wp_create_nonce('wpinv-nonce'); |
|
316 | + $localize['add_invoice_note_nonce'] = wp_create_nonce('add-invoice-note'); |
|
317 | + $localize['delete_invoice_note_nonce'] = wp_create_nonce('delete-invoice-note'); |
|
318 | + $localize['invoice_item_nonce'] = wp_create_nonce('invoice-item'); |
|
319 | + $localize['billing_details_nonce'] = wp_create_nonce('get-billing-details'); |
|
320 | 320 | $localize['tax'] = wpinv_tax_amount(); |
321 | 321 | $localize['discount'] = wpinv_discount_amount(); |
322 | 322 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
@@ -324,69 +324,69 @@ discard block |
||
324 | 324 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
325 | 325 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
326 | 326 | $localize['decimals'] = wpinv_decimals(); |
327 | - $localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
|
328 | - $localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
|
329 | - $localize['status_pending'] = wpinv_status_nicename( 'wpi-pending' ); |
|
330 | - $localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
|
331 | - $localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
|
332 | - $localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
|
333 | - $localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
|
334 | - $localize['confirmCalcTotals'] = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ); |
|
335 | - $localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
|
336 | - $localize['emptyInvoice'] = __( 'Add at least one item to save invoice!', 'invoicing' ); |
|
337 | - $localize['errDeleteItem'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
|
338 | - $localize['delete_subscription'] = __( 'Are you sure you want to delete this subscription?', 'invoicing' ); |
|
339 | - $localize['action_edit'] = __( 'Edit', 'invoicing' ); |
|
340 | - $localize['action_cancel'] = __( 'Cancel', 'invoicing' ); |
|
327 | + $localize['save_invoice'] = __('Save Invoice', 'invoicing'); |
|
328 | + $localize['status_publish'] = wpinv_status_nicename('publish'); |
|
329 | + $localize['status_pending'] = wpinv_status_nicename('wpi-pending'); |
|
330 | + $localize['delete_tax_rate'] = __('Are you sure you wish to delete this tax rate?', 'invoicing'); |
|
331 | + $localize['OneItemMin'] = __('Invoice must contain at least one item', 'invoicing'); |
|
332 | + $localize['DeleteInvoiceItem'] = __('Are you sure you wish to delete this item?', 'invoicing'); |
|
333 | + $localize['FillBillingDetails'] = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'); |
|
334 | + $localize['confirmCalcTotals'] = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'); |
|
335 | + $localize['AreYouSure'] = __('Are you sure?', 'invoicing'); |
|
336 | + $localize['emptyInvoice'] = __('Add at least one item to save invoice!', 'invoicing'); |
|
337 | + $localize['errDeleteItem'] = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'); |
|
338 | + $localize['delete_subscription'] = __('Are you sure you want to delete this subscription?', 'invoicing'); |
|
339 | + $localize['action_edit'] = __('Edit', 'invoicing'); |
|
340 | + $localize['action_cancel'] = __('Cancel', 'invoicing'); |
|
341 | 341 | |
342 | - $localize = apply_filters( 'wpinv_admin_js_localize', $localize ); |
|
342 | + $localize = apply_filters('wpinv_admin_js_localize', $localize); |
|
343 | 343 | |
344 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
|
344 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize); |
|
345 | 345 | |
346 | - if ( $page == 'wpinv-subscriptions' ) { |
|
347 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
348 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
346 | + if ($page == 'wpinv-subscriptions') { |
|
347 | + wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION); |
|
348 | + wp_enqueue_script('wpinv-sub-admin-script'); |
|
349 | 349 | } |
350 | 350 | } |
351 | 351 | |
352 | - public function admin_body_class( $classes ) { |
|
352 | + public function admin_body_class($classes) { |
|
353 | 353 | global $pagenow, $post, $current_screen; |
354 | 354 | |
355 | - if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote' ) ) { |
|
355 | + if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote')) { |
|
356 | 356 | $classes .= ' wpinv-cpt'; |
357 | 357 | } |
358 | 358 | |
359 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
359 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
360 | 360 | |
361 | - $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false; |
|
362 | - if ( $add_class ) { |
|
363 | - $classes .= ' wpi-' . wpinv_sanitize_key( $page ); |
|
361 | + $add_class = $page && $pagenow == 'admin.php' && strpos($page, 'wpinv-') === 0 ? true : false; |
|
362 | + if ($add_class) { |
|
363 | + $classes .= ' wpi-' . wpinv_sanitize_key($page); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | $settings_class = array(); |
367 | - if ( $page == 'wpinv-settings' ) { |
|
368 | - if ( !empty( $_REQUEST['tab'] ) ) { |
|
369 | - $settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
|
367 | + if ($page == 'wpinv-settings') { |
|
368 | + if (!empty($_REQUEST['tab'])) { |
|
369 | + $settings_class[] = sanitize_text_field($_REQUEST['tab']); |
|
370 | 370 | } |
371 | 371 | |
372 | - if ( !empty( $_REQUEST['section'] ) ) { |
|
373 | - $settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
|
372 | + if (!empty($_REQUEST['section'])) { |
|
373 | + $settings_class[] = sanitize_text_field($_REQUEST['section']); |
|
374 | 374 | } |
375 | 375 | |
376 | - $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
|
376 | + $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main'; |
|
377 | 377 | } |
378 | 378 | |
379 | - if ( !empty( $settings_class ) ) { |
|
380 | - $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
379 | + if (!empty($settings_class)) { |
|
380 | + $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-')); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | $post_type = wpinv_admin_post_type(); |
384 | 384 | |
385 | - if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) { |
|
385 | + if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) { |
|
386 | 386 | return $classes .= ' wpinv'; |
387 | 387 | } |
388 | 388 | |
389 | - if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) { |
|
389 | + if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) { |
|
390 | 390 | $classes .= ' wpi-editable-n'; |
391 | 391 | } |
392 | 392 | |
@@ -398,20 +398,20 @@ discard block |
||
398 | 398 | } |
399 | 399 | |
400 | 400 | public function wpinv_actions() { |
401 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
402 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
401 | + if (isset($_REQUEST['wpi_action'])) { |
|
402 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
403 | 403 | } |
404 | 404 | } |
405 | 405 | |
406 | - public function pre_get_posts( $wp_query ) { |
|
407 | - if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
408 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
406 | + public function pre_get_posts($wp_query) { |
|
407 | + if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
408 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | return $wp_query; |
412 | 412 | } |
413 | 413 | |
414 | 414 | public function bp_invoicing_init() { |
415 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
415 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
416 | 416 | } |
417 | 417 | } |
418 | 418 | \ No newline at end of file |
@@ -29,7 +29,7 @@ |
||
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 |
@@ -1,67 +1,67 @@ discard block |
||
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 | -function wpinv_add_meta_boxes( $post_type, $post ) { |
|
7 | +function wpinv_add_meta_boxes($post_type, $post) { |
|
8 | 8 | global $wpi_mb_invoice; |
9 | - if ( $post_type == 'wpi_invoice' && !empty( $post->ID ) ) { |
|
10 | - $wpi_mb_invoice = wpinv_get_invoice( $post->ID ); |
|
9 | + if ($post_type == 'wpi_invoice' && !empty($post->ID)) { |
|
10 | + $wpi_mb_invoice = wpinv_get_invoice($post->ID); |
|
11 | 11 | } |
12 | 12 | |
13 | - if ( !empty( $wpi_mb_invoice ) && !$wpi_mb_invoice->has_status( array( 'draft', 'auto-draft' ) ) ) { |
|
14 | - add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high' ); |
|
13 | + if (!empty($wpi_mb_invoice) && !$wpi_mb_invoice->has_status(array('draft', 'auto-draft'))) { |
|
14 | + add_meta_box('wpinv-mb-resend-invoice', __('Resend Invoice', 'invoicing'), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high'); |
|
15 | 15 | } |
16 | 16 | |
17 | - if ( !empty( $wpi_mb_invoice ) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent() ) { |
|
18 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscriptions', 'invoicing' ), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high' ); |
|
17 | + if (!empty($wpi_mb_invoice) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent()) { |
|
18 | + add_meta_box('wpinv-mb-subscriptions', __('Subscriptions', 'invoicing'), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high'); |
|
19 | 19 | } |
20 | 20 | |
21 | - if ( wpinv_is_subscription_payment( $wpi_mb_invoice ) ) { |
|
22 | - add_meta_box( 'wpinv-mb-renewals', __( 'Renewal Payment', 'invoicing' ), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high' ); |
|
21 | + if (wpinv_is_subscription_payment($wpi_mb_invoice)) { |
|
22 | + add_meta_box('wpinv-mb-renewals', __('Renewal Payment', 'invoicing'), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high'); |
|
23 | 23 | } |
24 | 24 | |
25 | - add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default' ); |
|
26 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default' ); |
|
25 | + add_meta_box('wpinv-details', __('Invoice Details', 'invoicing'), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default'); |
|
26 | + add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default'); |
|
27 | 27 | |
28 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high' ); |
|
29 | - add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high' ); |
|
30 | - add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' ); |
|
28 | + add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high'); |
|
29 | + add_meta_box('wpinv-items', __('Invoice Items', 'invoicing'), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high'); |
|
30 | + add_meta_box('wpinv-notes', __('Invoice Notes', 'invoicing'), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high'); |
|
31 | 31 | |
32 | 32 | remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal'); |
33 | 33 | } |
34 | -add_action( 'add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2 ); |
|
34 | +add_action('add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2); |
|
35 | 35 | |
36 | -function wpinv_save_meta_boxes( $post_id, $post, $update = false ) { |
|
37 | - remove_action( 'save_post', __FUNCTION__ ); |
|
36 | +function wpinv_save_meta_boxes($post_id, $post, $update = false) { |
|
37 | + remove_action('save_post', __FUNCTION__); |
|
38 | 38 | |
39 | 39 | // $post_id and $post are required |
40 | - if ( empty( $post_id ) || empty( $post ) ) { |
|
40 | + if (empty($post_id) || empty($post)) { |
|
41 | 41 | return; |
42 | 42 | } |
43 | 43 | |
44 | - if ( !current_user_can( 'edit_post', $post_id ) || empty( $post->post_type ) ) { |
|
44 | + if (!current_user_can('edit_post', $post_id) || empty($post->post_type)) { |
|
45 | 45 | return; |
46 | 46 | } |
47 | 47 | |
48 | 48 | // Dont' save meta boxes for revisions or autosaves |
49 | - if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
49 | + if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
50 | 50 | return; |
51 | 51 | } |
52 | 52 | |
53 | - if ( $post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote' ) { |
|
54 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
53 | + if ($post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote') { |
|
54 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
55 | 55 | return; |
56 | 56 | } |
57 | 57 | |
58 | - if ( isset( $_POST['wpinv_save_invoice'] ) && wp_verify_nonce( $_POST['wpinv_save_invoice'], 'wpinv_save_invoice' ) ) { |
|
59 | - WPInv_Meta_Box_Items::save( $post_id, $_POST, $post ); |
|
58 | + if (isset($_POST['wpinv_save_invoice']) && wp_verify_nonce($_POST['wpinv_save_invoice'], 'wpinv_save_invoice')) { |
|
59 | + WPInv_Meta_Box_Items::save($post_id, $_POST, $post); |
|
60 | 60 | } |
61 | - } else if ( $post->post_type == 'wpi_item' ) { |
|
61 | + } else if ($post->post_type == 'wpi_item') { |
|
62 | 62 | // verify nonce |
63 | - if ( isset( $_POST['wpinv_vat_meta_box_nonce'] ) && wp_verify_nonce( $_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save' ) ) { |
|
64 | - $fields = array(); |
|
63 | + if (isset($_POST['wpinv_vat_meta_box_nonce']) && wp_verify_nonce($_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save')) { |
|
64 | + $fields = array(); |
|
65 | 65 | $fields['_wpinv_price'] = 'wpinv_item_price'; |
66 | 66 | $fields['_wpinv_vat_class'] = 'wpinv_vat_class'; |
67 | 67 | $fields['_wpinv_vat_rule'] = 'wpinv_vat_rules'; |
@@ -74,92 +74,92 @@ discard block |
||
74 | 74 | $fields['_wpinv_trial_period'] = 'wpinv_trial_period'; |
75 | 75 | $fields['_wpinv_trial_interval'] = 'wpinv_trial_interval'; |
76 | 76 | |
77 | - if ( !isset( $_POST['wpinv_is_recurring'] ) ) { |
|
77 | + if (!isset($_POST['wpinv_is_recurring'])) { |
|
78 | 78 | $_POST['wpinv_is_recurring'] = 0; |
79 | 79 | } |
80 | 80 | |
81 | - if ( !isset( $_POST['wpinv_free_trial'] ) || empty( $_POST['wpinv_is_recurring'] ) ) { |
|
81 | + if (!isset($_POST['wpinv_free_trial']) || empty($_POST['wpinv_is_recurring'])) { |
|
82 | 82 | $_POST['wpinv_free_trial'] = 0; |
83 | 83 | } |
84 | 84 | |
85 | - foreach ( $fields as $field => $name ) { |
|
86 | - if ( isset( $_POST[ $name ] ) ) { |
|
87 | - $allowed = apply_filters( 'wpinv_item_allowed_save_meta_value', true, $field, $post_id ); |
|
85 | + foreach ($fields as $field => $name) { |
|
86 | + if (isset($_POST[$name])) { |
|
87 | + $allowed = apply_filters('wpinv_item_allowed_save_meta_value', true, $field, $post_id); |
|
88 | 88 | |
89 | - if ( !$allowed ) { |
|
89 | + if (!$allowed) { |
|
90 | 90 | continue; |
91 | 91 | } |
92 | 92 | |
93 | - if ( $field == '_wpinv_price' ) { |
|
94 | - $value = wpinv_sanitize_amount( $_POST[ $name ] ); |
|
93 | + if ($field == '_wpinv_price') { |
|
94 | + $value = wpinv_sanitize_amount($_POST[$name]); |
|
95 | 95 | } else { |
96 | - $value = is_string( $_POST[ $name ] ) ? sanitize_text_field( $_POST[ $name ] ) : $_POST[ $name ]; |
|
96 | + $value = is_string($_POST[$name]) ? sanitize_text_field($_POST[$name]) : $_POST[$name]; |
|
97 | 97 | } |
98 | 98 | |
99 | - $value = apply_filters( 'wpinv_item_metabox_save_' . $field, $value, $name ); |
|
100 | - update_post_meta( $post_id, $field, $value ); |
|
99 | + $value = apply_filters('wpinv_item_metabox_save_' . $field, $value, $name); |
|
100 | + update_post_meta($post_id, $field, $value); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
104 | - if ( !get_post_meta( $post_id, '_wpinv_custom_id', true ) ) { |
|
105 | - update_post_meta( $post_id, '_wpinv_custom_id', $post_id ); |
|
104 | + if (!get_post_meta($post_id, '_wpinv_custom_id', true)) { |
|
105 | + update_post_meta($post_id, '_wpinv_custom_id', $post_id); |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | } |
109 | 109 | } |
110 | -add_action( 'save_post', 'wpinv_save_meta_boxes', 10, 3 ); |
|
110 | +add_action('save_post', 'wpinv_save_meta_boxes', 10, 3); |
|
111 | 111 | |
112 | 112 | function wpinv_register_item_meta_boxes() { |
113 | 113 | global $wpinv_euvat; |
114 | 114 | |
115 | - add_meta_box( 'wpinv_field_prices', __( 'Item Price', 'invoicing' ), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high' ); |
|
115 | + add_meta_box('wpinv_field_prices', __('Item Price', 'invoicing'), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high'); |
|
116 | 116 | |
117 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
118 | - add_meta_box( 'wpinv_field_vat_rules', __( 'VAT rules type to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high' ); |
|
117 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
118 | + add_meta_box('wpinv_field_vat_rules', __('VAT rules type to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high'); |
|
119 | 119 | } |
120 | 120 | |
121 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
122 | - add_meta_box( 'wpinv_field_vat_classes', __( 'VAT rates class to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high' ); |
|
121 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
122 | + add_meta_box('wpinv_field_vat_classes', __('VAT rates class to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high'); |
|
123 | 123 | } |
124 | 124 | |
125 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core' ); |
|
126 | - add_meta_box( 'wpinv_field_meta_values', __( 'Item Meta Values', 'invoicing' ), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core' ); |
|
125 | + add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core'); |
|
126 | + add_meta_box('wpinv_field_meta_values', __('Item Meta Values', 'invoicing'), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core'); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | function wpinv_register_discount_meta_boxes() { |
130 | - add_meta_box( 'wpinv_discount_fields', __( 'Discount Details', 'invoicing' ), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high' ); |
|
130 | + add_meta_box('wpinv_discount_fields', __('Discount Details', 'invoicing'), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high'); |
|
131 | 131 | } |
132 | 132 | |
133 | -function wpinv_discount_metabox_details( $post ) { |
|
133 | +function wpinv_discount_metabox_details($post) { |
|
134 | 134 | $discount_id = $post->ID; |
135 | - $discount = wpinv_get_discount( $discount_id ); |
|
135 | + $discount = wpinv_get_discount($discount_id); |
|
136 | 136 | |
137 | - $type = wpinv_get_discount_type( $discount_id ); |
|
138 | - $item_reqs = wpinv_get_discount_item_reqs( $discount_id ); |
|
139 | - $excluded_items = wpinv_get_discount_excluded_items( $discount_id ); |
|
140 | - $min_total = wpinv_get_discount_min_total( $discount_id ); |
|
141 | - $max_total = wpinv_get_discount_max_total( $discount_id ); |
|
142 | - $max_uses = wpinv_get_discount_max_uses( $discount_id ); |
|
143 | - $single_use = wpinv_discount_is_single_use( $discount_id ); |
|
144 | - $recurring = (bool)wpinv_discount_is_recurring( $discount_id ); |
|
145 | - $start_date = wpinv_get_discount_start_date( $discount_id ); |
|
146 | - $expiration_date = wpinv_get_discount_expiration( $discount_id ); |
|
137 | + $type = wpinv_get_discount_type($discount_id); |
|
138 | + $item_reqs = wpinv_get_discount_item_reqs($discount_id); |
|
139 | + $excluded_items = wpinv_get_discount_excluded_items($discount_id); |
|
140 | + $min_total = wpinv_get_discount_min_total($discount_id); |
|
141 | + $max_total = wpinv_get_discount_max_total($discount_id); |
|
142 | + $max_uses = wpinv_get_discount_max_uses($discount_id); |
|
143 | + $single_use = wpinv_discount_is_single_use($discount_id); |
|
144 | + $recurring = (bool)wpinv_discount_is_recurring($discount_id); |
|
145 | + $start_date = wpinv_get_discount_start_date($discount_id); |
|
146 | + $expiration_date = wpinv_get_discount_expiration($discount_id); |
|
147 | 147 | |
148 | - if ( ! empty( $start_date ) && strpos( $start_date, '0000' ) === false ) { |
|
149 | - $start_time = strtotime( $start_date ); |
|
150 | - $start_h = date_i18n( 'H', $start_time ); |
|
151 | - $start_m = date_i18n( 'i', $start_time ); |
|
152 | - $start_date = date_i18n( 'Y-m-d', $start_time ); |
|
148 | + if (!empty($start_date) && strpos($start_date, '0000') === false) { |
|
149 | + $start_time = strtotime($start_date); |
|
150 | + $start_h = date_i18n('H', $start_time); |
|
151 | + $start_m = date_i18n('i', $start_time); |
|
152 | + $start_date = date_i18n('Y-m-d', $start_time); |
|
153 | 153 | } else { |
154 | 154 | $start_h = '00'; |
155 | 155 | $start_m = '00'; |
156 | 156 | } |
157 | 157 | |
158 | - if ( ! empty( $expiration_date ) && strpos( $expiration_date, '0000' ) === false ) { |
|
159 | - $expiration_time = strtotime( $expiration_date ); |
|
160 | - $expiration_h = date_i18n( 'H', $expiration_time ); |
|
161 | - $expiration_m = date_i18n( 'i', $expiration_time ); |
|
162 | - $expiration_date = date_i18n( 'Y-m-d', $expiration_time ); |
|
158 | + if (!empty($expiration_date) && strpos($expiration_date, '0000') === false) { |
|
159 | + $expiration_time = strtotime($expiration_date); |
|
160 | + $expiration_h = date_i18n('H', $expiration_time); |
|
161 | + $expiration_m = date_i18n('i', $expiration_time); |
|
162 | + $expiration_date = date_i18n('Y-m-d', $expiration_time); |
|
163 | 163 | } else { |
164 | 164 | $expiration_h = '23'; |
165 | 165 | $expiration_m = '59'; |
@@ -169,207 +169,207 @@ discard block |
||
169 | 169 | $max_total = $max_total > 0 ? $max_total : ''; |
170 | 170 | $max_uses = $max_uses > 0 ? $max_uses : ''; |
171 | 171 | ?> |
172 | -<?php do_action( 'wpinv_discount_form_top', $post ); ?> |
|
173 | -<?php wp_nonce_field( 'wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce' ); ;?> |
|
172 | +<?php do_action('wpinv_discount_form_top', $post); ?> |
|
173 | +<?php wp_nonce_field('wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce'); ;?> |
|
174 | 174 | <table class="form-table wpi-form-table"> |
175 | 175 | <tbody> |
176 | - <?php do_action( 'wpinv_discount_form_first', $post ); ?> |
|
177 | - <?php do_action( 'wpinv_discount_form_before_code', $post ); ?> |
|
176 | + <?php do_action('wpinv_discount_form_first', $post); ?> |
|
177 | + <?php do_action('wpinv_discount_form_before_code', $post); ?> |
|
178 | 178 | <tr> |
179 | 179 | <th valign="top" scope="row"> |
180 | - <label for="wpinv_discount_code"><?php _e( 'Discount Code', 'invoicing' ); ?></label> |
|
180 | + <label for="wpinv_discount_code"><?php _e('Discount Code', 'invoicing'); ?></label> |
|
181 | 181 | </th> |
182 | 182 | <td> |
183 | - <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr( wpinv_get_discount_code( $discount_id ) ); ?>" required> |
|
184 | - <p class="description"><?php _e( 'Enter a code for this discount, such as 10OFF', 'invoicing' ); ?></p> |
|
183 | + <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr(wpinv_get_discount_code($discount_id)); ?>" required> |
|
184 | + <p class="description"><?php _e('Enter a code for this discount, such as 10OFF', 'invoicing'); ?></p> |
|
185 | 185 | </td> |
186 | 186 | </tr> |
187 | - <?php do_action( 'wpinv_discount_form_before_type', $post ); ?> |
|
187 | + <?php do_action('wpinv_discount_form_before_type', $post); ?> |
|
188 | 188 | <tr> |
189 | 189 | <th valign="top" scope="row"> |
190 | - <label for="wpinv_discount_type"><?php _e( 'Discount Type', 'invoicing' ); ?></label> |
|
190 | + <label for="wpinv_discount_type"><?php _e('Discount Type', 'invoicing'); ?></label> |
|
191 | 191 | </th> |
192 | 192 | <td> |
193 | 193 | <select id="wpinv_discount_type" name="type" class="medium-text wpi_select2"> |
194 | - <?php foreach ( wpinv_get_discount_types() as $value => $label ) { ?> |
|
195 | - <option value="<?php echo $value ;?>" <?php selected( $type, $value ); ?>><?php echo $label; ?></option> |
|
194 | + <?php foreach (wpinv_get_discount_types() as $value => $label) { ?> |
|
195 | + <option value="<?php echo $value; ?>" <?php selected($type, $value); ?>><?php echo $label; ?></option> |
|
196 | 196 | <?php } ?> |
197 | 197 | </select> |
198 | - <p class="description"><?php _e( 'The kind of discount to apply for this discount.', 'invoicing' ); ?></p> |
|
198 | + <p class="description"><?php _e('The kind of discount to apply for this discount.', 'invoicing'); ?></p> |
|
199 | 199 | </td> |
200 | 200 | </tr> |
201 | - <?php do_action( 'wpinv_discount_form_before_amount', $post ); ?> |
|
201 | + <?php do_action('wpinv_discount_form_before_amount', $post); ?> |
|
202 | 202 | <tr> |
203 | 203 | <th valign="top" scope="row"> |
204 | - <label for="wpinv_discount_amount"><?php _e( 'Amount', 'invoicing' ); ?></label> |
|
204 | + <label for="wpinv_discount_amount"><?php _e('Amount', 'invoicing'); ?></label> |
|
205 | 205 | </th> |
206 | 206 | <td> |
207 | - <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr( wpinv_get_discount_amount( $discount_id ) ); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol() ;?></font> |
|
208 | - <p style="display:none;" class="description"><?php _e( 'Enter the discount amount in USD', 'invoicing' ); ?></p> |
|
209 | - <p class="description"><?php _e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?></p> |
|
207 | + <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr(wpinv_get_discount_amount($discount_id)); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol(); ?></font> |
|
208 | + <p style="display:none;" class="description"><?php _e('Enter the discount amount in USD', 'invoicing'); ?></p> |
|
209 | + <p class="description"><?php _e('Enter the discount value. Ex: 10', 'invoicing'); ?></p> |
|
210 | 210 | </td> |
211 | 211 | </tr> |
212 | - <?php do_action( 'wpinv_discount_form_before_items', $post ); ?> |
|
212 | + <?php do_action('wpinv_discount_form_before_items', $post); ?> |
|
213 | 213 | <tr> |
214 | 214 | <th valign="top" scope="row"> |
215 | - <label for="wpinv_discount_items"><?php _e( 'Items', 'invoicing' ); ?></label> |
|
215 | + <label for="wpinv_discount_items"><?php _e('Items', 'invoicing'); ?></label> |
|
216 | 216 | </th> |
217 | 217 | <td> |
218 | - <p><?php echo wpinv_item_dropdown( array( |
|
218 | + <p><?php echo wpinv_item_dropdown(array( |
|
219 | 219 | 'name' => 'items[]', |
220 | 220 | 'id' => 'items', |
221 | 221 | 'selected' => $item_reqs, |
222 | 222 | 'multiple' => true, |
223 | 223 | 'class' => 'medium-text wpi_select2', |
224 | - 'placeholder' => __( 'Select one or more Items', 'invoicing' ), |
|
224 | + 'placeholder' => __('Select one or more Items', 'invoicing'), |
|
225 | 225 | 'show_recurring' => true, |
226 | - ) ); ?> |
|
226 | + )); ?> |
|
227 | 227 | </p> |
228 | - <p class="description"><?php _e( 'Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing' ); ?></p> |
|
228 | + <p class="description"><?php _e('Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing'); ?></p> |
|
229 | 229 | </td> |
230 | 230 | </tr> |
231 | - <?php do_action( 'wpinv_discount_form_before_excluded_items', $post ); ?> |
|
231 | + <?php do_action('wpinv_discount_form_before_excluded_items', $post); ?> |
|
232 | 232 | <tr> |
233 | 233 | <th valign="top" scope="row"> |
234 | - <label for="wpinv_discount_excluded_items"><?php _e( 'Excluded Items', 'invoicing' ); ?></label> |
|
234 | + <label for="wpinv_discount_excluded_items"><?php _e('Excluded Items', 'invoicing'); ?></label> |
|
235 | 235 | </th> |
236 | 236 | <td> |
237 | - <p><?php echo wpinv_item_dropdown( array( |
|
237 | + <p><?php echo wpinv_item_dropdown(array( |
|
238 | 238 | 'name' => 'excluded_items[]', |
239 | 239 | 'id' => 'excluded_items', |
240 | 240 | 'selected' => $excluded_items, |
241 | 241 | 'multiple' => true, |
242 | 242 | 'class' => 'medium-text wpi_select2', |
243 | - 'placeholder' => __( 'Select one or more Items', 'invoicing' ), |
|
243 | + 'placeholder' => __('Select one or more Items', 'invoicing'), |
|
244 | 244 | 'show_recurring' => true, |
245 | - ) ); ?> |
|
245 | + )); ?> |
|
246 | 246 | </p> |
247 | - <p class="description"><?php _e( 'Items which are NOT allowed to use this discount.', 'invoicing' ); ?></p> |
|
247 | + <p class="description"><?php _e('Items which are NOT allowed to use this discount.', 'invoicing'); ?></p> |
|
248 | 248 | </td> |
249 | 249 | </tr> |
250 | - <?php do_action( 'wpinv_discount_form_before_start', $post ); ?> |
|
250 | + <?php do_action('wpinv_discount_form_before_start', $post); ?> |
|
251 | 251 | <tr> |
252 | 252 | <th valign="top" scope="row"> |
253 | - <label for="wpinv_discount_start"><?php _e( 'Start Date', 'invoicing' ); ?></label> |
|
253 | + <label for="wpinv_discount_start"><?php _e('Start Date', 'invoicing'); ?></label> |
|
254 | 254 | </th> |
255 | 255 | <td> |
256 | - <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr( $start_date ); ?>"> @ <select id="wpinv_discount_start_h" name="start_h"> |
|
257 | - <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
258 | - <option value="<?php echo $value;?>" <?php selected( $value, $start_h ); ?>><?php echo $value;?></option> |
|
256 | + <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr($start_date); ?>"> @ <select id="wpinv_discount_start_h" name="start_h"> |
|
257 | + <?php for ($i = 0; $i <= 23; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
258 | + <option value="<?php echo $value; ?>" <?php selected($value, $start_h); ?>><?php echo $value; ?></option> |
|
259 | 259 | <?php } ?> |
260 | 260 | </select> : <select id="wpinv_discount_start_m" name="start_m"> |
261 | - <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
262 | - <option value="<?php echo $value;?>" <?php selected( $value, $start_m ); ?>><?php echo $value;?></option> |
|
261 | + <?php for ($i = 0; $i <= 59; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
262 | + <option value="<?php echo $value; ?>" <?php selected($value, $start_m); ?>><?php echo $value; ?></option> |
|
263 | 263 | <?php } ?> |
264 | 264 | </select> |
265 | - <p class="description"><?php _e( 'Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing' ); ?></p> |
|
265 | + <p class="description"><?php _e('Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing'); ?></p> |
|
266 | 266 | </td> |
267 | 267 | </tr> |
268 | - <?php do_action( 'wpinv_discount_form_before_expiration', $post ); ?> |
|
268 | + <?php do_action('wpinv_discount_form_before_expiration', $post); ?> |
|
269 | 269 | <tr> |
270 | 270 | <th valign="top" scope="row"> |
271 | - <label for="wpinv_discount_expiration"><?php _e( 'Expiration Date', 'invoicing' ); ?></label> |
|
271 | + <label for="wpinv_discount_expiration"><?php _e('Expiration Date', 'invoicing'); ?></label> |
|
272 | 272 | </th> |
273 | 273 | <td> |
274 | - <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr( $expiration_date ); ?>"> @ <select id="wpinv_discount_expiration_h" name="expiration_h"> |
|
275 | - <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
276 | - <option value="<?php echo $value;?>" <?php selected( $value, $expiration_h ); ?>><?php echo $value;?></option> |
|
274 | + <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr($expiration_date); ?>"> @ <select id="wpinv_discount_expiration_h" name="expiration_h"> |
|
275 | + <?php for ($i = 0; $i <= 23; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
276 | + <option value="<?php echo $value; ?>" <?php selected($value, $expiration_h); ?>><?php echo $value; ?></option> |
|
277 | 277 | <?php } ?> |
278 | 278 | </select> : <select id="wpinv_discount_expiration_m" name="expiration_m"> |
279 | - <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
280 | - <option value="<?php echo $value;?>" <?php selected( $value, $expiration_m ); ?>><?php echo $value;?></option> |
|
279 | + <?php for ($i = 0; $i <= 59; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
280 | + <option value="<?php echo $value; ?>" <?php selected($value, $expiration_m); ?>><?php echo $value; ?></option> |
|
281 | 281 | <?php } ?> |
282 | 282 | </select> |
283 | - <p class="description"><?php _e( 'Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing' ); ?></p> |
|
283 | + <p class="description"><?php _e('Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing'); ?></p> |
|
284 | 284 | </td> |
285 | 285 | </tr> |
286 | - <?php do_action( 'wpinv_discount_form_before_min_total', $post ); ?> |
|
286 | + <?php do_action('wpinv_discount_form_before_min_total', $post); ?> |
|
287 | 287 | <tr> |
288 | 288 | <th valign="top" scope="row"> |
289 | - <label for="wpinv_discount_min_total"><?php _e( 'Minimum Amount', 'invoicing' ); ?></label> |
|
289 | + <label for="wpinv_discount_min_total"><?php _e('Minimum Amount', 'invoicing'); ?></label> |
|
290 | 290 | </th> |
291 | 291 | <td> |
292 | 292 | <input type="text" name="min_total" id="wpinv_discount_min_total" class="wpi-field-price wpi-price" value="<?php echo $min_total; ?>"> |
293 | - <p class="description"><?php _e( 'This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p> |
|
293 | + <p class="description"><?php _e('This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p> |
|
294 | 294 | </td> |
295 | 295 | </tr> |
296 | - <?php do_action( 'wpinv_discount_form_before_max_total', $post ); ?> |
|
296 | + <?php do_action('wpinv_discount_form_before_max_total', $post); ?> |
|
297 | 297 | <tr> |
298 | 298 | <th valign="top" scope="row"> |
299 | - <label for="wpinv_discount_max_total"><?php _e( 'Maximum Amount', 'invoicing' ); ?></label> |
|
299 | + <label for="wpinv_discount_max_total"><?php _e('Maximum Amount', 'invoicing'); ?></label> |
|
300 | 300 | </th> |
301 | 301 | <td> |
302 | 302 | <input type="text" name="max_total" id="wpinv_discount_max_total" class="wpi-field-price wpi-price" value="<?php echo $max_total; ?>"> |
303 | - <p class="description"><?php _e( 'This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p> |
|
303 | + <p class="description"><?php _e('This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p> |
|
304 | 304 | </td> |
305 | 305 | </tr> |
306 | - <?php do_action( 'wpinv_discount_form_before_recurring', $post ); ?> |
|
306 | + <?php do_action('wpinv_discount_form_before_recurring', $post); ?> |
|
307 | 307 | <tr> |
308 | 308 | <th valign="top" scope="row"> |
309 | - <label for="wpinv_discount_recurring"><?php _e( 'For recurring apply to', 'invoicing' ); ?></label> |
|
309 | + <label for="wpinv_discount_recurring"><?php _e('For recurring apply to', 'invoicing'); ?></label> |
|
310 | 310 | </th> |
311 | 311 | <td> |
312 | 312 | <select id="wpinv_discount_recurring" name="recurring" class="medium-text wpi_select2"> |
313 | - <option value="0" <?php selected( false, $recurring ); ?>><?php _e( 'All payments', 'invoicing' ); ?></option> |
|
314 | - <option value="1" <?php selected( true, $recurring ); ?>><?php _e( 'First payment only', 'invoicing' ); ?></option> |
|
313 | + <option value="0" <?php selected(false, $recurring); ?>><?php _e('All payments', 'invoicing'); ?></option> |
|
314 | + <option value="1" <?php selected(true, $recurring); ?>><?php _e('First payment only', 'invoicing'); ?></option> |
|
315 | 315 | </select> |
316 | - <p class="description"><?php _e( '<b>All payments:</b> Apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> Apply this discount to only first payment of the recurring invoice.', 'invoicing' ); ?></p> |
|
316 | + <p class="description"><?php _e('<b>All payments:</b> Apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> Apply this discount to only first payment of the recurring invoice.', 'invoicing'); ?></p> |
|
317 | 317 | </td> |
318 | 318 | </tr> |
319 | - <?php do_action( 'wpinv_discount_form_before_max_uses', $post ); ?> |
|
319 | + <?php do_action('wpinv_discount_form_before_max_uses', $post); ?> |
|
320 | 320 | <tr> |
321 | 321 | <th valign="top" scope="row"> |
322 | - <label for="wpinv_discount_max_uses"><?php _e( 'Max Uses', 'invoicing' ); ?></label> |
|
322 | + <label for="wpinv_discount_max_uses"><?php _e('Max Uses', 'invoicing'); ?></label> |
|
323 | 323 | </th> |
324 | 324 | <td> |
325 | 325 | <input type="number" min="0" step="1" id="wpinv_discount_max_uses" name="max_uses" class="medium-text" value="<?php echo $max_uses; ?>"> |
326 | - <p class="description"><?php _e( 'The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing' ); ?></p> |
|
326 | + <p class="description"><?php _e('The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing'); ?></p> |
|
327 | 327 | </td> |
328 | 328 | </tr> |
329 | - <?php do_action( 'wpinv_discount_form_before_single_use', $post ); ?> |
|
329 | + <?php do_action('wpinv_discount_form_before_single_use', $post); ?> |
|
330 | 330 | <tr> |
331 | 331 | <th valign="top" scope="row"> |
332 | - <label for="wpinv_discount_single_use"><?php _e( 'Use Once Per User', 'invoicing' ); ?></label> |
|
332 | + <label for="wpinv_discount_single_use"><?php _e('Use Once Per User', 'invoicing'); ?></label> |
|
333 | 333 | </th> |
334 | 334 | <td> |
335 | - <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked( true, $single_use ); ?>> |
|
336 | - <span class="description"><?php _e( 'Limit this discount to a single use per user?', 'invoicing' ); ?></span> |
|
335 | + <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked(true, $single_use); ?>> |
|
336 | + <span class="description"><?php _e('Limit this discount to a single use per user?', 'invoicing'); ?></span> |
|
337 | 337 | </td> |
338 | 338 | </tr> |
339 | - <?php do_action( 'wpinv_discount_form_last', $post ); ?> |
|
339 | + <?php do_action('wpinv_discount_form_last', $post); ?> |
|
340 | 340 | </tbody> |
341 | 341 | </table> |
342 | -<?php do_action( 'wpinv_discount_form_bottom', $post ); ?> |
|
342 | +<?php do_action('wpinv_discount_form_bottom', $post); ?> |
|
343 | 343 | <?php |
344 | 344 | } |
345 | 345 | |
346 | -function wpinv_discount_metabox_save( $post_id, $post, $update = false ) { |
|
347 | - $post_type = !empty( $post ) ? $post->post_type : ''; |
|
346 | +function wpinv_discount_metabox_save($post_id, $post, $update = false) { |
|
347 | + $post_type = !empty($post) ? $post->post_type : ''; |
|
348 | 348 | |
349 | - if ( $post_type != 'wpi_discount' ) { |
|
349 | + if ($post_type != 'wpi_discount') { |
|
350 | 350 | return; |
351 | 351 | } |
352 | 352 | |
353 | - if ( !isset( $_POST['wpinv_discount_metabox_nonce'] ) || ( isset( $_POST['wpinv_discount_metabox_nonce'] ) && !wp_verify_nonce( $_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce' ) ) ) { |
|
353 | + if (!isset($_POST['wpinv_discount_metabox_nonce']) || (isset($_POST['wpinv_discount_metabox_nonce']) && !wp_verify_nonce($_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce'))) { |
|
354 | 354 | return; |
355 | 355 | } |
356 | 356 | |
357 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
357 | + if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || (defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
358 | 358 | return; |
359 | 359 | } |
360 | 360 | |
361 | - if ( !current_user_can( 'manage_options', $post_id ) ) { |
|
361 | + if (!current_user_can('manage_options', $post_id)) { |
|
362 | 362 | return; |
363 | 363 | } |
364 | 364 | |
365 | - if ( !empty( $_POST['start'] ) && isset( $_POST['start_h'] ) && isset( $_POST['start_m'] ) && $_POST['start_h'] !== '' && $_POST['start_m'] !== '' ) { |
|
365 | + if (!empty($_POST['start']) && isset($_POST['start_h']) && isset($_POST['start_m']) && $_POST['start_h'] !== '' && $_POST['start_m'] !== '') { |
|
366 | 366 | $_POST['start'] = $_POST['start'] . ' ' . $_POST['start_h'] . ':' . $_POST['start_m']; |
367 | 367 | } |
368 | 368 | |
369 | - if ( !empty( $_POST['expiration'] ) && isset( $_POST['expiration_h'] ) && isset( $_POST['expiration_m'] ) ) { |
|
369 | + if (!empty($_POST['expiration']) && isset($_POST['expiration_h']) && isset($_POST['expiration_m'])) { |
|
370 | 370 | $_POST['expiration'] = $_POST['expiration'] . ' ' . $_POST['expiration_h'] . ':' . $_POST['expiration_m']; |
371 | 371 | } |
372 | 372 | |
373 | - return wpinv_store_discount( $post_id, $_POST, $post, $update ); |
|
373 | + return wpinv_store_discount($post_id, $_POST, $post, $update); |
|
374 | 374 | } |
375 | -add_action( 'save_post', 'wpinv_discount_metabox_save', 10, 3 ); |
|
376 | 375 | \ No newline at end of file |
376 | +add_action('save_post', 'wpinv_discount_metabox_save', 10, 3); |
|
377 | 377 | \ No newline at end of file |