@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * Please use GetPaid_Notification_Email_Sender |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /* |
12 | 12 | |-------------------------------------------------------------------------- |
@@ -17,19 +17,19 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * Generates the email header. |
19 | 19 | */ |
20 | -function wpinv_email_header( $email_heading ) { |
|
21 | - wpinv_get_template( 'emails/wpinv-email-header.php', compact( 'email_heading' ) ); |
|
20 | +function wpinv_email_header($email_heading) { |
|
21 | + wpinv_get_template('emails/wpinv-email-header.php', compact('email_heading')); |
|
22 | 22 | } |
23 | -add_action( 'wpinv_email_header', 'wpinv_email_header' ); |
|
23 | +add_action('wpinv_email_header', 'wpinv_email_header'); |
|
24 | 24 | |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Generates the email footer. |
28 | 28 | */ |
29 | 29 | function wpinv_email_footer() { |
30 | - wpinv_get_template( 'emails/wpinv-email-footer.php' ); |
|
30 | + wpinv_get_template('emails/wpinv-email-footer.php'); |
|
31 | 31 | } |
32 | -add_action( 'wpinv_email_footer', 'wpinv_email_footer' ); |
|
32 | +add_action('wpinv_email_footer', 'wpinv_email_footer'); |
|
33 | 33 | |
34 | 34 | |
35 | 35 | /** |
@@ -39,13 +39,13 @@ discard block |
||
39 | 39 | * @param string $email_type |
40 | 40 | * @param bool $sent_to_admin |
41 | 41 | */ |
42 | -function wpinv_email_invoice_details( $invoice, $email_type, $sent_to_admin ) { |
|
42 | +function wpinv_email_invoice_details($invoice, $email_type, $sent_to_admin) { |
|
43 | 43 | |
44 | - $args = compact( 'invoice', 'email_type', 'sent_to_admin' ); |
|
45 | - wpinv_get_template( 'emails/invoice-details.php', $args ); |
|
44 | + $args = compact('invoice', 'email_type', 'sent_to_admin'); |
|
45 | + wpinv_get_template('emails/invoice-details.php', $args); |
|
46 | 46 | |
47 | 47 | } |
48 | -add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 ); |
|
48 | +add_action('wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3); |
|
49 | 49 | |
50 | 50 | /** |
51 | 51 | * Display line items in emails. |
@@ -54,17 +54,17 @@ discard block |
||
54 | 54 | * @param string $email_type |
55 | 55 | * @param bool $sent_to_admin |
56 | 56 | */ |
57 | -function wpinv_email_invoice_items( $invoice, $email_type, $sent_to_admin ) { |
|
57 | +function wpinv_email_invoice_items($invoice, $email_type, $sent_to_admin) { |
|
58 | 58 | |
59 | 59 | // Prepare line items. |
60 | - $columns = getpaid_invoice_item_columns( $invoice ); |
|
61 | - $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice ); |
|
60 | + $columns = getpaid_invoice_item_columns($invoice); |
|
61 | + $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice); |
|
62 | 62 | |
63 | 63 | // Load the template. |
64 | - wpinv_get_template( 'emails/invoice-items.php', compact( 'invoice', 'columns', 'email_type', 'sent_to_admin' ) ); |
|
64 | + wpinv_get_template('emails/invoice-items.php', compact('invoice', 'columns', 'email_type', 'sent_to_admin')); |
|
65 | 65 | |
66 | 66 | } |
67 | -add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 ); |
|
67 | +add_action('wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3); |
|
68 | 68 | |
69 | 69 | |
70 | 70 | /** |
@@ -74,13 +74,13 @@ discard block |
||
74 | 74 | * @param string $email_type |
75 | 75 | * @param bool $sent_to_admin |
76 | 76 | */ |
77 | -function wpinv_email_billing_details( $invoice, $email_type, $sent_to_admin ) { |
|
77 | +function wpinv_email_billing_details($invoice, $email_type, $sent_to_admin) { |
|
78 | 78 | |
79 | - $args = compact( 'invoice', 'email_type', 'sent_to_admin' ); |
|
80 | - wpinv_get_template( 'emails/wpinv-email-billing-details.php', $args ); |
|
79 | + $args = compact('invoice', 'email_type', 'sent_to_admin'); |
|
80 | + wpinv_get_template('emails/wpinv-email-billing-details.php', $args); |
|
81 | 81 | |
82 | 82 | } |
83 | -add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 ); |
|
83 | +add_action('wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3); |
|
84 | 84 | |
85 | 85 | /** |
86 | 86 | * Returns email css. |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | */ |
89 | 89 | function getpaid_get_email_css() { |
90 | 90 | |
91 | - $css = wpinv_get_template_html( 'emails/wpinv-email-styles.php' ); |
|
92 | - return apply_filters( 'wpinv_email_styles', $css ); |
|
91 | + $css = wpinv_get_template_html('emails/wpinv-email-styles.php'); |
|
92 | + return apply_filters('wpinv_email_styles', $css); |
|
93 | 93 | |
94 | 94 | } |
95 | 95 | |
@@ -100,26 +100,26 @@ discard block |
||
100 | 100 | * @return string |
101 | 101 | * |
102 | 102 | */ |
103 | -function wpinv_email_style_body( $content ) { |
|
103 | +function wpinv_email_style_body($content) { |
|
104 | 104 | |
105 | - if ( ! class_exists( 'DOMDocument' ) ) { |
|
105 | + if (!class_exists('DOMDocument')) { |
|
106 | 106 | return $content; |
107 | 107 | } |
108 | 108 | |
109 | 109 | $css = getpaid_get_email_css(); |
110 | 110 | |
111 | 111 | // include css inliner |
112 | - if ( ! class_exists( 'Emogrifier' ) ) { |
|
112 | + if (!class_exists('Emogrifier')) { |
|
113 | 113 | include_once WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'; |
114 | 114 | } |
115 | 115 | |
116 | 116 | // Inline the css. |
117 | 117 | try { |
118 | - $emogrifier = new Emogrifier( $content, $css ); |
|
118 | + $emogrifier = new Emogrifier($content, $css); |
|
119 | 119 | $_content = $emogrifier->emogrify(); |
120 | 120 | $content = $_content; |
121 | - } catch ( Exception $e ) { |
|
122 | - wpinv_error_log( $e->getMessage(), 'emogrifier' ); |
|
121 | + } catch (Exception $e) { |
|
122 | + wpinv_error_log($e->getMessage(), 'emogrifier'); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | return $content; |
@@ -128,37 +128,37 @@ discard block |
||
128 | 128 | |
129 | 129 | // Backwards compatibility. |
130 | 130 | function wpinv_init_transactional_emails() { |
131 | - foreach ( apply_filters( 'wpinv_email_actions', array() ) as $action ) { |
|
132 | - add_action( $action, 'wpinv_send_transactional_email', 10, 10 ); |
|
131 | + foreach (apply_filters('wpinv_email_actions', array()) as $action) { |
|
132 | + add_action($action, 'wpinv_send_transactional_email', 10, 10); |
|
133 | 133 | } |
134 | 134 | } |
135 | -add_action( 'init', 'wpinv_init_transactional_emails' ); |
|
135 | +add_action('init', 'wpinv_init_transactional_emails'); |
|
136 | 136 | |
137 | 137 | function wpinv_send_transactional_email() { |
138 | 138 | $args = func_get_args(); |
139 | 139 | $function = current_filter() . '_notification'; |
140 | - do_action_ref_array( $function, $args ); |
|
140 | + do_action_ref_array($function, $args); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | function wpinv_mail_get_from_address() { |
144 | - $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from', get_option( 'admin_email' ) ) ); |
|
145 | - return sanitize_email( $from_address ); |
|
144 | + $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from', get_option('admin_email'))); |
|
145 | + return sanitize_email($from_address); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | function wpinv_mail_get_from_name() { |
149 | - $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name', get_bloginfo( 'name', 'display' ) ) ); |
|
150 | - return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES ); |
|
149 | + $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name', get_bloginfo('name', 'display'))); |
|
150 | + return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES); |
|
151 | 151 | } |
152 | 152 | |
153 | -function wpinv_mail_admin_bcc_active( $mail_type = '' ) { |
|
154 | - $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) ); |
|
155 | - return ( $active ? true : false ); |
|
153 | +function wpinv_mail_admin_bcc_active($mail_type = '') { |
|
154 | + $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc')); |
|
155 | + return ($active ? true : false); |
|
156 | 156 | } |
157 | 157 | |
158 | -function wpinv_mail_get_content_type( $content_type = 'text/html', $email_type = 'html' ) { |
|
159 | - $email_type = apply_filters( 'wpinv_mail_content_type', $email_type ); |
|
158 | +function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') { |
|
159 | + $email_type = apply_filters('wpinv_mail_content_type', $email_type); |
|
160 | 160 | |
161 | - switch ( $email_type ) { |
|
161 | + switch ($email_type) { |
|
162 | 162 | case 'html': |
163 | 163 | $content_type = 'text/html'; |
164 | 164 | break; |
@@ -183,11 +183,11 @@ discard block |
||
183 | 183 | * @param array $attachments Any files to attach to the email. |
184 | 184 | * @param string|array $cc An email or array of extra emails to send a copy of the email to. |
185 | 185 | */ |
186 | -function wpinv_mail_send( $to, $subject, $message, $deprecated, $attachments = array(), $cc = array() ) { |
|
186 | +function wpinv_mail_send($to, $subject, $message, $deprecated, $attachments = array(), $cc = array()) { |
|
187 | 187 | |
188 | 188 | $mailer = new GetPaid_Notification_Email_Sender(); |
189 | - $message = wpinv_email_style_body( $message ); |
|
190 | - $to = array_merge( wpinv_parse_list( $to ), wpinv_parse_list( $cc ) ); |
|
189 | + $message = wpinv_email_style_body($message); |
|
190 | + $to = array_merge(wpinv_parse_list($to), wpinv_parse_list($cc)); |
|
191 | 191 | |
192 | 192 | return $mailer->send( |
193 | 193 | $to, |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | * @return array |
205 | 205 | */ |
206 | 206 | function wpinv_get_emails() { |
207 | - return apply_filters( 'wpinv_get_emails', wpinv_get_data( 'email-settings' ) ); |
|
207 | + return apply_filters('wpinv_get_emails', wpinv_get_data('email-settings')); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -213,172 +213,172 @@ discard block |
||
213 | 213 | * @param array $settings |
214 | 214 | * @return array |
215 | 215 | */ |
216 | -function wpinv_settings_emails( $settings = array() ) { |
|
217 | - $settings = array_merge( $settings, wpinv_get_emails() ); |
|
218 | - return apply_filters( 'wpinv_settings_get_emails', $settings ); |
|
216 | +function wpinv_settings_emails($settings = array()) { |
|
217 | + $settings = array_merge($settings, wpinv_get_emails()); |
|
218 | + return apply_filters('wpinv_settings_get_emails', $settings); |
|
219 | 219 | } |
220 | -add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 ); |
|
220 | +add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1); |
|
221 | 221 | |
222 | 222 | /** |
223 | 223 | * Filter email section names. |
224 | 224 | * |
225 | 225 | */ |
226 | -function wpinv_settings_sections_emails( $settings ) { |
|
227 | - foreach ( wpinv_get_emails() as $key => $email ) { |
|
228 | - $settings[ $key ] = ! empty( $email[ 'email_' . $key . '_header' ]['name'] ) ? strip_tags( $email[ 'email_' . $key . '_header' ]['name'] ) : strip_tags( $key ); |
|
226 | +function wpinv_settings_sections_emails($settings) { |
|
227 | + foreach (wpinv_get_emails() as $key => $email) { |
|
228 | + $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : strip_tags($key); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | return $settings; |
232 | 232 | } |
233 | -add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 ); |
|
233 | +add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1); |
|
234 | 234 | |
235 | -function wpinv_email_is_enabled( $email_type ) { |
|
235 | +function wpinv_email_is_enabled($email_type) { |
|
236 | 236 | $emails = wpinv_get_emails(); |
237 | - $enabled = isset( $emails[ $email_type ] ) && wpinv_get_option( 'email_' . $email_type . '_active', 0 ) ? true : false; |
|
237 | + $enabled = isset($emails[$email_type]) && wpinv_get_option('email_' . $email_type . '_active', 0) ? true : false; |
|
238 | 238 | |
239 | - return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type ); |
|
239 | + return apply_filters('wpinv_email_is_enabled', $enabled, $email_type); |
|
240 | 240 | } |
241 | 241 | |
242 | -function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
243 | - switch ( $email_type ) { |
|
242 | +function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
243 | + switch ($email_type) { |
|
244 | 244 | case 'new_invoice': |
245 | 245 | case 'cancelled_invoice': |
246 | 246 | case 'failed_invoice': |
247 | 247 | $recipient = wpinv_get_admin_email(); |
248 | 248 | break; |
249 | 249 | default: |
250 | - $invoice = ! empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : null ); |
|
251 | - $recipient = ! empty( $invoice ) ? $invoice->get_email() : ''; |
|
250 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : null); |
|
251 | + $recipient = !empty($invoice) ? $invoice->get_email() : ''; |
|
252 | 252 | break; |
253 | 253 | } |
254 | 254 | |
255 | - return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice ); |
|
255 | + return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
259 | 259 | * Returns invoice CC recipients |
260 | 260 | */ |
261 | -function wpinv_email_get_cc_recipients( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
262 | - switch ( $email_type ) { |
|
261 | +function wpinv_email_get_cc_recipients($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
262 | + switch ($email_type) { |
|
263 | 263 | case 'new_invoice': |
264 | 264 | case 'cancelled_invoice': |
265 | 265 | case 'failed_invoice': |
266 | 266 | return array(); |
267 | 267 | break; |
268 | 268 | default: |
269 | - $invoice = ! empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : null ); |
|
270 | - $recipient = empty( $invoice ) ? '' : get_post_meta( $invoice->ID, 'wpinv_email_cc', true ); |
|
271 | - if ( empty( $recipient ) ) { |
|
269 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : null); |
|
270 | + $recipient = empty($invoice) ? '' : get_post_meta($invoice->ID, 'wpinv_email_cc', true); |
|
271 | + if (empty($recipient)) { |
|
272 | 272 | return array(); |
273 | 273 | } |
274 | - return array_filter( array_map( 'trim', explode( ',', $recipient ) ) ); |
|
274 | + return array_filter(array_map('trim', explode(',', $recipient))); |
|
275 | 275 | break; |
276 | 276 | } |
277 | 277 | |
278 | 278 | } |
279 | 279 | |
280 | -function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
281 | - $subject = wpinv_get_option( 'email_' . $email_type . '_subject' ); |
|
282 | - $subject = __( $subject, 'invoicing' ); |
|
280 | +function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
281 | + $subject = wpinv_get_option('email_' . $email_type . '_subject'); |
|
282 | + $subject = __($subject, 'invoicing'); |
|
283 | 283 | |
284 | - $subject = wpinv_email_format_text( $subject, $invoice ); |
|
284 | + $subject = wpinv_email_format_text($subject, $invoice); |
|
285 | 285 | |
286 | - return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice ); |
|
286 | + return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice); |
|
287 | 287 | } |
288 | 288 | |
289 | -function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
290 | - $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' ); |
|
291 | - $email_heading = __( $email_heading, 'invoicing' ); |
|
289 | +function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
290 | + $email_heading = wpinv_get_option('email_' . $email_type . '_heading'); |
|
291 | + $email_heading = __($email_heading, 'invoicing'); |
|
292 | 292 | |
293 | - $email_heading = wpinv_email_format_text( $email_heading, $invoice ); |
|
293 | + $email_heading = wpinv_email_format_text($email_heading, $invoice); |
|
294 | 294 | |
295 | - return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice ); |
|
295 | + return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice); |
|
296 | 296 | } |
297 | 297 | |
298 | -function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
299 | - $content = wpinv_get_option( 'email_' . $email_type . '_body' ); |
|
300 | - $content = __( $content, 'invoicing' ); |
|
298 | +function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
299 | + $content = wpinv_get_option('email_' . $email_type . '_body'); |
|
300 | + $content = __($content, 'invoicing'); |
|
301 | 301 | |
302 | - $content = wpinv_email_format_text( $content, $invoice ); |
|
302 | + $content = wpinv_email_format_text($content, $invoice); |
|
303 | 303 | |
304 | - return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice ); |
|
304 | + return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice); |
|
305 | 305 | } |
306 | 306 | |
307 | -function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
307 | +function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
308 | 308 | $from_name = wpinv_mail_get_from_address(); |
309 | 309 | $from_email = wpinv_mail_get_from_address(); |
310 | 310 | |
311 | - $invoice = ! empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : null ); |
|
311 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : null); |
|
312 | 312 | |
313 | - $headers = 'From: ' . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n"; |
|
313 | + $headers = 'From: ' . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n"; |
|
314 | 314 | $headers .= 'Reply-To: ' . $from_email . "\r\n"; |
315 | 315 | $headers .= 'Content-Type: ' . wpinv_mail_get_content_type() . "\r\n"; |
316 | 316 | |
317 | - return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice ); |
|
317 | + return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice); |
|
318 | 318 | } |
319 | 319 | |
320 | -function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
320 | +function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
321 | 321 | $attachments = array(); |
322 | 322 | |
323 | - return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice ); |
|
323 | + return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
327 | 327 | * Searches for and replaces certain placeholders in an email. |
328 | 328 | */ |
329 | -function wpinv_email_format_text( $content, $invoice ) { |
|
329 | +function wpinv_email_format_text($content, $invoice) { |
|
330 | 330 | |
331 | 331 | $replace_array = array( |
332 | 332 | '{site_title}' => wpinv_get_blogname(), |
333 | - '{date}' => getpaid_format_date( current_time( 'mysql' ) ), |
|
333 | + '{date}' => getpaid_format_date(current_time('mysql')), |
|
334 | 334 | ); |
335 | 335 | |
336 | - $invoice = new WPInv_Invoice( $invoice ); |
|
336 | + $invoice = new WPInv_Invoice($invoice); |
|
337 | 337 | |
338 | - if ( $invoice->get_id() ) { |
|
338 | + if ($invoice->get_id()) { |
|
339 | 339 | |
340 | 340 | $replace_array = array_merge( |
341 | 341 | $replace_array, |
342 | 342 | array( |
343 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
344 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
345 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
346 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
347 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
348 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
349 | - '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total( true ), $invoice->get_currency() ) ), |
|
350 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
351 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
352 | - '{invoice_date}' => date( get_option( 'date_format' ), strtotime( $invoice->get_date_created(), current_time( 'timestamp' ) ) ), |
|
353 | - '{invoice_due_date}' => date( get_option( 'date_format' ), strtotime( $invoice->get_due_date(), current_time( 'timestamp' ) ) ), |
|
354 | - '{invoice_quote}' => sanitize_text_field( $invoice->get_invoice_quote_type() ), |
|
355 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_invoice_quote_type() ) ), |
|
356 | - '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
343 | + '{name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
344 | + '{full_name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
345 | + '{first_name}' => sanitize_text_field($invoice->get_first_name()), |
|
346 | + '{last_name}' => sanitize_text_field($invoice->get_last_name()), |
|
347 | + '{email}' => sanitize_email($invoice->get_email()), |
|
348 | + '{invoice_number}' => sanitize_text_field($invoice->get_number()), |
|
349 | + '{invoice_total}' => sanitize_text_field(wpinv_price($invoice->get_total(true), $invoice->get_currency())), |
|
350 | + '{invoice_link}' => esc_url($invoice->get_view_url()), |
|
351 | + '{invoice_pay_link}' => esc_url($invoice->get_checkout_payment_url()), |
|
352 | + '{invoice_date}' => date(get_option('date_format'), strtotime($invoice->get_date_created(), current_time('timestamp'))), |
|
353 | + '{invoice_due_date}' => date(get_option('date_format'), strtotime($invoice->get_due_date(), current_time('timestamp'))), |
|
354 | + '{invoice_quote}' => sanitize_text_field($invoice->get_invoice_quote_type()), |
|
355 | + '{invoice_label}' => sanitize_text_field(ucfirst($invoice->get_invoice_quote_type())), |
|
356 | + '{is_was}' => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'), |
|
357 | 357 | ) |
358 | 358 | ); |
359 | 359 | |
360 | 360 | } |
361 | 361 | |
362 | 362 | // Let third party plugins filter the arra. |
363 | - $replace_array = apply_filters( 'wpinv_email_format_text', $replace_array, $content, $invoice ); |
|
363 | + $replace_array = apply_filters('wpinv_email_format_text', $replace_array, $content, $invoice); |
|
364 | 364 | |
365 | - foreach ( $replace_array as $key => $value ) { |
|
366 | - $content = str_replace( $key, $value, $content ); |
|
365 | + foreach ($replace_array as $key => $value) { |
|
366 | + $content = str_replace($key, $value, $content); |
|
367 | 367 | } |
368 | 368 | |
369 | - return apply_filters( 'wpinv_email_content_replace', $content ); |
|
369 | + return apply_filters('wpinv_email_content_replace', $content); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | |
373 | -function wpinv_email_wrap_message( $message ) { |
|
373 | +function wpinv_email_wrap_message($message) { |
|
374 | 374 | // Buffer |
375 | 375 | ob_start(); |
376 | 376 | |
377 | - do_action( 'wpinv_email_header' ); |
|
377 | + do_action('wpinv_email_header'); |
|
378 | 378 | |
379 | - echo wp_kses_post( wpautop( wptexturize( $message ) ) ); |
|
379 | + echo wp_kses_post(wpautop(wptexturize($message))); |
|
380 | 380 | |
381 | - do_action( 'wpinv_email_footer' ); |
|
381 | + do_action('wpinv_email_footer'); |
|
382 | 382 | |
383 | 383 | // Get contents |
384 | 384 | $message = ob_get_clean(); |
@@ -386,21 +386,21 @@ discard block |
||
386 | 386 | return $message; |
387 | 387 | } |
388 | 388 | |
389 | -function wpinv_add_notes_to_invoice_email( $invoice, $email_type ) { |
|
390 | - if ( ! empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->get_id(), true ) ) { |
|
391 | - $date_format = get_option( 'date_format' ); |
|
392 | - $time_format = get_option( 'time_format' ); |
|
389 | +function wpinv_add_notes_to_invoice_email($invoice, $email_type) { |
|
390 | + if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->get_id(), true)) { |
|
391 | + $date_format = get_option('date_format'); |
|
392 | + $time_format = get_option('time_format'); |
|
393 | 393 | ?> |
394 | 394 | <div id="wpinv-email-notes"> |
395 | - <h3 class="wpinv-notes-t"><?php echo esc_html( apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ) ); ?></h3> |
|
395 | + <h3 class="wpinv-notes-t"><?php echo esc_html(apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing'))); ?></h3> |
|
396 | 396 | <ol class="wpinv-notes-lists"> |
397 | 397 | <?php |
398 | - foreach ( $invoice_notes as $note ) { |
|
399 | - $note_time = strtotime( $note->comment_date ); |
|
398 | + foreach ($invoice_notes as $note) { |
|
399 | + $note_time = strtotime($note->comment_date); |
|
400 | 400 | ?> |
401 | 401 | <li class="comment wpinv-note"> |
402 | - <p class="wpinv-note-date meta"><?php printf( esc_html__( '%2$s at %3$s', 'invoicing' ), esc_html( $note->comment_author ), esc_html( date_i18n( $date_format, $note_time ) ), esc_html( date_i18n( $time_format, $note_time ) ), esc_html( $note_time ) ); ?></p> |
|
403 | - <div class="wpinv-note-desc description"><?php echo wp_kses_post( wpautop( wptexturize( $note->comment_content ) ) ); ?></div> |
|
402 | + <p class="wpinv-note-date meta"><?php printf(esc_html__('%2$s at %3$s', 'invoicing'), esc_html($note->comment_author), esc_html(date_i18n($date_format, $note_time)), esc_html(date_i18n($time_format, $note_time)), esc_html($note_time)); ?></p> |
|
403 | + <div class="wpinv-note-desc description"><?php echo wp_kses_post(wpautop(wptexturize($note->comment_content))); ?></div> |
|
404 | 404 | </li> |
405 | 405 | <?php |
406 | 406 | } |
@@ -410,4 +410,4 @@ discard block |
||
410 | 410 | <?php |
411 | 411 | } |
412 | 412 | } |
413 | -add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 ); |
|
413 | +add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3); |
@@ -1,38 +1,38 @@ |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( ! defined( 'WPINC' ) ) { |
|
3 | +if (!defined('WPINC')) { |
|
4 | 4 | exit; |
5 | 5 | } |
6 | 6 | |
7 | 7 | class WPInv_Meta_Box_Notes { |
8 | - public static function output( $post ) { |
|
8 | + public static function output($post) { |
|
9 | 9 | global $post; |
10 | 10 | |
11 | - $notes = wpinv_get_invoice_notes( $post->ID ); |
|
11 | + $notes = wpinv_get_invoice_notes($post->ID); |
|
12 | 12 | |
13 | 13 | echo '<ul class="invoice_notes">'; |
14 | 14 | |
15 | - if ( $notes ) { |
|
16 | - foreach ( $notes as $note ) { |
|
17 | - wpinv_get_invoice_note_line_item( $note ); |
|
15 | + if ($notes) { |
|
16 | + foreach ($notes as $note) { |
|
17 | + wpinv_get_invoice_note_line_item($note); |
|
18 | 18 | } |
19 | 19 | } else { |
20 | - echo '<li>' . esc_html__( 'There are no notes yet.', 'invoicing' ) . '</li>'; |
|
20 | + echo '<li>' . esc_html__('There are no notes yet.', 'invoicing') . '</li>'; |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | echo '</ul>'; |
24 | 24 | ?> |
25 | 25 | <div class="add_note"> |
26 | - <h4><?php esc_html_e( 'Add note', 'invoicing' ); ?></h4> |
|
26 | + <h4><?php esc_html_e('Add note', 'invoicing'); ?></h4> |
|
27 | 27 | <p> |
28 | 28 | <textarea type="text" name="invoice_note" id="add_invoice_note" class="input-text" cols="20" rows="5"></textarea> |
29 | 29 | </p> |
30 | 30 | <p> |
31 | 31 | <select name="invoice_note_type" id="invoice_note_type" class="regular-text"> |
32 | - <option value=""><?php esc_html_e( 'Private note', 'invoicing' ); ?></option> |
|
33 | - <option value="customer"><?php esc_html_e( 'Note to customer', 'invoicing' ); ?></option> |
|
32 | + <option value=""><?php esc_html_e('Private note', 'invoicing'); ?></option> |
|
33 | + <option value="customer"><?php esc_html_e('Note to customer', 'invoicing'); ?></option> |
|
34 | 34 | </select> |
35 | - <a href="#" class="add_note button"><?php esc_html_e( 'Add', 'invoicing' ); ?></a> <span class="description"><?php esc_html_e( 'Add a note for your reference, or add a customer note (the user will be notified).', 'invoicing' ); ?></span> |
|
35 | + <a href="#" class="add_note button"><?php esc_html_e('Add', 'invoicing'); ?></a> <span class="description"><?php esc_html_e('Add a note for your reference, or add a customer note (the user will be notified).', 'invoicing'); ?></span> |
|
36 | 36 | </p> |
37 | 37 | </div> |
38 | 38 | <?php |
@@ -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 | * Returns the errors as html |
@@ -15,35 +15,35 @@ discard block |
||
15 | 15 | * @param bool $wrap whether or not to wrap the errors. |
16 | 16 | * @since 1.0.19 |
17 | 17 | */ |
18 | -function getpaid_get_errors_html( $clear = true, $wrap = true ) { |
|
18 | +function getpaid_get_errors_html($clear = true, $wrap = true) { |
|
19 | 19 | |
20 | 20 | $errors = ''; |
21 | - foreach ( wpinv_get_errors() as $id => $error ) { |
|
22 | - $type = 'error'; |
|
21 | + foreach (wpinv_get_errors() as $id => $error) { |
|
22 | + $type = 'error'; |
|
23 | 23 | |
24 | - if ( is_array( $error ) ) { |
|
24 | + if (is_array($error)) { |
|
25 | 25 | $type = $error['type']; |
26 | 26 | $error = $error['text']; |
27 | 27 | } |
28 | 28 | |
29 | - if ( $wrap ) { |
|
29 | + if ($wrap) { |
|
30 | 30 | |
31 | 31 | $errors .= aui()->alert( |
32 | 32 | array( |
33 | - 'content' => wp_kses_post( $error ), |
|
33 | + 'content' => wp_kses_post($error), |
|
34 | 34 | 'type' => $type, |
35 | 35 | ) |
36 | 36 | ); |
37 | 37 | |
38 | 38 | } else { |
39 | 39 | |
40 | - $id = esc_attr( $id ); |
|
41 | - $error = wp_kses_post( $error ); |
|
40 | + $id = esc_attr($id); |
|
41 | + $error = wp_kses_post($error); |
|
42 | 42 | $errors .= "<div data-code='$id'>$error</div>"; |
43 | 43 | } |
44 | 44 | } |
45 | 45 | |
46 | - if ( $clear ) { |
|
46 | + if ($clear) { |
|
47 | 47 | wpinv_clear_errors(); |
48 | 48 | } |
49 | 49 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * Prints (then clears) all available errors. |
56 | 56 | */ |
57 | 57 | function wpinv_print_errors() { |
58 | - echo wp_kses_post( getpaid_get_errors_html() ); |
|
58 | + echo wp_kses_post(getpaid_get_errors_html()); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | * @return array |
65 | 65 | */ |
66 | 66 | function wpinv_get_errors() { |
67 | - $errors = getpaid_session()->get( 'wpinv_errors' ); |
|
68 | - return is_array( $errors ) ? $errors : array(); |
|
67 | + $errors = getpaid_session()->get('wpinv_errors'); |
|
68 | + return is_array($errors) ? $errors : array(); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -75,15 +75,15 @@ discard block |
||
75 | 75 | * @param string $error_message The error message. |
76 | 76 | * @param string $type Either error, info, warning, primary, dark, light or success. |
77 | 77 | */ |
78 | -function wpinv_set_error( $error_id, $error_message, $type = 'error' ) { |
|
78 | +function wpinv_set_error($error_id, $error_message, $type = 'error') { |
|
79 | 79 | |
80 | 80 | $errors = wpinv_get_errors(); |
81 | - $errors[ $error_id ] = array( |
|
81 | + $errors[$error_id] = array( |
|
82 | 82 | 'type' => $type, |
83 | 83 | 'text' => $error_message, |
84 | 84 | ); |
85 | 85 | |
86 | - getpaid_session()->set( 'wpinv_errors', $errors ); |
|
86 | + getpaid_session()->set('wpinv_errors', $errors); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * |
92 | 92 | */ |
93 | 93 | function wpinv_has_errors() { |
94 | - return count( wpinv_get_errors() ) > 0; |
|
94 | + return count(wpinv_get_errors()) > 0; |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -99,21 +99,21 @@ discard block |
||
99 | 99 | * |
100 | 100 | */ |
101 | 101 | function wpinv_clear_errors() { |
102 | - getpaid_session()->set( 'wpinv_errors', null ); |
|
102 | + getpaid_session()->set('wpinv_errors', null); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
106 | 106 | * Clears a single error. |
107 | 107 | * |
108 | 108 | */ |
109 | -function wpinv_unset_error( $error_id ) { |
|
109 | +function wpinv_unset_error($error_id) { |
|
110 | 110 | $errors = wpinv_get_errors(); |
111 | 111 | |
112 | - if ( isset( $errors[ $error_id ] ) ) { |
|
113 | - unset( $errors[ $error_id ] ); |
|
112 | + if (isset($errors[$error_id])) { |
|
113 | + unset($errors[$error_id]); |
|
114 | 114 | } |
115 | 115 | |
116 | - getpaid_session()->set( 'wpinv_errors', $errors ); |
|
116 | + getpaid_session()->set('wpinv_errors', $errors); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -124,15 +124,15 @@ discard block |
||
124 | 124 | * @param string $message Message to log. |
125 | 125 | * @param string $version Version the message was added in. |
126 | 126 | */ |
127 | -function getpaid_doing_it_wrong( $function, $message, $version ) { |
|
127 | +function getpaid_doing_it_wrong($function, $message, $version) { |
|
128 | 128 | |
129 | 129 | $message .= ' Backtrace: ' . wp_debug_backtrace_summary(); |
130 | 130 | |
131 | - if ( wp_doing_ajax() || defined( 'REST_REQUEST' ) ) { |
|
132 | - do_action( 'doing_it_wrong_run', $function, $message, $version ); |
|
133 | - error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." ); |
|
131 | + if (wp_doing_ajax() || defined('REST_REQUEST')) { |
|
132 | + do_action('doing_it_wrong_run', $function, $message, $version); |
|
133 | + error_log("{$function} was called incorrectly. {$message}. This message was added in version {$version}."); |
|
134 | 134 | } else { |
135 | - _doing_it_wrong( esc_html( $function ), wp_kses_post( $message ), esc_html( $version ) ); |
|
135 | + _doing_it_wrong(esc_html($function), wp_kses_post($message), esc_html($version)); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | } |
@@ -146,41 +146,41 @@ discard block |
||
146 | 146 | * @param string $line The line that contains the error. |
147 | 147 | * @param bool $exit Whether or not to exit function execution. |
148 | 148 | */ |
149 | -function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) { |
|
149 | +function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) { |
|
150 | 150 | |
151 | - if ( true === apply_filters( 'wpinv_log_errors', true ) ) { |
|
151 | + if (true === apply_filters('wpinv_log_errors', true)) { |
|
152 | 152 | |
153 | 153 | // Ensure the log is a scalar. |
154 | - if ( ! is_scalar( $log ) ) { |
|
155 | - $log = print_r( $log, true ); |
|
154 | + if (!is_scalar($log)) { |
|
155 | + $log = print_r($log, true); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | // Add title. |
159 | - if ( ! empty( $title ) ) { |
|
160 | - $log = $title . ' ' . trim( $log ); |
|
159 | + if (!empty($title)) { |
|
160 | + $log = $title . ' ' . trim($log); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | // Add the file to the label. |
164 | - if ( ! empty( $file ) ) { |
|
164 | + if (!empty($file)) { |
|
165 | 165 | $log .= ' in ' . $file; |
166 | 166 | } |
167 | 167 | |
168 | 168 | // Add the line number to the label. |
169 | - if ( ! empty( $line ) ) { |
|
169 | + if (!empty($line)) { |
|
170 | 170 | $log .= ' on line ' . $line; |
171 | 171 | } |
172 | 172 | |
173 | 173 | // Log the message. |
174 | - error_log( trim( $log ) ); |
|
174 | + error_log(trim($log)); |
|
175 | 175 | |
176 | 176 | // ... and a backtrace. |
177 | - if ( false !== $title && false !== $file ) { |
|
178 | - error_log( 'Backtrace ' . wp_debug_backtrace_summary() ); |
|
177 | + if (false !== $title && false !== $file) { |
|
178 | + error_log('Backtrace ' . wp_debug_backtrace_summary()); |
|
179 | 179 | } |
180 | 180 | } |
181 | 181 | |
182 | 182 | // Maybe exit. |
183 | - if ( $exit ) { |
|
183 | + if ($exit) { |
|
184 | 184 | exit; |
185 | 185 | } |
186 | 186 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * @deprecated |
@@ -19,48 +19,48 @@ discard block |
||
19 | 19 | * @deprecated |
20 | 20 | */ |
21 | 21 | function wpinv_get_invoice_cart() { |
22 | - return wpinv_get_invoice( getpaid_get_current_invoice_id() ); |
|
22 | + return wpinv_get_invoice(getpaid_get_current_invoice_id()); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
26 | 26 | * @deprecated |
27 | 27 | */ |
28 | -function wpinv_get_invoice_description( $invoice ) { |
|
29 | - $invoice = new WPInv_Invoice( $invoice ); |
|
28 | +function wpinv_get_invoice_description($invoice) { |
|
29 | + $invoice = new WPInv_Invoice($invoice); |
|
30 | 30 | return $invoice->get_description(); |
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | 34 | * @deprecated |
35 | 35 | */ |
36 | -function wpinv_get_invoice_currency_code( $invoice ) { |
|
37 | - $invoice = new WPInv_Invoice( $invoice ); |
|
36 | +function wpinv_get_invoice_currency_code($invoice) { |
|
37 | + $invoice = new WPInv_Invoice($invoice); |
|
38 | 38 | return $invoice->get_currency(); |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * @deprecated |
43 | 43 | */ |
44 | -function wpinv_get_payment_user_email( $invoice ) { |
|
45 | - $invoice = new WPInv_Invoice( $invoice ); |
|
44 | +function wpinv_get_payment_user_email($invoice) { |
|
45 | + $invoice = new WPInv_Invoice($invoice); |
|
46 | 46 | return $invoice->get_email(); |
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | 50 | * @deprecated |
51 | 51 | */ |
52 | -function wpinv_get_user_id( $invoice ) { |
|
53 | - $invoice = new WPInv_Invoice( $invoice ); |
|
52 | +function wpinv_get_user_id($invoice) { |
|
53 | + $invoice = new WPInv_Invoice($invoice); |
|
54 | 54 | return $invoice->get_user_id(); |
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | 58 | * @deprecated |
59 | 59 | */ |
60 | -function wpinv_get_invoice_status( $invoice, $return_label = false ) { |
|
61 | - $invoice = new WPInv_Invoice( $invoice ); |
|
60 | +function wpinv_get_invoice_status($invoice, $return_label = false) { |
|
61 | + $invoice = new WPInv_Invoice($invoice); |
|
62 | 62 | |
63 | - if ( $return_label ) { |
|
63 | + if ($return_label) { |
|
64 | 64 | return $invoice->get_status_nicename(); |
65 | 65 | } |
66 | 66 | |
@@ -70,10 +70,10 @@ discard block |
||
70 | 70 | /** |
71 | 71 | * @deprecated |
72 | 72 | */ |
73 | -function wpinv_get_payment_gateway( $invoice, $return_label = false ) { |
|
74 | - $invoice = new WPInv_Invoice( $invoice ); |
|
73 | +function wpinv_get_payment_gateway($invoice, $return_label = false) { |
|
74 | + $invoice = new WPInv_Invoice($invoice); |
|
75 | 75 | |
76 | - if ( $return_label ) { |
|
76 | + if ($return_label) { |
|
77 | 77 | return $invoice->get_gateway_title(); |
78 | 78 | } |
79 | 79 | |
@@ -83,75 +83,75 @@ discard block |
||
83 | 83 | /** |
84 | 84 | * @deprecated |
85 | 85 | */ |
86 | -function wpinv_get_payment_gateway_name( $invoice ) { |
|
87 | - return wpinv_get_payment_gateway( $invoice, true ); |
|
86 | +function wpinv_get_payment_gateway_name($invoice) { |
|
87 | + return wpinv_get_payment_gateway($invoice, true); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
91 | 91 | * @deprecated |
92 | 92 | */ |
93 | -function wpinv_get_payment_transaction_id( $invoice ) { |
|
94 | - $invoice = new WPInv_Invoice( $invoice ); |
|
93 | +function wpinv_get_payment_transaction_id($invoice) { |
|
94 | + $invoice = new WPInv_Invoice($invoice); |
|
95 | 95 | return $invoice->get_transaction_id(); |
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
99 | 99 | * @deprecated |
100 | 100 | */ |
101 | -function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
102 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
103 | - return $invoice->get_meta( $meta_key, $single ); |
|
101 | +function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) { |
|
102 | + $invoice = new WPInv_Invoice($invoice_id); |
|
103 | + return $invoice->get_meta($meta_key, $single); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
107 | 107 | * @deprecated |
108 | 108 | */ |
109 | -function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '' ) { |
|
110 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
111 | - return $invoice->update_meta_data( $meta_key, $meta_value ); |
|
109 | +function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '') { |
|
110 | + $invoice = new WPInv_Invoice($invoice_id); |
|
111 | + return $invoice->update_meta_data($meta_key, $meta_value); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
115 | 115 | * @deprecated |
116 | 116 | */ |
117 | -function wpinv_get_items( $invoice = 0 ) { |
|
118 | - $invoice = new WPInv_Invoice( $invoice ); |
|
117 | +function wpinv_get_items($invoice = 0) { |
|
118 | + $invoice = new WPInv_Invoice($invoice); |
|
119 | 119 | return $invoice->get_items(); |
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | 123 | * @deprecated |
124 | 124 | */ |
125 | -function wpinv_get_fees( $invoice = 0 ) { |
|
126 | - $invoice = new WPInv_Invoice( $invoice ); |
|
125 | +function wpinv_get_fees($invoice = 0) { |
|
126 | + $invoice = new WPInv_Invoice($invoice); |
|
127 | 127 | return $invoice->get_fees(); |
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
131 | 131 | * @deprecated |
132 | 132 | */ |
133 | -function wpinv_get_invoice_ip( $invoice ) { |
|
134 | - $invoice = new WPInv_Invoice( $invoice ); |
|
133 | +function wpinv_get_invoice_ip($invoice) { |
|
134 | + $invoice = new WPInv_Invoice($invoice); |
|
135 | 135 | return $invoice->get_ip(); |
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | 139 | * @deprecated |
140 | 140 | */ |
141 | -function wpinv_get_invoice_user_info( $invoice ) { |
|
142 | - $invoice = new WPInv_Invoice( $invoice ); |
|
141 | +function wpinv_get_invoice_user_info($invoice) { |
|
142 | + $invoice = new WPInv_Invoice($invoice); |
|
143 | 143 | return $invoice->get_user_info(); |
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
147 | 147 | * @deprecated |
148 | 148 | */ |
149 | -function wpinv_subtotal( $invoice = 0, $currency = false ) { |
|
150 | - $invoice = new WPInv_Invoice( $invoice ); |
|
149 | +function wpinv_subtotal($invoice = 0, $currency = false) { |
|
150 | + $invoice = new WPInv_Invoice($invoice); |
|
151 | 151 | $subtotal = $invoice->get_subtotal(); |
152 | 152 | |
153 | - if ( $currency ) { |
|
154 | - return wpinv_price( $subtotal, $invoice->get_currency() ); |
|
153 | + if ($currency) { |
|
154 | + return wpinv_price($subtotal, $invoice->get_currency()); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | return $subtotal; |
@@ -160,12 +160,12 @@ discard block |
||
160 | 160 | /** |
161 | 161 | * @deprecated |
162 | 162 | */ |
163 | -function wpinv_tax( $invoice = 0, $currency = false ) { |
|
164 | - $invoice = new WPInv_Invoice( $invoice ); |
|
163 | +function wpinv_tax($invoice = 0, $currency = false) { |
|
164 | + $invoice = new WPInv_Invoice($invoice); |
|
165 | 165 | $tax = $invoice->get_total_tax(); |
166 | 166 | |
167 | - if ( $currency ) { |
|
168 | - return wpinv_price( $tax, $invoice->get_currency() ); |
|
167 | + if ($currency) { |
|
168 | + return wpinv_price($tax, $invoice->get_currency()); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | return $tax; |
@@ -174,12 +174,12 @@ discard block |
||
174 | 174 | /** |
175 | 175 | * @deprecated |
176 | 176 | */ |
177 | -function wpinv_discount( $invoice = 0, $currency = false ) { |
|
178 | - $invoice = new WPInv_Invoice( $invoice ); |
|
177 | +function wpinv_discount($invoice = 0, $currency = false) { |
|
178 | + $invoice = new WPInv_Invoice($invoice); |
|
179 | 179 | $discount = $invoice->get_total_discount(); |
180 | 180 | |
181 | - if ( $currency ) { |
|
182 | - return wpinv_price( $discount, $invoice->get_currency() ); |
|
181 | + if ($currency) { |
|
182 | + return wpinv_price($discount, $invoice->get_currency()); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | return $discount; |
@@ -188,20 +188,20 @@ discard block |
||
188 | 188 | /** |
189 | 189 | * @deprecated |
190 | 190 | */ |
191 | -function wpinv_discount_code( $invoice = 0 ) { |
|
192 | - $invoice = new WPInv_Invoice( $invoice ); |
|
191 | +function wpinv_discount_code($invoice = 0) { |
|
192 | + $invoice = new WPInv_Invoice($invoice); |
|
193 | 193 | return $invoice->get_discount_code(); |
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
197 | 197 | * @deprecated |
198 | 198 | */ |
199 | -function wpinv_payment_total( $invoice = 0, $currency = false ) { |
|
200 | - $invoice = new WPInv_Invoice( $invoice ); |
|
199 | +function wpinv_payment_total($invoice = 0, $currency = false) { |
|
200 | + $invoice = new WPInv_Invoice($invoice); |
|
201 | 201 | $total = $invoice->get_total(); |
202 | 202 | |
203 | - if ( $currency ) { |
|
204 | - return wpinv_price( $total, $invoice->get_currency() ); |
|
203 | + if ($currency) { |
|
204 | + return wpinv_price($total, $invoice->get_currency()); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | return $total; |
@@ -210,51 +210,51 @@ discard block |
||
210 | 210 | /** |
211 | 211 | * @deprecated |
212 | 212 | */ |
213 | -function wpinv_get_date_created( $invoice = 0, $format = '' ) { |
|
214 | - $invoice = new WPInv_Invoice( $invoice ); |
|
213 | +function wpinv_get_date_created($invoice = 0, $format = '') { |
|
214 | + $invoice = new WPInv_Invoice($invoice); |
|
215 | 215 | |
216 | - $format = ! empty( $format ) ? $format : get_option( 'date_format' ); |
|
216 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
217 | 217 | $date_created = $invoice->get_created_date(); |
218 | 218 | |
219 | - return empty( $date_created ) ? date_i18n( $format, strtotime( $date_created ) ) : ''; |
|
219 | + return empty($date_created) ? date_i18n($format, strtotime($date_created)) : ''; |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
223 | 223 | * @deprecated |
224 | 224 | */ |
225 | -function wpinv_get_invoice_date( $invoice = 0, $format = '' ) { |
|
226 | - wpinv_get_date_created( $invoice, $format ); |
|
225 | +function wpinv_get_invoice_date($invoice = 0, $format = '') { |
|
226 | + wpinv_get_date_created($invoice, $format); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
230 | 230 | * @deprecated |
231 | 231 | */ |
232 | -function wpinv_get_invoice_vat_number( $invoice = 0 ) { |
|
233 | - $invoice = new WPInv_Invoice( $invoice ); |
|
232 | +function wpinv_get_invoice_vat_number($invoice = 0) { |
|
233 | + $invoice = new WPInv_Invoice($invoice); |
|
234 | 234 | return $invoice->get_vat_number(); |
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
238 | 238 | * @deprecated |
239 | 239 | */ |
240 | -function wpinv_insert_payment_note( $invoice = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) { |
|
241 | - $invoice = new WPInv_Invoice( $invoice ); |
|
242 | - return $invoice->add_note( $note, $user_type, $added_by_user, $system ); |
|
240 | +function wpinv_insert_payment_note($invoice = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) { |
|
241 | + $invoice = new WPInv_Invoice($invoice); |
|
242 | + return $invoice->add_note($note, $user_type, $added_by_user, $system); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
246 | 246 | * @deprecated |
247 | 247 | */ |
248 | -function wpinv_get_payment_key( $invoice = 0 ) { |
|
249 | - $invoice = new WPInv_Invoice( $invoice ); |
|
248 | +function wpinv_get_payment_key($invoice = 0) { |
|
249 | + $invoice = new WPInv_Invoice($invoice); |
|
250 | 250 | return $invoice->get_key(); |
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
254 | 254 | * @deprecated |
255 | 255 | */ |
256 | -function wpinv_get_invoice_number( $invoice = 0 ) { |
|
257 | - $invoice = new WPInv_Invoice( $invoice ); |
|
256 | +function wpinv_get_invoice_number($invoice = 0) { |
|
257 | + $invoice = new WPInv_Invoice($invoice); |
|
258 | 258 | return $invoice->get_number(); |
259 | 259 | } |
260 | 260 | |
@@ -401,9 +401,9 @@ discard block |
||
401 | 401 | /** |
402 | 402 | * @deprecated |
403 | 403 | */ |
404 | -function wpinv_update_payment_status( $invoice, $new_status = 'publish' ) { |
|
405 | - $invoice = new WPInv_Invoice( $invoice ); |
|
406 | - return $invoice->update_status( $new_status ); |
|
404 | +function wpinv_update_payment_status($invoice, $new_status = 'publish') { |
|
405 | + $invoice = new WPInv_Invoice($invoice); |
|
406 | + return $invoice->update_status($new_status); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
@@ -456,22 +456,22 @@ discard block |
||
456 | 456 | /** |
457 | 457 | * @deprecated |
458 | 458 | */ |
459 | -function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) { |
|
459 | +function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') { |
|
460 | 460 | |
461 | 461 | // Fetch the invoice. |
462 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
462 | + $invoice = new WPInv_Invoice($invoice_id); |
|
463 | 463 | |
464 | - if ( 0 == $invoice->get_id() ) { |
|
464 | + if (0 == $invoice->get_id()) { |
|
465 | 465 | return false; |
466 | 466 | } |
467 | 467 | |
468 | 468 | // Prepare the transaction id. |
469 | - if ( empty( $transaction_id ) ) { |
|
469 | + if (empty($transaction_id)) { |
|
470 | 470 | $transaction_id = $invoice_id; |
471 | 471 | } |
472 | 472 | |
473 | 473 | // Set the transaction id; |
474 | - $invoice->set_transaction_id( apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice ) ); |
|
474 | + $invoice->set_transaction_id(apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice)); |
|
475 | 475 | |
476 | 476 | // Save the invoice. |
477 | 477 | return $invoice->save(); |
@@ -484,12 +484,12 @@ discard block |
||
484 | 484 | * @param WPInv_Invoice $invoice |
485 | 485 | * @param string $gateway |
486 | 486 | */ |
487 | -function wpinv_send_to_gateway( $gateway, $invoice ) { |
|
487 | +function wpinv_send_to_gateway($gateway, $invoice) { |
|
488 | 488 | |
489 | 489 | $payment_data = array( |
490 | 490 | 'invoice_id' => $invoice->get_id(), |
491 | 491 | 'items' => $invoice->get_cart_details(), |
492 | - 'cart_discounts' => array( $invoice->get_discount_code() ), |
|
492 | + 'cart_discounts' => array($invoice->get_discount_code()), |
|
493 | 493 | 'fees' => $invoice->get_total_fees(), |
494 | 494 | 'subtotal' => $invoice->get_subtotal(), |
495 | 495 | 'discount' => $invoice->get_total_discount(), |
@@ -497,16 +497,16 @@ discard block |
||
497 | 497 | 'price' => $invoice->get_total(), |
498 | 498 | 'invoice_key' => $invoice->get_key(), |
499 | 499 | 'user_email' => $invoice->get_email(), |
500 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
500 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
501 | 501 | 'user_info' => $invoice->get_user_info(), |
502 | - 'post_data' => wp_kses_post( wp_unslash( $_POST ) ), |
|
502 | + 'post_data' => wp_kses_post(wp_unslash($_POST)), |
|
503 | 503 | 'cart_details' => $invoice->get_cart_details(), |
504 | 504 | 'gateway' => $gateway, |
505 | 505 | 'card_info' => array(), |
506 | - 'gateway_nonce' => wp_create_nonce( 'wpi-gateway' ), |
|
506 | + 'gateway_nonce' => wp_create_nonce('wpi-gateway'), |
|
507 | 507 | ); |
508 | 508 | |
509 | - do_action( 'wpinv_gateway_' . $gateway, $payment_data ); |
|
509 | + do_action('wpinv_gateway_' . $gateway, $payment_data); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | /** |
@@ -519,10 +519,10 @@ discard block |
||
519 | 519 | /** |
520 | 520 | * @deprecated |
521 | 521 | */ |
522 | -function wpinv_die( $message = '', $title = '', $status = 400 ) { |
|
523 | - add_filter( 'wp_die_ajax_handler', 'wpinv_die_handler', 10, 3 ); |
|
524 | - add_filter( 'wp_die_handler', 'wpinv_die_handler', 10, 3 ); |
|
525 | - wp_die( esc_html( $message ), esc_html( $title ), array( 'response' => (int) $status ) ); |
|
522 | +function wpinv_die($message = '', $title = '', $status = 400) { |
|
523 | + add_filter('wp_die_ajax_handler', 'wpinv_die_handler', 10, 3); |
|
524 | + add_filter('wp_die_handler', 'wpinv_die_handler', 10, 3); |
|
525 | + wp_die(esc_html($message), esc_html($title), array('response' => (int) $status)); |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | /** |
@@ -640,14 +640,14 @@ discard block |
||
640 | 640 | /** |
641 | 641 | * @deprecated |
642 | 642 | */ |
643 | -function wpinv_invoice_status_label( $status, $status_display = '' ) { |
|
644 | - return empty( $status_display ) ? sanitize_text_field( $status ) : sanitize_text_field( $status_display ); |
|
643 | +function wpinv_invoice_status_label($status, $status_display = '') { |
|
644 | + return empty($status_display) ? sanitize_text_field($status) : sanitize_text_field($status_display); |
|
645 | 645 | } |
646 | 646 | |
647 | 647 | /** |
648 | 648 | * @deprecated |
649 | 649 | */ |
650 | -function wpinv_clean_invoice_number( $number ) { |
|
650 | +function wpinv_clean_invoice_number($number) { |
|
651 | 651 | return $number; |
652 | 652 | } |
653 | 653 | |
@@ -852,12 +852,12 @@ discard block |
||
852 | 852 | /** |
853 | 853 | * @deprecated |
854 | 854 | */ |
855 | -function wpinv_item_show_price( $item_id = 0, $echo = true ) { |
|
855 | +function wpinv_item_show_price($item_id = 0, $echo = true) { |
|
856 | 856 | |
857 | - if ( $echo ) { |
|
858 | - echo wp_kses_post( wpinv_item_price( $item_id ) ); |
|
857 | + if ($echo) { |
|
858 | + echo wp_kses_post(wpinv_item_price($item_id)); |
|
859 | 859 | } else { |
860 | - return wpinv_item_price( $item_id ); |
|
860 | + return wpinv_item_price($item_id); |
|
861 | 861 | } |
862 | 862 | |
863 | 863 | } |
@@ -1272,6 +1272,6 @@ discard block |
||
1272 | 1272 | * @return WPInv_Subscription|bool |
1273 | 1273 | * @deprecated |
1274 | 1274 | */ |
1275 | -function wpinv_get_subscription( $invoice ) { |
|
1276 | - return wpinv_get_invoice_subscription( $invoice ); |
|
1275 | +function wpinv_get_subscription($invoice) { |
|
1276 | + return wpinv_get_invoice_subscription($invoice); |
|
1277 | 1277 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Reports Class. |
@@ -17,11 +17,11 @@ discard block |
||
17 | 17 | * |
18 | 18 | */ |
19 | 19 | public function __construct() { |
20 | - add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 ); |
|
21 | - add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) ); |
|
22 | - add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) ); |
|
23 | - add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) ); |
|
24 | - add_action( 'getpaid_authenticated_admin_action_export_invoices', array( $this, 'export_invoices' ) ); |
|
20 | + add_action('admin_menu', array($this, 'register_reports_page'), 20); |
|
21 | + add_action('wpinv_reports_tab_reports', array($this, 'display_reports_tab')); |
|
22 | + add_action('wpinv_reports_tab_export', array($this, 'display_exports_tab')); |
|
23 | + add_action('getpaid_authenticated_admin_action_download_graph', array($this, 'download_graph')); |
|
24 | + add_action('getpaid_authenticated_admin_action_export_invoices', array($this, 'export_invoices')); |
|
25 | 25 | |
26 | 26 | } |
27 | 27 | |
@@ -33,11 +33,11 @@ discard block |
||
33 | 33 | |
34 | 34 | add_submenu_page( |
35 | 35 | 'wpinv', |
36 | - __( 'Reports', 'invoicing' ), |
|
37 | - __( 'Reports', 'invoicing' ), |
|
36 | + __('Reports', 'invoicing'), |
|
37 | + __('Reports', 'invoicing'), |
|
38 | 38 | wpinv_get_capability(), |
39 | 39 | 'wpinv-reports', |
40 | - array( $this, 'display_reports_page' ) |
|
40 | + array($this, 'display_reports_page') |
|
41 | 41 | ); |
42 | 42 | |
43 | 43 | } |
@@ -50,46 +50,46 @@ discard block |
||
50 | 50 | |
51 | 51 | // Prepare variables. |
52 | 52 | $tabs = $this->get_tabs(); |
53 | - $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports'; |
|
54 | - $current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports'; |
|
53 | + $current_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'reports'; |
|
54 | + $current_tab = array_key_exists($current_tab, $tabs) ? $current_tab : 'reports'; |
|
55 | 55 | |
56 | 56 | // Display the current tab. |
57 | 57 | ?> |
58 | 58 | |
59 | 59 | <div class="wrap"> |
60 | 60 | |
61 | - <h1><?php echo esc_html( $tabs[ $current_tab ] ); ?></h1> |
|
61 | + <h1><?php echo esc_html($tabs[$current_tab]); ?></h1> |
|
62 | 62 | |
63 | 63 | <nav class="nav-tab-wrapper"> |
64 | 64 | |
65 | 65 | <?php |
66 | - foreach ( $tabs as $key => $label ) { |
|
66 | + foreach ($tabs as $key => $label) { |
|
67 | 67 | |
68 | - $key = sanitize_key( $key ); |
|
69 | - $label = esc_html( $label ); |
|
68 | + $key = sanitize_key($key); |
|
69 | + $label = esc_html($label); |
|
70 | 70 | $class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab'; |
71 | 71 | $url = esc_url( |
72 | - add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) ) |
|
72 | + add_query_arg('tab', $key, admin_url('admin.php?page=wpinv-reports')) |
|
73 | 73 | ); |
74 | 74 | |
75 | - echo wp_kses_post( "\n\t\t\t<a href='$url' class='" . $class . "'>$label</a>" ); |
|
75 | + echo wp_kses_post("\n\t\t\t<a href='$url' class='" . $class . "'>$label</a>"); |
|
76 | 76 | |
77 | 77 | } |
78 | 78 | ?> |
79 | 79 | |
80 | 80 | </nav> |
81 | 81 | |
82 | - <div class="bsui <?php echo esc_attr( $current_tab ); ?>"> |
|
83 | - <?php do_action( "wpinv_reports_tab_{$current_tab}" ); ?> |
|
82 | + <div class="bsui <?php echo esc_attr($current_tab); ?>"> |
|
83 | + <?php do_action("wpinv_reports_tab_{$current_tab}"); ?> |
|
84 | 84 | </div> |
85 | 85 | |
86 | 86 | </div> |
87 | 87 | <?php |
88 | 88 | |
89 | 89 | // Wordfence loads an unsupported version of chart js on our page. |
90 | - wp_deregister_style( 'chart-js' ); |
|
91 | - wp_deregister_script( 'chart-js' ); |
|
92 | - wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.min.js', array( 'jquery' ), '3.7.1', true ); |
|
90 | + wp_deregister_style('chart-js'); |
|
91 | + wp_deregister_script('chart-js'); |
|
92 | + wp_enqueue_script('chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.min.js', array('jquery'), '3.7.1', true); |
|
93 | 93 | |
94 | 94 | } |
95 | 95 | |
@@ -101,11 +101,11 @@ discard block |
||
101 | 101 | public function get_tabs() { |
102 | 102 | |
103 | 103 | $tabs = array( |
104 | - 'reports' => __( 'Reports', 'invoicing' ), |
|
105 | - 'export' => __( 'Export', 'invoicing' ), |
|
104 | + 'reports' => __('Reports', 'invoicing'), |
|
105 | + 'export' => __('Export', 'invoicing'), |
|
106 | 106 | ); |
107 | 107 | |
108 | - return apply_filters( 'getpaid_report_tabs', $tabs ); |
|
108 | + return apply_filters('getpaid_report_tabs', $tabs); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -135,11 +135,11 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @param array $args |
137 | 137 | */ |
138 | - public function download_graph( $args ) { |
|
138 | + public function download_graph($args) { |
|
139 | 139 | |
140 | - if ( ! empty( $args['graph'] ) ) { |
|
140 | + if (!empty($args['graph'])) { |
|
141 | 141 | $downloader = new GetPaid_Graph_Downloader(); |
142 | - $downloader->download( $args['graph'] ); |
|
142 | + $downloader->download($args['graph']); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | } |
@@ -149,17 +149,17 @@ discard block |
||
149 | 149 | * |
150 | 150 | * @param array $args |
151 | 151 | */ |
152 | - public function export_invoices( $args ) { |
|
152 | + public function export_invoices($args) { |
|
153 | 153 | |
154 | - if ( ! empty( $args['post_type'] ) ) { |
|
154 | + if (!empty($args['post_type'])) { |
|
155 | 155 | |
156 | - if ( 'subscriptions' === $args['post_type'] ) { |
|
156 | + if ('subscriptions' === $args['post_type']) { |
|
157 | 157 | $downloader = new GetPaid_Subscription_Exporter(); |
158 | 158 | } else { |
159 | 159 | $downloader = new GetPaid_Invoice_Exporter(); |
160 | 160 | } |
161 | 161 | |
162 | - $downloader->export( $args['post_type'], $args ); |
|
162 | + $downloader->export($args['post_type'], $args); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Graph_Downloader Class. |
@@ -30,13 +30,13 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts |
32 | 32 | */ |
33 | - public function prepare_handler( $graph ) { |
|
33 | + public function prepare_handler($graph) { |
|
34 | 34 | |
35 | - if ( empty( $this->handler->views[ $graph ] ) ) { |
|
36 | - wp_die( esc_html__( 'Invalid Graph', 'invoicing' ), 400 ); |
|
35 | + if (empty($this->handler->views[$graph])) { |
|
36 | + wp_die(esc_html__('Invalid Graph', 'invoicing'), 400); |
|
37 | 37 | } |
38 | 38 | |
39 | - return new $this->handler->views[ $graph ]['class'](); |
|
39 | + return new $this->handler->views[$graph]['class'](); |
|
40 | 40 | |
41 | 41 | } |
42 | 42 | |
@@ -47,10 +47,10 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function prepare_output() { |
49 | 49 | |
50 | - $output = fopen( 'php://output', 'w' ); |
|
50 | + $output = fopen('php://output', 'w'); |
|
51 | 51 | |
52 | - if ( false === $output ) { |
|
53 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
52 | + if (false === $output) { |
|
53 | + wp_die(esc_html__('Unsupported server', 'invoicing'), 500); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | return $output; |
@@ -61,13 +61,13 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @return string |
63 | 63 | */ |
64 | - public function prepare_file_type( $graph ) { |
|
64 | + public function prepare_file_type($graph) { |
|
65 | 65 | |
66 | - $file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] ); |
|
67 | - $file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) ); |
|
66 | + $file_type = empty($_REQUEST['file_type']) ? 'csv' : sanitize_text_field($_REQUEST['file_type']); |
|
67 | + $file_name = wpinv_sanitize_key("getpaid-$graph-" . current_time('Y-m-d')); |
|
68 | 68 | |
69 | - header( "Content-Type:application/$file_type" ); |
|
70 | - header( "Content-Disposition:attachment;filename=$file_name.$file_type" ); |
|
69 | + header("Content-Type:application/$file_type"); |
|
70 | + header("Content-Disposition:attachment;filename=$file_name.$file_type"); |
|
71 | 71 | |
72 | 72 | return $file_type; |
73 | 73 | } |
@@ -76,24 +76,24 @@ discard block |
||
76 | 76 | * Handles the actual download. |
77 | 77 | * |
78 | 78 | */ |
79 | - public function download( $graph ) { |
|
79 | + public function download($graph) { |
|
80 | 80 | global $wpdb; |
81 | 81 | |
82 | - $handler = $this->prepare_handler( $graph ); |
|
82 | + $handler = $this->prepare_handler($graph); |
|
83 | 83 | $stream = $this->prepare_output(); |
84 | - $stats = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) ); |
|
85 | - $headers = array( $handler->field, 'total', 'total_raw' ); |
|
86 | - $file_type = $this->prepare_file_type( $graph ); |
|
87 | - |
|
88 | - if ( 'csv' == $file_type ) { |
|
89 | - $this->download_csv( $stats, $stream, $headers ); |
|
90 | - } elseif ( 'xml' == $file_type ) { |
|
91 | - $this->download_xml( $stats, $stream, $headers ); |
|
84 | + $stats = $wpdb->get_results($handler->get_sql($handler->get_range())); |
|
85 | + $headers = array($handler->field, 'total', 'total_raw'); |
|
86 | + $file_type = $this->prepare_file_type($graph); |
|
87 | + |
|
88 | + if ('csv' == $file_type) { |
|
89 | + $this->download_csv($stats, $stream, $headers); |
|
90 | + } elseif ('xml' == $file_type) { |
|
91 | + $this->download_xml($stats, $stream, $headers); |
|
92 | 92 | } else { |
93 | - $this->download_json( $stats, $stream, $headers ); |
|
93 | + $this->download_json($stats, $stream, $headers); |
|
94 | 94 | } |
95 | 95 | |
96 | - fclose( $stream ); |
|
96 | + fclose($stream); |
|
97 | 97 | exit; |
98 | 98 | } |
99 | 99 | |
@@ -105,16 +105,16 @@ discard block |
||
105 | 105 | * @param array $headers The fields to stream. |
106 | 106 | * @since 1.0.19 |
107 | 107 | */ |
108 | - public function download_csv( $stats, $stream, $headers ) { |
|
108 | + public function download_csv($stats, $stream, $headers) { |
|
109 | 109 | |
110 | 110 | // Output the csv column headers. |
111 | - fputcsv( $stream, $headers ); |
|
111 | + fputcsv($stream, $headers); |
|
112 | 112 | |
113 | 113 | // Loop through |
114 | - foreach ( $stats as $stat ) { |
|
115 | - $row = array_values( $this->prepare_row( $stat, $headers ) ); |
|
116 | - $row = array_map( 'maybe_serialize', $row ); |
|
117 | - fputcsv( $stream, $row ); |
|
114 | + foreach ($stats as $stat) { |
|
115 | + $row = array_values($this->prepare_row($stat, $headers)); |
|
116 | + $row = array_map('maybe_serialize', $row); |
|
117 | + fputcsv($stream, $row); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | } |
@@ -127,16 +127,16 @@ discard block |
||
127 | 127 | * @param array $headers The fields to stream. |
128 | 128 | * @since 1.0.19 |
129 | 129 | */ |
130 | - public function download_json( $stats, $stream, $headers ) { |
|
130 | + public function download_json($stats, $stream, $headers) { |
|
131 | 131 | |
132 | 132 | $prepared = array(); |
133 | 133 | |
134 | 134 | // Loop through |
135 | - foreach ( $stats as $stat ) { |
|
136 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
135 | + foreach ($stats as $stat) { |
|
136 | + $prepared[] = $this->prepare_row($stat, $headers); |
|
137 | 137 | } |
138 | 138 | |
139 | - fwrite( $stream, wp_json_encode( $prepared ) ); |
|
139 | + fwrite($stream, wp_json_encode($prepared)); |
|
140 | 140 | |
141 | 141 | } |
142 | 142 | |
@@ -148,19 +148,19 @@ discard block |
||
148 | 148 | * @param array $headers The fields to stream. |
149 | 149 | * @since 1.0.19 |
150 | 150 | */ |
151 | - public function download_xml( $stats, $stream, $headers ) { |
|
151 | + public function download_xml($stats, $stream, $headers) { |
|
152 | 152 | |
153 | 153 | $prepared = array(); |
154 | 154 | |
155 | 155 | // Loop through |
156 | - foreach ( $stats as $stat ) { |
|
157 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
156 | + foreach ($stats as $stat) { |
|
157 | + $prepared[] = $this->prepare_row($stat, $headers); |
|
158 | 158 | } |
159 | 159 | |
160 | - $xml = new SimpleXMLElement( '<?xml version="1.0"?><data></data>' ); |
|
161 | - $this->convert_array_xml( $prepared, $xml ); |
|
160 | + $xml = new SimpleXMLElement('<?xml version="1.0"?><data></data>'); |
|
161 | + $this->convert_array_xml($prepared, $xml); |
|
162 | 162 | |
163 | - fwrite( $stream, $xml->asXML() ); |
|
163 | + fwrite($stream, $xml->asXML()); |
|
164 | 164 | |
165 | 165 | } |
166 | 166 | |
@@ -170,24 +170,24 @@ discard block |
||
170 | 170 | * @access public |
171 | 171 | * @since 1.0.19 |
172 | 172 | */ |
173 | - public function convert_array_xml( $data, $xml ) { |
|
173 | + public function convert_array_xml($data, $xml) { |
|
174 | 174 | |
175 | 175 | // Loop through |
176 | - foreach ( $data as $key => $value ) { |
|
176 | + foreach ($data as $key => $value) { |
|
177 | 177 | |
178 | - $key = preg_replace( '/[^A-Za-z0-9_\-]/', '', $key ); |
|
178 | + $key = preg_replace('/[^A-Za-z0-9_\-]/', '', $key); |
|
179 | 179 | |
180 | - if ( is_array( $value ) ) { |
|
180 | + if (is_array($value)) { |
|
181 | 181 | |
182 | - if ( is_numeric( $key ) ) { |
|
182 | + if (is_numeric($key)) { |
|
183 | 183 | $key = 'item' . $key; //dealing with <0/>..<n/> issues |
184 | 184 | } |
185 | 185 | |
186 | - $subnode = $xml->addChild( $key ); |
|
187 | - $this->convert_array_xml( $value, $subnode ); |
|
186 | + $subnode = $xml->addChild($key); |
|
187 | + $this->convert_array_xml($value, $subnode); |
|
188 | 188 | |
189 | 189 | } else { |
190 | - $xml->addChild( $key, htmlspecialchars( $value ) ); |
|
190 | + $xml->addChild($key, htmlspecialchars($value)); |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
@@ -201,24 +201,24 @@ discard block |
||
201 | 201 | * @since 1.0.19 |
202 | 202 | * @return array |
203 | 203 | */ |
204 | - public function prepare_row( $row, $fields ) { |
|
204 | + public function prepare_row($row, $fields) { |
|
205 | 205 | |
206 | 206 | $prepared = array(); |
207 | 207 | $row = (array) $row; |
208 | 208 | |
209 | - foreach ( $fields as $field ) { |
|
209 | + foreach ($fields as $field) { |
|
210 | 210 | |
211 | - if ( $field === 'total' ) { |
|
212 | - $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES ); |
|
211 | + if ($field === 'total') { |
|
212 | + $prepared[$field] = html_entity_decode(strip_tags(wpinv_price($row['total'])), ENT_QUOTES); |
|
213 | 213 | continue; |
214 | 214 | } |
215 | 215 | |
216 | - if ( $field === 'total_raw' ) { |
|
217 | - $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) ); |
|
216 | + if ($field === 'total_raw') { |
|
217 | + $prepared[$field] = wpinv_round_amount(wpinv_sanitize_amount($row['total'])); |
|
218 | 218 | continue; |
219 | 219 | } |
220 | 220 | |
221 | - $prepared[ $field ] = strip_tags( $row[ $field ] ); |
|
221 | + $prepared[$field] = strip_tags($row[$field]); |
|
222 | 222 | |
223 | 223 | } |
224 | 224 |
@@ -3,27 +3,27 @@ discard block |
||
3 | 3 | * Admin View: Page - Addons |
4 | 4 | * |
5 | 5 | */ |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | add_ThickBox(); |
10 | 10 | ?> |
11 | 11 | <div class="wrap wpi_addons_wrap"> |
12 | - <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
|
12 | + <h1><?php echo esc_html(get_admin_page_title()); ?></h1> |
|
13 | 13 | |
14 | - <?php if ( $tabs ) { ?> |
|
14 | + <?php if ($tabs) { ?> |
|
15 | 15 | <nav class="nav-tab-wrapper wpi-nav-tab-wrapper"> |
16 | 16 | <?php |
17 | - foreach ( $tabs as $name => $label ) { |
|
18 | - echo '<a href="' . esc_url( admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . esc_html( $label ) . '</a>'; |
|
17 | + foreach ($tabs as $name => $label) { |
|
18 | + echo '<a href="' . esc_url(admin_url('admin.php?page=wpi-addons&tab=' . $name)) . '" class="nav-tab ' . ($current_tab == $name ? 'nav-tab-active' : '') . '">' . esc_html($label) . '</a>'; |
|
19 | 19 | } |
20 | - do_action( 'wpi_addons_tabs' ); |
|
20 | + do_action('wpi_addons_tabs'); |
|
21 | 21 | ?> |
22 | 22 | </nav> |
23 | 23 | |
24 | 24 | <?php |
25 | 25 | |
26 | - if ( $current_tab == 'membership' ) { |
|
26 | + if ($current_tab == 'membership') { |
|
27 | 27 | |
28 | 28 | ?> |
29 | 29 | |
@@ -32,42 +32,42 @@ discard block |
||
32 | 32 | <!-- |
33 | 33 | <h2>With our WPInvoicing Membership you get access to all our products!</h2> |
34 | 34 | <p><a class="button button-primary" href="https://wpinvoicing.com/downloads/membership/">View Memberships</a></p>--> |
35 | - <?php if ( defined( 'WP_EASY_UPDATES_ACTIVE' ) ) { ?> |
|
36 | - <h2><?php esc_html_e( 'Have a membership key?', 'invoicing' ); ?></h2> |
|
35 | + <?php if (defined('WP_EASY_UPDATES_ACTIVE')) { ?> |
|
36 | + <h2><?php esc_html_e('Have a membership key?', 'invoicing'); ?></h2> |
|
37 | 37 | <p> |
38 | 38 | <?php |
39 | - $wpeu_admin = new External_Updates_Admin( 'wpinvoicing.com', '1' ); |
|
40 | - echo wp_kses_post( $wpeu_admin->render_licence_actions( 'wpinvoicing.com', 'membership', array( 95, 106, 108, 12351 ) ) ); |
|
39 | + $wpeu_admin = new External_Updates_Admin('wpinvoicing.com', '1'); |
|
40 | + echo wp_kses_post($wpeu_admin->render_licence_actions('wpinvoicing.com', 'membership', array(95, 106, 108, 12351))); |
|
41 | 41 | ?> |
42 | 42 | </p> |
43 | 43 | <?php } ?> |
44 | 44 | |
45 | 45 | <div class="membership-cta-contet"> |
46 | 46 | <div class="main-cta"> |
47 | - <h2><?php esc_html_e( 'Membership benefits Include:', 'invoicing' ); ?></h2> |
|
47 | + <h2><?php esc_html_e('Membership benefits Include:', 'invoicing'); ?></h2> |
|
48 | 48 | <div class="feature-list"> |
49 | 49 | <ul> |
50 | 50 | <?php |
51 | 51 | $addon_obj = new WPInv_Admin_Addons(); |
52 | - if ( $addons = $addon_obj->get_section_data( 'addons' ) ) { |
|
53 | - foreach ( $addons as $addon ) { |
|
54 | - echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html( $addon->info->title ) . '</li>'; |
|
52 | + if ($addons = $addon_obj->get_section_data('addons')) { |
|
53 | + foreach ($addons as $addon) { |
|
54 | + echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html($addon->info->title) . '</li>'; |
|
55 | 55 | } |
56 | 56 | } |
57 | 57 | ?> |
58 | 58 | </ul> |
59 | 59 | |
60 | 60 | <div class="feature-cta"> |
61 | - <h3><?php esc_html_e( 'Membership Starts from', 'invoicing' ); ?></h3> |
|
61 | + <h3><?php esc_html_e('Membership Starts from', 'invoicing'); ?></h3> |
|
62 | 62 | <h4>$99</h4> |
63 | - <a href="https://wpinvoicing.com/downloads/membership/" target="_blank"><?php esc_attr_e( 'Buy Membership', 'invoicing' ); ?></a> |
|
63 | + <a href="https://wpinvoicing.com/downloads/membership/" target="_blank"><?php esc_attr_e('Buy Membership', 'invoicing'); ?></a> |
|
64 | 64 | </div> |
65 | - <h3><?php esc_html_e( 'Included Gateways:', 'invoicing' ); ?></h3> |
|
65 | + <h3><?php esc_html_e('Included Gateways:', 'invoicing'); ?></h3> |
|
66 | 66 | <ul> |
67 | 67 | <?php |
68 | - if ( $addons = $addon_obj->get_section_data( 'gateways' ) ) { |
|
69 | - foreach ( $addons as $addon ) { |
|
70 | - echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html( $addon->info->title ) . '</li>'; |
|
68 | + if ($addons = $addon_obj->get_section_data('gateways')) { |
|
69 | + foreach ($addons as $addon) { |
|
70 | + echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html($addon->info->title) . '</li>'; |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | ?> |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | <div class="testimonial-content"> |
82 | 82 | <div class="t-image"> |
83 | 83 | <?php |
84 | - echo '<img src="' . esc_url( plugins_url( 'images/t-image2.png', dirname( __FILE__ ) ) ) . '" > '; |
|
84 | + echo '<img src="' . esc_url(plugins_url('images/t-image2.png', dirname(__FILE__))) . '" > '; |
|
85 | 85 | ?> |
86 | 86 | </div> |
87 | 87 | <div class="t-content"> |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | <div class="testimonial-content"> |
102 | 102 | <div class="t-image"> |
103 | 103 | <?php |
104 | - echo '<img src="' . esc_url( plugins_url( 'images/t-image1.png', dirname( __FILE__ ) ) ) . '" > '; |
|
104 | + echo '<img src="' . esc_url(plugins_url('images/t-image1.png', dirname(__FILE__))) . '" > '; |
|
105 | 105 | ?> |
106 | 106 | </div> |
107 | 107 | <div class="t-content"> |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | </div> |
118 | 118 | </div> |
119 | 119 | <div class="member-footer"> |
120 | - <a class="footer-btn" href="https://wpinvoicing.com/downloads/membership/" target="_blank"><?php esc_html_e( 'Buy Membership', 'invoicing' ); ?></a> |
|
121 | - <a class="footer-link" href="post-new.php?post_type=wpi_invoice"><?php esc_html_e( 'Create Invoice', 'invoicing' ); ?></a> |
|
120 | + <a class="footer-btn" href="https://wpinvoicing.com/downloads/membership/" target="_blank"><?php esc_html_e('Buy Membership', 'invoicing'); ?></a> |
|
121 | + <a class="footer-link" href="post-new.php?post_type=wpi_invoice"><?php esc_html_e('Create Invoice', 'invoicing'); ?></a> |
|
122 | 122 | </div> |
123 | 123 | </div> |
124 | 124 | |
@@ -129,55 +129,55 @@ discard block |
||
129 | 129 | } else { |
130 | 130 | $installed_plugins = get_plugins(); |
131 | 131 | $addon_obj = new WPInv_Admin_Addons(); |
132 | - if ( $addons = $addon_obj->get_section_data( $current_tab ) ) : |
|
132 | + if ($addons = $addon_obj->get_section_data($current_tab)) : |
|
133 | 133 | //print_r($addons); |
134 | 134 | ?> |
135 | 135 | <ul class="wpi-products"> |
136 | 136 | <?php |
137 | - foreach ( $addons as $addon ) : |
|
138 | - if ( 965 == $addon->info->id ) { |
|
139 | -continue;}// don't show quote add on |
|
137 | + foreach ($addons as $addon) : |
|
138 | + if (965 == $addon->info->id) { |
|
139 | +continue; }// don't show quote add on |
|
140 | 140 | ?> |
141 | 141 | <li class="wpi-product"> |
142 | 142 | <div class="wpi-product-title"> |
143 | 143 | <h3> |
144 | 144 | <?php |
145 | - if ( ! empty( $addon->info->excerpt ) ) { |
|
146 | - wpi_help_tip( $addon->info->excerpt, false, false, true ); |
|
145 | + if (!empty($addon->info->excerpt)) { |
|
146 | + wpi_help_tip($addon->info->excerpt, false, false, true); |
|
147 | 147 | } |
148 | - echo esc_html( $addon->info->title ); |
|
148 | + echo esc_html($addon->info->title); |
|
149 | 149 | ?> |
150 | 150 | </h3> |
151 | 151 | </div> |
152 | 152 | |
153 | 153 | <span class="wpi-product-image"> |
154 | - <?php if ( ! empty( $addon->info->thumbnail ) ) : ?> |
|
155 | - <img src="<?php echo esc_attr( $addon->info->thumbnail ); ?>"/> |
|
154 | + <?php if (!empty($addon->info->thumbnail)) : ?> |
|
155 | + <img src="<?php echo esc_attr($addon->info->thumbnail); ?>"/> |
|
156 | 156 | <?php |
157 | 157 | endif; |
158 | 158 | |
159 | - if ( 'stripe-payment-gateway' == $addon->info->slug ) { |
|
159 | + if ('stripe-payment-gateway' == $addon->info->slug) { |
|
160 | 160 | $addon->info->slug = 'getpaid-stripe-payments'; |
161 | 161 | $addon->info->link = 'https://wordpress.org/plugins/getpaid-stripe-payments/'; |
162 | 162 | } |
163 | 163 | |
164 | - if ( isset( $addon->info->link ) && substr( $addon->info->link, 0, 21 ) === 'https://wordpress.org' ) { |
|
165 | - echo '<a href="' . esc_url( admin_url( '/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug ) ) . '&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
|
166 | - echo '<span class="wpi-product-info">' . esc_html__( 'More info', 'invoicing' ) . '</span>'; |
|
164 | + if (isset($addon->info->link) && substr($addon->info->link, 0, 21) === 'https://wordpress.org') { |
|
165 | + echo '<a href="' . esc_url(admin_url('/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug)) . '&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
|
166 | + echo '<span class="wpi-product-info">' . esc_html__('More info', 'invoicing') . '</span>'; |
|
167 | 167 | echo '</a>'; |
168 | - } elseif ( isset( $addon->info->link ) && ( substr( $addon->info->link, 0, 23 ) === 'https://wpinvoicing.com' || substr( $addon->info->link, 0, 21 ) === 'https://wpgetpaid.com' ) ) { |
|
169 | - if ( defined( 'WP_EASY_UPDATES_ACTIVE' ) ) { |
|
170 | - $url = admin_url( '/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug . '&width=770&height=660&item_id=' . $addon->info->id . '&update_url=https://wpgetpaid.com&TB_iframe=true' ); |
|
168 | + } elseif (isset($addon->info->link) && (substr($addon->info->link, 0, 23) === 'https://wpinvoicing.com' || substr($addon->info->link, 0, 21) === 'https://wpgetpaid.com')) { |
|
169 | + if (defined('WP_EASY_UPDATES_ACTIVE')) { |
|
170 | + $url = admin_url('/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug . '&width=770&height=660&item_id=' . $addon->info->id . '&update_url=https://wpgetpaid.com&TB_iframe=true'); |
|
171 | 171 | } else { |
172 | 172 | // if installed show activation link |
173 | - if ( isset( $installed_plugins['wp-easy-updates/external-updates.php'] ) ) { |
|
173 | + if (isset($installed_plugins['wp-easy-updates/external-updates.php'])) { |
|
174 | 174 | $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation'; |
175 | 175 | } else { |
176 | 176 | $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external'; |
177 | 177 | } |
178 | 178 | } |
179 | - echo '<a href="' . esc_url( $url ) . '" class="thickbox">'; |
|
180 | - echo '<span class="wpi-product-info">' . esc_html__( 'More info', 'invoicing' ) . '</span>'; |
|
179 | + echo '<a href="' . esc_url($url) . '" class="thickbox">'; |
|
180 | + echo '<span class="wpi-product-info">' . esc_html__('More info', 'invoicing') . '</span>'; |
|
181 | 181 | echo '</a>'; |
182 | 182 | } |
183 | 183 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | |
189 | 189 | <span class="wpi-product-button"> |
190 | 190 | <?php |
191 | - $addon_obj->output_button( $addon ); |
|
191 | + $addon_obj->output_button($addon); |
|
192 | 192 | ?> |
193 | 193 | </span> |
194 | 194 | |
@@ -202,21 +202,21 @@ discard block |
||
202 | 202 | |
203 | 203 | <div class="clearfix" ></div> |
204 | 204 | |
205 | - <?php if ( $current_tab == 'addons' ) { ?> |
|
206 | - <p><?php printf( esc_attr__( 'All of our Addons can be found on wpGetPaid.com here: %sInvoicing Addons%s', 'invoicing' ), '<a href="https://wpinvoicing.com/downloads/category/addons/">','</a>' ); ?></p> |
|
207 | - <?php } if ( $current_tab == 'gateways' ) { ?> |
|
208 | - <p><?php printf( esc_attr__( 'All of our Payment Gateways can be found on wpGetPaid.com here: %sGetPaid Payment Gateways %s', 'invoicing' ), '<a href="https://wpinvoicing.com/downloads/category/gateways/">','</a>' ); ?></p> |
|
205 | + <?php if ($current_tab == 'addons') { ?> |
|
206 | + <p><?php printf(esc_attr__('All of our Addons can be found on wpGetPaid.com here: %sInvoicing Addons%s', 'invoicing'), '<a href="https://wpinvoicing.com/downloads/category/addons/">', '</a>'); ?></p> |
|
207 | + <?php } if ($current_tab == 'gateways') { ?> |
|
208 | + <p><?php printf(esc_attr__('All of our Payment Gateways can be found on wpGetPaid.com here: %sGetPaid Payment Gateways %s', 'invoicing'), '<a href="https://wpinvoicing.com/downloads/category/gateways/">', '</a>'); ?></p> |
|
209 | 209 | <?php } ?> |
210 | 210 | |
211 | - <div id="wpi-wpeu-required-activation" style="display:none;"><span class="wpi-notification "><?php echo wp_kses_post( sprintf( __( "The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s'>activate</a> it now.", 'invoicing' ), wp_nonce_url( admin_url( 'plugins.php?action=activate&plugin=wp-easy-updates/external-updates.php' ), 'activate-plugin_wp-easy-updates/external-updates.php' ) ) ); ?></span></div> |
|
212 | - <div id="wpi-wpeu-required-for-external" style="display:none;"><span class="wpi-notification "><?php echo wp_kses_post( sprintf( __( "The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s' onclick='window.open(\"https://wpeasyupdates.com/wp-easy-updates.zip\", \"_blank\");' >download</a> and install it now.", 'invoicing' ), admin_url( 'plugin-install.php?tab=upload&wpeu-install=true' ) ) ); ?></span></div> |
|
211 | + <div id="wpi-wpeu-required-activation" style="display:none;"><span class="wpi-notification "><?php echo wp_kses_post(sprintf(__("The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s'>activate</a> it now.", 'invoicing'), wp_nonce_url(admin_url('plugins.php?action=activate&plugin=wp-easy-updates/external-updates.php'), 'activate-plugin_wp-easy-updates/external-updates.php'))); ?></span></div> |
|
212 | + <div id="wpi-wpeu-required-for-external" style="display:none;"><span class="wpi-notification "><?php echo wp_kses_post(sprintf(__("The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s' onclick='window.open(\"https://wpeasyupdates.com/wp-easy-updates.zip\", \"_blank\");' >download</a> and install it now.", 'invoicing'), admin_url('plugin-install.php?tab=upload&wpeu-install=true'))); ?></span></div> |
|
213 | 213 | <div id="wpeu-licence-popup" style="display:none;"> |
214 | 214 | <span class="wpi-notification noti-white"> |
215 | - <h3 class="wpeu-licence-title"><?php esc_html_e( 'Licence key', 'invoicing' ); ?></h3> |
|
216 | - <input class="wpeu-licence-key" type="text" placeholder="<?php esc_attr_e( 'Enter your licence key', 'invoicing' ); ?>"> <button class="button-primary wpeu-licence-popup-button" ><?php esc_html_e( 'Install', 'invoicing' ); ?></button> |
|
215 | + <h3 class="wpeu-licence-title"><?php esc_html_e('Licence key', 'invoicing'); ?></h3> |
|
216 | + <input class="wpeu-licence-key" type="text" placeholder="<?php esc_attr_e('Enter your licence key', 'invoicing'); ?>"> <button class="button-primary wpeu-licence-popup-button" ><?php esc_html_e('Install', 'invoicing'); ?></button> |
|
217 | 217 | <br> |
218 | 218 | <?php |
219 | - printf( esc_html__( '%1$sFind your licence key here%2$s OR %3$sBuy one here%4$s', 'invoicing' ), '<a href="https://wpinvoicing.com/your-account/" target="_blank">', '</a>', '<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">', '</a>' ); |
|
219 | + printf(esc_html__('%1$sFind your licence key here%2$s OR %3$sBuy one here%4$s', 'invoicing'), '<a href="https://wpinvoicing.com/your-account/" target="_blank">', '</a>', '<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">', '</a>'); |
|
220 | 220 | ?> |
221 | 221 | </span> |
222 | 222 | </div> |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * WPInv_Ajax class. |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | * Hook in ajax handlers. |
18 | 18 | */ |
19 | 19 | public static function init() { |
20 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
20 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
21 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
22 | 22 | self::add_ajax_events(); |
23 | 23 | } |
24 | 24 | |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public static function define_ajax() { |
29 | 29 | |
30 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | - getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | - getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
30 | + if (!empty($_GET['wpinv-ajax'])) { |
|
31 | + getpaid_maybe_define_constant('DOING_AJAX', true); |
|
32 | + getpaid_maybe_define_constant('WPInv_DOING_AJAX', true); |
|
33 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
34 | + /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0); |
|
35 | 35 | } |
36 | 36 | $GLOBALS['wpdb']->hide_errors(); |
37 | 37 | } |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | * @since 1.0.18 |
45 | 45 | */ |
46 | 46 | private static function wpinv_ajax_headers() { |
47 | - if ( ! headers_sent() ) { |
|
47 | + if (!headers_sent()) { |
|
48 | 48 | send_origin_headers(); |
49 | 49 | send_nosniff_header(); |
50 | 50 | nocache_headers(); |
51 | - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | - header( 'X-Robots-Tag: noindex' ); |
|
53 | - status_header( 200 ); |
|
51 | + header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
52 | + header('X-Robots-Tag: noindex'); |
|
53 | + status_header(200); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
@@ -60,16 +60,16 @@ discard block |
||
60 | 60 | public static function do_wpinv_ajax() { |
61 | 61 | global $wp_query; |
62 | 62 | |
63 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
63 | + if (!empty($_GET['wpinv-ajax'])) { |
|
64 | + $wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax']))); |
|
65 | 65 | } |
66 | 66 | |
67 | - $action = $wp_query->get( 'wpinv-ajax' ); |
|
67 | + $action = $wp_query->get('wpinv-ajax'); |
|
68 | 68 | |
69 | - if ( $action ) { |
|
69 | + if ($action) { |
|
70 | 70 | self::wpinv_ajax_headers(); |
71 | - $action = sanitize_text_field( $action ); |
|
72 | - do_action( 'wpinv_ajax_' . $action ); |
|
71 | + $action = sanitize_text_field($action); |
|
72 | + do_action('wpinv_ajax_' . $action); |
|
73 | 73 | wp_die(); |
74 | 74 | } |
75 | 75 | |
@@ -106,36 +106,36 @@ discard block |
||
106 | 106 | 'file_upload' => true, |
107 | 107 | ); |
108 | 108 | |
109 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
110 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
111 | - add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
109 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
110 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
111 | + add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
112 | 112 | |
113 | - if ( $nopriv ) { |
|
114 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
115 | - add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
116 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
113 | + if ($nopriv) { |
|
114 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
115 | + add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
116 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
121 | 121 | public static function add_note() { |
122 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
122 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
123 | 123 | |
124 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
124 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
125 | 125 | die( -1 ); |
126 | 126 | } |
127 | 127 | |
128 | - $post_id = absint( $_POST['post_id'] ); |
|
129 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
130 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
128 | + $post_id = absint($_POST['post_id']); |
|
129 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
130 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
131 | 131 | |
132 | 132 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
133 | 133 | |
134 | - if ( $post_id > 0 ) { |
|
135 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
134 | + if ($post_id > 0) { |
|
135 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
136 | 136 | |
137 | - if ( $note_id > 0 && ! is_wp_error( $note_id ) ) { |
|
138 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
137 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
138 | + wpinv_get_invoice_note_line_item($note_id); |
|
139 | 139 | } |
140 | 140 | } |
141 | 141 | |
@@ -143,16 +143,16 @@ discard block |
||
143 | 143 | } |
144 | 144 | |
145 | 145 | public static function delete_note() { |
146 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
146 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
147 | 147 | |
148 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
148 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
149 | 149 | die( -1 ); |
150 | 150 | } |
151 | 151 | |
152 | - $note_id = (int)$_POST['note_id']; |
|
152 | + $note_id = (int) $_POST['note_id']; |
|
153 | 153 | |
154 | - if ( $note_id > 0 ) { |
|
155 | - wp_delete_comment( $note_id, true ); |
|
154 | + if ($note_id > 0) { |
|
155 | + wp_delete_comment($note_id, true); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | die(); |
@@ -170,34 +170,34 @@ discard block |
||
170 | 170 | public static function get_billing_details() { |
171 | 171 | |
172 | 172 | // Verify nonce. |
173 | - check_ajax_referer( 'wpinv-nonce' ); |
|
173 | + check_ajax_referer('wpinv-nonce'); |
|
174 | 174 | |
175 | 175 | // Can the user manage the plugin? |
176 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
176 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
177 | 177 | die( -1 ); |
178 | 178 | } |
179 | 179 | |
180 | 180 | // Do we have a user id? |
181 | 181 | $user_id = (int) $_GET['user_id']; |
182 | 182 | |
183 | - if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { |
|
183 | + if (empty($user_id) || !is_numeric($user_id)) { |
|
184 | 184 | die( -1 ); |
185 | 185 | } |
186 | 186 | |
187 | 187 | // Fetch the billing details. |
188 | - $billing_details = wpinv_get_user_address( $user_id ); |
|
189 | - $billing_details = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id ); |
|
188 | + $billing_details = wpinv_get_user_address($user_id); |
|
189 | + $billing_details = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id); |
|
190 | 190 | |
191 | 191 | // unset the user id and email. |
192 | - $to_ignore = array( 'user_id', 'email' ); |
|
192 | + $to_ignore = array('user_id', 'email'); |
|
193 | 193 | |
194 | - foreach ( $to_ignore as $key ) { |
|
195 | - if ( isset( $billing_details[ $key ] ) ) { |
|
196 | - unset( $billing_details[ $key ] ); |
|
194 | + foreach ($to_ignore as $key) { |
|
195 | + if (isset($billing_details[$key])) { |
|
196 | + unset($billing_details[$key]); |
|
197 | 197 | } |
198 | 198 | } |
199 | 199 | |
200 | - wp_send_json_success( $billing_details ); |
|
200 | + wp_send_json_success($billing_details); |
|
201 | 201 | |
202 | 202 | } |
203 | 203 | |
@@ -207,47 +207,47 @@ discard block |
||
207 | 207 | public static function check_new_user_email() { |
208 | 208 | |
209 | 209 | // Verify nonce. |
210 | - check_ajax_referer( 'wpinv-nonce' ); |
|
210 | + check_ajax_referer('wpinv-nonce'); |
|
211 | 211 | |
212 | 212 | // Can the user manage the plugin? |
213 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
213 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
214 | 214 | die( -1 ); |
215 | 215 | } |
216 | 216 | |
217 | 217 | // We need an email address. |
218 | - if ( empty( $_GET['email'] ) ) { |
|
219 | - esc_html_e( "Provide the new user's email address", 'invoicing' ); |
|
218 | + if (empty($_GET['email'])) { |
|
219 | + esc_html_e("Provide the new user's email address", 'invoicing'); |
|
220 | 220 | exit; |
221 | 221 | } |
222 | 222 | |
223 | 223 | // Ensure the email is valid. |
224 | - $email = sanitize_email( $_GET['email'] ); |
|
225 | - if ( ! is_email( $email ) ) { |
|
226 | - esc_html_e( 'Invalid email address', 'invoicing' ); |
|
224 | + $email = sanitize_email($_GET['email']); |
|
225 | + if (!is_email($email)) { |
|
226 | + esc_html_e('Invalid email address', 'invoicing'); |
|
227 | 227 | exit; |
228 | 228 | } |
229 | 229 | |
230 | 230 | // And it does not exist. |
231 | - $id = email_exists( $email ); |
|
232 | - if ( $id ) { |
|
233 | - wp_send_json_success( compact( 'id' ) ); |
|
231 | + $id = email_exists($email); |
|
232 | + if ($id) { |
|
233 | + wp_send_json_success(compact('id')); |
|
234 | 234 | } |
235 | 235 | |
236 | - wp_send_json_success( true ); |
|
236 | + wp_send_json_success(true); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | public static function run_tool() { |
240 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
241 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
240 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
241 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
242 | 242 | die( -1 ); |
243 | 243 | } |
244 | 244 | |
245 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
245 | + $tool = sanitize_text_field($_POST['tool']); |
|
246 | 246 | |
247 | - do_action( 'wpinv_run_tool' ); |
|
247 | + do_action('wpinv_run_tool'); |
|
248 | 248 | |
249 | - if ( ! empty( $tool ) ) { |
|
250 | - do_action( 'wpinv_tool_' . $tool ); |
|
249 | + if (!empty($tool)) { |
|
250 | + do_action('wpinv_tool_' . $tool); |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 | |
@@ -258,14 +258,14 @@ discard block |
||
258 | 258 | global $getpaid_force_checkbox; |
259 | 259 | |
260 | 260 | // Check nonce. |
261 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
261 | + check_ajax_referer('getpaid_form_nonce'); |
|
262 | 262 | |
263 | 263 | // Is the request set up correctly? |
264 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) { |
|
264 | + if (empty($_GET['form']) && empty($_GET['item']) && empty($_GET['invoice'])) { |
|
265 | 265 | aui()->alert( |
266 | 266 | array( |
267 | 267 | 'type' => 'warning', |
268 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
268 | + 'content' => __('No payment form or item provided', 'invoicing'), |
|
269 | 269 | ), |
270 | 270 | true |
271 | 271 | ); |
@@ -273,29 +273,29 @@ discard block |
||
273 | 273 | } |
274 | 274 | |
275 | 275 | // Payment form or button? |
276 | - if ( ! empty( $_GET['form'] ) ) { |
|
277 | - $form = sanitize_text_field( urldecode( $_GET['form'] ) ); |
|
276 | + if (!empty($_GET['form'])) { |
|
277 | + $form = sanitize_text_field(urldecode($_GET['form'])); |
|
278 | 278 | |
279 | - if ( false !== strpos( $form, '|' ) ) { |
|
280 | - $form_pos = strpos( $form, '|' ); |
|
281 | - $_items = getpaid_convert_items_to_array( substr( $form, $form_pos + 1 ) ); |
|
282 | - $form = substr( $form, 0, $form_pos ); |
|
279 | + if (false !== strpos($form, '|')) { |
|
280 | + $form_pos = strpos($form, '|'); |
|
281 | + $_items = getpaid_convert_items_to_array(substr($form, $form_pos + 1)); |
|
282 | + $form = substr($form, 0, $form_pos); |
|
283 | 283 | |
284 | 284 | // Retrieve appropriate payment form. |
285 | - $payment_form = new GetPaid_Payment_Form( $form ); |
|
286 | - $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
285 | + $payment_form = new GetPaid_Payment_Form($form); |
|
286 | + $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
287 | 287 | |
288 | 288 | $items = array(); |
289 | 289 | $item_ids = array(); |
290 | 290 | |
291 | - foreach ( $_items as $item_id => $qty ) { |
|
292 | - if ( ! in_array( $item_id, $item_ids ) ) { |
|
293 | - $item = new GetPaid_Form_Item( $item_id ); |
|
294 | - $item->set_quantity( $qty ); |
|
291 | + foreach ($_items as $item_id => $qty) { |
|
292 | + if (!in_array($item_id, $item_ids)) { |
|
293 | + $item = new GetPaid_Form_Item($item_id); |
|
294 | + $item->set_quantity($qty); |
|
295 | 295 | |
296 | - if ( 0 == $qty ) { |
|
297 | - $item->set_allow_quantities( true ); |
|
298 | - $item->set_is_required( false ); |
|
296 | + if (0 == $qty) { |
|
297 | + $item->set_allow_quantities(true); |
|
298 | + $item->set_is_required(false); |
|
299 | 299 | $getpaid_force_checkbox = true; |
300 | 300 | } |
301 | 301 | |
@@ -304,32 +304,32 @@ discard block |
||
304 | 304 | } |
305 | 305 | } |
306 | 306 | |
307 | - if ( ! $payment_form->is_default() ) { |
|
307 | + if (!$payment_form->is_default()) { |
|
308 | 308 | |
309 | - foreach ( $payment_form->get_items() as $item ) { |
|
310 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
309 | + foreach ($payment_form->get_items() as $item) { |
|
310 | + if (!in_array($item->get_id(), $item_ids)) { |
|
311 | 311 | $item_ids[] = $item->get_id(); |
312 | 312 | $items[] = $item; |
313 | 313 | } |
314 | 314 | } |
315 | 315 | } |
316 | 316 | |
317 | - $payment_form->set_items( $items ); |
|
318 | - $extra_items = esc_attr( getpaid_convert_items_to_string( $_items ) ); |
|
319 | - $extra_items_key = md5( NONCE_KEY . AUTH_KEY . $extra_items ); |
|
317 | + $payment_form->set_items($items); |
|
318 | + $extra_items = esc_attr(getpaid_convert_items_to_string($_items)); |
|
319 | + $extra_items_key = md5(NONCE_KEY . AUTH_KEY . $extra_items); |
|
320 | 320 | $extra_items = "<input type='hidden' name='getpaid-form-items' value='$extra_items' />"; |
321 | 321 | $extra_items .= "<input type='hidden' name='getpaid-form-items-key' value='$extra_items_key' />"; |
322 | - $payment_form->display( $extra_items ); |
|
322 | + $payment_form->display($extra_items); |
|
323 | 323 | $getpaid_force_checkbox = false; |
324 | 324 | |
325 | 325 | } else { |
326 | - getpaid_display_payment_form( $form ); |
|
326 | + getpaid_display_payment_form($form); |
|
327 | 327 | } |
328 | -} elseif ( ! empty( $_GET['invoice'] ) ) { |
|
329 | - getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) ); |
|
328 | +} elseif (!empty($_GET['invoice'])) { |
|
329 | + getpaid_display_invoice_payment_form((int) urldecode($_GET['invoice'])); |
|
330 | 330 | } else { |
331 | - $items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) ); |
|
332 | - getpaid_display_item_payment_form( $items ); |
|
331 | + $items = getpaid_convert_items_to_array(sanitize_text_field(urldecode($_GET['item']))); |
|
332 | + getpaid_display_item_payment_form($items); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | exit; |
@@ -344,17 +344,17 @@ discard block |
||
344 | 344 | public static function payment_form() { |
345 | 345 | |
346 | 346 | // Check nonce. |
347 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
347 | + check_ajax_referer('getpaid_form_nonce'); |
|
348 | 348 | |
349 | 349 | // ... form fields... |
350 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
351 | - esc_html_e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
350 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
351 | + esc_html_e('Error: Reload the page and try again.', 'invoicing'); |
|
352 | 352 | exit; |
353 | 353 | } |
354 | 354 | |
355 | 355 | // Process the payment form. |
356 | - $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' ); |
|
357 | - $checkout = new $checkout_class( new GetPaid_Payment_Form_Submission() ); |
|
356 | + $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout'); |
|
357 | + $checkout = new $checkout_class(new GetPaid_Payment_Form_Submission()); |
|
358 | 358 | $checkout->process_checkout(); |
359 | 359 | |
360 | 360 | exit; |
@@ -367,55 +367,55 @@ discard block |
||
367 | 367 | */ |
368 | 368 | public static function get_payment_form_states_field() { |
369 | 369 | |
370 | - if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) { |
|
370 | + if (empty($_GET['country']) || empty($_GET['form'])) { |
|
371 | 371 | exit; |
372 | 372 | } |
373 | 373 | |
374 | - $elements = getpaid_get_payment_form_elements( (int) $_GET['form'] ); |
|
374 | + $elements = getpaid_get_payment_form_elements((int) $_GET['form']); |
|
375 | 375 | |
376 | - if ( empty( $elements ) ) { |
|
376 | + if (empty($elements)) { |
|
377 | 377 | exit; |
378 | 378 | } |
379 | 379 | |
380 | 380 | $address_fields = array(); |
381 | - foreach ( $elements as $element ) { |
|
382 | - if ( 'address' === $element['type'] ) { |
|
381 | + foreach ($elements as $element) { |
|
382 | + if ('address' === $element['type']) { |
|
383 | 383 | $address_fields = $element; |
384 | 384 | break; |
385 | 385 | } |
386 | 386 | } |
387 | 387 | |
388 | - if ( empty( $address_fields ) ) { |
|
388 | + if (empty($address_fields)) { |
|
389 | 389 | exit; |
390 | 390 | } |
391 | 391 | |
392 | - foreach ( $address_fields['fields'] as $address_field ) { |
|
392 | + foreach ($address_fields['fields'] as $address_field) { |
|
393 | 393 | |
394 | - if ( 'wpinv_state' == $address_field['name'] ) { |
|
394 | + if ('wpinv_state' == $address_field['name']) { |
|
395 | 395 | |
396 | - $wrap_class = getpaid_get_form_element_grid_class( $address_field ); |
|
397 | - $wrap_class = esc_attr( "$wrap_class getpaid-address-field-wrapper" ); |
|
398 | - $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] ); |
|
399 | - $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] ); |
|
400 | - $value = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : ''; |
|
401 | - $label = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] ); |
|
396 | + $wrap_class = getpaid_get_form_element_grid_class($address_field); |
|
397 | + $wrap_class = esc_attr("$wrap_class getpaid-address-field-wrapper"); |
|
398 | + $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']); |
|
399 | + $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']); |
|
400 | + $value = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : ''; |
|
401 | + $label = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']); |
|
402 | 402 | |
403 | - if ( ! empty( $address_field['required'] ) ) { |
|
403 | + if (!empty($address_field['required'])) { |
|
404 | 404 | $label .= "<span class='text-danger'> *</span>"; |
405 | 405 | } |
406 | 406 | |
407 | 407 | $html = getpaid_get_states_select_markup( |
408 | - sanitize_text_field( $_GET['country'] ), |
|
408 | + sanitize_text_field($_GET['country']), |
|
409 | 409 | $value, |
410 | 410 | $placeholder, |
411 | 411 | $label, |
412 | 412 | $description, |
413 | - ! empty( $address_field['required'] ), |
|
413 | + !empty($address_field['required']), |
|
414 | 414 | $wrap_class, |
415 | - sanitize_text_field( $_GET['name'] ) |
|
415 | + sanitize_text_field($_GET['name']) |
|
416 | 416 | ); |
417 | 417 | |
418 | - wp_send_json_success( $html ); |
|
418 | + wp_send_json_success($html); |
|
419 | 419 | exit; |
420 | 420 | |
421 | 421 | } |
@@ -430,66 +430,66 @@ discard block |
||
430 | 430 | public static function recalculate_invoice_totals() { |
431 | 431 | |
432 | 432 | // Verify nonce. |
433 | - check_ajax_referer( 'wpinv-nonce' ); |
|
433 | + check_ajax_referer('wpinv-nonce'); |
|
434 | 434 | |
435 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
435 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
436 | 436 | exit; |
437 | 437 | } |
438 | 438 | |
439 | 439 | // We need an invoice. |
440 | - if ( empty( $_POST['post_id'] ) ) { |
|
440 | + if (empty($_POST['post_id'])) { |
|
441 | 441 | exit; |
442 | 442 | } |
443 | 443 | |
444 | 444 | // Fetch the invoice. |
445 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
445 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
446 | 446 | |
447 | 447 | // Ensure it exists. |
448 | - if ( ! $invoice->get_id() ) { |
|
448 | + if (!$invoice->get_id()) { |
|
449 | 449 | exit; |
450 | 450 | } |
451 | 451 | |
452 | 452 | // Maybe set the country, state, currency. |
453 | - foreach ( array( 'country', 'state', 'currency', 'vat_number', 'discount_code' ) as $key ) { |
|
454 | - if ( isset( $_POST[ $key ] ) ) { |
|
453 | + foreach (array('country', 'state', 'currency', 'vat_number', 'discount_code') as $key) { |
|
454 | + if (isset($_POST[$key])) { |
|
455 | 455 | $method = "set_$key"; |
456 | - $invoice->$method( sanitize_text_field( $_POST[ $key ] ) ); |
|
456 | + $invoice->$method(sanitize_text_field($_POST[$key])); |
|
457 | 457 | } |
458 | 458 | } |
459 | 459 | |
460 | 460 | // Maybe disable taxes. |
461 | - $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) ); |
|
461 | + $invoice->set_disable_taxes(!empty($_POST['taxes'])); |
|
462 | 462 | |
463 | 463 | // Discount code. |
464 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
465 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
466 | - if ( $discount->exists() ) { |
|
467 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
464 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
465 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
466 | + if ($discount->exists()) { |
|
467 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
468 | 468 | } else { |
469 | - $invoice->remove_discount( 'discount_code' ); |
|
469 | + $invoice->remove_discount('discount_code'); |
|
470 | 470 | } |
471 | 471 | } |
472 | 472 | |
473 | 473 | // Recalculate totals. |
474 | 474 | $invoice->recalculate_total(); |
475 | 475 | |
476 | - $total = wpinv_price( $invoice->get_total(), $invoice->get_currency() ); |
|
477 | - $suscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
478 | - if ( is_a( $suscriptions, 'WPInv_Subscription' ) && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) { |
|
479 | - $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() ); |
|
480 | - $total .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>'; |
|
476 | + $total = wpinv_price($invoice->get_total(), $invoice->get_currency()); |
|
477 | + $suscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
478 | + if (is_a($suscriptions, 'WPInv_Subscription') && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) { |
|
479 | + $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency()); |
|
480 | + $total .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>'; |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | $totals = array( |
484 | - 'subtotal' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ), |
|
485 | - 'discount' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ), |
|
486 | - 'tax' => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ), |
|
484 | + 'subtotal' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()), |
|
485 | + 'discount' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()), |
|
486 | + 'tax' => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()), |
|
487 | 487 | 'total' => $total, |
488 | 488 | ); |
489 | 489 | |
490 | - $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice ); |
|
490 | + $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice); |
|
491 | 491 | |
492 | - wp_send_json_success( compact( 'totals' ) ); |
|
492 | + wp_send_json_success(compact('totals')); |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | /** |
@@ -498,33 +498,33 @@ discard block |
||
498 | 498 | public static function get_invoice_items() { |
499 | 499 | |
500 | 500 | // Verify nonce. |
501 | - check_ajax_referer( 'wpinv-nonce' ); |
|
501 | + check_ajax_referer('wpinv-nonce'); |
|
502 | 502 | |
503 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
503 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
504 | 504 | exit; |
505 | 505 | } |
506 | 506 | |
507 | 507 | // We need an invoice and items. |
508 | - if ( empty( $_POST['post_id'] ) ) { |
|
508 | + if (empty($_POST['post_id'])) { |
|
509 | 509 | exit; |
510 | 510 | } |
511 | 511 | |
512 | 512 | // Fetch the invoice. |
513 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
513 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
514 | 514 | |
515 | 515 | // Ensure it exists. |
516 | - if ( ! $invoice->get_id() ) { |
|
516 | + if (!$invoice->get_id()) { |
|
517 | 517 | exit; |
518 | 518 | } |
519 | 519 | |
520 | 520 | // Return an array of invoice items. |
521 | 521 | $items = array(); |
522 | 522 | |
523 | - foreach ( $invoice->get_items() as $item ) { |
|
524 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency(), $invoice->is_renewal() ); |
|
523 | + foreach ($invoice->get_items() as $item) { |
|
524 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency(), $invoice->is_renewal()); |
|
525 | 525 | } |
526 | 526 | |
527 | - wp_send_json_success( compact( 'items' ) ); |
|
527 | + wp_send_json_success(compact('items')); |
|
528 | 528 | } |
529 | 529 | |
530 | 530 | /** |
@@ -533,50 +533,50 @@ discard block |
||
533 | 533 | public static function edit_invoice_item() { |
534 | 534 | |
535 | 535 | // Verify nonce. |
536 | - check_ajax_referer( 'wpinv-nonce' ); |
|
536 | + check_ajax_referer('wpinv-nonce'); |
|
537 | 537 | |
538 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
538 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
539 | 539 | exit; |
540 | 540 | } |
541 | 541 | |
542 | 542 | // We need an invoice and item details. |
543 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) { |
|
543 | + if (empty($_POST['post_id']) || empty($_POST['data'])) { |
|
544 | 544 | exit; |
545 | 545 | } |
546 | 546 | |
547 | 547 | // Fetch the invoice. |
548 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
548 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
549 | 549 | |
550 | 550 | // Ensure it exists and its not been paid for. |
551 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
551 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
552 | 552 | exit; |
553 | 553 | } |
554 | 554 | |
555 | 555 | // Format the data. |
556 | - $data = wp_kses_post_deep( wp_unslash( wp_list_pluck( $_POST['data'], 'value', 'field' ) ) ); |
|
556 | + $data = wp_kses_post_deep(wp_unslash(wp_list_pluck($_POST['data'], 'value', 'field'))); |
|
557 | 557 | |
558 | 558 | // Ensure that we have an item id. |
559 | - if ( empty( $data['id'] ) ) { |
|
559 | + if (empty($data['id'])) { |
|
560 | 560 | exit; |
561 | 561 | } |
562 | 562 | |
563 | 563 | // Abort if the invoice does not have the specified item. |
564 | - $item = $invoice->get_item( (int) $data['id'] ); |
|
564 | + $item = $invoice->get_item((int) $data['id']); |
|
565 | 565 | |
566 | - if ( empty( $item ) ) { |
|
566 | + if (empty($item)) { |
|
567 | 567 | exit; |
568 | 568 | } |
569 | 569 | |
570 | 570 | // Update the item. |
571 | - $item->set_price( getpaid_standardize_amount( $data['price'] ) ); |
|
572 | - $item->set_name( sanitize_text_field( $data['name'] ) ); |
|
573 | - $item->set_description( wp_kses_post( $data['description'] ) ); |
|
574 | - $item->set_quantity( floatval( $data['quantity'] ) ); |
|
571 | + $item->set_price(getpaid_standardize_amount($data['price'])); |
|
572 | + $item->set_name(sanitize_text_field($data['name'])); |
|
573 | + $item->set_description(wp_kses_post($data['description'])); |
|
574 | + $item->set_quantity(floatval($data['quantity'])); |
|
575 | 575 | |
576 | 576 | // Add it to the invoice. |
577 | - $error = $invoice->add_item( $item ); |
|
577 | + $error = $invoice->add_item($item); |
|
578 | 578 | $alert = false; |
579 | - if ( is_wp_error( $error ) ) { |
|
579 | + if (is_wp_error($error)) { |
|
580 | 580 | $alert = $error->get_error_message(); |
581 | 581 | } |
582 | 582 | |
@@ -589,11 +589,11 @@ discard block |
||
589 | 589 | // Return an array of invoice items. |
590 | 590 | $items = array(); |
591 | 591 | |
592 | - foreach ( $invoice->get_items() as $item ) { |
|
593 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
592 | + foreach ($invoice->get_items() as $item) { |
|
593 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
594 | 594 | } |
595 | 595 | |
596 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
596 | + wp_send_json_success(compact('items', 'alert')); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | /** |
@@ -602,53 +602,53 @@ discard block |
||
602 | 602 | public static function create_invoice_item() { |
603 | 603 | |
604 | 604 | // Verify nonce. |
605 | - check_ajax_referer( 'wpinv-nonce' ); |
|
605 | + check_ajax_referer('wpinv-nonce'); |
|
606 | 606 | |
607 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
607 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
608 | 608 | exit; |
609 | 609 | } |
610 | 610 | |
611 | 611 | // We need an invoice and item details. |
612 | - if ( empty( $_POST['invoice_id'] ) || empty( $_POST['_wpinv_quick'] ) ) { |
|
612 | + if (empty($_POST['invoice_id']) || empty($_POST['_wpinv_quick'])) { |
|
613 | 613 | exit; |
614 | 614 | } |
615 | 615 | |
616 | 616 | // Fetch the invoice. |
617 | - $invoice = new WPInv_Invoice( intval( $_POST['invoice_id'] ) ); |
|
617 | + $invoice = new WPInv_Invoice(intval($_POST['invoice_id'])); |
|
618 | 618 | |
619 | 619 | // Ensure it exists and its not been paid for. |
620 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
620 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
621 | 621 | exit; |
622 | 622 | } |
623 | 623 | |
624 | 624 | // Format the data. |
625 | - $data = wp_kses_post_deep( wp_unslash( $_POST['_wpinv_quick'] ) ); |
|
625 | + $data = wp_kses_post_deep(wp_unslash($_POST['_wpinv_quick'])); |
|
626 | 626 | |
627 | 627 | $item = new WPInv_Item(); |
628 | - $item->set_price( getpaid_standardize_amount( $data['price'] ) ); |
|
629 | - $item->set_name( sanitize_text_field( $data['name'] ) ); |
|
630 | - $item->set_description( wp_kses_post( $data['description'] ) ); |
|
631 | - $item->set_type( sanitize_text_field( $data['type'] ) ); |
|
632 | - $item->set_vat_rule( sanitize_text_field( $data['vat_rule'] ) ); |
|
633 | - $item->set_vat_class( sanitize_text_field( $data['vat_class'] ) ); |
|
634 | - $item->set_status( 'publish' ); |
|
628 | + $item->set_price(getpaid_standardize_amount($data['price'])); |
|
629 | + $item->set_name(sanitize_text_field($data['name'])); |
|
630 | + $item->set_description(wp_kses_post($data['description'])); |
|
631 | + $item->set_type(sanitize_text_field($data['type'])); |
|
632 | + $item->set_vat_rule(sanitize_text_field($data['vat_rule'])); |
|
633 | + $item->set_vat_class(sanitize_text_field($data['vat_class'])); |
|
634 | + $item->set_status('publish'); |
|
635 | 635 | $item->save(); |
636 | 636 | |
637 | - if ( ! $item->exists() ) { |
|
638 | - $alert = __( 'Could not create invoice item. Please try again.', 'invoicing' ); |
|
639 | - wp_send_json_success( compact( 'alert' ) ); |
|
637 | + if (!$item->exists()) { |
|
638 | + $alert = __('Could not create invoice item. Please try again.', 'invoicing'); |
|
639 | + wp_send_json_success(compact('alert')); |
|
640 | 640 | } |
641 | 641 | |
642 | - $item = new GetPaid_Form_Item( $item->get_id() ); |
|
643 | - $item->set_quantity( floatval( $data['qty'] ) ); |
|
642 | + $item = new GetPaid_Form_Item($item->get_id()); |
|
643 | + $item->set_quantity(floatval($data['qty'])); |
|
644 | 644 | |
645 | 645 | // Add it to the invoice. |
646 | - $error = $invoice->add_item( $item ); |
|
646 | + $error = $invoice->add_item($item); |
|
647 | 647 | $alert = false; |
648 | 648 | |
649 | - if ( is_wp_error( $error ) ) { |
|
649 | + if (is_wp_error($error)) { |
|
650 | 650 | $alert = $error->get_error_message(); |
651 | - wp_send_json_success( compact( 'alert' ) ); |
|
651 | + wp_send_json_success(compact('alert')); |
|
652 | 652 | } |
653 | 653 | |
654 | 654 | // Update totals. |
@@ -661,9 +661,9 @@ discard block |
||
661 | 661 | $invoice->recalculate_total(); |
662 | 662 | $invoice->save(); |
663 | 663 | ob_start(); |
664 | - GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice ); |
|
664 | + GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice); |
|
665 | 665 | $row = ob_get_clean(); |
666 | - wp_send_json_success( compact( 'row' ) ); |
|
666 | + wp_send_json_success(compact('row')); |
|
667 | 667 | } |
668 | 668 | |
669 | 669 | /** |
@@ -672,33 +672,33 @@ discard block |
||
672 | 672 | public static function remove_invoice_item() { |
673 | 673 | |
674 | 674 | // Verify nonce. |
675 | - check_ajax_referer( 'wpinv-nonce' ); |
|
675 | + check_ajax_referer('wpinv-nonce'); |
|
676 | 676 | |
677 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
677 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
678 | 678 | exit; |
679 | 679 | } |
680 | 680 | |
681 | 681 | // We need an invoice and an item. |
682 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
682 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
683 | 683 | exit; |
684 | 684 | } |
685 | 685 | |
686 | 686 | // Fetch the invoice. |
687 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
687 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
688 | 688 | |
689 | 689 | // Ensure it exists and its not been paid for. |
690 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
690 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
691 | 691 | exit; |
692 | 692 | } |
693 | 693 | |
694 | 694 | // Abort if the invoice does not have the specified item. |
695 | - $item = $invoice->get_item( (int) $_POST['item_id'] ); |
|
695 | + $item = $invoice->get_item((int) $_POST['item_id']); |
|
696 | 696 | |
697 | - if ( empty( $item ) ) { |
|
697 | + if (empty($item)) { |
|
698 | 698 | exit; |
699 | 699 | } |
700 | 700 | |
701 | - $invoice->remove_item( (int) $_POST['item_id'] ); |
|
701 | + $invoice->remove_item((int) $_POST['item_id']); |
|
702 | 702 | |
703 | 703 | // Update totals. |
704 | 704 | $invoice->recalculate_total(); |
@@ -709,11 +709,11 @@ discard block |
||
709 | 709 | // Return an array of invoice items. |
710 | 710 | $items = array(); |
711 | 711 | |
712 | - foreach ( $invoice->get_items() as $item ) { |
|
713 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
712 | + foreach ($invoice->get_items() as $item) { |
|
713 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
714 | 714 | } |
715 | 715 | |
716 | - wp_send_json_success( compact( 'items' ) ); |
|
716 | + wp_send_json_success(compact('items')); |
|
717 | 717 | } |
718 | 718 | |
719 | 719 | /** |
@@ -722,68 +722,68 @@ discard block |
||
722 | 722 | public static function recalculate_full_prices() { |
723 | 723 | |
724 | 724 | // Verify nonce. |
725 | - check_ajax_referer( 'wpinv-nonce' ); |
|
725 | + check_ajax_referer('wpinv-nonce'); |
|
726 | 726 | |
727 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
727 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
728 | 728 | exit; |
729 | 729 | } |
730 | 730 | |
731 | 731 | // We need an invoice and item. |
732 | - if ( empty( $_POST['post_id'] ) ) { |
|
732 | + if (empty($_POST['post_id'])) { |
|
733 | 733 | exit; |
734 | 734 | } |
735 | 735 | |
736 | 736 | // Fetch the invoice. |
737 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
737 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
738 | 738 | $alert = false; |
739 | 739 | |
740 | 740 | // Ensure it exists and its not been paid for. |
741 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
741 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
742 | 742 | exit; |
743 | 743 | } |
744 | 744 | |
745 | - $invoice->set_items( array() ); |
|
745 | + $invoice->set_items(array()); |
|
746 | 746 | |
747 | - if ( ! empty( $_POST['getpaid_items'] ) ) { |
|
747 | + if (!empty($_POST['getpaid_items'])) { |
|
748 | 748 | |
749 | - foreach ( wp_kses_post_deep( $_POST['getpaid_items'] ) as $item_id => $args ) { |
|
750 | - $item = new GetPaid_Form_Item( $item_id ); |
|
749 | + foreach (wp_kses_post_deep($_POST['getpaid_items']) as $item_id => $args) { |
|
750 | + $item = new GetPaid_Form_Item($item_id); |
|
751 | 751 | |
752 | - if ( $item->exists() ) { |
|
753 | - $item->set_price( getpaid_standardize_amount( $args['price'] ) ); |
|
754 | - $item->set_quantity( floatval( $args['quantity'] ) ); |
|
755 | - $item->set_name( sanitize_text_field( $args['name'] ) ); |
|
756 | - $item->set_description( wp_kses_post( $args['description'] ) ); |
|
757 | - $invoice->add_item( $item ); |
|
752 | + if ($item->exists()) { |
|
753 | + $item->set_price(getpaid_standardize_amount($args['price'])); |
|
754 | + $item->set_quantity(floatval($args['quantity'])); |
|
755 | + $item->set_name(sanitize_text_field($args['name'])); |
|
756 | + $item->set_description(wp_kses_post($args['description'])); |
|
757 | + $invoice->add_item($item); |
|
758 | 758 | } |
759 | 759 | } |
760 | 760 | } |
761 | 761 | |
762 | - $invoice->set_disable_taxes( ! empty( $_POST['disable_taxes'] ) ); |
|
762 | + $invoice->set_disable_taxes(!empty($_POST['disable_taxes'])); |
|
763 | 763 | |
764 | 764 | // Maybe set the country, state, currency. |
765 | - foreach ( array( 'wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code' ) as $key ) { |
|
766 | - if ( isset( $_POST[ $key ] ) ) { |
|
767 | - $_key = str_replace( 'wpinv_', '', $key ); |
|
765 | + foreach (array('wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code') as $key) { |
|
766 | + if (isset($_POST[$key])) { |
|
767 | + $_key = str_replace('wpinv_', '', $key); |
|
768 | 768 | $method = "set_$_key"; |
769 | - $invoice->$method( sanitize_text_field( $_POST[ $key ] ) ); |
|
769 | + $invoice->$method(sanitize_text_field($_POST[$key])); |
|
770 | 770 | } |
771 | 771 | } |
772 | 772 | |
773 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
774 | - if ( $discount->exists() ) { |
|
775 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
773 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
774 | + if ($discount->exists()) { |
|
775 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
776 | 776 | } else { |
777 | - $invoice->remove_discount( 'discount_code' ); |
|
777 | + $invoice->remove_discount('discount_code'); |
|
778 | 778 | } |
779 | 779 | |
780 | 780 | // Save the invoice. |
781 | 781 | $invoice->recalculate_total(); |
782 | 782 | $invoice->save(); |
783 | 783 | ob_start(); |
784 | - GetPaid_Meta_Box_Invoice_Items::output( get_post( $invoice->get_id() ), $invoice ); |
|
784 | + GetPaid_Meta_Box_Invoice_Items::output(get_post($invoice->get_id()), $invoice); |
|
785 | 785 | $table = ob_get_clean(); |
786 | - wp_send_json_success( compact( 'table' ) ); |
|
786 | + wp_send_json_success(compact('table')); |
|
787 | 787 | } |
788 | 788 | |
789 | 789 | /** |
@@ -792,42 +792,42 @@ discard block |
||
792 | 792 | public static function admin_add_invoice_item() { |
793 | 793 | |
794 | 794 | // Verify nonce. |
795 | - check_ajax_referer( 'wpinv-nonce' ); |
|
795 | + check_ajax_referer('wpinv-nonce'); |
|
796 | 796 | |
797 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
797 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
798 | 798 | exit; |
799 | 799 | } |
800 | 800 | |
801 | 801 | // We need an invoice and item. |
802 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
802 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
803 | 803 | exit; |
804 | 804 | } |
805 | 805 | |
806 | 806 | // Fetch the invoice. |
807 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
807 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
808 | 808 | $alert = false; |
809 | 809 | |
810 | 810 | // Ensure it exists and its not been paid for. |
811 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
811 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
812 | 812 | exit; |
813 | 813 | } |
814 | 814 | |
815 | 815 | // Add the item. |
816 | - $item = new GetPaid_Form_Item( (int) $_POST['item_id'] ); |
|
817 | - $error = $invoice->add_item( $item ); |
|
816 | + $item = new GetPaid_Form_Item((int) $_POST['item_id']); |
|
817 | + $error = $invoice->add_item($item); |
|
818 | 818 | |
819 | - if ( is_wp_error( $error ) ) { |
|
819 | + if (is_wp_error($error)) { |
|
820 | 820 | $alert = $error->get_error_message(); |
821 | - wp_send_json_success( compact( 'alert' ) ); |
|
821 | + wp_send_json_success(compact('alert')); |
|
822 | 822 | } |
823 | 823 | |
824 | 824 | // Save the invoice. |
825 | 825 | $invoice->recalculate_total(); |
826 | 826 | $invoice->save(); |
827 | 827 | ob_start(); |
828 | - GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice ); |
|
828 | + GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice); |
|
829 | 829 | $row = ob_get_clean(); |
830 | - wp_send_json_success( compact( 'row' ) ); |
|
830 | + wp_send_json_success(compact('row')); |
|
831 | 831 | } |
832 | 832 | |
833 | 833 | /** |
@@ -836,39 +836,39 @@ discard block |
||
836 | 836 | public static function add_invoice_items() { |
837 | 837 | |
838 | 838 | // Verify nonce. |
839 | - check_ajax_referer( 'wpinv-nonce' ); |
|
839 | + check_ajax_referer('wpinv-nonce'); |
|
840 | 840 | |
841 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
841 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
842 | 842 | exit; |
843 | 843 | } |
844 | 844 | |
845 | 845 | // We need an invoice and items. |
846 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) { |
|
846 | + if (empty($_POST['post_id']) || empty($_POST['items'])) { |
|
847 | 847 | exit; |
848 | 848 | } |
849 | 849 | |
850 | 850 | // Fetch the invoice. |
851 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
851 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
852 | 852 | $alert = false; |
853 | 853 | |
854 | 854 | // Ensure it exists and its not been paid for. |
855 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
855 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
856 | 856 | exit; |
857 | 857 | } |
858 | 858 | |
859 | 859 | // Add the items. |
860 | - foreach ( wp_kses_post_deep( wp_unslash( $_POST['items'] ) ) as $data ) { |
|
860 | + foreach (wp_kses_post_deep(wp_unslash($_POST['items'])) as $data) { |
|
861 | 861 | |
862 | - $item = new GetPaid_Form_Item( (int) $data['id'] ); |
|
862 | + $item = new GetPaid_Form_Item((int) $data['id']); |
|
863 | 863 | |
864 | - if ( is_numeric( $data['qty'] ) && (float) $data['qty'] > 0 ) { |
|
865 | - $item->set_quantity( floatval( $data['qty'] ) ); |
|
864 | + if (is_numeric($data['qty']) && (float) $data['qty'] > 0) { |
|
865 | + $item->set_quantity(floatval($data['qty'])); |
|
866 | 866 | } |
867 | 867 | |
868 | - if ( $item->get_id() > 0 ) { |
|
869 | - $error = $invoice->add_item( $item ); |
|
868 | + if ($item->get_id() > 0) { |
|
869 | + $error = $invoice->add_item($item); |
|
870 | 870 | |
871 | - if ( is_wp_error( $error ) ) { |
|
871 | + if (is_wp_error($error)) { |
|
872 | 872 | $alert = $error->get_error_message(); |
873 | 873 | } |
874 | 874 | } |
@@ -881,11 +881,11 @@ discard block |
||
881 | 881 | // Return an array of invoice items. |
882 | 882 | $items = array(); |
883 | 883 | |
884 | - foreach ( $invoice->get_items() as $item ) { |
|
885 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
884 | + foreach ($invoice->get_items() as $item) { |
|
885 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
886 | 886 | } |
887 | 887 | |
888 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
888 | + wp_send_json_success(compact('items', 'alert')); |
|
889 | 889 | } |
890 | 890 | |
891 | 891 | /** |
@@ -894,15 +894,15 @@ discard block |
||
894 | 894 | public static function get_invoicing_items() { |
895 | 895 | |
896 | 896 | // Verify nonce. |
897 | - check_ajax_referer( 'wpinv-nonce' ); |
|
897 | + check_ajax_referer('wpinv-nonce'); |
|
898 | 898 | |
899 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
899 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
900 | 900 | exit; |
901 | 901 | } |
902 | 902 | |
903 | 903 | // We need a search term. |
904 | - if ( empty( $_GET['search'] ) ) { |
|
905 | - wp_send_json_success( array() ); |
|
904 | + if (empty($_GET['search'])) { |
|
905 | + wp_send_json_success(array()); |
|
906 | 906 | } |
907 | 907 | |
908 | 908 | // Retrieve items. |
@@ -911,8 +911,8 @@ discard block |
||
911 | 911 | 'orderby' => 'title', |
912 | 912 | 'order' => 'ASC', |
913 | 913 | 'posts_per_page' => -1, |
914 | - 'post_status' => array( 'publish' ), |
|
915 | - 's' => sanitize_text_field( urldecode( $_GET['search'] ) ), |
|
914 | + 'post_status' => array('publish'), |
|
915 | + 's' => sanitize_text_field(urldecode($_GET['search'])), |
|
916 | 916 | 'meta_query' => array( |
917 | 917 | array( |
918 | 918 | 'key' => '_wpinv_type', |
@@ -922,25 +922,25 @@ discard block |
||
922 | 922 | ), |
923 | 923 | ); |
924 | 924 | |
925 | - if ( ! empty( $_GET['ignore'] ) ) { |
|
926 | - $item_args['exclude'] = wp_parse_id_list( sanitize_text_field( $_GET['ignore'] ) ); |
|
925 | + if (!empty($_GET['ignore'])) { |
|
926 | + $item_args['exclude'] = wp_parse_id_list(sanitize_text_field($_GET['ignore'])); |
|
927 | 927 | } |
928 | 928 | |
929 | - $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) ); |
|
929 | + $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args)); |
|
930 | 930 | $data = array(); |
931 | 931 | |
932 | - $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( (int) $_GET['post_id'] ) ); |
|
932 | + $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type((int) $_GET['post_id'])); |
|
933 | 933 | |
934 | - foreach ( $items as $item ) { |
|
935 | - $item = new GetPaid_Form_Item( $item ); |
|
934 | + foreach ($items as $item) { |
|
935 | + $item = new GetPaid_Form_Item($item); |
|
936 | 936 | $data[] = array( |
937 | 937 | 'id' => (int) $item->get_id(), |
938 | - 'text' => strip_tags( $item->get_name() ), |
|
939 | - 'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '', |
|
938 | + 'text' => strip_tags($item->get_name()), |
|
939 | + 'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '', |
|
940 | 940 | ); |
941 | 941 | } |
942 | 942 | |
943 | - wp_send_json_success( $data ); |
|
943 | + wp_send_json_success($data); |
|
944 | 944 | |
945 | 945 | } |
946 | 946 | |
@@ -950,37 +950,37 @@ discard block |
||
950 | 950 | public static function get_customers() { |
951 | 951 | |
952 | 952 | // Verify nonce. |
953 | - check_ajax_referer( 'wpinv-nonce' ); |
|
953 | + check_ajax_referer('wpinv-nonce'); |
|
954 | 954 | |
955 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
955 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
956 | 956 | exit; |
957 | 957 | } |
958 | 958 | |
959 | 959 | // We need a search term. |
960 | - if ( empty( $_GET['search'] ) ) { |
|
961 | - wp_send_json_success( array() ); |
|
960 | + if (empty($_GET['search'])) { |
|
961 | + wp_send_json_success(array()); |
|
962 | 962 | } |
963 | 963 | |
964 | 964 | // Retrieve customers. |
965 | 965 | |
966 | 966 | $customer_args = array( |
967 | - 'fields' => array( 'ID', 'user_email', 'display_name' ), |
|
967 | + 'fields' => array('ID', 'user_email', 'display_name'), |
|
968 | 968 | 'orderby' => 'display_name', |
969 | - 'search' => '*' . sanitize_text_field( $_GET['search'] ) . '*', |
|
970 | - 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
969 | + 'search' => '*' . sanitize_text_field($_GET['search']) . '*', |
|
970 | + 'search_columns' => array('user_login', 'user_email', 'display_name'), |
|
971 | 971 | ); |
972 | 972 | |
973 | - $customers = get_users( apply_filters( 'getpaid_ajax_invoice_customers_query_args', $customer_args ) ); |
|
973 | + $customers = get_users(apply_filters('getpaid_ajax_invoice_customers_query_args', $customer_args)); |
|
974 | 974 | $data = array(); |
975 | 975 | |
976 | - foreach ( $customers as $customer ) { |
|
976 | + foreach ($customers as $customer) { |
|
977 | 977 | $data[] = array( |
978 | 978 | 'id' => (int) $customer->ID, |
979 | - 'text' => strip_tags( sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ) ), |
|
979 | + 'text' => strip_tags(sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email)), |
|
980 | 980 | ); |
981 | 981 | } |
982 | 982 | |
983 | - wp_send_json_success( $data ); |
|
983 | + wp_send_json_success($data); |
|
984 | 984 | |
985 | 985 | } |
986 | 986 | |
@@ -990,28 +990,28 @@ discard block |
||
990 | 990 | public static function get_aui_states_field() { |
991 | 991 | |
992 | 992 | // Verify nonce. |
993 | - check_ajax_referer( 'wpinv-nonce' ); |
|
993 | + check_ajax_referer('wpinv-nonce'); |
|
994 | 994 | |
995 | 995 | // We need a country. |
996 | - if ( empty( $_GET['country'] ) ) { |
|
996 | + if (empty($_GET['country'])) { |
|
997 | 997 | exit; |
998 | 998 | } |
999 | 999 | |
1000 | - $states = wpinv_get_country_states( sanitize_text_field( $_GET['country'] ) ); |
|
1001 | - $state = isset( $_GET['state'] ) ? sanitize_text_field( $_GET['state'] ) : wpinv_get_default_state(); |
|
1002 | - $name = isset( $_GET['name'] ) ? sanitize_text_field( $_GET['name'] ) : 'wpinv_state'; |
|
1003 | - $class = isset( $_GET['class'] ) ? sanitize_text_field( $_GET['class'] ) : 'form-control-sm'; |
|
1000 | + $states = wpinv_get_country_states(sanitize_text_field($_GET['country'])); |
|
1001 | + $state = isset($_GET['state']) ? sanitize_text_field($_GET['state']) : wpinv_get_default_state(); |
|
1002 | + $name = isset($_GET['name']) ? sanitize_text_field($_GET['name']) : 'wpinv_state'; |
|
1003 | + $class = isset($_GET['class']) ? sanitize_text_field($_GET['class']) : 'form-control-sm'; |
|
1004 | 1004 | |
1005 | - if ( empty( $states ) ) { |
|
1005 | + if (empty($states)) { |
|
1006 | 1006 | |
1007 | 1007 | $html = aui()->input( |
1008 | 1008 | array( |
1009 | 1009 | 'type' => 'text', |
1010 | 1010 | 'id' => 'wpinv_state', |
1011 | 1011 | 'name' => $name, |
1012 | - 'label' => __( 'State', 'invoicing' ), |
|
1012 | + 'label' => __('State', 'invoicing'), |
|
1013 | 1013 | 'label_type' => 'vertical', |
1014 | - 'placeholder' => __( 'State', 'invoicing' ), |
|
1014 | + 'placeholder' => __('State', 'invoicing'), |
|
1015 | 1015 | 'class' => $class, |
1016 | 1016 | 'value' => $state, |
1017 | 1017 | ) |
@@ -1023,9 +1023,9 @@ discard block |
||
1023 | 1023 | array( |
1024 | 1024 | 'id' => 'wpinv_state', |
1025 | 1025 | 'name' => $name, |
1026 | - 'label' => __( 'State', 'invoicing' ), |
|
1026 | + 'label' => __('State', 'invoicing'), |
|
1027 | 1027 | 'label_type' => 'vertical', |
1028 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
1028 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
1029 | 1029 | 'class' => $class, |
1030 | 1030 | 'value' => $state, |
1031 | 1031 | 'options' => $states, |
@@ -1039,7 +1039,7 @@ discard block |
||
1039 | 1039 | wp_send_json_success( |
1040 | 1040 | array( |
1041 | 1041 | 'html' => $html, |
1042 | - 'select' => ! empty( $states ), |
|
1042 | + 'select' => !empty($states), |
|
1043 | 1043 | ) |
1044 | 1044 | ); |
1045 | 1045 | |
@@ -1053,11 +1053,11 @@ discard block |
||
1053 | 1053 | public static function payment_form_refresh_prices() { |
1054 | 1054 | |
1055 | 1055 | // Check nonce. |
1056 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
1056 | + check_ajax_referer('getpaid_form_nonce'); |
|
1057 | 1057 | |
1058 | 1058 | // ... form fields... |
1059 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
1060 | - esc_html_e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
1059 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
1060 | + esc_html_e('Error: Reload the page and try again.', 'invoicing'); |
|
1061 | 1061 | exit; |
1062 | 1062 | } |
1063 | 1063 | |
@@ -1065,7 +1065,7 @@ discard block |
||
1065 | 1065 | $submission = new GetPaid_Payment_Form_Submission(); |
1066 | 1066 | |
1067 | 1067 | // Do we have an error? |
1068 | - if ( ! empty( $submission->last_error ) ) { |
|
1068 | + if (!empty($submission->last_error)) { |
|
1069 | 1069 | wp_send_json_error( |
1070 | 1070 | array( |
1071 | 1071 | 'code' => $submission->last_error_code, |
@@ -1075,12 +1075,12 @@ discard block |
||
1075 | 1075 | } |
1076 | 1076 | |
1077 | 1077 | // Prepare the response. |
1078 | - $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission ); |
|
1078 | + $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission); |
|
1079 | 1079 | |
1080 | 1080 | // Filter the response. |
1081 | - $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission ); |
|
1081 | + $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission); |
|
1082 | 1082 | |
1083 | - wp_send_json_success( $response ); |
|
1083 | + wp_send_json_success($response); |
|
1084 | 1084 | } |
1085 | 1085 | |
1086 | 1086 | /** |
@@ -1092,63 +1092,63 @@ discard block |
||
1092 | 1092 | public static function file_upload() { |
1093 | 1093 | |
1094 | 1094 | // Check nonce. |
1095 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
1095 | + check_ajax_referer('getpaid_form_nonce'); |
|
1096 | 1096 | |
1097 | - if ( empty( $_POST['form_id'] ) || empty( $_POST['field_name'] ) || empty( $_FILES['file'] ) ) { |
|
1098 | - wp_die( esc_html_e( 'Bad Request', 'invoicing' ), 400 ); |
|
1097 | + if (empty($_POST['form_id']) || empty($_POST['field_name']) || empty($_FILES['file'])) { |
|
1098 | + wp_die(esc_html_e('Bad Request', 'invoicing'), 400); |
|
1099 | 1099 | } |
1100 | 1100 | |
1101 | 1101 | // Fetch form. |
1102 | - $form = new GetPaid_Payment_Form( intval( $_POST['form_id'] ) ); |
|
1102 | + $form = new GetPaid_Payment_Form(intval($_POST['form_id'])); |
|
1103 | 1103 | |
1104 | - if ( ! $form->is_active() ) { |
|
1105 | - wp_send_json_error( __( 'Payment form not active', 'invoicing' ) ); |
|
1104 | + if (!$form->is_active()) { |
|
1105 | + wp_send_json_error(__('Payment form not active', 'invoicing')); |
|
1106 | 1106 | } |
1107 | 1107 | |
1108 | 1108 | // Fetch appropriate field. |
1109 | - $upload_field = current( wp_list_filter( $form->get_elements(), array( 'id' => sanitize_text_field( $_POST['field_name'] ) ) ) ); |
|
1110 | - if ( empty( $upload_field ) ) { |
|
1111 | - wp_send_json_error( __( 'Invalid upload field.', 'invoicing' ) ); |
|
1109 | + $upload_field = current(wp_list_filter($form->get_elements(), array('id' => sanitize_text_field($_POST['field_name'])))); |
|
1110 | + if (empty($upload_field)) { |
|
1111 | + wp_send_json_error(__('Invalid upload field.', 'invoicing')); |
|
1112 | 1112 | } |
1113 | 1113 | |
1114 | 1114 | // Prepare allowed file types. |
1115 | - $file_types = isset( $upload_field['file_types'] ) ? $upload_field['file_types'] : array( 'jpg|jpeg|jpe', 'gif', 'png' ); |
|
1115 | + $file_types = isset($upload_field['file_types']) ? $upload_field['file_types'] : array('jpg|jpeg|jpe', 'gif', 'png'); |
|
1116 | 1116 | $all_types = getpaid_get_allowed_mime_types(); |
1117 | 1117 | $mime_types = array(); |
1118 | 1118 | |
1119 | - foreach ( $file_types as $file_type ) { |
|
1120 | - if ( isset( $all_types[ $file_type ] ) ) { |
|
1121 | - $mime_types[] = $all_types[ $file_type ]; |
|
1119 | + foreach ($file_types as $file_type) { |
|
1120 | + if (isset($all_types[$file_type])) { |
|
1121 | + $mime_types[] = $all_types[$file_type]; |
|
1122 | 1122 | } |
1123 | 1123 | } |
1124 | 1124 | |
1125 | - if ( ! in_array( $_FILES['file']['type'], $mime_types ) ) { |
|
1126 | - wp_send_json_error( __( 'Unsupported file type.', 'invoicing' ) ); |
|
1125 | + if (!in_array($_FILES['file']['type'], $mime_types)) { |
|
1126 | + wp_send_json_error(__('Unsupported file type.', 'invoicing')); |
|
1127 | 1127 | } |
1128 | 1128 | |
1129 | 1129 | // Upload file. |
1130 | - $file_name = explode( '.', strtolower( $_FILES['file']['name'] ) ); |
|
1131 | - $file_name = uniqid( 'getpaid-' ) . '.' . array_pop( $file_name ); |
|
1130 | + $file_name = explode('.', strtolower($_FILES['file']['name'])); |
|
1131 | + $file_name = uniqid('getpaid-') . '.' . array_pop($file_name); |
|
1132 | 1132 | |
1133 | 1133 | $uploaded = wp_upload_bits( |
1134 | 1134 | $file_name, |
1135 | 1135 | null, |
1136 | - file_get_contents( $_FILES['file']['tmp_name'] ) |
|
1136 | + file_get_contents($_FILES['file']['tmp_name']) |
|
1137 | 1137 | ); |
1138 | 1138 | |
1139 | - if ( ! empty( $uploaded['error'] ) ) { |
|
1140 | - wp_send_json_error( $uploaded['error'] ); |
|
1139 | + if (!empty($uploaded['error'])) { |
|
1140 | + wp_send_json_error($uploaded['error']); |
|
1141 | 1141 | } |
1142 | 1142 | |
1143 | 1143 | // Retrieve response. |
1144 | 1144 | $response = sprintf( |
1145 | 1145 | '<input type="hidden" name="%s[%s]" value="%s" />', |
1146 | - esc_attr( sanitize_text_field( $_POST['field_name'] ) ), |
|
1147 | - esc_url( $uploaded['url'] ), |
|
1148 | - esc_attr( sanitize_text_field( strtolower( $_FILES['file']['name'] ) ) ) |
|
1146 | + esc_attr(sanitize_text_field($_POST['field_name'])), |
|
1147 | + esc_url($uploaded['url']), |
|
1148 | + esc_attr(sanitize_text_field(strtolower($_FILES['file']['name']))) |
|
1149 | 1149 | ); |
1150 | 1150 | |
1151 | - wp_send_json_success( $response ); |
|
1151 | + wp_send_json_success($response); |
|
1152 | 1152 | |
1153 | 1153 | } |
1154 | 1154 |
@@ -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 itemss class |
@@ -23,37 +23,37 @@ 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 | $data = $submission->get_data(); |
29 | 29 | $payment_form = $submission->get_payment_form(); |
30 | 30 | |
31 | 31 | // Prepare the selected items. |
32 | 32 | $selected_items = array(); |
33 | - if ( ! empty( $data['getpaid-items'] ) ) { |
|
34 | - $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
33 | + if (!empty($data['getpaid-items'])) { |
|
34 | + $selected_items = wpinv_clean($data['getpaid-items']); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | // (Maybe) set form items. |
38 | - if ( isset( $data['getpaid-form-items'] ) ) { |
|
38 | + if (isset($data['getpaid-form-items'])) { |
|
39 | 39 | |
40 | 40 | // Confirm items key. |
41 | - $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
42 | - if ( ! isset( $data['getpaid-form-items-key'] ) || $data['getpaid-form-items-key'] !== md5( NONCE_KEY . AUTH_KEY . $form_items ) ) { |
|
43 | - throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) ); |
|
41 | + $form_items = wpinv_clean($data['getpaid-form-items']); |
|
42 | + if (!isset($data['getpaid-form-items-key']) || $data['getpaid-form-items-key'] !== md5(NONCE_KEY . AUTH_KEY . $form_items)) { |
|
43 | + throw new Exception(__('We could not validate the form items. Please reload the page and try again.', 'invoicing')); |
|
44 | 44 | } |
45 | 45 | |
46 | - $items = array(); |
|
46 | + $items = array(); |
|
47 | 47 | $item_ids = array(); |
48 | 48 | |
49 | - foreach ( getpaid_convert_items_to_array( $form_items ) as $item_id => $qty ) { |
|
50 | - if ( ! in_array( $item_id, $item_ids ) ) { |
|
51 | - $item = new GetPaid_Form_Item( $item_id ); |
|
52 | - $item->set_quantity( $qty ); |
|
49 | + foreach (getpaid_convert_items_to_array($form_items) as $item_id => $qty) { |
|
50 | + if (!in_array($item_id, $item_ids)) { |
|
51 | + $item = new GetPaid_Form_Item($item_id); |
|
52 | + $item->set_quantity($qty); |
|
53 | 53 | |
54 | - if ( 0 == $qty ) { |
|
55 | - $item->set_allow_quantities( true ); |
|
56 | - $item->set_is_required( false ); |
|
54 | + if (0 == $qty) { |
|
55 | + $item->set_allow_quantities(true); |
|
56 | + $item->set_is_required(false); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | $item_ids[] = $item->get_id(); |
@@ -61,23 +61,23 @@ discard block |
||
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
64 | - if ( ! $payment_form->is_default() ) { |
|
64 | + if (!$payment_form->is_default()) { |
|
65 | 65 | |
66 | - foreach ( $payment_form->get_items() as $item ) { |
|
67 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
66 | + foreach ($payment_form->get_items() as $item) { |
|
67 | + if (!in_array($item->get_id(), $item_ids)) { |
|
68 | 68 | $item_ids[] = $item->get_id(); |
69 | 69 | $items[] = $item; |
70 | 70 | } |
71 | 71 | } |
72 | 72 | } |
73 | 73 | |
74 | - $payment_form->set_items( $items ); |
|
74 | + $payment_form->set_items($items); |
|
75 | 75 | |
76 | 76 | } |
77 | 77 | |
78 | 78 | // Process each individual item. |
79 | - foreach ( $payment_form->get_items() as $item ) { |
|
80 | - $this->process_item( $item, $selected_items, $submission ); |
|
79 | + foreach ($payment_form->get_items() as $item) { |
|
80 | + $this->process_item($item, $selected_items, $submission); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | } |
@@ -89,40 +89,40 @@ discard block |
||
89 | 89 | * @param array $selected_items |
90 | 90 | * @param GetPaid_Payment_Form_Submission $submission |
91 | 91 | */ |
92 | - public function process_item( $item, $selected_items, $submission ) { |
|
92 | + public function process_item($item, $selected_items, $submission) { |
|
93 | 93 | |
94 | 94 | // Abort if this is an optional item and it has not been selected. |
95 | - if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
95 | + if (!$item->is_required() && !isset($selected_items[$item->get_id()])) { |
|
96 | 96 | return; |
97 | 97 | } |
98 | 98 | |
99 | 99 | // (maybe) let customers change the quantities and prices. |
100 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
100 | + if (isset($selected_items[$item->get_id()])) { |
|
101 | 101 | |
102 | 102 | // Maybe change the quantities. |
103 | - if ( $item->allows_quantities() ) { |
|
104 | - $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
103 | + if ($item->allows_quantities()) { |
|
104 | + $item->set_quantity((float) $selected_items[$item->get_id()]['quantity']); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | // Maybe change the price. |
108 | - if ( $item->user_can_set_their_price() ) { |
|
109 | - $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
108 | + if ($item->user_can_set_their_price()) { |
|
109 | + $price = (float) wpinv_sanitize_amount($selected_items[$item->get_id()]['price']); |
|
110 | 110 | |
111 | - if ( $item->get_minimum_price() > $price ) { |
|
112 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) ); |
|
111 | + if ($item->get_minimum_price() > $price) { |
|
112 | + throw new Exception(sprintf(__('The minimum allowed amount is %s', 'invoicing'), getpaid_unstandardize_amount($item->get_minimum_price()))); |
|
113 | 113 | } |
114 | 114 | |
115 | - $item->set_price( $price ); |
|
115 | + $item->set_price($price); |
|
116 | 116 | |
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | - if ( 0 == $item->get_quantity() ) { |
|
120 | + if (0 == $item->get_quantity()) { |
|
121 | 121 | return; |
122 | 122 | } |
123 | 123 | |
124 | 124 | // Save the item. |
125 | - $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item', $item, $submission ); |
|
125 | + $this->items[] = apply_filters('getpaid_payment_form_submission_processed_item', $item, $submission); |
|
126 | 126 | |
127 | 127 | } |
128 | 128 |