@@ -14,70 +14,70 @@ discard block |
||
14 | 14 | class WPInv_Ajax { |
15 | 15 | |
16 | 16 | /** |
17 | - * Hook in ajax handlers. |
|
18 | - */ |
|
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 ); |
|
22 | - self::add_ajax_events(); |
|
17 | + * Hook in ajax handlers. |
|
18 | + */ |
|
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 ); |
|
22 | + self::add_ajax_events(); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
26 | - * Set GetPaid AJAX constant and headers. |
|
27 | - */ |
|
28 | - public static function define_ajax() { |
|
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 ); |
|
35 | - } |
|
36 | - $GLOBALS['wpdb']->hide_errors(); |
|
37 | - } |
|
26 | + * Set GetPaid AJAX constant and headers. |
|
27 | + */ |
|
28 | + public static function define_ajax() { |
|
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 ); |
|
35 | + } |
|
36 | + $GLOBALS['wpdb']->hide_errors(); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | - * Send headers for GetPaid Ajax Requests. |
|
43 | - * |
|
44 | - * @since 1.0.18 |
|
45 | - */ |
|
46 | - private static function wpinv_ajax_headers() { |
|
47 | - if ( ! headers_sent() ) { |
|
48 | - send_origin_headers(); |
|
49 | - send_nosniff_header(); |
|
50 | - nocache_headers(); |
|
51 | - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | - header( 'X-Robots-Tag: noindex' ); |
|
53 | - status_header( 200 ); |
|
54 | - } |
|
42 | + * Send headers for GetPaid Ajax Requests. |
|
43 | + * |
|
44 | + * @since 1.0.18 |
|
45 | + */ |
|
46 | + private static function wpinv_ajax_headers() { |
|
47 | + if ( ! headers_sent() ) { |
|
48 | + send_origin_headers(); |
|
49 | + send_nosniff_header(); |
|
50 | + nocache_headers(); |
|
51 | + header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | + header( 'X-Robots-Tag: noindex' ); |
|
53 | + status_header( 200 ); |
|
54 | + } |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | - * Check for GetPaid Ajax request and fire action. |
|
59 | - */ |
|
60 | - public static function do_wpinv_ajax() { |
|
61 | - global $wp_query; |
|
58 | + * Check for GetPaid Ajax request and fire action. |
|
59 | + */ |
|
60 | + public static function do_wpinv_ajax() { |
|
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'] ) ) ); |
|
65 | - } |
|
63 | + if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | + $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
65 | + } |
|
66 | 66 | |
67 | - $action = $wp_query->get( 'wpinv-ajax' ); |
|
67 | + $action = $wp_query->get( 'wpinv-ajax' ); |
|
68 | 68 | |
69 | - if ( $action ) { |
|
70 | - self::wpinv_ajax_headers(); |
|
71 | - $action = sanitize_text_field( $action ); |
|
72 | - do_action( 'wpinv_ajax_' . $action ); |
|
73 | - wp_die(); |
|
74 | - } |
|
69 | + if ( $action ) { |
|
70 | + self::wpinv_ajax_headers(); |
|
71 | + $action = sanitize_text_field( $action ); |
|
72 | + do_action( 'wpinv_ajax_' . $action ); |
|
73 | + wp_die(); |
|
74 | + } |
|
75 | 75 | |
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | - * Hook in ajax methods. |
|
80 | - */ |
|
79 | + * Hook in ajax methods. |
|
80 | + */ |
|
81 | 81 | public static function add_ajax_events() { |
82 | 82 | |
83 | 83 | // array( 'event' => is_frontend ) |
@@ -258,11 +258,11 @@ discard block |
||
258 | 258 | global $getpaid_force_checkbox; |
259 | 259 | |
260 | 260 | // Is the request set up correctly? |
261 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) { |
|
262 | - aui()->alert( |
|
263 | - array( |
|
264 | - 'type' => 'warning', |
|
265 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
261 | + if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) { |
|
262 | + aui()->alert( |
|
263 | + array( |
|
264 | + 'type' => 'warning', |
|
265 | + 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
266 | 266 | ), |
267 | 267 | true |
268 | 268 | ); |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | } |
271 | 271 | |
272 | 272 | // Payment form or button? |
273 | - if ( ! empty( $_GET['form'] ) ) { |
|
273 | + if ( ! empty( $_GET['form'] ) ) { |
|
274 | 274 | $form = sanitize_text_field( urldecode( $_GET['form'] ) ); |
275 | 275 | |
276 | 276 | if ( false !== strpos( $form, '|' ) ) { |
@@ -323,10 +323,10 @@ discard block |
||
323 | 323 | getpaid_display_payment_form( $form ); |
324 | 324 | } |
325 | 325 | } elseif ( ! empty( $_GET['invoice'] ) ) { |
326 | - getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) ); |
|
326 | + getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) ); |
|
327 | 327 | } else { |
328 | - $items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) ); |
|
329 | - getpaid_display_item_payment_form( $items ); |
|
328 | + $items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) ); |
|
329 | + getpaid_display_item_payment_form( $items ); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | exit; |
@@ -643,7 +643,7 @@ discard block |
||
643 | 643 | if ( is_wp_error( $error ) ) { |
644 | 644 | $alert = $error->get_error_message(); |
645 | 645 | wp_send_json_success( compact( 'alert' ) ); |
646 | - } |
|
646 | + } |
|
647 | 647 | |
648 | 648 | // Update totals. |
649 | 649 | $invoice->recalculate_total(); |
@@ -1072,12 +1072,12 @@ discard block |
||
1072 | 1072 | } |
1073 | 1073 | |
1074 | 1074 | /** |
1075 | - * Handles file uploads. |
|
1076 | - * |
|
1077 | - * @since 1.0.0 |
|
1078 | - * @return void |
|
1079 | - */ |
|
1080 | - public static function file_upload() { |
|
1075 | + * Handles file uploads. |
|
1076 | + * |
|
1077 | + * @since 1.0.0 |
|
1078 | + * @return void |
|
1079 | + */ |
|
1080 | + public static function file_upload() { |
|
1081 | 1081 | |
1082 | 1082 | // Check nonce. |
1083 | 1083 | check_ajax_referer( 'getpaid_form_nonce' ); |
@@ -1138,7 +1138,7 @@ discard block |
||
1138 | 1138 | |
1139 | 1139 | wp_send_json_success( $response ); |
1140 | 1140 | |
1141 | - } |
|
1141 | + } |
|
1142 | 1142 | |
1143 | 1143 | } |
1144 | 1144 |
@@ -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,11 +258,11 @@ discard block |
||
258 | 258 | global $getpaid_force_checkbox; |
259 | 259 | |
260 | 260 | // Is the request set up correctly? |
261 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) { |
|
261 | + if (empty($_GET['form']) && empty($_GET['item']) && empty($_GET['invoice'])) { |
|
262 | 262 | aui()->alert( |
263 | 263 | array( |
264 | 264 | 'type' => 'warning', |
265 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
265 | + 'content' => __('No payment form or item provided', 'invoicing'), |
|
266 | 266 | ), |
267 | 267 | true |
268 | 268 | ); |
@@ -270,29 +270,29 @@ discard block |
||
270 | 270 | } |
271 | 271 | |
272 | 272 | // Payment form or button? |
273 | - if ( ! empty( $_GET['form'] ) ) { |
|
274 | - $form = sanitize_text_field( urldecode( $_GET['form'] ) ); |
|
273 | + if (!empty($_GET['form'])) { |
|
274 | + $form = sanitize_text_field(urldecode($_GET['form'])); |
|
275 | 275 | |
276 | - if ( false !== strpos( $form, '|' ) ) { |
|
277 | - $form_pos = strpos( $form, '|' ); |
|
278 | - $_items = getpaid_convert_items_to_array( substr( $form, $form_pos + 1 ) ); |
|
279 | - $form = substr( $form, 0, $form_pos ); |
|
276 | + if (false !== strpos($form, '|')) { |
|
277 | + $form_pos = strpos($form, '|'); |
|
278 | + $_items = getpaid_convert_items_to_array(substr($form, $form_pos + 1)); |
|
279 | + $form = substr($form, 0, $form_pos); |
|
280 | 280 | |
281 | 281 | // Retrieve appropriate payment form. |
282 | - $payment_form = new GetPaid_Payment_Form( $form ); |
|
283 | - $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
282 | + $payment_form = new GetPaid_Payment_Form($form); |
|
283 | + $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
284 | 284 | |
285 | 285 | $items = array(); |
286 | 286 | $item_ids = array(); |
287 | 287 | |
288 | - foreach ( $_items as $item_id => $qty ) { |
|
289 | - if ( ! in_array( $item_id, $item_ids ) ) { |
|
290 | - $item = new GetPaid_Form_Item( $item_id ); |
|
291 | - $item->set_quantity( $qty ); |
|
288 | + foreach ($_items as $item_id => $qty) { |
|
289 | + if (!in_array($item_id, $item_ids)) { |
|
290 | + $item = new GetPaid_Form_Item($item_id); |
|
291 | + $item->set_quantity($qty); |
|
292 | 292 | |
293 | - if ( 0 == $qty ) { |
|
294 | - $item->set_allow_quantities( true ); |
|
295 | - $item->set_is_required( false ); |
|
293 | + if (0 == $qty) { |
|
294 | + $item->set_allow_quantities(true); |
|
295 | + $item->set_is_required(false); |
|
296 | 296 | $getpaid_force_checkbox = true; |
297 | 297 | } |
298 | 298 | |
@@ -301,32 +301,32 @@ discard block |
||
301 | 301 | } |
302 | 302 | } |
303 | 303 | |
304 | - if ( ! $payment_form->is_default() ) { |
|
304 | + if (!$payment_form->is_default()) { |
|
305 | 305 | |
306 | - foreach ( $payment_form->get_items() as $item ) { |
|
307 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
306 | + foreach ($payment_form->get_items() as $item) { |
|
307 | + if (!in_array($item->get_id(), $item_ids)) { |
|
308 | 308 | $item_ids[] = $item->get_id(); |
309 | 309 | $items[] = $item; |
310 | 310 | } |
311 | 311 | } |
312 | 312 | } |
313 | 313 | |
314 | - $payment_form->set_items( $items ); |
|
315 | - $extra_items = esc_attr( getpaid_convert_items_to_string( $_items ) ); |
|
316 | - $extra_items_key = md5( NONCE_KEY . AUTH_KEY . $extra_items ); |
|
314 | + $payment_form->set_items($items); |
|
315 | + $extra_items = esc_attr(getpaid_convert_items_to_string($_items)); |
|
316 | + $extra_items_key = md5(NONCE_KEY . AUTH_KEY . $extra_items); |
|
317 | 317 | $extra_items = "<input type='hidden' name='getpaid-form-items' value='$extra_items' />"; |
318 | 318 | $extra_items .= "<input type='hidden' name='getpaid-form-items-key' value='$extra_items_key' />"; |
319 | - $payment_form->display( $extra_items ); |
|
319 | + $payment_form->display($extra_items); |
|
320 | 320 | $getpaid_force_checkbox = false; |
321 | 321 | |
322 | 322 | } else { |
323 | - getpaid_display_payment_form( $form ); |
|
323 | + getpaid_display_payment_form($form); |
|
324 | 324 | } |
325 | -} elseif ( ! empty( $_GET['invoice'] ) ) { |
|
326 | - getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) ); |
|
325 | +} elseif (!empty($_GET['invoice'])) { |
|
326 | + getpaid_display_invoice_payment_form((int) urldecode($_GET['invoice'])); |
|
327 | 327 | } else { |
328 | - $items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) ); |
|
329 | - getpaid_display_item_payment_form( $items ); |
|
328 | + $items = getpaid_convert_items_to_array(sanitize_text_field(urldecode($_GET['item']))); |
|
329 | + getpaid_display_item_payment_form($items); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | exit; |
@@ -341,14 +341,14 @@ discard block |
||
341 | 341 | public static function payment_form() { |
342 | 342 | |
343 | 343 | // ... form fields... |
344 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
345 | - esc_html_e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
344 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
345 | + esc_html_e('Error: Reload the page and try again.', 'invoicing'); |
|
346 | 346 | exit; |
347 | 347 | } |
348 | 348 | |
349 | 349 | // Process the payment form. |
350 | - $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' ); |
|
351 | - $checkout = new $checkout_class( new GetPaid_Payment_Form_Submission() ); |
|
350 | + $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout'); |
|
351 | + $checkout = new $checkout_class(new GetPaid_Payment_Form_Submission()); |
|
352 | 352 | $checkout->process_checkout(); |
353 | 353 | |
354 | 354 | exit; |
@@ -361,55 +361,55 @@ discard block |
||
361 | 361 | */ |
362 | 362 | public static function get_payment_form_states_field() { |
363 | 363 | |
364 | - if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) { |
|
364 | + if (empty($_GET['country']) || empty($_GET['form'])) { |
|
365 | 365 | exit; |
366 | 366 | } |
367 | 367 | |
368 | - $elements = getpaid_get_payment_form_elements( (int) $_GET['form'] ); |
|
368 | + $elements = getpaid_get_payment_form_elements((int) $_GET['form']); |
|
369 | 369 | |
370 | - if ( empty( $elements ) ) { |
|
370 | + if (empty($elements)) { |
|
371 | 371 | exit; |
372 | 372 | } |
373 | 373 | |
374 | 374 | $address_fields = array(); |
375 | - foreach ( $elements as $element ) { |
|
376 | - if ( 'address' === $element['type'] ) { |
|
375 | + foreach ($elements as $element) { |
|
376 | + if ('address' === $element['type']) { |
|
377 | 377 | $address_fields = $element; |
378 | 378 | break; |
379 | 379 | } |
380 | 380 | } |
381 | 381 | |
382 | - if ( empty( $address_fields ) ) { |
|
382 | + if (empty($address_fields)) { |
|
383 | 383 | exit; |
384 | 384 | } |
385 | 385 | |
386 | - foreach ( $address_fields['fields'] as $address_field ) { |
|
386 | + foreach ($address_fields['fields'] as $address_field) { |
|
387 | 387 | |
388 | - if ( 'wpinv_state' == $address_field['name'] ) { |
|
388 | + if ('wpinv_state' == $address_field['name']) { |
|
389 | 389 | |
390 | - $wrap_class = getpaid_get_form_element_grid_class( $address_field ); |
|
391 | - $wrap_class = esc_attr( "$wrap_class getpaid-address-field-wrapper" ); |
|
392 | - $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] ); |
|
393 | - $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] ); |
|
394 | - $value = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : ''; |
|
395 | - $label = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] ); |
|
390 | + $wrap_class = getpaid_get_form_element_grid_class($address_field); |
|
391 | + $wrap_class = esc_attr("$wrap_class getpaid-address-field-wrapper"); |
|
392 | + $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']); |
|
393 | + $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']); |
|
394 | + $value = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : ''; |
|
395 | + $label = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']); |
|
396 | 396 | |
397 | - if ( ! empty( $address_field['required'] ) ) { |
|
397 | + if (!empty($address_field['required'])) { |
|
398 | 398 | $label .= "<span class='text-danger'> *</span>"; |
399 | 399 | } |
400 | 400 | |
401 | 401 | $html = getpaid_get_states_select_markup( |
402 | - sanitize_text_field( $_GET['country'] ), |
|
402 | + sanitize_text_field($_GET['country']), |
|
403 | 403 | $value, |
404 | 404 | $placeholder, |
405 | 405 | $label, |
406 | 406 | $description, |
407 | - ! empty( $address_field['required'] ), |
|
407 | + !empty($address_field['required']), |
|
408 | 408 | $wrap_class, |
409 | - sanitize_text_field( $_GET['name'] ) |
|
409 | + sanitize_text_field($_GET['name']) |
|
410 | 410 | ); |
411 | 411 | |
412 | - wp_send_json_success( $html ); |
|
412 | + wp_send_json_success($html); |
|
413 | 413 | exit; |
414 | 414 | |
415 | 415 | } |
@@ -424,66 +424,66 @@ discard block |
||
424 | 424 | public static function recalculate_invoice_totals() { |
425 | 425 | |
426 | 426 | // Verify nonce. |
427 | - check_ajax_referer( 'wpinv-nonce' ); |
|
427 | + check_ajax_referer('wpinv-nonce'); |
|
428 | 428 | |
429 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
429 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
430 | 430 | exit; |
431 | 431 | } |
432 | 432 | |
433 | 433 | // We need an invoice. |
434 | - if ( empty( $_POST['post_id'] ) ) { |
|
434 | + if (empty($_POST['post_id'])) { |
|
435 | 435 | exit; |
436 | 436 | } |
437 | 437 | |
438 | 438 | // Fetch the invoice. |
439 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
439 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
440 | 440 | |
441 | 441 | // Ensure it exists. |
442 | - if ( ! $invoice->get_id() ) { |
|
442 | + if (!$invoice->get_id()) { |
|
443 | 443 | exit; |
444 | 444 | } |
445 | 445 | |
446 | 446 | // Maybe set the country, state, currency. |
447 | - foreach ( array( 'country', 'state', 'currency', 'vat_number', 'discount_code' ) as $key ) { |
|
448 | - if ( isset( $_POST[ $key ] ) ) { |
|
447 | + foreach (array('country', 'state', 'currency', 'vat_number', 'discount_code') as $key) { |
|
448 | + if (isset($_POST[$key])) { |
|
449 | 449 | $method = "set_$key"; |
450 | - $invoice->$method( sanitize_text_field( $_POST[ $key ] ) ); |
|
450 | + $invoice->$method(sanitize_text_field($_POST[$key])); |
|
451 | 451 | } |
452 | 452 | } |
453 | 453 | |
454 | 454 | // Maybe disable taxes. |
455 | - $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) ); |
|
455 | + $invoice->set_disable_taxes(!empty($_POST['taxes'])); |
|
456 | 456 | |
457 | 457 | // Discount code. |
458 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
459 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
460 | - if ( $discount->exists() ) { |
|
461 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
458 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
459 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
460 | + if ($discount->exists()) { |
|
461 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
462 | 462 | } else { |
463 | - $invoice->remove_discount( 'discount_code' ); |
|
463 | + $invoice->remove_discount('discount_code'); |
|
464 | 464 | } |
465 | 465 | } |
466 | 466 | |
467 | 467 | // Recalculate totals. |
468 | 468 | $invoice->recalculate_total(); |
469 | 469 | |
470 | - $total = wpinv_price( $invoice->get_total(), $invoice->get_currency() ); |
|
471 | - $suscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
472 | - if ( is_a( $suscriptions, 'WPInv_Subscription' ) && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) { |
|
473 | - $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() ); |
|
474 | - $total .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>'; |
|
470 | + $total = wpinv_price($invoice->get_total(), $invoice->get_currency()); |
|
471 | + $suscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
472 | + if (is_a($suscriptions, 'WPInv_Subscription') && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) { |
|
473 | + $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency()); |
|
474 | + $total .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>'; |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | $totals = array( |
478 | - 'subtotal' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ), |
|
479 | - 'discount' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ), |
|
480 | - 'tax' => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ), |
|
478 | + 'subtotal' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()), |
|
479 | + 'discount' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()), |
|
480 | + 'tax' => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()), |
|
481 | 481 | 'total' => $total, |
482 | 482 | ); |
483 | 483 | |
484 | - $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice ); |
|
484 | + $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice); |
|
485 | 485 | |
486 | - wp_send_json_success( compact( 'totals' ) ); |
|
486 | + wp_send_json_success(compact('totals')); |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | /** |
@@ -492,33 +492,33 @@ discard block |
||
492 | 492 | public static function get_invoice_items() { |
493 | 493 | |
494 | 494 | // Verify nonce. |
495 | - check_ajax_referer( 'wpinv-nonce' ); |
|
495 | + check_ajax_referer('wpinv-nonce'); |
|
496 | 496 | |
497 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
497 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
498 | 498 | exit; |
499 | 499 | } |
500 | 500 | |
501 | 501 | // We need an invoice and items. |
502 | - if ( empty( $_POST['post_id'] ) ) { |
|
502 | + if (empty($_POST['post_id'])) { |
|
503 | 503 | exit; |
504 | 504 | } |
505 | 505 | |
506 | 506 | // Fetch the invoice. |
507 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
507 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
508 | 508 | |
509 | 509 | // Ensure it exists. |
510 | - if ( ! $invoice->get_id() ) { |
|
510 | + if (!$invoice->get_id()) { |
|
511 | 511 | exit; |
512 | 512 | } |
513 | 513 | |
514 | 514 | // Return an array of invoice items. |
515 | 515 | $items = array(); |
516 | 516 | |
517 | - foreach ( $invoice->get_items() as $item ) { |
|
518 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency(), $invoice->is_renewal() ); |
|
517 | + foreach ($invoice->get_items() as $item) { |
|
518 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency(), $invoice->is_renewal()); |
|
519 | 519 | } |
520 | 520 | |
521 | - wp_send_json_success( compact( 'items' ) ); |
|
521 | + wp_send_json_success(compact('items')); |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | /** |
@@ -527,50 +527,50 @@ discard block |
||
527 | 527 | public static function edit_invoice_item() { |
528 | 528 | |
529 | 529 | // Verify nonce. |
530 | - check_ajax_referer( 'wpinv-nonce' ); |
|
530 | + check_ajax_referer('wpinv-nonce'); |
|
531 | 531 | |
532 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
532 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
533 | 533 | exit; |
534 | 534 | } |
535 | 535 | |
536 | 536 | // We need an invoice and item details. |
537 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) { |
|
537 | + if (empty($_POST['post_id']) || empty($_POST['data'])) { |
|
538 | 538 | exit; |
539 | 539 | } |
540 | 540 | |
541 | 541 | // Fetch the invoice. |
542 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
542 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
543 | 543 | |
544 | 544 | // Ensure it exists and its not been paid for. |
545 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
545 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
546 | 546 | exit; |
547 | 547 | } |
548 | 548 | |
549 | 549 | // Format the data. |
550 | - $data = wp_kses_post_deep( wp_unslash( wp_list_pluck( $_POST['data'], 'value', 'field' ) ) ); |
|
550 | + $data = wp_kses_post_deep(wp_unslash(wp_list_pluck($_POST['data'], 'value', 'field'))); |
|
551 | 551 | |
552 | 552 | // Ensure that we have an item id. |
553 | - if ( empty( $data['id'] ) ) { |
|
553 | + if (empty($data['id'])) { |
|
554 | 554 | exit; |
555 | 555 | } |
556 | 556 | |
557 | 557 | // Abort if the invoice does not have the specified item. |
558 | - $item = $invoice->get_item( (int) $data['id'] ); |
|
558 | + $item = $invoice->get_item((int) $data['id']); |
|
559 | 559 | |
560 | - if ( empty( $item ) ) { |
|
560 | + if (empty($item)) { |
|
561 | 561 | exit; |
562 | 562 | } |
563 | 563 | |
564 | 564 | // Update the item. |
565 | - $item->set_price( getpaid_standardize_amount( $data['price'] ) ); |
|
566 | - $item->set_name( sanitize_text_field( $data['name'] ) ); |
|
567 | - $item->set_description( wp_kses_post( $data['description'] ) ); |
|
568 | - $item->set_quantity( floatval( $data['quantity'] ) ); |
|
565 | + $item->set_price(getpaid_standardize_amount($data['price'])); |
|
566 | + $item->set_name(sanitize_text_field($data['name'])); |
|
567 | + $item->set_description(wp_kses_post($data['description'])); |
|
568 | + $item->set_quantity(floatval($data['quantity'])); |
|
569 | 569 | |
570 | 570 | // Add it to the invoice. |
571 | - $error = $invoice->add_item( $item ); |
|
571 | + $error = $invoice->add_item($item); |
|
572 | 572 | $alert = false; |
573 | - if ( is_wp_error( $error ) ) { |
|
573 | + if (is_wp_error($error)) { |
|
574 | 574 | $alert = $error->get_error_message(); |
575 | 575 | } |
576 | 576 | |
@@ -583,11 +583,11 @@ discard block |
||
583 | 583 | // Return an array of invoice items. |
584 | 584 | $items = array(); |
585 | 585 | |
586 | - foreach ( $invoice->get_items() as $item ) { |
|
587 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
586 | + foreach ($invoice->get_items() as $item) { |
|
587 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
588 | 588 | } |
589 | 589 | |
590 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
590 | + wp_send_json_success(compact('items', 'alert')); |
|
591 | 591 | } |
592 | 592 | |
593 | 593 | /** |
@@ -596,53 +596,53 @@ discard block |
||
596 | 596 | public static function create_invoice_item() { |
597 | 597 | |
598 | 598 | // Verify nonce. |
599 | - check_ajax_referer( 'wpinv-nonce' ); |
|
599 | + check_ajax_referer('wpinv-nonce'); |
|
600 | 600 | |
601 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
601 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
602 | 602 | exit; |
603 | 603 | } |
604 | 604 | |
605 | 605 | // We need an invoice and item details. |
606 | - if ( empty( $_POST['invoice_id'] ) || empty( $_POST['_wpinv_quick'] ) ) { |
|
606 | + if (empty($_POST['invoice_id']) || empty($_POST['_wpinv_quick'])) { |
|
607 | 607 | exit; |
608 | 608 | } |
609 | 609 | |
610 | 610 | // Fetch the invoice. |
611 | - $invoice = new WPInv_Invoice( intval( $_POST['invoice_id'] ) ); |
|
611 | + $invoice = new WPInv_Invoice(intval($_POST['invoice_id'])); |
|
612 | 612 | |
613 | 613 | // Ensure it exists and its not been paid for. |
614 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
614 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
615 | 615 | exit; |
616 | 616 | } |
617 | 617 | |
618 | 618 | // Format the data. |
619 | - $data = wp_kses_post_deep( wp_unslash( $_POST['_wpinv_quick'] ) ); |
|
619 | + $data = wp_kses_post_deep(wp_unslash($_POST['_wpinv_quick'])); |
|
620 | 620 | |
621 | 621 | $item = new WPInv_Item(); |
622 | - $item->set_price( getpaid_standardize_amount( $data['price'] ) ); |
|
623 | - $item->set_name( sanitize_text_field( $data['name'] ) ); |
|
624 | - $item->set_description( wp_kses_post( $data['description'] ) ); |
|
625 | - $item->set_type( sanitize_text_field( $data['type'] ) ); |
|
626 | - $item->set_vat_rule( sanitize_text_field( $data['vat_rule'] ) ); |
|
627 | - $item->set_vat_class( sanitize_text_field( $data['vat_class'] ) ); |
|
628 | - $item->set_status( 'publish' ); |
|
622 | + $item->set_price(getpaid_standardize_amount($data['price'])); |
|
623 | + $item->set_name(sanitize_text_field($data['name'])); |
|
624 | + $item->set_description(wp_kses_post($data['description'])); |
|
625 | + $item->set_type(sanitize_text_field($data['type'])); |
|
626 | + $item->set_vat_rule(sanitize_text_field($data['vat_rule'])); |
|
627 | + $item->set_vat_class(sanitize_text_field($data['vat_class'])); |
|
628 | + $item->set_status('publish'); |
|
629 | 629 | $item->save(); |
630 | 630 | |
631 | - if ( ! $item->exists() ) { |
|
632 | - $alert = __( 'Could not create invoice item. Please try again.', 'invoicing' ); |
|
633 | - wp_send_json_success( compact( 'alert' ) ); |
|
631 | + if (!$item->exists()) { |
|
632 | + $alert = __('Could not create invoice item. Please try again.', 'invoicing'); |
|
633 | + wp_send_json_success(compact('alert')); |
|
634 | 634 | } |
635 | 635 | |
636 | - $item = new GetPaid_Form_Item( $item->get_id() ); |
|
637 | - $item->set_quantity( floatval( $data['qty'] ) ); |
|
636 | + $item = new GetPaid_Form_Item($item->get_id()); |
|
637 | + $item->set_quantity(floatval($data['qty'])); |
|
638 | 638 | |
639 | 639 | // Add it to the invoice. |
640 | - $error = $invoice->add_item( $item ); |
|
640 | + $error = $invoice->add_item($item); |
|
641 | 641 | $alert = false; |
642 | 642 | |
643 | - if ( is_wp_error( $error ) ) { |
|
643 | + if (is_wp_error($error)) { |
|
644 | 644 | $alert = $error->get_error_message(); |
645 | - wp_send_json_success( compact( 'alert' ) ); |
|
645 | + wp_send_json_success(compact('alert')); |
|
646 | 646 | } |
647 | 647 | |
648 | 648 | // Update totals. |
@@ -655,9 +655,9 @@ discard block |
||
655 | 655 | $invoice->recalculate_total(); |
656 | 656 | $invoice->save(); |
657 | 657 | ob_start(); |
658 | - GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice ); |
|
658 | + GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice); |
|
659 | 659 | $row = ob_get_clean(); |
660 | - wp_send_json_success( compact( 'row' ) ); |
|
660 | + wp_send_json_success(compact('row')); |
|
661 | 661 | } |
662 | 662 | |
663 | 663 | /** |
@@ -666,33 +666,33 @@ discard block |
||
666 | 666 | public static function remove_invoice_item() { |
667 | 667 | |
668 | 668 | // Verify nonce. |
669 | - check_ajax_referer( 'wpinv-nonce' ); |
|
669 | + check_ajax_referer('wpinv-nonce'); |
|
670 | 670 | |
671 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
671 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
672 | 672 | exit; |
673 | 673 | } |
674 | 674 | |
675 | 675 | // We need an invoice and an item. |
676 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
676 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
677 | 677 | exit; |
678 | 678 | } |
679 | 679 | |
680 | 680 | // Fetch the invoice. |
681 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
681 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
682 | 682 | |
683 | 683 | // Ensure it exists and its not been paid for. |
684 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
684 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
685 | 685 | exit; |
686 | 686 | } |
687 | 687 | |
688 | 688 | // Abort if the invoice does not have the specified item. |
689 | - $item = $invoice->get_item( (int) $_POST['item_id'] ); |
|
689 | + $item = $invoice->get_item((int) $_POST['item_id']); |
|
690 | 690 | |
691 | - if ( empty( $item ) ) { |
|
691 | + if (empty($item)) { |
|
692 | 692 | exit; |
693 | 693 | } |
694 | 694 | |
695 | - $invoice->remove_item( (int) $_POST['item_id'] ); |
|
695 | + $invoice->remove_item((int) $_POST['item_id']); |
|
696 | 696 | |
697 | 697 | // Update totals. |
698 | 698 | $invoice->recalculate_total(); |
@@ -703,11 +703,11 @@ discard block |
||
703 | 703 | // Return an array of invoice items. |
704 | 704 | $items = array(); |
705 | 705 | |
706 | - foreach ( $invoice->get_items() as $item ) { |
|
707 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
706 | + foreach ($invoice->get_items() as $item) { |
|
707 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
708 | 708 | } |
709 | 709 | |
710 | - wp_send_json_success( compact( 'items' ) ); |
|
710 | + wp_send_json_success(compact('items')); |
|
711 | 711 | } |
712 | 712 | |
713 | 713 | /** |
@@ -716,68 +716,68 @@ discard block |
||
716 | 716 | public static function recalculate_full_prices() { |
717 | 717 | |
718 | 718 | // Verify nonce. |
719 | - check_ajax_referer( 'wpinv-nonce' ); |
|
719 | + check_ajax_referer('wpinv-nonce'); |
|
720 | 720 | |
721 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
721 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
722 | 722 | exit; |
723 | 723 | } |
724 | 724 | |
725 | 725 | // We need an invoice and item. |
726 | - if ( empty( $_POST['post_id'] ) ) { |
|
726 | + if (empty($_POST['post_id'])) { |
|
727 | 727 | exit; |
728 | 728 | } |
729 | 729 | |
730 | 730 | // Fetch the invoice. |
731 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
731 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
732 | 732 | $alert = false; |
733 | 733 | |
734 | 734 | // Ensure it exists and its not been paid for. |
735 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
735 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
736 | 736 | exit; |
737 | 737 | } |
738 | 738 | |
739 | - $invoice->set_items( array() ); |
|
739 | + $invoice->set_items(array()); |
|
740 | 740 | |
741 | - if ( ! empty( $_POST['getpaid_items'] ) ) { |
|
741 | + if (!empty($_POST['getpaid_items'])) { |
|
742 | 742 | |
743 | - foreach ( wp_kses_post_deep( $_POST['getpaid_items'] ) as $item_id => $args ) { |
|
744 | - $item = new GetPaid_Form_Item( $item_id ); |
|
743 | + foreach (wp_kses_post_deep($_POST['getpaid_items']) as $item_id => $args) { |
|
744 | + $item = new GetPaid_Form_Item($item_id); |
|
745 | 745 | |
746 | - if ( $item->exists() ) { |
|
747 | - $item->set_price( getpaid_standardize_amount( $args['price'] ) ); |
|
748 | - $item->set_quantity( floatval( $args['quantity'] ) ); |
|
749 | - $item->set_name( sanitize_text_field( $args['name'] ) ); |
|
750 | - $item->set_description( wp_kses_post( $args['description'] ) ); |
|
751 | - $invoice->add_item( $item ); |
|
746 | + if ($item->exists()) { |
|
747 | + $item->set_price(getpaid_standardize_amount($args['price'])); |
|
748 | + $item->set_quantity(floatval($args['quantity'])); |
|
749 | + $item->set_name(sanitize_text_field($args['name'])); |
|
750 | + $item->set_description(wp_kses_post($args['description'])); |
|
751 | + $invoice->add_item($item); |
|
752 | 752 | } |
753 | 753 | } |
754 | 754 | } |
755 | 755 | |
756 | - $invoice->set_disable_taxes( ! empty( $_POST['disable_taxes'] ) ); |
|
756 | + $invoice->set_disable_taxes(!empty($_POST['disable_taxes'])); |
|
757 | 757 | |
758 | 758 | // Maybe set the country, state, currency. |
759 | - foreach ( array( 'wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code' ) as $key ) { |
|
760 | - if ( isset( $_POST[ $key ] ) ) { |
|
761 | - $_key = str_replace( 'wpinv_', '', $key ); |
|
759 | + foreach (array('wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code') as $key) { |
|
760 | + if (isset($_POST[$key])) { |
|
761 | + $_key = str_replace('wpinv_', '', $key); |
|
762 | 762 | $method = "set_$_key"; |
763 | - $invoice->$method( sanitize_text_field( $_POST[ $key ] ) ); |
|
763 | + $invoice->$method(sanitize_text_field($_POST[$key])); |
|
764 | 764 | } |
765 | 765 | } |
766 | 766 | |
767 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
768 | - if ( $discount->exists() ) { |
|
769 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
767 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
768 | + if ($discount->exists()) { |
|
769 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
770 | 770 | } else { |
771 | - $invoice->remove_discount( 'discount_code' ); |
|
771 | + $invoice->remove_discount('discount_code'); |
|
772 | 772 | } |
773 | 773 | |
774 | 774 | // Save the invoice. |
775 | 775 | $invoice->recalculate_total(); |
776 | 776 | $invoice->save(); |
777 | 777 | ob_start(); |
778 | - GetPaid_Meta_Box_Invoice_Items::output( get_post( $invoice->get_id() ), $invoice ); |
|
778 | + GetPaid_Meta_Box_Invoice_Items::output(get_post($invoice->get_id()), $invoice); |
|
779 | 779 | $table = ob_get_clean(); |
780 | - wp_send_json_success( compact( 'table' ) ); |
|
780 | + wp_send_json_success(compact('table')); |
|
781 | 781 | } |
782 | 782 | |
783 | 783 | /** |
@@ -786,42 +786,42 @@ discard block |
||
786 | 786 | public static function admin_add_invoice_item() { |
787 | 787 | |
788 | 788 | // Verify nonce. |
789 | - check_ajax_referer( 'wpinv-nonce' ); |
|
789 | + check_ajax_referer('wpinv-nonce'); |
|
790 | 790 | |
791 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
791 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
792 | 792 | exit; |
793 | 793 | } |
794 | 794 | |
795 | 795 | // We need an invoice and item. |
796 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
796 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
797 | 797 | exit; |
798 | 798 | } |
799 | 799 | |
800 | 800 | // Fetch the invoice. |
801 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
801 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
802 | 802 | $alert = false; |
803 | 803 | |
804 | 804 | // Ensure it exists and its not been paid for. |
805 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
805 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
806 | 806 | exit; |
807 | 807 | } |
808 | 808 | |
809 | 809 | // Add the item. |
810 | - $item = new GetPaid_Form_Item( (int) $_POST['item_id'] ); |
|
811 | - $error = $invoice->add_item( $item ); |
|
810 | + $item = new GetPaid_Form_Item((int) $_POST['item_id']); |
|
811 | + $error = $invoice->add_item($item); |
|
812 | 812 | |
813 | - if ( is_wp_error( $error ) ) { |
|
813 | + if (is_wp_error($error)) { |
|
814 | 814 | $alert = $error->get_error_message(); |
815 | - wp_send_json_success( compact( 'alert' ) ); |
|
815 | + wp_send_json_success(compact('alert')); |
|
816 | 816 | } |
817 | 817 | |
818 | 818 | // Save the invoice. |
819 | 819 | $invoice->recalculate_total(); |
820 | 820 | $invoice->save(); |
821 | 821 | ob_start(); |
822 | - GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice ); |
|
822 | + GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice); |
|
823 | 823 | $row = ob_get_clean(); |
824 | - wp_send_json_success( compact( 'row' ) ); |
|
824 | + wp_send_json_success(compact('row')); |
|
825 | 825 | } |
826 | 826 | |
827 | 827 | /** |
@@ -830,39 +830,39 @@ discard block |
||
830 | 830 | public static function add_invoice_items() { |
831 | 831 | |
832 | 832 | // Verify nonce. |
833 | - check_ajax_referer( 'wpinv-nonce' ); |
|
833 | + check_ajax_referer('wpinv-nonce'); |
|
834 | 834 | |
835 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
835 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
836 | 836 | exit; |
837 | 837 | } |
838 | 838 | |
839 | 839 | // We need an invoice and items. |
840 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) { |
|
840 | + if (empty($_POST['post_id']) || empty($_POST['items'])) { |
|
841 | 841 | exit; |
842 | 842 | } |
843 | 843 | |
844 | 844 | // Fetch the invoice. |
845 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
845 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
846 | 846 | $alert = false; |
847 | 847 | |
848 | 848 | // Ensure it exists and its not been paid for. |
849 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
849 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
850 | 850 | exit; |
851 | 851 | } |
852 | 852 | |
853 | 853 | // Add the items. |
854 | - foreach ( wp_kses_post_deep( wp_unslash( $_POST['items'] ) ) as $data ) { |
|
854 | + foreach (wp_kses_post_deep(wp_unslash($_POST['items'])) as $data) { |
|
855 | 855 | |
856 | - $item = new GetPaid_Form_Item( (int) $data['id'] ); |
|
856 | + $item = new GetPaid_Form_Item((int) $data['id']); |
|
857 | 857 | |
858 | - if ( is_numeric( $data['qty'] ) && (float) $data['qty'] > 0 ) { |
|
859 | - $item->set_quantity( floatval( $data['qty'] ) ); |
|
858 | + if (is_numeric($data['qty']) && (float) $data['qty'] > 0) { |
|
859 | + $item->set_quantity(floatval($data['qty'])); |
|
860 | 860 | } |
861 | 861 | |
862 | - if ( $item->get_id() > 0 ) { |
|
863 | - $error = $invoice->add_item( $item ); |
|
862 | + if ($item->get_id() > 0) { |
|
863 | + $error = $invoice->add_item($item); |
|
864 | 864 | |
865 | - if ( is_wp_error( $error ) ) { |
|
865 | + if (is_wp_error($error)) { |
|
866 | 866 | $alert = $error->get_error_message(); |
867 | 867 | } |
868 | 868 | } |
@@ -875,11 +875,11 @@ discard block |
||
875 | 875 | // Return an array of invoice items. |
876 | 876 | $items = array(); |
877 | 877 | |
878 | - foreach ( $invoice->get_items() as $item ) { |
|
879 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
878 | + foreach ($invoice->get_items() as $item) { |
|
879 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
880 | 880 | } |
881 | 881 | |
882 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
882 | + wp_send_json_success(compact('items', 'alert')); |
|
883 | 883 | } |
884 | 884 | |
885 | 885 | /** |
@@ -888,15 +888,15 @@ discard block |
||
888 | 888 | public static function get_invoicing_items() { |
889 | 889 | |
890 | 890 | // Verify nonce. |
891 | - check_ajax_referer( 'wpinv-nonce' ); |
|
891 | + check_ajax_referer('wpinv-nonce'); |
|
892 | 892 | |
893 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
893 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
894 | 894 | exit; |
895 | 895 | } |
896 | 896 | |
897 | 897 | // We need a search term. |
898 | - if ( empty( $_GET['search'] ) ) { |
|
899 | - wp_send_json_success( array() ); |
|
898 | + if (empty($_GET['search'])) { |
|
899 | + wp_send_json_success(array()); |
|
900 | 900 | } |
901 | 901 | |
902 | 902 | // Retrieve items. |
@@ -905,8 +905,8 @@ discard block |
||
905 | 905 | 'orderby' => 'title', |
906 | 906 | 'order' => 'ASC', |
907 | 907 | 'posts_per_page' => -1, |
908 | - 'post_status' => array( 'publish' ), |
|
909 | - 's' => sanitize_text_field( urldecode( $_GET['search'] ) ), |
|
908 | + 'post_status' => array('publish'), |
|
909 | + 's' => sanitize_text_field(urldecode($_GET['search'])), |
|
910 | 910 | 'meta_query' => array( |
911 | 911 | array( |
912 | 912 | 'key' => '_wpinv_type', |
@@ -916,25 +916,25 @@ discard block |
||
916 | 916 | ), |
917 | 917 | ); |
918 | 918 | |
919 | - if ( ! empty( $_GET['ignore'] ) ) { |
|
920 | - $item_args['exclude'] = wp_parse_id_list( sanitize_text_field( $_GET['ignore'] ) ); |
|
919 | + if (!empty($_GET['ignore'])) { |
|
920 | + $item_args['exclude'] = wp_parse_id_list(sanitize_text_field($_GET['ignore'])); |
|
921 | 921 | } |
922 | 922 | |
923 | - $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) ); |
|
923 | + $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args)); |
|
924 | 924 | $data = array(); |
925 | 925 | |
926 | - $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( (int) $_GET['post_id'] ) ); |
|
926 | + $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type((int) $_GET['post_id'])); |
|
927 | 927 | |
928 | - foreach ( $items as $item ) { |
|
929 | - $item = new GetPaid_Form_Item( $item ); |
|
928 | + foreach ($items as $item) { |
|
929 | + $item = new GetPaid_Form_Item($item); |
|
930 | 930 | $data[] = array( |
931 | 931 | 'id' => (int) $item->get_id(), |
932 | - 'text' => strip_tags( $item->get_name() ), |
|
933 | - 'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '', |
|
932 | + 'text' => strip_tags($item->get_name()), |
|
933 | + 'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '', |
|
934 | 934 | ); |
935 | 935 | } |
936 | 936 | |
937 | - wp_send_json_success( $data ); |
|
937 | + wp_send_json_success($data); |
|
938 | 938 | |
939 | 939 | } |
940 | 940 | |
@@ -944,37 +944,37 @@ discard block |
||
944 | 944 | public static function get_customers() { |
945 | 945 | |
946 | 946 | // Verify nonce. |
947 | - check_ajax_referer( 'wpinv-nonce' ); |
|
947 | + check_ajax_referer('wpinv-nonce'); |
|
948 | 948 | |
949 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
949 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
950 | 950 | exit; |
951 | 951 | } |
952 | 952 | |
953 | 953 | // We need a search term. |
954 | - if ( empty( $_GET['search'] ) ) { |
|
955 | - wp_send_json_success( array() ); |
|
954 | + if (empty($_GET['search'])) { |
|
955 | + wp_send_json_success(array()); |
|
956 | 956 | } |
957 | 957 | |
958 | 958 | // Retrieve customers. |
959 | 959 | |
960 | 960 | $customer_args = array( |
961 | - 'fields' => array( 'ID', 'user_email', 'display_name' ), |
|
961 | + 'fields' => array('ID', 'user_email', 'display_name'), |
|
962 | 962 | 'orderby' => 'display_name', |
963 | - 'search' => '*' . sanitize_text_field( $_GET['search'] ) . '*', |
|
964 | - 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
963 | + 'search' => '*' . sanitize_text_field($_GET['search']) . '*', |
|
964 | + 'search_columns' => array('user_login', 'user_email', 'display_name'), |
|
965 | 965 | ); |
966 | 966 | |
967 | - $customers = get_users( apply_filters( 'getpaid_ajax_invoice_customers_query_args', $customer_args ) ); |
|
967 | + $customers = get_users(apply_filters('getpaid_ajax_invoice_customers_query_args', $customer_args)); |
|
968 | 968 | $data = array(); |
969 | 969 | |
970 | - foreach ( $customers as $customer ) { |
|
970 | + foreach ($customers as $customer) { |
|
971 | 971 | $data[] = array( |
972 | 972 | 'id' => (int) $customer->ID, |
973 | - 'text' => strip_tags( sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ) ), |
|
973 | + 'text' => strip_tags(sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email)), |
|
974 | 974 | ); |
975 | 975 | } |
976 | 976 | |
977 | - wp_send_json_success( $data ); |
|
977 | + wp_send_json_success($data); |
|
978 | 978 | |
979 | 979 | } |
980 | 980 | |
@@ -984,25 +984,25 @@ discard block |
||
984 | 984 | public static function get_aui_states_field() { |
985 | 985 | |
986 | 986 | // We need a country. |
987 | - if ( empty( $_GET['country'] ) ) { |
|
987 | + if (empty($_GET['country'])) { |
|
988 | 988 | exit; |
989 | 989 | } |
990 | 990 | |
991 | - $states = wpinv_get_country_states( sanitize_text_field( $_GET['country'] ) ); |
|
992 | - $state = isset( $_GET['state'] ) ? sanitize_text_field( $_GET['state'] ) : wpinv_get_default_state(); |
|
993 | - $name = isset( $_GET['name'] ) ? sanitize_text_field( $_GET['name'] ) : 'wpinv_state'; |
|
994 | - $class = isset( $_GET['class'] ) ? sanitize_text_field( $_GET['class'] ) : 'form-control-sm'; |
|
991 | + $states = wpinv_get_country_states(sanitize_text_field($_GET['country'])); |
|
992 | + $state = isset($_GET['state']) ? sanitize_text_field($_GET['state']) : wpinv_get_default_state(); |
|
993 | + $name = isset($_GET['name']) ? sanitize_text_field($_GET['name']) : 'wpinv_state'; |
|
994 | + $class = isset($_GET['class']) ? sanitize_text_field($_GET['class']) : 'form-control-sm'; |
|
995 | 995 | |
996 | - if ( empty( $states ) ) { |
|
996 | + if (empty($states)) { |
|
997 | 997 | |
998 | 998 | $html = aui()->input( |
999 | 999 | array( |
1000 | 1000 | 'type' => 'text', |
1001 | 1001 | 'id' => 'wpinv_state', |
1002 | 1002 | 'name' => $name, |
1003 | - 'label' => __( 'State', 'invoicing' ), |
|
1003 | + 'label' => __('State', 'invoicing'), |
|
1004 | 1004 | 'label_type' => 'vertical', |
1005 | - 'placeholder' => __( 'State', 'invoicing' ), |
|
1005 | + 'placeholder' => __('State', 'invoicing'), |
|
1006 | 1006 | 'class' => $class, |
1007 | 1007 | 'value' => $state, |
1008 | 1008 | ) |
@@ -1014,9 +1014,9 @@ discard block |
||
1014 | 1014 | array( |
1015 | 1015 | 'id' => 'wpinv_state', |
1016 | 1016 | 'name' => $name, |
1017 | - 'label' => __( 'State', 'invoicing' ), |
|
1017 | + 'label' => __('State', 'invoicing'), |
|
1018 | 1018 | 'label_type' => 'vertical', |
1019 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
1019 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
1020 | 1020 | 'class' => $class, |
1021 | 1021 | 'value' => $state, |
1022 | 1022 | 'options' => $states, |
@@ -1030,7 +1030,7 @@ discard block |
||
1030 | 1030 | wp_send_json_success( |
1031 | 1031 | array( |
1032 | 1032 | 'html' => $html, |
1033 | - 'select' => ! empty( $states ), |
|
1033 | + 'select' => !empty($states), |
|
1034 | 1034 | ) |
1035 | 1035 | ); |
1036 | 1036 | |
@@ -1044,8 +1044,8 @@ discard block |
||
1044 | 1044 | public static function payment_form_refresh_prices() { |
1045 | 1045 | |
1046 | 1046 | // ... form fields... |
1047 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
1048 | - esc_html_e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
1047 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
1048 | + esc_html_e('Error: Reload the page and try again.', 'invoicing'); |
|
1049 | 1049 | exit; |
1050 | 1050 | } |
1051 | 1051 | |
@@ -1053,7 +1053,7 @@ discard block |
||
1053 | 1053 | $submission = new GetPaid_Payment_Form_Submission(); |
1054 | 1054 | |
1055 | 1055 | // Do we have an error? |
1056 | - if ( ! empty( $submission->last_error ) ) { |
|
1056 | + if (!empty($submission->last_error)) { |
|
1057 | 1057 | wp_send_json_error( |
1058 | 1058 | array( |
1059 | 1059 | 'code' => $submission->last_error_code, |
@@ -1063,12 +1063,12 @@ discard block |
||
1063 | 1063 | } |
1064 | 1064 | |
1065 | 1065 | // Prepare the response. |
1066 | - $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission ); |
|
1066 | + $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission); |
|
1067 | 1067 | |
1068 | 1068 | // Filter the response. |
1069 | - $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission ); |
|
1069 | + $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission); |
|
1070 | 1070 | |
1071 | - wp_send_json_success( $response ); |
|
1071 | + wp_send_json_success($response); |
|
1072 | 1072 | } |
1073 | 1073 | |
1074 | 1074 | /** |
@@ -1080,63 +1080,63 @@ discard block |
||
1080 | 1080 | public static function file_upload() { |
1081 | 1081 | |
1082 | 1082 | // Check nonce. |
1083 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
1083 | + check_ajax_referer('getpaid_form_nonce'); |
|
1084 | 1084 | |
1085 | - if ( empty( $_POST['form_id'] ) || empty( $_POST['field_name'] ) || empty( $_FILES['file'] ) ) { |
|
1086 | - wp_die( esc_html_e( 'Bad Request', 'invoicing' ), 400 ); |
|
1085 | + if (empty($_POST['form_id']) || empty($_POST['field_name']) || empty($_FILES['file'])) { |
|
1086 | + wp_die(esc_html_e('Bad Request', 'invoicing'), 400); |
|
1087 | 1087 | } |
1088 | 1088 | |
1089 | 1089 | // Fetch form. |
1090 | - $form = new GetPaid_Payment_Form( intval( $_POST['form_id'] ) ); |
|
1090 | + $form = new GetPaid_Payment_Form(intval($_POST['form_id'])); |
|
1091 | 1091 | |
1092 | - if ( ! $form->is_active() ) { |
|
1093 | - wp_send_json_error( __( 'Payment form not active', 'invoicing' ) ); |
|
1092 | + if (!$form->is_active()) { |
|
1093 | + wp_send_json_error(__('Payment form not active', 'invoicing')); |
|
1094 | 1094 | } |
1095 | 1095 | |
1096 | 1096 | // Fetch appropriate field. |
1097 | - $upload_field = current( wp_list_filter( $form->get_elements(), array( 'id' => sanitize_text_field( $_POST['field_name'] ) ) ) ); |
|
1098 | - if ( empty( $upload_field ) ) { |
|
1099 | - wp_send_json_error( __( 'Invalid upload field.', 'invoicing' ) ); |
|
1097 | + $upload_field = current(wp_list_filter($form->get_elements(), array('id' => sanitize_text_field($_POST['field_name'])))); |
|
1098 | + if (empty($upload_field)) { |
|
1099 | + wp_send_json_error(__('Invalid upload field.', 'invoicing')); |
|
1100 | 1100 | } |
1101 | 1101 | |
1102 | 1102 | // Prepare allowed file types. |
1103 | - $file_types = isset( $upload_field['file_types'] ) ? $upload_field['file_types'] : array( 'jpg|jpeg|jpe', 'gif', 'png' ); |
|
1103 | + $file_types = isset($upload_field['file_types']) ? $upload_field['file_types'] : array('jpg|jpeg|jpe', 'gif', 'png'); |
|
1104 | 1104 | $all_types = getpaid_get_allowed_mime_types(); |
1105 | 1105 | $mime_types = array(); |
1106 | 1106 | |
1107 | - foreach ( $file_types as $file_type ) { |
|
1108 | - if ( isset( $all_types[ $file_type ] ) ) { |
|
1109 | - $mime_types[] = $all_types[ $file_type ]; |
|
1107 | + foreach ($file_types as $file_type) { |
|
1108 | + if (isset($all_types[$file_type])) { |
|
1109 | + $mime_types[] = $all_types[$file_type]; |
|
1110 | 1110 | } |
1111 | 1111 | } |
1112 | 1112 | |
1113 | - if ( ! in_array( $_FILES['file']['type'], $mime_types ) ) { |
|
1114 | - wp_send_json_error( __( 'Unsupported file type.', 'invoicing' ) ); |
|
1113 | + if (!in_array($_FILES['file']['type'], $mime_types)) { |
|
1114 | + wp_send_json_error(__('Unsupported file type.', 'invoicing')); |
|
1115 | 1115 | } |
1116 | 1116 | |
1117 | 1117 | // Upload file. |
1118 | - $file_name = explode( '.', strtolower( $_FILES['file']['name'] ) ); |
|
1119 | - $file_name = uniqid( 'getpaid-' ) . '.' . array_pop( $file_name ); |
|
1118 | + $file_name = explode('.', strtolower($_FILES['file']['name'])); |
|
1119 | + $file_name = uniqid('getpaid-') . '.' . array_pop($file_name); |
|
1120 | 1120 | |
1121 | 1121 | $uploaded = wp_upload_bits( |
1122 | 1122 | $file_name, |
1123 | 1123 | null, |
1124 | - file_get_contents( $_FILES['file']['tmp_name'] ) |
|
1124 | + file_get_contents($_FILES['file']['tmp_name']) |
|
1125 | 1125 | ); |
1126 | 1126 | |
1127 | - if ( ! empty( $uploaded['error'] ) ) { |
|
1128 | - wp_send_json_error( $uploaded['error'] ); |
|
1127 | + if (!empty($uploaded['error'])) { |
|
1128 | + wp_send_json_error($uploaded['error']); |
|
1129 | 1129 | } |
1130 | 1130 | |
1131 | 1131 | // Retrieve response. |
1132 | 1132 | $response = sprintf( |
1133 | 1133 | '<input type="hidden" name="%s[%s]" value="%s" />', |
1134 | - esc_attr( sanitize_text_field( $_POST['field_name'] ) ), |
|
1135 | - esc_url( $uploaded['url'] ), |
|
1136 | - esc_attr( sanitize_text_field( strtolower( $_FILES['file']['name'] ) ) ) |
|
1134 | + esc_attr(sanitize_text_field($_POST['field_name'])), |
|
1135 | + esc_url($uploaded['url']), |
|
1136 | + esc_attr(sanitize_text_field(strtolower($_FILES['file']['name']))) |
|
1137 | 1137 | ); |
1138 | 1138 | |
1139 | - wp_send_json_success( $response ); |
|
1139 | + wp_send_json_success($response); |
|
1140 | 1140 | |
1141 | 1141 | } |
1142 | 1142 |