@@ -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' ), 40 ); |
|
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( 'getpaid_checkout_before_gateway', array( $this, 'add_subscription' ), -999 ); |
|
85 | - add_action( 'wpinv_subscriptions_front_notices', array( $this, 'notices' ) ); |
|
79 | + add_action('admin_menu', array($this, 'wpinv_subscriptions_list'), 40); |
|
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('getpaid_checkout_before_gateway', array($this, 'add_subscription'), -999); |
|
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 | wpinv_get_capability(), |
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,29 +182,29 @@ 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 | |
187 | 187 | $frequency = ''; |
188 | 188 | //Format period details |
189 | - switch ( strtolower( $period ) ) { |
|
189 | + switch (strtolower($period)) { |
|
190 | 190 | case 'day' : |
191 | 191 | case 'd' : |
192 | - $frequency = sprintf( _n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count); |
|
192 | + $frequency = sprintf(_n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count); |
|
193 | 193 | break; |
194 | 194 | case 'week' : |
195 | 195 | case 'w' : |
196 | - $frequency = sprintf( _n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count); |
|
196 | + $frequency = sprintf(_n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count); |
|
197 | 197 | break; |
198 | 198 | case 'month' : |
199 | 199 | case 'm' : |
200 | - $frequency = sprintf( _n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count); |
|
200 | + $frequency = sprintf(_n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count); |
|
201 | 201 | break; |
202 | 202 | case 'year' : |
203 | 203 | case 'y' : |
204 | - $frequency = sprintf( _n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count); |
|
204 | + $frequency = sprintf(_n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count); |
|
205 | 205 | break; |
206 | 206 | default : |
207 | - $frequency = apply_filters( 'wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count ); |
|
207 | + $frequency = apply_filters('wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count); |
|
208 | 208 | break; |
209 | 209 | } |
210 | 210 | |
@@ -219,50 +219,50 @@ discard block |
||
219 | 219 | * @since 1.0.0 |
220 | 220 | * @return void |
221 | 221 | */ |
222 | - public function wpinv_process_cancellation( $data ) { |
|
222 | + public function wpinv_process_cancellation($data) { |
|
223 | 223 | |
224 | 224 | |
225 | - if( empty( $data['sub_id'] ) ) { |
|
225 | + if (empty($data['sub_id'])) { |
|
226 | 226 | return; |
227 | 227 | } |
228 | 228 | |
229 | - if( ! is_user_logged_in() ) { |
|
229 | + if (!is_user_logged_in()) { |
|
230 | 230 | return; |
231 | 231 | } |
232 | 232 | |
233 | - if( ! wp_verify_nonce( $data['_wpnonce'], 'wpinv-recurring-cancel' ) ) { |
|
234 | - wp_die( __( 'Error', 'invoicing' ), __( 'Nonce verification failed', 'invoicing' ), array( 'response' => 403 ) ); |
|
233 | + if (!wp_verify_nonce($data['_wpnonce'], 'wpinv-recurring-cancel')) { |
|
234 | + wp_die(__('Error', 'invoicing'), __('Nonce verification failed', 'invoicing'), array('response' => 403)); |
|
235 | 235 | } |
236 | 236 | |
237 | - $data['sub_id'] = absint( $data['sub_id'] ); |
|
238 | - $subscription = new WPInv_Subscription( $data['sub_id'] ); |
|
237 | + $data['sub_id'] = absint($data['sub_id']); |
|
238 | + $subscription = new WPInv_Subscription($data['sub_id']); |
|
239 | 239 | |
240 | - if( ! $subscription->can_cancel() ) { |
|
241 | - wp_die( __( 'Error', 'invoicing' ), __( 'This subscription cannot be cancelled', 'invoicing' ), array( 'response' => 403 ) ); |
|
240 | + if (!$subscription->can_cancel()) { |
|
241 | + wp_die(__('Error', 'invoicing'), __('This subscription cannot be cancelled', 'invoicing'), array('response' => 403)); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | try { |
245 | 245 | |
246 | - do_action( 'wpinv_recurring_cancel_' . $subscription->gateway . '_subscription', $subscription, true ); |
|
246 | + do_action('wpinv_recurring_cancel_' . $subscription->gateway . '_subscription', $subscription, true); |
|
247 | 247 | |
248 | 248 | $subscription->cancel(); |
249 | 249 | |
250 | - if( is_admin() ) { |
|
250 | + if (is_admin()) { |
|
251 | 251 | |
252 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=cancelled&id=' . $subscription->id ) ); |
|
252 | + wp_redirect(admin_url('admin.php?page=wpinv-subscriptions&wpinv-message=cancelled&id=' . $subscription->id)); |
|
253 | 253 | exit; |
254 | 254 | |
255 | 255 | } else { |
256 | 256 | |
257 | - $redirect = remove_query_arg( array( '_wpnonce', 'wpinv_action', 'sub_id' ), add_query_arg( array( 'wpinv-message' => 'cancelled' ) ) ); |
|
258 | - $redirect = apply_filters( 'wpinv_recurring_cancellation_redirect', $redirect, $subscription ); |
|
259 | - wp_safe_redirect( $redirect ); |
|
257 | + $redirect = remove_query_arg(array('_wpnonce', 'wpinv_action', 'sub_id'), add_query_arg(array('wpinv-message' => 'cancelled'))); |
|
258 | + $redirect = apply_filters('wpinv_recurring_cancellation_redirect', $redirect, $subscription); |
|
259 | + wp_safe_redirect($redirect); |
|
260 | 260 | exit; |
261 | 261 | |
262 | 262 | } |
263 | 263 | |
264 | - } catch ( Exception $e ) { |
|
265 | - wp_die( __( 'Error', 'invoicing' ), $e->getMessage(), array( 'response' => 403 ) ); |
|
264 | + } catch (Exception $e) { |
|
265 | + wp_die(__('Error', 'invoicing'), $e->getMessage(), array('response' => 403)); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | } |
@@ -275,33 +275,33 @@ discard block |
||
275 | 275 | * @since 1.0.0 |
276 | 276 | * @return void |
277 | 277 | */ |
278 | - public function add_subscription( $invoice ) { |
|
278 | + public function add_subscription($invoice) { |
|
279 | 279 | |
280 | - $invoice = new WPInv_Invoice( $invoice ); |
|
280 | + $invoice = new WPInv_Invoice($invoice); |
|
281 | 281 | |
282 | 282 | // Abort if it is not recurring. |
283 | - if ( ! $invoice->is_recurring() || $invoice->is_renewal() ) { |
|
283 | + if (!$invoice->is_recurring() || $invoice->is_renewal()) { |
|
284 | 284 | return; |
285 | 285 | } |
286 | 286 | |
287 | 287 | // Should we create a subscription for the invoice? |
288 | - if ( apply_filters( 'wpinv_skip_invoice_subscription_creation', false, $invoice ) ) { |
|
288 | + if (apply_filters('wpinv_skip_invoice_subscription_creation', false, $invoice)) { |
|
289 | 289 | return; |
290 | 290 | } |
291 | 291 | |
292 | 292 | // Get the recurring item. |
293 | - $subscription_item = $invoice->get_recurring( true ); |
|
293 | + $subscription_item = $invoice->get_recurring(true); |
|
294 | 294 | |
295 | 295 | // Prepare the subscription details. |
296 | - $period = $subscription_item->get_recurring_period( true ); |
|
296 | + $period = $subscription_item->get_recurring_period(true); |
|
297 | 297 | $interval = $subscription_item->get_recurring_interval(); |
298 | 298 | $add_period = $interval . ' ' . $period; |
299 | 299 | $trial_period = ''; |
300 | 300 | |
301 | - if ( $invoice->has_free_trial() ) { |
|
301 | + if ($invoice->has_free_trial()) { |
|
302 | 302 | |
303 | - if ( $subscription_item->has_free_trial() ) { |
|
304 | - $trial_period = $subscription_item->get_trial_period( true ); |
|
303 | + if ($subscription_item->has_free_trial()) { |
|
304 | + $trial_period = $subscription_item->get_trial_period(true); |
|
305 | 305 | $free_interval = $subscription_item->get_trial_interval(); |
306 | 306 | } else { |
307 | 307 | $trial_period = $period; |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | } |
315 | 315 | |
316 | 316 | // Calculate the next renewal date. |
317 | - $expiration = date( 'Y-m-d H:i:s', strtotime( "+ $add_period", current_time( 'timestamp' ) ) ); |
|
317 | + $expiration = date('Y-m-d H:i:s', strtotime("+ $add_period", current_time('timestamp'))); |
|
318 | 318 | |
319 | 319 | // Subscription arguments. |
320 | 320 | $args = array( |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | 'initial_amount' => $invoice->get_initial_total(), |
328 | 328 | 'recurring_amount' => $invoice->get_recurring_total(), |
329 | 329 | 'bill_times' => $subscription_item->get_recurring_limit(), |
330 | - 'created' => current_time( 'mysql' ), |
|
330 | + 'created' => current_time('mysql'), |
|
331 | 331 | 'expiration' => $expiration, |
332 | 332 | 'trial_period' => $trial_period, |
333 | 333 | 'profile_id' => '', |
@@ -335,19 +335,19 @@ discard block |
||
335 | 335 | ); |
336 | 336 | |
337 | 337 | // Create or update the subscription. |
338 | - $subscription = wpinv_get_subscription( $invoice ); |
|
338 | + $subscription = wpinv_get_subscription($invoice); |
|
339 | 339 | |
340 | - if ( empty( $subscription ) ) { |
|
340 | + if (empty($subscription)) { |
|
341 | 341 | |
342 | 342 | $subscription = new WPInv_Subscription(); |
343 | - $subscription->create( $args ); |
|
343 | + $subscription->create($args); |
|
344 | 344 | |
345 | 345 | } else { |
346 | 346 | |
347 | 347 | |
348 | - unset( $args['transaction_id'] ); |
|
349 | - unset( $args['profile_id'] ); |
|
350 | - $subscription->update( $args ); |
|
348 | + unset($args['transaction_id']); |
|
349 | + unset($args['profile_id']); |
|
350 | + $subscription->update($args); |
|
351 | 351 | |
352 | 352 | } |
353 | 353 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,60 +10,60 @@ discard block |
||
10 | 10 | class GetPaid_Form_Item extends WPInv_Item { |
11 | 11 | |
12 | 12 | /** |
13 | - * Stores a custom description for the item. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $custom_description = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * Stores the item quantity. |
|
21 | - * |
|
22 | - * @var int |
|
23 | - */ |
|
24 | - protected $quantity = 1; |
|
25 | - |
|
26 | - /** |
|
27 | - * Stores the item meta. |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $meta = array(); |
|
32 | - |
|
33 | - /** |
|
34 | - * Is this item required? |
|
35 | - * |
|
36 | - * @var int |
|
37 | - */ |
|
38 | - protected $is_required = true; |
|
39 | - |
|
40 | - /** |
|
41 | - * Are quantities allowed? |
|
42 | - * |
|
43 | - * @var int |
|
44 | - */ |
|
45 | - protected $allow_quantities = false; |
|
46 | - |
|
47 | - /** |
|
48 | - * Associated invoice. |
|
49 | - * |
|
50 | - * @var int |
|
51 | - */ |
|
52 | - public $invoice_id = 0; |
|
53 | - |
|
54 | - /** |
|
55 | - * Item discount. |
|
56 | - * |
|
57 | - * @var float |
|
58 | - */ |
|
59 | - public $item_discount = 0; |
|
60 | - |
|
61 | - /** |
|
62 | - * Item tax. |
|
63 | - * |
|
64 | - * @var float |
|
65 | - */ |
|
66 | - public $item_tax = 0; |
|
13 | + * Stores a custom description for the item. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $custom_description = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * Stores the item quantity. |
|
21 | + * |
|
22 | + * @var int |
|
23 | + */ |
|
24 | + protected $quantity = 1; |
|
25 | + |
|
26 | + /** |
|
27 | + * Stores the item meta. |
|
28 | + * |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $meta = array(); |
|
32 | + |
|
33 | + /** |
|
34 | + * Is this item required? |
|
35 | + * |
|
36 | + * @var int |
|
37 | + */ |
|
38 | + protected $is_required = true; |
|
39 | + |
|
40 | + /** |
|
41 | + * Are quantities allowed? |
|
42 | + * |
|
43 | + * @var int |
|
44 | + */ |
|
45 | + protected $allow_quantities = false; |
|
46 | + |
|
47 | + /** |
|
48 | + * Associated invoice. |
|
49 | + * |
|
50 | + * @var int |
|
51 | + */ |
|
52 | + public $invoice_id = 0; |
|
53 | + |
|
54 | + /** |
|
55 | + * Item discount. |
|
56 | + * |
|
57 | + * @var float |
|
58 | + */ |
|
59 | + public $item_discount = 0; |
|
60 | + |
|
61 | + /** |
|
62 | + * Item tax. |
|
63 | + * |
|
64 | + * @var float |
|
65 | + */ |
|
66 | + public $item_tax = 0; |
|
67 | 67 | |
68 | 68 | /* |
69 | 69 | |-------------------------------------------------------------------------- |
@@ -81,226 +81,226 @@ discard block |
||
81 | 81 | */ |
82 | 82 | |
83 | 83 | /** |
84 | - * Get the item name. |
|
85 | - * |
|
86 | - * @since 1.0.19 |
|
87 | - * @param string $context View or edit context. |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function get_name( $context = 'view' ) { |
|
91 | - $name = parent::get_name( $context ); |
|
92 | - return $name . wpinv_get_item_suffix( $this ); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Get the item name without a suffix. |
|
97 | - * |
|
98 | - * @since 1.0.19 |
|
99 | - * @param string $context View or edit context. |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - public function get_raw_name( $context = 'view' ) { |
|
103 | - return parent::get_name( $context ); |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Get the item description. |
|
108 | - * |
|
109 | - * @since 1.0.19 |
|
110 | - * @param string $context View or edit context. |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function get_description( $context = 'view' ) { |
|
114 | - |
|
115 | - if ( isset( $this->custom_description ) ) { |
|
116 | - return $this->custom_description; |
|
117 | - } |
|
118 | - |
|
119 | - return parent::get_description( $context ); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Returns the sub total. |
|
124 | - * |
|
125 | - * @since 1.0.19 |
|
126 | - * @param string $context View or edit context. |
|
127 | - * @return int |
|
128 | - */ |
|
129 | - public function get_sub_total( $context = 'view' ) { |
|
130 | - return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Returns the recurring sub total. |
|
135 | - * |
|
136 | - * @since 1.0.19 |
|
137 | - * @param string $context View or edit context. |
|
138 | - * @return int |
|
139 | - */ |
|
140 | - public function get_recurring_sub_total( $context = 'view' ) { |
|
141 | - return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * @deprecated |
|
146 | - */ |
|
147 | - public function get_qantity( $context = 'view' ) { |
|
148 | - return $this->get_quantity( $context ); |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Get the item quantity. |
|
153 | - * |
|
154 | - * @since 1.0.19 |
|
155 | - * @param string $context View or edit context. |
|
156 | - * @return int |
|
157 | - */ |
|
158 | - public function get_quantity( $context = 'view' ) { |
|
159 | - $quantity = (int) $this->quantity; |
|
160 | - |
|
161 | - if ( empty( $quantity ) || 1 > $quantity ) { |
|
162 | - $quantity = 1; |
|
163 | - } |
|
164 | - |
|
165 | - if ( 'view' == $context ) { |
|
166 | - return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
167 | - } |
|
168 | - |
|
169 | - return $quantity; |
|
170 | - |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * Get the item meta data. |
|
175 | - * |
|
176 | - * @since 1.0.19 |
|
177 | - * @param string $context View or edit context. |
|
178 | - * @return meta |
|
179 | - */ |
|
180 | - public function get_item_meta( $context = 'view' ) { |
|
181 | - $meta = $this->meta; |
|
182 | - |
|
183 | - if ( 'view' == $context ) { |
|
184 | - return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
185 | - } |
|
186 | - |
|
187 | - return $meta; |
|
188 | - |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Returns whether or not customers can update the item quantity. |
|
193 | - * |
|
194 | - * @since 1.0.19 |
|
195 | - * @param string $context View or edit context. |
|
196 | - * @return bool |
|
197 | - */ |
|
198 | - public function get_allow_quantities( $context = 'view' ) { |
|
199 | - $allow_quantities = (bool) $this->allow_quantities; |
|
200 | - |
|
201 | - if ( 'view' == $context ) { |
|
202 | - return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
203 | - } |
|
204 | - |
|
205 | - return $allow_quantities; |
|
206 | - |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Returns whether or not the item is required. |
|
211 | - * |
|
212 | - * @since 1.0.19 |
|
213 | - * @param string $context View or edit context. |
|
214 | - * @return bool |
|
215 | - */ |
|
216 | - public function get_is_required( $context = 'view' ) { |
|
217 | - $is_required = (bool) $this->is_required; |
|
218 | - |
|
219 | - if ( 'view' == $context ) { |
|
220 | - return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
221 | - } |
|
222 | - |
|
223 | - return $is_required; |
|
224 | - |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * Prepares form data for use. |
|
229 | - * |
|
230 | - * @since 1.0.19 |
|
231 | - * @return array |
|
232 | - */ |
|
233 | - public function prepare_data_for_use() { |
|
234 | - |
|
235 | - return array( |
|
236 | - 'title' => sanitize_text_field( $this->get_name() ), |
|
237 | - 'id' => $this->get_id(), |
|
238 | - 'price' => $this->get_price(), |
|
239 | - 'recurring' => $this->is_recurring(), |
|
240 | - 'description' => $this->get_description(), |
|
241 | - 'allow_quantities' => $this->allows_quantities(), |
|
242 | - 'required' => $this->is_required(), |
|
243 | - ); |
|
244 | - |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * Prepares form data for ajax use. |
|
249 | - * |
|
250 | - * @since 1.0.19 |
|
251 | - * @return array |
|
252 | - */ |
|
253 | - public function prepare_data_for_invoice_edit_ajax( $currency = '' ) { |
|
254 | - |
|
255 | - $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
256 | - |
|
257 | - if ( $description ) { |
|
258 | - $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
|
259 | - } |
|
260 | - |
|
261 | - return array( |
|
262 | - 'id' => $this->get_id(), |
|
263 | - 'texts' => array( |
|
264 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
265 | - 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
266 | - 'item-quantity' => absint( $this->get_quantity() ), |
|
267 | - 'item-price' => wpinv_price( wpinv_format_amount ( $this->get_price() ), $currency ), |
|
268 | - 'item-total' => wpinv_price( wpinv_format_amount( $this->get_sub_total() ), $currency ), |
|
269 | - ), |
|
270 | - 'inputs' => array( |
|
271 | - 'item-id' => $this->get_id(), |
|
272 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
273 | - 'item-description' => wp_kses_post( $this->get_description() ), |
|
274 | - 'item-quantity' => absint( $this->get_quantity() ), |
|
275 | - 'item-price' => $this->get_price(), |
|
276 | - ) |
|
277 | - ); |
|
278 | - |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * Prepares form data for saving (cart_details). |
|
283 | - * |
|
284 | - * @since 1.0.19 |
|
285 | - * @return array |
|
286 | - */ |
|
287 | - public function prepare_data_for_saving() { |
|
288 | - |
|
289 | - return array( |
|
290 | - 'post_id' => $this->invoice_id, |
|
291 | - 'item_id' => $this->get_id(), |
|
292 | - 'item_name' => sanitize_text_field( $this->get_raw_name() ), |
|
293 | - 'item_description' => $this->get_description(), |
|
294 | - 'tax' => $this->item_tax, |
|
295 | - 'item_price' => $this->get_price(), |
|
296 | - 'quantity' => (int) $this->get_quantity(), |
|
297 | - 'discount' => $this->item_discount, |
|
298 | - 'subtotal' => $this->get_sub_total(), |
|
299 | - 'price' => $this->get_sub_total() + $this->item_tax + $this->item_discount, |
|
300 | - 'meta' => $this->get_item_meta(), |
|
301 | - ); |
|
302 | - |
|
303 | - } |
|
84 | + * Get the item name. |
|
85 | + * |
|
86 | + * @since 1.0.19 |
|
87 | + * @param string $context View or edit context. |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function get_name( $context = 'view' ) { |
|
91 | + $name = parent::get_name( $context ); |
|
92 | + return $name . wpinv_get_item_suffix( $this ); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Get the item name without a suffix. |
|
97 | + * |
|
98 | + * @since 1.0.19 |
|
99 | + * @param string $context View or edit context. |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + public function get_raw_name( $context = 'view' ) { |
|
103 | + return parent::get_name( $context ); |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Get the item description. |
|
108 | + * |
|
109 | + * @since 1.0.19 |
|
110 | + * @param string $context View or edit context. |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function get_description( $context = 'view' ) { |
|
114 | + |
|
115 | + if ( isset( $this->custom_description ) ) { |
|
116 | + return $this->custom_description; |
|
117 | + } |
|
118 | + |
|
119 | + return parent::get_description( $context ); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Returns the sub total. |
|
124 | + * |
|
125 | + * @since 1.0.19 |
|
126 | + * @param string $context View or edit context. |
|
127 | + * @return int |
|
128 | + */ |
|
129 | + public function get_sub_total( $context = 'view' ) { |
|
130 | + return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Returns the recurring sub total. |
|
135 | + * |
|
136 | + * @since 1.0.19 |
|
137 | + * @param string $context View or edit context. |
|
138 | + * @return int |
|
139 | + */ |
|
140 | + public function get_recurring_sub_total( $context = 'view' ) { |
|
141 | + return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * @deprecated |
|
146 | + */ |
|
147 | + public function get_qantity( $context = 'view' ) { |
|
148 | + return $this->get_quantity( $context ); |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Get the item quantity. |
|
153 | + * |
|
154 | + * @since 1.0.19 |
|
155 | + * @param string $context View or edit context. |
|
156 | + * @return int |
|
157 | + */ |
|
158 | + public function get_quantity( $context = 'view' ) { |
|
159 | + $quantity = (int) $this->quantity; |
|
160 | + |
|
161 | + if ( empty( $quantity ) || 1 > $quantity ) { |
|
162 | + $quantity = 1; |
|
163 | + } |
|
164 | + |
|
165 | + if ( 'view' == $context ) { |
|
166 | + return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
167 | + } |
|
168 | + |
|
169 | + return $quantity; |
|
170 | + |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * Get the item meta data. |
|
175 | + * |
|
176 | + * @since 1.0.19 |
|
177 | + * @param string $context View or edit context. |
|
178 | + * @return meta |
|
179 | + */ |
|
180 | + public function get_item_meta( $context = 'view' ) { |
|
181 | + $meta = $this->meta; |
|
182 | + |
|
183 | + if ( 'view' == $context ) { |
|
184 | + return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
185 | + } |
|
186 | + |
|
187 | + return $meta; |
|
188 | + |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Returns whether or not customers can update the item quantity. |
|
193 | + * |
|
194 | + * @since 1.0.19 |
|
195 | + * @param string $context View or edit context. |
|
196 | + * @return bool |
|
197 | + */ |
|
198 | + public function get_allow_quantities( $context = 'view' ) { |
|
199 | + $allow_quantities = (bool) $this->allow_quantities; |
|
200 | + |
|
201 | + if ( 'view' == $context ) { |
|
202 | + return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
203 | + } |
|
204 | + |
|
205 | + return $allow_quantities; |
|
206 | + |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Returns whether or not the item is required. |
|
211 | + * |
|
212 | + * @since 1.0.19 |
|
213 | + * @param string $context View or edit context. |
|
214 | + * @return bool |
|
215 | + */ |
|
216 | + public function get_is_required( $context = 'view' ) { |
|
217 | + $is_required = (bool) $this->is_required; |
|
218 | + |
|
219 | + if ( 'view' == $context ) { |
|
220 | + return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
221 | + } |
|
222 | + |
|
223 | + return $is_required; |
|
224 | + |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * Prepares form data for use. |
|
229 | + * |
|
230 | + * @since 1.0.19 |
|
231 | + * @return array |
|
232 | + */ |
|
233 | + public function prepare_data_for_use() { |
|
234 | + |
|
235 | + return array( |
|
236 | + 'title' => sanitize_text_field( $this->get_name() ), |
|
237 | + 'id' => $this->get_id(), |
|
238 | + 'price' => $this->get_price(), |
|
239 | + 'recurring' => $this->is_recurring(), |
|
240 | + 'description' => $this->get_description(), |
|
241 | + 'allow_quantities' => $this->allows_quantities(), |
|
242 | + 'required' => $this->is_required(), |
|
243 | + ); |
|
244 | + |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * Prepares form data for ajax use. |
|
249 | + * |
|
250 | + * @since 1.0.19 |
|
251 | + * @return array |
|
252 | + */ |
|
253 | + public function prepare_data_for_invoice_edit_ajax( $currency = '' ) { |
|
254 | + |
|
255 | + $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
256 | + |
|
257 | + if ( $description ) { |
|
258 | + $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
|
259 | + } |
|
260 | + |
|
261 | + return array( |
|
262 | + 'id' => $this->get_id(), |
|
263 | + 'texts' => array( |
|
264 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
265 | + 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
266 | + 'item-quantity' => absint( $this->get_quantity() ), |
|
267 | + 'item-price' => wpinv_price( wpinv_format_amount ( $this->get_price() ), $currency ), |
|
268 | + 'item-total' => wpinv_price( wpinv_format_amount( $this->get_sub_total() ), $currency ), |
|
269 | + ), |
|
270 | + 'inputs' => array( |
|
271 | + 'item-id' => $this->get_id(), |
|
272 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
273 | + 'item-description' => wp_kses_post( $this->get_description() ), |
|
274 | + 'item-quantity' => absint( $this->get_quantity() ), |
|
275 | + 'item-price' => $this->get_price(), |
|
276 | + ) |
|
277 | + ); |
|
278 | + |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * Prepares form data for saving (cart_details). |
|
283 | + * |
|
284 | + * @since 1.0.19 |
|
285 | + * @return array |
|
286 | + */ |
|
287 | + public function prepare_data_for_saving() { |
|
288 | + |
|
289 | + return array( |
|
290 | + 'post_id' => $this->invoice_id, |
|
291 | + 'item_id' => $this->get_id(), |
|
292 | + 'item_name' => sanitize_text_field( $this->get_raw_name() ), |
|
293 | + 'item_description' => $this->get_description(), |
|
294 | + 'tax' => $this->item_tax, |
|
295 | + 'item_price' => $this->get_price(), |
|
296 | + 'quantity' => (int) $this->get_quantity(), |
|
297 | + 'discount' => $this->item_discount, |
|
298 | + 'subtotal' => $this->get_sub_total(), |
|
299 | + 'price' => $this->get_sub_total() + $this->item_tax + $this->item_discount, |
|
300 | + 'meta' => $this->get_item_meta(), |
|
301 | + ); |
|
302 | + |
|
303 | + } |
|
304 | 304 | |
305 | 305 | /* |
306 | 306 | |-------------------------------------------------------------------------- |
@@ -312,70 +312,70 @@ discard block |
||
312 | 312 | | object. |
313 | 313 | */ |
314 | 314 | |
315 | - /** |
|
316 | - * Set the item qantity. |
|
317 | - * |
|
318 | - * @since 1.0.19 |
|
319 | - * @param int $quantity The item quantity. |
|
320 | - */ |
|
321 | - public function set_quantity( $quantity ) { |
|
322 | - |
|
323 | - if ( empty( $quantity ) || ! is_numeric( $quantity ) ) { |
|
324 | - $quantity = 1; |
|
325 | - } |
|
326 | - |
|
327 | - $this->quantity = (int) $quantity; |
|
328 | - |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * Set the item meta data. |
|
333 | - * |
|
334 | - * @since 1.0.19 |
|
335 | - * @param array $meta The item meta data. |
|
336 | - */ |
|
337 | - public function set_item_meta( $meta ) { |
|
338 | - $this->meta = maybe_unserialize( $meta ); |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * Set whether or not the quantities are allowed. |
|
343 | - * |
|
344 | - * @since 1.0.19 |
|
345 | - * @param bool $allow_quantities |
|
346 | - */ |
|
347 | - public function set_allow_quantities( $allow_quantities ) { |
|
348 | - $this->allow_quantities = (bool) $allow_quantities; |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * Set whether or not the item is required. |
|
353 | - * |
|
354 | - * @since 1.0.19 |
|
355 | - * @param bool $is_required |
|
356 | - */ |
|
357 | - public function set_is_required( $is_required ) { |
|
358 | - $this->is_required = (bool) $is_required; |
|
359 | - } |
|
360 | - |
|
361 | - /** |
|
362 | - * Sets the custom item description. |
|
363 | - * |
|
364 | - * @since 1.0.19 |
|
365 | - * @param string $description |
|
366 | - */ |
|
367 | - public function set_custom_description( $description ) { |
|
368 | - $this->custom_description = $description; |
|
369 | - } |
|
315 | + /** |
|
316 | + * Set the item qantity. |
|
317 | + * |
|
318 | + * @since 1.0.19 |
|
319 | + * @param int $quantity The item quantity. |
|
320 | + */ |
|
321 | + public function set_quantity( $quantity ) { |
|
322 | + |
|
323 | + if ( empty( $quantity ) || ! is_numeric( $quantity ) ) { |
|
324 | + $quantity = 1; |
|
325 | + } |
|
326 | + |
|
327 | + $this->quantity = (int) $quantity; |
|
328 | + |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * Set the item meta data. |
|
333 | + * |
|
334 | + * @since 1.0.19 |
|
335 | + * @param array $meta The item meta data. |
|
336 | + */ |
|
337 | + public function set_item_meta( $meta ) { |
|
338 | + $this->meta = maybe_unserialize( $meta ); |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * Set whether or not the quantities are allowed. |
|
343 | + * |
|
344 | + * @since 1.0.19 |
|
345 | + * @param bool $allow_quantities |
|
346 | + */ |
|
347 | + public function set_allow_quantities( $allow_quantities ) { |
|
348 | + $this->allow_quantities = (bool) $allow_quantities; |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * Set whether or not the item is required. |
|
353 | + * |
|
354 | + * @since 1.0.19 |
|
355 | + * @param bool $is_required |
|
356 | + */ |
|
357 | + public function set_is_required( $is_required ) { |
|
358 | + $this->is_required = (bool) $is_required; |
|
359 | + } |
|
360 | + |
|
361 | + /** |
|
362 | + * Sets the custom item description. |
|
363 | + * |
|
364 | + * @since 1.0.19 |
|
365 | + * @param string $description |
|
366 | + */ |
|
367 | + public function set_custom_description( $description ) { |
|
368 | + $this->custom_description = $description; |
|
369 | + } |
|
370 | 370 | |
371 | 371 | /** |
372 | 372 | * We do not want to save items to the database. |
373 | 373 | * |
374 | - * @return int item id |
|
374 | + * @return int item id |
|
375 | 375 | */ |
376 | 376 | public function save( $data = array() ) { |
377 | 377 | return $this->get_id(); |
378 | - } |
|
378 | + } |
|
379 | 379 | |
380 | 380 | /* |
381 | 381 | |-------------------------------------------------------------------------- |
@@ -387,23 +387,23 @@ discard block |
||
387 | 387 | */ |
388 | 388 | |
389 | 389 | /** |
390 | - * Checks whether the item has enabled dynamic pricing. |
|
391 | - * |
|
392 | - * @since 1.0.19 |
|
393 | - * @return bool |
|
394 | - */ |
|
395 | - public function is_required() { |
|
390 | + * Checks whether the item has enabled dynamic pricing. |
|
391 | + * |
|
392 | + * @since 1.0.19 |
|
393 | + * @return bool |
|
394 | + */ |
|
395 | + public function is_required() { |
|
396 | 396 | return (bool) $this->get_is_required(); |
397 | - } |
|
398 | - |
|
399 | - /** |
|
400 | - * Checks whether users can edit the quantities. |
|
401 | - * |
|
402 | - * @since 1.0.19 |
|
403 | - * @return bool |
|
404 | - */ |
|
405 | - public function allows_quantities() { |
|
397 | + } |
|
398 | + |
|
399 | + /** |
|
400 | + * Checks whether users can edit the quantities. |
|
401 | + * |
|
402 | + * @since 1.0.19 |
|
403 | + * @return bool |
|
404 | + */ |
|
405 | + public function allows_quantities() { |
|
406 | 406 | return (bool) $this->get_allow_quantities(); |
407 | - } |
|
407 | + } |
|
408 | 408 | |
409 | 409 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | * @param string $context View or edit context. |
88 | 88 | * @return string |
89 | 89 | */ |
90 | - public function get_name( $context = 'view' ) { |
|
91 | - $name = parent::get_name( $context ); |
|
92 | - return $name . wpinv_get_item_suffix( $this ); |
|
90 | + public function get_name($context = 'view') { |
|
91 | + $name = parent::get_name($context); |
|
92 | + return $name . wpinv_get_item_suffix($this); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,8 +99,8 @@ discard block |
||
99 | 99 | * @param string $context View or edit context. |
100 | 100 | * @return string |
101 | 101 | */ |
102 | - public function get_raw_name( $context = 'view' ) { |
|
103 | - return parent::get_name( $context ); |
|
102 | + public function get_raw_name($context = 'view') { |
|
103 | + return parent::get_name($context); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -110,13 +110,13 @@ discard block |
||
110 | 110 | * @param string $context View or edit context. |
111 | 111 | * @return string |
112 | 112 | */ |
113 | - public function get_description( $context = 'view' ) { |
|
113 | + public function get_description($context = 'view') { |
|
114 | 114 | |
115 | - if ( isset( $this->custom_description ) ) { |
|
115 | + if (isset($this->custom_description)) { |
|
116 | 116 | return $this->custom_description; |
117 | 117 | } |
118 | 118 | |
119 | - return parent::get_description( $context ); |
|
119 | + return parent::get_description($context); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -126,8 +126,8 @@ discard block |
||
126 | 126 | * @param string $context View or edit context. |
127 | 127 | * @return int |
128 | 128 | */ |
129 | - public function get_sub_total( $context = 'view' ) { |
|
130 | - return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
129 | + public function get_sub_total($context = 'view') { |
|
130 | + return $this->get_quantity($context) * $this->get_initial_price($context); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -137,15 +137,15 @@ discard block |
||
137 | 137 | * @param string $context View or edit context. |
138 | 138 | * @return int |
139 | 139 | */ |
140 | - public function get_recurring_sub_total( $context = 'view' ) { |
|
141 | - return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
140 | + public function get_recurring_sub_total($context = 'view') { |
|
141 | + return $this->get_quantity($context) * $this->get_price($context); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
145 | 145 | * @deprecated |
146 | 146 | */ |
147 | - public function get_qantity( $context = 'view' ) { |
|
148 | - return $this->get_quantity( $context ); |
|
147 | + public function get_qantity($context = 'view') { |
|
148 | + return $this->get_quantity($context); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
@@ -155,15 +155,15 @@ discard block |
||
155 | 155 | * @param string $context View or edit context. |
156 | 156 | * @return int |
157 | 157 | */ |
158 | - public function get_quantity( $context = 'view' ) { |
|
158 | + public function get_quantity($context = 'view') { |
|
159 | 159 | $quantity = (int) $this->quantity; |
160 | 160 | |
161 | - if ( empty( $quantity ) || 1 > $quantity ) { |
|
161 | + if (empty($quantity) || 1 > $quantity) { |
|
162 | 162 | $quantity = 1; |
163 | 163 | } |
164 | 164 | |
165 | - if ( 'view' == $context ) { |
|
166 | - return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
165 | + if ('view' == $context) { |
|
166 | + return apply_filters('getpaid_payment_form_item_quantity', $quantity, $this); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | return $quantity; |
@@ -177,11 +177,11 @@ discard block |
||
177 | 177 | * @param string $context View or edit context. |
178 | 178 | * @return meta |
179 | 179 | */ |
180 | - public function get_item_meta( $context = 'view' ) { |
|
180 | + public function get_item_meta($context = 'view') { |
|
181 | 181 | $meta = $this->meta; |
182 | 182 | |
183 | - if ( 'view' == $context ) { |
|
184 | - return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
183 | + if ('view' == $context) { |
|
184 | + return apply_filters('getpaid_payment_form_item_meta', $meta, $this); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | return $meta; |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | * @param string $context View or edit context. |
196 | 196 | * @return bool |
197 | 197 | */ |
198 | - public function get_allow_quantities( $context = 'view' ) { |
|
198 | + public function get_allow_quantities($context = 'view') { |
|
199 | 199 | $allow_quantities = (bool) $this->allow_quantities; |
200 | 200 | |
201 | - if ( 'view' == $context ) { |
|
202 | - return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
201 | + if ('view' == $context) { |
|
202 | + return apply_filters('getpaid_payment_form_item_allow_quantities', $allow_quantities, $this); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | return $allow_quantities; |
@@ -213,11 +213,11 @@ discard block |
||
213 | 213 | * @param string $context View or edit context. |
214 | 214 | * @return bool |
215 | 215 | */ |
216 | - public function get_is_required( $context = 'view' ) { |
|
216 | + public function get_is_required($context = 'view') { |
|
217 | 217 | $is_required = (bool) $this->is_required; |
218 | 218 | |
219 | - if ( 'view' == $context ) { |
|
220 | - return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
219 | + if ('view' == $context) { |
|
220 | + return apply_filters('getpaid_payment_form_item_is_required', $is_required, $this); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | return $is_required; |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | public function prepare_data_for_use() { |
234 | 234 | |
235 | 235 | return array( |
236 | - 'title' => sanitize_text_field( $this->get_name() ), |
|
236 | + 'title' => sanitize_text_field($this->get_name()), |
|
237 | 237 | 'id' => $this->get_id(), |
238 | 238 | 'price' => $this->get_price(), |
239 | 239 | 'recurring' => $this->is_recurring(), |
@@ -250,28 +250,28 @@ discard block |
||
250 | 250 | * @since 1.0.19 |
251 | 251 | * @return array |
252 | 252 | */ |
253 | - public function prepare_data_for_invoice_edit_ajax( $currency = '' ) { |
|
253 | + public function prepare_data_for_invoice_edit_ajax($currency = '') { |
|
254 | 254 | |
255 | - $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
255 | + $description = getpaid_item_recurring_price_help_text($this, $currency); |
|
256 | 256 | |
257 | - if ( $description ) { |
|
257 | + if ($description) { |
|
258 | 258 | $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
259 | 259 | } |
260 | 260 | |
261 | 261 | return array( |
262 | 262 | 'id' => $this->get_id(), |
263 | 263 | 'texts' => array( |
264 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
265 | - 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
266 | - 'item-quantity' => absint( $this->get_quantity() ), |
|
267 | - 'item-price' => wpinv_price( wpinv_format_amount ( $this->get_price() ), $currency ), |
|
268 | - 'item-total' => wpinv_price( wpinv_format_amount( $this->get_sub_total() ), $currency ), |
|
264 | + 'item-name' => sanitize_text_field($this->get_name()), |
|
265 | + 'item-description' => wp_kses_post($this->get_description()) . $description, |
|
266 | + 'item-quantity' => absint($this->get_quantity()), |
|
267 | + 'item-price' => wpinv_price(wpinv_format_amount($this->get_price()), $currency), |
|
268 | + 'item-total' => wpinv_price(wpinv_format_amount($this->get_sub_total()), $currency), |
|
269 | 269 | ), |
270 | 270 | 'inputs' => array( |
271 | 271 | 'item-id' => $this->get_id(), |
272 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
273 | - 'item-description' => wp_kses_post( $this->get_description() ), |
|
274 | - 'item-quantity' => absint( $this->get_quantity() ), |
|
272 | + 'item-name' => sanitize_text_field($this->get_name()), |
|
273 | + 'item-description' => wp_kses_post($this->get_description()), |
|
274 | + 'item-quantity' => absint($this->get_quantity()), |
|
275 | 275 | 'item-price' => $this->get_price(), |
276 | 276 | ) |
277 | 277 | ); |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | return array( |
290 | 290 | 'post_id' => $this->invoice_id, |
291 | 291 | 'item_id' => $this->get_id(), |
292 | - 'item_name' => sanitize_text_field( $this->get_raw_name() ), |
|
292 | + 'item_name' => sanitize_text_field($this->get_raw_name()), |
|
293 | 293 | 'item_description' => $this->get_description(), |
294 | 294 | 'tax' => $this->item_tax, |
295 | 295 | 'item_price' => $this->get_price(), |
@@ -318,9 +318,9 @@ discard block |
||
318 | 318 | * @since 1.0.19 |
319 | 319 | * @param int $quantity The item quantity. |
320 | 320 | */ |
321 | - public function set_quantity( $quantity ) { |
|
321 | + public function set_quantity($quantity) { |
|
322 | 322 | |
323 | - if ( empty( $quantity ) || ! is_numeric( $quantity ) ) { |
|
323 | + if (empty($quantity) || !is_numeric($quantity)) { |
|
324 | 324 | $quantity = 1; |
325 | 325 | } |
326 | 326 | |
@@ -334,8 +334,8 @@ discard block |
||
334 | 334 | * @since 1.0.19 |
335 | 335 | * @param array $meta The item meta data. |
336 | 336 | */ |
337 | - public function set_item_meta( $meta ) { |
|
338 | - $this->meta = maybe_unserialize( $meta ); |
|
337 | + public function set_item_meta($meta) { |
|
338 | + $this->meta = maybe_unserialize($meta); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | * @since 1.0.19 |
345 | 345 | * @param bool $allow_quantities |
346 | 346 | */ |
347 | - public function set_allow_quantities( $allow_quantities ) { |
|
347 | + public function set_allow_quantities($allow_quantities) { |
|
348 | 348 | $this->allow_quantities = (bool) $allow_quantities; |
349 | 349 | } |
350 | 350 | |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | * @since 1.0.19 |
355 | 355 | * @param bool $is_required |
356 | 356 | */ |
357 | - public function set_is_required( $is_required ) { |
|
357 | + public function set_is_required($is_required) { |
|
358 | 358 | $this->is_required = (bool) $is_required; |
359 | 359 | } |
360 | 360 | |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | * @since 1.0.19 |
365 | 365 | * @param string $description |
366 | 366 | */ |
367 | - public function set_custom_description( $description ) { |
|
367 | + public function set_custom_description($description) { |
|
368 | 368 | $this->custom_description = $description; |
369 | 369 | } |
370 | 370 | |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | * |
374 | 374 | * @return int item id |
375 | 375 | */ |
376 | - public function save( $data = array() ) { |
|
376 | + public function save($data = array()) { |
|
377 | 377 | return $this->get_id(); |
378 | 378 | } |
379 | 379 |
@@ -1,23 +1,23 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -function wpinv_get_item_by_id( $id ) { |
|
6 | - return wpinv_get_item_by( 'id', $id ); |
|
5 | +function wpinv_get_item_by_id($id) { |
|
6 | + return wpinv_get_item_by('id', $id); |
|
7 | 7 | } |
8 | 8 | |
9 | -function wpinv_get_item_by( $field = '', $value = '', $type = '' ) { |
|
10 | - if( empty( $field ) || empty( $value ) ) { |
|
9 | +function wpinv_get_item_by($field = '', $value = '', $type = '') { |
|
10 | + if (empty($field) || empty($value)) { |
|
11 | 11 | return false; |
12 | 12 | } |
13 | 13 | |
14 | 14 | $posts = array(); |
15 | 15 | |
16 | - switch( strtolower( $field ) ) { |
|
16 | + switch (strtolower($field)) { |
|
17 | 17 | case 'id': |
18 | - $item = new WPInv_Item( $value ); |
|
18 | + $item = new WPInv_Item($value); |
|
19 | 19 | |
20 | - if ( !empty( $item ) && $item->post_type == 'wpi_item' ) { |
|
20 | + if (!empty($item) && $item->post_type == 'wpi_item') { |
|
21 | 21 | return $item; |
22 | 22 | } |
23 | 23 | return false; |
@@ -26,16 +26,16 @@ discard block |
||
26 | 26 | |
27 | 27 | case 'slug': |
28 | 28 | case 'name': |
29 | - $posts = get_posts( array( |
|
29 | + $posts = get_posts(array( |
|
30 | 30 | 'post_type' => 'wpi_item', |
31 | 31 | 'name' => $value, |
32 | 32 | 'posts_per_page' => 1, |
33 | 33 | 'post_status' => 'any' |
34 | - ) ); |
|
34 | + )); |
|
35 | 35 | |
36 | 36 | break; |
37 | 37 | case 'custom_id': |
38 | - if ( empty( $value ) || empty( $type ) ) { |
|
38 | + if (empty($value) || empty($type)) { |
|
39 | 39 | return false; |
40 | 40 | } |
41 | 41 | |
@@ -55,10 +55,10 @@ discard block |
||
55 | 55 | 'post_status' => 'any', |
56 | 56 | 'orderby' => 'ID', |
57 | 57 | 'order' => 'ASC', |
58 | - 'meta_query' => array( $meta_query ) |
|
58 | + 'meta_query' => array($meta_query) |
|
59 | 59 | ); |
60 | 60 | |
61 | - $posts = get_posts( $args ); |
|
61 | + $posts = get_posts($args); |
|
62 | 62 | |
63 | 63 | break; |
64 | 64 | |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | return false; |
67 | 67 | } |
68 | 68 | |
69 | - if ( !empty( $posts[0] ) ) { |
|
70 | - $item = new WPInv_Item( $posts[0]->ID ); |
|
69 | + if (!empty($posts[0])) { |
|
70 | + $item = new WPInv_Item($posts[0]->ID); |
|
71 | 71 | |
72 | - if ( !empty( $item ) && $item->post_type == 'wpi_item' ) { |
|
72 | + if (!empty($item) && $item->post_type == 'wpi_item') { |
|
73 | 73 | return $item; |
74 | 74 | } |
75 | 75 | } |
@@ -77,10 +77,10 @@ discard block |
||
77 | 77 | return false; |
78 | 78 | } |
79 | 79 | |
80 | -function wpinv_get_item( $item = 0 ) { |
|
81 | - if ( is_numeric( $item ) ) { |
|
82 | - $item = get_post( $item ); |
|
83 | - if ( ! $item || 'wpi_item' !== $item->post_type ) |
|
80 | +function wpinv_get_item($item = 0) { |
|
81 | + if (is_numeric($item)) { |
|
82 | + $item = get_post($item); |
|
83 | + if (!$item || 'wpi_item' !== $item->post_type) |
|
84 | 84 | return null; |
85 | 85 | return $item; |
86 | 86 | } |
@@ -93,18 +93,18 @@ discard block |
||
93 | 93 | |
94 | 94 | $item = get_posts($args); |
95 | 95 | |
96 | - if ( $item ) { |
|
96 | + if ($item) { |
|
97 | 97 | return $item[0]; |
98 | 98 | } |
99 | 99 | |
100 | 100 | return null; |
101 | 101 | } |
102 | 102 | |
103 | -function wpinv_get_all_items( $args = array() ) { |
|
103 | +function wpinv_get_all_items($args = array()) { |
|
104 | 104 | |
105 | - $args = wp_parse_args( $args, array( |
|
106 | - 'status' => array( 'publish' ), |
|
107 | - 'limit' => get_option( 'posts_per_page' ), |
|
105 | + $args = wp_parse_args($args, array( |
|
106 | + 'status' => array('publish'), |
|
107 | + 'limit' => get_option('posts_per_page'), |
|
108 | 108 | 'page' => 1, |
109 | 109 | 'exclude' => array(), |
110 | 110 | 'orderby' => 'date', |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | 'meta_query' => array(), |
114 | 114 | 'return' => 'objects', |
115 | 115 | 'paginate' => false, |
116 | - ) ); |
|
116 | + )); |
|
117 | 117 | |
118 | 118 | $wp_query_args = array( |
119 | 119 | 'post_type' => 'wpi_item', |
@@ -123,26 +123,26 @@ discard block |
||
123 | 123 | 'fields' => 'ids', |
124 | 124 | 'orderby' => $args['orderby'], |
125 | 125 | 'order' => $args['order'], |
126 | - 'paged' => absint( $args['page'] ), |
|
126 | + 'paged' => absint($args['page']), |
|
127 | 127 | ); |
128 | 128 | |
129 | - if ( ! empty( $args['exclude'] ) ) { |
|
130 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
129 | + if (!empty($args['exclude'])) { |
|
130 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
131 | 131 | } |
132 | 132 | |
133 | - if ( ! $args['paginate' ] ) { |
|
133 | + if (!$args['paginate']) { |
|
134 | 134 | $wp_query_args['no_found_rows'] = true; |
135 | 135 | } |
136 | 136 | |
137 | - if ( ! empty( $args['search'] ) ) { |
|
137 | + if (!empty($args['search'])) { |
|
138 | 138 | $wp_query_args['s'] = $args['search']; |
139 | 139 | } |
140 | 140 | |
141 | - if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) { |
|
142 | - $types = wpinv_parse_list( $args['type'] ); |
|
141 | + if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) { |
|
142 | + $types = wpinv_parse_list($args['type']); |
|
143 | 143 | $wp_query_args['meta_query'][] = array( |
144 | 144 | 'key' => '_wpinv_type', |
145 | - 'value' => implode( ',', $types ), |
|
145 | + 'value' => implode(',', $types), |
|
146 | 146 | 'compare' => 'IN', |
147 | 147 | ); |
148 | 148 | } |
@@ -150,17 +150,17 @@ discard block |
||
150 | 150 | $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args); |
151 | 151 | |
152 | 152 | // Get results. |
153 | - $items = new WP_Query( $wp_query_args ); |
|
153 | + $items = new WP_Query($wp_query_args); |
|
154 | 154 | |
155 | - if ( 'objects' === $args['return'] ) { |
|
156 | - $return = array_map( 'wpinv_get_item_by_id', $items->posts ); |
|
157 | - } elseif ( 'self' === $args['return'] ) { |
|
155 | + if ('objects' === $args['return']) { |
|
156 | + $return = array_map('wpinv_get_item_by_id', $items->posts); |
|
157 | + } elseif ('self' === $args['return']) { |
|
158 | 158 | return $items; |
159 | 159 | } else { |
160 | 160 | $return = $items->posts; |
161 | 161 | } |
162 | 162 | |
163 | - if ( $args['paginate' ] ) { |
|
163 | + if ($args['paginate']) { |
|
164 | 164 | return (object) array( |
165 | 165 | 'items' => $return, |
166 | 166 | 'total' => $items->found_posts, |
@@ -172,12 +172,12 @@ discard block |
||
172 | 172 | |
173 | 173 | } |
174 | 174 | |
175 | -function wpinv_is_free_item( $item_id = 0 ) { |
|
176 | - if( empty( $item_id ) ) { |
|
175 | +function wpinv_is_free_item($item_id = 0) { |
|
176 | + if (empty($item_id)) { |
|
177 | 177 | return false; |
178 | 178 | } |
179 | 179 | |
180 | - $item = new WPInv_Item( $item_id ); |
|
180 | + $item = new WPInv_Item($item_id); |
|
181 | 181 | |
182 | 182 | return $item->is_free(); |
183 | 183 | } |
@@ -187,128 +187,128 @@ discard block |
||
187 | 187 | * |
188 | 188 | * @param WP_Post|WPInv_Item|Int $item The item to check for. |
189 | 189 | */ |
190 | -function wpinv_item_is_editable( $item = 0 ) { |
|
190 | +function wpinv_item_is_editable($item = 0) { |
|
191 | 191 | |
192 | 192 | // Fetch the item. |
193 | - $item = new WPInv_Item( $item ); |
|
193 | + $item = new WPInv_Item($item); |
|
194 | 194 | |
195 | 195 | // Check if it is editable. |
196 | 196 | return $item->is_editable(); |
197 | 197 | } |
198 | 198 | |
199 | -function wpinv_get_item_price( $item_id = 0 ) { |
|
200 | - if( empty( $item_id ) ) { |
|
199 | +function wpinv_get_item_price($item_id = 0) { |
|
200 | + if (empty($item_id)) { |
|
201 | 201 | return false; |
202 | 202 | } |
203 | 203 | |
204 | - $item = new WPInv_Item( $item_id ); |
|
204 | + $item = new WPInv_Item($item_id); |
|
205 | 205 | |
206 | 206 | return $item->get_price(); |
207 | 207 | } |
208 | 208 | |
209 | -function wpinv_is_recurring_item( $item_id = 0 ) { |
|
210 | - if( empty( $item_id ) ) { |
|
209 | +function wpinv_is_recurring_item($item_id = 0) { |
|
210 | + if (empty($item_id)) { |
|
211 | 211 | return false; |
212 | 212 | } |
213 | 213 | |
214 | - $item = new WPInv_Item( $item_id ); |
|
214 | + $item = new WPInv_Item($item_id); |
|
215 | 215 | |
216 | 216 | return $item->is_recurring(); |
217 | 217 | } |
218 | 218 | |
219 | -function wpinv_item_price( $item_id = 0 ) { |
|
220 | - if( empty( $item_id ) ) { |
|
219 | +function wpinv_item_price($item_id = 0) { |
|
220 | + if (empty($item_id)) { |
|
221 | 221 | return false; |
222 | 222 | } |
223 | 223 | |
224 | - $price = wpinv_get_item_price( $item_id ); |
|
225 | - $price = wpinv_price( wpinv_format_amount( $price ) ); |
|
224 | + $price = wpinv_get_item_price($item_id); |
|
225 | + $price = wpinv_price(wpinv_format_amount($price)); |
|
226 | 226 | |
227 | - return apply_filters( 'wpinv_item_price', $price, $item_id ); |
|
227 | + return apply_filters('wpinv_item_price', $price, $item_id); |
|
228 | 228 | } |
229 | 229 | |
230 | -function wpinv_item_show_price( $item_id = 0, $echo = true ) { |
|
231 | - if ( empty( $item_id ) ) { |
|
230 | +function wpinv_item_show_price($item_id = 0, $echo = true) { |
|
231 | + if (empty($item_id)) { |
|
232 | 232 | $item_id = get_the_ID(); |
233 | 233 | } |
234 | 234 | |
235 | - $price = wpinv_item_price( $item_id ); |
|
235 | + $price = wpinv_item_price($item_id); |
|
236 | 236 | |
237 | - $price = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id ); |
|
237 | + $price = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id); |
|
238 | 238 | $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>'; |
239 | - $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price ); |
|
239 | + $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price); |
|
240 | 240 | |
241 | - if ( $echo ) { |
|
241 | + if ($echo) { |
|
242 | 242 | echo $formatted_price; |
243 | 243 | } else { |
244 | 244 | return $formatted_price; |
245 | 245 | } |
246 | 246 | } |
247 | 247 | |
248 | -function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) { |
|
249 | - if ( is_null( $amount_override ) ) { |
|
250 | - $original_price = get_post_meta( $item_id, '_wpinv_price', true ); |
|
248 | +function wpinv_get_item_final_price($item_id = 0, $amount_override = null) { |
|
249 | + if (is_null($amount_override)) { |
|
250 | + $original_price = get_post_meta($item_id, '_wpinv_price', true); |
|
251 | 251 | } else { |
252 | 252 | $original_price = $amount_override; |
253 | 253 | } |
254 | 254 | |
255 | 255 | $price = $original_price; |
256 | 256 | |
257 | - return apply_filters( 'wpinv_get_item_final_price', $price, $item_id ); |
|
257 | + return apply_filters('wpinv_get_item_final_price', $price, $item_id); |
|
258 | 258 | } |
259 | 259 | |
260 | -function wpinv_item_custom_singular_name( $item_id ) { |
|
261 | - if( empty( $item_id ) ) { |
|
260 | +function wpinv_item_custom_singular_name($item_id) { |
|
261 | + if (empty($item_id)) { |
|
262 | 262 | return false; |
263 | 263 | } |
264 | 264 | |
265 | - $item = new WPInv_Item( $item_id ); |
|
265 | + $item = new WPInv_Item($item_id); |
|
266 | 266 | |
267 | 267 | return $item->get_custom_singular_name(); |
268 | 268 | } |
269 | 269 | |
270 | 270 | function wpinv_get_item_types() { |
271 | 271 | $item_types = array( |
272 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
273 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
272 | + 'custom' => __('Standard', 'invoicing'), |
|
273 | + 'fee' => __('Fee', 'invoicing'), |
|
274 | 274 | ); |
275 | - return apply_filters( 'wpinv_get_item_types', $item_types ); |
|
275 | + return apply_filters('wpinv_get_item_types', $item_types); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | function wpinv_item_types() { |
279 | 279 | $item_types = wpinv_get_item_types(); |
280 | 280 | |
281 | - return ( !empty( $item_types ) ? array_keys( $item_types ) : array() ); |
|
281 | + return (!empty($item_types) ? array_keys($item_types) : array()); |
|
282 | 282 | } |
283 | 283 | |
284 | -function wpinv_get_item_type( $item_id ) { |
|
285 | - if( empty( $item_id ) ) { |
|
284 | +function wpinv_get_item_type($item_id) { |
|
285 | + if (empty($item_id)) { |
|
286 | 286 | return false; |
287 | 287 | } |
288 | 288 | |
289 | - $item = new WPInv_Item( $item_id ); |
|
289 | + $item = new WPInv_Item($item_id); |
|
290 | 290 | |
291 | 291 | return $item->get_type(); |
292 | 292 | } |
293 | 293 | |
294 | -function wpinv_item_type( $item_id ) { |
|
294 | +function wpinv_item_type($item_id) { |
|
295 | 295 | $item_types = wpinv_get_item_types(); |
296 | 296 | |
297 | - $item_type = wpinv_get_item_type( $item_id ); |
|
297 | + $item_type = wpinv_get_item_type($item_id); |
|
298 | 298 | |
299 | - if ( empty( $item_type ) ) { |
|
299 | + if (empty($item_type)) { |
|
300 | 300 | $item_type = '-'; |
301 | 301 | } |
302 | 302 | |
303 | - $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' ); |
|
303 | + $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing'); |
|
304 | 304 | |
305 | - return apply_filters( 'wpinv_item_type', $item_type, $item_id ); |
|
305 | + return apply_filters('wpinv_item_type', $item_type, $item_id); |
|
306 | 306 | } |
307 | 307 | |
308 | -function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) { |
|
308 | +function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) { |
|
309 | 309 | global $wpinv_logs; |
310 | 310 | |
311 | - if ( empty( $wpinv_logs ) ) { |
|
311 | + if (empty($wpinv_logs)) { |
|
312 | 312 | return false; |
313 | 313 | } |
314 | 314 | |
@@ -317,278 +317,278 @@ discard block |
||
317 | 317 | 'log_type' => 'wpi_item' |
318 | 318 | ); |
319 | 319 | |
320 | - $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1; |
|
320 | + $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1; |
|
321 | 321 | |
322 | 322 | $log_meta = array( |
323 | 323 | 'user_info' => $user_info, |
324 | 324 | 'user_id' => $user_id, |
325 | - 'file_id' => (int)$file_id, |
|
325 | + 'file_id' => (int) $file_id, |
|
326 | 326 | 'ip' => $ip, |
327 | 327 | 'invoice_id'=> $invoice_id, |
328 | 328 | ); |
329 | 329 | |
330 | - $wpinv_logs->insert_log( $log_data, $log_meta ); |
|
330 | + $wpinv_logs->insert_log($log_data, $log_meta); |
|
331 | 331 | } |
332 | 332 | |
333 | -function wpinv_remove_item_logs_on_delete( $item_id = 0 ) { |
|
334 | - if ( 'wpi_item' !== get_post_type( $item_id ) ) |
|
333 | +function wpinv_remove_item_logs_on_delete($item_id = 0) { |
|
334 | + if ('wpi_item' !== get_post_type($item_id)) |
|
335 | 335 | return; |
336 | 336 | |
337 | 337 | global $wpinv_logs; |
338 | 338 | |
339 | - if ( empty( $wpinv_logs ) ) { |
|
339 | + if (empty($wpinv_logs)) { |
|
340 | 340 | return false; |
341 | 341 | } |
342 | 342 | |
343 | 343 | // Remove all log entries related to this item |
344 | - $wpinv_logs->delete_logs( $item_id ); |
|
344 | + $wpinv_logs->delete_logs($item_id); |
|
345 | 345 | } |
346 | -add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' ); |
|
346 | +add_action('delete_post', 'wpinv_remove_item_logs_on_delete'); |
|
347 | 347 | |
348 | -function wpinv_get_random_item( $post_ids = true ) { |
|
349 | - wpinv_get_random_items( 1, $post_ids ); |
|
348 | +function wpinv_get_random_item($post_ids = true) { |
|
349 | + wpinv_get_random_items(1, $post_ids); |
|
350 | 350 | } |
351 | 351 | |
352 | -function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
|
353 | - if ( $post_ids ) { |
|
354 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' ); |
|
352 | +function wpinv_get_random_items($num = 3, $post_ids = true) { |
|
353 | + if ($post_ids) { |
|
354 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids'); |
|
355 | 355 | } else { |
356 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num ); |
|
356 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num); |
|
357 | 357 | } |
358 | 358 | |
359 | - $args = apply_filters( 'wpinv_get_random_items', $args ); |
|
359 | + $args = apply_filters('wpinv_get_random_items', $args); |
|
360 | 360 | |
361 | - return get_posts( $args ); |
|
361 | + return get_posts($args); |
|
362 | 362 | } |
363 | 363 | |
364 | -function wpinv_get_item_token( $url = '' ) { |
|
364 | +function wpinv_get_item_token($url = '') { |
|
365 | 365 | $args = array(); |
366 | - $hash = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' ); |
|
367 | - $secret = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) ); |
|
366 | + $hash = apply_filters('wpinv_get_url_token_algorithm', 'sha256'); |
|
367 | + $secret = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt())); |
|
368 | 368 | |
369 | - $parts = parse_url( $url ); |
|
369 | + $parts = parse_url($url); |
|
370 | 370 | $options = array(); |
371 | 371 | |
372 | - if ( isset( $parts['query'] ) ) { |
|
373 | - wp_parse_str( $parts['query'], $query_args ); |
|
372 | + if (isset($parts['query'])) { |
|
373 | + wp_parse_str($parts['query'], $query_args); |
|
374 | 374 | |
375 | - if ( ! empty( $query_args['o'] ) ) { |
|
376 | - $options = explode( ':', rawurldecode( $query_args['o'] ) ); |
|
375 | + if (!empty($query_args['o'])) { |
|
376 | + $options = explode(':', rawurldecode($query_args['o'])); |
|
377 | 377 | |
378 | - if ( in_array( 'ip', $options ) ) { |
|
378 | + if (in_array('ip', $options)) { |
|
379 | 379 | $args['ip'] = wpinv_get_ip(); |
380 | 380 | } |
381 | 381 | |
382 | - if ( in_array( 'ua', $options ) ) { |
|
382 | + if (in_array('ua', $options)) { |
|
383 | 383 | $ua = wpinv_get_user_agent(); |
384 | - $args['user_agent'] = rawurlencode( $ua ); |
|
384 | + $args['user_agent'] = rawurlencode($ua); |
|
385 | 385 | } |
386 | 386 | } |
387 | 387 | } |
388 | 388 | |
389 | - $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options ); |
|
389 | + $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options); |
|
390 | 390 | |
391 | 391 | $args['secret'] = $secret; |
392 | 392 | $args['token'] = false; |
393 | 393 | |
394 | - $url = add_query_arg( $args, $url ); |
|
395 | - $parts = parse_url( $url ); |
|
394 | + $url = add_query_arg($args, $url); |
|
395 | + $parts = parse_url($url); |
|
396 | 396 | |
397 | - if ( ! isset( $parts['path'] ) ) { |
|
397 | + if (!isset($parts['path'])) { |
|
398 | 398 | $parts['path'] = ''; |
399 | 399 | } |
400 | 400 | |
401 | - $token = md5( $parts['path'] . '?' . $parts['query'] ); |
|
401 | + $token = md5($parts['path'] . '?' . $parts['query']); |
|
402 | 402 | |
403 | 403 | return $token; |
404 | 404 | } |
405 | 405 | |
406 | -function wpinv_validate_url_token( $url = '' ) { |
|
406 | +function wpinv_validate_url_token($url = '') { |
|
407 | 407 | $ret = false; |
408 | - $parts = parse_url( $url ); |
|
408 | + $parts = parse_url($url); |
|
409 | 409 | |
410 | - if ( isset( $parts['query'] ) ) { |
|
411 | - wp_parse_str( $parts['query'], $query_args ); |
|
410 | + if (isset($parts['query'])) { |
|
411 | + wp_parse_str($parts['query'], $query_args); |
|
412 | 412 | |
413 | - $allowed = apply_filters( 'wpinv_url_token_allowed_params', array( |
|
413 | + $allowed = apply_filters('wpinv_url_token_allowed_params', array( |
|
414 | 414 | 'item', |
415 | 415 | 'ttl', |
416 | 416 | 'token' |
417 | - ) ); |
|
417 | + )); |
|
418 | 418 | |
419 | 419 | $remove = array(); |
420 | 420 | |
421 | - foreach( $query_args as $key => $value ) { |
|
422 | - if( false === in_array( $key, $allowed ) ) { |
|
421 | + foreach ($query_args as $key => $value) { |
|
422 | + if (false === in_array($key, $allowed)) { |
|
423 | 423 | $remove[] = $key; |
424 | 424 | } |
425 | 425 | } |
426 | 426 | |
427 | - if( ! empty( $remove ) ) { |
|
428 | - $url = remove_query_arg( $remove, $url ); |
|
427 | + if (!empty($remove)) { |
|
428 | + $url = remove_query_arg($remove, $url); |
|
429 | 429 | } |
430 | 430 | |
431 | - if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) { |
|
432 | - wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
431 | + if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) { |
|
432 | + wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403)); |
|
433 | 433 | } |
434 | 434 | |
435 | - if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) { |
|
435 | + if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) { |
|
436 | 436 | $ret = true; |
437 | 437 | } |
438 | 438 | |
439 | 439 | } |
440 | 440 | |
441 | - return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args ); |
|
441 | + return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args); |
|
442 | 442 | } |
443 | 443 | |
444 | -function wpinv_item_in_cart( $item_id = 0, $options = array() ) { |
|
444 | +function wpinv_item_in_cart($item_id = 0, $options = array()) { |
|
445 | 445 | $cart_items = wpinv_get_cart_contents(); |
446 | 446 | |
447 | 447 | $ret = false; |
448 | 448 | |
449 | - if ( is_array( $cart_items ) ) { |
|
450 | - foreach ( $cart_items as $item ) { |
|
451 | - if ( $item['id'] == $item_id ) { |
|
449 | + if (is_array($cart_items)) { |
|
450 | + foreach ($cart_items as $item) { |
|
451 | + if ($item['id'] == $item_id) { |
|
452 | 452 | $ret = true; |
453 | 453 | break; |
454 | 454 | } |
455 | 455 | } |
456 | 456 | } |
457 | 457 | |
458 | - return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options ); |
|
458 | + return (bool) apply_filters('wpinv_item_in_cart', $ret, $item_id, $options); |
|
459 | 459 | } |
460 | 460 | |
461 | -function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) { |
|
461 | +function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) { |
|
462 | 462 | $tax = 0; |
463 | - if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) { |
|
464 | - $country = !empty( $_POST['country'] ) ? $_POST['country'] : false; |
|
465 | - $state = isset( $_POST['state'] ) ? $_POST['state'] : ''; |
|
463 | + if (!wpinv_item_is_tax_exclusive($item_id)) { |
|
464 | + $country = !empty($_POST['country']) ? $_POST['country'] : false; |
|
465 | + $state = isset($_POST['state']) ? $_POST['state'] : ''; |
|
466 | 466 | |
467 | - $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id ); |
|
467 | + $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id); |
|
468 | 468 | } |
469 | 469 | |
470 | - return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options ); |
|
470 | + return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options); |
|
471 | 471 | } |
472 | 472 | |
473 | -function wpinv_cart_item_price( $item, $currency = '' ) { |
|
473 | +function wpinv_cart_item_price($item, $currency = '') { |
|
474 | 474 | |
475 | - if( empty( $currency ) ) { |
|
475 | + if (empty($currency)) { |
|
476 | 476 | $currency = wpinv_get_currency(); |
477 | 477 | } |
478 | 478 | |
479 | - $item_id = isset( $item['id'] ) ? $item['id'] : 0; |
|
480 | - $price = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0; |
|
481 | - $tax = wpinv_price( wpinv_format_amount( $item['tax'] ) ); |
|
479 | + $item_id = isset($item['id']) ? $item['id'] : 0; |
|
480 | + $price = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0; |
|
481 | + $tax = wpinv_price(wpinv_format_amount($item['tax'])); |
|
482 | 482 | |
483 | - if ( !wpinv_is_free_item( $item_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) { |
|
484 | - if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) { |
|
483 | + if (!wpinv_is_free_item($item_id) && !wpinv_item_is_tax_exclusive($item_id)) { |
|
484 | + if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) { |
|
485 | 485 | $price += $tax; |
486 | 486 | } |
487 | 487 | |
488 | - if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) { |
|
488 | + if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) { |
|
489 | 489 | $price -= $tax; |
490 | 490 | } |
491 | 491 | } |
492 | 492 | |
493 | - $price = wpinv_price( wpinv_format_amount( $price ), $currency ); |
|
493 | + $price = wpinv_price(wpinv_format_amount($price), $currency); |
|
494 | 494 | |
495 | - return apply_filters( 'wpinv_cart_item_price_label', $price, $item ); |
|
495 | + return apply_filters('wpinv_cart_item_price_label', $price, $item); |
|
496 | 496 | } |
497 | 497 | |
498 | -function wpinv_cart_item_subtotal( $item, $currency = '' ) { |
|
498 | +function wpinv_cart_item_subtotal($item, $currency = '') { |
|
499 | 499 | |
500 | - if( empty( $currency ) ) { |
|
500 | + if (empty($currency)) { |
|
501 | 501 | $currency = wpinv_get_currency(); |
502 | 502 | } |
503 | 503 | |
504 | - $subtotal = isset( $item['subtotal'] ) ? $item['subtotal'] : 0; |
|
505 | - $subtotal = wpinv_price( wpinv_format_amount( $subtotal ), $currency ); |
|
504 | + $subtotal = isset($item['subtotal']) ? $item['subtotal'] : 0; |
|
505 | + $subtotal = wpinv_price(wpinv_format_amount($subtotal), $currency); |
|
506 | 506 | |
507 | - return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item ); |
|
507 | + return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item); |
|
508 | 508 | } |
509 | 509 | |
510 | -function wpinv_cart_item_tax( $item, $currency = '' ) { |
|
510 | +function wpinv_cart_item_tax($item, $currency = '') { |
|
511 | 511 | $tax = ''; |
512 | 512 | $tax_rate = ''; |
513 | 513 | |
514 | - if( empty( $currency ) ) { |
|
514 | + if (empty($currency)) { |
|
515 | 515 | $currency = wpinv_get_currency(); |
516 | 516 | } |
517 | 517 | |
518 | - if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) { |
|
519 | - $tax = wpinv_price( wpinv_format_amount( $item['tax'] ), $currency ); |
|
520 | - $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100; |
|
521 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : ''; |
|
518 | + if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) { |
|
519 | + $tax = wpinv_price(wpinv_format_amount($item['tax']), $currency); |
|
520 | + $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100; |
|
521 | + $tax_rate = $tax_rate > 0 ? (float) wpinv_round_amount($tax_rate, 4) : ''; |
|
522 | 522 | $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : ''; |
523 | 523 | } |
524 | 524 | |
525 | - $tax = $tax . $tax_rate; |
|
525 | + $tax = $tax . $tax_rate; |
|
526 | 526 | |
527 | - if ( $tax === '' ) { |
|
527 | + if ($tax === '') { |
|
528 | 528 | $tax = 0; // Zero tax |
529 | 529 | } |
530 | 530 | |
531 | - return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item ); |
|
531 | + return apply_filters('wpinv_cart_item_tax_label', $tax, $item); |
|
532 | 532 | } |
533 | 533 | |
534 | -function wpinv_get_cart_item_price( $item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false ) { |
|
534 | +function wpinv_get_cart_item_price($item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false) { |
|
535 | 535 | $price = 0; |
536 | 536 | |
537 | 537 | // Set custom price |
538 | - if ( isset( $cart_item['custom_price'] ) && $cart_item['custom_price'] !== '' ) { |
|
538 | + if (isset($cart_item['custom_price']) && $cart_item['custom_price'] !== '') { |
|
539 | 539 | $price = $cart_item['custom_price']; |
540 | 540 | } else { |
541 | - $variable_prices = wpinv_has_variable_prices( $item_id ); |
|
541 | + $variable_prices = wpinv_has_variable_prices($item_id); |
|
542 | 542 | |
543 | - if ( $variable_prices ) { |
|
544 | - $prices = wpinv_get_variable_prices( $item_id ); |
|
543 | + if ($variable_prices) { |
|
544 | + $prices = wpinv_get_variable_prices($item_id); |
|
545 | 545 | |
546 | - if ( $prices ) { |
|
547 | - if( ! empty( $options ) ) { |
|
548 | - $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false; |
|
546 | + if ($prices) { |
|
547 | + if (!empty($options)) { |
|
548 | + $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false; |
|
549 | 549 | } else { |
550 | 550 | $price = false; |
551 | 551 | } |
552 | 552 | } |
553 | 553 | } |
554 | 554 | |
555 | - if( ! $variable_prices || false === $price ) { |
|
556 | - if($cart_item['item_price'] > 0){ |
|
555 | + if (!$variable_prices || false === $price) { |
|
556 | + if ($cart_item['item_price'] > 0) { |
|
557 | 557 | $price = $cart_item['item_price']; |
558 | 558 | } else { |
559 | 559 | // Get the standard Item price if not using variable prices |
560 | - $price = wpinv_get_item_price( $item_id ); |
|
560 | + $price = wpinv_get_item_price($item_id); |
|
561 | 561 | } |
562 | 562 | } |
563 | 563 | } |
564 | 564 | |
565 | - if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) { |
|
566 | - $price -= wpinv_get_cart_item_tax( $item_id, $price, $options ); |
|
565 | + if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) { |
|
566 | + $price -= wpinv_get_cart_item_tax($item_id, $price, $options); |
|
567 | 567 | } |
568 | 568 | |
569 | - return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive ); |
|
569 | + return apply_filters('wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive); |
|
570 | 570 | } |
571 | 571 | |
572 | -function wpinv_get_cart_item_price_id( $item = array() ) { |
|
573 | - if( isset( $item['item_number'] ) ) { |
|
574 | - $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null; |
|
572 | +function wpinv_get_cart_item_price_id($item = array()) { |
|
573 | + if (isset($item['item_number'])) { |
|
574 | + $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null; |
|
575 | 575 | } else { |
576 | - $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null; |
|
576 | + $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null; |
|
577 | 577 | } |
578 | 578 | return $price_id; |
579 | 579 | } |
580 | 580 | |
581 | -function wpinv_get_cart_item_price_name( $item = array() ) { |
|
582 | - $price_id = (int)wpinv_get_cart_item_price_id( $item ); |
|
583 | - $prices = wpinv_get_variable_prices( $item['id'] ); |
|
584 | - $name = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : ''; |
|
585 | - return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item ); |
|
581 | +function wpinv_get_cart_item_price_name($item = array()) { |
|
582 | + $price_id = (int) wpinv_get_cart_item_price_id($item); |
|
583 | + $prices = wpinv_get_variable_prices($item['id']); |
|
584 | + $name = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : ''; |
|
585 | + return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item); |
|
586 | 586 | } |
587 | 587 | |
588 | -function wpinv_get_cart_item_name( $item = array() ) { |
|
589 | - $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] ); |
|
588 | +function wpinv_get_cart_item_name($item = array()) { |
|
589 | + $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']); |
|
590 | 590 | |
591 | - if ( empty( $item_title ) ) { |
|
591 | + if (empty($item_title)) { |
|
592 | 592 | $item_title = $item['id']; |
593 | 593 | } |
594 | 594 | |
@@ -598,23 +598,23 @@ discard block |
||
598 | 598 | } |
599 | 599 | */ |
600 | 600 | |
601 | - return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item ); |
|
601 | + return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item); |
|
602 | 602 | } |
603 | 603 | |
604 | -function wpinv_has_variable_prices( $item_id = 0 ) { |
|
604 | +function wpinv_has_variable_prices($item_id = 0) { |
|
605 | 605 | return false; |
606 | 606 | } |
607 | 607 | |
608 | -function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) { |
|
608 | +function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) { |
|
609 | 609 | $cart_items = wpinv_get_cart_contents(); |
610 | 610 | |
611 | - if ( !is_array( $cart_items ) ) { |
|
611 | + if (!is_array($cart_items)) { |
|
612 | 612 | return false; // Empty cart |
613 | 613 | } else { |
614 | - foreach ( $cart_items as $position => $item ) { |
|
615 | - if ( $item['id'] == $item_id ) { |
|
616 | - if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) { |
|
617 | - if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) { |
|
614 | + foreach ($cart_items as $position => $item) { |
|
615 | + if ($item['id'] == $item_id) { |
|
616 | + if (isset($options['price_id']) && isset($item['options']['price_id'])) { |
|
617 | + if ((int) $options['price_id'] == (int) $item['options']['price_id']) { |
|
618 | 618 | return $position; |
619 | 619 | } |
620 | 620 | } else { |
@@ -627,80 +627,80 @@ discard block |
||
627 | 627 | return false; // Not found |
628 | 628 | } |
629 | 629 | |
630 | -function wpinv_get_cart_item_quantity( $item ) { |
|
631 | - if ( wpinv_item_quantities_enabled() ) { |
|
632 | - $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
630 | +function wpinv_get_cart_item_quantity($item) { |
|
631 | + if (wpinv_item_quantities_enabled()) { |
|
632 | + $quantity = !empty($item['quantity']) && (int) $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
633 | 633 | } else { |
634 | 634 | $quantity = 1; |
635 | 635 | } |
636 | 636 | |
637 | - if ( $quantity < 1 ) { |
|
637 | + if ($quantity < 1) { |
|
638 | 638 | $quantity = 1; |
639 | 639 | } |
640 | 640 | |
641 | - return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item ); |
|
641 | + return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item); |
|
642 | 642 | } |
643 | 643 | |
644 | -function wpinv_get_item_suffix( $item, $html = true ) { |
|
645 | - if ( empty( $item ) ) { |
|
644 | +function wpinv_get_item_suffix($item, $html = true) { |
|
645 | + if (empty($item)) { |
|
646 | 646 | return NULL; |
647 | 647 | } |
648 | 648 | |
649 | - if ( is_int( $item ) ) { |
|
650 | - $item = new WPInv_Item( $item ); |
|
649 | + if (is_int($item)) { |
|
650 | + $item = new WPInv_Item($item); |
|
651 | 651 | } |
652 | 652 | |
653 | - if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) { |
|
653 | + if (!(is_object($item) && is_a($item, 'WPInv_Item'))) { |
|
654 | 654 | return NULL; |
655 | 655 | } |
656 | 656 | |
657 | - $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : ''; |
|
657 | + $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : ''; |
|
658 | 658 | |
659 | - if ( !$html && $suffix ) { |
|
660 | - $suffix = strip_tags( $suffix ); |
|
659 | + if (!$html && $suffix) { |
|
660 | + $suffix = strip_tags($suffix); |
|
661 | 661 | } |
662 | 662 | |
663 | - return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html ); |
|
663 | + return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html); |
|
664 | 664 | } |
665 | 665 | |
666 | -function wpinv_remove_item( $item = 0, $force_delete = false ) { |
|
667 | - if ( empty( $item ) ) { |
|
666 | +function wpinv_remove_item($item = 0, $force_delete = false) { |
|
667 | + if (empty($item)) { |
|
668 | 668 | return NULL; |
669 | 669 | } |
670 | 670 | |
671 | - if ( is_int( $item ) ) { |
|
672 | - $item = new WPInv_Item( $item ); |
|
671 | + if (is_int($item)) { |
|
672 | + $item = new WPInv_Item($item); |
|
673 | 673 | } |
674 | 674 | |
675 | - if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) { |
|
675 | + if (!(is_object($item) && is_a($item, 'WPInv_Item'))) { |
|
676 | 676 | return NULL; |
677 | 677 | } |
678 | 678 | |
679 | - do_action( 'wpinv_pre_delete_item', $item ); |
|
679 | + do_action('wpinv_pre_delete_item', $item); |
|
680 | 680 | |
681 | - wp_delete_post( $item->ID, $force_delete ); |
|
681 | + wp_delete_post($item->ID, $force_delete); |
|
682 | 682 | |
683 | - do_action( 'wpinv_post_delete_item', $item ); |
|
683 | + do_action('wpinv_post_delete_item', $item); |
|
684 | 684 | } |
685 | 685 | |
686 | -function wpinv_can_delete_item( $post_id ) { |
|
686 | +function wpinv_can_delete_item($post_id) { |
|
687 | 687 | $return = wpinv_current_user_can_manage_invoicing() ? true : false; |
688 | 688 | |
689 | - if ( $return && wpinv_item_in_use( $post_id ) ) { |
|
689 | + if ($return && wpinv_item_in_use($post_id)) { |
|
690 | 690 | $return = false; // Don't delete item already use in invoices. |
691 | 691 | } |
692 | 692 | |
693 | - return apply_filters( 'wpinv_can_delete_item', $return, $post_id ); |
|
693 | + return apply_filters('wpinv_can_delete_item', $return, $post_id); |
|
694 | 694 | } |
695 | 695 | |
696 | 696 | function wpinv_admin_action_delete() { |
697 | 697 | $screen = get_current_screen(); |
698 | 698 | |
699 | - if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) { |
|
699 | + if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) { |
|
700 | 700 | $post_ids = array(); |
701 | 701 | |
702 | - foreach ( $_REQUEST['post'] as $post_id ) { |
|
703 | - if ( !wpinv_can_delete_item( $post_id ) ) { |
|
702 | + foreach ($_REQUEST['post'] as $post_id) { |
|
703 | + if (!wpinv_can_delete_item($post_id)) { |
|
704 | 704 | continue; |
705 | 705 | } |
706 | 706 | |
@@ -710,88 +710,88 @@ discard block |
||
710 | 710 | $_REQUEST['post'] = $post_ids; |
711 | 711 | } |
712 | 712 | } |
713 | -add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 ); |
|
714 | -add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 ); |
|
713 | +add_action('admin_action_trash', 'wpinv_admin_action_delete', -10); |
|
714 | +add_action('admin_action_delete', 'wpinv_admin_action_delete', -10); |
|
715 | 715 | |
716 | -function wpinv_check_delete_item( $check, $post, $force_delete ) { |
|
717 | - if ( $post->post_type == 'wpi_item' ) { |
|
718 | - if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) { |
|
716 | +function wpinv_check_delete_item($check, $post, $force_delete) { |
|
717 | + if ($post->post_type == 'wpi_item') { |
|
718 | + if ($force_delete && !wpinv_can_delete_item($post->ID)) { |
|
719 | 719 | return true; |
720 | 720 | } |
721 | 721 | } |
722 | 722 | |
723 | 723 | return $check; |
724 | 724 | } |
725 | -add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 ); |
|
725 | +add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3); |
|
726 | 726 | |
727 | -function wpinv_item_in_use( $item_id ) { |
|
727 | +function wpinv_item_in_use($item_id) { |
|
728 | 728 | global $wpdb, $wpi_items_in_use; |
729 | 729 | |
730 | - if ( !$item_id > 0 ) { |
|
730 | + if (!$item_id > 0) { |
|
731 | 731 | return false; |
732 | 732 | } |
733 | 733 | |
734 | - if ( !empty( $wpi_items_in_use ) ) { |
|
735 | - if ( isset( $wpi_items_in_use[$item_id] ) ) { |
|
734 | + if (!empty($wpi_items_in_use)) { |
|
735 | + if (isset($wpi_items_in_use[$item_id])) { |
|
736 | 736 | return $wpi_items_in_use[$item_id]; |
737 | 737 | } |
738 | 738 | } else { |
739 | 739 | $wpi_items_in_use = array(); |
740 | 740 | } |
741 | 741 | |
742 | - $statuses = array_keys( wpinv_get_invoice_statuses( true, true ) ); |
|
742 | + $statuses = array_keys(wpinv_get_invoice_statuses(true, true)); |
|
743 | 743 | |
744 | - $query = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )"; |
|
745 | - $in_use = $wpdb->get_var( $query ) > 0 ? true : false; |
|
744 | + $query = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int) $item_id . "', pm.meta_value )"; |
|
745 | + $in_use = $wpdb->get_var($query) > 0 ? true : false; |
|
746 | 746 | |
747 | 747 | $wpi_items_in_use[$item_id] = $in_use; |
748 | 748 | |
749 | 749 | return $in_use; |
750 | 750 | } |
751 | 751 | |
752 | -function wpinv_create_item( $args = array(), $wp_error = false, $force_update = false ) { |
|
752 | +function wpinv_create_item($args = array(), $wp_error = false, $force_update = false) { |
|
753 | 753 | // Set some defaults |
754 | 754 | $defaults = array( |
755 | - 'type' => 'custom', // Optional. Item type. Default 'custom'. |
|
756 | - 'title' => '', // Required. Item title. |
|
757 | - 'custom_id' => 0, // Optional. Any integer or non numeric id. Must be unique within item type. |
|
758 | - 'price' => '0.00', // Optional. Item price. Default '0.00'. |
|
759 | - 'status' => 'pending', // Optional. pending, publish |
|
760 | - 'custom_name' => '', // Optional. Plural sub title for item. |
|
761 | - 'custom_singular_name' => '', // Optional. Singular sub title for item. |
|
762 | - 'vat_rule' => 'digital', // Optional. digital => Digital item, physical => Physical item |
|
763 | - 'editable' => true, // Optional. Item editable from Items list page? Default true. |
|
764 | - 'excerpt' => '', // Optional. Item short description |
|
755 | + 'type' => 'custom', // Optional. Item type. Default 'custom'. |
|
756 | + 'title' => '', // Required. Item title. |
|
757 | + 'custom_id' => 0, // Optional. Any integer or non numeric id. Must be unique within item type. |
|
758 | + 'price' => '0.00', // Optional. Item price. Default '0.00'. |
|
759 | + 'status' => 'pending', // Optional. pending, publish |
|
760 | + 'custom_name' => '', // Optional. Plural sub title for item. |
|
761 | + 'custom_singular_name' => '', // Optional. Singular sub title for item. |
|
762 | + 'vat_rule' => 'digital', // Optional. digital => Digital item, physical => Physical item |
|
763 | + 'editable' => true, // Optional. Item editable from Items list page? Default true. |
|
764 | + 'excerpt' => '', // Optional. Item short description |
|
765 | 765 | /* Recurring item fields */ |
766 | - 'is_recurring' => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring |
|
767 | - 'recurring_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
768 | - 'recurring_interval' => 0, // Optional. Integer value between 1 - 90. |
|
769 | - 'recurring_limit' => 0, // Optional. Any integer number. 0 for recurring forever until cancelled. |
|
770 | - 'free_trial' => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial |
|
771 | - 'trial_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
772 | - 'trial_interval' => 0, // Optional. Any integer number. |
|
773 | - 'minimum_price' => '0.00', // Optional. Minimum allowed prices for items with dynamic pricing. |
|
774 | - 'dynamic_pricing' => 0, // Optional. Whether or not the item supports dynamic prices. |
|
766 | + 'is_recurring' => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring |
|
767 | + 'recurring_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
768 | + 'recurring_interval' => 0, // Optional. Integer value between 1 - 90. |
|
769 | + 'recurring_limit' => 0, // Optional. Any integer number. 0 for recurring forever until cancelled. |
|
770 | + 'free_trial' => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial |
|
771 | + 'trial_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
772 | + 'trial_interval' => 0, // Optional. Any integer number. |
|
773 | + 'minimum_price' => '0.00', // Optional. Minimum allowed prices for items with dynamic pricing. |
|
774 | + 'dynamic_pricing' => 0, // Optional. Whether or not the item supports dynamic prices. |
|
775 | 775 | ); |
776 | 776 | |
777 | - $data = wp_parse_args( $args, $defaults ); |
|
777 | + $data = wp_parse_args($args, $defaults); |
|
778 | 778 | |
779 | - if ( empty( $data['type'] ) ) { |
|
779 | + if (empty($data['type'])) { |
|
780 | 780 | $data['type'] = 'custom'; |
781 | 781 | } |
782 | 782 | |
783 | - if ( !empty( $data['custom_id'] ) ) { |
|
784 | - $item = wpinv_get_item_by( 'custom_id', $data['custom_id'], $data['type'] ); |
|
783 | + if (!empty($data['custom_id'])) { |
|
784 | + $item = wpinv_get_item_by('custom_id', $data['custom_id'], $data['type']); |
|
785 | 785 | } else { |
786 | 786 | $item = NULL; |
787 | 787 | } |
788 | 788 | |
789 | - if ( !empty( $item ) ) { |
|
790 | - if ( $force_update ) { |
|
791 | - if ( empty( $args['ID'] ) ) { |
|
789 | + if (!empty($item)) { |
|
790 | + if ($force_update) { |
|
791 | + if (empty($args['ID'])) { |
|
792 | 792 | $args['ID'] = $item->ID; |
793 | 793 | } |
794 | - return wpinv_update_item( $args, $wp_error ); |
|
794 | + return wpinv_update_item($args, $wp_error); |
|
795 | 795 | } |
796 | 796 | |
797 | 797 | return $item; |
@@ -802,21 +802,21 @@ discard block |
||
802 | 802 | $meta['custom_id'] = $data['custom_id']; |
803 | 803 | $meta['custom_singular_name'] = $data['custom_singular_name']; |
804 | 804 | $meta['custom_name'] = $data['custom_name']; |
805 | - $meta['price'] = wpinv_round_amount( $data['price'] ); |
|
806 | - $meta['editable'] = (int)$data['editable']; |
|
805 | + $meta['price'] = wpinv_round_amount($data['price']); |
|
806 | + $meta['editable'] = (int) $data['editable']; |
|
807 | 807 | $meta['vat_rule'] = $data['vat_rule']; |
808 | 808 | $meta['vat_class'] = '_standard'; |
809 | 809 | $meta['dynamic_pricing'] = (int) $data['dynamic_pricing']; |
810 | - $meta['minimum_price'] = wpinv_round_amount( $data['minimum_price'] ); |
|
810 | + $meta['minimum_price'] = wpinv_round_amount($data['minimum_price']); |
|
811 | 811 | |
812 | - if ( !empty( $data['is_recurring'] ) ) { |
|
812 | + if (!empty($data['is_recurring'])) { |
|
813 | 813 | $meta['is_recurring'] = $data['is_recurring']; |
814 | 814 | $meta['recurring_period'] = $data['recurring_period']; |
815 | - $meta['recurring_interval'] = absint( $data['recurring_interval'] ); |
|
816 | - $meta['recurring_limit'] = absint( $data['recurring_limit'] ); |
|
815 | + $meta['recurring_interval'] = absint($data['recurring_interval']); |
|
816 | + $meta['recurring_limit'] = absint($data['recurring_limit']); |
|
817 | 817 | $meta['free_trial'] = $data['free_trial']; |
818 | 818 | $meta['trial_period'] = $data['trial_period']; |
819 | - $meta['trial_interval'] = absint( $data['trial_interval'] ); |
|
819 | + $meta['trial_interval'] = absint($data['trial_interval']); |
|
820 | 820 | } else { |
821 | 821 | $meta['is_recurring'] = 0; |
822 | 822 | $meta['recurring_period'] = ''; |
@@ -827,7 +827,7 @@ discard block |
||
827 | 827 | $meta['trial_interval'] = ''; |
828 | 828 | } |
829 | 829 | |
830 | - $post_data = array( |
|
830 | + $post_data = array( |
|
831 | 831 | 'post_title' => $data['title'], |
832 | 832 | 'post_excerpt' => $data['excerpt'], |
833 | 833 | 'post_status' => $data['status'], |
@@ -835,34 +835,34 @@ discard block |
||
835 | 835 | ); |
836 | 836 | |
837 | 837 | $item = new WPInv_Item(); |
838 | - $return = $item->create( $post_data, $wp_error ); |
|
838 | + $return = $item->create($post_data, $wp_error); |
|
839 | 839 | |
840 | - if ( $return && !empty( $item ) && !is_wp_error( $return ) ) { |
|
840 | + if ($return && !empty($item) && !is_wp_error($return)) { |
|
841 | 841 | return $item; |
842 | 842 | } |
843 | 843 | |
844 | - if ( $wp_error && is_wp_error( $return ) ) { |
|
844 | + if ($wp_error && is_wp_error($return)) { |
|
845 | 845 | return $return; |
846 | 846 | } |
847 | 847 | return 0; |
848 | 848 | } |
849 | 849 | |
850 | -function wpinv_update_item( $args = array(), $wp_error = false ) { |
|
851 | - $item = !empty( $args['ID'] ) ? new WPInv_Item( $args['ID'] ) : NULL; |
|
850 | +function wpinv_update_item($args = array(), $wp_error = false) { |
|
851 | + $item = !empty($args['ID']) ? new WPInv_Item($args['ID']) : NULL; |
|
852 | 852 | |
853 | - if ( empty( $item ) || !( !empty( $item->post_type ) && $item->post_type == 'wpi_item' ) ) { |
|
854 | - if ( $wp_error ) { |
|
855 | - return new WP_Error( 'wpinv_invalid_item', __( 'Invalid item.', 'invoicing' ) ); |
|
853 | + if (empty($item) || !(!empty($item->post_type) && $item->post_type == 'wpi_item')) { |
|
854 | + if ($wp_error) { |
|
855 | + return new WP_Error('wpinv_invalid_item', __('Invalid item.', 'invoicing')); |
|
856 | 856 | } |
857 | 857 | return 0; |
858 | 858 | } |
859 | 859 | |
860 | - if ( !empty( $args['custom_id'] ) ) { |
|
861 | - $item_exists = wpinv_get_item_by( 'custom_id', $args['custom_id'], ( !empty( $args['type'] ) ? $args['type'] : $item->type ) ); |
|
860 | + if (!empty($args['custom_id'])) { |
|
861 | + $item_exists = wpinv_get_item_by('custom_id', $args['custom_id'], (!empty($args['type']) ? $args['type'] : $item->type)); |
|
862 | 862 | |
863 | - if ( !empty( $item_exists ) && $item_exists->ID != $args['ID'] ) { |
|
864 | - if ( $wp_error ) { |
|
865 | - return new WP_Error( 'wpinv_invalid_custom_id', __( 'Item with custom id already exists.', 'invoicing' ) ); |
|
863 | + if (!empty($item_exists) && $item_exists->ID != $args['ID']) { |
|
864 | + if ($wp_error) { |
|
865 | + return new WP_Error('wpinv_invalid_custom_id', __('Item with custom id already exists.', 'invoicing')); |
|
866 | 866 | } |
867 | 867 | return 0; |
868 | 868 | } |
@@ -889,54 +889,54 @@ discard block |
||
889 | 889 | ); |
890 | 890 | |
891 | 891 | $post_data = array(); |
892 | - if ( isset( $args['title'] ) ) { |
|
892 | + if (isset($args['title'])) { |
|
893 | 893 | $post_data['post_title'] = $args['title']; |
894 | 894 | } |
895 | - if ( isset( $args['excerpt'] ) ) { |
|
895 | + if (isset($args['excerpt'])) { |
|
896 | 896 | $post_data['post_excerpt'] = $args['excerpt']; |
897 | 897 | } |
898 | - if ( isset( $args['status'] ) ) { |
|
898 | + if (isset($args['status'])) { |
|
899 | 899 | $post_data['post_status'] = $args['status']; |
900 | 900 | } |
901 | 901 | |
902 | - foreach ( $meta_fields as $meta_field ) { |
|
903 | - if ( isset( $args[ $meta_field ] ) ) { |
|
904 | - $value = $args[ $meta_field ]; |
|
902 | + foreach ($meta_fields as $meta_field) { |
|
903 | + if (isset($args[$meta_field])) { |
|
904 | + $value = $args[$meta_field]; |
|
905 | 905 | |
906 | - switch ( $meta_field ) { |
|
906 | + switch ($meta_field) { |
|
907 | 907 | case 'price': |
908 | 908 | case 'minimum_price': |
909 | - $value = wpinv_round_amount( $value ); |
|
909 | + $value = wpinv_round_amount($value); |
|
910 | 910 | break; |
911 | 911 | case 'recurring_interval': |
912 | 912 | case 'recurring_limit': |
913 | 913 | case 'trial_interval': |
914 | - $value = absint( $value ); |
|
914 | + $value = absint($value); |
|
915 | 915 | break; |
916 | 916 | case 'editable': |
917 | 917 | $value = (int) $value; |
918 | 918 | break; |
919 | 919 | } |
920 | 920 | |
921 | - $post_data['meta'][ $meta_field ] = $value; |
|
921 | + $post_data['meta'][$meta_field] = $value; |
|
922 | 922 | }; |
923 | 923 | } |
924 | 924 | |
925 | - if ( empty( $post_data ) ) { |
|
926 | - if ( $wp_error ) { |
|
927 | - return new WP_Error( 'wpinv_invalid_item_data', __( 'Invalid item data.', 'invoicing' ) ); |
|
925 | + if (empty($post_data)) { |
|
926 | + if ($wp_error) { |
|
927 | + return new WP_Error('wpinv_invalid_item_data', __('Invalid item data.', 'invoicing')); |
|
928 | 928 | } |
929 | 929 | return 0; |
930 | 930 | } |
931 | 931 | $post_data['ID'] = $args['ID']; |
932 | 932 | |
933 | - $return = $item->update( $post_data, $wp_error ); |
|
933 | + $return = $item->update($post_data, $wp_error); |
|
934 | 934 | |
935 | - if ( $return && !empty( $item ) && !is_wp_error( $return ) ) { |
|
935 | + if ($return && !empty($item) && !is_wp_error($return)) { |
|
936 | 936 | return $item; |
937 | 937 | } |
938 | 938 | |
939 | - if ( $wp_error && is_wp_error( $return ) ) { |
|
939 | + if ($wp_error && is_wp_error($return)) { |
|
940 | 940 | return $return; |
941 | 941 | } |
942 | 942 | return 0; |
@@ -945,7 +945,7 @@ discard block |
||
945 | 945 | /** |
946 | 946 | * Sanitizes a recurring period |
947 | 947 | */ |
948 | -function getpaid_sanitize_recurring_period( $period, $full = false ) { |
|
948 | +function getpaid_sanitize_recurring_period($period, $full = false) { |
|
949 | 949 | |
950 | 950 | $periods = array( |
951 | 951 | 'D' => 'day', |
@@ -954,11 +954,11 @@ discard block |
||
954 | 954 | 'Y' => 'year', |
955 | 955 | ); |
956 | 956 | |
957 | - if ( ! isset( $periods[ $period ] ) ) { |
|
957 | + if (!isset($periods[$period])) { |
|
958 | 958 | $period = 'D'; |
959 | 959 | } |
960 | 960 | |
961 | - return $full ? $periods[ $period ] : $period; |
|
961 | + return $full ? $periods[$period] : $period; |
|
962 | 962 | |
963 | 963 | } |
964 | 964 | |
@@ -967,51 +967,51 @@ discard block |
||
967 | 967 | * |
968 | 968 | * @param WPInv_Item $item |
969 | 969 | */ |
970 | -function getpaid_item_recurring_price_help_text( $item, $currency = '' ) { |
|
970 | +function getpaid_item_recurring_price_help_text($item, $currency = '') { |
|
971 | 971 | |
972 | 972 | // Abort if it is not recurring. |
973 | - if ( ! $item->is_recurring() ) { |
|
973 | + if (!$item->is_recurring()) { |
|
974 | 974 | return ''; |
975 | 975 | } |
976 | 976 | |
977 | - $initial_price = wpinv_price( wpinv_sanitize_amount( $item->get_initial_price() ), $currency ); |
|
978 | - $recurring_price = wpinv_price( wpinv_sanitize_amount( $item->get_recurring_price() ), $currency ); |
|
979 | - $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->get_recurring_period(), $item->get_recurring_interval() ); |
|
980 | - $period = str_replace( '1 ', '', strtolower( $period ) ); |
|
977 | + $initial_price = wpinv_price(wpinv_sanitize_amount($item->get_initial_price()), $currency); |
|
978 | + $recurring_price = wpinv_price(wpinv_sanitize_amount($item->get_recurring_price()), $currency); |
|
979 | + $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($item->get_recurring_period(), $item->get_recurring_interval()); |
|
980 | + $period = str_replace('1 ', '', strtolower($period)); |
|
981 | 981 | |
982 | 982 | // For free trial items. |
983 | - if ( $item->has_free_trial() ) { |
|
984 | - $trial_period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->get_trial_period(), $item->get_trial_interval() ); |
|
983 | + if ($item->has_free_trial()) { |
|
984 | + $trial_period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($item->get_trial_period(), $item->get_trial_interval()); |
|
985 | 985 | |
986 | - if ( 0 == $item->get_initial_price() ) { |
|
986 | + if (0 == $item->get_initial_price()) { |
|
987 | 987 | return sprintf( |
988 | - __( 'Free for %s then %s every %s', 'invoicing' ), |
|
989 | - strtolower( $trial_period ), |
|
988 | + __('Free for %s then %s every %s', 'invoicing'), |
|
989 | + strtolower($trial_period), |
|
990 | 990 | $recurring_price, |
991 | 991 | $period |
992 | 992 | ); |
993 | 993 | } |
994 | 994 | |
995 | 995 | return sprintf( |
996 | - __( '%s for %s then %s every %s', 'invoicing' ), |
|
996 | + __('%s for %s then %s every %s', 'invoicing'), |
|
997 | 997 | $initial_price, |
998 | - strtolower( $trial_period ), |
|
998 | + strtolower($trial_period), |
|
999 | 999 | $recurring_price, |
1000 | 1000 | $period |
1001 | 1001 | ); |
1002 | 1002 | |
1003 | 1003 | } |
1004 | 1004 | |
1005 | - if ( $initial_price == $recurring_price ) { |
|
1005 | + if ($initial_price == $recurring_price) { |
|
1006 | 1006 | return sprintf( |
1007 | - __( '%s every %s', 'invoicing' ), |
|
1007 | + __('%s every %s', 'invoicing'), |
|
1008 | 1008 | $recurring_price, |
1009 | 1009 | $period |
1010 | 1010 | ); |
1011 | 1011 | } |
1012 | 1012 | |
1013 | 1013 | return sprintf( |
1014 | - __( '%s for %s then %s every %s', 'invoicing' ), |
|
1014 | + __('%s for %s then %s every %s', 'invoicing'), |
|
1015 | 1015 | $initial_price, |
1016 | 1016 | $period, |
1017 | 1017 | $recurring_price, |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * @deprecated |
@@ -19,48 +19,48 @@ discard block |
||
19 | 19 | * @deprecated |
20 | 20 | */ |
21 | 21 | function wpinv_get_invoice_cart() { |
22 | - return wpinv_get_invoice( getpaid_get_current_invoice_id() ); |
|
22 | + return wpinv_get_invoice(getpaid_get_current_invoice_id()); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
26 | 26 | * @deprecated |
27 | 27 | */ |
28 | -function wpinv_get_invoice_description( $invoice ) { |
|
29 | - $invoice = new WPInv_Invoice( $invoice ); |
|
28 | +function wpinv_get_invoice_description($invoice) { |
|
29 | + $invoice = new WPInv_Invoice($invoice); |
|
30 | 30 | return $invoice->get_description(); |
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | 34 | * @deprecated |
35 | 35 | */ |
36 | -function wpinv_get_invoice_currency_code( $invoice ) { |
|
37 | - $invoice = new WPInv_Invoice( $invoice ); |
|
36 | +function wpinv_get_invoice_currency_code($invoice) { |
|
37 | + $invoice = new WPInv_Invoice($invoice); |
|
38 | 38 | return $invoice->get_currency(); |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * @deprecated |
43 | 43 | */ |
44 | -function wpinv_get_payment_user_email( $invoice ) { |
|
45 | - $invoice = new WPInv_Invoice( $invoice ); |
|
44 | +function wpinv_get_payment_user_email($invoice) { |
|
45 | + $invoice = new WPInv_Invoice($invoice); |
|
46 | 46 | return $invoice->get_email(); |
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | 50 | * @deprecated |
51 | 51 | */ |
52 | -function wpinv_get_user_id( $invoice ) { |
|
53 | - $invoice = new WPInv_Invoice( $invoice ); |
|
52 | +function wpinv_get_user_id($invoice) { |
|
53 | + $invoice = new WPInv_Invoice($invoice); |
|
54 | 54 | return $invoice->get_user_id(); |
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | 58 | * @deprecated |
59 | 59 | */ |
60 | -function wpinv_get_invoice_status( $invoice, $return_label = false ) { |
|
61 | - $invoice = new WPInv_Invoice( $invoice ); |
|
60 | +function wpinv_get_invoice_status($invoice, $return_label = false) { |
|
61 | + $invoice = new WPInv_Invoice($invoice); |
|
62 | 62 | |
63 | - if ( $return_label ) { |
|
63 | + if ($return_label) { |
|
64 | 64 | return $invoice->get_status_nicename(); |
65 | 65 | } |
66 | 66 | |
@@ -70,10 +70,10 @@ discard block |
||
70 | 70 | /** |
71 | 71 | * @deprecated |
72 | 72 | */ |
73 | -function wpinv_get_payment_gateway( $invoice, $return_label = false ) { |
|
74 | - $invoice = new WPInv_Invoice( $invoice ); |
|
73 | +function wpinv_get_payment_gateway($invoice, $return_label = false) { |
|
74 | + $invoice = new WPInv_Invoice($invoice); |
|
75 | 75 | |
76 | - if ( $return_label ) { |
|
76 | + if ($return_label) { |
|
77 | 77 | return $invoice->get_gateway_title(); |
78 | 78 | } |
79 | 79 | |
@@ -83,75 +83,75 @@ discard block |
||
83 | 83 | /** |
84 | 84 | * @deprecated |
85 | 85 | */ |
86 | -function wpinv_get_payment_gateway_name( $invoice ) { |
|
87 | - return wpinv_get_payment_gateway( $invoice, true ); |
|
86 | +function wpinv_get_payment_gateway_name($invoice) { |
|
87 | + return wpinv_get_payment_gateway($invoice, true); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
91 | 91 | * @deprecated |
92 | 92 | */ |
93 | -function wpinv_get_payment_transaction_id( $invoice ) { |
|
94 | - $invoice = new WPInv_Invoice( $invoice ); |
|
93 | +function wpinv_get_payment_transaction_id($invoice) { |
|
94 | + $invoice = new WPInv_Invoice($invoice); |
|
95 | 95 | return $invoice->get_transaction_id(); |
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
99 | 99 | * @deprecated |
100 | 100 | */ |
101 | -function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
102 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
103 | - return $invoice->get_meta( $meta_key, $single ); |
|
101 | +function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) { |
|
102 | + $invoice = new WPInv_Invoice($invoice_id); |
|
103 | + return $invoice->get_meta($meta_key, $single); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
107 | 107 | * @deprecated |
108 | 108 | */ |
109 | -function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '' ) { |
|
110 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
111 | - return $invoice->update_meta_data( $meta_key, $meta_value ); |
|
109 | +function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '') { |
|
110 | + $invoice = new WPInv_Invoice($invoice_id); |
|
111 | + return $invoice->update_meta_data($meta_key, $meta_value); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
115 | 115 | * @deprecated |
116 | 116 | */ |
117 | -function wpinv_get_items( $invoice = 0 ) { |
|
118 | - $invoice = new WPInv_Invoice( $invoice ); |
|
117 | +function wpinv_get_items($invoice = 0) { |
|
118 | + $invoice = new WPInv_Invoice($invoice); |
|
119 | 119 | return $invoice->get_items(); |
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | 123 | * @deprecated |
124 | 124 | */ |
125 | -function wpinv_get_fees( $invoice = 0 ) { |
|
126 | - $invoice = new WPInv_Invoice( $invoice ); |
|
125 | +function wpinv_get_fees($invoice = 0) { |
|
126 | + $invoice = new WPInv_Invoice($invoice); |
|
127 | 127 | return $invoice->get_fees(); |
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
131 | 131 | * @deprecated |
132 | 132 | */ |
133 | -function wpinv_get_invoice_ip( $invoice ) { |
|
134 | - $invoice = new WPInv_Invoice( $invoice ); |
|
133 | +function wpinv_get_invoice_ip($invoice) { |
|
134 | + $invoice = new WPInv_Invoice($invoice); |
|
135 | 135 | return $invoice->get_ip(); |
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | 139 | * @deprecated |
140 | 140 | */ |
141 | -function wpinv_get_invoice_user_info( $invoice ) { |
|
142 | - $invoice = new WPInv_Invoice( $invoice ); |
|
141 | +function wpinv_get_invoice_user_info($invoice) { |
|
142 | + $invoice = new WPInv_Invoice($invoice); |
|
143 | 143 | return $invoice->get_user_info(); |
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
147 | 147 | * @deprecated |
148 | 148 | */ |
149 | -function wpinv_subtotal( $invoice = 0, $currency = false ) { |
|
150 | - $invoice = new WPInv_Invoice( $invoice ); |
|
149 | +function wpinv_subtotal($invoice = 0, $currency = false) { |
|
150 | + $invoice = new WPInv_Invoice($invoice); |
|
151 | 151 | $subtotal = $invoice->get_subtotal(); |
152 | 152 | |
153 | - if ( $currency ) { |
|
154 | - return wpinv_price( wpinv_format_amount( $subtotal ), $invoice->get_currency() ); |
|
153 | + if ($currency) { |
|
154 | + return wpinv_price(wpinv_format_amount($subtotal), $invoice->get_currency()); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | return $subtotal; |
@@ -160,12 +160,12 @@ discard block |
||
160 | 160 | /** |
161 | 161 | * @deprecated |
162 | 162 | */ |
163 | -function wpinv_tax( $invoice = 0, $currency = false ) { |
|
164 | - $invoice = new WPInv_Invoice( $invoice ); |
|
163 | +function wpinv_tax($invoice = 0, $currency = false) { |
|
164 | + $invoice = new WPInv_Invoice($invoice); |
|
165 | 165 | $tax = $invoice->get_total_tax(); |
166 | 166 | |
167 | - if ( $currency ) { |
|
168 | - return wpinv_price( wpinv_format_amount( $tax ), $invoice->get_currency() ); |
|
167 | + if ($currency) { |
|
168 | + return wpinv_price(wpinv_format_amount($tax), $invoice->get_currency()); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | return $tax; |
@@ -174,12 +174,12 @@ discard block |
||
174 | 174 | /** |
175 | 175 | * @deprecated |
176 | 176 | */ |
177 | -function wpinv_discount( $invoice = 0, $currency = false, $deprecated ) { |
|
178 | - $invoice = new WPInv_Invoice( $invoice ); |
|
177 | +function wpinv_discount($invoice = 0, $currency = false, $deprecated) { |
|
178 | + $invoice = new WPInv_Invoice($invoice); |
|
179 | 179 | $discount = $invoice->get_total_discount(); |
180 | 180 | |
181 | - if ( $currency ) { |
|
182 | - return wpinv_price( wpinv_format_amount( $discount ), $invoice->get_currency() ); |
|
181 | + if ($currency) { |
|
182 | + return wpinv_price(wpinv_format_amount($discount), $invoice->get_currency()); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | return $discount; |
@@ -188,20 +188,20 @@ discard block |
||
188 | 188 | /** |
189 | 189 | * @deprecated |
190 | 190 | */ |
191 | -function wpinv_discount_code( $invoice = 0 ) { |
|
192 | - $invoice = new WPInv_Invoice( $invoice ); |
|
191 | +function wpinv_discount_code($invoice = 0) { |
|
192 | + $invoice = new WPInv_Invoice($invoice); |
|
193 | 193 | return $invoice->get_discount_code(); |
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
197 | 197 | * @deprecated |
198 | 198 | */ |
199 | -function wpinv_payment_total( $invoice = 0, $currency = false ) { |
|
200 | - $invoice = new WPInv_Invoice( $invoice ); |
|
199 | +function wpinv_payment_total($invoice = 0, $currency = false) { |
|
200 | + $invoice = new WPInv_Invoice($invoice); |
|
201 | 201 | $total = $invoice->get_total(); |
202 | 202 | |
203 | - if ( $currency ) { |
|
204 | - return wpinv_price( wpinv_format_amount( $total ), $invoice->get_currency() ); |
|
203 | + if ($currency) { |
|
204 | + return wpinv_price(wpinv_format_amount($total), $invoice->get_currency()); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | return $total; |
@@ -210,51 +210,51 @@ discard block |
||
210 | 210 | /** |
211 | 211 | * @deprecated |
212 | 212 | */ |
213 | -function wpinv_get_date_created( $invoice = 0, $format = '' ) { |
|
214 | - $invoice = new WPInv_Invoice( $invoice ); |
|
213 | +function wpinv_get_date_created($invoice = 0, $format = '') { |
|
214 | + $invoice = new WPInv_Invoice($invoice); |
|
215 | 215 | |
216 | - $format = ! empty( $format ) ? $format : get_option( 'date_format' ); |
|
216 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
217 | 217 | $date_created = $invoice->get_created_date(); |
218 | 218 | |
219 | - return empty( $date_created ) ? date_i18n( $format, strtotime( $date_created ) ) : ''; |
|
219 | + return empty($date_created) ? date_i18n($format, strtotime($date_created)) : ''; |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
223 | 223 | * @deprecated |
224 | 224 | */ |
225 | -function wpinv_get_invoice_date( $invoice = 0, $format = '' ) { |
|
226 | - wpinv_get_date_created( $invoice, $format ); |
|
225 | +function wpinv_get_invoice_date($invoice = 0, $format = '') { |
|
226 | + wpinv_get_date_created($invoice, $format); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
230 | 230 | * @deprecated |
231 | 231 | */ |
232 | -function wpinv_get_invoice_vat_number( $invoice = 0 ) { |
|
233 | - $invoice = new WPInv_Invoice( $invoice ); |
|
232 | +function wpinv_get_invoice_vat_number($invoice = 0) { |
|
233 | + $invoice = new WPInv_Invoice($invoice); |
|
234 | 234 | return $invoice->get_vat_number(); |
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
238 | 238 | * @deprecated |
239 | 239 | */ |
240 | -function wpinv_insert_payment_note( $invoice = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) { |
|
241 | - $invoice = new WPInv_Invoice( $invoice ); |
|
242 | - return $invoice->add_note( $note, $user_type, $added_by_user, $system ); |
|
240 | +function wpinv_insert_payment_note($invoice = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) { |
|
241 | + $invoice = new WPInv_Invoice($invoice); |
|
242 | + return $invoice->add_note($note, $user_type, $added_by_user, $system); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
246 | 246 | * @deprecated |
247 | 247 | */ |
248 | -function wpinv_get_payment_key( $invoice = 0 ) { |
|
249 | - $invoice = new WPInv_Invoice( $invoice ); |
|
248 | +function wpinv_get_payment_key($invoice = 0) { |
|
249 | + $invoice = new WPInv_Invoice($invoice); |
|
250 | 250 | return $invoice->get_key(); |
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
254 | 254 | * @deprecated |
255 | 255 | */ |
256 | -function wpinv_get_invoice_number( $invoice = 0 ) { |
|
257 | - $invoice = new WPInv_Invoice( $invoice ); |
|
256 | +function wpinv_get_invoice_number($invoice = 0) { |
|
257 | + $invoice = new WPInv_Invoice($invoice); |
|
258 | 258 | return $invoice->get_number(); |
259 | 259 | } |
260 | 260 | |
@@ -401,9 +401,9 @@ discard block |
||
401 | 401 | /** |
402 | 402 | * @deprecated |
403 | 403 | */ |
404 | -function wpinv_update_payment_status( $invoice, $new_status = 'publish' ) { |
|
405 | - $invoice = new WPInv_Invoice( $invoice ); |
|
406 | - return $invoice->update_status( $new_status ); |
|
404 | +function wpinv_update_payment_status($invoice, $new_status = 'publish') { |
|
405 | + $invoice = new WPInv_Invoice($invoice); |
|
406 | + return $invoice->update_status($new_status); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
@@ -456,22 +456,22 @@ discard block |
||
456 | 456 | /** |
457 | 457 | * @deprecated |
458 | 458 | */ |
459 | -function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) { |
|
459 | +function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') { |
|
460 | 460 | |
461 | 461 | // Fetch the invoice. |
462 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
462 | + $invoice = new WPInv_Invoice($invoice_id); |
|
463 | 463 | |
464 | - if ( 0 == $invoice->get_id() ) { |
|
464 | + if (0 == $invoice->get_id()) { |
|
465 | 465 | return false; |
466 | 466 | } |
467 | 467 | |
468 | 468 | // Prepare the transaction id. |
469 | - if ( empty( $transaction_id ) ) { |
|
469 | + if (empty($transaction_id)) { |
|
470 | 470 | $transaction_id = $invoice_id; |
471 | 471 | } |
472 | 472 | |
473 | 473 | // Set the transaction id; |
474 | - $invoice->set_transaction_id( apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice ) ); |
|
474 | + $invoice->set_transaction_id(apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice)); |
|
475 | 475 | |
476 | 476 | // Save the invoice. |
477 | 477 | return $invoice->save(); |
@@ -480,6 +480,6 @@ discard block |
||
480 | 480 | /** |
481 | 481 | * @deprecated |
482 | 482 | */ |
483 | -function wpinv_send_to_gateway( $gateway, $payment_data ) { |
|
484 | - do_action( 'wpinv_gateway_' . $gateway, $payment_data ); |
|
483 | +function wpinv_send_to_gateway($gateway, $payment_data) { |
|
484 | + do_action('wpinv_gateway_' . $gateway, $payment_data); |
|
485 | 485 | } |
@@ -7,15 +7,15 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | |
15 | 15 | function wpinv_get_default_country() { |
16 | - $country = wpinv_get_option( 'default_country', 'UK' ); |
|
16 | + $country = wpinv_get_option('default_country', 'UK'); |
|
17 | 17 | |
18 | - return apply_filters( 'wpinv_default_country', $country ); |
|
18 | + return apply_filters('wpinv_default_country', $country); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -24,59 +24,59 @@ discard block |
||
24 | 24 | * @param string $country The country code to sanitize |
25 | 25 | * @return array |
26 | 26 | */ |
27 | -function wpinv_sanitize_country( $country ) { |
|
27 | +function wpinv_sanitize_country($country) { |
|
28 | 28 | |
29 | 29 | // Enure the country is specified |
30 | - if ( empty( $country ) ) { |
|
30 | + if (empty($country)) { |
|
31 | 31 | $country = wpinv_get_default_country(); |
32 | 32 | } |
33 | - return trim( wpinv_utf8_strtoupper( $country ) ); |
|
33 | + return trim(wpinv_utf8_strtoupper($country)); |
|
34 | 34 | |
35 | 35 | } |
36 | 36 | |
37 | -function wpinv_is_base_country( $country ) { |
|
37 | +function wpinv_is_base_country($country) { |
|
38 | 38 | $base_country = wpinv_get_default_country(); |
39 | 39 | |
40 | - if ( $base_country === 'UK' ) { |
|
40 | + if ($base_country === 'UK') { |
|
41 | 41 | $base_country = 'GB'; |
42 | 42 | } |
43 | - if ( $country == 'UK' ) { |
|
43 | + if ($country == 'UK') { |
|
44 | 44 | $country = 'GB'; |
45 | 45 | } |
46 | 46 | |
47 | - return ( $country && $country === $base_country ) ? true : false; |
|
47 | + return ($country && $country === $base_country) ? true : false; |
|
48 | 48 | } |
49 | 49 | |
50 | -function wpinv_country_name( $country_code = '' ) { |
|
50 | +function wpinv_country_name($country_code = '') { |
|
51 | 51 | $countries = wpinv_get_country_list(); |
52 | 52 | $country_code = $country_code == 'UK' ? 'GB' : $country_code; |
53 | - $country = isset( $countries[$country_code] ) ? $countries[$country_code] : $country_code; |
|
53 | + $country = isset($countries[$country_code]) ? $countries[$country_code] : $country_code; |
|
54 | 54 | |
55 | - return apply_filters( 'wpinv_country_name', $country, $country_code ); |
|
55 | + return apply_filters('wpinv_country_name', $country, $country_code); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | function wpinv_get_default_state() { |
59 | - $state = wpinv_get_option( 'default_state', false ); |
|
59 | + $state = wpinv_get_option('default_state', false); |
|
60 | 60 | |
61 | - return apply_filters( 'wpinv_default_state', $state ); |
|
61 | + return apply_filters('wpinv_default_state', $state); |
|
62 | 62 | } |
63 | 63 | |
64 | -function wpinv_state_name( $state_code = '', $country_code = '' ) { |
|
64 | +function wpinv_state_name($state_code = '', $country_code = '') { |
|
65 | 65 | $state = $state_code; |
66 | 66 | |
67 | - if ( !empty( $country_code ) ) { |
|
68 | - $states = wpinv_get_country_states( $country_code ); |
|
67 | + if (!empty($country_code)) { |
|
68 | + $states = wpinv_get_country_states($country_code); |
|
69 | 69 | |
70 | - $state = !empty( $states ) && isset( $states[$state_code] ) ? $states[$state_code] : $state; |
|
70 | + $state = !empty($states) && isset($states[$state_code]) ? $states[$state_code] : $state; |
|
71 | 71 | } |
72 | 72 | |
73 | - return apply_filters( 'wpinv_state_name', $state, $state_code, $country_code ); |
|
73 | + return apply_filters('wpinv_state_name', $state, $state_code, $country_code); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | function wpinv_store_address() { |
77 | - $address = wpinv_get_option( 'store_address', '' ); |
|
77 | + $address = wpinv_get_option('store_address', ''); |
|
78 | 78 | |
79 | - return apply_filters( 'wpinv_store_address', $address ); |
|
79 | + return apply_filters('wpinv_store_address', $address); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -86,13 +86,13 @@ discard block |
||
86 | 86 | * |
87 | 87 | * @param WPInv_Invoice $invoice |
88 | 88 | */ |
89 | -function getpaid_save_invoice_user_address( $invoice ) { |
|
89 | +function getpaid_save_invoice_user_address($invoice) { |
|
90 | 90 | |
91 | 91 | // Retrieve the invoice. |
92 | - $invoice = wpinv_get_invoice( $invoice ); |
|
92 | + $invoice = wpinv_get_invoice($invoice); |
|
93 | 93 | |
94 | 94 | // Abort if it does not exist. |
95 | - if ( empty( $invoice ) ) { |
|
95 | + if (empty($invoice)) { |
|
96 | 96 | return; |
97 | 97 | } |
98 | 98 | |
@@ -110,25 +110,25 @@ discard block |
||
110 | 110 | 'zip' |
111 | 111 | ); |
112 | 112 | |
113 | - foreach ( $address_fields as $field ) { |
|
113 | + foreach ($address_fields as $field) { |
|
114 | 114 | $method = "get_{$field}"; |
115 | 115 | $value = $invoice->$method(); |
116 | 116 | |
117 | 117 | // Only save if it is not empty. |
118 | - if ( ! empty( $value ) ) { |
|
119 | - update_user_meta( $invoice->get_user_id(), '_wpinv_' . $field, $value ); |
|
118 | + if (!empty($value)) { |
|
119 | + update_user_meta($invoice->get_user_id(), '_wpinv_' . $field, $value); |
|
120 | 120 | } |
121 | 121 | } |
122 | 122 | |
123 | 123 | } |
124 | -add_action( 'getpaid_new_invoice', 'getpaid_save_invoice_user_address' ); |
|
125 | -add_action( 'getpaid_update_invoice', 'getpaid_save_invoice_user_address' ); |
|
124 | +add_action('getpaid_new_invoice', 'getpaid_save_invoice_user_address'); |
|
125 | +add_action('getpaid_update_invoice', 'getpaid_save_invoice_user_address'); |
|
126 | 126 | |
127 | -function wpinv_get_user_address( $user_id = 0, $with_default = true ) { |
|
127 | +function wpinv_get_user_address($user_id = 0, $with_default = true) { |
|
128 | 128 | global $wpi_userID; |
129 | 129 | |
130 | - if( empty( $user_id ) ) { |
|
131 | - $user_id = !empty( $wpi_userID ) ? $wpi_userID : get_current_user_id(); |
|
130 | + if (empty($user_id)) { |
|
131 | + $user_id = !empty($wpi_userID) ? $wpi_userID : get_current_user_id(); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | $address_fields = array( |
@@ -145,29 +145,29 @@ discard block |
||
145 | 145 | 'phone', |
146 | 146 | ); |
147 | 147 | |
148 | - $user_info = get_userdata( $user_id ); |
|
148 | + $user_info = get_userdata($user_id); |
|
149 | 149 | |
150 | 150 | $address = array(); |
151 | 151 | $address['user_id'] = $user_id; |
152 | - $address['email'] = !empty( $user_info ) ? $user_info->user_email : ''; |
|
153 | - foreach ( $address_fields as $field ) { |
|
154 | - $address[$field] = get_user_meta( $user_id, '_wpinv_' . $field, true ); |
|
152 | + $address['email'] = !empty($user_info) ? $user_info->user_email : ''; |
|
153 | + foreach ($address_fields as $field) { |
|
154 | + $address[$field] = get_user_meta($user_id, '_wpinv_' . $field, true); |
|
155 | 155 | } |
156 | 156 | |
157 | - if ( !empty( $user_info ) ) { |
|
158 | - if( empty( $address['first_name'] ) ) |
|
157 | + if (!empty($user_info)) { |
|
158 | + if (empty($address['first_name'])) |
|
159 | 159 | $address['first_name'] = $user_info->first_name; |
160 | 160 | |
161 | - if( empty( $address['last_name'] ) ) |
|
161 | + if (empty($address['last_name'])) |
|
162 | 162 | $address['last_name'] = $user_info->last_name; |
163 | 163 | } |
164 | 164 | |
165 | - $address['name'] = trim( trim( $address['first_name'] . ' ' . $address['last_name'] ), "," ); |
|
165 | + $address['name'] = trim(trim($address['first_name'] . ' ' . $address['last_name']), ","); |
|
166 | 166 | |
167 | - if( empty( $address['state'] ) && $with_default ) |
|
167 | + if (empty($address['state']) && $with_default) |
|
168 | 168 | $address['state'] = wpinv_get_default_state(); |
169 | 169 | |
170 | - if( empty( $address['country'] ) && $with_default ) |
|
170 | + if (empty($address['country']) && $with_default) |
|
171 | 171 | $address['country'] = wpinv_get_default_country(); |
172 | 172 | |
173 | 173 | |
@@ -181,16 +181,16 @@ discard block |
||
181 | 181 | * @param string $return What to return. |
182 | 182 | * @return array |
183 | 183 | */ |
184 | -function wpinv_get_continents( $return = 'all' ) { |
|
184 | +function wpinv_get_continents($return = 'all') { |
|
185 | 185 | |
186 | - $continents = wpinv_get_data( 'continents' ); |
|
186 | + $continents = wpinv_get_data('continents'); |
|
187 | 187 | |
188 | - switch( $return ) { |
|
188 | + switch ($return) { |
|
189 | 189 | case 'name' : |
190 | - return wp_list_pluck( $continents, 'name' ); |
|
190 | + return wp_list_pluck($continents, 'name'); |
|
191 | 191 | break; |
192 | 192 | case 'countries' : |
193 | - return wp_list_pluck( $continents, 'countries' ); |
|
193 | + return wp_list_pluck($continents, 'countries'); |
|
194 | 194 | break; |
195 | 195 | default : |
196 | 196 | return $continents; |
@@ -206,12 +206,12 @@ discard block |
||
206 | 206 | * @param string $country Country code. If no code is specified, defaults to the default country. |
207 | 207 | * @return string |
208 | 208 | */ |
209 | -function wpinv_get_continent_code_for_country( $country = false ) { |
|
209 | +function wpinv_get_continent_code_for_country($country = false) { |
|
210 | 210 | |
211 | - $country = wpinv_sanitize_country( $country ); |
|
211 | + $country = wpinv_sanitize_country($country); |
|
212 | 212 | |
213 | - foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
214 | - if ( false !== array_search( $country, $countries, true ) ) { |
|
213 | + foreach (wpinv_get_continents('countries') as $continent_code => $countries) { |
|
214 | + if (false !== array_search($country, $countries, true)) { |
|
215 | 215 | return $continent_code; |
216 | 216 | } |
217 | 217 | } |
@@ -227,13 +227,13 @@ discard block |
||
227 | 227 | * @param string $country Country code. If no code is specified, defaults to the default country. |
228 | 228 | * @return array |
229 | 229 | */ |
230 | -function wpinv_get_country_calling_code( $country = null) { |
|
230 | +function wpinv_get_country_calling_code($country = null) { |
|
231 | 231 | |
232 | - $country = wpinv_sanitize_country( $country ); |
|
233 | - $codes = wpinv_get_data( 'phone-codes' ); |
|
234 | - $code = isset( $codes[ $country ] ) ? $codes[ $country ] : ''; |
|
232 | + $country = wpinv_sanitize_country($country); |
|
233 | + $codes = wpinv_get_data('phone-codes'); |
|
234 | + $code = isset($codes[$country]) ? $codes[$country] : ''; |
|
235 | 235 | |
236 | - if ( is_array( $code ) ) { |
|
236 | + if (is_array($code)) { |
|
237 | 237 | return $code[0]; |
238 | 238 | } |
239 | 239 | return $code; |
@@ -246,8 +246,8 @@ discard block |
||
246 | 246 | * @param bool $first_empty Whether or not the first item in the list should be empty |
247 | 247 | * @return array |
248 | 248 | */ |
249 | -function wpinv_get_country_list( $first_empty = false ) { |
|
250 | - return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty ); |
|
249 | +function wpinv_get_country_list($first_empty = false) { |
|
250 | + return wpinv_maybe_add_empty_option(apply_filters('wpinv_countries', wpinv_get_data('countries')), $first_empty); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -257,22 +257,22 @@ discard block |
||
257 | 257 | * @param bool $first_empty Whether or not the first item in the list should be empty |
258 | 258 | * @return array |
259 | 259 | */ |
260 | -function wpinv_get_country_states( $country = null, $first_empty = false ) { |
|
260 | +function wpinv_get_country_states($country = null, $first_empty = false) { |
|
261 | 261 | |
262 | 262 | // Prepare the country. |
263 | - $country = wpinv_sanitize_country( $country ); |
|
263 | + $country = wpinv_sanitize_country($country); |
|
264 | 264 | |
265 | 265 | // Fetch all states. |
266 | - $all_states = wpinv_get_data( 'states' ); |
|
266 | + $all_states = wpinv_get_data('states'); |
|
267 | 267 | |
268 | 268 | // Fetch the specified country's states. |
269 | - $states = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array() ; |
|
270 | - $states = apply_filters( "wpinv_{$country}_states", $states ); |
|
271 | - $states = apply_filters( 'wpinv_country_states', $states, $country ); |
|
269 | + $states = isset($all_states[$country]) ? $all_states[$country] : array(); |
|
270 | + $states = apply_filters("wpinv_{$country}_states", $states); |
|
271 | + $states = apply_filters('wpinv_country_states', $states, $country); |
|
272 | 272 | |
273 | - asort( $states ); |
|
273 | + asort($states); |
|
274 | 274 | |
275 | - return wpinv_maybe_add_empty_option( $states, $first_empty ); |
|
275 | + return wpinv_maybe_add_empty_option($states, $first_empty); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | * @return array |
283 | 283 | */ |
284 | 284 | function wpinv_get_us_states_list() { |
285 | - return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) ); |
|
285 | + return apply_filters('wpinv_usa_states', wpinv_get_country_states('US')); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | * @return array |
293 | 293 | */ |
294 | 294 | function wpinv_get_canada_states_list() { |
295 | - return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) ); |
|
295 | + return apply_filters('wpinv_canada_provinces', wpinv_get_country_states('CA')); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | /** |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | * @return array |
303 | 303 | */ |
304 | 304 | function wpinv_get_australia_states_list() { |
305 | - return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) ); |
|
305 | + return apply_filters('wpinv_australia_states', wpinv_get_country_states('AU')); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | * @return array |
313 | 313 | */ |
314 | 314 | function wpinv_get_bangladesh_states_list() { |
315 | - return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) ); |
|
315 | + return apply_filters('wpinv_bangladesh_states', wpinv_get_country_states('BD')); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | /** |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | * @return array |
323 | 323 | */ |
324 | 324 | function wpinv_get_brazil_states_list() { |
325 | - return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) ); |
|
325 | + return apply_filters('wpinv_brazil_states', wpinv_get_country_states('BR')); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | /** |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | * @return array |
333 | 333 | */ |
334 | 334 | function wpinv_get_bulgaria_states_list() { |
335 | - return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) ); |
|
335 | + return apply_filters('wpinv_bulgaria_states', wpinv_get_country_states('BG')); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | /** |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | * @return array |
343 | 343 | */ |
344 | 344 | function wpinv_get_hong_kong_states_list() { |
345 | - return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) ); |
|
345 | + return apply_filters('wpinv_hong_kong_states', wpinv_get_country_states('HK')); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | /** |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | * @return array |
353 | 353 | */ |
354 | 354 | function wpinv_get_hungary_states_list() { |
355 | - return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) ); |
|
355 | + return apply_filters('wpinv_hungary_states', wpinv_get_country_states('HU')); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | /** |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | * @return array |
363 | 363 | */ |
364 | 364 | function wpinv_get_japan_states_list() { |
365 | - return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) ); |
|
365 | + return apply_filters('wpinv_japan_states', wpinv_get_country_states('JP')); |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | /** |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | * @return array |
373 | 373 | */ |
374 | 374 | function wpinv_get_china_states_list() { |
375 | - return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) ); |
|
375 | + return apply_filters('wpinv_china_states', wpinv_get_country_states('CN')); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | /** |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | * @return array |
383 | 383 | */ |
384 | 384 | function wpinv_get_new_zealand_states_list() { |
385 | - return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) ); |
|
385 | + return apply_filters('wpinv_new_zealand_states', wpinv_get_country_states('NZ')); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | /** |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | * @return array |
393 | 393 | */ |
394 | 394 | function wpinv_get_peru_states_list() { |
395 | - return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) ); |
|
395 | + return apply_filters('wpinv_peru_states', wpinv_get_country_states('PE')); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | /** |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | * @return array |
403 | 403 | */ |
404 | 404 | function wpinv_get_indonesia_states_list() { |
405 | - return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) ); |
|
405 | + return apply_filters('wpinv_indonesia_states', wpinv_get_country_states('ID')); |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | /** |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | * @return array |
413 | 413 | */ |
414 | 414 | function wpinv_get_india_states_list() { |
415 | - return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) ); |
|
415 | + return apply_filters('wpinv_india_states', wpinv_get_country_states('IN')); |
|
416 | 416 | } |
417 | 417 | |
418 | 418 | /** |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | * @return array |
423 | 423 | */ |
424 | 424 | function wpinv_get_iran_states_list() { |
425 | - return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) ); |
|
425 | + return apply_filters('wpinv_iran_states', wpinv_get_country_states('IR')); |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | /** |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | * @return array |
433 | 433 | */ |
434 | 434 | function wpinv_get_italy_states_list() { |
435 | - return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) ); |
|
435 | + return apply_filters('wpinv_italy_states', wpinv_get_country_states('IT')); |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | /** |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | * @return array |
443 | 443 | */ |
444 | 444 | function wpinv_get_malaysia_states_list() { |
445 | - return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) ); |
|
445 | + return apply_filters('wpinv_malaysia_states', wpinv_get_country_states('MY')); |
|
446 | 446 | } |
447 | 447 | |
448 | 448 | /** |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | * @return array |
453 | 453 | */ |
454 | 454 | function wpinv_get_mexico_states_list() { |
455 | - return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) ); |
|
455 | + return apply_filters('wpinv_mexico_states', wpinv_get_country_states('MX')); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | /** |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | * @return array |
463 | 463 | */ |
464 | 464 | function wpinv_get_nepal_states_list() { |
465 | - return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) ); |
|
465 | + return apply_filters('wpinv_nepal_states', wpinv_get_country_states('NP')); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | /** |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | * @return array |
473 | 473 | */ |
474 | 474 | function wpinv_get_south_africa_states_list() { |
475 | - return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) ); |
|
475 | + return apply_filters('wpinv_south_africa_states', wpinv_get_country_states('ZA')); |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | /** |
@@ -482,7 +482,7 @@ discard block |
||
482 | 482 | * @return array |
483 | 483 | */ |
484 | 484 | function wpinv_get_thailand_states_list() { |
485 | - return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) ); |
|
485 | + return apply_filters('wpinv_thailand_states', wpinv_get_country_states('TH')); |
|
486 | 486 | } |
487 | 487 | |
488 | 488 | /** |
@@ -492,7 +492,7 @@ discard block |
||
492 | 492 | * @return array |
493 | 493 | */ |
494 | 494 | function wpinv_get_turkey_states_list() { |
495 | - return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) ); |
|
495 | + return apply_filters('wpinv_turkey_states', wpinv_get_country_states('TR')); |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | /** |
@@ -502,28 +502,28 @@ discard block |
||
502 | 502 | * @return array |
503 | 503 | */ |
504 | 504 | function wpinv_get_spain_states_list() { |
505 | - return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) ); |
|
505 | + return apply_filters('wpinv_spain_states', wpinv_get_country_states('ES')); |
|
506 | 506 | } |
507 | 507 | |
508 | 508 | function wpinv_get_states_field() { |
509 | - if( empty( $_POST['country'] ) ) { |
|
509 | + if (empty($_POST['country'])) { |
|
510 | 510 | $_POST['country'] = wpinv_get_default_country(); |
511 | 511 | } |
512 | - $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
512 | + $states = wpinv_get_country_states(sanitize_text_field($_POST['country'])); |
|
513 | 513 | |
514 | - if( !empty( $states ) ) { |
|
515 | - $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
514 | + if (!empty($states)) { |
|
515 | + $sanitized_field_name = sanitize_text_field($_POST['field_name']); |
|
516 | 516 | |
517 | 517 | $args = array( |
518 | 518 | 'name' => $sanitized_field_name, |
519 | 519 | 'id' => $sanitized_field_name, |
520 | 520 | 'class' => $sanitized_field_name . 'custom-select wpinv-select wpi_select2', |
521 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
521 | + 'options' => array_merge(array('' => ''), $states), |
|
522 | 522 | 'show_option_all' => false, |
523 | 523 | 'show_option_none' => false |
524 | 524 | ); |
525 | 525 | |
526 | - $response = wpinv_html_select( $args ); |
|
526 | + $response = wpinv_html_select($args); |
|
527 | 527 | |
528 | 528 | } else { |
529 | 529 | $response = 'nostates'; |
@@ -532,10 +532,10 @@ discard block |
||
532 | 532 | return $response; |
533 | 533 | } |
534 | 534 | |
535 | -function wpinv_default_billing_country( $country = '', $user_id = 0 ) { |
|
536 | - $country = !empty( $country ) ? $country : wpinv_get_default_country(); |
|
535 | +function wpinv_default_billing_country($country = '', $user_id = 0) { |
|
536 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
537 | 537 | |
538 | - return apply_filters( 'wpinv_default_billing_country', $country, $user_id ); |
|
538 | + return apply_filters('wpinv_default_billing_country', $country, $user_id); |
|
539 | 539 | } |
540 | 540 | |
541 | 541 | /** |
@@ -547,7 +547,7 @@ discard block |
||
547 | 547 | */ |
548 | 548 | function wpinv_get_address_formats() { |
549 | 549 | |
550 | - return apply_filters( 'wpinv_localisation_address_formats', |
|
550 | + return apply_filters('wpinv_localisation_address_formats', |
|
551 | 551 | array( |
552 | 552 | 'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}", |
553 | 553 | 'AU' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}", |
@@ -596,9 +596,9 @@ discard block |
||
596 | 596 | * @see `wpinv_get_invoice_address_replacements` |
597 | 597 | * @return string |
598 | 598 | */ |
599 | -function wpinv_get_full_address_format( $country = false) { |
|
599 | +function wpinv_get_full_address_format($country = false) { |
|
600 | 600 | |
601 | - if( empty( $country ) ) { |
|
601 | + if (empty($country)) { |
|
602 | 602 | $country = wpinv_get_default_country(); |
603 | 603 | } |
604 | 604 | |
@@ -606,7 +606,7 @@ discard block |
||
606 | 606 | $formats = wpinv_get_address_formats(); |
607 | 607 | |
608 | 608 | // Get format for the specified country. |
609 | - $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
609 | + $format = ($country && isset($formats[$country])) ? $formats[$country] : $formats['default']; |
|
610 | 610 | |
611 | 611 | /** |
612 | 612 | * Filters the address format to use on Invoices. |
@@ -618,7 +618,7 @@ discard block |
||
618 | 618 | * @param string $format The address format to use. |
619 | 619 | * @param string $country The country who's address format is being retrieved. |
620 | 620 | */ |
621 | - return apply_filters( 'wpinv_get_full_address_format', $format, $country ); |
|
621 | + return apply_filters('wpinv_get_full_address_format', $format, $country); |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | /** |
@@ -629,7 +629,7 @@ discard block |
||
629 | 629 | * @param array $billing_details customer's billing details |
630 | 630 | * @return array |
631 | 631 | */ |
632 | -function wpinv_get_invoice_address_replacements( $billing_details ) { |
|
632 | +function wpinv_get_invoice_address_replacements($billing_details) { |
|
633 | 633 | |
634 | 634 | $default_args = array( |
635 | 635 | 'address' => '', |
@@ -642,22 +642,22 @@ discard block |
||
642 | 642 | 'company' => '', |
643 | 643 | ); |
644 | 644 | |
645 | - $args = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' ); |
|
645 | + $args = map_deep(wp_parse_args($billing_details, $default_args), 'trim'); |
|
646 | 646 | $state = $args['state']; |
647 | 647 | $country = $args['country']; |
648 | 648 | |
649 | 649 | // Handle full country name. |
650 | - $full_country = empty( $country ) ? $country : wpinv_country_name( $country ); |
|
650 | + $full_country = empty($country) ? $country : wpinv_country_name($country); |
|
651 | 651 | |
652 | 652 | // Handle full state name. |
653 | - $full_state = ( $country && $state ) ? wpinv_state_name( $state, $country ) : $state; |
|
653 | + $full_state = ($country && $state) ? wpinv_state_name($state, $country) : $state; |
|
654 | 654 | |
655 | 655 | $args['postcode'] = $args['zip']; |
656 | 656 | $args['name'] = $args['first_name'] . ' ' . $args['last_name']; |
657 | 657 | $args['state'] = $full_state; |
658 | 658 | $args['state_code'] = $state; |
659 | 659 | $args['country'] = $full_country; |
660 | - $args['country_code']= $country; |
|
660 | + $args['country_code'] = $country; |
|
661 | 661 | |
662 | 662 | /** |
663 | 663 | * Filters the address format replacements to use on Invoices. |
@@ -668,14 +668,14 @@ discard block |
||
668 | 668 | * @param array $replacements The address replacements to use. |
669 | 669 | * @param array $billing_details The billing details to use. |
670 | 670 | */ |
671 | - $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details ); |
|
671 | + $replacements = apply_filters('wpinv_get_invoice_address_replacements', $args, $billing_details); |
|
672 | 672 | |
673 | 673 | $return = array(); |
674 | 674 | |
675 | - foreach( $replacements as $key => $value ) { |
|
676 | - $value = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : ''; |
|
675 | + foreach ($replacements as $key => $value) { |
|
676 | + $value = is_scalar($value) ? trim(sanitize_text_field($value)) : ''; |
|
677 | 677 | $return['{{' . $key . '}}'] = $value; |
678 | - $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper( $value ); |
|
678 | + $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper($value); |
|
679 | 679 | } |
680 | 680 | |
681 | 681 | return $return; |
@@ -689,6 +689,6 @@ discard block |
||
689 | 689 | * @since 1.0.14 |
690 | 690 | * @return string |
691 | 691 | */ |
692 | -function wpinv_trim_formatted_address_line( $line ) { |
|
693 | - return trim( $line, ', ' ); |
|
692 | +function wpinv_trim_formatted_address_line($line) { |
|
693 | + return trim($line, ', '); |
|
694 | 694 | } |
695 | 695 | \ No newline at end of file |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * WPInv_Ajax class. |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | * Hook in ajax handlers. |
18 | 18 | */ |
19 | 19 | public static function init() { |
20 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
20 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
21 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
22 | 22 | self::add_ajax_events(); |
23 | 23 | } |
24 | 24 | |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public static function define_ajax() { |
29 | 29 | |
30 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | - getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | - getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
30 | + if (!empty($_GET['wpinv-ajax'])) { |
|
31 | + getpaid_maybe_define_constant('DOING_AJAX', true); |
|
32 | + getpaid_maybe_define_constant('WPInv_DOING_AJAX', true); |
|
33 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
34 | + /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0); |
|
35 | 35 | } |
36 | 36 | $GLOBALS['wpdb']->hide_errors(); |
37 | 37 | } |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | * @since 1.0.18 |
45 | 45 | */ |
46 | 46 | private static function wpinv_ajax_headers() { |
47 | - if ( ! headers_sent() ) { |
|
47 | + if (!headers_sent()) { |
|
48 | 48 | send_origin_headers(); |
49 | 49 | send_nosniff_header(); |
50 | 50 | nocache_headers(); |
51 | - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | - header( 'X-Robots-Tag: noindex' ); |
|
53 | - status_header( 200 ); |
|
51 | + header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
52 | + header('X-Robots-Tag: noindex'); |
|
53 | + status_header(200); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
@@ -60,16 +60,16 @@ discard block |
||
60 | 60 | public static function do_wpinv_ajax() { |
61 | 61 | global $wp_query; |
62 | 62 | |
63 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
63 | + if (!empty($_GET['wpinv-ajax'])) { |
|
64 | + $wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax']))); |
|
65 | 65 | } |
66 | 66 | |
67 | - $action = $wp_query->get( 'wpinv-ajax' ); |
|
67 | + $action = $wp_query->get('wpinv-ajax'); |
|
68 | 68 | |
69 | - if ( $action ) { |
|
69 | + if ($action) { |
|
70 | 70 | self::wpinv_ajax_headers(); |
71 | - $action = sanitize_text_field( $action ); |
|
72 | - do_action( 'wpinv_ajax_' . $action ); |
|
71 | + $action = sanitize_text_field($action); |
|
72 | + do_action('wpinv_ajax_' . $action); |
|
73 | 73 | wp_die(); |
74 | 74 | } |
75 | 75 | |
@@ -103,36 +103,36 @@ discard block |
||
103 | 103 | 'ip_geolocation' => true, |
104 | 104 | ); |
105 | 105 | |
106 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
107 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
108 | - add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
106 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
107 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
108 | + add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
109 | 109 | |
110 | - if ( $nopriv ) { |
|
111 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
112 | - add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
113 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
110 | + if ($nopriv) { |
|
111 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
112 | + add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
113 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
118 | 118 | public static function add_note() { |
119 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
119 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
120 | 120 | |
121 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
121 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
122 | 122 | die(-1); |
123 | 123 | } |
124 | 124 | |
125 | - $post_id = absint( $_POST['post_id'] ); |
|
126 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
127 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
125 | + $post_id = absint($_POST['post_id']); |
|
126 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
127 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
128 | 128 | |
129 | 129 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
130 | 130 | |
131 | - if ( $post_id > 0 ) { |
|
132 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
131 | + if ($post_id > 0) { |
|
132 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
133 | 133 | |
134 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
135 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
134 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
135 | + wpinv_get_invoice_note_line_item($note_id); |
|
136 | 136 | } |
137 | 137 | } |
138 | 138 | |
@@ -140,16 +140,16 @@ discard block |
||
140 | 140 | } |
141 | 141 | |
142 | 142 | public static function delete_note() { |
143 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
143 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
144 | 144 | |
145 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
145 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
146 | 146 | die(-1); |
147 | 147 | } |
148 | 148 | |
149 | - $note_id = (int)$_POST['note_id']; |
|
149 | + $note_id = (int) $_POST['note_id']; |
|
150 | 150 | |
151 | - if ( $note_id > 0 ) { |
|
152 | - wp_delete_comment( $note_id, true ); |
|
151 | + if ($note_id > 0) { |
|
152 | + wp_delete_comment($note_id, true); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | die(); |
@@ -167,34 +167,34 @@ discard block |
||
167 | 167 | public static function get_billing_details() { |
168 | 168 | |
169 | 169 | // Verify nonce. |
170 | - check_ajax_referer( 'wpinv-nonce' ); |
|
170 | + check_ajax_referer('wpinv-nonce'); |
|
171 | 171 | |
172 | 172 | // Can the user manage the plugin? |
173 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
173 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
174 | 174 | die(-1); |
175 | 175 | } |
176 | 176 | |
177 | 177 | // Do we have a user id? |
178 | 178 | $user_id = $_GET['user_id']; |
179 | 179 | |
180 | - if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { |
|
180 | + if (empty($user_id) || !is_numeric($user_id)) { |
|
181 | 181 | die(-1); |
182 | 182 | } |
183 | 183 | |
184 | 184 | // Fetch the billing details. |
185 | - $billing_details = wpinv_get_user_address( $user_id ); |
|
186 | - $billing_details = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id ); |
|
185 | + $billing_details = wpinv_get_user_address($user_id); |
|
186 | + $billing_details = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id); |
|
187 | 187 | |
188 | 188 | // unset the user id and email. |
189 | - $to_ignore = array( 'user_id', 'email' ); |
|
189 | + $to_ignore = array('user_id', 'email'); |
|
190 | 190 | |
191 | - foreach ( $to_ignore as $key ) { |
|
192 | - if ( isset( $billing_details[ $key ] ) ) { |
|
193 | - unset( $billing_details[ $key ] ); |
|
191 | + foreach ($to_ignore as $key) { |
|
192 | + if (isset($billing_details[$key])) { |
|
193 | + unset($billing_details[$key]); |
|
194 | 194 | } |
195 | 195 | } |
196 | 196 | |
197 | - wp_send_json_success( $billing_details ); |
|
197 | + wp_send_json_success($billing_details); |
|
198 | 198 | |
199 | 199 | } |
200 | 200 | |
@@ -204,47 +204,47 @@ discard block |
||
204 | 204 | public static function check_new_user_email() { |
205 | 205 | |
206 | 206 | // Verify nonce. |
207 | - check_ajax_referer( 'wpinv-nonce' ); |
|
207 | + check_ajax_referer('wpinv-nonce'); |
|
208 | 208 | |
209 | 209 | // Can the user manage the plugin? |
210 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
210 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
211 | 211 | die(-1); |
212 | 212 | } |
213 | 213 | |
214 | 214 | // We need an email address. |
215 | - if ( empty( $_GET['email'] ) ) { |
|
216 | - _e( "Provide the new user's email address", 'invoicing' ); |
|
215 | + if (empty($_GET['email'])) { |
|
216 | + _e("Provide the new user's email address", 'invoicing'); |
|
217 | 217 | exit; |
218 | 218 | } |
219 | 219 | |
220 | 220 | // Ensure the email is valid. |
221 | - $email = sanitize_text_field( $_GET['email'] ); |
|
222 | - if ( ! is_email( $email ) ) { |
|
223 | - _e( 'Invalid email address', 'invoicing' ); |
|
221 | + $email = sanitize_text_field($_GET['email']); |
|
222 | + if (!is_email($email)) { |
|
223 | + _e('Invalid email address', 'invoicing'); |
|
224 | 224 | exit; |
225 | 225 | } |
226 | 226 | |
227 | 227 | // And it does not exist. |
228 | - if ( email_exists( $email ) ) { |
|
229 | - _e( 'A user with this email address already exists', 'invoicing' ); |
|
228 | + if (email_exists($email)) { |
|
229 | + _e('A user with this email address already exists', 'invoicing'); |
|
230 | 230 | exit; |
231 | 231 | } |
232 | 232 | |
233 | - wp_send_json_success( true ); |
|
233 | + wp_send_json_success(true); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | public static function run_tool() { |
237 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
238 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
237 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
238 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
239 | 239 | die(-1); |
240 | 240 | } |
241 | 241 | |
242 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
242 | + $tool = sanitize_text_field($_POST['tool']); |
|
243 | 243 | |
244 | - do_action( 'wpinv_run_tool' ); |
|
244 | + do_action('wpinv_run_tool'); |
|
245 | 245 | |
246 | - if ( !empty( $tool ) ) { |
|
247 | - do_action( 'wpinv_tool_' . $tool ); |
|
246 | + if (!empty($tool)) { |
|
247 | + do_action('wpinv_tool_' . $tool); |
|
248 | 248 | } |
249 | 249 | } |
250 | 250 | |
@@ -254,30 +254,30 @@ discard block |
||
254 | 254 | public static function get_payment_form() { |
255 | 255 | |
256 | 256 | // Check nonce. |
257 | - if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'], 'getpaid_ajax_form' ) ) { |
|
258 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
257 | + if (!isset($_GET['nonce']) || !wp_verify_nonce($_GET['nonce'], 'getpaid_ajax_form')) { |
|
258 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
259 | 259 | exit; |
260 | 260 | } |
261 | 261 | |
262 | 262 | // Is the request set up correctly? |
263 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
263 | + if (empty($_GET['form']) && empty($_GET['item'])) { |
|
264 | 264 | echo aui()->alert( |
265 | 265 | array( |
266 | 266 | 'type' => 'warning', |
267 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
267 | + 'content' => __('No payment form or item provided', 'invoicing'), |
|
268 | 268 | ) |
269 | 269 | ); |
270 | 270 | exit; |
271 | 271 | } |
272 | 272 | |
273 | 273 | // Payment form or button? |
274 | - if ( ! empty( $_GET['form'] ) ) { |
|
275 | - echo getpaid_display_payment_form( $_GET['form'] ); |
|
276 | - } else if( $_GET['invoice'] ) { |
|
277 | - echo getpaid_display_invoice_payment_form( $_GET['invoice'] ); |
|
274 | + if (!empty($_GET['form'])) { |
|
275 | + echo getpaid_display_payment_form($_GET['form']); |
|
276 | + } else if ($_GET['invoice']) { |
|
277 | + echo getpaid_display_invoice_payment_form($_GET['invoice']); |
|
278 | 278 | } else { |
279 | - $items = getpaid_convert_items_to_array( $_GET['item'] ); |
|
280 | - echo getpaid_display_item_payment_form( $items ); |
|
279 | + $items = getpaid_convert_items_to_array($_GET['item']); |
|
280 | + echo getpaid_display_item_payment_form($items); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | exit; |
@@ -293,11 +293,11 @@ discard block |
||
293 | 293 | global $invoicing; |
294 | 294 | |
295 | 295 | // Check nonce. |
296 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
296 | + check_ajax_referer('getpaid_form_nonce'); |
|
297 | 297 | |
298 | 298 | // ... form fields... |
299 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
300 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
299 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
300 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
301 | 301 | exit; |
302 | 302 | } |
303 | 303 | |
@@ -305,66 +305,66 @@ discard block |
||
305 | 305 | $submission = new GetPaid_Payment_Form_Submission(); |
306 | 306 | |
307 | 307 | // Do we have an error? |
308 | - if ( ! empty( $submission->last_error ) ) { |
|
308 | + if (!empty($submission->last_error)) { |
|
309 | 309 | echo $submission->last_error; |
310 | 310 | exit; |
311 | 311 | } |
312 | 312 | |
313 | 313 | // We need a billing email. |
314 | - if ( ! $submission->has_billing_email() || ! is_email( $submission->get_billing_email() ) ) { |
|
315 | - wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
|
314 | + if (!$submission->has_billing_email() || !is_email($submission->get_billing_email())) { |
|
315 | + wp_send_json_error(__('Provide a valid billing email.', 'invoicing')); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | // Clear any checkout errors. |
319 | 319 | wpinv_clear_errors(); |
320 | 320 | |
321 | 321 | // Validate the gateway. |
322 | - wpinv_checkout_validate_gateway( $submission ); |
|
322 | + wpinv_checkout_validate_gateway($submission); |
|
323 | 323 | |
324 | 324 | // Allow themes and plugins to hook to errors |
325 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
325 | + do_action('getpaid_checkout_error_checks', $submission); |
|
326 | 326 | |
327 | 327 | // Do we have any errors? |
328 | - if ( wpinv_get_errors() ) { |
|
329 | - wp_send_json_error( getpaid_get_errors_html() ); |
|
328 | + if (wpinv_get_errors()) { |
|
329 | + wp_send_json_error(getpaid_get_errors_html()); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | // Prepare items. |
333 | 333 | $items = $submission->get_items(); |
334 | 334 | |
335 | 335 | // Ensure that we have items. |
336 | - if ( empty( $items ) ) { |
|
337 | - wp_send_json_error( __( 'You have not selected any items.', 'invoicing' ) ); |
|
336 | + if (empty($items)) { |
|
337 | + wp_send_json_error(__('You have not selected any items.', 'invoicing')); |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | // Prepare the invoice. |
341 | - if ( ! $submission->has_invoice() ) { |
|
341 | + if (!$submission->has_invoice()) { |
|
342 | 342 | $invoice = new WPInv_Invoice(); |
343 | 343 | } else { |
344 | 344 | $invoice = $submission->get_invoice(); |
345 | 345 | } |
346 | 346 | |
347 | 347 | // Make sure that it is neither paid or refunded. |
348 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
349 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
348 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
349 | + wp_send_json_error(__('This invoice has already been paid for.', 'invoicing')); |
|
350 | 350 | } |
351 | 351 | |
352 | 352 | // Set the billing email. |
353 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
353 | + $invoice->set_email(sanitize_email($submission->get_billing_email())); |
|
354 | 354 | |
355 | 355 | // Payment form. |
356 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
356 | + $invoice->set_payment_form(absint($submission->get_payment_form()->get_id())); |
|
357 | 357 | |
358 | 358 | // Discount code. |
359 | - if ( $submission->has_discount_code() ) { |
|
360 | - $invoice->set_discount_code( $submission->get_discount_code() ); |
|
359 | + if ($submission->has_discount_code()) { |
|
360 | + $invoice->set_discount_code($submission->get_discount_code()); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | // Items, Fees, taxes and discounts. |
364 | - $invoice->set_items( $items ); |
|
365 | - $invoice->set_fees( $submission->get_fees() ); |
|
366 | - $invoice->set_taxes( $submission->get_taxes() ); |
|
367 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
364 | + $invoice->set_items($items); |
|
365 | + $invoice->set_fees($submission->get_fees()); |
|
366 | + $invoice->set_taxes($submission->get_taxes()); |
|
367 | + $invoice->set_discounts($submission->get_discounts()); |
|
368 | 368 | |
369 | 369 | // Prepared submission details. |
370 | 370 | $prepared = array(); |
@@ -373,48 +373,48 @@ discard block |
||
373 | 373 | $data = $submission->get_data(); |
374 | 374 | |
375 | 375 | // Loop throught the submitted details. |
376 | - foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
|
376 | + foreach ($submission->get_payment_form()->get_elements() as $field) { |
|
377 | 377 | |
378 | - if ( ! empty( $field['premade'] ) ) { |
|
378 | + if (!empty($field['premade'])) { |
|
379 | 379 | continue; |
380 | 380 | } |
381 | 381 | |
382 | 382 | // If it is required and not set, abort. |
383 | - if ( ! $submission->is_required_field_set( $field ) ) { |
|
384 | - wp_send_json_error( __( 'Some required fields are not set.', 'invoicing' ) ); |
|
383 | + if (!$submission->is_required_field_set($field)) { |
|
384 | + wp_send_json_error(__('Some required fields are not set.', 'invoicing')); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | // Handle address fields. |
388 | - if ( $field['type'] == 'address' ) { |
|
388 | + if ($field['type'] == 'address') { |
|
389 | 389 | |
390 | - foreach ( $field['fields'] as $address_field ) { |
|
390 | + foreach ($field['fields'] as $address_field) { |
|
391 | 391 | |
392 | 392 | // skip if it is not visible. |
393 | - if ( empty( $address_field['visible'] ) ) { |
|
393 | + if (empty($address_field['visible'])) { |
|
394 | 394 | continue; |
395 | 395 | } |
396 | 396 | |
397 | 397 | // If it is required and not set, abort |
398 | - if ( ! empty( $address_field['required'] ) && empty( $data[ $address_field['name'] ] ) ) { |
|
399 | - wp_send_json_error( __( 'Some required fields are not set.', 'invoicing' ) ); |
|
398 | + if (!empty($address_field['required']) && empty($data[$address_field['name']])) { |
|
399 | + wp_send_json_error(__('Some required fields are not set.', 'invoicing')); |
|
400 | 400 | } |
401 | 401 | |
402 | - if ( isset( $data[ $address_field['name'] ] ) ) { |
|
403 | - $name = str_replace( 'wpinv_', '', $address_field['name'] ); |
|
402 | + if (isset($data[$address_field['name']])) { |
|
403 | + $name = str_replace('wpinv_', '', $address_field['name']); |
|
404 | 404 | $method = "set_$name"; |
405 | - $invoice->$method( wpinv_clean( $data[ $address_field['name'] ] ) ); |
|
405 | + $invoice->$method(wpinv_clean($data[$address_field['name']])); |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | } |
409 | 409 | |
410 | - } else if ( isset( $data[ $field['id'] ] ) ) { |
|
410 | + } else if (isset($data[$field['id']])) { |
|
411 | 411 | $label = $field['id']; |
412 | 412 | |
413 | - if ( isset( $field['label'] ) ) { |
|
413 | + if (isset($field['label'])) { |
|
414 | 414 | $label = $field['label']; |
415 | 415 | } |
416 | 416 | |
417 | - $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] ); |
|
417 | + $prepared[wpinv_clean($label)] = wpinv_clean($data[$field['id']]); |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | } |
@@ -422,26 +422,26 @@ discard block |
||
422 | 422 | // (Maybe) create the user. |
423 | 423 | $user = get_current_user_id(); |
424 | 424 | |
425 | - if ( empty( $user ) ) { |
|
426 | - $user = get_user_by( 'email', $submission->get_billing_email() ); |
|
425 | + if (empty($user)) { |
|
426 | + $user = get_user_by('email', $submission->get_billing_email()); |
|
427 | 427 | } |
428 | 428 | |
429 | - if ( empty( $user ) ) { |
|
430 | - $user = wpinv_create_user( $submission->get_billing_email() ); |
|
429 | + if (empty($user)) { |
|
430 | + $user = wpinv_create_user($submission->get_billing_email()); |
|
431 | 431 | } |
432 | 432 | |
433 | - if ( is_wp_error( $user ) ) { |
|
434 | - wp_send_json_error( $user->get_error_message() ); |
|
433 | + if (is_wp_error($user)) { |
|
434 | + wp_send_json_error($user->get_error_message()); |
|
435 | 435 | } |
436 | 436 | |
437 | - if ( is_numeric( $user ) ) { |
|
438 | - $user = get_user_by( 'id', $user ); |
|
437 | + if (is_numeric($user)) { |
|
438 | + $user = get_user_by('id', $user); |
|
439 | 439 | } |
440 | 440 | |
441 | - $invoice->set_user_id( $user->ID ); |
|
441 | + $invoice->set_user_id($user->ID); |
|
442 | 442 | |
443 | 443 | // Set gateway. |
444 | - $invoice->set_gateway( $data['wpi-gateway'] ); |
|
444 | + $invoice->set_gateway($data['wpi-gateway']); |
|
445 | 445 | |
446 | 446 | $invoice->recalculate_total(); |
447 | 447 | |
@@ -449,20 +449,20 @@ discard block |
||
449 | 449 | $invoice->save(); |
450 | 450 | |
451 | 451 | // Was it saved successfully: |
452 | - if ($invoice->get_id() == 0 ) { |
|
453 | - wp_send_json_error( __( 'An error occured while saving your invoice.', 'invoicing' ) ); |
|
452 | + if ($invoice->get_id() == 0) { |
|
453 | + wp_send_json_error(__('An error occured while saving your invoice.', 'invoicing')); |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | // Save payment form data. |
457 | - if ( ! empty( $prepared ) ) { |
|
458 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared ); |
|
457 | + if (!empty($prepared)) { |
|
458 | + update_post_meta($invoice->get_id(), 'payment_form_data', $prepared); |
|
459 | 459 | } |
460 | 460 | |
461 | 461 | // Process the checkout. |
462 | - add_filter( 'wp_redirect', array( $invoicing->form_elements, 'send_redirect_response' ) ); |
|
463 | - add_action( 'wpinv_pre_send_back_to_checkout', array( $invoicing->form_elements, 'checkout_error' ) ); |
|
462 | + add_filter('wp_redirect', array($invoicing->form_elements, 'send_redirect_response')); |
|
463 | + add_action('wpinv_pre_send_back_to_checkout', array($invoicing->form_elements, 'checkout_error')); |
|
464 | 464 | |
465 | - wpinv_process_checkout( $invoice, $submission ); |
|
465 | + wpinv_process_checkout($invoice, $submission); |
|
466 | 466 | |
467 | 467 | // If we are here, there was an error. |
468 | 468 | $invoicing->form_elements->checkout_error(); |
@@ -478,51 +478,51 @@ discard block |
||
478 | 478 | public static function get_payment_form_states_field() { |
479 | 479 | global $invoicing; |
480 | 480 | |
481 | - if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) { |
|
481 | + if (empty($_GET['country']) || empty($_GET['form'])) { |
|
482 | 482 | exit; |
483 | 483 | } |
484 | 484 | |
485 | - $elements = $invoicing->form_elements->get_form_elements( $_GET['form'] ); |
|
485 | + $elements = $invoicing->form_elements->get_form_elements($_GET['form']); |
|
486 | 486 | |
487 | - if ( empty( $elements ) ) { |
|
487 | + if (empty($elements)) { |
|
488 | 488 | exit; |
489 | 489 | } |
490 | 490 | |
491 | 491 | $address_fields = array(); |
492 | - foreach ( $elements as $element ) { |
|
493 | - if ( 'address' === $element['type'] ) { |
|
492 | + foreach ($elements as $element) { |
|
493 | + if ('address' === $element['type']) { |
|
494 | 494 | $address_fields = $element; |
495 | 495 | break; |
496 | 496 | } |
497 | 497 | } |
498 | 498 | |
499 | - if ( empty( $address_fields ) ) { |
|
499 | + if (empty($address_fields)) { |
|
500 | 500 | exit; |
501 | 501 | } |
502 | 502 | |
503 | - foreach( $address_fields['fields'] as $address_field ) { |
|
503 | + foreach ($address_fields['fields'] as $address_field) { |
|
504 | 504 | |
505 | - if ( 'wpinv_state' == $address_field['name'] ) { |
|
505 | + if ('wpinv_state' == $address_field['name']) { |
|
506 | 506 | |
507 | 507 | $label = $address_field['label']; |
508 | 508 | |
509 | - if ( ! empty( $address_field['required'] ) ) { |
|
509 | + if (!empty($address_field['required'])) { |
|
510 | 510 | $label .= "<span class='text-danger'> *</span>"; |
511 | 511 | } |
512 | 512 | |
513 | - $states = wpinv_get_country_states( $_GET['country'] ); |
|
513 | + $states = wpinv_get_country_states($_GET['country']); |
|
514 | 514 | |
515 | - if ( ! empty( $states ) ) { |
|
515 | + if (!empty($states)) { |
|
516 | 516 | |
517 | 517 | $html = aui()->select( |
518 | 518 | array( |
519 | 519 | 'options' => $states, |
520 | - 'name' => esc_attr( $address_field['name'] ), |
|
521 | - 'id' => esc_attr( $address_field['name'] ), |
|
522 | - 'placeholder' => esc_attr( $address_field['placeholder'] ), |
|
520 | + 'name' => esc_attr($address_field['name']), |
|
521 | + 'id' => esc_attr($address_field['name']), |
|
522 | + 'placeholder' => esc_attr($address_field['placeholder']), |
|
523 | 523 | 'required' => (bool) $address_field['required'], |
524 | 524 | 'no_wrap' => true, |
525 | - 'label' => wp_kses_post( $label ), |
|
525 | + 'label' => wp_kses_post($label), |
|
526 | 526 | 'select2' => false, |
527 | 527 | ) |
528 | 528 | ); |
@@ -531,10 +531,10 @@ discard block |
||
531 | 531 | |
532 | 532 | $html = aui()->input( |
533 | 533 | array( |
534 | - 'name' => esc_attr( $address_field['name'] ), |
|
535 | - 'id' => esc_attr( $address_field['name'] ), |
|
534 | + 'name' => esc_attr($address_field['name']), |
|
535 | + 'id' => esc_attr($address_field['name']), |
|
536 | 536 | 'required' => (bool) $address_field['required'], |
537 | - 'label' => wp_kses_post( $label ), |
|
537 | + 'label' => wp_kses_post($label), |
|
538 | 538 | 'no_wrap' => true, |
539 | 539 | 'type' => 'text', |
540 | 540 | ) |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | |
543 | 543 | } |
544 | 544 | |
545 | - wp_send_json_success( str_replace( 'sr-only', '', $html ) ); |
|
545 | + wp_send_json_success(str_replace('sr-only', '', $html)); |
|
546 | 546 | exit; |
547 | 547 | |
548 | 548 | } |
@@ -558,56 +558,56 @@ discard block |
||
558 | 558 | public static function recalculate_invoice_totals() { |
559 | 559 | |
560 | 560 | // Verify nonce. |
561 | - check_ajax_referer( 'wpinv-nonce' ); |
|
561 | + check_ajax_referer('wpinv-nonce'); |
|
562 | 562 | |
563 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
563 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
564 | 564 | exit; |
565 | 565 | } |
566 | 566 | |
567 | 567 | // We need an invoice. |
568 | - if ( empty( $_POST['post_id'] ) ) { |
|
568 | + if (empty($_POST['post_id'])) { |
|
569 | 569 | exit; |
570 | 570 | } |
571 | 571 | |
572 | 572 | // Fetch the invoice. |
573 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
573 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
574 | 574 | |
575 | 575 | // Ensure it exists. |
576 | - if ( ! $invoice->get_id() ) { |
|
576 | + if (!$invoice->get_id()) { |
|
577 | 577 | exit; |
578 | 578 | } |
579 | 579 | |
580 | 580 | // Maybe set the country, state, currency. |
581 | - foreach ( array( 'country', 'state', 'currency' ) as $key ) { |
|
582 | - if ( isset( $_POST[ $key ] ) ) { |
|
581 | + foreach (array('country', 'state', 'currency') as $key) { |
|
582 | + if (isset($_POST[$key])) { |
|
583 | 583 | $method = "set_$key"; |
584 | - $invoice->$method( $_POST[ $key ] ); |
|
584 | + $invoice->$method($_POST[$key]); |
|
585 | 585 | } |
586 | 586 | } |
587 | 587 | |
588 | 588 | // Maybe disable taxes. |
589 | - $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) ); |
|
589 | + $invoice->set_disable_taxes(!empty($_POST['taxes'])); |
|
590 | 590 | |
591 | 591 | // Recalculate totals. |
592 | 592 | $invoice->recalculate_total(); |
593 | 593 | |
594 | - $total = wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() ); |
|
594 | + $total = wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency()); |
|
595 | 595 | |
596 | - if ( $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) { |
|
597 | - $recurring_total = wpinv_price( wpinv_format_amount( $invoice->get_recurring_total() ), $invoice->get_currency() ); |
|
598 | - $total .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>'; |
|
596 | + if ($invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) { |
|
597 | + $recurring_total = wpinv_price(wpinv_format_amount($invoice->get_recurring_total()), $invoice->get_currency()); |
|
598 | + $total .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>'; |
|
599 | 599 | } |
600 | 600 | |
601 | 601 | $totals = array( |
602 | - 'subtotal' => wpinv_price( wpinv_format_amount( $invoice->get_subtotal() ), $invoice->get_currency() ), |
|
603 | - 'discount' => wpinv_price( wpinv_format_amount( $invoice->get_total_discount() ), $invoice->get_currency() ), |
|
604 | - 'tax' => wpinv_price( wpinv_format_amount( $invoice->get_total_tax() ), $invoice->get_currency() ), |
|
602 | + 'subtotal' => wpinv_price(wpinv_format_amount($invoice->get_subtotal()), $invoice->get_currency()), |
|
603 | + 'discount' => wpinv_price(wpinv_format_amount($invoice->get_total_discount()), $invoice->get_currency()), |
|
604 | + 'tax' => wpinv_price(wpinv_format_amount($invoice->get_total_tax()), $invoice->get_currency()), |
|
605 | 605 | 'total' => $total, |
606 | 606 | ); |
607 | 607 | |
608 | - $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice ); |
|
608 | + $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice); |
|
609 | 609 | |
610 | - wp_send_json_success( compact( 'totals' ) ); |
|
610 | + wp_send_json_success(compact('totals')); |
|
611 | 611 | } |
612 | 612 | |
613 | 613 | /** |
@@ -616,33 +616,33 @@ discard block |
||
616 | 616 | public static function get_invoice_items() { |
617 | 617 | |
618 | 618 | // Verify nonce. |
619 | - check_ajax_referer( 'wpinv-nonce' ); |
|
619 | + check_ajax_referer('wpinv-nonce'); |
|
620 | 620 | |
621 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
621 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
622 | 622 | exit; |
623 | 623 | } |
624 | 624 | |
625 | 625 | // We need an invoice and items. |
626 | - if ( empty( $_POST['post_id'] ) ) { |
|
626 | + if (empty($_POST['post_id'])) { |
|
627 | 627 | exit; |
628 | 628 | } |
629 | 629 | |
630 | 630 | // Fetch the invoice. |
631 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
631 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
632 | 632 | |
633 | 633 | // Ensure it exists. |
634 | - if ( ! $invoice->get_id() ) { |
|
634 | + if (!$invoice->get_id()) { |
|
635 | 635 | exit; |
636 | 636 | } |
637 | 637 | |
638 | 638 | // Return an array of invoice items. |
639 | 639 | $items = array(); |
640 | 640 | |
641 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
642 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
641 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
642 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
643 | 643 | } |
644 | 644 | |
645 | - wp_send_json_success( compact( 'items' ) ); |
|
645 | + wp_send_json_success(compact('items')); |
|
646 | 646 | } |
647 | 647 | |
648 | 648 | /** |
@@ -651,50 +651,50 @@ discard block |
||
651 | 651 | public static function edit_invoice_item() { |
652 | 652 | |
653 | 653 | // Verify nonce. |
654 | - check_ajax_referer( 'wpinv-nonce' ); |
|
654 | + check_ajax_referer('wpinv-nonce'); |
|
655 | 655 | |
656 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
656 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
657 | 657 | exit; |
658 | 658 | } |
659 | 659 | |
660 | 660 | // We need an invoice and item details. |
661 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) { |
|
661 | + if (empty($_POST['post_id']) || empty($_POST['data'])) { |
|
662 | 662 | exit; |
663 | 663 | } |
664 | 664 | |
665 | 665 | // Fetch the invoice. |
666 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
666 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
667 | 667 | |
668 | 668 | // Ensure it exists and its not been paid for. |
669 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
669 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
670 | 670 | exit; |
671 | 671 | } |
672 | 672 | |
673 | 673 | // Format the data. |
674 | - $data = wp_list_pluck( $_POST['data'], 'value', 'field' ); |
|
674 | + $data = wp_list_pluck($_POST['data'], 'value', 'field'); |
|
675 | 675 | |
676 | 676 | // Ensure that we have an item id. |
677 | - if ( empty( $data['id'] ) ) { |
|
677 | + if (empty($data['id'])) { |
|
678 | 678 | exit; |
679 | 679 | } |
680 | 680 | |
681 | 681 | // Abort if the invoice does not have the specified item. |
682 | - $item = $invoice->get_item( (int) $data['id'] ); |
|
682 | + $item = $invoice->get_item((int) $data['id']); |
|
683 | 683 | |
684 | - if ( empty( $item ) ) { |
|
684 | + if (empty($item)) { |
|
685 | 685 | exit; |
686 | 686 | } |
687 | 687 | |
688 | 688 | // Update the item. |
689 | - $item->set_price( $data['price'] ); |
|
690 | - $item->set_name( $data['name'] ); |
|
691 | - $item->set_description( $data['description'] ); |
|
692 | - $item->set_quantity( $data['quantity'] ); |
|
689 | + $item->set_price($data['price']); |
|
690 | + $item->set_name($data['name']); |
|
691 | + $item->set_description($data['description']); |
|
692 | + $item->set_quantity($data['quantity']); |
|
693 | 693 | |
694 | 694 | // Add it to the invoice. |
695 | - $error = $invoice->add_item( $item ); |
|
695 | + $error = $invoice->add_item($item); |
|
696 | 696 | $alert = false; |
697 | - if ( is_wp_error( $error ) ) { |
|
697 | + if (is_wp_error($error)) { |
|
698 | 698 | $alert = $error->get_error_message(); |
699 | 699 | } |
700 | 700 | |
@@ -707,11 +707,11 @@ discard block |
||
707 | 707 | // Return an array of invoice items. |
708 | 708 | $items = array(); |
709 | 709 | |
710 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
711 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
710 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
711 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
712 | 712 | } |
713 | 713 | |
714 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
714 | + wp_send_json_success(compact('items', 'alert')); |
|
715 | 715 | } |
716 | 716 | |
717 | 717 | /** |
@@ -720,33 +720,33 @@ discard block |
||
720 | 720 | public static function remove_invoice_item() { |
721 | 721 | |
722 | 722 | // Verify nonce. |
723 | - check_ajax_referer( 'wpinv-nonce' ); |
|
723 | + check_ajax_referer('wpinv-nonce'); |
|
724 | 724 | |
725 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
725 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
726 | 726 | exit; |
727 | 727 | } |
728 | 728 | |
729 | 729 | // We need an invoice and an item. |
730 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
730 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
731 | 731 | exit; |
732 | 732 | } |
733 | 733 | |
734 | 734 | // Fetch the invoice. |
735 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
735 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
736 | 736 | |
737 | 737 | // Ensure it exists and its not been paid for. |
738 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
738 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
739 | 739 | exit; |
740 | 740 | } |
741 | 741 | |
742 | 742 | // Abort if the invoice does not have the specified item. |
743 | - $item = $invoice->get_item( (int) $_POST['item_id'] ); |
|
743 | + $item = $invoice->get_item((int) $_POST['item_id']); |
|
744 | 744 | |
745 | - if ( empty( $item ) ) { |
|
745 | + if (empty($item)) { |
|
746 | 746 | exit; |
747 | 747 | } |
748 | 748 | |
749 | - $invoice->remove_item( (int) $_POST['item_id'] ); |
|
749 | + $invoice->remove_item((int) $_POST['item_id']); |
|
750 | 750 | |
751 | 751 | // Update totals. |
752 | 752 | $invoice->recalculate_total(); |
@@ -757,11 +757,11 @@ discard block |
||
757 | 757 | // Return an array of invoice items. |
758 | 758 | $items = array(); |
759 | 759 | |
760 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
761 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
760 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
761 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
762 | 762 | } |
763 | 763 | |
764 | - wp_send_json_success( compact( 'items' ) ); |
|
764 | + wp_send_json_success(compact('items')); |
|
765 | 765 | } |
766 | 766 | |
767 | 767 | /** |
@@ -770,39 +770,39 @@ discard block |
||
770 | 770 | public static function add_invoice_items() { |
771 | 771 | |
772 | 772 | // Verify nonce. |
773 | - check_ajax_referer( 'wpinv-nonce' ); |
|
773 | + check_ajax_referer('wpinv-nonce'); |
|
774 | 774 | |
775 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
775 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
776 | 776 | exit; |
777 | 777 | } |
778 | 778 | |
779 | 779 | // We need an invoice and items. |
780 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) { |
|
780 | + if (empty($_POST['post_id']) || empty($_POST['items'])) { |
|
781 | 781 | exit; |
782 | 782 | } |
783 | 783 | |
784 | 784 | // Fetch the invoice. |
785 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
785 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
786 | 786 | $alert = false; |
787 | 787 | |
788 | 788 | // Ensure it exists and its not been paid for. |
789 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
789 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
790 | 790 | exit; |
791 | 791 | } |
792 | 792 | |
793 | 793 | // Add the items. |
794 | - foreach ( $_POST['items'] as $data ) { |
|
794 | + foreach ($_POST['items'] as $data) { |
|
795 | 795 | |
796 | - $item = new GetPaid_Form_Item( $data[ 'id' ] ); |
|
796 | + $item = new GetPaid_Form_Item($data['id']); |
|
797 | 797 | |
798 | - if ( is_numeric( $data[ 'qty' ] ) && (int) $data[ 'qty' ] > 0 ) { |
|
799 | - $item->set_quantity( $data[ 'qty' ] ); |
|
798 | + if (is_numeric($data['qty']) && (int) $data['qty'] > 0) { |
|
799 | + $item->set_quantity($data['qty']); |
|
800 | 800 | } |
801 | 801 | |
802 | - if ( $item->get_id() > 0 ) { |
|
803 | - $error = $invoice->add_item( $item ); |
|
802 | + if ($item->get_id() > 0) { |
|
803 | + $error = $invoice->add_item($item); |
|
804 | 804 | |
805 | - if ( is_wp_error( $error ) ) { |
|
805 | + if (is_wp_error($error)) { |
|
806 | 806 | $alert = $error->get_error_message(); |
807 | 807 | } |
808 | 808 | |
@@ -817,11 +817,11 @@ discard block |
||
817 | 817 | // Return an array of invoice items. |
818 | 818 | $items = array(); |
819 | 819 | |
820 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
821 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
820 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
821 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
822 | 822 | } |
823 | 823 | |
824 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
824 | + wp_send_json_success(compact('items', 'alert')); |
|
825 | 825 | } |
826 | 826 | |
827 | 827 | /** |
@@ -830,15 +830,15 @@ discard block |
||
830 | 830 | public static function get_invoicing_items() { |
831 | 831 | |
832 | 832 | // Verify nonce. |
833 | - check_ajax_referer( 'wpinv-nonce' ); |
|
833 | + check_ajax_referer('wpinv-nonce'); |
|
834 | 834 | |
835 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
835 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
836 | 836 | exit; |
837 | 837 | } |
838 | 838 | |
839 | 839 | // We need a search term. |
840 | - if ( empty( $_GET['search'] ) ) { |
|
841 | - wp_send_json_success( array() ); |
|
840 | + if (empty($_GET['search'])) { |
|
841 | + wp_send_json_success(array()); |
|
842 | 842 | } |
843 | 843 | |
844 | 844 | // Retrieve items. |
@@ -847,8 +847,8 @@ discard block |
||
847 | 847 | 'orderby' => 'title', |
848 | 848 | 'order' => 'ASC', |
849 | 849 | 'posts_per_page' => -1, |
850 | - 'post_status' => array( 'publish' ), |
|
851 | - 's' => trim( $_GET['search'] ), |
|
850 | + 'post_status' => array('publish'), |
|
851 | + 's' => trim($_GET['search']), |
|
852 | 852 | 'meta_query' => array( |
853 | 853 | array( |
854 | 854 | 'key' => '_wpinv_type', |
@@ -858,18 +858,18 @@ discard block |
||
858 | 858 | ) |
859 | 859 | ); |
860 | 860 | |
861 | - $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) ); |
|
861 | + $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args)); |
|
862 | 862 | $data = array(); |
863 | 863 | |
864 | - foreach ( $items as $item ) { |
|
865 | - $item = new GetPaid_Form_Item( $item ); |
|
864 | + foreach ($items as $item) { |
|
865 | + $item = new GetPaid_Form_Item($item); |
|
866 | 866 | $data[] = array( |
867 | 867 | 'id' => $item->get_id(), |
868 | 868 | 'text' => $item->get_name() |
869 | 869 | ); |
870 | 870 | } |
871 | 871 | |
872 | - wp_send_json_success( $data ); |
|
872 | + wp_send_json_success($data); |
|
873 | 873 | |
874 | 874 | } |
875 | 875 | |
@@ -879,24 +879,24 @@ discard block |
||
879 | 879 | public static function get_aui_states_field() { |
880 | 880 | |
881 | 881 | // Verify nonce. |
882 | - check_ajax_referer( 'wpinv-nonce' ); |
|
882 | + check_ajax_referer('wpinv-nonce'); |
|
883 | 883 | |
884 | 884 | // We need a country. |
885 | - if ( empty( $_GET['country'] ) ) { |
|
885 | + if (empty($_GET['country'])) { |
|
886 | 886 | exit; |
887 | 887 | } |
888 | 888 | |
889 | - $states = wpinv_get_country_states( trim( $_GET['country'] ) ); |
|
890 | - $state = isset( $_GET['state'] ) ? trim( $_GET['state'] ) : wpinv_get_default_state(); |
|
889 | + $states = wpinv_get_country_states(trim($_GET['country'])); |
|
890 | + $state = isset($_GET['state']) ? trim($_GET['state']) : wpinv_get_default_state(); |
|
891 | 891 | |
892 | - if ( empty( $states ) ) { |
|
892 | + if (empty($states)) { |
|
893 | 893 | |
894 | 894 | $html = aui()->input( |
895 | 895 | array( |
896 | 896 | 'type' => 'text', |
897 | 897 | 'id' => 'wpinv_state', |
898 | 898 | 'name' => 'wpinv_state', |
899 | - 'label' => __( 'State', 'invoicing' ), |
|
899 | + 'label' => __('State', 'invoicing'), |
|
900 | 900 | 'label_type' => 'vertical', |
901 | 901 | 'placeholder' => 'Liège', |
902 | 902 | 'class' => 'form-control-sm', |
@@ -910,9 +910,9 @@ discard block |
||
910 | 910 | array( |
911 | 911 | 'id' => 'wpinv_state', |
912 | 912 | 'name' => 'wpinv_state', |
913 | - 'label' => __( 'State', 'invoicing' ), |
|
913 | + 'label' => __('State', 'invoicing'), |
|
914 | 914 | 'label_type' => 'vertical', |
915 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
915 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
916 | 916 | 'class' => 'form-control-sm', |
917 | 917 | 'value' => $state, |
918 | 918 | 'options' => $states, |
@@ -926,7 +926,7 @@ discard block |
||
926 | 926 | wp_send_json_success( |
927 | 927 | array( |
928 | 928 | 'html' => $html, |
929 | - 'select' => ! empty ( $states ) |
|
929 | + 'select' => !empty ($states) |
|
930 | 930 | ) |
931 | 931 | ); |
932 | 932 | |
@@ -940,46 +940,46 @@ discard block |
||
940 | 940 | public static function ip_geolocation() { |
941 | 941 | |
942 | 942 | // Check nonce. |
943 | - check_ajax_referer( 'getpaid-ip-location' ); |
|
943 | + check_ajax_referer('getpaid-ip-location'); |
|
944 | 944 | |
945 | 945 | // IP address. |
946 | - if ( empty( $_GET['ip'] ) || ! rest_is_ip_address( $_GET['ip'] ) ) { |
|
947 | - _e( 'Invalid IP Address.', 'invoicing' ); |
|
946 | + if (empty($_GET['ip']) || !rest_is_ip_address($_GET['ip'])) { |
|
947 | + _e('Invalid IP Address.', 'invoicing'); |
|
948 | 948 | exit; |
949 | 949 | } |
950 | 950 | |
951 | 951 | // Retrieve location info. |
952 | - $location = getpaid_geolocate_ip_address( $_GET['ip'] ); |
|
952 | + $location = getpaid_geolocate_ip_address($_GET['ip']); |
|
953 | 953 | |
954 | - if ( empty( $location ) ) { |
|
955 | - _e( 'Unable to find geolocation for the IP Address.', 'invoicing' ); |
|
954 | + if (empty($location)) { |
|
955 | + _e('Unable to find geolocation for the IP Address.', 'invoicing'); |
|
956 | 956 | exit; |
957 | 957 | } |
958 | 958 | |
959 | 959 | // Sorry. |
960 | - extract( $location ); |
|
960 | + extract($location); |
|
961 | 961 | |
962 | 962 | // Prepare the address. |
963 | 963 | $content = ''; |
964 | 964 | |
965 | - if ( ! empty( $location['city'] ) ) { |
|
966 | - $content .= $location['city'] . ', '; |
|
965 | + if (!empty($location['city'])) { |
|
966 | + $content .= $location['city'] . ', '; |
|
967 | 967 | } |
968 | 968 | |
969 | - if ( ! empty( $location['region'] ) ) { |
|
970 | - $content .= $location['region'] . ', '; |
|
969 | + if (!empty($location['region'])) { |
|
970 | + $content .= $location['region'] . ', '; |
|
971 | 971 | } |
972 | 972 | |
973 | - $content .= $location['country'] . ' (' . $location['iso'] . ')'; |
|
973 | + $content .= $location['country'] . ' (' . $location['iso'] . ')'; |
|
974 | 974 | |
975 | 975 | $location['address'] = $content; |
976 | 976 | |
977 | - $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $content ) . '</p>'; |
|
978 | - $content .= '<p>'. $location['credit'] . '</p>'; |
|
977 | + $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $content) . '</p>'; |
|
978 | + $content .= '<p>' . $location['credit'] . '</p>'; |
|
979 | 979 | |
980 | 980 | $location['content'] = $content; |
981 | 981 | |
982 | - wpinv_get_template( 'geolocation.php', $location ); |
|
982 | + wpinv_get_template('geolocation.php', $location); |
|
983 | 983 | |
984 | 984 | exit; |
985 | 985 | } |
@@ -992,11 +992,11 @@ discard block |
||
992 | 992 | public static function payment_form_refresh_prices() { |
993 | 993 | |
994 | 994 | // Check nonce. |
995 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
995 | + check_ajax_referer('getpaid_form_nonce'); |
|
996 | 996 | |
997 | 997 | // ... form fields... |
998 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
999 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
998 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
999 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
1000 | 1000 | exit; |
1001 | 1001 | } |
1002 | 1002 | |
@@ -1004,7 +1004,7 @@ discard block |
||
1004 | 1004 | $submission = new GetPaid_Payment_Form_Submission(); |
1005 | 1005 | |
1006 | 1006 | // Do we have an error? |
1007 | - if ( ! empty( $submission->last_error ) ) { |
|
1007 | + if (!empty($submission->last_error)) { |
|
1008 | 1008 | echo $submission->last_error; |
1009 | 1009 | exit; |
1010 | 1010 | } |
@@ -1017,43 +1017,43 @@ discard block |
||
1017 | 1017 | 'is_free' => $submission->get_payment_details(), |
1018 | 1018 | |
1019 | 1019 | 'totals' => array( |
1020 | - 'subtotal' => wpinv_price( wpinv_format_amount( $submission->subtotal_amount ), $submission->get_currency() ), |
|
1021 | - 'discount' => wpinv_price( wpinv_format_amount( $submission->get_total_discount() ), $submission->get_currency() ), |
|
1022 | - 'fees' => wpinv_price( wpinv_format_amount( $submission->get_total_fees() ), $submission->get_currency() ), |
|
1023 | - 'tax' => wpinv_price( wpinv_format_amount( $submission->get_total_tax() ), $submission->get_currency() ), |
|
1024 | - 'total' => wpinv_price( wpinv_format_amount( $submission->get_total() ), $submission->get_currency() ), |
|
1020 | + 'subtotal' => wpinv_price(wpinv_format_amount($submission->subtotal_amount), $submission->get_currency()), |
|
1021 | + 'discount' => wpinv_price(wpinv_format_amount($submission->get_total_discount()), $submission->get_currency()), |
|
1022 | + 'fees' => wpinv_price(wpinv_format_amount($submission->get_total_fees()), $submission->get_currency()), |
|
1023 | + 'tax' => wpinv_price(wpinv_format_amount($submission->get_total_tax()), $submission->get_currency()), |
|
1024 | + 'total' => wpinv_price(wpinv_format_amount($submission->get_total()), $submission->get_currency()), |
|
1025 | 1025 | ), |
1026 | 1026 | |
1027 | 1027 | 'texts' => array( |
1028 | - '.getpaid-checkout-total-payable' => wpinv_price( wpinv_format_amount( $submission->get_total() ), $submission->get_currency() ), |
|
1028 | + '.getpaid-checkout-total-payable' => wpinv_price(wpinv_format_amount($submission->get_total()), $submission->get_currency()), |
|
1029 | 1029 | ) |
1030 | 1030 | |
1031 | 1031 | ); |
1032 | 1032 | |
1033 | 1033 | // Add items. |
1034 | 1034 | $items = $submission->get_items(); |
1035 | - if ( ! empty( $items ) ) { |
|
1035 | + if (!empty($items)) { |
|
1036 | 1036 | $result['items'] = array(); |
1037 | 1037 | |
1038 | - foreach( $items as $item_id => $item ) { |
|
1039 | - $result['items']["$item_id"] = wpinv_price( wpinv_format_amount( $item->get_price() * $item->get_quantity() ) ); |
|
1038 | + foreach ($items as $item_id => $item) { |
|
1039 | + $result['items']["$item_id"] = wpinv_price(wpinv_format_amount($item->get_price() * $item->get_quantity())); |
|
1040 | 1040 | } |
1041 | 1041 | } |
1042 | 1042 | |
1043 | 1043 | // Add invoice. |
1044 | - if ( $submission->has_invoice() ) { |
|
1044 | + if ($submission->has_invoice()) { |
|
1045 | 1045 | $result['invoice'] = $submission->get_invoice()->ID; |
1046 | 1046 | } |
1047 | 1047 | |
1048 | 1048 | // Add discount code. |
1049 | - if ( $submission->has_discount_code() ) { |
|
1049 | + if ($submission->has_discount_code()) { |
|
1050 | 1050 | $result['discount_code'] = $submission->get_discount_code(); |
1051 | 1051 | } |
1052 | 1052 | |
1053 | 1053 | // Filter the result. |
1054 | - $result = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $result, $submission ); |
|
1054 | + $result = apply_filters('getpaid_payment_form_ajax_refresh_prices', $result, $submission); |
|
1055 | 1055 | |
1056 | - wp_send_json_success( $result ); |
|
1056 | + wp_send_json_success($result); |
|
1057 | 1057 | } |
1058 | 1058 | |
1059 | 1059 | /** |
@@ -1064,53 +1064,53 @@ discard block |
||
1064 | 1064 | public static function buy_items() { |
1065 | 1065 | $user_id = get_current_user_id(); |
1066 | 1066 | |
1067 | - if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page |
|
1068 | - wp_send_json( array( |
|
1069 | - 'success' => wp_login_url( wp_get_referer() ) |
|
1070 | - ) ); |
|
1067 | + if (empty($user_id)) { // If not logged in then lets redirect to the login page |
|
1068 | + wp_send_json(array( |
|
1069 | + 'success' => wp_login_url(wp_get_referer()) |
|
1070 | + )); |
|
1071 | 1071 | } else { |
1072 | 1072 | // Only check nonce if logged in as it could be cached when logged out. |
1073 | - if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) { |
|
1074 | - wp_send_json( array( |
|
1075 | - 'error' => __( 'Security checks failed.', 'invoicing' ) |
|
1076 | - ) ); |
|
1073 | + if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) { |
|
1074 | + wp_send_json(array( |
|
1075 | + 'error' => __('Security checks failed.', 'invoicing') |
|
1076 | + )); |
|
1077 | 1077 | wp_die(); |
1078 | 1078 | } |
1079 | 1079 | |
1080 | 1080 | // allow to set a custom price through post_id |
1081 | 1081 | $items = $_POST['items']; |
1082 | - $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0; |
|
1083 | - $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0; |
|
1082 | + $related_post_id = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0; |
|
1083 | + $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0; |
|
1084 | 1084 | |
1085 | 1085 | $cart_items = array(); |
1086 | - if ( $items ) { |
|
1087 | - $items = explode( ',', $items ); |
|
1086 | + if ($items) { |
|
1087 | + $items = explode(',', $items); |
|
1088 | 1088 | |
1089 | - foreach( $items as $item ) { |
|
1089 | + foreach ($items as $item) { |
|
1090 | 1090 | $item_id = $item; |
1091 | 1091 | $quantity = 1; |
1092 | 1092 | |
1093 | - if ( strpos( $item, '|' ) !== false ) { |
|
1094 | - $item_parts = explode( '|', $item ); |
|
1093 | + if (strpos($item, '|') !== false) { |
|
1094 | + $item_parts = explode('|', $item); |
|
1095 | 1095 | $item_id = $item_parts[0]; |
1096 | 1096 | $quantity = $item_parts[1]; |
1097 | 1097 | } |
1098 | 1098 | |
1099 | - if ( $item_id && $quantity ) { |
|
1099 | + if ($item_id && $quantity) { |
|
1100 | 1100 | $cart_items_arr = array( |
1101 | - 'id' => (int)$item_id, |
|
1102 | - 'quantity' => (int)$quantity |
|
1101 | + 'id' => (int) $item_id, |
|
1102 | + 'quantity' => (int) $quantity |
|
1103 | 1103 | ); |
1104 | 1104 | |
1105 | 1105 | // If there is a related post id then add it to meta |
1106 | - if ( $related_post_id ) { |
|
1106 | + if ($related_post_id) { |
|
1107 | 1107 | $cart_items_arr['meta'] = array( |
1108 | 1108 | 'post_id' => $related_post_id |
1109 | 1109 | ); |
1110 | 1110 | } |
1111 | 1111 | |
1112 | 1112 | // If there is a custom price then set it. |
1113 | - if ( $custom_item_price ) { |
|
1113 | + if ($custom_item_price) { |
|
1114 | 1114 | $cart_items_arr['custom_price'] = $custom_item_price; |
1115 | 1115 | } |
1116 | 1116 | |
@@ -1126,37 +1126,37 @@ discard block |
||
1126 | 1126 | * @param int $related_post_id The related post id if any. |
1127 | 1127 | * @since 1.0.0 |
1128 | 1128 | */ |
1129 | - $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id ); |
|
1129 | + $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id); |
|
1130 | 1130 | |
1131 | 1131 | // Make sure its not in the cart already, if it is then redirect to checkout. |
1132 | 1132 | $cart_invoice = wpinv_get_invoice_cart(); |
1133 | 1133 | |
1134 | - if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) { |
|
1135 | - wp_send_json( array( |
|
1134 | + if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) { |
|
1135 | + wp_send_json(array( |
|
1136 | 1136 | 'success' => $cart_invoice->get_checkout_payment_url() |
1137 | - ) ); |
|
1137 | + )); |
|
1138 | 1138 | wp_die(); |
1139 | 1139 | } |
1140 | 1140 | |
1141 | 1141 | // Check if user has invoice with same items waiting to be paid. |
1142 | - $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' ); |
|
1143 | - if ( !empty( $user_invoices ) ) { |
|
1144 | - foreach( $user_invoices as $user_invoice ) { |
|
1142 | + $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending'); |
|
1143 | + if (!empty($user_invoices)) { |
|
1144 | + foreach ($user_invoices as $user_invoice) { |
|
1145 | 1145 | $user_cart_details = array(); |
1146 | - $invoice = wpinv_get_invoice( $user_invoice->ID ); |
|
1146 | + $invoice = wpinv_get_invoice($user_invoice->ID); |
|
1147 | 1147 | $cart_details = $invoice->get_cart_details(); |
1148 | 1148 | |
1149 | - if ( !empty( $cart_details ) ) { |
|
1150 | - foreach ( $cart_details as $invoice_item ) { |
|
1149 | + if (!empty($cart_details)) { |
|
1150 | + foreach ($cart_details as $invoice_item) { |
|
1151 | 1151 | $ii_arr = array(); |
1152 | - $ii_arr['id'] = (int)$invoice_item['id']; |
|
1153 | - $ii_arr['quantity'] = (int)$invoice_item['quantity']; |
|
1152 | + $ii_arr['id'] = (int) $invoice_item['id']; |
|
1153 | + $ii_arr['quantity'] = (int) $invoice_item['quantity']; |
|
1154 | 1154 | |
1155 | - if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) { |
|
1155 | + if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) { |
|
1156 | 1156 | $ii_arr['meta'] = $invoice_item['meta']; |
1157 | 1157 | } |
1158 | 1158 | |
1159 | - if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) { |
|
1159 | + if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) { |
|
1160 | 1160 | $ii_arr['custom_price'] = $invoice_item['custom_price']; |
1161 | 1161 | } |
1162 | 1162 | |
@@ -1164,17 +1164,17 @@ discard block |
||
1164 | 1164 | } |
1165 | 1165 | } |
1166 | 1166 | |
1167 | - if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) { |
|
1168 | - wp_send_json( array( |
|
1167 | + if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) { |
|
1168 | + wp_send_json(array( |
|
1169 | 1169 | 'success' => $invoice->get_checkout_payment_url() |
1170 | - ) ); |
|
1170 | + )); |
|
1171 | 1171 | wp_die(); |
1172 | 1172 | } |
1173 | 1173 | } |
1174 | 1174 | } |
1175 | 1175 | |
1176 | 1176 | // Create invoice and send user to checkout |
1177 | - if ( !empty( $cart_items ) ) { |
|
1177 | + if (!empty($cart_items)) { |
|
1178 | 1178 | $invoice_data = array( |
1179 | 1179 | 'status' => 'wpi-pending', |
1180 | 1180 | 'created_via' => 'wpi', |
@@ -1182,21 +1182,21 @@ discard block |
||
1182 | 1182 | 'cart_details' => $cart_items, |
1183 | 1183 | ); |
1184 | 1184 | |
1185 | - $invoice = wpinv_insert_invoice( $invoice_data, true ); |
|
1185 | + $invoice = wpinv_insert_invoice($invoice_data, true); |
|
1186 | 1186 | |
1187 | - if ( !empty( $invoice ) && isset( $invoice->ID ) ) { |
|
1188 | - wp_send_json( array( |
|
1187 | + if (!empty($invoice) && isset($invoice->ID)) { |
|
1188 | + wp_send_json(array( |
|
1189 | 1189 | 'success' => $invoice->get_checkout_payment_url() |
1190 | - ) ); |
|
1190 | + )); |
|
1191 | 1191 | } else { |
1192 | - wp_send_json( array( |
|
1193 | - 'error' => __( 'Invoice failed to create', 'invoicing' ) |
|
1194 | - ) ); |
|
1192 | + wp_send_json(array( |
|
1193 | + 'error' => __('Invoice failed to create', 'invoicing') |
|
1194 | + )); |
|
1195 | 1195 | } |
1196 | 1196 | } else { |
1197 | - wp_send_json( array( |
|
1198 | - 'error' => __( 'Items not valid.', 'invoicing' ) |
|
1199 | - ) ); |
|
1197 | + wp_send_json(array( |
|
1198 | + 'error' => __('Items not valid.', 'invoicing') |
|
1199 | + )); |
|
1200 | 1200 | } |
1201 | 1201 | } |
1202 | 1202 |
@@ -268,26 +268,26 @@ discard block |
||
268 | 268 | } |
269 | 269 | |
270 | 270 | function wpinv_get_chosen_gateway( $invoice_id = 0 ) { |
271 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
271 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
272 | 272 | |
273 | 273 | $chosen = false; |
274 | 274 | if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) { |
275 | 275 | $chosen = $invoice->get_gateway(); |
276 | 276 | } |
277 | 277 | |
278 | - $chosen = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen; |
|
278 | + $chosen = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen; |
|
279 | 279 | |
280 | - if ( false !== $chosen ) { |
|
281 | - $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen ); |
|
282 | - } |
|
280 | + if ( false !== $chosen ) { |
|
281 | + $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen ); |
|
282 | + } |
|
283 | 283 | |
284 | - if ( ! empty ( $chosen ) ) { |
|
285 | - $enabled_gateway = urldecode( $chosen ); |
|
286 | - } else if ( !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) { |
|
287 | - $enabled_gateway = 'manual'; |
|
288 | - } else { |
|
289 | - $enabled_gateway = wpinv_get_default_gateway(); |
|
290 | - } |
|
284 | + if ( ! empty ( $chosen ) ) { |
|
285 | + $enabled_gateway = urldecode( $chosen ); |
|
286 | + } else if ( !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) { |
|
287 | + $enabled_gateway = 'manual'; |
|
288 | + } else { |
|
289 | + $enabled_gateway = wpinv_get_default_gateway(); |
|
290 | + } |
|
291 | 291 | |
292 | 292 | if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) { |
293 | 293 | if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){ |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | |
299 | 299 | } |
300 | 300 | |
301 | - return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway ); |
|
301 | + return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway ); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | function wpinv_record_gateway_error( $title = '', $message = '', $parent = 0 ) { |
@@ -306,21 +306,21 @@ discard block |
||
306 | 306 | } |
307 | 307 | |
308 | 308 | function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) { |
309 | - $ret = 0; |
|
310 | - $args = array( |
|
311 | - 'meta_key' => '_wpinv_gateway', |
|
312 | - 'meta_value' => $gateway_id, |
|
313 | - 'nopaging' => true, |
|
314 | - 'post_type' => 'wpi_invoice', |
|
315 | - 'post_status' => $status, |
|
316 | - 'fields' => 'ids' |
|
317 | - ); |
|
309 | + $ret = 0; |
|
310 | + $args = array( |
|
311 | + 'meta_key' => '_wpinv_gateway', |
|
312 | + 'meta_value' => $gateway_id, |
|
313 | + 'nopaging' => true, |
|
314 | + 'post_type' => 'wpi_invoice', |
|
315 | + 'post_status' => $status, |
|
316 | + 'fields' => 'ids' |
|
317 | + ); |
|
318 | 318 | |
319 | - $payments = new WP_Query( $args ); |
|
319 | + $payments = new WP_Query( $args ); |
|
320 | 320 | |
321 | - if( $payments ) |
|
322 | - $ret = $payments->post_count; |
|
323 | - return $ret; |
|
321 | + if( $payments ) |
|
322 | + $ret = $payments->post_count; |
|
323 | + return $ret; |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | function wpinv_settings_update_gateways( $input ) { |
@@ -854,7 +854,7 @@ discard block |
||
854 | 854 | $required_fields = wpinv_checkout_required_fields(); |
855 | 855 | |
856 | 856 | // Loop through required fields and show error messages |
857 | - if ( !empty( $required_fields ) ) { |
|
857 | + if ( !empty( $required_fields ) ) { |
|
858 | 858 | foreach ( $required_fields as $field_name => $value ) { |
859 | 859 | if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) { |
860 | 860 | wpinv_set_error( $value['error_id'], $value['error_message'] ); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Returns an array of payment gateways. |
@@ -13,188 +13,188 @@ discard block |
||
13 | 13 | // Default, built-in gateways |
14 | 14 | $gateways = array( |
15 | 15 | 'authorizenet' => array( |
16 | - 'admin_label' => __( 'Authorize.Net (AIM)', 'invoicing' ), |
|
17 | - 'checkout_label' => __( 'Authorize.Net - Credit Card / Debit Card', 'invoicing' ), |
|
16 | + 'admin_label' => __('Authorize.Net (AIM)', 'invoicing'), |
|
17 | + 'checkout_label' => __('Authorize.Net - Credit Card / Debit Card', 'invoicing'), |
|
18 | 18 | 'ordering' => 4, |
19 | 19 | ), |
20 | 20 | 'worldpay' => array( |
21 | - 'admin_label' => __( 'Worldpay', 'invoicing' ), |
|
22 | - 'checkout_label' => __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ), |
|
21 | + 'admin_label' => __('Worldpay', 'invoicing'), |
|
22 | + 'checkout_label' => __('Worldpay - Credit Card / Debit Card', 'invoicing'), |
|
23 | 23 | 'ordering' => 5, |
24 | 24 | ), |
25 | 25 | 'bank_transfer' => array( |
26 | - 'admin_label' => __( 'Pre Bank Transfer', 'invoicing' ), |
|
27 | - 'checkout_label' => __( 'Pre Bank Transfer', 'invoicing' ), |
|
26 | + 'admin_label' => __('Pre Bank Transfer', 'invoicing'), |
|
27 | + 'checkout_label' => __('Pre Bank Transfer', 'invoicing'), |
|
28 | 28 | 'ordering' => 11, |
29 | 29 | ), |
30 | 30 | ); |
31 | 31 | |
32 | - return apply_filters( 'wpinv_payment_gateways', $gateways ); |
|
32 | + return apply_filters('wpinv_payment_gateways', $gateways); |
|
33 | 33 | } |
34 | 34 | |
35 | -function wpinv_payment_gateway_titles( $all_gateways ) { |
|
35 | +function wpinv_payment_gateway_titles($all_gateways) { |
|
36 | 36 | global $wpinv_options; |
37 | 37 | |
38 | 38 | $gateways = array(); |
39 | - foreach ( $all_gateways as $key => $gateway ) { |
|
40 | - if ( !empty( $wpinv_options[$key . '_title'] ) ) { |
|
41 | - $all_gateways[$key]['checkout_label'] = __( $wpinv_options[$key . '_title'], 'invoicing' ); |
|
39 | + foreach ($all_gateways as $key => $gateway) { |
|
40 | + if (!empty($wpinv_options[$key . '_title'])) { |
|
41 | + $all_gateways[$key]['checkout_label'] = __($wpinv_options[$key . '_title'], 'invoicing'); |
|
42 | 42 | } |
43 | 43 | |
44 | - $gateways[$key] = isset( $wpinv_options[$key . '_ordering'] ) ? $wpinv_options[$key . '_ordering'] : ( isset( $gateway['ordering'] ) ? $gateway['ordering'] : '' ); |
|
44 | + $gateways[$key] = isset($wpinv_options[$key . '_ordering']) ? $wpinv_options[$key . '_ordering'] : (isset($gateway['ordering']) ? $gateway['ordering'] : ''); |
|
45 | 45 | } |
46 | 46 | |
47 | - asort( $gateways ); |
|
47 | + asort($gateways); |
|
48 | 48 | |
49 | - foreach ( $gateways as $gateway => $key ) { |
|
49 | + foreach ($gateways as $gateway => $key) { |
|
50 | 50 | $gateways[$gateway] = $all_gateways[$gateway]; |
51 | 51 | } |
52 | 52 | |
53 | 53 | return $gateways; |
54 | 54 | } |
55 | -add_filter( 'wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1 ); |
|
55 | +add_filter('wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1); |
|
56 | 56 | |
57 | -function wpinv_get_enabled_payment_gateways( $sort = false ) { |
|
57 | +function wpinv_get_enabled_payment_gateways($sort = false) { |
|
58 | 58 | $gateways = wpinv_get_payment_gateways(); |
59 | - $enabled = wpinv_get_option( 'gateways', false ); |
|
59 | + $enabled = wpinv_get_option('gateways', false); |
|
60 | 60 | |
61 | 61 | $gateway_list = array(); |
62 | 62 | |
63 | - foreach ( $gateways as $key => $gateway ) { |
|
64 | - if ( isset( $enabled[ $key ] ) && $enabled[ $key ] == 1 ) { |
|
65 | - $gateway_list[ $key ] = $gateway; |
|
63 | + foreach ($gateways as $key => $gateway) { |
|
64 | + if (isset($enabled[$key]) && $enabled[$key] == 1) { |
|
65 | + $gateway_list[$key] = $gateway; |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 | |
69 | - if ( true === $sort ) { |
|
70 | - uasort( $gateway_list, 'wpinv_sort_gateway_order' ); |
|
69 | + if (true === $sort) { |
|
70 | + uasort($gateway_list, 'wpinv_sort_gateway_order'); |
|
71 | 71 | |
72 | 72 | // Reorder our gateways so the default is first |
73 | 73 | $default_gateway_id = wpinv_get_default_gateway(); |
74 | 74 | |
75 | - if ( wpinv_is_gateway_active( $default_gateway_id ) ) { |
|
76 | - $default_gateway = array( $default_gateway_id => $gateway_list[ $default_gateway_id ] ); |
|
77 | - unset( $gateway_list[ $default_gateway_id ] ); |
|
75 | + if (wpinv_is_gateway_active($default_gateway_id)) { |
|
76 | + $default_gateway = array($default_gateway_id => $gateway_list[$default_gateway_id]); |
|
77 | + unset($gateway_list[$default_gateway_id]); |
|
78 | 78 | |
79 | - $gateway_list = array_merge( $default_gateway, $gateway_list ); |
|
79 | + $gateway_list = array_merge($default_gateway, $gateway_list); |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | |
83 | - return apply_filters( 'wpinv_enabled_payment_gateways', $gateway_list ); |
|
83 | + return apply_filters('wpinv_enabled_payment_gateways', $gateway_list); |
|
84 | 84 | } |
85 | 85 | |
86 | -function wpinv_sort_gateway_order( $a, $b ) { |
|
86 | +function wpinv_sort_gateway_order($a, $b) { |
|
87 | 87 | return $a['ordering'] - $b['ordering']; |
88 | 88 | } |
89 | 89 | |
90 | -function wpinv_is_gateway_active( $gateway ) { |
|
90 | +function wpinv_is_gateway_active($gateway) { |
|
91 | 91 | $gateways = wpinv_get_enabled_payment_gateways(); |
92 | 92 | |
93 | - $ret = is_array($gateways) && $gateway ? array_key_exists( $gateway, $gateways ) : false; |
|
93 | + $ret = is_array($gateways) && $gateway ? array_key_exists($gateway, $gateways) : false; |
|
94 | 94 | |
95 | - return apply_filters( 'wpinv_is_gateway_active', $ret, $gateway, $gateways ); |
|
95 | + return apply_filters('wpinv_is_gateway_active', $ret, $gateway, $gateways); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | function wpinv_get_default_gateway() { |
99 | - $default = wpinv_get_option( 'default_gateway', 'paypal' ); |
|
99 | + $default = wpinv_get_option('default_gateway', 'paypal'); |
|
100 | 100 | |
101 | - if ( !wpinv_is_gateway_active( $default ) ) { |
|
101 | + if (!wpinv_is_gateway_active($default)) { |
|
102 | 102 | $gateways = wpinv_get_enabled_payment_gateways(); |
103 | - $gateways = array_keys( $gateways ); |
|
104 | - $default = reset( $gateways ); |
|
103 | + $gateways = array_keys($gateways); |
|
104 | + $default = reset($gateways); |
|
105 | 105 | } |
106 | 106 | |
107 | - return apply_filters( 'wpinv_default_gateway', $default ); |
|
107 | + return apply_filters('wpinv_default_gateway', $default); |
|
108 | 108 | } |
109 | 109 | |
110 | -function wpinv_get_gateway_admin_label( $gateway ) { |
|
110 | +function wpinv_get_gateway_admin_label($gateway) { |
|
111 | 111 | $gateways = wpinv_get_payment_gateways(); |
112 | - $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway; |
|
113 | - $payment = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : false; |
|
112 | + $label = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway; |
|
113 | + $payment = isset($_GET['id']) ? absint($_GET['id']) : false; |
|
114 | 114 | |
115 | - if( $gateway == 'manual' && $payment ) { |
|
116 | - if( !( (float)wpinv_payment_total( $payment ) > 0 ) ) { |
|
117 | - $label = __( 'Free Purchase', 'invoicing' ); |
|
115 | + if ($gateway == 'manual' && $payment) { |
|
116 | + if (!((float) wpinv_payment_total($payment) > 0)) { |
|
117 | + $label = __('Free Purchase', 'invoicing'); |
|
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
121 | - return apply_filters( 'wpinv_gateway_admin_label', $label, $gateway ); |
|
121 | + return apply_filters('wpinv_gateway_admin_label', $label, $gateway); |
|
122 | 122 | } |
123 | 123 | |
124 | -function wpinv_get_gateway_description( $gateway ) { |
|
124 | +function wpinv_get_gateway_description($gateway) { |
|
125 | 125 | global $wpinv_options; |
126 | 126 | |
127 | - $description = ! empty( $wpinv_options[$gateway . '_desc'] ) ? $wpinv_options[$gateway . '_desc'] : ''; |
|
127 | + $description = !empty($wpinv_options[$gateway . '_desc']) ? $wpinv_options[$gateway . '_desc'] : ''; |
|
128 | 128 | |
129 | - return apply_filters( 'wpinv_gateway_description', $description, $gateway ); |
|
129 | + return apply_filters('wpinv_gateway_description', $description, $gateway); |
|
130 | 130 | } |
131 | 131 | |
132 | -function wpinv_get_gateway_button_label( $gateway ) { |
|
133 | - return apply_filters( 'wpinv_gateway_' . $gateway . '_button_label', '' ); |
|
132 | +function wpinv_get_gateway_button_label($gateway) { |
|
133 | + return apply_filters('wpinv_gateway_' . $gateway . '_button_label', ''); |
|
134 | 134 | } |
135 | 135 | |
136 | -function wpinv_get_gateway_checkout_label( $gateway ) { |
|
136 | +function wpinv_get_gateway_checkout_label($gateway) { |
|
137 | 137 | $gateways = wpinv_get_payment_gateways(); |
138 | - $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway; |
|
138 | + $label = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway; |
|
139 | 139 | |
140 | - if( $gateway == 'manual' ) { |
|
141 | - $label = __( 'Manual Payment', 'invoicing' ); |
|
140 | + if ($gateway == 'manual') { |
|
141 | + $label = __('Manual Payment', 'invoicing'); |
|
142 | 142 | } |
143 | 143 | |
144 | - return apply_filters( 'wpinv_gateway_checkout_label', ucfirst( $label ), $gateway ); |
|
144 | + return apply_filters('wpinv_gateway_checkout_label', ucfirst($label), $gateway); |
|
145 | 145 | } |
146 | 146 | |
147 | -function wpinv_settings_sections_gateways( $settings ) { |
|
147 | +function wpinv_settings_sections_gateways($settings) { |
|
148 | 148 | $gateways = wpinv_get_payment_gateways(); |
149 | 149 | |
150 | 150 | if (!empty($gateways)) { |
151 | - foreach ($gateways as $key => $gateway) { |
|
151 | + foreach ($gateways as $key => $gateway) { |
|
152 | 152 | $settings[$key] = $gateway['admin_label']; |
153 | 153 | } |
154 | 154 | } |
155 | 155 | |
156 | 156 | return $settings; |
157 | 157 | } |
158 | -add_filter( 'wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1 ); |
|
158 | +add_filter('wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1); |
|
159 | 159 | |
160 | -function wpinv_settings_gateways( $settings ) { |
|
160 | +function wpinv_settings_gateways($settings) { |
|
161 | 161 | $gateways = wpinv_get_payment_gateways(); |
162 | 162 | |
163 | 163 | if (!empty($gateways)) { |
164 | - foreach ($gateways as $key => $gateway) { |
|
164 | + foreach ($gateways as $key => $gateway) { |
|
165 | 165 | $setting = array(); |
166 | 166 | $setting[$key . '_header'] = array( |
167 | 167 | 'id' => 'gateway_header', |
168 | - 'name' => '<h3>' . wp_sprintf( __( '%s Settings', 'invoicing' ), $gateway['admin_label'] ) . '</h3>', |
|
168 | + 'name' => '<h3>' . wp_sprintf(__('%s Settings', 'invoicing'), $gateway['admin_label']) . '</h3>', |
|
169 | 169 | 'custom' => $key, |
170 | 170 | 'type' => 'gateway_header', |
171 | 171 | ); |
172 | 172 | $setting[$key . '_active'] = array( |
173 | 173 | 'id' => $key . '_active', |
174 | - 'name' => __( 'Active', 'invoicing' ), |
|
175 | - 'desc' => wp_sprintf( __( 'Enable %s', 'invoicing' ), $gateway['admin_label'] ), |
|
174 | + 'name' => __('Active', 'invoicing'), |
|
175 | + 'desc' => wp_sprintf(__('Enable %s', 'invoicing'), $gateway['admin_label']), |
|
176 | 176 | 'type' => 'checkbox', |
177 | 177 | ); |
178 | 178 | |
179 | 179 | $setting[$key . '_title'] = array( |
180 | 180 | 'id' => $key . '_title', |
181 | - 'name' => __( 'Title', 'invoicing' ), |
|
182 | - 'desc' => __( 'This controls the title which the user sees during checkout.', 'invoicing' ), |
|
181 | + 'name' => __('Title', 'invoicing'), |
|
182 | + 'desc' => __('This controls the title which the user sees during checkout.', 'invoicing'), |
|
183 | 183 | 'type' => 'text', |
184 | 184 | 'std' => isset($gateway['checkout_label']) ? $gateway['checkout_label'] : '' |
185 | 185 | ); |
186 | 186 | |
187 | 187 | $setting[$key . '_desc'] = array( |
188 | 188 | 'id' => $key . '_desc', |
189 | - 'name' => __( 'Description', 'invoicing' ), |
|
190 | - 'desc' => __( 'This controls the description which the user sees during checkout.', 'invoicing' ), |
|
189 | + 'name' => __('Description', 'invoicing'), |
|
190 | + 'desc' => __('This controls the description which the user sees during checkout.', 'invoicing'), |
|
191 | 191 | 'type' => 'text', |
192 | 192 | 'size' => 'large' |
193 | 193 | ); |
194 | 194 | |
195 | 195 | $setting[$key . '_ordering'] = array( |
196 | 196 | 'id' => $key . '_ordering', |
197 | - 'name' => __( 'Display Order', 'invoicing' ), |
|
197 | + 'name' => __('Display Order', 'invoicing'), |
|
198 | 198 | 'type' => 'number', |
199 | 199 | 'size' => 'small', |
200 | 200 | 'std' => isset($gateway['ordering']) ? $gateway['ordering'] : '10', |
@@ -203,8 +203,8 @@ discard block |
||
203 | 203 | 'step' => '1' |
204 | 204 | ); |
205 | 205 | |
206 | - $setting = apply_filters( 'wpinv_gateway_settings', $setting, $key ); |
|
207 | - $setting = apply_filters( 'wpinv_gateway_settings_' . $key, $setting ); |
|
206 | + $setting = apply_filters('wpinv_gateway_settings', $setting, $key); |
|
207 | + $setting = apply_filters('wpinv_gateway_settings_' . $key, $setting); |
|
208 | 208 | |
209 | 209 | $settings[$key] = $setting; |
210 | 210 | } |
@@ -212,38 +212,38 @@ discard block |
||
212 | 212 | |
213 | 213 | return $settings; |
214 | 214 | } |
215 | -add_filter( 'wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1 ); |
|
215 | +add_filter('wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1); |
|
216 | 216 | |
217 | -function wpinv_gateway_header_callback( $args ) { |
|
218 | - echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr( $args['custom'] ) . '" />'; |
|
217 | +function wpinv_gateway_header_callback($args) { |
|
218 | + echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr($args['custom']) . '" />'; |
|
219 | 219 | } |
220 | 220 | |
221 | -function wpinv_get_gateway_supports( $gateway ) { |
|
221 | +function wpinv_get_gateway_supports($gateway) { |
|
222 | 222 | $gateways = wpinv_get_enabled_payment_gateways(); |
223 | - $supports = isset( $gateways[ $gateway ]['supports'] ) ? $gateways[ $gateway ]['supports'] : array(); |
|
224 | - return apply_filters( 'wpinv_gateway_supports', $supports, $gateway ); |
|
223 | + $supports = isset($gateways[$gateway]['supports']) ? $gateways[$gateway]['supports'] : array(); |
|
224 | + return apply_filters('wpinv_gateway_supports', $supports, $gateway); |
|
225 | 225 | } |
226 | 226 | |
227 | -function wpinv_gateway_supports_buy_now( $gateway ) { |
|
228 | - $supports = wpinv_get_gateway_supports( $gateway ); |
|
229 | - $ret = in_array( 'buy_now', $supports ); |
|
230 | - return apply_filters( 'wpinv_gateway_supports_buy_now', $ret, $gateway ); |
|
227 | +function wpinv_gateway_supports_buy_now($gateway) { |
|
228 | + $supports = wpinv_get_gateway_supports($gateway); |
|
229 | + $ret = in_array('buy_now', $supports); |
|
230 | + return apply_filters('wpinv_gateway_supports_buy_now', $ret, $gateway); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | function wpinv_shop_supports_buy_now() { |
234 | 234 | $gateways = wpinv_get_enabled_payment_gateways(); |
235 | 235 | $ret = false; |
236 | 236 | |
237 | - if ( !wpinv_use_taxes() && $gateways ) { |
|
238 | - foreach ( $gateways as $gateway_id => $gateway ) { |
|
239 | - if ( wpinv_gateway_supports_buy_now( $gateway_id ) ) { |
|
237 | + if (!wpinv_use_taxes() && $gateways) { |
|
238 | + foreach ($gateways as $gateway_id => $gateway) { |
|
239 | + if (wpinv_gateway_supports_buy_now($gateway_id)) { |
|
240 | 240 | $ret = true; |
241 | 241 | break; |
242 | 242 | } |
243 | 243 | } |
244 | 244 | } |
245 | 245 | |
246 | - return apply_filters( 'wpinv_shop_supports_buy_now', $ret ); |
|
246 | + return apply_filters('wpinv_shop_supports_buy_now', $ret); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | |
@@ -251,61 +251,61 @@ discard block |
||
251 | 251 | $gateways = wpinv_get_enabled_payment_gateways(); |
252 | 252 | $show_gateways = false; |
253 | 253 | |
254 | - $chosen_gateway = isset( $_GET['payment-mode'] ) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode'] ) : false; |
|
254 | + $chosen_gateway = isset($_GET['payment-mode']) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode']) : false; |
|
255 | 255 | |
256 | - if ( count( $gateways ) > 1 && empty( $chosen_gateway ) ) { |
|
256 | + if (count($gateways) > 1 && empty($chosen_gateway)) { |
|
257 | 257 | $show_gateways = true; |
258 | - if ( wpinv_get_cart_total() <= 0 ) { |
|
258 | + if (wpinv_get_cart_total() <= 0) { |
|
259 | 259 | $show_gateways = false; |
260 | 260 | } |
261 | 261 | } |
262 | 262 | |
263 | - if ( !$show_gateways && wpinv_cart_has_recurring_item() ) { |
|
263 | + if (!$show_gateways && wpinv_cart_has_recurring_item()) { |
|
264 | 264 | $show_gateways = true; |
265 | 265 | } |
266 | 266 | |
267 | - return apply_filters( 'wpinv_show_gateways', $show_gateways ); |
|
267 | + return apply_filters('wpinv_show_gateways', $show_gateways); |
|
268 | 268 | } |
269 | 269 | |
270 | -function wpinv_get_chosen_gateway( $invoice_id = 0 ) { |
|
271 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
270 | +function wpinv_get_chosen_gateway($invoice_id = 0) { |
|
271 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
272 | 272 | |
273 | 273 | $chosen = false; |
274 | - if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
274 | + if ($invoice_id > 0 && $invoice = wpinv_get_invoice($invoice_id)) { |
|
275 | 275 | $chosen = $invoice->get_gateway(); |
276 | 276 | } |
277 | 277 | |
278 | - $chosen = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen; |
|
278 | + $chosen = isset($_REQUEST['payment-mode']) ? sanitize_text_field($_REQUEST['payment-mode']) : $chosen; |
|
279 | 279 | |
280 | - if ( false !== $chosen ) { |
|
281 | - $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen ); |
|
280 | + if (false !== $chosen) { |
|
281 | + $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen); |
|
282 | 282 | } |
283 | 283 | |
284 | - if ( ! empty ( $chosen ) ) { |
|
285 | - $enabled_gateway = urldecode( $chosen ); |
|
286 | - } else if ( !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) { |
|
284 | + if (!empty ($chosen)) { |
|
285 | + $enabled_gateway = urldecode($chosen); |
|
286 | + } else if (!empty($invoice) && (float) $invoice->get_subtotal() <= 0) { |
|
287 | 287 | $enabled_gateway = 'manual'; |
288 | 288 | } else { |
289 | 289 | $enabled_gateway = wpinv_get_default_gateway(); |
290 | 290 | } |
291 | 291 | |
292 | - if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) { |
|
293 | - if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){ |
|
292 | + if (!wpinv_is_gateway_active($enabled_gateway) && !empty($gateways)) { |
|
293 | + if (wpinv_is_gateway_active(wpinv_get_default_gateway())) { |
|
294 | 294 | $enabled_gateway = wpinv_get_default_gateway(); |
295 | - }else{ |
|
295 | + } else { |
|
296 | 296 | $enabled_gateway = $gateways[0]; |
297 | 297 | } |
298 | 298 | |
299 | 299 | } |
300 | 300 | |
301 | - return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway ); |
|
301 | + return apply_filters('wpinv_chosen_gateway', $enabled_gateway); |
|
302 | 302 | } |
303 | 303 | |
304 | -function wpinv_record_gateway_error( $title = '', $message = '', $parent = 0 ) { |
|
305 | - return wpinv_error_log( $message, $title ); |
|
304 | +function wpinv_record_gateway_error($title = '', $message = '', $parent = 0) { |
|
305 | + return wpinv_error_log($message, $title); |
|
306 | 306 | } |
307 | 307 | |
308 | -function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) { |
|
308 | +function wpinv_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') { |
|
309 | 309 | $ret = 0; |
310 | 310 | $args = array( |
311 | 311 | 'meta_key' => '_wpinv_gateway', |
@@ -316,48 +316,48 @@ discard block |
||
316 | 316 | 'fields' => 'ids' |
317 | 317 | ); |
318 | 318 | |
319 | - $payments = new WP_Query( $args ); |
|
319 | + $payments = new WP_Query($args); |
|
320 | 320 | |
321 | - if( $payments ) |
|
321 | + if ($payments) |
|
322 | 322 | $ret = $payments->post_count; |
323 | 323 | return $ret; |
324 | 324 | } |
325 | 325 | |
326 | -function wpinv_settings_update_gateways( $input ) { |
|
326 | +function wpinv_settings_update_gateways($input) { |
|
327 | 327 | global $wpinv_options; |
328 | 328 | |
329 | - if ( !empty( $input['save_gateway'] ) ) { |
|
330 | - $gateways = wpinv_get_option( 'gateways', false ); |
|
329 | + if (!empty($input['save_gateway'])) { |
|
330 | + $gateways = wpinv_get_option('gateways', false); |
|
331 | 331 | $gateways = !empty($gateways) ? $gateways : array(); |
332 | 332 | $gateway = $input['save_gateway']; |
333 | 333 | |
334 | - if ( !empty( $input[$gateway . '_active'] ) ) { |
|
334 | + if (!empty($input[$gateway . '_active'])) { |
|
335 | 335 | $gateways[$gateway] = 1; |
336 | 336 | } else { |
337 | - if ( isset( $gateways[$gateway] ) ) { |
|
338 | - unset( $gateways[$gateway] ); |
|
337 | + if (isset($gateways[$gateway])) { |
|
338 | + unset($gateways[$gateway]); |
|
339 | 339 | } |
340 | 340 | } |
341 | 341 | |
342 | 342 | $input['gateways'] = $gateways; |
343 | 343 | } |
344 | 344 | |
345 | - if ( !empty( $input['default_gateway'] ) ) { |
|
345 | + if (!empty($input['default_gateway'])) { |
|
346 | 346 | $gateways = wpinv_get_payment_gateways(); |
347 | 347 | |
348 | - foreach ( $gateways as $key => $gateway ) { |
|
349 | - $active = 0; |
|
350 | - if ( !empty( $input['gateways'] ) && !empty( $input['gateways'][$key] ) ) { |
|
348 | + foreach ($gateways as $key => $gateway) { |
|
349 | + $active = 0; |
|
350 | + if (!empty($input['gateways']) && !empty($input['gateways'][$key])) { |
|
351 | 351 | $active = 1; |
352 | 352 | } |
353 | 353 | |
354 | 354 | $input[$key . '_active'] = $active; |
355 | 355 | |
356 | - if ( empty( $wpinv_options[$key . '_title'] ) ) { |
|
356 | + if (empty($wpinv_options[$key . '_title'])) { |
|
357 | 357 | $input[$key . '_title'] = $gateway['checkout_label']; |
358 | 358 | } |
359 | 359 | |
360 | - if ( !isset( $wpinv_options[$key . '_ordering'] ) && isset( $gateway['ordering'] ) ) { |
|
360 | + if (!isset($wpinv_options[$key . '_ordering']) && isset($gateway['ordering'])) { |
|
361 | 361 | $input[$key . '_ordering'] = $gateway['ordering']; |
362 | 362 | } |
363 | 363 | } |
@@ -365,27 +365,27 @@ discard block |
||
365 | 365 | |
366 | 366 | return $input; |
367 | 367 | } |
368 | -add_filter( 'wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1 ); |
|
368 | +add_filter('wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1); |
|
369 | 369 | |
370 | 370 | // PayPal Standard settings |
371 | -function wpinv_gateway_settings_paypal( $setting ) { |
|
372 | - $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing' ); |
|
373 | - $setting['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
|
371 | +function wpinv_gateway_settings_paypal($setting) { |
|
372 | + $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __('( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing'); |
|
373 | + $setting['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing'); |
|
374 | 374 | |
375 | 375 | $setting['paypal_sandbox'] = array( |
376 | 376 | 'type' => 'checkbox', |
377 | 377 | 'id' => 'paypal_sandbox', |
378 | - 'name' => __( 'PayPal Sandbox', 'invoicing' ), |
|
379 | - 'desc' => __( 'PayPal sandbox can be used to test payments.', 'invoicing' ), |
|
378 | + 'name' => __('PayPal Sandbox', 'invoicing'), |
|
379 | + 'desc' => __('PayPal sandbox can be used to test payments.', 'invoicing'), |
|
380 | 380 | 'std' => 1 |
381 | 381 | ); |
382 | 382 | |
383 | 383 | $setting['paypal_email'] = array( |
384 | 384 | 'type' => 'text', |
385 | 385 | 'id' => 'paypal_email', |
386 | - 'name' => __( 'PayPal Email', 'invoicing' ), |
|
387 | - 'desc' => __( 'Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing' ), |
|
388 | - 'std' => __( '[email protected]', 'invoicing' ), |
|
386 | + 'name' => __('PayPal Email', 'invoicing'), |
|
387 | + 'desc' => __('Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing'), |
|
388 | + 'std' => __('[email protected]', 'invoicing'), |
|
389 | 389 | ); |
390 | 390 | /* |
391 | 391 | $setting['paypal_ipn_url'] = array( |
@@ -399,139 +399,139 @@ discard block |
||
399 | 399 | |
400 | 400 | return $setting; |
401 | 401 | } |
402 | -add_filter( 'wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1 ); |
|
402 | +add_filter('wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1); |
|
403 | 403 | |
404 | 404 | // Pre Bank Transfer settings |
405 | -function wpinv_gateway_settings_bank_transfer( $setting ) { |
|
406 | - $setting['bank_transfer_desc']['std'] = __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' ); |
|
405 | +function wpinv_gateway_settings_bank_transfer($setting) { |
|
406 | + $setting['bank_transfer_desc']['std'] = __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing'); |
|
407 | 407 | |
408 | 408 | $setting['bank_transfer_ac_name'] = array( |
409 | 409 | 'type' => 'text', |
410 | 410 | 'id' => 'bank_transfer_ac_name', |
411 | - 'name' => __( 'Account Name', 'invoicing' ), |
|
412 | - 'desc' => __( 'Enter the bank account name to which you want to transfer payment.', 'invoicing' ), |
|
413 | - 'std' => __( 'Mr. John Martin', 'invoicing' ), |
|
411 | + 'name' => __('Account Name', 'invoicing'), |
|
412 | + 'desc' => __('Enter the bank account name to which you want to transfer payment.', 'invoicing'), |
|
413 | + 'std' => __('Mr. John Martin', 'invoicing'), |
|
414 | 414 | ); |
415 | 415 | |
416 | 416 | $setting['bank_transfer_ac_no'] = array( |
417 | 417 | 'type' => 'text', |
418 | 418 | 'id' => 'bank_transfer_ac_no', |
419 | - 'name' => __( 'Account Number', 'invoicing' ), |
|
420 | - 'desc' => __( 'Enter your bank account number.', 'invoicing' ), |
|
421 | - 'std' => __( 'TEST1234567890', 'invoicing' ), |
|
419 | + 'name' => __('Account Number', 'invoicing'), |
|
420 | + 'desc' => __('Enter your bank account number.', 'invoicing'), |
|
421 | + 'std' => __('TEST1234567890', 'invoicing'), |
|
422 | 422 | ); |
423 | 423 | |
424 | 424 | $setting['bank_transfer_bank_name'] = array( |
425 | 425 | 'type' => 'text', |
426 | 426 | 'id' => 'bank_transfer_bank_name', |
427 | - 'name' => __( 'Bank Name', 'invoicing' ), |
|
428 | - 'desc' => __( 'Enter the bank name to which you want to transfer payment.', 'invoicing' ), |
|
429 | - 'std' => __( 'ICICI Bank', 'invoicing' ), |
|
427 | + 'name' => __('Bank Name', 'invoicing'), |
|
428 | + 'desc' => __('Enter the bank name to which you want to transfer payment.', 'invoicing'), |
|
429 | + 'std' => __('ICICI Bank', 'invoicing'), |
|
430 | 430 | ); |
431 | 431 | |
432 | 432 | $setting['bank_transfer_ifsc'] = array( |
433 | 433 | 'type' => 'text', |
434 | 434 | 'id' => 'bank_transfer_ifsc', |
435 | - 'name' => __( 'IFSC Code', 'invoicing' ), |
|
436 | - 'desc' => __( 'Enter your bank IFSC code.', 'invoicing' ), |
|
437 | - 'std' => __( 'ICIC0001234', 'invoicing' ), |
|
435 | + 'name' => __('IFSC Code', 'invoicing'), |
|
436 | + 'desc' => __('Enter your bank IFSC code.', 'invoicing'), |
|
437 | + 'std' => __('ICIC0001234', 'invoicing'), |
|
438 | 438 | ); |
439 | 439 | |
440 | 440 | $setting['bank_transfer_iban'] = array( |
441 | 441 | 'type' => 'text', |
442 | 442 | 'id' => 'bank_transfer_iban', |
443 | - 'name' => __( 'IBAN', 'invoicing' ), |
|
444 | - 'desc' => __( 'Enter your International Bank Account Number(IBAN).', 'invoicing' ), |
|
445 | - 'std' => __( 'GB29NWBK60161331926819', 'invoicing' ), |
|
443 | + 'name' => __('IBAN', 'invoicing'), |
|
444 | + 'desc' => __('Enter your International Bank Account Number(IBAN).', 'invoicing'), |
|
445 | + 'std' => __('GB29NWBK60161331926819', 'invoicing'), |
|
446 | 446 | ); |
447 | 447 | |
448 | 448 | $setting['bank_transfer_bic'] = array( |
449 | 449 | 'type' => 'text', |
450 | 450 | 'id' => 'bank_transfer_bic', |
451 | - 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
|
452 | - 'std' => __( 'ICICGB2L129', 'invoicing' ), |
|
451 | + 'name' => __('BIC/Swift Code', 'invoicing'), |
|
452 | + 'std' => __('ICICGB2L129', 'invoicing'), |
|
453 | 453 | ); |
454 | 454 | |
455 | 455 | $setting['bank_transfer_sort_code'] = array( |
456 | 456 | 'type' => 'text', |
457 | 457 | 'id' => 'bank_transfer_sort_code', |
458 | - 'name' => __( 'Sort Code', 'invoicing' ), |
|
459 | - 'std' => __( '12-34-56', 'invoicing' ), |
|
458 | + 'name' => __('Sort Code', 'invoicing'), |
|
459 | + 'std' => __('12-34-56', 'invoicing'), |
|
460 | 460 | ); |
461 | 461 | |
462 | 462 | $setting['bank_transfer_info'] = array( |
463 | 463 | 'id' => 'bank_transfer_info', |
464 | - 'name' => __( 'Instructions', 'invoicing' ), |
|
465 | - 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
|
464 | + 'name' => __('Instructions', 'invoicing'), |
|
465 | + 'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'), |
|
466 | 466 | 'type' => 'textarea', |
467 | - 'std' => __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' ), |
|
467 | + 'std' => __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing'), |
|
468 | 468 | 'cols' => 37, |
469 | 469 | 'rows' => 5 |
470 | 470 | ); |
471 | 471 | |
472 | 472 | return $setting; |
473 | 473 | } |
474 | -add_filter( 'wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1 ); |
|
474 | +add_filter('wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1); |
|
475 | 475 | |
476 | 476 | // Authorize.Net settings |
477 | -function wpinv_gateway_settings_authorizenet( $setting ) { |
|
478 | - $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing' ); |
|
479 | - $setting['authorizenet_desc']['std'] = __( 'Pay using a Authorize.Net to process Credit card / Debit card transactions.', 'invoicing' ); |
|
477 | +function wpinv_gateway_settings_authorizenet($setting) { |
|
478 | + $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __('( Supported Currencies: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing'); |
|
479 | + $setting['authorizenet_desc']['std'] = __('Pay using a Authorize.Net to process Credit card / Debit card transactions.', 'invoicing'); |
|
480 | 480 | |
481 | 481 | $setting['authorizenet_sandbox'] = array( |
482 | 482 | 'type' => 'checkbox', |
483 | 483 | 'id' => 'authorizenet_sandbox', |
484 | - 'name' => __( 'Authorize.Net Test Mode', 'invoicing' ), |
|
485 | - 'desc' => __( 'Enable Authorize.Net test mode to test payments.', 'invoicing' ), |
|
484 | + 'name' => __('Authorize.Net Test Mode', 'invoicing'), |
|
485 | + 'desc' => __('Enable Authorize.Net test mode to test payments.', 'invoicing'), |
|
486 | 486 | 'std' => 1 |
487 | 487 | ); |
488 | 488 | |
489 | 489 | $setting['authorizenet_login_id'] = array( |
490 | 490 | 'type' => 'text', |
491 | 491 | 'id' => 'authorizenet_login_id', |
492 | - 'name' => __( 'API Login ID', 'invoicing' ), |
|
493 | - 'desc' => __( 'API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing' ), |
|
492 | + 'name' => __('API Login ID', 'invoicing'), |
|
493 | + 'desc' => __('API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing'), |
|
494 | 494 | 'std' => '2j4rBekUnD', |
495 | 495 | ); |
496 | 496 | |
497 | 497 | $setting['authorizenet_transaction_key'] = array( |
498 | 498 | 'type' => 'text', |
499 | 499 | 'id' => 'authorizenet_transaction_key', |
500 | - 'name' => __( 'Transaction Key', 'invoicing' ), |
|
501 | - 'desc' => __( 'Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing' ), |
|
500 | + 'name' => __('Transaction Key', 'invoicing'), |
|
501 | + 'desc' => __('Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing'), |
|
502 | 502 | 'std' => '4vyBUOJgR74679xa', |
503 | 503 | ); |
504 | 504 | |
505 | 505 | $setting['authorizenet_md5_hash'] = array( |
506 | 506 | 'type' => 'text', |
507 | 507 | 'id' => 'authorizenet_md5_hash', |
508 | - 'name' => __( 'MD5-Hash', 'invoicing' ), |
|
509 | - 'desc' => __( 'The MD5 Hash security feature allows to authenticate transaction responses from the Authorize.Net for recurring payments. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing' ), |
|
508 | + 'name' => __('MD5-Hash', 'invoicing'), |
|
509 | + 'desc' => __('The MD5 Hash security feature allows to authenticate transaction responses from the Authorize.Net for recurring payments. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing'), |
|
510 | 510 | 'std' => '', |
511 | 511 | ); |
512 | 512 | |
513 | 513 | $setting['authorizenet_transaction_type'] = array( |
514 | 514 | 'id' => 'authorizenet_transaction_type', |
515 | - 'name' => __( 'Transaction Type', 'invoicing' ), |
|
516 | - 'desc' => __( 'Choose transaction type.', 'invoicing' ), |
|
515 | + 'name' => __('Transaction Type', 'invoicing'), |
|
516 | + 'desc' => __('Choose transaction type.', 'invoicing'), |
|
517 | 517 | 'type' => 'select', |
518 | 518 | 'class' => 'wpi_select2', |
519 | 519 | 'options' => array( |
520 | - 'authorize_capture' => __( 'Authorize And Capture', 'invoicing' ), |
|
521 | - 'authorize_only' => __( 'Authorize Only', 'invoicing' ), |
|
520 | + 'authorize_capture' => __('Authorize And Capture', 'invoicing'), |
|
521 | + 'authorize_only' => __('Authorize Only', 'invoicing'), |
|
522 | 522 | ), |
523 | 523 | 'std' => 'authorize_capture' |
524 | 524 | ); |
525 | 525 | |
526 | 526 | $setting['authorizenet_transaction_type_recurring'] = array( |
527 | 527 | 'id' => 'authorizenet_transaction_type_recurring', |
528 | - 'name' => __( 'Transaction Type for Recurring', 'invoicing' ), |
|
529 | - 'desc' => __( 'Choose transaction type for recurring payments.', 'invoicing' ), |
|
528 | + 'name' => __('Transaction Type for Recurring', 'invoicing'), |
|
529 | + 'desc' => __('Choose transaction type for recurring payments.', 'invoicing'), |
|
530 | 530 | 'type' => 'select', |
531 | 531 | 'class' => 'wpi_select2', |
532 | 532 | 'options' => array( |
533 | - 'authorize_capture' => __( 'Authorize And Capture', 'invoicing' ), |
|
534 | - 'authorize_only' => __( 'Authorize Only', 'invoicing' ), |
|
533 | + 'authorize_capture' => __('Authorize And Capture', 'invoicing'), |
|
534 | + 'authorize_only' => __('Authorize Only', 'invoicing'), |
|
535 | 535 | ), |
536 | 536 | 'std' => 'authorize_only' |
537 | 537 | ); |
@@ -539,9 +539,9 @@ discard block |
||
539 | 539 | $setting['authorizenet_ipn_url'] = array( |
540 | 540 | 'type' => 'ipn_url', |
541 | 541 | 'id' => 'authorizenet_ipn_url', |
542 | - 'name' => __( 'Silent Post URL', 'invoicing' ), |
|
543 | - 'std' => wpinv_get_ipn_url( 'authorizenet' ), |
|
544 | - 'desc' => __( 'If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing' ), |
|
542 | + 'name' => __('Silent Post URL', 'invoicing'), |
|
543 | + 'std' => wpinv_get_ipn_url('authorizenet'), |
|
544 | + 'desc' => __('If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing'), |
|
545 | 545 | 'size' => 'large', |
546 | 546 | 'custom' => 'authorizenet', |
547 | 547 | 'readonly' => true |
@@ -549,26 +549,26 @@ discard block |
||
549 | 549 | |
550 | 550 | return $setting; |
551 | 551 | } |
552 | -add_filter( 'wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1 ); |
|
552 | +add_filter('wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1); |
|
553 | 553 | |
554 | 554 | // Worldpay settings |
555 | -function wpinv_gateway_settings_worldpay( $setting ) { |
|
556 | - $setting['worldpay_active']['desc'] = $setting['worldpay_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, ARS, CAD, CHF, DKK, EUR, HKD, MYR, GBP, NZD, NOK, SGD, LKR, SEK, TRY, USD, ZAR )', 'invoicing' ); |
|
557 | - $setting['worldpay_desc']['std'] = __( 'Pay using a Worldpay account to process Credit card / Debit card transactions.', 'invoicing' ); |
|
555 | +function wpinv_gateway_settings_worldpay($setting) { |
|
556 | + $setting['worldpay_active']['desc'] = $setting['worldpay_active']['desc'] . ' ' . __('( Supported Currencies: AUD, ARS, CAD, CHF, DKK, EUR, HKD, MYR, GBP, NZD, NOK, SGD, LKR, SEK, TRY, USD, ZAR )', 'invoicing'); |
|
557 | + $setting['worldpay_desc']['std'] = __('Pay using a Worldpay account to process Credit card / Debit card transactions.', 'invoicing'); |
|
558 | 558 | |
559 | 559 | $setting['worldpay_sandbox'] = array( |
560 | 560 | 'type' => 'checkbox', |
561 | 561 | 'id' => 'worldpay_sandbox', |
562 | - 'name' => __( 'Worldpay Test Mode', 'invoicing' ), |
|
563 | - 'desc' => __( 'This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing' ), |
|
562 | + 'name' => __('Worldpay Test Mode', 'invoicing'), |
|
563 | + 'desc' => __('This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing'), |
|
564 | 564 | 'std' => 1 |
565 | 565 | ); |
566 | 566 | |
567 | 567 | $setting['worldpay_instId'] = array( |
568 | 568 | 'type' => 'text', |
569 | 569 | 'id' => 'worldpay_instId', |
570 | - 'name' => __( 'Installation Id', 'invoicing' ), |
|
571 | - 'desc' => __( 'Your installation id. Ex: 211616', 'invoicing' ), |
|
570 | + 'name' => __('Installation Id', 'invoicing'), |
|
571 | + 'desc' => __('Your installation id. Ex: 211616', 'invoicing'), |
|
572 | 572 | 'std' => '211616', |
573 | 573 | ); |
574 | 574 | /* |
@@ -584,9 +584,9 @@ discard block |
||
584 | 584 | $setting['worldpay_ipn_url'] = array( |
585 | 585 | 'type' => 'ipn_url', |
586 | 586 | 'id' => 'worldpay_ipn_url', |
587 | - 'name' => __( 'Worldpay Callback Url', 'invoicing' ), |
|
588 | - 'std' => wpinv_get_ipn_url( 'worldpay' ), |
|
589 | - 'desc' => wp_sprintf( __( 'Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing' ), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url( 'worldpay' ) . '</font>', '<font style="color:#000;font-style:normal"><wpdisplay item=MC_callback></font>' ), |
|
587 | + 'name' => __('Worldpay Callback Url', 'invoicing'), |
|
588 | + 'std' => wpinv_get_ipn_url('worldpay'), |
|
589 | + 'desc' => wp_sprintf(__('Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing'), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url('worldpay') . '</font>', '<font style="color:#000;font-style:normal"><wpdisplay item=MC_callback></font>'), |
|
590 | 590 | 'size' => 'large', |
591 | 591 | 'custom' => 'worldpay', |
592 | 592 | 'readonly' => true |
@@ -594,99 +594,99 @@ discard block |
||
594 | 594 | |
595 | 595 | return $setting; |
596 | 596 | } |
597 | -add_filter( 'wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1 ); |
|
597 | +add_filter('wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1); |
|
598 | 598 | |
599 | -function wpinv_ipn_url_callback( $args ) { |
|
600 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
599 | +function wpinv_ipn_url_callback($args) { |
|
600 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
601 | 601 | |
602 | 602 | $attrs = $args['readonly'] ? ' readonly' : ''; |
603 | 603 | |
604 | - $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr( $args['std'] ) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">'; |
|
605 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>'; |
|
604 | + $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr($args['std']) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">'; |
|
605 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>'; |
|
606 | 606 | |
607 | 607 | echo $html; |
608 | 608 | } |
609 | 609 | |
610 | -function wpinv_is_test_mode( $gateway = '' ) { |
|
611 | - if ( empty( $gateway ) ) { |
|
610 | +function wpinv_is_test_mode($gateway = '') { |
|
611 | + if (empty($gateway)) { |
|
612 | 612 | return false; |
613 | 613 | } |
614 | 614 | |
615 | - $is_test_mode = wpinv_get_option( $gateway . '_sandbox', false ); |
|
615 | + $is_test_mode = wpinv_get_option($gateway . '_sandbox', false); |
|
616 | 616 | |
617 | - return apply_filters( 'wpinv_is_test_mode', $is_test_mode, $gateway ); |
|
617 | + return apply_filters('wpinv_is_test_mode', $is_test_mode, $gateway); |
|
618 | 618 | } |
619 | 619 | |
620 | -function wpinv_get_ipn_url( $gateway = '', $args = array() ) { |
|
621 | - $data = array( 'wpi-listener' => 'IPN' ); |
|
620 | +function wpinv_get_ipn_url($gateway = '', $args = array()) { |
|
621 | + $data = array('wpi-listener' => 'IPN'); |
|
622 | 622 | |
623 | - if ( !empty( $gateway ) ) { |
|
624 | - $data['wpi-gateway'] = wpinv_sanitize_key( $gateway ); |
|
623 | + if (!empty($gateway)) { |
|
624 | + $data['wpi-gateway'] = wpinv_sanitize_key($gateway); |
|
625 | 625 | } |
626 | 626 | |
627 | - $args = !empty( $args ) && is_array( $args ) ? array_merge( $data, $args ) : $data; |
|
627 | + $args = !empty($args) && is_array($args) ? array_merge($data, $args) : $data; |
|
628 | 628 | |
629 | - $ipn_url = add_query_arg( $args, home_url( 'index.php' ) ); |
|
629 | + $ipn_url = add_query_arg($args, home_url('index.php')); |
|
630 | 630 | |
631 | - return apply_filters( 'wpinv_ipn_url', $ipn_url ); |
|
631 | + return apply_filters('wpinv_ipn_url', $ipn_url); |
|
632 | 632 | } |
633 | 633 | |
634 | 634 | function wpinv_listen_for_payment_ipn() { |
635 | 635 | // Regular PayPal IPN |
636 | - if ( isset( $_GET['wpi-listener'] ) && $_GET['wpi-listener'] == 'IPN' ) { |
|
637 | - do_action( 'wpinv_verify_payment_ipn' ); |
|
636 | + if (isset($_GET['wpi-listener']) && $_GET['wpi-listener'] == 'IPN') { |
|
637 | + do_action('wpinv_verify_payment_ipn'); |
|
638 | 638 | |
639 | - if ( !empty( $_GET['wpi-gateway'] ) ) { |
|
640 | - wpinv_error_log( sanitize_text_field( $_GET['wpi-gateway'] ), 'WP Invoicing IPN', __FILE__, __LINE__ ); |
|
641 | - do_action( 'wpinv_verify_' . sanitize_text_field( $_GET['wpi-gateway'] ) . '_ipn' ); |
|
639 | + if (!empty($_GET['wpi-gateway'])) { |
|
640 | + wpinv_error_log(sanitize_text_field($_GET['wpi-gateway']), 'WP Invoicing IPN', __FILE__, __LINE__); |
|
641 | + do_action('wpinv_verify_' . sanitize_text_field($_GET['wpi-gateway']) . '_ipn'); |
|
642 | 642 | } |
643 | 643 | } |
644 | 644 | } |
645 | -add_action( 'init', 'wpinv_listen_for_payment_ipn' ); |
|
645 | +add_action('init', 'wpinv_listen_for_payment_ipn'); |
|
646 | 646 | |
647 | 647 | function wpinv_get_bank_instructions() { |
648 | - $bank_instructions = wpinv_get_option( 'bank_transfer_info' ); |
|
648 | + $bank_instructions = wpinv_get_option('bank_transfer_info'); |
|
649 | 649 | |
650 | - return apply_filters( 'wpinv_bank_instructions', $bank_instructions ); |
|
650 | + return apply_filters('wpinv_bank_instructions', $bank_instructions); |
|
651 | 651 | } |
652 | 652 | |
653 | -function wpinv_get_bank_info( $filtered = false ) { |
|
653 | +function wpinv_get_bank_info($filtered = false) { |
|
654 | 654 | $bank_fields = array( |
655 | - 'bank_transfer_ac_name' => __( 'Account Name', 'invoicing' ), |
|
656 | - 'bank_transfer_ac_no' => __( 'Account Number', 'invoicing' ), |
|
657 | - 'bank_transfer_bank_name' => __( 'Bank Name', 'invoicing' ), |
|
658 | - 'bank_transfer_ifsc' => __( 'IFSC code', 'invoicing' ), |
|
659 | - 'bank_transfer_iban' => __( 'IBAN', 'invoicing' ), |
|
660 | - 'bank_transfer_bic' => __( 'BIC/Swift code', 'invoicing' ), |
|
661 | - 'bank_transfer_sort_code' => __( 'Sort Code', 'invoicing' ) |
|
655 | + 'bank_transfer_ac_name' => __('Account Name', 'invoicing'), |
|
656 | + 'bank_transfer_ac_no' => __('Account Number', 'invoicing'), |
|
657 | + 'bank_transfer_bank_name' => __('Bank Name', 'invoicing'), |
|
658 | + 'bank_transfer_ifsc' => __('IFSC code', 'invoicing'), |
|
659 | + 'bank_transfer_iban' => __('IBAN', 'invoicing'), |
|
660 | + 'bank_transfer_bic' => __('BIC/Swift code', 'invoicing'), |
|
661 | + 'bank_transfer_sort_code' => __('Sort Code', 'invoicing') |
|
662 | 662 | ); |
663 | 663 | |
664 | 664 | $bank_info = array(); |
665 | - foreach ( $bank_fields as $field => $label ) { |
|
666 | - if ( $filtered && !( $value = wpinv_get_option( $field ) ) ) { |
|
665 | + foreach ($bank_fields as $field => $label) { |
|
666 | + if ($filtered && !($value = wpinv_get_option($field))) { |
|
667 | 667 | continue; |
668 | 668 | } |
669 | 669 | |
670 | - $bank_info[$field] = array( 'label' => $label, 'value' => $value ); |
|
670 | + $bank_info[$field] = array('label' => $label, 'value' => $value); |
|
671 | 671 | } |
672 | 672 | |
673 | - return apply_filters( 'wpinv_bank_info', $bank_info, $filtered ); |
|
673 | + return apply_filters('wpinv_bank_info', $bank_info, $filtered); |
|
674 | 674 | } |
675 | 675 | |
676 | -function wpinv_get_post_data( $method = 'request' ) { |
|
676 | +function wpinv_get_post_data($method = 'request') { |
|
677 | 677 | $data = array(); |
678 | 678 | $request = $_REQUEST; |
679 | 679 | |
680 | - if ( $method == 'post' ) { |
|
681 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
680 | + if ($method == 'post') { |
|
681 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') { |
|
682 | 682 | return $data; |
683 | 683 | } |
684 | 684 | |
685 | 685 | $request = $_POST; |
686 | 686 | } |
687 | 687 | |
688 | - if ( $method == 'get' ) { |
|
689 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'GET' ) { |
|
688 | + if ($method == 'get') { |
|
689 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'GET') { |
|
690 | 690 | return $data; |
691 | 691 | } |
692 | 692 | |
@@ -697,11 +697,11 @@ discard block |
||
697 | 697 | $post_data = ''; |
698 | 698 | |
699 | 699 | // Fallback just in case post_max_size is lower than needed |
700 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
701 | - $post_data = file_get_contents( 'php://input' ); |
|
700 | + if (ini_get('allow_url_fopen')) { |
|
701 | + $post_data = file_get_contents('php://input'); |
|
702 | 702 | } else { |
703 | 703 | // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
704 | - ini_set( 'post_max_size', '12M' ); |
|
704 | + ini_set('post_max_size', '12M'); |
|
705 | 705 | } |
706 | 706 | // Start the encoded data collection with notification command |
707 | 707 | $encoded_data = 'cmd=_notify-validate'; |
@@ -710,33 +710,33 @@ discard block |
||
710 | 710 | $arg_separator = wpinv_get_php_arg_separator_output(); |
711 | 711 | |
712 | 712 | // Verify there is a post_data |
713 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
713 | + if ($post_data || strlen($post_data) > 0) { |
|
714 | 714 | // Append the data |
715 | 715 | $encoded_data .= $arg_separator . $post_data; |
716 | 716 | } else { |
717 | 717 | // Check if POST is empty |
718 | - if ( empty( $request ) ) { |
|
718 | + if (empty($request)) { |
|
719 | 719 | // Nothing to do |
720 | 720 | return; |
721 | 721 | } else { |
722 | 722 | // Loop through each POST |
723 | - foreach ( $request as $key => $value ) { |
|
723 | + foreach ($request as $key => $value) { |
|
724 | 724 | // Encode the value and append the data |
725 | - $encoded_data .= $arg_separator . "$key=" . urlencode( $value ); |
|
725 | + $encoded_data .= $arg_separator . "$key=" . urlencode($value); |
|
726 | 726 | } |
727 | 727 | } |
728 | 728 | } |
729 | 729 | |
730 | 730 | // Convert collected post data to an array |
731 | - wp_parse_str( $encoded_data, $data ); |
|
731 | + wp_parse_str($encoded_data, $data); |
|
732 | 732 | |
733 | - foreach ( $data as $key => $value ) { |
|
734 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
735 | - $new_key = str_replace( '&', '&', $key ); |
|
736 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
733 | + foreach ($data as $key => $value) { |
|
734 | + if (false !== strpos($key, 'amp;')) { |
|
735 | + $new_key = str_replace('&', '&', $key); |
|
736 | + $new_key = str_replace('amp;', '&', $new_key); |
|
737 | 737 | |
738 | - unset( $data[ $key ] ); |
|
739 | - $data[ $new_key ] = sanitize_text_field( $value ); |
|
738 | + unset($data[$key]); |
|
739 | + $data[$new_key] = sanitize_text_field($value); |
|
740 | 740 | } |
741 | 741 | } |
742 | 742 | |
@@ -746,12 +746,12 @@ discard block |
||
746 | 746 | /** |
747 | 747 | * Checks if a given gateway supports subscription payments. |
748 | 748 | */ |
749 | -function wpinv_gateway_support_subscription( $gateway ) { |
|
749 | +function wpinv_gateway_support_subscription($gateway) { |
|
750 | 750 | $supports = false; |
751 | 751 | |
752 | - if ( wpinv_is_gateway_active( $gateway ) ) { |
|
753 | - $supports = apply_filters( 'wpinv_' . $gateway . '_support_subscription', $supports ); |
|
754 | - $supports = apply_filters( 'getapid_gateway_supports_subscription', $supports, $gateway ); |
|
752 | + if (wpinv_is_gateway_active($gateway)) { |
|
753 | + $supports = apply_filters('wpinv_' . $gateway . '_support_subscription', $supports); |
|
754 | + $supports = apply_filters('getapid_gateway_supports_subscription', $supports, $gateway); |
|
755 | 755 | } |
756 | 756 | |
757 | 757 | return $supports; |
@@ -763,14 +763,14 @@ discard block |
||
763 | 763 | * @param array $gateways an array of gateways. |
764 | 764 | * @param GetPaid_Payment_Form $form payment form. |
765 | 765 | */ |
766 | -function wpinv_payment_gateways_on_cart( $gateways, $form ) { |
|
766 | +function wpinv_payment_gateways_on_cart($gateways, $form) { |
|
767 | 767 | |
768 | - if ( $form->is_recurring() ) { |
|
768 | + if ($form->is_recurring()) { |
|
769 | 769 | |
770 | - foreach ( array_keys( $gateways ) as $gateway ) { |
|
770 | + foreach (array_keys($gateways) as $gateway) { |
|
771 | 771 | |
772 | - if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
773 | - unset( $gateways[$gateway] ); |
|
772 | + if (!wpinv_gateway_support_subscription($gateway)) { |
|
773 | + unset($gateways[$gateway]); |
|
774 | 774 | } |
775 | 775 | |
776 | 776 | } |
@@ -779,24 +779,24 @@ discard block |
||
779 | 779 | |
780 | 780 | return $gateways; |
781 | 781 | } |
782 | -add_filter( 'getpaid_payment_form_gateways', 'wpinv_payment_gateways_on_cart', 10, 2 ); |
|
782 | +add_filter('getpaid_payment_form_gateways', 'wpinv_payment_gateways_on_cart', 10, 2); |
|
783 | 783 | |
784 | 784 | /** |
785 | 785 | * Validates checkout fields. |
786 | 786 | * |
787 | 787 | * @param GetPaid_Payment_Form_Submission $submission |
788 | 788 | */ |
789 | -function wpinv_checkout_validate_gateway( $submission ) { |
|
789 | +function wpinv_checkout_validate_gateway($submission) { |
|
790 | 790 | |
791 | 791 | $data = $submission->get_data(); |
792 | 792 | |
793 | 793 | // Non-recurring gateways should not be allowed to process recurring invoices. |
794 | - if ( $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
795 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway does not support subscription payment.', 'invoicing' ) ); |
|
794 | + if ($submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) { |
|
795 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway does not support subscription payment.', 'invoicing')); |
|
796 | 796 | } |
797 | 797 | |
798 | - if ( ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
799 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
798 | + if (!wpinv_is_gateway_active($data['wpi-gateway'])) { |
|
799 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway is not active', 'invoicing')); |
|
800 | 800 | } |
801 | 801 | |
802 | 802 | } |
@@ -804,84 +804,84 @@ discard block |
||
804 | 804 | /** |
805 | 805 | * Validates a zip code. |
806 | 806 | */ |
807 | -function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
807 | +function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') { |
|
808 | 808 | |
809 | - if ( empty( $zip ) || empty( $country_code ) ){ |
|
809 | + if (empty($zip) || empty($country_code)) { |
|
810 | 810 | return false; |
811 | 811 | } |
812 | 812 | |
813 | 813 | // Prepare the country code. |
814 | - $country_code = strtoupper( trim( $country_code ) ); |
|
814 | + $country_code = strtoupper(trim($country_code)); |
|
815 | 815 | |
816 | 816 | // Fetch the regexes. |
817 | - $zip_regex = wpinv_get_data( 'zip-regexes' ); |
|
817 | + $zip_regex = wpinv_get_data('zip-regexes'); |
|
818 | 818 | |
819 | 819 | // Check if it is valid. |
820 | - $is_valid = ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ); |
|
820 | + $is_valid = !isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip); |
|
821 | 821 | |
822 | - return apply_filters( 'wpinv_is_zip_valid', $is_valid, $zip, $country_code ); |
|
822 | + return apply_filters('wpinv_is_zip_valid', $is_valid, $zip, $country_code); |
|
823 | 823 | } |
824 | 824 | |
825 | 825 | function wpinv_checkout_validate_agree_to_terms() { |
826 | 826 | // Validate agree to terms |
827 | - if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) { |
|
827 | + if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) { |
|
828 | 828 | // User did not agree |
829 | - wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) ); |
|
829 | + wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing'))); |
|
830 | 830 | } |
831 | 831 | } |
832 | 832 | |
833 | 833 | function wpinv_checkout_validate_invoice_user() { |
834 | 834 | global $wpi_cart, $user_ID; |
835 | 835 | |
836 | - if(empty($wpi_cart)){ |
|
836 | + if (empty($wpi_cart)) { |
|
837 | 837 | $wpi_cart = wpinv_get_invoice_cart(); |
838 | 838 | } |
839 | 839 | |
840 | - $invoice_user = (int)$wpi_cart->get_user_id(); |
|
840 | + $invoice_user = (int) $wpi_cart->get_user_id(); |
|
841 | 841 | $valid_user_data = array( |
842 | 842 | 'user_id' => $invoice_user |
843 | 843 | ); |
844 | 844 | |
845 | 845 | // If guest checkout allowed |
846 | - if ( !wpinv_require_login_to_checkout() ) { |
|
846 | + if (!wpinv_require_login_to_checkout()) { |
|
847 | 847 | return $valid_user_data; |
848 | 848 | } |
849 | 849 | |
850 | 850 | // Verify there is a user_ID |
851 | - if ( $user_ID == $invoice_user ) { |
|
851 | + if ($user_ID == $invoice_user) { |
|
852 | 852 | // Get the logged in user data |
853 | - $user_data = get_userdata( $user_ID ); |
|
854 | - $required_fields = wpinv_checkout_required_fields(); |
|
853 | + $user_data = get_userdata($user_ID); |
|
854 | + $required_fields = wpinv_checkout_required_fields(); |
|
855 | 855 | |
856 | 856 | // Loop through required fields and show error messages |
857 | - if ( !empty( $required_fields ) ) { |
|
858 | - foreach ( $required_fields as $field_name => $value ) { |
|
859 | - if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) { |
|
860 | - wpinv_set_error( $value['error_id'], $value['error_message'] ); |
|
857 | + if (!empty($required_fields)) { |
|
858 | + foreach ($required_fields as $field_name => $value) { |
|
859 | + if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) { |
|
860 | + wpinv_set_error($value['error_id'], $value['error_message']); |
|
861 | 861 | } |
862 | 862 | } |
863 | 863 | } |
864 | 864 | |
865 | 865 | // Verify data |
866 | - if ( $user_data ) { |
|
866 | + if ($user_data) { |
|
867 | 867 | // Collected logged in user data |
868 | 868 | $valid_user_data = array( |
869 | 869 | 'user_id' => $user_ID, |
870 | - 'email' => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email, |
|
871 | - 'first_name' => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name, |
|
872 | - 'last_name' => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name'] ) ? sanitize_text_field( $_POST['wpinv_last_name'] ) : $user_data->last_name, |
|
870 | + 'email' => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email, |
|
871 | + 'first_name' => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name, |
|
872 | + 'last_name' => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name, |
|
873 | 873 | ); |
874 | 874 | |
875 | - if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) { |
|
876 | - wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) ); |
|
875 | + if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) { |
|
876 | + wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing')); |
|
877 | 877 | } |
878 | 878 | } else { |
879 | 879 | // Set invalid user error |
880 | - wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) ); |
|
880 | + wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing')); |
|
881 | 881 | } |
882 | 882 | } else { |
883 | 883 | // Set invalid user error |
884 | - wpinv_set_error( 'invalid_user_id', __( 'The invalid invoice user id', 'invoicing' ) ); |
|
884 | + wpinv_set_error('invalid_user_id', __('The invalid invoice user id', 'invoicing')); |
|
885 | 885 | } |
886 | 886 | |
887 | 887 | // Return user data |
@@ -893,18 +893,18 @@ discard block |
||
893 | 893 | |
894 | 894 | $data = array(); |
895 | 895 | |
896 | - if ( is_user_logged_in() ) { |
|
897 | - if ( !wpinv_require_login_to_checkout() || ( wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id() ) ) { |
|
898 | - $data['user_id'] = (int)get_current_user_id(); |
|
896 | + if (is_user_logged_in()) { |
|
897 | + if (!wpinv_require_login_to_checkout() || (wpinv_require_login_to_checkout() && (int) $wpi_cart->get_user_id() === (int) get_current_user_id())) { |
|
898 | + $data['user_id'] = (int) get_current_user_id(); |
|
899 | 899 | } else { |
900 | - wpinv_set_error( 'logged_in_only', __( 'You are not allowed to pay for this invoice', 'invoicing' ) ); |
|
900 | + wpinv_set_error('logged_in_only', __('You are not allowed to pay for this invoice', 'invoicing')); |
|
901 | 901 | } |
902 | 902 | } else { |
903 | 903 | // If guest checkout allowed |
904 | - if ( !wpinv_require_login_to_checkout() ) { |
|
904 | + if (!wpinv_require_login_to_checkout()) { |
|
905 | 905 | $data['user_id'] = 0; |
906 | 906 | } else { |
907 | - wpinv_set_error( 'logged_in_only', __( 'You must be logged in to pay for this invoice', 'invoicing' ) ); |
|
907 | + wpinv_set_error('logged_in_only', __('You must be logged in to pay for this invoice', 'invoicing')); |
|
908 | 908 | } |
909 | 909 | } |
910 | 910 | |
@@ -918,41 +918,41 @@ discard block |
||
918 | 918 | * @param WPInv_Invoice $invoice |
919 | 919 | * @param GetPaid_Payment_Form_Submission $submission |
920 | 920 | */ |
921 | -function wpinv_process_checkout( $invoice, $submission ) { |
|
921 | +function wpinv_process_checkout($invoice, $submission) { |
|
922 | 922 | |
923 | 923 | // No need to send free invoices to the gateway. |
924 | - if ( $invoice->is_free() ) { |
|
925 | - $invoice->set_gateway( 'none' ); |
|
926 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
924 | + if ($invoice->is_free()) { |
|
925 | + $invoice->set_gateway('none'); |
|
926 | + $invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true); |
|
927 | 927 | $invoice->mark_paid(); |
928 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
928 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
929 | 929 | } |
930 | 930 | |
931 | 931 | // Clear an checkout errors. |
932 | 932 | wpinv_clear_errors(); |
933 | 933 | |
934 | 934 | // Fires before sending to the gateway. |
935 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
935 | + do_action('getpaid_checkout_before_gateway', $invoice, $submission); |
|
936 | 936 | |
937 | 937 | // Allow the sumission data to be modified before it is sent to the gateway. |
938 | 938 | $submission_data = $submission->get_data(); |
939 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $submission_data['wpi-gateway'], $submission, $invoice ); |
|
940 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
939 | + $submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $submission_data['wpi-gateway'], $submission, $invoice); |
|
940 | + $submission_data = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice); |
|
941 | 941 | |
942 | 942 | // Validate the currency. |
943 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
944 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) ); |
|
943 | + if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) { |
|
944 | + wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support the invoice currency', 'invoicing')); |
|
945 | 945 | } |
946 | 946 | |
947 | 947 | // Check to see if we have any errors. |
948 | - if ( wpinv_get_errors() ) { |
|
948 | + if (wpinv_get_errors()) { |
|
949 | 949 | wpinv_send_back_to_checkout(); |
950 | 950 | } |
951 | 951 | |
952 | 952 | // Send info to the gateway for payment processing |
953 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
953 | + do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission); |
|
954 | 954 | |
955 | 955 | // Backwards compatibility. |
956 | - do_action( "wpinv_gateway_$submission_gateway", null, $invoice, $submission_data, $submission ); |
|
956 | + do_action("wpinv_gateway_$submission_gateway", null, $invoice, $submission_data, $submission); |
|
957 | 957 | |
958 | 958 | } |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' ); |
179 | 179 | |
180 | 180 | // Register autoloader. |
181 | - try { |
|
182 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
183 | - } catch ( Exception $e ) { |
|
184 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
181 | + try { |
|
182 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
183 | + } catch ( Exception $e ) { |
|
184 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | require_once( WPINV_PLUGIN_DIR . 'includes/class-getpaid-post-types.php' ); |
@@ -206,11 +206,11 @@ discard block |
||
206 | 206 | require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
207 | 207 | require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
208 | 208 | require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
209 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
210 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
211 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
212 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
213 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
209 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
210 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
211 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
212 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
213 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
214 | 214 | require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
215 | 215 | require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
216 | 216 | require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' ); |
@@ -272,48 +272,48 @@ discard block |
||
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
275 | - * Class autoloader |
|
276 | - * |
|
277 | - * @param string $class_name The name of the class to load. |
|
278 | - * @access public |
|
279 | - * @since 1.0.19 |
|
280 | - * @return void |
|
281 | - */ |
|
282 | - public function autoload( $class_name ) { |
|
283 | - |
|
284 | - // Normalize the class name... |
|
285 | - $class_name = strtolower( $class_name ); |
|
286 | - |
|
287 | - // ... and make sure it is our class. |
|
288 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
289 | - return; |
|
290 | - } |
|
291 | - |
|
292 | - // Next, prepare the file name from the class. |
|
293 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
294 | - |
|
295 | - // And an array of possible locations in order of importance. |
|
296 | - $locations = array( |
|
297 | - 'includes', |
|
275 | + * Class autoloader |
|
276 | + * |
|
277 | + * @param string $class_name The name of the class to load. |
|
278 | + * @access public |
|
279 | + * @since 1.0.19 |
|
280 | + * @return void |
|
281 | + */ |
|
282 | + public function autoload( $class_name ) { |
|
283 | + |
|
284 | + // Normalize the class name... |
|
285 | + $class_name = strtolower( $class_name ); |
|
286 | + |
|
287 | + // ... and make sure it is our class. |
|
288 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
289 | + return; |
|
290 | + } |
|
291 | + |
|
292 | + // Next, prepare the file name from the class. |
|
293 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
294 | + |
|
295 | + // And an array of possible locations in order of importance. |
|
296 | + $locations = array( |
|
297 | + 'includes', |
|
298 | 298 | 'includes/data-stores', |
299 | 299 | 'includes/gateways', |
300 | 300 | 'includes/admin', |
301 | 301 | 'includes/admin/meta-boxes' |
302 | - ); |
|
302 | + ); |
|
303 | 303 | |
304 | - // Base path of the classes. |
|
305 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
304 | + // Base path of the classes. |
|
305 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
306 | 306 | |
307 | - foreach ( $locations as $location ) { |
|
307 | + foreach ( $locations as $location ) { |
|
308 | 308 | |
309 | - if ( file_exists( "$plugin_path/$location/$file_name" ) ) { |
|
310 | - include "$plugin_path/$location/$file_name"; |
|
311 | - break; |
|
312 | - } |
|
309 | + if ( file_exists( "$plugin_path/$location/$file_name" ) ) { |
|
310 | + include "$plugin_path/$location/$file_name"; |
|
311 | + break; |
|
312 | + } |
|
313 | 313 | |
314 | - } |
|
314 | + } |
|
315 | 315 | |
316 | - } |
|
316 | + } |
|
317 | 317 | |
318 | 318 | /** |
319 | 319 | * Inits hooks etc. |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
424 | 424 | wp_enqueue_style( 'jquery-ui-css' ); |
425 | 425 | wp_deregister_style( 'yoast-seo-select2' ); |
426 | - wp_deregister_style( 'yoast-seo-monorepo' ); |
|
426 | + wp_deregister_style( 'yoast-seo-monorepo' ); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | if ( $page == 'wpinv-subscriptions' ) { |
438 | 438 | wp_enqueue_script( 'jquery-ui-datepicker' ); |
439 | 439 | wp_deregister_style( 'yoast-seo-select2' ); |
440 | - wp_deregister_style( 'yoast-seo-monorepo' ); |
|
440 | + wp_deregister_style( 'yoast-seo-monorepo' ); |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) { |
@@ -606,19 +606,19 @@ discard block |
||
606 | 606 | require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
607 | 607 | } |
608 | 608 | |
609 | - /** |
|
610 | - * Register widgets |
|
611 | - * |
|
612 | - */ |
|
613 | - public function register_widgets() { |
|
614 | - register_widget( "WPInv_Checkout_Widget" ); |
|
615 | - register_widget( "WPInv_History_Widget" ); |
|
616 | - register_widget( "WPInv_Receipt_Widget" ); |
|
617 | - register_widget( "WPInv_Subscriptions_Widget" ); |
|
618 | - register_widget( "WPInv_Buy_Item_Widget" ); |
|
609 | + /** |
|
610 | + * Register widgets |
|
611 | + * |
|
612 | + */ |
|
613 | + public function register_widgets() { |
|
614 | + register_widget( "WPInv_Checkout_Widget" ); |
|
615 | + register_widget( "WPInv_History_Widget" ); |
|
616 | + register_widget( "WPInv_Receipt_Widget" ); |
|
617 | + register_widget( "WPInv_Subscriptions_Widget" ); |
|
618 | + register_widget( "WPInv_Buy_Item_Widget" ); |
|
619 | 619 | register_widget( "WPInv_Messages_Widget" ); |
620 | 620 | register_widget( 'WPInv_GetPaid_Widget' ); |
621 | - } |
|
621 | + } |
|
622 | 622 | |
623 | 623 | /** |
624 | 624 | * Remove our pages from yoast sitemaps. |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Manual Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | public $gateways; |
25 | 25 | |
26 | 26 | public static function run() { |
27 | - if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) { |
|
27 | + if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) { |
|
28 | 28 | self::$instance = new WPInv_Plugin; |
29 | 29 | self::$instance->includes(); |
30 | 30 | self::$instance->actions(); |
@@ -47,37 +47,37 @@ discard block |
||
47 | 47 | } |
48 | 48 | |
49 | 49 | public function define_constants() { |
50 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
51 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
50 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
51 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | private function actions() { |
55 | 55 | /* Internationalize the text strings used. */ |
56 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
56 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
57 | 57 | |
58 | 58 | /* Perform actions on admin initialization. */ |
59 | - add_action( 'admin_init', array( &$this, 'admin_init') ); |
|
59 | + add_action('admin_init', array(&$this, 'admin_init')); |
|
60 | 60 | |
61 | 61 | // Init the plugin after WordPress inits. |
62 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
63 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
62 | + add_action('init', array($this, 'init'), 1); |
|
63 | + add_action('init', array(&$this, 'wpinv_actions')); |
|
64 | 64 | |
65 | - if ( class_exists( 'BuddyPress' ) ) { |
|
66 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
65 | + if (class_exists('BuddyPress')) { |
|
66 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
67 | 67 | } |
68 | 68 | |
69 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
70 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
71 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
72 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
69 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
70 | + add_action('wp_footer', array(&$this, 'wp_footer')); |
|
71 | + add_action('widgets_init', array(&$this, 'register_widgets')); |
|
72 | + add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids')); |
|
73 | 73 | |
74 | - if ( is_admin() ) { |
|
75 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
|
76 | - add_filter( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
|
77 | - add_action( 'admin_init', array( &$this, 'init_ayecode_connect_helper' ) ); |
|
74 | + if (is_admin()) { |
|
75 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts')); |
|
76 | + add_filter('admin_body_class', array(&$this, 'admin_body_class')); |
|
77 | + add_action('admin_init', array(&$this, 'init_ayecode_connect_helper')); |
|
78 | 78 | |
79 | 79 | } else { |
80 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
80 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -87,28 +87,28 @@ discard block |
||
87 | 87 | * |
88 | 88 | * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference. |
89 | 89 | */ |
90 | - do_action_ref_array( 'wpinv_actions', array( &$this ) ); |
|
90 | + do_action_ref_array('wpinv_actions', array(&$this)); |
|
91 | 91 | |
92 | - add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
|
92 | + add_action('admin_init', array(&$this, 'activation_redirect')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
96 | 96 | * Maybe show the AyeCode Connect Notice. |
97 | 97 | */ |
98 | - public function init_ayecode_connect_helper(){ |
|
98 | + public function init_ayecode_connect_helper() { |
|
99 | 99 | // AyeCode Connect notice |
100 | - if ( is_admin() ){ |
|
100 | + if (is_admin()) { |
|
101 | 101 | // set the strings so they can be translated |
102 | 102 | $strings = array( |
103 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
104 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
105 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
106 | - 'connect_button' => __("Connect Site","invoicing"), |
|
107 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
108 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
109 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
103 | + 'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"), |
|
104 | + 'connect_external' => __("Please confirm you wish to connect your site?", "invoicing"), |
|
105 | + 'connect' => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"), |
|
106 | + 'connect_button' => __("Connect Site", "invoicing"), |
|
107 | + 'connecting_button' => __("Connecting...", "invoicing"), |
|
108 | + 'error_localhost' => __("This service will only work with a live domain, not a localhost.", "invoicing"), |
|
109 | + 'error' => __("Something went wrong, please refresh and try again.", "invoicing"), |
|
110 | 110 | ); |
111 | - new AyeCode_Connect_Helper($strings,array('wpi-addons')); |
|
111 | + new AyeCode_Connect_Helper($strings, array('wpi-addons')); |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | |
@@ -116,10 +116,10 @@ discard block |
||
116 | 116 | /* Internationalize the text strings used. */ |
117 | 117 | $this->load_textdomain(); |
118 | 118 | |
119 | - do_action( 'wpinv_loaded' ); |
|
119 | + do_action('wpinv_loaded'); |
|
120 | 120 | |
121 | 121 | // Fix oxygen page builder conflict |
122 | - if ( function_exists( 'ct_css_output' ) ) { |
|
122 | + if (function_exists('ct_css_output')) { |
|
123 | 123 | wpinv_oxygen_fix_conflict(); |
124 | 124 | } |
125 | 125 | } |
@@ -129,146 +129,146 @@ discard block |
||
129 | 129 | * |
130 | 130 | * @since 1.0 |
131 | 131 | */ |
132 | - public function load_textdomain( $locale = NULL ) { |
|
133 | - if ( empty( $locale ) ) { |
|
134 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
132 | + public function load_textdomain($locale = NULL) { |
|
133 | + if (empty($locale)) { |
|
134 | + $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
|
135 | 135 | } |
136 | 136 | |
137 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
137 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
138 | 138 | |
139 | - unload_textdomain( 'invoicing' ); |
|
140 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
141 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
139 | + unload_textdomain('invoicing'); |
|
140 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
141 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
142 | 142 | |
143 | 143 | /** |
144 | 144 | * Define language constants. |
145 | 145 | */ |
146 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
146 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | public function includes() { |
150 | 150 | global $wpinv_options; |
151 | 151 | |
152 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
152 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
153 | 153 | $wpinv_options = wpinv_get_settings(); |
154 | 154 | |
155 | 155 | // Load composer packages. |
156 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
156 | + require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php'); |
|
157 | 157 | |
158 | 158 | // load AUI |
159 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
159 | + require_once(WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'); |
|
160 | 160 | |
161 | 161 | // Load the action scheduler. |
162 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' ); |
|
162 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php'); |
|
163 | 163 | |
164 | 164 | // Load functions. |
165 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
166 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
167 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
168 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
169 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
170 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
171 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
172 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
173 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
174 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
175 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
176 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
177 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
178 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' ); |
|
165 | + require_once(WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'); |
|
166 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
167 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
168 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
169 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
170 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
171 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
172 | + require_once(WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'); |
|
173 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
174 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
175 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
176 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
177 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
178 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php'); |
|
179 | 179 | |
180 | 180 | // Register autoloader. |
181 | 181 | try { |
182 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
183 | - } catch ( Exception $e ) { |
|
184 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
185 | - } |
|
186 | - |
|
187 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-getpaid-post-types.php' ); |
|
188 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' ); |
|
189 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' ); |
|
190 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-discount.php' ); |
|
191 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' ); |
|
192 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' ); |
|
193 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
194 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
195 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
196 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
198 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
199 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
200 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
202 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' ); |
|
203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
204 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' ); |
|
205 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
206 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
207 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
208 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
209 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
210 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
211 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
212 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
213 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
214 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
215 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
216 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' ); |
|
182 | + spl_autoload_register(array($this, 'autoload'), true); |
|
183 | + } catch (Exception $e) { |
|
184 | + wpinv_error_log($e->getMessage(), '', __FILE__, 149, true); |
|
185 | + } |
|
186 | + |
|
187 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-getpaid-post-types.php'); |
|
188 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php'); |
|
189 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php'); |
|
190 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-discount.php'); |
|
191 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php'); |
|
192 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php'); |
|
193 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'); |
|
194 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'); |
|
195 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
196 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
197 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
198 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'); |
|
199 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'); |
|
200 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'); |
|
201 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'); |
|
202 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php'); |
|
203 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'); |
|
204 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php'); |
|
205 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'); |
|
206 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'); |
|
207 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'); |
|
208 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'); |
|
209 | + require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php'); |
|
210 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'); |
|
211 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'); |
|
212 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'); |
|
213 | + require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'); |
|
214 | + require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php'); |
|
215 | + require_once(WPINV_PLUGIN_DIR . 'widgets/getpaid.php'); |
|
216 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php'); |
|
217 | 217 | |
218 | 218 | /** |
219 | 219 | * Load the tax class. |
220 | 220 | */ |
221 | - if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
222 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
221 | + if (!class_exists('WPInv_EUVat')) { |
|
222 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
223 | 223 | } |
224 | 224 | |
225 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
226 | - if ( !empty( $gateways ) ) { |
|
227 | - foreach ( $gateways as $gateway ) { |
|
228 | - if ( $gateway == 'manual' ) { |
|
225 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
226 | + if (!empty($gateways)) { |
|
227 | + foreach ($gateways as $gateway) { |
|
228 | + if ($gateway == 'manual') { |
|
229 | 229 | continue; |
230 | 230 | } |
231 | 231 | |
232 | 232 | $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
233 | 233 | |
234 | - if ( file_exists( $gateway_file ) ) { |
|
235 | - require_once( $gateway_file ); |
|
234 | + if (file_exists($gateway_file)) { |
|
235 | + require_once($gateway_file); |
|
236 | 236 | } |
237 | 237 | } |
238 | 238 | } |
239 | 239 | |
240 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
240 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
241 | 241 | GetPaid_Post_Types_Admin::init(); |
242 | 242 | |
243 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
244 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
243 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php'); |
|
244 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
245 | 245 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
246 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
247 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
248 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
249 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
250 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
251 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
246 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'); |
|
247 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
248 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
249 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'); |
|
250 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'); |
|
251 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'); |
|
252 | 252 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
253 | 253 | // load the user class only on the users.php page |
254 | 254 | global $pagenow; |
255 | - if($pagenow=='users.php'){ |
|
255 | + if ($pagenow == 'users.php') { |
|
256 | 256 | new WPInv_Admin_Users(); |
257 | 257 | } |
258 | 258 | } |
259 | 259 | |
260 | 260 | // Register cli commands |
261 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
262 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
263 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
261 | + if (defined('WP_CLI') && WP_CLI) { |
|
262 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'); |
|
263 | + WP_CLI::add_command('invoicing', 'WPInv_CLI'); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | // include css inliner |
267 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
268 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
267 | + if (!class_exists('Emogrifier') && class_exists('DOMDocument')) { |
|
268 | + include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'); |
|
269 | 269 | } |
270 | 270 | |
271 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
271 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
@@ -279,18 +279,18 @@ discard block |
||
279 | 279 | * @since 1.0.19 |
280 | 280 | * @return void |
281 | 281 | */ |
282 | - public function autoload( $class_name ) { |
|
282 | + public function autoload($class_name) { |
|
283 | 283 | |
284 | 284 | // Normalize the class name... |
285 | - $class_name = strtolower( $class_name ); |
|
285 | + $class_name = strtolower($class_name); |
|
286 | 286 | |
287 | 287 | // ... and make sure it is our class. |
288 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
288 | + if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) { |
|
289 | 289 | return; |
290 | 290 | } |
291 | 291 | |
292 | 292 | // Next, prepare the file name from the class. |
293 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
293 | + $file_name = 'class-' . str_replace('_', '-', $class_name) . '.php'; |
|
294 | 294 | |
295 | 295 | // And an array of possible locations in order of importance. |
296 | 296 | $locations = array( |
@@ -302,11 +302,11 @@ discard block |
||
302 | 302 | ); |
303 | 303 | |
304 | 304 | // Base path of the classes. |
305 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
305 | + $plugin_path = untrailingslashit(WPINV_PLUGIN_DIR); |
|
306 | 306 | |
307 | - foreach ( $locations as $location ) { |
|
307 | + foreach ($locations as $location) { |
|
308 | 308 | |
309 | - if ( file_exists( "$plugin_path/$location/$file_name" ) ) { |
|
309 | + if (file_exists("$plugin_path/$location/$file_name")) { |
|
310 | 310 | include "$plugin_path/$location/$file_name"; |
311 | 311 | break; |
312 | 312 | } |
@@ -329,125 +329,125 @@ discard block |
||
329 | 329 | ) |
330 | 330 | ); |
331 | 331 | |
332 | - foreach ( $gateways as $id => $class ) { |
|
333 | - $this->gateways[ $id ] = new $class(); |
|
332 | + foreach ($gateways as $id => $class) { |
|
333 | + $this->gateways[$id] = new $class(); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | } |
337 | 337 | |
338 | 338 | public function admin_init() { |
339 | 339 | self::$instance->default_payment_form = wpinv_get_default_payment_form(); |
340 | - add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
|
340 | + add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php')); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | public function activation_redirect() { |
344 | 344 | // Bail if no activation redirect |
345 | - if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
|
345 | + if (!get_transient('_wpinv_activation_redirect')) { |
|
346 | 346 | return; |
347 | 347 | } |
348 | 348 | |
349 | 349 | // Delete the redirect transient |
350 | - delete_transient( '_wpinv_activation_redirect' ); |
|
350 | + delete_transient('_wpinv_activation_redirect'); |
|
351 | 351 | |
352 | 352 | // Bail if activating from network, or bulk |
353 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
353 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
354 | 354 | return; |
355 | 355 | } |
356 | 356 | |
357 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
357 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
358 | 358 | exit; |
359 | 359 | } |
360 | 360 | |
361 | 361 | public function enqueue_scripts() { |
362 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
362 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
363 | 363 | |
364 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
365 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
366 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
364 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css'); |
|
365 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version); |
|
366 | + wp_enqueue_style('wpinv_front_style'); |
|
367 | 367 | |
368 | 368 | // Register scripts |
369 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
370 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
369 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
370 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array('jquery'), filemtime(WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js')); |
|
371 | 371 | |
372 | 372 | $localize = array(); |
373 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
374 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
373 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
374 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
375 | 375 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
376 | 376 | $localize['currency_pos'] = wpinv_currency_position(); |
377 | 377 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
378 | 378 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
379 | 379 | $localize['decimals'] = wpinv_decimals(); |
380 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
380 | + $localize['txtComplete'] = __('Continue', 'invoicing'); |
|
381 | 381 | $localize['UseTaxes'] = wpinv_use_taxes(); |
382 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
383 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
384 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
382 | + $localize['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce'); |
|
383 | + $localize['formNonce'] = wp_create_nonce('getpaid_form_nonce'); |
|
384 | + $localize['connectionError'] = __('Could not establish a connection to the server.', 'invoicing'); |
|
385 | 385 | |
386 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
386 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
387 | 387 | |
388 | - wp_enqueue_script( 'jquery-blockui' ); |
|
388 | + wp_enqueue_script('jquery-blockui'); |
|
389 | 389 | $autofill_api = wpinv_get_option('address_autofill_api'); |
390 | 390 | $autofill_active = wpinv_get_option('address_autofill_active'); |
391 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
392 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
393 | - wp_dequeue_script( 'google-maps-api' ); |
|
391 | + if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) { |
|
392 | + if (wp_script_is('google-maps-api', 'enqueued')) { |
|
393 | + wp_dequeue_script('google-maps-api'); |
|
394 | 394 | } |
395 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
396 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
395 | + wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false); |
|
396 | + wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true); |
|
397 | 397 | } |
398 | 398 | |
399 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
400 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
399 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all'); |
|
400 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
401 | 401 | |
402 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
403 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
402 | + wp_enqueue_script('wpinv-front-script'); |
|
403 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
404 | 404 | |
405 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
406 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
405 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js'); |
|
406 | + wp_enqueue_script('wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('wpinv-front-script', 'wp-hooks'), $version, true); |
|
407 | 407 | } |
408 | 408 | |
409 | - public function admin_enqueue_scripts( $hook ) { |
|
409 | + public function admin_enqueue_scripts($hook) { |
|
410 | 410 | global $post, $pagenow; |
411 | 411 | |
412 | 412 | $post_type = wpinv_admin_post_type(); |
413 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
414 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : ''; |
|
413 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
414 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : ''; |
|
415 | 415 | |
416 | 416 | $jquery_ui_css = false; |
417 | - if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
417 | + if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
418 | 418 | $jquery_ui_css = true; |
419 | - } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) { |
|
419 | + } else if ($page == 'wpinv-settings' || $page == 'wpinv-reports') { |
|
420 | 420 | $jquery_ui_css = true; |
421 | 421 | } |
422 | - if ( $jquery_ui_css ) { |
|
423 | - wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
|
424 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
425 | - wp_deregister_style( 'yoast-seo-select2' ); |
|
426 | - wp_deregister_style( 'yoast-seo-monorepo' ); |
|
422 | + if ($jquery_ui_css) { |
|
423 | + wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16'); |
|
424 | + wp_enqueue_style('jquery-ui-css'); |
|
425 | + wp_deregister_style('yoast-seo-select2'); |
|
426 | + wp_deregister_style('yoast-seo-monorepo'); |
|
427 | 427 | } |
428 | 428 | |
429 | - wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
430 | - wp_enqueue_style( 'wpinv_meta_box_style' ); |
|
429 | + wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
430 | + wp_enqueue_style('wpinv_meta_box_style'); |
|
431 | 431 | |
432 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' ); |
|
433 | - wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version ); |
|
434 | - wp_enqueue_style( 'wpinv_admin_style' ); |
|
432 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css'); |
|
433 | + wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version); |
|
434 | + wp_enqueue_style('wpinv_admin_style'); |
|
435 | 435 | |
436 | - $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ); |
|
437 | - if ( $page == 'wpinv-subscriptions' ) { |
|
438 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
439 | - wp_deregister_style( 'yoast-seo-select2' ); |
|
440 | - wp_deregister_style( 'yoast-seo-monorepo' ); |
|
436 | + $enqueue = ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')); |
|
437 | + if ($page == 'wpinv-subscriptions') { |
|
438 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
439 | + wp_deregister_style('yoast-seo-select2'); |
|
440 | + wp_deregister_style('yoast-seo-monorepo'); |
|
441 | 441 | } |
442 | 442 | |
443 | - if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) { |
|
444 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
443 | + if ($enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue)) { |
|
444 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
445 | 445 | } |
446 | 446 | |
447 | - wp_enqueue_style( 'wp-color-picker' ); |
|
448 | - wp_enqueue_script( 'wp-color-picker' ); |
|
447 | + wp_enqueue_style('wp-color-picker'); |
|
448 | + wp_enqueue_script('wp-color-picker'); |
|
449 | 449 | |
450 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
450 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
451 | 451 | |
452 | 452 | if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
453 | 453 | $autofill_api = wpinv_get_option('address_autofill_api'); |
@@ -458,21 +458,21 @@ discard block |
||
458 | 458 | } |
459 | 459 | } |
460 | 460 | |
461 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
462 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
461 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all'); |
|
462 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
463 | 463 | |
464 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' ); |
|
465 | - wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ), $version ); |
|
466 | - wp_enqueue_script( 'wpinv-admin-script' ); |
|
464 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js'); |
|
465 | + wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), $version); |
|
466 | + wp_enqueue_script('wpinv-admin-script'); |
|
467 | 467 | |
468 | 468 | $localize = array(); |
469 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
470 | - $localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
|
471 | - $localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
472 | - $localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
|
473 | - $localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
|
474 | - $localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
|
475 | - $localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
|
469 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
470 | + $localize['post_ID'] = isset($post->ID) ? $post->ID : ''; |
|
471 | + $localize['wpinv_nonce'] = wp_create_nonce('wpinv-nonce'); |
|
472 | + $localize['add_invoice_note_nonce'] = wp_create_nonce('add-invoice-note'); |
|
473 | + $localize['delete_invoice_note_nonce'] = wp_create_nonce('delete-invoice-note'); |
|
474 | + $localize['invoice_item_nonce'] = wp_create_nonce('invoice-item'); |
|
475 | + $localize['billing_details_nonce'] = wp_create_nonce('get-billing-details'); |
|
476 | 476 | $localize['tax'] = wpinv_tax_amount(); |
477 | 477 | $localize['discount'] = wpinv_discount_amount(); |
478 | 478 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
@@ -480,104 +480,104 @@ discard block |
||
480 | 480 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
481 | 481 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
482 | 482 | $localize['decimals'] = wpinv_decimals(); |
483 | - $localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
|
484 | - $localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
|
485 | - $localize['status_pending'] = wpinv_status_nicename( 'wpi-pending' ); |
|
486 | - $localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
|
487 | - $localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
|
488 | - $localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
|
489 | - $localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
|
490 | - $localize['confirmCalcTotals'] = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ); |
|
491 | - $localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
|
492 | - $localize['emptyInvoice'] = __( 'Add at least one item to save invoice!', 'invoicing' ); |
|
493 | - $localize['errDeleteItem'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
|
494 | - $localize['delete_subscription'] = __( 'Are you sure you want to delete this subscription?', 'invoicing' ); |
|
495 | - $localize['action_edit'] = __( 'Edit', 'invoicing' ); |
|
496 | - $localize['action_cancel'] = __( 'Cancel', 'invoicing' ); |
|
497 | - $localize['item_description'] = __( 'Item Description', 'invoicing' ); |
|
498 | - $localize['discount_description'] = __( 'Discount Description', 'invoicing' ); |
|
499 | - $localize['invoice_description'] = __( 'Invoice Description', 'invoicing' ); |
|
500 | - $localize['searching'] = __( 'Searching', 'invoicing' ); |
|
501 | - |
|
502 | - $localize = apply_filters( 'wpinv_admin_js_localize', $localize ); |
|
503 | - |
|
504 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
|
483 | + $localize['save_invoice'] = __('Save Invoice', 'invoicing'); |
|
484 | + $localize['status_publish'] = wpinv_status_nicename('publish'); |
|
485 | + $localize['status_pending'] = wpinv_status_nicename('wpi-pending'); |
|
486 | + $localize['delete_tax_rate'] = __('Are you sure you wish to delete this tax rate?', 'invoicing'); |
|
487 | + $localize['OneItemMin'] = __('Invoice must contain at least one item', 'invoicing'); |
|
488 | + $localize['DeleteInvoiceItem'] = __('Are you sure you wish to delete this item?', 'invoicing'); |
|
489 | + $localize['FillBillingDetails'] = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'); |
|
490 | + $localize['confirmCalcTotals'] = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'); |
|
491 | + $localize['AreYouSure'] = __('Are you sure?', 'invoicing'); |
|
492 | + $localize['emptyInvoice'] = __('Add at least one item to save invoice!', 'invoicing'); |
|
493 | + $localize['errDeleteItem'] = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'); |
|
494 | + $localize['delete_subscription'] = __('Are you sure you want to delete this subscription?', 'invoicing'); |
|
495 | + $localize['action_edit'] = __('Edit', 'invoicing'); |
|
496 | + $localize['action_cancel'] = __('Cancel', 'invoicing'); |
|
497 | + $localize['item_description'] = __('Item Description', 'invoicing'); |
|
498 | + $localize['discount_description'] = __('Discount Description', 'invoicing'); |
|
499 | + $localize['invoice_description'] = __('Invoice Description', 'invoicing'); |
|
500 | + $localize['searching'] = __('Searching', 'invoicing'); |
|
501 | + |
|
502 | + $localize = apply_filters('wpinv_admin_js_localize', $localize); |
|
503 | + |
|
504 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize); |
|
505 | 505 | |
506 | 506 | // Load payment form scripts on our admin pages only. |
507 | - if ( ( $hook == 'post-new.php' || $hook == 'post.php' ) && 'wpi_payment_form' === $post->post_type ) { |
|
507 | + if (($hook == 'post-new.php' || $hook == 'post.php') && 'wpi_payment_form' === $post->post_type) { |
|
508 | 508 | |
509 | - wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
|
510 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
511 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
509 | + wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION); |
|
510 | + wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION); |
|
511 | + wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION); |
|
512 | 512 | |
513 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
514 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
513 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js'); |
|
514 | + wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version); |
|
515 | 515 | |
516 | - wp_localize_script( 'wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array( |
|
516 | + wp_localize_script('wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array( |
|
517 | 517 | 'elements' => $this->form_elements->get_elements(), |
518 | - 'form_elements' => $this->form_elements->get_form_elements( $post->ID ), |
|
518 | + 'form_elements' => $this->form_elements->get_form_elements($post->ID), |
|
519 | 519 | 'all_items' => $this->form_elements->get_published_items(), |
520 | 520 | 'currency' => wpinv_currency_symbol(), |
521 | 521 | 'position' => wpinv_currency_position(), |
522 | 522 | 'decimals' => (int) wpinv_decimals(), |
523 | 523 | 'thousands_sep' => wpinv_thousands_separator(), |
524 | 524 | 'decimals_sep' => wpinv_decimal_separator(), |
525 | - 'form_items' => $this->form_elements->get_form_items( $post->ID ), |
|
525 | + 'form_items' => $this->form_elements->get_form_items($post->ID), |
|
526 | 526 | 'is_default' => $post->ID == $this->default_payment_form, |
527 | - ) ); |
|
527 | + )); |
|
528 | 528 | |
529 | - wp_enqueue_script( 'wpinv-admin-payment-form-script' ); |
|
529 | + wp_enqueue_script('wpinv-admin-payment-form-script'); |
|
530 | 530 | } |
531 | 531 | |
532 | - if ( $page == 'wpinv-subscriptions' ) { |
|
533 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
534 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
532 | + if ($page == 'wpinv-subscriptions') { |
|
533 | + wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION); |
|
534 | + wp_enqueue_script('wpinv-sub-admin-script'); |
|
535 | 535 | } |
536 | 536 | |
537 | - if ( $page == 'wpinv-reports' ) { |
|
538 | - wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' ); |
|
537 | + if ($page == 'wpinv-reports') { |
|
538 | + wp_enqueue_script('jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array('jquery'), '0.7'); |
|
539 | 539 | } |
540 | 540 | |
541 | 541 | } |
542 | 542 | |
543 | - public function admin_body_class( $classes ) { |
|
543 | + public function admin_body_class($classes) { |
|
544 | 544 | global $pagenow, $post, $current_screen; |
545 | 545 | |
546 | - if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote' ) ) { |
|
546 | + if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote')) { |
|
547 | 547 | $classes .= ' wpinv-cpt'; |
548 | 548 | } |
549 | 549 | |
550 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
550 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
551 | 551 | |
552 | - $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false; |
|
553 | - if ( $add_class ) { |
|
554 | - $classes .= ' wpi-' . wpinv_sanitize_key( $page ); |
|
552 | + $add_class = $page && $pagenow == 'admin.php' && strpos($page, 'wpinv-') === 0 ? true : false; |
|
553 | + if ($add_class) { |
|
554 | + $classes .= ' wpi-' . wpinv_sanitize_key($page); |
|
555 | 555 | } |
556 | 556 | |
557 | 557 | $settings_class = array(); |
558 | - if ( $page == 'wpinv-settings' ) { |
|
559 | - if ( !empty( $_REQUEST['tab'] ) ) { |
|
560 | - $settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
|
558 | + if ($page == 'wpinv-settings') { |
|
559 | + if (!empty($_REQUEST['tab'])) { |
|
560 | + $settings_class[] = sanitize_text_field($_REQUEST['tab']); |
|
561 | 561 | } |
562 | 562 | |
563 | - if ( !empty( $_REQUEST['section'] ) ) { |
|
564 | - $settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
|
563 | + if (!empty($_REQUEST['section'])) { |
|
564 | + $settings_class[] = sanitize_text_field($_REQUEST['section']); |
|
565 | 565 | } |
566 | 566 | |
567 | - $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
|
567 | + $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main'; |
|
568 | 568 | } |
569 | 569 | |
570 | - if ( !empty( $settings_class ) ) { |
|
571 | - $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
570 | + if (!empty($settings_class)) { |
|
571 | + $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-')); |
|
572 | 572 | } |
573 | 573 | |
574 | 574 | $post_type = wpinv_admin_post_type(); |
575 | 575 | |
576 | - if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) { |
|
576 | + if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) { |
|
577 | 577 | return $classes .= ' wpinv'; |
578 | 578 | } |
579 | 579 | |
580 | - if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) { |
|
580 | + if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) { |
|
581 | 581 | $classes .= ' wpi-editable-n'; |
582 | 582 | } |
583 | 583 | |
@@ -589,21 +589,21 @@ discard block |
||
589 | 589 | } |
590 | 590 | |
591 | 591 | public function wpinv_actions() { |
592 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
593 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
592 | + if (isset($_REQUEST['wpi_action'])) { |
|
593 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
594 | 594 | } |
595 | 595 | } |
596 | 596 | |
597 | - public function pre_get_posts( $wp_query ) { |
|
598 | - if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
599 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
597 | + public function pre_get_posts($wp_query) { |
|
598 | + if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
599 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
600 | 600 | } |
601 | 601 | |
602 | 602 | return $wp_query; |
603 | 603 | } |
604 | 604 | |
605 | 605 | public function bp_invoicing_init() { |
606 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
606 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | /** |
@@ -611,13 +611,13 @@ discard block |
||
611 | 611 | * |
612 | 612 | */ |
613 | 613 | public function register_widgets() { |
614 | - register_widget( "WPInv_Checkout_Widget" ); |
|
615 | - register_widget( "WPInv_History_Widget" ); |
|
616 | - register_widget( "WPInv_Receipt_Widget" ); |
|
617 | - register_widget( "WPInv_Subscriptions_Widget" ); |
|
618 | - register_widget( "WPInv_Buy_Item_Widget" ); |
|
619 | - register_widget( "WPInv_Messages_Widget" ); |
|
620 | - register_widget( 'WPInv_GetPaid_Widget' ); |
|
614 | + register_widget("WPInv_Checkout_Widget"); |
|
615 | + register_widget("WPInv_History_Widget"); |
|
616 | + register_widget("WPInv_Receipt_Widget"); |
|
617 | + register_widget("WPInv_Subscriptions_Widget"); |
|
618 | + register_widget("WPInv_Buy_Item_Widget"); |
|
619 | + register_widget("WPInv_Messages_Widget"); |
|
620 | + register_widget('WPInv_GetPaid_Widget'); |
|
621 | 621 | } |
622 | 622 | |
623 | 623 | /** |
@@ -626,10 +626,10 @@ discard block |
||
626 | 626 | * @since 1.0.19 |
627 | 627 | * @param int[] $excluded_posts_ids |
628 | 628 | */ |
629 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
629 | + public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) { |
|
630 | 630 | |
631 | 631 | // Ensure that we have an array. |
632 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
632 | + if (!is_array($excluded_posts_ids)) { |
|
633 | 633 | $excluded_posts_ids = array(); |
634 | 634 | } |
635 | 635 | |
@@ -637,24 +637,24 @@ discard block |
||
637 | 637 | $our_pages = array(); |
638 | 638 | |
639 | 639 | // Checkout page. |
640 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
640 | + $our_pages[] = wpinv_get_option('checkout_page', false); |
|
641 | 641 | |
642 | 642 | // Success page. |
643 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
643 | + $our_pages[] = wpinv_get_option('success_page', false); |
|
644 | 644 | |
645 | 645 | // Failure page. |
646 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
646 | + $our_pages[] = wpinv_get_option('failure_page', false); |
|
647 | 647 | |
648 | 648 | // History page. |
649 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
649 | + $our_pages[] = wpinv_get_option('invoice_history_page', false); |
|
650 | 650 | |
651 | 651 | // Subscriptions page. |
652 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
652 | + $our_pages[] = wpinv_get_option('invoice_subscription_page', false); |
|
653 | 653 | |
654 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
654 | + $our_pages = array_map('intval', array_filter($our_pages)); |
|
655 | 655 | |
656 | 656 | $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
657 | - return array_unique( $excluded_posts_ids ); |
|
657 | + return array_unique($excluded_posts_ids); |
|
658 | 658 | |
659 | 659 | } |
660 | 660 |
@@ -1,7 +1,7 @@ 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 | 7 | /** |
@@ -20,55 +20,55 @@ discard block |
||
20 | 20 | function wpinv_print_errors() { |
21 | 21 | $errors = wpinv_get_errors(); |
22 | 22 | |
23 | - if ( $errors ) { |
|
24 | - $classes = apply_filters( 'wpinv_error_class', array( |
|
23 | + if ($errors) { |
|
24 | + $classes = apply_filters('wpinv_error_class', array( |
|
25 | 25 | 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-error' |
26 | - ) ); |
|
27 | - echo '<div class="' . implode( ' ', $classes ) . '">'; |
|
26 | + )); |
|
27 | + echo '<div class="' . implode(' ', $classes) . '">'; |
|
28 | 28 | // Loop error codes and display errors |
29 | - foreach ( $errors as $error_id => $error ) { |
|
30 | - echo '<p class="wpinv_error" id="wpinv_error_' . $error_id . '"><strong>' . __( 'Error', 'invoicing' ) . '</strong>: ' . $error . '</p>'; |
|
29 | + foreach ($errors as $error_id => $error) { |
|
30 | + echo '<p class="wpinv_error" id="wpinv_error_' . $error_id . '"><strong>' . __('Error', 'invoicing') . '</strong>: ' . $error . '</p>'; |
|
31 | 31 | } |
32 | 32 | echo '</div>'; |
33 | 33 | wpinv_clear_errors(); |
34 | 34 | } |
35 | 35 | } |
36 | -add_action( 'wpinv_purchase_form_before_submit', 'wpinv_print_errors' ); |
|
37 | -add_action( 'wpinv_ajax_checkout_errors', 'wpinv_print_errors' ); |
|
36 | +add_action('wpinv_purchase_form_before_submit', 'wpinv_print_errors'); |
|
37 | +add_action('wpinv_ajax_checkout_errors', 'wpinv_print_errors'); |
|
38 | 38 | |
39 | 39 | function wpinv_get_errors() { |
40 | 40 | global $wpi_session; |
41 | 41 | |
42 | - return $wpi_session->get( 'wpinv_errors' ); |
|
42 | + return $wpi_session->get('wpinv_errors'); |
|
43 | 43 | } |
44 | 44 | |
45 | -function wpinv_set_error( $error_id, $error_message ) { |
|
45 | +function wpinv_set_error($error_id, $error_message) { |
|
46 | 46 | global $wpi_session; |
47 | 47 | |
48 | 48 | $errors = wpinv_get_errors(); |
49 | 49 | |
50 | - if ( ! $errors ) { |
|
50 | + if (!$errors) { |
|
51 | 51 | $errors = array(); |
52 | 52 | } |
53 | 53 | |
54 | - $errors[ $error_id ] = $error_message; |
|
55 | - $wpi_session->set( 'wpinv_errors', $errors ); |
|
54 | + $errors[$error_id] = $error_message; |
|
55 | + $wpi_session->set('wpinv_errors', $errors); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | function wpinv_clear_errors() { |
59 | 59 | global $wpi_session; |
60 | 60 | |
61 | - $wpi_session->set( 'wpinv_errors', null ); |
|
61 | + $wpi_session->set('wpinv_errors', null); |
|
62 | 62 | } |
63 | 63 | |
64 | -function wpinv_unset_error( $error_id ) { |
|
64 | +function wpinv_unset_error($error_id) { |
|
65 | 65 | global $wpi_session; |
66 | 66 | |
67 | 67 | $errors = wpinv_get_errors(); |
68 | 68 | |
69 | - if ( $errors ) { |
|
70 | - unset( $errors[ $error_id ] ); |
|
71 | - $wpi_session->set( 'wpinv_errors', $errors ); |
|
69 | + if ($errors) { |
|
70 | + unset($errors[$error_id]); |
|
71 | + $wpi_session->set('wpinv_errors', $errors); |
|
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
@@ -76,10 +76,10 @@ discard block |
||
76 | 76 | die(); |
77 | 77 | } |
78 | 78 | |
79 | -function wpinv_die( $message = '', $title = '', $status = 400 ) { |
|
80 | - add_filter( 'wp_die_ajax_handler', 'wpinv_die_handler', 10, 3 ); |
|
81 | - add_filter( 'wp_die_handler', 'wpinv_die_handler', 10, 3 ); |
|
82 | - wp_die( $message, $title, array( 'response' => $status )); |
|
79 | +function wpinv_die($message = '', $title = '', $status = 400) { |
|
80 | + add_filter('wp_die_ajax_handler', 'wpinv_die_handler', 10, 3); |
|
81 | + add_filter('wp_die_handler', 'wpinv_die_handler', 10, 3); |
|
82 | + wp_die($message, $title, array('response' => $status)); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -90,15 +90,15 @@ discard block |
||
90 | 90 | * @param string $message Message to log. |
91 | 91 | * @param string $version Version the message was added in. |
92 | 92 | */ |
93 | -function getpaid_doing_it_wrong( $function, $message, $version ) { |
|
93 | +function getpaid_doing_it_wrong($function, $message, $version) { |
|
94 | 94 | |
95 | 95 | $message .= ' Backtrace: ' . wp_debug_backtrace_summary(); |
96 | 96 | |
97 | - if ( is_ajax() || defined( 'REST_REQUEST' ) ) { |
|
98 | - do_action( 'doing_it_wrong_run', $function, $message, $version ); |
|
99 | - error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." ); |
|
97 | + if (is_ajax() || defined('REST_REQUEST')) { |
|
98 | + do_action('doing_it_wrong_run', $function, $message, $version); |
|
99 | + error_log("{$function} was called incorrectly. {$message}. This message was added in version {$version}."); |
|
100 | 100 | } else { |
101 | - _doing_it_wrong( $function, $message, $version ); |
|
101 | + _doing_it_wrong($function, $message, $version); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | } |