@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly. |
3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | 5 | /** |
6 | 6 | * The Subscriptions DB Class |
@@ -68,8 +68,8 @@ discard block |
||
68 | 68 | 'transaction_id' => '', |
69 | 69 | 'parent_payment_id' => 0, |
70 | 70 | 'product_id' => 0, |
71 | - 'created' => date( 'Y-m-d H:i:s' ), |
|
72 | - 'expiration' => date( 'Y-m-d H:i:s' ), |
|
71 | + 'created' => date('Y-m-d H:i:s'), |
|
72 | + 'expiration' => date('Y-m-d H:i:s'), |
|
73 | 73 | 'trial_period' => '', |
74 | 74 | 'status' => '', |
75 | 75 | 'profile_id' => '', |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | * @access public |
83 | 83 | * @since 1.0.0 |
84 | 84 | */ |
85 | - public function get_subscriptions( $args = array() ) { |
|
85 | + public function get_subscriptions($args = array()) { |
|
86 | 86 | global $wpdb; |
87 | 87 | |
88 | 88 | $defaults = array( |
89 | - 'number' => get_option( 'posts_per_page' ), |
|
89 | + 'number' => get_option('posts_per_page'), |
|
90 | 90 | 'offset' => 0, |
91 | 91 | 'search' => '', |
92 | 92 | 'customer_id' => 0, |
@@ -94,21 +94,21 @@ discard block |
||
94 | 94 | 'order' => 'DESC' |
95 | 95 | ); |
96 | 96 | |
97 | - $args = wp_parse_args( $args, $defaults ); |
|
97 | + $args = wp_parse_args($args, $defaults); |
|
98 | 98 | |
99 | - if( $args['number'] < 1 ) { |
|
99 | + if ($args['number'] < 1) { |
|
100 | 100 | $args['number'] = 999999999999; |
101 | 101 | } |
102 | 102 | |
103 | 103 | $where = ' WHERE 1=1 '; |
104 | 104 | |
105 | 105 | // specific customers |
106 | - if( ! empty( $args['id'] ) ) { |
|
106 | + if (!empty($args['id'])) { |
|
107 | 107 | |
108 | - if( is_array( $args['id'] ) ) { |
|
109 | - $ids = implode( ',', array_map('intval', $args['id'] ) ); |
|
108 | + if (is_array($args['id'])) { |
|
109 | + $ids = implode(',', array_map('intval', $args['id'])); |
|
110 | 110 | } else { |
111 | - $ids = intval( $args['id'] ); |
|
111 | + $ids = intval($args['id']); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | $where .= " AND `id` IN( {$ids} ) "; |
@@ -116,12 +116,12 @@ discard block |
||
116 | 116 | } |
117 | 117 | |
118 | 118 | // Specific products |
119 | - if( ! empty( $args['product_id'] ) ) { |
|
119 | + if (!empty($args['product_id'])) { |
|
120 | 120 | |
121 | - if( is_array( $args['product_id'] ) ) { |
|
122 | - $product_ids = implode( ',', array_map('intval', $args['product_id'] ) ); |
|
121 | + if (is_array($args['product_id'])) { |
|
122 | + $product_ids = implode(',', array_map('intval', $args['product_id'])); |
|
123 | 123 | } else { |
124 | - $product_ids = intval( $args['product_id'] ); |
|
124 | + $product_ids = intval($args['product_id']); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | $where .= " AND `product_id` IN( {$product_ids} ) "; |
@@ -129,12 +129,12 @@ discard block |
||
129 | 129 | } |
130 | 130 | |
131 | 131 | // Specific parent payments |
132 | - if( ! empty( $args['parent_payment_id'] ) ) { |
|
132 | + if (!empty($args['parent_payment_id'])) { |
|
133 | 133 | |
134 | - if( is_array( $args['parent_payment_id'] ) ) { |
|
135 | - $parent_payment_ids = implode( ',', array_map('intval', $args['parent_payment_id'] ) ); |
|
134 | + if (is_array($args['parent_payment_id'])) { |
|
135 | + $parent_payment_ids = implode(',', array_map('intval', $args['parent_payment_id'])); |
|
136 | 136 | } else { |
137 | - $parent_payment_ids = intval( $args['parent_payment_id'] ); |
|
137 | + $parent_payment_ids = intval($args['parent_payment_id']); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | $where .= " AND `parent_payment_id` IN( {$parent_payment_ids} ) "; |
@@ -142,12 +142,12 @@ discard block |
||
142 | 142 | } |
143 | 143 | |
144 | 144 | // Specific transaction IDs |
145 | - if( ! empty( $args['transaction_id'] ) ) { |
|
145 | + if (!empty($args['transaction_id'])) { |
|
146 | 146 | |
147 | - if( is_array( $args['transaction_id'] ) ) { |
|
148 | - $transaction_ids = implode( "','", array_map('sanitize_text_field', $args['transaction_id'] ) ); |
|
147 | + if (is_array($args['transaction_id'])) { |
|
148 | + $transaction_ids = implode("','", array_map('sanitize_text_field', $args['transaction_id'])); |
|
149 | 149 | } else { |
150 | - $transaction_ids = sanitize_text_field( $args['transaction_id'] ); |
|
150 | + $transaction_ids = sanitize_text_field($args['transaction_id']); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | $where .= " AND `transaction_id` IN ( '{$transaction_ids}' ) "; |
@@ -155,12 +155,12 @@ discard block |
||
155 | 155 | } |
156 | 156 | |
157 | 157 | // Subscriptoins for specific customers |
158 | - if( ! empty( $args['customer_id'] ) ) { |
|
158 | + if (!empty($args['customer_id'])) { |
|
159 | 159 | |
160 | - if( is_array( $args['customer_id'] ) ) { |
|
161 | - $customer_ids = implode( ',', array_map('intval', $args['customer_id'] ) ); |
|
160 | + if (is_array($args['customer_id'])) { |
|
161 | + $customer_ids = implode(',', array_map('intval', $args['customer_id'])); |
|
162 | 162 | } else { |
163 | - $customer_ids = intval( $args['customer_id'] ); |
|
163 | + $customer_ids = intval($args['customer_id']); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | $where .= " AND `customer_id` IN( {$customer_ids} ) "; |
@@ -168,12 +168,12 @@ discard block |
||
168 | 168 | } |
169 | 169 | |
170 | 170 | // Subscriptions for specific profile IDs |
171 | - if( ! empty( $args['profile_id'] ) ) { |
|
171 | + if (!empty($args['profile_id'])) { |
|
172 | 172 | |
173 | - if( is_array( $args['profile_id'] ) ) { |
|
174 | - $profile_ids = implode( "','", array_map('sanitize_text_field', $args['profile_id'] ) ); |
|
173 | + if (is_array($args['profile_id'])) { |
|
174 | + $profile_ids = implode("','", array_map('sanitize_text_field', $args['profile_id'])); |
|
175 | 175 | } else { |
176 | - $profile_ids = sanitize_text_field( $args['profile_id'] ); |
|
176 | + $profile_ids = sanitize_text_field($args['profile_id']); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | $where .= " AND `profile_id` IN( '{$profile_ids}' ) "; |
@@ -181,12 +181,12 @@ discard block |
||
181 | 181 | } |
182 | 182 | |
183 | 183 | // Subscriptions for specific statuses |
184 | - if( ! empty( $args['status'] ) ) { |
|
184 | + if (!empty($args['status'])) { |
|
185 | 185 | |
186 | - if( is_array( $args['status'] ) ) { |
|
187 | - $statuses = implode( "','", array_map( 'sanitize_text_field', $args['status'] ) ); |
|
186 | + if (is_array($args['status'])) { |
|
187 | + $statuses = implode("','", array_map('sanitize_text_field', $args['status'])); |
|
188 | 188 | } else { |
189 | - $statuses = sanitize_text_field( $args['status'] ); |
|
189 | + $statuses = sanitize_text_field($args['status']); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | $where .= " AND `status` IN( '{$statuses}' ) "; |
@@ -194,21 +194,21 @@ discard block |
||
194 | 194 | } |
195 | 195 | |
196 | 196 | // Subscriptions created for a specific date or in a date range |
197 | - if( ! empty( $args['date'] ) ) { |
|
197 | + if (!empty($args['date'])) { |
|
198 | 198 | |
199 | - if( is_array( $args['date'] ) ) { |
|
199 | + if (is_array($args['date'])) { |
|
200 | 200 | |
201 | - if( ! empty( $args['date']['start'] ) ) { |
|
201 | + if (!empty($args['date']['start'])) { |
|
202 | 202 | |
203 | - $start = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) ); |
|
203 | + $start = date('Y-m-d H:i:s', strtotime($args['date']['start'])); |
|
204 | 204 | |
205 | 205 | $where .= " AND `created` >= '{$start}'"; |
206 | 206 | |
207 | 207 | } |
208 | 208 | |
209 | - if( ! empty( $args['date']['end'] ) ) { |
|
209 | + if (!empty($args['date']['end'])) { |
|
210 | 210 | |
211 | - $end = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) ); |
|
211 | + $end = date('Y-m-d H:i:s', strtotime($args['date']['end'])); |
|
212 | 212 | |
213 | 213 | $where .= " AND `created` <= '{$end}'"; |
214 | 214 | |
@@ -216,9 +216,9 @@ discard block |
||
216 | 216 | |
217 | 217 | } else { |
218 | 218 | |
219 | - $year = date( 'Y', strtotime( $args['date'] ) ); |
|
220 | - $month = date( 'm', strtotime( $args['date'] ) ); |
|
221 | - $day = date( 'd', strtotime( $args['date'] ) ); |
|
219 | + $year = date('Y', strtotime($args['date'])); |
|
220 | + $month = date('m', strtotime($args['date'])); |
|
221 | + $day = date('d', strtotime($args['date'])); |
|
222 | 222 | |
223 | 223 | $where .= " AND $year = YEAR ( created ) AND $month = MONTH ( created ) AND $day = DAY ( created )"; |
224 | 224 | } |
@@ -226,21 +226,21 @@ discard block |
||
226 | 226 | } |
227 | 227 | |
228 | 228 | // Subscriptions with a specific expiration date or in an expiration date range |
229 | - if( ! empty( $args['expiration'] ) ) { |
|
229 | + if (!empty($args['expiration'])) { |
|
230 | 230 | |
231 | - if( is_array( $args['expiration'] ) ) { |
|
231 | + if (is_array($args['expiration'])) { |
|
232 | 232 | |
233 | - if( ! empty( $args['expiration']['start'] ) ) { |
|
233 | + if (!empty($args['expiration']['start'])) { |
|
234 | 234 | |
235 | - $start = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['start'] ) ); |
|
235 | + $start = date('Y-m-d H:i:s', strtotime($args['expiration']['start'])); |
|
236 | 236 | |
237 | 237 | $where .= " AND `expiration` >= '{$start}'"; |
238 | 238 | |
239 | 239 | } |
240 | 240 | |
241 | - if( ! empty( $args['expiration']['end'] ) ) { |
|
241 | + if (!empty($args['expiration']['end'])) { |
|
242 | 242 | |
243 | - $end = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['end'] ) ); |
|
243 | + $end = date('Y-m-d H:i:s', strtotime($args['expiration']['end'])); |
|
244 | 244 | |
245 | 245 | $where .= " AND `expiration` <= '{$end}'"; |
246 | 246 | |
@@ -248,73 +248,73 @@ discard block |
||
248 | 248 | |
249 | 249 | } else { |
250 | 250 | |
251 | - $year = date( 'Y', strtotime( $args['expiration'] ) ); |
|
252 | - $month = date( 'm', strtotime( $args['expiration'] ) ); |
|
253 | - $day = date( 'd', strtotime( $args['expiration'] ) ); |
|
251 | + $year = date('Y', strtotime($args['expiration'])); |
|
252 | + $month = date('m', strtotime($args['expiration'])); |
|
253 | + $day = date('d', strtotime($args['expiration'])); |
|
254 | 254 | |
255 | 255 | $where .= " AND $year = YEAR ( expiration ) AND $month = MONTH ( expiration ) AND $day = DAY ( expiration )"; |
256 | 256 | } |
257 | 257 | |
258 | 258 | } |
259 | 259 | |
260 | - if ( ! empty( $args['search'] ) ) { |
|
260 | + if (!empty($args['search'])) { |
|
261 | 261 | |
262 | - if( false !== strpos( 'id:', $args['search'] ) ) { |
|
262 | + if (false !== strpos('id:', $args['search'])) { |
|
263 | 263 | |
264 | - $args['search'] = trim( str_replace( 'id:', '', $args['search'] ) ); |
|
265 | - $where .= " AND `id` = '" . esc_sql( $args['search'] ) . "'"; |
|
264 | + $args['search'] = trim(str_replace('id:', '', $args['search'])); |
|
265 | + $where .= " AND `id` = '" . esc_sql($args['search']) . "'"; |
|
266 | 266 | |
267 | - } else if( false !== strpos( $args['search'], 'txn:' ) ) { |
|
267 | + } else if (false !== strpos($args['search'], 'txn:')) { |
|
268 | 268 | |
269 | - $args['search'] = trim( str_replace( 'txn:', '', $args['search'] ) ); |
|
270 | - $where .= " AND `transaction_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
269 | + $args['search'] = trim(str_replace('txn:', '', $args['search'])); |
|
270 | + $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'"; |
|
271 | 271 | |
272 | - } else if( false !== strpos( $args['search'], 'profile_id:' ) ) { |
|
272 | + } else if (false !== strpos($args['search'], 'profile_id:')) { |
|
273 | 273 | |
274 | - $args['search'] = trim( str_replace( 'profile_id:', '', $args['search'] ) ); |
|
275 | - $where .= " AND `profile_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
274 | + $args['search'] = trim(str_replace('profile_id:', '', $args['search'])); |
|
275 | + $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'"; |
|
276 | 276 | |
277 | - } else if( false !== strpos( $args['search'], 'product_id:' ) ) { |
|
277 | + } else if (false !== strpos($args['search'], 'product_id:')) { |
|
278 | 278 | |
279 | - $args['search'] = trim( str_replace( 'product_id:', '', $args['search'] ) ); |
|
280 | - $where .= " AND `product_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
279 | + $args['search'] = trim(str_replace('product_id:', '', $args['search'])); |
|
280 | + $where .= " AND `product_id` = '" . esc_sql($args['search']) . "'"; |
|
281 | 281 | |
282 | - } else if( false !== strpos( $args['search'], 'customer_id:' ) ) { |
|
282 | + } else if (false !== strpos($args['search'], 'customer_id:')) { |
|
283 | 283 | |
284 | - $args['search'] = trim( str_replace( 'customer_id:', '', $args['search'] ) ); |
|
285 | - $where .= " AND `customer_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
284 | + $args['search'] = trim(str_replace('customer_id:', '', $args['search'])); |
|
285 | + $where .= " AND `customer_id` = '" . esc_sql($args['search']) . "'"; |
|
286 | 286 | |
287 | 287 | } else { |
288 | 288 | |
289 | - $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `profile_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `transaction_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `product_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `id` = '" . esc_sql( $args['search'] ) . "' )"; |
|
289 | + $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `profile_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `transaction_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `product_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `id` = '" . esc_sql($args['search']) . "' )"; |
|
290 | 290 | |
291 | 291 | } |
292 | 292 | |
293 | 293 | } |
294 | 294 | |
295 | - $args['orderby'] = ! array_key_exists( $args['orderby'], $this->get_columns() ) ? 'id' : $args['orderby']; |
|
295 | + $args['orderby'] = !array_key_exists($args['orderby'], $this->get_columns()) ? 'id' : $args['orderby']; |
|
296 | 296 | |
297 | - if( 'amount' == $args['orderby'] ) { |
|
297 | + if ('amount' == $args['orderby']) { |
|
298 | 298 | $args['orderby'] = 'amount+0'; |
299 | 299 | } |
300 | 300 | |
301 | - $cache_key = md5( 'wpinv_subscriptions_' . serialize( $args ) ); |
|
301 | + $cache_key = md5('wpinv_subscriptions_' . serialize($args)); |
|
302 | 302 | |
303 | - $subscriptions = wp_cache_get( $cache_key, 'subscriptions' ); |
|
303 | + $subscriptions = wp_cache_get($cache_key, 'subscriptions'); |
|
304 | 304 | |
305 | - $args['orderby'] = esc_sql( $args['orderby'] ); |
|
306 | - $args['order'] = esc_sql( $args['order'] ); |
|
305 | + $args['orderby'] = esc_sql($args['orderby']); |
|
306 | + $args['order'] = esc_sql($args['order']); |
|
307 | 307 | |
308 | - if( $subscriptions === false ) { |
|
309 | - $subscriptions = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint( $args['offset'] ), absint( $args['number'] ) ), OBJECT ); |
|
308 | + if ($subscriptions === false) { |
|
309 | + $subscriptions = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint($args['offset']), absint($args['number'])), OBJECT); |
|
310 | 310 | |
311 | - if( ! empty( $subscriptions ) ) { |
|
311 | + if (!empty($subscriptions)) { |
|
312 | 312 | |
313 | - foreach( $subscriptions as $key => $subscription ) { |
|
314 | - $subscriptions[ $key ] = new WPInv_Subscription( $subscription ); |
|
313 | + foreach ($subscriptions as $key => $subscription) { |
|
314 | + $subscriptions[$key] = new WPInv_Subscription($subscription); |
|
315 | 315 | } |
316 | 316 | |
317 | - wp_cache_set( $cache_key, $subscriptions, 'subscriptions', 3600 ); |
|
317 | + wp_cache_set($cache_key, $subscriptions, 'subscriptions', 3600); |
|
318 | 318 | |
319 | 319 | } |
320 | 320 | |
@@ -329,19 +329,19 @@ discard block |
||
329 | 329 | * @access public |
330 | 330 | * @since 1.0.0 |
331 | 331 | */ |
332 | - public function count( $args = array() ) { |
|
332 | + public function count($args = array()) { |
|
333 | 333 | |
334 | 334 | global $wpdb; |
335 | 335 | |
336 | 336 | $where = ' WHERE 1=1 '; |
337 | 337 | |
338 | 338 | // specific customers |
339 | - if( ! empty( $args['id'] ) ) { |
|
339 | + if (!empty($args['id'])) { |
|
340 | 340 | |
341 | - if( is_array( $args['id'] ) ) { |
|
342 | - $ids = implode( ',', array_map('intval', $args['id'] ) ); |
|
341 | + if (is_array($args['id'])) { |
|
342 | + $ids = implode(',', array_map('intval', $args['id'])); |
|
343 | 343 | } else { |
344 | - $ids = intval( $args['id'] ); |
|
344 | + $ids = intval($args['id']); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | $where .= " AND `id` IN( {$ids} ) "; |
@@ -349,12 +349,12 @@ discard block |
||
349 | 349 | } |
350 | 350 | |
351 | 351 | // Specific products |
352 | - if( ! empty( $args['product_id'] ) ) { |
|
352 | + if (!empty($args['product_id'])) { |
|
353 | 353 | |
354 | - if( is_array( $args['product_id'] ) ) { |
|
355 | - $product_ids = implode( ',', array_map('intval', $args['product_id'] ) ); |
|
354 | + if (is_array($args['product_id'])) { |
|
355 | + $product_ids = implode(',', array_map('intval', $args['product_id'])); |
|
356 | 356 | } else { |
357 | - $product_ids = intval( $args['product_id'] ); |
|
357 | + $product_ids = intval($args['product_id']); |
|
358 | 358 | } |
359 | 359 | |
360 | 360 | $where .= " AND `product_id` IN( {$product_ids} ) "; |
@@ -362,12 +362,12 @@ discard block |
||
362 | 362 | } |
363 | 363 | |
364 | 364 | // Specific parent payments |
365 | - if( ! empty( $args['parent_payment_id'] ) ) { |
|
365 | + if (!empty($args['parent_payment_id'])) { |
|
366 | 366 | |
367 | - if( is_array( $args['parent_payment_id'] ) ) { |
|
368 | - $parent_payment_ids = implode( ',', array_map('intval', $args['parent_payment_id'] ) ); |
|
367 | + if (is_array($args['parent_payment_id'])) { |
|
368 | + $parent_payment_ids = implode(',', array_map('intval', $args['parent_payment_id'])); |
|
369 | 369 | } else { |
370 | - $parent_payment_ids = intval( $args['parent_payment_id'] ); |
|
370 | + $parent_payment_ids = intval($args['parent_payment_id']); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | $where .= " AND `parent_payment_id` IN( {$parent_payment_ids} ) "; |
@@ -375,12 +375,12 @@ discard block |
||
375 | 375 | } |
376 | 376 | |
377 | 377 | // Subscriptoins for specific customers |
378 | - if( ! empty( $args['customer_id'] ) ) { |
|
378 | + if (!empty($args['customer_id'])) { |
|
379 | 379 | |
380 | - if( is_array( $args['customer_id'] ) ) { |
|
381 | - $customer_ids = implode( ',', array_map('intval', $args['customer_id'] ) ); |
|
380 | + if (is_array($args['customer_id'])) { |
|
381 | + $customer_ids = implode(',', array_map('intval', $args['customer_id'])); |
|
382 | 382 | } else { |
383 | - $customer_ids = intval( $args['customer_id'] ); |
|
383 | + $customer_ids = intval($args['customer_id']); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | $where .= " AND `customer_id` IN( {$customer_ids} ) "; |
@@ -388,12 +388,12 @@ discard block |
||
388 | 388 | } |
389 | 389 | |
390 | 390 | // Subscriptions for specific profile IDs |
391 | - if( ! empty( $args['profile_id'] ) ) { |
|
391 | + if (!empty($args['profile_id'])) { |
|
392 | 392 | |
393 | - if( is_array( $args['profile_id'] ) ) { |
|
394 | - $profile_ids = implode( ',', array_map('intval', $args['profile_id'] ) ); |
|
393 | + if (is_array($args['profile_id'])) { |
|
394 | + $profile_ids = implode(',', array_map('intval', $args['profile_id'])); |
|
395 | 395 | } else { |
396 | - $profile_ids = intval( $args['profile_id'] ); |
|
396 | + $profile_ids = intval($args['profile_id']); |
|
397 | 397 | } |
398 | 398 | |
399 | 399 | $where .= " AND `profile_id` IN( {$profile_ids} ) "; |
@@ -401,12 +401,12 @@ discard block |
||
401 | 401 | } |
402 | 402 | |
403 | 403 | // Specific transaction IDs |
404 | - if( ! empty( $args['transaction_id'] ) ) { |
|
404 | + if (!empty($args['transaction_id'])) { |
|
405 | 405 | |
406 | - if( is_array( $args['transaction_id'] ) ) { |
|
407 | - $transaction_ids = implode( ',', array_map('sanitize_text_field', $args['transaction_id'] ) ); |
|
406 | + if (is_array($args['transaction_id'])) { |
|
407 | + $transaction_ids = implode(',', array_map('sanitize_text_field', $args['transaction_id'])); |
|
408 | 408 | } else { |
409 | - $transaction_ids = sanitize_text_field( $args['transaction_id'] ); |
|
409 | + $transaction_ids = sanitize_text_field($args['transaction_id']); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | $where .= " AND `transaction_id` IN( {$transaction_ids} ) "; |
@@ -414,10 +414,10 @@ discard block |
||
414 | 414 | } |
415 | 415 | |
416 | 416 | // Subscriptions for specific statuses |
417 | - if( ! empty( $args['status'] ) ) { |
|
417 | + if (!empty($args['status'])) { |
|
418 | 418 | |
419 | - if( is_array( $args['status'] ) ) { |
|
420 | - $statuses = implode( ',', $args['status'] ); |
|
419 | + if (is_array($args['status'])) { |
|
420 | + $statuses = implode(',', $args['status']); |
|
421 | 421 | $where .= " AND `status` IN( {$statuses} ) "; |
422 | 422 | } else { |
423 | 423 | $statuses = $args['status']; |
@@ -429,21 +429,21 @@ discard block |
||
429 | 429 | } |
430 | 430 | |
431 | 431 | // Subscriptions created for a specific date or in a date range |
432 | - if( ! empty( $args['date'] ) ) { |
|
432 | + if (!empty($args['date'])) { |
|
433 | 433 | |
434 | - if( is_array( $args['date'] ) ) { |
|
434 | + if (is_array($args['date'])) { |
|
435 | 435 | |
436 | - if( ! empty( $args['date']['start'] ) ) { |
|
436 | + if (!empty($args['date']['start'])) { |
|
437 | 437 | |
438 | - $start = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) ); |
|
438 | + $start = date('Y-m-d H:i:s', strtotime($args['date']['start'])); |
|
439 | 439 | |
440 | 440 | $where .= " AND `created` >= '{$start}'"; |
441 | 441 | |
442 | 442 | } |
443 | 443 | |
444 | - if( ! empty( $args['date']['end'] ) ) { |
|
444 | + if (!empty($args['date']['end'])) { |
|
445 | 445 | |
446 | - $end = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) ); |
|
446 | + $end = date('Y-m-d H:i:s', strtotime($args['date']['end'])); |
|
447 | 447 | |
448 | 448 | $where .= " AND `created` <= '{$end}'"; |
449 | 449 | |
@@ -451,9 +451,9 @@ discard block |
||
451 | 451 | |
452 | 452 | } else { |
453 | 453 | |
454 | - $year = date( 'Y', strtotime( $args['date'] ) ); |
|
455 | - $month = date( 'm', strtotime( $args['date'] ) ); |
|
456 | - $day = date( 'd', strtotime( $args['date'] ) ); |
|
454 | + $year = date('Y', strtotime($args['date'])); |
|
455 | + $month = date('m', strtotime($args['date'])); |
|
456 | + $day = date('d', strtotime($args['date'])); |
|
457 | 457 | |
458 | 458 | $where .= " AND $year = YEAR ( created ) AND $month = MONTH ( created ) AND $day = DAY ( created )"; |
459 | 459 | } |
@@ -461,21 +461,21 @@ discard block |
||
461 | 461 | } |
462 | 462 | |
463 | 463 | // Subscriptions with a specific expiration date or in an expiration date range |
464 | - if( ! empty( $args['expiration'] ) ) { |
|
464 | + if (!empty($args['expiration'])) { |
|
465 | 465 | |
466 | - if( is_array( $args['expiration'] ) ) { |
|
466 | + if (is_array($args['expiration'])) { |
|
467 | 467 | |
468 | - if( ! empty( $args['expiration']['start'] ) ) { |
|
468 | + if (!empty($args['expiration']['start'])) { |
|
469 | 469 | |
470 | - $start = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['start'] ) ); |
|
470 | + $start = date('Y-m-d H:i:s', strtotime($args['expiration']['start'])); |
|
471 | 471 | |
472 | 472 | $where .= " AND `expiration` >= '{$start}'"; |
473 | 473 | |
474 | 474 | } |
475 | 475 | |
476 | - if( ! empty( $args['expiration']['end'] ) ) { |
|
476 | + if (!empty($args['expiration']['end'])) { |
|
477 | 477 | |
478 | - $end = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['end'] ) ); |
|
478 | + $end = date('Y-m-d H:i:s', strtotime($args['expiration']['end'])); |
|
479 | 479 | |
480 | 480 | $where .= " AND `expiration` <= '{$end}'"; |
481 | 481 | |
@@ -483,64 +483,64 @@ discard block |
||
483 | 483 | |
484 | 484 | } else { |
485 | 485 | |
486 | - $year = date( 'Y', strtotime( $args['expiration'] ) ); |
|
487 | - $month = date( 'm', strtotime( $args['expiration'] ) ); |
|
488 | - $day = date( 'd', strtotime( $args['expiration'] ) ); |
|
486 | + $year = date('Y', strtotime($args['expiration'])); |
|
487 | + $month = date('m', strtotime($args['expiration'])); |
|
488 | + $day = date('d', strtotime($args['expiration'])); |
|
489 | 489 | |
490 | 490 | $where .= " AND $year = YEAR ( expiration ) AND $month = MONTH ( expiration ) AND $day = DAY ( expiration )"; |
491 | 491 | } |
492 | 492 | |
493 | 493 | } |
494 | 494 | |
495 | - if ( ! empty( $args['search'] ) ) { |
|
495 | + if (!empty($args['search'])) { |
|
496 | 496 | |
497 | - if( false !== strpos( 'id:', $args['search'] ) ) { |
|
497 | + if (false !== strpos('id:', $args['search'])) { |
|
498 | 498 | |
499 | - $args['search'] = trim( str_replace( 'id:', '', $args['search'] ) ); |
|
500 | - $where .= " AND `id` = '" . esc_sql( $args['search'] ) . "'"; |
|
499 | + $args['search'] = trim(str_replace('id:', '', $args['search'])); |
|
500 | + $where .= " AND `id` = '" . esc_sql($args['search']) . "'"; |
|
501 | 501 | |
502 | - } else if( false !== strpos( $args['search'], 'txn:' ) ) { |
|
502 | + } else if (false !== strpos($args['search'], 'txn:')) { |
|
503 | 503 | |
504 | - $args['search'] = trim( str_replace( 'txn:', '', $args['search'] ) ); |
|
505 | - $where .= " AND `transaction_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
504 | + $args['search'] = trim(str_replace('txn:', '', $args['search'])); |
|
505 | + $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'"; |
|
506 | 506 | |
507 | - } else if( false !== strpos( $args['search'], 'profile_id:' ) ) { |
|
507 | + } else if (false !== strpos($args['search'], 'profile_id:')) { |
|
508 | 508 | |
509 | - $args['search'] = trim( str_replace( 'profile_id:', '', $args['search'] ) ); |
|
510 | - $where .= " AND `profile_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
509 | + $args['search'] = trim(str_replace('profile_id:', '', $args['search'])); |
|
510 | + $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'"; |
|
511 | 511 | |
512 | - } else if( false !== strpos( $args['search'], 'product_id:' ) ) { |
|
512 | + } else if (false !== strpos($args['search'], 'product_id:')) { |
|
513 | 513 | |
514 | - $args['search'] = trim( str_replace( 'product_id:', '', $args['search'] ) ); |
|
515 | - $where .= " AND `product_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
514 | + $args['search'] = trim(str_replace('product_id:', '', $args['search'])); |
|
515 | + $where .= " AND `product_id` = '" . esc_sql($args['search']) . "'"; |
|
516 | 516 | |
517 | - } else if( false !== strpos( $args['search'], 'customer_id:' ) ) { |
|
517 | + } else if (false !== strpos($args['search'], 'customer_id:')) { |
|
518 | 518 | |
519 | - $args['search'] = trim( str_replace( 'customer_id:', '', $args['search'] ) ); |
|
520 | - $where .= " AND `customer_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
519 | + $args['search'] = trim(str_replace('customer_id:', '', $args['search'])); |
|
520 | + $where .= " AND `customer_id` = '" . esc_sql($args['search']) . "'"; |
|
521 | 521 | |
522 | 522 | } else { |
523 | 523 | |
524 | - $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `profile_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `transaction_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `product_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `id` = '" . esc_sql( $args['search'] ) . "' )"; |
|
524 | + $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `profile_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `transaction_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `product_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `id` = '" . esc_sql($args['search']) . "' )"; |
|
525 | 525 | |
526 | 526 | } |
527 | 527 | |
528 | 528 | } |
529 | 529 | |
530 | - $cache_key = md5( 'wpinv_subscriptions_count' . serialize( $args ) ); |
|
530 | + $cache_key = md5('wpinv_subscriptions_count' . serialize($args)); |
|
531 | 531 | |
532 | - $count = wp_cache_get( $cache_key, 'subscriptions' ); |
|
532 | + $count = wp_cache_get($cache_key, 'subscriptions'); |
|
533 | 533 | |
534 | - if( $count === false ) { |
|
534 | + if ($count === false) { |
|
535 | 535 | |
536 | 536 | $sql = "SELECT COUNT($this->primary_key) FROM " . $this->table_name . "{$where};"; |
537 | - $count = $wpdb->get_var( $sql ); |
|
537 | + $count = $wpdb->get_var($sql); |
|
538 | 538 | |
539 | - wp_cache_set( $cache_key, $count, 'subscriptions', 3600 ); |
|
539 | + wp_cache_set($cache_key, $count, 'subscriptions', 3600); |
|
540 | 540 | |
541 | 541 | } |
542 | 542 | |
543 | - return absint( $count ); |
|
543 | + return absint($count); |
|
544 | 544 | |
545 | 545 | } |
546 | 546 | |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | public function create_table() { |
554 | 554 | global $wpdb; |
555 | 555 | |
556 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
556 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
557 | 557 | |
558 | 558 | $sql = "CREATE TABLE " . $this->table_name . " ( |
559 | 559 | id bigint(20) NOT NULL AUTO_INCREMENT, |
@@ -578,9 +578,9 @@ discard block |
||
578 | 578 | KEY customer_and_status ( customer_id, status) |
579 | 579 | ) CHARACTER SET utf8 COLLATE utf8_general_ci;"; |
580 | 580 | |
581 | - dbDelta( $sql ); |
|
581 | + dbDelta($sql); |
|
582 | 582 | |
583 | - update_option( $this->table_name . '_db_version', $this->version ); |
|
583 | + update_option($this->table_name . '_db_version', $this->version); |
|
584 | 584 | } |
585 | 585 | |
586 | 586 | } |
587 | 587 | \ No newline at end of file |
@@ -1,11 +1,11 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly. |
3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | 5 | function wpinv_subscription_init() { |
6 | 6 | return WPInv_Subscriptions::instance(); |
7 | 7 | } |
8 | -add_action( 'plugins_loaded', 'wpinv_subscription_init', 100 ); |
|
8 | +add_action('plugins_loaded', 'wpinv_subscription_init', 100); |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * WPInv_Subscriptions Class. |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * Main WPInv_Subscriptions Instance |
21 | 21 | */ |
22 | 22 | public static function instance() { |
23 | - if ( ! isset( self::$instance ) ) { |
|
23 | + if (!isset(self::$instance)) { |
|
24 | 24 | self::$instance = new WPInv_Subscriptions; |
25 | 25 | |
26 | 26 | self::$instance->init(); |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @since 1.0.0 |
36 | 36 | */ |
37 | - private function __construct(){ |
|
37 | + private function __construct() { |
|
38 | 38 | |
39 | 39 | } |
40 | 40 | |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | private function setup_constants() { |
64 | 64 | |
65 | 65 | // Make sure CAL_GREGORIAN is defined. |
66 | - if ( ! defined( 'CAL_GREGORIAN' ) ) { |
|
67 | - define( 'CAL_GREGORIAN', 1 ); |
|
66 | + if (!defined('CAL_GREGORIAN')) { |
|
67 | + define('CAL_GREGORIAN', 1); |
|
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
@@ -76,13 +76,13 @@ discard block |
||
76 | 76 | */ |
77 | 77 | private function actions() { |
78 | 78 | |
79 | - add_action( 'admin_menu', array( $this, 'wpinv_subscriptions_list' ), 10 ); |
|
80 | - add_action( 'admin_notices', array( $this, 'notices' ) ); |
|
81 | - add_action( 'init', array( $this, 'wpinv_post_actions' ) ); |
|
82 | - add_action( 'init', array( $this, 'wpinv_get_actions' ) ); |
|
83 | - add_action( 'wpinv_cancel_subscription', array( $this, 'wpinv_process_cancellation' ) ); |
|
84 | - add_action( 'wpi-pending_wpi_invoice', array( $this, 'wpinv_add_update_subscription' ), 10, 2 ); |
|
85 | - add_action( 'wpinv_subscriptions_front_notices', array( $this, 'notices' ) ); |
|
79 | + add_action('admin_menu', array($this, 'wpinv_subscriptions_list'), 10); |
|
80 | + add_action('admin_notices', array($this, 'notices')); |
|
81 | + add_action('init', array($this, 'wpinv_post_actions')); |
|
82 | + add_action('init', array($this, 'wpinv_get_actions')); |
|
83 | + add_action('wpinv_cancel_subscription', array($this, 'wpinv_process_cancellation')); |
|
84 | + add_action('wpi-pending_wpi_invoice', array($this, 'wpinv_add_update_subscription'), 10, 2); |
|
85 | + add_action('wpinv_subscriptions_front_notices', array($this, 'notices')); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | public function wpinv_subscriptions_list() { |
105 | 105 | add_submenu_page( |
106 | 106 | 'wpinv', |
107 | - __( 'Subscriptions', 'invoicing' ), |
|
108 | - __( 'Subscriptions', 'invoicing' ), |
|
107 | + __('Subscriptions', 'invoicing'), |
|
108 | + __('Subscriptions', 'invoicing'), |
|
109 | 109 | 'manage_invoicing', |
110 | 110 | 'wpinv-subscriptions', |
111 | 111 | 'wpinv_subscriptions_page' |
@@ -114,37 +114,37 @@ discard block |
||
114 | 114 | |
115 | 115 | public function notices() { |
116 | 116 | |
117 | - if( empty( $_GET['wpinv-message'] ) ) { |
|
117 | + if (empty($_GET['wpinv-message'])) { |
|
118 | 118 | return; |
119 | 119 | } |
120 | 120 | |
121 | 121 | $type = 'updated'; |
122 | 122 | $message = ''; |
123 | 123 | |
124 | - switch( strtolower( $_GET['wpinv-message'] ) ) { |
|
124 | + switch (strtolower($_GET['wpinv-message'])) { |
|
125 | 125 | |
126 | 126 | case 'updated' : |
127 | 127 | |
128 | - $message = __( 'Subscription updated successfully.', 'invoicing' ); |
|
128 | + $message = __('Subscription updated successfully.', 'invoicing'); |
|
129 | 129 | |
130 | 130 | break; |
131 | 131 | |
132 | 132 | case 'deleted' : |
133 | 133 | |
134 | - $message = __( 'Subscription deleted successfully.', 'invoicing' ); |
|
134 | + $message = __('Subscription deleted successfully.', 'invoicing'); |
|
135 | 135 | |
136 | 136 | break; |
137 | 137 | |
138 | 138 | case 'cancelled' : |
139 | 139 | |
140 | - $message = __( 'Subscription cancelled successfully.', 'invoicing' ); |
|
140 | + $message = __('Subscription cancelled successfully.', 'invoicing'); |
|
141 | 141 | |
142 | 142 | break; |
143 | 143 | |
144 | 144 | } |
145 | 145 | |
146 | - if ( ! empty( $message ) ) { |
|
147 | - echo '<div class="' . esc_attr( $type ) . '"><p>' . $message . '</p></div>'; |
|
146 | + if (!empty($message)) { |
|
147 | + echo '<div class="' . esc_attr($type) . '"><p>' . $message . '</p></div>'; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | } |
@@ -157,8 +157,8 @@ discard block |
||
157 | 157 | * @return void |
158 | 158 | */ |
159 | 159 | function wpinv_get_actions() { |
160 | - if ( isset( $_GET['wpinv_action'] ) ) { |
|
161 | - do_action( 'wpinv_' . $_GET['wpinv_action'], $_GET ); |
|
160 | + if (isset($_GET['wpinv_action'])) { |
|
161 | + do_action('wpinv_' . $_GET['wpinv_action'], $_GET); |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
@@ -170,8 +170,8 @@ discard block |
||
170 | 170 | * @return void |
171 | 171 | */ |
172 | 172 | function wpinv_post_actions() { |
173 | - if ( isset( $_POST['wpinv_action'] ) ) { |
|
174 | - do_action( 'wpinv_' . $_POST['wpinv_action'], $_POST ); |
|
173 | + if (isset($_POST['wpinv_action'])) { |
|
174 | + do_action('wpinv_' . $_POST['wpinv_action'], $_POST); |
|
175 | 175 | } |
176 | 176 | } |
177 | 177 | |
@@ -182,24 +182,24 @@ discard block |
||
182 | 182 | * @param int $frequency_count The frequency of the period. |
183 | 183 | * @return mixed|string|void |
184 | 184 | */ |
185 | - public static function wpinv_get_pretty_subscription_frequency( $period, $frequency_count = 1) { |
|
185 | + public static function wpinv_get_pretty_subscription_frequency($period, $frequency_count = 1) { |
|
186 | 186 | $frequency = ''; |
187 | 187 | //Format period details |
188 | - switch ( $period ) { |
|
188 | + switch ($period) { |
|
189 | 189 | case 'day' : |
190 | - $frequency = sprintf( _n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count); |
|
190 | + $frequency = sprintf(_n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count); |
|
191 | 191 | break; |
192 | 192 | case 'week' : |
193 | - $frequency = sprintf( _n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count); |
|
193 | + $frequency = sprintf(_n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count); |
|
194 | 194 | break; |
195 | 195 | case 'month' : |
196 | - $frequency = sprintf( _n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count); |
|
196 | + $frequency = sprintf(_n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count); |
|
197 | 197 | break; |
198 | 198 | case 'year' : |
199 | - $frequency = sprintf( _n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count); |
|
199 | + $frequency = sprintf(_n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count); |
|
200 | 200 | break; |
201 | 201 | default : |
202 | - $frequency = apply_filters( 'wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count ); |
|
202 | + $frequency = apply_filters('wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count); |
|
203 | 203 | break; |
204 | 204 | } |
205 | 205 | |
@@ -214,50 +214,50 @@ discard block |
||
214 | 214 | * @since 1.0.0 |
215 | 215 | * @return void |
216 | 216 | */ |
217 | - public function wpinv_process_cancellation( $data ) { |
|
217 | + public function wpinv_process_cancellation($data) { |
|
218 | 218 | |
219 | 219 | |
220 | - if( empty( $data['sub_id'] ) ) { |
|
220 | + if (empty($data['sub_id'])) { |
|
221 | 221 | return; |
222 | 222 | } |
223 | 223 | |
224 | - if( ! is_user_logged_in() ) { |
|
224 | + if (!is_user_logged_in()) { |
|
225 | 225 | return; |
226 | 226 | } |
227 | 227 | |
228 | - if( ! wp_verify_nonce( $data['_wpnonce'], 'wpinv-recurring-cancel' ) ) { |
|
229 | - wp_die( __( 'Error', 'invoicing' ), __( 'Nonce verification failed', 'invoicing' ), array( 'response' => 403 ) ); |
|
228 | + if (!wp_verify_nonce($data['_wpnonce'], 'wpinv-recurring-cancel')) { |
|
229 | + wp_die(__('Error', 'invoicing'), __('Nonce verification failed', 'invoicing'), array('response' => 403)); |
|
230 | 230 | } |
231 | 231 | |
232 | - $data['sub_id'] = absint( $data['sub_id'] ); |
|
233 | - $subscription = new WPInv_Subscription( $data['sub_id'] ); |
|
232 | + $data['sub_id'] = absint($data['sub_id']); |
|
233 | + $subscription = new WPInv_Subscription($data['sub_id']); |
|
234 | 234 | |
235 | - if( ! $subscription->can_cancel() ) { |
|
236 | - wp_die( __( 'Error', 'invoicing' ), __( 'This subscription cannot be cancelled', 'invoicing' ), array( 'response' => 403 ) ); |
|
235 | + if (!$subscription->can_cancel()) { |
|
236 | + wp_die(__('Error', 'invoicing'), __('This subscription cannot be cancelled', 'invoicing'), array('response' => 403)); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | try { |
240 | 240 | |
241 | - do_action( 'wpinv_recurring_cancel_' . $subscription->gateway . '_subscription', $subscription, true ); |
|
241 | + do_action('wpinv_recurring_cancel_' . $subscription->gateway . '_subscription', $subscription, true); |
|
242 | 242 | |
243 | 243 | $subscription->cancel(); |
244 | 244 | |
245 | - if( is_admin() ) { |
|
245 | + if (is_admin()) { |
|
246 | 246 | |
247 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=cancelled&id=' . $subscription->id ) ); |
|
247 | + wp_redirect(admin_url('admin.php?page=wpinv-subscriptions&wpinv-message=cancelled&id=' . $subscription->id)); |
|
248 | 248 | exit; |
249 | 249 | |
250 | 250 | } else { |
251 | 251 | |
252 | - $redirect = remove_query_arg( array( '_wpnonce', 'wpinv_action', 'sub_id' ), add_query_arg( array( 'wpinv-message' => 'cancelled' ) ) ); |
|
253 | - $redirect = apply_filters( 'wpinv_recurring_cancellation_redirect', $redirect, $subscription ); |
|
254 | - wp_safe_redirect( $redirect ); |
|
252 | + $redirect = remove_query_arg(array('_wpnonce', 'wpinv_action', 'sub_id'), add_query_arg(array('wpinv-message' => 'cancelled'))); |
|
253 | + $redirect = apply_filters('wpinv_recurring_cancellation_redirect', $redirect, $subscription); |
|
254 | + wp_safe_redirect($redirect); |
|
255 | 255 | exit; |
256 | 256 | |
257 | 257 | } |
258 | 258 | |
259 | - } catch ( Exception $e ) { |
|
260 | - wp_die( __( 'Error', 'invoicing' ), $e->getMessage(), array( 'response' => 403 ) ); |
|
259 | + } catch (Exception $e) { |
|
260 | + wp_die(__('Error', 'invoicing'), $e->getMessage(), array('response' => 403)); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | } |
@@ -269,51 +269,51 @@ discard block |
||
269 | 269 | * @since 1.0.0 |
270 | 270 | * @return void |
271 | 271 | */ |
272 | - public function wpinv_add_update_subscription( $invoice_id, $post ) { |
|
273 | - remove_action( 'save_post', __FUNCTION__ ); |
|
272 | + public function wpinv_add_update_subscription($invoice_id, $post) { |
|
273 | + remove_action('save_post', __FUNCTION__); |
|
274 | 274 | |
275 | - if ( ! ( ! empty( $invoice_id ) && 'wpi_invoice' == get_post_type( $invoice_id ) ) ) { |
|
275 | + if (!(!empty($invoice_id) && 'wpi_invoice' == get_post_type($invoice_id))) { |
|
276 | 276 | return; |
277 | 277 | } |
278 | 278 | |
279 | - if ( defined( 'DOING_AUTOSAVE' ) ) { |
|
279 | + if (defined('DOING_AUTOSAVE')) { |
|
280 | 280 | return; |
281 | 281 | } |
282 | 282 | |
283 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
283 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
284 | 284 | return; |
285 | 285 | } |
286 | 286 | |
287 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
287 | + $invoice = new WPInv_Invoice($invoice_id); |
|
288 | 288 | |
289 | - if ( ! ( ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) { |
|
289 | + if (!(!empty($invoice->ID) && $invoice->is_recurring())) { |
|
290 | 290 | return; |
291 | 291 | } |
292 | 292 | |
293 | - $item = $invoice->get_recurring( true ); |
|
294 | - if ( empty( $item ) ) { |
|
293 | + $item = $invoice->get_recurring(true); |
|
294 | + if (empty($item)) { |
|
295 | 295 | return; |
296 | 296 | } |
297 | 297 | |
298 | - $invoice_date = $invoice->get_invoice_date( false ); |
|
298 | + $invoice_date = $invoice->get_invoice_date(false); |
|
299 | 299 | $status = 'pending'; |
300 | 300 | |
301 | - $period = $item->get_recurring_period( true ); |
|
301 | + $period = $item->get_recurring_period(true); |
|
302 | 302 | $interval = $item->get_recurring_interval(); |
303 | 303 | $bill_times = (int)$item->get_recurring_limit(); |
304 | 304 | $add_period = $interval . ' ' . $period; |
305 | 305 | $trial_period = ''; |
306 | 306 | |
307 | - if ( $invoice->is_free_trial() ) { |
|
307 | + if ($invoice->is_free_trial()) { |
|
308 | 308 | $status = 'trialling'; |
309 | - $trial_period = $item->get_trial_period( true ); |
|
309 | + $trial_period = $item->get_trial_period(true); |
|
310 | 310 | $free_interval = $item->get_trial_interval(); |
311 | 311 | $trial_period = $free_interval . ' ' . $trial_period; |
312 | 312 | |
313 | 313 | $add_period = $trial_period; |
314 | 314 | } |
315 | 315 | |
316 | - $expiration = date_i18n( 'Y-m-d H:i:s', strtotime( '+' . $add_period . ' 23:59:59', strtotime( $invoice_date ) ) ); |
|
316 | + $expiration = date_i18n('Y-m-d H:i:s', strtotime('+' . $add_period . ' 23:59:59', strtotime($invoice_date))); |
|
317 | 317 | |
318 | 318 | $args = array( |
319 | 319 | 'product_id' => $item->ID, |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | 'frequency' => $interval, |
324 | 324 | 'period' => $period, |
325 | 325 | 'initial_amount' => $invoice->get_total(), |
326 | - 'recurring_amount' => $invoice->get_recurring_details( 'total' ), |
|
326 | + 'recurring_amount' => $invoice->get_recurring_details('total'), |
|
327 | 327 | 'bill_times' => $bill_times, |
328 | 328 | 'created' => $invoice_date, |
329 | 329 | 'expiration' => $expiration, |
@@ -333,12 +333,12 @@ discard block |
||
333 | 333 | ); |
334 | 334 | |
335 | 335 | $subs_db = new WPInv_Subscriptions_DB; |
336 | - $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice->ID, 'number' => 1 ) ); |
|
337 | - $subscription = reset( $subs ); |
|
336 | + $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice->ID, 'number' => 1)); |
|
337 | + $subscription = reset($subs); |
|
338 | 338 | |
339 | - if ( empty( $subscription ) || $subscription->id <= 0 ) { |
|
339 | + if (empty($subscription) || $subscription->id <= 0) { |
|
340 | 340 | $subscription = new WPInv_Subscription(); |
341 | - $subscription->create( $args ); |
|
341 | + $subscription->create($args); |
|
342 | 342 | } |
343 | 343 | } |
344 | 344 | } |
345 | 345 | \ No newline at end of file |
@@ -7,40 +7,40 @@ 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 | function wpinv_get_invoice_cart_id() { |
15 | 15 | $wpinv_checkout = wpinv_get_checkout_session(); |
16 | 16 | |
17 | - if ( !empty( $wpinv_checkout['invoice_id'] ) ) { |
|
17 | + if (!empty($wpinv_checkout['invoice_id'])) { |
|
18 | 18 | return $wpinv_checkout['invoice_id']; |
19 | 19 | } |
20 | 20 | |
21 | 21 | return NULL; |
22 | 22 | } |
23 | 23 | |
24 | -function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) { |
|
25 | - if ( empty( $invoice_data ) ) { |
|
24 | +function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) { |
|
25 | + if (empty($invoice_data)) { |
|
26 | 26 | return false; |
27 | 27 | } |
28 | 28 | |
29 | - if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) { |
|
30 | - return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast on item.', 'invoicing' ) ) : 0; |
|
29 | + if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) { |
|
30 | + return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast on item.', 'invoicing')) : 0; |
|
31 | 31 | } |
32 | 32 | |
33 | - if ( empty( $invoice_data['user_id'] ) ) { |
|
33 | + if (empty($invoice_data['user_id'])) { |
|
34 | 34 | $invoice_data['user_id'] = get_current_user_id(); |
35 | 35 | } |
36 | 36 | |
37 | - $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0; |
|
37 | + $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int)$invoice_data['invoice_id'] : 0; |
|
38 | 38 | |
39 | - if ( empty( $invoice_data['status'] ) ) { |
|
39 | + if (empty($invoice_data['status'])) { |
|
40 | 40 | $invoice_data['status'] = 'wpi-pending'; |
41 | 41 | } |
42 | 42 | |
43 | - if ( empty( $invoice_data['ip'] ) ) { |
|
43 | + if (empty($invoice_data['ip'])) { |
|
44 | 44 | $invoice_data['ip'] = wpinv_get_ip(); |
45 | 45 | } |
46 | 46 | |
@@ -51,12 +51,12 @@ discard block |
||
51 | 51 | 'status' => $invoice_data['status'], |
52 | 52 | ); |
53 | 53 | |
54 | - $invoice = wpinv_create_invoice( $default_args, $invoice_data, true ); |
|
55 | - if ( is_wp_error( $invoice ) ) { |
|
54 | + $invoice = wpinv_create_invoice($default_args, $invoice_data, true); |
|
55 | + if (is_wp_error($invoice)) { |
|
56 | 56 | return $wp_error ? $invoice : 0; |
57 | 57 | } |
58 | 58 | |
59 | - if ( empty( $invoice_data['invoice_id'] ) ) { |
|
59 | + if (empty($invoice_data['invoice_id'])) { |
|
60 | 60 | //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) ); |
61 | 61 | } |
62 | 62 | |
@@ -79,24 +79,24 @@ discard block |
||
79 | 79 | 'discount' => array(), |
80 | 80 | ); |
81 | 81 | |
82 | - if ( $user_id = (int)$invoice->get_user_id() ) { |
|
83 | - if ( $user_address = wpinv_get_user_address( $user_id ) ) { |
|
84 | - $default_user_info = wp_parse_args( $user_address, $default_user_info ); |
|
82 | + if ($user_id = (int)$invoice->get_user_id()) { |
|
83 | + if ($user_address = wpinv_get_user_address($user_id)) { |
|
84 | + $default_user_info = wp_parse_args($user_address, $default_user_info); |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
88 | - if ( empty( $invoice_data['user_info'] ) ) { |
|
88 | + if (empty($invoice_data['user_info'])) { |
|
89 | 89 | $invoice_data['user_info'] = array(); |
90 | 90 | } |
91 | 91 | |
92 | - $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info ); |
|
92 | + $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info); |
|
93 | 93 | |
94 | - if ( empty( $user_info['first_name'] ) ) { |
|
94 | + if (empty($user_info['first_name'])) { |
|
95 | 95 | $user_info['first_name'] = $default_user_info['first_name']; |
96 | 96 | $user_info['last_name'] = $default_user_info['last_name']; |
97 | 97 | } |
98 | 98 | |
99 | - if ( empty( $user_info['country'] ) ) { |
|
99 | + if (empty($user_info['country'])) { |
|
100 | 100 | $user_info['country'] = $default_user_info['country']; |
101 | 101 | $user_info['state'] = $default_user_info['state']; |
102 | 102 | $user_info['city'] = $default_user_info['city']; |
@@ -105,13 +105,13 @@ discard block |
||
105 | 105 | $user_info['phone'] = $default_user_info['phone']; |
106 | 106 | } |
107 | 107 | |
108 | - if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) { |
|
108 | + if (!empty($user_info['discount']) && !is_array($user_info['discount'])) { |
|
109 | 109 | $user_info['discount'] = (array)$user_info['discount']; |
110 | 110 | } |
111 | 111 | |
112 | 112 | // Payment details |
113 | 113 | $payment_details = array(); |
114 | - if ( !empty( $invoice_data['payment_details'] ) ) { |
|
114 | + if (!empty($invoice_data['payment_details'])) { |
|
115 | 115 | $default_payment_details = array( |
116 | 116 | 'gateway' => 'manual', |
117 | 117 | 'gateway_title' => '', |
@@ -119,56 +119,56 @@ discard block |
||
119 | 119 | 'transaction_id' => '', |
120 | 120 | ); |
121 | 121 | |
122 | - $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details ); |
|
122 | + $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details); |
|
123 | 123 | |
124 | - if ( empty( $payment_details['gateway'] ) ) { |
|
124 | + if (empty($payment_details['gateway'])) { |
|
125 | 125 | $payment_details['gateway'] = 'manual'; |
126 | 126 | } |
127 | 127 | |
128 | - if ( empty( $payment_details['currency'] ) ) { |
|
128 | + if (empty($payment_details['currency'])) { |
|
129 | 129 | $payment_details['currency'] = wpinv_get_default_country(); |
130 | 130 | } |
131 | 131 | |
132 | - if ( empty( $payment_details['gateway_title'] ) ) { |
|
133 | - $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] ); |
|
132 | + if (empty($payment_details['gateway_title'])) { |
|
133 | + $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']); |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | |
137 | - $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'wpi-pending' ) ); |
|
138 | - |
|
139 | - if ( !empty( $payment_details ) ) { |
|
140 | - $invoice->set( 'currency', $payment_details['currency'] ); |
|
141 | - $invoice->set( 'gateway', $payment_details['gateway'] ); |
|
142 | - $invoice->set( 'gateway_title', $payment_details['gateway_title'] ); |
|
143 | - $invoice->set( 'transaction_id', $payment_details['transaction_id'] ); |
|
144 | - } |
|
145 | - |
|
146 | - $invoice->set( 'user_info', $user_info ); |
|
147 | - $invoice->set( 'first_name', $user_info['first_name'] ); |
|
148 | - $invoice->set( 'last_name', $user_info['last_name'] ); |
|
149 | - $invoice->set( 'address', $user_info['address'] ); |
|
150 | - $invoice->set( 'company', $user_info['company'] ); |
|
151 | - $invoice->set( 'vat_number', $user_info['vat_number'] ); |
|
152 | - $invoice->set( 'phone', $user_info['phone'] ); |
|
153 | - $invoice->set( 'city', $user_info['city'] ); |
|
154 | - $invoice->set( 'country', $user_info['country'] ); |
|
155 | - $invoice->set( 'state', $user_info['state'] ); |
|
156 | - $invoice->set( 'zip', $user_info['zip'] ); |
|
157 | - $invoice->set( 'discounts', $user_info['discount'] ); |
|
158 | - $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) ); |
|
159 | - $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) ); |
|
160 | - $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) ); |
|
161 | - |
|
162 | - if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) { |
|
163 | - foreach ( $invoice_data['cart_details'] as $key => $item ) { |
|
164 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
165 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
166 | - $name = !empty( $item['name'] ) ? $item['name'] : ''; |
|
167 | - $item_price = isset( $item['item_price'] ) ? $item['item_price'] : ''; |
|
137 | + $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'wpi-pending')); |
|
138 | + |
|
139 | + if (!empty($payment_details)) { |
|
140 | + $invoice->set('currency', $payment_details['currency']); |
|
141 | + $invoice->set('gateway', $payment_details['gateway']); |
|
142 | + $invoice->set('gateway_title', $payment_details['gateway_title']); |
|
143 | + $invoice->set('transaction_id', $payment_details['transaction_id']); |
|
144 | + } |
|
145 | + |
|
146 | + $invoice->set('user_info', $user_info); |
|
147 | + $invoice->set('first_name', $user_info['first_name']); |
|
148 | + $invoice->set('last_name', $user_info['last_name']); |
|
149 | + $invoice->set('address', $user_info['address']); |
|
150 | + $invoice->set('company', $user_info['company']); |
|
151 | + $invoice->set('vat_number', $user_info['vat_number']); |
|
152 | + $invoice->set('phone', $user_info['phone']); |
|
153 | + $invoice->set('city', $user_info['city']); |
|
154 | + $invoice->set('country', $user_info['country']); |
|
155 | + $invoice->set('state', $user_info['state']); |
|
156 | + $invoice->set('zip', $user_info['zip']); |
|
157 | + $invoice->set('discounts', $user_info['discount']); |
|
158 | + $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip())); |
|
159 | + $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live')); |
|
160 | + $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : '')); |
|
161 | + |
|
162 | + if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) { |
|
163 | + foreach ($invoice_data['cart_details'] as $key => $item) { |
|
164 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
165 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
166 | + $name = !empty($item['name']) ? $item['name'] : ''; |
|
167 | + $item_price = isset($item['item_price']) ? $item['item_price'] : ''; |
|
168 | 168 | |
169 | - $post_item = new WPInv_Item( $item_id ); |
|
170 | - if ( !empty( $post_item ) ) { |
|
171 | - $name = !empty( $name ) ? $name : $post_item->get_name(); |
|
169 | + $post_item = new WPInv_Item($item_id); |
|
170 | + if (!empty($post_item)) { |
|
171 | + $name = !empty($name) ? $name : $post_item->get_name(); |
|
172 | 172 | $item_price = $item_price !== '' ? $item_price : $post_item->get_price(); |
173 | 173 | } else { |
174 | 174 | continue; |
@@ -178,253 +178,253 @@ discard block |
||
178 | 178 | 'name' => $name, |
179 | 179 | 'quantity' => $quantity, |
180 | 180 | 'item_price' => $item_price, |
181 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
182 | - 'tax' => !empty( $item['tax'] ) ? $item['tax'] : 0.00, |
|
183 | - 'discount' => isset( $item['discount'] ) ? $item['discount'] : 0, |
|
184 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
185 | - 'fees' => isset( $item['fees'] ) ? $item['fees'] : array(), |
|
181 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
182 | + 'tax' => !empty($item['tax']) ? $item['tax'] : 0.00, |
|
183 | + 'discount' => isset($item['discount']) ? $item['discount'] : 0, |
|
184 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
185 | + 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
|
186 | 186 | ); |
187 | 187 | |
188 | - $invoice->add_item( $item_id, $args ); |
|
188 | + $invoice->add_item($item_id, $args); |
|
189 | 189 | } |
190 | 190 | } |
191 | 191 | |
192 | - $invoice->increase_tax( wpinv_get_cart_fee_tax() ); |
|
192 | + $invoice->increase_tax(wpinv_get_cart_fee_tax()); |
|
193 | 193 | |
194 | - if ( isset( $invoice_data['post_date'] ) ) { |
|
195 | - $invoice->set( 'date', $invoice_data['post_date'] ); |
|
194 | + if (isset($invoice_data['post_date'])) { |
|
195 | + $invoice->set('date', $invoice_data['post_date']); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | // Invoice due date |
199 | - if ( isset( $invoice_data['due_date'] ) ) { |
|
200 | - $invoice->set( 'due_date', $invoice_data['due_date'] ); |
|
199 | + if (isset($invoice_data['due_date'])) { |
|
200 | + $invoice->set('due_date', $invoice_data['due_date']); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | $invoice->save(); |
204 | 204 | |
205 | 205 | // Add notes |
206 | - if ( !empty( $invoice_data['private_note'] ) ) { |
|
207 | - $invoice->add_note( $invoice_data['private_note'] ); |
|
206 | + if (!empty($invoice_data['private_note'])) { |
|
207 | + $invoice->add_note($invoice_data['private_note']); |
|
208 | 208 | } |
209 | - if ( !empty( $invoice_data['user_note'] ) ) { |
|
210 | - $invoice->add_note( $invoice_data['user_note'], true ); |
|
209 | + if (!empty($invoice_data['user_note'])) { |
|
210 | + $invoice->add_note($invoice_data['user_note'], true); |
|
211 | 211 | } |
212 | 212 | |
213 | - do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data ); |
|
213 | + do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data); |
|
214 | 214 | |
215 | - if ( ! empty( $invoice->ID ) ) { |
|
215 | + if (!empty($invoice->ID)) { |
|
216 | 216 | global $wpi_userID, $wpinv_ip_address_country; |
217 | 217 | |
218 | 218 | $checkout_session = wpinv_get_checkout_session(); |
219 | 219 | |
220 | 220 | $data_session = array(); |
221 | 221 | $data_session['invoice_id'] = $invoice->ID; |
222 | - $data_session['cart_discounts'] = $invoice->get_discounts( true ); |
|
222 | + $data_session['cart_discounts'] = $invoice->get_discounts(true); |
|
223 | 223 | |
224 | - wpinv_set_checkout_session( $data_session ); |
|
224 | + wpinv_set_checkout_session($data_session); |
|
225 | 225 | |
226 | 226 | $wpi_userID = (int)$invoice->get_user_id(); |
227 | 227 | |
228 | - $_POST['country'] = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country(); |
|
228 | + $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
|
229 | 229 | $_POST['state'] = $invoice->state; |
230 | 230 | |
231 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
232 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
231 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
232 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
233 | 233 | |
234 | 234 | $wpinv_ip_address_country = $invoice->country; |
235 | 235 | |
236 | - $invoice = $invoice->recalculate_totals( true ); |
|
236 | + $invoice = $invoice->recalculate_totals(true); |
|
237 | 237 | |
238 | - wpinv_set_checkout_session( $checkout_session ); |
|
238 | + wpinv_set_checkout_session($checkout_session); |
|
239 | 239 | |
240 | 240 | return $invoice; |
241 | 241 | } |
242 | 242 | |
243 | - if ( $wp_error ) { |
|
244 | - if ( is_wp_error( $invoice ) ) { |
|
243 | + if ($wp_error) { |
|
244 | + if (is_wp_error($invoice)) { |
|
245 | 245 | return $invoice; |
246 | 246 | } else { |
247 | - return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) ); |
|
247 | + return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing')); |
|
248 | 248 | } |
249 | 249 | } else { |
250 | 250 | return 0; |
251 | 251 | } |
252 | 252 | } |
253 | 253 | |
254 | -function wpinv_update_invoice( $invoice_data = array(), $wp_error = false ) { |
|
255 | - $invoice_ID = !empty( $invoice_data['ID'] ) ? absint( $invoice_data['ID'] ) : NULL; |
|
254 | +function wpinv_update_invoice($invoice_data = array(), $wp_error = false) { |
|
255 | + $invoice_ID = !empty($invoice_data['ID']) ? absint($invoice_data['ID']) : NULL; |
|
256 | 256 | |
257 | - if ( !$invoice_ID ) { |
|
258 | - if ( $wp_error ) { |
|
259 | - return new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) ); |
|
257 | + if (!$invoice_ID) { |
|
258 | + if ($wp_error) { |
|
259 | + return new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing')); |
|
260 | 260 | } |
261 | 261 | return 0; |
262 | 262 | } |
263 | 263 | |
264 | - $invoice = wpinv_get_invoice( $invoice_ID ); |
|
264 | + $invoice = wpinv_get_invoice($invoice_ID); |
|
265 | 265 | |
266 | - $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring( true ) : NULL; |
|
266 | + $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring(true) : NULL; |
|
267 | 267 | |
268 | - if ( empty( $invoice->ID ) ) { |
|
269 | - if ( $wp_error ) { |
|
270 | - return new WP_Error( 'invalid_invoice', __( 'Invalid invoice.', 'invoicing' ) ); |
|
268 | + if (empty($invoice->ID)) { |
|
269 | + if ($wp_error) { |
|
270 | + return new WP_Error('invalid_invoice', __('Invalid invoice.', 'invoicing')); |
|
271 | 271 | } |
272 | 272 | return 0; |
273 | 273 | } |
274 | 274 | |
275 | - if ( !$invoice->has_status( array( 'wpi-pending' ) ) ) { |
|
276 | - if ( $wp_error ) { |
|
277 | - return new WP_Error( 'invalid_invoice_status', __( 'Only invoice with pending payment is allowed to update.', 'invoicing' ) ); |
|
275 | + if (!$invoice->has_status(array('wpi-pending'))) { |
|
276 | + if ($wp_error) { |
|
277 | + return new WP_Error('invalid_invoice_status', __('Only invoice with pending payment is allowed to update.', 'invoicing')); |
|
278 | 278 | } |
279 | 279 | return 0; |
280 | 280 | } |
281 | 281 | |
282 | 282 | // Invoice status |
283 | - if ( !empty( $invoice_data['status'] ) ) { |
|
284 | - $invoice->set( 'status', $invoice_data['status'] ); |
|
283 | + if (!empty($invoice_data['status'])) { |
|
284 | + $invoice->set('status', $invoice_data['status']); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | // Invoice date |
288 | - if ( !empty( $invoice_data['post_date'] ) ) { |
|
289 | - $invoice->set( 'date', $invoice_data['post_date'] ); |
|
288 | + if (!empty($invoice_data['post_date'])) { |
|
289 | + $invoice->set('date', $invoice_data['post_date']); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | // Invoice due date |
293 | - if ( isset( $invoice_data['due_date'] ) ) { |
|
294 | - $invoice->set( 'due_date', $invoice_data['due_date'] ); |
|
293 | + if (isset($invoice_data['due_date'])) { |
|
294 | + $invoice->set('due_date', $invoice_data['due_date']); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | // Invoice IP address |
298 | - if ( !empty( $invoice_data['ip'] ) ) { |
|
299 | - $invoice->set( 'ip', $invoice_data['ip'] ); |
|
298 | + if (!empty($invoice_data['ip'])) { |
|
299 | + $invoice->set('ip', $invoice_data['ip']); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | // User info |
303 | - if ( !empty( $invoice_data['user_info'] ) && is_array( $invoice_data['user_info'] ) ) { |
|
304 | - $user_info = wp_parse_args( $invoice_data['user_info'], $invoice->user_info ); |
|
303 | + if (!empty($invoice_data['user_info']) && is_array($invoice_data['user_info'])) { |
|
304 | + $user_info = wp_parse_args($invoice_data['user_info'], $invoice->user_info); |
|
305 | 305 | |
306 | - if ( $discounts = $invoice->get_discounts() ) { |
|
306 | + if ($discounts = $invoice->get_discounts()) { |
|
307 | 307 | $set_discount = $discounts; |
308 | 308 | } else { |
309 | 309 | $set_discount = ''; |
310 | 310 | } |
311 | 311 | |
312 | 312 | // Manage discount |
313 | - if ( !empty( $invoice_data['user_info']['discount'] ) ) { |
|
313 | + if (!empty($invoice_data['user_info']['discount'])) { |
|
314 | 314 | // Remove discount |
315 | - if ( $invoice_data['user_info']['discount'] == 'none' ) { |
|
315 | + if ($invoice_data['user_info']['discount'] == 'none') { |
|
316 | 316 | $set_discount = ''; |
317 | 317 | } else { |
318 | 318 | $set_discount = $invoice_data['user_info']['discount']; |
319 | 319 | } |
320 | 320 | |
321 | - $invoice->set( 'discounts', $set_discount ); |
|
321 | + $invoice->set('discounts', $set_discount); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | $user_info['discount'] = $set_discount; |
325 | 325 | |
326 | - $invoice->set( 'user_info', $user_info ); |
|
326 | + $invoice->set('user_info', $user_info); |
|
327 | 327 | } |
328 | 328 | |
329 | - if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) && $cart_details = $invoice_data['cart_details'] ) { |
|
330 | - $remove_items = !empty( $cart_details['remove_items'] ) && is_array( $cart_details['remove_items'] ) ? $cart_details['remove_items'] : array(); |
|
329 | + if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']) && $cart_details = $invoice_data['cart_details']) { |
|
330 | + $remove_items = !empty($cart_details['remove_items']) && is_array($cart_details['remove_items']) ? $cart_details['remove_items'] : array(); |
|
331 | 331 | |
332 | - if ( !empty( $remove_items[0]['id'] ) ) { |
|
333 | - foreach ( $remove_items as $item ) { |
|
334 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
335 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
336 | - if ( empty( $item_id ) ) { |
|
332 | + if (!empty($remove_items[0]['id'])) { |
|
333 | + foreach ($remove_items as $item) { |
|
334 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
335 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
336 | + if (empty($item_id)) { |
|
337 | 337 | continue; |
338 | 338 | } |
339 | 339 | |
340 | - foreach ( $invoice->cart_details as $cart_index => $cart_item ) { |
|
341 | - if ( $item_id == $cart_item['id'] ) { |
|
340 | + foreach ($invoice->cart_details as $cart_index => $cart_item) { |
|
341 | + if ($item_id == $cart_item['id']) { |
|
342 | 342 | $args = array( |
343 | 343 | 'id' => $item_id, |
344 | 344 | 'quantity' => $quantity, |
345 | 345 | 'cart_index' => $cart_index |
346 | 346 | ); |
347 | 347 | |
348 | - $invoice->remove_item( $item_id, $args ); |
|
348 | + $invoice->remove_item($item_id, $args); |
|
349 | 349 | break; |
350 | 350 | } |
351 | 351 | } |
352 | 352 | } |
353 | 353 | } |
354 | 354 | |
355 | - $add_items = !empty( $cart_details['add_items'] ) && is_array( $cart_details['add_items'] ) ? $cart_details['add_items'] : array(); |
|
355 | + $add_items = !empty($cart_details['add_items']) && is_array($cart_details['add_items']) ? $cart_details['add_items'] : array(); |
|
356 | 356 | |
357 | - if ( !empty( $add_items[0]['id'] ) ) { |
|
358 | - foreach ( $add_items as $item ) { |
|
359 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
360 | - $post_item = new WPInv_Item( $item_id ); |
|
361 | - if ( empty( $post_item ) ) { |
|
357 | + if (!empty($add_items[0]['id'])) { |
|
358 | + foreach ($add_items as $item) { |
|
359 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
360 | + $post_item = new WPInv_Item($item_id); |
|
361 | + if (empty($post_item)) { |
|
362 | 362 | continue; |
363 | 363 | } |
364 | 364 | |
365 | 365 | $valid_item = true; |
366 | - if ( !empty( $recurring_item ) ) { |
|
367 | - if ( $recurring_item->ID != $item_id ) { |
|
366 | + if (!empty($recurring_item)) { |
|
367 | + if ($recurring_item->ID != $item_id) { |
|
368 | 368 | $valid_item = false; |
369 | 369 | } |
370 | - } else if ( wpinv_is_recurring_item( $item_id ) ) { |
|
370 | + } else if (wpinv_is_recurring_item($item_id)) { |
|
371 | 371 | $valid_item = false; |
372 | 372 | } |
373 | 373 | |
374 | - if ( !$valid_item ) { |
|
375 | - if ( $wp_error ) { |
|
376 | - return new WP_Error( 'invalid_invoice_item', __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ) ); |
|
374 | + if (!$valid_item) { |
|
375 | + if ($wp_error) { |
|
376 | + return new WP_Error('invalid_invoice_item', __('You can not add item because recurring item must be paid individually!', 'invoicing')); |
|
377 | 377 | } |
378 | 378 | return 0; |
379 | 379 | } |
380 | 380 | |
381 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
382 | - $name = !empty( $item['name'] ) ? $item['name'] : $post_item->get_name(); |
|
383 | - $item_price = isset( $item['item_price'] ) ? $item['item_price'] : $post_item->get_price(); |
|
381 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
382 | + $name = !empty($item['name']) ? $item['name'] : $post_item->get_name(); |
|
383 | + $item_price = isset($item['item_price']) ? $item['item_price'] : $post_item->get_price(); |
|
384 | 384 | |
385 | 385 | $args = array( |
386 | 386 | 'name' => $name, |
387 | 387 | 'quantity' => $quantity, |
388 | 388 | 'item_price' => $item_price, |
389 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
390 | - 'tax' => !empty( $item['tax'] ) ? $item['tax'] : 0, |
|
391 | - 'discount' => isset( $item['discount'] ) ? $item['discount'] : 0, |
|
392 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
393 | - 'fees' => isset( $item['fees'] ) ? $item['fees'] : array(), |
|
389 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
390 | + 'tax' => !empty($item['tax']) ? $item['tax'] : 0, |
|
391 | + 'discount' => isset($item['discount']) ? $item['discount'] : 0, |
|
392 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
393 | + 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
|
394 | 394 | ); |
395 | 395 | |
396 | - $invoice->add_item( $item_id, $args ); |
|
396 | + $invoice->add_item($item_id, $args); |
|
397 | 397 | } |
398 | 398 | } |
399 | 399 | } |
400 | 400 | |
401 | 401 | // Payment details |
402 | - if ( !empty( $invoice_data['payment_details'] ) && $payment_details = $invoice_data['payment_details'] ) { |
|
403 | - if ( !empty( $payment_details['gateway'] ) ) { |
|
404 | - $invoice->set( 'gateway', $payment_details['gateway'] ); |
|
402 | + if (!empty($invoice_data['payment_details']) && $payment_details = $invoice_data['payment_details']) { |
|
403 | + if (!empty($payment_details['gateway'])) { |
|
404 | + $invoice->set('gateway', $payment_details['gateway']); |
|
405 | 405 | } |
406 | 406 | |
407 | - if ( !empty( $payment_details['transaction_id'] ) ) { |
|
408 | - $invoice->set( 'transaction_id', $payment_details['transaction_id'] ); |
|
407 | + if (!empty($payment_details['transaction_id'])) { |
|
408 | + $invoice->set('transaction_id', $payment_details['transaction_id']); |
|
409 | 409 | } |
410 | 410 | } |
411 | 411 | |
412 | - do_action( 'wpinv_pre_update_invoice', $invoice->ID, $invoice_data ); |
|
412 | + do_action('wpinv_pre_update_invoice', $invoice->ID, $invoice_data); |
|
413 | 413 | |
414 | 414 | // Parent invoice |
415 | - if ( !empty( $invoice_data['parent'] ) ) { |
|
416 | - $invoice->set( 'parent_invoice', $invoice_data['parent'] ); |
|
415 | + if (!empty($invoice_data['parent'])) { |
|
416 | + $invoice->set('parent_invoice', $invoice_data['parent']); |
|
417 | 417 | } |
418 | 418 | |
419 | 419 | // Save invoice data. |
420 | 420 | $invoice->save(); |
421 | 421 | |
422 | - if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) { |
|
423 | - if ( $wp_error ) { |
|
424 | - if ( is_wp_error( $invoice ) ) { |
|
422 | + if (empty($invoice->ID) || is_wp_error($invoice)) { |
|
423 | + if ($wp_error) { |
|
424 | + if (is_wp_error($invoice)) { |
|
425 | 425 | return $invoice; |
426 | 426 | } else { |
427 | - return new WP_Error( 'wpinv_update_invoice_error', __( 'Error in update invoice.', 'invoicing' ) ); |
|
427 | + return new WP_Error('wpinv_update_invoice_error', __('Error in update invoice.', 'invoicing')); |
|
428 | 428 | } |
429 | 429 | } else { |
430 | 430 | return 0; |
@@ -432,13 +432,13 @@ discard block |
||
432 | 432 | } |
433 | 433 | |
434 | 434 | // Add private note |
435 | - if ( !empty( $invoice_data['private_note'] ) ) { |
|
436 | - $invoice->add_note( $invoice_data['private_note'] ); |
|
435 | + if (!empty($invoice_data['private_note'])) { |
|
436 | + $invoice->add_note($invoice_data['private_note']); |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | // Add user note |
440 | - if ( !empty( $invoice_data['user_note'] ) ) { |
|
441 | - $invoice->add_note( $invoice_data['user_note'], true ); |
|
440 | + if (!empty($invoice_data['user_note'])) { |
|
441 | + $invoice->add_note($invoice_data['user_note'], true); |
|
442 | 442 | } |
443 | 443 | |
444 | 444 | global $wpi_userID, $wpinv_ip_address_country; |
@@ -447,445 +447,445 @@ discard block |
||
447 | 447 | |
448 | 448 | $data_session = array(); |
449 | 449 | $data_session['invoice_id'] = $invoice->ID; |
450 | - $data_session['cart_discounts'] = $invoice->get_discounts( true ); |
|
450 | + $data_session['cart_discounts'] = $invoice->get_discounts(true); |
|
451 | 451 | |
452 | - wpinv_set_checkout_session( $data_session ); |
|
452 | + wpinv_set_checkout_session($data_session); |
|
453 | 453 | |
454 | 454 | $wpi_userID = (int)$invoice->get_user_id(); |
455 | 455 | |
456 | - $_POST['country'] = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country(); |
|
456 | + $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
|
457 | 457 | $_POST['state'] = $invoice->state; |
458 | 458 | |
459 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
460 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
459 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
460 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
461 | 461 | |
462 | 462 | $wpinv_ip_address_country = $invoice->country; |
463 | 463 | |
464 | - $invoice = $invoice->recalculate_totals( true ); |
|
464 | + $invoice = $invoice->recalculate_totals(true); |
|
465 | 465 | |
466 | - do_action( 'wpinv_post_update_invoice', $invoice->ID, $invoice_data ); |
|
466 | + do_action('wpinv_post_update_invoice', $invoice->ID, $invoice_data); |
|
467 | 467 | |
468 | - wpinv_set_checkout_session( $checkout_session ); |
|
468 | + wpinv_set_checkout_session($checkout_session); |
|
469 | 469 | |
470 | 470 | return $invoice; |
471 | 471 | } |
472 | 472 | |
473 | -function wpinv_get_invoice( $invoice_id = 0, $cart = false ) { |
|
474 | - if ( $cart && empty( $invoice_id ) ) { |
|
473 | +function wpinv_get_invoice($invoice_id = 0, $cart = false) { |
|
474 | + if ($cart && empty($invoice_id)) { |
|
475 | 475 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
476 | 476 | } |
477 | 477 | |
478 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
478 | + $invoice = new WPInv_Invoice($invoice_id); |
|
479 | 479 | return $invoice; |
480 | 480 | } |
481 | 481 | |
482 | -function wpinv_get_invoice_cart( $invoice_id = 0 ) { |
|
483 | - return wpinv_get_invoice( $invoice_id, true ); |
|
482 | +function wpinv_get_invoice_cart($invoice_id = 0) { |
|
483 | + return wpinv_get_invoice($invoice_id, true); |
|
484 | 484 | } |
485 | 485 | |
486 | -function wpinv_get_invoice_description( $invoice_id = 0 ) { |
|
487 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
486 | +function wpinv_get_invoice_description($invoice_id = 0) { |
|
487 | + $invoice = new WPInv_Invoice($invoice_id); |
|
488 | 488 | return $invoice->get_description(); |
489 | 489 | } |
490 | 490 | |
491 | -function wpinv_get_invoice_currency_code( $invoice_id = 0 ) { |
|
492 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
491 | +function wpinv_get_invoice_currency_code($invoice_id = 0) { |
|
492 | + $invoice = new WPInv_Invoice($invoice_id); |
|
493 | 493 | return $invoice->get_currency(); |
494 | 494 | } |
495 | 495 | |
496 | -function wpinv_get_payment_user_email( $invoice_id ) { |
|
497 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
496 | +function wpinv_get_payment_user_email($invoice_id) { |
|
497 | + $invoice = new WPInv_Invoice($invoice_id); |
|
498 | 498 | return $invoice->get_email(); |
499 | 499 | } |
500 | 500 | |
501 | -function wpinv_get_user_id( $invoice_id ) { |
|
502 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
501 | +function wpinv_get_user_id($invoice_id) { |
|
502 | + $invoice = new WPInv_Invoice($invoice_id); |
|
503 | 503 | return $invoice->get_user_id(); |
504 | 504 | } |
505 | 505 | |
506 | -function wpinv_get_invoice_status( $invoice_id, $return_label = false ) { |
|
507 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
506 | +function wpinv_get_invoice_status($invoice_id, $return_label = false) { |
|
507 | + $invoice = new WPInv_Invoice($invoice_id); |
|
508 | 508 | |
509 | - return $invoice->get_status( $return_label ); |
|
509 | + return $invoice->get_status($return_label); |
|
510 | 510 | } |
511 | 511 | |
512 | -function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) { |
|
513 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
512 | +function wpinv_get_payment_gateway($invoice_id, $return_label = false) { |
|
513 | + $invoice = new WPInv_Invoice($invoice_id); |
|
514 | 514 | |
515 | - return $invoice->get_gateway( $return_label ); |
|
515 | + return $invoice->get_gateway($return_label); |
|
516 | 516 | } |
517 | 517 | |
518 | -function wpinv_get_payment_gateway_name( $invoice_id ) { |
|
519 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
518 | +function wpinv_get_payment_gateway_name($invoice_id) { |
|
519 | + $invoice = new WPInv_Invoice($invoice_id); |
|
520 | 520 | |
521 | 521 | return $invoice->get_gateway_title(); |
522 | 522 | } |
523 | 523 | |
524 | -function wpinv_get_payment_transaction_id( $invoice_id ) { |
|
525 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
524 | +function wpinv_get_payment_transaction_id($invoice_id) { |
|
525 | + $invoice = new WPInv_Invoice($invoice_id); |
|
526 | 526 | |
527 | 527 | return $invoice->get_transaction_id(); |
528 | 528 | } |
529 | 529 | |
530 | -function wpinv_get_id_by_transaction_id( $key ) { |
|
530 | +function wpinv_get_id_by_transaction_id($key) { |
|
531 | 531 | global $wpdb; |
532 | 532 | |
533 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) ); |
|
533 | + $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key)); |
|
534 | 534 | |
535 | - if ( $invoice_id != NULL ) |
|
535 | + if ($invoice_id != NULL) |
|
536 | 536 | return $invoice_id; |
537 | 537 | |
538 | 538 | return 0; |
539 | 539 | } |
540 | 540 | |
541 | -function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
542 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
541 | +function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) { |
|
542 | + $invoice = new WPInv_Invoice($invoice_id); |
|
543 | 543 | |
544 | - return $invoice->get_meta( $meta_key, $single ); |
|
544 | + return $invoice->get_meta($meta_key, $single); |
|
545 | 545 | } |
546 | 546 | |
547 | -function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
548 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
547 | +function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') { |
|
548 | + $invoice = new WPInv_Invoice($invoice_id); |
|
549 | 549 | |
550 | - return $invoice->update_meta( $meta_key, $meta_value, $prev_value ); |
|
550 | + return $invoice->update_meta($meta_key, $meta_value, $prev_value); |
|
551 | 551 | } |
552 | 552 | |
553 | -function wpinv_get_items( $invoice_id = 0 ) { |
|
554 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
553 | +function wpinv_get_items($invoice_id = 0) { |
|
554 | + $invoice = wpinv_get_invoice($invoice_id); |
|
555 | 555 | |
556 | 556 | $items = $invoice->get_items(); |
557 | 557 | $invoice_currency = $invoice->get_currency(); |
558 | 558 | |
559 | - if ( !empty( $items ) && is_array( $items ) ) { |
|
560 | - foreach ( $items as $key => $item ) { |
|
559 | + if (!empty($items) && is_array($items)) { |
|
560 | + foreach ($items as $key => $item) { |
|
561 | 561 | $items[$key]['currency'] = $invoice_currency; |
562 | 562 | |
563 | - if ( !isset( $cart_item['subtotal'] ) ) { |
|
563 | + if (!isset($cart_item['subtotal'])) { |
|
564 | 564 | $items[$key]['subtotal'] = $items[$key]['amount'] * 1; |
565 | 565 | } |
566 | 566 | } |
567 | 567 | } |
568 | 568 | |
569 | - return apply_filters( 'wpinv_get_items', $items, $invoice_id ); |
|
569 | + return apply_filters('wpinv_get_items', $items, $invoice_id); |
|
570 | 570 | } |
571 | 571 | |
572 | -function wpinv_get_fees( $invoice_id = 0 ) { |
|
573 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
572 | +function wpinv_get_fees($invoice_id = 0) { |
|
573 | + $invoice = wpinv_get_invoice($invoice_id); |
|
574 | 574 | $fees = $invoice->get_fees(); |
575 | 575 | |
576 | - return apply_filters( 'wpinv_get_fees', $fees, $invoice_id ); |
|
576 | + return apply_filters('wpinv_get_fees', $fees, $invoice_id); |
|
577 | 577 | } |
578 | 578 | |
579 | -function wpinv_get_invoice_ip( $invoice_id ) { |
|
580 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
579 | +function wpinv_get_invoice_ip($invoice_id) { |
|
580 | + $invoice = new WPInv_Invoice($invoice_id); |
|
581 | 581 | return $invoice->get_ip(); |
582 | 582 | } |
583 | 583 | |
584 | -function wpinv_get_invoice_user_info( $invoice_id ) { |
|
585 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
584 | +function wpinv_get_invoice_user_info($invoice_id) { |
|
585 | + $invoice = new WPInv_Invoice($invoice_id); |
|
586 | 586 | return $invoice->get_user_info(); |
587 | 587 | } |
588 | 588 | |
589 | -function wpinv_subtotal( $invoice_id = 0, $currency = false ) { |
|
590 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
589 | +function wpinv_subtotal($invoice_id = 0, $currency = false) { |
|
590 | + $invoice = new WPInv_Invoice($invoice_id); |
|
591 | 591 | |
592 | - return $invoice->get_subtotal( $currency ); |
|
592 | + return $invoice->get_subtotal($currency); |
|
593 | 593 | } |
594 | 594 | |
595 | -function wpinv_tax( $invoice_id = 0, $currency = false ) { |
|
596 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
595 | +function wpinv_tax($invoice_id = 0, $currency = false) { |
|
596 | + $invoice = new WPInv_Invoice($invoice_id); |
|
597 | 597 | |
598 | - return $invoice->get_tax( $currency ); |
|
598 | + return $invoice->get_tax($currency); |
|
599 | 599 | } |
600 | 600 | |
601 | -function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) { |
|
602 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
601 | +function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) { |
|
602 | + $invoice = wpinv_get_invoice($invoice_id); |
|
603 | 603 | |
604 | - return $invoice->get_discount( $currency, $dash ); |
|
604 | + return $invoice->get_discount($currency, $dash); |
|
605 | 605 | } |
606 | 606 | |
607 | -function wpinv_discount_code( $invoice_id = 0 ) { |
|
608 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
607 | +function wpinv_discount_code($invoice_id = 0) { |
|
608 | + $invoice = new WPInv_Invoice($invoice_id); |
|
609 | 609 | |
610 | 610 | return $invoice->get_discount_code(); |
611 | 611 | } |
612 | 612 | |
613 | -function wpinv_payment_total( $invoice_id = 0, $currency = false ) { |
|
614 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
613 | +function wpinv_payment_total($invoice_id = 0, $currency = false) { |
|
614 | + $invoice = new WPInv_Invoice($invoice_id); |
|
615 | 615 | |
616 | - return $invoice->get_total( $currency ); |
|
616 | + return $invoice->get_total($currency); |
|
617 | 617 | } |
618 | 618 | |
619 | -function wpinv_get_date_created( $invoice_id = 0, $format = '' ) { |
|
620 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
619 | +function wpinv_get_date_created($invoice_id = 0, $format = '') { |
|
620 | + $invoice = new WPInv_Invoice($invoice_id); |
|
621 | 621 | |
622 | - $format = !empty( $format ) ? $format : get_option( 'date_format' ); |
|
622 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
623 | 623 | $date_created = $invoice->get_created_date(); |
624 | - $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : ''; |
|
624 | + $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : ''; |
|
625 | 625 | |
626 | 626 | return $date_created; |
627 | 627 | } |
628 | 628 | |
629 | -function wpinv_get_invoice_date( $invoice_id = 0, $format = '', $default = true ) { |
|
630 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
629 | +function wpinv_get_invoice_date($invoice_id = 0, $format = '', $default = true) { |
|
630 | + $invoice = new WPInv_Invoice($invoice_id); |
|
631 | 631 | |
632 | - $format = !empty( $format ) ? $format : get_option( 'date_format' ); |
|
632 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
633 | 633 | $date_completed = $invoice->get_completed_date(); |
634 | - $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : ''; |
|
635 | - if ( $invoice_date == '' && $default ) { |
|
636 | - $invoice_date = wpinv_get_date_created( $invoice_id, $format ); |
|
634 | + $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : ''; |
|
635 | + if ($invoice_date == '' && $default) { |
|
636 | + $invoice_date = wpinv_get_date_created($invoice_id, $format); |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | return $invoice_date; |
640 | 640 | } |
641 | 641 | |
642 | -function wpinv_get_invoice_vat_number( $invoice_id = 0 ) { |
|
643 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
642 | +function wpinv_get_invoice_vat_number($invoice_id = 0) { |
|
643 | + $invoice = new WPInv_Invoice($invoice_id); |
|
644 | 644 | |
645 | 645 | return $invoice->vat_number; |
646 | 646 | } |
647 | 647 | |
648 | -function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) { |
|
649 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
648 | +function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) { |
|
649 | + $invoice = new WPInv_Invoice($invoice_id); |
|
650 | 650 | |
651 | - return $invoice->add_note( $note, $user_type, $added_by_user, $system ); |
|
651 | + return $invoice->add_note($note, $user_type, $added_by_user, $system); |
|
652 | 652 | } |
653 | 653 | |
654 | -function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) { |
|
654 | +function wpinv_get_invoice_notes($invoice_id = 0, $type = '') { |
|
655 | 655 | global $invoicing; |
656 | 656 | |
657 | - if ( empty( $invoice_id ) ) { |
|
657 | + if (empty($invoice_id)) { |
|
658 | 658 | return NULL; |
659 | 659 | } |
660 | 660 | |
661 | - $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type ); |
|
661 | + $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type); |
|
662 | 662 | |
663 | - return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type ); |
|
663 | + return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type); |
|
664 | 664 | } |
665 | 665 | |
666 | -function wpinv_get_payment_key( $invoice_id = 0 ) { |
|
667 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
666 | +function wpinv_get_payment_key($invoice_id = 0) { |
|
667 | + $invoice = new WPInv_Invoice($invoice_id); |
|
668 | 668 | return $invoice->get_key(); |
669 | 669 | } |
670 | 670 | |
671 | -function wpinv_get_invoice_number( $invoice_id = 0 ) { |
|
672 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
671 | +function wpinv_get_invoice_number($invoice_id = 0) { |
|
672 | + $invoice = new WPInv_Invoice($invoice_id); |
|
673 | 673 | return $invoice->get_number(); |
674 | 674 | } |
675 | 675 | |
676 | -function wpinv_get_cart_discountable_subtotal( $code_id ) { |
|
676 | +function wpinv_get_cart_discountable_subtotal($code_id) { |
|
677 | 677 | $cart_items = wpinv_get_cart_content_details(); |
678 | 678 | $items = array(); |
679 | 679 | |
680 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
680 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
681 | 681 | |
682 | - if( $cart_items ) { |
|
682 | + if ($cart_items) { |
|
683 | 683 | |
684 | - foreach( $cart_items as $item ) { |
|
684 | + foreach ($cart_items as $item) { |
|
685 | 685 | |
686 | - if( ! in_array( $item['id'], $excluded_items ) ) { |
|
687 | - $items[] = $item; |
|
686 | + if (!in_array($item['id'], $excluded_items)) { |
|
687 | + $items[] = $item; |
|
688 | 688 | } |
689 | 689 | } |
690 | 690 | } |
691 | 691 | |
692 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
692 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
693 | 693 | |
694 | - return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal ); |
|
694 | + return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal); |
|
695 | 695 | } |
696 | 696 | |
697 | -function wpinv_get_cart_items_subtotal( $items ) { |
|
697 | +function wpinv_get_cart_items_subtotal($items) { |
|
698 | 698 | $subtotal = 0.00; |
699 | 699 | |
700 | - if ( is_array( $items ) && ! empty( $items ) ) { |
|
701 | - $prices = wp_list_pluck( $items, 'subtotal' ); |
|
700 | + if (is_array($items) && !empty($items)) { |
|
701 | + $prices = wp_list_pluck($items, 'subtotal'); |
|
702 | 702 | |
703 | - if( is_array( $prices ) ) { |
|
704 | - $subtotal = array_sum( $prices ); |
|
703 | + if (is_array($prices)) { |
|
704 | + $subtotal = array_sum($prices); |
|
705 | 705 | } else { |
706 | 706 | $subtotal = 0.00; |
707 | 707 | } |
708 | 708 | |
709 | - if( $subtotal < 0 ) { |
|
709 | + if ($subtotal < 0) { |
|
710 | 710 | $subtotal = 0.00; |
711 | 711 | } |
712 | 712 | } |
713 | 713 | |
714 | - return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal ); |
|
714 | + return apply_filters('wpinv_get_cart_items_subtotal', $subtotal); |
|
715 | 715 | } |
716 | 716 | |
717 | -function wpinv_get_cart_subtotal( $items = array() ) { |
|
718 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
719 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
717 | +function wpinv_get_cart_subtotal($items = array()) { |
|
718 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
719 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
720 | 720 | |
721 | - return apply_filters( 'wpinv_get_cart_subtotal', $subtotal ); |
|
721 | + return apply_filters('wpinv_get_cart_subtotal', $subtotal); |
|
722 | 722 | } |
723 | 723 | |
724 | -function wpinv_cart_subtotal( $items = array() ) { |
|
725 | - $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ) ); |
|
724 | +function wpinv_cart_subtotal($items = array()) { |
|
725 | + $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items))); |
|
726 | 726 | |
727 | 727 | return $price; |
728 | 728 | } |
729 | 729 | |
730 | -function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) { |
|
731 | - $subtotal = (float)wpinv_get_cart_subtotal( $items ); |
|
732 | - $discounts = (float)wpinv_get_cart_discounted_amount( $items ); |
|
733 | - $cart_tax = (float)wpinv_get_cart_tax( $items ); |
|
730 | +function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) { |
|
731 | + $subtotal = (float)wpinv_get_cart_subtotal($items); |
|
732 | + $discounts = (float)wpinv_get_cart_discounted_amount($items); |
|
733 | + $cart_tax = (float)wpinv_get_cart_tax($items); |
|
734 | 734 | $fees = (float)wpinv_get_cart_fee_total(); |
735 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
735 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
736 | 736 | $total = 0; |
737 | 737 | } else { |
738 | - $total = $subtotal - $discounts + $cart_tax + $fees; |
|
738 | + $total = $subtotal - $discounts + $cart_tax + $fees; |
|
739 | 739 | } |
740 | 740 | |
741 | - if ( $total < 0 ) { |
|
741 | + if ($total < 0) { |
|
742 | 742 | $total = 0.00; |
743 | 743 | } |
744 | 744 | |
745 | - $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items ); |
|
745 | + $total = (float)apply_filters('wpinv_get_cart_total', $total, $items); |
|
746 | 746 | |
747 | - return wpinv_sanitize_amount( $total ); |
|
747 | + return wpinv_sanitize_amount($total); |
|
748 | 748 | } |
749 | 749 | |
750 | -function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) { |
|
750 | +function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) { |
|
751 | 751 | global $cart_total; |
752 | - $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ) ); |
|
753 | - $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice ); |
|
752 | + $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice))); |
|
753 | + $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice); |
|
754 | 754 | |
755 | 755 | $cart_total = $total; |
756 | 756 | |
757 | - if ( !$echo ) { |
|
757 | + if (!$echo) { |
|
758 | 758 | return $total; |
759 | 759 | } |
760 | 760 | |
761 | 761 | echo $total; |
762 | 762 | } |
763 | 763 | |
764 | -function wpinv_get_cart_tax( $items = array() ) { |
|
764 | +function wpinv_get_cart_tax($items = array()) { |
|
765 | 765 | $cart_tax = 0; |
766 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
766 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
767 | 767 | |
768 | - if ( $items ) { |
|
769 | - $taxes = wp_list_pluck( $items, 'tax' ); |
|
768 | + if ($items) { |
|
769 | + $taxes = wp_list_pluck($items, 'tax'); |
|
770 | 770 | |
771 | - if( is_array( $taxes ) ) { |
|
772 | - $cart_tax = array_sum( $taxes ); |
|
771 | + if (is_array($taxes)) { |
|
772 | + $cart_tax = array_sum($taxes); |
|
773 | 773 | } |
774 | 774 | } |
775 | 775 | |
776 | 776 | $cart_tax += wpinv_get_cart_fee_tax(); |
777 | 777 | |
778 | - return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) ); |
|
778 | + return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax)); |
|
779 | 779 | } |
780 | 780 | |
781 | -function wpinv_cart_tax( $items = array(), $echo = false ) { |
|
782 | - $cart_tax = wpinv_get_cart_tax( $items ); |
|
783 | - $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ) ); |
|
781 | +function wpinv_cart_tax($items = array(), $echo = false) { |
|
782 | + $cart_tax = wpinv_get_cart_tax($items); |
|
783 | + $cart_tax = wpinv_price(wpinv_format_amount($cart_tax)); |
|
784 | 784 | |
785 | - $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items ); |
|
785 | + $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items); |
|
786 | 786 | |
787 | - if ( !$echo ) { |
|
787 | + if (!$echo) { |
|
788 | 788 | return $tax; |
789 | 789 | } |
790 | 790 | |
791 | 791 | echo $tax; |
792 | 792 | } |
793 | 793 | |
794 | -function wpinv_get_cart_discount_code( $items = array() ) { |
|
794 | +function wpinv_get_cart_discount_code($items = array()) { |
|
795 | 795 | $invoice = wpinv_get_invoice_cart(); |
796 | - $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : ''; |
|
796 | + $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : ''; |
|
797 | 797 | |
798 | - return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code ); |
|
798 | + return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code); |
|
799 | 799 | } |
800 | 800 | |
801 | -function wpinv_cart_discount_code( $items = array(), $echo = false ) { |
|
802 | - $cart_discount_code = wpinv_get_cart_discount_code( $items ); |
|
801 | +function wpinv_cart_discount_code($items = array(), $echo = false) { |
|
802 | + $cart_discount_code = wpinv_get_cart_discount_code($items); |
|
803 | 803 | |
804 | - if ( $cart_discount_code != '' ) { |
|
804 | + if ($cart_discount_code != '') { |
|
805 | 805 | $cart_discount_code = ' (' . $cart_discount_code . ')'; |
806 | 806 | } |
807 | 807 | |
808 | - $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items ); |
|
808 | + $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items); |
|
809 | 809 | |
810 | - if ( !$echo ) { |
|
810 | + if (!$echo) { |
|
811 | 811 | return $discount_code; |
812 | 812 | } |
813 | 813 | |
814 | 814 | echo $discount_code; |
815 | 815 | } |
816 | 816 | |
817 | -function wpinv_get_cart_discount( $items = array() ) { |
|
817 | +function wpinv_get_cart_discount($items = array()) { |
|
818 | 818 | $invoice = wpinv_get_invoice_cart(); |
819 | - $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0; |
|
819 | + $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0; |
|
820 | 820 | |
821 | - return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items ); |
|
821 | + return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items); |
|
822 | 822 | } |
823 | 823 | |
824 | -function wpinv_cart_discount( $items = array(), $echo = false ) { |
|
825 | - $cart_discount = wpinv_get_cart_discount( $items ); |
|
826 | - $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) ); |
|
824 | +function wpinv_cart_discount($items = array(), $echo = false) { |
|
825 | + $cart_discount = wpinv_get_cart_discount($items); |
|
826 | + $cart_discount = wpinv_price(wpinv_format_amount($cart_discount)); |
|
827 | 827 | |
828 | - $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items ); |
|
828 | + $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items); |
|
829 | 829 | |
830 | - if ( !$echo ) { |
|
830 | + if (!$echo) { |
|
831 | 831 | return $discount; |
832 | 832 | } |
833 | 833 | |
834 | 834 | echo $discount; |
835 | 835 | } |
836 | 836 | |
837 | -function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) { |
|
838 | - $item = new WPInv_Item( $item_id ); |
|
837 | +function wpinv_get_cart_fees($type = 'all', $item_id = 0) { |
|
838 | + $item = new WPInv_Item($item_id); |
|
839 | 839 | |
840 | - return $item->get_fees( $type, $item_id ); |
|
840 | + return $item->get_fees($type, $item_id); |
|
841 | 841 | } |
842 | 842 | |
843 | 843 | function wpinv_get_cart_fee_total() { |
844 | - $total = 0; |
|
844 | + $total = 0; |
|
845 | 845 | $fees = wpinv_get_cart_fees(); |
846 | 846 | |
847 | - if ( $fees ) { |
|
848 | - foreach ( $fees as $fee_id => $fee ) { |
|
847 | + if ($fees) { |
|
848 | + foreach ($fees as $fee_id => $fee) { |
|
849 | 849 | $total += $fee['amount']; |
850 | 850 | } |
851 | 851 | } |
852 | 852 | |
853 | - return apply_filters( 'wpinv_get_cart_fee_total', $total ); |
|
853 | + return apply_filters('wpinv_get_cart_fee_total', $total); |
|
854 | 854 | } |
855 | 855 | |
856 | 856 | function wpinv_get_cart_fee_tax() { |
857 | 857 | $tax = 0; |
858 | 858 | $fees = wpinv_get_cart_fees(); |
859 | 859 | |
860 | - if ( $fees ) { |
|
861 | - foreach ( $fees as $fee_id => $fee ) { |
|
862 | - if( ! empty( $fee['no_tax'] ) ) { |
|
860 | + if ($fees) { |
|
861 | + foreach ($fees as $fee_id => $fee) { |
|
862 | + if (!empty($fee['no_tax'])) { |
|
863 | 863 | continue; |
864 | 864 | } |
865 | 865 | |
866 | - $tax += wpinv_calculate_tax( $fee['amount'] ); |
|
866 | + $tax += wpinv_calculate_tax($fee['amount']); |
|
867 | 867 | } |
868 | 868 | } |
869 | 869 | |
870 | - return apply_filters( 'wpinv_get_cart_fee_tax', $tax ); |
|
870 | + return apply_filters('wpinv_get_cart_fee_tax', $tax); |
|
871 | 871 | } |
872 | 872 | |
873 | 873 | function wpinv_cart_has_recurring_item() { |
874 | 874 | $cart_items = wpinv_get_cart_contents(); |
875 | 875 | |
876 | - if ( empty( $cart_items ) ) { |
|
876 | + if (empty($cart_items)) { |
|
877 | 877 | return false; |
878 | 878 | } |
879 | 879 | |
880 | 880 | $has_subscription = false; |
881 | - foreach( $cart_items as $cart_item ) { |
|
882 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
881 | + foreach ($cart_items as $cart_item) { |
|
882 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
883 | 883 | $has_subscription = true; |
884 | 884 | break; |
885 | 885 | } |
886 | 886 | } |
887 | 887 | |
888 | - return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items ); |
|
888 | + return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items); |
|
889 | 889 | } |
890 | 890 | |
891 | 891 | function wpinv_cart_has_free_trial() { |
@@ -893,94 +893,94 @@ discard block |
||
893 | 893 | |
894 | 894 | $free_trial = false; |
895 | 895 | |
896 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
896 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
897 | 897 | $free_trial = true; |
898 | 898 | } |
899 | 899 | |
900 | - return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice ); |
|
900 | + return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice); |
|
901 | 901 | } |
902 | 902 | |
903 | 903 | function wpinv_get_cart_contents() { |
904 | 904 | $cart_details = wpinv_get_cart_details(); |
905 | 905 | |
906 | - return apply_filters( 'wpinv_get_cart_contents', $cart_details ); |
|
906 | + return apply_filters('wpinv_get_cart_contents', $cart_details); |
|
907 | 907 | } |
908 | 908 | |
909 | 909 | function wpinv_get_cart_content_details() { |
910 | 910 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
911 | 911 | $cart_items = wpinv_get_cart_contents(); |
912 | 912 | |
913 | - if ( empty( $cart_items ) ) { |
|
913 | + if (empty($cart_items)) { |
|
914 | 914 | return false; |
915 | 915 | } |
916 | 916 | $invoice = wpinv_get_invoice_cart(); |
917 | 917 | |
918 | 918 | $details = array(); |
919 | - $length = count( $cart_items ) - 1; |
|
919 | + $length = count($cart_items) - 1; |
|
920 | 920 | |
921 | - if ( empty( $_POST['country'] ) ) { |
|
921 | + if (empty($_POST['country'])) { |
|
922 | 922 | $_POST['country'] = $invoice->country; |
923 | 923 | } |
924 | - if ( !isset( $_POST['state'] ) ) { |
|
924 | + if (!isset($_POST['state'])) { |
|
925 | 925 | $_POST['state'] = $invoice->state; |
926 | 926 | } |
927 | 927 | |
928 | - foreach( $cart_items as $key => $item ) { |
|
929 | - $item_id = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : ''; |
|
930 | - if ( empty( $item_id ) ) { |
|
928 | + foreach ($cart_items as $key => $item) { |
|
929 | + $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : ''; |
|
930 | + if (empty($item_id)) { |
|
931 | 931 | continue; |
932 | 932 | } |
933 | 933 | |
934 | 934 | $wpi_current_id = $invoice->ID; |
935 | 935 | $wpi_item_id = $item_id; |
936 | 936 | |
937 | - if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) { |
|
937 | + if (isset($item['custom_price']) && $item['custom_price'] !== '') { |
|
938 | 938 | $item_price = $item['custom_price']; |
939 | 939 | } else { |
940 | - if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) { |
|
940 | + if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) { |
|
941 | 941 | $item_price = $item['item_price']; |
942 | 942 | } else { |
943 | - $item_price = wpinv_get_item_price( $item_id ); |
|
943 | + $item_price = wpinv_get_item_price($item_id); |
|
944 | 944 | } |
945 | 945 | } |
946 | - $discount = wpinv_get_cart_item_discount_amount( $item ); |
|
947 | - $discount = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item ); |
|
948 | - $quantity = wpinv_get_cart_item_quantity( $item ); |
|
949 | - $fees = wpinv_get_cart_fees( 'fee', $item_id ); |
|
946 | + $discount = wpinv_get_cart_item_discount_amount($item); |
|
947 | + $discount = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item); |
|
948 | + $quantity = wpinv_get_cart_item_quantity($item); |
|
949 | + $fees = wpinv_get_cart_fees('fee', $item_id); |
|
950 | 950 | |
951 | 951 | $subtotal = $item_price * $quantity; |
952 | - $tax_rate = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id ); |
|
953 | - $tax_class = $wpinv_euvat->get_item_class( $item_id ); |
|
954 | - $tax = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount ); |
|
952 | + $tax_rate = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id); |
|
953 | + $tax_class = $wpinv_euvat->get_item_class($item_id); |
|
954 | + $tax = wpinv_get_cart_item_tax($item_id, $subtotal - $discount); |
|
955 | 955 | |
956 | - if ( wpinv_prices_include_tax() ) { |
|
957 | - $subtotal -= wpinv_round_amount( $tax ); |
|
956 | + if (wpinv_prices_include_tax()) { |
|
957 | + $subtotal -= wpinv_round_amount($tax); |
|
958 | 958 | } |
959 | 959 | |
960 | - $total = $subtotal - $discount + $tax; |
|
960 | + $total = $subtotal - $discount + $tax; |
|
961 | 961 | |
962 | 962 | // Do not allow totals to go negatve |
963 | - if( $total < 0 ) { |
|
963 | + if ($total < 0) { |
|
964 | 964 | $total = 0; |
965 | 965 | } |
966 | 966 | |
967 | - $details[ $key ] = array( |
|
967 | + $details[$key] = array( |
|
968 | 968 | 'id' => $item_id, |
969 | - 'name' => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ), |
|
970 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
971 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
969 | + 'name' => !empty($item['name']) ? $item['name'] : get_the_title($item_id), |
|
970 | + 'item_price' => wpinv_round_amount($item_price), |
|
971 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
972 | 972 | 'quantity' => $quantity, |
973 | - 'discount' => wpinv_round_amount( $discount ), |
|
974 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
975 | - 'tax' => wpinv_round_amount( $tax ), |
|
976 | - 'price' => wpinv_round_amount( $total ), |
|
973 | + 'discount' => wpinv_round_amount($discount), |
|
974 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
975 | + 'tax' => wpinv_round_amount($tax), |
|
976 | + 'price' => wpinv_round_amount($total), |
|
977 | 977 | 'vat_rates_class' => $tax_class, |
978 | 978 | 'vat_rate' => $tax_rate, |
979 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
979 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
980 | 980 | 'fees' => $fees, |
981 | 981 | ); |
982 | 982 | |
983 | - if ( $wpinv_is_last_cart_item ) { |
|
983 | + if ($wpinv_is_last_cart_item) { |
|
984 | 984 | $wpinv_is_last_cart_item = false; |
985 | 985 | $wpinv_flat_discount_total = 0.00; |
986 | 986 | } |
@@ -989,60 +989,60 @@ discard block |
||
989 | 989 | return $details; |
990 | 990 | } |
991 | 991 | |
992 | -function wpinv_get_cart_details( $invoice_id = 0 ) { |
|
992 | +function wpinv_get_cart_details($invoice_id = 0) { |
|
993 | 993 | global $ajax_cart_details; |
994 | 994 | |
995 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
996 | - $cart_details = !empty( $ajax_cart_details ) ? $ajax_cart_details : $invoice->cart_details; |
|
995 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
996 | + $cart_details = !empty($ajax_cart_details) ? $ajax_cart_details : $invoice->cart_details; |
|
997 | 997 | |
998 | 998 | $invoice_currency = $invoice->currency; |
999 | 999 | |
1000 | - if ( ! empty( $cart_details ) && is_array( $cart_details ) ) { |
|
1001 | - foreach ( $cart_details as $key => $cart_item ) { |
|
1002 | - $cart_details[ $key ]['currency'] = $invoice_currency; |
|
1000 | + if (!empty($cart_details) && is_array($cart_details)) { |
|
1001 | + foreach ($cart_details as $key => $cart_item) { |
|
1002 | + $cart_details[$key]['currency'] = $invoice_currency; |
|
1003 | 1003 | |
1004 | - if ( ! isset( $cart_item['subtotal'] ) ) { |
|
1005 | - $cart_details[ $key ]['subtotal'] = $cart_item['price']; |
|
1004 | + if (!isset($cart_item['subtotal'])) { |
|
1005 | + $cart_details[$key]['subtotal'] = $cart_item['price']; |
|
1006 | 1006 | } |
1007 | 1007 | } |
1008 | 1008 | } |
1009 | 1009 | |
1010 | - return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id ); |
|
1010 | + return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id); |
|
1011 | 1011 | } |
1012 | 1012 | |
1013 | -function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) { |
|
1014 | - if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) { |
|
1013 | +function wpinv_record_status_change($invoice_id, $new_status, $old_status) { |
|
1014 | + if ('wpi_invoice' != get_post_type($invoice_id)) { |
|
1015 | 1015 | return; |
1016 | 1016 | } |
1017 | 1017 | |
1018 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1018 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1019 | 1019 | |
1020 | - $old_status = wpinv_status_nicename( $old_status ); |
|
1021 | - $new_status = wpinv_status_nicename( $new_status ); |
|
1020 | + $old_status = wpinv_status_nicename($old_status); |
|
1021 | + $new_status = wpinv_status_nicename($new_status); |
|
1022 | 1022 | |
1023 | - $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status ); |
|
1023 | + $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status); |
|
1024 | 1024 | |
1025 | 1025 | // Add note |
1026 | - return $invoice->add_note( $status_change, false, false, true ); |
|
1026 | + return $invoice->add_note($status_change, false, false, true); |
|
1027 | 1027 | } |
1028 | -add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 ); |
|
1028 | +add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3); |
|
1029 | 1029 | |
1030 | -function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) { |
|
1030 | +function wpinv_complete_payment($invoice_id, $new_status, $old_status) { |
|
1031 | 1031 | global $wpi_has_free_trial; |
1032 | 1032 | |
1033 | 1033 | $wpi_has_free_trial = false; |
1034 | 1034 | |
1035 | - if ( $old_status == 'publish' ) { |
|
1035 | + if ($old_status == 'publish') { |
|
1036 | 1036 | return; // Make sure that payments are only paid once |
1037 | 1037 | } |
1038 | 1038 | |
1039 | 1039 | // Make sure the payment completion is only processed when new status is paid |
1040 | - if ( $new_status != 'publish' ) { |
|
1040 | + if ($new_status != 'publish') { |
|
1041 | 1041 | return; |
1042 | 1042 | } |
1043 | 1043 | |
1044 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
1045 | - if ( empty( $invoice ) ) { |
|
1044 | + $invoice = new WPInv_Invoice($invoice_id); |
|
1045 | + if (empty($invoice)) { |
|
1046 | 1046 | return; |
1047 | 1047 | } |
1048 | 1048 | |
@@ -1050,58 +1050,58 @@ discard block |
||
1050 | 1050 | $completed_date = $invoice->completed_date; |
1051 | 1051 | $cart_details = $invoice->cart_details; |
1052 | 1052 | |
1053 | - do_action( 'wpinv_pre_complete_payment', $invoice_id ); |
|
1053 | + do_action('wpinv_pre_complete_payment', $invoice_id); |
|
1054 | 1054 | |
1055 | - if ( is_array( $cart_details ) ) { |
|
1055 | + if (is_array($cart_details)) { |
|
1056 | 1056 | // Increase purchase count and earnings |
1057 | - foreach ( $cart_details as $cart_index => $item ) { |
|
1057 | + foreach ($cart_details as $cart_index => $item) { |
|
1058 | 1058 | // Ensure these actions only run once, ever |
1059 | - if ( empty( $completed_date ) ) { |
|
1060 | - do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index ); |
|
1059 | + if (empty($completed_date)) { |
|
1060 | + do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index); |
|
1061 | 1061 | } |
1062 | 1062 | } |
1063 | 1063 | } |
1064 | 1064 | |
1065 | 1065 | // Check for discount codes and increment their use counts |
1066 | - if ( $discounts = $invoice->get_discounts( true ) ) { |
|
1067 | - if( ! empty( $discounts ) ) { |
|
1068 | - foreach( $discounts as $code ) { |
|
1069 | - wpinv_increase_discount_usage( $code ); |
|
1066 | + if ($discounts = $invoice->get_discounts(true)) { |
|
1067 | + if (!empty($discounts)) { |
|
1068 | + foreach ($discounts as $code) { |
|
1069 | + wpinv_increase_discount_usage($code); |
|
1070 | 1070 | } |
1071 | 1071 | } |
1072 | 1072 | } |
1073 | 1073 | |
1074 | 1074 | // Ensure this action only runs once ever |
1075 | - if( empty( $completed_date ) ) { |
|
1075 | + if (empty($completed_date)) { |
|
1076 | 1076 | // Save the completed date |
1077 | - $invoice->set( 'completed_date', current_time( 'mysql', 0 ) ); |
|
1077 | + $invoice->set('completed_date', current_time('mysql', 0)); |
|
1078 | 1078 | $invoice->save(); |
1079 | 1079 | |
1080 | - do_action( 'wpinv_complete_payment', $invoice_id ); |
|
1080 | + do_action('wpinv_complete_payment', $invoice_id); |
|
1081 | 1081 | } |
1082 | 1082 | |
1083 | 1083 | // Empty the shopping cart |
1084 | 1084 | wpinv_empty_cart(); |
1085 | 1085 | } |
1086 | -add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 ); |
|
1086 | +add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3); |
|
1087 | 1087 | |
1088 | -function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) { |
|
1089 | - $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id ); |
|
1088 | +function wpinv_update_payment_status($invoice_id, $new_status = 'publish') { |
|
1089 | + $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int)$invoice_id); |
|
1090 | 1090 | |
1091 | - if ( empty( $invoice ) ) { |
|
1091 | + if (empty($invoice)) { |
|
1092 | 1092 | return false; |
1093 | 1093 | } |
1094 | 1094 | |
1095 | - return $invoice->update_status( $new_status ); |
|
1095 | + return $invoice->update_status($new_status); |
|
1096 | 1096 | } |
1097 | 1097 | |
1098 | -function wpinv_cart_has_fees( $type = 'all' ) { |
|
1098 | +function wpinv_cart_has_fees($type = 'all') { |
|
1099 | 1099 | return false; |
1100 | 1100 | } |
1101 | 1101 | |
1102 | 1102 | function wpinv_validate_checkout_fields() { |
1103 | 1103 | // Check if there is $_POST |
1104 | - if ( empty( $_POST ) ) { |
|
1104 | + if (empty($_POST)) { |
|
1105 | 1105 | return false; |
1106 | 1106 | } |
1107 | 1107 | |
@@ -1113,7 +1113,7 @@ discard block |
||
1113 | 1113 | ); |
1114 | 1114 | |
1115 | 1115 | // Validate agree to terms |
1116 | - if ( wpinv_get_option( 'show_agree_to_terms', false ) ) { |
|
1116 | + if (wpinv_get_option('show_agree_to_terms', false)) { |
|
1117 | 1117 | wpinv_checkout_validate_agree_to_terms(); |
1118 | 1118 | } |
1119 | 1119 | |
@@ -1129,26 +1129,26 @@ discard block |
||
1129 | 1129 | |
1130 | 1130 | $invoice = wpinv_get_invoice_cart(); |
1131 | 1131 | $has_subscription = $invoice->is_recurring(); |
1132 | - if ( empty( $invoice ) ) { |
|
1133 | - wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) ); |
|
1132 | + if (empty($invoice)) { |
|
1133 | + wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing')); |
|
1134 | 1134 | return $gateway; |
1135 | 1135 | } |
1136 | 1136 | |
1137 | 1137 | // Check if a gateway value is present |
1138 | - if ( !empty( $_REQUEST['wpi-gateway'] ) ) { |
|
1139 | - $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] ); |
|
1138 | + if (!empty($_REQUEST['wpi-gateway'])) { |
|
1139 | + $gateway = sanitize_text_field($_REQUEST['wpi-gateway']); |
|
1140 | 1140 | |
1141 | - if ( $invoice->is_free() ) { |
|
1141 | + if ($invoice->is_free()) { |
|
1142 | 1142 | $gateway = 'manual'; |
1143 | - } elseif ( !wpinv_is_gateway_active( $gateway ) ) { |
|
1144 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) ); |
|
1145 | - } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) { |
|
1146 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway doesnot support subscription payment', 'invoicing' ) ); |
|
1143 | + } elseif (!wpinv_is_gateway_active($gateway)) { |
|
1144 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing')); |
|
1145 | + } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) { |
|
1146 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway doesnot support subscription payment', 'invoicing')); |
|
1147 | 1147 | } |
1148 | 1148 | } |
1149 | 1149 | |
1150 | - if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) { |
|
1151 | - wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) ); |
|
1150 | + if ($has_subscription && count(wpinv_get_cart_contents()) > 1) { |
|
1151 | + wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing')); |
|
1152 | 1152 | } |
1153 | 1153 | |
1154 | 1154 | return $gateway; |
@@ -1162,10 +1162,10 @@ discard block |
||
1162 | 1162 | |
1163 | 1163 | $error = false; |
1164 | 1164 | // If we have discounts, loop through them |
1165 | - if ( ! empty( $discounts ) ) { |
|
1166 | - foreach ( $discounts as $discount ) { |
|
1165 | + if (!empty($discounts)) { |
|
1166 | + foreach ($discounts as $discount) { |
|
1167 | 1167 | // Check if valid |
1168 | - if ( !wpinv_is_discount_valid( $discount, (int)$wpi_cart->get_user_id() ) ) { |
|
1168 | + if (!wpinv_is_discount_valid($discount, (int)$wpi_cart->get_user_id())) { |
|
1169 | 1169 | // Discount is not valid |
1170 | 1170 | $error = true; |
1171 | 1171 | } |
@@ -1175,20 +1175,20 @@ discard block |
||
1175 | 1175 | return NULL; |
1176 | 1176 | } |
1177 | 1177 | |
1178 | - if ( $error && !wpinv_get_errors() ) { |
|
1179 | - wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) ); |
|
1178 | + if ($error && !wpinv_get_errors()) { |
|
1179 | + wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing')); |
|
1180 | 1180 | } |
1181 | 1181 | |
1182 | - return implode( ',', $discounts ); |
|
1182 | + return implode(',', $discounts); |
|
1183 | 1183 | } |
1184 | 1184 | |
1185 | 1185 | function wpinv_checkout_validate_cc() { |
1186 | 1186 | $card_data = wpinv_checkout_get_cc_info(); |
1187 | 1187 | |
1188 | 1188 | // Validate the card zip |
1189 | - if ( !empty( $card_data['wpinv_zip'] ) ) { |
|
1190 | - if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) { |
|
1191 | - wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) ); |
|
1189 | + if (!empty($card_data['wpinv_zip'])) { |
|
1190 | + if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) { |
|
1191 | + wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing')); |
|
1192 | 1192 | } |
1193 | 1193 | } |
1194 | 1194 | |
@@ -1198,28 +1198,28 @@ discard block |
||
1198 | 1198 | |
1199 | 1199 | function wpinv_checkout_get_cc_info() { |
1200 | 1200 | $cc_info = array(); |
1201 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
1202 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
1203 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
1204 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
1205 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
1206 | - $cc_info['card_address'] = isset( $_POST['wpinv_address'] ) ? sanitize_text_field( $_POST['wpinv_address'] ) : ''; |
|
1207 | - $cc_info['card_city'] = isset( $_POST['wpinv_city'] ) ? sanitize_text_field( $_POST['wpinv_city'] ) : ''; |
|
1208 | - $cc_info['card_state'] = isset( $_POST['wpinv_state'] ) ? sanitize_text_field( $_POST['wpinv_state'] ) : ''; |
|
1209 | - $cc_info['card_country'] = isset( $_POST['wpinv_country'] ) ? sanitize_text_field( $_POST['wpinv_country'] ) : ''; |
|
1210 | - $cc_info['card_zip'] = isset( $_POST['wpinv_zip'] ) ? sanitize_text_field( $_POST['wpinv_zip'] ) : ''; |
|
1201 | + $cc_info['card_name'] = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : ''; |
|
1202 | + $cc_info['card_number'] = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : ''; |
|
1203 | + $cc_info['card_cvc'] = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : ''; |
|
1204 | + $cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : ''; |
|
1205 | + $cc_info['card_exp_year'] = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : ''; |
|
1206 | + $cc_info['card_address'] = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : ''; |
|
1207 | + $cc_info['card_city'] = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : ''; |
|
1208 | + $cc_info['card_state'] = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : ''; |
|
1209 | + $cc_info['card_country'] = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : ''; |
|
1210 | + $cc_info['card_zip'] = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : ''; |
|
1211 | 1211 | |
1212 | 1212 | // Return cc info |
1213 | 1213 | return $cc_info; |
1214 | 1214 | } |
1215 | 1215 | |
1216 | -function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
1216 | +function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') { |
|
1217 | 1217 | $ret = false; |
1218 | 1218 | |
1219 | - if ( empty( $zip ) || empty( $country_code ) ) |
|
1219 | + if (empty($zip) || empty($country_code)) |
|
1220 | 1220 | return $ret; |
1221 | 1221 | |
1222 | - $country_code = strtoupper( $country_code ); |
|
1222 | + $country_code = strtoupper($country_code); |
|
1223 | 1223 | |
1224 | 1224 | $zip_regex = array( |
1225 | 1225 | "AD" => "AD\d{3}", |
@@ -1379,17 +1379,17 @@ discard block |
||
1379 | 1379 | "ZM" => "\d{5}" |
1380 | 1380 | ); |
1381 | 1381 | |
1382 | - if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) |
|
1382 | + if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip)) |
|
1383 | 1383 | $ret = true; |
1384 | 1384 | |
1385 | - return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code ); |
|
1385 | + return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code); |
|
1386 | 1386 | } |
1387 | 1387 | |
1388 | 1388 | function wpinv_checkout_validate_agree_to_terms() { |
1389 | 1389 | // Validate agree to terms |
1390 | - if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) { |
|
1390 | + if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) { |
|
1391 | 1391 | // User did not agree |
1392 | - wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) ); |
|
1392 | + wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing'))); |
|
1393 | 1393 | } |
1394 | 1394 | } |
1395 | 1395 | |
@@ -1401,40 +1401,40 @@ discard block |
||
1401 | 1401 | ); |
1402 | 1402 | |
1403 | 1403 | // Verify there is a user_ID |
1404 | - if ( $user_ID = (int)$wpi_cart->get_user_id() ) { |
|
1404 | + if ($user_ID = (int)$wpi_cart->get_user_id()) { |
|
1405 | 1405 | // Get the logged in user data |
1406 | - $user_data = get_userdata( $user_ID ); |
|
1407 | - $required_fields = wpinv_checkout_required_fields(); |
|
1406 | + $user_data = get_userdata($user_ID); |
|
1407 | + $required_fields = wpinv_checkout_required_fields(); |
|
1408 | 1408 | |
1409 | 1409 | // Loop through required fields and show error messages |
1410 | - if ( !empty( $required_fields ) ) { |
|
1411 | - foreach ( $required_fields as $field_name => $value ) { |
|
1412 | - if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) { |
|
1413 | - wpinv_set_error( $value['error_id'], $value['error_message'] ); |
|
1410 | + if (!empty($required_fields)) { |
|
1411 | + foreach ($required_fields as $field_name => $value) { |
|
1412 | + if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) { |
|
1413 | + wpinv_set_error($value['error_id'], $value['error_message']); |
|
1414 | 1414 | } |
1415 | 1415 | } |
1416 | 1416 | } |
1417 | 1417 | |
1418 | 1418 | // Verify data |
1419 | - if ( $user_data ) { |
|
1419 | + if ($user_data) { |
|
1420 | 1420 | // Collected logged in user data |
1421 | 1421 | $valid_user_data = array( |
1422 | 1422 | 'user_id' => $user_ID, |
1423 | - 'email' => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email, |
|
1424 | - 'first_name' => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name, |
|
1425 | - 'last_name' => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name'] ) ? sanitize_text_field( $_POST['wpinv_last_name'] ) : $user_data->last_name, |
|
1423 | + 'email' => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email, |
|
1424 | + 'first_name' => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name, |
|
1425 | + 'last_name' => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name, |
|
1426 | 1426 | ); |
1427 | 1427 | |
1428 | - if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) { |
|
1429 | - wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) ); |
|
1428 | + if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) { |
|
1429 | + wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing')); |
|
1430 | 1430 | } |
1431 | 1431 | } else { |
1432 | 1432 | // Set invalid user error |
1433 | - wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) ); |
|
1433 | + wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing')); |
|
1434 | 1434 | } |
1435 | 1435 | } else { |
1436 | 1436 | // Set invalid user error |
1437 | - wpinv_set_error( 'invalid_user_id', __( 'The invalid invoice user id', 'invoicing' ) ); |
|
1437 | + wpinv_set_error('invalid_user_id', __('The invalid invoice user id', 'invoicing')); |
|
1438 | 1438 | } |
1439 | 1439 | |
1440 | 1440 | // Return user data |
@@ -1446,30 +1446,30 @@ discard block |
||
1446 | 1446 | |
1447 | 1447 | $data = array(); |
1448 | 1448 | |
1449 | - if ( is_user_logged_in() ) { |
|
1450 | - if ( !wpinv_require_login_to_checkout() || ( wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id() ) ) { |
|
1449 | + if (is_user_logged_in()) { |
|
1450 | + if (!wpinv_require_login_to_checkout() || (wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id())) { |
|
1451 | 1451 | $data['user_id'] = (int)get_current_user_id(); |
1452 | 1452 | } else { |
1453 | - wpinv_set_error( 'logged_in_only', __( 'You are not allowed to pay for this invoice', 'invoicing' ) ); |
|
1453 | + wpinv_set_error('logged_in_only', __('You are not allowed to pay for this invoice', 'invoicing')); |
|
1454 | 1454 | } |
1455 | 1455 | } else { |
1456 | 1456 | // If guest checkout allowed |
1457 | - if ( !wpinv_require_login_to_checkout() ) { |
|
1457 | + if (!wpinv_require_login_to_checkout()) { |
|
1458 | 1458 | $data['user_id'] = 0; |
1459 | 1459 | } else { |
1460 | - wpinv_set_error( 'logged_in_only', __( 'You must be logged in to pay for this invoice', 'invoicing' ) ); |
|
1460 | + wpinv_set_error('logged_in_only', __('You must be logged in to pay for this invoice', 'invoicing')); |
|
1461 | 1461 | } |
1462 | 1462 | } |
1463 | 1463 | |
1464 | 1464 | return $data; |
1465 | 1465 | } |
1466 | 1466 | |
1467 | -function wpinv_checkout_form_get_user( $valid_data = array() ) { |
|
1467 | +function wpinv_checkout_form_get_user($valid_data = array()) { |
|
1468 | 1468 | // Initialize user |
1469 | 1469 | $user = false; |
1470 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
1470 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
1471 | 1471 | |
1472 | - if ( empty( $valid_data['current_user'] ) ) { |
|
1472 | + if (empty($valid_data['current_user'])) { |
|
1473 | 1473 | $user = false; |
1474 | 1474 | } else { |
1475 | 1475 | // Set the valid invoice user |
@@ -1477,7 +1477,7 @@ discard block |
||
1477 | 1477 | } |
1478 | 1478 | |
1479 | 1479 | // Verify invoice have an user |
1480 | - if ( false === $user || empty( $user ) ) { |
|
1480 | + if (false === $user || empty($user)) { |
|
1481 | 1481 | return false; |
1482 | 1482 | } |
1483 | 1483 | |
@@ -1494,11 +1494,11 @@ discard block |
||
1494 | 1494 | 'zip', |
1495 | 1495 | ); |
1496 | 1496 | |
1497 | - foreach ( $address_fields as $field ) { |
|
1498 | - $user[$field] = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false; |
|
1497 | + foreach ($address_fields as $field) { |
|
1498 | + $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false; |
|
1499 | 1499 | |
1500 | - if ( !empty( $user['user_id'] ) && !empty( $valid_data['current_user']['user_id'] ) && $valid_data['current_user']['user_id'] == $user['user_id'] ) { |
|
1501 | - update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] ); |
|
1500 | + if (!empty($user['user_id']) && !empty($valid_data['current_user']['user_id']) && $valid_data['current_user']['user_id'] == $user['user_id']) { |
|
1501 | + update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]); |
|
1502 | 1502 | } |
1503 | 1503 | } |
1504 | 1504 | |
@@ -1506,28 +1506,28 @@ discard block |
||
1506 | 1506 | return $user; |
1507 | 1507 | } |
1508 | 1508 | |
1509 | -function wpinv_set_checkout_session( $invoice_data = array() ) { |
|
1509 | +function wpinv_set_checkout_session($invoice_data = array()) { |
|
1510 | 1510 | global $wpi_session; |
1511 | 1511 | |
1512 | - return $wpi_session->set( 'wpinv_checkout', $invoice_data ); |
|
1512 | + return $wpi_session->set('wpinv_checkout', $invoice_data); |
|
1513 | 1513 | } |
1514 | 1514 | |
1515 | 1515 | function wpinv_get_checkout_session() { |
1516 | 1516 | global $wpi_session; |
1517 | 1517 | |
1518 | - return $wpi_session->get( 'wpinv_checkout' ); |
|
1518 | + return $wpi_session->get('wpinv_checkout'); |
|
1519 | 1519 | } |
1520 | 1520 | |
1521 | 1521 | function wpinv_empty_cart() { |
1522 | 1522 | global $wpi_session; |
1523 | 1523 | |
1524 | 1524 | // Remove cart contents |
1525 | - $wpi_session->set( 'wpinv_checkout', NULL ); |
|
1525 | + $wpi_session->set('wpinv_checkout', NULL); |
|
1526 | 1526 | |
1527 | 1527 | // Remove all cart fees |
1528 | - $wpi_session->set( 'wpi_cart_fees', NULL ); |
|
1528 | + $wpi_session->set('wpi_cart_fees', NULL); |
|
1529 | 1529 | |
1530 | - do_action( 'wpinv_empty_cart' ); |
|
1530 | + do_action('wpinv_empty_cart'); |
|
1531 | 1531 | } |
1532 | 1532 | |
1533 | 1533 | function wpinv_process_checkout() { |
@@ -1540,42 +1540,42 @@ discard block |
||
1540 | 1540 | |
1541 | 1541 | $wpi_checkout_id = $invoice->ID; |
1542 | 1542 | |
1543 | - do_action( 'wpinv_pre_process_checkout' ); |
|
1543 | + do_action('wpinv_pre_process_checkout'); |
|
1544 | 1544 | |
1545 | - if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty |
|
1545 | + if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty |
|
1546 | 1546 | $valid_data = false; |
1547 | - wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) ); |
|
1547 | + wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing')); |
|
1548 | 1548 | } else { |
1549 | 1549 | // Validate the form $_POST data |
1550 | 1550 | $valid_data = wpinv_validate_checkout_fields(); |
1551 | 1551 | |
1552 | 1552 | // Allow themes and plugins to hook to errors |
1553 | - do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST ); |
|
1553 | + do_action('wpinv_checkout_error_checks', $valid_data, $_POST); |
|
1554 | 1554 | } |
1555 | 1555 | |
1556 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
1556 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
1557 | 1557 | |
1558 | 1558 | // Validate the user |
1559 | - $user = wpinv_checkout_form_get_user( $valid_data ); |
|
1559 | + $user = wpinv_checkout_form_get_user($valid_data); |
|
1560 | 1560 | |
1561 | 1561 | // Let extensions validate fields after user is logged in if user has used login/registration form |
1562 | - do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST ); |
|
1562 | + do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST); |
|
1563 | 1563 | |
1564 | - if ( false === $valid_data || wpinv_get_errors() || ! $user ) { |
|
1565 | - if ( $is_ajax ) { |
|
1566 | - do_action( 'wpinv_ajax_checkout_errors' ); |
|
1564 | + if (false === $valid_data || wpinv_get_errors() || !$user) { |
|
1565 | + if ($is_ajax) { |
|
1566 | + do_action('wpinv_ajax_checkout_errors'); |
|
1567 | 1567 | die(); |
1568 | 1568 | } else { |
1569 | 1569 | return false; |
1570 | 1570 | } |
1571 | 1571 | } |
1572 | 1572 | |
1573 | - if ( $is_ajax ) { |
|
1573 | + if ($is_ajax) { |
|
1574 | 1574 | // Save address fields. |
1575 | - $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' ); |
|
1576 | - foreach ( $address_fields as $field ) { |
|
1577 | - if ( isset( $user[$field] ) ) { |
|
1578 | - $invoice->set( $field, $user[$field] ); |
|
1575 | + $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company'); |
|
1576 | + foreach ($address_fields as $field) { |
|
1577 | + if (isset($user[$field])) { |
|
1578 | + $invoice->set($field, $user[$field]); |
|
1579 | 1579 | } |
1580 | 1580 | |
1581 | 1581 | $invoice->save(); |
@@ -1583,15 +1583,15 @@ discard block |
||
1583 | 1583 | |
1584 | 1584 | $response['success'] = true; |
1585 | 1585 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
1586 | - $response['data']['subtotalf'] = $invoice->get_subtotal( true ); |
|
1586 | + $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
|
1587 | 1587 | $response['data']['discount'] = $invoice->get_discount(); |
1588 | - $response['data']['discountf'] = $invoice->get_discount( true ); |
|
1588 | + $response['data']['discountf'] = $invoice->get_discount(true); |
|
1589 | 1589 | $response['data']['tax'] = $invoice->get_tax(); |
1590 | - $response['data']['taxf'] = $invoice->get_tax( true ); |
|
1590 | + $response['data']['taxf'] = $invoice->get_tax(true); |
|
1591 | 1591 | $response['data']['total'] = $invoice->get_total(); |
1592 | - $response['data']['totalf'] = $invoice->get_total( true ); |
|
1592 | + $response['data']['totalf'] = $invoice->get_total(true); |
|
1593 | 1593 | |
1594 | - wp_send_json( $response ); |
|
1594 | + wp_send_json($response); |
|
1595 | 1595 | } |
1596 | 1596 | |
1597 | 1597 | $user_info = array( |
@@ -1613,42 +1613,42 @@ discard block |
||
1613 | 1613 | |
1614 | 1614 | // Setup invoice information |
1615 | 1615 | $invoice_data = array( |
1616 | - 'invoice_id' => !empty( $invoice ) ? $invoice->ID : 0, |
|
1616 | + 'invoice_id' => !empty($invoice) ? $invoice->ID : 0, |
|
1617 | 1617 | 'items' => $cart_items, |
1618 | 1618 | 'cart_discounts' => $discounts, |
1619 | - 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
1620 | - 'subtotal' => wpinv_get_cart_subtotal( $cart_items ), // Amount before taxes and discounts |
|
1621 | - 'discount' => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount |
|
1622 | - 'tax' => wpinv_get_cart_tax( $cart_items ), // Taxed amount |
|
1623 | - 'price' => wpinv_get_cart_total( $cart_items, $discounts ), // Amount after taxes |
|
1619 | + 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
1620 | + 'subtotal' => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts |
|
1621 | + 'discount' => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount |
|
1622 | + 'tax' => wpinv_get_cart_tax($cart_items), // Taxed amount |
|
1623 | + 'price' => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes |
|
1624 | 1624 | 'invoice_key' => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(), |
1625 | 1625 | 'user_email' => $user['email'], |
1626 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
1627 | - 'user_info' => stripslashes_deep( $user_info ), |
|
1626 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
1627 | + 'user_info' => stripslashes_deep($user_info), |
|
1628 | 1628 | 'post_data' => $_POST, |
1629 | 1629 | 'cart_details' => $cart_items, |
1630 | 1630 | 'gateway' => $valid_data['gateway'], |
1631 | 1631 | 'card_info' => $valid_data['cc_info'] |
1632 | 1632 | ); |
1633 | 1633 | |
1634 | - $vat_info = $wpinv_euvat->current_vat_data(); |
|
1635 | - if ( is_array( $vat_info ) ) { |
|
1634 | + $vat_info = $wpinv_euvat->current_vat_data(); |
|
1635 | + if (is_array($vat_info)) { |
|
1636 | 1636 | $invoice_data['user_info']['vat_number'] = $vat_info['number']; |
1637 | 1637 | $invoice_data['user_info']['vat_rate'] = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']); |
1638 | - $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
1638 | + $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
1639 | 1639 | |
1640 | 1640 | // Add the VAT rate to each item in the cart |
1641 | - foreach( $invoice_data['cart_details'] as $key => $item_data) { |
|
1641 | + foreach ($invoice_data['cart_details'] as $key => $item_data) { |
|
1642 | 1642 | $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']); |
1643 | - $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 ); |
|
1643 | + $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4); |
|
1644 | 1644 | } |
1645 | 1645 | } |
1646 | 1646 | |
1647 | 1647 | // Save vat fields. |
1648 | - $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' ); |
|
1649 | - foreach ( $address_fields as $field ) { |
|
1650 | - if ( isset( $invoice_data['user_info'][$field] ) ) { |
|
1651 | - $invoice->set( $field, $invoice_data['user_info'][$field] ); |
|
1648 | + $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed'); |
|
1649 | + foreach ($address_fields as $field) { |
|
1650 | + if (isset($invoice_data['user_info'][$field])) { |
|
1651 | + $invoice->set($field, $invoice_data['user_info'][$field]); |
|
1652 | 1652 | } |
1653 | 1653 | |
1654 | 1654 | $invoice->save(); |
@@ -1658,49 +1658,49 @@ discard block |
||
1658 | 1658 | $valid_data['user'] = $user; |
1659 | 1659 | |
1660 | 1660 | // Allow themes and plugins to hook before the gateway |
1661 | - do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data ); |
|
1661 | + do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data); |
|
1662 | 1662 | |
1663 | 1663 | // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice |
1664 | - if ( !$invoice_data['price'] ) { |
|
1664 | + if (!$invoice_data['price']) { |
|
1665 | 1665 | // Revert to manual |
1666 | 1666 | $invoice_data['gateway'] = 'manual'; |
1667 | 1667 | $_POST['wpi-gateway'] = 'manual'; |
1668 | 1668 | } |
1669 | 1669 | |
1670 | 1670 | // Allow the invoice data to be modified before it is sent to the gateway |
1671 | - $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data ); |
|
1671 | + $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data); |
|
1672 | 1672 | |
1673 | 1673 | // Setup the data we're storing in the purchase session |
1674 | 1674 | $session_data = $invoice_data; |
1675 | 1675 | // Make sure credit card numbers are never stored in sessions |
1676 | - if ( !empty( $session_data['card_info']['card_number'] ) ) { |
|
1677 | - unset( $session_data['card_info']['card_number'] ); |
|
1676 | + if (!empty($session_data['card_info']['card_number'])) { |
|
1677 | + unset($session_data['card_info']['card_number']); |
|
1678 | 1678 | } |
1679 | 1679 | |
1680 | 1680 | // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data. |
1681 | - wpinv_set_checkout_session( $invoice_data ); |
|
1681 | + wpinv_set_checkout_session($invoice_data); |
|
1682 | 1682 | |
1683 | 1683 | // Set gateway |
1684 | - $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] ); |
|
1685 | - $invoice->update_meta( '_wpinv_mode', ( wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live' ) ); |
|
1686 | - $invoice->update_meta( '_wpinv_checkout', true ); |
|
1684 | + $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']); |
|
1685 | + $invoice->update_meta('_wpinv_mode', (wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live')); |
|
1686 | + $invoice->update_meta('_wpinv_checkout', true); |
|
1687 | 1687 | |
1688 | - do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data ); |
|
1688 | + do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data); |
|
1689 | 1689 | |
1690 | 1690 | // Send info to the gateway for payment processing |
1691 | - wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data ); |
|
1691 | + wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data); |
|
1692 | 1692 | die(); |
1693 | 1693 | } |
1694 | -add_action( 'wpinv_payment', 'wpinv_process_checkout' ); |
|
1694 | +add_action('wpinv_payment', 'wpinv_process_checkout'); |
|
1695 | 1695 | |
1696 | -function wpinv_get_invoices( $args ) { |
|
1697 | - $args = wp_parse_args( $args, array( |
|
1698 | - 'status' => array_keys( wpinv_get_invoice_statuses() ), |
|
1696 | +function wpinv_get_invoices($args) { |
|
1697 | + $args = wp_parse_args($args, array( |
|
1698 | + 'status' => array_keys(wpinv_get_invoice_statuses()), |
|
1699 | 1699 | 'type' => 'wpi_invoice', |
1700 | 1700 | 'parent' => null, |
1701 | 1701 | 'user' => null, |
1702 | 1702 | 'email' => '', |
1703 | - 'limit' => get_option( 'posts_per_page' ), |
|
1703 | + 'limit' => get_option('posts_per_page'), |
|
1704 | 1704 | 'offset' => null, |
1705 | 1705 | 'page' => 1, |
1706 | 1706 | 'exclude' => array(), |
@@ -1708,7 +1708,7 @@ discard block |
||
1708 | 1708 | 'order' => 'DESC', |
1709 | 1709 | 'return' => 'objects', |
1710 | 1710 | 'paginate' => false, |
1711 | - ) ); |
|
1711 | + )); |
|
1712 | 1712 | |
1713 | 1713 | // Handle some BW compatibility arg names where wp_query args differ in naming. |
1714 | 1714 | $map_legacy = array( |
@@ -1721,18 +1721,18 @@ discard block |
||
1721 | 1721 | 'paged' => 'page', |
1722 | 1722 | ); |
1723 | 1723 | |
1724 | - foreach ( $map_legacy as $from => $to ) { |
|
1725 | - if ( isset( $args[ $from ] ) ) { |
|
1726 | - $args[ $to ] = $args[ $from ]; |
|
1724 | + foreach ($map_legacy as $from => $to) { |
|
1725 | + if (isset($args[$from])) { |
|
1726 | + $args[$to] = $args[$from]; |
|
1727 | 1727 | } |
1728 | 1728 | } |
1729 | 1729 | |
1730 | - if ( get_query_var( 'paged' ) ) |
|
1730 | + if (get_query_var('paged')) |
|
1731 | 1731 | $args['page'] = get_query_var('paged'); |
1732 | - else if ( get_query_var( 'page' ) ) |
|
1733 | - $args['page'] = get_query_var( 'page' ); |
|
1734 | - else if ( !empty( $args[ 'page' ] ) ) |
|
1735 | - $args['page'] = $args[ 'page' ]; |
|
1732 | + else if (get_query_var('page')) |
|
1733 | + $args['page'] = get_query_var('page'); |
|
1734 | + else if (!empty($args['page'])) |
|
1735 | + $args['page'] = $args['page']; |
|
1736 | 1736 | else |
1737 | 1737 | $args['page'] = 1; |
1738 | 1738 | |
@@ -1745,47 +1745,47 @@ discard block |
||
1745 | 1745 | 'post_status' => $args['status'], |
1746 | 1746 | 'posts_per_page' => $args['limit'], |
1747 | 1747 | 'meta_query' => array(), |
1748 | - 'date_query' => !empty( $args['date_query'] ) ? $args['date_query'] : array(), |
|
1748 | + 'date_query' => !empty($args['date_query']) ? $args['date_query'] : array(), |
|
1749 | 1749 | 'fields' => 'ids', |
1750 | 1750 | 'orderby' => $args['orderby'], |
1751 | 1751 | 'order' => $args['order'], |
1752 | 1752 | ); |
1753 | 1753 | |
1754 | - if ( !empty( $args['user'] ) ) { |
|
1755 | - $wp_query_args['author'] = absint( $args['user'] ); |
|
1754 | + if (!empty($args['user'])) { |
|
1755 | + $wp_query_args['author'] = absint($args['user']); |
|
1756 | 1756 | } |
1757 | 1757 | |
1758 | - if ( ! is_null( $args['parent'] ) ) { |
|
1759 | - $wp_query_args['post_parent'] = absint( $args['parent'] ); |
|
1758 | + if (!is_null($args['parent'])) { |
|
1759 | + $wp_query_args['post_parent'] = absint($args['parent']); |
|
1760 | 1760 | } |
1761 | 1761 | |
1762 | - if ( ! is_null( $args['offset'] ) ) { |
|
1763 | - $wp_query_args['offset'] = absint( $args['offset'] ); |
|
1762 | + if (!is_null($args['offset'])) { |
|
1763 | + $wp_query_args['offset'] = absint($args['offset']); |
|
1764 | 1764 | } else { |
1765 | - $wp_query_args['paged'] = absint( $args['page'] ); |
|
1765 | + $wp_query_args['paged'] = absint($args['page']); |
|
1766 | 1766 | } |
1767 | 1767 | |
1768 | - if ( ! empty( $args['exclude'] ) ) { |
|
1769 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
1768 | + if (!empty($args['exclude'])) { |
|
1769 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
1770 | 1770 | } |
1771 | 1771 | |
1772 | - if ( ! $args['paginate' ] ) { |
|
1772 | + if (!$args['paginate']) { |
|
1773 | 1773 | $wp_query_args['no_found_rows'] = true; |
1774 | 1774 | } |
1775 | 1775 | |
1776 | 1776 | // Get results. |
1777 | - $invoices = new WP_Query( $wp_query_args ); |
|
1777 | + $invoices = new WP_Query($wp_query_args); |
|
1778 | 1778 | |
1779 | - if ( 'objects' === $args['return'] ) { |
|
1780 | - $return = array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
1781 | - } elseif ( 'self' === $args['return'] ) { |
|
1779 | + if ('objects' === $args['return']) { |
|
1780 | + $return = array_map('wpinv_get_invoice', $invoices->posts); |
|
1781 | + } elseif ('self' === $args['return']) { |
|
1782 | 1782 | return $invoices; |
1783 | 1783 | } else { |
1784 | 1784 | $return = $invoices->posts; |
1785 | 1785 | } |
1786 | 1786 | |
1787 | - if ( $args['paginate' ] ) { |
|
1788 | - return (object) array( |
|
1787 | + if ($args['paginate']) { |
|
1788 | + return (object)array( |
|
1789 | 1789 | 'invoices' => $return, |
1790 | 1790 | 'total' => $invoices->found_posts, |
1791 | 1791 | 'max_num_pages' => $invoices->max_num_pages, |
@@ -1797,22 +1797,22 @@ discard block |
||
1797 | 1797 | |
1798 | 1798 | function wpinv_get_user_invoices_columns() { |
1799 | 1799 | $columns = array( |
1800 | - 'invoice-number' => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ), |
|
1801 | - 'created-date' => array( 'title' => __( 'Created Date', 'invoicing' ), 'class' => 'text-left' ), |
|
1802 | - 'payment-date' => array( 'title' => __( 'Payment Date', 'invoicing' ), 'class' => 'text-left' ), |
|
1803 | - 'invoice-status' => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ), |
|
1804 | - 'invoice-total' => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ), |
|
1805 | - 'invoice-actions' => array( 'title' => ' ', 'class' => 'text-center' ), |
|
1800 | + 'invoice-number' => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'), |
|
1801 | + 'created-date' => array('title' => __('Created Date', 'invoicing'), 'class' => 'text-left'), |
|
1802 | + 'payment-date' => array('title' => __('Payment Date', 'invoicing'), 'class' => 'text-left'), |
|
1803 | + 'invoice-status' => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'), |
|
1804 | + 'invoice-total' => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'), |
|
1805 | + 'invoice-actions' => array('title' => ' ', 'class' => 'text-center'), |
|
1806 | 1806 | ); |
1807 | 1807 | |
1808 | - return apply_filters( 'wpinv_user_invoices_columns', $columns ); |
|
1808 | + return apply_filters('wpinv_user_invoices_columns', $columns); |
|
1809 | 1809 | } |
1810 | 1810 | |
1811 | -function wpinv_payment_receipt( $atts, $content = null ) { |
|
1811 | +function wpinv_payment_receipt($atts, $content = null) { |
|
1812 | 1812 | global $wpinv_receipt_args; |
1813 | 1813 | |
1814 | - $wpinv_receipt_args = shortcode_atts( array( |
|
1815 | - 'error' => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ), |
|
1814 | + $wpinv_receipt_args = shortcode_atts(array( |
|
1815 | + 'error' => __('Sorry, trouble retrieving payment receipt.', 'invoicing'), |
|
1816 | 1816 | 'price' => true, |
1817 | 1817 | 'discount' => true, |
1818 | 1818 | 'items' => true, |
@@ -1821,195 +1821,195 @@ discard block |
||
1821 | 1821 | 'invoice_key' => false, |
1822 | 1822 | 'payment_method' => true, |
1823 | 1823 | 'invoice_id' => true |
1824 | - ), $atts, 'wpinv_receipt' ); |
|
1824 | + ), $atts, 'wpinv_receipt'); |
|
1825 | 1825 | |
1826 | 1826 | $session = wpinv_get_checkout_session(); |
1827 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
1828 | - $invoice_key = urldecode( $_GET['invoice_key'] ); |
|
1829 | - } else if ( $session && isset( $session['invoice_key'] ) ) { |
|
1827 | + if (isset($_GET['invoice_key'])) { |
|
1828 | + $invoice_key = urldecode($_GET['invoice_key']); |
|
1829 | + } else if ($session && isset($session['invoice_key'])) { |
|
1830 | 1830 | $invoice_key = $session['invoice_key']; |
1831 | - } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) { |
|
1831 | + } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) { |
|
1832 | 1832 | $invoice_key = $wpinv_receipt_args['invoice_key']; |
1833 | - } else if ( isset( $_GET['invoice-id'] ) ) { |
|
1834 | - $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] ); |
|
1833 | + } else if (isset($_GET['invoice-id'])) { |
|
1834 | + $invoice_key = wpinv_get_payment_key((int)$_GET['invoice-id']); |
|
1835 | 1835 | } |
1836 | 1836 | |
1837 | 1837 | // No key found |
1838 | - if ( ! isset( $invoice_key ) ) { |
|
1838 | + if (!isset($invoice_key)) { |
|
1839 | 1839 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
1840 | 1840 | } |
1841 | 1841 | |
1842 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1843 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
1844 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
1842 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
1843 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
1844 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
1845 | 1845 | $invoice_id = (int)$_GET['invoice-id']; |
1846 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
1846 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false; |
|
1847 | 1847 | } |
1848 | 1848 | |
1849 | 1849 | // Key was provided, but user is logged out. Offer them the ability to login and view the receipt |
1850 | - if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) { |
|
1850 | + if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) { |
|
1851 | 1851 | // login redirect |
1852 | - return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>'; |
|
1852 | + return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>'; |
|
1853 | 1853 | } |
1854 | 1854 | |
1855 | - if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) { |
|
1855 | + if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) { |
|
1856 | 1856 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
1857 | 1857 | } |
1858 | 1858 | |
1859 | 1859 | ob_start(); |
1860 | 1860 | |
1861 | - wpinv_get_template_part( 'wpinv-invoice-receipt' ); |
|
1861 | + wpinv_get_template_part('wpinv-invoice-receipt'); |
|
1862 | 1862 | |
1863 | 1863 | $display = ob_get_clean(); |
1864 | 1864 | |
1865 | 1865 | return $display; |
1866 | 1866 | } |
1867 | 1867 | |
1868 | -function wpinv_get_invoice_id_by_key( $key ) { |
|
1868 | +function wpinv_get_invoice_id_by_key($key) { |
|
1869 | 1869 | global $wpdb; |
1870 | 1870 | |
1871 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) ); |
|
1871 | + $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key)); |
|
1872 | 1872 | |
1873 | - if ( $invoice_id != NULL ) |
|
1873 | + if ($invoice_id != NULL) |
|
1874 | 1874 | return $invoice_id; |
1875 | 1875 | |
1876 | 1876 | return 0; |
1877 | 1877 | } |
1878 | 1878 | |
1879 | -function wpinv_can_view_receipt( $invoice_key = '' ) { |
|
1879 | +function wpinv_can_view_receipt($invoice_key = '') { |
|
1880 | 1880 | $return = false; |
1881 | 1881 | |
1882 | - if ( empty( $invoice_key ) ) { |
|
1882 | + if (empty($invoice_key)) { |
|
1883 | 1883 | return $return; |
1884 | 1884 | } |
1885 | 1885 | |
1886 | 1886 | global $wpinv_receipt_args; |
1887 | 1887 | |
1888 | - $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1889 | - if ( isset( $_GET['invoice-id'] ) ) { |
|
1890 | - $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0; |
|
1888 | + $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key); |
|
1889 | + if (isset($_GET['invoice-id'])) { |
|
1890 | + $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? (int)$_GET['invoice-id'] : 0; |
|
1891 | 1891 | } |
1892 | 1892 | |
1893 | - if ( empty( $wpinv_receipt_args['id'] ) ) { |
|
1893 | + if (empty($wpinv_receipt_args['id'])) { |
|
1894 | 1894 | return $return; |
1895 | 1895 | } |
1896 | 1896 | |
1897 | - $invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] ); |
|
1898 | - if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) { |
|
1897 | + $invoice = wpinv_get_invoice($wpinv_receipt_args['id']); |
|
1898 | + if (!(!empty($invoice->ID) && $invoice->get_key() === $invoice_key)) { |
|
1899 | 1899 | return $return; |
1900 | 1900 | } |
1901 | 1901 | |
1902 | - if ( is_user_logged_in() ) { |
|
1903 | - if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) { |
|
1902 | + if (is_user_logged_in()) { |
|
1903 | + if ((int)$invoice->get_user_id() === (int)get_current_user_id()) { |
|
1904 | 1904 | $return = true; |
1905 | 1905 | } |
1906 | 1906 | } |
1907 | 1907 | |
1908 | 1908 | $session = wpinv_get_checkout_session(); |
1909 | - if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) { |
|
1910 | - $check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
1909 | + if (isset($_GET['invoice_key']) || ($session && isset($session['invoice_key']))) { |
|
1910 | + $check_key = isset($_GET['invoice_key']) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
1911 | 1911 | |
1912 | - if ( wpinv_require_login_to_checkout() ) { |
|
1912 | + if (wpinv_require_login_to_checkout()) { |
|
1913 | 1913 | $return = $return && $check_key === $invoice_key; |
1914 | 1914 | } else { |
1915 | 1915 | $return = $check_key === $invoice_key; |
1916 | 1916 | } |
1917 | 1917 | } |
1918 | 1918 | |
1919 | - return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key ); |
|
1919 | + return (bool)apply_filters('wpinv_can_view_receipt', $return, $invoice_key); |
|
1920 | 1920 | } |
1921 | 1921 | |
1922 | 1922 | function wpinv_pay_for_invoice() { |
1923 | 1923 | global $wpinv_euvat; |
1924 | 1924 | |
1925 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
1925 | + if (isset($_GET['invoice_key'])) { |
|
1926 | 1926 | $checkout_uri = wpinv_get_checkout_uri(); |
1927 | - $invoice_key = sanitize_text_field( $_GET['invoice_key'] ); |
|
1927 | + $invoice_key = sanitize_text_field($_GET['invoice_key']); |
|
1928 | 1928 | |
1929 | - if ( empty( $invoice_key ) ) { |
|
1930 | - wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) ); |
|
1931 | - wp_redirect( $checkout_uri ); |
|
1929 | + if (empty($invoice_key)) { |
|
1930 | + wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing')); |
|
1931 | + wp_redirect($checkout_uri); |
|
1932 | 1932 | wpinv_die(); |
1933 | 1933 | } |
1934 | 1934 | |
1935 | - do_action( 'wpinv_check_pay_for_invoice', $invoice_key ); |
|
1935 | + do_action('wpinv_check_pay_for_invoice', $invoice_key); |
|
1936 | 1936 | |
1937 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1938 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
1939 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
1937 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
1938 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
1939 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
1940 | 1940 | $invoice_id = (int)$_GET['invoice-id']; |
1941 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
1941 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false; |
|
1942 | 1942 | } |
1943 | 1943 | |
1944 | - if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) { |
|
1945 | - if ( $invoice->needs_payment() ) { |
|
1944 | + if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) { |
|
1945 | + if ($invoice->needs_payment()) { |
|
1946 | 1946 | $data = array(); |
1947 | 1947 | $data['invoice_id'] = $invoice_id; |
1948 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
1948 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
1949 | 1949 | |
1950 | - wpinv_set_checkout_session( $data ); |
|
1950 | + wpinv_set_checkout_session($data); |
|
1951 | 1951 | |
1952 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
1952 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
1953 | 1953 | $_POST['country'] = $wpinv_euvat->get_country_by_ip(); |
1954 | 1954 | $_POST['state'] = $_POST['country'] == $invoice->country ? $invoice->state : ''; |
1955 | 1955 | |
1956 | - wpinv_recalculate_tax( true ); |
|
1956 | + wpinv_recalculate_tax(true); |
|
1957 | 1957 | } |
1958 | 1958 | |
1959 | 1959 | } else { |
1960 | 1960 | $checkout_uri = $invoice->get_view_url(); |
1961 | 1961 | } |
1962 | 1962 | } else { |
1963 | - wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) ); |
|
1963 | + wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing')); |
|
1964 | 1964 | |
1965 | - $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() ); |
|
1965 | + $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink()); |
|
1966 | 1966 | } |
1967 | 1967 | |
1968 | - wp_redirect( $checkout_uri ); |
|
1968 | + wp_redirect($checkout_uri); |
|
1969 | 1969 | wpinv_die(); |
1970 | 1970 | } |
1971 | 1971 | } |
1972 | -add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' ); |
|
1972 | +add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice'); |
|
1973 | 1973 | |
1974 | -function wpinv_handle_pay_via_invoice_link( $invoice_key ) { |
|
1975 | - if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) { |
|
1976 | - if ( $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
1974 | +function wpinv_handle_pay_via_invoice_link($invoice_key) { |
|
1975 | + if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) { |
|
1976 | + if ($invoice = wpinv_get_invoice($invoice_id)) { |
|
1977 | 1977 | $user_id = $invoice->get_user_id(); |
1978 | - $secret = sanitize_text_field( $_GET['_wpipay'] ); |
|
1978 | + $secret = sanitize_text_field($_GET['_wpipay']); |
|
1979 | 1979 | |
1980 | - if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link |
|
1981 | - $redirect_to = remove_query_arg( '_wpipay', get_permalink() ); |
|
1980 | + if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link |
|
1981 | + $redirect_to = remove_query_arg('_wpipay', get_permalink()); |
|
1982 | 1982 | |
1983 | - wpinv_guest_redirect( $redirect_to, $user_id ); |
|
1983 | + wpinv_guest_redirect($redirect_to, $user_id); |
|
1984 | 1984 | wpinv_die(); |
1985 | 1985 | } |
1986 | 1986 | } |
1987 | 1987 | } |
1988 | 1988 | } |
1989 | -add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' ); |
|
1989 | +add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link'); |
|
1990 | 1990 | |
1991 | -function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) { |
|
1992 | - $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id; |
|
1991 | +function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') { |
|
1992 | + $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id; |
|
1993 | 1993 | |
1994 | - if ( empty( $invoice_id ) && $invoice_id > 0 ) { |
|
1994 | + if (empty($invoice_id) && $invoice_id > 0) { |
|
1995 | 1995 | return false; |
1996 | 1996 | } |
1997 | 1997 | |
1998 | - if ( empty( $transaction_id ) ) { |
|
1998 | + if (empty($transaction_id)) { |
|
1999 | 1999 | $transaction_id = $invoice_id; |
2000 | 2000 | } |
2001 | 2001 | |
2002 | - $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id ); |
|
2002 | + $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id); |
|
2003 | 2003 | |
2004 | - return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id ); |
|
2004 | + return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id); |
|
2005 | 2005 | } |
2006 | 2006 | |
2007 | -function wpinv_invoice_status_label( $status, $status_display = '' ) { |
|
2008 | - if ( empty( $status_display ) ) { |
|
2009 | - $status_display = wpinv_status_nicename( $status ); |
|
2007 | +function wpinv_invoice_status_label($status, $status_display = '') { |
|
2008 | + if (empty($status_display)) { |
|
2009 | + $status_display = wpinv_status_nicename($status); |
|
2010 | 2010 | } |
2011 | 2011 | |
2012 | - switch ( $status ) { |
|
2012 | + switch ($status) { |
|
2013 | 2013 | case 'publish' : |
2014 | 2014 | case 'wpi-renewal' : |
2015 | 2015 | $class = 'label-success'; |
@@ -2034,243 +2034,243 @@ discard block |
||
2034 | 2034 | |
2035 | 2035 | $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>'; |
2036 | 2036 | |
2037 | - return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display ); |
|
2037 | + return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display); |
|
2038 | 2038 | } |
2039 | 2039 | |
2040 | -function wpinv_format_invoice_number( $number, $type = '' ) { |
|
2041 | - $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type ); |
|
2042 | - if ( null !== $check ) { |
|
2040 | +function wpinv_format_invoice_number($number, $type = '') { |
|
2041 | + $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type); |
|
2042 | + if (null !== $check) { |
|
2043 | 2043 | return $check; |
2044 | 2044 | } |
2045 | 2045 | |
2046 | - if ( !empty( $number ) && !is_numeric( $number ) ) { |
|
2046 | + if (!empty($number) && !is_numeric($number)) { |
|
2047 | 2047 | return $number; |
2048 | 2048 | } |
2049 | 2049 | |
2050 | - $padd = wpinv_get_option( 'invoice_number_padd' ); |
|
2051 | - $prefix = wpinv_get_option( 'invoice_number_prefix' ); |
|
2052 | - $postfix = wpinv_get_option( 'invoice_number_postfix' ); |
|
2050 | + $padd = wpinv_get_option('invoice_number_padd'); |
|
2051 | + $prefix = wpinv_get_option('invoice_number_prefix'); |
|
2052 | + $postfix = wpinv_get_option('invoice_number_postfix'); |
|
2053 | 2053 | |
2054 | - $padd = absint( $padd ); |
|
2055 | - $formatted_number = absint( $number ); |
|
2054 | + $padd = absint($padd); |
|
2055 | + $formatted_number = absint($number); |
|
2056 | 2056 | |
2057 | - if ( $padd > 0 ) { |
|
2058 | - $formatted_number = zeroise( $formatted_number, $padd ); |
|
2057 | + if ($padd > 0) { |
|
2058 | + $formatted_number = zeroise($formatted_number, $padd); |
|
2059 | 2059 | } |
2060 | 2060 | |
2061 | 2061 | $formatted_number = $prefix . $formatted_number . $postfix; |
2062 | 2062 | |
2063 | - return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd ); |
|
2063 | + return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd); |
|
2064 | 2064 | } |
2065 | 2065 | |
2066 | -function wpinv_get_next_invoice_number( $type = '' ) { |
|
2067 | - $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type ); |
|
2068 | - if ( null !== $check ) { |
|
2066 | +function wpinv_get_next_invoice_number($type = '') { |
|
2067 | + $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type); |
|
2068 | + if (null !== $check) { |
|
2069 | 2069 | return $check; |
2070 | 2070 | } |
2071 | 2071 | |
2072 | - if ( !wpinv_sequential_number_active() ) { |
|
2072 | + if (!wpinv_sequential_number_active()) { |
|
2073 | 2073 | return false; |
2074 | 2074 | } |
2075 | 2075 | |
2076 | - $number = $last_number = get_option( 'wpinv_last_invoice_number' ); |
|
2077 | - $start = wpinv_get_option( 'invoice_sequence_start' ); |
|
2078 | - if ( !absint( $start ) > 0 ) { |
|
2076 | + $number = $last_number = get_option('wpinv_last_invoice_number'); |
|
2077 | + $start = wpinv_get_option('invoice_sequence_start'); |
|
2078 | + if (!absint($start) > 0) { |
|
2079 | 2079 | $start = 1; |
2080 | 2080 | } |
2081 | 2081 | $increment_number = true; |
2082 | 2082 | $save_number = false; |
2083 | 2083 | |
2084 | - if ( !empty( $number ) && !is_numeric( $number ) && $number == wpinv_format_invoice_number( $number ) ) { |
|
2085 | - $number = wpinv_clean_invoice_number( $number ); |
|
2084 | + if (!empty($number) && !is_numeric($number) && $number == wpinv_format_invoice_number($number)) { |
|
2085 | + $number = wpinv_clean_invoice_number($number); |
|
2086 | 2086 | } |
2087 | 2087 | |
2088 | - if ( empty( $number ) ) { |
|
2089 | - if ( !( $last_number === 0 || $last_number === '0' ) ) { |
|
2090 | - $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys( wpinv_get_invoice_statuses( true ) ) ) ); |
|
2088 | + if (empty($number)) { |
|
2089 | + if (!($last_number === 0 || $last_number === '0')) { |
|
2090 | + $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys(wpinv_get_invoice_statuses(true)))); |
|
2091 | 2091 | |
2092 | - if ( !empty( $last_invoice[0] ) && $invoice_number = wpinv_get_invoice_number( $last_invoice[0] ) ) { |
|
2093 | - if ( is_numeric( $invoice_number ) ) { |
|
2092 | + if (!empty($last_invoice[0]) && $invoice_number = wpinv_get_invoice_number($last_invoice[0])) { |
|
2093 | + if (is_numeric($invoice_number)) { |
|
2094 | 2094 | $number = $invoice_number; |
2095 | 2095 | } else { |
2096 | - $number = wpinv_clean_invoice_number( $invoice_number ); |
|
2096 | + $number = wpinv_clean_invoice_number($invoice_number); |
|
2097 | 2097 | } |
2098 | 2098 | } |
2099 | 2099 | |
2100 | - if ( empty( $number ) ) { |
|
2100 | + if (empty($number)) { |
|
2101 | 2101 | $increment_number = false; |
2102 | 2102 | $number = $start; |
2103 | - $save_number = ( $number - 1 ); |
|
2103 | + $save_number = ($number - 1); |
|
2104 | 2104 | } else { |
2105 | 2105 | $save_number = $number; |
2106 | 2106 | } |
2107 | 2107 | } |
2108 | 2108 | } |
2109 | 2109 | |
2110 | - if ( $start > $number ) { |
|
2110 | + if ($start > $number) { |
|
2111 | 2111 | $increment_number = false; |
2112 | 2112 | $number = $start; |
2113 | - $save_number = ( $number - 1 ); |
|
2113 | + $save_number = ($number - 1); |
|
2114 | 2114 | } |
2115 | 2115 | |
2116 | - if ( $save_number !== false ) { |
|
2117 | - update_option( 'wpinv_last_invoice_number', $save_number ); |
|
2116 | + if ($save_number !== false) { |
|
2117 | + update_option('wpinv_last_invoice_number', $save_number); |
|
2118 | 2118 | } |
2119 | 2119 | |
2120 | - $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number ); |
|
2120 | + $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number); |
|
2121 | 2121 | |
2122 | - if ( $increment_number ) { |
|
2122 | + if ($increment_number) { |
|
2123 | 2123 | $number++; |
2124 | 2124 | } |
2125 | 2125 | |
2126 | - return apply_filters( 'wpinv_get_next_invoice_number', $number ); |
|
2126 | + return apply_filters('wpinv_get_next_invoice_number', $number); |
|
2127 | 2127 | } |
2128 | 2128 | |
2129 | -function wpinv_clean_invoice_number( $number, $type = '' ) { |
|
2130 | - $check = apply_filters( 'wpinv_pre_clean_invoice_number', null, $number, $type ); |
|
2131 | - if ( null !== $check ) { |
|
2129 | +function wpinv_clean_invoice_number($number, $type = '') { |
|
2130 | + $check = apply_filters('wpinv_pre_clean_invoice_number', null, $number, $type); |
|
2131 | + if (null !== $check) { |
|
2132 | 2132 | return $check; |
2133 | 2133 | } |
2134 | 2134 | |
2135 | - $prefix = wpinv_get_option( 'invoice_number_prefix' ); |
|
2136 | - $postfix = wpinv_get_option( 'invoice_number_postfix' ); |
|
2135 | + $prefix = wpinv_get_option('invoice_number_prefix'); |
|
2136 | + $postfix = wpinv_get_option('invoice_number_postfix'); |
|
2137 | 2137 | |
2138 | - $number = preg_replace( '/' . $prefix . '/', '', $number, 1 ); |
|
2138 | + $number = preg_replace('/' . $prefix . '/', '', $number, 1); |
|
2139 | 2139 | |
2140 | - $length = strlen( $number ); |
|
2141 | - $postfix_pos = strrpos( $number, $postfix ); |
|
2140 | + $length = strlen($number); |
|
2141 | + $postfix_pos = strrpos($number, $postfix); |
|
2142 | 2142 | |
2143 | - if ( false !== $postfix_pos ) { |
|
2144 | - $number = substr_replace( $number, '', $postfix_pos, $length ); |
|
2143 | + if (false !== $postfix_pos) { |
|
2144 | + $number = substr_replace($number, '', $postfix_pos, $length); |
|
2145 | 2145 | } |
2146 | 2146 | |
2147 | - $number = intval( $number ); |
|
2147 | + $number = intval($number); |
|
2148 | 2148 | |
2149 | - return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix ); |
|
2149 | + return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix); |
|
2150 | 2150 | } |
2151 | 2151 | |
2152 | -function wpinv_save_number_post_saved( $post_ID, $post, $update ) { |
|
2152 | +function wpinv_save_number_post_saved($post_ID, $post, $update) { |
|
2153 | 2153 | global $wpdb; |
2154 | 2154 | |
2155 | - if ( !$update && !get_post_meta( $post_ID, '_wpinv_number', true ) ) { |
|
2156 | - wpinv_update_invoice_number( $post_ID, $post->post_status != 'auto-draft', $post->post_type ); |
|
2155 | + if (!$update && !get_post_meta($post_ID, '_wpinv_number', true)) { |
|
2156 | + wpinv_update_invoice_number($post_ID, $post->post_status != 'auto-draft', $post->post_type); |
|
2157 | 2157 | } |
2158 | 2158 | |
2159 | - if ( !$update ) { |
|
2160 | - $wpdb->update( $wpdb->posts, array( 'post_name' => wpinv_generate_post_name( $post_ID ) ), array( 'ID' => $post_ID ) ); |
|
2161 | - clean_post_cache( $post_ID ); |
|
2159 | + if (!$update) { |
|
2160 | + $wpdb->update($wpdb->posts, array('post_name' => wpinv_generate_post_name($post_ID)), array('ID' => $post_ID)); |
|
2161 | + clean_post_cache($post_ID); |
|
2162 | 2162 | } |
2163 | 2163 | } |
2164 | -add_action( 'save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3 ); |
|
2164 | +add_action('save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3); |
|
2165 | 2165 | |
2166 | -function wpinv_save_number_post_updated( $post_ID, $post_after, $post_before ) { |
|
2167 | - if ( !empty( $post_after->post_type ) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status ) { |
|
2168 | - wpinv_update_invoice_number( $post_ID, true, $post_after->post_type ); |
|
2166 | +function wpinv_save_number_post_updated($post_ID, $post_after, $post_before) { |
|
2167 | + if (!empty($post_after->post_type) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status) { |
|
2168 | + wpinv_update_invoice_number($post_ID, true, $post_after->post_type); |
|
2169 | 2169 | } |
2170 | 2170 | } |
2171 | -add_action( 'post_updated', 'wpinv_save_number_post_updated', 1, 3 ); |
|
2171 | +add_action('post_updated', 'wpinv_save_number_post_updated', 1, 3); |
|
2172 | 2172 | |
2173 | -function wpinv_update_invoice_number( $post_ID, $save_sequential = false, $type = '' ) { |
|
2173 | +function wpinv_update_invoice_number($post_ID, $save_sequential = false, $type = '') { |
|
2174 | 2174 | global $wpdb; |
2175 | 2175 | |
2176 | - $check = apply_filters( 'wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type ); |
|
2177 | - if ( null !== $check ) { |
|
2176 | + $check = apply_filters('wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type); |
|
2177 | + if (null !== $check) { |
|
2178 | 2178 | return $check; |
2179 | 2179 | } |
2180 | 2180 | |
2181 | - if ( wpinv_sequential_number_active() ) { |
|
2181 | + if (wpinv_sequential_number_active()) { |
|
2182 | 2182 | $number = wpinv_get_next_invoice_number(); |
2183 | 2183 | |
2184 | - if ( $save_sequential ) { |
|
2185 | - update_option( 'wpinv_last_invoice_number', $number ); |
|
2184 | + if ($save_sequential) { |
|
2185 | + update_option('wpinv_last_invoice_number', $number); |
|
2186 | 2186 | } |
2187 | 2187 | } else { |
2188 | 2188 | $number = $post_ID; |
2189 | 2189 | } |
2190 | 2190 | |
2191 | - $number = wpinv_format_invoice_number( $number ); |
|
2191 | + $number = wpinv_format_invoice_number($number); |
|
2192 | 2192 | |
2193 | - update_post_meta( $post_ID, '_wpinv_number', $number ); |
|
2193 | + update_post_meta($post_ID, '_wpinv_number', $number); |
|
2194 | 2194 | |
2195 | - $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) ); |
|
2195 | + $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID)); |
|
2196 | 2196 | |
2197 | - clean_post_cache( $post_ID ); |
|
2197 | + clean_post_cache($post_ID); |
|
2198 | 2198 | |
2199 | 2199 | return $number; |
2200 | 2200 | } |
2201 | 2201 | |
2202 | -function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) { |
|
2203 | - return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type ); |
|
2202 | +function wpinv_post_name_prefix($post_type = 'wpi_invoice') { |
|
2203 | + return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type); |
|
2204 | 2204 | } |
2205 | 2205 | |
2206 | -function wpinv_generate_post_name( $post_ID ) { |
|
2207 | - $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) ); |
|
2208 | - $post_name = sanitize_title( $prefix . $post_ID ); |
|
2206 | +function wpinv_generate_post_name($post_ID) { |
|
2207 | + $prefix = wpinv_post_name_prefix(get_post_type($post_ID)); |
|
2208 | + $post_name = sanitize_title($prefix . $post_ID); |
|
2209 | 2209 | |
2210 | - return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix ); |
|
2210 | + return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix); |
|
2211 | 2211 | } |
2212 | 2212 | |
2213 | -function wpinv_is_invoice_viewed( $invoice_id ) { |
|
2214 | - if ( empty( $invoice_id ) ) { |
|
2213 | +function wpinv_is_invoice_viewed($invoice_id) { |
|
2214 | + if (empty($invoice_id)) { |
|
2215 | 2215 | return false; |
2216 | 2216 | } |
2217 | 2217 | |
2218 | - $viewed_meta = get_post_meta( $invoice_id, '_wpinv_is_viewed', true ); |
|
2218 | + $viewed_meta = get_post_meta($invoice_id, '_wpinv_is_viewed', true); |
|
2219 | 2219 | |
2220 | - if ( isset($viewed_meta) && 1 == $viewed_meta ) { |
|
2220 | + if (isset($viewed_meta) && 1 == $viewed_meta) { |
|
2221 | 2221 | $is_viewed = true; |
2222 | 2222 | } else { |
2223 | 2223 | $is_viewed = false; |
2224 | 2224 | } |
2225 | 2225 | |
2226 | - return apply_filters( 'wpinv_is_invoice_viewed', $is_viewed, $invoice_id ); |
|
2226 | + return apply_filters('wpinv_is_invoice_viewed', $is_viewed, $invoice_id); |
|
2227 | 2227 | } |
2228 | 2228 | |
2229 | 2229 | function wpinv_mark_invoice_viewed() { |
2230 | 2230 | |
2231 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
2231 | + if (isset($_GET['invoice_key'])) { |
|
2232 | 2232 | $invoice_key = urldecode($_GET['invoice_key']); |
2233 | 2233 | |
2234 | 2234 | $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
2235 | 2235 | $invoice = new WPInv_Invoice($invoice_id); |
2236 | 2236 | |
2237 | - if(!$invoice_id){ |
|
2237 | + if (!$invoice_id) { |
|
2238 | 2238 | return; |
2239 | 2239 | } |
2240 | 2240 | |
2241 | - if( is_user_logged_in()){ |
|
2241 | + if (is_user_logged_in()) { |
|
2242 | 2242 | $current_user = wp_get_current_user(); |
2243 | - if(!current_user_can('administrator') && $current_user->user_email == $invoice->get_email()){ |
|
2244 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2243 | + if (!current_user_can('administrator') && $current_user->user_email == $invoice->get_email()) { |
|
2244 | + update_post_meta($invoice_id, '_wpinv_is_viewed', 1); |
|
2245 | 2245 | } |
2246 | 2246 | } else { |
2247 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2247 | + update_post_meta($invoice_id, '_wpinv_is_viewed', 1); |
|
2248 | 2248 | } |
2249 | 2249 | } |
2250 | 2250 | |
2251 | 2251 | } |
2252 | -add_action( 'init', 'wpinv_mark_invoice_viewed' ); |
|
2252 | +add_action('init', 'wpinv_mark_invoice_viewed'); |
|
2253 | 2253 | |
2254 | -function wpinv_get_subscription( $invoice ) { |
|
2255 | - if ( empty( $invoice ) ) { |
|
2254 | +function wpinv_get_subscription($invoice) { |
|
2255 | + if (empty($invoice)) { |
|
2256 | 2256 | return false; |
2257 | 2257 | } |
2258 | 2258 | |
2259 | - if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
2260 | - $invoice = wpinv_get_invoice( $invoice ); |
|
2259 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
2260 | + $invoice = wpinv_get_invoice($invoice); |
|
2261 | 2261 | } |
2262 | 2262 | |
2263 | - if ( !( is_object( $invoice ) && ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) { |
|
2263 | + if (!(is_object($invoice) && !empty($invoice->ID) && $invoice->is_recurring())) { |
|
2264 | 2264 | return false; |
2265 | 2265 | } |
2266 | 2266 | |
2267 | - $invoice_id = ! empty( $invoice->parent_invoice ) ? $invoice->parent_invoice : $invoice->ID; |
|
2267 | + $invoice_id = !empty($invoice->parent_invoice) ? $invoice->parent_invoice : $invoice->ID; |
|
2268 | 2268 | |
2269 | 2269 | $subs_db = new WPInv_Subscriptions_DB; |
2270 | - $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice_id, 'number' => 1 ) ); |
|
2270 | + $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice_id, 'number' => 1)); |
|
2271 | 2271 | |
2272 | - if ( ! empty( $subs ) ) { |
|
2273 | - return reset( $subs ); |
|
2272 | + if (!empty($subs)) { |
|
2273 | + return reset($subs); |
|
2274 | 2274 | } |
2275 | 2275 | |
2276 | 2276 | return false; |
@@ -7,91 +7,91 @@ 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 | -if ( !is_admin() ) { |
|
15 | - add_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
16 | - add_action( 'wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar' ); |
|
17 | - add_action( 'wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions' ); |
|
18 | - add_action( 'wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions' ); |
|
14 | +if (!is_admin()) { |
|
15 | + add_filter('template_include', 'wpinv_template', 10, 1); |
|
16 | + add_action('wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar'); |
|
17 | + add_action('wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions'); |
|
18 | + add_action('wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions'); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | function wpinv_template_path() { |
22 | - return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() ); |
|
22 | + return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name()); |
|
23 | 23 | } |
24 | 24 | |
25 | -function wpinv_display_invoice_top_bar( $invoice ) { |
|
26 | - if ( empty( $invoice ) ) { |
|
25 | +function wpinv_display_invoice_top_bar($invoice) { |
|
26 | + if (empty($invoice)) { |
|
27 | 27 | return; |
28 | 28 | } |
29 | 29 | ?> |
30 | 30 | <div class="row wpinv-top-bar no-print"> |
31 | 31 | <div class="container"> |
32 | 32 | <div class="col-xs-6"> |
33 | - <?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?> |
|
33 | + <?php do_action('wpinv_invoice_top_bar_left', $invoice); ?> |
|
34 | 34 | </div> |
35 | 35 | <div class="col-xs-6 text-right"> |
36 | - <?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?> |
|
36 | + <?php do_action('wpinv_invoice_top_bar_right', $invoice); ?> |
|
37 | 37 | </div> |
38 | 38 | </div> |
39 | 39 | </div> |
40 | 40 | <?php |
41 | 41 | } |
42 | 42 | |
43 | -function wpinv_invoice_display_left_actions( $invoice ) { |
|
44 | - if ( empty( $invoice ) ) { |
|
43 | +function wpinv_invoice_display_left_actions($invoice) { |
|
44 | + if (empty($invoice)) { |
|
45 | 45 | return; // Exit if invoice is not set. |
46 | 46 | } |
47 | 47 | |
48 | - if ( $invoice->post_type == 'wpi_invoice' ) { |
|
49 | - if ( $invoice->needs_payment() ) { |
|
50 | - ?> <a class="btn btn-success btn-sm" title="<?php esc_attr_e( 'Pay This Invoice', 'invoicing' ); ?>" href="<?php echo esc_url( $invoice->get_checkout_payment_url() ); ?>"><?php _e( 'Pay For Invoice', 'invoicing' ); ?></a><?php |
|
48 | + if ($invoice->post_type == 'wpi_invoice') { |
|
49 | + if ($invoice->needs_payment()) { |
|
50 | + ?> <a class="btn btn-success btn-sm" title="<?php esc_attr_e('Pay This Invoice', 'invoicing'); ?>" href="<?php echo esc_url($invoice->get_checkout_payment_url()); ?>"><?php _e('Pay For Invoice', 'invoicing'); ?></a><?php |
|
51 | 51 | } |
52 | 52 | } |
53 | 53 | do_action('wpinv_invoice_display_left_actions', $invoice); |
54 | 54 | } |
55 | 55 | |
56 | -function wpinv_invoice_display_right_actions( $invoice ) { |
|
57 | - if ( empty( $invoice ) ) { |
|
56 | +function wpinv_invoice_display_right_actions($invoice) { |
|
57 | + if (empty($invoice)) { |
|
58 | 58 | return; // Exit if invoice is not set. |
59 | 59 | } |
60 | 60 | |
61 | - if ( $invoice->post_type == 'wpi_invoice' ) { ?> |
|
62 | - <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a> |
|
63 | - <?php if ( is_user_logged_in() ) { ?> |
|
64 | - <a class="btn btn-warning btn-sm" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a> |
|
61 | + if ($invoice->post_type == 'wpi_invoice') { ?> |
|
62 | + <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a> |
|
63 | + <?php if (is_user_logged_in()) { ?> |
|
64 | + <a class="btn btn-warning btn-sm" href="<?php echo esc_url(wpinv_get_history_page_uri()); ?>"><?php _e('Invoice History', 'invoicing'); ?></a> |
|
65 | 65 | <?php } |
66 | 66 | } |
67 | 67 | do_action('wpinv_invoice_display_right_actions', $invoice); |
68 | 68 | } |
69 | 69 | |
70 | -function wpinv_before_invoice_content( $content ) { |
|
70 | +function wpinv_before_invoice_content($content) { |
|
71 | 71 | global $post; |
72 | 72 | |
73 | - if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) { |
|
73 | + if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) { |
|
74 | 74 | ob_start(); |
75 | - do_action( 'wpinv_before_invoice_content', $post->ID ); |
|
75 | + do_action('wpinv_before_invoice_content', $post->ID); |
|
76 | 76 | $content = ob_get_clean() . $content; |
77 | 77 | } |
78 | 78 | |
79 | 79 | return $content; |
80 | 80 | } |
81 | -add_filter( 'the_content', 'wpinv_before_invoice_content' ); |
|
81 | +add_filter('the_content', 'wpinv_before_invoice_content'); |
|
82 | 82 | |
83 | -function wpinv_after_invoice_content( $content ) { |
|
83 | +function wpinv_after_invoice_content($content) { |
|
84 | 84 | global $post; |
85 | 85 | |
86 | - if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) { |
|
86 | + if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) { |
|
87 | 87 | ob_start(); |
88 | - do_action( 'wpinv_after_invoice_content', $post->ID ); |
|
88 | + do_action('wpinv_after_invoice_content', $post->ID); |
|
89 | 89 | $content .= ob_get_clean(); |
90 | 90 | } |
91 | 91 | |
92 | 92 | return $content; |
93 | 93 | } |
94 | -add_filter( 'the_content', 'wpinv_after_invoice_content' ); |
|
94 | +add_filter('the_content', 'wpinv_after_invoice_content'); |
|
95 | 95 | |
96 | 96 | function wpinv_get_templates_dir() { |
97 | 97 | return WPINV_PLUGIN_DIR . 'templates'; |
@@ -101,105 +101,105 @@ discard block |
||
101 | 101 | return WPINV_PLUGIN_URL . 'templates'; |
102 | 102 | } |
103 | 103 | |
104 | -function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
105 | - if ( ! empty( $args ) && is_array( $args ) ) { |
|
106 | - extract( $args ); |
|
104 | +function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
105 | + if (!empty($args) && is_array($args)) { |
|
106 | + extract($args); |
|
107 | 107 | } |
108 | 108 | |
109 | - $located = wpinv_locate_template( $template_name, $template_path, $default_path ); |
|
109 | + $located = wpinv_locate_template($template_name, $template_path, $default_path); |
|
110 | 110 | // Allow 3rd party plugin filter template file from their plugin. |
111 | - $located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path ); |
|
111 | + $located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path); |
|
112 | 112 | |
113 | - if ( ! file_exists( $located ) ) { |
|
114 | - _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' ); |
|
113 | + if (!file_exists($located)) { |
|
114 | + _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1'); |
|
115 | 115 | return; |
116 | 116 | } |
117 | 117 | |
118 | - do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args ); |
|
118 | + do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args); |
|
119 | 119 | |
120 | - include( $located ); |
|
120 | + include($located); |
|
121 | 121 | |
122 | - do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args ); |
|
122 | + do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args); |
|
123 | 123 | } |
124 | 124 | |
125 | -function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
125 | +function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
126 | 126 | ob_start(); |
127 | - wpinv_get_template( $template_name, $args, $template_path, $default_path ); |
|
127 | + wpinv_get_template($template_name, $args, $template_path, $default_path); |
|
128 | 128 | return ob_get_clean(); |
129 | 129 | } |
130 | 130 | |
131 | -function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
132 | - if ( ! $template_path ) { |
|
131 | +function wpinv_locate_template($template_name, $template_path = '', $default_path = '') { |
|
132 | + if (!$template_path) { |
|
133 | 133 | $template_path = wpinv_template_path(); |
134 | 134 | } |
135 | 135 | |
136 | - if ( ! $default_path ) { |
|
136 | + if (!$default_path) { |
|
137 | 137 | $default_path = WPINV_PLUGIN_DIR . 'templates/'; |
138 | 138 | } |
139 | 139 | |
140 | 140 | // Look within passed path within the theme - this is priority. |
141 | 141 | $template = locate_template( |
142 | 142 | array( |
143 | - trailingslashit( $template_path ) . $template_name, |
|
143 | + trailingslashit($template_path) . $template_name, |
|
144 | 144 | $template_name |
145 | 145 | ) |
146 | 146 | ); |
147 | 147 | |
148 | 148 | // Get default templates/ |
149 | - if ( !$template && $default_path ) { |
|
150 | - $template = trailingslashit( $default_path ) . $template_name; |
|
149 | + if (!$template && $default_path) { |
|
150 | + $template = trailingslashit($default_path) . $template_name; |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | // Return what we found. |
154 | - return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path ); |
|
154 | + return apply_filters('wpinv_locate_template', $template, $template_name, $template_path); |
|
155 | 155 | } |
156 | 156 | |
157 | -function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
|
158 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
157 | +function wpinv_get_template_part($slug, $name = null, $load = true) { |
|
158 | + do_action('get_template_part_' . $slug, $slug, $name); |
|
159 | 159 | |
160 | 160 | // Setup possible parts |
161 | 161 | $templates = array(); |
162 | - if ( isset( $name ) ) |
|
162 | + if (isset($name)) |
|
163 | 163 | $templates[] = $slug . '-' . $name . '.php'; |
164 | 164 | $templates[] = $slug . '.php'; |
165 | 165 | |
166 | 166 | // Allow template parts to be filtered |
167 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
167 | + $templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name); |
|
168 | 168 | |
169 | 169 | // Return the part that is found |
170 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
170 | + return wpinv_locate_tmpl($templates, $load, false); |
|
171 | 171 | } |
172 | 172 | |
173 | -function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
|
173 | +function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) { |
|
174 | 174 | // No file found yet |
175 | 175 | $located = false; |
176 | 176 | |
177 | 177 | // Try to find a template file |
178 | - foreach ( (array)$template_names as $template_name ) { |
|
178 | + foreach ((array)$template_names as $template_name) { |
|
179 | 179 | |
180 | 180 | // Continue if template is empty |
181 | - if ( empty( $template_name ) ) |
|
181 | + if (empty($template_name)) |
|
182 | 182 | continue; |
183 | 183 | |
184 | 184 | // Trim off any slashes from the template name |
185 | - $template_name = ltrim( $template_name, '/' ); |
|
185 | + $template_name = ltrim($template_name, '/'); |
|
186 | 186 | |
187 | 187 | // try locating this template file by looping through the template paths |
188 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
188 | + foreach (wpinv_get_theme_template_paths() as $template_path) { |
|
189 | 189 | |
190 | - if( file_exists( $template_path . $template_name ) ) { |
|
190 | + if (file_exists($template_path . $template_name)) { |
|
191 | 191 | $located = $template_path . $template_name; |
192 | 192 | break; |
193 | 193 | } |
194 | 194 | } |
195 | 195 | |
196 | - if( !empty( $located ) ) { |
|
196 | + if (!empty($located)) { |
|
197 | 197 | break; |
198 | 198 | } |
199 | 199 | } |
200 | 200 | |
201 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
202 | - load_template( $located, $require_once ); |
|
201 | + if ((true == $load) && !empty($located)) |
|
202 | + load_template($located, $require_once); |
|
203 | 203 | |
204 | 204 | return $located; |
205 | 205 | } |
@@ -208,149 +208,149 @@ discard block |
||
208 | 208 | $template_dir = wpinv_get_theme_template_dir_name(); |
209 | 209 | |
210 | 210 | $file_paths = array( |
211 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
212 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
211 | + 1 => trailingslashit(get_stylesheet_directory()) . $template_dir, |
|
212 | + 10 => trailingslashit(get_template_directory()) . $template_dir, |
|
213 | 213 | 100 => wpinv_get_templates_dir() |
214 | 214 | ); |
215 | 215 | |
216 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
216 | + $file_paths = apply_filters('wpinv_template_paths', $file_paths); |
|
217 | 217 | |
218 | 218 | // sort the file paths based on priority |
219 | - ksort( $file_paths, SORT_NUMERIC ); |
|
219 | + ksort($file_paths, SORT_NUMERIC); |
|
220 | 220 | |
221 | - return array_map( 'trailingslashit', $file_paths ); |
|
221 | + return array_map('trailingslashit', $file_paths); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | function wpinv_get_theme_template_dir_name() { |
225 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
225 | + return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing')); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | function wpinv_checkout_meta_tags() { |
229 | 229 | |
230 | 230 | $pages = array(); |
231 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
232 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
233 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
234 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
231 | + $pages[] = wpinv_get_option('success_page'); |
|
232 | + $pages[] = wpinv_get_option('failure_page'); |
|
233 | + $pages[] = wpinv_get_option('invoice_history_page'); |
|
234 | + $pages[] = wpinv_get_option('invoice_subscription_page'); |
|
235 | 235 | |
236 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
236 | + if (!wpinv_is_checkout() && !is_page($pages)) { |
|
237 | 237 | return; |
238 | 238 | } |
239 | 239 | |
240 | 240 | echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
241 | 241 | } |
242 | -add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
|
242 | +add_action('wp_head', 'wpinv_checkout_meta_tags'); |
|
243 | 243 | |
244 | -function wpinv_add_body_classes( $class ) { |
|
244 | +function wpinv_add_body_classes($class) { |
|
245 | 245 | $classes = (array)$class; |
246 | 246 | |
247 | - if( wpinv_is_checkout() ) { |
|
247 | + if (wpinv_is_checkout()) { |
|
248 | 248 | $classes[] = 'wpinv-checkout'; |
249 | 249 | $classes[] = 'wpinv-page'; |
250 | 250 | } |
251 | 251 | |
252 | - if( wpinv_is_success_page() ) { |
|
252 | + if (wpinv_is_success_page()) { |
|
253 | 253 | $classes[] = 'wpinv-success'; |
254 | 254 | $classes[] = 'wpinv-page'; |
255 | 255 | } |
256 | 256 | |
257 | - if( wpinv_is_failed_transaction_page() ) { |
|
257 | + if (wpinv_is_failed_transaction_page()) { |
|
258 | 258 | $classes[] = 'wpinv-failed-transaction'; |
259 | 259 | $classes[] = 'wpinv-page'; |
260 | 260 | } |
261 | 261 | |
262 | - if( wpinv_is_invoice_history_page() ) { |
|
262 | + if (wpinv_is_invoice_history_page()) { |
|
263 | 263 | $classes[] = 'wpinv-history'; |
264 | 264 | $classes[] = 'wpinv-page'; |
265 | 265 | } |
266 | 266 | |
267 | - if( wpinv_is_subscriptions_history_page() ) { |
|
267 | + if (wpinv_is_subscriptions_history_page()) { |
|
268 | 268 | $classes[] = 'wpinv-subscription'; |
269 | 269 | $classes[] = 'wpinv-page'; |
270 | 270 | } |
271 | 271 | |
272 | - if( wpinv_is_test_mode() ) { |
|
272 | + if (wpinv_is_test_mode()) { |
|
273 | 273 | $classes[] = 'wpinv-test-mode'; |
274 | 274 | $classes[] = 'wpinv-page'; |
275 | 275 | } |
276 | 276 | |
277 | - return array_unique( $classes ); |
|
277 | + return array_unique($classes); |
|
278 | 278 | } |
279 | -add_filter( 'body_class', 'wpinv_add_body_classes' ); |
|
279 | +add_filter('body_class', 'wpinv_add_body_classes'); |
|
280 | 280 | |
281 | -function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) { |
|
282 | - $args = array( 'nopaging' => true ); |
|
281 | +function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') { |
|
282 | + $args = array('nopaging' => true); |
|
283 | 283 | |
284 | - if ( ! empty( $status ) ) |
|
284 | + if (!empty($status)) |
|
285 | 285 | $args['post_status'] = $status; |
286 | 286 | |
287 | - $discounts = wpinv_get_discounts( $args ); |
|
287 | + $discounts = wpinv_get_discounts($args); |
|
288 | 288 | $options = array(); |
289 | 289 | |
290 | - if ( $discounts ) { |
|
291 | - foreach ( $discounts as $discount ) { |
|
292 | - $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) ); |
|
290 | + if ($discounts) { |
|
291 | + foreach ($discounts as $discount) { |
|
292 | + $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID)); |
|
293 | 293 | } |
294 | 294 | } else { |
295 | - $options[0] = __( 'No discounts found', 'invoicing' ); |
|
295 | + $options[0] = __('No discounts found', 'invoicing'); |
|
296 | 296 | } |
297 | 297 | |
298 | - $output = wpinv_html_select( array( |
|
298 | + $output = wpinv_html_select(array( |
|
299 | 299 | 'name' => $name, |
300 | 300 | 'selected' => $selected, |
301 | 301 | 'options' => $options, |
302 | 302 | 'show_option_all' => false, |
303 | 303 | 'show_option_none' => false, |
304 | - ) ); |
|
304 | + )); |
|
305 | 305 | |
306 | 306 | return $output; |
307 | 307 | } |
308 | 308 | |
309 | -function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) { |
|
310 | - $current = date( 'Y' ); |
|
311 | - $start_year = $current - absint( $years_before ); |
|
312 | - $end_year = $current + absint( $years_after ); |
|
313 | - $selected = empty( $selected ) ? date( 'Y' ) : $selected; |
|
309 | +function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) { |
|
310 | + $current = date('Y'); |
|
311 | + $start_year = $current - absint($years_before); |
|
312 | + $end_year = $current + absint($years_after); |
|
313 | + $selected = empty($selected) ? date('Y') : $selected; |
|
314 | 314 | $options = array(); |
315 | 315 | |
316 | - while ( $start_year <= $end_year ) { |
|
317 | - $options[ absint( $start_year ) ] = $start_year; |
|
316 | + while ($start_year <= $end_year) { |
|
317 | + $options[absint($start_year)] = $start_year; |
|
318 | 318 | $start_year++; |
319 | 319 | } |
320 | 320 | |
321 | - $output = wpinv_html_select( array( |
|
321 | + $output = wpinv_html_select(array( |
|
322 | 322 | 'name' => $name, |
323 | 323 | 'selected' => $selected, |
324 | 324 | 'options' => $options, |
325 | 325 | 'show_option_all' => false, |
326 | 326 | 'show_option_none' => false |
327 | - ) ); |
|
327 | + )); |
|
328 | 328 | |
329 | 329 | return $output; |
330 | 330 | } |
331 | 331 | |
332 | -function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) { |
|
332 | +function wpinv_html_month_dropdown($name = 'month', $selected = 0) { |
|
333 | 333 | $month = 1; |
334 | 334 | $options = array(); |
335 | - $selected = empty( $selected ) ? date( 'n' ) : $selected; |
|
335 | + $selected = empty($selected) ? date('n') : $selected; |
|
336 | 336 | |
337 | - while ( $month <= 12 ) { |
|
338 | - $options[ absint( $month ) ] = wpinv_month_num_to_name( $month ); |
|
337 | + while ($month <= 12) { |
|
338 | + $options[absint($month)] = wpinv_month_num_to_name($month); |
|
339 | 339 | $month++; |
340 | 340 | } |
341 | 341 | |
342 | - $output = wpinv_html_select( array( |
|
342 | + $output = wpinv_html_select(array( |
|
343 | 343 | 'name' => $name, |
344 | 344 | 'selected' => $selected, |
345 | 345 | 'options' => $options, |
346 | 346 | 'show_option_all' => false, |
347 | 347 | 'show_option_none' => false |
348 | - ) ); |
|
348 | + )); |
|
349 | 349 | |
350 | 350 | return $output; |
351 | 351 | } |
352 | 352 | |
353 | -function wpinv_html_select( $args = array() ) { |
|
353 | +function wpinv_html_select($args = array()) { |
|
354 | 354 | $defaults = array( |
355 | 355 | 'options' => array(), |
356 | 356 | 'name' => null, |
@@ -359,8 +359,8 @@ discard block |
||
359 | 359 | 'selected' => 0, |
360 | 360 | 'placeholder' => null, |
361 | 361 | 'multiple' => false, |
362 | - 'show_option_all' => _x( 'All', 'all dropdown items', 'invoicing' ), |
|
363 | - 'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ), |
|
362 | + 'show_option_all' => _x('All', 'all dropdown items', 'invoicing'), |
|
363 | + 'show_option_none' => _x('None', 'no dropdown items', 'invoicing'), |
|
364 | 364 | 'data' => array(), |
365 | 365 | 'onchange' => null, |
366 | 366 | 'required' => false, |
@@ -368,74 +368,74 @@ discard block |
||
368 | 368 | 'readonly' => false, |
369 | 369 | ); |
370 | 370 | |
371 | - $args = wp_parse_args( $args, $defaults ); |
|
371 | + $args = wp_parse_args($args, $defaults); |
|
372 | 372 | |
373 | 373 | $data_elements = ''; |
374 | - foreach ( $args['data'] as $key => $value ) { |
|
375 | - $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
374 | + foreach ($args['data'] as $key => $value) { |
|
375 | + $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"'; |
|
376 | 376 | } |
377 | 377 | |
378 | - if( $args['multiple'] ) { |
|
378 | + if ($args['multiple']) { |
|
379 | 379 | $multiple = ' MULTIPLE'; |
380 | 380 | } else { |
381 | 381 | $multiple = ''; |
382 | 382 | } |
383 | 383 | |
384 | - if( $args['placeholder'] ) { |
|
384 | + if ($args['placeholder']) { |
|
385 | 385 | $placeholder = $args['placeholder']; |
386 | 386 | } else { |
387 | 387 | $placeholder = ''; |
388 | 388 | } |
389 | 389 | |
390 | 390 | $options = ''; |
391 | - if( !empty( $args['onchange'] ) ) { |
|
392 | - $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
391 | + if (!empty($args['onchange'])) { |
|
392 | + $options .= ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
393 | 393 | } |
394 | 394 | |
395 | - if( !empty( $args['required'] ) ) { |
|
395 | + if (!empty($args['required'])) { |
|
396 | 396 | $options .= ' required="required"'; |
397 | 397 | } |
398 | 398 | |
399 | - if( !empty( $args['disabled'] ) ) { |
|
399 | + if (!empty($args['disabled'])) { |
|
400 | 400 | $options .= ' disabled'; |
401 | 401 | } |
402 | 402 | |
403 | - if( !empty( $args['readonly'] ) ) { |
|
403 | + if (!empty($args['readonly'])) { |
|
404 | 404 | $options .= ' readonly'; |
405 | 405 | } |
406 | 406 | |
407 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
408 | - $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>'; |
|
407 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
408 | + $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>'; |
|
409 | 409 | |
410 | - if ( $args['show_option_all'] ) { |
|
411 | - if( $args['multiple'] ) { |
|
412 | - $selected = selected( true, in_array( 0, $args['selected'] ), false ); |
|
410 | + if ($args['show_option_all']) { |
|
411 | + if ($args['multiple']) { |
|
412 | + $selected = selected(true, in_array(0, $args['selected']), false); |
|
413 | 413 | } else { |
414 | - $selected = selected( $args['selected'], 0, false ); |
|
414 | + $selected = selected($args['selected'], 0, false); |
|
415 | 415 | } |
416 | - $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
416 | + $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>'; |
|
417 | 417 | } |
418 | 418 | |
419 | - if ( !empty( $args['options'] ) ) { |
|
419 | + if (!empty($args['options'])) { |
|
420 | 420 | |
421 | - if ( $args['show_option_none'] ) { |
|
422 | - if( $args['multiple'] ) { |
|
423 | - $selected = selected( true, in_array( "", $args['selected'] ), false ); |
|
421 | + if ($args['show_option_none']) { |
|
422 | + if ($args['multiple']) { |
|
423 | + $selected = selected(true, in_array("", $args['selected']), false); |
|
424 | 424 | } else { |
425 | - $selected = selected( $args['selected'] === "", true, false ); |
|
425 | + $selected = selected($args['selected'] === "", true, false); |
|
426 | 426 | } |
427 | - $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
427 | + $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>'; |
|
428 | 428 | } |
429 | 429 | |
430 | - foreach( $args['options'] as $key => $option ) { |
|
430 | + foreach ($args['options'] as $key => $option) { |
|
431 | 431 | |
432 | - if( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
433 | - $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false ); |
|
432 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
433 | + $selected = selected(true, (bool)in_array($key, $args['selected']), false); |
|
434 | 434 | } else { |
435 | - $selected = selected( $args['selected'], $key, false ); |
|
435 | + $selected = selected($args['selected'], $key, false); |
|
436 | 436 | } |
437 | 437 | |
438 | - $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>'; |
|
438 | + $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>'; |
|
439 | 439 | } |
440 | 440 | } |
441 | 441 | |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | return $output; |
445 | 445 | } |
446 | 446 | |
447 | -function wpinv_item_dropdown( $args = array() ) { |
|
447 | +function wpinv_item_dropdown($args = array()) { |
|
448 | 448 | $defaults = array( |
449 | 449 | 'name' => 'wpi_item', |
450 | 450 | 'id' => 'wpi_item', |
@@ -452,14 +452,14 @@ discard block |
||
452 | 452 | 'multiple' => false, |
453 | 453 | 'selected' => 0, |
454 | 454 | 'number' => 100, |
455 | - 'placeholder' => __( 'Choose a item', 'invoicing' ), |
|
456 | - 'data' => array( 'search-type' => 'item' ), |
|
455 | + 'placeholder' => __('Choose a item', 'invoicing'), |
|
456 | + 'data' => array('search-type' => 'item'), |
|
457 | 457 | 'show_option_all' => false, |
458 | 458 | 'show_option_none' => false, |
459 | 459 | 'show_recurring' => false, |
460 | 460 | ); |
461 | 461 | |
462 | - $args = wp_parse_args( $args, $defaults ); |
|
462 | + $args = wp_parse_args($args, $defaults); |
|
463 | 463 | |
464 | 464 | $item_args = array( |
465 | 465 | 'post_type' => 'wpi_item', |
@@ -468,44 +468,44 @@ discard block |
||
468 | 468 | 'posts_per_page' => $args['number'] |
469 | 469 | ); |
470 | 470 | |
471 | - $item_args = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults ); |
|
471 | + $item_args = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults); |
|
472 | 472 | |
473 | - $items = get_posts( $item_args ); |
|
473 | + $items = get_posts($item_args); |
|
474 | 474 | $options = array(); |
475 | - if ( $items ) { |
|
476 | - foreach ( $items as $item ) { |
|
477 | - $title = esc_html( $item->post_title ); |
|
475 | + if ($items) { |
|
476 | + foreach ($items as $item) { |
|
477 | + $title = esc_html($item->post_title); |
|
478 | 478 | |
479 | - if ( !empty( $args['show_recurring'] ) ) { |
|
480 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
479 | + if (!empty($args['show_recurring'])) { |
|
480 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
481 | 481 | } |
482 | 482 | |
483 | - $options[ absint( $item->ID ) ] = $title; |
|
483 | + $options[absint($item->ID)] = $title; |
|
484 | 484 | } |
485 | 485 | } |
486 | 486 | |
487 | 487 | // This ensures that any selected items are included in the drop down |
488 | - if( is_array( $args['selected'] ) ) { |
|
489 | - foreach( $args['selected'] as $item ) { |
|
490 | - if( ! in_array( $item, $options ) ) { |
|
491 | - $title = get_the_title( $item ); |
|
492 | - if ( !empty( $args['show_recurring'] ) ) { |
|
493 | - $title .= wpinv_get_item_suffix( $item, false ); |
|
488 | + if (is_array($args['selected'])) { |
|
489 | + foreach ($args['selected'] as $item) { |
|
490 | + if (!in_array($item, $options)) { |
|
491 | + $title = get_the_title($item); |
|
492 | + if (!empty($args['show_recurring'])) { |
|
493 | + $title .= wpinv_get_item_suffix($item, false); |
|
494 | 494 | } |
495 | 495 | $options[$item] = $title; |
496 | 496 | } |
497 | 497 | } |
498 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
499 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
500 | - $title = get_the_title( $args['selected'] ); |
|
501 | - if ( !empty( $args['show_recurring'] ) ) { |
|
502 | - $title .= wpinv_get_item_suffix( $args['selected'], false ); |
|
498 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
499 | + if (!in_array($args['selected'], $options)) { |
|
500 | + $title = get_the_title($args['selected']); |
|
501 | + if (!empty($args['show_recurring'])) { |
|
502 | + $title .= wpinv_get_item_suffix($args['selected'], false); |
|
503 | 503 | } |
504 | - $options[$args['selected']] = get_the_title( $args['selected'] ); |
|
504 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
505 | 505 | } |
506 | 506 | } |
507 | 507 | |
508 | - $output = wpinv_html_select( array( |
|
508 | + $output = wpinv_html_select(array( |
|
509 | 509 | 'name' => $args['name'], |
510 | 510 | 'selected' => $args['selected'], |
511 | 511 | 'id' => $args['id'], |
@@ -516,12 +516,12 @@ discard block |
||
516 | 516 | 'show_option_all' => $args['show_option_all'], |
517 | 517 | 'show_option_none' => $args['show_option_none'], |
518 | 518 | 'data' => $args['data'], |
519 | - ) ); |
|
519 | + )); |
|
520 | 520 | |
521 | 521 | return $output; |
522 | 522 | } |
523 | 523 | |
524 | -function wpinv_html_checkbox( $args = array() ) { |
|
524 | +function wpinv_html_checkbox($args = array()) { |
|
525 | 525 | $defaults = array( |
526 | 526 | 'name' => null, |
527 | 527 | 'current' => null, |
@@ -532,38 +532,38 @@ discard block |
||
532 | 532 | ) |
533 | 533 | ); |
534 | 534 | |
535 | - $args = wp_parse_args( $args, $defaults ); |
|
535 | + $args = wp_parse_args($args, $defaults); |
|
536 | 536 | |
537 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
537 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
538 | 538 | $options = ''; |
539 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
539 | + if (!empty($args['options']['disabled'])) { |
|
540 | 540 | $options .= ' disabled="disabled"'; |
541 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
541 | + } elseif (!empty($args['options']['readonly'])) { |
|
542 | 542 | $options .= ' readonly'; |
543 | 543 | } |
544 | 544 | |
545 | - $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />'; |
|
545 | + $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />'; |
|
546 | 546 | |
547 | 547 | return $output; |
548 | 548 | } |
549 | 549 | |
550 | -function wpinv_html_text( $args = array() ) { |
|
550 | +function wpinv_html_text($args = array()) { |
|
551 | 551 | // Backwards compatibility |
552 | - if ( func_num_args() > 1 ) { |
|
552 | + if (func_num_args() > 1) { |
|
553 | 553 | $args = func_get_args(); |
554 | 554 | |
555 | 555 | $name = $args[0]; |
556 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
557 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
558 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
556 | + $value = isset($args[1]) ? $args[1] : ''; |
|
557 | + $label = isset($args[2]) ? $args[2] : ''; |
|
558 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
559 | 559 | } |
560 | 560 | |
561 | 561 | $defaults = array( |
562 | 562 | 'id' => '', |
563 | - 'name' => isset( $name ) ? $name : 'text', |
|
564 | - 'value' => isset( $value ) ? $value : null, |
|
565 | - 'label' => isset( $label ) ? $label : null, |
|
566 | - 'desc' => isset( $desc ) ? $desc : null, |
|
563 | + 'name' => isset($name) ? $name : 'text', |
|
564 | + 'value' => isset($value) ? $value : null, |
|
565 | + 'label' => isset($label) ? $label : null, |
|
566 | + 'desc' => isset($desc) ? $desc : null, |
|
567 | 567 | 'placeholder' => '', |
568 | 568 | 'class' => 'regular-text', |
569 | 569 | 'disabled' => false, |
@@ -573,51 +573,51 @@ discard block |
||
573 | 573 | 'data' => false |
574 | 574 | ); |
575 | 575 | |
576 | - $args = wp_parse_args( $args, $defaults ); |
|
576 | + $args = wp_parse_args($args, $defaults); |
|
577 | 577 | |
578 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
578 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
579 | 579 | $options = ''; |
580 | - if( $args['required'] ) { |
|
580 | + if ($args['required']) { |
|
581 | 581 | $options .= ' required="required"'; |
582 | 582 | } |
583 | - if( $args['readonly'] ) { |
|
583 | + if ($args['readonly']) { |
|
584 | 584 | $options .= ' readonly'; |
585 | 585 | } |
586 | - if( $args['readonly'] ) { |
|
586 | + if ($args['readonly']) { |
|
587 | 587 | $options .= ' readonly'; |
588 | 588 | } |
589 | 589 | |
590 | 590 | $data = ''; |
591 | - if ( !empty( $args['data'] ) ) { |
|
592 | - foreach ( $args['data'] as $key => $value ) { |
|
593 | - $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" '; |
|
591 | + if (!empty($args['data'])) { |
|
592 | + foreach ($args['data'] as $key => $value) { |
|
593 | + $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" '; |
|
594 | 594 | } |
595 | 595 | } |
596 | 596 | |
597 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
598 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
599 | - if ( ! empty( $args['desc'] ) ) { |
|
600 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
597 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
598 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>'; |
|
599 | + if (!empty($args['desc'])) { |
|
600 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
601 | 601 | } |
602 | 602 | |
603 | - $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>'; |
|
603 | + $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>'; |
|
604 | 604 | |
605 | 605 | $output .= '</span>'; |
606 | 606 | |
607 | 607 | return $output; |
608 | 608 | } |
609 | 609 | |
610 | -function wpinv_html_date_field( $args = array() ) { |
|
611 | - if( empty( $args['class'] ) ) { |
|
610 | +function wpinv_html_date_field($args = array()) { |
|
611 | + if (empty($args['class'])) { |
|
612 | 612 | $args['class'] = 'wpiDatepicker'; |
613 | - } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) { |
|
613 | + } elseif (!strpos($args['class'], 'wpiDatepicker')) { |
|
614 | 614 | $args['class'] .= ' wpiDatepicker'; |
615 | 615 | } |
616 | 616 | |
617 | - return wpinv_html_text( $args ); |
|
617 | + return wpinv_html_text($args); |
|
618 | 618 | } |
619 | 619 | |
620 | -function wpinv_html_textarea( $args = array() ) { |
|
620 | +function wpinv_html_textarea($args = array()) { |
|
621 | 621 | $defaults = array( |
622 | 622 | 'name' => 'textarea', |
623 | 623 | 'value' => null, |
@@ -627,31 +627,31 @@ discard block |
||
627 | 627 | 'disabled' => false |
628 | 628 | ); |
629 | 629 | |
630 | - $args = wp_parse_args( $args, $defaults ); |
|
630 | + $args = wp_parse_args($args, $defaults); |
|
631 | 631 | |
632 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
632 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
633 | 633 | $disabled = ''; |
634 | - if( $args['disabled'] ) { |
|
634 | + if ($args['disabled']) { |
|
635 | 635 | $disabled = ' disabled="disabled"'; |
636 | 636 | } |
637 | 637 | |
638 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
639 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
640 | - $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
638 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
639 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>'; |
|
640 | + $output .= '<textarea name="' . esc_attr($args['name']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>'; |
|
641 | 641 | |
642 | - if ( ! empty( $args['desc'] ) ) { |
|
643 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
642 | + if (!empty($args['desc'])) { |
|
643 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
644 | 644 | } |
645 | 645 | $output .= '</span>'; |
646 | 646 | |
647 | 647 | return $output; |
648 | 648 | } |
649 | 649 | |
650 | -function wpinv_html_ajax_user_search( $args = array() ) { |
|
650 | +function wpinv_html_ajax_user_search($args = array()) { |
|
651 | 651 | $defaults = array( |
652 | 652 | 'name' => 'user_id', |
653 | 653 | 'value' => null, |
654 | - 'placeholder' => __( 'Enter username', 'invoicing' ), |
|
654 | + 'placeholder' => __('Enter username', 'invoicing'), |
|
655 | 655 | 'label' => null, |
656 | 656 | 'desc' => null, |
657 | 657 | 'class' => '', |
@@ -660,13 +660,13 @@ discard block |
||
660 | 660 | 'data' => false |
661 | 661 | ); |
662 | 662 | |
663 | - $args = wp_parse_args( $args, $defaults ); |
|
663 | + $args = wp_parse_args($args, $defaults); |
|
664 | 664 | |
665 | 665 | $args['class'] = 'wpinv-ajax-user-search ' . $args['class']; |
666 | 666 | |
667 | 667 | $output = '<span class="wpinv_user_search_wrap">'; |
668 | - $output .= wpinv_html_text( $args ); |
|
669 | - $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>'; |
|
668 | + $output .= wpinv_html_text($args); |
|
669 | + $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>'; |
|
670 | 670 | $output .= '</span>'; |
671 | 671 | |
672 | 672 | return $output; |
@@ -675,7 +675,7 @@ discard block |
||
675 | 675 | function wpinv_ip_geolocation() { |
676 | 676 | global $wpinv_euvat; |
677 | 677 | |
678 | - $ip = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : ''; |
|
678 | + $ip = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : ''; |
|
679 | 679 | $content = ''; |
680 | 680 | $iso = ''; |
681 | 681 | $country = ''; |
@@ -686,69 +686,69 @@ discard block |
||
686 | 686 | $credit = ''; |
687 | 687 | $address = ''; |
688 | 688 | |
689 | - if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) { |
|
689 | + if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) { |
|
690 | 690 | try { |
691 | 691 | $iso = $geoip2_city->country->isoCode; |
692 | 692 | $country = $geoip2_city->country->name; |
693 | - $region = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : ''; |
|
693 | + $region = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : ''; |
|
694 | 694 | $city = $geoip2_city->city->name; |
695 | 695 | $longitude = $geoip2_city->location->longitude; |
696 | 696 | $latitude = $geoip2_city->location->latitude; |
697 | - $credit = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' ); |
|
698 | - } catch( Exception $e ) { } |
|
697 | + $credit = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing'); |
|
698 | + } catch (Exception $e) { } |
|
699 | 699 | } |
700 | 700 | |
701 | - if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) { |
|
701 | + if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) { |
|
702 | 702 | try { |
703 | - $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip ); |
|
703 | + $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip); |
|
704 | 704 | |
705 | - if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) { |
|
705 | + if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) { |
|
706 | 706 | $iso = $load_xml->geoplugin_countryCode; |
707 | 707 | $country = $load_xml->geoplugin_countryName; |
708 | - $region = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : ''; |
|
709 | - $city = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : ''; |
|
708 | + $region = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : ''; |
|
709 | + $city = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : ''; |
|
710 | 710 | $longitude = $load_xml->geoplugin_longitude; |
711 | 711 | $latitude = $load_xml->geoplugin_latitude; |
712 | 712 | $credit = $load_xml->geoplugin_credit; |
713 | - $credit = __( 'Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing' ) . '<br>' . $load_xml->geoplugin_credit; |
|
713 | + $credit = __('Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing') . '<br>' . $load_xml->geoplugin_credit; |
|
714 | 714 | } |
715 | - } catch( Exception $e ) { } |
|
715 | + } catch (Exception $e) { } |
|
716 | 716 | } |
717 | 717 | |
718 | - if ( $iso && $longitude && $latitude ) { |
|
719 | - if ( $city ) { |
|
718 | + if ($iso && $longitude && $latitude) { |
|
719 | + if ($city) { |
|
720 | 720 | $address .= $city . ', '; |
721 | 721 | } |
722 | 722 | |
723 | - if ( $region ) { |
|
723 | + if ($region) { |
|
724 | 724 | $address .= $region . ', '; |
725 | 725 | } |
726 | 726 | |
727 | 727 | $address .= $country . ' (' . $iso . ')'; |
728 | - $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>'; |
|
729 | - $content .= '<p>'. $credit . '</p>'; |
|
728 | + $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>'; |
|
729 | + $content .= '<p>' . $credit . '</p>'; |
|
730 | 730 | } else { |
731 | - $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>'; |
|
731 | + $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>'; |
|
732 | 732 | } |
733 | 733 | ?> |
734 | 734 | <!DOCTYPE html> |
735 | -<html><head><title><?php echo sprintf( __( 'IP: %s', 'invoicing' ), $ip );?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head> |
|
735 | +<html><head><title><?php echo sprintf(__('IP: %s', 'invoicing'), $ip); ?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head> |
|
736 | 736 | <body> |
737 | - <?php if ( $latitude && $latitude ) { ?> |
|
737 | + <?php if ($latitude && $latitude) { ?> |
|
738 | 738 | <div id="map"></div> |
739 | 739 | <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script> |
740 | 740 | <script type="text/javascript"> |
741 | 741 | var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', |
742 | 742 | osmAttrib = '© <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors', |
743 | 743 | osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}), |
744 | - latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>); |
|
744 | + latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>); |
|
745 | 745 | |
746 | 746 | var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]}); |
747 | 747 | |
748 | 748 | var marker = new L.Marker(latlng); |
749 | 749 | map.addLayer(marker); |
750 | 750 | |
751 | - marker.bindPopup("<p><?php esc_attr_e( $address );?></p>"); |
|
751 | + marker.bindPopup("<p><?php esc_attr_e($address); ?></p>"); |
|
752 | 752 | </script> |
753 | 753 | <?php } ?> |
754 | 754 | <div style="height:100px"><?php echo $content; ?></div> |
@@ -756,18 +756,18 @@ discard block |
||
756 | 756 | <?php |
757 | 757 | exit; |
758 | 758 | } |
759 | -add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' ); |
|
760 | -add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' ); |
|
759 | +add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation'); |
|
760 | +add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation'); |
|
761 | 761 | |
762 | 762 | // Set up the template for the invoice. |
763 | -function wpinv_template( $template ) { |
|
763 | +function wpinv_template($template) { |
|
764 | 764 | global $post, $wp_query; |
765 | 765 | |
766 | - if ( ( is_single() || is_404() ) && !empty( $post->ID ) && (get_post_type( $post->ID ) == 'wpi_invoice' or get_post_type( $post->ID ) == 'wpi_quote')) { |
|
767 | - if ( wpinv_user_can_view_invoice( $post->ID ) ) { |
|
768 | - $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false ); |
|
766 | + if ((is_single() || is_404()) && !empty($post->ID) && (get_post_type($post->ID) == 'wpi_invoice' or get_post_type($post->ID) == 'wpi_quote')) { |
|
767 | + if (wpinv_user_can_view_invoice($post->ID)) { |
|
768 | + $template = wpinv_get_template_part('wpinv-invoice-print', false, false); |
|
769 | 769 | } else { |
770 | - $template = wpinv_get_template_part( 'wpinv-invalid-access', false, false ); |
|
770 | + $template = wpinv_get_template_part('wpinv-invalid-access', false, false); |
|
771 | 771 | } |
772 | 772 | } |
773 | 773 | |
@@ -776,7 +776,7 @@ discard block |
||
776 | 776 | |
777 | 777 | function wpinv_get_business_address() { |
778 | 778 | $business_address = wpinv_store_address(); |
779 | - $business_address = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : ''; |
|
779 | + $business_address = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : ''; |
|
780 | 780 | |
781 | 781 | /* |
782 | 782 | $default_country = wpinv_get_default_country(); |
@@ -800,7 +800,7 @@ discard block |
||
800 | 800 | |
801 | 801 | $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : ''; |
802 | 802 | |
803 | - return apply_filters( 'wpinv_get_business_address', $business_address ); |
|
803 | + return apply_filters('wpinv_get_business_address', $business_address); |
|
804 | 804 | } |
805 | 805 | |
806 | 806 | function wpinv_display_from_address() { |
@@ -810,192 +810,192 @@ discard block |
||
810 | 810 | if (empty($from_name)) { |
811 | 811 | $from_name = wpinv_get_business_name(); |
812 | 812 | } |
813 | - ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div> |
|
813 | + ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div> |
|
814 | 814 | <div class="wrapper col-xs-10"> |
815 | - <div class="name"><?php echo esc_html( $from_name ); ?></div> |
|
816 | - <?php if ( $address = wpinv_get_business_address() ) { ?> |
|
817 | - <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div> |
|
815 | + <div class="name"><?php echo esc_html($from_name); ?></div> |
|
816 | + <?php if ($address = wpinv_get_business_address()) { ?> |
|
817 | + <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div> |
|
818 | 818 | <?php } ?> |
819 | - <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?> |
|
820 | - <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s', 'invoicing' ), $email_from );?></div> |
|
819 | + <?php if ($email_from = wpinv_mail_get_from_address()) { ?> |
|
820 | + <div class="email_from"><?php echo wp_sprintf(__('Email: %s', 'invoicing'), $email_from); ?></div> |
|
821 | 821 | <?php } ?> |
822 | 822 | </div> |
823 | 823 | <?php |
824 | 824 | } |
825 | 825 | |
826 | -function wpinv_watermark( $id = 0 ) { |
|
827 | - $output = wpinv_get_watermark( $id ); |
|
826 | +function wpinv_watermark($id = 0) { |
|
827 | + $output = wpinv_get_watermark($id); |
|
828 | 828 | |
829 | - return apply_filters( 'wpinv_get_watermark', $output, $id ); |
|
829 | + return apply_filters('wpinv_get_watermark', $output, $id); |
|
830 | 830 | } |
831 | 831 | |
832 | -function wpinv_get_watermark( $id ) { |
|
833 | - if ( !$id > 0 ) { |
|
832 | +function wpinv_get_watermark($id) { |
|
833 | + if (!$id > 0) { |
|
834 | 834 | return NULL; |
835 | 835 | } |
836 | - $invoice = wpinv_get_invoice( $id ); |
|
836 | + $invoice = wpinv_get_invoice($id); |
|
837 | 837 | |
838 | - if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) { |
|
839 | - if ( $invoice->is_paid() ) { |
|
840 | - return __( 'Paid', 'invoicing' ); |
|
838 | + if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) { |
|
839 | + if ($invoice->is_paid()) { |
|
840 | + return __('Paid', 'invoicing'); |
|
841 | 841 | } |
842 | - if ( $invoice->is_refunded() ) { |
|
843 | - return __( 'Refunded', 'invoicing' ); |
|
842 | + if ($invoice->is_refunded()) { |
|
843 | + return __('Refunded', 'invoicing'); |
|
844 | 844 | } |
845 | - if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) { |
|
846 | - return __( 'Cancelled', 'invoicing' ); |
|
845 | + if ($invoice->has_status(array('wpi-cancelled'))) { |
|
846 | + return __('Cancelled', 'invoicing'); |
|
847 | 847 | } |
848 | 848 | } |
849 | 849 | |
850 | 850 | return NULL; |
851 | 851 | } |
852 | 852 | |
853 | -function wpinv_display_invoice_details( $invoice ) { |
|
853 | +function wpinv_display_invoice_details($invoice) { |
|
854 | 854 | global $wpinv_euvat; |
855 | 855 | |
856 | 856 | $invoice_id = $invoice->ID; |
857 | 857 | $vat_name = $wpinv_euvat->get_vat_name(); |
858 | 858 | $use_taxes = wpinv_use_taxes(); |
859 | 859 | |
860 | - $invoice_status = wpinv_get_invoice_status( $invoice_id ); |
|
860 | + $invoice_status = wpinv_get_invoice_status($invoice_id); |
|
861 | 861 | ?> |
862 | 862 | <table class="table table-bordered table-sm"> |
863 | - <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?> |
|
863 | + <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?> |
|
864 | 864 | <tr class="wpi-row-number"> |
865 | - <th><?php echo apply_filters( 'wpinv_invoice_number_label', __( 'Invoice Number', 'invoicing' ), $invoice ); ?></th> |
|
866 | - <td><?php echo esc_html( $invoice_number ); ?></td> |
|
865 | + <th><?php echo apply_filters('wpinv_invoice_number_label', __('Invoice Number', 'invoicing'), $invoice); ?></th> |
|
866 | + <td><?php echo esc_html($invoice_number); ?></td> |
|
867 | 867 | </tr> |
868 | 868 | <?php } ?> |
869 | 869 | <tr class="wpi-row-status"> |
870 | - <th><?php echo apply_filters( 'wpinv_invoice_status_label', __( 'Invoice Status', 'invoicing' ), $invoice ); ?></th> |
|
871 | - <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td> |
|
870 | + <th><?php echo apply_filters('wpinv_invoice_status_label', __('Invoice Status', 'invoicing'), $invoice); ?></th> |
|
871 | + <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td> |
|
872 | 872 | </tr> |
873 | - <?php if ( $invoice->is_renewal() ) { ?> |
|
873 | + <?php if ($invoice->is_renewal()) { ?> |
|
874 | 874 | <tr class="wpi-row-parent"> |
875 | - <th><?php echo apply_filters( 'wpinv_invoice_parent_invoice_label', __( 'Parent Invoice', 'invoicing' ), $invoice ); ?></th> |
|
876 | - <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td> |
|
875 | + <th><?php echo apply_filters('wpinv_invoice_parent_invoice_label', __('Parent Invoice', 'invoicing'), $invoice); ?></th> |
|
876 | + <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td> |
|
877 | 877 | </tr> |
878 | 878 | <?php } ?> |
879 | - <?php if ( ( $gateway_name = wpinv_get_payment_gateway_name( $invoice_id ) ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) { ?> |
|
879 | + <?php if (($gateway_name = wpinv_get_payment_gateway_name($invoice_id)) && ($invoice->is_paid() || $invoice->is_refunded())) { ?> |
|
880 | 880 | <tr class="wpi-row-gateway"> |
881 | - <th><?php echo apply_filters( 'wpinv_invoice_payment_method_label', __( 'Payment Method', 'invoicing' ), $invoice ); ?></th> |
|
881 | + <th><?php echo apply_filters('wpinv_invoice_payment_method_label', __('Payment Method', 'invoicing'), $invoice); ?></th> |
|
882 | 882 | <td><?php echo $gateway_name; ?></td> |
883 | 883 | </tr> |
884 | 884 | <?php } ?> |
885 | - <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?> |
|
885 | + <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?> |
|
886 | 886 | <tr class="wpi-row-date"> |
887 | - <th><?php echo apply_filters( 'wpinv_invoice_date_label', __( 'Invoice Date', 'invoicing' ), $invoice ); ?></th> |
|
887 | + <th><?php echo apply_filters('wpinv_invoice_date_label', __('Invoice Date', 'invoicing'), $invoice); ?></th> |
|
888 | 888 | <td><?php echo $invoice_date; ?></td> |
889 | 889 | </tr> |
890 | 890 | <?php } ?> |
891 | - <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?> |
|
891 | + <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?> |
|
892 | 892 | <tr class="wpi-row-date"> |
893 | - <th><?php echo apply_filters( 'wpinv_invoice_due_date_label', __( 'Due Date', 'invoicing' ), $invoice ); ?></th> |
|
893 | + <th><?php echo apply_filters('wpinv_invoice_due_date_label', __('Due Date', 'invoicing'), $invoice); ?></th> |
|
894 | 894 | <td><?php echo $due_date; ?></td> |
895 | 895 | </tr> |
896 | 896 | <?php } ?> |
897 | - <?php do_action( 'wpinv_display_details_after_due_date', $invoice_id ); ?> |
|
898 | - <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?> |
|
897 | + <?php do_action('wpinv_display_details_after_due_date', $invoice_id); ?> |
|
898 | + <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?> |
|
899 | 899 | <tr class="wpi-row-ovatno"> |
900 | - <th><?php echo apply_filters( 'wpinv_invoice_owner_vat_number_label', wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ), $invoice, $vat_name ); ?></th> |
|
900 | + <th><?php echo apply_filters('wpinv_invoice_owner_vat_number_label', wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name), $invoice, $vat_name); ?></th> |
|
901 | 901 | <td><?php echo $owner_vat_number; ?></td> |
902 | 902 | </tr> |
903 | 903 | <?php } ?> |
904 | - <?php do_action( 'wpinv_display_details_after_due_date', $invoice_id ); ?> |
|
905 | - <?php if ( $use_taxes && ( $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) ) { ?> |
|
904 | + <?php do_action('wpinv_display_details_after_due_date', $invoice_id); ?> |
|
905 | + <?php if ($use_taxes && ($user_vat_number = wpinv_get_invoice_vat_number($invoice_id))) { ?> |
|
906 | 906 | <tr class="wpi-row-uvatno"> |
907 | - <th><?php echo apply_filters( 'wpinv_invoice_user_vat_number_label', wp_sprintf( __( 'Invoice %s Number', 'invoicing' ), $vat_name ), $invoice, $vat_name ); ?></th> |
|
907 | + <th><?php echo apply_filters('wpinv_invoice_user_vat_number_label', wp_sprintf(__('Invoice %s Number', 'invoicing'), $vat_name), $invoice, $vat_name); ?></th> |
|
908 | 908 | <td><?php echo $user_vat_number; ?></td> |
909 | 909 | </tr> |
910 | 910 | <?php } ?> |
911 | 911 | <tr class="table-active tr-total wpi-row-total"> |
912 | - <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th> |
|
913 | - <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td> |
|
912 | + <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th> |
|
913 | + <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td> |
|
914 | 914 | </tr> |
915 | 915 | </table> |
916 | 916 | <?php |
917 | 917 | } |
918 | 918 | |
919 | -function wpinv_display_to_address( $invoice_id = 0 ) { |
|
920 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
919 | +function wpinv_display_to_address($invoice_id = 0) { |
|
920 | + $invoice = wpinv_get_invoice($invoice_id); |
|
921 | 921 | |
922 | - if ( empty( $invoice ) ) { |
|
922 | + if (empty($invoice)) { |
|
923 | 923 | return NULL; |
924 | 924 | } |
925 | 925 | |
926 | 926 | $billing_details = $invoice->get_user_info(); |
927 | - $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>'; |
|
927 | + $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>'; |
|
928 | 928 | $output .= '<div class="wrapper col-xs-10">'; |
929 | 929 | |
930 | 930 | ob_start(); |
931 | - do_action( 'wpinv_display_to_address_top', $invoice ); |
|
931 | + do_action('wpinv_display_to_address_top', $invoice); |
|
932 | 932 | $output .= ob_get_clean(); |
933 | 933 | |
934 | - $output .= '<div class="name">' . esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) . '</div>'; |
|
935 | - if ( $company = $billing_details['company'] ) { |
|
936 | - $output .= '<div class="company">' . wpautop( wp_kses_post( $company ) ) . '</div>'; |
|
934 | + $output .= '<div class="name">' . esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])) . '</div>'; |
|
935 | + if ($company = $billing_details['company']) { |
|
936 | + $output .= '<div class="company">' . wpautop(wp_kses_post($company)) . '</div>'; |
|
937 | 937 | } |
938 | 938 | $address_row = ''; |
939 | - if ( $address = $billing_details['address'] ) { |
|
940 | - $address_row .= wpautop( wp_kses_post( $address ) ); |
|
939 | + if ($address = $billing_details['address']) { |
|
940 | + $address_row .= wpautop(wp_kses_post($address)); |
|
941 | 941 | } |
942 | 942 | |
943 | 943 | $address_fields = array(); |
944 | - if ( !empty( $billing_details['city'] ) ) { |
|
944 | + if (!empty($billing_details['city'])) { |
|
945 | 945 | $address_fields[] = $billing_details['city']; |
946 | 946 | } |
947 | 947 | |
948 | - $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : ''; |
|
949 | - if ( !empty( $billing_details['state'] ) ) { |
|
950 | - $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country ); |
|
948 | + $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : ''; |
|
949 | + if (!empty($billing_details['state'])) { |
|
950 | + $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country); |
|
951 | 951 | } |
952 | 952 | |
953 | - if ( !empty( $billing_country ) ) { |
|
954 | - $address_fields[] = wpinv_country_name( $billing_country ); |
|
953 | + if (!empty($billing_country)) { |
|
954 | + $address_fields[] = wpinv_country_name($billing_country); |
|
955 | 955 | } |
956 | 956 | |
957 | - if ( !empty( $address_fields ) ) { |
|
958 | - $address_fields = implode( ", ", $address_fields ); |
|
957 | + if (!empty($address_fields)) { |
|
958 | + $address_fields = implode(", ", $address_fields); |
|
959 | 959 | |
960 | - if ( !empty( $billing_details['zip'] ) ) { |
|
960 | + if (!empty($billing_details['zip'])) { |
|
961 | 961 | $address_fields .= ' ' . $billing_details['zip']; |
962 | 962 | } |
963 | 963 | |
964 | - $address_row .= wpautop( wp_kses_post( $address_fields ) ); |
|
964 | + $address_row .= wpautop(wp_kses_post($address_fields)); |
|
965 | 965 | } |
966 | 966 | |
967 | - if ( $address_row ) { |
|
967 | + if ($address_row) { |
|
968 | 968 | $output .= '<div class="address">' . $address_row . '</div>'; |
969 | 969 | } |
970 | 970 | |
971 | - if ( $phone = $invoice->get_phone() ) { |
|
972 | - $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s', 'invoicing' ), esc_html( $phone ) ) . '</div>'; |
|
971 | + if ($phone = $invoice->get_phone()) { |
|
972 | + $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s', 'invoicing'), esc_html($phone)) . '</div>'; |
|
973 | 973 | } |
974 | - if ( $email = $invoice->get_email() ) { |
|
975 | - $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' , 'invoicing'), esc_html( $email ) ) . '</div>'; |
|
974 | + if ($email = $invoice->get_email()) { |
|
975 | + $output .= '<div class="email">' . wp_sprintf(__('Email: %s', 'invoicing'), esc_html($email)) . '</div>'; |
|
976 | 976 | } |
977 | 977 | |
978 | 978 | ob_start(); |
979 | - do_action( 'wpinv_display_to_address_bottom', $invoice ); |
|
979 | + do_action('wpinv_display_to_address_bottom', $invoice); |
|
980 | 980 | $output .= ob_get_clean(); |
981 | 981 | |
982 | 982 | $output .= '</div>'; |
983 | - $output = apply_filters( 'wpinv_display_to_address', $output, $invoice ); |
|
983 | + $output = apply_filters('wpinv_display_to_address', $output, $invoice); |
|
984 | 984 | |
985 | 985 | echo $output; |
986 | 986 | } |
987 | 987 | |
988 | -function wpinv_display_line_items( $invoice_id = 0 ) { |
|
988 | +function wpinv_display_line_items($invoice_id = 0) { |
|
989 | 989 | global $wpinv_euvat, $ajax_cart_details; |
990 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
990 | + $invoice = wpinv_get_invoice($invoice_id); |
|
991 | 991 | $quantities_enabled = wpinv_item_quantities_enabled(); |
992 | 992 | $use_taxes = wpinv_use_taxes(); |
993 | - if ( !$use_taxes && (float)$invoice->get_tax() > 0 ) { |
|
993 | + if (!$use_taxes && (float)$invoice->get_tax() > 0) { |
|
994 | 994 | $use_taxes = true; |
995 | 995 | } |
996 | 996 | $zero_tax = !(float)$invoice->get_tax() > 0 ? true : false; |
997 | - $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' ); |
|
998 | - $tax_title = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : ''; |
|
997 | + $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing'); |
|
998 | + $tax_title = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : ''; |
|
999 | 999 | |
1000 | 1000 | $cart_details = $invoice->get_cart_details(); |
1001 | 1001 | $ajax_cart_details = $cart_details; |
@@ -1004,64 +1004,64 @@ discard block |
||
1004 | 1004 | <table class="table table-sm table-bordered table-responsive"> |
1005 | 1005 | <thead> |
1006 | 1006 | <tr> |
1007 | - <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th> |
|
1008 | - <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th> |
|
1007 | + <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th> |
|
1008 | + <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th> |
|
1009 | 1009 | <?php if ($quantities_enabled) { ?> |
1010 | - <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th> |
|
1010 | + <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th> |
|
1011 | 1011 | <?php } ?> |
1012 | 1012 | <?php if ($use_taxes && !$zero_tax) { ?> |
1013 | 1013 | <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th> |
1014 | 1014 | <?php } ?> |
1015 | - <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th> |
|
1015 | + <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th> |
|
1016 | 1016 | </tr> |
1017 | 1017 | </thead> |
1018 | 1018 | <tbody> |
1019 | 1019 | <?php |
1020 | - if ( !empty( $cart_details ) ) { |
|
1021 | - do_action( 'wpinv_display_line_items_start', $invoice ); |
|
1020 | + if (!empty($cart_details)) { |
|
1021 | + do_action('wpinv_display_line_items_start', $invoice); |
|
1022 | 1022 | |
1023 | 1023 | $count = 0; |
1024 | 1024 | $cols = 3; |
1025 | - foreach ( $cart_details as $key => $cart_item ) { |
|
1026 | - $item_id = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : ''; |
|
1027 | - $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount( $cart_item["item_price"] ) : 0; |
|
1028 | - $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount( $cart_item["subtotal"] ) : 0; |
|
1029 | - $quantity = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1; |
|
1025 | + foreach ($cart_details as $key => $cart_item) { |
|
1026 | + $item_id = !empty($cart_item['id']) ? absint($cart_item['id']) : ''; |
|
1027 | + $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount($cart_item["item_price"]) : 0; |
|
1028 | + $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount($cart_item["subtotal"]) : 0; |
|
1029 | + $quantity = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1; |
|
1030 | 1030 | |
1031 | - $item = $item_id ? new WPInv_Item( $item_id ) : NULL; |
|
1031 | + $item = $item_id ? new WPInv_Item($item_id) : NULL; |
|
1032 | 1032 | $summary = ''; |
1033 | 1033 | $cols = 3; |
1034 | - if ( !empty($item) ) { |
|
1034 | + if (!empty($item)) { |
|
1035 | 1035 | $item_name = $item->get_name(); |
1036 | 1036 | $summary = $item->get_summary(); |
1037 | 1037 | } |
1038 | - $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name; |
|
1038 | + $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name; |
|
1039 | 1039 | |
1040 | - $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice ); |
|
1040 | + $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice); |
|
1041 | 1041 | |
1042 | 1042 | $item_tax = ''; |
1043 | 1043 | $tax_rate = ''; |
1044 | - if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) { |
|
1045 | - $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ), $invoice->get_currency() ); |
|
1046 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100; |
|
1047 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : ''; |
|
1044 | + if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) { |
|
1045 | + $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']), $invoice->get_currency()); |
|
1046 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100; |
|
1047 | + $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : ''; |
|
1048 | 1048 | $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : ''; |
1049 | 1049 | } |
1050 | 1050 | |
1051 | 1051 | $line_item_tax = $item_tax . $tax_rate; |
1052 | 1052 | |
1053 | - if ( $line_item_tax === '' ) { |
|
1053 | + if ($line_item_tax === '') { |
|
1054 | 1054 | $line_item_tax = 0; // Zero tax |
1055 | 1055 | } |
1056 | 1056 | |
1057 | - $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">'; |
|
1058 | - $line_item .= '<td class="name">' . esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item ); |
|
1059 | - if ( $summary !== '' ) { |
|
1060 | - $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>'; |
|
1057 | + $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">'; |
|
1058 | + $line_item .= '<td class="name">' . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item); |
|
1059 | + if ($summary !== '') { |
|
1060 | + $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>'; |
|
1061 | 1061 | } |
1062 | 1062 | $line_item .= '</td>'; |
1063 | 1063 | |
1064 | - $line_item .= '<td class="rate">' . esc_html__( wpinv_price( wpinv_format_amount( $item_price ), $invoice->get_currency() ) ) . '</td>'; |
|
1064 | + $line_item .= '<td class="rate">' . esc_html__(wpinv_price(wpinv_format_amount($item_price), $invoice->get_currency())) . '</td>'; |
|
1065 | 1065 | if ($quantities_enabled) { |
1066 | 1066 | $cols++; |
1067 | 1067 | $line_item .= '<td class="qty">' . $quantity . '</td>'; |
@@ -1070,55 +1070,55 @@ discard block |
||
1070 | 1070 | $cols++; |
1071 | 1071 | $line_item .= '<td class="tax">' . $line_item_tax . '</td>'; |
1072 | 1072 | } |
1073 | - $line_item .= '<td class="total">' . esc_html__( wpinv_price( wpinv_format_amount( $line_total ), $invoice->get_currency() ) ) . '</td>'; |
|
1073 | + $line_item .= '<td class="total">' . esc_html__(wpinv_price(wpinv_format_amount($line_total), $invoice->get_currency())) . '</td>'; |
|
1074 | 1074 | $line_item .= '</tr>'; |
1075 | 1075 | |
1076 | - echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols ); |
|
1076 | + echo apply_filters('wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols); |
|
1077 | 1077 | |
1078 | 1078 | $count++; |
1079 | 1079 | } |
1080 | 1080 | |
1081 | - do_action( 'wpinv_display_before_subtotal', $invoice, $cols ); |
|
1081 | + do_action('wpinv_display_before_subtotal', $invoice, $cols); |
|
1082 | 1082 | ?> |
1083 | 1083 | <tr class="row-sub-total row_odd"> |
1084 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td> |
|
1085 | - <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td> |
|
1084 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_subtotal_label', '<strong>' . __('Sub Total', 'invoicing') . ':</strong>', $invoice); ?></td> |
|
1085 | + <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td> |
|
1086 | 1086 | </tr> |
1087 | 1087 | <?php |
1088 | - do_action( 'wpinv_display_after_subtotal', $invoice, $cols ); |
|
1088 | + do_action('wpinv_display_after_subtotal', $invoice, $cols); |
|
1089 | 1089 | |
1090 | - if ( wpinv_discount( $invoice_id, false ) > 0 ) { |
|
1091 | - do_action( 'wpinv_display_before_discount', $invoice, $cols ); |
|
1090 | + if (wpinv_discount($invoice_id, false) > 0) { |
|
1091 | + do_action('wpinv_display_before_discount', $invoice, $cols); |
|
1092 | 1092 | ?> |
1093 | 1093 | <tr class="row-discount"> |
1094 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td> |
|
1095 | - <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td> |
|
1094 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</td> |
|
1095 | + <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td> |
|
1096 | 1096 | </tr> |
1097 | 1097 | <?php |
1098 | - do_action( 'wpinv_display_after_discount', $invoice, $cols ); |
|
1098 | + do_action('wpinv_display_after_discount', $invoice, $cols); |
|
1099 | 1099 | } |
1100 | 1100 | |
1101 | - if ( $use_taxes ) { |
|
1102 | - do_action( 'wpinv_display_before_tax', $invoice, $cols ); |
|
1101 | + if ($use_taxes) { |
|
1102 | + do_action('wpinv_display_before_tax', $invoice, $cols); |
|
1103 | 1103 | ?> |
1104 | 1104 | <tr class="row-tax"> |
1105 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td> |
|
1106 | - <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td> |
|
1105 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice); ?></td> |
|
1106 | + <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td> |
|
1107 | 1107 | </tr> |
1108 | 1108 | <?php |
1109 | - do_action( 'wpinv_display_after_tax', $invoice, $cols ); |
|
1109 | + do_action('wpinv_display_after_tax', $invoice, $cols); |
|
1110 | 1110 | } |
1111 | 1111 | |
1112 | - do_action( 'wpinv_display_before_total', $invoice, $cols ); |
|
1112 | + do_action('wpinv_display_before_total', $invoice, $cols); |
|
1113 | 1113 | ?> |
1114 | 1114 | <tr class="table-active row-total"> |
1115 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td> |
|
1116 | - <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td> |
|
1115 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?></td> |
|
1116 | + <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td> |
|
1117 | 1117 | </tr> |
1118 | 1118 | <?php |
1119 | - do_action( 'wpinv_display_after_total', $invoice, $cols ); |
|
1119 | + do_action('wpinv_display_after_total', $invoice, $cols); |
|
1120 | 1120 | |
1121 | - do_action( 'wpinv_display_line_end', $invoice, $cols ); |
|
1121 | + do_action('wpinv_display_line_end', $invoice, $cols); |
|
1122 | 1122 | } |
1123 | 1123 | ?> |
1124 | 1124 | </tbody> |
@@ -1127,35 +1127,35 @@ discard block |
||
1127 | 1127 | echo ob_get_clean(); |
1128 | 1128 | } |
1129 | 1129 | |
1130 | -function wpinv_display_invoice_totals( $invoice_id = 0 ) { |
|
1130 | +function wpinv_display_invoice_totals($invoice_id = 0) { |
|
1131 | 1131 | $use_taxes = wpinv_use_taxes(); |
1132 | 1132 | |
1133 | - do_action( 'wpinv_before_display_totals_table', $invoice_id ); |
|
1133 | + do_action('wpinv_before_display_totals_table', $invoice_id); |
|
1134 | 1134 | ?> |
1135 | 1135 | <table class="table table-sm table-bordered table-responsive"> |
1136 | 1136 | <tbody> |
1137 | - <?php do_action( 'wpinv_before_display_totals' ); ?> |
|
1137 | + <?php do_action('wpinv_before_display_totals'); ?> |
|
1138 | 1138 | <tr class="row-sub-total"> |
1139 | - <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td> |
|
1140 | - <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td> |
|
1139 | + <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td> |
|
1140 | + <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td> |
|
1141 | 1141 | </tr> |
1142 | - <?php do_action( 'wpinv_after_display_totals' ); ?> |
|
1143 | - <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?> |
|
1142 | + <?php do_action('wpinv_after_display_totals'); ?> |
|
1143 | + <?php if (wpinv_discount($invoice_id, false) > 0) { ?> |
|
1144 | 1144 | <tr class="row-discount"> |
1145 | - <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td> |
|
1146 | - <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td> |
|
1145 | + <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td> |
|
1146 | + <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td> |
|
1147 | 1147 | </tr> |
1148 | - <?php do_action( 'wpinv_after_display_discount' ); ?> |
|
1148 | + <?php do_action('wpinv_after_display_discount'); ?> |
|
1149 | 1149 | <?php } ?> |
1150 | - <?php if ( $use_taxes ) { ?> |
|
1150 | + <?php if ($use_taxes) { ?> |
|
1151 | 1151 | <tr class="row-tax"> |
1152 | - <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td> |
|
1153 | - <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td> |
|
1152 | + <td class="rate"><?php _e('Tax', 'invoicing'); ?></td> |
|
1153 | + <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td> |
|
1154 | 1154 | </tr> |
1155 | - <?php do_action( 'wpinv_after_display_tax' ); ?> |
|
1155 | + <?php do_action('wpinv_after_display_tax'); ?> |
|
1156 | 1156 | <?php } ?> |
1157 | - <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?> |
|
1158 | - <?php foreach ( $fees as $fee ) { ?> |
|
1157 | + <?php if ($fees = wpinv_get_fees($invoice_id)) { ?> |
|
1158 | + <?php foreach ($fees as $fee) { ?> |
|
1159 | 1159 | <tr class="row-fee"> |
1160 | 1160 | <td class="rate"><?php echo $fee['label']; ?></td> |
1161 | 1161 | <td class="total"><?php echo $fee['amount_display']; ?></td> |
@@ -1163,73 +1163,73 @@ discard block |
||
1163 | 1163 | <?php } ?> |
1164 | 1164 | <?php } ?> |
1165 | 1165 | <tr class="table-active row-total"> |
1166 | - <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td> |
|
1167 | - <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td> |
|
1166 | + <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td> |
|
1167 | + <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td> |
|
1168 | 1168 | </tr> |
1169 | - <?php do_action( 'wpinv_after_totals' ); ?> |
|
1169 | + <?php do_action('wpinv_after_totals'); ?> |
|
1170 | 1170 | </tbody> |
1171 | 1171 | |
1172 | 1172 | </table> |
1173 | 1173 | |
1174 | - <?php do_action( 'wpinv_after_totals_table' ); |
|
1174 | + <?php do_action('wpinv_after_totals_table'); |
|
1175 | 1175 | } |
1176 | 1176 | |
1177 | -function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) { |
|
1178 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1177 | +function wpinv_display_payments_info($invoice_id = 0, $echo = true) { |
|
1178 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1179 | 1179 | |
1180 | 1180 | ob_start(); |
1181 | - do_action( 'wpinv_before_display_payments_info', $invoice_id ); |
|
1182 | - if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
1181 | + do_action('wpinv_before_display_payments_info', $invoice_id); |
|
1182 | + if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid() || $invoice->is_refunded()) { |
|
1183 | 1183 | ?> |
1184 | 1184 | <div class="wpi-payment-info"> |
1185 | - <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p> |
|
1186 | - <?php if ( $gateway_title ) { ?> |
|
1187 | - <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p> |
|
1185 | + <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p> |
|
1186 | + <?php if ($gateway_title) { ?> |
|
1187 | + <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p> |
|
1188 | 1188 | <?php } ?> |
1189 | 1189 | </div> |
1190 | 1190 | <?php |
1191 | 1191 | } |
1192 | - do_action( 'wpinv_after_display_payments_info', $invoice_id ); |
|
1192 | + do_action('wpinv_after_display_payments_info', $invoice_id); |
|
1193 | 1193 | $outout = ob_get_clean(); |
1194 | 1194 | |
1195 | - if ( $echo ) { |
|
1195 | + if ($echo) { |
|
1196 | 1196 | echo $outout; |
1197 | 1197 | } else { |
1198 | 1198 | return $outout; |
1199 | 1199 | } |
1200 | 1200 | } |
1201 | 1201 | |
1202 | -function wpinv_display_style( $invoice ) { |
|
1203 | - wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION ); |
|
1202 | +function wpinv_display_style($invoice) { |
|
1203 | + wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION); |
|
1204 | 1204 | |
1205 | - wp_print_styles( 'open-sans' ); |
|
1206 | - wp_print_styles( 'wpinv-single-style' ); |
|
1205 | + wp_print_styles('open-sans'); |
|
1206 | + wp_print_styles('wpinv-single-style'); |
|
1207 | 1207 | } |
1208 | -add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
1209 | -add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' ); |
|
1208 | +add_action('wpinv_invoice_print_head', 'wpinv_display_style'); |
|
1209 | +add_action('wpinv_invalid_invoice_head', 'wpinv_display_style'); |
|
1210 | 1210 | |
1211 | 1211 | function wpinv_checkout_billing_details() { |
1212 | 1212 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
1213 | 1213 | if (empty($invoice_id)) { |
1214 | - wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ ); |
|
1214 | + wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__); |
|
1215 | 1215 | return null; |
1216 | 1216 | } |
1217 | 1217 | |
1218 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
1218 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
1219 | 1219 | if (empty($invoice)) { |
1220 | - wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ ); |
|
1220 | + wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__); |
|
1221 | 1221 | return null; |
1222 | 1222 | } |
1223 | 1223 | $user_id = $invoice->get_user_id(); |
1224 | 1224 | $user_info = $invoice->get_user_info(); |
1225 | - $address_info = wpinv_get_user_address( $user_id ); |
|
1225 | + $address_info = wpinv_get_user_address($user_id); |
|
1226 | 1226 | |
1227 | - if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) { |
|
1227 | + if (empty($user_info['first_name']) && !empty($user_info['first_name'])) { |
|
1228 | 1228 | $user_info['first_name'] = $user_info['first_name']; |
1229 | 1229 | $user_info['last_name'] = $user_info['last_name']; |
1230 | 1230 | } |
1231 | 1231 | |
1232 | - if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) { |
|
1232 | + if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) { |
|
1233 | 1233 | $user_info['country'] = $address_info['country']; |
1234 | 1234 | $user_info['state'] = $address_info['state']; |
1235 | 1235 | $user_info['city'] = $address_info['city']; |
@@ -1245,98 +1245,98 @@ discard block |
||
1245 | 1245 | 'address' |
1246 | 1246 | ); |
1247 | 1247 | |
1248 | - foreach ( $address_fields as $field ) { |
|
1249 | - if ( empty( $user_info[$field] ) ) { |
|
1248 | + foreach ($address_fields as $field) { |
|
1249 | + if (empty($user_info[$field])) { |
|
1250 | 1250 | $user_info[$field] = $address_info[$field]; |
1251 | 1251 | } |
1252 | 1252 | } |
1253 | 1253 | |
1254 | - return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice ); |
|
1254 | + return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice); |
|
1255 | 1255 | } |
1256 | 1256 | |
1257 | 1257 | function wpinv_admin_get_line_items($invoice = array()) { |
1258 | 1258 | $item_quantities = wpinv_item_quantities_enabled(); |
1259 | 1259 | $use_taxes = wpinv_use_taxes(); |
1260 | 1260 | |
1261 | - if ( empty( $invoice ) ) { |
|
1261 | + if (empty($invoice)) { |
|
1262 | 1262 | return NULL; |
1263 | 1263 | } |
1264 | 1264 | |
1265 | 1265 | $cart_items = $invoice->get_cart_details(); |
1266 | - if ( empty( $cart_items ) ) { |
|
1266 | + if (empty($cart_items)) { |
|
1267 | 1267 | return NULL; |
1268 | 1268 | } |
1269 | 1269 | ob_start(); |
1270 | 1270 | |
1271 | - do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice ); |
|
1271 | + do_action('wpinv_admin_before_line_items', $cart_items, $invoice); |
|
1272 | 1272 | |
1273 | 1273 | $count = 0; |
1274 | - foreach ( $cart_items as $key => $cart_item ) { |
|
1274 | + foreach ($cart_items as $key => $cart_item) { |
|
1275 | 1275 | $item_id = $cart_item['id']; |
1276 | - $wpi_item = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL; |
|
1276 | + $wpi_item = $item_id > 0 ? new WPInv_Item($item_id) : NULL; |
|
1277 | 1277 | |
1278 | 1278 | if (empty($wpi_item)) { |
1279 | 1279 | continue; |
1280 | 1280 | } |
1281 | 1281 | |
1282 | - $item_price = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ), $invoice->get_currency() ); |
|
1283 | - $quantity = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1; |
|
1284 | - $item_subtotal = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ), $invoice->get_currency() ); |
|
1282 | + $item_price = wpinv_price(wpinv_format_amount($cart_item['item_price']), $invoice->get_currency()); |
|
1283 | + $quantity = !empty($cart_item['quantity']) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1; |
|
1284 | + $item_subtotal = wpinv_price(wpinv_format_amount($cart_item['subtotal']), $invoice->get_currency()); |
|
1285 | 1285 | $can_remove = true; |
1286 | 1286 | |
1287 | - $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', '', $cart_item, $wpi_item, $invoice ); |
|
1287 | + $summary = apply_filters('wpinv_admin_invoice_line_item_summary', '', $cart_item, $wpi_item, $invoice); |
|
1288 | 1288 | |
1289 | 1289 | $item_tax = ''; |
1290 | 1290 | $tax_rate = ''; |
1291 | - if ( $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) { |
|
1292 | - $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ), $invoice->get_currency() ); |
|
1293 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100; |
|
1294 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : ''; |
|
1291 | + if ($cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) { |
|
1292 | + $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']), $invoice->get_currency()); |
|
1293 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100; |
|
1294 | + $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : ''; |
|
1295 | 1295 | $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : ''; |
1296 | 1296 | } |
1297 | 1297 | $line_item_tax = $item_tax . $tax_rate; |
1298 | 1298 | |
1299 | - if ( $line_item_tax === '' ) { |
|
1299 | + if ($line_item_tax === '') { |
|
1300 | 1300 | $line_item_tax = 0; // Zero tax |
1301 | 1301 | } |
1302 | 1302 | |
1303 | - $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">'; |
|
1303 | + $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">'; |
|
1304 | 1304 | $line_item .= '<td class="id">' . $item_id . '</td>'; |
1305 | - $line_item .= '<td class="title"><a href="' . get_edit_post_link( $item_id ) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix( $wpi_item ); |
|
1306 | - if ( $summary !== '' ) { |
|
1307 | - $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>'; |
|
1305 | + $line_item .= '<td class="title"><a href="' . get_edit_post_link($item_id) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix($wpi_item); |
|
1306 | + if ($summary !== '') { |
|
1307 | + $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>'; |
|
1308 | 1308 | } |
1309 | 1309 | $line_item .= '</td>'; |
1310 | 1310 | $line_item .= '<td class="price">' . $item_price . '</td>'; |
1311 | 1311 | |
1312 | - if ( $item_quantities ) { |
|
1313 | - if ( count( $cart_items ) == 1 && $quantity <= 1 ) { |
|
1312 | + if ($item_quantities) { |
|
1313 | + if (count($cart_items) == 1 && $quantity <= 1) { |
|
1314 | 1314 | $can_remove = false; |
1315 | 1315 | } |
1316 | 1316 | $line_item .= '<td class="qty" data-quantity="' . $quantity . '"> × ' . $quantity . '</td>'; |
1317 | 1317 | } else { |
1318 | - if ( count( $cart_items ) == 1 ) { |
|
1318 | + if (count($cart_items) == 1) { |
|
1319 | 1319 | $can_remove = false; |
1320 | 1320 | } |
1321 | 1321 | } |
1322 | 1322 | $line_item .= '<td class="total">' . $item_subtotal . '</td>'; |
1323 | 1323 | |
1324 | - if ( $use_taxes ) { |
|
1324 | + if ($use_taxes) { |
|
1325 | 1325 | $line_item .= '<td class="tax">' . $line_item_tax . '</td>'; |
1326 | 1326 | } |
1327 | 1327 | $line_item .= '<td class="action">'; |
1328 | - if ( !$invoice->is_paid() && !$invoice->is_refunded() && $can_remove ) { |
|
1328 | + if (!$invoice->is_paid() && !$invoice->is_refunded() && $can_remove) { |
|
1329 | 1329 | $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>'; |
1330 | 1330 | } |
1331 | 1331 | $line_item .= '</td>'; |
1332 | 1332 | $line_item .= '</tr>'; |
1333 | 1333 | |
1334 | - echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice ); |
|
1334 | + echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice); |
|
1335 | 1335 | |
1336 | 1336 | $count++; |
1337 | 1337 | } |
1338 | 1338 | |
1339 | - do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice ); |
|
1339 | + do_action('wpinv_admin_after_line_items', $cart_items, $invoice); |
|
1340 | 1340 | |
1341 | 1341 | return ob_get_clean(); |
1342 | 1342 | } |
@@ -1347,35 +1347,35 @@ discard block |
||
1347 | 1347 | // Set current invoice id. |
1348 | 1348 | $wpi_checkout_id = wpinv_get_invoice_cart_id(); |
1349 | 1349 | |
1350 | - $form_action = esc_url( wpinv_get_checkout_uri() ); |
|
1350 | + $form_action = esc_url(wpinv_get_checkout_uri()); |
|
1351 | 1351 | |
1352 | 1352 | ob_start(); |
1353 | 1353 | echo '<div id="wpinv_checkout_wrap">'; |
1354 | 1354 | |
1355 | - if ( wpinv_get_cart_contents() || wpinv_cart_has_fees() ) { |
|
1355 | + if (wpinv_get_cart_contents() || wpinv_cart_has_fees()) { |
|
1356 | 1356 | ?> |
1357 | 1357 | <div id="wpinv_checkout_form_wrap" class="wpinv_clearfix table-responsive"> |
1358 | - <?php do_action( 'wpinv_before_checkout_form' ); ?> |
|
1358 | + <?php do_action('wpinv_before_checkout_form'); ?> |
|
1359 | 1359 | <form id="wpinv_checkout_form" class="wpi-form" action="<?php echo $form_action; ?>" method="POST"> |
1360 | 1360 | <?php |
1361 | - do_action( 'wpinv_checkout_form_top' ); |
|
1362 | - do_action( 'wpinv_checkout_billing_info' ); |
|
1363 | - do_action( 'wpinv_checkout_cart' ); |
|
1364 | - do_action( 'wpinv_payment_mode_select' ); |
|
1365 | - do_action( 'wpinv_checkout_form_bottom' ) |
|
1361 | + do_action('wpinv_checkout_form_top'); |
|
1362 | + do_action('wpinv_checkout_billing_info'); |
|
1363 | + do_action('wpinv_checkout_cart'); |
|
1364 | + do_action('wpinv_payment_mode_select'); |
|
1365 | + do_action('wpinv_checkout_form_bottom') |
|
1366 | 1366 | ?> |
1367 | 1367 | </form> |
1368 | - <?php do_action( 'wpinv_after_purchase_form' ); ?> |
|
1368 | + <?php do_action('wpinv_after_purchase_form'); ?> |
|
1369 | 1369 | </div><!--end #wpinv_checkout_form_wrap--> |
1370 | 1370 | <?php |
1371 | 1371 | } else { |
1372 | - do_action( 'wpinv_cart_empty' ); |
|
1372 | + do_action('wpinv_cart_empty'); |
|
1373 | 1373 | } |
1374 | 1374 | echo '</div><!--end #wpinv_checkout_wrap-->'; |
1375 | 1375 | return ob_get_clean(); |
1376 | 1376 | } |
1377 | 1377 | |
1378 | -function wpinv_checkout_cart( $cart_details = array(), $echo = true ) { |
|
1378 | +function wpinv_checkout_cart($cart_details = array(), $echo = true) { |
|
1379 | 1379 | global $ajax_cart_details; |
1380 | 1380 | $ajax_cart_details = $cart_details; |
1381 | 1381 | /* |
@@ -1390,25 +1390,25 @@ discard block |
||
1390 | 1390 | } |
1391 | 1391 | */ |
1392 | 1392 | ob_start(); |
1393 | - do_action( 'wpinv_before_checkout_cart' ); |
|
1393 | + do_action('wpinv_before_checkout_cart'); |
|
1394 | 1394 | echo '<div id="wpinv_checkout_cart_form" method="post">'; |
1395 | 1395 | echo '<div id="wpinv_checkout_cart_wrap">'; |
1396 | - wpinv_get_template_part( 'wpinv-checkout-cart' ); |
|
1396 | + wpinv_get_template_part('wpinv-checkout-cart'); |
|
1397 | 1397 | echo '</div>'; |
1398 | 1398 | echo '</div>'; |
1399 | - do_action( 'wpinv_after_checkout_cart' ); |
|
1399 | + do_action('wpinv_after_checkout_cart'); |
|
1400 | 1400 | $content = ob_get_clean(); |
1401 | 1401 | |
1402 | - if ( $echo ) { |
|
1402 | + if ($echo) { |
|
1403 | 1403 | echo $content; |
1404 | 1404 | } else { |
1405 | 1405 | return $content; |
1406 | 1406 | } |
1407 | 1407 | } |
1408 | -add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 ); |
|
1408 | +add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10); |
|
1409 | 1409 | |
1410 | 1410 | function wpinv_empty_cart_message() { |
1411 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1411 | + return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>'); |
|
1412 | 1412 | } |
1413 | 1413 | |
1414 | 1414 | /** |
@@ -1420,91 +1420,91 @@ discard block |
||
1420 | 1420 | function wpinv_empty_checkout_cart() { |
1421 | 1421 | echo wpinv_empty_cart_message(); |
1422 | 1422 | } |
1423 | -add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
1423 | +add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart'); |
|
1424 | 1424 | |
1425 | 1425 | function wpinv_save_cart_button() { |
1426 | - if ( wpinv_is_cart_saving_disabled() ) |
|
1426 | + if (wpinv_is_cart_saving_disabled()) |
|
1427 | 1427 | return; |
1428 | 1428 | ?> |
1429 | - <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url( add_query_arg( 'wpi_action', 'save_cart' ) ); ?>"><?php _e( 'Save Cart', 'invoicing' ); ?></a> |
|
1429 | + <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url(add_query_arg('wpi_action', 'save_cart')); ?>"><?php _e('Save Cart', 'invoicing'); ?></a> |
|
1430 | 1430 | <?php |
1431 | 1431 | } |
1432 | 1432 | |
1433 | 1433 | function wpinv_update_cart_button() { |
1434 | - if ( !wpinv_item_quantities_enabled() ) |
|
1434 | + if (!wpinv_item_quantities_enabled()) |
|
1435 | 1435 | return; |
1436 | 1436 | ?> |
1437 | - <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/> |
|
1437 | + <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/> |
|
1438 | 1438 | <input type="hidden" name="wpi_action" value="update_cart"/> |
1439 | 1439 | <?php |
1440 | 1440 | } |
1441 | 1441 | |
1442 | 1442 | function wpinv_checkout_cart_columns() { |
1443 | 1443 | $default = 3; |
1444 | - if ( wpinv_item_quantities_enabled() ) { |
|
1444 | + if (wpinv_item_quantities_enabled()) { |
|
1445 | 1445 | $default++; |
1446 | 1446 | } |
1447 | 1447 | |
1448 | - if ( wpinv_use_taxes() ) { |
|
1448 | + if (wpinv_use_taxes()) { |
|
1449 | 1449 | $default++; |
1450 | 1450 | } |
1451 | 1451 | |
1452 | - return apply_filters( 'wpinv_checkout_cart_columns', $default ); |
|
1452 | + return apply_filters('wpinv_checkout_cart_columns', $default); |
|
1453 | 1453 | } |
1454 | 1454 | |
1455 | 1455 | function wpinv_display_cart_messages() { |
1456 | 1456 | global $wpi_session; |
1457 | 1457 | |
1458 | - $messages = $wpi_session->get( 'wpinv_cart_messages' ); |
|
1458 | + $messages = $wpi_session->get('wpinv_cart_messages'); |
|
1459 | 1459 | |
1460 | - if ( $messages ) { |
|
1461 | - foreach ( $messages as $message_id => $message ) { |
|
1460 | + if ($messages) { |
|
1461 | + foreach ($messages as $message_id => $message) { |
|
1462 | 1462 | // Try and detect what type of message this is |
1463 | - if ( strpos( strtolower( $message ), 'error' ) ) { |
|
1463 | + if (strpos(strtolower($message), 'error')) { |
|
1464 | 1464 | $type = 'error'; |
1465 | - } elseif ( strpos( strtolower( $message ), 'success' ) ) { |
|
1465 | + } elseif (strpos(strtolower($message), 'success')) { |
|
1466 | 1466 | $type = 'success'; |
1467 | 1467 | } else { |
1468 | 1468 | $type = 'info'; |
1469 | 1469 | } |
1470 | 1470 | |
1471 | - $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) ); |
|
1471 | + $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type)); |
|
1472 | 1472 | |
1473 | - echo '<div class="' . implode( ' ', $classes ) . '">'; |
|
1473 | + echo '<div class="' . implode(' ', $classes) . '">'; |
|
1474 | 1474 | // Loop message codes and display messages |
1475 | 1475 | echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>'; |
1476 | 1476 | echo '</div>'; |
1477 | 1477 | } |
1478 | 1478 | |
1479 | 1479 | // Remove all of the cart saving messages |
1480 | - $wpi_session->set( 'wpinv_cart_messages', null ); |
|
1480 | + $wpi_session->set('wpinv_cart_messages', null); |
|
1481 | 1481 | } |
1482 | 1482 | } |
1483 | -add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' ); |
|
1483 | +add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages'); |
|
1484 | 1484 | |
1485 | 1485 | function wpinv_discount_field() { |
1486 | - if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) { |
|
1486 | + if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) { |
|
1487 | 1487 | return; // Only show before a payment method has been selected if ajax is disabled |
1488 | 1488 | } |
1489 | 1489 | |
1490 | - if ( !wpinv_is_checkout() ) { |
|
1490 | + if (!wpinv_is_checkout()) { |
|
1491 | 1491 | return; |
1492 | 1492 | } |
1493 | 1493 | |
1494 | - if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) { |
|
1494 | + if (wpinv_has_active_discounts() && wpinv_get_cart_total()) { |
|
1495 | 1495 | ?> |
1496 | 1496 | <div id="wpinv-discount-field" class="panel panel-default"> |
1497 | 1497 | <div class="panel-body"> |
1498 | 1498 | <p> |
1499 | - <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label> |
|
1500 | - <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span> |
|
1499 | + <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label> |
|
1500 | + <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span> |
|
1501 | 1501 | </p> |
1502 | 1502 | <div class="form-group row"> |
1503 | 1503 | <div class="col-sm-4"> |
1504 | - <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/> |
|
1504 | + <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/> |
|
1505 | 1505 | </div> |
1506 | 1506 | <div class="col-sm-3"> |
1507 | - <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button> |
|
1507 | + <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button> |
|
1508 | 1508 | </div> |
1509 | 1509 | <div style="clear:both"></div> |
1510 | 1510 | <div class="col-sm-12 wpinv-discount-msg"> |
@@ -1517,10 +1517,10 @@ discard block |
||
1517 | 1517 | <?php |
1518 | 1518 | } |
1519 | 1519 | } |
1520 | -add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 ); |
|
1520 | +add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10); |
|
1521 | 1521 | |
1522 | 1522 | function wpinv_agree_to_terms_js() { |
1523 | - if ( wpinv_get_option( 'show_agree_to_terms', false ) ) { |
|
1523 | + if (wpinv_get_option('show_agree_to_terms', false)) { |
|
1524 | 1524 | ?> |
1525 | 1525 | <script type="text/javascript"> |
1526 | 1526 | jQuery(document).ready(function($){ |
@@ -1535,126 +1535,126 @@ discard block |
||
1535 | 1535 | <?php |
1536 | 1536 | } |
1537 | 1537 | } |
1538 | -add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' ); |
|
1538 | +add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js'); |
|
1539 | 1539 | |
1540 | 1540 | function wpinv_payment_mode_select() { |
1541 | - $gateways = wpinv_get_enabled_payment_gateways( true ); |
|
1542 | - $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways ); |
|
1541 | + $gateways = wpinv_get_enabled_payment_gateways(true); |
|
1542 | + $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways); |
|
1543 | 1543 | $page_URL = wpinv_get_current_page_url(); |
1544 | - $invoice = wpinv_get_invoice( 0, true ); |
|
1544 | + $invoice = wpinv_get_invoice(0, true); |
|
1545 | 1545 | |
1546 | 1546 | do_action('wpinv_payment_mode_top'); |
1547 | 1547 | $invoice_id = (int)$invoice->ID; |
1548 | - $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id ); |
|
1548 | + $chosen_gateway = wpinv_get_chosen_gateway($invoice_id); |
|
1549 | 1549 | ?> |
1550 | - <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ( $invoice->is_free() ? 'style="display:none;" data-free="1"' : '' ); ?>> |
|
1551 | - <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?> |
|
1550 | + <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ($invoice->is_free() ? 'style="display:none;" data-free="1"' : ''); ?>> |
|
1551 | + <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?> |
|
1552 | 1552 | <div id="wpinv-payment-mode-wrap" class="panel panel-default"> |
1553 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div> |
|
1553 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div> |
|
1554 | 1554 | <div class="panel-body list-group wpi-payment_methods"> |
1555 | 1555 | <?php |
1556 | - do_action( 'wpinv_payment_mode_before_gateways' ); |
|
1556 | + do_action('wpinv_payment_mode_before_gateways'); |
|
1557 | 1557 | |
1558 | - if ( !empty( $gateways ) ) { |
|
1559 | - foreach ( $gateways as $gateway_id => $gateway ) { |
|
1560 | - $checked = checked( $gateway_id, $chosen_gateway, false ); |
|
1561 | - $button_label = wpinv_get_gateway_button_label( $gateway_id ); |
|
1562 | - $description = wpinv_get_gateway_description( $gateway_id ); |
|
1558 | + if (!empty($gateways)) { |
|
1559 | + foreach ($gateways as $gateway_id => $gateway) { |
|
1560 | + $checked = checked($gateway_id, $chosen_gateway, false); |
|
1561 | + $button_label = wpinv_get_gateway_button_label($gateway_id); |
|
1562 | + $description = wpinv_get_gateway_description($gateway_id); |
|
1563 | 1563 | ?> |
1564 | 1564 | <div class="list-group-item"> |
1565 | 1565 | <div class="radio"> |
1566 | - <label><input type="radio" data-button-text="<?php echo esc_attr( $button_label );?>" value="<?php echo esc_attr( $gateway_id ) ;?>" <?php echo $checked ;?> id="wpi_gateway_<?php echo esc_attr( $gateway_id );?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html( $gateway['checkout_label'] ); ?></label> |
|
1566 | + <label><input type="radio" data-button-text="<?php echo esc_attr($button_label); ?>" value="<?php echo esc_attr($gateway_id); ?>" <?php echo $checked; ?> id="wpi_gateway_<?php echo esc_attr($gateway_id); ?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html($gateway['checkout_label']); ?></label> |
|
1567 | 1567 | </div> |
1568 | - <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert"> |
|
1569 | - <?php if ( !empty( $description ) ) { ?> |
|
1570 | - <div class="wpi-gateway-desc alert alert-info"><?php echo $description;?></div> |
|
1568 | + <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert"> |
|
1569 | + <?php if (!empty($description)) { ?> |
|
1570 | + <div class="wpi-gateway-desc alert alert-info"><?php echo $description; ?></div> |
|
1571 | 1571 | <?php } ?> |
1572 | - <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?> |
|
1572 | + <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?> |
|
1573 | 1573 | </div> |
1574 | 1574 | </div> |
1575 | 1575 | <?php |
1576 | 1576 | } |
1577 | 1577 | } else { |
1578 | - echo '<div class="alert alert-warning">'. __( 'No payment gateway active', 'invoicing' ) .'</div>'; |
|
1578 | + echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>'; |
|
1579 | 1579 | } |
1580 | 1580 | |
1581 | - do_action( 'wpinv_payment_mode_after_gateways' ); |
|
1581 | + do_action('wpinv_payment_mode_after_gateways'); |
|
1582 | 1582 | ?> |
1583 | 1583 | </div> |
1584 | 1584 | </div> |
1585 | - <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?> |
|
1585 | + <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?> |
|
1586 | 1586 | </div> |
1587 | 1587 | <?php |
1588 | 1588 | do_action('wpinv_payment_mode_bottom'); |
1589 | 1589 | } |
1590 | -add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' ); |
|
1590 | +add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select'); |
|
1591 | 1591 | |
1592 | 1592 | function wpinv_checkout_billing_info() { |
1593 | - if ( wpinv_is_checkout() ) { |
|
1593 | + if (wpinv_is_checkout()) { |
|
1594 | 1594 | $logged_in = is_user_logged_in(); |
1595 | 1595 | $billing_details = wpinv_checkout_billing_details(); |
1596 | - $selected_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country(); |
|
1596 | + $selected_country = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country(); |
|
1597 | 1597 | ?> |
1598 | 1598 | <div id="wpinv-fields" class="clearfix"> |
1599 | 1599 | <div id="wpi-billing" class="wpi-billing clearfix panel panel-default"> |
1600 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div> |
|
1600 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div> |
|
1601 | 1601 | <div id="wpinv-fields-box" class="panel-body"> |
1602 | - <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?> |
|
1602 | + <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?> |
|
1603 | 1603 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1604 | - <label for="wpinv_first_name" class="wpi-label"><?php _e( 'First Name', 'invoicing' );?><?php if ( wpinv_get_option( 'fname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1604 | + <label for="wpinv_first_name" class="wpi-label"><?php _e('First Name', 'invoicing'); ?><?php if (wpinv_get_option('fname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1605 | 1605 | <?php |
1606 | - echo wpinv_html_text( array( |
|
1606 | + echo wpinv_html_text(array( |
|
1607 | 1607 | 'id' => 'wpinv_first_name', |
1608 | 1608 | 'name' => 'wpinv_first_name', |
1609 | 1609 | 'value' => $billing_details['first_name'], |
1610 | 1610 | 'class' => 'wpi-input form-control', |
1611 | - 'placeholder' => __( 'First name', 'invoicing' ), |
|
1612 | - 'required' => (bool)wpinv_get_option( 'fname_mandatory' ), |
|
1613 | - ) ); |
|
1611 | + 'placeholder' => __('First name', 'invoicing'), |
|
1612 | + 'required' => (bool)wpinv_get_option('fname_mandatory'), |
|
1613 | + )); |
|
1614 | 1614 | ?> |
1615 | 1615 | </p> |
1616 | 1616 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
1617 | - <label for="wpinv_last_name" class="wpi-label"><?php _e( 'Last Name', 'invoicing' );?><?php if ( wpinv_get_option( 'lname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1617 | + <label for="wpinv_last_name" class="wpi-label"><?php _e('Last Name', 'invoicing'); ?><?php if (wpinv_get_option('lname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1618 | 1618 | <?php |
1619 | - echo wpinv_html_text( array( |
|
1619 | + echo wpinv_html_text(array( |
|
1620 | 1620 | 'id' => 'wpinv_last_name', |
1621 | 1621 | 'name' => 'wpinv_last_name', |
1622 | 1622 | 'value' => $billing_details['last_name'], |
1623 | 1623 | 'class' => 'wpi-input form-control', |
1624 | - 'placeholder' => __( 'Last name', 'invoicing' ), |
|
1625 | - 'required' => (bool)wpinv_get_option( 'lname_mandatory' ), |
|
1626 | - ) ); |
|
1624 | + 'placeholder' => __('Last name', 'invoicing'), |
|
1625 | + 'required' => (bool)wpinv_get_option('lname_mandatory'), |
|
1626 | + )); |
|
1627 | 1627 | ?> |
1628 | 1628 | </p> |
1629 | 1629 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1630 | - <label for="wpinv_address" class="wpi-label"><?php _e( 'Address', 'invoicing' );?><?php if ( wpinv_get_option( 'address_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1630 | + <label for="wpinv_address" class="wpi-label"><?php _e('Address', 'invoicing'); ?><?php if (wpinv_get_option('address_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1631 | 1631 | <?php |
1632 | - echo wpinv_html_text( array( |
|
1632 | + echo wpinv_html_text(array( |
|
1633 | 1633 | 'id' => 'wpinv_address', |
1634 | 1634 | 'name' => 'wpinv_address', |
1635 | 1635 | 'value' => $billing_details['address'], |
1636 | 1636 | 'class' => 'wpi-input form-control', |
1637 | - 'placeholder' => __( 'Address', 'invoicing' ), |
|
1638 | - 'required' => (bool)wpinv_get_option( 'address_mandatory' ), |
|
1639 | - ) ); |
|
1637 | + 'placeholder' => __('Address', 'invoicing'), |
|
1638 | + 'required' => (bool)wpinv_get_option('address_mandatory'), |
|
1639 | + )); |
|
1640 | 1640 | ?> |
1641 | 1641 | </p> |
1642 | 1642 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
1643 | - <label for="wpinv_city" class="wpi-label"><?php _e( 'City', 'invoicing' );?><?php if ( wpinv_get_option( 'city_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1643 | + <label for="wpinv_city" class="wpi-label"><?php _e('City', 'invoicing'); ?><?php if (wpinv_get_option('city_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1644 | 1644 | <?php |
1645 | - echo wpinv_html_text( array( |
|
1645 | + echo wpinv_html_text(array( |
|
1646 | 1646 | 'id' => 'wpinv_city', |
1647 | 1647 | 'name' => 'wpinv_city', |
1648 | 1648 | 'value' => $billing_details['city'], |
1649 | 1649 | 'class' => 'wpi-input form-control', |
1650 | - 'placeholder' => __( 'City', 'invoicing' ), |
|
1651 | - 'required' => (bool)wpinv_get_option( 'city_mandatory' ), |
|
1652 | - ) ); |
|
1650 | + 'placeholder' => __('City', 'invoicing'), |
|
1651 | + 'required' => (bool)wpinv_get_option('city_mandatory'), |
|
1652 | + )); |
|
1653 | 1653 | ?> |
1654 | 1654 | </p> |
1655 | 1655 | <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf"> |
1656 | - <label for="wpinv_country" class="wpi-label"><?php _e( 'Country', 'invoicing' );?><?php if ( wpinv_get_option( 'country_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1657 | - <?php echo wpinv_html_select( array( |
|
1656 | + <label for="wpinv_country" class="wpi-label"><?php _e('Country', 'invoicing'); ?><?php if (wpinv_get_option('country_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1657 | + <?php echo wpinv_html_select(array( |
|
1658 | 1658 | 'options' => wpinv_get_country_list(), |
1659 | 1659 | 'name' => 'wpinv_country', |
1660 | 1660 | 'id' => 'wpinv_country', |
@@ -1662,16 +1662,16 @@ discard block |
||
1662 | 1662 | 'show_option_all' => false, |
1663 | 1663 | 'show_option_none' => false, |
1664 | 1664 | 'class' => 'wpi-input form-control', |
1665 | - 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
1666 | - 'required' => (bool)wpinv_get_option( 'country_mandatory' ), |
|
1667 | - ) ); ?> |
|
1665 | + 'placeholder' => __('Choose a country', 'invoicing'), |
|
1666 | + 'required' => (bool)wpinv_get_option('country_mandatory'), |
|
1667 | + )); ?> |
|
1668 | 1668 | </p> |
1669 | 1669 | <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll"> |
1670 | - <label for="wpinv_state" class="wpi-label"><?php _e( 'State / Province', 'invoicing' );?><?php if ( wpinv_get_option( 'state_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1670 | + <label for="wpinv_state" class="wpi-label"><?php _e('State / Province', 'invoicing'); ?><?php if (wpinv_get_option('state_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1671 | 1671 | <?php |
1672 | - $states = wpinv_get_country_states( $selected_country ); |
|
1673 | - if( !empty( $states ) ) { |
|
1674 | - echo wpinv_html_select( array( |
|
1672 | + $states = wpinv_get_country_states($selected_country); |
|
1673 | + if (!empty($states)) { |
|
1674 | + echo wpinv_html_select(array( |
|
1675 | 1675 | 'options' => $states, |
1676 | 1676 | 'name' => 'wpinv_state', |
1677 | 1677 | 'id' => 'wpinv_state', |
@@ -1679,61 +1679,61 @@ discard block |
||
1679 | 1679 | 'show_option_all' => false, |
1680 | 1680 | 'show_option_none' => false, |
1681 | 1681 | 'class' => 'wpi-input form-control', |
1682 | - 'placeholder' => __( 'Choose a state', 'invoicing' ), |
|
1683 | - 'required' => (bool)wpinv_get_option( 'state_mandatory' ), |
|
1684 | - ) ); |
|
1682 | + 'placeholder' => __('Choose a state', 'invoicing'), |
|
1683 | + 'required' => (bool)wpinv_get_option('state_mandatory'), |
|
1684 | + )); |
|
1685 | 1685 | } else { |
1686 | - echo wpinv_html_text( array( |
|
1686 | + echo wpinv_html_text(array( |
|
1687 | 1687 | 'name' => 'wpinv_state', |
1688 | 1688 | 'value' => $billing_details['state'], |
1689 | 1689 | 'id' => 'wpinv_state', |
1690 | 1690 | 'class' => 'wpi-input form-control', |
1691 | - 'placeholder' => __( 'State / Province', 'invoicing' ), |
|
1692 | - 'required' => (bool)wpinv_get_option( 'state_mandatory' ), |
|
1693 | - ) ); |
|
1691 | + 'placeholder' => __('State / Province', 'invoicing'), |
|
1692 | + 'required' => (bool)wpinv_get_option('state_mandatory'), |
|
1693 | + )); |
|
1694 | 1694 | } |
1695 | 1695 | ?> |
1696 | 1696 | </p> |
1697 | 1697 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1698 | - <label for="wpinv_zip" class="wpi-label"><?php _e( 'ZIP / Postcode', 'invoicing' );?><?php if ( wpinv_get_option( 'zip_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1698 | + <label for="wpinv_zip" class="wpi-label"><?php _e('ZIP / Postcode', 'invoicing'); ?><?php if (wpinv_get_option('zip_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1699 | 1699 | <?php |
1700 | - echo wpinv_html_text( array( |
|
1700 | + echo wpinv_html_text(array( |
|
1701 | 1701 | 'name' => 'wpinv_zip', |
1702 | 1702 | 'value' => $billing_details['zip'], |
1703 | 1703 | 'id' => 'wpinv_zip', |
1704 | 1704 | 'class' => 'wpi-input form-control', |
1705 | - 'placeholder' => __( 'ZIP / Postcode', 'invoicing' ), |
|
1706 | - 'required' => (bool)wpinv_get_option( 'zip_mandatory' ), |
|
1707 | - ) ); |
|
1705 | + 'placeholder' => __('ZIP / Postcode', 'invoicing'), |
|
1706 | + 'required' => (bool)wpinv_get_option('zip_mandatory'), |
|
1707 | + )); |
|
1708 | 1708 | ?> |
1709 | 1709 | </p> |
1710 | 1710 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
1711 | - <label for="wpinv_phone" class="wpi-label"><?php _e( 'Phone', 'invoicing' );?><?php if ( wpinv_get_option( 'phone_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1711 | + <label for="wpinv_phone" class="wpi-label"><?php _e('Phone', 'invoicing'); ?><?php if (wpinv_get_option('phone_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1712 | 1712 | <?php |
1713 | - echo wpinv_html_text( array( |
|
1713 | + echo wpinv_html_text(array( |
|
1714 | 1714 | 'id' => 'wpinv_phone', |
1715 | 1715 | 'name' => 'wpinv_phone', |
1716 | 1716 | 'value' => $billing_details['phone'], |
1717 | 1717 | 'class' => 'wpi-input form-control', |
1718 | - 'placeholder' => __( 'Phone', 'invoicing' ), |
|
1719 | - 'required' => (bool)wpinv_get_option( 'phone_mandatory' ), |
|
1720 | - ) ); |
|
1718 | + 'placeholder' => __('Phone', 'invoicing'), |
|
1719 | + 'required' => (bool)wpinv_get_option('phone_mandatory'), |
|
1720 | + )); |
|
1721 | 1721 | ?> |
1722 | 1722 | </p> |
1723 | - <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?> |
|
1723 | + <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?> |
|
1724 | 1724 | <div class="clearfix"></div> |
1725 | 1725 | </div> |
1726 | 1726 | </div> |
1727 | - <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?> |
|
1727 | + <?php do_action('wpinv_after_billing_fields', $billing_details); ?> |
|
1728 | 1728 | </div> |
1729 | 1729 | <?php |
1730 | 1730 | } |
1731 | 1731 | } |
1732 | -add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' ); |
|
1732 | +add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info'); |
|
1733 | 1733 | |
1734 | 1734 | function wpinv_checkout_hidden_fields() { |
1735 | 1735 | ?> |
1736 | - <?php if ( is_user_logged_in() ) { ?> |
|
1736 | + <?php if (is_user_logged_in()) { ?> |
|
1737 | 1737 | <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/> |
1738 | 1738 | <?php } ?> |
1739 | 1739 | <input type="hidden" name="wpi_action" value="payment" /> |
@@ -1743,9 +1743,9 @@ discard block |
||
1743 | 1743 | function wpinv_checkout_button_purchase() { |
1744 | 1744 | ob_start(); |
1745 | 1745 | ?> |
1746 | - <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>" name="wpinv_payment" value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>"/> |
|
1746 | + <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>" name="wpinv_payment" value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>"/> |
|
1747 | 1747 | <?php |
1748 | - return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() ); |
|
1748 | + return apply_filters('wpinv_checkout_button_purchase', ob_get_clean()); |
|
1749 | 1749 | } |
1750 | 1750 | |
1751 | 1751 | function wpinv_checkout_total() { |
@@ -1754,96 +1754,96 @@ discard block |
||
1754 | 1754 | <div id="wpinv_checkout_total" class="panel panel-info"> |
1755 | 1755 | <div class="panel-body"> |
1756 | 1756 | <?php |
1757 | - do_action( 'wpinv_purchase_form_before_checkout_total' ); |
|
1757 | + do_action('wpinv_purchase_form_before_checkout_total'); |
|
1758 | 1758 | ?> |
1759 | - <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span> |
|
1759 | + <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span> |
|
1760 | 1760 | <?php |
1761 | - do_action( 'wpinv_purchase_form_after_checkout_total' ); |
|
1761 | + do_action('wpinv_purchase_form_after_checkout_total'); |
|
1762 | 1762 | ?> |
1763 | 1763 | </div> |
1764 | 1764 | </div> |
1765 | 1765 | <?php |
1766 | 1766 | } |
1767 | -add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 ); |
|
1767 | +add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998); |
|
1768 | 1768 | |
1769 | 1769 | function wpinv_checkout_submit() { |
1770 | 1770 | ?> |
1771 | 1771 | <div id="wpinv_purchase_submit" class="panel panel-success"> |
1772 | 1772 | <div class="panel-body text-center"> |
1773 | 1773 | <?php |
1774 | - do_action( 'wpinv_purchase_form_before_submit' ); |
|
1774 | + do_action('wpinv_purchase_form_before_submit'); |
|
1775 | 1775 | wpinv_checkout_hidden_fields(); |
1776 | 1776 | echo wpinv_checkout_button_purchase(); |
1777 | - do_action( 'wpinv_purchase_form_after_submit' ); |
|
1777 | + do_action('wpinv_purchase_form_after_submit'); |
|
1778 | 1778 | ?> |
1779 | 1779 | </div> |
1780 | 1780 | </div> |
1781 | 1781 | <?php |
1782 | 1782 | } |
1783 | -add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 ); |
|
1783 | +add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999); |
|
1784 | 1784 | |
1785 | -function wpinv_receipt_billing_address( $invoice_id = 0 ) { |
|
1786 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1785 | +function wpinv_receipt_billing_address($invoice_id = 0) { |
|
1786 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1787 | 1787 | |
1788 | - if ( empty( $invoice ) ) { |
|
1788 | + if (empty($invoice)) { |
|
1789 | 1789 | return NULL; |
1790 | 1790 | } |
1791 | 1791 | |
1792 | 1792 | $billing_details = $invoice->get_user_info(); |
1793 | 1793 | $address_row = ''; |
1794 | - if ( $address = $billing_details['address'] ) { |
|
1795 | - $address_row .= wpautop( wp_kses_post( $address ) ); |
|
1794 | + if ($address = $billing_details['address']) { |
|
1795 | + $address_row .= wpautop(wp_kses_post($address)); |
|
1796 | 1796 | } |
1797 | 1797 | |
1798 | 1798 | $address_fields = array(); |
1799 | - if ( !empty( $billing_details['city'] ) ) { |
|
1799 | + if (!empty($billing_details['city'])) { |
|
1800 | 1800 | $address_fields[] = $billing_details['city']; |
1801 | 1801 | } |
1802 | 1802 | |
1803 | - $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : ''; |
|
1804 | - if ( !empty( $billing_details['state'] ) ) { |
|
1805 | - $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country ); |
|
1803 | + $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : ''; |
|
1804 | + if (!empty($billing_details['state'])) { |
|
1805 | + $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country); |
|
1806 | 1806 | } |
1807 | 1807 | |
1808 | - if ( !empty( $billing_country ) ) { |
|
1809 | - $address_fields[] = wpinv_country_name( $billing_country ); |
|
1808 | + if (!empty($billing_country)) { |
|
1809 | + $address_fields[] = wpinv_country_name($billing_country); |
|
1810 | 1810 | } |
1811 | 1811 | |
1812 | - if ( !empty( $address_fields ) ) { |
|
1813 | - $address_fields = implode( ", ", $address_fields ); |
|
1812 | + if (!empty($address_fields)) { |
|
1813 | + $address_fields = implode(", ", $address_fields); |
|
1814 | 1814 | |
1815 | - if ( !empty( $billing_details['zip'] ) ) { |
|
1815 | + if (!empty($billing_details['zip'])) { |
|
1816 | 1816 | $address_fields .= ' ' . $billing_details['zip']; |
1817 | 1817 | } |
1818 | 1818 | |
1819 | - $address_row .= wpautop( wp_kses_post( $address_fields ) ); |
|
1819 | + $address_row .= wpautop(wp_kses_post($address_fields)); |
|
1820 | 1820 | } |
1821 | 1821 | ob_start(); |
1822 | 1822 | ?> |
1823 | 1823 | <table class="table table-bordered table-sm wpi-billing-details"> |
1824 | 1824 | <tbody> |
1825 | 1825 | <tr class="wpi-receipt-name"> |
1826 | - <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th> |
|
1827 | - <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td> |
|
1826 | + <th class="text-left"><?php _e('Name', 'invoicing'); ?></th> |
|
1827 | + <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td> |
|
1828 | 1828 | </tr> |
1829 | 1829 | <tr class="wpi-receipt-email"> |
1830 | - <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th> |
|
1831 | - <td><?php echo $billing_details['email'] ;?></td> |
|
1830 | + <th class="text-left"><?php _e('Email', 'invoicing'); ?></th> |
|
1831 | + <td><?php echo $billing_details['email']; ?></td> |
|
1832 | 1832 | </tr> |
1833 | - <?php if ( $billing_details['company'] ) { ?> |
|
1833 | + <?php if ($billing_details['company']) { ?> |
|
1834 | 1834 | <tr class="wpi-receipt-company"> |
1835 | - <th class="text-left"><?php _e( 'Company', 'invoicing' ); ?></th> |
|
1836 | - <td><?php echo esc_html( $billing_details['company'] ) ;?></td> |
|
1835 | + <th class="text-left"><?php _e('Company', 'invoicing'); ?></th> |
|
1836 | + <td><?php echo esc_html($billing_details['company']); ?></td> |
|
1837 | 1837 | </tr> |
1838 | 1838 | <?php } ?> |
1839 | 1839 | <tr class="wpi-receipt-address"> |
1840 | - <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th> |
|
1841 | - <td><?php echo $address_row ;?></td> |
|
1840 | + <th class="text-left"><?php _e('Address', 'invoicing'); ?></th> |
|
1841 | + <td><?php echo $address_row; ?></td> |
|
1842 | 1842 | </tr> |
1843 | - <?php if ( $billing_details['phone'] ) { ?> |
|
1843 | + <?php if ($billing_details['phone']) { ?> |
|
1844 | 1844 | <tr class="wpi-receipt-phone"> |
1845 | - <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th> |
|
1846 | - <td><?php echo esc_html( $billing_details['phone'] ) ;?></td> |
|
1845 | + <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th> |
|
1846 | + <td><?php echo esc_html($billing_details['phone']); ?></td> |
|
1847 | 1847 | </tr> |
1848 | 1848 | <?php } ?> |
1849 | 1849 | </tbody> |
@@ -1851,76 +1851,76 @@ discard block |
||
1851 | 1851 | <?php |
1852 | 1852 | $output = ob_get_clean(); |
1853 | 1853 | |
1854 | - $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id ); |
|
1854 | + $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id); |
|
1855 | 1855 | |
1856 | 1856 | echo $output; |
1857 | 1857 | } |
1858 | 1858 | |
1859 | -function wpinv_filter_success_page_content( $content ) { |
|
1860 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
1861 | - if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) { |
|
1862 | - $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content ); |
|
1859 | +function wpinv_filter_success_page_content($content) { |
|
1860 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
1861 | + if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) { |
|
1862 | + $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content); |
|
1863 | 1863 | } |
1864 | 1864 | } |
1865 | 1865 | |
1866 | 1866 | return $content; |
1867 | 1867 | } |
1868 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
1868 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
1869 | 1869 | |
1870 | -function wpinv_receipt_actions( $invoice ) { |
|
1871 | - if ( !empty( $invoice ) ) { |
|
1870 | +function wpinv_receipt_actions($invoice) { |
|
1871 | + if (!empty($invoice)) { |
|
1872 | 1872 | $actions = array(); |
1873 | 1873 | |
1874 | - if ( wpinv_user_can_view_invoice( $invoice->ID ) ) { |
|
1875 | - $actions['print'] = array( |
|
1876 | - 'url' => $invoice->get_view_url( true ), |
|
1877 | - 'name' => __( 'Print Invoice', 'invoicing' ), |
|
1874 | + if (wpinv_user_can_view_invoice($invoice->ID)) { |
|
1875 | + $actions['print'] = array( |
|
1876 | + 'url' => $invoice->get_view_url(true), |
|
1877 | + 'name' => __('Print Invoice', 'invoicing'), |
|
1878 | 1878 | 'class' => 'btn-primary', |
1879 | 1879 | ); |
1880 | 1880 | } |
1881 | 1881 | |
1882 | - if ( is_user_logged_in() ) { |
|
1882 | + if (is_user_logged_in()) { |
|
1883 | 1883 | $actions['history'] = array( |
1884 | 1884 | 'url' => wpinv_get_history_page_uri(), |
1885 | - 'name' => __( 'Invoice History', 'invoicing' ), |
|
1885 | + 'name' => __('Invoice History', 'invoicing'), |
|
1886 | 1886 | 'class' => 'btn-warning', |
1887 | 1887 | ); |
1888 | 1888 | } |
1889 | 1889 | |
1890 | - $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice ); |
|
1890 | + $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice); |
|
1891 | 1891 | |
1892 | - if ( !empty( $actions ) ) { |
|
1892 | + if (!empty($actions)) { |
|
1893 | 1893 | ?> |
1894 | 1894 | <div class="wpinv-receipt-actions text-right"> |
1895 | - <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?> |
|
1896 | - <a href="<?php echo esc_url( $action['url'] );?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class( $key );?>" <?php echo ( !empty($action['attrs']) ? $action['attrs'] : '' ) ;?>><?php echo esc_html( $action['name'] );?></a> |
|
1895 | + <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?> |
|
1896 | + <a href="<?php echo esc_url($action['url']); ?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class($key); ?>" <?php echo (!empty($action['attrs']) ? $action['attrs'] : ''); ?>><?php echo esc_html($action['name']); ?></a> |
|
1897 | 1897 | <?php } ?> |
1898 | 1898 | </div> |
1899 | 1899 | <?php |
1900 | 1900 | } |
1901 | 1901 | } |
1902 | 1902 | } |
1903 | -add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 ); |
|
1903 | +add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1); |
|
1904 | 1904 | |
1905 | -function wpinv_invoice_link( $invoice_id ) { |
|
1906 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1905 | +function wpinv_invoice_link($invoice_id) { |
|
1906 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1907 | 1907 | |
1908 | - if ( empty( $invoice ) ) { |
|
1908 | + if (empty($invoice)) { |
|
1909 | 1909 | return NULL; |
1910 | 1910 | } |
1911 | 1911 | |
1912 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
1912 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
1913 | 1913 | |
1914 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
1914 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
1915 | 1915 | } |
1916 | 1916 | |
1917 | -function wpinv_invoice_subscription_details( $invoice ) { |
|
1918 | - if ( !empty( $invoice ) && $invoice->is_recurring() && !wpinv_is_subscription_payment( $invoice ) ) { |
|
1917 | +function wpinv_invoice_subscription_details($invoice) { |
|
1918 | + if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) { |
|
1919 | 1919 | $subs_db = new WPInv_Subscriptions_DB; |
1920 | 1920 | $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice->ID, 'number' => 1)); |
1921 | 1921 | $sub = reset($subs); |
1922 | 1922 | |
1923 | - if ( empty( $sub ) ) { |
|
1923 | + if (empty($sub)) { |
|
1924 | 1924 | return; |
1925 | 1925 | } |
1926 | 1926 | |
@@ -1931,15 +1931,15 @@ discard block |
||
1931 | 1931 | $payments = $sub->get_child_payments(); |
1932 | 1932 | ?> |
1933 | 1933 | <div class="wpinv-subscriptions-details"> |
1934 | - <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3> |
|
1934 | + <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3> |
|
1935 | 1935 | <table class="table"> |
1936 | 1936 | <thead> |
1937 | 1937 | <tr> |
1938 | - <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th> |
|
1939 | - <th><?php _e( 'Start Date', 'invoicing' ) ;?></th> |
|
1940 | - <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th> |
|
1941 | - <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th> |
|
1942 | - <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th> |
|
1938 | + <th><?php _e('Billing Cycle', 'invoicing'); ?></th> |
|
1939 | + <th><?php _e('Start Date', 'invoicing'); ?></th> |
|
1940 | + <th><?php _e('Expiration Date', 'invoicing'); ?></th> |
|
1941 | + <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th> |
|
1942 | + <th class="text-center"><?php _e('Status', 'invoicing'); ?></th> |
|
1943 | 1943 | </tr> |
1944 | 1944 | </thead> |
1945 | 1945 | <tbody> |
@@ -1954,29 +1954,29 @@ discard block |
||
1954 | 1954 | </tbody> |
1955 | 1955 | </table> |
1956 | 1956 | </div> |
1957 | - <?php if ( !empty( $payments ) ) { ?> |
|
1957 | + <?php if (!empty($payments)) { ?> |
|
1958 | 1958 | <div class="wpinv-renewal-payments"> |
1959 | - <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3> |
|
1959 | + <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3> |
|
1960 | 1960 | <table class="table"> |
1961 | 1961 | <thead> |
1962 | 1962 | <tr> |
1963 | 1963 | <th>#</th> |
1964 | - <th><?php _e( 'Invoice', 'invoicing' ) ;?></th> |
|
1965 | - <th><?php _e( 'Date', 'invoicing' ) ;?></th> |
|
1966 | - <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th> |
|
1964 | + <th><?php _e('Invoice', 'invoicing'); ?></th> |
|
1965 | + <th><?php _e('Date', 'invoicing'); ?></th> |
|
1966 | + <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th> |
|
1967 | 1967 | </tr> |
1968 | 1968 | </thead> |
1969 | 1969 | <tbody> |
1970 | 1970 | <?php |
1971 | 1971 | $i = 1; |
1972 | - foreach ( $payments as $payment ) { |
|
1972 | + foreach ($payments as $payment) { |
|
1973 | 1973 | $invoice_id = $payment->ID; |
1974 | 1974 | ?> |
1975 | 1975 | <tr> |
1976 | - <th scope="row"><?php echo $i;?></th> |
|
1977 | - <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td> |
|
1978 | - <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td> |
|
1979 | - <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td> |
|
1976 | + <th scope="row"><?php echo $i; ?></th> |
|
1977 | + <td><?php echo wpinv_invoice_link($invoice_id); ?></td> |
|
1978 | + <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td> |
|
1979 | + <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td> |
|
1980 | 1980 | </tr> |
1981 | 1981 | <?php $i++; } ?> |
1982 | 1982 | <tr><td colspan="4" style="padding:0"></td></tr> |
@@ -1988,52 +1988,52 @@ discard block |
||
1988 | 1988 | } |
1989 | 1989 | } |
1990 | 1990 | |
1991 | -function wpinv_cart_total_label( $label, $invoice ) { |
|
1992 | - if ( empty( $invoice ) ) { |
|
1991 | +function wpinv_cart_total_label($label, $invoice) { |
|
1992 | + if (empty($invoice)) { |
|
1993 | 1993 | return $label; |
1994 | 1994 | } |
1995 | 1995 | |
1996 | 1996 | $prefix_label = ''; |
1997 | - if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) { |
|
1998 | - $prefix_label = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice ); |
|
1999 | - } else if ( $invoice->is_renewal() ) { |
|
2000 | - $prefix_label = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> '; |
|
1997 | + if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) { |
|
1998 | + $prefix_label = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice); |
|
1999 | + } else if ($invoice->is_renewal()) { |
|
2000 | + $prefix_label = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> '; |
|
2001 | 2001 | } |
2002 | 2002 | |
2003 | - if ( $prefix_label != '' ) { |
|
2004 | - $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
2003 | + if ($prefix_label != '') { |
|
2004 | + $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
2005 | 2005 | } |
2006 | 2006 | |
2007 | 2007 | return $label; |
2008 | 2008 | } |
2009 | -add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
2010 | -add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
2011 | -add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
2009 | +add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
2010 | +add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
2011 | +add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
2012 | 2012 | |
2013 | -add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 ); |
|
2013 | +add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1); |
|
2014 | 2014 | |
2015 | -function wpinv_invoice_print_description( $invoice ) { |
|
2016 | - if ( empty( $invoice ) ) { |
|
2015 | +function wpinv_invoice_print_description($invoice) { |
|
2016 | + if (empty($invoice)) { |
|
2017 | 2017 | return NULL; |
2018 | 2018 | } |
2019 | - if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) { |
|
2019 | + if ($description = wpinv_get_invoice_description($invoice->ID)) { |
|
2020 | 2020 | ?> |
2021 | 2021 | <div class="row wpinv-lower"> |
2022 | 2022 | <div class="col-sm-12 wpinv-description"> |
2023 | - <?php echo wpautop( $description ); ?> |
|
2023 | + <?php echo wpautop($description); ?> |
|
2024 | 2024 | </div> |
2025 | 2025 | </div> |
2026 | 2026 | <?php |
2027 | 2027 | } |
2028 | 2028 | } |
2029 | -add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 ); |
|
2029 | +add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1); |
|
2030 | 2030 | |
2031 | -function wpinv_invoice_print_payment_info( $invoice ) { |
|
2032 | - if ( empty( $invoice ) ) { |
|
2031 | +function wpinv_invoice_print_payment_info($invoice) { |
|
2032 | + if (empty($invoice)) { |
|
2033 | 2033 | return NULL; |
2034 | 2034 | } |
2035 | 2035 | |
2036 | - if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) { |
|
2036 | + if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) { |
|
2037 | 2037 | ?> |
2038 | 2038 | <div class="row wpinv-payments"> |
2039 | 2039 | <div class="col-sm-12"> |
@@ -2045,43 +2045,43 @@ discard block |
||
2045 | 2045 | } |
2046 | 2046 | // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 ); |
2047 | 2047 | |
2048 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
2049 | - if ( empty( $note ) ) { |
|
2048 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
2049 | + if (empty($note)) { |
|
2050 | 2050 | return NULL; |
2051 | 2051 | } |
2052 | 2052 | |
2053 | - if ( is_int( $note ) ) { |
|
2054 | - $note = get_comment( $note ); |
|
2053 | + if (is_int($note)) { |
|
2054 | + $note = get_comment($note); |
|
2055 | 2055 | } |
2056 | 2056 | |
2057 | - if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
2057 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
2058 | 2058 | return NULL; |
2059 | 2059 | } |
2060 | 2060 | |
2061 | - $note_classes = array( 'note' ); |
|
2062 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
2061 | + $note_classes = array('note'); |
|
2062 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
2063 | 2063 | $note_classes[] = $note->comment_author === 'System' ? 'system-note' : ''; |
2064 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
2065 | - $note_classes = !empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
2064 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
2065 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
2066 | 2066 | |
2067 | 2067 | ob_start(); |
2068 | 2068 | ?> |
2069 | - <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>"> |
|
2069 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>"> |
|
2070 | 2070 | <div class="note_content"> |
2071 | - <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?> |
|
2071 | + <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?> |
|
2072 | 2072 | </div> |
2073 | 2073 | <p class="meta"> |
2074 | - <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr> |
|
2075 | - <?php if ( $note->comment_author !== 'System' || current_user_can( 'manage_options' ) ) { ?> |
|
2076 | - <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a> |
|
2074 | + <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr> |
|
2075 | + <?php if ($note->comment_author !== 'System' || current_user_can('manage_options')) { ?> |
|
2076 | + <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a> |
|
2077 | 2077 | <?php } ?> |
2078 | 2078 | </p> |
2079 | 2079 | </li> |
2080 | 2080 | <?php |
2081 | 2081 | $note_content = ob_get_clean(); |
2082 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
2082 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
2083 | 2083 | |
2084 | - if ( $echo ) { |
|
2084 | + if ($echo) { |
|
2085 | 2085 | echo $note_content; |
2086 | 2086 | } else { |
2087 | 2087 | return $note_content; |
@@ -2091,33 +2091,33 @@ discard block |
||
2091 | 2091 | function wpinv_invalid_invoice_content() { |
2092 | 2092 | global $post; |
2093 | 2093 | |
2094 | - $invoice = wpinv_get_invoice( $post->ID ); |
|
2094 | + $invoice = wpinv_get_invoice($post->ID); |
|
2095 | 2095 | |
2096 | - $error = __( 'This invoice is only viewable by clicking on the invoice link that sent to you via email.', 'invoicing' ); |
|
2097 | - if ( !empty( $invoice->ID ) && $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) { |
|
2098 | - if ( is_user_logged_in() ) { |
|
2099 | - if ( wpinv_require_login_to_checkout() ) { |
|
2100 | - if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
2101 | - $error = __( 'You are not allowed to view this invoice.', 'invoicing' ); |
|
2096 | + $error = __('This invoice is only viewable by clicking on the invoice link that sent to you via email.', 'invoicing'); |
|
2097 | + if (!empty($invoice->ID) && $invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) { |
|
2098 | + if (is_user_logged_in()) { |
|
2099 | + if (wpinv_require_login_to_checkout()) { |
|
2100 | + if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
2101 | + $error = __('You are not allowed to view this invoice.', 'invoicing'); |
|
2102 | 2102 | } |
2103 | 2103 | } |
2104 | 2104 | } else { |
2105 | - if ( wpinv_require_login_to_checkout() ) { |
|
2106 | - if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
2107 | - $error = __( 'You must be logged in to view this invoice.', 'invoicing' ); |
|
2105 | + if (wpinv_require_login_to_checkout()) { |
|
2106 | + if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
2107 | + $error = __('You must be logged in to view this invoice.', 'invoicing'); |
|
2108 | 2108 | } |
2109 | 2109 | } |
2110 | 2110 | } |
2111 | 2111 | } else { |
2112 | - $error = __( 'This invoice is deleted or does not exist.', 'invoicing' ); |
|
2112 | + $error = __('This invoice is deleted or does not exist.', 'invoicing'); |
|
2113 | 2113 | } |
2114 | 2114 | ?> |
2115 | 2115 | <div class="row wpinv-row-invalid"> |
2116 | 2116 | <div class="col-md-6 col-md-offset-3 wpinv-message error"> |
2117 | - <h3><?php _e( 'Access Denied', 'invoicing' ); ?></h3> |
|
2117 | + <h3><?php _e('Access Denied', 'invoicing'); ?></h3> |
|
2118 | 2118 | <p class="wpinv-msg-text"><?php echo $error; ?></p> |
2119 | 2119 | </div> |
2120 | 2120 | </div> |
2121 | 2121 | <?php |
2122 | 2122 | } |
2123 | -add_action( 'wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content' ); |
|
2124 | 2123 | \ No newline at end of file |
2124 | +add_action('wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content'); |
|
2125 | 2125 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Exit if accessed directly |
4 | -if ( ! defined( 'ABSPATH' ) ) { |
|
4 | +if (!defined('ABSPATH')) { |
|
5 | 5 | exit; |
6 | 6 | } |
7 | 7 | |
@@ -38,15 +38,15 @@ discard block |
||
38 | 38 | * @since 1.0.0 |
39 | 39 | * @return void |
40 | 40 | */ |
41 | - function __construct( $_id_or_object = 0, $_by_profile_id = false ) { |
|
41 | + function __construct($_id_or_object = 0, $_by_profile_id = false) { |
|
42 | 42 | |
43 | 43 | $this->subs_db = new WPInv_Subscriptions_DB; |
44 | 44 | |
45 | - if( $_by_profile_id ) { |
|
45 | + if ($_by_profile_id) { |
|
46 | 46 | |
47 | - $_sub = $this->subs_db->get_by( 'profile_id', $_id_or_object ); |
|
47 | + $_sub = $this->subs_db->get_by('profile_id', $_id_or_object); |
|
48 | 48 | |
49 | - if( empty( $_sub ) ) { |
|
49 | + if (empty($_sub)) { |
|
50 | 50 | return false; |
51 | 51 | } |
52 | 52 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | |
55 | 55 | } |
56 | 56 | |
57 | - return $this->setup_subscription( $_id_or_object ); |
|
57 | + return $this->setup_subscription($_id_or_object); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -63,34 +63,34 @@ discard block |
||
63 | 63 | * @since 1.0.0 |
64 | 64 | * @return void |
65 | 65 | */ |
66 | - private function setup_subscription( $id_or_object = 0 ) { |
|
66 | + private function setup_subscription($id_or_object = 0) { |
|
67 | 67 | |
68 | - if( empty( $id_or_object ) ) { |
|
68 | + if (empty($id_or_object)) { |
|
69 | 69 | return false; |
70 | 70 | } |
71 | 71 | |
72 | - if( is_numeric( $id_or_object ) ) { |
|
72 | + if (is_numeric($id_or_object)) { |
|
73 | 73 | |
74 | - $sub = $this->subs_db->get( $id_or_object ); |
|
74 | + $sub = $this->subs_db->get($id_or_object); |
|
75 | 75 | |
76 | - } elseif( is_object( $id_or_object ) ) { |
|
76 | + } elseif (is_object($id_or_object)) { |
|
77 | 77 | |
78 | 78 | $sub = $id_or_object; |
79 | 79 | |
80 | 80 | } |
81 | 81 | |
82 | - if( empty( $sub ) ) { |
|
82 | + if (empty($sub)) { |
|
83 | 83 | return false; |
84 | 84 | } |
85 | 85 | |
86 | - foreach( $sub as $key => $value ) { |
|
86 | + foreach ($sub as $key => $value) { |
|
87 | 87 | $this->$key = $value; |
88 | 88 | } |
89 | 89 | |
90 | - $this->customer = get_userdata( $this->customer_id ); |
|
91 | - $this->gateway = wpinv_get_payment_gateway( $this->parent_payment_id ); |
|
90 | + $this->customer = get_userdata($this->customer_id); |
|
91 | + $this->gateway = wpinv_get_payment_gateway($this->parent_payment_id); |
|
92 | 92 | |
93 | - do_action( 'wpinv_recurring_setup_subscription', $this ); |
|
93 | + do_action('wpinv_recurring_setup_subscription', $this); |
|
94 | 94 | |
95 | 95 | return $this; |
96 | 96 | } |
@@ -100,15 +100,15 @@ discard block |
||
100 | 100 | * |
101 | 101 | * @since 1.0.0 |
102 | 102 | */ |
103 | - public function __get( $key ) { |
|
103 | + public function __get($key) { |
|
104 | 104 | |
105 | - if( method_exists( $this, 'get_' . $key ) ) { |
|
105 | + if (method_exists($this, 'get_' . $key)) { |
|
106 | 106 | |
107 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
107 | + return call_user_func(array($this, 'get_' . $key)); |
|
108 | 108 | |
109 | 109 | } else { |
110 | 110 | |
111 | - return new WP_Error( 'wpinv-subscription-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) ); |
|
111 | + return new WP_Error('wpinv-subscription-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key)); |
|
112 | 112 | |
113 | 113 | } |
114 | 114 | |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | * @param array $data Array of attributes for a subscription |
122 | 122 | * @return mixed false if data isn't passed and class not instantiated for creation |
123 | 123 | */ |
124 | - public function create( $data = array() ) { |
|
124 | + public function create($data = array()) { |
|
125 | 125 | |
126 | - if ( $this->id != 0 ) { |
|
126 | + if ($this->id != 0) { |
|
127 | 127 | return false; |
128 | 128 | } |
129 | 129 | |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | 'profile_id' => '', |
143 | 143 | ); |
144 | 144 | |
145 | - $args = wp_parse_args( $data, $defaults ); |
|
145 | + $args = wp_parse_args($data, $defaults); |
|
146 | 146 | |
147 | - if( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { |
|
147 | + if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) { |
|
148 | 148 | |
149 | - if( 'active' == $args['status'] || 'trialling' == $args['status'] ) { |
|
149 | + if ('active' == $args['status'] || 'trialling' == $args['status']) { |
|
150 | 150 | |
151 | 151 | // Force an active subscription to expired if expiration date is in the past |
152 | 152 | $args['status'] = 'expired'; |
@@ -154,13 +154,13 @@ discard block |
||
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
157 | - do_action( 'wpinv_subscription_pre_create', $args ); |
|
157 | + do_action('wpinv_subscription_pre_create', $args); |
|
158 | 158 | |
159 | - $id = $this->subs_db->insert( $args, 'subscription' ); |
|
159 | + $id = $this->subs_db->insert($args, 'subscription'); |
|
160 | 160 | |
161 | - do_action( 'wpinv_subscription_post_create', $id, $args ); |
|
161 | + do_action('wpinv_subscription_post_create', $id, $args); |
|
162 | 162 | |
163 | - return $this->setup_subscription( $id ); |
|
163 | + return $this->setup_subscription($id); |
|
164 | 164 | |
165 | 165 | } |
166 | 166 | |
@@ -171,11 +171,11 @@ discard block |
||
171 | 171 | * @param array $args Array of fields to update |
172 | 172 | * @return bool |
173 | 173 | */ |
174 | - public function update( $args = array() ) { |
|
174 | + public function update($args = array()) { |
|
175 | 175 | |
176 | - $ret = $this->subs_db->update( $this->id, $args ); |
|
176 | + $ret = $this->subs_db->update($this->id, $args); |
|
177 | 177 | |
178 | - do_action( 'wpinv_recurring_update_subscription', $this->id, $args, $this ); |
|
178 | + do_action('wpinv_recurring_update_subscription', $this->id, $args, $this); |
|
179 | 179 | |
180 | 180 | return $ret; |
181 | 181 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @return bool |
189 | 189 | */ |
190 | 190 | public function delete() { |
191 | - return $this->subs_db->delete( $this->id ); |
|
191 | + return $this->subs_db->delete($this->id); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -208,14 +208,14 @@ discard block |
||
208 | 208 | * @return array |
209 | 209 | */ |
210 | 210 | public function get_child_payments() { |
211 | - $payments = get_posts( array( |
|
212 | - 'post_parent' => (int) $this->parent_payment_id, |
|
211 | + $payments = get_posts(array( |
|
212 | + 'post_parent' => (int)$this->parent_payment_id, |
|
213 | 213 | 'posts_per_page' => '999', |
214 | - 'post_status' => array( 'publish', 'wpi-processing', 'wpi-renewal' ), |
|
214 | + 'post_status' => array('publish', 'wpi-processing', 'wpi-renewal'), |
|
215 | 215 | 'orderby' => 'ID', |
216 | 216 | 'order' => 'DESC', |
217 | 217 | 'post_type' => 'wpi_invoice' |
218 | - ) ); |
|
218 | + )); |
|
219 | 219 | |
220 | 220 | return $payments; |
221 | 221 | } |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | */ |
229 | 229 | public function get_total_payments() { |
230 | 230 | $child_payments = $this->get_child_payments(); |
231 | - $total_payments = !empty( $child_payments ) ? count( $child_payments ) : 0; |
|
231 | + $total_payments = !empty($child_payments) ? count($child_payments) : 0; |
|
232 | 232 | |
233 | - if ( 'pending' != $this->status ) { |
|
233 | + if ('pending' != $this->status) { |
|
234 | 234 | $total_payments++; |
235 | 235 | } |
236 | 236 | |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | public function get_times_billed() { |
247 | 247 | $times_billed = (int)$this->get_total_payments(); |
248 | 248 | |
249 | - if ( ! empty( $this->trial_period ) && $times_billed > 0 ) { |
|
249 | + if (!empty($this->trial_period) && $times_billed > 0) { |
|
250 | 250 | $times_billed--; |
251 | 251 | } |
252 | 252 | |
@@ -260,51 +260,51 @@ discard block |
||
260 | 260 | * @param array $args Array of values for the payment, including amount and transaction ID |
261 | 261 | * @return bool |
262 | 262 | */ |
263 | - public function add_payment( $args = array() ) { |
|
264 | - if ( ! $this->parent_payment_id ) { |
|
263 | + public function add_payment($args = array()) { |
|
264 | + if (!$this->parent_payment_id) { |
|
265 | 265 | return false; |
266 | 266 | } |
267 | 267 | |
268 | - $args = wp_parse_args( $args, array( |
|
268 | + $args = wp_parse_args($args, array( |
|
269 | 269 | 'amount' => '', |
270 | 270 | 'transaction_id' => '', |
271 | 271 | 'gateway' => '' |
272 | - ) ); |
|
272 | + )); |
|
273 | 273 | |
274 | - if ( empty( $args['transaction_id'] ) || $this->payment_exists( $args['transaction_id'] ) ) { |
|
274 | + if (empty($args['transaction_id']) || $this->payment_exists($args['transaction_id'])) { |
|
275 | 275 | return false; |
276 | 276 | } |
277 | 277 | |
278 | - $parent_invoice = wpinv_get_invoice( $this->parent_payment_id ); |
|
279 | - if ( empty( $parent_invoice->ID ) ) { |
|
278 | + $parent_invoice = wpinv_get_invoice($this->parent_payment_id); |
|
279 | + if (empty($parent_invoice->ID)) { |
|
280 | 280 | return false; |
281 | 281 | } |
282 | 282 | |
283 | 283 | $invoice = new WPInv_Invoice(); |
284 | - $invoice->set( 'post_type', 'wpi_invoice' ); |
|
285 | - $invoice->set( 'parent_invoice', $this->parent_payment_id ); |
|
286 | - $invoice->set( 'currency', $parent_invoice->get_currency() ); |
|
287 | - $invoice->set( 'transaction_id', $args['transaction_id'] ); |
|
288 | - $invoice->set( 'key', $parent_invoice->generate_key() ); |
|
289 | - $invoice->set( 'ip', $parent_invoice->ip ); |
|
290 | - $invoice->set( 'user_id', $parent_invoice->get_user_id() ); |
|
291 | - $invoice->set( 'first_name', $parent_invoice->get_first_name() ); |
|
292 | - $invoice->set( 'last_name', $parent_invoice->get_last_name() ); |
|
293 | - $invoice->set( 'phone', $parent_invoice->phone ); |
|
294 | - $invoice->set( 'address', $parent_invoice->address ); |
|
295 | - $invoice->set( 'city', $parent_invoice->city ); |
|
296 | - $invoice->set( 'country', $parent_invoice->country ); |
|
297 | - $invoice->set( 'state', $parent_invoice->state ); |
|
298 | - $invoice->set( 'zip', $parent_invoice->zip ); |
|
299 | - $invoice->set( 'company', $parent_invoice->company ); |
|
300 | - $invoice->set( 'vat_number', $parent_invoice->vat_number ); |
|
301 | - $invoice->set( 'vat_rate', $parent_invoice->vat_rate ); |
|
302 | - $invoice->set( 'adddress_confirmed', $parent_invoice->adddress_confirmed ); |
|
303 | - |
|
304 | - if ( empty( $args['gateway'] ) ) { |
|
305 | - $invoice->set( 'gateway', $parent_invoice->get_gateway() ); |
|
284 | + $invoice->set('post_type', 'wpi_invoice'); |
|
285 | + $invoice->set('parent_invoice', $this->parent_payment_id); |
|
286 | + $invoice->set('currency', $parent_invoice->get_currency()); |
|
287 | + $invoice->set('transaction_id', $args['transaction_id']); |
|
288 | + $invoice->set('key', $parent_invoice->generate_key()); |
|
289 | + $invoice->set('ip', $parent_invoice->ip); |
|
290 | + $invoice->set('user_id', $parent_invoice->get_user_id()); |
|
291 | + $invoice->set('first_name', $parent_invoice->get_first_name()); |
|
292 | + $invoice->set('last_name', $parent_invoice->get_last_name()); |
|
293 | + $invoice->set('phone', $parent_invoice->phone); |
|
294 | + $invoice->set('address', $parent_invoice->address); |
|
295 | + $invoice->set('city', $parent_invoice->city); |
|
296 | + $invoice->set('country', $parent_invoice->country); |
|
297 | + $invoice->set('state', $parent_invoice->state); |
|
298 | + $invoice->set('zip', $parent_invoice->zip); |
|
299 | + $invoice->set('company', $parent_invoice->company); |
|
300 | + $invoice->set('vat_number', $parent_invoice->vat_number); |
|
301 | + $invoice->set('vat_rate', $parent_invoice->vat_rate); |
|
302 | + $invoice->set('adddress_confirmed', $parent_invoice->adddress_confirmed); |
|
303 | + |
|
304 | + if (empty($args['gateway'])) { |
|
305 | + $invoice->set('gateway', $parent_invoice->get_gateway()); |
|
306 | 306 | } else { |
307 | - $invoice->set( 'gateway', $args['gateway'] ); |
|
307 | + $invoice->set('gateway', $args['gateway']); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | $recurring_details = $parent_invoice->get_recurring_details(); |
@@ -312,11 +312,11 @@ discard block |
||
312 | 312 | // increase the earnings for each item in the subscription |
313 | 313 | $items = $recurring_details['cart_details']; |
314 | 314 | |
315 | - if ( $items ) { |
|
315 | + if ($items) { |
|
316 | 316 | $add_items = array(); |
317 | 317 | $cart_details = array(); |
318 | 318 | |
319 | - foreach ( $items as $item ) { |
|
319 | + foreach ($items as $item) { |
|
320 | 320 | $add_item = array(); |
321 | 321 | $add_item['id'] = $item['id']; |
322 | 322 | $add_item['quantity'] = $item['quantity']; |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | break; |
327 | 327 | } |
328 | 328 | |
329 | - $invoice->set( 'items', $add_items ); |
|
329 | + $invoice->set('items', $add_items); |
|
330 | 330 | $invoice->cart_details = $cart_details; |
331 | 331 | } |
332 | 332 | |
@@ -336,29 +336,29 @@ discard block |
||
336 | 336 | $tax = $recurring_details['tax']; |
337 | 337 | $discount = $recurring_details['discount']; |
338 | 338 | |
339 | - if ( $discount > 0 ) { |
|
340 | - $invoice->set( 'discount_code', $parent_invoice->discount_code ); |
|
339 | + if ($discount > 0) { |
|
340 | + $invoice->set('discount_code', $parent_invoice->discount_code); |
|
341 | 341 | } |
342 | 342 | |
343 | - $invoice->subtotal = wpinv_round_amount( $subtotal ); |
|
344 | - $invoice->tax = wpinv_round_amount( $tax ); |
|
345 | - $invoice->discount = wpinv_round_amount( $discount ); |
|
346 | - $invoice->total = wpinv_round_amount( $total ); |
|
343 | + $invoice->subtotal = wpinv_round_amount($subtotal); |
|
344 | + $invoice->tax = wpinv_round_amount($tax); |
|
345 | + $invoice->discount = wpinv_round_amount($discount); |
|
346 | + $invoice->total = wpinv_round_amount($total); |
|
347 | 347 | |
348 | - $invoice = apply_filters( 'wpinv_subscription_add_payment_save', $invoice, $this, $args ); |
|
348 | + $invoice = apply_filters('wpinv_subscription_add_payment_save', $invoice, $this, $args); |
|
349 | 349 | |
350 | 350 | $invoice->save(); |
351 | - $invoice->update_meta( '_wpinv_subscription_id', $this->id ); |
|
351 | + $invoice->update_meta('_wpinv_subscription_id', $this->id); |
|
352 | 352 | |
353 | - if ( !empty( $invoice->ID ) ) { |
|
354 | - wpinv_update_payment_status( $invoice->ID, 'publish' ); |
|
353 | + if (!empty($invoice->ID)) { |
|
354 | + wpinv_update_payment_status($invoice->ID, 'publish'); |
|
355 | 355 | sleep(1); |
356 | - wpinv_update_payment_status( $invoice->ID, 'wpi-renewal' ); |
|
356 | + wpinv_update_payment_status($invoice->ID, 'wpi-renewal'); |
|
357 | 357 | |
358 | - $invoice = wpinv_get_invoice( $invoice->ID ); |
|
358 | + $invoice = wpinv_get_invoice($invoice->ID); |
|
359 | 359 | |
360 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
361 | - do_action( 'wpinv_recurring_record_payment', $invoice->ID, $this->parent_payment_id, $args['amount'], $args['transaction_id'] ); |
|
360 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $this); |
|
361 | + do_action('wpinv_recurring_record_payment', $invoice->ID, $this->parent_payment_id, $args['amount'], $args['transaction_id']); |
|
362 | 362 | |
363 | 363 | return $invoice->ID; |
364 | 364 | } |
@@ -374,12 +374,12 @@ discard block |
||
374 | 374 | */ |
375 | 375 | public function get_transaction_id() { |
376 | 376 | |
377 | - if( empty( $this->transaction_id ) ) { |
|
377 | + if (empty($this->transaction_id)) { |
|
378 | 378 | |
379 | - $txn_id = wpinv_get_payment_transaction_id( $this->parent_payment_id ); |
|
379 | + $txn_id = wpinv_get_payment_transaction_id($this->parent_payment_id); |
|
380 | 380 | |
381 | - if( ! empty( $txn_id ) && (int) $this->parent_payment_id !== (int) $txn_id ) { |
|
382 | - $this->set_transaction_id( $txn_id ); |
|
381 | + if (!empty($txn_id) && (int)$this->parent_payment_id !== (int)$txn_id) { |
|
382 | + $this->set_transaction_id($txn_id); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | } |
@@ -394,8 +394,8 @@ discard block |
||
394 | 394 | * @since 1.0.0.4 |
395 | 395 | * @return bool |
396 | 396 | */ |
397 | - public function set_transaction_id( $txn_id = '' ) { |
|
398 | - $this->update( array( 'transaction_id' => $txn_id ) ); |
|
397 | + public function set_transaction_id($txn_id = '') { |
|
398 | + $this->update(array('transaction_id' => $txn_id)); |
|
399 | 399 | $this->transaction_id = $txn_id; |
400 | 400 | } |
401 | 401 | |
@@ -411,35 +411,35 @@ discard block |
||
411 | 411 | |
412 | 412 | |
413 | 413 | // Determine what date to use as the start for the new expiration calculation |
414 | - if( $expires > current_time( 'timestamp' ) && $this->is_active() ) { |
|
414 | + if ($expires > current_time('timestamp') && $this->is_active()) { |
|
415 | 415 | |
416 | - $base_date = $expires; |
|
416 | + $base_date = $expires; |
|
417 | 417 | |
418 | 418 | } else { |
419 | 419 | |
420 | - $base_date = current_time( 'timestamp' ); |
|
420 | + $base_date = current_time('timestamp'); |
|
421 | 421 | |
422 | 422 | } |
423 | 423 | |
424 | - $last_day = wpinv_cal_days_in_month( CAL_GREGORIAN, date( 'n', $base_date ), date( 'Y', $base_date ) ); |
|
424 | + $last_day = wpinv_cal_days_in_month(CAL_GREGORIAN, date('n', $base_date), date('Y', $base_date)); |
|
425 | 425 | |
426 | 426 | |
427 | 427 | $frequency = isset($this->frequency) ? $this->frequency : 1; |
428 | - $expiration = date( 'Y-m-d H:i:s', strtotime( '+' . $frequency . ' ' . $this->period . ' 23:59:59', $base_date ) ); |
|
428 | + $expiration = date('Y-m-d H:i:s', strtotime('+' . $frequency . ' ' . $this->period . ' 23:59:59', $base_date)); |
|
429 | 429 | |
430 | - if( date( 'j', $base_date ) == $last_day && 'day' != $this->period ) { |
|
431 | - $expiration = date( 'Y-m-d H:i:s', strtotime( $expiration . ' +2 days' ) ); |
|
430 | + if (date('j', $base_date) == $last_day && 'day' != $this->period) { |
|
431 | + $expiration = date('Y-m-d H:i:s', strtotime($expiration . ' +2 days')); |
|
432 | 432 | } |
433 | 433 | |
434 | - $expiration = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->id, $this ); |
|
434 | + $expiration = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->id, $this); |
|
435 | 435 | |
436 | - do_action( 'wpinv_subscription_pre_renew', $this->id, $expiration, $this ); |
|
436 | + do_action('wpinv_subscription_pre_renew', $this->id, $expiration, $this); |
|
437 | 437 | |
438 | 438 | $this->status = 'active'; |
439 | 439 | $times_billed = $this->get_times_billed(); |
440 | 440 | |
441 | 441 | // Complete subscription if applicable |
442 | - if ( $this->bill_times > 0 && $times_billed >= $this->bill_times ) { |
|
442 | + if ($this->bill_times > 0 && $times_billed >= $this->bill_times) { |
|
443 | 443 | $this->complete(); |
444 | 444 | $this->status = 'completed'; |
445 | 445 | } |
@@ -449,10 +449,10 @@ discard block |
||
449 | 449 | 'status' => $this->status, |
450 | 450 | ); |
451 | 451 | |
452 | - $this->subs_db->update( $this->id, $args ); |
|
452 | + $this->subs_db->update($this->id, $args); |
|
453 | 453 | |
454 | - do_action( 'wpinv_subscription_post_renew', $this->id, $expiration, $this ); |
|
455 | - do_action( 'wpinv_recurring_set_subscription_status', $this->id, $this->status, $this ); |
|
454 | + do_action('wpinv_subscription_post_renew', $this->id, $expiration, $this); |
|
455 | + do_action('wpinv_recurring_set_subscription_status', $this->id, $this->status, $this); |
|
456 | 456 | |
457 | 457 | } |
458 | 458 | |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | public function complete() { |
468 | 468 | |
469 | 469 | // Only mark a subscription as complete if it's not already cancelled. |
470 | - if ( 'cancelled' === $this->status ) { |
|
470 | + if ('cancelled' === $this->status) { |
|
471 | 471 | return; |
472 | 472 | } |
473 | 473 | |
@@ -475,11 +475,11 @@ discard block |
||
475 | 475 | 'status' => 'completed' |
476 | 476 | ); |
477 | 477 | |
478 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
478 | + if ($this->subs_db->update($this->id, $args)) { |
|
479 | 479 | |
480 | 480 | $this->status = 'completed'; |
481 | 481 | |
482 | - do_action( 'wpinv_subscription_completed', $this->id, $this ); |
|
482 | + do_action('wpinv_subscription_completed', $this->id, $this); |
|
483 | 483 | |
484 | 484 | } |
485 | 485 | |
@@ -494,15 +494,15 @@ discard block |
||
494 | 494 | * @param $check_expiration bool True if expiration date should be checked with merchant processor before expiring |
495 | 495 | * @return void |
496 | 496 | */ |
497 | - public function expire( $check_expiration = false ) { |
|
497 | + public function expire($check_expiration = false) { |
|
498 | 498 | |
499 | 499 | $expiration = $this->expiration; |
500 | 500 | |
501 | - if( $check_expiration ) { |
|
501 | + if ($check_expiration) { |
|
502 | 502 | |
503 | 503 | // check_expiration() updates $this->expiration so compare to $expiration above |
504 | 504 | |
505 | - if( $expiration < $this->get_expiration() && current_time( 'timestamp' ) < $this->get_expiration_time() ) { |
|
505 | + if ($expiration < $this->get_expiration() && current_time('timestamp') < $this->get_expiration_time()) { |
|
506 | 506 | |
507 | 507 | return false; // Do not mark as expired since real expiration date is in the future |
508 | 508 | } |
@@ -513,11 +513,11 @@ discard block |
||
513 | 513 | 'status' => 'expired' |
514 | 514 | ); |
515 | 515 | |
516 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
516 | + if ($this->subs_db->update($this->id, $args)) { |
|
517 | 517 | |
518 | 518 | $this->status = 'expired'; |
519 | 519 | |
520 | - do_action( 'wpinv_subscription_expired', $this->id, $this ); |
|
520 | + do_action('wpinv_subscription_expired', $this->id, $this); |
|
521 | 521 | |
522 | 522 | } |
523 | 523 | |
@@ -535,11 +535,11 @@ discard block |
||
535 | 535 | 'status' => 'failing' |
536 | 536 | ); |
537 | 537 | |
538 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
538 | + if ($this->subs_db->update($this->id, $args)) { |
|
539 | 539 | |
540 | 540 | $this->status = 'failing'; |
541 | 541 | |
542 | - do_action( 'wpinv_subscription_failing', $this->id, $this ); |
|
542 | + do_action('wpinv_subscription_failing', $this->id, $this); |
|
543 | 543 | |
544 | 544 | |
545 | 545 | } |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | * @return void |
554 | 554 | */ |
555 | 555 | public function cancel() { |
556 | - if ( 'cancelled' === $this->status ) { |
|
556 | + if ('cancelled' === $this->status) { |
|
557 | 557 | return; // Already cancelled |
558 | 558 | } |
559 | 559 | |
@@ -561,20 +561,20 @@ discard block |
||
561 | 561 | 'status' => 'cancelled' |
562 | 562 | ); |
563 | 563 | |
564 | - if ( $this->subs_db->update( $this->id, $args ) ) { |
|
565 | - if ( is_user_logged_in() ) { |
|
566 | - $userdata = get_userdata( get_current_user_id() ); |
|
564 | + if ($this->subs_db->update($this->id, $args)) { |
|
565 | + if (is_user_logged_in()) { |
|
566 | + $userdata = get_userdata(get_current_user_id()); |
|
567 | 567 | $user = $userdata->display_name; |
568 | 568 | } else { |
569 | - $user = __( 'gateway', 'invoicing' ); |
|
569 | + $user = __('gateway', 'invoicing'); |
|
570 | 570 | } |
571 | 571 | |
572 | - $note = sprintf( __( 'Subscription has been cancelled by %s', 'invoicing' ), $this->parent_payment_id, $user ); |
|
573 | - wpinv_insert_payment_note( $this->parent_payment_id, $note, '', '', true ); |
|
572 | + $note = sprintf(__('Subscription has been cancelled by %s', 'invoicing'), $this->parent_payment_id, $user); |
|
573 | + wpinv_insert_payment_note($this->parent_payment_id, $note, '', '', true); |
|
574 | 574 | |
575 | 575 | $this->status = 'cancelled'; |
576 | 576 | |
577 | - do_action( 'wpinv_subscription_cancelled', $this->id, $this ); |
|
577 | + do_action('wpinv_subscription_cancelled', $this->id, $this); |
|
578 | 578 | } |
579 | 579 | } |
580 | 580 | |
@@ -589,10 +589,10 @@ discard block |
||
589 | 589 | */ |
590 | 590 | public function can_cancel() { |
591 | 591 | $ret = false; |
592 | - if( $this->gateway === 'manual' || in_array( $this->status, $this->get_cancellable_statuses() ) ) { |
|
592 | + if ($this->gateway === 'manual' || in_array($this->status, $this->get_cancellable_statuses())) { |
|
593 | 593 | $ret = true; |
594 | 594 | } |
595 | - return apply_filters( 'wpinv_subscription_can_cancel', $ret, $this ); |
|
595 | + return apply_filters('wpinv_subscription_can_cancel', $ret, $this); |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | /** |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | * @return array |
604 | 604 | */ |
605 | 605 | public function get_cancellable_statuses() { |
606 | - return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
|
606 | + return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing')); |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | /** |
@@ -614,9 +614,9 @@ discard block |
||
614 | 614 | */ |
615 | 615 | public function get_cancel_url() { |
616 | 616 | |
617 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-cancel' ); |
|
617 | + $url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id)), 'wpinv-recurring-cancel'); |
|
618 | 618 | |
619 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
619 | + return apply_filters('wpinv_subscription_cancel_url', $url, $this); |
|
620 | 620 | } |
621 | 621 | |
622 | 622 | /** |
@@ -630,7 +630,7 @@ discard block |
||
630 | 630 | */ |
631 | 631 | public function can_renew() { |
632 | 632 | |
633 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
633 | + return apply_filters('wpinv_subscription_can_renew', true, $this); |
|
634 | 634 | } |
635 | 635 | |
636 | 636 | /** |
@@ -641,9 +641,9 @@ discard block |
||
641 | 641 | */ |
642 | 642 | public function get_renew_url() { |
643 | 643 | |
644 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-renew' ); |
|
644 | + $url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'renew_subscription', 'sub_id' => $this->id)), 'wpinv-recurring-renew'); |
|
645 | 645 | |
646 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
646 | + return apply_filters('wpinv_subscription_renew_url', $url, $this); |
|
647 | 647 | } |
648 | 648 | |
649 | 649 | /** |
@@ -653,7 +653,7 @@ discard block |
||
653 | 653 | * @return bool |
654 | 654 | */ |
655 | 655 | public function can_update() { |
656 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
656 | + return apply_filters('wpinv_subscription_can_update', false, $this); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | /** |
@@ -664,9 +664,9 @@ discard block |
||
664 | 664 | */ |
665 | 665 | public function get_update_url() { |
666 | 666 | |
667 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->id ) ); |
|
667 | + $url = add_query_arg(array('action' => 'update', 'subscription_id' => $this->id)); |
|
668 | 668 | |
669 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
669 | + return apply_filters('wpinv_subscription_update_url', $url, $this); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | /** |
@@ -679,11 +679,11 @@ discard block |
||
679 | 679 | |
680 | 680 | $ret = false; |
681 | 681 | |
682 | - if( ! $this->is_expired() && ( $this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling' ) ) { |
|
682 | + if (!$this->is_expired() && ($this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling')) { |
|
683 | 683 | $ret = true; |
684 | 684 | } |
685 | 685 | |
686 | - return apply_filters( 'wpinv_subscription_is_active', $ret, $this->id, $this ); |
|
686 | + return apply_filters('wpinv_subscription_is_active', $ret, $this->id, $this); |
|
687 | 687 | |
688 | 688 | } |
689 | 689 | |
@@ -697,26 +697,26 @@ discard block |
||
697 | 697 | |
698 | 698 | $ret = false; |
699 | 699 | |
700 | - if ( $this->status == 'expired' ) { |
|
700 | + if ($this->status == 'expired') { |
|
701 | 701 | |
702 | 702 | $ret = true; |
703 | 703 | |
704 | - } elseif( 'active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling' ) { |
|
704 | + } elseif ('active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling') { |
|
705 | 705 | |
706 | 706 | $ret = false; |
707 | 707 | $expiration = $this->get_expiration_time(); |
708 | 708 | |
709 | - if( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { |
|
709 | + if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) { |
|
710 | 710 | $ret = true; |
711 | 711 | |
712 | - if ( 'active' === $this->status || $this->status == 'trialling' ) { |
|
712 | + if ('active' === $this->status || $this->status == 'trialling') { |
|
713 | 713 | $this->expire(); |
714 | 714 | } |
715 | 715 | } |
716 | 716 | |
717 | 717 | } |
718 | 718 | |
719 | - return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->id, $this ); |
|
719 | + return apply_filters('wpinv_subscription_is_expired', $ret, $this->id, $this); |
|
720 | 720 | |
721 | 721 | } |
722 | 722 | |
@@ -737,7 +737,7 @@ discard block |
||
737 | 737 | * @return int |
738 | 738 | */ |
739 | 739 | public function get_expiration_time() { |
740 | - return strtotime( $this->expiration, current_time( 'timestamp' ) ); |
|
740 | + return strtotime($this->expiration, current_time('timestamp')); |
|
741 | 741 | } |
742 | 742 | |
743 | 743 | /** |
@@ -761,37 +761,37 @@ discard block |
||
761 | 761 | */ |
762 | 762 | public function get_status_label() { |
763 | 763 | |
764 | - switch( $this->get_status() ) { |
|
764 | + switch ($this->get_status()) { |
|
765 | 765 | case 'active' : |
766 | - $status = __( 'Active', 'invoicing' ); |
|
766 | + $status = __('Active', 'invoicing'); |
|
767 | 767 | break; |
768 | 768 | |
769 | 769 | case 'cancelled' : |
770 | - $status = __( 'Cancelled', 'invoicing' ); |
|
770 | + $status = __('Cancelled', 'invoicing'); |
|
771 | 771 | break; |
772 | 772 | |
773 | 773 | case 'expired' : |
774 | - $status = __( 'Expired', 'invoicing' ); |
|
774 | + $status = __('Expired', 'invoicing'); |
|
775 | 775 | break; |
776 | 776 | |
777 | 777 | case 'pending' : |
778 | - $status = __( 'Pending', 'invoicing' ); |
|
778 | + $status = __('Pending', 'invoicing'); |
|
779 | 779 | break; |
780 | 780 | |
781 | 781 | case 'failing' : |
782 | - $status = __( 'Failing', 'invoicing' ); |
|
782 | + $status = __('Failing', 'invoicing'); |
|
783 | 783 | break; |
784 | 784 | |
785 | 785 | case 'trialling' : |
786 | - $status = __( 'Trialling', 'invoicing' ); |
|
786 | + $status = __('Trialling', 'invoicing'); |
|
787 | 787 | break; |
788 | 788 | |
789 | 789 | case 'completed' : |
790 | - $status = __( 'Completed', 'invoicing' ); |
|
790 | + $status = __('Completed', 'invoicing'); |
|
791 | 791 | break; |
792 | 792 | |
793 | 793 | default: |
794 | - $status = ucfirst( $this->get_status() ); |
|
794 | + $status = ucfirst($this->get_status()); |
|
795 | 795 | break; |
796 | 796 | } |
797 | 797 | |
@@ -806,51 +806,51 @@ discard block |
||
806 | 806 | */ |
807 | 807 | public function get_status_label_html() { |
808 | 808 | |
809 | - switch( $get_status = $this->get_status() ) { |
|
809 | + switch ($get_status = $this->get_status()) { |
|
810 | 810 | case 'active' : |
811 | - $status = __( 'Active', 'invoicing' ); |
|
811 | + $status = __('Active', 'invoicing'); |
|
812 | 812 | $class = 'label-info'; |
813 | 813 | break; |
814 | 814 | |
815 | 815 | case 'cancelled' : |
816 | - $status = __( 'Cancelled', 'invoicing' ); |
|
816 | + $status = __('Cancelled', 'invoicing'); |
|
817 | 817 | $class = 'label-danger'; |
818 | 818 | break; |
819 | 819 | |
820 | 820 | case 'expired' : |
821 | - $status = __( 'Expired', 'invoicing' ); |
|
821 | + $status = __('Expired', 'invoicing'); |
|
822 | 822 | $class = 'label-default'; |
823 | 823 | break; |
824 | 824 | |
825 | 825 | case 'pending' : |
826 | - $status = __( 'Pending', 'invoicing' ); |
|
826 | + $status = __('Pending', 'invoicing'); |
|
827 | 827 | $class = 'label-primary'; |
828 | 828 | break; |
829 | 829 | |
830 | 830 | case 'failing' : |
831 | - $status = __( 'Failing', 'invoicing' ); |
|
831 | + $status = __('Failing', 'invoicing'); |
|
832 | 832 | $class = 'label-danger'; |
833 | 833 | break; |
834 | 834 | |
835 | 835 | case 'trialling' : |
836 | - $status = __( 'Trialling', 'invoicing' ); |
|
836 | + $status = __('Trialling', 'invoicing'); |
|
837 | 837 | $class = 'label-info'; |
838 | 838 | break; |
839 | 839 | |
840 | 840 | case 'completed' : |
841 | - $status = __( 'Completed', 'invoicing' ); |
|
841 | + $status = __('Completed', 'invoicing'); |
|
842 | 842 | $class = 'label-success'; |
843 | 843 | break; |
844 | 844 | |
845 | 845 | default: |
846 | - $status = ucfirst( $this->get_status() ); |
|
846 | + $status = ucfirst($this->get_status()); |
|
847 | 847 | $class = 'label-default'; |
848 | 848 | break; |
849 | 849 | } |
850 | 850 | |
851 | 851 | $label = '<span class="sub-status label label-sub-' . $get_status . ' ' . $class . '">' . $status . '</span>'; |
852 | 852 | |
853 | - return apply_filters( 'wpinv_subscription_status_label_html', $label, $get_status, $status ); |
|
853 | + return apply_filters('wpinv_subscription_status_label_html', $label, $get_status, $status); |
|
854 | 854 | } |
855 | 855 | |
856 | 856 | /** |
@@ -860,18 +860,18 @@ discard block |
||
860 | 860 | * @param string $txn_id The transaction ID from the merchant processor |
861 | 861 | * @return bool |
862 | 862 | */ |
863 | - public function payment_exists( $txn_id = '' ) { |
|
863 | + public function payment_exists($txn_id = '') { |
|
864 | 864 | global $wpdb; |
865 | 865 | |
866 | - if ( empty( $txn_id ) ) { |
|
866 | + if (empty($txn_id)) { |
|
867 | 867 | return false; |
868 | 868 | } |
869 | 869 | |
870 | - $txn_id = esc_sql( $txn_id ); |
|
870 | + $txn_id = esc_sql($txn_id); |
|
871 | 871 | |
872 | - $purchase = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1" ); |
|
872 | + $purchase = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1"); |
|
873 | 873 | |
874 | - if ( $purchase != null ) { |
|
874 | + if ($purchase != null) { |
|
875 | 875 | return true; |
876 | 876 | } |
877 | 877 |
@@ -7,12 +7,12 @@ 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 | function wpinv_init_transactional_emails() { |
15 | - $email_actions = apply_filters( 'wpinv_email_actions', array( |
|
15 | + $email_actions = apply_filters('wpinv_email_actions', array( |
|
16 | 16 | 'wpinv_status_wpi-pending_to_wpi-processing', |
17 | 17 | 'wpinv_status_wpi-pending_to_publish', |
18 | 18 | 'wpinv_status_wpi-pending_to_wpi-cancelled', |
@@ -30,238 +30,238 @@ discard block |
||
30 | 30 | 'wpinv_fully_refunded', |
31 | 31 | 'wpinv_partially_refunded', |
32 | 32 | 'wpinv_new_invoice_note' |
33 | - ) ); |
|
33 | + )); |
|
34 | 34 | |
35 | - foreach ( $email_actions as $action ) { |
|
36 | - add_action( $action, 'wpinv_send_transactional_email', 10, 10 ); |
|
35 | + foreach ($email_actions as $action) { |
|
36 | + add_action($action, 'wpinv_send_transactional_email', 10, 10); |
|
37 | 37 | } |
38 | 38 | } |
39 | -add_action( 'init', 'wpinv_init_transactional_emails' ); |
|
39 | +add_action('init', 'wpinv_init_transactional_emails'); |
|
40 | 40 | |
41 | 41 | // New invoice email |
42 | -add_action( 'wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_new_invoice_notification' ); |
|
43 | -add_action( 'wpinv_status_wpi-pending_to_publish_notification', 'wpinv_new_invoice_notification' ); |
|
44 | -add_action( 'wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_new_invoice_notification' ); |
|
45 | -add_action( 'wpinv_status_wpi-failed_to_wpi-processing_notification', 'wpinv_new_invoice_notification' ); |
|
46 | -add_action( 'wpinv_status_wpi-failed_to_publish_notification', 'wpinv_new_invoice_notification' ); |
|
47 | -add_action( 'wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_new_invoice_notification' ); |
|
42 | +add_action('wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_new_invoice_notification'); |
|
43 | +add_action('wpinv_status_wpi-pending_to_publish_notification', 'wpinv_new_invoice_notification'); |
|
44 | +add_action('wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_new_invoice_notification'); |
|
45 | +add_action('wpinv_status_wpi-failed_to_wpi-processing_notification', 'wpinv_new_invoice_notification'); |
|
46 | +add_action('wpinv_status_wpi-failed_to_publish_notification', 'wpinv_new_invoice_notification'); |
|
47 | +add_action('wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_new_invoice_notification'); |
|
48 | 48 | |
49 | 49 | // Cancelled invoice email |
50 | -add_action( 'wpinv_status_wpi-pending_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification' ); |
|
51 | -add_action( 'wpinv_status_wpi-onhold_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification' ); |
|
50 | +add_action('wpinv_status_wpi-pending_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification'); |
|
51 | +add_action('wpinv_status_wpi-onhold_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification'); |
|
52 | 52 | |
53 | 53 | // Failed invoice email |
54 | -add_action( 'wpinv_status_wpi-pending_to_wpi-failed_notification', 'wpinv_failed_invoice_notification' ); |
|
55 | -add_action( 'wpinv_status_wpi-onhold_to_wpi-failed_notification', 'wpinv_failed_invoice_notification' ); |
|
54 | +add_action('wpinv_status_wpi-pending_to_wpi-failed_notification', 'wpinv_failed_invoice_notification'); |
|
55 | +add_action('wpinv_status_wpi-onhold_to_wpi-failed_notification', 'wpinv_failed_invoice_notification'); |
|
56 | 56 | |
57 | 57 | // On hold invoice email |
58 | -add_action( 'wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification' ); |
|
59 | -add_action( 'wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification' ); |
|
58 | +add_action('wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification'); |
|
59 | +add_action('wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification'); |
|
60 | 60 | |
61 | 61 | // Processing invoice email |
62 | -add_action( 'wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_processing_invoice_notification' ); |
|
62 | +add_action('wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_processing_invoice_notification'); |
|
63 | 63 | |
64 | 64 | // Paid invoice email |
65 | -add_action( 'wpinv_status_publish_notification', 'wpinv_completed_invoice_notification' ); |
|
65 | +add_action('wpinv_status_publish_notification', 'wpinv_completed_invoice_notification'); |
|
66 | 66 | |
67 | 67 | // Refunded invoice email |
68 | -add_action( 'wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification' ); |
|
69 | -add_action( 'wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification' ); |
|
70 | -add_action( 'wpinv_status_publish_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification' ); |
|
71 | -add_action( 'wpinv_status_wpi-processing_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification' ); |
|
68 | +add_action('wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification'); |
|
69 | +add_action('wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification'); |
|
70 | +add_action('wpinv_status_publish_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification'); |
|
71 | +add_action('wpinv_status_wpi-processing_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification'); |
|
72 | 72 | |
73 | 73 | // Invoice note |
74 | -add_action( 'wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification' ); |
|
74 | +add_action('wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification'); |
|
75 | 75 | |
76 | -add_action( 'wpinv_email_header', 'wpinv_email_header' ); |
|
77 | -add_action( 'wpinv_email_footer', 'wpinv_email_footer' ); |
|
78 | -add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 ); |
|
79 | -add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 ); |
|
80 | -add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 ); |
|
76 | +add_action('wpinv_email_header', 'wpinv_email_header'); |
|
77 | +add_action('wpinv_email_footer', 'wpinv_email_footer'); |
|
78 | +add_action('wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3); |
|
79 | +add_action('wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3); |
|
80 | +add_action('wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3); |
|
81 | 81 | |
82 | 82 | function wpinv_send_transactional_email() { |
83 | 83 | $args = func_get_args(); |
84 | 84 | $function = current_filter() . '_notification'; |
85 | - do_action_ref_array( $function, $args ); |
|
85 | + do_action_ref_array($function, $args); |
|
86 | 86 | } |
87 | 87 | |
88 | -function wpinv_new_invoice_notification( $invoice_id, $new_status = '' ) { |
|
88 | +function wpinv_new_invoice_notification($invoice_id, $new_status = '') { |
|
89 | 89 | $email_type = 'new_invoice'; |
90 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
90 | + if (!wpinv_email_is_enabled($email_type)) { |
|
91 | 91 | return false; |
92 | 92 | } |
93 | 93 | |
94 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
95 | - if ( empty( $invoice ) ) { |
|
94 | + $invoice = wpinv_get_invoice($invoice_id); |
|
95 | + if (empty($invoice)) { |
|
96 | 96 | return false; |
97 | 97 | } |
98 | 98 | |
99 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
99 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
100 | 100 | return false; |
101 | 101 | } |
102 | 102 | |
103 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
104 | - if ( !is_email( $recipient ) ) { |
|
103 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
104 | + if (!is_email($recipient)) { |
|
105 | 105 | return false; |
106 | 106 | } |
107 | 107 | |
108 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
109 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
110 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
111 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
112 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
108 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
109 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
110 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
111 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
112 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
113 | 113 | |
114 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
114 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
115 | 115 | 'invoice' => $invoice, |
116 | 116 | 'email_type' => $email_type, |
117 | 117 | 'email_heading' => $email_heading, |
118 | 118 | 'sent_to_admin' => true, |
119 | 119 | 'plain_text' => false, |
120 | 120 | 'message_body' => $message_body, |
121 | - ) ); |
|
121 | + )); |
|
122 | 122 | |
123 | - return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
123 | + return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
124 | 124 | } |
125 | 125 | |
126 | -function wpinv_cancelled_invoice_notification( $invoice_id, $new_status = '' ) { |
|
126 | +function wpinv_cancelled_invoice_notification($invoice_id, $new_status = '') { |
|
127 | 127 | $email_type = 'cancelled_invoice'; |
128 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
128 | + if (!wpinv_email_is_enabled($email_type)) { |
|
129 | 129 | return false; |
130 | 130 | } |
131 | 131 | |
132 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
133 | - if ( empty( $invoice ) ) { |
|
132 | + $invoice = wpinv_get_invoice($invoice_id); |
|
133 | + if (empty($invoice)) { |
|
134 | 134 | return false; |
135 | 135 | } |
136 | 136 | |
137 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
137 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
138 | 138 | return false; |
139 | 139 | } |
140 | 140 | |
141 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
142 | - if ( !is_email( $recipient ) ) { |
|
141 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
142 | + if (!is_email($recipient)) { |
|
143 | 143 | return false; |
144 | 144 | } |
145 | 145 | |
146 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
147 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
148 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
149 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
150 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
146 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
147 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
148 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
149 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
150 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
151 | 151 | |
152 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
152 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
153 | 153 | 'invoice' => $invoice, |
154 | 154 | 'email_type' => $email_type, |
155 | 155 | 'email_heading' => $email_heading, |
156 | 156 | 'sent_to_admin' => true, |
157 | 157 | 'plain_text' => false, |
158 | 158 | 'message_body' => $message_body, |
159 | - ) ); |
|
159 | + )); |
|
160 | 160 | |
161 | - return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
161 | + return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
162 | 162 | } |
163 | 163 | |
164 | -function wpinv_failed_invoice_notification( $invoice_id, $new_status = '' ) { |
|
164 | +function wpinv_failed_invoice_notification($invoice_id, $new_status = '') { |
|
165 | 165 | $email_type = 'failed_invoice'; |
166 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
166 | + if (!wpinv_email_is_enabled($email_type)) { |
|
167 | 167 | return false; |
168 | 168 | } |
169 | 169 | |
170 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
171 | - if ( empty( $invoice ) ) { |
|
170 | + $invoice = wpinv_get_invoice($invoice_id); |
|
171 | + if (empty($invoice)) { |
|
172 | 172 | return false; |
173 | 173 | } |
174 | 174 | |
175 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
175 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
176 | 176 | return false; |
177 | 177 | } |
178 | 178 | |
179 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
180 | - if ( !is_email( $recipient ) ) { |
|
179 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
180 | + if (!is_email($recipient)) { |
|
181 | 181 | return false; |
182 | 182 | } |
183 | 183 | |
184 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
185 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
186 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
187 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
188 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
184 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
185 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
186 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
187 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
188 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
189 | 189 | |
190 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
190 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
191 | 191 | 'invoice' => $invoice, |
192 | 192 | 'email_type' => $email_type, |
193 | 193 | 'email_heading' => $email_heading, |
194 | 194 | 'sent_to_admin' => true, |
195 | 195 | 'plain_text' => false, |
196 | 196 | 'message_body' => $message_body, |
197 | - ) ); |
|
197 | + )); |
|
198 | 198 | |
199 | - return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
199 | + return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
200 | 200 | } |
201 | 201 | |
202 | -function wpinv_onhold_invoice_notification( $invoice_id, $new_status = '' ) { |
|
202 | +function wpinv_onhold_invoice_notification($invoice_id, $new_status = '') { |
|
203 | 203 | $email_type = 'onhold_invoice'; |
204 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
204 | + if (!wpinv_email_is_enabled($email_type)) { |
|
205 | 205 | return false; |
206 | 206 | } |
207 | 207 | |
208 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
209 | - if ( empty( $invoice ) ) { |
|
208 | + $invoice = wpinv_get_invoice($invoice_id); |
|
209 | + if (empty($invoice)) { |
|
210 | 210 | return false; |
211 | 211 | } |
212 | 212 | |
213 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
213 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
214 | 214 | return false; |
215 | 215 | } |
216 | 216 | |
217 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
218 | - if ( !is_email( $recipient ) ) { |
|
217 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
218 | + if (!is_email($recipient)) { |
|
219 | 219 | return false; |
220 | 220 | } |
221 | 221 | |
222 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
223 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
224 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
225 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
226 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
222 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
223 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
224 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
225 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
226 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
227 | 227 | |
228 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
228 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
229 | 229 | 'invoice' => $invoice, |
230 | 230 | 'email_type' => $email_type, |
231 | 231 | 'email_heading' => $email_heading, |
232 | 232 | 'sent_to_admin' => false, |
233 | 233 | 'plain_text' => false, |
234 | 234 | 'message_body' => $message_body, |
235 | - ) ); |
|
235 | + )); |
|
236 | 236 | |
237 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
237 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
238 | 238 | |
239 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
240 | - $recipient = wpinv_get_admin_email(); |
|
241 | - $subject .= ' - ADMIN BCC COPY'; |
|
242 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
239 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
240 | + $recipient = wpinv_get_admin_email(); |
|
241 | + $subject .= ' - ADMIN BCC COPY'; |
|
242 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | return $sent; |
246 | 246 | } |
247 | 247 | |
248 | -function wpinv_processing_invoice_notification( $invoice_id, $new_status = '' ) { |
|
248 | +function wpinv_processing_invoice_notification($invoice_id, $new_status = '') { |
|
249 | 249 | $email_type = 'processing_invoice'; |
250 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
250 | + if (!wpinv_email_is_enabled($email_type)) { |
|
251 | 251 | return false; |
252 | 252 | } |
253 | 253 | |
254 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
255 | - if ( empty( $invoice ) ) { |
|
254 | + $invoice = wpinv_get_invoice($invoice_id); |
|
255 | + if (empty($invoice)) { |
|
256 | 256 | return false; |
257 | 257 | } |
258 | 258 | |
259 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
259 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
260 | 260 | return false; |
261 | 261 | } |
262 | 262 | |
263 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
264 | - if ( !is_email( $recipient ) ) { |
|
263 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
264 | + if (!is_email($recipient)) { |
|
265 | 265 | return false; |
266 | 266 | } |
267 | 267 | |
@@ -270,105 +270,105 @@ discard block |
||
270 | 270 | $search['invoice_date'] = '{invoice_date}'; |
271 | 271 | $search['name'] = '{name}'; |
272 | 272 | |
273 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
274 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
275 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
276 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
277 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
273 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
274 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
275 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
276 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
277 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
278 | 278 | |
279 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
279 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
280 | 280 | 'invoice' => $invoice, |
281 | 281 | 'email_type' => $email_type, |
282 | 282 | 'email_heading' => $email_heading, |
283 | 283 | 'sent_to_admin' => false, |
284 | 284 | 'plain_text' => false, |
285 | 285 | 'message_body' => $message_body, |
286 | - ) ); |
|
286 | + )); |
|
287 | 287 | |
288 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
288 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
289 | 289 | |
290 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
291 | - $recipient = wpinv_get_admin_email(); |
|
292 | - $subject .= ' - ADMIN BCC COPY'; |
|
293 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
290 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
291 | + $recipient = wpinv_get_admin_email(); |
|
292 | + $subject .= ' - ADMIN BCC COPY'; |
|
293 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | return $sent; |
297 | 297 | } |
298 | 298 | |
299 | -function wpinv_completed_invoice_notification( $invoice_id, $new_status = '' ) { |
|
299 | +function wpinv_completed_invoice_notification($invoice_id, $new_status = '') { |
|
300 | 300 | $email_type = 'completed_invoice'; |
301 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
301 | + if (!wpinv_email_is_enabled($email_type)) { |
|
302 | 302 | return false; |
303 | 303 | } |
304 | 304 | |
305 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
306 | - if ( empty( $invoice ) ) { |
|
305 | + $invoice = wpinv_get_invoice($invoice_id); |
|
306 | + if (empty($invoice)) { |
|
307 | 307 | return false; |
308 | 308 | } |
309 | 309 | |
310 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
310 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
311 | 311 | return false; |
312 | 312 | } |
313 | 313 | |
314 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
315 | - if ( !is_email( $recipient ) ) { |
|
314 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
315 | + if (!is_email($recipient)) { |
|
316 | 316 | return false; |
317 | 317 | } |
318 | 318 | |
319 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
320 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
321 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
322 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
323 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
319 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
320 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
321 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
322 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
323 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
324 | 324 | |
325 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
325 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
326 | 326 | 'invoice' => $invoice, |
327 | 327 | 'email_type' => $email_type, |
328 | 328 | 'email_heading' => $email_heading, |
329 | 329 | 'sent_to_admin' => false, |
330 | 330 | 'plain_text' => false, |
331 | 331 | 'message_body' => $message_body, |
332 | - ) ); |
|
332 | + )); |
|
333 | 333 | |
334 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
334 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
335 | 335 | |
336 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
337 | - $recipient = wpinv_get_admin_email(); |
|
338 | - $subject .= ' - ADMIN BCC COPY'; |
|
339 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
336 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
337 | + $recipient = wpinv_get_admin_email(); |
|
338 | + $subject .= ' - ADMIN BCC COPY'; |
|
339 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | return $sent; |
343 | 343 | } |
344 | 344 | |
345 | -function wpinv_fully_refunded_notification( $invoice_id, $new_status = '' ) { |
|
345 | +function wpinv_fully_refunded_notification($invoice_id, $new_status = '') { |
|
346 | 346 | $email_type = 'refunded_invoice'; |
347 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
347 | + if (!wpinv_email_is_enabled($email_type)) { |
|
348 | 348 | return false; |
349 | 349 | } |
350 | 350 | |
351 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
352 | - if ( empty( $invoice ) ) { |
|
351 | + $invoice = wpinv_get_invoice($invoice_id); |
|
352 | + if (empty($invoice)) { |
|
353 | 353 | return false; |
354 | 354 | } |
355 | 355 | |
356 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
356 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
357 | 357 | return false; |
358 | 358 | } |
359 | 359 | |
360 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
361 | - if ( !is_email( $recipient ) ) { |
|
360 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
361 | + if (!is_email($recipient)) { |
|
362 | 362 | return false; |
363 | 363 | } |
364 | 364 | |
365 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
366 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
367 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
368 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
369 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
365 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
366 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
367 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
368 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
369 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
370 | 370 | |
371 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
371 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
372 | 372 | 'invoice' => $invoice, |
373 | 373 | 'email_type' => $email_type, |
374 | 374 | 'email_heading' => $email_heading, |
@@ -376,46 +376,46 @@ discard block |
||
376 | 376 | 'plain_text' => false, |
377 | 377 | 'partial_refund' => false, |
378 | 378 | 'message_body' => $message_body, |
379 | - ) ); |
|
379 | + )); |
|
380 | 380 | |
381 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
381 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
382 | 382 | |
383 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
384 | - $recipient = wpinv_get_admin_email(); |
|
385 | - $subject .= ' - ADMIN BCC COPY'; |
|
386 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
383 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
384 | + $recipient = wpinv_get_admin_email(); |
|
385 | + $subject .= ' - ADMIN BCC COPY'; |
|
386 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | return $sent; |
390 | 390 | } |
391 | 391 | |
392 | -function wpinv_partially_refunded_notification( $invoice_id, $new_status = '' ) { |
|
392 | +function wpinv_partially_refunded_notification($invoice_id, $new_status = '') { |
|
393 | 393 | $email_type = 'refunded_invoice'; |
394 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
394 | + if (!wpinv_email_is_enabled($email_type)) { |
|
395 | 395 | return false; |
396 | 396 | } |
397 | 397 | |
398 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
399 | - if ( empty( $invoice ) ) { |
|
398 | + $invoice = wpinv_get_invoice($invoice_id); |
|
399 | + if (empty($invoice)) { |
|
400 | 400 | return false; |
401 | 401 | } |
402 | 402 | |
403 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
403 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
404 | 404 | return false; |
405 | 405 | } |
406 | 406 | |
407 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
408 | - if ( !is_email( $recipient ) ) { |
|
407 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
408 | + if (!is_email($recipient)) { |
|
409 | 409 | return false; |
410 | 410 | } |
411 | 411 | |
412 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
413 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
414 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
415 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
416 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
412 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
413 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
414 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
415 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
416 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
417 | 417 | |
418 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
418 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
419 | 419 | 'invoice' => $invoice, |
420 | 420 | 'email_type' => $email_type, |
421 | 421 | 'email_heading' => $email_heading, |
@@ -423,89 +423,89 @@ discard block |
||
423 | 423 | 'plain_text' => false, |
424 | 424 | 'partial_refund' => true, |
425 | 425 | 'message_body' => $message_body, |
426 | - ) ); |
|
426 | + )); |
|
427 | 427 | |
428 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
428 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
429 | 429 | |
430 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
431 | - $recipient = wpinv_get_admin_email(); |
|
432 | - $subject .= ' - ADMIN BCC COPY'; |
|
433 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
430 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
431 | + $recipient = wpinv_get_admin_email(); |
|
432 | + $subject .= ' - ADMIN BCC COPY'; |
|
433 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | return $sent; |
437 | 437 | } |
438 | 438 | |
439 | -function wpinv_new_invoice_note_notification( $invoice_id, $new_status = '' ) { |
|
439 | +function wpinv_new_invoice_note_notification($invoice_id, $new_status = '') { |
|
440 | 440 | } |
441 | 441 | |
442 | -function wpinv_user_invoice_notification( $invoice_id ) { |
|
442 | +function wpinv_user_invoice_notification($invoice_id) { |
|
443 | 443 | $email_type = 'user_invoice'; |
444 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
444 | + if (!wpinv_email_is_enabled($email_type)) { |
|
445 | 445 | return -1; |
446 | 446 | } |
447 | 447 | |
448 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
449 | - if ( empty( $invoice ) ) { |
|
448 | + $invoice = wpinv_get_invoice($invoice_id); |
|
449 | + if (empty($invoice)) { |
|
450 | 450 | return false; |
451 | 451 | } |
452 | 452 | |
453 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
453 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
454 | 454 | return false; |
455 | 455 | } |
456 | 456 | |
457 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
458 | - if ( !is_email( $recipient ) ) { |
|
457 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
458 | + if (!is_email($recipient)) { |
|
459 | 459 | return false; |
460 | 460 | } |
461 | 461 | |
462 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
463 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
464 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
465 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
466 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
462 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
463 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
464 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
465 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
466 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
467 | 467 | |
468 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
468 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
469 | 469 | 'invoice' => $invoice, |
470 | 470 | 'email_type' => $email_type, |
471 | 471 | 'email_heading' => $email_heading, |
472 | 472 | 'sent_to_admin' => false, |
473 | 473 | 'plain_text' => false, |
474 | 474 | 'message_body' => $message_body, |
475 | - ) ); |
|
475 | + )); |
|
476 | 476 | |
477 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
477 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
478 | 478 | |
479 | - if ( $sent ) { |
|
480 | - $note = __( 'Invoice has been emailed to the user.', 'invoicing' ); |
|
479 | + if ($sent) { |
|
480 | + $note = __('Invoice has been emailed to the user.', 'invoicing'); |
|
481 | 481 | } else { |
482 | - $note = __( 'Fail to send invoice to the user!', 'invoicing' ); |
|
482 | + $note = __('Fail to send invoice to the user!', 'invoicing'); |
|
483 | 483 | } |
484 | 484 | |
485 | - $invoice->add_note( $note, '', '', true ); // Add system note. |
|
485 | + $invoice->add_note($note, '', '', true); // Add system note. |
|
486 | 486 | |
487 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
488 | - $recipient = wpinv_get_admin_email(); |
|
489 | - $subject .= ' - ADMIN BCC COPY'; |
|
490 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
487 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
488 | + $recipient = wpinv_get_admin_email(); |
|
489 | + $subject .= ' - ADMIN BCC COPY'; |
|
490 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
491 | 491 | } |
492 | 492 | |
493 | 493 | return $sent; |
494 | 494 | } |
495 | 495 | |
496 | -function wpinv_user_note_notification( $invoice_id, $args = array() ) { |
|
496 | +function wpinv_user_note_notification($invoice_id, $args = array()) { |
|
497 | 497 | $email_type = 'user_note'; |
498 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
498 | + if (!wpinv_email_is_enabled($email_type)) { |
|
499 | 499 | return false; |
500 | 500 | } |
501 | 501 | |
502 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
503 | - if ( empty( $invoice ) ) { |
|
502 | + $invoice = wpinv_get_invoice($invoice_id); |
|
503 | + if (empty($invoice)) { |
|
504 | 504 | return false; |
505 | 505 | } |
506 | 506 | |
507 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
508 | - if ( !is_email( $recipient ) ) { |
|
507 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
508 | + if (!is_email($recipient)) { |
|
509 | 509 | return false; |
510 | 510 | } |
511 | 511 | |
@@ -513,17 +513,17 @@ discard block |
||
513 | 513 | 'user_note' => '' |
514 | 514 | ); |
515 | 515 | |
516 | - $args = wp_parse_args( $args, $defaults ); |
|
516 | + $args = wp_parse_args($args, $defaults); |
|
517 | 517 | |
518 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
519 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
520 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
521 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
522 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
518 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
519 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
520 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
521 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
522 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
523 | 523 | |
524 | - $message_body = str_replace( '{customer_note}', $args['user_note'], $message_body ); |
|
524 | + $message_body = str_replace('{customer_note}', $args['user_note'], $message_body); |
|
525 | 525 | |
526 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
526 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
527 | 527 | 'invoice' => $invoice, |
528 | 528 | 'email_type' => $email_type, |
529 | 529 | 'email_heading' => $email_heading, |
@@ -531,34 +531,34 @@ discard block |
||
531 | 531 | 'plain_text' => false, |
532 | 532 | 'message_body' => $message_body, |
533 | 533 | 'customer_note' => $args['user_note'] |
534 | - ) ); |
|
534 | + )); |
|
535 | 535 | |
536 | - $content = wpinv_email_format_text( $content, $invoice ); |
|
536 | + $content = wpinv_email_format_text($content, $invoice); |
|
537 | 537 | |
538 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
538 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
539 | 539 | |
540 | 540 | return $sent; |
541 | 541 | } |
542 | 542 | |
543 | 543 | function wpinv_mail_get_from_address() { |
544 | - $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from' ) ); |
|
545 | - return sanitize_email( $from_address ); |
|
544 | + $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from')); |
|
545 | + return sanitize_email($from_address); |
|
546 | 546 | } |
547 | 547 | |
548 | 548 | function wpinv_mail_get_from_name() { |
549 | - $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name' ) ); |
|
550 | - return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES ); |
|
549 | + $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name')); |
|
550 | + return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES); |
|
551 | 551 | } |
552 | 552 | |
553 | -function wpinv_mail_admin_bcc_active( $mail_type = '' ) { |
|
554 | - $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) ); |
|
555 | - return ( $active ? true : false ); |
|
553 | +function wpinv_mail_admin_bcc_active($mail_type = '') { |
|
554 | + $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc')); |
|
555 | + return ($active ? true : false); |
|
556 | 556 | } |
557 | 557 | |
558 | -function wpinv_mail_get_content_type( $content_type = 'text/html', $email_type = 'html' ) { |
|
559 | - $email_type = apply_filters( 'wpinv_mail_content_type', $email_type ); |
|
558 | +function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') { |
|
559 | + $email_type = apply_filters('wpinv_mail_content_type', $email_type); |
|
560 | 560 | |
561 | - switch ( $email_type ) { |
|
561 | + switch ($email_type) { |
|
562 | 562 | case 'html' : |
563 | 563 | $content_type = 'text/html'; |
564 | 564 | break; |
@@ -573,35 +573,35 @@ discard block |
||
573 | 573 | return $content_type; |
574 | 574 | } |
575 | 575 | |
576 | -function wpinv_mail_send( $to, $subject, $message, $headers, $attachments ) { |
|
577 | - add_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' ); |
|
578 | - add_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' ); |
|
579 | - add_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' ); |
|
576 | +function wpinv_mail_send($to, $subject, $message, $headers, $attachments) { |
|
577 | + add_filter('wp_mail_from', 'wpinv_mail_get_from_address'); |
|
578 | + add_filter('wp_mail_from_name', 'wpinv_mail_get_from_name'); |
|
579 | + add_filter('wp_mail_content_type', 'wpinv_mail_get_content_type'); |
|
580 | 580 | |
581 | - $message = wpinv_email_style_body( $message ); |
|
582 | - $message = apply_filters( 'wpinv_mail_content', $message ); |
|
581 | + $message = wpinv_email_style_body($message); |
|
582 | + $message = apply_filters('wpinv_mail_content', $message); |
|
583 | 583 | |
584 | - $sent = wp_mail( $to, $subject, $message, $headers, $attachments ); |
|
584 | + $sent = wp_mail($to, $subject, $message, $headers, $attachments); |
|
585 | 585 | |
586 | - if ( !$sent ) { |
|
587 | - $log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), ( is_array( $to ) ? implode( ', ', $to ) : $to ), $subject ); |
|
588 | - wpinv_error_log( $log_message, __( "Email from Invoicing plugin failed to send", 'invoicing' ), __FILE__, __LINE__ ); |
|
586 | + if (!$sent) { |
|
587 | + $log_message = wp_sprintf(__("\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing'), date_i18n('F j Y H:i:s', current_time('timestamp')), (is_array($to) ? implode(', ', $to) : $to), $subject); |
|
588 | + wpinv_error_log($log_message, __("Email from Invoicing plugin failed to send", 'invoicing'), __FILE__, __LINE__); |
|
589 | 589 | } |
590 | 590 | |
591 | - remove_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' ); |
|
592 | - remove_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' ); |
|
593 | - remove_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' ); |
|
591 | + remove_filter('wp_mail_from', 'wpinv_mail_get_from_address'); |
|
592 | + remove_filter('wp_mail_from_name', 'wpinv_mail_get_from_name'); |
|
593 | + remove_filter('wp_mail_content_type', 'wpinv_mail_get_content_type'); |
|
594 | 594 | |
595 | 595 | return $sent; |
596 | 596 | } |
597 | 597 | |
598 | 598 | function wpinv_get_emails() { |
599 | 599 | $overdue_days_options = array(); |
600 | - $overdue_days_options[0] = __( 'On the Due Date', 'invoicing' ); |
|
601 | - $overdue_days_options[1] = __( '1 day after Due Date', 'invoicing' ); |
|
600 | + $overdue_days_options[0] = __('On the Due Date', 'invoicing'); |
|
601 | + $overdue_days_options[1] = __('1 day after Due Date', 'invoicing'); |
|
602 | 602 | |
603 | - for ( $i = 2; $i <= 10; $i++ ) { |
|
604 | - $overdue_days_options[$i] = wp_sprintf( __( '%d days after Due Date', 'invoicing' ), $i ); |
|
603 | + for ($i = 2; $i <= 10; $i++) { |
|
604 | + $overdue_days_options[$i] = wp_sprintf(__('%d days after Due Date', 'invoicing'), $i); |
|
605 | 605 | } |
606 | 606 | |
607 | 607 | // Default, built-in gateways |
@@ -609,39 +609,39 @@ discard block |
||
609 | 609 | 'new_invoice' => array( |
610 | 610 | 'email_new_invoice_header' => array( |
611 | 611 | 'id' => 'email_new_invoice_header', |
612 | - 'name' => '<h3>' . __( 'New Invoice', 'invoicing' ) . '</h3>', |
|
613 | - 'desc' => __( 'New invoice emails are sent to admin when a new invoice is received.', 'invoicing' ), |
|
612 | + 'name' => '<h3>' . __('New Invoice', 'invoicing') . '</h3>', |
|
613 | + 'desc' => __('New invoice emails are sent to admin when a new invoice is received.', 'invoicing'), |
|
614 | 614 | 'type' => 'header', |
615 | 615 | ), |
616 | 616 | 'email_new_invoice_active' => array( |
617 | 617 | 'id' => 'email_new_invoice_active', |
618 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
619 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
618 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
619 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
620 | 620 | 'type' => 'checkbox', |
621 | 621 | 'std' => 1 |
622 | 622 | ), |
623 | 623 | 'email_new_invoice_subject' => array( |
624 | 624 | 'id' => 'email_new_invoice_subject', |
625 | - 'name' => __( 'Subject', 'invoicing' ), |
|
626 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
625 | + 'name' => __('Subject', 'invoicing'), |
|
626 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
627 | 627 | 'type' => 'text', |
628 | - 'std' => __( '[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing' ), |
|
628 | + 'std' => __('[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing'), |
|
629 | 629 | 'size' => 'large' |
630 | 630 | ), |
631 | 631 | 'email_new_invoice_heading' => array( |
632 | 632 | 'id' => 'email_new_invoice_heading', |
633 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
634 | - 'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
633 | + 'name' => __('Email Heading', 'invoicing'), |
|
634 | + 'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
635 | 635 | 'type' => 'text', |
636 | - 'std' => __( 'New payment invoice', 'invoicing' ), |
|
636 | + 'std' => __('New payment invoice', 'invoicing'), |
|
637 | 637 | 'size' => 'large' |
638 | 638 | ), |
639 | 639 | 'email_new_invoice_body' => array( |
640 | 640 | 'id' => 'email_new_invoice_body', |
641 | - 'name' => __( 'Email Content', 'invoicing' ), |
|
642 | - 'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ), |
|
641 | + 'name' => __('Email Content', 'invoicing'), |
|
642 | + 'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'), |
|
643 | 643 | 'type' => 'rich_editor', |
644 | - 'std' => __( '<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing' ), |
|
644 | + 'std' => __('<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing'), |
|
645 | 645 | 'class' => 'large', |
646 | 646 | 'size' => '10' |
647 | 647 | ), |
@@ -649,39 +649,39 @@ discard block |
||
649 | 649 | 'cancelled_invoice' => array( |
650 | 650 | 'email_cancelled_invoice_header' => array( |
651 | 651 | 'id' => 'email_cancelled_invoice_header', |
652 | - 'name' => '<h3>' . __( 'Cancelled Invoice', 'invoicing' ) . '</h3>', |
|
653 | - 'desc' => __( 'Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing' ), |
|
652 | + 'name' => '<h3>' . __('Cancelled Invoice', 'invoicing') . '</h3>', |
|
653 | + 'desc' => __('Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing'), |
|
654 | 654 | 'type' => 'header', |
655 | 655 | ), |
656 | 656 | 'email_cancelled_invoice_active' => array( |
657 | 657 | 'id' => 'email_cancelled_invoice_active', |
658 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
659 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
658 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
659 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
660 | 660 | 'type' => 'checkbox', |
661 | 661 | 'std' => 1 |
662 | 662 | ), |
663 | 663 | 'email_cancelled_invoice_subject' => array( |
664 | 664 | 'id' => 'email_cancelled_invoice_subject', |
665 | - 'name' => __( 'Subject', 'invoicing' ), |
|
666 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
665 | + 'name' => __('Subject', 'invoicing'), |
|
666 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
667 | 667 | 'type' => 'text', |
668 | - 'std' => __( '[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing' ), |
|
668 | + 'std' => __('[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing'), |
|
669 | 669 | 'size' => 'large' |
670 | 670 | ), |
671 | 671 | 'email_cancelled_invoice_heading' => array( |
672 | 672 | 'id' => 'email_cancelled_invoice_heading', |
673 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
674 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
673 | + 'name' => __('Email Heading', 'invoicing'), |
|
674 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
675 | 675 | 'type' => 'text', |
676 | - 'std' => __( 'Cancelled invoice', 'invoicing' ), |
|
676 | + 'std' => __('Cancelled invoice', 'invoicing'), |
|
677 | 677 | 'size' => 'large' |
678 | 678 | ), |
679 | 679 | 'email_cancelled_invoice_body' => array( |
680 | 680 | 'id' => 'email_cancelled_invoice_body', |
681 | - 'name' => __( 'Email Content', 'invoicing' ), |
|
682 | - 'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ), |
|
681 | + 'name' => __('Email Content', 'invoicing'), |
|
682 | + 'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'), |
|
683 | 683 | 'type' => 'rich_editor', |
684 | - 'std' => __( '<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing' ), |
|
684 | + 'std' => __('<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing'), |
|
685 | 685 | 'class' => 'large', |
686 | 686 | 'size' => '10' |
687 | 687 | ), |
@@ -689,39 +689,39 @@ discard block |
||
689 | 689 | 'failed_invoice' => array( |
690 | 690 | 'email_failed_invoice_header' => array( |
691 | 691 | 'id' => 'email_failed_invoice_header', |
692 | - 'name' => '<h3>' . __( 'Failed Invoice', 'invoicing' ) . '</h3>', |
|
693 | - 'desc' => __( 'Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing' ), |
|
692 | + 'name' => '<h3>' . __('Failed Invoice', 'invoicing') . '</h3>', |
|
693 | + 'desc' => __('Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing'), |
|
694 | 694 | 'type' => 'header', |
695 | 695 | ), |
696 | 696 | 'email_failed_invoice_active' => array( |
697 | 697 | 'id' => 'email_failed_invoice_active', |
698 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
699 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
698 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
699 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
700 | 700 | 'type' => 'checkbox', |
701 | 701 | 'std' => 1 |
702 | 702 | ), |
703 | 703 | 'email_failed_invoice_subject' => array( |
704 | 704 | 'id' => 'email_failed_invoice_subject', |
705 | - 'name' => __( 'Subject', 'invoicing' ), |
|
706 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
705 | + 'name' => __('Subject', 'invoicing'), |
|
706 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
707 | 707 | 'type' => 'text', |
708 | - 'std' => __( '[{site_title}] Failed invoice ({invoice_number})', 'invoicing' ), |
|
708 | + 'std' => __('[{site_title}] Failed invoice ({invoice_number})', 'invoicing'), |
|
709 | 709 | 'size' => 'large' |
710 | 710 | ), |
711 | 711 | 'email_failed_invoice_heading' => array( |
712 | 712 | 'id' => 'email_failed_invoice_heading', |
713 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
714 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
713 | + 'name' => __('Email Heading', 'invoicing'), |
|
714 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
715 | 715 | 'type' => 'text', |
716 | - 'std' => __( 'Failed invoice', 'invoicing' ), |
|
716 | + 'std' => __('Failed invoice', 'invoicing'), |
|
717 | 717 | 'size' => 'large' |
718 | 718 | ), |
719 | 719 | 'email_failed_invoice_body' => array( |
720 | 720 | 'id' => 'email_failed_invoice_body', |
721 | - 'name' => __( 'Email Content', 'invoicing' ), |
|
722 | - 'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ), |
|
721 | + 'name' => __('Email Content', 'invoicing'), |
|
722 | + 'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'), |
|
723 | 723 | 'type' => 'rich_editor', |
724 | - 'std' => __( '<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing' ), |
|
724 | + 'std' => __('<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing'), |
|
725 | 725 | 'class' => 'large', |
726 | 726 | 'size' => '10' |
727 | 727 | ), |
@@ -729,46 +729,46 @@ discard block |
||
729 | 729 | 'onhold_invoice' => array( |
730 | 730 | 'email_onhold_invoice_header' => array( |
731 | 731 | 'id' => 'email_onhold_invoice_header', |
732 | - 'name' => '<h3>' . __( 'On Hold Invoice', 'invoicing' ) . '</h3>', |
|
733 | - 'desc' => __( 'This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing' ), |
|
732 | + 'name' => '<h3>' . __('On Hold Invoice', 'invoicing') . '</h3>', |
|
733 | + 'desc' => __('This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing'), |
|
734 | 734 | 'type' => 'header', |
735 | 735 | ), |
736 | 736 | 'email_onhold_invoice_active' => array( |
737 | 737 | 'id' => 'email_onhold_invoice_active', |
738 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
739 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
738 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
739 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
740 | 740 | 'type' => 'checkbox', |
741 | 741 | 'std' => 1 |
742 | 742 | ), |
743 | 743 | 'email_onhold_invoice_subject' => array( |
744 | 744 | 'id' => 'email_onhold_invoice_subject', |
745 | - 'name' => __( 'Subject', 'invoicing' ), |
|
746 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
745 | + 'name' => __('Subject', 'invoicing'), |
|
746 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
747 | 747 | 'type' => 'text', |
748 | - 'std' => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ), |
|
748 | + 'std' => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'), |
|
749 | 749 | 'size' => 'large' |
750 | 750 | ), |
751 | 751 | 'email_onhold_invoice_heading' => array( |
752 | 752 | 'id' => 'email_onhold_invoice_heading', |
753 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
754 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
753 | + 'name' => __('Email Heading', 'invoicing'), |
|
754 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
755 | 755 | 'type' => 'text', |
756 | - 'std' => __( 'Thank you for your invoice', 'invoicing' ), |
|
756 | + 'std' => __('Thank you for your invoice', 'invoicing'), |
|
757 | 757 | 'size' => 'large' |
758 | 758 | ), |
759 | 759 | 'email_onhold_invoice_admin_bcc' => array( |
760 | 760 | 'id' => 'email_onhold_invoice_admin_bcc', |
761 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
762 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
761 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
762 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
763 | 763 | 'type' => 'checkbox', |
764 | 764 | 'std' => 1 |
765 | 765 | ), |
766 | 766 | 'email_onhold_invoice_body' => array( |
767 | 767 | 'id' => 'email_onhold_invoice_body', |
768 | - 'name' => __( 'Email Content', 'invoicing' ), |
|
769 | - 'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ), |
|
768 | + 'name' => __('Email Content', 'invoicing'), |
|
769 | + 'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'), |
|
770 | 770 | 'type' => 'rich_editor', |
771 | - 'std' => __( '<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing' ), |
|
771 | + 'std' => __('<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing'), |
|
772 | 772 | 'class' => 'large', |
773 | 773 | 'size' => '10' |
774 | 774 | ), |
@@ -776,46 +776,46 @@ discard block |
||
776 | 776 | 'processing_invoice' => array( |
777 | 777 | 'email_processing_invoice_header' => array( |
778 | 778 | 'id' => 'email_processing_invoice_header', |
779 | - 'name' => '<h3>' . __( 'Processing Invoice', 'invoicing' ) . '</h3>', |
|
780 | - 'desc' => __( 'This is an invoice notification sent to users containing invoice details after payment.', 'invoicing' ), |
|
779 | + 'name' => '<h3>' . __('Processing Invoice', 'invoicing') . '</h3>', |
|
780 | + 'desc' => __('This is an invoice notification sent to users containing invoice details after payment.', 'invoicing'), |
|
781 | 781 | 'type' => 'header', |
782 | 782 | ), |
783 | 783 | 'email_processing_invoice_active' => array( |
784 | 784 | 'id' => 'email_processing_invoice_active', |
785 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
786 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
785 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
786 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
787 | 787 | 'type' => 'checkbox', |
788 | 788 | 'std' => 1 |
789 | 789 | ), |
790 | 790 | 'email_processing_invoice_subject' => array( |
791 | 791 | 'id' => 'email_processing_invoice_subject', |
792 | - 'name' => __( 'Subject', 'invoicing' ), |
|
793 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
792 | + 'name' => __('Subject', 'invoicing'), |
|
793 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
794 | 794 | 'type' => 'text', |
795 | - 'std' => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ), |
|
795 | + 'std' => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'), |
|
796 | 796 | 'size' => 'large' |
797 | 797 | ), |
798 | 798 | 'email_processing_invoice_heading' => array( |
799 | 799 | 'id' => 'email_processing_invoice_heading', |
800 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
801 | - 'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
800 | + 'name' => __('Email Heading', 'invoicing'), |
|
801 | + 'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
802 | 802 | 'type' => 'text', |
803 | - 'std' => __( 'Thank you for your invoice', 'invoicing' ), |
|
803 | + 'std' => __('Thank you for your invoice', 'invoicing'), |
|
804 | 804 | 'size' => 'large' |
805 | 805 | ), |
806 | 806 | 'email_processing_invoice_admin_bcc' => array( |
807 | 807 | 'id' => 'email_processing_invoice_admin_bcc', |
808 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
809 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
808 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
809 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
810 | 810 | 'type' => 'checkbox', |
811 | 811 | 'std' => 1 |
812 | 812 | ), |
813 | 813 | 'email_processing_invoice_body' => array( |
814 | 814 | 'id' => 'email_processing_invoice_body', |
815 | - 'name' => __( 'Email Content', 'invoicing' ), |
|
816 | - 'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ), |
|
815 | + 'name' => __('Email Content', 'invoicing'), |
|
816 | + 'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'), |
|
817 | 817 | 'type' => 'rich_editor', |
818 | - 'std' => __( '<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing' ), |
|
818 | + 'std' => __('<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing'), |
|
819 | 819 | 'class' => 'large', |
820 | 820 | 'size' => '10' |
821 | 821 | ), |
@@ -823,45 +823,45 @@ discard block |
||
823 | 823 | 'completed_invoice' => array( |
824 | 824 | 'email_completed_invoice_header' => array( |
825 | 825 | 'id' => 'email_completed_invoice_header', |
826 | - 'name' => '<h3>' . __( 'Paid Invoice', 'invoicing' ) . '</h3>', |
|
827 | - 'desc' => __( 'Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing' ), |
|
826 | + 'name' => '<h3>' . __('Paid Invoice', 'invoicing') . '</h3>', |
|
827 | + 'desc' => __('Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing'), |
|
828 | 828 | 'type' => 'header', |
829 | 829 | ), |
830 | 830 | 'email_completed_invoice_active' => array( |
831 | 831 | 'id' => 'email_completed_invoice_active', |
832 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
833 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
832 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
833 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
834 | 834 | 'type' => 'checkbox', |
835 | 835 | 'std' => 1 |
836 | 836 | ), |
837 | 837 | 'email_completed_invoice_subject' => array( |
838 | 838 | 'id' => 'email_completed_invoice_subject', |
839 | - 'name' => __( 'Subject', 'invoicing' ), |
|
840 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
839 | + 'name' => __('Subject', 'invoicing'), |
|
840 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
841 | 841 | 'type' => 'text', |
842 | - 'std' => __( '[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing' ), |
|
842 | + 'std' => __('[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing'), |
|
843 | 843 | 'size' => 'large' |
844 | 844 | ), |
845 | 845 | 'email_completed_invoice_heading' => array( |
846 | 846 | 'id' => 'email_completed_invoice_heading', |
847 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
848 | - 'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
847 | + 'name' => __('Email Heading', 'invoicing'), |
|
848 | + 'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
849 | 849 | 'type' => 'text', |
850 | - 'std' => __( 'Your invoice has been paid', 'invoicing' ), |
|
850 | + 'std' => __('Your invoice has been paid', 'invoicing'), |
|
851 | 851 | 'size' => 'large' |
852 | 852 | ), |
853 | 853 | 'email_completed_invoice_admin_bcc' => array( |
854 | 854 | 'id' => 'email_completed_invoice_admin_bcc', |
855 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
856 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
855 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
856 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
857 | 857 | 'type' => 'checkbox', |
858 | 858 | ), |
859 | 859 | 'email_completed_invoice_body' => array( |
860 | 860 | 'id' => 'email_completed_invoice_body', |
861 | - 'name' => __( 'Email Content', 'invoicing' ), |
|
862 | - 'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ), |
|
861 | + 'name' => __('Email Content', 'invoicing'), |
|
862 | + 'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'), |
|
863 | 863 | 'type' => 'rich_editor', |
864 | - 'std' => __( '<p>Hi {name},</p><p>Your recent invoice on {site_title} has been paid.</p>', 'invoicing' ), |
|
864 | + 'std' => __('<p>Hi {name},</p><p>Your recent invoice on {site_title} has been paid.</p>', 'invoicing'), |
|
865 | 865 | 'class' => 'large', |
866 | 866 | 'size' => '10' |
867 | 867 | ), |
@@ -870,46 +870,46 @@ discard block |
||
870 | 870 | 'refunded_invoice' => array( |
871 | 871 | 'email_refunded_invoice_header' => array( |
872 | 872 | 'id' => 'email_refunded_invoice_header', |
873 | - 'name' => '<h3>' . __( 'Refunded Invoice', 'invoicing' ) . '</h3>', |
|
874 | - 'desc' => __( 'Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing' ), |
|
873 | + 'name' => '<h3>' . __('Refunded Invoice', 'invoicing') . '</h3>', |
|
874 | + 'desc' => __('Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing'), |
|
875 | 875 | 'type' => 'header', |
876 | 876 | ), |
877 | 877 | 'email_refunded_invoice_active' => array( |
878 | 878 | 'id' => 'email_refunded_invoice_active', |
879 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
880 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
879 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
880 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
881 | 881 | 'type' => 'checkbox', |
882 | 882 | 'std' => 1 |
883 | 883 | ), |
884 | 884 | 'email_refunded_invoice_subject' => array( |
885 | 885 | 'id' => 'email_refunded_invoice_subject', |
886 | - 'name' => __( 'Subject', 'invoicing' ), |
|
887 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
886 | + 'name' => __('Subject', 'invoicing'), |
|
887 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
888 | 888 | 'type' => 'text', |
889 | - 'std' => __( '[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing' ), |
|
889 | + 'std' => __('[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing'), |
|
890 | 890 | 'size' => 'large' |
891 | 891 | ), |
892 | 892 | 'email_refunded_invoice_heading' => array( |
893 | 893 | 'id' => 'email_refunded_invoice_heading', |
894 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
895 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
894 | + 'name' => __('Email Heading', 'invoicing'), |
|
895 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
896 | 896 | 'type' => 'text', |
897 | - 'std' => __( 'Your invoice has been refunded', 'invoicing' ), |
|
897 | + 'std' => __('Your invoice has been refunded', 'invoicing'), |
|
898 | 898 | 'size' => 'large' |
899 | 899 | ), |
900 | 900 | 'email_refunded_invoice_admin_bcc' => array( |
901 | 901 | 'id' => 'email_refunded_invoice_admin_bcc', |
902 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
903 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
902 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
903 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
904 | 904 | 'type' => 'checkbox', |
905 | 905 | 'std' => 1 |
906 | 906 | ), |
907 | 907 | 'email_refunded_invoice_body' => array( |
908 | 908 | 'id' => 'email_refunded_invoice_body', |
909 | - 'name' => __( 'Email Content', 'invoicing' ), |
|
910 | - 'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ), |
|
909 | + 'name' => __('Email Content', 'invoicing'), |
|
910 | + 'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'), |
|
911 | 911 | 'type' => 'rich_editor', |
912 | - 'std' => __( '<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing' ), |
|
912 | + 'std' => __('<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing'), |
|
913 | 913 | 'class' => 'large', |
914 | 914 | 'size' => '10' |
915 | 915 | ), |
@@ -917,46 +917,46 @@ discard block |
||
917 | 917 | 'user_invoice' => array( |
918 | 918 | 'email_user_invoice_header' => array( |
919 | 919 | 'id' => 'email_user_invoice_header', |
920 | - 'name' => '<h3>' . __( 'Customer Invoice', 'invoicing' ) . '</h3>', |
|
921 | - 'desc' => __( 'Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing' ), |
|
920 | + 'name' => '<h3>' . __('Customer Invoice', 'invoicing') . '</h3>', |
|
921 | + 'desc' => __('Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing'), |
|
922 | 922 | 'type' => 'header', |
923 | 923 | ), |
924 | 924 | 'email_user_invoice_active' => array( |
925 | 925 | 'id' => 'email_user_invoice_active', |
926 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
927 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
926 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
927 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
928 | 928 | 'type' => 'checkbox', |
929 | 929 | 'std' => 1 |
930 | 930 | ), |
931 | 931 | 'email_user_invoice_subject' => array( |
932 | 932 | 'id' => 'email_user_invoice_subject', |
933 | - 'name' => __( 'Subject', 'invoicing' ), |
|
934 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
933 | + 'name' => __('Subject', 'invoicing'), |
|
934 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
935 | 935 | 'type' => 'text', |
936 | - 'std' => __( '[{site_title}] Your invoice from {invoice_date}', 'invoicing' ), |
|
936 | + 'std' => __('[{site_title}] Your invoice from {invoice_date}', 'invoicing'), |
|
937 | 937 | 'size' => 'large' |
938 | 938 | ), |
939 | 939 | 'email_user_invoice_heading' => array( |
940 | 940 | 'id' => 'email_user_invoice_heading', |
941 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
942 | - 'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
941 | + 'name' => __('Email Heading', 'invoicing'), |
|
942 | + 'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
943 | 943 | 'type' => 'text', |
944 | - 'std' => __( 'Your invoice {invoice_number} details', 'invoicing' ), |
|
944 | + 'std' => __('Your invoice {invoice_number} details', 'invoicing'), |
|
945 | 945 | 'size' => 'large' |
946 | 946 | ), |
947 | 947 | 'email_user_invoice_admin_bcc' => array( |
948 | 948 | 'id' => 'email_user_invoice_admin_bcc', |
949 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
950 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
949 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
950 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
951 | 951 | 'type' => 'checkbox', |
952 | 952 | 'std' => 1 |
953 | 953 | ), |
954 | 954 | 'email_user_invoice_body' => array( |
955 | 955 | 'id' => 'email_user_invoice_body', |
956 | - 'name' => __( 'Email Content', 'invoicing' ), |
|
957 | - 'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ), |
|
956 | + 'name' => __('Email Content', 'invoicing'), |
|
957 | + 'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'), |
|
958 | 958 | 'type' => 'rich_editor', |
959 | - 'std' => __( '<p>Hi {name},</p><p>An invoice has been created for you on {site_title}. To view / pay for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ), |
|
959 | + 'std' => __('<p>Hi {name},</p><p>An invoice has been created for you on {site_title}. To view / pay for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing'), |
|
960 | 960 | 'class' => 'large', |
961 | 961 | 'size' => '10' |
962 | 962 | ), |
@@ -964,39 +964,39 @@ discard block |
||
964 | 964 | 'user_note' => array( |
965 | 965 | 'email_user_note_header' => array( |
966 | 966 | 'id' => 'email_user_note_header', |
967 | - 'name' => '<h3>' . __( 'Customer Note', 'invoicing' ) . '</h3>', |
|
968 | - 'desc' => __( 'Customer note emails are sent when you add a note to an invoice/quote.', 'invoicing' ), |
|
967 | + 'name' => '<h3>' . __('Customer Note', 'invoicing') . '</h3>', |
|
968 | + 'desc' => __('Customer note emails are sent when you add a note to an invoice/quote.', 'invoicing'), |
|
969 | 969 | 'type' => 'header', |
970 | 970 | ), |
971 | 971 | 'email_user_note_active' => array( |
972 | 972 | 'id' => 'email_user_note_active', |
973 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
974 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
973 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
974 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
975 | 975 | 'type' => 'checkbox', |
976 | 976 | 'std' => 1 |
977 | 977 | ), |
978 | 978 | 'email_user_note_subject' => array( |
979 | 979 | 'id' => 'email_user_note_subject', |
980 | - 'name' => __( 'Subject', 'invoicing' ), |
|
981 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
980 | + 'name' => __('Subject', 'invoicing'), |
|
981 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
982 | 982 | 'type' => 'text', |
983 | - 'std' => __( '[{site_title}] Note added to your {invoice_label} #{invoice_number} from {invoice_date}', 'invoicing' ), |
|
983 | + 'std' => __('[{site_title}] Note added to your {invoice_label} #{invoice_number} from {invoice_date}', 'invoicing'), |
|
984 | 984 | 'size' => 'large' |
985 | 985 | ), |
986 | 986 | 'email_user_note_heading' => array( |
987 | 987 | 'id' => 'email_user_note_heading', |
988 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
989 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
988 | + 'name' => __('Email Heading', 'invoicing'), |
|
989 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
990 | 990 | 'type' => 'text', |
991 | - 'std' => __( 'A note has been added to your {invoice_label}', 'invoicing' ), |
|
991 | + 'std' => __('A note has been added to your {invoice_label}', 'invoicing'), |
|
992 | 992 | 'size' => 'large' |
993 | 993 | ), |
994 | 994 | 'email_user_note_body' => array( |
995 | 995 | 'id' => 'email_user_note_body', |
996 | - 'name' => __( 'Email Content', 'invoicing' ), |
|
997 | - 'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ), |
|
996 | + 'name' => __('Email Content', 'invoicing'), |
|
997 | + 'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'), |
|
998 | 998 | 'type' => 'rich_editor', |
999 | - 'std' => __( '<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing' ), |
|
999 | + 'std' => __('<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing'), |
|
1000 | 1000 | 'class' => 'large', |
1001 | 1001 | 'size' => '10' |
1002 | 1002 | ), |
@@ -1004,155 +1004,155 @@ discard block |
||
1004 | 1004 | 'overdue' => array( |
1005 | 1005 | 'email_overdue_header' => array( |
1006 | 1006 | 'id' => 'email_overdue_header', |
1007 | - 'name' => '<h3>' . __( 'Payment Reminder', 'invoicing' ) . '</h3>', |
|
1008 | - 'desc' => __( 'Payment reminder emails are sent to user automatically.', 'invoicing' ), |
|
1007 | + 'name' => '<h3>' . __('Payment Reminder', 'invoicing') . '</h3>', |
|
1008 | + 'desc' => __('Payment reminder emails are sent to user automatically.', 'invoicing'), |
|
1009 | 1009 | 'type' => 'header', |
1010 | 1010 | ), |
1011 | 1011 | 'email_overdue_active' => array( |
1012 | 1012 | 'id' => 'email_overdue_active', |
1013 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
1014 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
1013 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
1014 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
1015 | 1015 | 'type' => 'checkbox', |
1016 | 1016 | 'std' => 1 |
1017 | 1017 | ), |
1018 | 1018 | 'email_due_reminder_days' => array( |
1019 | 1019 | 'id' => 'email_due_reminder_days', |
1020 | - 'name' => __( 'When to Send', 'invoicing' ), |
|
1021 | - 'desc' => __( 'Check when you would like payment reminders sent out.', 'invoicing' ), |
|
1020 | + 'name' => __('When to Send', 'invoicing'), |
|
1021 | + 'desc' => __('Check when you would like payment reminders sent out.', 'invoicing'), |
|
1022 | 1022 | 'default' => '', |
1023 | 1023 | 'type' => 'multicheck', |
1024 | 1024 | 'options' => $overdue_days_options, |
1025 | 1025 | ), |
1026 | 1026 | 'email_overdue_subject' => array( |
1027 | 1027 | 'id' => 'email_overdue_subject', |
1028 | - 'name' => __( 'Subject', 'invoicing' ), |
|
1029 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
1028 | + 'name' => __('Subject', 'invoicing'), |
|
1029 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
1030 | 1030 | 'type' => 'text', |
1031 | - 'std' => __( '[{site_title}] Payment Reminder', 'invoicing' ), |
|
1031 | + 'std' => __('[{site_title}] Payment Reminder', 'invoicing'), |
|
1032 | 1032 | 'size' => 'large' |
1033 | 1033 | ), |
1034 | 1034 | 'email_overdue_heading' => array( |
1035 | 1035 | 'id' => 'email_overdue_heading', |
1036 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
1037 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
1036 | + 'name' => __('Email Heading', 'invoicing'), |
|
1037 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
1038 | 1038 | 'type' => 'text', |
1039 | - 'std' => __( 'Payment reminder for your invoice', 'invoicing' ), |
|
1039 | + 'std' => __('Payment reminder for your invoice', 'invoicing'), |
|
1040 | 1040 | 'size' => 'large' |
1041 | 1041 | ), |
1042 | 1042 | 'email_overdue_body' => array( |
1043 | 1043 | 'id' => 'email_overdue_body', |
1044 | - 'name' => __( 'Email Content', 'invoicing' ), |
|
1045 | - 'desc' => __( 'The content of the email.', 'invoicing' ), |
|
1044 | + 'name' => __('Email Content', 'invoicing'), |
|
1045 | + 'desc' => __('The content of the email.', 'invoicing'), |
|
1046 | 1046 | 'type' => 'rich_editor', |
1047 | - 'std' => __( '<p>Hi {full_name},</p><p>This is just a friendly reminder that your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To view / pay now for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ), |
|
1047 | + 'std' => __('<p>Hi {full_name},</p><p>This is just a friendly reminder that your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To view / pay now for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing'), |
|
1048 | 1048 | 'class' => 'large', |
1049 | 1049 | 'size' => 10, |
1050 | 1050 | ), |
1051 | 1051 | ), |
1052 | 1052 | ); |
1053 | 1053 | |
1054 | - return apply_filters( 'wpinv_get_emails', $emails ); |
|
1054 | + return apply_filters('wpinv_get_emails', $emails); |
|
1055 | 1055 | } |
1056 | 1056 | |
1057 | -function wpinv_settings_emails( $settings = array() ) { |
|
1057 | +function wpinv_settings_emails($settings = array()) { |
|
1058 | 1058 | $emails = wpinv_get_emails(); |
1059 | 1059 | |
1060 | - if ( !empty( $emails ) ) { |
|
1061 | - foreach ( $emails as $key => $email ) { |
|
1060 | + if (!empty($emails)) { |
|
1061 | + foreach ($emails as $key => $email) { |
|
1062 | 1062 | $settings[$key] = $email; |
1063 | 1063 | } |
1064 | 1064 | } |
1065 | 1065 | |
1066 | - return apply_filters( 'wpinv_settings_get_emails', $settings ); |
|
1066 | + return apply_filters('wpinv_settings_get_emails', $settings); |
|
1067 | 1067 | } |
1068 | -add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 ); |
|
1068 | +add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1); |
|
1069 | 1069 | |
1070 | -function wpinv_settings_sections_emails( $settings ) { |
|
1070 | +function wpinv_settings_sections_emails($settings) { |
|
1071 | 1071 | $emails = wpinv_get_emails(); |
1072 | 1072 | |
1073 | 1073 | if (!empty($emails)) { |
1074 | - foreach ($emails as $key => $email) { |
|
1075 | - $settings[$key] = !empty( $email['email_' . $key . '_header']['name'] ) ? strip_tags( $email['email_' . $key . '_header']['name'] ) : $key; |
|
1074 | + foreach ($emails as $key => $email) { |
|
1075 | + $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : $key; |
|
1076 | 1076 | } |
1077 | 1077 | } |
1078 | 1078 | |
1079 | 1079 | return $settings; |
1080 | 1080 | } |
1081 | -add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 ); |
|
1081 | +add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1); |
|
1082 | 1082 | |
1083 | -function wpinv_email_is_enabled( $email_type ) { |
|
1083 | +function wpinv_email_is_enabled($email_type) { |
|
1084 | 1084 | $emails = wpinv_get_emails(); |
1085 | - $enabled = isset( $emails[$email_type] ) && wpinv_get_option( 'email_'. $email_type . '_active', 0 ) ? true : false; |
|
1085 | + $enabled = isset($emails[$email_type]) && wpinv_get_option('email_' . $email_type . '_active', 0) ? true : false; |
|
1086 | 1086 | |
1087 | - return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type ); |
|
1087 | + return apply_filters('wpinv_email_is_enabled', $enabled, $email_type); |
|
1088 | 1088 | } |
1089 | 1089 | |
1090 | -function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1091 | - switch ( $email_type ) { |
|
1090 | +function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1091 | + switch ($email_type) { |
|
1092 | 1092 | case 'new_invoice': |
1093 | 1093 | case 'cancelled_invoice': |
1094 | 1094 | case 'failed_invoice': |
1095 | 1095 | $recipient = wpinv_get_admin_email(); |
1096 | 1096 | break; |
1097 | 1097 | default: |
1098 | - $invoice = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL ); |
|
1099 | - $recipient = !empty( $invoice ) ? $invoice->get_email() : ''; |
|
1098 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL); |
|
1099 | + $recipient = !empty($invoice) ? $invoice->get_email() : ''; |
|
1100 | 1100 | break; |
1101 | 1101 | } |
1102 | 1102 | |
1103 | - return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice ); |
|
1103 | + return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice); |
|
1104 | 1104 | } |
1105 | 1105 | |
1106 | -function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1107 | - $subject = wpinv_get_option( 'email_' . $email_type . '_subject' ); |
|
1106 | +function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1107 | + $subject = wpinv_get_option('email_' . $email_type . '_subject'); |
|
1108 | 1108 | |
1109 | - $subject = wpinv_email_format_text( $subject, $invoice ); |
|
1109 | + $subject = wpinv_email_format_text($subject, $invoice); |
|
1110 | 1110 | |
1111 | - return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice ); |
|
1111 | + return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice); |
|
1112 | 1112 | } |
1113 | 1113 | |
1114 | -function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1115 | - $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' ); |
|
1114 | +function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1115 | + $email_heading = wpinv_get_option('email_' . $email_type . '_heading'); |
|
1116 | 1116 | |
1117 | - $email_heading = wpinv_email_format_text( $email_heading, $invoice ); |
|
1117 | + $email_heading = wpinv_email_format_text($email_heading, $invoice); |
|
1118 | 1118 | |
1119 | - return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice ); |
|
1119 | + return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice); |
|
1120 | 1120 | } |
1121 | 1121 | |
1122 | -function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1123 | - $content = wpinv_get_option( 'email_' . $email_type . '_body' ); |
|
1122 | +function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1123 | + $content = wpinv_get_option('email_' . $email_type . '_body'); |
|
1124 | 1124 | |
1125 | - $content = wpinv_email_format_text( $content, $invoice ); |
|
1125 | + $content = wpinv_email_format_text($content, $invoice); |
|
1126 | 1126 | |
1127 | - return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice ); |
|
1127 | + return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice); |
|
1128 | 1128 | } |
1129 | 1129 | |
1130 | -function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1130 | +function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1131 | 1131 | $from_name = wpinv_mail_get_from_address(); |
1132 | 1132 | $from_email = wpinv_mail_get_from_address(); |
1133 | 1133 | |
1134 | - $invoice = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL ); |
|
1134 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL); |
|
1135 | 1135 | |
1136 | - $headers = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n"; |
|
1137 | - $headers .= "Reply-To: ". $from_email . "\r\n"; |
|
1136 | + $headers = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n"; |
|
1137 | + $headers .= "Reply-To: " . $from_email . "\r\n"; |
|
1138 | 1138 | $headers .= "Content-Type: " . wpinv_mail_get_content_type() . "\r\n"; |
1139 | 1139 | |
1140 | - return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice ); |
|
1140 | + return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice); |
|
1141 | 1141 | } |
1142 | 1142 | |
1143 | -function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1143 | +function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1144 | 1144 | $attachments = array(); |
1145 | 1145 | |
1146 | - return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice ); |
|
1146 | + return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice); |
|
1147 | 1147 | } |
1148 | 1148 | |
1149 | -function wpinv_email_format_text( $content, $invoice ) { |
|
1149 | +function wpinv_email_format_text($content, $invoice) { |
|
1150 | 1150 | $replace_array = array( |
1151 | 1151 | '{site_title}' => wpinv_get_blogname(), |
1152 | - '{date}' => date_i18n( get_option( 'date_format' ), (int) current_time( 'timestamp' ) ), |
|
1152 | + '{date}' => date_i18n(get_option('date_format'), (int)current_time('timestamp')), |
|
1153 | 1153 | ); |
1154 | 1154 | |
1155 | - if ( !empty( $invoice->ID ) ) { |
|
1155 | + if (!empty($invoice->ID)) { |
|
1156 | 1156 | $replace_array = array_merge( |
1157 | 1157 | $replace_array, |
1158 | 1158 | array( |
@@ -1162,65 +1162,65 @@ discard block |
||
1162 | 1162 | '{last_name}' => $invoice->get_last_name(), |
1163 | 1163 | '{email}' => $invoice->get_email(), |
1164 | 1164 | '{invoice_number}' => $invoice->get_number(), |
1165 | - '{invoice_total}' => $invoice->get_total( true ), |
|
1166 | - '{invoice_link}' => $invoice->get_view_url( true ), |
|
1167 | - '{invoice_pay_link}'=> $invoice->get_view_url( true ), |
|
1168 | - '{invoice_date}' => $invoice->get_invoice_date( true ), |
|
1169 | - '{invoice_due_date}'=> $invoice->get_due_date( true ), |
|
1170 | - '{invoice_quote}' => $invoice->get_invoice_quote_type( $invoice->ID ), |
|
1171 | - '{invoice_label}' => $invoice->get_invoice_quote_type( $invoice->ID ), |
|
1172 | - '{is_was}' => strtotime( $invoice->get_due_date() ) < strtotime( date_i18n( 'Y-m-d' ) ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
1165 | + '{invoice_total}' => $invoice->get_total(true), |
|
1166 | + '{invoice_link}' => $invoice->get_view_url(true), |
|
1167 | + '{invoice_pay_link}'=> $invoice->get_view_url(true), |
|
1168 | + '{invoice_date}' => $invoice->get_invoice_date(true), |
|
1169 | + '{invoice_due_date}'=> $invoice->get_due_date(true), |
|
1170 | + '{invoice_quote}' => $invoice->get_invoice_quote_type($invoice->ID), |
|
1171 | + '{invoice_label}' => $invoice->get_invoice_quote_type($invoice->ID), |
|
1172 | + '{is_was}' => strtotime($invoice->get_due_date()) < strtotime(date_i18n('Y-m-d')) ? __('was', 'invoicing') : __('is', 'invoicing'), |
|
1173 | 1173 | ) |
1174 | 1174 | ); |
1175 | 1175 | } |
1176 | 1176 | |
1177 | - $replace_array = apply_filters( 'wpinv_email_format_text', $replace_array, $content, $invoice ); |
|
1177 | + $replace_array = apply_filters('wpinv_email_format_text', $replace_array, $content, $invoice); |
|
1178 | 1178 | |
1179 | - foreach ( $replace_array as $key => $value ) { |
|
1180 | - $content = str_replace( $key, $value, $content ); |
|
1179 | + foreach ($replace_array as $key => $value) { |
|
1180 | + $content = str_replace($key, $value, $content); |
|
1181 | 1181 | } |
1182 | 1182 | |
1183 | - return apply_filters( 'wpinv_email_content_replace', $content ); |
|
1183 | + return apply_filters('wpinv_email_content_replace', $content); |
|
1184 | 1184 | } |
1185 | 1185 | |
1186 | -function wpinv_email_style_body( $content ) { |
|
1186 | +function wpinv_email_style_body($content) { |
|
1187 | 1187 | // make sure we only inline CSS for html emails |
1188 | - if ( in_array( wpinv_mail_get_content_type(), array( 'text/html', 'multipart/alternative' ) ) && class_exists( 'DOMDocument' ) ) { |
|
1188 | + if (in_array(wpinv_mail_get_content_type(), array('text/html', 'multipart/alternative')) && class_exists('DOMDocument')) { |
|
1189 | 1189 | ob_start(); |
1190 | - wpinv_get_template( 'emails/wpinv-email-styles.php' ); |
|
1191 | - $css = apply_filters( 'wpinv_email_styles', ob_get_clean() ); |
|
1190 | + wpinv_get_template('emails/wpinv-email-styles.php'); |
|
1191 | + $css = apply_filters('wpinv_email_styles', ob_get_clean()); |
|
1192 | 1192 | |
1193 | 1193 | // apply CSS styles inline for picky email clients |
1194 | 1194 | try { |
1195 | - $emogrifier = new Emogrifier( $content, $css ); |
|
1195 | + $emogrifier = new Emogrifier($content, $css); |
|
1196 | 1196 | $content = $emogrifier->emogrify(); |
1197 | - } catch ( Exception $e ) { |
|
1198 | - wpinv_error_log( $e->getMessage(), 'emogrifier' ); |
|
1197 | + } catch (Exception $e) { |
|
1198 | + wpinv_error_log($e->getMessage(), 'emogrifier'); |
|
1199 | 1199 | } |
1200 | 1200 | } |
1201 | 1201 | return $content; |
1202 | 1202 | } |
1203 | 1203 | |
1204 | -function wpinv_email_header( $email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false ) { |
|
1205 | - wpinv_get_template( 'emails/wpinv-email-header.php', array( 'email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1204 | +function wpinv_email_header($email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false) { |
|
1205 | + wpinv_get_template('emails/wpinv-email-header.php', array('email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1206 | 1206 | } |
1207 | 1207 | |
1208 | 1208 | /** |
1209 | 1209 | * Get the email footer. |
1210 | 1210 | */ |
1211 | -function wpinv_email_footer( $invoice = array(), $email_type = '', $sent_to_admin = false ) { |
|
1212 | - wpinv_get_template( 'emails/wpinv-email-footer.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1211 | +function wpinv_email_footer($invoice = array(), $email_type = '', $sent_to_admin = false) { |
|
1212 | + wpinv_get_template('emails/wpinv-email-footer.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1213 | 1213 | } |
1214 | 1214 | |
1215 | -function wpinv_email_wrap_message( $message ) { |
|
1215 | +function wpinv_email_wrap_message($message) { |
|
1216 | 1216 | // Buffer |
1217 | 1217 | ob_start(); |
1218 | 1218 | |
1219 | - do_action( 'wpinv_email_header' ); |
|
1219 | + do_action('wpinv_email_header'); |
|
1220 | 1220 | |
1221 | - echo wpautop( wptexturize( $message ) ); |
|
1221 | + echo wpautop(wptexturize($message)); |
|
1222 | 1222 | |
1223 | - do_action( 'wpinv_email_footer' ); |
|
1223 | + do_action('wpinv_email_footer'); |
|
1224 | 1224 | |
1225 | 1225 | // Get contents |
1226 | 1226 | $message = ob_get_clean(); |
@@ -1228,92 +1228,92 @@ discard block |
||
1228 | 1228 | return $message; |
1229 | 1229 | } |
1230 | 1230 | |
1231 | -function wpinv_email_invoice_details( $invoice, $email_type = '', $sent_to_admin = false ) { |
|
1232 | - wpinv_get_template( 'emails/wpinv-email-invoice-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1231 | +function wpinv_email_invoice_details($invoice, $email_type = '', $sent_to_admin = false) { |
|
1232 | + wpinv_get_template('emails/wpinv-email-invoice-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1233 | 1233 | } |
1234 | 1234 | |
1235 | -function wpinv_email_invoice_items( $invoice, $email_type = '', $sent_to_admin = false ) { |
|
1236 | - wpinv_get_template( 'emails/wpinv-email-invoice-items.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1235 | +function wpinv_email_invoice_items($invoice, $email_type = '', $sent_to_admin = false) { |
|
1236 | + wpinv_get_template('emails/wpinv-email-invoice-items.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1237 | 1237 | } |
1238 | 1238 | |
1239 | -function wpinv_email_billing_details( $invoice, $email_type = '', $sent_to_admin = false ) { |
|
1240 | - wpinv_get_template( 'emails/wpinv-email-billing-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1239 | +function wpinv_email_billing_details($invoice, $email_type = '', $sent_to_admin = false) { |
|
1240 | + wpinv_get_template('emails/wpinv-email-billing-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1241 | 1241 | } |
1242 | 1242 | |
1243 | -function wpinv_send_customer_invoice( $data = array() ) { |
|
1244 | - $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL; |
|
1243 | +function wpinv_send_customer_invoice($data = array()) { |
|
1244 | + $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL; |
|
1245 | 1245 | |
1246 | - if ( empty( $invoice_id ) ) { |
|
1246 | + if (empty($invoice_id)) { |
|
1247 | 1247 | return; |
1248 | 1248 | } |
1249 | 1249 | |
1250 | - if ( !current_user_can( 'manage_options' ) ) { |
|
1251 | - wp_die( __( 'You do not have permission to send invoice notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
1250 | + if (!current_user_can('manage_options')) { |
|
1251 | + wp_die(__('You do not have permission to send invoice notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
1252 | 1252 | } |
1253 | 1253 | |
1254 | - $sent = wpinv_user_invoice_notification( $invoice_id ); |
|
1254 | + $sent = wpinv_user_invoice_notification($invoice_id); |
|
1255 | 1255 | |
1256 | 1256 | if ( -1 == $sent ) { |
1257 | 1257 | $status = 'email_disabled'; |
1258 | - } elseif ( $sent ) { |
|
1258 | + } elseif ($sent) { |
|
1259 | 1259 | $status = 'email_sent'; |
1260 | 1260 | } else { |
1261 | 1261 | $status = 'email_fail'; |
1262 | 1262 | } |
1263 | 1263 | |
1264 | - $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) ); |
|
1265 | - wp_redirect( $redirect ); |
|
1264 | + $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false)); |
|
1265 | + wp_redirect($redirect); |
|
1266 | 1266 | exit; |
1267 | 1267 | } |
1268 | -add_action( 'wpinv_send_invoice', 'wpinv_send_customer_invoice' ); |
|
1268 | +add_action('wpinv_send_invoice', 'wpinv_send_customer_invoice'); |
|
1269 | 1269 | |
1270 | -function wpinv_send_overdue_reminder( $data = array() ) { |
|
1271 | - $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL; |
|
1270 | +function wpinv_send_overdue_reminder($data = array()) { |
|
1271 | + $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL; |
|
1272 | 1272 | |
1273 | - if ( empty( $invoice_id ) ) { |
|
1273 | + if (empty($invoice_id)) { |
|
1274 | 1274 | return; |
1275 | 1275 | } |
1276 | 1276 | |
1277 | - if ( !current_user_can( 'manage_options' ) ) { |
|
1278 | - wp_die( __( 'You do not have permission to send reminder notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
1277 | + if (!current_user_can('manage_options')) { |
|
1278 | + wp_die(__('You do not have permission to send reminder notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
1279 | 1279 | } |
1280 | 1280 | |
1281 | - $sent = wpinv_send_payment_reminder_notification( $invoice_id ); |
|
1281 | + $sent = wpinv_send_payment_reminder_notification($invoice_id); |
|
1282 | 1282 | |
1283 | 1283 | $status = $sent ? 'email_sent' : 'email_fail'; |
1284 | 1284 | |
1285 | - $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) ); |
|
1286 | - wp_redirect( $redirect ); |
|
1285 | + $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false)); |
|
1286 | + wp_redirect($redirect); |
|
1287 | 1287 | exit; |
1288 | 1288 | } |
1289 | -add_action( 'wpinv_send_reminder', 'wpinv_send_overdue_reminder' ); |
|
1289 | +add_action('wpinv_send_reminder', 'wpinv_send_overdue_reminder'); |
|
1290 | 1290 | |
1291 | -function wpinv_send_customer_note_email( $data ) { |
|
1292 | - $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL; |
|
1291 | +function wpinv_send_customer_note_email($data) { |
|
1292 | + $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL; |
|
1293 | 1293 | |
1294 | - if ( empty( $invoice_id ) ) { |
|
1294 | + if (empty($invoice_id)) { |
|
1295 | 1295 | return; |
1296 | 1296 | } |
1297 | 1297 | |
1298 | - $sent = wpinv_user_note_notification( $invoice_id, $data ); |
|
1298 | + $sent = wpinv_user_note_notification($invoice_id, $data); |
|
1299 | 1299 | } |
1300 | -add_action( 'wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1 ); |
|
1300 | +add_action('wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1); |
|
1301 | 1301 | |
1302 | -function wpinv_add_notes_to_invoice_email( $invoice, $email_type, $sent_to_admin ) { |
|
1303 | - if ( !empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->ID, true ) ) { |
|
1304 | - $date_format = get_option( 'date_format' ); |
|
1305 | - $time_format = get_option( 'time_format' ); |
|
1302 | +function wpinv_add_notes_to_invoice_email($invoice, $email_type, $sent_to_admin) { |
|
1303 | + if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->ID, true)) { |
|
1304 | + $date_format = get_option('date_format'); |
|
1305 | + $time_format = get_option('time_format'); |
|
1306 | 1306 | ?> |
1307 | 1307 | <div id="wpinv-email-notes"> |
1308 | - <h3 class="wpinv-notes-t"><?php echo apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ); ?></h3> |
|
1308 | + <h3 class="wpinv-notes-t"><?php echo apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing')); ?></h3> |
|
1309 | 1309 | <ol class="wpinv-notes-lists"> |
1310 | 1310 | <?php |
1311 | - foreach ( $invoice_notes as $note ) { |
|
1312 | - $note_time = strtotime( $note->comment_date ); |
|
1311 | + foreach ($invoice_notes as $note) { |
|
1312 | + $note_time = strtotime($note->comment_date); |
|
1313 | 1313 | ?> |
1314 | 1314 | <li class="comment wpinv-note"> |
1315 | - <p class="wpinv-note-date meta"><?php printf( __( '%2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( $date_format, $note_time ), date_i18n( $time_format, $note_time ), $note_time ); ?></p> |
|
1316 | - <div class="wpinv-note-desc description"><?php echo wpautop( wptexturize( $note->comment_content ) ); ?></div> |
|
1315 | + <p class="wpinv-note-date meta"><?php printf(__('%2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n($date_format, $note_time), date_i18n($time_format, $note_time), $note_time); ?></p> |
|
1316 | + <div class="wpinv-note-desc description"><?php echo wpautop(wptexturize($note->comment_content)); ?></div> |
|
1317 | 1317 | </li> |
1318 | 1318 | <?php |
1319 | 1319 | } |
@@ -1322,21 +1322,21 @@ discard block |
||
1322 | 1322 | <?php |
1323 | 1323 | } |
1324 | 1324 | } |
1325 | -add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 ); |
|
1325 | +add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3); |
|
1326 | 1326 | |
1327 | 1327 | function wpinv_email_payment_reminders() { |
1328 | 1328 | global $wpi_auto_reminder; |
1329 | - if ( !wpinv_get_option( 'email_overdue_active' ) ) { |
|
1329 | + if (!wpinv_get_option('email_overdue_active')) { |
|
1330 | 1330 | return; |
1331 | 1331 | } |
1332 | 1332 | |
1333 | - if ( $reminder_days = wpinv_get_option( 'email_due_reminder_days' ) ) { |
|
1334 | - $reminder_days = is_array( $reminder_days ) ? array_values( $reminder_days ) : ''; |
|
1333 | + if ($reminder_days = wpinv_get_option('email_due_reminder_days')) { |
|
1334 | + $reminder_days = is_array($reminder_days) ? array_values($reminder_days) : ''; |
|
1335 | 1335 | |
1336 | - if ( empty( $reminder_days ) ) { |
|
1336 | + if (empty($reminder_days)) { |
|
1337 | 1337 | return; |
1338 | 1338 | } |
1339 | - $reminder_days = array_unique( array_map( 'absint', $reminder_days ) ); |
|
1339 | + $reminder_days = array_unique(array_map('absint', $reminder_days)); |
|
1340 | 1340 | |
1341 | 1341 | $args = array( |
1342 | 1342 | 'post_type' => 'wpi_invoice', |
@@ -1346,7 +1346,7 @@ discard block |
||
1346 | 1346 | 'meta_query' => array( |
1347 | 1347 | array( |
1348 | 1348 | 'key' => '_wpinv_due_date', |
1349 | - 'value' => array( '', 'none' ), |
|
1349 | + 'value' => array('', 'none'), |
|
1350 | 1350 | 'compare' => 'NOT IN', |
1351 | 1351 | ) |
1352 | 1352 | ), |
@@ -1355,109 +1355,109 @@ discard block |
||
1355 | 1355 | 'order' => 'ASC', |
1356 | 1356 | ); |
1357 | 1357 | |
1358 | - $invoices = get_posts( $args ); |
|
1358 | + $invoices = get_posts($args); |
|
1359 | 1359 | |
1360 | - if ( empty( $invoices ) ) { |
|
1360 | + if (empty($invoices)) { |
|
1361 | 1361 | return; |
1362 | 1362 | } |
1363 | 1363 | |
1364 | - $date_to_send = array(); |
|
1364 | + $date_to_send = array(); |
|
1365 | 1365 | |
1366 | - foreach ( $invoices as $id ) { |
|
1367 | - $due_date = get_post_meta( $id, '_wpinv_due_date', true ); |
|
1366 | + foreach ($invoices as $id) { |
|
1367 | + $due_date = get_post_meta($id, '_wpinv_due_date', true); |
|
1368 | 1368 | |
1369 | - foreach ( $reminder_days as $key => $days ) { |
|
1370 | - if ( $days !== '' ) { |
|
1371 | - $date_to_send[$id][] = date_i18n( 'Y-m-d', strtotime( $due_date ) + ( $days * DAY_IN_SECONDS ) ); |
|
1369 | + foreach ($reminder_days as $key => $days) { |
|
1370 | + if ($days !== '') { |
|
1371 | + $date_to_send[$id][] = date_i18n('Y-m-d', strtotime($due_date) + ($days * DAY_IN_SECONDS)); |
|
1372 | 1372 | } |
1373 | 1373 | } |
1374 | 1374 | } |
1375 | 1375 | |
1376 | - $today = date_i18n( 'Y-m-d' ); |
|
1376 | + $today = date_i18n('Y-m-d'); |
|
1377 | 1377 | $wpi_auto_reminder = true; |
1378 | 1378 | |
1379 | - foreach ( $date_to_send as $id => $values ) { |
|
1380 | - if ( in_array( $today, $values ) ) { |
|
1381 | - $sent = get_post_meta( $id, '_wpinv_reminder_sent', true ); |
|
1379 | + foreach ($date_to_send as $id => $values) { |
|
1380 | + if (in_array($today, $values)) { |
|
1381 | + $sent = get_post_meta($id, '_wpinv_reminder_sent', true); |
|
1382 | 1382 | |
1383 | - if ( isset( $sent ) && !empty( $sent ) ) { |
|
1384 | - if ( !in_array( $today, $sent ) ) { |
|
1385 | - do_action( 'wpinv_send_payment_reminder_notification', $id ); |
|
1383 | + if (isset($sent) && !empty($sent)) { |
|
1384 | + if (!in_array($today, $sent)) { |
|
1385 | + do_action('wpinv_send_payment_reminder_notification', $id); |
|
1386 | 1386 | } |
1387 | 1387 | } else { |
1388 | - do_action( 'wpinv_send_payment_reminder_notification', $id ); |
|
1388 | + do_action('wpinv_send_payment_reminder_notification', $id); |
|
1389 | 1389 | } |
1390 | 1390 | } |
1391 | 1391 | } |
1392 | 1392 | |
1393 | - $wpi_auto_reminder = false; |
|
1393 | + $wpi_auto_reminder = false; |
|
1394 | 1394 | } |
1395 | 1395 | } |
1396 | 1396 | |
1397 | -function wpinv_send_payment_reminder_notification( $invoice_id ) { |
|
1397 | +function wpinv_send_payment_reminder_notification($invoice_id) { |
|
1398 | 1398 | $email_type = 'overdue'; |
1399 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
1399 | + if (!wpinv_email_is_enabled($email_type)) { |
|
1400 | 1400 | return false; |
1401 | 1401 | } |
1402 | 1402 | |
1403 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1404 | - if ( empty( $invoice ) ) { |
|
1403 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1404 | + if (empty($invoice)) { |
|
1405 | 1405 | return false; |
1406 | 1406 | } |
1407 | 1407 | |
1408 | - if ( !$invoice->needs_payment() ) { |
|
1408 | + if (!$invoice->needs_payment()) { |
|
1409 | 1409 | return false; |
1410 | 1410 | } |
1411 | 1411 | |
1412 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
1413 | - if ( !is_email( $recipient ) ) { |
|
1412 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
1413 | + if (!is_email($recipient)) { |
|
1414 | 1414 | return false; |
1415 | 1415 | } |
1416 | 1416 | |
1417 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
1418 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
1419 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
1420 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
1421 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
1417 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
1418 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
1419 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
1420 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
1421 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
1422 | 1422 | |
1423 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
1423 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
1424 | 1424 | 'invoice' => $invoice, |
1425 | 1425 | 'email_type' => $email_type, |
1426 | 1426 | 'email_heading' => $email_heading, |
1427 | 1427 | 'sent_to_admin' => false, |
1428 | 1428 | 'plain_text' => false, |
1429 | 1429 | 'message_body' => $message_body |
1430 | - ) ); |
|
1430 | + )); |
|
1431 | 1431 | |
1432 | - $content = wpinv_email_format_text( $content, $invoice ); |
|
1432 | + $content = wpinv_email_format_text($content, $invoice); |
|
1433 | 1433 | |
1434 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
1435 | - if ( $sent ) { |
|
1436 | - do_action( 'wpinv_payment_reminder_sent', $invoice_id, $invoice ); |
|
1434 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
1435 | + if ($sent) { |
|
1436 | + do_action('wpinv_payment_reminder_sent', $invoice_id, $invoice); |
|
1437 | 1437 | } |
1438 | 1438 | |
1439 | 1439 | return $sent; |
1440 | 1440 | } |
1441 | -add_action( 'wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1 ); |
|
1441 | +add_action('wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1); |
|
1442 | 1442 | |
1443 | -function wpinv_payment_reminder_sent( $invoice_id, $invoice ) { |
|
1443 | +function wpinv_payment_reminder_sent($invoice_id, $invoice) { |
|
1444 | 1444 | global $wpi_auto_reminder; |
1445 | 1445 | |
1446 | - $sent = get_post_meta( $invoice_id, '_wpinv_reminder_sent', true ); |
|
1446 | + $sent = get_post_meta($invoice_id, '_wpinv_reminder_sent', true); |
|
1447 | 1447 | |
1448 | - if ( empty( $sent ) ) { |
|
1448 | + if (empty($sent)) { |
|
1449 | 1449 | $sent = array(); |
1450 | 1450 | } |
1451 | - $sent[] = date_i18n( 'Y-m-d' ); |
|
1451 | + $sent[] = date_i18n('Y-m-d'); |
|
1452 | 1452 | |
1453 | - update_post_meta( $invoice_id, '_wpinv_reminder_sent', $sent ); |
|
1453 | + update_post_meta($invoice_id, '_wpinv_reminder_sent', $sent); |
|
1454 | 1454 | |
1455 | - if ( $wpi_auto_reminder ) { // Auto reminder note. |
|
1456 | - $note = __( 'Manual reminder sent to the user.', 'invoicing' ); |
|
1457 | - $invoice->add_note( $note, false, false, true ); |
|
1455 | + if ($wpi_auto_reminder) { // Auto reminder note. |
|
1456 | + $note = __('Manual reminder sent to the user.', 'invoicing'); |
|
1457 | + $invoice->add_note($note, false, false, true); |
|
1458 | 1458 | } else { // Menual reminder note. |
1459 | - $note = __( 'Manual reminder sent to the user.', 'invoicing' ); |
|
1460 | - $invoice->add_note( $note ); |
|
1459 | + $note = __('Manual reminder sent to the user.', 'invoicing'); |
|
1460 | + $invoice->add_note($note); |
|
1461 | 1461 | } |
1462 | 1462 | } |
1463 | -add_action( 'wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2 ); |
|
1463 | +add_action('wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2); |
@@ -1,73 +1,73 @@ 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 | -add_action( 'admin_menu', 'wpinv_add_options_link', 10 ); |
|
7 | +add_action('admin_menu', 'wpinv_add_options_link', 10); |
|
8 | 8 | function wpinv_add_options_link() { |
9 | 9 | global $menu; |
10 | 10 | |
11 | - if ( !(current_user_can( 'manage_invoicing' ) || current_user_can( 'manage_options' )) ) { |
|
11 | + if (!(current_user_can('manage_invoicing') || current_user_can('manage_options'))) { |
|
12 | 12 | return; |
13 | 13 | } |
14 | 14 | |
15 | - $capability = apply_filters( 'invoicing_capability', 'manage_invoicing' ); |
|
15 | + $capability = apply_filters('invoicing_capability', 'manage_invoicing'); |
|
16 | 16 | |
17 | - if ( current_user_can( 'manage_options' ) ) { |
|
18 | - $menu[] = array( '', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv' ); |
|
17 | + if (current_user_can('manage_options')) { |
|
18 | + $menu[] = array('', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv'); |
|
19 | 19 | } |
20 | 20 | |
21 | - $wpi_invoice = get_post_type_object( 'wpi_invoice' ); |
|
21 | + $wpi_invoice = get_post_type_object('wpi_invoice'); |
|
22 | 22 | |
23 | - add_menu_page( __( 'Invoicing', 'invoicing' ), __( 'Invoicing', 'invoicing' ), $capability, 'wpinv', null, $wpi_invoice->menu_icon, '54.123460' ); |
|
23 | + add_menu_page(__('Invoicing', 'invoicing'), __('Invoicing', 'invoicing'), $capability, 'wpinv', null, $wpi_invoice->menu_icon, '54.123460'); |
|
24 | 24 | |
25 | - $wpi_settings_page = add_submenu_page( 'wpinv', __( 'Invoice Settings', 'invoicing' ), __( 'Settings', 'invoicing' ), $capability, 'wpinv-settings', 'wpinv_options_page' ); |
|
25 | + $wpi_settings_page = add_submenu_page('wpinv', __('Invoice Settings', 'invoicing'), __('Settings', 'invoicing'), $capability, 'wpinv-settings', 'wpinv_options_page'); |
|
26 | 26 | } |
27 | 27 | |
28 | -add_action( 'admin_menu', 'wpinv_remove_admin_submenus', 999 ); |
|
28 | +add_action('admin_menu', 'wpinv_remove_admin_submenus', 999); |
|
29 | 29 | function wpinv_remove_admin_submenus() { |
30 | - remove_submenu_page( 'edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice' ); |
|
30 | + remove_submenu_page('edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice'); |
|
31 | 31 | } |
32 | 32 | |
33 | -add_filter( 'manage_wpi_discount_posts_columns', 'wpinv_discount_columns' ); |
|
34 | -function wpinv_discount_columns( $existing_columns ) { |
|
33 | +add_filter('manage_wpi_discount_posts_columns', 'wpinv_discount_columns'); |
|
34 | +function wpinv_discount_columns($existing_columns) { |
|
35 | 35 | $columns = array(); |
36 | 36 | $columns['cb'] = $existing_columns['cb']; |
37 | - $columns['name'] = __( 'Name', 'invoicing' ); |
|
38 | - $columns['code'] = __( 'Code', 'invoicing' ); |
|
39 | - $columns['amount'] = __( 'Amount', 'invoicing' ); |
|
40 | - $columns['usage'] = __( 'Usage / Limit', 'invoicing' ); |
|
41 | - $columns['start_date'] = __( 'Start Date', 'invoicing' ); |
|
42 | - $columns['expiry_date'] = __( 'Expiry Date', 'invoicing' ); |
|
43 | - $columns['status'] = __( 'Status', 'invoicing' ); |
|
37 | + $columns['name'] = __('Name', 'invoicing'); |
|
38 | + $columns['code'] = __('Code', 'invoicing'); |
|
39 | + $columns['amount'] = __('Amount', 'invoicing'); |
|
40 | + $columns['usage'] = __('Usage / Limit', 'invoicing'); |
|
41 | + $columns['start_date'] = __('Start Date', 'invoicing'); |
|
42 | + $columns['expiry_date'] = __('Expiry Date', 'invoicing'); |
|
43 | + $columns['status'] = __('Status', 'invoicing'); |
|
44 | 44 | |
45 | 45 | return $columns; |
46 | 46 | } |
47 | 47 | |
48 | -add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' ); |
|
49 | -function wpinv_discount_custom_column( $column ) { |
|
48 | +add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column'); |
|
49 | +function wpinv_discount_custom_column($column) { |
|
50 | 50 | global $post; |
51 | 51 | |
52 | 52 | $discount = $post; |
53 | 53 | |
54 | - switch ( $column ) { |
|
54 | + switch ($column) { |
|
55 | 55 | case 'name' : |
56 | - echo get_the_title( $discount->ID ); |
|
56 | + echo get_the_title($discount->ID); |
|
57 | 57 | break; |
58 | 58 | case 'code' : |
59 | - echo wpinv_get_discount_code( $discount->ID ); |
|
59 | + echo wpinv_get_discount_code($discount->ID); |
|
60 | 60 | break; |
61 | 61 | case 'amount' : |
62 | - echo wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) ); |
|
62 | + echo wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID)); |
|
63 | 63 | break; |
64 | 64 | case 'usage_limit' : |
65 | - echo wpinv_get_discount_uses( $discount->ID ); |
|
65 | + echo wpinv_get_discount_uses($discount->ID); |
|
66 | 66 | break; |
67 | 67 | case 'usage' : |
68 | - $usage = wpinv_get_discount_uses( $discount->ID ) . ' / '; |
|
69 | - if ( wpinv_get_discount_max_uses( $discount->ID ) ) { |
|
70 | - $usage .= wpinv_get_discount_max_uses( $discount->ID ); |
|
68 | + $usage = wpinv_get_discount_uses($discount->ID) . ' / '; |
|
69 | + if (wpinv_get_discount_max_uses($discount->ID)) { |
|
70 | + $usage .= wpinv_get_discount_max_uses($discount->ID); |
|
71 | 71 | } else { |
72 | 72 | $usage .= ' ∞'; |
73 | 73 | } |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | echo $usage; |
76 | 76 | break; |
77 | 77 | case 'start_date' : |
78 | - if ( $start_date = wpinv_get_discount_start_date( $discount->ID ) ) { |
|
79 | - $value = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), strtotime( $start_date ) ); |
|
78 | + if ($start_date = wpinv_get_discount_start_date($discount->ID)) { |
|
79 | + $value = date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), strtotime($start_date)); |
|
80 | 80 | } else { |
81 | 81 | $value = '-'; |
82 | 82 | } |
@@ -84,163 +84,163 @@ discard block |
||
84 | 84 | echo $value; |
85 | 85 | break; |
86 | 86 | case 'expiry_date' : |
87 | - if ( $expiration = wpinv_get_discount_expiration( $discount->ID ) ) { |
|
88 | - $value = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), strtotime( $expiration ) ); |
|
87 | + if ($expiration = wpinv_get_discount_expiration($discount->ID)) { |
|
88 | + $value = date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), strtotime($expiration)); |
|
89 | 89 | } else { |
90 | - $value = __( 'Never', 'invoicing' ); |
|
90 | + $value = __('Never', 'invoicing'); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | echo $value; |
94 | 94 | break; |
95 | 95 | break; |
96 | 96 | case 'description' : |
97 | - echo wp_kses_post( $post->post_excerpt ); |
|
97 | + echo wp_kses_post($post->post_excerpt); |
|
98 | 98 | break; |
99 | 99 | case 'status' : |
100 | - $status = wpinv_is_discount_expired( $discount->ID ) ? 'expired' : $discount->post_status; |
|
100 | + $status = wpinv_is_discount_expired($discount->ID) ? 'expired' : $discount->post_status; |
|
101 | 101 | |
102 | - echo wpinv_discount_status( $status ); |
|
102 | + echo wpinv_discount_status($status); |
|
103 | 103 | break; |
104 | 104 | } |
105 | 105 | } |
106 | 106 | |
107 | -add_filter( 'post_row_actions', 'wpinv_post_row_actions', 9999, 2 ); |
|
108 | -function wpinv_post_row_actions( $actions, $post ) { |
|
109 | - $post_type = !empty( $post->post_type ) ? $post->post_type : ''; |
|
107 | +add_filter('post_row_actions', 'wpinv_post_row_actions', 9999, 2); |
|
108 | +function wpinv_post_row_actions($actions, $post) { |
|
109 | + $post_type = !empty($post->post_type) ? $post->post_type : ''; |
|
110 | 110 | |
111 | - if ( $post_type == 'wpi_invoice' ) { |
|
111 | + if ($post_type == 'wpi_invoice') { |
|
112 | 112 | $actions = array(); |
113 | 113 | } |
114 | 114 | |
115 | - if ( $post_type == 'wpi_discount' ) { |
|
116 | - $actions = wpinv_discount_row_actions( $post, $actions ); |
|
115 | + if ($post_type == 'wpi_discount') { |
|
116 | + $actions = wpinv_discount_row_actions($post, $actions); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | return $actions; |
120 | 120 | } |
121 | 121 | |
122 | -function wpinv_discount_row_actions( $discount, $row_actions ) { |
|
123 | - $row_actions = array(); |
|
124 | - $edit_link = get_edit_post_link( $discount->ID ); |
|
125 | - $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>'; |
|
122 | +function wpinv_discount_row_actions($discount, $row_actions) { |
|
123 | + $row_actions = array(); |
|
124 | + $edit_link = get_edit_post_link($discount->ID); |
|
125 | + $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>'; |
|
126 | 126 | |
127 | - if( in_array( strtolower( $discount->post_status ), array( 'publish' ) ) ) { |
|
128 | - $row_actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'deactivate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Deactivate', 'invoicing' ) . '</a>'; |
|
129 | - } elseif( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) { |
|
130 | - $row_actions['activate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'activate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Activate', 'invoicing' ) . '</a>'; |
|
127 | + if (in_array(strtolower($discount->post_status), array('publish'))) { |
|
128 | + $row_actions['deactivate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'deactivate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Deactivate', 'invoicing') . '</a>'; |
|
129 | + } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) { |
|
130 | + $row_actions['activate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'activate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Activate', 'invoicing') . '</a>'; |
|
131 | 131 | } |
132 | 132 | |
133 | - if ( wpinv_get_discount_uses( $discount->ID ) > 0 ) { |
|
134 | - if ( isset( $row_actions['delete'] ) ) { |
|
135 | - unset( $row_actions['delete'] ); // Don't delete used discounts. |
|
133 | + if (wpinv_get_discount_uses($discount->ID) > 0) { |
|
134 | + if (isset($row_actions['delete'])) { |
|
135 | + unset($row_actions['delete']); // Don't delete used discounts. |
|
136 | 136 | } |
137 | 137 | } else { |
138 | - $row_actions['delete'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'delete_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Delete', 'invoicing' ) . '</a>'; |
|
138 | + $row_actions['delete'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'delete_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Delete', 'invoicing') . '</a>'; |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | |
142 | - $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount ); |
|
142 | + $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount); |
|
143 | 143 | |
144 | 144 | return $row_actions; |
145 | 145 | } |
146 | 146 | |
147 | -add_filter( 'list_table_primary_column', 'wpinv_table_primary_column', 10, 2 ); |
|
148 | -function wpinv_table_primary_column( $default, $screen_id ) { |
|
149 | - if ( 'edit-wpi_invoice' === $screen_id ) { |
|
147 | +add_filter('list_table_primary_column', 'wpinv_table_primary_column', 10, 2); |
|
148 | +function wpinv_table_primary_column($default, $screen_id) { |
|
149 | + if ('edit-wpi_invoice' === $screen_id) { |
|
150 | 150 | return 'name'; |
151 | 151 | } |
152 | 152 | |
153 | 153 | return $default; |
154 | 154 | } |
155 | 155 | |
156 | -function wpinv_discount_bulk_actions( $actions, $display = false ) { |
|
157 | - if ( !$display ) { |
|
156 | +function wpinv_discount_bulk_actions($actions, $display = false) { |
|
157 | + if (!$display) { |
|
158 | 158 | return array(); |
159 | 159 | } |
160 | 160 | |
161 | 161 | $actions = array( |
162 | - 'activate' => __( 'Activate', 'invoicing' ), |
|
163 | - 'deactivate' => __( 'Deactivate', 'invoicing' ), |
|
164 | - 'delete' => __( 'Delete', 'invoicing' ), |
|
162 | + 'activate' => __('Activate', 'invoicing'), |
|
163 | + 'deactivate' => __('Deactivate', 'invoicing'), |
|
164 | + 'delete' => __('Delete', 'invoicing'), |
|
165 | 165 | ); |
166 | 166 | $two = ''; |
167 | 167 | $which = 'top'; |
168 | 168 | echo '</div><div class="alignleft actions bulkactions">'; |
169 | - echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>'; |
|
170 | - echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">"; |
|
171 | - echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>"; |
|
169 | + echo '<label for="bulk-action-selector-' . esc_attr($which) . '" class="screen-reader-text">' . __('Select bulk action') . '</label>'; |
|
170 | + echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr($which) . "\">"; |
|
171 | + echo '<option value="-1">' . __('Bulk Actions') . "</option>"; |
|
172 | 172 | |
173 | - foreach ( $actions as $name => $title ) { |
|
173 | + foreach ($actions as $name => $title) { |
|
174 | 174 | $class = 'edit' === $name ? ' class="hide-if-no-js"' : ''; |
175 | 175 | |
176 | 176 | echo "" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>"; |
177 | 177 | } |
178 | 178 | echo "</select>"; |
179 | 179 | |
180 | - submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) ); |
|
180 | + submit_button(__('Apply'), 'action', '', false, array('id' => "doaction$two")); |
|
181 | 181 | |
182 | 182 | echo '</div><div class="alignleft actions">'; |
183 | 183 | } |
184 | -add_filter( 'bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10 ); |
|
184 | +add_filter('bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10); |
|
185 | 185 | |
186 | -function wpinv_disable_months_dropdown( $disable, $post_type ) { |
|
187 | - if ( $post_type == 'wpi_discount' ) { |
|
186 | +function wpinv_disable_months_dropdown($disable, $post_type) { |
|
187 | + if ($post_type == 'wpi_discount') { |
|
188 | 188 | $disable = true; |
189 | 189 | } |
190 | 190 | |
191 | 191 | return $disable; |
192 | 192 | } |
193 | -add_filter( 'disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2 ); |
|
193 | +add_filter('disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2); |
|
194 | 194 | |
195 | 195 | function wpinv_restrict_manage_posts() { |
196 | 196 | global $typenow; |
197 | 197 | |
198 | - if( 'wpi_discount' == $typenow ) { |
|
198 | + if ('wpi_discount' == $typenow) { |
|
199 | 199 | wpinv_discount_filters(); |
200 | 200 | } |
201 | 201 | } |
202 | -add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 ); |
|
202 | +add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10); |
|
203 | 203 | |
204 | 204 | function wpinv_discount_filters() { |
205 | - echo wpinv_discount_bulk_actions( array(), true ); |
|
205 | + echo wpinv_discount_bulk_actions(array(), true); |
|
206 | 206 | |
207 | 207 | ?> |
208 | 208 | <select name="discount_type" id="dropdown_wpinv_discount_type"> |
209 | - <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option> |
|
209 | + <option value=""><?php _e('Show all types', 'invoicing'); ?></option> |
|
210 | 210 | <?php |
211 | 211 | $types = wpinv_get_discount_types(); |
212 | 212 | |
213 | - foreach ( $types as $name => $type ) { |
|
214 | - echo '<option value="' . esc_attr( $name ) . '"'; |
|
213 | + foreach ($types as $name => $type) { |
|
214 | + echo '<option value="' . esc_attr($name) . '"'; |
|
215 | 215 | |
216 | - if ( isset( $_GET['discount_type'] ) ) |
|
217 | - selected( $name, $_GET['discount_type'] ); |
|
216 | + if (isset($_GET['discount_type'])) |
|
217 | + selected($name, $_GET['discount_type']); |
|
218 | 218 | |
219 | - echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
219 | + echo '>' . esc_html__($type, 'invoicing') . '</option>'; |
|
220 | 220 | } |
221 | 221 | ?> |
222 | 222 | </select> |
223 | 223 | <?php |
224 | 224 | } |
225 | 225 | |
226 | -function wpinv_request( $vars ) { |
|
226 | +function wpinv_request($vars) { |
|
227 | 227 | global $typenow, $wp_query, $wp_post_statuses; |
228 | 228 | |
229 | - if ( 'wpi_invoice' === $typenow ) { |
|
230 | - if ( !isset( $vars['post_status'] ) ) { |
|
229 | + if ('wpi_invoice' === $typenow) { |
|
230 | + if (!isset($vars['post_status'])) { |
|
231 | 231 | $post_statuses = wpinv_get_invoice_statuses(); |
232 | 232 | |
233 | - foreach ( $post_statuses as $status => $value ) { |
|
234 | - if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) { |
|
235 | - unset( $post_statuses[ $status ] ); |
|
233 | + foreach ($post_statuses as $status => $value) { |
|
234 | + if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) { |
|
235 | + unset($post_statuses[$status]); |
|
236 | 236 | } |
237 | 237 | } |
238 | 238 | |
239 | - $vars['post_status'] = array_keys( $post_statuses ); |
|
239 | + $vars['post_status'] = array_keys($post_statuses); |
|
240 | 240 | } |
241 | 241 | |
242 | - if ( isset( $vars['orderby'] ) ) { |
|
243 | - if ( 'amount' == $vars['orderby'] ) { |
|
242 | + if (isset($vars['orderby'])) { |
|
243 | + if ('amount' == $vars['orderby']) { |
|
244 | 244 | $vars = array_merge( |
245 | 245 | $vars, |
246 | 246 | array( |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | 'orderby' => 'meta_value_num' |
249 | 249 | ) |
250 | 250 | ); |
251 | - } else if ( 'customer' == $vars['orderby'] ) { |
|
251 | + } else if ('customer' == $vars['orderby']) { |
|
252 | 252 | $vars = array_merge( |
253 | 253 | $vars, |
254 | 254 | array( |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | 'orderby' => 'meta_value' |
257 | 257 | ) |
258 | 258 | ); |
259 | - } else if ( 'number' == $vars['orderby'] ) { |
|
259 | + } else if ('number' == $vars['orderby']) { |
|
260 | 260 | $vars = array_merge( |
261 | 261 | $vars, |
262 | 262 | array( |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | 'orderby' => 'meta_value' |
265 | 265 | ) |
266 | 266 | ); |
267 | - } else if ( 'payment_date' == $vars['orderby'] ) { |
|
267 | + } else if ('payment_date' == $vars['orderby']) { |
|
268 | 268 | $vars = array_merge( |
269 | 269 | $vars, |
270 | 270 | array( |
@@ -274,9 +274,9 @@ discard block |
||
274 | 274 | ); |
275 | 275 | } |
276 | 276 | } |
277 | - } else if ( 'wpi_item' == $typenow ) { |
|
277 | + } else if ('wpi_item' == $typenow) { |
|
278 | 278 | // Check if 'orderby' is set to "price" |
279 | - if ( isset( $vars['orderby'] ) && 'price' == $vars['orderby'] ) { |
|
279 | + if (isset($vars['orderby']) && 'price' == $vars['orderby']) { |
|
280 | 280 | $vars = array_merge( |
281 | 281 | $vars, |
282 | 282 | array( |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | } |
288 | 288 | |
289 | 289 | // Check if "orderby" is set to "vat_rule" |
290 | - if ( isset( $vars['orderby'] ) && 'vat_rule' == $vars['orderby'] ) { |
|
290 | + if (isset($vars['orderby']) && 'vat_rule' == $vars['orderby']) { |
|
291 | 291 | $vars = array_merge( |
292 | 292 | $vars, |
293 | 293 | array( |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | } |
299 | 299 | |
300 | 300 | // Check if "orderby" is set to "vat_class" |
301 | - if ( isset( $vars['orderby'] ) && 'vat_class' == $vars['orderby'] ) { |
|
301 | + if (isset($vars['orderby']) && 'vat_class' == $vars['orderby']) { |
|
302 | 302 | $vars = array_merge( |
303 | 303 | $vars, |
304 | 304 | array( |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | } |
310 | 310 | |
311 | 311 | // Check if "orderby" is set to "type" |
312 | - if ( isset( $vars['orderby'] ) && 'type' == $vars['orderby'] ) { |
|
312 | + if (isset($vars['orderby']) && 'type' == $vars['orderby']) { |
|
313 | 313 | $vars = array_merge( |
314 | 314 | $vars, |
315 | 315 | array( |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | } |
321 | 321 | |
322 | 322 | // Check if "orderby" is set to "recurring" |
323 | - if ( isset( $vars['orderby'] ) && 'recurring' == $vars['orderby'] ) { |
|
323 | + if (isset($vars['orderby']) && 'recurring' == $vars['orderby']) { |
|
324 | 324 | $vars = array_merge( |
325 | 325 | $vars, |
326 | 326 | array( |
@@ -330,120 +330,120 @@ discard block |
||
330 | 330 | ); |
331 | 331 | } |
332 | 332 | |
333 | - $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array(); |
|
333 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array(); |
|
334 | 334 | // Filter vat rule type |
335 | - if ( isset( $_GET['vat_rule'] ) && $_GET['vat_rule'] !== '' ) { |
|
335 | + if (isset($_GET['vat_rule']) && $_GET['vat_rule'] !== '') { |
|
336 | 336 | $meta_query[] = array( |
337 | 337 | 'key' => '_wpinv_vat_rule', |
338 | - 'value' => sanitize_text_field( $_GET['vat_rule'] ), |
|
338 | + 'value' => sanitize_text_field($_GET['vat_rule']), |
|
339 | 339 | 'compare' => '=' |
340 | 340 | ); |
341 | 341 | } |
342 | 342 | |
343 | 343 | // Filter vat class |
344 | - if ( isset( $_GET['vat_class'] ) && $_GET['vat_class'] !== '' ) { |
|
344 | + if (isset($_GET['vat_class']) && $_GET['vat_class'] !== '') { |
|
345 | 345 | $meta_query[] = array( |
346 | 346 | 'key' => '_wpinv_vat_class', |
347 | - 'value' => sanitize_text_field( $_GET['vat_class'] ), |
|
347 | + 'value' => sanitize_text_field($_GET['vat_class']), |
|
348 | 348 | 'compare' => '=' |
349 | 349 | ); |
350 | 350 | } |
351 | 351 | |
352 | 352 | // Filter item type |
353 | - if ( isset( $_GET['type'] ) && $_GET['type'] !== '' ) { |
|
353 | + if (isset($_GET['type']) && $_GET['type'] !== '') { |
|
354 | 354 | $meta_query[] = array( |
355 | 355 | 'key' => '_wpinv_type', |
356 | - 'value' => sanitize_text_field( $_GET['type'] ), |
|
356 | + 'value' => sanitize_text_field($_GET['type']), |
|
357 | 357 | 'compare' => '=' |
358 | 358 | ); |
359 | 359 | } |
360 | 360 | |
361 | - if ( !empty( $meta_query ) ) { |
|
361 | + if (!empty($meta_query)) { |
|
362 | 362 | $vars['meta_query'] = $meta_query; |
363 | 363 | } |
364 | - } else if ( 'wpi_discount' == $typenow ) { |
|
365 | - $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array(); |
|
364 | + } else if ('wpi_discount' == $typenow) { |
|
365 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array(); |
|
366 | 366 | // Filter vat rule type |
367 | - if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) { |
|
367 | + if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') { |
|
368 | 368 | $meta_query[] = array( |
369 | 369 | 'key' => '_wpi_discount_type', |
370 | - 'value' => sanitize_text_field( $_GET['discount_type'] ), |
|
370 | + 'value' => sanitize_text_field($_GET['discount_type']), |
|
371 | 371 | 'compare' => '=' |
372 | 372 | ); |
373 | 373 | } |
374 | 374 | |
375 | - if ( !empty( $meta_query ) ) { |
|
375 | + if (!empty($meta_query)) { |
|
376 | 376 | $vars['meta_query'] = $meta_query; |
377 | 377 | } |
378 | 378 | } |
379 | 379 | |
380 | 380 | return $vars; |
381 | 381 | } |
382 | -add_filter( 'request', 'wpinv_request' ); |
|
382 | +add_filter('request', 'wpinv_request'); |
|
383 | 383 | |
384 | 384 | function wpinv_options_page() { |
385 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
385 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
386 | 386 | |
387 | - if ( $page !== 'wpinv-settings' ) { |
|
387 | + if ($page !== 'wpinv-settings') { |
|
388 | 388 | return; |
389 | 389 | } |
390 | 390 | |
391 | 391 | $settings_tabs = wpinv_get_settings_tabs(); |
392 | 392 | $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs; |
393 | - $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general'; |
|
394 | - $sections = wpinv_get_settings_tab_sections( $active_tab ); |
|
393 | + $active_tab = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? sanitize_text_field($_GET['tab']) : 'general'; |
|
394 | + $sections = wpinv_get_settings_tab_sections($active_tab); |
|
395 | 395 | $key = 'main'; |
396 | 396 | |
397 | - if ( is_array( $sections ) ) { |
|
398 | - $key = key( $sections ); |
|
397 | + if (is_array($sections)) { |
|
398 | + $key = key($sections); |
|
399 | 399 | } |
400 | 400 | |
401 | - $registered_sections = wpinv_get_settings_tab_sections( $active_tab ); |
|
402 | - $section = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? $_GET['section'] : $key; |
|
401 | + $registered_sections = wpinv_get_settings_tab_sections($active_tab); |
|
402 | + $section = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? $_GET['section'] : $key; |
|
403 | 403 | ob_start(); |
404 | 404 | ?> |
405 | 405 | <div class="wrap"> |
406 | 406 | <h1 class="nav-tab-wrapper"> |
407 | 407 | <?php |
408 | - foreach( wpinv_get_settings_tabs() as $tab_id => $tab_name ) { |
|
409 | - $tab_url = add_query_arg( array( |
|
408 | + foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) { |
|
409 | + $tab_url = add_query_arg(array( |
|
410 | 410 | 'settings-updated' => false, |
411 | 411 | 'tab' => $tab_id, |
412 | - ) ); |
|
412 | + )); |
|
413 | 413 | |
414 | 414 | // Remove the section from the tabs so we always end up at the main section |
415 | - $tab_url = remove_query_arg( 'section', $tab_url ); |
|
416 | - $tab_url = remove_query_arg( 'wpi_sub', $tab_url ); |
|
415 | + $tab_url = remove_query_arg('section', $tab_url); |
|
416 | + $tab_url = remove_query_arg('wpi_sub', $tab_url); |
|
417 | 417 | |
418 | 418 | $active = $active_tab == $tab_id ? ' nav-tab-active' : ''; |
419 | 419 | |
420 | - echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">'; |
|
421 | - echo esc_html( $tab_name ); |
|
420 | + echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">'; |
|
421 | + echo esc_html($tab_name); |
|
422 | 422 | echo '</a>'; |
423 | 423 | } |
424 | 424 | ?> |
425 | 425 | </h1> |
426 | 426 | <?php |
427 | - $number_of_sections = count( $sections ); |
|
427 | + $number_of_sections = count($sections); |
|
428 | 428 | $number = 0; |
429 | - if ( $number_of_sections > 1 ) { |
|
429 | + if ($number_of_sections > 1) { |
|
430 | 430 | echo '<div><ul class="subsubsub">'; |
431 | - foreach( $sections as $section_id => $section_name ) { |
|
431 | + foreach ($sections as $section_id => $section_name) { |
|
432 | 432 | echo '<li>'; |
433 | 433 | $number++; |
434 | - $tab_url = add_query_arg( array( |
|
434 | + $tab_url = add_query_arg(array( |
|
435 | 435 | 'settings-updated' => false, |
436 | 436 | 'tab' => $active_tab, |
437 | 437 | 'section' => $section_id |
438 | - ) ); |
|
439 | - $tab_url = remove_query_arg( 'wpi_sub', $tab_url ); |
|
438 | + )); |
|
439 | + $tab_url = remove_query_arg('wpi_sub', $tab_url); |
|
440 | 440 | $class = ''; |
441 | - if ( $section == $section_id ) { |
|
441 | + if ($section == $section_id) { |
|
442 | 442 | $class = 'current'; |
443 | 443 | } |
444 | - echo '<a class="' . $class . '" href="' . esc_url( $tab_url ) . '">' . $section_name . '</a>'; |
|
444 | + echo '<a class="' . $class . '" href="' . esc_url($tab_url) . '">' . $section_name . '</a>'; |
|
445 | 445 | |
446 | - if ( $number != $number_of_sections ) { |
|
446 | + if ($number != $number_of_sections) { |
|
447 | 447 | echo ' | '; |
448 | 448 | } |
449 | 449 | echo '</li>'; |
@@ -455,19 +455,19 @@ discard block |
||
455 | 455 | <form method="post" action="options.php"> |
456 | 456 | <table class="form-table"> |
457 | 457 | <?php |
458 | - settings_fields( 'wpinv_settings' ); |
|
458 | + settings_fields('wpinv_settings'); |
|
459 | 459 | |
460 | - if ( 'main' === $section ) { |
|
461 | - do_action( 'wpinv_settings_tab_top', $active_tab ); |
|
460 | + if ('main' === $section) { |
|
461 | + do_action('wpinv_settings_tab_top', $active_tab); |
|
462 | 462 | } |
463 | 463 | |
464 | - do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
465 | - do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
466 | - do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
464 | + do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section); |
|
465 | + do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section); |
|
466 | + do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section); |
|
467 | 467 | |
468 | 468 | // For backwards compatibility |
469 | - if ( 'main' === $section ) { |
|
470 | - do_action( 'wpinv_settings_tab_bottom', $active_tab ); |
|
469 | + if ('main' === $section) { |
|
470 | + do_action('wpinv_settings_tab_bottom', $active_tab); |
|
471 | 471 | } |
472 | 472 | ?> |
473 | 473 | </table> |
@@ -480,53 +480,53 @@ discard block |
||
480 | 480 | echo $content; |
481 | 481 | } |
482 | 482 | |
483 | -function wpinv_item_type_class( $classes, $class, $post_id ) { |
|
483 | +function wpinv_item_type_class($classes, $class, $post_id) { |
|
484 | 484 | global $pagenow, $typenow; |
485 | 485 | |
486 | - if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow ) { |
|
487 | - if ( $type = get_post_meta( $post_id, '_wpinv_type', true ) ) { |
|
488 | - $classes[] = 'wpi-type-' . sanitize_html_class( $type ); |
|
486 | + if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow) { |
|
487 | + if ($type = get_post_meta($post_id, '_wpinv_type', true)) { |
|
488 | + $classes[] = 'wpi-type-' . sanitize_html_class($type); |
|
489 | 489 | } |
490 | 490 | |
491 | - if ( !wpinv_item_is_editable( $post_id ) ) { |
|
491 | + if (!wpinv_item_is_editable($post_id)) { |
|
492 | 492 | $classes[] = 'wpi-editable-n'; |
493 | 493 | } |
494 | 494 | } |
495 | 495 | return $classes; |
496 | 496 | } |
497 | -add_filter( 'post_class', 'wpinv_item_type_class', 10, 3 ); |
|
497 | +add_filter('post_class', 'wpinv_item_type_class', 10, 3); |
|
498 | 498 | |
499 | 499 | function wpinv_check_quick_edit() { |
500 | 500 | global $pagenow, $current_screen, $wpinv_item_screen; |
501 | 501 | |
502 | - if ( $pagenow == 'edit.php' && !empty( $current_screen->post_type ) ) { |
|
503 | - if ( empty( $wpinv_item_screen ) ) { |
|
504 | - if ( $current_screen->post_type == 'wpi_item' ) { |
|
502 | + if ($pagenow == 'edit.php' && !empty($current_screen->post_type)) { |
|
503 | + if (empty($wpinv_item_screen)) { |
|
504 | + if ($current_screen->post_type == 'wpi_item') { |
|
505 | 505 | $wpinv_item_screen = 'y'; |
506 | 506 | } else { |
507 | 507 | $wpinv_item_screen = 'n'; |
508 | 508 | } |
509 | 509 | } |
510 | 510 | |
511 | - if ( $wpinv_item_screen == 'y' && $pagenow == 'edit.php' ) { |
|
512 | - add_filter( 'post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 ); |
|
513 | - add_filter( 'page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 ); |
|
511 | + if ($wpinv_item_screen == 'y' && $pagenow == 'edit.php') { |
|
512 | + add_filter('post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2); |
|
513 | + add_filter('page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2); |
|
514 | 514 | } |
515 | 515 | } |
516 | 516 | } |
517 | -add_action( 'admin_head', 'wpinv_check_quick_edit', 10 ); |
|
517 | +add_action('admin_head', 'wpinv_check_quick_edit', 10); |
|
518 | 518 | |
519 | -function wpinv_item_disable_quick_edit( $actions = array(), $row = null ) { |
|
520 | - if ( isset( $actions['inline hide-if-no-js'] ) ) { |
|
521 | - unset( $actions['inline hide-if-no-js'] ); |
|
519 | +function wpinv_item_disable_quick_edit($actions = array(), $row = null) { |
|
520 | + if (isset($actions['inline hide-if-no-js'])) { |
|
521 | + unset($actions['inline hide-if-no-js']); |
|
522 | 522 | } |
523 | 523 | |
524 | - if ( !empty( $row->post_type ) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable( $row ) ) { |
|
525 | - if ( isset( $actions['trash'] ) ) { |
|
526 | - unset( $actions['trash'] ); |
|
524 | + if (!empty($row->post_type) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable($row)) { |
|
525 | + if (isset($actions['trash'])) { |
|
526 | + unset($actions['trash']); |
|
527 | 527 | } |
528 | - if ( isset( $actions['delete'] ) ) { |
|
529 | - unset( $actions['delete'] ); |
|
528 | + if (isset($actions['delete'])) { |
|
529 | + unset($actions['delete']); |
|
530 | 530 | } |
531 | 531 | } |
532 | 532 | |
@@ -543,19 +543,19 @@ discard block |
||
543 | 543 | * @param int $post_parent (default: 0) Parent for the new page |
544 | 544 | * @return int page ID |
545 | 545 | */ |
546 | -function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) { |
|
546 | +function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) { |
|
547 | 547 | global $wpdb; |
548 | 548 | |
549 | - $option_value = wpinv_get_option( $option ); |
|
549 | + $option_value = wpinv_get_option($option); |
|
550 | 550 | |
551 | - if ( $option_value > 0 && ( $page_object = get_post( $option_value ) ) ) { |
|
552 | - if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) { |
|
551 | + if ($option_value > 0 && ($page_object = get_post($option_value))) { |
|
552 | + if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) { |
|
553 | 553 | // Valid page is already in place |
554 | 554 | return $page_object->ID; |
555 | 555 | } |
556 | 556 | } |
557 | 557 | |
558 | - if(!empty($post_parent)){ |
|
558 | + if (!empty($post_parent)) { |
|
559 | 559 | $page = get_page_by_path($post_parent); |
560 | 560 | if ($page) { |
561 | 561 | $post_parent = $page->ID; |
@@ -564,40 +564,40 @@ discard block |
||
564 | 564 | } |
565 | 565 | } |
566 | 566 | |
567 | - if ( strlen( $page_content ) > 0 ) { |
|
567 | + if (strlen($page_content) > 0) { |
|
568 | 568 | // Search for an existing page with the specified page content (typically a shortcode) |
569 | - $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); |
|
569 | + $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
|
570 | 570 | } else { |
571 | 571 | // Search for an existing page with the specified page slug |
572 | - $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug ) ); |
|
572 | + $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug)); |
|
573 | 573 | } |
574 | 574 | |
575 | - $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content ); |
|
575 | + $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content); |
|
576 | 576 | |
577 | - if ( $valid_page_found ) { |
|
578 | - if ( $option ) { |
|
579 | - wpinv_update_option( $option, $valid_page_found ); |
|
577 | + if ($valid_page_found) { |
|
578 | + if ($option) { |
|
579 | + wpinv_update_option($option, $valid_page_found); |
|
580 | 580 | } |
581 | 581 | return $valid_page_found; |
582 | 582 | } |
583 | 583 | |
584 | 584 | // Search for a matching valid trashed page |
585 | - if ( strlen( $page_content ) > 0 ) { |
|
585 | + if (strlen($page_content) > 0) { |
|
586 | 586 | // Search for an existing page with the specified page content (typically a shortcode) |
587 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); |
|
587 | + $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
|
588 | 588 | } else { |
589 | 589 | // Search for an existing page with the specified page slug |
590 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) ); |
|
590 | + $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug)); |
|
591 | 591 | } |
592 | 592 | |
593 | - if ( $trashed_page_found ) { |
|
593 | + if ($trashed_page_found) { |
|
594 | 594 | $page_id = $trashed_page_found; |
595 | 595 | $page_data = array( |
596 | 596 | 'ID' => $page_id, |
597 | 597 | 'post_status' => 'publish', |
598 | 598 | 'post_parent' => $post_parent, |
599 | 599 | ); |
600 | - wp_update_post( $page_data ); |
|
600 | + wp_update_post($page_data); |
|
601 | 601 | } else { |
602 | 602 | $page_data = array( |
603 | 603 | 'post_status' => 'publish', |
@@ -609,11 +609,11 @@ discard block |
||
609 | 609 | 'post_parent' => $post_parent, |
610 | 610 | 'comment_status' => 'closed', |
611 | 611 | ); |
612 | - $page_id = wp_insert_post( $page_data ); |
|
612 | + $page_id = wp_insert_post($page_data); |
|
613 | 613 | } |
614 | 614 | |
615 | - if ( $option ) { |
|
616 | - wpinv_update_option( $option, (int)$page_id ); |
|
615 | + if ($option) { |
|
616 | + wpinv_update_option($option, (int)$page_id); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | return $page_id; |
@@ -8,11 +8,11 @@ discard block |
||
8 | 8 | |
9 | 9 | |
10 | 10 | // Exit if accessed directly |
11 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
11 | +if (!defined('ABSPATH')) exit; |
|
12 | 12 | |
13 | 13 | |
14 | 14 | // Load WP_List_Table if not loaded |
15 | -if( ! class_exists( 'WP_List_Table' ) ) { |
|
15 | +if (!class_exists('WP_List_Table')) { |
|
16 | 16 | require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
17 | 17 | } |
18 | 18 | |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | public $pending_count = 0; |
36 | 36 | public $expired_count = 0; |
37 | 37 | public $completed_count = 0; |
38 | - public $trialling_count = 0; |
|
38 | + public $trialling_count = 0; |
|
39 | 39 | public $cancelled_count = 0; |
40 | 40 | public $failing_count = 0; |
41 | 41 | |
@@ -46,15 +46,15 @@ discard block |
||
46 | 46 | * @since 1.0.0 |
47 | 47 | * @return void |
48 | 48 | */ |
49 | - function __construct(){ |
|
49 | + function __construct() { |
|
50 | 50 | global $status, $page; |
51 | 51 | |
52 | 52 | // Set parent defaults |
53 | - parent::__construct( array( |
|
53 | + parent::__construct(array( |
|
54 | 54 | 'singular' => 'subscription', |
55 | 55 | 'plural' => 'subscriptions', |
56 | 56 | 'ajax' => false |
57 | - ) ); |
|
57 | + )); |
|
58 | 58 | |
59 | 59 | $this->get_subscription_counts(); |
60 | 60 | |
@@ -69,28 +69,28 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function get_views() { |
71 | 71 | |
72 | - $current = isset( $_GET['status'] ) ? $_GET['status'] : ''; |
|
73 | - $total_count = ' <span class="count">(' . $this->total_count . ')</span>'; |
|
72 | + $current = isset($_GET['status']) ? $_GET['status'] : ''; |
|
73 | + $total_count = ' <span class="count">(' . $this->total_count . ')</span>'; |
|
74 | 74 | $active_count = ' <span class="count">(' . $this->active_count . ')</span>'; |
75 | 75 | $pending_count = ' <span class="count">(' . $this->pending_count . ')</span>'; |
76 | - $expired_count = ' <span class="count">(' . $this->expired_count . ')</span>'; |
|
76 | + $expired_count = ' <span class="count">(' . $this->expired_count . ')</span>'; |
|
77 | 77 | $completed_count = ' <span class="count">(' . $this->completed_count . ')</span>'; |
78 | - $trialling_count = ' <span class="count">(' . $this->trialling_count . ')</span>'; |
|
79 | - $cancelled_count = ' <span class="count">(' . $this->cancelled_count . ')</span>'; |
|
80 | - $failing_count = ' <span class="count">(' . $this->failing_count . ')</span>'; |
|
78 | + $trialling_count = ' <span class="count">(' . $this->trialling_count . ')</span>'; |
|
79 | + $cancelled_count = ' <span class="count">(' . $this->cancelled_count . ')</span>'; |
|
80 | + $failing_count = ' <span class="count">(' . $this->failing_count . ')</span>'; |
|
81 | 81 | |
82 | 82 | $views = array( |
83 | - 'all' => sprintf( '<a href="%s"%s>%s</a>', remove_query_arg( array( 'status', 'paged' ) ), $current === 'all' || $current == '' ? ' class="current"' : '', __('All','invoicing' ) . $total_count ), |
|
84 | - 'active' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'active', 'paged' => FALSE ) ), $current === 'active' ? ' class="current"' : '', __('Active','invoicing' ) . $active_count ), |
|
85 | - 'pending' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'pending', 'paged' => FALSE ) ), $current === 'pending' ? ' class="current"' : '', __('Pending','invoicing' ) . $pending_count ), |
|
86 | - 'expired' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'expired', 'paged' => FALSE ) ), $current === 'expired' ? ' class="current"' : '', __('Expired','invoicing' ) . $expired_count ), |
|
87 | - 'completed' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'completed', 'paged' => FALSE ) ), $current === 'completed' ? ' class="current"' : '', __('Completed','invoicing' ) . $completed_count ), |
|
88 | - 'trialling' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'trialling', 'paged' => FALSE ) ), $current === 'trialling' ? ' class="current"' : '', __('Trialling','invoicing' ) . $trialling_count ), |
|
89 | - 'cancelled' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'cancelled', 'paged' => FALSE ) ), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled','invoicing' ) . $cancelled_count ), |
|
90 | - 'failing' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'failing', 'paged' => FALSE ) ), $current === 'failing' ? ' class="current"' : '', __('Failing','invoicing' ) . $failing_count ), |
|
83 | + 'all' => sprintf('<a href="%s"%s>%s</a>', remove_query_arg(array('status', 'paged')), $current === 'all' || $current == '' ? ' class="current"' : '', __('All', 'invoicing') . $total_count), |
|
84 | + 'active' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'active', 'paged' => FALSE)), $current === 'active' ? ' class="current"' : '', __('Active', 'invoicing') . $active_count), |
|
85 | + 'pending' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'pending', 'paged' => FALSE)), $current === 'pending' ? ' class="current"' : '', __('Pending', 'invoicing') . $pending_count), |
|
86 | + 'expired' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'expired', 'paged' => FALSE)), $current === 'expired' ? ' class="current"' : '', __('Expired', 'invoicing') . $expired_count), |
|
87 | + 'completed' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'completed', 'paged' => FALSE)), $current === 'completed' ? ' class="current"' : '', __('Completed', 'invoicing') . $completed_count), |
|
88 | + 'trialling' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'trialling', 'paged' => FALSE)), $current === 'trialling' ? ' class="current"' : '', __('Trialling', 'invoicing') . $trialling_count), |
|
89 | + 'cancelled' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'cancelled', 'paged' => FALSE)), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled', 'invoicing') . $cancelled_count), |
|
90 | + 'failing' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'failing', 'paged' => FALSE)), $current === 'failing' ? ' class="current"' : '', __('Failing', 'invoicing') . $failing_count), |
|
91 | 91 | ); |
92 | 92 | |
93 | - return apply_filters( 'wpinv_recurring_subscriptions_table_views', $views ); |
|
93 | + return apply_filters('wpinv_recurring_subscriptions_table_views', $views); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -104,27 +104,27 @@ discard block |
||
104 | 104 | * |
105 | 105 | * @return void |
106 | 106 | */ |
107 | - public function search_box( $text, $input_id ) { |
|
107 | + public function search_box($text, $input_id) { |
|
108 | 108 | |
109 | - if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { |
|
109 | + if (empty($_REQUEST['s']) && !$this->has_items()) { |
|
110 | 110 | return; |
111 | 111 | } |
112 | 112 | |
113 | 113 | $input_id = $input_id . '-search-input'; |
114 | 114 | |
115 | - if ( ! empty( $_REQUEST['orderby'] ) ) { |
|
116 | - echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
|
115 | + if (!empty($_REQUEST['orderby'])) { |
|
116 | + echo '<input type="hidden" name="orderby" value="' . esc_attr($_REQUEST['orderby']) . '" />'; |
|
117 | 117 | } |
118 | 118 | |
119 | - if ( ! empty( $_REQUEST['order'] ) ) { |
|
120 | - echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
|
119 | + if (!empty($_REQUEST['order'])) { |
|
120 | + echo '<input type="hidden" name="order" value="' . esc_attr($_REQUEST['order']) . '" />'; |
|
121 | 121 | } |
122 | 122 | ?> |
123 | 123 | <p class="search-box"> |
124 | - <?php do_action( 'wpinv_recurring_subscription_search_box' ); ?> |
|
124 | + <?php do_action('wpinv_recurring_subscription_search_box'); ?> |
|
125 | 125 | <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label> |
126 | 126 | <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" /> |
127 | - <?php submit_button( $text, 'button', false, false, array('ID' => 'search-submit') ); ?><br/> |
|
127 | + <?php submit_button($text, 'button', false, false, array('ID' => 'search-submit')); ?><br/> |
|
128 | 128 | </p> |
129 | 129 | <?php |
130 | 130 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * @since 1.0.0 |
137 | 137 | * @return string |
138 | 138 | */ |
139 | - function column_default( $item, $column_name ) { |
|
139 | + function column_default($item, $column_name) { |
|
140 | 140 | return $item->$column_name; |
141 | 141 | } |
142 | 142 | |
@@ -147,8 +147,8 @@ discard block |
||
147 | 147 | * @since 1.0.0 |
148 | 148 | * @return string |
149 | 149 | */ |
150 | - function column_sub_id( $item ) { |
|
151 | - return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" target="_blank">' . $item->id . '</a>'; |
|
150 | + function column_sub_id($item) { |
|
151 | + return '<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $item->id)) . '" target="_blank">' . $item->id . '</a>'; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
@@ -158,11 +158,11 @@ discard block |
||
158 | 158 | * @since 1.0.0 |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - function column_customer_id( $item ) { |
|
162 | - $subscriber = get_userdata( $item->customer_id ); |
|
163 | - $customer = ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email; |
|
161 | + function column_customer_id($item) { |
|
162 | + $subscriber = get_userdata($item->customer_id); |
|
163 | + $customer = !empty($subscriber->display_name) ? $subscriber->display_name : $subscriber->user_email; |
|
164 | 164 | |
165 | - return '<a href="' . esc_url( get_edit_user_link( $item->customer_id ) ) . '" target="_blank">' . $customer . '</a>'; |
|
165 | + return '<a href="' . esc_url(get_edit_user_link($item->customer_id)) . '" target="_blank">' . $customer . '</a>'; |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * @since 1.0.0 |
173 | 173 | * @return string |
174 | 174 | */ |
175 | - function column_status( $item ) { |
|
175 | + function column_status($item) { |
|
176 | 176 | return $item->get_status_label(); |
177 | 177 | } |
178 | 178 | |
@@ -183,11 +183,11 @@ discard block |
||
183 | 183 | * @since 1.0.0 |
184 | 184 | * @return string |
185 | 185 | */ |
186 | - function column_period( $item ) { |
|
186 | + function column_period($item) { |
|
187 | 187 | |
188 | - $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->period,$item->frequency ); |
|
188 | + $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($item->period, $item->frequency); |
|
189 | 189 | |
190 | - return wpinv_price( wpinv_format_amount( $item->recurring_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ) . ' / ' . $period; |
|
190 | + return wpinv_price(wpinv_format_amount($item->recurring_amount), wpinv_get_invoice_currency_code($item->parent_payment_id)) . ' / ' . $period; |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | /** |
@@ -197,8 +197,8 @@ discard block |
||
197 | 197 | * @since 1.0.0 |
198 | 198 | * @return string |
199 | 199 | */ |
200 | - function column_bill_times( $item ) { |
|
201 | - return $item->get_times_billed() . ' / ' . ( ( $item->bill_times == 0 ) ? 'Until Cancelled' : $item->bill_times ); |
|
200 | + function column_bill_times($item) { |
|
201 | + return $item->get_times_billed() . ' / ' . (($item->bill_times == 0) ? 'Until Cancelled' : $item->bill_times); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -208,8 +208,8 @@ discard block |
||
208 | 208 | * @since 1.0.0 |
209 | 209 | * @return string |
210 | 210 | */ |
211 | - function column_initial_amount( $item ) { |
|
212 | - return wpinv_price( wpinv_format_amount( $item->initial_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ); |
|
211 | + function column_initial_amount($item) { |
|
212 | + return wpinv_price(wpinv_format_amount($item->initial_amount), wpinv_get_invoice_currency_code($item->parent_payment_id)); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
@@ -219,8 +219,8 @@ discard block |
||
219 | 219 | * @since 1.0.0 |
220 | 220 | * @return string |
221 | 221 | */ |
222 | - function column_renewal_date( $item ) { |
|
223 | - return $renewal_date = ! empty( $item->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $item->expiration ) ) : __( 'N/A', 'invoicing' ); |
|
222 | + function column_renewal_date($item) { |
|
223 | + return $renewal_date = !empty($item->expiration) ? date_i18n(get_option('date_format'), strtotime($item->expiration)) : __('N/A', 'invoicing'); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -230,8 +230,8 @@ discard block |
||
230 | 230 | * @since 1.0.0 |
231 | 231 | * @return string |
232 | 232 | */ |
233 | - function column_parent_payment_id( $item ) { |
|
234 | - return '<a href="' . get_edit_post_link( $item->parent_payment_id ) . '" target="_blank">' . wpinv_get_invoice_number( $item->parent_payment_id ) . '</a>'; |
|
233 | + function column_parent_payment_id($item) { |
|
234 | + return '<a href="' . get_edit_post_link($item->parent_payment_id) . '" target="_blank">' . wpinv_get_invoice_number($item->parent_payment_id) . '</a>'; |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
@@ -241,8 +241,8 @@ discard block |
||
241 | 241 | * @since 1.0.0 |
242 | 242 | * @return string |
243 | 243 | */ |
244 | - function column_product_id( $item ) { |
|
245 | - return '<a href="' . esc_url( admin_url( 'post.php?action=edit&post=' . $item->product_id ) ) . '" target="_blank">' . get_the_title( $item->product_id ) . '</a>'; |
|
244 | + function column_product_id($item) { |
|
245 | + return '<a href="' . esc_url(admin_url('post.php?action=edit&post=' . $item->product_id)) . '" target="_blank">' . get_the_title($item->product_id) . '</a>'; |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
@@ -252,8 +252,8 @@ discard block |
||
252 | 252 | * @since 2.0 |
253 | 253 | * @return string |
254 | 254 | */ |
255 | - function column_actions( $item ) { |
|
256 | - return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" title="' . esc_attr( __( 'View or edit subscription', 'invoicing' ) ) . '" target="_blank">' . __( 'View', 'invoicing' ) . '</a>'; |
|
255 | + function column_actions($item) { |
|
256 | + return '<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $item->id)) . '" title="' . esc_attr(__('View or edit subscription', 'invoicing')) . '" target="_blank">' . __('View', 'invoicing') . '</a>'; |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | |
@@ -265,21 +265,21 @@ discard block |
||
265 | 265 | * @return array |
266 | 266 | */ |
267 | 267 | |
268 | - function get_columns(){ |
|
268 | + function get_columns() { |
|
269 | 269 | $columns = array( |
270 | - 'sub_id' => __( 'ID', 'invoicing' ), |
|
271 | - 'customer_id' => __( 'Customer', 'invoicing' ), |
|
272 | - 'status' => __( 'Status', 'invoicing' ), |
|
273 | - 'period' => __( 'Billing Cycle', 'invoicing' ), |
|
274 | - 'initial_amount' => __( 'Initial Amount', 'invoicing' ), |
|
275 | - 'bill_times' => __( 'Times Billed', 'invoicing' ), |
|
276 | - 'renewal_date' => __( 'Renewal Date', 'invoicing' ), |
|
277 | - 'parent_payment_id' => __( 'Invoice', 'invoicing' ), |
|
278 | - 'product_id' => __( 'Item', 'invoicing' ), |
|
279 | - 'actions' => __( 'Actions', 'invoicing' ), |
|
270 | + 'sub_id' => __('ID', 'invoicing'), |
|
271 | + 'customer_id' => __('Customer', 'invoicing'), |
|
272 | + 'status' => __('Status', 'invoicing'), |
|
273 | + 'period' => __('Billing Cycle', 'invoicing'), |
|
274 | + 'initial_amount' => __('Initial Amount', 'invoicing'), |
|
275 | + 'bill_times' => __('Times Billed', 'invoicing'), |
|
276 | + 'renewal_date' => __('Renewal Date', 'invoicing'), |
|
277 | + 'parent_payment_id' => __('Invoice', 'invoicing'), |
|
278 | + 'product_id' => __('Item', 'invoicing'), |
|
279 | + 'actions' => __('Actions', 'invoicing'), |
|
280 | 280 | ); |
281 | 281 | |
282 | - return apply_filters( 'wpinv_report_subscription_columns', $columns ); |
|
282 | + return apply_filters('wpinv_report_subscription_columns', $columns); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | * @return int |
291 | 291 | */ |
292 | 292 | function get_paged() { |
293 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
293 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
@@ -306,16 +306,16 @@ discard block |
||
306 | 306 | |
307 | 307 | $db = new WPInv_Subscriptions_DB; |
308 | 308 | |
309 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
309 | + $search = !empty($_GET['s']) ? sanitize_text_field($_GET['s']) : ''; |
|
310 | 310 | |
311 | 311 | $this->total_count = $db->count(); |
312 | - $this->active_count = $db->count( array( 'status' => 'active', 'search' => $search ) ); |
|
313 | - $this->pending_count = $db->count( array( 'status' => 'pending', 'search' => $search ) ); |
|
314 | - $this->expired_count = $db->count( array( 'status' => 'expired', 'search' => $search ) ); |
|
315 | - $this->trialling_count = $db->count( array( 'status' => 'trialling', 'search' => $search ) ); |
|
316 | - $this->cancelled_count = $db->count( array( 'status' => 'cancelled', 'search' => $search ) ); |
|
317 | - $this->completed_count = $db->count( array( 'status' => 'completed', 'search' => $search ) ); |
|
318 | - $this->failing_count = $db->count( array( 'status' => 'failing', 'search' => $search ) ); |
|
312 | + $this->active_count = $db->count(array('status' => 'active', 'search' => $search)); |
|
313 | + $this->pending_count = $db->count(array('status' => 'pending', 'search' => $search)); |
|
314 | + $this->expired_count = $db->count(array('status' => 'expired', 'search' => $search)); |
|
315 | + $this->trialling_count = $db->count(array('status' => 'trialling', 'search' => $search)); |
|
316 | + $this->cancelled_count = $db->count(array('status' => 'cancelled', 'search' => $search)); |
|
317 | + $this->completed_count = $db->count(array('status' => 'completed', 'search' => $search)); |
|
318 | + $this->failing_count = $db->count(array('status' => 'failing', 'search' => $search)); |
|
319 | 319 | |
320 | 320 | } |
321 | 321 | |
@@ -336,28 +336,28 @@ discard block |
||
336 | 336 | |
337 | 337 | $columns = $this->get_columns(); |
338 | 338 | $hidden = array(); // No hidden columns |
339 | - $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any'; |
|
339 | + $status = isset($_GET['status']) ? $_GET['status'] : 'any'; |
|
340 | 340 | $sortable = $this->get_sortable_columns(); |
341 | 341 | |
342 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
342 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
343 | 343 | |
344 | 344 | $current_page = $this->get_pagenum(); |
345 | 345 | |
346 | 346 | $db = new WPInv_Subscriptions_DB; |
347 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
347 | + $search = !empty($_GET['s']) ? sanitize_text_field($_GET['s']) : ''; |
|
348 | 348 | $args = array( |
349 | 349 | 'number' => $this->per_page, |
350 | - 'offset' => $this->per_page * ( $this->get_paged() - 1 ), |
|
350 | + 'offset' => $this->per_page * ($this->get_paged() - 1), |
|
351 | 351 | 'search' => $search |
352 | 352 | ); |
353 | 353 | |
354 | - if ( 'any' !== $status ) { |
|
354 | + if ('any' !== $status) { |
|
355 | 355 | $args['status'] = $status; |
356 | 356 | } |
357 | 357 | |
358 | - $this->items = $db->get_subscriptions( $args ); |
|
358 | + $this->items = $db->get_subscriptions($args); |
|
359 | 359 | |
360 | - switch ( $status ) { |
|
360 | + switch ($status) { |
|
361 | 361 | case 'active': |
362 | 362 | $total_items = $this->active_count; |
363 | 363 | break; |
@@ -385,10 +385,10 @@ discard block |
||
385 | 385 | break; |
386 | 386 | } |
387 | 387 | |
388 | - $this->set_pagination_args( array( |
|
388 | + $this->set_pagination_args(array( |
|
389 | 389 | 'total_items' => $total_items, |
390 | 390 | 'per_page' => $this->per_page, |
391 | - 'total_pages' => ceil( $total_items / $this->per_page ) |
|
392 | - ) ); |
|
391 | + 'total_pages' => ceil($total_items / $this->per_page) |
|
392 | + )); |
|
393 | 393 | } |
394 | 394 | } |
@@ -11,49 +11,49 @@ discard block |
||
11 | 11 | * @since 1.0.0 |
12 | 12 | */ |
13 | 13 | function wpinv_automatic_upgrade() { |
14 | - $wpi_version = get_option( 'wpinv_version' ); |
|
14 | + $wpi_version = get_option('wpinv_version'); |
|
15 | 15 | |
16 | - if ( $wpi_version == WPINV_VERSION ) { |
|
16 | + if ($wpi_version == WPINV_VERSION) { |
|
17 | 17 | return; |
18 | 18 | } |
19 | 19 | |
20 | - if ( version_compare( $wpi_version, '0.0.5', '<' ) ) { |
|
20 | + if (version_compare($wpi_version, '0.0.5', '<')) { |
|
21 | 21 | wpinv_v005_upgrades(); |
22 | 22 | } |
23 | 23 | |
24 | - if ( version_compare( $wpi_version, '1.0.3', '<' ) ) { |
|
24 | + if (version_compare($wpi_version, '1.0.3', '<')) { |
|
25 | 25 | wpinv_v103_upgrades(); |
26 | 26 | } |
27 | 27 | |
28 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
28 | + update_option('wpinv_version', WPINV_VERSION); |
|
29 | 29 | } |
30 | -add_action( 'admin_init', 'wpinv_automatic_upgrade' ); |
|
30 | +add_action('admin_init', 'wpinv_automatic_upgrade'); |
|
31 | 31 | |
32 | 32 | function wpinv_v005_upgrades() { |
33 | 33 | global $wpdb; |
34 | 34 | |
35 | 35 | // Invoices status |
36 | - $results = $wpdb->get_results( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
37 | - if ( !empty( $results ) ) { |
|
38 | - $wpdb->query( "UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
36 | + $results = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )"); |
|
37 | + if (!empty($results)) { |
|
38 | + $wpdb->query("UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )"); |
|
39 | 39 | |
40 | 40 | // Clean post cache |
41 | - foreach ( $results as $row ) { |
|
42 | - clean_post_cache( $row->ID ); |
|
41 | + foreach ($results as $row) { |
|
42 | + clean_post_cache($row->ID); |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 | |
46 | 46 | // Item meta key changes |
47 | 47 | $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
48 | - $results = $wpdb->get_results( $query ); |
|
48 | + $results = $wpdb->get_results($query); |
|
49 | 49 | |
50 | - if ( !empty( $results ) ) { |
|
51 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
52 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
53 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
50 | + if (!empty($results)) { |
|
51 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )"); |
|
52 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'"); |
|
53 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'"); |
|
54 | 54 | |
55 | - foreach ( $results as $row ) { |
|
56 | - clean_post_cache( $row->post_id ); |
|
55 | + foreach ($results as $row) { |
|
56 | + clean_post_cache($row->post_id); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
@@ -74,79 +74,79 @@ discard block |
||
74 | 74 | function wpinv_convert_old_subscriptions() { |
75 | 75 | global $wpdb; |
76 | 76 | |
77 | - $query = "SELECT ". $wpdb->posts .".ID FROM ". $wpdb->posts ." INNER JOIN ". $wpdb->postmeta ." ON ( ". $wpdb->posts .".ID = ". $wpdb->postmeta .".post_id ) WHERE 1=1 AND ". $wpdb->postmeta .".meta_key = '_wpinv_subscr_status' AND (". $wpdb->postmeta .".meta_value = 'pending' OR ". $wpdb->postmeta .".meta_value = 'active' OR ". $wpdb->postmeta .".meta_value = 'cancelled' OR ". $wpdb->postmeta .".meta_value = 'completed' OR ". $wpdb->postmeta .".meta_value = 'expired' OR ". $wpdb->postmeta .".meta_value = 'trialling' OR ". $wpdb->postmeta .".meta_value = 'failing') AND ". $wpdb->posts .".post_type = 'wpi_invoice' GROUP BY ". $wpdb->posts .".ID ORDER BY ". $wpdb->posts .".ID ASC"; |
|
77 | + $query = "SELECT " . $wpdb->posts . ".ID FROM " . $wpdb->posts . " INNER JOIN " . $wpdb->postmeta . " ON ( " . $wpdb->posts . ".ID = " . $wpdb->postmeta . ".post_id ) WHERE 1=1 AND " . $wpdb->postmeta . ".meta_key = '_wpinv_subscr_status' AND (" . $wpdb->postmeta . ".meta_value = 'pending' OR " . $wpdb->postmeta . ".meta_value = 'active' OR " . $wpdb->postmeta . ".meta_value = 'cancelled' OR " . $wpdb->postmeta . ".meta_value = 'completed' OR " . $wpdb->postmeta . ".meta_value = 'expired' OR " . $wpdb->postmeta . ".meta_value = 'trialling' OR " . $wpdb->postmeta . ".meta_value = 'failing') AND " . $wpdb->posts . ".post_type = 'wpi_invoice' GROUP BY " . $wpdb->posts . ".ID ORDER BY " . $wpdb->posts . ".ID ASC"; |
|
78 | 78 | |
79 | - $results = $wpdb->get_results( $query ); |
|
79 | + $results = $wpdb->get_results($query); |
|
80 | 80 | |
81 | - if ( empty( $results ) ) { |
|
81 | + if (empty($results)) { |
|
82 | 82 | return; |
83 | 83 | } |
84 | 84 | |
85 | - foreach ( $results as $row ) { |
|
86 | - $invoice = new WPInv_Invoice( $row->ID ); |
|
85 | + foreach ($results as $row) { |
|
86 | + $invoice = new WPInv_Invoice($row->ID); |
|
87 | 87 | |
88 | - if ( empty( $invoice->ID ) ) { |
|
88 | + if (empty($invoice->ID)) { |
|
89 | 89 | continue; |
90 | 90 | } |
91 | 91 | |
92 | - if ( $invoice->has_status( 'wpi-renewal' ) ) { |
|
92 | + if ($invoice->has_status('wpi-renewal')) { |
|
93 | 93 | continue; |
94 | 94 | } |
95 | 95 | |
96 | - $item = $invoice->get_recurring( true ); |
|
96 | + $item = $invoice->get_recurring(true); |
|
97 | 97 | |
98 | - if ( empty( $item ) ) { |
|
98 | + if (empty($item)) { |
|
99 | 99 | continue; |
100 | 100 | } |
101 | 101 | |
102 | 102 | $is_free_trial = $invoice->is_free_trial(); |
103 | - $profile_id = get_post_meta( $invoice->ID, '_wpinv_subscr_profile_id', true ); |
|
104 | - $subscription_status = get_post_meta( $invoice->ID, '_wpinv_subscr_status', true ); |
|
103 | + $profile_id = get_post_meta($invoice->ID, '_wpinv_subscr_profile_id', true); |
|
104 | + $subscription_status = get_post_meta($invoice->ID, '_wpinv_subscr_status', true); |
|
105 | 105 | $transaction_id = $invoice->get_transaction_id(); |
106 | 106 | |
107 | 107 | // Last invoice |
108 | - $query = "SELECT ID, post_date FROM ". $wpdb->posts ." WHERE post_type = 'wpi_invoice' AND post_parent = '" . $invoice->ID . "' ORDER BY ID DESC LIMIT 1"; |
|
109 | - $last_payment = $wpdb->get_row( $query ); |
|
108 | + $query = "SELECT ID, post_date FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_parent = '" . $invoice->ID . "' ORDER BY ID DESC LIMIT 1"; |
|
109 | + $last_payment = $wpdb->get_row($query); |
|
110 | 110 | |
111 | - if ( !empty( $last_payment ) ) { |
|
112 | - $invoice_date = $last_payment->post_date; |
|
111 | + if (!empty($last_payment)) { |
|
112 | + $invoice_date = $last_payment->post_date; |
|
113 | 113 | |
114 | - $meta_profile_id = get_post_meta( $last_payment->ID, '_wpinv_subscr_profile_id', true ); |
|
115 | - $meta_transaction_id = get_post_meta( $last_payment->ID, '_wpinv_transaction_id', true ); |
|
114 | + $meta_profile_id = get_post_meta($last_payment->ID, '_wpinv_subscr_profile_id', true); |
|
115 | + $meta_transaction_id = get_post_meta($last_payment->ID, '_wpinv_transaction_id', true); |
|
116 | 116 | |
117 | - if ( !empty( $meta_profile_id ) ) { |
|
118 | - $profile_id = $meta_profile_id; |
|
117 | + if (!empty($meta_profile_id)) { |
|
118 | + $profile_id = $meta_profile_id; |
|
119 | 119 | } |
120 | 120 | |
121 | - if ( !empty( $meta_transaction_id ) ) { |
|
122 | - $transaction_id = $meta_transaction_id; |
|
121 | + if (!empty($meta_transaction_id)) { |
|
122 | + $transaction_id = $meta_transaction_id; |
|
123 | 123 | } |
124 | 124 | } else { |
125 | - $invoice_date = $invoice->get_invoice_date( false ); |
|
125 | + $invoice_date = $invoice->get_invoice_date(false); |
|
126 | 126 | } |
127 | 127 | |
128 | - $profile_id = empty( $profile_id ) ? $invoice->ID : $profile_id; |
|
129 | - $status = empty( $subscription_status ) ? 'pending' : $subscription_status; |
|
128 | + $profile_id = empty($profile_id) ? $invoice->ID : $profile_id; |
|
129 | + $status = empty($subscription_status) ? 'pending' : $subscription_status; |
|
130 | 130 | |
131 | - $period = $item->get_recurring_period( true ); |
|
131 | + $period = $item->get_recurring_period(true); |
|
132 | 132 | $interval = $item->get_recurring_interval(); |
133 | 133 | $bill_times = (int)$item->get_recurring_limit(); |
134 | 134 | $add_period = $interval . ' ' . $period; |
135 | 135 | $trial_period = ''; |
136 | 136 | |
137 | - if ( $invoice->is_free_trial() ) { |
|
138 | - $trial_period = $item->get_trial_period( true ); |
|
137 | + if ($invoice->is_free_trial()) { |
|
138 | + $trial_period = $item->get_trial_period(true); |
|
139 | 139 | $free_interval = $item->get_trial_interval(); |
140 | 140 | $trial_period = $free_interval . ' ' . $trial_period; |
141 | 141 | |
142 | - if ( empty( $last_payment ) ) { |
|
142 | + if (empty($last_payment)) { |
|
143 | 143 | $add_period = $trial_period; |
144 | 144 | } |
145 | 145 | } |
146 | 146 | |
147 | - $expiration = date_i18n( 'Y-m-d H:i:s', strtotime( '+' . $add_period . ' 23:59:59', strtotime( $invoice_date ) ) ); |
|
148 | - if ( strtotime( $expiration ) < strtotime( date_i18n( 'Y-m-d' ) ) ) { |
|
149 | - if ( $status == 'active' || $status == 'trialling' || $status == 'pending' ) { |
|
147 | + $expiration = date_i18n('Y-m-d H:i:s', strtotime('+' . $add_period . ' 23:59:59', strtotime($invoice_date))); |
|
148 | + if (strtotime($expiration) < strtotime(date_i18n('Y-m-d'))) { |
|
149 | + if ($status == 'active' || $status == 'trialling' || $status == 'pending') { |
|
150 | 150 | $status = 'expired'; |
151 | 151 | } |
152 | 152 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | 'frequency' => $interval, |
160 | 160 | 'period' => $period, |
161 | 161 | 'initial_amount' => $invoice->get_total(), |
162 | - 'recurring_amount' => $invoice->get_recurring_details( 'total' ), |
|
162 | + 'recurring_amount' => $invoice->get_recurring_details('total'), |
|
163 | 163 | 'bill_times' => $bill_times, |
164 | 164 | 'created' => $invoice_date, |
165 | 165 | 'expiration' => $expiration, |
@@ -169,14 +169,14 @@ discard block |
||
169 | 169 | ); |
170 | 170 | |
171 | 171 | $subs_db = new WPInv_Subscriptions_DB; |
172 | - $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice->ID, 'number' => 1 ) ); |
|
173 | - $subscription = reset( $subs ); |
|
172 | + $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice->ID, 'number' => 1)); |
|
173 | + $subscription = reset($subs); |
|
174 | 174 | |
175 | - if ( empty( $subscription ) || $subscription->id <= 0 ) { |
|
175 | + if (empty($subscription) || $subscription->id <= 0) { |
|
176 | 176 | $subscription = new WPInv_Subscription(); |
177 | - $new_sub = $subscription->create( $args ); |
|
177 | + $new_sub = $subscription->create($args); |
|
178 | 178 | |
179 | - if ( !empty( $bill_times ) && $new_sub->get_times_billed() >= $bill_times && ( 'active' == $new_sub->status || 'trialling' == $new_sub->status ) ) { |
|
179 | + if (!empty($bill_times) && $new_sub->get_times_billed() >= $bill_times && ('active' == $new_sub->status || 'trialling' == $new_sub->status)) { |
|
180 | 180 | $new_sub->complete(); // Mark completed if all times billed |
181 | 181 | } |
182 | 182 | } |
@@ -186,34 +186,34 @@ discard block |
||
186 | 186 | function wpinv_update_new_email_settings() { |
187 | 187 | global $wpinv_options; |
188 | 188 | |
189 | - $current_options = get_option( 'wpinv_settings', array() ); |
|
189 | + $current_options = get_option('wpinv_settings', array()); |
|
190 | 190 | $options = array(); |
191 | 191 | |
192 | 192 | // Populate some default values |
193 | - foreach( wpinv_get_registered_settings() as $tab => $sections ) { |
|
194 | - foreach( $sections as $section => $settings) { |
|
193 | + foreach (wpinv_get_registered_settings() as $tab => $sections) { |
|
194 | + foreach ($sections as $section => $settings) { |
|
195 | 195 | // Check for backwards compatibility |
196 | - $tab_sections = wpinv_get_settings_tab_sections( $tab ); |
|
197 | - if( ! is_array( $tab_sections ) || ! array_key_exists( $section, $tab_sections ) ) { |
|
196 | + $tab_sections = wpinv_get_settings_tab_sections($tab); |
|
197 | + if (!is_array($tab_sections) || !array_key_exists($section, $tab_sections)) { |
|
198 | 198 | $section = 'main'; |
199 | 199 | $settings = $sections; |
200 | 200 | } |
201 | 201 | |
202 | - foreach ( $settings as $option ) { |
|
203 | - if ( !empty( $option['id'] ) && !isset( $wpinv_options[ $option['id'] ] ) ) { |
|
204 | - if ( 'checkbox' == $option['type'] && !empty( $option['std'] ) ) { |
|
205 | - $options[ $option['id'] ] = '1'; |
|
206 | - } else if ( !empty( $option['std'] ) ) { |
|
207 | - $options[ $option['id'] ] = $option['std']; |
|
202 | + foreach ($settings as $option) { |
|
203 | + if (!empty($option['id']) && !isset($wpinv_options[$option['id']])) { |
|
204 | + if ('checkbox' == $option['type'] && !empty($option['std'])) { |
|
205 | + $options[$option['id']] = '1'; |
|
206 | + } else if (!empty($option['std'])) { |
|
207 | + $options[$option['id']] = $option['std']; |
|
208 | 208 | } |
209 | 209 | } |
210 | 210 | } |
211 | 211 | } |
212 | 212 | } |
213 | 213 | |
214 | - $merged_options_current = array_merge( $wpinv_options, $options ); |
|
215 | - $merged_options = array_merge( $merged_options_current, $current_options ); |
|
214 | + $merged_options_current = array_merge($wpinv_options, $options); |
|
215 | + $merged_options = array_merge($merged_options_current, $current_options); |
|
216 | 216 | $wpinv_options = $merged_options; |
217 | 217 | |
218 | - update_option( 'wpinv_settings', $merged_options ); |
|
218 | + update_option('wpinv_settings', $merged_options); |
|
219 | 219 | } |
220 | 220 | \ No newline at end of file |