@@ -19,16 +19,16 @@ discard block |
||
19 | 19 | |
20 | 20 | // Define constants. |
21 | 21 | if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) { |
22 | - define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
22 | + define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | if ( ! defined( 'WPINV_VERSION' ) ) { |
26 | - define( 'WPINV_VERSION', '2.1.0' ); |
|
26 | + define( 'WPINV_VERSION', '2.1.0' ); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | // Include the main Invoicing class. |
30 | 30 | if ( ! class_exists( 'WPInv_Plugin', false ) ) { |
31 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
31 | + require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $GLOBALS['invoicing'] = new WPInv_Plugin(); |
44 | 44 | } |
45 | 45 | |
46 | - return $GLOBALS['invoicing']; |
|
46 | + return $GLOBALS['invoicing']; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -15,20 +15,20 @@ discard block |
||
15 | 15 | * @package GetPaid |
16 | 16 | */ |
17 | 17 | |
18 | -defined( 'ABSPATH' ) || exit; |
|
18 | +defined('ABSPATH') || exit; |
|
19 | 19 | |
20 | 20 | // Define constants. |
21 | -if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) { |
|
22 | - define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
21 | +if (!defined('WPINV_PLUGIN_FILE')) { |
|
22 | + define('WPINV_PLUGIN_FILE', __FILE__); |
|
23 | 23 | } |
24 | 24 | |
25 | -if ( ! defined( 'WPINV_VERSION' ) ) { |
|
26 | - define( 'WPINV_VERSION', '2.1.0' ); |
|
25 | +if (!defined('WPINV_VERSION')) { |
|
26 | + define('WPINV_VERSION', '2.1.0'); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | // Include the main Invoicing class. |
30 | -if ( ! class_exists( 'WPInv_Plugin', false ) ) { |
|
31 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
30 | +if (!class_exists('WPInv_Plugin', false)) { |
|
31 | + require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/class-wpinv.php'; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | */ |
40 | 40 | function getpaid() { |
41 | 41 | |
42 | - if ( empty( $GLOBALS['invoicing'] ) ) { |
|
42 | + if (empty($GLOBALS['invoicing'])) { |
|
43 | 43 | $GLOBALS['invoicing'] = new WPInv_Plugin(); |
44 | 44 | } |
45 | 45 | |
@@ -52,9 +52,9 @@ discard block |
||
52 | 52 | * @since 2.0.8 |
53 | 53 | */ |
54 | 54 | function getpaid_deactivation_hook() { |
55 | - update_option( 'wpinv_flush_permalinks', 1 ); |
|
55 | + update_option('wpinv_flush_permalinks', 1); |
|
56 | 56 | } |
57 | -register_deactivation_hook( __FILE__, 'getpaid_deactivation_hook' ); |
|
57 | +register_deactivation_hook(__FILE__, 'getpaid_deactivation_hook'); |
|
58 | 58 | |
59 | 59 | /** |
60 | 60 | * @deprecated |
@@ -64,4 +64,4 @@ discard block |
||
64 | 64 | } |
65 | 65 | |
66 | 66 | // Kickstart the plugin. |
67 | -add_action( 'plugins_loaded', 'getpaid', -100 ); |
|
67 | +add_action('plugins_loaded', 'getpaid', -100); |
@@ -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 | |
@@ -101,36 +101,36 @@ discard block |
||
101 | 101 | 'payment_form_refresh_prices' => true, |
102 | 102 | ); |
103 | 103 | |
104 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
105 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
106 | - add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
104 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
105 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
106 | + add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
107 | 107 | |
108 | - if ( $nopriv ) { |
|
109 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
110 | - add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
111 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
108 | + if ($nopriv) { |
|
109 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
110 | + add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
111 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
116 | 116 | public static function add_note() { |
117 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
117 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
118 | 118 | |
119 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
119 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
120 | 120 | die(-1); |
121 | 121 | } |
122 | 122 | |
123 | - $post_id = absint( $_POST['post_id'] ); |
|
124 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
125 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
123 | + $post_id = absint($_POST['post_id']); |
|
124 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
125 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
126 | 126 | |
127 | 127 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
128 | 128 | |
129 | - if ( $post_id > 0 ) { |
|
130 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
129 | + if ($post_id > 0) { |
|
130 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
131 | 131 | |
132 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
133 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
132 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
133 | + wpinv_get_invoice_note_line_item($note_id); |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | |
@@ -138,16 +138,16 @@ discard block |
||
138 | 138 | } |
139 | 139 | |
140 | 140 | public static function delete_note() { |
141 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
141 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
142 | 142 | |
143 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
143 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
144 | 144 | die(-1); |
145 | 145 | } |
146 | 146 | |
147 | - $note_id = (int)$_POST['note_id']; |
|
147 | + $note_id = (int) $_POST['note_id']; |
|
148 | 148 | |
149 | - if ( $note_id > 0 ) { |
|
150 | - wp_delete_comment( $note_id, true ); |
|
149 | + if ($note_id > 0) { |
|
150 | + wp_delete_comment($note_id, true); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | die(); |
@@ -165,34 +165,34 @@ discard block |
||
165 | 165 | public static function get_billing_details() { |
166 | 166 | |
167 | 167 | // Verify nonce. |
168 | - check_ajax_referer( 'wpinv-nonce' ); |
|
168 | + check_ajax_referer('wpinv-nonce'); |
|
169 | 169 | |
170 | 170 | // Can the user manage the plugin? |
171 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
171 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
172 | 172 | die(-1); |
173 | 173 | } |
174 | 174 | |
175 | 175 | // Do we have a user id? |
176 | 176 | $user_id = $_GET['user_id']; |
177 | 177 | |
178 | - if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { |
|
178 | + if (empty($user_id) || !is_numeric($user_id)) { |
|
179 | 179 | die(-1); |
180 | 180 | } |
181 | 181 | |
182 | 182 | // Fetch the billing details. |
183 | - $billing_details = wpinv_get_user_address( $user_id ); |
|
184 | - $billing_details = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id ); |
|
183 | + $billing_details = wpinv_get_user_address($user_id); |
|
184 | + $billing_details = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id); |
|
185 | 185 | |
186 | 186 | // unset the user id and email. |
187 | - $to_ignore = array( 'user_id', 'email' ); |
|
187 | + $to_ignore = array('user_id', 'email'); |
|
188 | 188 | |
189 | - foreach ( $to_ignore as $key ) { |
|
190 | - if ( isset( $billing_details[ $key ] ) ) { |
|
191 | - unset( $billing_details[ $key ] ); |
|
189 | + foreach ($to_ignore as $key) { |
|
190 | + if (isset($billing_details[$key])) { |
|
191 | + unset($billing_details[$key]); |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | |
195 | - wp_send_json_success( $billing_details ); |
|
195 | + wp_send_json_success($billing_details); |
|
196 | 196 | |
197 | 197 | } |
198 | 198 | |
@@ -202,47 +202,47 @@ discard block |
||
202 | 202 | public static function check_new_user_email() { |
203 | 203 | |
204 | 204 | // Verify nonce. |
205 | - check_ajax_referer( 'wpinv-nonce' ); |
|
205 | + check_ajax_referer('wpinv-nonce'); |
|
206 | 206 | |
207 | 207 | // Can the user manage the plugin? |
208 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
208 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
209 | 209 | die(-1); |
210 | 210 | } |
211 | 211 | |
212 | 212 | // We need an email address. |
213 | - if ( empty( $_GET['email'] ) ) { |
|
214 | - _e( "Provide the new user's email address", 'invoicing' ); |
|
213 | + if (empty($_GET['email'])) { |
|
214 | + _e("Provide the new user's email address", 'invoicing'); |
|
215 | 215 | exit; |
216 | 216 | } |
217 | 217 | |
218 | 218 | // Ensure the email is valid. |
219 | - $email = sanitize_text_field( $_GET['email'] ); |
|
220 | - if ( ! is_email( $email ) ) { |
|
221 | - _e( 'Invalid email address', 'invoicing' ); |
|
219 | + $email = sanitize_text_field($_GET['email']); |
|
220 | + if (!is_email($email)) { |
|
221 | + _e('Invalid email address', 'invoicing'); |
|
222 | 222 | exit; |
223 | 223 | } |
224 | 224 | |
225 | 225 | // And it does not exist. |
226 | - if ( email_exists( $email ) ) { |
|
227 | - _e( 'A user with this email address already exists', 'invoicing' ); |
|
226 | + if (email_exists($email)) { |
|
227 | + _e('A user with this email address already exists', 'invoicing'); |
|
228 | 228 | exit; |
229 | 229 | } |
230 | 230 | |
231 | - wp_send_json_success( true ); |
|
231 | + wp_send_json_success(true); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | public static function run_tool() { |
235 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
236 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
235 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
236 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
237 | 237 | die(-1); |
238 | 238 | } |
239 | 239 | |
240 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
240 | + $tool = sanitize_text_field($_POST['tool']); |
|
241 | 241 | |
242 | - do_action( 'wpinv_run_tool' ); |
|
242 | + do_action('wpinv_run_tool'); |
|
243 | 243 | |
244 | - if ( !empty( $tool ) ) { |
|
245 | - do_action( 'wpinv_tool_' . $tool ); |
|
244 | + if (!empty($tool)) { |
|
245 | + do_action('wpinv_tool_' . $tool); |
|
246 | 246 | } |
247 | 247 | } |
248 | 248 | |
@@ -252,27 +252,27 @@ discard block |
||
252 | 252 | public static function get_payment_form() { |
253 | 253 | |
254 | 254 | // Check nonce. |
255 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
255 | + check_ajax_referer('getpaid_form_nonce'); |
|
256 | 256 | |
257 | 257 | // Is the request set up correctly? |
258 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
258 | + if (empty($_GET['form']) && empty($_GET['item'])) { |
|
259 | 259 | echo aui()->alert( |
260 | 260 | array( |
261 | 261 | 'type' => 'warning', |
262 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
262 | + 'content' => __('No payment form or item provided', 'invoicing'), |
|
263 | 263 | ) |
264 | 264 | ); |
265 | 265 | exit; |
266 | 266 | } |
267 | 267 | |
268 | 268 | // Payment form or button? |
269 | - if ( ! empty( $_GET['form'] ) ) { |
|
270 | - getpaid_display_payment_form( urldecode( $_GET['form'] ) ); |
|
271 | - } else if( ! empty( $_GET['invoice'] ) ) { |
|
272 | - getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) ); |
|
269 | + if (!empty($_GET['form'])) { |
|
270 | + getpaid_display_payment_form(urldecode($_GET['form'])); |
|
271 | + } else if (!empty($_GET['invoice'])) { |
|
272 | + getpaid_display_invoice_payment_form(urldecode($_GET['invoice'])); |
|
273 | 273 | } else { |
274 | - $items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) ); |
|
275 | - getpaid_display_item_payment_form( $items ); |
|
274 | + $items = getpaid_convert_items_to_array(urldecode($_GET['item'])); |
|
275 | + getpaid_display_item_payment_form($items); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | exit; |
@@ -287,17 +287,17 @@ discard block |
||
287 | 287 | public static function payment_form() { |
288 | 288 | |
289 | 289 | // Check nonce. |
290 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
290 | + check_ajax_referer('getpaid_form_nonce'); |
|
291 | 291 | |
292 | 292 | // ... form fields... |
293 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
294 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
293 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
294 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
295 | 295 | exit; |
296 | 296 | } |
297 | 297 | |
298 | 298 | // Process the payment form. |
299 | - $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' ); |
|
300 | - $checkout = new $checkout_class( new GetPaid_Payment_Form_Submission() ); |
|
299 | + $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout'); |
|
300 | + $checkout = new $checkout_class(new GetPaid_Payment_Form_Submission()); |
|
301 | 301 | $checkout->process_checkout(); |
302 | 302 | |
303 | 303 | exit; |
@@ -310,55 +310,55 @@ discard block |
||
310 | 310 | */ |
311 | 311 | public static function get_payment_form_states_field() { |
312 | 312 | |
313 | - if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) { |
|
313 | + if (empty($_GET['country']) || empty($_GET['form'])) { |
|
314 | 314 | exit; |
315 | 315 | } |
316 | 316 | |
317 | - $elements = getpaid_get_payment_form_elements( $_GET['form'] ); |
|
317 | + $elements = getpaid_get_payment_form_elements($_GET['form']); |
|
318 | 318 | |
319 | - if ( empty( $elements ) ) { |
|
319 | + if (empty($elements)) { |
|
320 | 320 | exit; |
321 | 321 | } |
322 | 322 | |
323 | 323 | $address_fields = array(); |
324 | - foreach ( $elements as $element ) { |
|
325 | - if ( 'address' === $element['type'] ) { |
|
324 | + foreach ($elements as $element) { |
|
325 | + if ('address' === $element['type']) { |
|
326 | 326 | $address_fields = $element; |
327 | 327 | break; |
328 | 328 | } |
329 | 329 | } |
330 | 330 | |
331 | - if ( empty( $address_fields ) ) { |
|
331 | + if (empty($address_fields)) { |
|
332 | 332 | exit; |
333 | 333 | } |
334 | 334 | |
335 | - foreach ( $address_fields['fields'] as $address_field ) { |
|
335 | + foreach ($address_fields['fields'] as $address_field) { |
|
336 | 336 | |
337 | - if ( 'wpinv_state' == $address_field['name'] ) { |
|
337 | + if ('wpinv_state' == $address_field['name']) { |
|
338 | 338 | |
339 | - $wrap_class = getpaid_get_form_element_grid_class( $address_field ); |
|
340 | - $wrap_class = esc_attr( "$wrap_class getpaid-address-field-wrapper" ); |
|
341 | - $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] ); |
|
342 | - $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] ); |
|
343 | - $value = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : ''; |
|
344 | - $label = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] ); |
|
339 | + $wrap_class = getpaid_get_form_element_grid_class($address_field); |
|
340 | + $wrap_class = esc_attr("$wrap_class getpaid-address-field-wrapper"); |
|
341 | + $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']); |
|
342 | + $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']); |
|
343 | + $value = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : ''; |
|
344 | + $label = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']); |
|
345 | 345 | |
346 | - if ( ! empty( $address_field['required'] ) ) { |
|
346 | + if (!empty($address_field['required'])) { |
|
347 | 347 | $label .= "<span class='text-danger'> *</span>"; |
348 | 348 | } |
349 | 349 | |
350 | - $html = getpaid_get_states_select_markup ( |
|
351 | - sanitize_text_field( $_GET['country'] ), |
|
350 | + $html = getpaid_get_states_select_markup( |
|
351 | + sanitize_text_field($_GET['country']), |
|
352 | 352 | $value, |
353 | 353 | $placeholder, |
354 | 354 | $label, |
355 | 355 | $description, |
356 | - ! empty( $address_field['required'] ), |
|
356 | + !empty($address_field['required']), |
|
357 | 357 | $wrap_class, |
358 | - wpinv_clean( $_GET['name'] ) |
|
358 | + wpinv_clean($_GET['name']) |
|
359 | 359 | ); |
360 | 360 | |
361 | - wp_send_json_success( $html ); |
|
361 | + wp_send_json_success($html); |
|
362 | 362 | exit; |
363 | 363 | |
364 | 364 | } |
@@ -374,56 +374,56 @@ discard block |
||
374 | 374 | public static function recalculate_invoice_totals() { |
375 | 375 | |
376 | 376 | // Verify nonce. |
377 | - check_ajax_referer( 'wpinv-nonce' ); |
|
377 | + check_ajax_referer('wpinv-nonce'); |
|
378 | 378 | |
379 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
379 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
380 | 380 | exit; |
381 | 381 | } |
382 | 382 | |
383 | 383 | // We need an invoice. |
384 | - if ( empty( $_POST['post_id'] ) ) { |
|
384 | + if (empty($_POST['post_id'])) { |
|
385 | 385 | exit; |
386 | 386 | } |
387 | 387 | |
388 | 388 | // Fetch the invoice. |
389 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
389 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
390 | 390 | |
391 | 391 | // Ensure it exists. |
392 | - if ( ! $invoice->get_id() ) { |
|
392 | + if (!$invoice->get_id()) { |
|
393 | 393 | exit; |
394 | 394 | } |
395 | 395 | |
396 | 396 | // Maybe set the country, state, currency. |
397 | - foreach ( array( 'country', 'state', 'currency' ) as $key ) { |
|
398 | - if ( isset( $_POST[ $key ] ) ) { |
|
397 | + foreach (array('country', 'state', 'currency') as $key) { |
|
398 | + if (isset($_POST[$key])) { |
|
399 | 399 | $method = "set_$key"; |
400 | - $invoice->$method( $_POST[ $key ] ); |
|
400 | + $invoice->$method($_POST[$key]); |
|
401 | 401 | } |
402 | 402 | } |
403 | 403 | |
404 | 404 | // Maybe disable taxes. |
405 | - $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) ); |
|
405 | + $invoice->set_disable_taxes(!empty($_POST['taxes'])); |
|
406 | 406 | |
407 | 407 | // Recalculate totals. |
408 | 408 | $invoice->recalculate_total(); |
409 | 409 | |
410 | - $total = wpinv_price( $invoice->get_total(), $invoice->get_currency() ); |
|
410 | + $total = wpinv_price($invoice->get_total(), $invoice->get_currency()); |
|
411 | 411 | |
412 | - if ( $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) { |
|
413 | - $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() ); |
|
414 | - $total .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>'; |
|
412 | + if ($invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) { |
|
413 | + $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency()); |
|
414 | + $total .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>'; |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | $totals = array( |
418 | - 'subtotal' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ), |
|
419 | - 'discount' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ), |
|
420 | - 'tax' => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ), |
|
418 | + 'subtotal' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()), |
|
419 | + 'discount' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()), |
|
420 | + 'tax' => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()), |
|
421 | 421 | 'total' => $total, |
422 | 422 | ); |
423 | 423 | |
424 | - $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice ); |
|
424 | + $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice); |
|
425 | 425 | |
426 | - wp_send_json_success( compact( 'totals' ) ); |
|
426 | + wp_send_json_success(compact('totals')); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | /** |
@@ -432,33 +432,33 @@ discard block |
||
432 | 432 | public static function get_invoice_items() { |
433 | 433 | |
434 | 434 | // Verify nonce. |
435 | - check_ajax_referer( 'wpinv-nonce' ); |
|
435 | + check_ajax_referer('wpinv-nonce'); |
|
436 | 436 | |
437 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
437 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
438 | 438 | exit; |
439 | 439 | } |
440 | 440 | |
441 | 441 | // We need an invoice and items. |
442 | - if ( empty( $_POST['post_id'] ) ) { |
|
442 | + if (empty($_POST['post_id'])) { |
|
443 | 443 | exit; |
444 | 444 | } |
445 | 445 | |
446 | 446 | // Fetch the invoice. |
447 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
447 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
448 | 448 | |
449 | 449 | // Ensure it exists. |
450 | - if ( ! $invoice->get_id() ) { |
|
450 | + if (!$invoice->get_id()) { |
|
451 | 451 | exit; |
452 | 452 | } |
453 | 453 | |
454 | 454 | // Return an array of invoice items. |
455 | 455 | $items = array(); |
456 | 456 | |
457 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
458 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency(), $invoice->is_renewal() ); |
|
457 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
458 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency(), $invoice->is_renewal()); |
|
459 | 459 | } |
460 | 460 | |
461 | - wp_send_json_success( compact( 'items' ) ); |
|
461 | + wp_send_json_success(compact('items')); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | /** |
@@ -467,50 +467,50 @@ discard block |
||
467 | 467 | public static function edit_invoice_item() { |
468 | 468 | |
469 | 469 | // Verify nonce. |
470 | - check_ajax_referer( 'wpinv-nonce' ); |
|
470 | + check_ajax_referer('wpinv-nonce'); |
|
471 | 471 | |
472 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
472 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
473 | 473 | exit; |
474 | 474 | } |
475 | 475 | |
476 | 476 | // We need an invoice and item details. |
477 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) { |
|
477 | + if (empty($_POST['post_id']) || empty($_POST['data'])) { |
|
478 | 478 | exit; |
479 | 479 | } |
480 | 480 | |
481 | 481 | // Fetch the invoice. |
482 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
482 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
483 | 483 | |
484 | 484 | // Ensure it exists and its not been paid for. |
485 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
485 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
486 | 486 | exit; |
487 | 487 | } |
488 | 488 | |
489 | 489 | // Format the data. |
490 | - $data = wp_list_pluck( $_POST['data'], 'value', 'field' ); |
|
490 | + $data = wp_list_pluck($_POST['data'], 'value', 'field'); |
|
491 | 491 | |
492 | 492 | // Ensure that we have an item id. |
493 | - if ( empty( $data['id'] ) ) { |
|
493 | + if (empty($data['id'])) { |
|
494 | 494 | exit; |
495 | 495 | } |
496 | 496 | |
497 | 497 | // Abort if the invoice does not have the specified item. |
498 | - $item = $invoice->get_item( (int) $data['id'] ); |
|
498 | + $item = $invoice->get_item((int) $data['id']); |
|
499 | 499 | |
500 | - if ( empty( $item ) ) { |
|
500 | + if (empty($item)) { |
|
501 | 501 | exit; |
502 | 502 | } |
503 | 503 | |
504 | 504 | // Update the item. |
505 | - $item->set_price( $data['price'] ); |
|
506 | - $item->set_name( $data['name'] ); |
|
507 | - $item->set_description( $data['description'] ); |
|
508 | - $item->set_quantity( $data['quantity'] ); |
|
505 | + $item->set_price($data['price']); |
|
506 | + $item->set_name($data['name']); |
|
507 | + $item->set_description($data['description']); |
|
508 | + $item->set_quantity($data['quantity']); |
|
509 | 509 | |
510 | 510 | // Add it to the invoice. |
511 | - $error = $invoice->add_item( $item ); |
|
511 | + $error = $invoice->add_item($item); |
|
512 | 512 | $alert = false; |
513 | - if ( is_wp_error( $error ) ) { |
|
513 | + if (is_wp_error($error)) { |
|
514 | 514 | $alert = $error->get_error_message(); |
515 | 515 | } |
516 | 516 | |
@@ -523,11 +523,11 @@ discard block |
||
523 | 523 | // Return an array of invoice items. |
524 | 524 | $items = array(); |
525 | 525 | |
526 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
527 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
526 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
527 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
528 | 528 | } |
529 | 529 | |
530 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
530 | + wp_send_json_success(compact('items', 'alert')); |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | /** |
@@ -536,33 +536,33 @@ discard block |
||
536 | 536 | public static function remove_invoice_item() { |
537 | 537 | |
538 | 538 | // Verify nonce. |
539 | - check_ajax_referer( 'wpinv-nonce' ); |
|
539 | + check_ajax_referer('wpinv-nonce'); |
|
540 | 540 | |
541 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
541 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
542 | 542 | exit; |
543 | 543 | } |
544 | 544 | |
545 | 545 | // We need an invoice and an item. |
546 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
546 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
547 | 547 | exit; |
548 | 548 | } |
549 | 549 | |
550 | 550 | // Fetch the invoice. |
551 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
551 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
552 | 552 | |
553 | 553 | // Ensure it exists and its not been paid for. |
554 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
554 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
555 | 555 | exit; |
556 | 556 | } |
557 | 557 | |
558 | 558 | // Abort if the invoice does not have the specified item. |
559 | - $item = $invoice->get_item( (int) $_POST['item_id'] ); |
|
559 | + $item = $invoice->get_item((int) $_POST['item_id']); |
|
560 | 560 | |
561 | - if ( empty( $item ) ) { |
|
561 | + if (empty($item)) { |
|
562 | 562 | exit; |
563 | 563 | } |
564 | 564 | |
565 | - $invoice->remove_item( (int) $_POST['item_id'] ); |
|
565 | + $invoice->remove_item((int) $_POST['item_id']); |
|
566 | 566 | |
567 | 567 | // Update totals. |
568 | 568 | $invoice->recalculate_total(); |
@@ -573,11 +573,11 @@ discard block |
||
573 | 573 | // Return an array of invoice items. |
574 | 574 | $items = array(); |
575 | 575 | |
576 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
577 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
576 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
577 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
578 | 578 | } |
579 | 579 | |
580 | - wp_send_json_success( compact( 'items' ) ); |
|
580 | + wp_send_json_success(compact('items')); |
|
581 | 581 | } |
582 | 582 | |
583 | 583 | /** |
@@ -586,39 +586,39 @@ discard block |
||
586 | 586 | public static function add_invoice_items() { |
587 | 587 | |
588 | 588 | // Verify nonce. |
589 | - check_ajax_referer( 'wpinv-nonce' ); |
|
589 | + check_ajax_referer('wpinv-nonce'); |
|
590 | 590 | |
591 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
591 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
592 | 592 | exit; |
593 | 593 | } |
594 | 594 | |
595 | 595 | // We need an invoice and items. |
596 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) { |
|
596 | + if (empty($_POST['post_id']) || empty($_POST['items'])) { |
|
597 | 597 | exit; |
598 | 598 | } |
599 | 599 | |
600 | 600 | // Fetch the invoice. |
601 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
601 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
602 | 602 | $alert = false; |
603 | 603 | |
604 | 604 | // Ensure it exists and its not been paid for. |
605 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
605 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
606 | 606 | exit; |
607 | 607 | } |
608 | 608 | |
609 | 609 | // Add the items. |
610 | - foreach ( $_POST['items'] as $data ) { |
|
610 | + foreach ($_POST['items'] as $data) { |
|
611 | 611 | |
612 | - $item = new GetPaid_Form_Item( $data[ 'id' ] ); |
|
612 | + $item = new GetPaid_Form_Item($data['id']); |
|
613 | 613 | |
614 | - if ( is_numeric( $data[ 'qty' ] ) && (float) $data[ 'qty' ] > 0 ) { |
|
615 | - $item->set_quantity( $data[ 'qty' ] ); |
|
614 | + if (is_numeric($data['qty']) && (float) $data['qty'] > 0) { |
|
615 | + $item->set_quantity($data['qty']); |
|
616 | 616 | } |
617 | 617 | |
618 | - if ( $item->get_id() > 0 ) { |
|
619 | - $error = $invoice->add_item( $item ); |
|
618 | + if ($item->get_id() > 0) { |
|
619 | + $error = $invoice->add_item($item); |
|
620 | 620 | |
621 | - if ( is_wp_error( $error ) ) { |
|
621 | + if (is_wp_error($error)) { |
|
622 | 622 | $alert = $error->get_error_message(); |
623 | 623 | } |
624 | 624 | |
@@ -633,11 +633,11 @@ discard block |
||
633 | 633 | // Return an array of invoice items. |
634 | 634 | $items = array(); |
635 | 635 | |
636 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
637 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
636 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
637 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
638 | 638 | } |
639 | 639 | |
640 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
640 | + wp_send_json_success(compact('items', 'alert')); |
|
641 | 641 | } |
642 | 642 | |
643 | 643 | /** |
@@ -646,15 +646,15 @@ discard block |
||
646 | 646 | public static function get_invoicing_items() { |
647 | 647 | |
648 | 648 | // Verify nonce. |
649 | - check_ajax_referer( 'wpinv-nonce' ); |
|
649 | + check_ajax_referer('wpinv-nonce'); |
|
650 | 650 | |
651 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
651 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
652 | 652 | exit; |
653 | 653 | } |
654 | 654 | |
655 | 655 | // We need a search term. |
656 | - if ( empty( $_GET['search'] ) ) { |
|
657 | - wp_send_json_success( array() ); |
|
656 | + if (empty($_GET['search'])) { |
|
657 | + wp_send_json_success(array()); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | // Retrieve items. |
@@ -663,8 +663,8 @@ discard block |
||
663 | 663 | 'orderby' => 'title', |
664 | 664 | 'order' => 'ASC', |
665 | 665 | 'posts_per_page' => -1, |
666 | - 'post_status' => array( 'publish' ), |
|
667 | - 's' => trim( $_GET['search'] ), |
|
666 | + 'post_status' => array('publish'), |
|
667 | + 's' => trim($_GET['search']), |
|
668 | 668 | 'meta_query' => array( |
669 | 669 | array( |
670 | 670 | 'key' => '_wpinv_type', |
@@ -674,22 +674,22 @@ discard block |
||
674 | 674 | ) |
675 | 675 | ); |
676 | 676 | |
677 | - $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) ); |
|
677 | + $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args)); |
|
678 | 678 | $data = array(); |
679 | 679 | |
680 | 680 | |
681 | - $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( $_GET['post_id'] ) ); |
|
681 | + $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type($_GET['post_id'])); |
|
682 | 682 | |
683 | - foreach ( $items as $item ) { |
|
684 | - $item = new GetPaid_Form_Item( $item ); |
|
683 | + foreach ($items as $item) { |
|
684 | + $item = new GetPaid_Form_Item($item); |
|
685 | 685 | $data[] = array( |
686 | 686 | 'id' => (int) $item->get_id(), |
687 | - 'text' => strip_tags( $item->get_name() ), |
|
688 | - 'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '', |
|
687 | + 'text' => strip_tags($item->get_name()), |
|
688 | + 'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '', |
|
689 | 689 | ); |
690 | 690 | } |
691 | 691 | |
692 | - wp_send_json_success( $data ); |
|
692 | + wp_send_json_success($data); |
|
693 | 693 | |
694 | 694 | } |
695 | 695 | |
@@ -699,24 +699,24 @@ discard block |
||
699 | 699 | public static function get_aui_states_field() { |
700 | 700 | |
701 | 701 | // Verify nonce. |
702 | - check_ajax_referer( 'wpinv-nonce' ); |
|
702 | + check_ajax_referer('wpinv-nonce'); |
|
703 | 703 | |
704 | 704 | // We need a country. |
705 | - if ( empty( $_GET['country'] ) ) { |
|
705 | + if (empty($_GET['country'])) { |
|
706 | 706 | exit; |
707 | 707 | } |
708 | 708 | |
709 | - $states = wpinv_get_country_states( trim( $_GET['country'] ) ); |
|
710 | - $state = isset( $_GET['state'] ) ? trim( $_GET['state'] ) : wpinv_get_default_state(); |
|
709 | + $states = wpinv_get_country_states(trim($_GET['country'])); |
|
710 | + $state = isset($_GET['state']) ? trim($_GET['state']) : wpinv_get_default_state(); |
|
711 | 711 | |
712 | - if ( empty( $states ) ) { |
|
712 | + if (empty($states)) { |
|
713 | 713 | |
714 | 714 | $html = aui()->input( |
715 | 715 | array( |
716 | 716 | 'type' => 'text', |
717 | 717 | 'id' => 'wpinv_state', |
718 | 718 | 'name' => 'wpinv_state', |
719 | - 'label' => __( 'State', 'invoicing' ), |
|
719 | + 'label' => __('State', 'invoicing'), |
|
720 | 720 | 'label_type' => 'vertical', |
721 | 721 | 'placeholder' => 'Liège', |
722 | 722 | 'class' => 'form-control-sm', |
@@ -730,9 +730,9 @@ discard block |
||
730 | 730 | array( |
731 | 731 | 'id' => 'wpinv_state', |
732 | 732 | 'name' => 'wpinv_state', |
733 | - 'label' => __( 'State', 'invoicing' ), |
|
733 | + 'label' => __('State', 'invoicing'), |
|
734 | 734 | 'label_type' => 'vertical', |
735 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
735 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
736 | 736 | 'class' => 'form-control-sm', |
737 | 737 | 'value' => $state, |
738 | 738 | 'options' => $states, |
@@ -746,7 +746,7 @@ discard block |
||
746 | 746 | wp_send_json_success( |
747 | 747 | array( |
748 | 748 | 'html' => $html, |
749 | - 'select' => ! empty ( $states ) |
|
749 | + 'select' => !empty ($states) |
|
750 | 750 | ) |
751 | 751 | ); |
752 | 752 | |
@@ -760,11 +760,11 @@ discard block |
||
760 | 760 | public static function payment_form_refresh_prices() { |
761 | 761 | |
762 | 762 | // Check nonce. |
763 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
763 | + check_ajax_referer('getpaid_form_nonce'); |
|
764 | 764 | |
765 | 765 | // ... form fields... |
766 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
767 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
766 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
767 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
768 | 768 | exit; |
769 | 769 | } |
770 | 770 | |
@@ -772,18 +772,18 @@ discard block |
||
772 | 772 | $submission = new GetPaid_Payment_Form_Submission(); |
773 | 773 | |
774 | 774 | // Do we have an error? |
775 | - if ( ! empty( $submission->last_error ) ) { |
|
775 | + if (!empty($submission->last_error)) { |
|
776 | 776 | echo $submission->last_error; |
777 | 777 | exit; |
778 | 778 | } |
779 | 779 | |
780 | 780 | // Prepare the response. |
781 | - $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission ); |
|
781 | + $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission); |
|
782 | 782 | |
783 | 783 | // Filter the response. |
784 | - $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission ); |
|
784 | + $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission); |
|
785 | 785 | |
786 | - wp_send_json_success( $response ); |
|
786 | + wp_send_json_success($response); |
|
787 | 787 | } |
788 | 788 | |
789 | 789 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,60 +10,60 @@ discard block |
||
10 | 10 | class GetPaid_Form_Item extends WPInv_Item { |
11 | 11 | |
12 | 12 | /** |
13 | - * Stores a custom description for the item. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $custom_description = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * Stores the item quantity. |
|
21 | - * |
|
22 | - * @var float |
|
23 | - */ |
|
24 | - protected $quantity = 1; |
|
25 | - |
|
26 | - /** |
|
27 | - * Stores the item meta. |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $meta = array(); |
|
32 | - |
|
33 | - /** |
|
34 | - * Is this item required? |
|
35 | - * |
|
36 | - * @var int |
|
37 | - */ |
|
38 | - protected $is_required = true; |
|
39 | - |
|
40 | - /** |
|
41 | - * Are quantities allowed? |
|
42 | - * |
|
43 | - * @var int |
|
44 | - */ |
|
45 | - protected $allow_quantities = false; |
|
46 | - |
|
47 | - /** |
|
48 | - * Associated invoice. |
|
49 | - * |
|
50 | - * @var int |
|
51 | - */ |
|
52 | - public $invoice_id = 0; |
|
53 | - |
|
54 | - /** |
|
55 | - * Item discount. |
|
56 | - * |
|
57 | - * @var float |
|
58 | - */ |
|
59 | - public $item_discount = 0; |
|
60 | - |
|
61 | - /** |
|
62 | - * Item tax. |
|
63 | - * |
|
64 | - * @var float |
|
65 | - */ |
|
66 | - public $item_tax = 0; |
|
13 | + * Stores a custom description for the item. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $custom_description = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * Stores the item quantity. |
|
21 | + * |
|
22 | + * @var float |
|
23 | + */ |
|
24 | + protected $quantity = 1; |
|
25 | + |
|
26 | + /** |
|
27 | + * Stores the item meta. |
|
28 | + * |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $meta = array(); |
|
32 | + |
|
33 | + /** |
|
34 | + * Is this item required? |
|
35 | + * |
|
36 | + * @var int |
|
37 | + */ |
|
38 | + protected $is_required = true; |
|
39 | + |
|
40 | + /** |
|
41 | + * Are quantities allowed? |
|
42 | + * |
|
43 | + * @var int |
|
44 | + */ |
|
45 | + protected $allow_quantities = false; |
|
46 | + |
|
47 | + /** |
|
48 | + * Associated invoice. |
|
49 | + * |
|
50 | + * @var int |
|
51 | + */ |
|
52 | + public $invoice_id = 0; |
|
53 | + |
|
54 | + /** |
|
55 | + * Item discount. |
|
56 | + * |
|
57 | + * @var float |
|
58 | + */ |
|
59 | + public $item_discount = 0; |
|
60 | + |
|
61 | + /** |
|
62 | + * Item tax. |
|
63 | + * |
|
64 | + * @var float |
|
65 | + */ |
|
66 | + public $item_tax = 0; |
|
67 | 67 | |
68 | 68 | /* |
69 | 69 | |-------------------------------------------------------------------------- |
@@ -81,234 +81,234 @@ discard block |
||
81 | 81 | */ |
82 | 82 | |
83 | 83 | /** |
84 | - * Get the item name. |
|
85 | - * |
|
86 | - * @since 1.0.19 |
|
87 | - * @param string $context View or edit context. |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function get_name( $context = 'view' ) { |
|
91 | - $name = parent::get_name( $context ); |
|
92 | - return $name . wpinv_get_item_suffix( $this ); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Get the item name without a suffix. |
|
97 | - * |
|
98 | - * @since 1.0.19 |
|
99 | - * @param string $context View or edit context. |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - public function get_raw_name( $context = 'view' ) { |
|
103 | - return parent::get_name( $context ); |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Get the item description. |
|
108 | - * |
|
109 | - * @since 1.0.19 |
|
110 | - * @param string $context View or edit context. |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function get_description( $context = 'view' ) { |
|
114 | - |
|
115 | - if ( isset( $this->custom_description ) ) { |
|
116 | - return $this->custom_description; |
|
117 | - } |
|
118 | - |
|
119 | - return parent::get_description( $context ); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Returns the sub total. |
|
124 | - * |
|
125 | - * @since 1.0.19 |
|
126 | - * @param string $context View or edit context. |
|
127 | - * @return float |
|
128 | - */ |
|
129 | - public function get_sub_total( $context = 'view' ) { |
|
130 | - return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Returns the recurring sub total. |
|
135 | - * |
|
136 | - * @since 1.0.19 |
|
137 | - * @param string $context View or edit context. |
|
138 | - * @return float |
|
139 | - */ |
|
140 | - public function get_recurring_sub_total( $context = 'view' ) { |
|
141 | - |
|
142 | - if ( $this->is_recurring() ) { |
|
143 | - return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
144 | - } |
|
145 | - |
|
146 | - return 0; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * @deprecated |
|
151 | - */ |
|
152 | - public function get_qantity( $context = 'view' ) { |
|
153 | - return $this->get_quantity( $context ); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Get the item quantity. |
|
158 | - * |
|
159 | - * @since 1.0.19 |
|
160 | - * @param string $context View or edit context. |
|
161 | - * @return float |
|
162 | - */ |
|
163 | - public function get_quantity( $context = 'view' ) { |
|
164 | - $quantity = (float) $this->quantity; |
|
165 | - |
|
166 | - if ( empty( $quantity ) || 1 > $quantity ) { |
|
167 | - $quantity = 1; |
|
168 | - } |
|
169 | - |
|
170 | - if ( 'view' == $context ) { |
|
171 | - return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
172 | - } |
|
173 | - |
|
174 | - return $quantity; |
|
175 | - |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Get the item meta data. |
|
180 | - * |
|
181 | - * @since 1.0.19 |
|
182 | - * @param string $context View or edit context. |
|
183 | - * @return meta |
|
184 | - */ |
|
185 | - public function get_item_meta( $context = 'view' ) { |
|
186 | - $meta = $this->meta; |
|
187 | - |
|
188 | - if ( 'view' == $context ) { |
|
189 | - return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
190 | - } |
|
191 | - |
|
192 | - return $meta; |
|
193 | - |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Returns whether or not customers can update the item quantity. |
|
198 | - * |
|
199 | - * @since 1.0.19 |
|
200 | - * @param string $context View or edit context. |
|
201 | - * @return bool |
|
202 | - */ |
|
203 | - public function get_allow_quantities( $context = 'view' ) { |
|
204 | - $allow_quantities = (bool) $this->allow_quantities; |
|
205 | - |
|
206 | - if ( 'view' == $context ) { |
|
207 | - return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
208 | - } |
|
209 | - |
|
210 | - return $allow_quantities; |
|
211 | - |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * Returns whether or not the item is required. |
|
216 | - * |
|
217 | - * @since 1.0.19 |
|
218 | - * @param string $context View or edit context. |
|
219 | - * @return bool |
|
220 | - */ |
|
221 | - public function get_is_required( $context = 'view' ) { |
|
222 | - $is_required = (bool) $this->is_required; |
|
223 | - |
|
224 | - if ( 'view' == $context ) { |
|
225 | - return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
226 | - } |
|
227 | - |
|
228 | - return $is_required; |
|
229 | - |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * Prepares form data for use. |
|
234 | - * |
|
235 | - * @since 1.0.19 |
|
236 | - * @return array |
|
237 | - */ |
|
238 | - public function prepare_data_for_use( $required = null ) { |
|
239 | - |
|
240 | - $required = is_null( $required ) ? $this->is_required() : $required; |
|
241 | - return array( |
|
242 | - 'title' => strip_tags( $this->get_name() ), |
|
243 | - 'id' => $this->get_id(), |
|
244 | - 'price' => $this->get_price(), |
|
245 | - 'recurring' => $this->is_recurring(), |
|
246 | - 'description' => $this->get_description(), |
|
247 | - 'allow_quantities' => $this->allows_quantities(), |
|
248 | - 'required' => $required, |
|
249 | - ); |
|
250 | - |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * Prepares form data for ajax use. |
|
255 | - * |
|
256 | - * @since 1.0.19 |
|
257 | - * @return array |
|
258 | - */ |
|
259 | - public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) { |
|
260 | - |
|
261 | - $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
262 | - |
|
263 | - if ( $description ) { |
|
264 | - $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
|
265 | - } |
|
266 | - |
|
267 | - $price = ! $is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
268 | - $subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
269 | - return array( |
|
270 | - 'id' => $this->get_id(), |
|
271 | - 'texts' => array( |
|
272 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
273 | - 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
274 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
275 | - 'item-price' => wpinv_price( $price, $currency ), |
|
276 | - 'item-total' => wpinv_price( $subtotal, $currency ), |
|
277 | - ), |
|
278 | - 'inputs' => array( |
|
279 | - 'item-id' => $this->get_id(), |
|
280 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
281 | - 'item-description' => wp_kses_post( $this->get_description() ), |
|
282 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
283 | - 'item-price' => $price, |
|
284 | - ) |
|
285 | - ); |
|
286 | - |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * Prepares form data for saving (cart_details). |
|
291 | - * |
|
292 | - * @since 1.0.19 |
|
293 | - * @return array |
|
294 | - */ |
|
295 | - public function prepare_data_for_saving() { |
|
296 | - |
|
297 | - return array( |
|
298 | - 'post_id' => $this->invoice_id, |
|
299 | - 'item_id' => $this->get_id(), |
|
300 | - 'item_name' => sanitize_text_field( $this->get_raw_name() ), |
|
301 | - 'item_description' => $this->get_description(), |
|
302 | - 'tax' => $this->item_tax, |
|
303 | - 'item_price' => $this->get_price(), |
|
304 | - 'quantity' => (float) $this->get_quantity(), |
|
305 | - 'discount' => $this->item_discount, |
|
306 | - 'subtotal' => $this->get_sub_total(), |
|
307 | - 'price' => $this->get_sub_total() + $this->item_tax + $this->item_discount, |
|
308 | - 'meta' => $this->get_item_meta(), |
|
309 | - ); |
|
310 | - |
|
311 | - } |
|
84 | + * Get the item name. |
|
85 | + * |
|
86 | + * @since 1.0.19 |
|
87 | + * @param string $context View or edit context. |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function get_name( $context = 'view' ) { |
|
91 | + $name = parent::get_name( $context ); |
|
92 | + return $name . wpinv_get_item_suffix( $this ); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Get the item name without a suffix. |
|
97 | + * |
|
98 | + * @since 1.0.19 |
|
99 | + * @param string $context View or edit context. |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + public function get_raw_name( $context = 'view' ) { |
|
103 | + return parent::get_name( $context ); |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Get the item description. |
|
108 | + * |
|
109 | + * @since 1.0.19 |
|
110 | + * @param string $context View or edit context. |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function get_description( $context = 'view' ) { |
|
114 | + |
|
115 | + if ( isset( $this->custom_description ) ) { |
|
116 | + return $this->custom_description; |
|
117 | + } |
|
118 | + |
|
119 | + return parent::get_description( $context ); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Returns the sub total. |
|
124 | + * |
|
125 | + * @since 1.0.19 |
|
126 | + * @param string $context View or edit context. |
|
127 | + * @return float |
|
128 | + */ |
|
129 | + public function get_sub_total( $context = 'view' ) { |
|
130 | + return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Returns the recurring sub total. |
|
135 | + * |
|
136 | + * @since 1.0.19 |
|
137 | + * @param string $context View or edit context. |
|
138 | + * @return float |
|
139 | + */ |
|
140 | + public function get_recurring_sub_total( $context = 'view' ) { |
|
141 | + |
|
142 | + if ( $this->is_recurring() ) { |
|
143 | + return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
144 | + } |
|
145 | + |
|
146 | + return 0; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * @deprecated |
|
151 | + */ |
|
152 | + public function get_qantity( $context = 'view' ) { |
|
153 | + return $this->get_quantity( $context ); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Get the item quantity. |
|
158 | + * |
|
159 | + * @since 1.0.19 |
|
160 | + * @param string $context View or edit context. |
|
161 | + * @return float |
|
162 | + */ |
|
163 | + public function get_quantity( $context = 'view' ) { |
|
164 | + $quantity = (float) $this->quantity; |
|
165 | + |
|
166 | + if ( empty( $quantity ) || 1 > $quantity ) { |
|
167 | + $quantity = 1; |
|
168 | + } |
|
169 | + |
|
170 | + if ( 'view' == $context ) { |
|
171 | + return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
172 | + } |
|
173 | + |
|
174 | + return $quantity; |
|
175 | + |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Get the item meta data. |
|
180 | + * |
|
181 | + * @since 1.0.19 |
|
182 | + * @param string $context View or edit context. |
|
183 | + * @return meta |
|
184 | + */ |
|
185 | + public function get_item_meta( $context = 'view' ) { |
|
186 | + $meta = $this->meta; |
|
187 | + |
|
188 | + if ( 'view' == $context ) { |
|
189 | + return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
190 | + } |
|
191 | + |
|
192 | + return $meta; |
|
193 | + |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Returns whether or not customers can update the item quantity. |
|
198 | + * |
|
199 | + * @since 1.0.19 |
|
200 | + * @param string $context View or edit context. |
|
201 | + * @return bool |
|
202 | + */ |
|
203 | + public function get_allow_quantities( $context = 'view' ) { |
|
204 | + $allow_quantities = (bool) $this->allow_quantities; |
|
205 | + |
|
206 | + if ( 'view' == $context ) { |
|
207 | + return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
208 | + } |
|
209 | + |
|
210 | + return $allow_quantities; |
|
211 | + |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * Returns whether or not the item is required. |
|
216 | + * |
|
217 | + * @since 1.0.19 |
|
218 | + * @param string $context View or edit context. |
|
219 | + * @return bool |
|
220 | + */ |
|
221 | + public function get_is_required( $context = 'view' ) { |
|
222 | + $is_required = (bool) $this->is_required; |
|
223 | + |
|
224 | + if ( 'view' == $context ) { |
|
225 | + return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
226 | + } |
|
227 | + |
|
228 | + return $is_required; |
|
229 | + |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * Prepares form data for use. |
|
234 | + * |
|
235 | + * @since 1.0.19 |
|
236 | + * @return array |
|
237 | + */ |
|
238 | + public function prepare_data_for_use( $required = null ) { |
|
239 | + |
|
240 | + $required = is_null( $required ) ? $this->is_required() : $required; |
|
241 | + return array( |
|
242 | + 'title' => strip_tags( $this->get_name() ), |
|
243 | + 'id' => $this->get_id(), |
|
244 | + 'price' => $this->get_price(), |
|
245 | + 'recurring' => $this->is_recurring(), |
|
246 | + 'description' => $this->get_description(), |
|
247 | + 'allow_quantities' => $this->allows_quantities(), |
|
248 | + 'required' => $required, |
|
249 | + ); |
|
250 | + |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * Prepares form data for ajax use. |
|
255 | + * |
|
256 | + * @since 1.0.19 |
|
257 | + * @return array |
|
258 | + */ |
|
259 | + public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) { |
|
260 | + |
|
261 | + $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
262 | + |
|
263 | + if ( $description ) { |
|
264 | + $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
|
265 | + } |
|
266 | + |
|
267 | + $price = ! $is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
268 | + $subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
269 | + return array( |
|
270 | + 'id' => $this->get_id(), |
|
271 | + 'texts' => array( |
|
272 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
273 | + 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
274 | + 'item-quantity' => floatval( $this->get_quantity() ), |
|
275 | + 'item-price' => wpinv_price( $price, $currency ), |
|
276 | + 'item-total' => wpinv_price( $subtotal, $currency ), |
|
277 | + ), |
|
278 | + 'inputs' => array( |
|
279 | + 'item-id' => $this->get_id(), |
|
280 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
281 | + 'item-description' => wp_kses_post( $this->get_description() ), |
|
282 | + 'item-quantity' => floatval( $this->get_quantity() ), |
|
283 | + 'item-price' => $price, |
|
284 | + ) |
|
285 | + ); |
|
286 | + |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * Prepares form data for saving (cart_details). |
|
291 | + * |
|
292 | + * @since 1.0.19 |
|
293 | + * @return array |
|
294 | + */ |
|
295 | + public function prepare_data_for_saving() { |
|
296 | + |
|
297 | + return array( |
|
298 | + 'post_id' => $this->invoice_id, |
|
299 | + 'item_id' => $this->get_id(), |
|
300 | + 'item_name' => sanitize_text_field( $this->get_raw_name() ), |
|
301 | + 'item_description' => $this->get_description(), |
|
302 | + 'tax' => $this->item_tax, |
|
303 | + 'item_price' => $this->get_price(), |
|
304 | + 'quantity' => (float) $this->get_quantity(), |
|
305 | + 'discount' => $this->item_discount, |
|
306 | + 'subtotal' => $this->get_sub_total(), |
|
307 | + 'price' => $this->get_sub_total() + $this->item_tax + $this->item_discount, |
|
308 | + 'meta' => $this->get_item_meta(), |
|
309 | + ); |
|
310 | + |
|
311 | + } |
|
312 | 312 | |
313 | 313 | /* |
314 | 314 | |-------------------------------------------------------------------------- |
@@ -320,70 +320,70 @@ discard block |
||
320 | 320 | | object. |
321 | 321 | */ |
322 | 322 | |
323 | - /** |
|
324 | - * Set the item qantity. |
|
325 | - * |
|
326 | - * @since 1.0.19 |
|
327 | - * @param float $quantity The item quantity. |
|
328 | - */ |
|
329 | - public function set_quantity( $quantity ) { |
|
330 | - |
|
331 | - if ( empty( $quantity ) || ! is_numeric( $quantity ) ) { |
|
332 | - $quantity = 1; |
|
333 | - } |
|
334 | - |
|
335 | - $this->quantity = (float) $quantity; |
|
336 | - |
|
337 | - } |
|
338 | - |
|
339 | - /** |
|
340 | - * Set the item meta data. |
|
341 | - * |
|
342 | - * @since 1.0.19 |
|
343 | - * @param array $meta The item meta data. |
|
344 | - */ |
|
345 | - public function set_item_meta( $meta ) { |
|
346 | - $this->meta = maybe_unserialize( $meta ); |
|
347 | - } |
|
348 | - |
|
349 | - /** |
|
350 | - * Set whether or not the quantities are allowed. |
|
351 | - * |
|
352 | - * @since 1.0.19 |
|
353 | - * @param bool $allow_quantities |
|
354 | - */ |
|
355 | - public function set_allow_quantities( $allow_quantities ) { |
|
356 | - $this->allow_quantities = (bool) $allow_quantities; |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Set whether or not the item is required. |
|
361 | - * |
|
362 | - * @since 1.0.19 |
|
363 | - * @param bool $is_required |
|
364 | - */ |
|
365 | - public function set_is_required( $is_required ) { |
|
366 | - $this->is_required = (bool) $is_required; |
|
367 | - } |
|
368 | - |
|
369 | - /** |
|
370 | - * Sets the custom item description. |
|
371 | - * |
|
372 | - * @since 1.0.19 |
|
373 | - * @param string $description |
|
374 | - */ |
|
375 | - public function set_custom_description( $description ) { |
|
376 | - $this->custom_description = $description; |
|
377 | - } |
|
323 | + /** |
|
324 | + * Set the item qantity. |
|
325 | + * |
|
326 | + * @since 1.0.19 |
|
327 | + * @param float $quantity The item quantity. |
|
328 | + */ |
|
329 | + public function set_quantity( $quantity ) { |
|
330 | + |
|
331 | + if ( empty( $quantity ) || ! is_numeric( $quantity ) ) { |
|
332 | + $quantity = 1; |
|
333 | + } |
|
334 | + |
|
335 | + $this->quantity = (float) $quantity; |
|
336 | + |
|
337 | + } |
|
338 | + |
|
339 | + /** |
|
340 | + * Set the item meta data. |
|
341 | + * |
|
342 | + * @since 1.0.19 |
|
343 | + * @param array $meta The item meta data. |
|
344 | + */ |
|
345 | + public function set_item_meta( $meta ) { |
|
346 | + $this->meta = maybe_unserialize( $meta ); |
|
347 | + } |
|
348 | + |
|
349 | + /** |
|
350 | + * Set whether or not the quantities are allowed. |
|
351 | + * |
|
352 | + * @since 1.0.19 |
|
353 | + * @param bool $allow_quantities |
|
354 | + */ |
|
355 | + public function set_allow_quantities( $allow_quantities ) { |
|
356 | + $this->allow_quantities = (bool) $allow_quantities; |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Set whether or not the item is required. |
|
361 | + * |
|
362 | + * @since 1.0.19 |
|
363 | + * @param bool $is_required |
|
364 | + */ |
|
365 | + public function set_is_required( $is_required ) { |
|
366 | + $this->is_required = (bool) $is_required; |
|
367 | + } |
|
368 | + |
|
369 | + /** |
|
370 | + * Sets the custom item description. |
|
371 | + * |
|
372 | + * @since 1.0.19 |
|
373 | + * @param string $description |
|
374 | + */ |
|
375 | + public function set_custom_description( $description ) { |
|
376 | + $this->custom_description = $description; |
|
377 | + } |
|
378 | 378 | |
379 | 379 | /** |
380 | 380 | * We do not want to save items to the database. |
381 | 381 | * |
382 | - * @return int item id |
|
382 | + * @return int item id |
|
383 | 383 | */ |
384 | 384 | public function save( $data = array() ) { |
385 | 385 | return $this->get_id(); |
386 | - } |
|
386 | + } |
|
387 | 387 | |
388 | 388 | /* |
389 | 389 | |-------------------------------------------------------------------------- |
@@ -395,23 +395,23 @@ discard block |
||
395 | 395 | */ |
396 | 396 | |
397 | 397 | /** |
398 | - * Checks whether the item has enabled dynamic pricing. |
|
399 | - * |
|
400 | - * @since 1.0.19 |
|
401 | - * @return bool |
|
402 | - */ |
|
403 | - public function is_required() { |
|
398 | + * Checks whether the item has enabled dynamic pricing. |
|
399 | + * |
|
400 | + * @since 1.0.19 |
|
401 | + * @return bool |
|
402 | + */ |
|
403 | + public function is_required() { |
|
404 | 404 | return (bool) $this->get_is_required(); |
405 | - } |
|
406 | - |
|
407 | - /** |
|
408 | - * Checks whether users can edit the quantities. |
|
409 | - * |
|
410 | - * @since 1.0.19 |
|
411 | - * @return bool |
|
412 | - */ |
|
413 | - public function allows_quantities() { |
|
405 | + } |
|
406 | + |
|
407 | + /** |
|
408 | + * Checks whether users can edit the quantities. |
|
409 | + * |
|
410 | + * @since 1.0.19 |
|
411 | + * @return bool |
|
412 | + */ |
|
413 | + public function allows_quantities() { |
|
414 | 414 | return (bool) $this->get_allow_quantities(); |
415 | - } |
|
415 | + } |
|
416 | 416 | |
417 | 417 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | * @param string $context View or edit context. |
88 | 88 | * @return string |
89 | 89 | */ |
90 | - public function get_name( $context = 'view' ) { |
|
91 | - $name = parent::get_name( $context ); |
|
92 | - return $name . wpinv_get_item_suffix( $this ); |
|
90 | + public function get_name($context = 'view') { |
|
91 | + $name = parent::get_name($context); |
|
92 | + return $name . wpinv_get_item_suffix($this); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,8 +99,8 @@ discard block |
||
99 | 99 | * @param string $context View or edit context. |
100 | 100 | * @return string |
101 | 101 | */ |
102 | - public function get_raw_name( $context = 'view' ) { |
|
103 | - return parent::get_name( $context ); |
|
102 | + public function get_raw_name($context = 'view') { |
|
103 | + return parent::get_name($context); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -110,13 +110,13 @@ discard block |
||
110 | 110 | * @param string $context View or edit context. |
111 | 111 | * @return string |
112 | 112 | */ |
113 | - public function get_description( $context = 'view' ) { |
|
113 | + public function get_description($context = 'view') { |
|
114 | 114 | |
115 | - if ( isset( $this->custom_description ) ) { |
|
115 | + if (isset($this->custom_description)) { |
|
116 | 116 | return $this->custom_description; |
117 | 117 | } |
118 | 118 | |
119 | - return parent::get_description( $context ); |
|
119 | + return parent::get_description($context); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -126,8 +126,8 @@ discard block |
||
126 | 126 | * @param string $context View or edit context. |
127 | 127 | * @return float |
128 | 128 | */ |
129 | - public function get_sub_total( $context = 'view' ) { |
|
130 | - return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
129 | + public function get_sub_total($context = 'view') { |
|
130 | + return $this->get_quantity($context) * $this->get_initial_price($context); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -137,10 +137,10 @@ discard block |
||
137 | 137 | * @param string $context View or edit context. |
138 | 138 | * @return float |
139 | 139 | */ |
140 | - public function get_recurring_sub_total( $context = 'view' ) { |
|
140 | + public function get_recurring_sub_total($context = 'view') { |
|
141 | 141 | |
142 | - if ( $this->is_recurring() ) { |
|
143 | - return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
142 | + if ($this->is_recurring()) { |
|
143 | + return $this->get_quantity($context) * $this->get_price($context); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | return 0; |
@@ -149,8 +149,8 @@ discard block |
||
149 | 149 | /** |
150 | 150 | * @deprecated |
151 | 151 | */ |
152 | - public function get_qantity( $context = 'view' ) { |
|
153 | - return $this->get_quantity( $context ); |
|
152 | + public function get_qantity($context = 'view') { |
|
153 | + return $this->get_quantity($context); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -160,15 +160,15 @@ discard block |
||
160 | 160 | * @param string $context View or edit context. |
161 | 161 | * @return float |
162 | 162 | */ |
163 | - public function get_quantity( $context = 'view' ) { |
|
163 | + public function get_quantity($context = 'view') { |
|
164 | 164 | $quantity = (float) $this->quantity; |
165 | 165 | |
166 | - if ( empty( $quantity ) || 1 > $quantity ) { |
|
166 | + if (empty($quantity) || 1 > $quantity) { |
|
167 | 167 | $quantity = 1; |
168 | 168 | } |
169 | 169 | |
170 | - if ( 'view' == $context ) { |
|
171 | - return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
170 | + if ('view' == $context) { |
|
171 | + return apply_filters('getpaid_payment_form_item_quantity', $quantity, $this); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | return $quantity; |
@@ -182,11 +182,11 @@ discard block |
||
182 | 182 | * @param string $context View or edit context. |
183 | 183 | * @return meta |
184 | 184 | */ |
185 | - public function get_item_meta( $context = 'view' ) { |
|
185 | + public function get_item_meta($context = 'view') { |
|
186 | 186 | $meta = $this->meta; |
187 | 187 | |
188 | - if ( 'view' == $context ) { |
|
189 | - return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
188 | + if ('view' == $context) { |
|
189 | + return apply_filters('getpaid_payment_form_item_meta', $meta, $this); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | return $meta; |
@@ -200,11 +200,11 @@ discard block |
||
200 | 200 | * @param string $context View or edit context. |
201 | 201 | * @return bool |
202 | 202 | */ |
203 | - public function get_allow_quantities( $context = 'view' ) { |
|
203 | + public function get_allow_quantities($context = 'view') { |
|
204 | 204 | $allow_quantities = (bool) $this->allow_quantities; |
205 | 205 | |
206 | - if ( 'view' == $context ) { |
|
207 | - return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
206 | + if ('view' == $context) { |
|
207 | + return apply_filters('getpaid_payment_form_item_allow_quantities', $allow_quantities, $this); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | return $allow_quantities; |
@@ -218,11 +218,11 @@ discard block |
||
218 | 218 | * @param string $context View or edit context. |
219 | 219 | * @return bool |
220 | 220 | */ |
221 | - public function get_is_required( $context = 'view' ) { |
|
221 | + public function get_is_required($context = 'view') { |
|
222 | 222 | $is_required = (bool) $this->is_required; |
223 | 223 | |
224 | - if ( 'view' == $context ) { |
|
225 | - return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
224 | + if ('view' == $context) { |
|
225 | + return apply_filters('getpaid_payment_form_item_is_required', $is_required, $this); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | return $is_required; |
@@ -235,11 +235,11 @@ discard block |
||
235 | 235 | * @since 1.0.19 |
236 | 236 | * @return array |
237 | 237 | */ |
238 | - public function prepare_data_for_use( $required = null ) { |
|
238 | + public function prepare_data_for_use($required = null) { |
|
239 | 239 | |
240 | - $required = is_null( $required ) ? $this->is_required() : $required; |
|
240 | + $required = is_null($required) ? $this->is_required() : $required; |
|
241 | 241 | return array( |
242 | - 'title' => strip_tags( $this->get_name() ), |
|
242 | + 'title' => strip_tags($this->get_name()), |
|
243 | 243 | 'id' => $this->get_id(), |
244 | 244 | 'price' => $this->get_price(), |
245 | 245 | 'recurring' => $this->is_recurring(), |
@@ -256,30 +256,30 @@ discard block |
||
256 | 256 | * @since 1.0.19 |
257 | 257 | * @return array |
258 | 258 | */ |
259 | - public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) { |
|
259 | + public function prepare_data_for_invoice_edit_ajax($currency = '', $is_renewal = false) { |
|
260 | 260 | |
261 | - $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
261 | + $description = getpaid_item_recurring_price_help_text($this, $currency); |
|
262 | 262 | |
263 | - if ( $description ) { |
|
263 | + if ($description) { |
|
264 | 264 | $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
265 | 265 | } |
266 | 266 | |
267 | - $price = ! $is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
268 | - $subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
267 | + $price = !$is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
268 | + $subtotal = !$is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
269 | 269 | return array( |
270 | 270 | 'id' => $this->get_id(), |
271 | 271 | 'texts' => array( |
272 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
273 | - 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
274 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
275 | - 'item-price' => wpinv_price( $price, $currency ), |
|
276 | - 'item-total' => wpinv_price( $subtotal, $currency ), |
|
272 | + 'item-name' => sanitize_text_field($this->get_name()), |
|
273 | + 'item-description' => wp_kses_post($this->get_description()) . $description, |
|
274 | + 'item-quantity' => floatval($this->get_quantity()), |
|
275 | + 'item-price' => wpinv_price($price, $currency), |
|
276 | + 'item-total' => wpinv_price($subtotal, $currency), |
|
277 | 277 | ), |
278 | 278 | 'inputs' => array( |
279 | 279 | 'item-id' => $this->get_id(), |
280 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
281 | - 'item-description' => wp_kses_post( $this->get_description() ), |
|
282 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
280 | + 'item-name' => sanitize_text_field($this->get_name()), |
|
281 | + 'item-description' => wp_kses_post($this->get_description()), |
|
282 | + 'item-quantity' => floatval($this->get_quantity()), |
|
283 | 283 | 'item-price' => $price, |
284 | 284 | ) |
285 | 285 | ); |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | return array( |
298 | 298 | 'post_id' => $this->invoice_id, |
299 | 299 | 'item_id' => $this->get_id(), |
300 | - 'item_name' => sanitize_text_field( $this->get_raw_name() ), |
|
300 | + 'item_name' => sanitize_text_field($this->get_raw_name()), |
|
301 | 301 | 'item_description' => $this->get_description(), |
302 | 302 | 'tax' => $this->item_tax, |
303 | 303 | 'item_price' => $this->get_price(), |
@@ -326,9 +326,9 @@ discard block |
||
326 | 326 | * @since 1.0.19 |
327 | 327 | * @param float $quantity The item quantity. |
328 | 328 | */ |
329 | - public function set_quantity( $quantity ) { |
|
329 | + public function set_quantity($quantity) { |
|
330 | 330 | |
331 | - if ( empty( $quantity ) || ! is_numeric( $quantity ) ) { |
|
331 | + if (empty($quantity) || !is_numeric($quantity)) { |
|
332 | 332 | $quantity = 1; |
333 | 333 | } |
334 | 334 | |
@@ -342,8 +342,8 @@ discard block |
||
342 | 342 | * @since 1.0.19 |
343 | 343 | * @param array $meta The item meta data. |
344 | 344 | */ |
345 | - public function set_item_meta( $meta ) { |
|
346 | - $this->meta = maybe_unserialize( $meta ); |
|
345 | + public function set_item_meta($meta) { |
|
346 | + $this->meta = maybe_unserialize($meta); |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | /** |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | * @since 1.0.19 |
353 | 353 | * @param bool $allow_quantities |
354 | 354 | */ |
355 | - public function set_allow_quantities( $allow_quantities ) { |
|
355 | + public function set_allow_quantities($allow_quantities) { |
|
356 | 356 | $this->allow_quantities = (bool) $allow_quantities; |
357 | 357 | } |
358 | 358 | |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | * @since 1.0.19 |
363 | 363 | * @param bool $is_required |
364 | 364 | */ |
365 | - public function set_is_required( $is_required ) { |
|
365 | + public function set_is_required($is_required) { |
|
366 | 366 | $this->is_required = (bool) $is_required; |
367 | 367 | } |
368 | 368 | |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | * @since 1.0.19 |
373 | 373 | * @param string $description |
374 | 374 | */ |
375 | - public function set_custom_description( $description ) { |
|
375 | + public function set_custom_description($description) { |
|
376 | 376 | $this->custom_description = $description; |
377 | 377 | } |
378 | 378 | |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | * |
382 | 382 | * @return int item id |
383 | 383 | */ |
384 | - public function save( $data = array() ) { |
|
384 | + public function save($data = array()) { |
|
385 | 385 | return $this->get_id(); |
386 | 386 | } |
387 | 387 |