@@ -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.4.7' ); |
|
26 | + define( 'WPINV_VERSION', '2.4.7' ); |
|
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.4.7' ); |
|
25 | +if (!defined('WPINV_VERSION')) { |
|
26 | + define('WPINV_VERSION', '2.4.7'); |
|
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); |
@@ -7,40 +7,40 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | -if ( empty( $form->get_items() ) ) { |
|
12 | +if (empty($form->get_items())) { |
|
13 | 13 | return; |
14 | 14 | } |
15 | 15 | |
16 | -if ( ! empty( $GLOBALS['getpaid_force_checkbox'] ) ) { |
|
16 | +if (!empty($GLOBALS['getpaid_force_checkbox'])) { |
|
17 | 17 | $items_type = 'checkbox'; |
18 | 18 | } |
19 | 19 | |
20 | -if ( empty( $items_type ) ) { |
|
20 | +if (empty($items_type)) { |
|
21 | 21 | $items_type = 'total'; |
22 | 22 | } |
23 | 23 | |
24 | -switch( $items_type ) { |
|
24 | +switch ($items_type) { |
|
25 | 25 | case 'radio': |
26 | - wpinv_get_template( 'payment-forms/variations/radio.php', compact( 'form', 'items_type' ) ); |
|
26 | + wpinv_get_template('payment-forms/variations/radio.php', compact('form', 'items_type')); |
|
27 | 27 | break; |
28 | 28 | case 'checkbox': |
29 | - wpinv_get_template( 'payment-forms/variations/checkbox.php', compact( 'form', 'items_type' ) ); |
|
29 | + wpinv_get_template('payment-forms/variations/checkbox.php', compact('form', 'items_type')); |
|
30 | 30 | break; |
31 | 31 | case 'select': |
32 | - wpinv_get_template( 'payment-forms/variations/select.php', compact( 'form', 'items_type' ) ); |
|
32 | + wpinv_get_template('payment-forms/variations/select.php', compact('form', 'items_type')); |
|
33 | 33 | break; |
34 | 34 | } |
35 | 35 | |
36 | 36 | // Display the cart totals. |
37 | -if ( ! empty( $hide_cart ) ) { |
|
37 | +if (!empty($hide_cart)) { |
|
38 | 38 | echo '<div class="d-none">'; |
39 | 39 | } |
40 | 40 | |
41 | 41 | // Display the cart totals. |
42 | -wpinv_get_template( 'payment-forms/cart.php', compact( 'form', 'items_type' ) ); |
|
42 | +wpinv_get_template('payment-forms/cart.php', compact('form', 'items_type')); |
|
43 | 43 | |
44 | -if ( ! empty( $hide_cart ) ) { |
|
44 | +if (!empty($hide_cart)) { |
|
45 | 45 | echo '</div>'; |
46 | 46 | } |
@@ -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 ) |
@@ -260,18 +260,18 @@ discard block |
||
260 | 260 | check_ajax_referer( 'getpaid_form_nonce' ); |
261 | 261 | |
262 | 262 | // Is the request set up correctly? |
263 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) { |
|
264 | - echo aui()->alert( |
|
265 | - array( |
|
266 | - 'type' => 'warning', |
|
267 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
268 | - ) |
|
263 | + if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) { |
|
264 | + echo aui()->alert( |
|
265 | + array( |
|
266 | + 'type' => 'warning', |
|
267 | + 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
268 | + ) |
|
269 | 269 | ); |
270 | 270 | exit; |
271 | 271 | } |
272 | 272 | |
273 | 273 | // Payment form or button? |
274 | - if ( ! empty( $_GET['form'] ) ) { |
|
274 | + if ( ! empty( $_GET['form'] ) ) { |
|
275 | 275 | $form = urldecode( $_GET['form'] ); |
276 | 276 | |
277 | 277 | if ( false !== strpos( $form, '|' ) ) { |
@@ -325,11 +325,11 @@ discard block |
||
325 | 325 | getpaid_display_payment_form( $form ); |
326 | 326 | } |
327 | 327 | |
328 | - } else if( ! empty( $_GET['invoice'] ) ) { |
|
329 | - getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) ); |
|
328 | + } else if( ! empty( $_GET['invoice'] ) ) { |
|
329 | + getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) ); |
|
330 | 330 | } else { |
331 | - $items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) ); |
|
332 | - getpaid_display_item_payment_form( $items ); |
|
331 | + $items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) ); |
|
332 | + getpaid_display_item_payment_form( $items ); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | exit; |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | if ( is_wp_error( $error ) ) { |
651 | 651 | $alert = $error->get_error_message(); |
652 | 652 | wp_send_json_success( compact( 'alert' ) ); |
653 | - } |
|
653 | + } |
|
654 | 654 | |
655 | 655 | // Update totals. |
656 | 656 | $invoice->recalculate_total(); |
@@ -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 | |
@@ -105,36 +105,36 @@ discard block |
||
105 | 105 | 'payment_form_refresh_prices' => true, |
106 | 106 | ); |
107 | 107 | |
108 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
109 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
110 | - add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
108 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
109 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
110 | + add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
111 | 111 | |
112 | - if ( $nopriv ) { |
|
113 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
114 | - add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
115 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
112 | + if ($nopriv) { |
|
113 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
114 | + add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
115 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | 120 | public static function add_note() { |
121 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
121 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
122 | 122 | |
123 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
123 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
124 | 124 | die(-1); |
125 | 125 | } |
126 | 126 | |
127 | - $post_id = absint( $_POST['post_id'] ); |
|
128 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
129 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
127 | + $post_id = absint($_POST['post_id']); |
|
128 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
129 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
130 | 130 | |
131 | 131 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
132 | 132 | |
133 | - if ( $post_id > 0 ) { |
|
134 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
133 | + if ($post_id > 0) { |
|
134 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
135 | 135 | |
136 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
137 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
136 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
137 | + wpinv_get_invoice_note_line_item($note_id); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
@@ -142,16 +142,16 @@ discard block |
||
142 | 142 | } |
143 | 143 | |
144 | 144 | public static function delete_note() { |
145 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
145 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
146 | 146 | |
147 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
147 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
148 | 148 | die(-1); |
149 | 149 | } |
150 | 150 | |
151 | - $note_id = (int)$_POST['note_id']; |
|
151 | + $note_id = (int) $_POST['note_id']; |
|
152 | 152 | |
153 | - if ( $note_id > 0 ) { |
|
154 | - wp_delete_comment( $note_id, true ); |
|
153 | + if ($note_id > 0) { |
|
154 | + wp_delete_comment($note_id, true); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | die(); |
@@ -169,34 +169,34 @@ discard block |
||
169 | 169 | public static function get_billing_details() { |
170 | 170 | |
171 | 171 | // Verify nonce. |
172 | - check_ajax_referer( 'wpinv-nonce' ); |
|
172 | + check_ajax_referer('wpinv-nonce'); |
|
173 | 173 | |
174 | 174 | // Can the user manage the plugin? |
175 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
175 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
176 | 176 | die(-1); |
177 | 177 | } |
178 | 178 | |
179 | 179 | // Do we have a user id? |
180 | 180 | $user_id = $_GET['user_id']; |
181 | 181 | |
182 | - if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { |
|
182 | + if (empty($user_id) || !is_numeric($user_id)) { |
|
183 | 183 | die(-1); |
184 | 184 | } |
185 | 185 | |
186 | 186 | // Fetch the billing details. |
187 | - $billing_details = wpinv_get_user_address( $user_id ); |
|
188 | - $billing_details = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id ); |
|
187 | + $billing_details = wpinv_get_user_address($user_id); |
|
188 | + $billing_details = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id); |
|
189 | 189 | |
190 | 190 | // unset the user id and email. |
191 | - $to_ignore = array( 'user_id', 'email' ); |
|
191 | + $to_ignore = array('user_id', 'email'); |
|
192 | 192 | |
193 | - foreach ( $to_ignore as $key ) { |
|
194 | - if ( isset( $billing_details[ $key ] ) ) { |
|
195 | - unset( $billing_details[ $key ] ); |
|
193 | + foreach ($to_ignore as $key) { |
|
194 | + if (isset($billing_details[$key])) { |
|
195 | + unset($billing_details[$key]); |
|
196 | 196 | } |
197 | 197 | } |
198 | 198 | |
199 | - wp_send_json_success( $billing_details ); |
|
199 | + wp_send_json_success($billing_details); |
|
200 | 200 | |
201 | 201 | } |
202 | 202 | |
@@ -206,47 +206,47 @@ discard block |
||
206 | 206 | public static function check_new_user_email() { |
207 | 207 | |
208 | 208 | // Verify nonce. |
209 | - check_ajax_referer( 'wpinv-nonce' ); |
|
209 | + check_ajax_referer('wpinv-nonce'); |
|
210 | 210 | |
211 | 211 | // Can the user manage the plugin? |
212 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
212 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
213 | 213 | die(-1); |
214 | 214 | } |
215 | 215 | |
216 | 216 | // We need an email address. |
217 | - if ( empty( $_GET['email'] ) ) { |
|
218 | - _e( "Provide the new user's email address", 'invoicing' ); |
|
217 | + if (empty($_GET['email'])) { |
|
218 | + _e("Provide the new user's email address", 'invoicing'); |
|
219 | 219 | exit; |
220 | 220 | } |
221 | 221 | |
222 | 222 | // Ensure the email is valid. |
223 | - $email = sanitize_text_field( $_GET['email'] ); |
|
224 | - if ( ! is_email( $email ) ) { |
|
225 | - _e( 'Invalid email address', 'invoicing' ); |
|
223 | + $email = sanitize_text_field($_GET['email']); |
|
224 | + if (!is_email($email)) { |
|
225 | + _e('Invalid email address', 'invoicing'); |
|
226 | 226 | exit; |
227 | 227 | } |
228 | 228 | |
229 | 229 | // And it does not exist. |
230 | - $id = email_exists( $email ); |
|
231 | - if ( $id ) { |
|
232 | - wp_send_json_success( compact( 'id' ) ); |
|
230 | + $id = email_exists($email); |
|
231 | + if ($id) { |
|
232 | + wp_send_json_success(compact('id')); |
|
233 | 233 | } |
234 | 234 | |
235 | - wp_send_json_success( true ); |
|
235 | + wp_send_json_success(true); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | public static function run_tool() { |
239 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
240 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
239 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
240 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
241 | 241 | die(-1); |
242 | 242 | } |
243 | 243 | |
244 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
244 | + $tool = sanitize_text_field($_POST['tool']); |
|
245 | 245 | |
246 | - do_action( 'wpinv_run_tool' ); |
|
246 | + do_action('wpinv_run_tool'); |
|
247 | 247 | |
248 | - if ( !empty( $tool ) ) { |
|
249 | - do_action( 'wpinv_tool_' . $tool ); |
|
248 | + if (!empty($tool)) { |
|
249 | + do_action('wpinv_tool_' . $tool); |
|
250 | 250 | } |
251 | 251 | } |
252 | 252 | |
@@ -257,43 +257,43 @@ discard block |
||
257 | 257 | global $getpaid_force_checkbox; |
258 | 258 | |
259 | 259 | // Check nonce. |
260 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
260 | + check_ajax_referer('getpaid_form_nonce'); |
|
261 | 261 | |
262 | 262 | // Is the request set up correctly? |
263 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) { |
|
263 | + if (empty($_GET['form']) && empty($_GET['item']) && empty($_GET['invoice'])) { |
|
264 | 264 | echo aui()->alert( |
265 | 265 | array( |
266 | 266 | 'type' => 'warning', |
267 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
267 | + 'content' => __('No payment form or item provided', 'invoicing'), |
|
268 | 268 | ) |
269 | 269 | ); |
270 | 270 | exit; |
271 | 271 | } |
272 | 272 | |
273 | 273 | // Payment form or button? |
274 | - if ( ! empty( $_GET['form'] ) ) { |
|
275 | - $form = urldecode( $_GET['form'] ); |
|
274 | + if (!empty($_GET['form'])) { |
|
275 | + $form = urldecode($_GET['form']); |
|
276 | 276 | |
277 | - if ( false !== strpos( $form, '|' ) ) { |
|
278 | - $form_pos = strpos( $form, '|' ); |
|
279 | - $_items = getpaid_convert_items_to_array( substr( $form, $form_pos + 1 ) ); |
|
280 | - $form = substr( $form, 0, $form_pos ); |
|
277 | + if (false !== strpos($form, '|')) { |
|
278 | + $form_pos = strpos($form, '|'); |
|
279 | + $_items = getpaid_convert_items_to_array(substr($form, $form_pos + 1)); |
|
280 | + $form = substr($form, 0, $form_pos); |
|
281 | 281 | |
282 | 282 | // Retrieve appropriate payment form. |
283 | - $payment_form = new GetPaid_Payment_Form( $form ); |
|
284 | - $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
283 | + $payment_form = new GetPaid_Payment_Form($form); |
|
284 | + $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
285 | 285 | |
286 | 286 | $items = array(); |
287 | 287 | $item_ids = array(); |
288 | 288 | |
289 | - foreach ( $_items as $item_id => $qty ) { |
|
290 | - if ( ! in_array( $item_id, $item_ids ) ) { |
|
291 | - $item = new GetPaid_Form_Item( $item_id ); |
|
292 | - $item->set_quantity( $qty ); |
|
289 | + foreach ($_items as $item_id => $qty) { |
|
290 | + if (!in_array($item_id, $item_ids)) { |
|
291 | + $item = new GetPaid_Form_Item($item_id); |
|
292 | + $item->set_quantity($qty); |
|
293 | 293 | |
294 | - if ( 0 == $qty ) { |
|
295 | - $item->set_allow_quantities( true ); |
|
296 | - $item->set_is_required( false ); |
|
294 | + if (0 == $qty) { |
|
295 | + $item->set_allow_quantities(true); |
|
296 | + $item->set_is_required(false); |
|
297 | 297 | $getpaid_force_checkbox = true; |
298 | 298 | } |
299 | 299 | |
@@ -302,10 +302,10 @@ discard block |
||
302 | 302 | } |
303 | 303 | } |
304 | 304 | |
305 | - if ( ! $payment_form->is_default() ) { |
|
305 | + if (!$payment_form->is_default()) { |
|
306 | 306 | |
307 | - foreach ( $payment_form->get_items() as $item ) { |
|
308 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
307 | + foreach ($payment_form->get_items() as $item) { |
|
308 | + if (!in_array($item->get_id(), $item_ids)) { |
|
309 | 309 | $item_ids[] = $item->get_id(); |
310 | 310 | $items[] = $item; |
311 | 311 | } |
@@ -313,23 +313,23 @@ discard block |
||
313 | 313 | |
314 | 314 | } |
315 | 315 | |
316 | - $payment_form->set_items( $items ); |
|
317 | - $extra_items = esc_attr( getpaid_convert_items_to_string( $_items ) ); |
|
318 | - $extra_items_key = md5( NONCE_KEY . AUTH_KEY . $extra_items ); |
|
316 | + $payment_form->set_items($items); |
|
317 | + $extra_items = esc_attr(getpaid_convert_items_to_string($_items)); |
|
318 | + $extra_items_key = md5(NONCE_KEY . AUTH_KEY . $extra_items); |
|
319 | 319 | $extra_items = "<input type='hidden' name='getpaid-form-items' value='$extra_items' />"; |
320 | 320 | $extra_items .= "<input type='hidden' name='getpaid-form-items-key' value='$extra_items_key' />"; |
321 | - $payment_form->display( $extra_items ); |
|
321 | + $payment_form->display($extra_items); |
|
322 | 322 | $getpaid_force_checkbox = false; |
323 | 323 | |
324 | 324 | } else { |
325 | - getpaid_display_payment_form( $form ); |
|
325 | + getpaid_display_payment_form($form); |
|
326 | 326 | } |
327 | 327 | |
328 | - } else if( ! empty( $_GET['invoice'] ) ) { |
|
329 | - getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) ); |
|
328 | + } else if (!empty($_GET['invoice'])) { |
|
329 | + getpaid_display_invoice_payment_form(urldecode($_GET['invoice'])); |
|
330 | 330 | } else { |
331 | - $items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) ); |
|
332 | - getpaid_display_item_payment_form( $items ); |
|
331 | + $items = getpaid_convert_items_to_array(urldecode($_GET['item'])); |
|
332 | + getpaid_display_item_payment_form($items); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | exit; |
@@ -344,17 +344,17 @@ discard block |
||
344 | 344 | public static function payment_form() { |
345 | 345 | |
346 | 346 | // Check nonce. |
347 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
347 | + check_ajax_referer('getpaid_form_nonce'); |
|
348 | 348 | |
349 | 349 | // ... form fields... |
350 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
351 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
350 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
351 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
352 | 352 | exit; |
353 | 353 | } |
354 | 354 | |
355 | 355 | // Process the payment form. |
356 | - $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' ); |
|
357 | - $checkout = new $checkout_class( new GetPaid_Payment_Form_Submission() ); |
|
356 | + $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout'); |
|
357 | + $checkout = new $checkout_class(new GetPaid_Payment_Form_Submission()); |
|
358 | 358 | $checkout->process_checkout(); |
359 | 359 | |
360 | 360 | exit; |
@@ -367,55 +367,55 @@ discard block |
||
367 | 367 | */ |
368 | 368 | public static function get_payment_form_states_field() { |
369 | 369 | |
370 | - if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) { |
|
370 | + if (empty($_GET['country']) || empty($_GET['form'])) { |
|
371 | 371 | exit; |
372 | 372 | } |
373 | 373 | |
374 | - $elements = getpaid_get_payment_form_elements( $_GET['form'] ); |
|
374 | + $elements = getpaid_get_payment_form_elements($_GET['form']); |
|
375 | 375 | |
376 | - if ( empty( $elements ) ) { |
|
376 | + if (empty($elements)) { |
|
377 | 377 | exit; |
378 | 378 | } |
379 | 379 | |
380 | 380 | $address_fields = array(); |
381 | - foreach ( $elements as $element ) { |
|
382 | - if ( 'address' === $element['type'] ) { |
|
381 | + foreach ($elements as $element) { |
|
382 | + if ('address' === $element['type']) { |
|
383 | 383 | $address_fields = $element; |
384 | 384 | break; |
385 | 385 | } |
386 | 386 | } |
387 | 387 | |
388 | - if ( empty( $address_fields ) ) { |
|
388 | + if (empty($address_fields)) { |
|
389 | 389 | exit; |
390 | 390 | } |
391 | 391 | |
392 | - foreach ( $address_fields['fields'] as $address_field ) { |
|
392 | + foreach ($address_fields['fields'] as $address_field) { |
|
393 | 393 | |
394 | - if ( 'wpinv_state' == $address_field['name'] ) { |
|
394 | + if ('wpinv_state' == $address_field['name']) { |
|
395 | 395 | |
396 | - $wrap_class = getpaid_get_form_element_grid_class( $address_field ); |
|
397 | - $wrap_class = esc_attr( "$wrap_class getpaid-address-field-wrapper" ); |
|
398 | - $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] ); |
|
399 | - $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] ); |
|
400 | - $value = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : ''; |
|
401 | - $label = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] ); |
|
396 | + $wrap_class = getpaid_get_form_element_grid_class($address_field); |
|
397 | + $wrap_class = esc_attr("$wrap_class getpaid-address-field-wrapper"); |
|
398 | + $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']); |
|
399 | + $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']); |
|
400 | + $value = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : ''; |
|
401 | + $label = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']); |
|
402 | 402 | |
403 | - if ( ! empty( $address_field['required'] ) ) { |
|
403 | + if (!empty($address_field['required'])) { |
|
404 | 404 | $label .= "<span class='text-danger'> *</span>"; |
405 | 405 | } |
406 | 406 | |
407 | - $html = getpaid_get_states_select_markup ( |
|
408 | - sanitize_text_field( $_GET['country'] ), |
|
407 | + $html = getpaid_get_states_select_markup( |
|
408 | + sanitize_text_field($_GET['country']), |
|
409 | 409 | $value, |
410 | 410 | $placeholder, |
411 | 411 | $label, |
412 | 412 | $description, |
413 | - ! empty( $address_field['required'] ), |
|
413 | + !empty($address_field['required']), |
|
414 | 414 | $wrap_class, |
415 | - wpinv_clean( $_GET['name'] ) |
|
415 | + wpinv_clean($_GET['name']) |
|
416 | 416 | ); |
417 | 417 | |
418 | - wp_send_json_success( $html ); |
|
418 | + wp_send_json_success($html); |
|
419 | 419 | exit; |
420 | 420 | |
421 | 421 | } |
@@ -431,66 +431,66 @@ discard block |
||
431 | 431 | public static function recalculate_invoice_totals() { |
432 | 432 | |
433 | 433 | // Verify nonce. |
434 | - check_ajax_referer( 'wpinv-nonce' ); |
|
434 | + check_ajax_referer('wpinv-nonce'); |
|
435 | 435 | |
436 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
436 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
437 | 437 | exit; |
438 | 438 | } |
439 | 439 | |
440 | 440 | // We need an invoice. |
441 | - if ( empty( $_POST['post_id'] ) ) { |
|
441 | + if (empty($_POST['post_id'])) { |
|
442 | 442 | exit; |
443 | 443 | } |
444 | 444 | |
445 | 445 | // Fetch the invoice. |
446 | - $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) ); |
|
446 | + $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id'])); |
|
447 | 447 | |
448 | 448 | // Ensure it exists. |
449 | - if ( ! $invoice->get_id() ) { |
|
449 | + if (!$invoice->get_id()) { |
|
450 | 450 | exit; |
451 | 451 | } |
452 | 452 | |
453 | 453 | // Maybe set the country, state, currency. |
454 | - foreach ( array( 'country', 'state', 'currency', 'vat_number', 'discount_code' ) as $key ) { |
|
455 | - if ( isset( $_POST[ $key ] ) ) { |
|
454 | + foreach (array('country', 'state', 'currency', 'vat_number', 'discount_code') as $key) { |
|
455 | + if (isset($_POST[$key])) { |
|
456 | 456 | $method = "set_$key"; |
457 | - $invoice->$method( sanitize_text_field( $_POST[ $key ] ) ); |
|
457 | + $invoice->$method(sanitize_text_field($_POST[$key])); |
|
458 | 458 | } |
459 | 459 | } |
460 | 460 | |
461 | 461 | // Maybe disable taxes. |
462 | - $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) ); |
|
462 | + $invoice->set_disable_taxes(!empty($_POST['taxes'])); |
|
463 | 463 | |
464 | 464 | // Discount code. |
465 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
466 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
467 | - if ( $discount->exists() ) { |
|
468 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
465 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
466 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
467 | + if ($discount->exists()) { |
|
468 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
469 | 469 | } else { |
470 | - $invoice->remove_discount( 'discount_code' ); |
|
470 | + $invoice->remove_discount('discount_code'); |
|
471 | 471 | } |
472 | 472 | } |
473 | 473 | |
474 | 474 | // Recalculate totals. |
475 | 475 | $invoice->recalculate_total(); |
476 | 476 | |
477 | - $total = wpinv_price( $invoice->get_total(), $invoice->get_currency() ); |
|
478 | - $suscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
479 | - if ( is_a( $suscriptions, 'WPInv_Subscription' ) && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) { |
|
480 | - $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() ); |
|
481 | - $total .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>'; |
|
477 | + $total = wpinv_price($invoice->get_total(), $invoice->get_currency()); |
|
478 | + $suscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
479 | + if (is_a($suscriptions, 'WPInv_Subscription') && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) { |
|
480 | + $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency()); |
|
481 | + $total .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>'; |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | $totals = array( |
485 | - 'subtotal' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ), |
|
486 | - 'discount' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ), |
|
487 | - 'tax' => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ), |
|
485 | + 'subtotal' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()), |
|
486 | + 'discount' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()), |
|
487 | + 'tax' => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()), |
|
488 | 488 | 'total' => $total, |
489 | 489 | ); |
490 | 490 | |
491 | - $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice ); |
|
491 | + $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice); |
|
492 | 492 | |
493 | - wp_send_json_success( compact( 'totals' ) ); |
|
493 | + wp_send_json_success(compact('totals')); |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | /** |
@@ -499,33 +499,33 @@ discard block |
||
499 | 499 | public static function get_invoice_items() { |
500 | 500 | |
501 | 501 | // Verify nonce. |
502 | - check_ajax_referer( 'wpinv-nonce' ); |
|
502 | + check_ajax_referer('wpinv-nonce'); |
|
503 | 503 | |
504 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
504 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
505 | 505 | exit; |
506 | 506 | } |
507 | 507 | |
508 | 508 | // We need an invoice and items. |
509 | - if ( empty( $_POST['post_id'] ) ) { |
|
509 | + if (empty($_POST['post_id'])) { |
|
510 | 510 | exit; |
511 | 511 | } |
512 | 512 | |
513 | 513 | // Fetch the invoice. |
514 | - $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) ); |
|
514 | + $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id'])); |
|
515 | 515 | |
516 | 516 | // Ensure it exists. |
517 | - if ( ! $invoice->get_id() ) { |
|
517 | + if (!$invoice->get_id()) { |
|
518 | 518 | exit; |
519 | 519 | } |
520 | 520 | |
521 | 521 | // Return an array of invoice items. |
522 | 522 | $items = array(); |
523 | 523 | |
524 | - foreach ( $invoice->get_items() as $item ) { |
|
525 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency(), $invoice->is_renewal() ); |
|
524 | + foreach ($invoice->get_items() as $item) { |
|
525 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency(), $invoice->is_renewal()); |
|
526 | 526 | } |
527 | 527 | |
528 | - wp_send_json_success( compact( 'items' ) ); |
|
528 | + wp_send_json_success(compact('items')); |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | /** |
@@ -534,50 +534,50 @@ discard block |
||
534 | 534 | public static function edit_invoice_item() { |
535 | 535 | |
536 | 536 | // Verify nonce. |
537 | - check_ajax_referer( 'wpinv-nonce' ); |
|
537 | + check_ajax_referer('wpinv-nonce'); |
|
538 | 538 | |
539 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
539 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
540 | 540 | exit; |
541 | 541 | } |
542 | 542 | |
543 | 543 | // We need an invoice and item details. |
544 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) { |
|
544 | + if (empty($_POST['post_id']) || empty($_POST['data'])) { |
|
545 | 545 | exit; |
546 | 546 | } |
547 | 547 | |
548 | 548 | // Fetch the invoice. |
549 | - $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) ); |
|
549 | + $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id'])); |
|
550 | 550 | |
551 | 551 | // Ensure it exists and its not been paid for. |
552 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
552 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
553 | 553 | exit; |
554 | 554 | } |
555 | 555 | |
556 | 556 | // Format the data. |
557 | - $data = wp_kses_post_deep( wp_unslash( wp_list_pluck( $_POST['data'], 'value', 'field' ) ) ); |
|
557 | + $data = wp_kses_post_deep(wp_unslash(wp_list_pluck($_POST['data'], 'value', 'field'))); |
|
558 | 558 | |
559 | 559 | // Ensure that we have an item id. |
560 | - if ( empty( $data['id'] ) ) { |
|
560 | + if (empty($data['id'])) { |
|
561 | 561 | exit; |
562 | 562 | } |
563 | 563 | |
564 | 564 | // Abort if the invoice does not have the specified item. |
565 | - $item = $invoice->get_item( (int) $data['id'] ); |
|
565 | + $item = $invoice->get_item((int) $data['id']); |
|
566 | 566 | |
567 | - if ( empty( $item ) ) { |
|
567 | + if (empty($item)) { |
|
568 | 568 | exit; |
569 | 569 | } |
570 | 570 | |
571 | 571 | // Update the item. |
572 | - $item->set_price( getpaid_standardize_amount( $data['price'] ) ); |
|
573 | - $item->set_name( sanitize_text_field( $data['name'] ) ); |
|
574 | - $item->set_description( wp_kses_post( $data['description'] ) ); |
|
575 | - $item->set_quantity( floatval( $data['quantity'] ) ); |
|
572 | + $item->set_price(getpaid_standardize_amount($data['price'])); |
|
573 | + $item->set_name(sanitize_text_field($data['name'])); |
|
574 | + $item->set_description(wp_kses_post($data['description'])); |
|
575 | + $item->set_quantity(floatval($data['quantity'])); |
|
576 | 576 | |
577 | 577 | // Add it to the invoice. |
578 | - $error = $invoice->add_item( $item ); |
|
578 | + $error = $invoice->add_item($item); |
|
579 | 579 | $alert = false; |
580 | - if ( is_wp_error( $error ) ) { |
|
580 | + if (is_wp_error($error)) { |
|
581 | 581 | $alert = $error->get_error_message(); |
582 | 582 | } |
583 | 583 | |
@@ -590,11 +590,11 @@ discard block |
||
590 | 590 | // Return an array of invoice items. |
591 | 591 | $items = array(); |
592 | 592 | |
593 | - foreach ( $invoice->get_items() as $item ) { |
|
594 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
593 | + foreach ($invoice->get_items() as $item) { |
|
594 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
595 | 595 | } |
596 | 596 | |
597 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
597 | + wp_send_json_success(compact('items', 'alert')); |
|
598 | 598 | } |
599 | 599 | |
600 | 600 | /** |
@@ -603,53 +603,53 @@ discard block |
||
603 | 603 | public static function create_invoice_item() { |
604 | 604 | |
605 | 605 | // Verify nonce. |
606 | - check_ajax_referer( 'wpinv-nonce' ); |
|
606 | + check_ajax_referer('wpinv-nonce'); |
|
607 | 607 | |
608 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
608 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
609 | 609 | exit; |
610 | 610 | } |
611 | 611 | |
612 | 612 | // We need an invoice and item details. |
613 | - if ( empty( $_POST['invoice_id'] ) || empty( $_POST['_wpinv_quick'] ) ) { |
|
613 | + if (empty($_POST['invoice_id']) || empty($_POST['_wpinv_quick'])) { |
|
614 | 614 | exit; |
615 | 615 | } |
616 | 616 | |
617 | 617 | // Fetch the invoice. |
618 | - $invoice = new WPInv_Invoice( wpinv_clean( $_POST['invoice_id'] ) ); |
|
618 | + $invoice = new WPInv_Invoice(wpinv_clean($_POST['invoice_id'])); |
|
619 | 619 | |
620 | 620 | // Ensure it exists and its not been paid for. |
621 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
621 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
622 | 622 | exit; |
623 | 623 | } |
624 | 624 | |
625 | 625 | // Format the data. |
626 | - $data = wp_unslash( $_POST['_wpinv_quick'] ); |
|
626 | + $data = wp_unslash($_POST['_wpinv_quick']); |
|
627 | 627 | |
628 | 628 | $item = new WPInv_Item(); |
629 | - $item->set_price( getpaid_standardize_amount( $data['price'] ) ); |
|
630 | - $item->set_name( sanitize_text_field( $data['name'] ) ); |
|
631 | - $item->set_description( wp_kses_post( $data['description'] ) ); |
|
632 | - $item->set_type( sanitize_text_field( $data['type'] ) ); |
|
633 | - $item->set_vat_rule( sanitize_text_field( $data['vat_rule'] ) ); |
|
634 | - $item->set_vat_class( sanitize_text_field( $data['vat_class'] ) ); |
|
635 | - $item->set_status( 'publish' ); |
|
629 | + $item->set_price(getpaid_standardize_amount($data['price'])); |
|
630 | + $item->set_name(sanitize_text_field($data['name'])); |
|
631 | + $item->set_description(wp_kses_post($data['description'])); |
|
632 | + $item->set_type(sanitize_text_field($data['type'])); |
|
633 | + $item->set_vat_rule(sanitize_text_field($data['vat_rule'])); |
|
634 | + $item->set_vat_class(sanitize_text_field($data['vat_class'])); |
|
635 | + $item->set_status('publish'); |
|
636 | 636 | $item->save(); |
637 | 637 | |
638 | - if ( ! $item->exists() ) { |
|
639 | - $alert = __( 'Could not create invoice item. Please try again.', 'invoicing' ); |
|
640 | - wp_send_json_success( compact( 'alert' ) ); |
|
638 | + if (!$item->exists()) { |
|
639 | + $alert = __('Could not create invoice item. Please try again.', 'invoicing'); |
|
640 | + wp_send_json_success(compact('alert')); |
|
641 | 641 | } |
642 | 642 | |
643 | - $item = new GetPaid_Form_Item( $item->get_id() ); |
|
644 | - $item->set_quantity( floatval( $data['qty'] ) ); |
|
643 | + $item = new GetPaid_Form_Item($item->get_id()); |
|
644 | + $item->set_quantity(floatval($data['qty'])); |
|
645 | 645 | |
646 | 646 | // Add it to the invoice. |
647 | - $error = $invoice->add_item( $item ); |
|
647 | + $error = $invoice->add_item($item); |
|
648 | 648 | $alert = false; |
649 | 649 | |
650 | - if ( is_wp_error( $error ) ) { |
|
650 | + if (is_wp_error($error)) { |
|
651 | 651 | $alert = $error->get_error_message(); |
652 | - wp_send_json_success( compact( 'alert' ) ); |
|
652 | + wp_send_json_success(compact('alert')); |
|
653 | 653 | } |
654 | 654 | |
655 | 655 | // Update totals. |
@@ -662,9 +662,9 @@ discard block |
||
662 | 662 | $invoice->recalculate_total(); |
663 | 663 | $invoice->save(); |
664 | 664 | ob_start(); |
665 | - GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice ); |
|
665 | + GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice); |
|
666 | 666 | $row = ob_get_clean(); |
667 | - wp_send_json_success( compact( 'row' ) ); |
|
667 | + wp_send_json_success(compact('row')); |
|
668 | 668 | } |
669 | 669 | |
670 | 670 | /** |
@@ -673,33 +673,33 @@ discard block |
||
673 | 673 | public static function remove_invoice_item() { |
674 | 674 | |
675 | 675 | // Verify nonce. |
676 | - check_ajax_referer( 'wpinv-nonce' ); |
|
676 | + check_ajax_referer('wpinv-nonce'); |
|
677 | 677 | |
678 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
678 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
679 | 679 | exit; |
680 | 680 | } |
681 | 681 | |
682 | 682 | // We need an invoice and an item. |
683 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
683 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
684 | 684 | exit; |
685 | 685 | } |
686 | 686 | |
687 | 687 | // Fetch the invoice. |
688 | - $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) ); |
|
688 | + $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id'])); |
|
689 | 689 | |
690 | 690 | // Ensure it exists and its not been paid for. |
691 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
691 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
692 | 692 | exit; |
693 | 693 | } |
694 | 694 | |
695 | 695 | // Abort if the invoice does not have the specified item. |
696 | - $item = $invoice->get_item( (int) $_POST['item_id'] ); |
|
696 | + $item = $invoice->get_item((int) $_POST['item_id']); |
|
697 | 697 | |
698 | - if ( empty( $item ) ) { |
|
698 | + if (empty($item)) { |
|
699 | 699 | exit; |
700 | 700 | } |
701 | 701 | |
702 | - $invoice->remove_item( (int) $_POST['item_id'] ); |
|
702 | + $invoice->remove_item((int) $_POST['item_id']); |
|
703 | 703 | |
704 | 704 | // Update totals. |
705 | 705 | $invoice->recalculate_total(); |
@@ -710,11 +710,11 @@ discard block |
||
710 | 710 | // Return an array of invoice items. |
711 | 711 | $items = array(); |
712 | 712 | |
713 | - foreach ( $invoice->get_items() as $item ) { |
|
714 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
713 | + foreach ($invoice->get_items() as $item) { |
|
714 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
715 | 715 | } |
716 | 716 | |
717 | - wp_send_json_success( compact( 'items' ) ); |
|
717 | + wp_send_json_success(compact('items')); |
|
718 | 718 | } |
719 | 719 | |
720 | 720 | /** |
@@ -723,69 +723,69 @@ discard block |
||
723 | 723 | public static function recalculate_full_prices() { |
724 | 724 | |
725 | 725 | // Verify nonce. |
726 | - check_ajax_referer( 'wpinv-nonce' ); |
|
726 | + check_ajax_referer('wpinv-nonce'); |
|
727 | 727 | |
728 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
728 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
729 | 729 | exit; |
730 | 730 | } |
731 | 731 | |
732 | 732 | // We need an invoice and item. |
733 | - if ( empty( $_POST['post_id'] ) ) { |
|
733 | + if (empty($_POST['post_id'])) { |
|
734 | 734 | exit; |
735 | 735 | } |
736 | 736 | |
737 | 737 | // Fetch the invoice. |
738 | - $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) ); |
|
738 | + $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id'])); |
|
739 | 739 | $alert = false; |
740 | 740 | |
741 | 741 | // Ensure it exists and its not been paid for. |
742 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
742 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
743 | 743 | exit; |
744 | 744 | } |
745 | 745 | |
746 | - $invoice->set_items( array() ); |
|
746 | + $invoice->set_items(array()); |
|
747 | 747 | |
748 | - if ( ! empty( $_POST['getpaid_items'] ) ) { |
|
748 | + if (!empty($_POST['getpaid_items'])) { |
|
749 | 749 | |
750 | - foreach ( $_POST['getpaid_items'] as $item_id => $args ) { |
|
751 | - $item = new GetPaid_Form_Item( $item_id ); |
|
750 | + foreach ($_POST['getpaid_items'] as $item_id => $args) { |
|
751 | + $item = new GetPaid_Form_Item($item_id); |
|
752 | 752 | |
753 | - if ( $item->exists() ) { |
|
754 | - $item->set_price( getpaid_standardize_amount( $args['price'] ) ); |
|
755 | - $item->set_quantity( floatval( $args['quantity'] ) ); |
|
756 | - $item->set_name( sanitize_text_field( $args['name'] ) ); |
|
757 | - $item->set_description( wp_kses_post( $args['description'] ) ); |
|
758 | - $invoice->add_item( $item ); |
|
753 | + if ($item->exists()) { |
|
754 | + $item->set_price(getpaid_standardize_amount($args['price'])); |
|
755 | + $item->set_quantity(floatval($args['quantity'])); |
|
756 | + $item->set_name(sanitize_text_field($args['name'])); |
|
757 | + $item->set_description(wp_kses_post($args['description'])); |
|
758 | + $invoice->add_item($item); |
|
759 | 759 | } |
760 | 760 | } |
761 | 761 | |
762 | 762 | } |
763 | 763 | |
764 | - $invoice->set_disable_taxes( ! empty( $_POST['disable_taxes'] ) ); |
|
764 | + $invoice->set_disable_taxes(!empty($_POST['disable_taxes'])); |
|
765 | 765 | |
766 | 766 | // Maybe set the country, state, currency. |
767 | - foreach ( array( 'wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code' ) as $key ) { |
|
768 | - if ( isset( $_POST[ $key ] ) ) { |
|
769 | - $_key = str_replace( 'wpinv_', '', $key ); |
|
767 | + foreach (array('wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code') as $key) { |
|
768 | + if (isset($_POST[$key])) { |
|
769 | + $_key = str_replace('wpinv_', '', $key); |
|
770 | 770 | $method = "set_$_key"; |
771 | - $invoice->$method( sanitize_text_field( $_POST[ $key ] ) ); |
|
771 | + $invoice->$method(sanitize_text_field($_POST[$key])); |
|
772 | 772 | } |
773 | 773 | } |
774 | 774 | |
775 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
776 | - if ( $discount->exists() ) { |
|
777 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
775 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
776 | + if ($discount->exists()) { |
|
777 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
778 | 778 | } else { |
779 | - $invoice->remove_discount( 'discount_code' ); |
|
779 | + $invoice->remove_discount('discount_code'); |
|
780 | 780 | } |
781 | 781 | |
782 | 782 | // Save the invoice. |
783 | 783 | $invoice->recalculate_total(); |
784 | 784 | $invoice->save(); |
785 | 785 | ob_start(); |
786 | - GetPaid_Meta_Box_Invoice_Items::output( get_post( $invoice->get_id() ), $invoice ); |
|
786 | + GetPaid_Meta_Box_Invoice_Items::output(get_post($invoice->get_id()), $invoice); |
|
787 | 787 | $table = ob_get_clean(); |
788 | - wp_send_json_success( compact( 'table' ) ); |
|
788 | + wp_send_json_success(compact('table')); |
|
789 | 789 | } |
790 | 790 | |
791 | 791 | /** |
@@ -794,42 +794,42 @@ discard block |
||
794 | 794 | public static function admin_add_invoice_item() { |
795 | 795 | |
796 | 796 | // Verify nonce. |
797 | - check_ajax_referer( 'wpinv-nonce' ); |
|
797 | + check_ajax_referer('wpinv-nonce'); |
|
798 | 798 | |
799 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
799 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
800 | 800 | exit; |
801 | 801 | } |
802 | 802 | |
803 | 803 | // We need an invoice and item. |
804 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
804 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
805 | 805 | exit; |
806 | 806 | } |
807 | 807 | |
808 | 808 | // Fetch the invoice. |
809 | - $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) ); |
|
809 | + $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id'])); |
|
810 | 810 | $alert = false; |
811 | 811 | |
812 | 812 | // Ensure it exists and its not been paid for. |
813 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
813 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
814 | 814 | exit; |
815 | 815 | } |
816 | 816 | |
817 | 817 | // Add the item. |
818 | - $item = new GetPaid_Form_Item( (int) $_POST['item_id'] ); |
|
819 | - $error = $invoice->add_item( $item ); |
|
818 | + $item = new GetPaid_Form_Item((int) $_POST['item_id']); |
|
819 | + $error = $invoice->add_item($item); |
|
820 | 820 | |
821 | - if ( is_wp_error( $error ) ) { |
|
821 | + if (is_wp_error($error)) { |
|
822 | 822 | $alert = $error->get_error_message(); |
823 | - wp_send_json_success( compact( 'alert' ) ); |
|
823 | + wp_send_json_success(compact('alert')); |
|
824 | 824 | } |
825 | 825 | |
826 | 826 | // Save the invoice. |
827 | 827 | $invoice->recalculate_total(); |
828 | 828 | $invoice->save(); |
829 | 829 | ob_start(); |
830 | - GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice ); |
|
830 | + GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice); |
|
831 | 831 | $row = ob_get_clean(); |
832 | - wp_send_json_success( compact( 'row' ) ); |
|
832 | + wp_send_json_success(compact('row')); |
|
833 | 833 | } |
834 | 834 | |
835 | 835 | /** |
@@ -838,39 +838,39 @@ discard block |
||
838 | 838 | public static function add_invoice_items() { |
839 | 839 | |
840 | 840 | // Verify nonce. |
841 | - check_ajax_referer( 'wpinv-nonce' ); |
|
841 | + check_ajax_referer('wpinv-nonce'); |
|
842 | 842 | |
843 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
843 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
844 | 844 | exit; |
845 | 845 | } |
846 | 846 | |
847 | 847 | // We need an invoice and items. |
848 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) { |
|
848 | + if (empty($_POST['post_id']) || empty($_POST['items'])) { |
|
849 | 849 | exit; |
850 | 850 | } |
851 | 851 | |
852 | 852 | // Fetch the invoice. |
853 | - $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) ); |
|
853 | + $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id'])); |
|
854 | 854 | $alert = false; |
855 | 855 | |
856 | 856 | // Ensure it exists and its not been paid for. |
857 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
857 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
858 | 858 | exit; |
859 | 859 | } |
860 | 860 | |
861 | 861 | // Add the items. |
862 | - foreach ( $_POST['items'] as $data ) { |
|
862 | + foreach ($_POST['items'] as $data) { |
|
863 | 863 | |
864 | - $item = new GetPaid_Form_Item( (int) $data[ 'id' ] ); |
|
864 | + $item = new GetPaid_Form_Item((int) $data['id']); |
|
865 | 865 | |
866 | - if ( is_numeric( $data[ 'qty' ] ) && (float) $data[ 'qty' ] > 0 ) { |
|
867 | - $item->set_quantity( floatval( $data[ 'qty' ] ) ); |
|
866 | + if (is_numeric($data['qty']) && (float) $data['qty'] > 0) { |
|
867 | + $item->set_quantity(floatval($data['qty'])); |
|
868 | 868 | } |
869 | 869 | |
870 | - if ( $item->get_id() > 0 ) { |
|
871 | - $error = $invoice->add_item( $item ); |
|
870 | + if ($item->get_id() > 0) { |
|
871 | + $error = $invoice->add_item($item); |
|
872 | 872 | |
873 | - if ( is_wp_error( $error ) ) { |
|
873 | + if (is_wp_error($error)) { |
|
874 | 874 | $alert = $error->get_error_message(); |
875 | 875 | } |
876 | 876 | |
@@ -885,11 +885,11 @@ discard block |
||
885 | 885 | // Return an array of invoice items. |
886 | 886 | $items = array(); |
887 | 887 | |
888 | - foreach ( $invoice->get_items() as $item ) { |
|
889 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
888 | + foreach ($invoice->get_items() as $item) { |
|
889 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
890 | 890 | } |
891 | 891 | |
892 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
892 | + wp_send_json_success(compact('items', 'alert')); |
|
893 | 893 | } |
894 | 894 | |
895 | 895 | /** |
@@ -898,15 +898,15 @@ discard block |
||
898 | 898 | public static function get_invoicing_items() { |
899 | 899 | |
900 | 900 | // Verify nonce. |
901 | - check_ajax_referer( 'wpinv-nonce' ); |
|
901 | + check_ajax_referer('wpinv-nonce'); |
|
902 | 902 | |
903 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
903 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
904 | 904 | exit; |
905 | 905 | } |
906 | 906 | |
907 | 907 | // We need a search term. |
908 | - if ( empty( $_GET['search'] ) ) { |
|
909 | - wp_send_json_success( array() ); |
|
908 | + if (empty($_GET['search'])) { |
|
909 | + wp_send_json_success(array()); |
|
910 | 910 | } |
911 | 911 | |
912 | 912 | // Retrieve items. |
@@ -915,8 +915,8 @@ discard block |
||
915 | 915 | 'orderby' => 'title', |
916 | 916 | 'order' => 'ASC', |
917 | 917 | 'posts_per_page' => -1, |
918 | - 'post_status' => array( 'publish' ), |
|
919 | - 's' => trim( $_GET['search'] ), |
|
918 | + 'post_status' => array('publish'), |
|
919 | + 's' => trim($_GET['search']), |
|
920 | 920 | 'meta_query' => array( |
921 | 921 | array( |
922 | 922 | 'key' => '_wpinv_type', |
@@ -926,21 +926,21 @@ discard block |
||
926 | 926 | ) |
927 | 927 | ); |
928 | 928 | |
929 | - $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) ); |
|
929 | + $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args)); |
|
930 | 930 | $data = array(); |
931 | 931 | |
932 | - $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( $_GET['post_id'] ) ); |
|
932 | + $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type($_GET['post_id'])); |
|
933 | 933 | |
934 | - foreach ( $items as $item ) { |
|
935 | - $item = new GetPaid_Form_Item( $item ); |
|
934 | + foreach ($items as $item) { |
|
935 | + $item = new GetPaid_Form_Item($item); |
|
936 | 936 | $data[] = array( |
937 | 937 | 'id' => (int) $item->get_id(), |
938 | - 'text' => strip_tags( $item->get_name() ), |
|
939 | - 'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '', |
|
938 | + 'text' => strip_tags($item->get_name()), |
|
939 | + 'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '', |
|
940 | 940 | ); |
941 | 941 | } |
942 | 942 | |
943 | - wp_send_json_success( $data ); |
|
943 | + wp_send_json_success($data); |
|
944 | 944 | |
945 | 945 | } |
946 | 946 | |
@@ -950,37 +950,37 @@ discard block |
||
950 | 950 | public static function get_customers() { |
951 | 951 | |
952 | 952 | // Verify nonce. |
953 | - check_ajax_referer( 'wpinv-nonce' ); |
|
953 | + check_ajax_referer('wpinv-nonce'); |
|
954 | 954 | |
955 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
955 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
956 | 956 | exit; |
957 | 957 | } |
958 | 958 | |
959 | 959 | // We need a search term. |
960 | - if ( empty( $_GET['search'] ) ) { |
|
961 | - wp_send_json_success( array() ); |
|
960 | + if (empty($_GET['search'])) { |
|
961 | + wp_send_json_success(array()); |
|
962 | 962 | } |
963 | 963 | |
964 | 964 | // Retrieve customers. |
965 | 965 | |
966 | 966 | $customer_args = array( |
967 | - 'fields' => array( 'ID', 'user_email', 'display_name' ), |
|
967 | + 'fields' => array('ID', 'user_email', 'display_name'), |
|
968 | 968 | 'orderby' => 'display_name', |
969 | - 'search' => '*' . sanitize_text_field( $_GET['search'] ) . '*', |
|
970 | - 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
969 | + 'search' => '*' . sanitize_text_field($_GET['search']) . '*', |
|
970 | + 'search_columns' => array('user_login', 'user_email', 'display_name'), |
|
971 | 971 | ); |
972 | 972 | |
973 | - $customers = get_users( apply_filters( 'getpaid_ajax_invoice_customers_query_args', $customer_args ) ); |
|
973 | + $customers = get_users(apply_filters('getpaid_ajax_invoice_customers_query_args', $customer_args)); |
|
974 | 974 | $data = array(); |
975 | 975 | |
976 | - foreach ( $customers as $customer ) { |
|
976 | + foreach ($customers as $customer) { |
|
977 | 977 | $data[] = array( |
978 | 978 | 'id' => (int) $customer->ID, |
979 | - 'text' => strip_tags( sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ) ), |
|
979 | + 'text' => strip_tags(sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email)), |
|
980 | 980 | ); |
981 | 981 | } |
982 | 982 | |
983 | - wp_send_json_success( $data ); |
|
983 | + wp_send_json_success($data); |
|
984 | 984 | |
985 | 985 | } |
986 | 986 | |
@@ -990,28 +990,28 @@ discard block |
||
990 | 990 | public static function get_aui_states_field() { |
991 | 991 | |
992 | 992 | // Verify nonce. |
993 | - check_ajax_referer( 'wpinv-nonce' ); |
|
993 | + check_ajax_referer('wpinv-nonce'); |
|
994 | 994 | |
995 | 995 | // We need a country. |
996 | - if ( empty( $_GET['country'] ) ) { |
|
996 | + if (empty($_GET['country'])) { |
|
997 | 997 | exit; |
998 | 998 | } |
999 | 999 | |
1000 | - $states = wpinv_get_country_states( sanitize_text_field( $_GET['country'] ) ); |
|
1001 | - $state = isset( $_GET['state'] ) ? sanitize_text_field( $_GET['state'] ) : wpinv_get_default_state(); |
|
1002 | - $name = isset( $_GET['name'] ) ? sanitize_text_field( $_GET['name'] ) : 'wpinv_state'; |
|
1003 | - $class = isset( $_GET['class'] ) ? sanitize_text_field( $_GET['class'] ) : 'form-control-sm'; |
|
1000 | + $states = wpinv_get_country_states(sanitize_text_field($_GET['country'])); |
|
1001 | + $state = isset($_GET['state']) ? sanitize_text_field($_GET['state']) : wpinv_get_default_state(); |
|
1002 | + $name = isset($_GET['name']) ? sanitize_text_field($_GET['name']) : 'wpinv_state'; |
|
1003 | + $class = isset($_GET['class']) ? sanitize_text_field($_GET['class']) : 'form-control-sm'; |
|
1004 | 1004 | |
1005 | - if ( empty( $states ) ) { |
|
1005 | + if (empty($states)) { |
|
1006 | 1006 | |
1007 | 1007 | $html = aui()->input( |
1008 | 1008 | array( |
1009 | 1009 | 'type' => 'text', |
1010 | 1010 | 'id' => 'wpinv_state', |
1011 | 1011 | 'name' => $name, |
1012 | - 'label' => __( 'State', 'invoicing' ), |
|
1012 | + 'label' => __('State', 'invoicing'), |
|
1013 | 1013 | 'label_type' => 'vertical', |
1014 | - 'placeholder' => __( 'State', 'invoicing' ), |
|
1014 | + 'placeholder' => __('State', 'invoicing'), |
|
1015 | 1015 | 'class' => $class, |
1016 | 1016 | 'value' => $state, |
1017 | 1017 | ) |
@@ -1023,9 +1023,9 @@ discard block |
||
1023 | 1023 | array( |
1024 | 1024 | 'id' => 'wpinv_state', |
1025 | 1025 | 'name' => $name, |
1026 | - 'label' => __( 'State', 'invoicing' ), |
|
1026 | + 'label' => __('State', 'invoicing'), |
|
1027 | 1027 | 'label_type' => 'vertical', |
1028 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
1028 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
1029 | 1029 | 'class' => $class, |
1030 | 1030 | 'value' => $state, |
1031 | 1031 | 'options' => $states, |
@@ -1039,7 +1039,7 @@ discard block |
||
1039 | 1039 | wp_send_json_success( |
1040 | 1040 | array( |
1041 | 1041 | 'html' => $html, |
1042 | - 'select' => ! empty ( $states ) |
|
1042 | + 'select' => !empty ($states) |
|
1043 | 1043 | ) |
1044 | 1044 | ); |
1045 | 1045 | |
@@ -1053,11 +1053,11 @@ discard block |
||
1053 | 1053 | public static function payment_form_refresh_prices() { |
1054 | 1054 | |
1055 | 1055 | // Check nonce. |
1056 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
1056 | + check_ajax_referer('getpaid_form_nonce'); |
|
1057 | 1057 | |
1058 | 1058 | // ... form fields... |
1059 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
1060 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
1059 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
1060 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
1061 | 1061 | exit; |
1062 | 1062 | } |
1063 | 1063 | |
@@ -1065,7 +1065,7 @@ discard block |
||
1065 | 1065 | $submission = new GetPaid_Payment_Form_Submission(); |
1066 | 1066 | |
1067 | 1067 | // Do we have an error? |
1068 | - if ( ! empty( $submission->last_error ) ) { |
|
1068 | + if (!empty($submission->last_error)) { |
|
1069 | 1069 | wp_send_json_error( |
1070 | 1070 | array( |
1071 | 1071 | 'code' => $submission->last_error_code, |
@@ -1075,12 +1075,12 @@ discard block |
||
1075 | 1075 | } |
1076 | 1076 | |
1077 | 1077 | // Prepare the response. |
1078 | - $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission ); |
|
1078 | + $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission); |
|
1079 | 1079 | |
1080 | 1080 | // Filter the response. |
1081 | - $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission ); |
|
1081 | + $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission); |
|
1082 | 1082 | |
1083 | - wp_send_json_success( $response ); |
|
1083 | + wp_send_json_success($response); |
|
1084 | 1084 | } |
1085 | 1085 | |
1086 | 1086 | } |