@@ -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 | * The Subscriptions DB Class |
@@ -72,8 +72,8 @@ discard block |
||
72 | 72 | 'transaction_id' => '', |
73 | 73 | 'parent_payment_id' => 0, |
74 | 74 | 'product_id' => 0, |
75 | - 'created' => date( 'Y-m-d H:i:s' ), |
|
76 | - 'expiration' => date( 'Y-m-d H:i:s' ), |
|
75 | + 'created' => date('Y-m-d H:i:s'), |
|
76 | + 'expiration' => date('Y-m-d H:i:s'), |
|
77 | 77 | 'trial_period' => '', |
78 | 78 | 'status' => '', |
79 | 79 | 'profile_id' => '', |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | * @access public |
87 | 87 | * @since 1.0.0 |
88 | 88 | */ |
89 | - public function get_subscriptions( $args = array() ) { |
|
90 | - return getpaid_get_subscriptions( $args ); |
|
89 | + public function get_subscriptions($args = array()) { |
|
90 | + return getpaid_get_subscriptions($args); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | * @access public |
97 | 97 | * @since 1.0.0 |
98 | 98 | */ |
99 | - public function count( $args = array() ) { |
|
100 | - return getpaid_get_subscriptions( $args, 'count' ); |
|
99 | + public function count($args = array()) { |
|
100 | + return getpaid_get_subscriptions($args, 'count'); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -133,9 +133,9 @@ discard block |
||
133 | 133 | KEY customer_and_status ( customer_id, status) |
134 | 134 | ) CHARACTER SET utf8 COLLATE utf8_general_ci;"; |
135 | 135 | |
136 | - dbDelta( $sql ); |
|
136 | + dbDelta($sql); |
|
137 | 137 | |
138 | - update_option( $this->table_name . '_db_version', $this->version ); |
|
138 | + update_option($this->table_name . '_db_version', $this->version); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | } |
@@ -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 | * This class handles subscription notificaiton emails. |
@@ -45,21 +45,21 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function init_hooks() { |
47 | 47 | |
48 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
49 | - foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
48 | + add_filter('getpaid_get_email_merge_tags', array($this, 'subscription_merge_tags'), 10, 2); |
|
49 | + foreach ($this->subscription_actions as $hook => $email_type) { |
|
50 | 50 | |
51 | - $email = new GetPaid_Notification_Email( $email_type ); |
|
51 | + $email = new GetPaid_Notification_Email($email_type); |
|
52 | 52 | |
53 | - if ( ! $email->is_active() ) { |
|
53 | + if (!$email->is_active()) { |
|
54 | 54 | continue; |
55 | 55 | } |
56 | 56 | |
57 | - if ( method_exists( $this, $email_type ) ) { |
|
58 | - add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
57 | + if (method_exists($this, $email_type)) { |
|
58 | + add_action($hook, array($this, $email_type), 100, 2); |
|
59 | 59 | continue; |
60 | 60 | } |
61 | 61 | |
62 | - do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
62 | + do_action('getpaid_subscription_notification_email_register_hook', $email_type, $hook); |
|
63 | 63 | |
64 | 64 | } |
65 | 65 | |
@@ -71,12 +71,12 @@ discard block |
||
71 | 71 | * @param array $merge_tags |
72 | 72 | * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
73 | 73 | */ |
74 | - public function subscription_merge_tags( $merge_tags, $object ) { |
|
74 | + public function subscription_merge_tags($merge_tags, $object) { |
|
75 | 75 | |
76 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
76 | + if (is_a($object, 'WPInv_Subscription')) { |
|
77 | 77 | $merge_tags = array_merge( |
78 | 78 | $merge_tags, |
79 | - $this->get_subscription_merge_tags( $object ) |
|
79 | + $this->get_subscription_merge_tags($object) |
|
80 | 80 | ); |
81 | 81 | } |
82 | 82 | |
@@ -90,25 +90,25 @@ discard block |
||
90 | 90 | * @param WPInv_Subscription $subscription |
91 | 91 | * @return array |
92 | 92 | */ |
93 | - public function get_subscription_merge_tags( $subscription ) { |
|
93 | + public function get_subscription_merge_tags($subscription) { |
|
94 | 94 | |
95 | 95 | // Abort if it does not exist. |
96 | - if ( ! $subscription->get_id() ) { |
|
96 | + if (!$subscription->get_id()) { |
|
97 | 97 | return array(); |
98 | 98 | } |
99 | 99 | |
100 | - $invoice = $subscription->get_parent_invoice(); |
|
100 | + $invoice = $subscription->get_parent_invoice(); |
|
101 | 101 | return array( |
102 | - '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
103 | - '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
104 | - '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
105 | - '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
106 | - '{subscription_id}' => absint( $subscription->get_id() ), |
|
107 | - '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ), |
|
108 | - '{subscription_initial_amount}' => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ), |
|
109 | - '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
102 | + '{subscription_renewal_date}' => getpaid_format_date_value($subscription->get_next_renewal_date(), __('Never', 'invoicing')), |
|
103 | + '{subscription_created}' => getpaid_format_date_value($subscription->get_date_created()), |
|
104 | + '{subscription_status}' => sanitize_text_field($subscription->get_status_label()), |
|
105 | + '{subscription_profile_id}' => sanitize_text_field($subscription->get_profile_id()), |
|
106 | + '{subscription_id}' => absint($subscription->get_id()), |
|
107 | + '{subscription_recurring_amount}' => sanitize_text_field(wpinv_price($subscription->get_recurring_amount(), $invoice->get_currency())), |
|
108 | + '{subscription_initial_amount}' => sanitize_text_field(wpinv_price($subscription->get_initial_amount(), $invoice->get_currency())), |
|
109 | + '{subscription_recurring_period}' => getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), ''), |
|
110 | 110 | '{subscription_bill_times}' => $subscription->get_bill_times(), |
111 | - '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
111 | + '{subscription_url}' => esc_url($subscription->get_view_url()), |
|
112 | 112 | ); |
113 | 113 | |
114 | 114 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @param WPInv_Invoice $invoice |
120 | 120 | * @return bool |
121 | 121 | */ |
122 | - public function should_send_notification( $invoice ) { |
|
122 | + public function should_send_notification($invoice) { |
|
123 | 123 | return 0 != $invoice->get_id(); |
124 | 124 | } |
125 | 125 | |
@@ -129,14 +129,14 @@ discard block |
||
129 | 129 | * @param WPInv_Invoice $invoice |
130 | 130 | * @return array |
131 | 131 | */ |
132 | - public function get_recipients( $invoice ) { |
|
133 | - $recipients = array( $invoice->get_email() ); |
|
132 | + public function get_recipients($invoice) { |
|
133 | + $recipients = array($invoice->get_email()); |
|
134 | 134 | |
135 | 135 | $cc = $invoice->get_email_cc(); |
136 | 136 | |
137 | - if ( ! empty( $cc ) ) { |
|
138 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
139 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
137 | + if (!empty($cc)) { |
|
138 | + $cc = array_map('sanitize_email', wpinv_parse_list($cc)); |
|
139 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc))); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | return $recipients; |
@@ -150,63 +150,63 @@ discard block |
||
150 | 150 | * @param string $type |
151 | 151 | * @param array $extra_args Extra template args. |
152 | 152 | */ |
153 | - public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
153 | + public function send_email($subscription, $email, $type, $extra_args = array()) { |
|
154 | 154 | |
155 | 155 | // Abort in case the parent invoice does not exist. |
156 | 156 | $invoice = $subscription->get_parent_invoice(); |
157 | - if ( ! $this->should_send_notification( $invoice ) ) { |
|
157 | + if (!$this->should_send_notification($invoice)) { |
|
158 | 158 | return; |
159 | 159 | } |
160 | 160 | |
161 | - if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) { |
|
161 | + if (apply_filters('getpaid_skip_subscription_email', false, $type, $subscription)) { |
|
162 | 162 | return; |
163 | 163 | } |
164 | 164 | |
165 | - do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
165 | + do_action('getpaid_before_send_subscription_notification', $type, $subscription, $email); |
|
166 | 166 | |
167 | - $recipients = $this->get_recipients( $invoice ); |
|
167 | + $recipients = $this->get_recipients($invoice); |
|
168 | 168 | $mailer = new GetPaid_Notification_Email_Sender(); |
169 | 169 | $merge_tags = $email->get_merge_tags(); |
170 | - $content = $email->get_content( $merge_tags, $extra_args ); |
|
171 | - $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
170 | + $content = $email->get_content($merge_tags, $extra_args); |
|
171 | + $subject = $email->add_merge_tags($email->get_subject(), $merge_tags); |
|
172 | 172 | $attachments = $email->get_attachments(); |
173 | 173 | |
174 | 174 | $result = $mailer->send( |
175 | - apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
175 | + apply_filters('getpaid_subscription_email_recipients', wpinv_parse_list($recipients), $email), |
|
176 | 176 | $subject, |
177 | 177 | $content, |
178 | 178 | $attachments |
179 | 179 | ); |
180 | 180 | |
181 | 181 | // Maybe send a copy to the admin. |
182 | - if ( $email->include_admin_bcc() ) { |
|
182 | + if ($email->include_admin_bcc()) { |
|
183 | 183 | $mailer->send( |
184 | 184 | wpinv_get_admin_email(), |
185 | - $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
185 | + $subject . __(' - ADMIN BCC COPY', 'invoicing'), |
|
186 | 186 | $content, |
187 | 187 | $attachments |
188 | 188 | ); |
189 | 189 | } |
190 | 190 | |
191 | - if ( $result ) { |
|
191 | + if ($result) { |
|
192 | 192 | $invoice->add_system_note( |
193 | 193 | sprintf( |
194 | - __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
195 | - sanitize_key( $type ), |
|
196 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
194 | + __('Successfully sent %1$s notification email to %2$s.', 'invoicing'), |
|
195 | + sanitize_key($type), |
|
196 | + $email->is_admin_email() ? __('admin') : __('the customer') |
|
197 | 197 | ) |
198 | 198 | ); |
199 | 199 | } else { |
200 | 200 | $invoice->add_system_note( |
201 | 201 | sprintf( |
202 | - __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
203 | - sanitize_key( $type ), |
|
204 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
202 | + __('Failed sending %1$s notification email to %2$s.', 'invoicing'), |
|
203 | + sanitize_key($type), |
|
204 | + $email->is_admin_email() ? __('admin') : __('the customer') |
|
205 | 205 | ) |
206 | 206 | ); |
207 | 207 | } |
208 | 208 | |
209 | - do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
209 | + do_action('getpaid_after_send_subscription_notification', $type, $subscription, $email); |
|
210 | 210 | |
211 | 211 | } |
212 | 212 | |
@@ -215,10 +215,10 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @param WPInv_Subscription $subscription |
217 | 217 | */ |
218 | - public function subscription_trial( $subscription ) { |
|
218 | + public function subscription_trial($subscription) { |
|
219 | 219 | |
220 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
221 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
220 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
221 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
222 | 222 | |
223 | 223 | } |
224 | 224 | |
@@ -227,10 +227,10 @@ discard block |
||
227 | 227 | * |
228 | 228 | * @param WPInv_Subscription $subscription |
229 | 229 | */ |
230 | - public function subscription_cancelled( $subscription ) { |
|
230 | + public function subscription_cancelled($subscription) { |
|
231 | 231 | |
232 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
233 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
232 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
233 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
234 | 234 | |
235 | 235 | } |
236 | 236 | |
@@ -239,10 +239,10 @@ discard block |
||
239 | 239 | * |
240 | 240 | * @param WPInv_Subscription $subscription |
241 | 241 | */ |
242 | - public function subscription_expired( $subscription ) { |
|
242 | + public function subscription_expired($subscription) { |
|
243 | 243 | |
244 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
245 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
244 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
245 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
246 | 246 | |
247 | 247 | } |
248 | 248 | |
@@ -251,10 +251,10 @@ discard block |
||
251 | 251 | * |
252 | 252 | * @param WPInv_Subscription $subscription |
253 | 253 | */ |
254 | - public function subscription_complete( $subscription ) { |
|
254 | + public function subscription_complete($subscription) { |
|
255 | 255 | |
256 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
257 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
256 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
257 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
258 | 258 | |
259 | 259 | } |
260 | 260 | |
@@ -264,18 +264,18 @@ discard block |
||
264 | 264 | */ |
265 | 265 | public function renewal_reminder() { |
266 | 266 | |
267 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
267 | + $email = new GetPaid_Notification_Email(__FUNCTION__); |
|
268 | 268 | |
269 | 269 | // Fetch reminder days. |
270 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
270 | + $reminder_days = array_unique(wp_parse_id_list($email->get_option('days'))); |
|
271 | 271 | |
272 | 272 | // Abort if non is set. |
273 | - if ( empty( $reminder_days ) ) { |
|
273 | + if (empty($reminder_days)) { |
|
274 | 274 | return; |
275 | 275 | } |
276 | 276 | |
277 | 277 | // Fetch matching subscriptions. |
278 | - $args = array( |
|
278 | + $args = array( |
|
279 | 279 | 'number' => -1, |
280 | 280 | 'count_total' => false, |
281 | 281 | 'status' => 'trialling active', |
@@ -284,8 +284,8 @@ discard block |
||
284 | 284 | ), |
285 | 285 | ); |
286 | 286 | |
287 | - foreach ( $reminder_days as $days ) { |
|
288 | - $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
287 | + foreach ($reminder_days as $days) { |
|
288 | + $date = date_parse(date('Y-m-d', strtotime("+$days days", current_time('timestamp')))); |
|
289 | 289 | |
290 | 290 | $args['date_expires_query'][] = array( |
291 | 291 | 'year' => $date['year'], |
@@ -295,14 +295,14 @@ discard block |
||
295 | 295 | |
296 | 296 | } |
297 | 297 | |
298 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
298 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
299 | 299 | |
300 | - foreach ( $subscriptions as $subscription ) { |
|
300 | + foreach ($subscriptions as $subscription) { |
|
301 | 301 | |
302 | 302 | // Skip packages. |
303 | - if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) { |
|
303 | + if (apply_filters('getpaid_send_subscription_renewal_reminder_email', true)) { |
|
304 | 304 | $email->object = $subscription; |
305 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
305 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
306 | 306 | } |
307 | 307 | } |
308 | 308 |
@@ -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 | * Retrieves an item by it's ID. |
@@ -14,9 +14,9 @@ discard block |
||
14 | 14 | * @param int the item ID to retrieve. |
15 | 15 | * @return WPInv_Item|false |
16 | 16 | */ |
17 | -function wpinv_get_item_by_id( $id ) { |
|
18 | - $item = wpinv_get_item( $id ); |
|
19 | - return empty( $item ) || $id != $item->get_id() ? false : $item; |
|
17 | +function wpinv_get_item_by_id($id) { |
|
18 | + $item = wpinv_get_item($id); |
|
19 | + return empty($item) || $id != $item->get_id() ? false : $item; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -24,14 +24,14 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @return WPInv_Item|false |
26 | 26 | */ |
27 | -function wpinv_get_item_by( $field = '', $value = '', $type = '' ) { |
|
27 | +function wpinv_get_item_by($field = '', $value = '', $type = '') { |
|
28 | 28 | |
29 | - if ( 'id' == strtolower( $field ) ) { |
|
30 | - return wpinv_get_item_by_id( $field ); |
|
29 | + if ('id' == strtolower($field)) { |
|
30 | + return wpinv_get_item_by_id($field); |
|
31 | 31 | } |
32 | 32 | |
33 | - $id = WPInv_Item::get_item_id_by_field( $value, strtolower( $field ), $type ); |
|
34 | - return empty( $id ) ? false : wpinv_get_item( $id ); |
|
33 | + $id = WPInv_Item::get_item_id_by_field($value, strtolower($field), $type); |
|
34 | + return empty($id) ? false : wpinv_get_item($id); |
|
35 | 35 | |
36 | 36 | } |
37 | 37 | |
@@ -41,24 +41,24 @@ discard block |
||
41 | 41 | * @param int|WPInv_Item the item to retrieve. |
42 | 42 | * @return WPInv_Item|false |
43 | 43 | */ |
44 | -function wpinv_get_item( $item = 0 ) { |
|
44 | +function wpinv_get_item($item = 0) { |
|
45 | 45 | |
46 | - if ( empty( $item ) ) { |
|
46 | + if (empty($item)) { |
|
47 | 47 | return false; |
48 | 48 | } |
49 | 49 | |
50 | - $item = new WPInv_Item( $item ); |
|
50 | + $item = new WPInv_Item($item); |
|
51 | 51 | return $item->exists() ? $item : false; |
52 | 52 | |
53 | 53 | } |
54 | 54 | |
55 | -function wpinv_get_all_items( $args = array() ) { |
|
55 | +function wpinv_get_all_items($args = array()) { |
|
56 | 56 | |
57 | 57 | $args = wp_parse_args( |
58 | 58 | $args, |
59 | 59 | array( |
60 | - 'status' => array( 'publish' ), |
|
61 | - 'limit' => get_option( 'posts_per_page' ), |
|
60 | + 'status' => array('publish'), |
|
61 | + 'limit' => get_option('posts_per_page'), |
|
62 | 62 | 'page' => 1, |
63 | 63 | 'exclude' => array(), |
64 | 64 | 'orderby' => 'date', |
@@ -78,44 +78,44 @@ discard block |
||
78 | 78 | 'fields' => 'ids', |
79 | 79 | 'orderby' => $args['orderby'], |
80 | 80 | 'order' => $args['order'], |
81 | - 'paged' => absint( $args['page'] ), |
|
81 | + 'paged' => absint($args['page']), |
|
82 | 82 | ); |
83 | 83 | |
84 | - if ( ! empty( $args['exclude'] ) ) { |
|
85 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
84 | + if (!empty($args['exclude'])) { |
|
85 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
86 | 86 | } |
87 | 87 | |
88 | - if ( ! $args['paginate'] ) { |
|
88 | + if (!$args['paginate']) { |
|
89 | 89 | $wp_query_args['no_found_rows'] = true; |
90 | 90 | } |
91 | 91 | |
92 | - if ( ! empty( $args['search'] ) ) { |
|
92 | + if (!empty($args['search'])) { |
|
93 | 93 | $wp_query_args['s'] = $args['search']; |
94 | 94 | } |
95 | 95 | |
96 | - if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) { |
|
97 | - $types = wpinv_parse_list( $args['type'] ); |
|
96 | + if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) { |
|
97 | + $types = wpinv_parse_list($args['type']); |
|
98 | 98 | $wp_query_args['meta_query'][] = array( |
99 | 99 | 'key' => '_wpinv_type', |
100 | - 'value' => implode( ',', $types ), |
|
100 | + 'value' => implode(',', $types), |
|
101 | 101 | 'compare' => 'IN', |
102 | 102 | ); |
103 | 103 | } |
104 | 104 | |
105 | - $wp_query_args = apply_filters( 'wpinv_get_items_args', $wp_query_args, $args ); |
|
105 | + $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args); |
|
106 | 106 | |
107 | 107 | // Get results. |
108 | - $items = new WP_Query( $wp_query_args ); |
|
108 | + $items = new WP_Query($wp_query_args); |
|
109 | 109 | |
110 | - if ( 'objects' === $args['return'] ) { |
|
111 | - $return = array_map( 'wpinv_get_item_by_id', $items->posts ); |
|
112 | - } elseif ( 'self' === $args['return'] ) { |
|
110 | + if ('objects' === $args['return']) { |
|
111 | + $return = array_map('wpinv_get_item_by_id', $items->posts); |
|
112 | + } elseif ('self' === $args['return']) { |
|
113 | 113 | return $items; |
114 | 114 | } else { |
115 | 115 | $return = $items->posts; |
116 | 116 | } |
117 | 117 | |
118 | - if ( $args['paginate'] ) { |
|
118 | + if ($args['paginate']) { |
|
119 | 119 | return (object) array( |
120 | 120 | 'items' => $return, |
121 | 121 | 'total' => $items->found_posts, |
@@ -127,12 +127,12 @@ discard block |
||
127 | 127 | |
128 | 128 | } |
129 | 129 | |
130 | -function wpinv_is_free_item( $item_id = 0 ) { |
|
131 | - if ( empty( $item_id ) ) { |
|
130 | +function wpinv_is_free_item($item_id = 0) { |
|
131 | + if (empty($item_id)) { |
|
132 | 132 | return false; |
133 | 133 | } |
134 | 134 | |
135 | - $item = new WPInv_Item( $item_id ); |
|
135 | + $item = new WPInv_Item($item_id); |
|
136 | 136 | |
137 | 137 | return $item->is_free(); |
138 | 138 | } |
@@ -142,21 +142,21 @@ discard block |
||
142 | 142 | * |
143 | 143 | * @param WP_Post|WPInv_Item|Int $item The item to check for. |
144 | 144 | */ |
145 | -function wpinv_item_is_editable( $item = 0 ) { |
|
145 | +function wpinv_item_is_editable($item = 0) { |
|
146 | 146 | |
147 | 147 | // Fetch the item. |
148 | - $item = new WPInv_Item( $item ); |
|
148 | + $item = new WPInv_Item($item); |
|
149 | 149 | |
150 | 150 | // Check if it is editable. |
151 | 151 | return $item->is_editable(); |
152 | 152 | } |
153 | 153 | |
154 | -function wpinv_get_item_price( $item_id = 0 ) { |
|
155 | - if ( empty( $item_id ) ) { |
|
154 | +function wpinv_get_item_price($item_id = 0) { |
|
155 | + if (empty($item_id)) { |
|
156 | 156 | return false; |
157 | 157 | } |
158 | 158 | |
159 | - $item = new WPInv_Item( $item_id ); |
|
159 | + $item = new WPInv_Item($item_id); |
|
160 | 160 | |
161 | 161 | return $item->get_price(); |
162 | 162 | } |
@@ -166,88 +166,88 @@ discard block |
||
166 | 166 | * |
167 | 167 | * @param WPInv_Item|int $item |
168 | 168 | */ |
169 | -function wpinv_is_recurring_item( $item = 0 ) { |
|
170 | - $item = new WPInv_Item( $item ); |
|
169 | +function wpinv_is_recurring_item($item = 0) { |
|
170 | + $item = new WPInv_Item($item); |
|
171 | 171 | return $item->is_recurring(); |
172 | 172 | } |
173 | 173 | |
174 | -function wpinv_item_price( $item_id = 0 ) { |
|
175 | - if ( empty( $item_id ) ) { |
|
174 | +function wpinv_item_price($item_id = 0) { |
|
175 | + if (empty($item_id)) { |
|
176 | 176 | return false; |
177 | 177 | } |
178 | 178 | |
179 | - $price = wpinv_get_item_price( $item_id ); |
|
180 | - $price = wpinv_price( $price ); |
|
179 | + $price = wpinv_get_item_price($item_id); |
|
180 | + $price = wpinv_price($price); |
|
181 | 181 | |
182 | - return apply_filters( 'wpinv_item_price', $price, $item_id ); |
|
182 | + return apply_filters('wpinv_item_price', $price, $item_id); |
|
183 | 183 | } |
184 | 184 | |
185 | -function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) { |
|
186 | - if ( is_null( $amount_override ) ) { |
|
187 | - $original_price = get_post_meta( $item_id, '_wpinv_price', true ); |
|
185 | +function wpinv_get_item_final_price($item_id = 0, $amount_override = null) { |
|
186 | + if (is_null($amount_override)) { |
|
187 | + $original_price = get_post_meta($item_id, '_wpinv_price', true); |
|
188 | 188 | } else { |
189 | 189 | $original_price = $amount_override; |
190 | 190 | } |
191 | 191 | |
192 | 192 | $price = $original_price; |
193 | 193 | |
194 | - return apply_filters( 'wpinv_get_item_final_price', $price, $item_id ); |
|
194 | + return apply_filters('wpinv_get_item_final_price', $price, $item_id); |
|
195 | 195 | } |
196 | 196 | |
197 | -function wpinv_item_custom_singular_name( $item_id ) { |
|
198 | - if ( empty( $item_id ) ) { |
|
197 | +function wpinv_item_custom_singular_name($item_id) { |
|
198 | + if (empty($item_id)) { |
|
199 | 199 | return false; |
200 | 200 | } |
201 | 201 | |
202 | - $item = new WPInv_Item( $item_id ); |
|
202 | + $item = new WPInv_Item($item_id); |
|
203 | 203 | |
204 | 204 | return $item->get_custom_singular_name(); |
205 | 205 | } |
206 | 206 | |
207 | 207 | function wpinv_get_item_types() { |
208 | 208 | $item_types = array( |
209 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
210 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
209 | + 'custom' => __('Standard', 'invoicing'), |
|
210 | + 'fee' => __('Fee', 'invoicing'), |
|
211 | 211 | ); |
212 | - return apply_filters( 'wpinv_get_item_types', $item_types ); |
|
212 | + return apply_filters('wpinv_get_item_types', $item_types); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | function wpinv_item_types() { |
216 | 216 | $item_types = wpinv_get_item_types(); |
217 | 217 | |
218 | - return ( ! empty( $item_types ) ? array_keys( $item_types ) : array() ); |
|
218 | + return (!empty($item_types) ? array_keys($item_types) : array()); |
|
219 | 219 | } |
220 | 220 | |
221 | -function wpinv_get_item_type( $item_id ) { |
|
222 | - if ( empty( $item_id ) ) { |
|
221 | +function wpinv_get_item_type($item_id) { |
|
222 | + if (empty($item_id)) { |
|
223 | 223 | return false; |
224 | 224 | } |
225 | 225 | |
226 | - $item = new WPInv_Item( $item_id ); |
|
226 | + $item = new WPInv_Item($item_id); |
|
227 | 227 | |
228 | 228 | return $item->get_type(); |
229 | 229 | } |
230 | 230 | |
231 | -function wpinv_item_type( $item_id ) { |
|
231 | +function wpinv_item_type($item_id) { |
|
232 | 232 | $item_types = wpinv_get_item_types(); |
233 | 233 | |
234 | - $item_type = wpinv_get_item_type( $item_id ); |
|
234 | + $item_type = wpinv_get_item_type($item_id); |
|
235 | 235 | |
236 | - if ( empty( $item_type ) ) { |
|
236 | + if (empty($item_type)) { |
|
237 | 237 | $item_type = '-'; |
238 | 238 | } |
239 | 239 | |
240 | - $item_type = isset( $item_types[ $item_type ] ) ? $item_types[ $item_type ] : __( $item_type, 'invoicing' ); |
|
240 | + $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing'); |
|
241 | 241 | |
242 | - return apply_filters( 'wpinv_item_type', $item_type, $item_id ); |
|
242 | + return apply_filters('wpinv_item_type', $item_type, $item_id); |
|
243 | 243 | } |
244 | 244 | |
245 | -function wpinv_get_random_item( $post_ids = true ) { |
|
246 | - wpinv_get_random_items( 1, $post_ids ); |
|
245 | +function wpinv_get_random_item($post_ids = true) { |
|
246 | + wpinv_get_random_items(1, $post_ids); |
|
247 | 247 | } |
248 | 248 | |
249 | -function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
|
250 | - if ( $post_ids ) { |
|
249 | +function wpinv_get_random_items($num = 3, $post_ids = true) { |
|
250 | + if ($post_ids) { |
|
251 | 251 | $args = array( |
252 | 252 | 'post_type' => 'wpi_item', |
253 | 253 | 'orderby' => 'rand', |
@@ -262,9 +262,9 @@ discard block |
||
262 | 262 | ); |
263 | 263 | } |
264 | 264 | |
265 | - $args = apply_filters( 'wpinv_get_random_items', $args ); |
|
265 | + $args = apply_filters('wpinv_get_random_items', $args); |
|
266 | 266 | |
267 | - return get_posts( $args ); |
|
267 | + return get_posts($args); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
@@ -273,13 +273,13 @@ discard block |
||
273 | 273 | * @param WPInv_Item|int $item |
274 | 274 | * @param bool $html |
275 | 275 | */ |
276 | -function wpinv_get_item_suffix( $item, $html = true ) { |
|
276 | +function wpinv_get_item_suffix($item, $html = true) { |
|
277 | 277 | |
278 | - $item = new WPInv_Item( $item ); |
|
279 | - $suffix = $item->is_recurring() ? ' ' . __( '(r)', 'invoicing' ) : ''; |
|
280 | - $suffix = $html ? $suffix : strip_tags( $suffix ); |
|
278 | + $item = new WPInv_Item($item); |
|
279 | + $suffix = $item->is_recurring() ? ' ' . __('(r)', 'invoicing') : ''; |
|
280 | + $suffix = $html ? $suffix : strip_tags($suffix); |
|
281 | 281 | |
282 | - return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html ); |
|
282 | + return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
@@ -288,9 +288,9 @@ discard block |
||
288 | 288 | * @param WPInv_Item|int $item |
289 | 289 | * @param bool $force_delete |
290 | 290 | */ |
291 | -function wpinv_remove_item( $item = 0, $force_delete = false ) { |
|
292 | - $item = new WPInv_Item( $item ); |
|
293 | - $item->delete( $force_delete ); |
|
291 | +function wpinv_remove_item($item = 0, $force_delete = false) { |
|
292 | + $item = new WPInv_Item($item); |
|
293 | + $item->delete($force_delete); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
@@ -329,44 +329,44 @@ discard block |
||
329 | 329 | * @param bool $wp_error whether or not to return a WP_Error on failure. |
330 | 330 | * @return bool|WP_Error|WPInv_Item |
331 | 331 | */ |
332 | -function wpinv_create_item( $args = array(), $wp_error = false ) { |
|
332 | +function wpinv_create_item($args = array(), $wp_error = false) { |
|
333 | 333 | |
334 | 334 | // Prepare the item. |
335 | - if ( ! empty( $args['custom_id'] ) && empty( $args['ID'] ) ) { |
|
336 | - $type = empty( $args['type'] ) ? 'custom' : $args['type']; |
|
337 | - $item = wpinv_get_item_by( 'custom_id', $args['custom_id'], $type ); |
|
335 | + if (!empty($args['custom_id']) && empty($args['ID'])) { |
|
336 | + $type = empty($args['type']) ? 'custom' : $args['type']; |
|
337 | + $item = wpinv_get_item_by('custom_id', $args['custom_id'], $type); |
|
338 | 338 | |
339 | - if ( ! empty( $item ) ) { |
|
339 | + if (!empty($item)) { |
|
340 | 340 | $args['ID'] = $item->get_id(); |
341 | 341 | } |
342 | 342 | } |
343 | 343 | |
344 | 344 | // Do we have an item? |
345 | - if ( ! empty( $args['ID'] ) ) { |
|
346 | - $item = new WPInv_Item( $args['ID'] ); |
|
345 | + if (!empty($args['ID'])) { |
|
346 | + $item = new WPInv_Item($args['ID']); |
|
347 | 347 | } else { |
348 | 348 | $item = new WPInv_Item(); |
349 | 349 | } |
350 | 350 | |
351 | 351 | // Do we have an error? |
352 | - if ( ! empty( $item->last_error ) ) { |
|
353 | - return $wp_error ? new WP_Error( 'invalid_item', $item->last_error ) : false; |
|
352 | + if (!empty($item->last_error)) { |
|
353 | + return $wp_error ? new WP_Error('invalid_item', $item->last_error) : false; |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | // Update item props. |
357 | - $item->set_props( $args ); |
|
357 | + $item->set_props($args); |
|
358 | 358 | |
359 | 359 | // Save the item. |
360 | 360 | $item->save(); |
361 | 361 | |
362 | 362 | // Do we have an error? |
363 | - if ( ! empty( $item->last_error ) ) { |
|
364 | - return $wp_error ? new WP_Error( 'not_saved', $item->last_error ) : false; |
|
363 | + if (!empty($item->last_error)) { |
|
364 | + return $wp_error ? new WP_Error('not_saved', $item->last_error) : false; |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | // Was the item saved? |
368 | - if ( ! $item->get_id() ) { |
|
369 | - return $wp_error ? new WP_Error( 'not_saved', __( 'An error occured while saving the item', 'invoicing' ) ) : false; |
|
368 | + if (!$item->get_id()) { |
|
369 | + return $wp_error ? new WP_Error('not_saved', __('An error occured while saving the item', 'invoicing')) : false; |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | return $item; |
@@ -378,14 +378,14 @@ discard block |
||
378 | 378 | * |
379 | 379 | * @see wpinv_create_item() |
380 | 380 | */ |
381 | -function wpinv_update_item( $args = array(), $wp_error = false ) { |
|
382 | - return wpinv_create_item( $args, $wp_error ); |
|
381 | +function wpinv_update_item($args = array(), $wp_error = false) { |
|
382 | + return wpinv_create_item($args, $wp_error); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | /** |
386 | 386 | * Sanitizes a recurring period |
387 | 387 | */ |
388 | -function getpaid_sanitize_recurring_period( $period, $full = false ) { |
|
388 | +function getpaid_sanitize_recurring_period($period, $full = false) { |
|
389 | 389 | |
390 | 390 | $periods = array( |
391 | 391 | 'D' => 'day', |
@@ -394,16 +394,16 @@ discard block |
||
394 | 394 | 'Y' => 'year', |
395 | 395 | ); |
396 | 396 | |
397 | - if ( ! isset( $periods[ $period ] ) ) { |
|
397 | + if (!isset($periods[$period])) { |
|
398 | 398 | $period = 'D'; |
399 | 399 | } |
400 | 400 | |
401 | - return $full ? $periods[ $period ] : $period; |
|
401 | + return $full ? $periods[$period] : $period; |
|
402 | 402 | |
403 | 403 | } |
404 | 404 | |
405 | -function wpinv_item_max_buyable_quantity( $item_id ) { |
|
406 | - return apply_filters( 'wpinv_item_max_buyable_quantity', 5, $item_id ); |
|
405 | +function wpinv_item_max_buyable_quantity($item_id) { |
|
406 | + return apply_filters('wpinv_item_max_buyable_quantity', 5, $item_id); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
@@ -411,45 +411,45 @@ discard block |
||
411 | 411 | * |
412 | 412 | * @param WPInv_Item|GetPaid_Form_Item $item |
413 | 413 | */ |
414 | -function getpaid_item_recurring_price_help_text( $item, $currency = '', $_initial_price = false, $_recurring_price = false ) { |
|
414 | +function getpaid_item_recurring_price_help_text($item, $currency = '', $_initial_price = false, $_recurring_price = false) { |
|
415 | 415 | |
416 | 416 | // Abort if it is not recurring. |
417 | - if ( ! $item->is_recurring() ) { |
|
417 | + if (!$item->is_recurring()) { |
|
418 | 418 | return ''; |
419 | 419 | } |
420 | 420 | |
421 | - $initial_price = false === $_initial_price ? wpinv_price( $item->get_initial_price(), $currency ) : $_initial_price; |
|
422 | - $recurring_price = false === $_recurring_price ? wpinv_price( $item->get_recurring_price(), $currency ) : $_recurring_price; |
|
423 | - $period = getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ); |
|
421 | + $initial_price = false === $_initial_price ? wpinv_price($item->get_initial_price(), $currency) : $_initial_price; |
|
422 | + $recurring_price = false === $_recurring_price ? wpinv_price($item->get_recurring_price(), $currency) : $_recurring_price; |
|
423 | + $period = getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), ''); |
|
424 | 424 | $initial_class = 'getpaid-item-initial-price'; |
425 | 425 | $recurring_class = 'getpaid-item-recurring-price'; |
426 | 426 | $bill_times = $item->get_recurring_limit(); |
427 | 427 | |
428 | - if ( ! empty( $bill_times ) ) { |
|
428 | + if (!empty($bill_times)) { |
|
429 | 429 | $bill_times = $item->get_recurring_interval() * $bill_times; |
430 | - $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
430 | + $bill_times = getpaid_get_subscription_period_label($item->get_recurring_period(), $bill_times); |
|
431 | 431 | } |
432 | 432 | |
433 | - if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) { |
|
434 | - $initial_price = wpinv_price( $item->get_sub_total(), $currency ); |
|
435 | - $recurring_price = wpinv_price( $item->get_recurring_sub_total(), $currency ); |
|
433 | + if ($item instanceof GetPaid_Form_Item && false === $_initial_price) { |
|
434 | + $initial_price = wpinv_price($item->get_sub_total(), $currency); |
|
435 | + $recurring_price = wpinv_price($item->get_recurring_sub_total(), $currency); |
|
436 | 436 | } |
437 | 437 | |
438 | - if ( wpinv_price( 0, $currency ) == $initial_price && wpinv_price( 0, $currency ) == $recurring_price ) { |
|
439 | - return __( 'Free forever', 'invoicing' ); |
|
438 | + if (wpinv_price(0, $currency) == $initial_price && wpinv_price(0, $currency) == $recurring_price) { |
|
439 | + return __('Free forever', 'invoicing'); |
|
440 | 440 | } |
441 | 441 | |
442 | 442 | // For free trial items. |
443 | - if ( $item->has_free_trial() ) { |
|
444 | - $trial_period = getpaid_get_subscription_period_label( $item->get_trial_period(), $item->get_trial_interval() ); |
|
443 | + if ($item->has_free_trial()) { |
|
444 | + $trial_period = getpaid_get_subscription_period_label($item->get_trial_period(), $item->get_trial_interval()); |
|
445 | 445 | |
446 | - if ( wpinv_price( 0, $currency ) == $initial_price ) { |
|
446 | + if (wpinv_price(0, $currency) == $initial_price) { |
|
447 | 447 | |
448 | - if ( empty( $bill_times ) ) { |
|
448 | + if (empty($bill_times)) { |
|
449 | 449 | |
450 | 450 | return sprintf( |
451 | 451 | // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period |
452 | - _x( 'Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing' ), |
|
452 | + _x('Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing'), |
|
453 | 453 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
454 | 454 | "<span class='$recurring_class'>$recurring_price</span>", |
455 | 455 | "<span class='getpaid-item-recurring-period'>$period</span>" |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | |
460 | 460 | return sprintf( |
461 | 461 | // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period, $4: is the bill times |
462 | - _x( 'Free for %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year for 4 years)', 'invoicing' ), |
|
462 | + _x('Free for %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year for 4 years)', 'invoicing'), |
|
463 | 463 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
464 | 464 | "<span class='$recurring_class'>$recurring_price</span>", |
465 | 465 | "<span class='getpaid-item-recurring-period'>$period</span>", |
@@ -468,11 +468,11 @@ discard block |
||
468 | 468 | |
469 | 469 | } |
470 | 470 | |
471 | - if ( empty( $bill_times ) ) { |
|
471 | + if (empty($bill_times)) { |
|
472 | 472 | |
473 | 473 | return sprintf( |
474 | 474 | // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period |
475 | - _x( '%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing' ), |
|
475 | + _x('%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing'), |
|
476 | 476 | "<span class='$initial_class'>$initial_price</span>", |
477 | 477 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
478 | 478 | "<span class='$recurring_class'>$recurring_price</span>", |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | |
484 | 484 | return sprintf( |
485 | 485 | // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period, $4: is the susbcription bill times |
486 | - _x( '%1$s for %2$s then %3$s / %4$s for %5$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year for 5 years)', 'invoicing' ), |
|
486 | + _x('%1$s for %2$s then %3$s / %4$s for %5$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year for 5 years)', 'invoicing'), |
|
487 | 487 | "<span class='$initial_class'>$initial_price</span>", |
488 | 488 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
489 | 489 | "<span class='$recurring_class'>$recurring_price</span>", |
@@ -493,13 +493,13 @@ discard block |
||
493 | 493 | |
494 | 494 | } |
495 | 495 | |
496 | - if ( $initial_price == $recurring_price ) { |
|
496 | + if ($initial_price == $recurring_price) { |
|
497 | 497 | |
498 | - if ( empty( $bill_times ) ) { |
|
498 | + if (empty($bill_times)) { |
|
499 | 499 | |
500 | 500 | return sprintf( |
501 | 501 | // translators: $1: is the recurring price, $2: is the susbcription period |
502 | - _x( '%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
502 | + _x('%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing'), |
|
503 | 503 | "<span class='$recurring_class'>$recurring_price</span>", |
504 | 504 | "<span class='getpaid-item-recurring-period'>$period</span>" |
505 | 505 | ); |
@@ -508,7 +508,7 @@ discard block |
||
508 | 508 | |
509 | 509 | return sprintf( |
510 | 510 | // translators: $1: is the recurring price, $2: is the susbcription period, $3: is the susbcription bill times |
511 | - _x( '%1$s / %2$s for %3$s', 'Item subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ), |
|
511 | + _x('%1$s / %2$s for %3$s', 'Item subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing'), |
|
512 | 512 | "<span class='$recurring_class'>$recurring_price</span>", |
513 | 513 | "<span class='getpaid-item-recurring-period'>$period</span>", |
514 | 514 | "<span class='getpaid-item-recurring-bill-times'>$bill_times</span>" |
@@ -516,13 +516,13 @@ discard block |
||
516 | 516 | |
517 | 517 | } |
518 | 518 | |
519 | - if ( $initial_price == wpinv_price( 0, $currency ) ) { |
|
519 | + if ($initial_price == wpinv_price(0, $currency)) { |
|
520 | 520 | |
521 | - if ( empty( $bill_times ) ) { |
|
521 | + if (empty($bill_times)) { |
|
522 | 522 | |
523 | 523 | return sprintf( |
524 | 524 | // translators: $1: is the recurring period, $2: is the recurring price |
525 | - _x( 'Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing' ), |
|
525 | + _x('Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing'), |
|
526 | 526 | "<span class='getpaid-item-recurring-period'>$period</span>", |
527 | 527 | "<span class='$recurring_class'>$recurring_price</span>" |
528 | 528 | ); |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | |
532 | 532 | return sprintf( |
533 | 533 | // translators: $1: is the recurring period, $2: is the recurring price, $3: is the bill times |
534 | - _x( 'Free for %1$s then %2$s / %1$s for %3$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months for 12 months)', 'invoicing' ), |
|
534 | + _x('Free for %1$s then %2$s / %1$s for %3$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months for 12 months)', 'invoicing'), |
|
535 | 535 | "<span class='getpaid-item-recurring-period'>$period</span>", |
536 | 536 | "<span class='$recurring_class'>$recurring_price</span>", |
537 | 537 | "<span class='getpaid-item-recurring-bill-times'>$bill_times</span>" |
@@ -539,11 +539,11 @@ discard block |
||
539 | 539 | |
540 | 540 | } |
541 | 541 | |
542 | - if ( empty( $bill_times ) ) { |
|
542 | + if (empty($bill_times)) { |
|
543 | 543 | |
544 | 544 | return sprintf( |
545 | 545 | // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period |
546 | - _x( 'Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing' ), |
|
546 | + _x('Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing'), |
|
547 | 547 | "<span class='$initial_class'>$initial_price</span>", |
548 | 548 | "<span class='$recurring_class'>$recurring_price</span>", |
549 | 549 | "<span class='getpaid-item-recurring-period'>$period</span>" |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | |
554 | 554 | return sprintf( |
555 | 555 | // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period, $4: is the susbcription bill times |
556 | - _x( 'Initial payment of %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year for 4 years)', 'invoicing' ), |
|
556 | + _x('Initial payment of %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year for 4 years)', 'invoicing'), |
|
557 | 557 | "<span class='$initial_class'>$initial_price</span>", |
558 | 558 | "<span class='$recurring_class'>$recurring_price</span>", |
559 | 559 | "<span class='getpaid-item-recurring-period'>$period</span>", |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | $this->state = wpinv_get_default_state(); |
147 | 147 | |
148 | 148 | // Do we have an actual submission? |
149 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
150 | - $this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) ); |
|
149 | + if (isset($_POST['getpaid_payment_form_submission'])) { |
|
150 | + $this->load_data(wp_kses_post_deep(wp_unslash($_POST))); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | } |
@@ -157,16 +157,16 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @param array $data |
159 | 159 | */ |
160 | - public function load_data( $data ) { |
|
160 | + public function load_data($data) { |
|
161 | 161 | |
162 | 162 | // Allow plugins to filter the data. |
163 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
163 | + $data = apply_filters('getpaid_submission_data', $data, $this); |
|
164 | 164 | |
165 | 165 | // Cache it... |
166 | 166 | $this->data = $data; |
167 | 167 | |
168 | 168 | // Then generate a unique id from the data. |
169 | - $this->id = md5( wp_json_encode( $data ) ); |
|
169 | + $this->id = md5(wp_json_encode($data)); |
|
170 | 170 | |
171 | 171 | // Finally, process the submission. |
172 | 172 | try { |
@@ -176,29 +176,29 @@ discard block |
||
176 | 176 | $processors = apply_filters( |
177 | 177 | 'getpaid_payment_form_submission_processors', |
178 | 178 | array( |
179 | - array( $this, 'process_payment_form' ), |
|
180 | - array( $this, 'process_invoice' ), |
|
181 | - array( $this, 'process_fees' ), |
|
182 | - array( $this, 'process_items' ), |
|
183 | - array( $this, 'process_discount' ), |
|
184 | - array( $this, 'process_taxes' ), |
|
179 | + array($this, 'process_payment_form'), |
|
180 | + array($this, 'process_invoice'), |
|
181 | + array($this, 'process_fees'), |
|
182 | + array($this, 'process_items'), |
|
183 | + array($this, 'process_discount'), |
|
184 | + array($this, 'process_taxes'), |
|
185 | 185 | ), |
186 | 186 | $this |
187 | 187 | ); |
188 | 188 | |
189 | - foreach ( $processors as $processor ) { |
|
190 | - call_user_func_array( $processor, array( &$this ) ); |
|
189 | + foreach ($processors as $processor) { |
|
190 | + call_user_func_array($processor, array(&$this)); |
|
191 | 191 | } |
192 | -} catch ( GetPaid_Payment_Exception $e ) { |
|
192 | +} catch (GetPaid_Payment_Exception $e) { |
|
193 | 193 | $this->last_error = $e->getMessage(); |
194 | 194 | $this->last_error_code = $e->getErrorCode(); |
195 | - } catch ( Exception $e ) { |
|
195 | + } catch (Exception $e) { |
|
196 | 196 | $this->last_error = $e->getMessage(); |
197 | 197 | $this->last_error_code = $e->getCode(); |
198 | 198 | } |
199 | 199 | |
200 | 200 | // Fired when we are done processing a submission. |
201 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
201 | + do_action_ref_array('getpaid_process_submission', array(&$this)); |
|
202 | 202 | |
203 | 203 | } |
204 | 204 | |
@@ -219,18 +219,18 @@ discard block |
||
219 | 219 | public function process_payment_form() { |
220 | 220 | |
221 | 221 | // Every submission needs an active payment form. |
222 | - if ( empty( $this->data['form_id'] ) ) { |
|
223 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
222 | + if (empty($this->data['form_id'])) { |
|
223 | + throw new Exception(__('Missing payment form', 'invoicing')); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | // Fetch the payment form. |
227 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
227 | + $this->payment_form = new GetPaid_Payment_Form($this->data['form_id']); |
|
228 | 228 | |
229 | - if ( ! $this->payment_form->is_active() ) { |
|
230 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
229 | + if (!$this->payment_form->is_active()) { |
|
230 | + throw new Exception(__('Payment form not active', 'invoicing')); |
|
231 | 231 | } |
232 | 232 | |
233 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
233 | + do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this)); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
@@ -260,53 +260,53 @@ discard block |
||
260 | 260 | public function process_invoice() { |
261 | 261 | |
262 | 262 | // Abort if there is no invoice. |
263 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
263 | + if (empty($this->data['invoice_id'])) { |
|
264 | 264 | return; |
265 | 265 | } |
266 | 266 | |
267 | 267 | // If the submission is for an existing invoice, ensure that it exists |
268 | 268 | // and that it is not paid for. |
269 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
269 | + $invoice = wpinv_get_invoice($this->data['invoice_id']); |
|
270 | 270 | |
271 | - if ( empty( $invoice ) ) { |
|
272 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
271 | + if (empty($invoice)) { |
|
272 | + throw new Exception(__('Invalid invoice', 'invoicing')); |
|
273 | 273 | } |
274 | 274 | |
275 | - if ( $invoice->is_paid() ) { |
|
276 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
275 | + if ($invoice->is_paid()) { |
|
276 | + throw new Exception(__('This invoice is already paid for.', 'invoicing')); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | $this->payment_form->invoice = $invoice; |
280 | - if ( ! $this->payment_form->is_default() ) { |
|
280 | + if (!$this->payment_form->is_default()) { |
|
281 | 281 | |
282 | 282 | $items = array(); |
283 | 283 | $item_ids = array(); |
284 | 284 | |
285 | - foreach ( $invoice->get_items() as $item ) { |
|
286 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
285 | + foreach ($invoice->get_items() as $item) { |
|
286 | + if (!in_array($item->get_id(), $item_ids)) { |
|
287 | 287 | $item_ids[] = $item->get_id(); |
288 | 288 | $items[] = $item; |
289 | 289 | } |
290 | 290 | } |
291 | 291 | |
292 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
293 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
292 | + foreach ($this->payment_form->get_items() as $item) { |
|
293 | + if (!in_array($item->get_id(), $item_ids)) { |
|
294 | 294 | $item_ids[] = $item->get_id(); |
295 | 295 | $items[] = $item; |
296 | 296 | } |
297 | 297 | } |
298 | 298 | |
299 | - $this->payment_form->set_items( $items ); |
|
299 | + $this->payment_form->set_items($items); |
|
300 | 300 | |
301 | 301 | } else { |
302 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
302 | + $this->payment_form->set_items($invoice->get_items()); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | $this->country = $invoice->get_country(); |
306 | 306 | $this->state = $invoice->get_state(); |
307 | 307 | $this->invoice = $invoice; |
308 | 308 | |
309 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
309 | + do_action_ref_array('getpaid_submissions_process_invoice', array(&$this)); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | /** |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | * @return bool |
327 | 327 | */ |
328 | 328 | public function has_invoice() { |
329 | - return ! empty( $this->invoice ); |
|
329 | + return !empty($this->invoice); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | /* |
@@ -345,13 +345,13 @@ discard block |
||
345 | 345 | */ |
346 | 346 | public function process_items() { |
347 | 347 | |
348 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
348 | + $processor = new GetPaid_Payment_Form_Submission_Items($this); |
|
349 | 349 | |
350 | - foreach ( $processor->items as $item ) { |
|
351 | - $this->add_item( $item ); |
|
350 | + foreach ($processor->items as $item) { |
|
351 | + $this->add_item($item); |
|
352 | 352 | } |
353 | 353 | |
354 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
354 | + do_action_ref_array('getpaid_submissions_process_items', array(&$this)); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
@@ -360,20 +360,20 @@ discard block |
||
360 | 360 | * @since 1.0.19 |
361 | 361 | * @param GetPaid_Form_Item $item |
362 | 362 | */ |
363 | - public function add_item( $item ) { |
|
363 | + public function add_item($item) { |
|
364 | 364 | |
365 | 365 | // Make sure that it is available for purchase. |
366 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
366 | + if (!$item->can_purchase() || isset($this->items[$item->get_id()])) { |
|
367 | 367 | return; |
368 | 368 | } |
369 | 369 | |
370 | 370 | // Each submission can only contain one recurring item. |
371 | - if ( $item->is_recurring() ) { |
|
371 | + if ($item->is_recurring()) { |
|
372 | 372 | $this->has_recurring = $item->get_id(); |
373 | 373 | } |
374 | 374 | |
375 | 375 | // Update the items and totals. |
376 | - $this->items[ $item->get_id() ] = $item; |
|
376 | + $this->items[$item->get_id()] = $item; |
|
377 | 377 | $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
378 | 378 | $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
379 | 379 | |
@@ -387,17 +387,17 @@ discard block |
||
387 | 387 | * |
388 | 388 | * @since 1.0.19 |
389 | 389 | */ |
390 | - public function remove_item( $item_id ) { |
|
390 | + public function remove_item($item_id) { |
|
391 | 391 | |
392 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
393 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
394 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
392 | + if (isset($this->items[$item_id])) { |
|
393 | + $this->totals['subtotal']['initial'] -= $this->items[$item_id]->get_sub_total(); |
|
394 | + $this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total(); |
|
395 | 395 | |
396 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
396 | + if ($this->items[$item_id]->is_recurring()) { |
|
397 | 397 | $this->has_recurring = 0; |
398 | 398 | } |
399 | 399 | |
400 | - unset( $this->items[ $item_id ] ); |
|
400 | + unset($this->items[$item_id]); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | } |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | */ |
410 | 410 | public function get_subtotal() { |
411 | 411 | |
412 | - if ( wpinv_prices_include_tax() ) { |
|
412 | + if (wpinv_prices_include_tax()) { |
|
413 | 413 | return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
414 | 414 | } |
415 | 415 | |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | */ |
424 | 424 | public function get_recurring_subtotal() { |
425 | 425 | |
426 | - if ( wpinv_prices_include_tax() ) { |
|
426 | + if (wpinv_prices_include_tax()) { |
|
427 | 427 | return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
428 | 428 | } |
429 | 429 | |
@@ -447,7 +447,7 @@ discard block |
||
447 | 447 | * @return bool |
448 | 448 | */ |
449 | 449 | public function has_subscription_group() { |
450 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
450 | + return $this->has_recurring && getpaid_should_group_subscriptions($this) && 1 == count(getpaid_get_subscription_groups($this)); |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | /** |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | * @return bool |
458 | 458 | */ |
459 | 459 | public function has_multiple_subscription_groups() { |
460 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
460 | + return $this->has_recurring && 1 < count(getpaid_get_subscription_groups($this)); |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | /* |
@@ -477,39 +477,39 @@ discard block |
||
477 | 477 | public function process_taxes() { |
478 | 478 | |
479 | 479 | // Abort if we're not using taxes. |
480 | - if ( ! $this->use_taxes() ) { |
|
480 | + if (!$this->use_taxes()) { |
|
481 | 481 | return; |
482 | 482 | } |
483 | 483 | |
484 | 484 | // If a custom country && state has been passed in, use it to calculate taxes. |
485 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
486 | - if ( ! empty( $country ) ) { |
|
485 | + $country = $this->get_field('wpinv_country', 'billing'); |
|
486 | + if (!empty($country)) { |
|
487 | 487 | $this->country = $country; |
488 | 488 | } |
489 | 489 | |
490 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
491 | - if ( ! empty( $state ) ) { |
|
490 | + $state = $this->get_field('wpinv_state', 'billing'); |
|
491 | + if (!empty($state)) { |
|
492 | 492 | $this->state = $state; |
493 | 493 | } |
494 | 494 | |
495 | 495 | // Confirm if the provided country and the ip country are similar. |
496 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
497 | - if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
498 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
496 | + $address_confirmed = $this->get_field('confirm-address'); |
|
497 | + if (isset($_POST['billing']['country']) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) { |
|
498 | + throw new Exception(__('The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing')); |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | // Abort if the country is not taxable. |
502 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
502 | + if (!wpinv_is_country_taxable($this->country)) { |
|
503 | 503 | return; |
504 | 504 | } |
505 | 505 | |
506 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
506 | + $processor = new GetPaid_Payment_Form_Submission_Taxes($this); |
|
507 | 507 | |
508 | - foreach ( $processor->taxes as $tax ) { |
|
509 | - $this->add_tax( $tax ); |
|
508 | + foreach ($processor->taxes as $tax) { |
|
509 | + $this->add_tax($tax); |
|
510 | 510 | } |
511 | 511 | |
512 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
512 | + do_action_ref_array('getpaid_submissions_process_taxes', array(&$this)); |
|
513 | 513 | } |
514 | 514 | |
515 | 515 | /** |
@@ -518,16 +518,16 @@ discard block |
||
518 | 518 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
519 | 519 | * @since 1.0.19 |
520 | 520 | */ |
521 | - public function add_tax( $tax ) { |
|
521 | + public function add_tax($tax) { |
|
522 | 522 | |
523 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
524 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
525 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
523 | + if (wpinv_round_tax_per_tax_rate()) { |
|
524 | + $tax['initial_tax'] = wpinv_round_amount($tax['initial_tax']); |
|
525 | + $tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']); |
|
526 | 526 | } |
527 | 527 | |
528 | - $this->taxes[ $tax['name'] ] = $tax; |
|
529 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
530 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
528 | + $this->taxes[$tax['name']] = $tax; |
|
529 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount($tax['initial_tax']); |
|
530 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']); |
|
531 | 531 | |
532 | 532 | } |
533 | 533 | |
@@ -536,12 +536,12 @@ discard block |
||
536 | 536 | * |
537 | 537 | * @since 1.0.19 |
538 | 538 | */ |
539 | - public function remove_tax( $tax_name ) { |
|
539 | + public function remove_tax($tax_name) { |
|
540 | 540 | |
541 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
542 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
543 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
544 | - unset( $this->taxes[ $tax_name ] ); |
|
541 | + if (isset($this->taxes[$tax_name])) { |
|
542 | + $this->totals['taxes']['initial'] -= $this->taxes[$tax_name]['initial_tax']; |
|
543 | + $this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax']; |
|
544 | + unset($this->taxes[$tax_name]); |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | } |
@@ -555,11 +555,11 @@ discard block |
||
555 | 555 | |
556 | 556 | $use_taxes = wpinv_use_taxes(); |
557 | 557 | |
558 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
558 | + if ($this->has_invoice() && !$this->invoice->is_taxable()) { |
|
559 | 559 | $use_taxes = false; |
560 | 560 | } |
561 | 561 | |
562 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
562 | + return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this); |
|
563 | 563 | |
564 | 564 | } |
565 | 565 | |
@@ -608,13 +608,13 @@ discard block |
||
608 | 608 | |
609 | 609 | $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
610 | 610 | $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
611 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
611 | + $processor = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total); |
|
612 | 612 | |
613 | - foreach ( $processor->discounts as $discount ) { |
|
614 | - $this->add_discount( $discount ); |
|
613 | + foreach ($processor->discounts as $discount) { |
|
614 | + $this->add_discount($discount); |
|
615 | 615 | } |
616 | 616 | |
617 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
617 | + do_action_ref_array('getpaid_submissions_process_discounts', array(&$this)); |
|
618 | 618 | } |
619 | 619 | |
620 | 620 | /** |
@@ -623,10 +623,10 @@ discard block |
||
623 | 623 | * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
624 | 624 | * @since 1.0.19 |
625 | 625 | */ |
626 | - public function add_discount( $discount ) { |
|
627 | - $this->discounts[ $discount['name'] ] = $discount; |
|
628 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
629 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
626 | + public function add_discount($discount) { |
|
627 | + $this->discounts[$discount['name']] = $discount; |
|
628 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount($discount['initial_discount']); |
|
629 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']); |
|
630 | 630 | } |
631 | 631 | |
632 | 632 | /** |
@@ -634,12 +634,12 @@ discard block |
||
634 | 634 | * |
635 | 635 | * @since 1.0.19 |
636 | 636 | */ |
637 | - public function remove_discount( $name ) { |
|
637 | + public function remove_discount($name) { |
|
638 | 638 | |
639 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
640 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
641 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
642 | - unset( $this->discounts[ $name ] ); |
|
639 | + if (isset($this->discounts[$name])) { |
|
640 | + $this->totals['discount']['initial'] -= $this->discounts[$name]['initial_discount']; |
|
641 | + $this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount']; |
|
642 | + unset($this->discounts[$name]); |
|
643 | 643 | } |
644 | 644 | |
645 | 645 | } |
@@ -651,7 +651,7 @@ discard block |
||
651 | 651 | * @return bool |
652 | 652 | */ |
653 | 653 | public function has_discount_code() { |
654 | - return ! empty( $this->discounts['discount_code'] ); |
|
654 | + return !empty($this->discounts['discount_code']); |
|
655 | 655 | } |
656 | 656 | |
657 | 657 | /** |
@@ -708,13 +708,13 @@ discard block |
||
708 | 708 | */ |
709 | 709 | public function process_fees() { |
710 | 710 | |
711 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
711 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees($this); |
|
712 | 712 | |
713 | - foreach ( $fees_processor->fees as $fee ) { |
|
714 | - $this->add_fee( $fee ); |
|
713 | + foreach ($fees_processor->fees as $fee) { |
|
714 | + $this->add_fee($fee); |
|
715 | 715 | } |
716 | 716 | |
717 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
717 | + do_action_ref_array('getpaid_submissions_process_fees', array(&$this)); |
|
718 | 718 | } |
719 | 719 | |
720 | 720 | /** |
@@ -723,17 +723,17 @@ discard block |
||
723 | 723 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
724 | 724 | * @since 1.0.19 |
725 | 725 | */ |
726 | - public function add_fee( $fee ) { |
|
726 | + public function add_fee($fee) { |
|
727 | 727 | |
728 | - if ( $fee['name'] == 'shipping' ) { |
|
729 | - $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
730 | - $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
728 | + if ($fee['name'] == 'shipping') { |
|
729 | + $this->totals['shipping']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
730 | + $this->totals['shipping']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
731 | 731 | return; |
732 | 732 | } |
733 | 733 | |
734 | - $this->fees[ $fee['name'] ] = $fee; |
|
735 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
736 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
734 | + $this->fees[$fee['name']] = $fee; |
|
735 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
736 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
737 | 737 | |
738 | 738 | } |
739 | 739 | |
@@ -742,15 +742,15 @@ discard block |
||
742 | 742 | * |
743 | 743 | * @since 1.0.19 |
744 | 744 | */ |
745 | - public function remove_fee( $name ) { |
|
745 | + public function remove_fee($name) { |
|
746 | 746 | |
747 | - if ( isset( $this->fees[ $name ] ) ) { |
|
748 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
749 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
750 | - unset( $this->fees[ $name ] ); |
|
747 | + if (isset($this->fees[$name])) { |
|
748 | + $this->totals['fees']['initial'] -= $this->fees[$name]['initial_fee']; |
|
749 | + $this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee']; |
|
750 | + unset($this->fees[$name]); |
|
751 | 751 | } |
752 | 752 | |
753 | - if ( 'shipping' == $name ) { |
|
753 | + if ('shipping' == $name) { |
|
754 | 754 | $this->totals['shipping']['initial'] = 0; |
755 | 755 | $this->totals['shipping']['recurring'] = 0; |
756 | 756 | } |
@@ -791,7 +791,7 @@ discard block |
||
791 | 791 | * @since 1.0.19 |
792 | 792 | */ |
793 | 793 | public function has_fees() { |
794 | - return count( $this->fees ) !== 0; |
|
794 | + return count($this->fees) !== 0; |
|
795 | 795 | } |
796 | 796 | |
797 | 797 | /* |
@@ -827,7 +827,7 @@ discard block |
||
827 | 827 | * @since 1.0.19 |
828 | 828 | */ |
829 | 829 | public function has_shipping() { |
830 | - return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
830 | + return apply_filters('getpaid_payment_form_has_shipping', false, $this); |
|
831 | 831 | } |
832 | 832 | |
833 | 833 | /** |
@@ -837,7 +837,7 @@ discard block |
||
837 | 837 | * @since 1.0.19 |
838 | 838 | */ |
839 | 839 | public function is_initial_fetch() { |
840 | - return empty( $this->data['initial_state'] ); |
|
840 | + return empty($this->data['initial_state']); |
|
841 | 841 | } |
842 | 842 | |
843 | 843 | /** |
@@ -847,7 +847,7 @@ discard block |
||
847 | 847 | */ |
848 | 848 | public function get_total() { |
849 | 849 | $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
850 | - return max( $total, 0 ); |
|
850 | + return max($total, 0); |
|
851 | 851 | } |
852 | 852 | |
853 | 853 | /** |
@@ -857,7 +857,7 @@ discard block |
||
857 | 857 | */ |
858 | 858 | public function get_recurring_total() { |
859 | 859 | $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
860 | - return max( $total, 0 ); |
|
860 | + return max($total, 0); |
|
861 | 861 | } |
862 | 862 | |
863 | 863 | /** |
@@ -869,12 +869,12 @@ discard block |
||
869 | 869 | $initial = $this->get_total(); |
870 | 870 | $recurring = $this->get_recurring_total(); |
871 | 871 | |
872 | - if ( $this->has_recurring == 0 ) { |
|
872 | + if ($this->has_recurring == 0) { |
|
873 | 873 | $recurring = 0; |
874 | 874 | } |
875 | 875 | |
876 | 876 | $collect = $initial > 0 || $recurring > 0; |
877 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
877 | + return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this); |
|
878 | 878 | } |
879 | 879 | |
880 | 880 | /** |
@@ -883,7 +883,7 @@ discard block |
||
883 | 883 | * @since 1.0.19 |
884 | 884 | */ |
885 | 885 | public function get_billing_email() { |
886 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
886 | + return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this); |
|
887 | 887 | } |
888 | 888 | |
889 | 889 | /** |
@@ -893,7 +893,7 @@ discard block |
||
893 | 893 | */ |
894 | 894 | public function has_billing_email() { |
895 | 895 | $billing_email = $this->get_billing_email(); |
896 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
896 | + return !empty($billing_email) && is_email($billing_email); |
|
897 | 897 | } |
898 | 898 | |
899 | 899 | /** |
@@ -923,8 +923,8 @@ discard block |
||
923 | 923 | * @since 1.0.19 |
924 | 924 | * @return mixed|null |
925 | 925 | */ |
926 | - public function get_field( $field, $sub_array_key = null ) { |
|
927 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
926 | + public function get_field($field, $sub_array_key = null) { |
|
927 | + return getpaid_get_array_field($this->data, $field, $sub_array_key); |
|
928 | 928 | } |
929 | 929 | |
930 | 930 | /** |
@@ -932,8 +932,8 @@ discard block |
||
932 | 932 | * |
933 | 933 | * @since 1.0.19 |
934 | 934 | */ |
935 | - public function is_required_field_set( $field ) { |
|
936 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
935 | + public function is_required_field_set($field) { |
|
936 | + return empty($field['required']) || !empty($this->data[$field['id']]); |
|
937 | 937 | } |
938 | 938 | |
939 | 939 | /** |
@@ -941,8 +941,8 @@ discard block |
||
941 | 941 | * |
942 | 942 | * @since 1.0.19 |
943 | 943 | */ |
944 | - public function format_amount( $amount ) { |
|
945 | - return wpinv_price( $amount, $this->get_currency() ); |
|
944 | + public function format_amount($amount) { |
|
945 | + return wpinv_price($amount, $this->get_currency()); |
|
946 | 946 | } |
947 | 947 | |
948 | 948 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -72,28 +72,28 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
74 | 74 | */ |
75 | - public function __construct( $form = 0 ) { |
|
76 | - parent::__construct( $form ); |
|
75 | + public function __construct($form = 0) { |
|
76 | + parent::__construct($form); |
|
77 | 77 | |
78 | - if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | - $this->set_id( $form ); |
|
80 | - } elseif ( $form instanceof self ) { |
|
78 | + if (is_numeric($form) && $form > 0) { |
|
79 | + $this->set_id($form); |
|
80 | + } elseif ($form instanceof self) { |
|
81 | 81 | |
82 | - $this->set_id( $form->get_id() ); |
|
82 | + $this->set_id($form->get_id()); |
|
83 | 83 | $this->invoice = $form->invoice; |
84 | 84 | |
85 | - } elseif ( ! empty( $form->ID ) ) { |
|
86 | - $this->set_id( $form->ID ); |
|
85 | + } elseif (!empty($form->ID)) { |
|
86 | + $this->set_id($form->ID); |
|
87 | 87 | } else { |
88 | - $this->set_object_read( true ); |
|
88 | + $this->set_object_read(true); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | // Load the datastore. |
92 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
92 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
93 | 93 | |
94 | - if ( $this->get_id() > 0 ) { |
|
95 | - $this->post = get_post( $this->get_id() ); |
|
96 | - $this->data_store->read( $this ); |
|
94 | + if ($this->get_id() > 0) { |
|
95 | + $this->post = get_post($this->get_id()); |
|
96 | + $this->data_store->read($this); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | } |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | * @param string $context View or edit context. |
121 | 121 | * @return string |
122 | 122 | */ |
123 | - public function get_version( $context = 'view' ) { |
|
124 | - return $this->get_prop( 'version', $context ); |
|
123 | + public function get_version($context = 'view') { |
|
124 | + return $this->get_prop('version', $context); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | * @param string $context View or edit context. |
132 | 132 | * @return string |
133 | 133 | */ |
134 | - public function get_date_created( $context = 'view' ) { |
|
135 | - return $this->get_prop( 'date_created', $context ); |
|
134 | + public function get_date_created($context = 'view') { |
|
135 | + return $this->get_prop('date_created', $context); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | * @param string $context View or edit context. |
143 | 143 | * @return string |
144 | 144 | */ |
145 | - public function get_date_created_gmt( $context = 'view' ) { |
|
146 | - $date = $this->get_date_created( $context ); |
|
145 | + public function get_date_created_gmt($context = 'view') { |
|
146 | + $date = $this->get_date_created($context); |
|
147 | 147 | |
148 | - if ( $date ) { |
|
149 | - $date = get_gmt_from_date( $date ); |
|
148 | + if ($date) { |
|
149 | + $date = get_gmt_from_date($date); |
|
150 | 150 | } |
151 | 151 | return $date; |
152 | 152 | } |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * @param string $context View or edit context. |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - public function get_date_modified( $context = 'view' ) { |
|
162 | - return $this->get_prop( 'date_modified', $context ); |
|
161 | + public function get_date_modified($context = 'view') { |
|
162 | + return $this->get_prop('date_modified', $context); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -169,11 +169,11 @@ discard block |
||
169 | 169 | * @param string $context View or edit context. |
170 | 170 | * @return string |
171 | 171 | */ |
172 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
173 | - $date = $this->get_date_modified( $context ); |
|
172 | + public function get_date_modified_gmt($context = 'view') { |
|
173 | + $date = $this->get_date_modified($context); |
|
174 | 174 | |
175 | - if ( $date ) { |
|
176 | - $date = get_gmt_from_date( $date ); |
|
175 | + if ($date) { |
|
176 | + $date = get_gmt_from_date($date); |
|
177 | 177 | } |
178 | 178 | return $date; |
179 | 179 | } |
@@ -185,8 +185,8 @@ discard block |
||
185 | 185 | * @param string $context View or edit context. |
186 | 186 | * @return string |
187 | 187 | */ |
188 | - public function get_name( $context = 'view' ) { |
|
189 | - return $this->get_prop( 'name', $context ); |
|
188 | + public function get_name($context = 'view') { |
|
189 | + return $this->get_prop('name', $context); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -196,8 +196,8 @@ discard block |
||
196 | 196 | * @param string $context View or edit context. |
197 | 197 | * @return string |
198 | 198 | */ |
199 | - public function get_title( $context = 'view' ) { |
|
200 | - return $this->get_name( $context ); |
|
199 | + public function get_title($context = 'view') { |
|
200 | + return $this->get_name($context); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -207,8 +207,8 @@ discard block |
||
207 | 207 | * @param string $context View or edit context. |
208 | 208 | * @return int |
209 | 209 | */ |
210 | - public function get_author( $context = 'view' ) { |
|
211 | - return (int) $this->get_prop( 'author', $context ); |
|
210 | + public function get_author($context = 'view') { |
|
211 | + return (int) $this->get_prop('author', $context); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -218,21 +218,21 @@ discard block |
||
218 | 218 | * @param string $context View or edit context. |
219 | 219 | * @return array |
220 | 220 | */ |
221 | - public function get_elements( $context = 'view' ) { |
|
222 | - $elements = $this->get_prop( 'elements', $context ); |
|
221 | + public function get_elements($context = 'view') { |
|
222 | + $elements = $this->get_prop('elements', $context); |
|
223 | 223 | |
224 | - if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
225 | - return wpinv_get_data( 'sample-payment-form' ); |
|
224 | + if (empty($elements) || !is_array($elements)) { |
|
225 | + return wpinv_get_data('sample-payment-form'); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | // Ensure that all required elements exist. |
229 | 229 | $_elements = array(); |
230 | - foreach ( $elements as $element ) { |
|
230 | + foreach ($elements as $element) { |
|
231 | 231 | |
232 | - if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
232 | + if ($element['type'] == 'pay_button' && !$this->has_element_type('gateway_select')) { |
|
233 | 233 | |
234 | 234 | $_elements[] = array( |
235 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
235 | + 'text' => __('Select Payment Method', 'invoicing'), |
|
236 | 236 | 'id' => 'gtscicd', |
237 | 237 | 'name' => 'gtscicd', |
238 | 238 | 'type' => 'gateway_select', |
@@ -257,22 +257,22 @@ discard block |
||
257 | 257 | * @param string $return objects or arrays. |
258 | 258 | * @return GetPaid_Form_Item[] |
259 | 259 | */ |
260 | - public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | - $items = $this->get_prop( 'items', $context ); |
|
260 | + public function get_items($context = 'view', $return = 'objects') { |
|
261 | + $items = $this->get_prop('items', $context); |
|
262 | 262 | |
263 | - if ( empty( $items ) || ! is_array( $items ) ) { |
|
264 | - $items = wpinv_get_data( 'sample-payment-form-items' ); |
|
263 | + if (empty($items) || !is_array($items)) { |
|
264 | + $items = wpinv_get_data('sample-payment-form-items'); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | // Convert the items. |
268 | 268 | $prepared = array(); |
269 | 269 | |
270 | - foreach ( $items as $key => $value ) { |
|
270 | + foreach ($items as $key => $value) { |
|
271 | 271 | |
272 | 272 | // Form items. |
273 | - if ( $value instanceof GetPaid_Form_Item ) { |
|
273 | + if ($value instanceof GetPaid_Form_Item) { |
|
274 | 274 | |
275 | - if ( $value->can_purchase() ) { |
|
275 | + if ($value->can_purchase()) { |
|
276 | 276 | $prepared[] = $value; |
277 | 277 | } |
278 | 278 | |
@@ -281,16 +281,16 @@ discard block |
||
281 | 281 | } |
282 | 282 | |
283 | 283 | // $item_id => $quantity (buy buttons) |
284 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | - $item = new GetPaid_Form_Item( $key ); |
|
284 | + if (is_numeric($key) && is_numeric($value)) { |
|
285 | + $item = new GetPaid_Form_Item($key); |
|
286 | 286 | |
287 | - if ( $item->can_purchase() ) { |
|
287 | + if ($item->can_purchase()) { |
|
288 | 288 | |
289 | 289 | $value = (float) $value; |
290 | - $item->set_quantity( $value ); |
|
291 | - if ( 0 == $value ) { |
|
292 | - $item->set_quantity( 1 ); |
|
293 | - $item->set_allow_quantities( true ); |
|
290 | + $item->set_quantity($value); |
|
291 | + if (0 == $value) { |
|
292 | + $item->set_quantity(1); |
|
293 | + $item->set_allow_quantities(true); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | $prepared[] = $item; |
@@ -300,33 +300,33 @@ discard block |
||
300 | 300 | } |
301 | 301 | |
302 | 302 | // Items saved via payment forms editor. |
303 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
303 | + if (is_array($value) && isset($value['id'])) { |
|
304 | 304 | |
305 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
305 | + $item = new GetPaid_Form_Item($value['id']); |
|
306 | 306 | |
307 | - if ( ! $item->can_purchase() ) { |
|
307 | + if (!$item->can_purchase()) { |
|
308 | 308 | continue; |
309 | 309 | } |
310 | 310 | |
311 | 311 | // Sub-total (Cart items). |
312 | - if ( isset( $value['subtotal'] ) ) { |
|
313 | - $item->set_price( $value['subtotal'] ); |
|
312 | + if (isset($value['subtotal'])) { |
|
313 | + $item->set_price($value['subtotal']); |
|
314 | 314 | } |
315 | 315 | |
316 | - if ( isset( $value['quantity'] ) ) { |
|
317 | - $item->set_quantity( $value['quantity'] ); |
|
316 | + if (isset($value['quantity'])) { |
|
317 | + $item->set_quantity($value['quantity']); |
|
318 | 318 | } |
319 | 319 | |
320 | - if ( isset( $value['allow_quantities'] ) ) { |
|
321 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
320 | + if (isset($value['allow_quantities'])) { |
|
321 | + $item->set_allow_quantities($value['allow_quantities']); |
|
322 | 322 | } |
323 | 323 | |
324 | - if ( isset( $value['required'] ) ) { |
|
325 | - $item->set_is_required( $value['required'] ); |
|
324 | + if (isset($value['required'])) { |
|
325 | + $item->set_is_required($value['required']); |
|
326 | 326 | } |
327 | 327 | |
328 | - if ( isset( $value['description'] ) ) { |
|
329 | - $item->set_custom_description( $value['description'] ); |
|
328 | + if (isset($value['description'])) { |
|
329 | + $item->set_custom_description($value['description']); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | $prepared[] = $item; |
@@ -335,14 +335,14 @@ discard block |
||
335 | 335 | } |
336 | 336 | |
337 | 337 | // $item_id => array( 'price' => 10 ) (item variations) |
338 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
339 | - $item = new GetPaid_Form_Item( $key ); |
|
338 | + if (is_numeric($key) && is_array($value)) { |
|
339 | + $item = new GetPaid_Form_Item($key); |
|
340 | 340 | |
341 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
342 | - $item->set_price( $value['price'] ); |
|
341 | + if (isset($value['price']) && $item->user_can_set_their_price()) { |
|
342 | + $item->set_price($value['price']); |
|
343 | 343 | } |
344 | 344 | |
345 | - if ( $item->can_purchase() ) { |
|
345 | + if ($item->can_purchase()) { |
|
346 | 346 | $prepared[] = $item; |
347 | 347 | } |
348 | 348 | |
@@ -350,12 +350,12 @@ discard block |
||
350 | 350 | } |
351 | 351 | } |
352 | 352 | |
353 | - if ( 'objects' == $return && 'view' == $context ) { |
|
353 | + if ('objects' == $return && 'view' == $context) { |
|
354 | 354 | return $prepared; |
355 | 355 | } |
356 | 356 | |
357 | 357 | $items = array(); |
358 | - foreach ( $prepared as $item ) { |
|
358 | + foreach ($prepared as $item) { |
|
359 | 359 | $items[] = $item->prepare_data_for_use(); |
360 | 360 | } |
361 | 361 | |
@@ -369,14 +369,14 @@ discard block |
||
369 | 369 | * @param int $item_id The item id to return. |
370 | 370 | * @return GetPaid_Form_Item|bool |
371 | 371 | */ |
372 | - public function get_item( $item_id ) { |
|
372 | + public function get_item($item_id) { |
|
373 | 373 | |
374 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
374 | + if (empty($item_id) || !is_numeric($item_id)) { |
|
375 | 375 | return false; |
376 | 376 | } |
377 | 377 | |
378 | - foreach ( $this->get_items() as $item ) { |
|
379 | - if ( $item->get_id() == (int) $item_id ) { |
|
378 | + foreach ($this->get_items() as $item) { |
|
379 | + if ($item->get_id() == (int) $item_id) { |
|
380 | 380 | return $item; |
381 | 381 | } |
382 | 382 | } |
@@ -392,15 +392,15 @@ discard block |
||
392 | 392 | * @param string $element_type The element type to return. |
393 | 393 | * @return array|bool |
394 | 394 | */ |
395 | - public function get_element_type( $element_type ) { |
|
395 | + public function get_element_type($element_type) { |
|
396 | 396 | |
397 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
397 | + if (empty($element_type) || !is_scalar($element_type)) { |
|
398 | 398 | return false; |
399 | 399 | } |
400 | 400 | |
401 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
401 | + foreach ($this->get_prop('elements') as $element) { |
|
402 | 402 | |
403 | - if ( $element['type'] == $element_type ) { |
|
403 | + if ($element['type'] == $element_type) { |
|
404 | 404 | return $element; |
405 | 405 | } |
406 | 406 | } |
@@ -416,8 +416,8 @@ discard block |
||
416 | 416 | * @param string $context View or edit context. |
417 | 417 | * @return float |
418 | 418 | */ |
419 | - public function get_earned( $context = 'view' ) { |
|
420 | - return $this->get_prop( 'earned', $context ); |
|
419 | + public function get_earned($context = 'view') { |
|
420 | + return $this->get_prop('earned', $context); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | /** |
@@ -427,8 +427,8 @@ discard block |
||
427 | 427 | * @param string $context View or edit context. |
428 | 428 | * @return float |
429 | 429 | */ |
430 | - public function get_refunded( $context = 'view' ) { |
|
431 | - return $this->get_prop( 'refunded', $context ); |
|
430 | + public function get_refunded($context = 'view') { |
|
431 | + return $this->get_prop('refunded', $context); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | /** |
@@ -438,8 +438,8 @@ discard block |
||
438 | 438 | * @param string $context View or edit context. |
439 | 439 | * @return float |
440 | 440 | */ |
441 | - public function get_cancelled( $context = 'view' ) { |
|
442 | - return $this->get_prop( 'cancelled', $context ); |
|
441 | + public function get_cancelled($context = 'view') { |
|
442 | + return $this->get_prop('cancelled', $context); |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | /** |
@@ -449,8 +449,8 @@ discard block |
||
449 | 449 | * @param string $context View or edit context. |
450 | 450 | * @return float |
451 | 451 | */ |
452 | - public function get_failed( $context = 'view' ) { |
|
453 | - return $this->get_prop( 'failed', $context ); |
|
452 | + public function get_failed($context = 'view') { |
|
453 | + return $this->get_prop('failed', $context); |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | /** |
@@ -461,8 +461,8 @@ discard block |
||
461 | 461 | * @return string |
462 | 462 | */ |
463 | 463 | public function get_currency() { |
464 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
465 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
464 | + $currency = empty($this->invoice) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
465 | + return apply_filters('getpaid-payment-form-currency', $currency, $this); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | /* |
@@ -480,8 +480,8 @@ discard block |
||
480 | 480 | * |
481 | 481 | * @since 1.0.19 |
482 | 482 | */ |
483 | - public function set_version( $value ) { |
|
484 | - $this->set_prop( 'version', $value ); |
|
483 | + public function set_version($value) { |
|
484 | + $this->set_prop('version', $value); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
@@ -491,11 +491,11 @@ discard block |
||
491 | 491 | * @param string $value Value to set. |
492 | 492 | * @return bool Whether or not the date was set. |
493 | 493 | */ |
494 | - public function set_date_created( $value ) { |
|
495 | - $date = strtotime( $value ); |
|
494 | + public function set_date_created($value) { |
|
495 | + $date = strtotime($value); |
|
496 | 496 | |
497 | - if ( $date ) { |
|
498 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
497 | + if ($date) { |
|
498 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
499 | 499 | return true; |
500 | 500 | } |
501 | 501 | |
@@ -510,11 +510,11 @@ discard block |
||
510 | 510 | * @param string $value Value to set. |
511 | 511 | * @return bool Whether or not the date was set. |
512 | 512 | */ |
513 | - public function set_date_modified( $value ) { |
|
514 | - $date = strtotime( $value ); |
|
513 | + public function set_date_modified($value) { |
|
514 | + $date = strtotime($value); |
|
515 | 515 | |
516 | - if ( $date ) { |
|
517 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
516 | + if ($date) { |
|
517 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
518 | 518 | return true; |
519 | 519 | } |
520 | 520 | |
@@ -528,8 +528,8 @@ discard block |
||
528 | 528 | * @since 1.0.19 |
529 | 529 | * @param string $value New name. |
530 | 530 | */ |
531 | - public function set_name( $value ) { |
|
532 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
531 | + public function set_name($value) { |
|
532 | + $this->set_prop('name', sanitize_text_field($value)); |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | /** |
@@ -538,8 +538,8 @@ discard block |
||
538 | 538 | * @since 1.0.19 |
539 | 539 | * @param string $value New name. |
540 | 540 | */ |
541 | - public function set_title( $value ) { |
|
542 | - $this->set_name( $value ); |
|
541 | + public function set_title($value) { |
|
542 | + $this->set_name($value); |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | /** |
@@ -548,8 +548,8 @@ discard block |
||
548 | 548 | * @since 1.0.19 |
549 | 549 | * @param int $value New author. |
550 | 550 | */ |
551 | - public function set_author( $value ) { |
|
552 | - $this->set_prop( 'author', (int) $value ); |
|
551 | + public function set_author($value) { |
|
552 | + $this->set_prop('author', (int) $value); |
|
553 | 553 | } |
554 | 554 | |
555 | 555 | /** |
@@ -559,9 +559,9 @@ discard block |
||
559 | 559 | * @sinve 2.3.4 Array values sanitized. |
560 | 560 | * @param array $value Form elements. |
561 | 561 | */ |
562 | - public function set_elements( $value ) { |
|
563 | - if ( is_array( $value ) ) { |
|
564 | - $this->set_prop( 'elements', wp_kses_post_deep( $value ) ); |
|
562 | + public function set_elements($value) { |
|
563 | + if (is_array($value)) { |
|
564 | + $this->set_prop('elements', wp_kses_post_deep($value)); |
|
565 | 565 | } |
566 | 566 | } |
567 | 567 | |
@@ -572,36 +572,36 @@ discard block |
||
572 | 572 | * |
573 | 573 | * @return mixed |
574 | 574 | */ |
575 | - public function sanitize_array_values( $value ) { |
|
575 | + public function sanitize_array_values($value) { |
|
576 | 576 | |
577 | 577 | // sanitize |
578 | - if ( ! empty( $value ) ) { |
|
578 | + if (!empty($value)) { |
|
579 | 579 | |
580 | - foreach ( $value as $key => $val_arr ) { |
|
580 | + foreach ($value as $key => $val_arr) { |
|
581 | 581 | |
582 | - if ( is_array( $val_arr ) ) { |
|
582 | + if (is_array($val_arr)) { |
|
583 | 583 | // check if we have sub array items. |
584 | 584 | $sub_arr = array(); |
585 | - foreach ( $val_arr as $key2 => $val2 ) { |
|
586 | - if ( is_array( $val2 ) ) { |
|
587 | - $sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 ); |
|
588 | - unset( $val_arr[ $key ][ $key2 ] ); |
|
585 | + foreach ($val_arr as $key2 => $val2) { |
|
586 | + if (is_array($val2)) { |
|
587 | + $sub_arr[$key2] = $this->sanitize_array_values($val2); |
|
588 | + unset($val_arr[$key][$key2]); |
|
589 | 589 | } |
590 | 590 | } |
591 | 591 | |
592 | 592 | // we allow some html in description so we sanitize it separately. |
593 | - $help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : ''; |
|
593 | + $help_text = !empty($val_arr['description']) ? wp_kses_post($val_arr['description']) : ''; |
|
594 | 594 | |
595 | 595 | // sanitize array elements |
596 | - $value[ $key ] = array_map( 'sanitize_text_field', $val_arr ); |
|
596 | + $value[$key] = array_map('sanitize_text_field', $val_arr); |
|
597 | 597 | |
598 | 598 | // add back the description if set |
599 | - if ( isset( $val_arr['description'] ) ) { |
|
600 | -$value[ $key ]['description'] = $help_text;} |
|
599 | + if (isset($val_arr['description'])) { |
|
600 | +$value[$key]['description'] = $help_text; } |
|
601 | 601 | |
602 | 602 | // add back sub array items after its been sanitized. |
603 | - if ( ! empty( $sub_arr ) ) { |
|
604 | - $value[ $key ] = array_merge( $value[ $key ], $sub_arr ); |
|
603 | + if (!empty($sub_arr)) { |
|
604 | + $value[$key] = array_merge($value[$key], $sub_arr); |
|
605 | 605 | } |
606 | 606 | } |
607 | 607 | } |
@@ -616,9 +616,9 @@ discard block |
||
616 | 616 | * @since 1.0.19 |
617 | 617 | * @param array $value Form elements. |
618 | 618 | */ |
619 | - public function set_items( $value ) { |
|
620 | - if ( is_array( $value ) ) { |
|
621 | - $this->set_prop( 'items', $value ); |
|
619 | + public function set_items($value) { |
|
620 | + if (is_array($value)) { |
|
621 | + $this->set_prop('items', $value); |
|
622 | 622 | } |
623 | 623 | } |
624 | 624 | |
@@ -628,9 +628,9 @@ discard block |
||
628 | 628 | * @since 1.0.19 |
629 | 629 | * @param float $value Amount earned. |
630 | 630 | */ |
631 | - public function set_earned( $value ) { |
|
632 | - $value = max( (float) $value, 0 ); |
|
633 | - $this->set_prop( 'earned', $value ); |
|
631 | + public function set_earned($value) { |
|
632 | + $value = max((float) $value, 0); |
|
633 | + $this->set_prop('earned', $value); |
|
634 | 634 | } |
635 | 635 | |
636 | 636 | /** |
@@ -639,9 +639,9 @@ discard block |
||
639 | 639 | * @since 1.0.19 |
640 | 640 | * @param float $value Amount refunded. |
641 | 641 | */ |
642 | - public function set_refunded( $value ) { |
|
643 | - $value = max( (float) $value, 0 ); |
|
644 | - $this->set_prop( 'refunded', $value ); |
|
642 | + public function set_refunded($value) { |
|
643 | + $value = max((float) $value, 0); |
|
644 | + $this->set_prop('refunded', $value); |
|
645 | 645 | } |
646 | 646 | |
647 | 647 | /** |
@@ -650,9 +650,9 @@ discard block |
||
650 | 650 | * @since 1.0.19 |
651 | 651 | * @param float $value Amount cancelled. |
652 | 652 | */ |
653 | - public function set_cancelled( $value ) { |
|
654 | - $value = max( (float) $value, 0 ); |
|
655 | - $this->set_prop( 'cancelled', $value ); |
|
653 | + public function set_cancelled($value) { |
|
654 | + $value = max((float) $value, 0); |
|
655 | + $this->set_prop('cancelled', $value); |
|
656 | 656 | } |
657 | 657 | |
658 | 658 | /** |
@@ -661,9 +661,9 @@ discard block |
||
661 | 661 | * @since 1.0.19 |
662 | 662 | * @param float $value Amount cancelled. |
663 | 663 | */ |
664 | - public function set_failed( $value ) { |
|
665 | - $value = max( (float) $value, 0 ); |
|
666 | - $this->set_prop( 'failed', $value ); |
|
664 | + public function set_failed($value) { |
|
665 | + $value = max((float) $value, 0); |
|
666 | + $this->set_prop('failed', $value); |
|
667 | 667 | } |
668 | 668 | |
669 | 669 | /** |
@@ -672,11 +672,11 @@ discard block |
||
672 | 672 | * @deprecated |
673 | 673 | * @return int item id |
674 | 674 | */ |
675 | - public function create( $data = array() ) { |
|
675 | + public function create($data = array()) { |
|
676 | 676 | |
677 | 677 | // Set the properties. |
678 | - if ( is_array( $data ) ) { |
|
679 | - $this->set_props( $data ); |
|
678 | + if (is_array($data)) { |
|
679 | + $this->set_props($data); |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | // Save the item. |
@@ -690,8 +690,8 @@ discard block |
||
690 | 690 | * @deprecated |
691 | 691 | * @return int item id |
692 | 692 | */ |
693 | - public function update( $data = array() ) { |
|
694 | - return $this->create( $data ); |
|
693 | + public function update($data = array()) { |
|
694 | + return $this->create($data); |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | /* |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | */ |
712 | 712 | public function is_default() { |
713 | 713 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
714 | - return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
|
714 | + return (bool) apply_filters('wpinv_is_default_payment_form', $is_default, $this->get_id(), $this); |
|
715 | 715 | } |
716 | 716 | |
717 | 717 | /** |
@@ -723,11 +723,11 @@ discard block |
||
723 | 723 | public function is_active() { |
724 | 724 | $is_active = 0 !== (int) $this->get_id(); |
725 | 725 | |
726 | - if ( $is_active && ! current_user_can( 'edit_post', $this->get_id() ) && $this->get_status() != 'publish' ) { |
|
726 | + if ($is_active && !current_user_can('edit_post', $this->get_id()) && $this->get_status() != 'publish') { |
|
727 | 727 | $is_active = false; |
728 | 728 | } |
729 | 729 | |
730 | - return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
|
730 | + return (bool) apply_filters('wpinv_is_payment_form_active', $is_active, $this); |
|
731 | 731 | } |
732 | 732 | |
733 | 733 | /** |
@@ -736,8 +736,8 @@ discard block |
||
736 | 736 | * @since 1.0.19 |
737 | 737 | * @return bool |
738 | 738 | */ |
739 | - public function has_item( $item_id ) { |
|
740 | - return false !== $this->get_item( $item_id ); |
|
739 | + public function has_item($item_id) { |
|
740 | + return false !== $this->get_item($item_id); |
|
741 | 741 | } |
742 | 742 | |
743 | 743 | /** |
@@ -746,8 +746,8 @@ discard block |
||
746 | 746 | * @since 1.0.19 |
747 | 747 | * @return bool |
748 | 748 | */ |
749 | - public function has_element_type( $element_type ) { |
|
750 | - return false !== $this->get_element_type( $element_type ); |
|
749 | + public function has_element_type($element_type) { |
|
750 | + return false !== $this->get_element_type($element_type); |
|
751 | 751 | } |
752 | 752 | |
753 | 753 | /** |
@@ -758,13 +758,13 @@ discard block |
||
758 | 758 | */ |
759 | 759 | public function is_recurring() { |
760 | 760 | |
761 | - if ( ! empty( $this->invoice ) ) { |
|
761 | + if (!empty($this->invoice)) { |
|
762 | 762 | return $this->invoice->is_recurring(); |
763 | 763 | } |
764 | 764 | |
765 | - foreach ( $this->get_items() as $item ) { |
|
765 | + foreach ($this->get_items() as $item) { |
|
766 | 766 | |
767 | - if ( $item->is_recurring() ) { |
|
767 | + if ($item->is_recurring()) { |
|
768 | 768 | return true; |
769 | 769 | } |
770 | 770 | } |
@@ -777,7 +777,7 @@ discard block |
||
777 | 777 | * |
778 | 778 | * @since 1.0.19 |
779 | 779 | */ |
780 | - public function get_html( $extra_markup = '' ) { |
|
780 | + public function get_html($extra_markup = '') { |
|
781 | 781 | |
782 | 782 | // Return the HTML. |
783 | 783 | return wpinv_get_template_html( |
@@ -795,8 +795,8 @@ discard block |
||
795 | 795 | * |
796 | 796 | * @since 1.0.19 |
797 | 797 | */ |
798 | - public function display( $extra_markup = '' ) { |
|
799 | - echo $this->get_html( $extra_markup ); |
|
798 | + public function display($extra_markup = '') { |
|
799 | + echo $this->get_html($extra_markup); |
|
800 | 800 | } |
801 | 801 | |
802 | 802 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | * @param string $context View or edit context. |
95 | 95 | * @return string |
96 | 96 | */ |
97 | - public function get_name( $context = 'view' ) { |
|
98 | - $name = parent::get_name( $context ); |
|
99 | - return $name . wpinv_get_item_suffix( $this ); |
|
97 | + public function get_name($context = 'view') { |
|
98 | + $name = parent::get_name($context); |
|
99 | + return $name . wpinv_get_item_suffix($this); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -106,8 +106,8 @@ discard block |
||
106 | 106 | * @param string $context View or edit context. |
107 | 107 | * @return string |
108 | 108 | */ |
109 | - public function get_raw_name( $context = 'view' ) { |
|
110 | - return parent::get_name( $context ); |
|
109 | + public function get_raw_name($context = 'view') { |
|
110 | + return parent::get_name($context); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -117,13 +117,13 @@ discard block |
||
117 | 117 | * @param string $context View or edit context. |
118 | 118 | * @return string |
119 | 119 | */ |
120 | - public function get_description( $context = 'view' ) { |
|
120 | + public function get_description($context = 'view') { |
|
121 | 121 | |
122 | - if ( isset( $this->custom_description ) ) { |
|
122 | + if (isset($this->custom_description)) { |
|
123 | 123 | return $this->custom_description; |
124 | 124 | } |
125 | 125 | |
126 | - return parent::get_description( $context ); |
|
126 | + return parent::get_description($context); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -133,8 +133,8 @@ discard block |
||
133 | 133 | * @param string $context View or edit context. |
134 | 134 | * @return float |
135 | 135 | */ |
136 | - public function get_sub_total( $context = 'view' ) { |
|
137 | - return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
136 | + public function get_sub_total($context = 'view') { |
|
137 | + return $this->get_quantity($context) * $this->get_initial_price($context); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -144,10 +144,10 @@ discard block |
||
144 | 144 | * @param string $context View or edit context. |
145 | 145 | * @return float |
146 | 146 | */ |
147 | - public function get_recurring_sub_total( $context = 'view' ) { |
|
147 | + public function get_recurring_sub_total($context = 'view') { |
|
148 | 148 | |
149 | - if ( $this->is_recurring() ) { |
|
150 | - return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
149 | + if ($this->is_recurring()) { |
|
150 | + return $this->get_quantity($context) * $this->get_price($context); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | return 0; |
@@ -156,8 +156,8 @@ discard block |
||
156 | 156 | /** |
157 | 157 | * @deprecated |
158 | 158 | */ |
159 | - public function get_qantity( $context = 'view' ) { |
|
160 | - return $this->get_quantity( $context ); |
|
159 | + public function get_qantity($context = 'view') { |
|
160 | + return $this->get_quantity($context); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -167,11 +167,11 @@ discard block |
||
167 | 167 | * @param string $context View or edit context. |
168 | 168 | * @return float |
169 | 169 | */ |
170 | - public function get_quantity( $context = 'view' ) { |
|
170 | + public function get_quantity($context = 'view') { |
|
171 | 171 | $quantity = (float) $this->quantity; |
172 | 172 | |
173 | - if ( 'view' == $context ) { |
|
174 | - return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
173 | + if ('view' == $context) { |
|
174 | + return apply_filters('getpaid_payment_form_item_quantity', $quantity, $this); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | return $quantity; |
@@ -185,11 +185,11 @@ discard block |
||
185 | 185 | * @param string $context View or edit context. |
186 | 186 | * @return meta |
187 | 187 | */ |
188 | - public function get_item_meta( $context = 'view' ) { |
|
188 | + public function get_item_meta($context = 'view') { |
|
189 | 189 | $meta = $this->meta; |
190 | 190 | |
191 | - if ( 'view' == $context ) { |
|
192 | - return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
191 | + if ('view' == $context) { |
|
192 | + return apply_filters('getpaid_payment_form_item_meta', $meta, $this); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | return $meta; |
@@ -203,11 +203,11 @@ discard block |
||
203 | 203 | * @param string $context View or edit context. |
204 | 204 | * @return bool |
205 | 205 | */ |
206 | - public function get_allow_quantities( $context = 'view' ) { |
|
206 | + public function get_allow_quantities($context = 'view') { |
|
207 | 207 | $allow_quantities = (bool) $this->allow_quantities; |
208 | 208 | |
209 | - if ( 'view' == $context ) { |
|
210 | - return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
209 | + if ('view' == $context) { |
|
210 | + return apply_filters('getpaid_payment_form_item_allow_quantities', $allow_quantities, $this); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | return $allow_quantities; |
@@ -221,11 +221,11 @@ discard block |
||
221 | 221 | * @param string $context View or edit context. |
222 | 222 | * @return bool |
223 | 223 | */ |
224 | - public function get_is_required( $context = 'view' ) { |
|
224 | + public function get_is_required($context = 'view') { |
|
225 | 225 | $is_required = (bool) $this->is_required; |
226 | 226 | |
227 | - if ( 'view' == $context ) { |
|
228 | - return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
227 | + if ('view' == $context) { |
|
228 | + return apply_filters('getpaid_payment_form_item_is_required', $is_required, $this); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | return $is_required; |
@@ -238,11 +238,11 @@ discard block |
||
238 | 238 | * @since 1.0.19 |
239 | 239 | * @return array |
240 | 240 | */ |
241 | - public function prepare_data_for_use( $required = null ) { |
|
241 | + public function prepare_data_for_use($required = null) { |
|
242 | 242 | |
243 | - $required = is_null( $required ) ? $this->is_required() : $required; |
|
243 | + $required = is_null($required) ? $this->is_required() : $required; |
|
244 | 244 | return array( |
245 | - 'title' => strip_tags( $this->get_name() ), |
|
245 | + 'title' => strip_tags($this->get_name()), |
|
246 | 246 | 'id' => $this->get_id(), |
247 | 247 | 'price' => $this->get_price(), |
248 | 248 | 'recurring' => $this->is_recurring(), |
@@ -259,30 +259,30 @@ discard block |
||
259 | 259 | * @since 1.0.19 |
260 | 260 | * @return array |
261 | 261 | */ |
262 | - public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) { |
|
262 | + public function prepare_data_for_invoice_edit_ajax($currency = '', $is_renewal = false) { |
|
263 | 263 | |
264 | - $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
264 | + $description = getpaid_item_recurring_price_help_text($this, $currency); |
|
265 | 265 | |
266 | - if ( $description ) { |
|
266 | + if ($description) { |
|
267 | 267 | $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
268 | 268 | } |
269 | 269 | |
270 | - $price = ! $is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
271 | - $subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
270 | + $price = !$is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
271 | + $subtotal = !$is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
272 | 272 | return array( |
273 | 273 | 'id' => $this->get_id(), |
274 | 274 | 'texts' => array( |
275 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
276 | - 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
277 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
278 | - 'item-price' => wpinv_price( $price, $currency ), |
|
279 | - 'item-total' => wpinv_price( $subtotal, $currency ), |
|
275 | + 'item-name' => sanitize_text_field($this->get_name()), |
|
276 | + 'item-description' => wp_kses_post($this->get_description()) . $description, |
|
277 | + 'item-quantity' => floatval($this->get_quantity()), |
|
278 | + 'item-price' => wpinv_price($price, $currency), |
|
279 | + 'item-total' => wpinv_price($subtotal, $currency), |
|
280 | 280 | ), |
281 | 281 | 'inputs' => array( |
282 | 282 | 'item-id' => $this->get_id(), |
283 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
284 | - 'item-description' => wp_kses_post( $this->get_description() ), |
|
285 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
283 | + 'item-name' => sanitize_text_field($this->get_name()), |
|
284 | + 'item-description' => wp_kses_post($this->get_description()), |
|
285 | + 'item-quantity' => floatval($this->get_quantity()), |
|
286 | 286 | 'item-price' => $price, |
287 | 287 | ), |
288 | 288 | ); |
@@ -300,15 +300,15 @@ discard block |
||
300 | 300 | return array( |
301 | 301 | 'post_id' => $this->invoice_id, |
302 | 302 | 'item_id' => $this->get_id(), |
303 | - 'item_name' => sanitize_text_field( $this->get_raw_name( 'edit' ) ), |
|
304 | - 'item_description' => $this->get_description( 'edit' ), |
|
303 | + 'item_name' => sanitize_text_field($this->get_raw_name('edit')), |
|
304 | + 'item_description' => $this->get_description('edit'), |
|
305 | 305 | 'tax' => $this->item_tax, |
306 | - 'item_price' => $this->get_price( 'edit' ), |
|
307 | - 'quantity' => (float) $this->get_quantity( 'edit' ), |
|
306 | + 'item_price' => $this->get_price('edit'), |
|
307 | + 'quantity' => (float) $this->get_quantity('edit'), |
|
308 | 308 | 'discount' => $this->item_discount, |
309 | - 'subtotal' => $this->get_sub_total( 'edit' ), |
|
310 | - 'price' => $this->get_sub_total( 'edit' ) + $this->item_tax - $this->item_discount, |
|
311 | - 'meta' => $this->get_item_meta( 'edit' ), |
|
309 | + 'subtotal' => $this->get_sub_total('edit'), |
|
310 | + 'price' => $this->get_sub_total('edit') + $this->item_tax - $this->item_discount, |
|
311 | + 'meta' => $this->get_item_meta('edit'), |
|
312 | 312 | ); |
313 | 313 | |
314 | 314 | } |
@@ -329,9 +329,9 @@ discard block |
||
329 | 329 | * @since 1.0.19 |
330 | 330 | * @param float $quantity The item quantity. |
331 | 331 | */ |
332 | - public function set_quantity( $quantity ) { |
|
332 | + public function set_quantity($quantity) { |
|
333 | 333 | |
334 | - if ( ! is_numeric( $quantity ) ) { |
|
334 | + if (!is_numeric($quantity)) { |
|
335 | 335 | $quantity = 1; |
336 | 336 | } |
337 | 337 | |
@@ -345,8 +345,8 @@ discard block |
||
345 | 345 | * @since 1.0.19 |
346 | 346 | * @param array $meta The item meta data. |
347 | 347 | */ |
348 | - public function set_item_meta( $meta ) { |
|
349 | - $this->meta = maybe_unserialize( $meta ); |
|
348 | + public function set_item_meta($meta) { |
|
349 | + $this->meta = maybe_unserialize($meta); |
|
350 | 350 | } |
351 | 351 | |
352 | 352 | /** |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | * @since 1.0.19 |
356 | 356 | * @param bool $allow_quantities |
357 | 357 | */ |
358 | - public function set_allow_quantities( $allow_quantities ) { |
|
358 | + public function set_allow_quantities($allow_quantities) { |
|
359 | 359 | $this->allow_quantities = (bool) $allow_quantities; |
360 | 360 | } |
361 | 361 | |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | * @since 1.0.19 |
366 | 366 | * @param bool $is_required |
367 | 367 | */ |
368 | - public function set_is_required( $is_required ) { |
|
368 | + public function set_is_required($is_required) { |
|
369 | 369 | $this->is_required = (bool) $is_required; |
370 | 370 | } |
371 | 371 | |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | * @since 1.0.19 |
376 | 376 | * @param string $description |
377 | 377 | */ |
378 | - public function set_custom_description( $description ) { |
|
378 | + public function set_custom_description($description) { |
|
379 | 379 | $this->custom_description = $description; |
380 | 380 | } |
381 | 381 | |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | * |
385 | 385 | * @return int item id |
386 | 386 | */ |
387 | - public function save( $data = array() ) { |
|
387 | + public function save($data = array()) { |
|
388 | 388 | return $this->get_id(); |
389 | 389 | } |
390 | 390 |
@@ -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 | * Payment form submission discount class |
@@ -25,28 +25,28 @@ discard block |
||
25 | 25 | * @param float $initial_total |
26 | 26 | * @param float $recurring_total |
27 | 27 | */ |
28 | - public function __construct( $submission, $initial_total, $recurring_total ) { |
|
28 | + public function __construct($submission, $initial_total, $recurring_total) { |
|
29 | 29 | |
30 | 30 | // Process any existing invoice discounts. |
31 | - if ( $submission->has_invoice() ) { |
|
31 | + if ($submission->has_invoice()) { |
|
32 | 32 | $this->discounts = $submission->get_invoice()->get_discounts(); |
33 | 33 | } |
34 | 34 | |
35 | 35 | // Do we have a discount? |
36 | - $discount = $submission->get_field( 'discount' ); |
|
36 | + $discount = $submission->get_field('discount'); |
|
37 | 37 | |
38 | - if ( empty( $discount ) ) { |
|
38 | + if (empty($discount)) { |
|
39 | 39 | |
40 | - if ( isset( $this->discounts['discount_code'] ) ) { |
|
41 | - unset( $this->discounts['discount_code'] ); |
|
40 | + if (isset($this->discounts['discount_code'])) { |
|
41 | + unset($this->discounts['discount_code']); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | return; |
45 | 45 | } |
46 | 46 | |
47 | 47 | // Processes the discount code. |
48 | - $amount = max( $initial_total, $recurring_total ); |
|
49 | - $this->process_discount( $submission, $discount, $amount ); |
|
48 | + $amount = max($initial_total, $recurring_total); |
|
49 | + $this->process_discount($submission, $discount, $amount); |
|
50 | 50 | |
51 | 51 | } |
52 | 52 | |
@@ -57,34 +57,34 @@ discard block |
||
57 | 57 | * @param string $discount |
58 | 58 | * @param float $amount |
59 | 59 | */ |
60 | - public function process_discount( $submission, $discount, $amount ) { |
|
60 | + public function process_discount($submission, $discount, $amount) { |
|
61 | 61 | |
62 | 62 | // Fetch the discount. |
63 | - $discount = new WPInv_Discount( $discount ); |
|
63 | + $discount = new WPInv_Discount($discount); |
|
64 | 64 | |
65 | 65 | // Ensure it is active. |
66 | - if ( ! $this->is_discount_active( $discount ) ) { |
|
67 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'Invalid or expired discount code', 'invoicing' ) ); |
|
66 | + if (!$this->is_discount_active($discount)) { |
|
67 | + throw new GetPaid_Payment_Exception('.getpaid-discount-field .getpaid-custom-payment-form-errors', __('Invalid or expired discount code', 'invoicing')); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | // Required items. |
71 | - if ( ! $discount->is_required_items_met( array_keys( $submission->get_items() ) ) ) { |
|
72 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You are not allowed to use this discount code.', 'invoicing' ) ); |
|
71 | + if (!$discount->is_required_items_met(array_keys($submission->get_items()))) { |
|
72 | + throw new GetPaid_Payment_Exception('.getpaid-discount-field .getpaid-custom-payment-form-errors', __('You are not allowed to use this discount code.', 'invoicing')); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | // Exceeded limit. |
76 | - if ( $discount->has_exceeded_limit() ) { |
|
77 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'This discount code has been used up', 'invoicing' ) ); |
|
76 | + if ($discount->has_exceeded_limit()) { |
|
77 | + throw new GetPaid_Payment_Exception('.getpaid-discount-field .getpaid-custom-payment-form-errors', __('This discount code has been used up', 'invoicing')); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | // Validate usages. |
81 | - $this->validate_single_use_discount( $submission, $discount ); |
|
81 | + $this->validate_single_use_discount($submission, $discount); |
|
82 | 82 | |
83 | 83 | // Validate amount. |
84 | - $this->validate_discount_amount( $submission, $discount, $amount ); |
|
84 | + $this->validate_discount_amount($submission, $discount, $amount); |
|
85 | 85 | |
86 | 86 | // Save the discount. |
87 | - $this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount ); |
|
87 | + $this->discounts['discount_code'] = $this->calculate_discount($submission, $discount); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | * @param WPInv_Discount $discount |
94 | 94 | * @return bool |
95 | 95 | */ |
96 | - public function is_discount_active( $discount ) { |
|
97 | - return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired(); |
|
96 | + public function is_discount_active($discount) { |
|
97 | + return $discount->exists() && $discount->is_active() && $discount->has_started() && !$discount->is_expired(); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -103,13 +103,13 @@ discard block |
||
103 | 103 | * @param string $email |
104 | 104 | * @return int|string|false |
105 | 105 | */ |
106 | - public function get_user_id_or_email( $email ) { |
|
106 | + public function get_user_id_or_email($email) { |
|
107 | 107 | |
108 | - if ( is_user_logged_in() ) { |
|
108 | + if (is_user_logged_in()) { |
|
109 | 109 | return get_current_user_id(); |
110 | 110 | } |
111 | 111 | |
112 | - return empty( $email ) ? false : sanitize_email( $email ); |
|
112 | + return empty($email) ? false : sanitize_email($email); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -118,23 +118,23 @@ discard block |
||
118 | 118 | * @param GetPaid_Payment_Form_Submission $submission |
119 | 119 | * @param WPInv_Discount $discount |
120 | 120 | */ |
121 | - public function validate_single_use_discount( $submission, $discount ) { |
|
121 | + public function validate_single_use_discount($submission, $discount) { |
|
122 | 122 | |
123 | 123 | // Abort if it is not a single use discount. |
124 | - if ( ! $discount->is_single_use() ) { |
|
124 | + if (!$discount->is_single_use()) { |
|
125 | 125 | return; |
126 | 126 | } |
127 | 127 | |
128 | 128 | // Ensure there is a valid billing email. |
129 | - $user = $this->get_user_id_or_email( $submission->get_billing_email() ); |
|
129 | + $user = $this->get_user_id_or_email($submission->get_billing_email()); |
|
130 | 130 | |
131 | - if ( empty( $user ) ) { |
|
132 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) ); |
|
131 | + if (empty($user)) { |
|
132 | + throw new GetPaid_Payment_Exception('.getpaid-discount-field .getpaid-custom-payment-form-errors', __('You need to either log in or enter your billing email before applying this discount', 'invoicing')); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | // Has the user used this discount code before? |
136 | - if ( ! $discount->is_valid_for_user( $user ) ) { |
|
137 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You have already used this discount', 'invoicing' ) ); |
|
136 | + if (!$discount->is_valid_for_user($user)) { |
|
137 | + throw new GetPaid_Payment_Exception('.getpaid-discount-field .getpaid-custom-payment-form-errors', __('You have already used this discount', 'invoicing')); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | } |
@@ -146,18 +146,18 @@ discard block |
||
146 | 146 | * @param WPInv_Discount $discount |
147 | 147 | * @param float $amount |
148 | 148 | */ |
149 | - public function validate_discount_amount( $submission, $discount, $amount ) { |
|
149 | + public function validate_discount_amount($submission, $discount, $amount) { |
|
150 | 150 | |
151 | 151 | // Validate minimum amount. |
152 | - if ( ! $discount->is_minimum_amount_met( $amount ) ) { |
|
153 | - $min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() ); |
|
154 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) ); |
|
152 | + if (!$discount->is_minimum_amount_met($amount)) { |
|
153 | + $min = wpinv_price($discount->get_minimum_total(), $submission->get_currency()); |
|
154 | + throw new GetPaid_Payment_Exception('.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf(__('The minimum total for using this discount is %s', 'invoicing'), $min)); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | // Validate the maximum amount. |
158 | - if ( ! $discount->is_maximum_amount_met( $amount ) ) { |
|
159 | - $max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() ); |
|
160 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) ); |
|
158 | + if (!$discount->is_maximum_amount_met($amount)) { |
|
159 | + $max = wpinv_price($discount->get_maximum_total(), $submission->get_currency()); |
|
160 | + throw new GetPaid_Payment_Exception('.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf(__('The maximum total for using this discount is %s', 'invoicing'), $max)); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | } |
@@ -171,8 +171,8 @@ discard block |
||
171 | 171 | * @param WPInv_Discount $discount |
172 | 172 | * @return array |
173 | 173 | */ |
174 | - public function calculate_discount( $submission, $discount ) { |
|
175 | - return getpaid_calculate_invoice_discount( $submission, $discount ); |
|
174 | + public function calculate_discount($submission, $discount) { |
|
175 | + return getpaid_calculate_invoice_discount($submission, $discount); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | } |
@@ -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 | * Payment form submission fees class |
@@ -29,10 +29,10 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @param GetPaid_Payment_Form_Submission $submission |
31 | 31 | */ |
32 | - public function __construct( $submission ) { |
|
32 | + public function __construct($submission) { |
|
33 | 33 | |
34 | 34 | // Process any existing invoice fees. |
35 | - if ( $submission->has_invoice() ) { |
|
35 | + if ($submission->has_invoice()) { |
|
36 | 36 | $this->fees = $submission->get_invoice()->get_fees(); |
37 | 37 | } |
38 | 38 | |
@@ -40,14 +40,14 @@ discard block |
||
40 | 40 | $data = $submission->get_data(); |
41 | 41 | $payment_form = $submission->get_payment_form(); |
42 | 42 | |
43 | - foreach ( $payment_form->get_elements() as $element ) { |
|
43 | + foreach ($payment_form->get_elements() as $element) { |
|
44 | 44 | |
45 | - if ( 'price_input' == $element['type'] ) { |
|
46 | - $this->process_price_input( $element, $data, $submission ); |
|
45 | + if ('price_input' == $element['type']) { |
|
46 | + $this->process_price_input($element, $data, $submission); |
|
47 | 47 | } |
48 | 48 | |
49 | - if ( 'price_select' == $element['type'] ) { |
|
50 | - $this->process_price_select( $element, $data ); |
|
49 | + if ('price_select' == $element['type']) { |
|
50 | + $this->process_price_select($element, $data); |
|
51 | 51 | } |
52 | 52 | } |
53 | 53 | |
@@ -60,21 +60,21 @@ discard block |
||
60 | 60 | * @param array $data |
61 | 61 | * @param GetPaid_Payment_Form_Submission $submission |
62 | 62 | */ |
63 | - public function process_price_input( $element, $data, $submission ) { |
|
63 | + public function process_price_input($element, $data, $submission) { |
|
64 | 64 | |
65 | 65 | // Abort if not passed. |
66 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
66 | + if (empty($data[$element['id']])) { |
|
67 | 67 | return; |
68 | 68 | } |
69 | 69 | |
70 | - $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
71 | - $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
70 | + $amount = (float) wpinv_sanitize_amount($data[$element['id']]); |
|
71 | + $minimum = empty($element['minimum']) ? 0 : (float) wpinv_sanitize_amount($element['minimum']); |
|
72 | 72 | |
73 | - if ( $amount < $minimum ) { |
|
74 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $minimum, $submission->get_currency() ) ) ); |
|
73 | + if ($amount < $minimum) { |
|
74 | + throw new Exception(sprintf(__('The minimum allowed amount is %s', 'invoicing'), getpaid_unstandardize_amount($minimum, $submission->get_currency()))); |
|
75 | 75 | } |
76 | 76 | |
77 | - $this->fees[ $element['label'] ] = array( |
|
77 | + $this->fees[$element['label']] = array( |
|
78 | 78 | 'name' => $element['label'], |
79 | 79 | 'initial_fee' => $amount, |
80 | 80 | 'recurring_fee' => 0, |
@@ -88,35 +88,35 @@ discard block |
||
88 | 88 | * @param array $element |
89 | 89 | * @param array $data |
90 | 90 | */ |
91 | - public function process_price_select( $element, $data ) { |
|
91 | + public function process_price_select($element, $data) { |
|
92 | 92 | |
93 | 93 | // Abort if not passed. |
94 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
94 | + if (empty($data[$element['id']])) { |
|
95 | 95 | return; |
96 | 96 | } |
97 | 97 | |
98 | - $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
99 | - $selected = array_filter( array_map( 'trim', explode( ',', $data[ $element['id'] ] ) ) ); |
|
98 | + $options = getpaid_convert_price_string_to_options($element['options']); |
|
99 | + $selected = array_filter(array_map('trim', explode(',', $data[$element['id']]))); |
|
100 | 100 | $total = 0; |
101 | 101 | $sub_labels = array(); |
102 | 102 | |
103 | - foreach ( $selected as $price ) { |
|
103 | + foreach ($selected as $price) { |
|
104 | 104 | |
105 | - if ( ! isset( $options[ $price ] ) ) { |
|
106 | - throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
105 | + if (!isset($options[$price])) { |
|
106 | + throw new Exception(__('You have selected an invalid amount', 'invoicing')); |
|
107 | 107 | } |
108 | 108 | |
109 | - $price = explode( '|', $price ); |
|
109 | + $price = explode('|', $price); |
|
110 | 110 | |
111 | 111 | $sub_labels[] = $price[0]; |
112 | - $total += (float) wpinv_sanitize_amount( $price[1] ); |
|
112 | + $total += (float) wpinv_sanitize_amount($price[1]); |
|
113 | 113 | } |
114 | 114 | |
115 | - $this->fees[ $element['label'] ] = array( |
|
115 | + $this->fees[$element['label']] = array( |
|
116 | 116 | 'name' => $element['label'], |
117 | 117 | 'initial_fee' => $total, |
118 | 118 | 'recurring_fee' => 0, |
119 | - 'description' => implode( ', ', $sub_labels ), |
|
119 | + 'description' => implode(', ', $sub_labels), |
|
120 | 120 | ); |
121 | 121 | |
122 | 122 | } |
@@ -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 | * Payment form submission refresh prices class |
@@ -23,24 +23,24 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @param GetPaid_Payment_Form_Submission $submission |
25 | 25 | */ |
26 | - public function __construct( $submission ) { |
|
26 | + public function __construct($submission) { |
|
27 | 27 | |
28 | 28 | $this->response = array( |
29 | 29 | 'submission_id' => $submission->id, |
30 | 30 | 'has_recurring' => $submission->has_recurring, |
31 | 31 | 'has_subscription_group' => $submission->has_subscription_group(), |
32 | 32 | 'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(), |
33 | - 'is_free' => ! $submission->should_collect_payment_details(), |
|
33 | + 'is_free' => !$submission->should_collect_payment_details(), |
|
34 | 34 | ); |
35 | 35 | |
36 | - $this->add_totals( $submission ); |
|
37 | - $this->add_texts( $submission ); |
|
38 | - $this->add_items( $submission ); |
|
39 | - $this->add_fees( $submission ); |
|
40 | - $this->add_discounts( $submission ); |
|
41 | - $this->add_taxes( $submission ); |
|
42 | - $this->add_gateways( $submission ); |
|
43 | - $this->add_data( $submission ); |
|
36 | + $this->add_totals($submission); |
|
37 | + $this->add_texts($submission); |
|
38 | + $this->add_items($submission); |
|
39 | + $this->add_fees($submission); |
|
40 | + $this->add_discounts($submission); |
|
41 | + $this->add_taxes($submission); |
|
42 | + $this->add_gateways($submission); |
|
43 | + $this->add_data($submission); |
|
44 | 44 | |
45 | 45 | } |
46 | 46 | |
@@ -49,30 +49,30 @@ discard block |
||
49 | 49 | * |
50 | 50 | * @param GetPaid_Payment_Form_Submission $submission |
51 | 51 | */ |
52 | - public function add_totals( $submission ) { |
|
52 | + public function add_totals($submission) { |
|
53 | 53 | |
54 | 54 | $this->response = array_merge( |
55 | 55 | $this->response, |
56 | 56 | array( |
57 | 57 | |
58 | 58 | 'totals' => array( |
59 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
60 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
61 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
62 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
63 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
64 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
59 | + 'subtotal' => $submission->format_amount($submission->get_subtotal()), |
|
60 | + 'discount' => $submission->format_amount($submission->get_discount()), |
|
61 | + 'fees' => $submission->format_amount($submission->get_fee()), |
|
62 | + 'tax' => $submission->format_amount($submission->get_tax()), |
|
63 | + 'total' => $submission->format_amount($submission->get_total()), |
|
64 | + 'raw_total' => html_entity_decode(sanitize_text_field($submission->format_amount($submission->get_total())), ENT_QUOTES), |
|
65 | 65 | ), |
66 | 66 | |
67 | 67 | 'recurring' => array( |
68 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
69 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
70 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
71 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
72 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
68 | + 'subtotal' => $submission->format_amount($submission->get_recurring_subtotal()), |
|
69 | + 'discount' => $submission->format_amount($submission->get_recurring_discount()), |
|
70 | + 'fees' => $submission->format_amount($submission->get_recurring_fee()), |
|
71 | + 'tax' => $submission->format_amount($submission->get_recurring_tax()), |
|
72 | + 'total' => $submission->format_amount($submission->get_recurring_total()), |
|
73 | 73 | ), |
74 | 74 | |
75 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
75 | + 'initial_amt' => wpinv_round_amount($submission->get_total(), null, true), |
|
76 | 76 | 'currency' => $submission->get_currency(), |
77 | 77 | |
78 | 78 | ) |
@@ -85,53 +85,53 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @param GetPaid_Payment_Form_Submission $submission |
87 | 87 | */ |
88 | - public function add_texts( $submission ) { |
|
88 | + public function add_texts($submission) { |
|
89 | 89 | |
90 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
91 | - $groups = getpaid_get_subscription_groups( $submission ); |
|
90 | + $payable = $submission->format_amount($submission->get_total()); |
|
91 | + $groups = getpaid_get_subscription_groups($submission); |
|
92 | 92 | |
93 | - if ( $submission->has_recurring && 2 > count( $groups ) ) { |
|
93 | + if ($submission->has_recurring && 2 > count($groups)) { |
|
94 | 94 | |
95 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
96 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
97 | - $main_item = reset( $groups ); |
|
95 | + $recurring = new WPInv_Item($submission->has_recurring); |
|
96 | + $period = getpaid_get_subscription_period_label($recurring->get_recurring_period(true), $recurring->get_recurring_interval(), ''); |
|
97 | + $main_item = reset($groups); |
|
98 | 98 | |
99 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
99 | + if ($submission->get_total() == $submission->get_recurring_total()) { |
|
100 | 100 | $payable = "$payable / $period"; |
101 | - } elseif ( $main_item ) { |
|
101 | + } elseif ($main_item) { |
|
102 | 102 | |
103 | - $main_item = reset( $main_item ); |
|
103 | + $main_item = reset($main_item); |
|
104 | 104 | |
105 | 105 | // Calculate the next renewal date. |
106 | - $_period = $main_item->get_recurring_period( true ); |
|
106 | + $_period = $main_item->get_recurring_period(true); |
|
107 | 107 | $_interval = $main_item->get_recurring_interval(); |
108 | 108 | |
109 | 109 | // If the subscription item has a trial period... |
110 | - if ( $main_item->has_free_trial() ) { |
|
111 | - $_period = $main_item->get_trial_period( true ); |
|
110 | + if ($main_item->has_free_trial()) { |
|
111 | + $_period = $main_item->get_trial_period(true); |
|
112 | 112 | $_interval = $main_item->get_trial_interval(); |
113 | 113 | } |
114 | 114 | |
115 | 115 | $payable = sprintf( |
116 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
117 | - $submission->format_amount( $submission->get_total() ), |
|
118 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
116 | + __('%1$s (renews at %2$s / %3$s)', 'invoicing'), |
|
117 | + $submission->format_amount($submission->get_total()), |
|
118 | + $submission->format_amount($submission->get_recurring_total()), |
|
119 | 119 | $period |
120 | 120 | ); |
121 | 121 | |
122 | 122 | $payable .= sprintf( |
123 | 123 | '<small class="text-muted form-text">%s</small>', |
124 | 124 | sprintf( |
125 | - __( 'First renewal on %s', 'invoicing' ), |
|
126 | - getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) ) |
|
125 | + __('First renewal on %s', 'invoicing'), |
|
126 | + getpaid_format_date(date('Y-m-d H:i:s', strtotime("+$_interval $_period", current_time('timestamp')))) |
|
127 | 127 | ) |
128 | 128 | ); |
129 | 129 | |
130 | 130 | } else { |
131 | 131 | $payable = sprintf( |
132 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
133 | - $submission->format_amount( $submission->get_total() ), |
|
134 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
132 | + __('%1$s (renews at %2$s / %3$s)', 'invoicing'), |
|
133 | + $submission->format_amount($submission->get_total()), |
|
134 | + $submission->format_amount($submission->get_recurring_total()), |
|
135 | 135 | $period |
136 | 136 | ); |
137 | 137 | } |
@@ -141,19 +141,19 @@ discard block |
||
141 | 141 | '.getpaid-checkout-total-payable' => $payable, |
142 | 142 | ); |
143 | 143 | |
144 | - foreach ( $submission->get_items() as $item ) { |
|
144 | + foreach ($submission->get_items() as $item) { |
|
145 | 145 | $item_id = $item->get_id(); |
146 | - $initial_price = $submission->format_amount( $item->get_sub_total() - $item->item_discount ); |
|
147 | - $recurring_price = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount ); |
|
148 | - $texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
149 | - $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) ); |
|
146 | + $initial_price = $submission->format_amount($item->get_sub_total() - $item->item_discount); |
|
147 | + $recurring_price = $submission->format_amount($item->get_recurring_sub_total() - $item->recurring_item_discount); |
|
148 | + $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text($item, $submission->get_currency(), $initial_price, $recurring_price); |
|
149 | + $texts[".item-$item_id .getpaid-mobile-item-subtotal"] = sprintf(__('Subtotal: %s', 'invoicing'), $submission->format_amount($item->get_sub_total())); |
|
150 | 150 | |
151 | - if ( $item->get_quantity() == 1 ) { |
|
152 | - $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = ''; |
|
151 | + if ($item->get_quantity() == 1) { |
|
152 | + $texts[".item-$item_id .getpaid-mobile-item-subtotal"] = ''; |
|
153 | 153 | } |
154 | 154 | } |
155 | 155 | |
156 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
156 | + $this->response = array_merge($this->response, array('texts' => $texts)); |
|
157 | 157 | |
158 | 158 | } |
159 | 159 | |
@@ -162,19 +162,19 @@ discard block |
||
162 | 162 | * |
163 | 163 | * @param GetPaid_Payment_Form_Submission $submission |
164 | 164 | */ |
165 | - public function add_items( $submission ) { |
|
165 | + public function add_items($submission) { |
|
166 | 166 | |
167 | 167 | // Add items. |
168 | 168 | $items = array(); |
169 | 169 | |
170 | - foreach ( $submission->get_items() as $item ) { |
|
171 | - $item_id = $item->get_id(); |
|
172 | - $items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() ); |
|
170 | + foreach ($submission->get_items() as $item) { |
|
171 | + $item_id = $item->get_id(); |
|
172 | + $items["$item_id"] = $submission->format_amount($item->get_sub_total()); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | $this->response = array_merge( |
176 | 176 | $this->response, |
177 | - array( 'items' => $items ) |
|
177 | + array('items' => $items) |
|
178 | 178 | ); |
179 | 179 | |
180 | 180 | } |
@@ -184,17 +184,17 @@ discard block |
||
184 | 184 | * |
185 | 185 | * @param GetPaid_Payment_Form_Submission $submission |
186 | 186 | */ |
187 | - public function add_fees( $submission ) { |
|
187 | + public function add_fees($submission) { |
|
188 | 188 | |
189 | 189 | $fees = array(); |
190 | 190 | |
191 | - foreach ( $submission->get_fees() as $name => $data ) { |
|
192 | - $fees[ $name ] = $submission->format_amount( $data['initial_fee'] ); |
|
191 | + foreach ($submission->get_fees() as $name => $data) { |
|
192 | + $fees[$name] = $submission->format_amount($data['initial_fee']); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | $this->response = array_merge( |
196 | 196 | $this->response, |
197 | - array( 'fees' => $fees ) |
|
197 | + array('fees' => $fees) |
|
198 | 198 | ); |
199 | 199 | |
200 | 200 | } |
@@ -204,17 +204,17 @@ discard block |
||
204 | 204 | * |
205 | 205 | * @param GetPaid_Payment_Form_Submission $submission |
206 | 206 | */ |
207 | - public function add_discounts( $submission ) { |
|
207 | + public function add_discounts($submission) { |
|
208 | 208 | |
209 | 209 | $discounts = array(); |
210 | 210 | |
211 | - foreach ( $submission->get_discounts() as $name => $data ) { |
|
212 | - $discounts[ $name ] = $submission->format_amount( $data['initial_discount'] ); |
|
211 | + foreach ($submission->get_discounts() as $name => $data) { |
|
212 | + $discounts[$name] = $submission->format_amount($data['initial_discount']); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | $this->response = array_merge( |
216 | 216 | $this->response, |
217 | - array( 'discounts' => $discounts ) |
|
217 | + array('discounts' => $discounts) |
|
218 | 218 | ); |
219 | 219 | |
220 | 220 | } |
@@ -224,24 +224,24 @@ discard block |
||
224 | 224 | * |
225 | 225 | * @param GetPaid_Payment_Form_Submission $submission |
226 | 226 | */ |
227 | - public function add_taxes( $submission ) { |
|
227 | + public function add_taxes($submission) { |
|
228 | 228 | |
229 | 229 | $taxes = array(); |
230 | 230 | $markup = ''; |
231 | - foreach ( $submission->get_taxes() as $name => $data ) { |
|
232 | - $name = sanitize_text_field( $name ); |
|
233 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
234 | - $taxes[ $name ] = $amount; |
|
231 | + foreach ($submission->get_taxes() as $name => $data) { |
|
232 | + $name = sanitize_text_field($name); |
|
233 | + $amount = $submission->format_amount($data['initial_tax']); |
|
234 | + $taxes[$name] = $amount; |
|
235 | 235 | $markup .= "<small class='form-text'>$name : $amount</small>"; |
236 | 236 | } |
237 | 237 | |
238 | - if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
238 | + if (wpinv_display_individual_tax_rates() && !empty($taxes)) { |
|
239 | 239 | $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
240 | 240 | } |
241 | 241 | |
242 | 242 | $this->response = array_merge( |
243 | 243 | $this->response, |
244 | - array( 'taxes' => $taxes ) |
|
244 | + array('taxes' => $taxes) |
|
245 | 245 | ); |
246 | 246 | |
247 | 247 | } |
@@ -251,27 +251,27 @@ discard block |
||
251 | 251 | * |
252 | 252 | * @param GetPaid_Payment_Form_Submission $submission |
253 | 253 | */ |
254 | - public function add_gateways( $submission ) { |
|
254 | + public function add_gateways($submission) { |
|
255 | 255 | |
256 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
256 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
257 | 257 | |
258 | - if ( $this->response['has_recurring'] ) { |
|
258 | + if ($this->response['has_recurring']) { |
|
259 | 259 | |
260 | - foreach ( $gateways as $i => $gateway ) { |
|
260 | + foreach ($gateways as $i => $gateway) { |
|
261 | 261 | |
262 | 262 | if ( |
263 | - ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) |
|
264 | - || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) ) |
|
265 | - || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) { |
|
266 | - unset( $gateways[ $i ] ); |
|
263 | + !getpaid_payment_gateway_supports($gateway, 'subscription') |
|
264 | + || ($this->response['has_subscription_group'] && !getpaid_payment_gateway_supports($gateway, 'single_subscription_group')) |
|
265 | + || ($this->response['has_multiple_subscription_groups'] && !getpaid_payment_gateway_supports($gateway, 'multiple_subscription_groups')) ) { |
|
266 | + unset($gateways[$i]); |
|
267 | 267 | } |
268 | 268 | } |
269 | 269 | } |
270 | 270 | |
271 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
271 | + $gateways = apply_filters('getpaid_submission_gateways', $gateways, $submission); |
|
272 | 272 | $this->response = array_merge( |
273 | 273 | $this->response, |
274 | - array( 'gateways' => $gateways ) |
|
274 | + array('gateways' => $gateways) |
|
275 | 275 | ); |
276 | 276 | |
277 | 277 | } |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | * |
282 | 282 | * @param GetPaid_Payment_Form_Submission $submission |
283 | 283 | */ |
284 | - public function add_data( $submission ) { |
|
284 | + public function add_data($submission) { |
|
285 | 285 | |
286 | 286 | $this->response = array_merge( |
287 | 287 | $this->response, |