@@ -6,33 +6,33 @@ |
||
6 | 6 | |
7 | 7 | class ComposerStaticInit8b6d4385c391849a80038f0b0e87c8b5 |
8 | 8 | { |
9 | - public static $files = array ( |
|
9 | + public static $files = array( |
|
10 | 10 | 'e8d544c98e79f913e13eae1306ab635e' => __DIR__ . '/..' . '/ayecode/wp-ayecode-ui/ayecode-ui-loader.php', |
11 | 11 | '24583d3588ebda5228dd453cfaa070da' => __DIR__ . '/..' . '/ayecode/wp-font-awesome-settings/wp-font-awesome-settings.php', |
12 | 12 | ); |
13 | 13 | |
14 | - public static $prefixLengthsPsr4 = array ( |
|
14 | + public static $prefixLengthsPsr4 = array( |
|
15 | 15 | 'C' => |
16 | - array ( |
|
16 | + array( |
|
17 | 17 | 'Composer\\Installers\\' => 20, |
18 | 18 | ), |
19 | 19 | ); |
20 | 20 | |
21 | - public static $prefixDirsPsr4 = array ( |
|
21 | + public static $prefixDirsPsr4 = array( |
|
22 | 22 | 'Composer\\Installers\\' => |
23 | - array ( |
|
23 | + array( |
|
24 | 24 | 0 => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers', |
25 | 25 | ), |
26 | 26 | ); |
27 | 27 | |
28 | - public static $classMap = array ( |
|
28 | + public static $classMap = array( |
|
29 | 29 | 'AyeCode_Connect_Helper' => __DIR__ . '/..' . '/ayecode/ayecode-connect-helper/ayecode-connect-helper.php', |
30 | 30 | 'WP_Super_Duper' => __DIR__ . '/..' . '/ayecode/wp-super-duper/wp-super-duper.php', |
31 | 31 | ); |
32 | 32 | |
33 | 33 | public static function getInitializer(ClassLoader $loader) |
34 | 34 | { |
35 | - return \Closure::bind(function () use ($loader) { |
|
35 | + return \Closure::bind(function() use ($loader) { |
|
36 | 36 | $loader->prefixLengthsPsr4 = ComposerStaticInit8b6d4385c391849a80038f0b0e87c8b5::$prefixLengthsPsr4; |
37 | 37 | $loader->prefixDirsPsr4 = ComposerStaticInit8b6d4385c391849a80038f0b0e87c8b5::$prefixDirsPsr4; |
38 | 38 | $loader->classMap = ComposerStaticInit8b6d4385c391849a80038f0b0e87c8b5::$classMap; |
@@ -8,13 +8,13 @@ discard block |
||
8 | 8 | * @version 1.0.19 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | return array( |
14 | 14 | |
15 | 15 | array( |
16 | 16 | |
17 | - 'title' => __( 'My Cool Item', 'invoicing' ), |
|
17 | + 'title' => __('My Cool Item', 'invoicing'), |
|
18 | 18 | 'id' => 'fxhnagzi', |
19 | 19 | 'price' => '999.00', |
20 | 20 | 'recurring' => false, |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | |
25 | 25 | array( |
26 | 26 | |
27 | - 'title' => __( 'Shipping Fee', 'invoicing' ), |
|
27 | + 'title' => __('Shipping Fee', 'invoicing'), |
|
28 | 28 | 'id' => 'rxnymibri', |
29 | 29 | 'price' => '19.99', |
30 | 30 | 'recurring' => false, |
@@ -8,14 +8,14 @@ discard block |
||
8 | 8 | * @version 1.0.19 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | return array( |
14 | 14 | |
15 | 15 | array( |
16 | 16 | |
17 | 17 | 'level' => 'h2', |
18 | - 'text' => __( 'Payment Form', 'invoicing' ), |
|
18 | + 'text' => __('Payment Form', 'invoicing'), |
|
19 | 19 | 'id' => 'uiylyczw', |
20 | 20 | 'name' => 'uiylyczw', |
21 | 21 | 'type' => 'heading' |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | |
24 | 24 | array( |
25 | 25 | |
26 | - 'text' => __( 'Fill the form below to place an order for my cool item', 'invoicing' ), |
|
26 | + 'text' => __('Fill the form below to place an order for my cool item', 'invoicing'), |
|
27 | 27 | 'id' => 'pcvqjj', |
28 | 28 | 'name' => 'pcvqjj', |
29 | 29 | 'type' => 'paragraph' |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | |
35 | 35 | 'placeholder' => 'Jon', |
36 | 36 | 'value' => '', |
37 | - 'label' => __( 'First Name', 'invoicing' ), |
|
37 | + 'label' => __('First Name', 'invoicing'), |
|
38 | 38 | 'description' => '', |
39 | 39 | 'required' => false, |
40 | 40 | 'id' => 'ynkzkjyc', |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | |
48 | 48 | 'placeholder' => 'Snow', |
49 | 49 | 'value' => '', |
50 | - 'label' => __( 'Last Name', 'invoicing' ), |
|
50 | + 'label' => __('Last Name', 'invoicing'), |
|
51 | 51 | 'description' => '', |
52 | 52 | 'required' => false, |
53 | 53 | 'id' => 'wfjcdmzox', |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | |
61 | 61 | 'placeholder' => '[email protected]', |
62 | 62 | 'value' => '', |
63 | - 'label' => __( 'Billing Email', 'invoicing' ), |
|
63 | + 'label' => __('Billing Email', 'invoicing'), |
|
64 | 64 | 'description' => '', |
65 | 65 | 'required' => true, |
66 | 66 | 'id' => 'mmdwqzpox', |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | |
86 | 86 | 'value' =>'', |
87 | 87 | 'class' => 'btn-primary', |
88 | - 'label' => __( 'Pay Now »', 'invoicing' ), |
|
89 | - 'description' => __( 'By continuing with your payment, you are agreeing to our privacy policy and terms of service.', 'invoicing' ), |
|
88 | + 'label' => __('Pay Now »', 'invoicing'), |
|
89 | + 'description' => __('By continuing with your payment, you are agreeing to our privacy policy and terms of service.', 'invoicing'), |
|
90 | 90 | 'id' => 'rtqljyy', |
91 | 91 | 'name' => 'rtqljyy', |
92 | 92 | 'type' => 'pay_button', |
@@ -1,70 +1,70 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | -function wpinv_add_meta_boxes( $post_type, $post ) { |
|
7 | +function wpinv_add_meta_boxes($post_type, $post) { |
|
8 | 8 | global $wpi_mb_invoice; |
9 | - if ( $post_type == 'wpi_invoice' && !empty( $post->ID ) ) { |
|
10 | - $wpi_mb_invoice = wpinv_get_invoice( $post->ID ); |
|
9 | + if ($post_type == 'wpi_invoice' && !empty($post->ID)) { |
|
10 | + $wpi_mb_invoice = wpinv_get_invoice($post->ID); |
|
11 | 11 | } |
12 | 12 | |
13 | - if ( !empty( $wpi_mb_invoice ) && !$wpi_mb_invoice->has_status( array( 'draft', 'auto-draft' ) ) ) { |
|
14 | - add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high' ); |
|
13 | + if (!empty($wpi_mb_invoice) && !$wpi_mb_invoice->has_status(array('draft', 'auto-draft'))) { |
|
14 | + add_meta_box('wpinv-mb-resend-invoice', __('Resend Invoice', 'invoicing'), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high'); |
|
15 | 15 | } |
16 | 16 | |
17 | - if ( !empty( $wpi_mb_invoice ) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent() ) { |
|
18 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscriptions', 'invoicing' ), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high' ); |
|
17 | + if (!empty($wpi_mb_invoice) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent()) { |
|
18 | + add_meta_box('wpinv-mb-subscriptions', __('Subscriptions', 'invoicing'), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high'); |
|
19 | 19 | } |
20 | 20 | |
21 | - if ( wpinv_is_subscription_payment( $wpi_mb_invoice ) ) { |
|
22 | - add_meta_box( 'wpinv-mb-renewals', __( 'Renewal Payment', 'invoicing' ), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high' ); |
|
21 | + if (wpinv_is_subscription_payment($wpi_mb_invoice)) { |
|
22 | + add_meta_box('wpinv-mb-renewals', __('Renewal Payment', 'invoicing'), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high'); |
|
23 | 23 | } |
24 | 24 | |
25 | - add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default' ); |
|
26 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default' ); |
|
25 | + add_meta_box('wpinv-details', __('Invoice Details', 'invoicing'), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default'); |
|
26 | + add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default'); |
|
27 | 27 | |
28 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
29 | - add_meta_box( 'wpinv-payment-form-shortcode', __( 'Shortcode', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_shortcode', 'wpi_payment_form', 'side' ); |
|
28 | + add_meta_box('wpinv-payment-form-design', __('Payment Form', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal'); |
|
29 | + add_meta_box('wpinv-payment-form-shortcode', __('Shortcode', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_shortcode', 'wpi_payment_form', 'side'); |
|
30 | 30 | |
31 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high' ); |
|
32 | - add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high' ); |
|
33 | - add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' ); |
|
31 | + add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high'); |
|
32 | + add_meta_box('wpinv-items', __('Invoice Items', 'invoicing'), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high'); |
|
33 | + add_meta_box('wpinv-notes', __('Invoice Notes', 'invoicing'), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high'); |
|
34 | 34 | |
35 | 35 | remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal'); |
36 | 36 | } |
37 | -add_action( 'add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2 ); |
|
37 | +add_action('add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2); |
|
38 | 38 | |
39 | -function wpinv_save_meta_boxes( $post_id, $post, $update = false ) { |
|
40 | - remove_action( 'save_post', __FUNCTION__ ); |
|
39 | +function wpinv_save_meta_boxes($post_id, $post, $update = false) { |
|
40 | + remove_action('save_post', __FUNCTION__); |
|
41 | 41 | |
42 | 42 | // $post_id and $post are required |
43 | - if ( empty( $post_id ) || empty( $post ) ) { |
|
43 | + if (empty($post_id) || empty($post)) { |
|
44 | 44 | return; |
45 | 45 | } |
46 | 46 | |
47 | - if ( !current_user_can( 'edit_post', $post_id ) || empty( $post->post_type ) ) { |
|
47 | + if (!current_user_can('edit_post', $post_id) || empty($post->post_type)) { |
|
48 | 48 | return; |
49 | 49 | } |
50 | 50 | |
51 | 51 | // Dont' save meta boxes for revisions or autosaves |
52 | - if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
52 | + if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
53 | 53 | return; |
54 | 54 | } |
55 | 55 | |
56 | - if ( $post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote' ) { |
|
57 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
56 | + if ($post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote') { |
|
57 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
58 | 58 | return; |
59 | 59 | } |
60 | 60 | |
61 | - if ( isset( $_POST['wpinv_save_invoice'] ) && wp_verify_nonce( $_POST['wpinv_save_invoice'], 'wpinv_save_invoice' ) ) { |
|
62 | - WPInv_Meta_Box_Items::save( $post_id, $_POST, $post ); |
|
61 | + if (isset($_POST['wpinv_save_invoice']) && wp_verify_nonce($_POST['wpinv_save_invoice'], 'wpinv_save_invoice')) { |
|
62 | + WPInv_Meta_Box_Items::save($post_id, $_POST, $post); |
|
63 | 63 | } |
64 | - } else if ( $post->post_type == 'wpi_item' ) { |
|
64 | + } else if ($post->post_type == 'wpi_item') { |
|
65 | 65 | // verify nonce |
66 | - if ( isset( $_POST['wpinv_vat_meta_box_nonce'] ) && wp_verify_nonce( $_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save' ) ) { |
|
67 | - $fields = array(); |
|
66 | + if (isset($_POST['wpinv_vat_meta_box_nonce']) && wp_verify_nonce($_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save')) { |
|
67 | + $fields = array(); |
|
68 | 68 | $fields['_wpinv_price'] = 'wpinv_item_price'; |
69 | 69 | $fields['_wpinv_vat_class'] = 'wpinv_vat_class'; |
70 | 70 | $fields['_wpinv_vat_rule'] = 'wpinv_vat_rules'; |
@@ -79,96 +79,96 @@ discard block |
||
79 | 79 | $fields['_wpinv_dynamic_pricing'] = 'wpinv_name_your_price'; |
80 | 80 | $fields['_minimum_price'] = 'wpinv_minimum_price'; |
81 | 81 | |
82 | - if ( !isset( $_POST['wpinv_is_recurring'] ) ) { |
|
82 | + if (!isset($_POST['wpinv_is_recurring'])) { |
|
83 | 83 | $_POST['wpinv_is_recurring'] = 0; |
84 | 84 | } |
85 | 85 | |
86 | - if ( !isset( $_POST['wpinv_name_your_price'] ) ) { |
|
86 | + if (!isset($_POST['wpinv_name_your_price'])) { |
|
87 | 87 | $_POST['wpinv_name_your_price'] = 0; |
88 | 88 | } |
89 | 89 | |
90 | - if ( !isset( $_POST['wpinv_free_trial'] ) || empty( $_POST['wpinv_is_recurring'] ) ) { |
|
90 | + if (!isset($_POST['wpinv_free_trial']) || empty($_POST['wpinv_is_recurring'])) { |
|
91 | 91 | $_POST['wpinv_free_trial'] = 0; |
92 | 92 | } |
93 | 93 | |
94 | - foreach ( $fields as $field => $name ) { |
|
95 | - if ( isset( $_POST[ $name ] ) ) { |
|
96 | - $allowed = apply_filters( 'wpinv_item_allowed_save_meta_value', true, $field, $post_id ); |
|
94 | + foreach ($fields as $field => $name) { |
|
95 | + if (isset($_POST[$name])) { |
|
96 | + $allowed = apply_filters('wpinv_item_allowed_save_meta_value', true, $field, $post_id); |
|
97 | 97 | |
98 | - if ( !$allowed ) { |
|
98 | + if (!$allowed) { |
|
99 | 99 | continue; |
100 | 100 | } |
101 | 101 | |
102 | - if ( $field == '_wpinv_price' ) { |
|
103 | - $value = wpinv_sanitize_amount( $_POST[ $name ] ); |
|
102 | + if ($field == '_wpinv_price') { |
|
103 | + $value = wpinv_sanitize_amount($_POST[$name]); |
|
104 | 104 | } else { |
105 | - $value = is_string( $_POST[ $name ] ) ? sanitize_text_field( $_POST[ $name ] ) : $_POST[ $name ]; |
|
105 | + $value = is_string($_POST[$name]) ? sanitize_text_field($_POST[$name]) : $_POST[$name]; |
|
106 | 106 | } |
107 | 107 | |
108 | - $value = apply_filters( 'wpinv_item_metabox_save_' . $field, $value, $name ); |
|
109 | - update_post_meta( $post_id, $field, $value ); |
|
108 | + $value = apply_filters('wpinv_item_metabox_save_' . $field, $value, $name); |
|
109 | + update_post_meta($post_id, $field, $value); |
|
110 | 110 | } |
111 | 111 | } |
112 | 112 | |
113 | - if ( !get_post_meta( $post_id, '_wpinv_custom_id', true ) ) { |
|
114 | - update_post_meta( $post_id, '_wpinv_custom_id', $post_id ); |
|
113 | + if (!get_post_meta($post_id, '_wpinv_custom_id', true)) { |
|
114 | + update_post_meta($post_id, '_wpinv_custom_id', $post_id); |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | } |
118 | 118 | } |
119 | -add_action( 'save_post', 'wpinv_save_meta_boxes', 10, 3 ); |
|
119 | +add_action('save_post', 'wpinv_save_meta_boxes', 10, 3); |
|
120 | 120 | |
121 | 121 | function wpinv_register_item_meta_boxes() { |
122 | 122 | global $wpinv_euvat; |
123 | 123 | |
124 | - add_meta_box( 'wpinv_field_prices', __( 'Item Price', 'invoicing' ), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high' ); |
|
124 | + add_meta_box('wpinv_field_prices', __('Item Price', 'invoicing'), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high'); |
|
125 | 125 | |
126 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
127 | - add_meta_box( 'wpinv_field_vat_rules', __( 'VAT rules type to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high' ); |
|
126 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
127 | + add_meta_box('wpinv_field_vat_rules', __('VAT rules type to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high'); |
|
128 | 128 | } |
129 | 129 | |
130 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
131 | - add_meta_box( 'wpinv_field_vat_classes', __( 'VAT rates class to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high' ); |
|
130 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
131 | + add_meta_box('wpinv_field_vat_classes', __('VAT rates class to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high'); |
|
132 | 132 | } |
133 | 133 | |
134 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core' ); |
|
135 | - add_meta_box( 'wpinv_field_meta_values', __( 'Item Meta Values', 'invoicing' ), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core' ); |
|
134 | + add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core'); |
|
135 | + add_meta_box('wpinv_field_meta_values', __('Item Meta Values', 'invoicing'), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core'); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | function wpinv_register_discount_meta_boxes() { |
139 | - add_meta_box( 'wpinv_discount_fields', __( 'Discount Details', 'invoicing' ), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high' ); |
|
139 | + add_meta_box('wpinv_discount_fields', __('Discount Details', 'invoicing'), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high'); |
|
140 | 140 | } |
141 | 141 | |
142 | -function wpinv_discount_metabox_details( $post ) { |
|
142 | +function wpinv_discount_metabox_details($post) { |
|
143 | 143 | $discount_id = $post->ID; |
144 | - $discount = wpinv_get_discount( $discount_id ); |
|
144 | + $discount = wpinv_get_discount($discount_id); |
|
145 | 145 | |
146 | - $type = wpinv_get_discount_type( $discount_id ); |
|
147 | - $item_reqs = wpinv_get_discount_item_reqs( $discount_id ); |
|
148 | - $excluded_items = wpinv_get_discount_excluded_items( $discount_id ); |
|
149 | - $min_total = wpinv_get_discount_min_total( $discount_id ); |
|
150 | - $max_total = wpinv_get_discount_max_total( $discount_id ); |
|
151 | - $max_uses = wpinv_get_discount_max_uses( $discount_id ); |
|
152 | - $single_use = wpinv_discount_is_single_use( $discount_id ); |
|
153 | - $recurring = (bool)wpinv_discount_is_recurring( $discount_id ); |
|
154 | - $start_date = wpinv_get_discount_start_date( $discount_id ); |
|
155 | - $expiration_date = wpinv_get_discount_expiration( $discount_id ); |
|
146 | + $type = wpinv_get_discount_type($discount_id); |
|
147 | + $item_reqs = wpinv_get_discount_item_reqs($discount_id); |
|
148 | + $excluded_items = wpinv_get_discount_excluded_items($discount_id); |
|
149 | + $min_total = wpinv_get_discount_min_total($discount_id); |
|
150 | + $max_total = wpinv_get_discount_max_total($discount_id); |
|
151 | + $max_uses = wpinv_get_discount_max_uses($discount_id); |
|
152 | + $single_use = wpinv_discount_is_single_use($discount_id); |
|
153 | + $recurring = (bool) wpinv_discount_is_recurring($discount_id); |
|
154 | + $start_date = wpinv_get_discount_start_date($discount_id); |
|
155 | + $expiration_date = wpinv_get_discount_expiration($discount_id); |
|
156 | 156 | |
157 | - if ( ! empty( $start_date ) && strpos( $start_date, '0000' ) === false ) { |
|
158 | - $start_time = strtotime( $start_date ); |
|
159 | - $start_h = date_i18n( 'H', $start_time ); |
|
160 | - $start_m = date_i18n( 'i', $start_time ); |
|
161 | - $start_date = date_i18n( 'Y-m-d', $start_time ); |
|
157 | + if (!empty($start_date) && strpos($start_date, '0000') === false) { |
|
158 | + $start_time = strtotime($start_date); |
|
159 | + $start_h = date_i18n('H', $start_time); |
|
160 | + $start_m = date_i18n('i', $start_time); |
|
161 | + $start_date = date_i18n('Y-m-d', $start_time); |
|
162 | 162 | } else { |
163 | 163 | $start_h = '00'; |
164 | 164 | $start_m = '00'; |
165 | 165 | } |
166 | 166 | |
167 | - if ( ! empty( $expiration_date ) && strpos( $expiration_date, '0000' ) === false ) { |
|
168 | - $expiration_time = strtotime( $expiration_date ); |
|
169 | - $expiration_h = date_i18n( 'H', $expiration_time ); |
|
170 | - $expiration_m = date_i18n( 'i', $expiration_time ); |
|
171 | - $expiration_date = date_i18n( 'Y-m-d', $expiration_time ); |
|
167 | + if (!empty($expiration_date) && strpos($expiration_date, '0000') === false) { |
|
168 | + $expiration_time = strtotime($expiration_date); |
|
169 | + $expiration_h = date_i18n('H', $expiration_time); |
|
170 | + $expiration_m = date_i18n('i', $expiration_time); |
|
171 | + $expiration_date = date_i18n('Y-m-d', $expiration_time); |
|
172 | 172 | } else { |
173 | 173 | $expiration_h = '23'; |
174 | 174 | $expiration_m = '59'; |
@@ -178,207 +178,207 @@ discard block |
||
178 | 178 | $max_total = $max_total > 0 ? $max_total : ''; |
179 | 179 | $max_uses = $max_uses > 0 ? $max_uses : ''; |
180 | 180 | ?> |
181 | -<?php do_action( 'wpinv_discount_form_top', $post ); ?> |
|
182 | -<?php wp_nonce_field( 'wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce' ); ;?> |
|
181 | +<?php do_action('wpinv_discount_form_top', $post); ?> |
|
182 | +<?php wp_nonce_field('wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce'); ;?> |
|
183 | 183 | <table class="form-table wpi-form-table"> |
184 | 184 | <tbody> |
185 | - <?php do_action( 'wpinv_discount_form_first', $post ); ?> |
|
186 | - <?php do_action( 'wpinv_discount_form_before_code', $post ); ?> |
|
185 | + <?php do_action('wpinv_discount_form_first', $post); ?> |
|
186 | + <?php do_action('wpinv_discount_form_before_code', $post); ?> |
|
187 | 187 | <tr> |
188 | 188 | <th valign="top" scope="row"> |
189 | - <label for="wpinv_discount_code"><?php _e( 'Discount Code', 'invoicing' ); ?></label> |
|
189 | + <label for="wpinv_discount_code"><?php _e('Discount Code', 'invoicing'); ?></label> |
|
190 | 190 | </th> |
191 | 191 | <td> |
192 | - <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr( wpinv_get_discount_code( $discount_id ) ); ?>" required> |
|
193 | - <p class="description"><?php _e( 'Enter a code for this discount, such as 10OFF', 'invoicing' ); ?></p> |
|
192 | + <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr(wpinv_get_discount_code($discount_id)); ?>" required> |
|
193 | + <p class="description"><?php _e('Enter a code for this discount, such as 10OFF', 'invoicing'); ?></p> |
|
194 | 194 | </td> |
195 | 195 | </tr> |
196 | - <?php do_action( 'wpinv_discount_form_before_type', $post ); ?> |
|
196 | + <?php do_action('wpinv_discount_form_before_type', $post); ?> |
|
197 | 197 | <tr> |
198 | 198 | <th valign="top" scope="row"> |
199 | - <label for="wpinv_discount_type"><?php _e( 'Discount Type', 'invoicing' ); ?></label> |
|
199 | + <label for="wpinv_discount_type"><?php _e('Discount Type', 'invoicing'); ?></label> |
|
200 | 200 | </th> |
201 | 201 | <td> |
202 | 202 | <select id="wpinv_discount_type" name="type" class="medium-text wpi_select2"> |
203 | - <?php foreach ( wpinv_get_discount_types() as $value => $label ) { ?> |
|
204 | - <option value="<?php echo $value ;?>" <?php selected( $type, $value ); ?>><?php echo $label; ?></option> |
|
203 | + <?php foreach (wpinv_get_discount_types() as $value => $label) { ?> |
|
204 | + <option value="<?php echo $value; ?>" <?php selected($type, $value); ?>><?php echo $label; ?></option> |
|
205 | 205 | <?php } ?> |
206 | 206 | </select> |
207 | - <p class="description"><?php _e( 'The kind of discount to apply for this discount.', 'invoicing' ); ?></p> |
|
207 | + <p class="description"><?php _e('The kind of discount to apply for this discount.', 'invoicing'); ?></p> |
|
208 | 208 | </td> |
209 | 209 | </tr> |
210 | - <?php do_action( 'wpinv_discount_form_before_amount', $post ); ?> |
|
210 | + <?php do_action('wpinv_discount_form_before_amount', $post); ?> |
|
211 | 211 | <tr> |
212 | 212 | <th valign="top" scope="row"> |
213 | - <label for="wpinv_discount_amount"><?php _e( 'Amount', 'invoicing' ); ?></label> |
|
213 | + <label for="wpinv_discount_amount"><?php _e('Amount', 'invoicing'); ?></label> |
|
214 | 214 | </th> |
215 | 215 | <td> |
216 | - <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr( wpinv_get_discount_amount( $discount_id ) ); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol() ;?></font> |
|
217 | - <p style="display:none;" class="description"><?php _e( 'Enter the discount amount in USD', 'invoicing' ); ?></p> |
|
218 | - <p class="description"><?php _e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?></p> |
|
216 | + <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr(wpinv_get_discount_amount($discount_id)); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol(); ?></font> |
|
217 | + <p style="display:none;" class="description"><?php _e('Enter the discount amount in USD', 'invoicing'); ?></p> |
|
218 | + <p class="description"><?php _e('Enter the discount value. Ex: 10', 'invoicing'); ?></p> |
|
219 | 219 | </td> |
220 | 220 | </tr> |
221 | - <?php do_action( 'wpinv_discount_form_before_items', $post ); ?> |
|
221 | + <?php do_action('wpinv_discount_form_before_items', $post); ?> |
|
222 | 222 | <tr> |
223 | 223 | <th valign="top" scope="row"> |
224 | - <label for="wpinv_discount_items"><?php _e( 'Items', 'invoicing' ); ?></label> |
|
224 | + <label for="wpinv_discount_items"><?php _e('Items', 'invoicing'); ?></label> |
|
225 | 225 | </th> |
226 | 226 | <td> |
227 | - <p><?php echo wpinv_item_dropdown( array( |
|
227 | + <p><?php echo wpinv_item_dropdown(array( |
|
228 | 228 | 'name' => 'items[]', |
229 | 229 | 'id' => 'items', |
230 | 230 | 'selected' => $item_reqs, |
231 | 231 | 'multiple' => true, |
232 | 232 | 'class' => 'medium-text wpi_select2', |
233 | - 'placeholder' => __( 'Select one or more Items', 'invoicing' ), |
|
233 | + 'placeholder' => __('Select one or more Items', 'invoicing'), |
|
234 | 234 | 'show_recurring' => true, |
235 | - ) ); ?> |
|
235 | + )); ?> |
|
236 | 236 | </p> |
237 | - <p class="description"><?php _e( 'Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing' ); ?></p> |
|
237 | + <p class="description"><?php _e('Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing'); ?></p> |
|
238 | 238 | </td> |
239 | 239 | </tr> |
240 | - <?php do_action( 'wpinv_discount_form_before_excluded_items', $post ); ?> |
|
240 | + <?php do_action('wpinv_discount_form_before_excluded_items', $post); ?> |
|
241 | 241 | <tr> |
242 | 242 | <th valign="top" scope="row"> |
243 | - <label for="wpinv_discount_excluded_items"><?php _e( 'Excluded Items', 'invoicing' ); ?></label> |
|
243 | + <label for="wpinv_discount_excluded_items"><?php _e('Excluded Items', 'invoicing'); ?></label> |
|
244 | 244 | </th> |
245 | 245 | <td> |
246 | - <p><?php echo wpinv_item_dropdown( array( |
|
246 | + <p><?php echo wpinv_item_dropdown(array( |
|
247 | 247 | 'name' => 'excluded_items[]', |
248 | 248 | 'id' => 'excluded_items', |
249 | 249 | 'selected' => $excluded_items, |
250 | 250 | 'multiple' => true, |
251 | 251 | 'class' => 'medium-text wpi_select2', |
252 | - 'placeholder' => __( 'Select one or more Items', 'invoicing' ), |
|
252 | + 'placeholder' => __('Select one or more Items', 'invoicing'), |
|
253 | 253 | 'show_recurring' => true, |
254 | - ) ); ?> |
|
254 | + )); ?> |
|
255 | 255 | </p> |
256 | - <p class="description"><?php _e( 'Items which are NOT allowed to use this discount.', 'invoicing' ); ?></p> |
|
256 | + <p class="description"><?php _e('Items which are NOT allowed to use this discount.', 'invoicing'); ?></p> |
|
257 | 257 | </td> |
258 | 258 | </tr> |
259 | - <?php do_action( 'wpinv_discount_form_before_start', $post ); ?> |
|
259 | + <?php do_action('wpinv_discount_form_before_start', $post); ?> |
|
260 | 260 | <tr> |
261 | 261 | <th valign="top" scope="row"> |
262 | - <label for="wpinv_discount_start"><?php _e( 'Start Date', 'invoicing' ); ?></label> |
|
262 | + <label for="wpinv_discount_start"><?php _e('Start Date', 'invoicing'); ?></label> |
|
263 | 263 | </th> |
264 | 264 | <td> |
265 | - <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr( $start_date ); ?>"> @ <select id="wpinv_discount_start_h" name="start_h"> |
|
266 | - <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
267 | - <option value="<?php echo $value;?>" <?php selected( $value, $start_h ); ?>><?php echo $value;?></option> |
|
265 | + <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr($start_date); ?>"> @ <select id="wpinv_discount_start_h" name="start_h"> |
|
266 | + <?php for ($i = 0; $i <= 23; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
267 | + <option value="<?php echo $value; ?>" <?php selected($value, $start_h); ?>><?php echo $value; ?></option> |
|
268 | 268 | <?php } ?> |
269 | 269 | </select> : <select id="wpinv_discount_start_m" name="start_m"> |
270 | - <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
271 | - <option value="<?php echo $value;?>" <?php selected( $value, $start_m ); ?>><?php echo $value;?></option> |
|
270 | + <?php for ($i = 0; $i <= 59; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
271 | + <option value="<?php echo $value; ?>" <?php selected($value, $start_m); ?>><?php echo $value; ?></option> |
|
272 | 272 | <?php } ?> |
273 | 273 | </select> |
274 | - <p class="description"><?php _e( 'Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing' ); ?></p> |
|
274 | + <p class="description"><?php _e('Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing'); ?></p> |
|
275 | 275 | </td> |
276 | 276 | </tr> |
277 | - <?php do_action( 'wpinv_discount_form_before_expiration', $post ); ?> |
|
277 | + <?php do_action('wpinv_discount_form_before_expiration', $post); ?> |
|
278 | 278 | <tr> |
279 | 279 | <th valign="top" scope="row"> |
280 | - <label for="wpinv_discount_expiration"><?php _e( 'Expiration Date', 'invoicing' ); ?></label> |
|
280 | + <label for="wpinv_discount_expiration"><?php _e('Expiration Date', 'invoicing'); ?></label> |
|
281 | 281 | </th> |
282 | 282 | <td> |
283 | - <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr( $expiration_date ); ?>"> @ <select id="wpinv_discount_expiration_h" name="expiration_h"> |
|
284 | - <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
285 | - <option value="<?php echo $value;?>" <?php selected( $value, $expiration_h ); ?>><?php echo $value;?></option> |
|
283 | + <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr($expiration_date); ?>"> @ <select id="wpinv_discount_expiration_h" name="expiration_h"> |
|
284 | + <?php for ($i = 0; $i <= 23; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
285 | + <option value="<?php echo $value; ?>" <?php selected($value, $expiration_h); ?>><?php echo $value; ?></option> |
|
286 | 286 | <?php } ?> |
287 | 287 | </select> : <select id="wpinv_discount_expiration_m" name="expiration_m"> |
288 | - <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
289 | - <option value="<?php echo $value;?>" <?php selected( $value, $expiration_m ); ?>><?php echo $value;?></option> |
|
288 | + <?php for ($i = 0; $i <= 59; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
289 | + <option value="<?php echo $value; ?>" <?php selected($value, $expiration_m); ?>><?php echo $value; ?></option> |
|
290 | 290 | <?php } ?> |
291 | 291 | </select> |
292 | - <p class="description"><?php _e( 'Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing' ); ?></p> |
|
292 | + <p class="description"><?php _e('Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing'); ?></p> |
|
293 | 293 | </td> |
294 | 294 | </tr> |
295 | - <?php do_action( 'wpinv_discount_form_before_min_total', $post ); ?> |
|
295 | + <?php do_action('wpinv_discount_form_before_min_total', $post); ?> |
|
296 | 296 | <tr> |
297 | 297 | <th valign="top" scope="row"> |
298 | - <label for="wpinv_discount_min_total"><?php _e( 'Minimum Amount', 'invoicing' ); ?></label> |
|
298 | + <label for="wpinv_discount_min_total"><?php _e('Minimum Amount', 'invoicing'); ?></label> |
|
299 | 299 | </th> |
300 | 300 | <td> |
301 | 301 | <input type="text" name="min_total" id="wpinv_discount_min_total" class="wpi-field-price wpi-price" value="<?php echo $min_total; ?>"> |
302 | - <p class="description"><?php _e( 'This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p> |
|
302 | + <p class="description"><?php _e('This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p> |
|
303 | 303 | </td> |
304 | 304 | </tr> |
305 | - <?php do_action( 'wpinv_discount_form_before_max_total', $post ); ?> |
|
305 | + <?php do_action('wpinv_discount_form_before_max_total', $post); ?> |
|
306 | 306 | <tr> |
307 | 307 | <th valign="top" scope="row"> |
308 | - <label for="wpinv_discount_max_total"><?php _e( 'Maximum Amount', 'invoicing' ); ?></label> |
|
308 | + <label for="wpinv_discount_max_total"><?php _e('Maximum Amount', 'invoicing'); ?></label> |
|
309 | 309 | </th> |
310 | 310 | <td> |
311 | 311 | <input type="text" name="max_total" id="wpinv_discount_max_total" class="wpi-field-price wpi-price" value="<?php echo $max_total; ?>"> |
312 | - <p class="description"><?php _e( 'This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p> |
|
312 | + <p class="description"><?php _e('This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p> |
|
313 | 313 | </td> |
314 | 314 | </tr> |
315 | - <?php do_action( 'wpinv_discount_form_before_recurring', $post ); ?> |
|
315 | + <?php do_action('wpinv_discount_form_before_recurring', $post); ?> |
|
316 | 316 | <tr> |
317 | 317 | <th valign="top" scope="row"> |
318 | - <label for="wpinv_discount_recurring"><?php _e( 'For recurring apply to', 'invoicing' ); ?></label> |
|
318 | + <label for="wpinv_discount_recurring"><?php _e('For recurring apply to', 'invoicing'); ?></label> |
|
319 | 319 | </th> |
320 | 320 | <td> |
321 | 321 | <select id="wpinv_discount_recurring" name="recurring" class="medium-text wpi_select2"> |
322 | - <option value="0" <?php selected( false, $recurring ); ?>><?php _e( 'First payment only', 'invoicing' ); ?></option> |
|
323 | - <option value="1" <?php selected( true, $recurring ); ?>><?php _e( 'All payments', 'invoicing' ); ?></option> |
|
322 | + <option value="0" <?php selected(false, $recurring); ?>><?php _e('First payment only', 'invoicing'); ?></option> |
|
323 | + <option value="1" <?php selected(true, $recurring); ?>><?php _e('All payments', 'invoicing'); ?></option> |
|
324 | 324 | </select> |
325 | - <p class="description"><?php _e( '<b>All payments:</b> Apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> Apply this discount to only first payment of the recurring invoice.', 'invoicing' ); ?></p> |
|
325 | + <p class="description"><?php _e('<b>All payments:</b> Apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> Apply this discount to only first payment of the recurring invoice.', 'invoicing'); ?></p> |
|
326 | 326 | </td> |
327 | 327 | </tr> |
328 | - <?php do_action( 'wpinv_discount_form_before_max_uses', $post ); ?> |
|
328 | + <?php do_action('wpinv_discount_form_before_max_uses', $post); ?> |
|
329 | 329 | <tr> |
330 | 330 | <th valign="top" scope="row"> |
331 | - <label for="wpinv_discount_max_uses"><?php _e( 'Max Uses', 'invoicing' ); ?></label> |
|
331 | + <label for="wpinv_discount_max_uses"><?php _e('Max Uses', 'invoicing'); ?></label> |
|
332 | 332 | </th> |
333 | 333 | <td> |
334 | 334 | <input type="number" min="0" step="1" id="wpinv_discount_max_uses" name="max_uses" class="medium-text" value="<?php echo $max_uses; ?>"> |
335 | - <p class="description"><?php _e( 'The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing' ); ?></p> |
|
335 | + <p class="description"><?php _e('The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing'); ?></p> |
|
336 | 336 | </td> |
337 | 337 | </tr> |
338 | - <?php do_action( 'wpinv_discount_form_before_single_use', $post ); ?> |
|
338 | + <?php do_action('wpinv_discount_form_before_single_use', $post); ?> |
|
339 | 339 | <tr> |
340 | 340 | <th valign="top" scope="row"> |
341 | - <label for="wpinv_discount_single_use"><?php _e( 'Use Once Per User', 'invoicing' ); ?></label> |
|
341 | + <label for="wpinv_discount_single_use"><?php _e('Use Once Per User', 'invoicing'); ?></label> |
|
342 | 342 | </th> |
343 | 343 | <td> |
344 | - <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked( true, $single_use ); ?>> |
|
345 | - <span class="description"><?php _e( 'Limit this discount to a single use per user?', 'invoicing' ); ?></span> |
|
344 | + <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked(true, $single_use); ?>> |
|
345 | + <span class="description"><?php _e('Limit this discount to a single use per user?', 'invoicing'); ?></span> |
|
346 | 346 | </td> |
347 | 347 | </tr> |
348 | - <?php do_action( 'wpinv_discount_form_last', $post ); ?> |
|
348 | + <?php do_action('wpinv_discount_form_last', $post); ?> |
|
349 | 349 | </tbody> |
350 | 350 | </table> |
351 | -<?php do_action( 'wpinv_discount_form_bottom', $post ); ?> |
|
351 | +<?php do_action('wpinv_discount_form_bottom', $post); ?> |
|
352 | 352 | <?php |
353 | 353 | } |
354 | 354 | |
355 | -function wpinv_discount_metabox_save( $post_id, $post, $update = false ) { |
|
356 | - $post_type = !empty( $post ) ? $post->post_type : ''; |
|
355 | +function wpinv_discount_metabox_save($post_id, $post, $update = false) { |
|
356 | + $post_type = !empty($post) ? $post->post_type : ''; |
|
357 | 357 | |
358 | - if ( $post_type != 'wpi_discount' ) { |
|
358 | + if ($post_type != 'wpi_discount') { |
|
359 | 359 | return; |
360 | 360 | } |
361 | 361 | |
362 | - if ( !isset( $_POST['wpinv_discount_metabox_nonce'] ) || ( isset( $_POST['wpinv_discount_metabox_nonce'] ) && !wp_verify_nonce( $_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce' ) ) ) { |
|
362 | + if (!isset($_POST['wpinv_discount_metabox_nonce']) || (isset($_POST['wpinv_discount_metabox_nonce']) && !wp_verify_nonce($_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce'))) { |
|
363 | 363 | return; |
364 | 364 | } |
365 | 365 | |
366 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
366 | + if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || (defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
367 | 367 | return; |
368 | 368 | } |
369 | 369 | |
370 | - if ( !current_user_can( wpinv_get_capability(), $post_id ) ) { |
|
370 | + if (!current_user_can(wpinv_get_capability(), $post_id)) { |
|
371 | 371 | return; |
372 | 372 | } |
373 | 373 | |
374 | - if ( !empty( $_POST['start'] ) && isset( $_POST['start_h'] ) && isset( $_POST['start_m'] ) && $_POST['start_h'] !== '' && $_POST['start_m'] !== '' ) { |
|
374 | + if (!empty($_POST['start']) && isset($_POST['start_h']) && isset($_POST['start_m']) && $_POST['start_h'] !== '' && $_POST['start_m'] !== '') { |
|
375 | 375 | $_POST['start'] = $_POST['start'] . ' ' . $_POST['start_h'] . ':' . $_POST['start_m']; |
376 | 376 | } |
377 | 377 | |
378 | - if ( !empty( $_POST['expiration'] ) && isset( $_POST['expiration_h'] ) && isset( $_POST['expiration_m'] ) ) { |
|
378 | + if (!empty($_POST['expiration']) && isset($_POST['expiration_h']) && isset($_POST['expiration_m'])) { |
|
379 | 379 | $_POST['expiration'] = $_POST['expiration'] . ' ' . $_POST['expiration_h'] . ':' . $_POST['expiration_m']; |
380 | 380 | } |
381 | 381 | |
382 | - return /** @scrutinizer ignore-call */ wpinv_store_discount( $post_id, $_POST, $post, $update ); |
|
382 | + return /** @scrutinizer ignore-call */ wpinv_store_discount($post_id, $_POST, $post, $update); |
|
383 | 383 | } |
384 | -add_action( 'save_post', 'wpinv_discount_metabox_save', 10, 3 ); |
|
385 | 384 | \ No newline at end of file |
385 | +add_action('save_post', 'wpinv_discount_metabox_save', 10, 3); |
|
386 | 386 | \ No newline at end of file |
@@ -1,66 +1,66 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | -add_filter( 'manage_wpi_payment_form_posts_columns', 'wpinv_payment_form_columns' ); |
|
8 | -function wpinv_payment_form_columns( $existing_columns ) { |
|
7 | +add_filter('manage_wpi_payment_form_posts_columns', 'wpinv_payment_form_columns'); |
|
8 | +function wpinv_payment_form_columns($existing_columns) { |
|
9 | 9 | $date = $existing_columns['date']; |
10 | - unset( $existing_columns['date'] ); |
|
11 | - $existing_columns['shortcode'] = __( 'Shortcode', 'invoicing' ); |
|
10 | + unset($existing_columns['date']); |
|
11 | + $existing_columns['shortcode'] = __('Shortcode', 'invoicing'); |
|
12 | 12 | $existing_columns['date'] = $date; |
13 | 13 | return $existing_columns; |
14 | 14 | } |
15 | 15 | |
16 | -add_action( 'manage_wpi_payment_form_posts_custom_column', 'wpinv_payment_form_custom_column' ); |
|
17 | -function wpinv_payment_form_custom_column( $column ) { |
|
16 | +add_action('manage_wpi_payment_form_posts_custom_column', 'wpinv_payment_form_custom_column'); |
|
17 | +function wpinv_payment_form_custom_column($column) { |
|
18 | 18 | global $post; |
19 | 19 | |
20 | - if( 'shortcode' == $column ) { |
|
21 | - WPInv_Meta_Box_Payment_Form::output_shortcode( $post ); |
|
20 | + if ('shortcode' == $column) { |
|
21 | + WPInv_Meta_Box_Payment_Form::output_shortcode($post); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | } |
25 | 25 | |
26 | -add_filter( 'manage_wpi_discount_posts_columns', 'wpinv_discount_columns' ); |
|
27 | -function wpinv_discount_columns( $existing_columns ) { |
|
26 | +add_filter('manage_wpi_discount_posts_columns', 'wpinv_discount_columns'); |
|
27 | +function wpinv_discount_columns($existing_columns) { |
|
28 | 28 | $columns = array(); |
29 | 29 | $columns['cb'] = $existing_columns['cb']; |
30 | - $columns['name'] = __( 'Name', 'invoicing' ); |
|
31 | - $columns['code'] = __( 'Code', 'invoicing' ); |
|
32 | - $columns['amount'] = __( 'Amount', 'invoicing' ); |
|
33 | - $columns['usage'] = __( 'Usage / Limit', 'invoicing' ); |
|
34 | - $columns['start_date'] = __( 'Start Date', 'invoicing' ); |
|
35 | - $columns['expiry_date'] = __( 'Expiry Date', 'invoicing' ); |
|
36 | - $columns['status'] = __( 'Status', 'invoicing' ); |
|
30 | + $columns['name'] = __('Name', 'invoicing'); |
|
31 | + $columns['code'] = __('Code', 'invoicing'); |
|
32 | + $columns['amount'] = __('Amount', 'invoicing'); |
|
33 | + $columns['usage'] = __('Usage / Limit', 'invoicing'); |
|
34 | + $columns['start_date'] = __('Start Date', 'invoicing'); |
|
35 | + $columns['expiry_date'] = __('Expiry Date', 'invoicing'); |
|
36 | + $columns['status'] = __('Status', 'invoicing'); |
|
37 | 37 | |
38 | 38 | return $columns; |
39 | 39 | } |
40 | 40 | |
41 | -add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' ); |
|
42 | -function wpinv_discount_custom_column( $column ) { |
|
41 | +add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column'); |
|
42 | +function wpinv_discount_custom_column($column) { |
|
43 | 43 | global $post; |
44 | 44 | |
45 | 45 | $discount = $post; |
46 | 46 | |
47 | - switch ( $column ) { |
|
47 | + switch ($column) { |
|
48 | 48 | case 'name' : |
49 | - echo get_the_title( $discount->ID ); |
|
49 | + echo get_the_title($discount->ID); |
|
50 | 50 | break; |
51 | 51 | case 'code' : |
52 | - echo wpinv_get_discount_code( $discount->ID ); |
|
52 | + echo wpinv_get_discount_code($discount->ID); |
|
53 | 53 | break; |
54 | 54 | case 'amount' : |
55 | - echo wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) ); |
|
55 | + echo wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID)); |
|
56 | 56 | break; |
57 | 57 | case 'usage_limit' : |
58 | - echo wpinv_get_discount_uses( $discount->ID ); |
|
58 | + echo wpinv_get_discount_uses($discount->ID); |
|
59 | 59 | break; |
60 | 60 | case 'usage' : |
61 | - $usage = wpinv_get_discount_uses( $discount->ID ) . ' / '; |
|
62 | - if ( wpinv_get_discount_max_uses( $discount->ID ) ) { |
|
63 | - $usage .= wpinv_get_discount_max_uses( $discount->ID ); |
|
61 | + $usage = wpinv_get_discount_uses($discount->ID) . ' / '; |
|
62 | + if (wpinv_get_discount_max_uses($discount->ID)) { |
|
63 | + $usage .= wpinv_get_discount_max_uses($discount->ID); |
|
64 | 64 | } else { |
65 | 65 | $usage .= ' ∞'; |
66 | 66 | } |
@@ -68,8 +68,8 @@ discard block |
||
68 | 68 | echo $usage; |
69 | 69 | break; |
70 | 70 | case 'start_date' : |
71 | - if ( $start_date = wpinv_get_discount_start_date( $discount->ID ) ) { |
|
72 | - $value = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), strtotime( $start_date ) ); |
|
71 | + if ($start_date = wpinv_get_discount_start_date($discount->ID)) { |
|
72 | + $value = date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), strtotime($start_date)); |
|
73 | 73 | } else { |
74 | 74 | $value = '-'; |
75 | 75 | } |
@@ -77,163 +77,163 @@ discard block |
||
77 | 77 | echo $value; |
78 | 78 | break; |
79 | 79 | case 'expiry_date' : |
80 | - if ( $expiration = wpinv_get_discount_expiration( $discount->ID ) ) { |
|
81 | - $value = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), strtotime( $expiration ) ); |
|
80 | + if ($expiration = wpinv_get_discount_expiration($discount->ID)) { |
|
81 | + $value = date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), strtotime($expiration)); |
|
82 | 82 | } else { |
83 | - $value = __( 'Never', 'invoicing' ); |
|
83 | + $value = __('Never', 'invoicing'); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | echo $value; |
87 | 87 | break; |
88 | 88 | break; |
89 | 89 | case 'description' : |
90 | - echo wp_kses_post( $post->post_excerpt ); |
|
90 | + echo wp_kses_post($post->post_excerpt); |
|
91 | 91 | break; |
92 | 92 | case 'status' : |
93 | - $status = wpinv_is_discount_expired( $discount->ID ) ? 'expired' : $discount->post_status; |
|
93 | + $status = wpinv_is_discount_expired($discount->ID) ? 'expired' : $discount->post_status; |
|
94 | 94 | |
95 | - echo wpinv_discount_status( $status ); |
|
95 | + echo wpinv_discount_status($status); |
|
96 | 96 | break; |
97 | 97 | } |
98 | 98 | } |
99 | 99 | |
100 | -add_filter( 'post_row_actions', 'wpinv_post_row_actions', 9999, 2 ); |
|
101 | -function wpinv_post_row_actions( $actions, $post ) { |
|
102 | - $post_type = !empty( $post->post_type ) ? $post->post_type : ''; |
|
100 | +add_filter('post_row_actions', 'wpinv_post_row_actions', 9999, 2); |
|
101 | +function wpinv_post_row_actions($actions, $post) { |
|
102 | + $post_type = !empty($post->post_type) ? $post->post_type : ''; |
|
103 | 103 | |
104 | - if ( $post_type == 'wpi_invoice' ) { |
|
104 | + if ($post_type == 'wpi_invoice') { |
|
105 | 105 | $actions = array(); |
106 | 106 | } |
107 | 107 | |
108 | - if ( $post_type == 'wpi_discount' ) { |
|
109 | - $actions = wpinv_discount_row_actions( $post, $actions ); |
|
108 | + if ($post_type == 'wpi_discount') { |
|
109 | + $actions = wpinv_discount_row_actions($post, $actions); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | return $actions; |
113 | 113 | } |
114 | 114 | |
115 | -function wpinv_discount_row_actions( $discount, $row_actions ) { |
|
116 | - $row_actions = array(); |
|
117 | - $edit_link = get_edit_post_link( $discount->ID ); |
|
118 | - $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>'; |
|
115 | +function wpinv_discount_row_actions($discount, $row_actions) { |
|
116 | + $row_actions = array(); |
|
117 | + $edit_link = get_edit_post_link($discount->ID); |
|
118 | + $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>'; |
|
119 | 119 | |
120 | - if( in_array( strtolower( $discount->post_status ), array( 'publish' ) ) ) { |
|
121 | - $row_actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'deactivate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Deactivate', 'invoicing' ) . '</a>'; |
|
122 | - } elseif( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) { |
|
123 | - $row_actions['activate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'activate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Activate', 'invoicing' ) . '</a>'; |
|
120 | + if (in_array(strtolower($discount->post_status), array('publish'))) { |
|
121 | + $row_actions['deactivate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'deactivate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Deactivate', 'invoicing') . '</a>'; |
|
122 | + } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) { |
|
123 | + $row_actions['activate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'activate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Activate', 'invoicing') . '</a>'; |
|
124 | 124 | } |
125 | 125 | |
126 | - if ( wpinv_get_discount_uses( $discount->ID ) > 0 ) { |
|
127 | - if ( isset( $row_actions['delete'] ) ) { |
|
128 | - unset( $row_actions['delete'] ); // Don't delete used discounts. |
|
126 | + if (wpinv_get_discount_uses($discount->ID) > 0) { |
|
127 | + if (isset($row_actions['delete'])) { |
|
128 | + unset($row_actions['delete']); // Don't delete used discounts. |
|
129 | 129 | } |
130 | 130 | } else { |
131 | - $row_actions['delete'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'delete_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Delete', 'invoicing' ) . '</a>'; |
|
131 | + $row_actions['delete'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'delete_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Delete', 'invoicing') . '</a>'; |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | |
135 | - $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount ); |
|
135 | + $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount); |
|
136 | 136 | |
137 | 137 | return $row_actions; |
138 | 138 | } |
139 | 139 | |
140 | -add_filter( 'list_table_primary_column', 'wpinv_table_primary_column', 10, 2 ); |
|
141 | -function wpinv_table_primary_column( $default, $screen_id ) { |
|
142 | - if ( 'edit-wpi_invoice' === $screen_id ) { |
|
140 | +add_filter('list_table_primary_column', 'wpinv_table_primary_column', 10, 2); |
|
141 | +function wpinv_table_primary_column($default, $screen_id) { |
|
142 | + if ('edit-wpi_invoice' === $screen_id) { |
|
143 | 143 | return 'name'; |
144 | 144 | } |
145 | 145 | |
146 | 146 | return $default; |
147 | 147 | } |
148 | 148 | |
149 | -function wpinv_discount_bulk_actions( $actions, $display = false ) { |
|
150 | - if ( !$display ) { |
|
149 | +function wpinv_discount_bulk_actions($actions, $display = false) { |
|
150 | + if (!$display) { |
|
151 | 151 | return array(); |
152 | 152 | } |
153 | 153 | |
154 | 154 | $actions = array( |
155 | - 'activate' => __( 'Activate', 'invoicing' ), |
|
156 | - 'deactivate' => __( 'Deactivate', 'invoicing' ), |
|
157 | - 'delete' => __( 'Delete', 'invoicing' ), |
|
155 | + 'activate' => __('Activate', 'invoicing'), |
|
156 | + 'deactivate' => __('Deactivate', 'invoicing'), |
|
157 | + 'delete' => __('Delete', 'invoicing'), |
|
158 | 158 | ); |
159 | 159 | $two = ''; |
160 | 160 | $which = 'top'; |
161 | 161 | echo '</div><div class="alignleft actions bulkactions">'; |
162 | - echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>'; |
|
163 | - echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">"; |
|
164 | - echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>"; |
|
162 | + echo '<label for="bulk-action-selector-' . esc_attr($which) . '" class="screen-reader-text">' . __('Select bulk action') . '</label>'; |
|
163 | + echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr($which) . "\">"; |
|
164 | + echo '<option value="-1">' . __('Bulk Actions') . "</option>"; |
|
165 | 165 | |
166 | - foreach ( $actions as $name => $title ) { |
|
166 | + foreach ($actions as $name => $title) { |
|
167 | 167 | $class = 'edit' === $name ? ' class="hide-if-no-js"' : ''; |
168 | 168 | |
169 | 169 | echo "" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>"; |
170 | 170 | } |
171 | 171 | echo "</select>"; |
172 | 172 | |
173 | - submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) ); |
|
173 | + submit_button(__('Apply'), 'action', '', false, array('id' => "doaction$two")); |
|
174 | 174 | |
175 | 175 | echo '</div><div class="alignleft actions">'; |
176 | 176 | } |
177 | -add_filter( 'bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10 ); |
|
177 | +add_filter('bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10); |
|
178 | 178 | |
179 | -function wpinv_disable_months_dropdown( $disable, $post_type ) { |
|
180 | - if ( $post_type == 'wpi_discount' ) { |
|
179 | +function wpinv_disable_months_dropdown($disable, $post_type) { |
|
180 | + if ($post_type == 'wpi_discount') { |
|
181 | 181 | $disable = true; |
182 | 182 | } |
183 | 183 | |
184 | 184 | return $disable; |
185 | 185 | } |
186 | -add_filter( 'disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2 ); |
|
186 | +add_filter('disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2); |
|
187 | 187 | |
188 | 188 | function wpinv_restrict_manage_posts() { |
189 | 189 | global $typenow; |
190 | 190 | |
191 | - if( 'wpi_discount' == $typenow ) { |
|
191 | + if ('wpi_discount' == $typenow) { |
|
192 | 192 | wpinv_discount_filters(); |
193 | 193 | } |
194 | 194 | } |
195 | -add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 ); |
|
195 | +add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10); |
|
196 | 196 | |
197 | 197 | function wpinv_discount_filters() { |
198 | - echo wpinv_discount_bulk_actions( array(), true ); |
|
198 | + echo wpinv_discount_bulk_actions(array(), true); |
|
199 | 199 | |
200 | 200 | ?> |
201 | 201 | <select name="discount_type" id="dropdown_wpinv_discount_type"> |
202 | - <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option> |
|
202 | + <option value=""><?php _e('Show all types', 'invoicing'); ?></option> |
|
203 | 203 | <?php |
204 | 204 | $types = wpinv_get_discount_types(); |
205 | 205 | |
206 | - foreach ( $types as $name => $type ) { |
|
207 | - echo '<option value="' . esc_attr( $name ) . '"'; |
|
206 | + foreach ($types as $name => $type) { |
|
207 | + echo '<option value="' . esc_attr($name) . '"'; |
|
208 | 208 | |
209 | - if ( isset( $_GET['discount_type'] ) ) |
|
210 | - selected( $name, $_GET['discount_type'] ); |
|
209 | + if (isset($_GET['discount_type'])) |
|
210 | + selected($name, $_GET['discount_type']); |
|
211 | 211 | |
212 | - echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
212 | + echo '>' . esc_html__($type, 'invoicing') . '</option>'; |
|
213 | 213 | } |
214 | 214 | ?> |
215 | 215 | </select> |
216 | 216 | <?php |
217 | 217 | } |
218 | 218 | |
219 | -function wpinv_request( $vars ) { |
|
219 | +function wpinv_request($vars) { |
|
220 | 220 | global $typenow, $wp_query, $wp_post_statuses; |
221 | 221 | |
222 | - if ( 'wpi_invoice' === $typenow ) { |
|
223 | - if ( !isset( $vars['post_status'] ) ) { |
|
222 | + if ('wpi_invoice' === $typenow) { |
|
223 | + if (!isset($vars['post_status'])) { |
|
224 | 224 | $post_statuses = wpinv_get_invoice_statuses(); |
225 | 225 | |
226 | - foreach ( $post_statuses as $status => $value ) { |
|
227 | - if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) { |
|
228 | - unset( $post_statuses[ $status ] ); |
|
226 | + foreach ($post_statuses as $status => $value) { |
|
227 | + if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) { |
|
228 | + unset($post_statuses[$status]); |
|
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
232 | - $vars['post_status'] = array_keys( $post_statuses ); |
|
232 | + $vars['post_status'] = array_keys($post_statuses); |
|
233 | 233 | } |
234 | 234 | |
235 | - if ( isset( $vars['orderby'] ) ) { |
|
236 | - if ( 'amount' == $vars['orderby'] ) { |
|
235 | + if (isset($vars['orderby'])) { |
|
236 | + if ('amount' == $vars['orderby']) { |
|
237 | 237 | $vars = array_merge( |
238 | 238 | $vars, |
239 | 239 | array( |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | 'orderby' => 'meta_value_num' |
242 | 242 | ) |
243 | 243 | ); |
244 | - } else if ( 'customer' == $vars['orderby'] ) { |
|
244 | + } else if ('customer' == $vars['orderby']) { |
|
245 | 245 | $vars = array_merge( |
246 | 246 | $vars, |
247 | 247 | array( |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | 'orderby' => 'meta_value' |
250 | 250 | ) |
251 | 251 | ); |
252 | - } else if ( 'number' == $vars['orderby'] ) { |
|
252 | + } else if ('number' == $vars['orderby']) { |
|
253 | 253 | $vars = array_merge( |
254 | 254 | $vars, |
255 | 255 | array( |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | 'orderby' => 'meta_value' |
258 | 258 | ) |
259 | 259 | ); |
260 | - } else if ( 'payment_date' == $vars['orderby'] ) { |
|
260 | + } else if ('payment_date' == $vars['orderby']) { |
|
261 | 261 | $vars = array_merge( |
262 | 262 | $vars, |
263 | 263 | array( |
@@ -267,9 +267,9 @@ discard block |
||
267 | 267 | ); |
268 | 268 | } |
269 | 269 | } |
270 | - } else if ( 'wpi_item' == $typenow ) { |
|
270 | + } else if ('wpi_item' == $typenow) { |
|
271 | 271 | // Check if 'orderby' is set to "price" |
272 | - if ( isset( $vars['orderby'] ) && 'price' == $vars['orderby'] ) { |
|
272 | + if (isset($vars['orderby']) && 'price' == $vars['orderby']) { |
|
273 | 273 | $vars = array_merge( |
274 | 274 | $vars, |
275 | 275 | array( |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | } |
281 | 281 | |
282 | 282 | // Check if "orderby" is set to "vat_rule" |
283 | - if ( isset( $vars['orderby'] ) && 'vat_rule' == $vars['orderby'] ) { |
|
283 | + if (isset($vars['orderby']) && 'vat_rule' == $vars['orderby']) { |
|
284 | 284 | $vars = array_merge( |
285 | 285 | $vars, |
286 | 286 | array( |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | } |
292 | 292 | |
293 | 293 | // Check if "orderby" is set to "vat_class" |
294 | - if ( isset( $vars['orderby'] ) && 'vat_class' == $vars['orderby'] ) { |
|
294 | + if (isset($vars['orderby']) && 'vat_class' == $vars['orderby']) { |
|
295 | 295 | $vars = array_merge( |
296 | 296 | $vars, |
297 | 297 | array( |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | } |
303 | 303 | |
304 | 304 | // Check if "orderby" is set to "type" |
305 | - if ( isset( $vars['orderby'] ) && 'type' == $vars['orderby'] ) { |
|
305 | + if (isset($vars['orderby']) && 'type' == $vars['orderby']) { |
|
306 | 306 | $vars = array_merge( |
307 | 307 | $vars, |
308 | 308 | array( |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | } |
314 | 314 | |
315 | 315 | // Check if "orderby" is set to "recurring" |
316 | - if ( isset( $vars['orderby'] ) && 'recurring' == $vars['orderby'] ) { |
|
316 | + if (isset($vars['orderby']) && 'recurring' == $vars['orderby']) { |
|
317 | 317 | $vars = array_merge( |
318 | 318 | $vars, |
319 | 319 | array( |
@@ -323,104 +323,104 @@ discard block |
||
323 | 323 | ); |
324 | 324 | } |
325 | 325 | |
326 | - $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array(); |
|
326 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array(); |
|
327 | 327 | // Filter vat rule type |
328 | - if ( isset( $_GET['vat_rule'] ) && $_GET['vat_rule'] !== '' ) { |
|
328 | + if (isset($_GET['vat_rule']) && $_GET['vat_rule'] !== '') { |
|
329 | 329 | $meta_query[] = array( |
330 | 330 | 'key' => '_wpinv_vat_rule', |
331 | - 'value' => sanitize_text_field( $_GET['vat_rule'] ), |
|
331 | + 'value' => sanitize_text_field($_GET['vat_rule']), |
|
332 | 332 | 'compare' => '=' |
333 | 333 | ); |
334 | 334 | } |
335 | 335 | |
336 | 336 | // Filter vat class |
337 | - if ( isset( $_GET['vat_class'] ) && $_GET['vat_class'] !== '' ) { |
|
337 | + if (isset($_GET['vat_class']) && $_GET['vat_class'] !== '') { |
|
338 | 338 | $meta_query[] = array( |
339 | 339 | 'key' => '_wpinv_vat_class', |
340 | - 'value' => sanitize_text_field( $_GET['vat_class'] ), |
|
340 | + 'value' => sanitize_text_field($_GET['vat_class']), |
|
341 | 341 | 'compare' => '=' |
342 | 342 | ); |
343 | 343 | } |
344 | 344 | |
345 | 345 | // Filter item type |
346 | - if ( isset( $_GET['type'] ) && $_GET['type'] !== '' ) { |
|
346 | + if (isset($_GET['type']) && $_GET['type'] !== '') { |
|
347 | 347 | $meta_query[] = array( |
348 | 348 | 'key' => '_wpinv_type', |
349 | - 'value' => sanitize_text_field( $_GET['type'] ), |
|
349 | + 'value' => sanitize_text_field($_GET['type']), |
|
350 | 350 | 'compare' => '=' |
351 | 351 | ); |
352 | 352 | } |
353 | 353 | |
354 | - if ( !empty( $meta_query ) ) { |
|
354 | + if (!empty($meta_query)) { |
|
355 | 355 | $vars['meta_query'] = $meta_query; |
356 | 356 | } |
357 | - } else if ( 'wpi_discount' == $typenow ) { |
|
358 | - $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array(); |
|
357 | + } else if ('wpi_discount' == $typenow) { |
|
358 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array(); |
|
359 | 359 | // Filter vat rule type |
360 | - if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) { |
|
360 | + if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') { |
|
361 | 361 | $meta_query[] = array( |
362 | 362 | 'key' => '_wpi_discount_type', |
363 | - 'value' => sanitize_text_field( $_GET['discount_type'] ), |
|
363 | + 'value' => sanitize_text_field($_GET['discount_type']), |
|
364 | 364 | 'compare' => '=' |
365 | 365 | ); |
366 | 366 | } |
367 | 367 | |
368 | - if ( !empty( $meta_query ) ) { |
|
368 | + if (!empty($meta_query)) { |
|
369 | 369 | $vars['meta_query'] = $meta_query; |
370 | 370 | } |
371 | 371 | } |
372 | 372 | |
373 | 373 | return $vars; |
374 | 374 | } |
375 | -add_filter( 'request', 'wpinv_request' ); |
|
375 | +add_filter('request', 'wpinv_request'); |
|
376 | 376 | |
377 | -function wpinv_item_type_class( $classes, $class, $post_id ) { |
|
377 | +function wpinv_item_type_class($classes, $class, $post_id) { |
|
378 | 378 | global $pagenow, $typenow; |
379 | 379 | |
380 | - if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow ) { |
|
381 | - if ( $type = get_post_meta( $post_id, '_wpinv_type', true ) ) { |
|
382 | - $classes[] = 'wpi-type-' . sanitize_html_class( $type ); |
|
380 | + if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow) { |
|
381 | + if ($type = get_post_meta($post_id, '_wpinv_type', true)) { |
|
382 | + $classes[] = 'wpi-type-' . sanitize_html_class($type); |
|
383 | 383 | } |
384 | 384 | |
385 | - if ( !wpinv_item_is_editable( $post_id ) ) { |
|
385 | + if (!wpinv_item_is_editable($post_id)) { |
|
386 | 386 | $classes[] = 'wpi-editable-n'; |
387 | 387 | } |
388 | 388 | } |
389 | 389 | return $classes; |
390 | 390 | } |
391 | -add_filter( 'post_class', 'wpinv_item_type_class', 10, 3 ); |
|
391 | +add_filter('post_class', 'wpinv_item_type_class', 10, 3); |
|
392 | 392 | |
393 | 393 | function wpinv_check_quick_edit() { |
394 | 394 | global $pagenow, $current_screen, $wpinv_item_screen; |
395 | 395 | |
396 | - if ( $pagenow == 'edit.php' && !empty( $current_screen->post_type ) ) { |
|
397 | - if ( empty( $wpinv_item_screen ) ) { |
|
398 | - if ( $current_screen->post_type == 'wpi_item' ) { |
|
396 | + if ($pagenow == 'edit.php' && !empty($current_screen->post_type)) { |
|
397 | + if (empty($wpinv_item_screen)) { |
|
398 | + if ($current_screen->post_type == 'wpi_item') { |
|
399 | 399 | $wpinv_item_screen = 'y'; |
400 | 400 | } else { |
401 | 401 | $wpinv_item_screen = 'n'; |
402 | 402 | } |
403 | 403 | } |
404 | 404 | |
405 | - if ( $wpinv_item_screen == 'y' && $pagenow == 'edit.php' ) { |
|
406 | - add_filter( 'post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 ); |
|
407 | - add_filter( 'page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 ); |
|
405 | + if ($wpinv_item_screen == 'y' && $pagenow == 'edit.php') { |
|
406 | + add_filter('post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2); |
|
407 | + add_filter('page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2); |
|
408 | 408 | } |
409 | 409 | } |
410 | 410 | } |
411 | -add_action( 'admin_head', 'wpinv_check_quick_edit', 10 ); |
|
411 | +add_action('admin_head', 'wpinv_check_quick_edit', 10); |
|
412 | 412 | |
413 | -function wpinv_item_disable_quick_edit( $actions = array(), $row = null ) { |
|
414 | - if ( isset( $actions['inline hide-if-no-js'] ) ) { |
|
415 | - unset( $actions['inline hide-if-no-js'] ); |
|
413 | +function wpinv_item_disable_quick_edit($actions = array(), $row = null) { |
|
414 | + if (isset($actions['inline hide-if-no-js'])) { |
|
415 | + unset($actions['inline hide-if-no-js']); |
|
416 | 416 | } |
417 | 417 | |
418 | - if ( !empty( $row->post_type ) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable( $row ) ) { |
|
419 | - if ( isset( $actions['trash'] ) ) { |
|
420 | - unset( $actions['trash'] ); |
|
418 | + if (!empty($row->post_type) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable($row)) { |
|
419 | + if (isset($actions['trash'])) { |
|
420 | + unset($actions['trash']); |
|
421 | 421 | } |
422 | - if ( isset( $actions['delete'] ) ) { |
|
423 | - unset( $actions['delete'] ); |
|
422 | + if (isset($actions['delete'])) { |
|
423 | + unset($actions['delete']); |
|
424 | 424 | } |
425 | 425 | } |
426 | 426 | |
@@ -437,19 +437,19 @@ discard block |
||
437 | 437 | * @param int $post_parent (default: 0) Parent for the new page |
438 | 438 | * @return int page ID |
439 | 439 | */ |
440 | -function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) { |
|
440 | +function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) { |
|
441 | 441 | global $wpdb; |
442 | 442 | |
443 | - $option_value = wpinv_get_option( $option ); |
|
443 | + $option_value = wpinv_get_option($option); |
|
444 | 444 | |
445 | - if ( $option_value > 0 && ( $page_object = get_post( $option_value ) ) ) { |
|
446 | - if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) { |
|
445 | + if ($option_value > 0 && ($page_object = get_post($option_value))) { |
|
446 | + if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) { |
|
447 | 447 | // Valid page is already in place |
448 | 448 | return $page_object->ID; |
449 | 449 | } |
450 | 450 | } |
451 | 451 | |
452 | - if(!empty($post_parent)){ |
|
452 | + if (!empty($post_parent)) { |
|
453 | 453 | $page = get_page_by_path($post_parent); |
454 | 454 | if ($page) { |
455 | 455 | $post_parent = $page->ID; |
@@ -458,40 +458,40 @@ discard block |
||
458 | 458 | } |
459 | 459 | } |
460 | 460 | |
461 | - if ( strlen( $page_content ) > 0 ) { |
|
461 | + if (strlen($page_content) > 0) { |
|
462 | 462 | // Search for an existing page with the specified page content (typically a shortcode) |
463 | - $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); |
|
463 | + $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
|
464 | 464 | } else { |
465 | 465 | // Search for an existing page with the specified page slug |
466 | - $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug ) ); |
|
466 | + $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug)); |
|
467 | 467 | } |
468 | 468 | |
469 | - $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content ); |
|
469 | + $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content); |
|
470 | 470 | |
471 | - if ( $valid_page_found ) { |
|
472 | - if ( $option ) { |
|
473 | - wpinv_update_option( $option, $valid_page_found ); |
|
471 | + if ($valid_page_found) { |
|
472 | + if ($option) { |
|
473 | + wpinv_update_option($option, $valid_page_found); |
|
474 | 474 | } |
475 | 475 | return $valid_page_found; |
476 | 476 | } |
477 | 477 | |
478 | 478 | // Search for a matching valid trashed page |
479 | - if ( strlen( $page_content ) > 0 ) { |
|
479 | + if (strlen($page_content) > 0) { |
|
480 | 480 | // Search for an existing page with the specified page content (typically a shortcode) |
481 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); |
|
481 | + $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
|
482 | 482 | } else { |
483 | 483 | // Search for an existing page with the specified page slug |
484 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) ); |
|
484 | + $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug)); |
|
485 | 485 | } |
486 | 486 | |
487 | - if ( $trashed_page_found ) { |
|
487 | + if ($trashed_page_found) { |
|
488 | 488 | $page_id = $trashed_page_found; |
489 | 489 | $page_data = array( |
490 | 490 | 'ID' => $page_id, |
491 | 491 | 'post_status' => 'publish', |
492 | 492 | 'post_parent' => $post_parent, |
493 | 493 | ); |
494 | - wp_update_post( $page_data ); |
|
494 | + wp_update_post($page_data); |
|
495 | 495 | } else { |
496 | 496 | $page_data = array( |
497 | 497 | 'post_status' => 'publish', |
@@ -503,11 +503,11 @@ discard block |
||
503 | 503 | 'post_parent' => $post_parent, |
504 | 504 | 'comment_status' => 'closed', |
505 | 505 | ); |
506 | - $page_id = wp_insert_post( $page_data ); |
|
506 | + $page_id = wp_insert_post($page_data); |
|
507 | 507 | } |
508 | 508 | |
509 | - if ( $option ) { |
|
510 | - wpinv_update_option( $option, (int)$page_id ); |
|
509 | + if ($option) { |
|
510 | + wpinv_update_option($option, (int) $page_id); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | return $page_id; |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | class WPInv_Meta_Box_Payment_Form { |
@@ -11,9 +11,9 @@ discard block |
||
11 | 11 | * |
12 | 12 | * @param WP_Post $post |
13 | 13 | */ |
14 | - public static function output_shortcode( $post ) { |
|
14 | + public static function output_shortcode($post) { |
|
15 | 15 | |
16 | - if ( ! is_numeric( $post ) ) { |
|
16 | + if (!is_numeric($post)) { |
|
17 | 17 | $post = $post->ID; |
18 | 18 | } |
19 | 19 | |
@@ -25,9 +25,9 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @param WP_Post $post |
27 | 27 | */ |
28 | - public static function output ( $post ) { |
|
29 | - $success_page = get_post_meta( $post->ID, 'wpinv_success_page', true ); |
|
30 | - $success_page = empty( $success_page ) ? wpinv_get_success_page_uri() : $success_page |
|
28 | + public static function output($post) { |
|
29 | + $success_page = get_post_meta($post->ID, 'wpinv_success_page', true); |
|
30 | + $success_page = empty($success_page) ? wpinv_get_success_page_uri() : $success_page |
|
31 | 31 | ?> |
32 | 32 | |
33 | 33 | <div id="wpinv-form-builder" style="display: flex; flex-flow: wrap;"> |
@@ -35,20 +35,20 @@ discard block |
||
35 | 35 | <div class="wpinv-form-builder-left bsui" style="flex: 0 0 320px;"> |
36 | 36 | <ul class="wpinv-form-builder-tabs nav nav-tabs"> |
37 | 37 | <li class='nav-item' v-if="active_tab!='new_item'"> |
38 | - <a @click.prevent="active_tab='new_item'" class="nav-link p-3" :class="{ 'active': active_tab=='new_item' }" href="#"><?php _e( 'Add new element', 'invoicing' ); ?></a> |
|
38 | + <a @click.prevent="active_tab='new_item'" class="nav-link p-3" :class="{ 'active': active_tab=='new_item' }" href="#"><?php _e('Add new element', 'invoicing'); ?></a> |
|
39 | 39 | </li> |
40 | 40 | <li class='nav-item' v-if='false'> |
41 | - <a @click.prevent="active_tab='edit_item'" class="nav-link p-3" :class="{ 'active': active_tab=='edit_item' }" href="#"><?php _e( 'Edit element', 'invoicing' ); ?></a> |
|
41 | + <a @click.prevent="active_tab='edit_item'" class="nav-link p-3" :class="{ 'active': active_tab=='edit_item' }" href="#"><?php _e('Edit element', 'invoicing'); ?></a> |
|
42 | 42 | </li> |
43 | 43 | <li class='nav-item' v-if='false'> |
44 | - <a @click.prevent="active_tab='settings'" class="nav-link p-3" :class="{ 'active': active_tab=='settings' }" href="#"><?php _e( 'Settings', 'invoicing' ); ?></a> |
|
44 | + <a @click.prevent="active_tab='settings'" class="nav-link p-3" :class="{ 'active': active_tab=='settings' }" href="#"><?php _e('Settings', 'invoicing'); ?></a> |
|
45 | 45 | </li> |
46 | 46 | </ul> |
47 | 47 | |
48 | 48 | <div class="wpinv-form-builder-tab-content bsui" style="margin-top: 16px;"> |
49 | 49 | <div class="wpinv-form-builder-tab-pane" v-if="active_tab=='new_item'"> |
50 | 50 | <div class="wpinv-form-builder-add-field-types"> |
51 | - <small class='form-text text-muted'><?php _e( 'Add an element by dragging it to the payment form.', 'invoicing' ); ?></small> |
|
51 | + <small class='form-text text-muted'><?php _e('Add an element by dragging it to the payment form.', 'invoicing'); ?></small> |
|
52 | 52 | <draggable class="section mt-2" style="display: flex; flex-flow: wrap; justify-content: space-between;" v-model="elements" :group="{ name: 'fields', pull: 'clone', put: false }" :sort="false" :clone="addDraggedField" tag="ul" filter=".wpinv-undraggable"> |
53 | 53 | <li v-for="element in elements" style="width: 49%; background-color: #fafafa; margin-bottom: 9px; cursor: move; border: 1px solid #eeeeee;" @click.prevent="addField(element)" :class="{ 'd-none': element.defaults.premade }"> |
54 | 54 | <button class="button btn" style="width: 100%; cursor: move;"> |
@@ -63,9 +63,9 @@ discard block |
||
63 | 63 | |
64 | 64 | <div class="wpinv-form-builder-tab-pane bsui" v-if="active_tab=='edit_item'" style="font-size: 16px;"> |
65 | 65 | <div class="wpinv-form-builder-edit-field-wrapper"> |
66 | - <?php do_action( 'wpinv_payment_form_edit_element_template', 'active_form_element', $post ); ?> |
|
66 | + <?php do_action('wpinv_payment_form_edit_element_template', 'active_form_element', $post); ?> |
|
67 | 67 | <div> |
68 | - <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e( 'Delete Field', 'invoicing' ); ?></button> |
|
68 | + <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e('Delete Field', 'invoicing'); ?></button> |
|
69 | 69 | </div> |
70 | 70 | </div> |
71 | 71 | </div> |
@@ -74,9 +74,9 @@ discard block |
||
74 | 74 | <div class="wpinv-form-builder-settings-wrapper"> |
75 | 75 | |
76 | 76 | <div class='form-group'> |
77 | - <label for="wpi-success-page"><?php _e( 'Success Page', 'invoicing' ); ?></label> |
|
78 | - <input placeholder="https://" id='wpi-success-page' value="<?php echo esc_url( $success_page ); ?>" class='form-control' type='text'> |
|
79 | - <small class='form-text text-muted'><?php _e( 'Where should we redirect users after successfuly completing their payment?', 'invoicing' ); ?></small> |
|
77 | + <label for="wpi-success-page"><?php _e('Success Page', 'invoicing'); ?></label> |
|
78 | + <input placeholder="https://" id='wpi-success-page' value="<?php echo esc_url($success_page); ?>" class='form-control' type='text'> |
|
79 | + <small class='form-text text-muted'><?php _e('Where should we redirect users after successfuly completing their payment?', 'invoicing'); ?></small> |
|
80 | 80 | </div> |
81 | 81 | |
82 | 82 | </div> |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | |
88 | 88 | <div class="wpinv-form-builder-right" style="flex: 1; padding-top: 40px;border-left: 1px solid #ddd;padding-left: 20px;min-height: 520px;margin-left: 10px;"> |
89 | 89 | |
90 | - <small class='form-text text-muted' v-if='form_elements.length'><?php _e( 'Click on any element to edit or delete it.', 'invoicing' ); ?></small> |
|
91 | - <p class='form-text text-muted' v-if='! form_elements.length'><?php _e( 'This form is empty. Add new elements by dragging them from the right.', 'invoicing' ); ?></p> |
|
90 | + <small class='form-text text-muted' v-if='form_elements.length'><?php _e('Click on any element to edit or delete it.', 'invoicing'); ?></small> |
|
91 | + <p class='form-text text-muted' v-if='! form_elements.length'><?php _e('This form is empty. Add new elements by dragging them from the right.', 'invoicing'); ?></p> |
|
92 | 92 | |
93 | 93 | <draggable class="section bsui" v-model="form_elements" @add="highlightLastDroppedField" group="fields" tag="div" style="min-height: 100%; font-size: 16px;"> |
94 | 94 | <div v-for="form_element in form_elements" class="wpinv-form-builder-element-preview" :class="{ active: active_form_element==form_element && active_tab=='edit_item' }" @click="active_tab = 'edit_item'; active_form_element = form_element"> |
95 | - <?php do_action( 'wpinv_payment_form_render_element_template', 'form_element', $post ); ?> |
|
95 | + <?php do_action('wpinv_payment_form_render_element_template', 'form_element', $post); ?> |
|
96 | 96 | </div> |
97 | 97 | </draggable> |
98 | 98 | </div> |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | <textarea style="display:none;" name="wpinv_form_items" v-model="itemString"></textarea> |
102 | 102 | </div> |
103 | 103 | |
104 | - <?php wp_nonce_field( 'wpinv_save_payment_form', 'wpinv_save_payment_form' ) ;?> |
|
104 | + <?php wp_nonce_field('wpinv_save_payment_form', 'wpinv_save_payment_form'); ?> |
|
105 | 105 | |
106 | 106 | <?php |
107 | 107 | } |
@@ -109,83 +109,83 @@ discard block |
||
109 | 109 | /** |
110 | 110 | * Saves our payment forms. |
111 | 111 | */ |
112 | - public static function save( $post_id, $post ) { |
|
112 | + public static function save($post_id, $post) { |
|
113 | 113 | |
114 | - remove_action( 'save_post', 'WPInv_Meta_Box_Payment_Form::save' ); |
|
114 | + remove_action('save_post', 'WPInv_Meta_Box_Payment_Form::save'); |
|
115 | 115 | |
116 | 116 | // $post_id and $post are required. |
117 | - if ( empty( $post_id ) || empty( $post ) ) { |
|
117 | + if (empty($post_id) || empty($post)) { |
|
118 | 118 | return; |
119 | 119 | } |
120 | 120 | |
121 | 121 | // Ensure that this user can edit the post. |
122 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
122 | + if (!current_user_can('edit_post', $post_id)) { |
|
123 | 123 | return; |
124 | 124 | } |
125 | 125 | |
126 | 126 | // Dont' save meta boxes for revisions or autosaves |
127 | - if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
127 | + if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
128 | 128 | return; |
129 | 129 | } |
130 | 130 | |
131 | 131 | // Do not save for ajax requests. |
132 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
132 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
133 | 133 | return; |
134 | 134 | } |
135 | 135 | |
136 | 136 | // Confirm the security nonce. |
137 | - if ( empty( $_POST['wpinv_save_payment_form'] ) || ! wp_verify_nonce( $_POST['wpinv_save_payment_form'], 'wpinv_save_payment_form' ) ) { |
|
137 | + if (empty($_POST['wpinv_save_payment_form']) || !wp_verify_nonce($_POST['wpinv_save_payment_form'], 'wpinv_save_payment_form')) { |
|
138 | 138 | return; |
139 | 139 | } |
140 | 140 | |
141 | 141 | // Save form items. |
142 | - $form_items = json_decode( wp_unslash( $_POST['wpinv_form_items'] ), true ); |
|
142 | + $form_items = json_decode(wp_unslash($_POST['wpinv_form_items']), true); |
|
143 | 143 | |
144 | - if ( empty( $form_items ) ) { |
|
144 | + if (empty($form_items)) { |
|
145 | 145 | $form_items = array(); |
146 | 146 | } |
147 | 147 | |
148 | - update_post_meta( $post_id, 'wpinv_form_items', self::maybe_save_items( $form_items ) ); |
|
148 | + update_post_meta($post_id, 'wpinv_form_items', self::maybe_save_items($form_items)); |
|
149 | 149 | |
150 | 150 | // Save form elements. |
151 | - $wpinv_form_elements = json_decode( wp_unslash( $_POST['wpinv_form_elements'] ), true ); |
|
152 | - if ( empty( $wpinv_form_elements ) ) { |
|
151 | + $wpinv_form_elements = json_decode(wp_unslash($_POST['wpinv_form_elements']), true); |
|
152 | + if (empty($wpinv_form_elements)) { |
|
153 | 153 | $wpinv_form_elements = array(); |
154 | 154 | } |
155 | 155 | |
156 | - update_post_meta( $post_id, 'wpinv_form_elements', $wpinv_form_elements ); |
|
156 | + update_post_meta($post_id, 'wpinv_form_elements', $wpinv_form_elements); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
160 | 160 | * Saves unsaved form items. |
161 | 161 | */ |
162 | - public static function maybe_save_items( $items ) { |
|
162 | + public static function maybe_save_items($items) { |
|
163 | 163 | |
164 | 164 | $saved = array(); |
165 | 165 | |
166 | - foreach( $items as $item ) { |
|
166 | + foreach ($items as $item) { |
|
167 | 167 | |
168 | - if ( is_numeric( $item['id'] ) ) { |
|
168 | + if (is_numeric($item['id'])) { |
|
169 | 169 | $saved[] = $item; |
170 | 170 | continue; |
171 | 171 | } |
172 | 172 | |
173 | 173 | $data = array( |
174 | - 'post_title' => sanitize_text_field( $item['title'] ), |
|
175 | - 'post_excerpt' => wp_kses_post( $item['description'] ), |
|
174 | + 'post_title' => sanitize_text_field($item['title']), |
|
175 | + 'post_excerpt' => wp_kses_post($item['description']), |
|
176 | 176 | 'post_status' => 'publish', |
177 | 177 | 'meta' => array( |
178 | 178 | 'type' => 'custom', |
179 | - 'price' => wpinv_sanitize_amount( $item['price'] ), |
|
179 | + 'price' => wpinv_sanitize_amount($item['price']), |
|
180 | 180 | 'vat_rule' => 'digital', |
181 | 181 | 'vat_class' => '_standard', |
182 | 182 | ) |
183 | 183 | ); |
184 | 184 | |
185 | - $new_item = new WPInv_Item(); |
|
186 | - $new_item->create( $data ); |
|
185 | + $new_item = new WPInv_Item(); |
|
186 | + $new_item->create($data); |
|
187 | 187 | |
188 | - if ( ! empty( $new_item ) ) { |
|
188 | + if (!empty($new_item)) { |
|
189 | 189 | $item['id'] = $new_item->ID; |
190 | 190 | $saved[] = $item; |
191 | 191 | } |
@@ -198,5 +198,5 @@ discard block |
||
198 | 198 | |
199 | 199 | } |
200 | 200 | |
201 | -add_action( 'save_post_wpi_payment_form', 'WPInv_Meta_Box_Payment_Form::save', 10, 2 ); |
|
201 | +add_action('save_post_wpi_payment_form', 'WPInv_Meta_Box_Payment_Form::save', 10, 2); |
|
202 | 202 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
3 | +if (!defined('ABSPATH')) { |
|
4 | 4 | exit; // Exit if accessed directly |
5 | 5 | } |
6 | 6 | |
@@ -22,16 +22,16 @@ discard block |
||
22 | 22 | 'orderby' => 'title', |
23 | 23 | 'order' => 'ASC', |
24 | 24 | 'posts_per_page' => -1, |
25 | - 'post_status' => array( 'publish' ), |
|
25 | + 'post_status' => array('publish'), |
|
26 | 26 | ) |
27 | 27 | ); |
28 | 28 | |
29 | 29 | $options = array( |
30 | - '' => __('Select a Form','invoicing') |
|
30 | + '' => __('Select a Form', 'invoicing') |
|
31 | 31 | ); |
32 | 32 | |
33 | - foreach( $forms as $form ) { |
|
34 | - $options[ $form->ID ] = $form->post_title; |
|
33 | + foreach ($forms as $form) { |
|
34 | + $options[$form->ID] = $form->post_title; |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | $options = array( |
@@ -41,15 +41,15 @@ discard block |
||
41 | 41 | 'block-keywords'=> "['invoicing','buy', 'buy item', 'pay', 'payment form']", |
42 | 42 | 'class_name' => __CLASS__, |
43 | 43 | 'base_id' => 'wpinv_payment_form', |
44 | - 'name' => __('Invoicing > Payment Form','invoicing'), |
|
44 | + 'name' => __('Invoicing > Payment Form', 'invoicing'), |
|
45 | 45 | 'widget_ops' => array( |
46 | 46 | 'classname' => 'wpinv-payment-form-class bsui', |
47 | - 'description' => esc_html__('Displays a payment form.','invoicing'), |
|
47 | + 'description' => esc_html__('Displays a payment form.', 'invoicing'), |
|
48 | 48 | ), |
49 | 49 | 'arguments' => array( |
50 | 50 | 'form' => array( |
51 | - 'title' => __( 'Payment Form', 'invoicing' ), |
|
52 | - 'desc' => __( 'Select your payment form.', 'invoicing' ), |
|
51 | + 'title' => __('Payment Form', 'invoicing'), |
|
52 | + 'desc' => __('Select your payment form.', 'invoicing'), |
|
53 | 53 | 'type' => 'select', |
54 | 54 | 'options' => $options, |
55 | 55 | 'desc_tip' => true, |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | ); |
62 | 62 | |
63 | 63 | |
64 | - parent::__construct( $options ); |
|
64 | + parent::__construct($options); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -73,42 +73,42 @@ discard block |
||
73 | 73 | * |
74 | 74 | * @return string |
75 | 75 | */ |
76 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
76 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
77 | 77 | global $invoicing; |
78 | 78 | |
79 | 79 | // Do we have a payment form? |
80 | - if ( empty( $args['form'] ) ) { |
|
80 | + if (empty($args['form'])) { |
|
81 | 81 | return aui()->alert( |
82 | 82 | array( |
83 | 83 | 'type' => 'warning', |
84 | - 'content' => __( 'No payment form selected', 'invoicing' ), |
|
84 | + 'content' => __('No payment form selected', 'invoicing'), |
|
85 | 85 | ) |
86 | 86 | ); |
87 | 87 | |
88 | 88 | } |
89 | 89 | |
90 | 90 | // If yes, ensure that it is published. |
91 | - if ( 'publish' != get_post_status( $args['form'] ) ) { |
|
91 | + if ('publish' != get_post_status($args['form'])) { |
|
92 | 92 | return aui()->alert( |
93 | 93 | array( |
94 | 94 | 'type' => 'warning', |
95 | - 'content' => __( 'This payment form is no longer active', 'invoicing' ), |
|
95 | + 'content' => __('This payment form is no longer active', 'invoicing'), |
|
96 | 96 | ) |
97 | 97 | ); |
98 | 98 | } |
99 | 99 | |
100 | 100 | // Get the form elements and items. |
101 | - $elements = $invoicing->form_elements->get_form_elements( $args['form'] ); |
|
102 | - $items = $invoicing->form_elements->get_form_items( $args['form'] ); |
|
101 | + $elements = $invoicing->form_elements->get_form_elements($args['form']); |
|
102 | + $items = $invoicing->form_elements->get_form_items($args['form']); |
|
103 | 103 | |
104 | 104 | ob_start(); |
105 | 105 | echo "<form class='wpinv_payment_form'>"; |
106 | 106 | echo "<input type='hidden' name='form_id' value='{$args['form']}'/>"; |
107 | - wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' ); |
|
107 | + wp_nonce_field('wpinv_payment_form', 'wpinv_payment_form'); |
|
108 | 108 | |
109 | - foreach ( $elements as $element ) { |
|
110 | - do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $args['form'] ); |
|
111 | - do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $args['form'] ); |
|
109 | + foreach ($elements as $element) { |
|
110 | + do_action('wpinv_frontend_render_payment_form_element', $element, $items, $args['form']); |
|
111 | + do_action("wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $args['form']); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>"; |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | |
117 | 117 | $content = ob_get_clean(); |
118 | 118 | |
119 | - return str_replace( 'sr-only', '', $content ); |
|
119 | + return str_replace('sr-only', '', $content); |
|
120 | 120 | |
121 | 121 | } |
122 | 122 |
@@ -7,28 +7,28 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | class WPInv_Ajax { |
15 | 15 | public static function init() { |
16 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
17 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
16 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
17 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
18 | 18 | self::add_ajax_events(); |
19 | 19 | } |
20 | 20 | |
21 | 21 | public static function define_ajax() { |
22 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
23 | - if ( ! defined( 'DOING_AJAX' ) ) { |
|
24 | - define( 'DOING_AJAX', true ); |
|
22 | + if (!empty($_GET['wpinv-ajax'])) { |
|
23 | + if (!defined('DOING_AJAX')) { |
|
24 | + define('DOING_AJAX', true); |
|
25 | 25 | } |
26 | - if ( ! defined( 'WC_DOING_AJAX' ) ) { |
|
27 | - define( 'WC_DOING_AJAX', true ); |
|
26 | + if (!defined('WC_DOING_AJAX')) { |
|
27 | + define('WC_DOING_AJAX', true); |
|
28 | 28 | } |
29 | 29 | // Turn off display_errors during AJAX events to prevent malformed JSON |
30 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
31 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
30 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
31 | + /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0); |
|
32 | 32 | } |
33 | 33 | $GLOBALS['wpdb']->hide_errors(); |
34 | 34 | } |
@@ -37,24 +37,24 @@ discard block |
||
37 | 37 | public static function do_wpinv_ajax() { |
38 | 38 | global $wp_query; |
39 | 39 | |
40 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
41 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) ); |
|
40 | + if (!empty($_GET['wpinv-ajax'])) { |
|
41 | + $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax'])); |
|
42 | 42 | } |
43 | 43 | |
44 | - if ( $action = $wp_query->get( 'wpinv-ajax' ) ) { |
|
44 | + if ($action = $wp_query->get('wpinv-ajax')) { |
|
45 | 45 | self::wpinv_ajax_headers(); |
46 | - do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) ); |
|
46 | + do_action('wpinv_ajax_' . sanitize_text_field($action)); |
|
47 | 47 | die(); |
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
51 | 51 | private static function wpinv_ajax_headers() { |
52 | 52 | send_origin_headers(); |
53 | - /** @scrutinizer ignore-unhandled */ @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
54 | - /** @scrutinizer ignore-unhandled */ @header( 'X-Robots-Tag: noindex' ); |
|
53 | + /** @scrutinizer ignore-unhandled */ @header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
54 | + /** @scrutinizer ignore-unhandled */ @header('X-Robots-Tag: noindex'); |
|
55 | 55 | send_nosniff_header(); |
56 | 56 | nocache_headers(); |
57 | - status_header( 200 ); |
|
57 | + status_header(200); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | public static function add_ajax_events() { |
@@ -78,39 +78,39 @@ discard block |
||
78 | 78 | 'buy_items' => true, |
79 | 79 | ); |
80 | 80 | |
81 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
82 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
81 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
82 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
83 | 83 | |
84 | - if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) { |
|
85 | - define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 ); |
|
84 | + if (!defined('WPI_AJAX_' . strtoupper($nopriv))) { |
|
85 | + define('WPI_AJAX_' . strtoupper($nopriv), 1); |
|
86 | 86 | } |
87 | 87 | |
88 | - if ( $nopriv ) { |
|
89 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
88 | + if ($nopriv) { |
|
89 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
90 | 90 | |
91 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
91 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | } |
95 | 95 | |
96 | 96 | public static function add_note() { |
97 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
97 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
98 | 98 | |
99 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
99 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
100 | 100 | die(-1); |
101 | 101 | } |
102 | 102 | |
103 | - $post_id = absint( $_POST['post_id'] ); |
|
104 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
105 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
103 | + $post_id = absint($_POST['post_id']); |
|
104 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
105 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
106 | 106 | |
107 | 107 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
108 | 108 | |
109 | - if ( $post_id > 0 ) { |
|
110 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
109 | + if ($post_id > 0) { |
|
110 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
111 | 111 | |
112 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
113 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
112 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
113 | + wpinv_get_invoice_note_line_item($note_id); |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | |
@@ -118,16 +118,16 @@ discard block |
||
118 | 118 | } |
119 | 119 | |
120 | 120 | public static function delete_note() { |
121 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
121 | + check_ajax_referer('delete-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 | - $note_id = (int)$_POST['note_id']; |
|
127 | + $note_id = (int) $_POST['note_id']; |
|
128 | 128 | |
129 | - if ( $note_id > 0 ) { |
|
130 | - wp_delete_comment( $note_id, true ); |
|
129 | + if ($note_id > 0) { |
|
130 | + wp_delete_comment($note_id, true); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | die(); |
@@ -140,8 +140,8 @@ discard block |
||
140 | 140 | } |
141 | 141 | |
142 | 142 | public static function checkout() { |
143 | - if ( ! defined( 'WPINV_CHECKOUT' ) ) { |
|
144 | - define( 'WPINV_CHECKOUT', true ); |
|
143 | + if (!defined('WPINV_CHECKOUT')) { |
|
144 | + define('WPINV_CHECKOUT', true); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | wpinv_process_checkout(); |
@@ -150,53 +150,53 @@ discard block |
||
150 | 150 | |
151 | 151 | public static function add_invoice_item() { |
152 | 152 | global $wpi_userID, $wpinv_ip_address_country; |
153 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
154 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
153 | + check_ajax_referer('invoice-item', '_nonce'); |
|
154 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
155 | 155 | die(-1); |
156 | 156 | } |
157 | 157 | |
158 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
159 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
158 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
159 | + $invoice_id = absint($_POST['invoice_id']); |
|
160 | 160 | |
161 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
161 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
162 | 162 | die(); |
163 | 163 | } |
164 | 164 | |
165 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
166 | - if ( empty( $invoice ) ) { |
|
165 | + $invoice = wpinv_get_invoice($invoice_id); |
|
166 | + if (empty($invoice)) { |
|
167 | 167 | die(); |
168 | 168 | } |
169 | 169 | |
170 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
170 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
171 | 171 | die(); // Don't allow modify items for paid invoice. |
172 | 172 | } |
173 | 173 | |
174 | - if ( !empty( $_POST['user_id'] ) ) { |
|
175 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
174 | + if (!empty($_POST['user_id'])) { |
|
175 | + $wpi_userID = absint($_POST['user_id']); |
|
176 | 176 | } |
177 | 177 | |
178 | - $item = new WPInv_Item( $item_id ); |
|
179 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
178 | + $item = new WPInv_Item($item_id); |
|
179 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
180 | 180 | die(); |
181 | 181 | } |
182 | 182 | |
183 | 183 | // Validate item before adding to invoice because recurring item must be paid individually. |
184 | - if ( !empty( $invoice->cart_details ) ) { |
|
184 | + if (!empty($invoice->cart_details)) { |
|
185 | 185 | $valid = true; |
186 | 186 | |
187 | - if ( $recurring_item = $invoice->get_recurring() ) { |
|
188 | - if ( $recurring_item != $item_id ) { |
|
187 | + if ($recurring_item = $invoice->get_recurring()) { |
|
188 | + if ($recurring_item != $item_id) { |
|
189 | 189 | $valid = false; |
190 | 190 | } |
191 | - } else if ( wpinv_is_recurring_item( $item_id ) ) { |
|
191 | + } else if (wpinv_is_recurring_item($item_id)) { |
|
192 | 192 | $valid = false; |
193 | 193 | } |
194 | 194 | |
195 | - if ( !$valid ) { |
|
195 | + if (!$valid) { |
|
196 | 196 | $response = array(); |
197 | 197 | $response['success'] = false; |
198 | - $response['msg'] = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ); |
|
199 | - wp_send_json( $response ); |
|
198 | + $response['msg'] = __('You can not add item because recurring item must be paid individually!', 'invoicing'); |
|
199 | + wp_send_json($response); |
|
200 | 200 | } |
201 | 201 | } |
202 | 202 | |
@@ -204,11 +204,11 @@ discard block |
||
204 | 204 | |
205 | 205 | $data = array(); |
206 | 206 | $data['invoice_id'] = $invoice_id; |
207 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
207 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
208 | 208 | |
209 | - wpinv_set_checkout_session( $data ); |
|
209 | + wpinv_set_checkout_session($data); |
|
210 | 210 | |
211 | - $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1; |
|
211 | + $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int) $_POST['qty'] > 0 ? (int) $_POST['qty'] : 1; |
|
212 | 212 | |
213 | 213 | $args = array( |
214 | 214 | 'id' => $item_id, |
@@ -221,21 +221,21 @@ discard block |
||
221 | 221 | 'fees' => array() |
222 | 222 | ); |
223 | 223 | |
224 | - $invoice->add_item( $item_id, $args ); |
|
224 | + $invoice->add_item($item_id, $args); |
|
225 | 225 | $invoice->save(); |
226 | 226 | |
227 | - if ( empty( $_POST['country'] ) ) { |
|
227 | + if (empty($_POST['country'])) { |
|
228 | 228 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
229 | 229 | } |
230 | - if ( empty( $_POST['state'] ) ) { |
|
230 | + if (empty($_POST['state'])) { |
|
231 | 231 | $_POST['state'] = $invoice->state; |
232 | 232 | } |
233 | 233 | |
234 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
235 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
234 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
235 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
236 | 236 | |
237 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
238 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
237 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
238 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
239 | 239 | |
240 | 240 | $wpinv_ip_address_country = $invoice->country; |
241 | 241 | |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | |
244 | 244 | $response = array(); |
245 | 245 | $response['success'] = true; |
246 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
246 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
247 | 247 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
248 | 248 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
249 | 249 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -255,41 +255,41 @@ discard block |
||
255 | 255 | |
256 | 256 | wpinv_set_checkout_session($checkout_session); |
257 | 257 | |
258 | - wp_send_json( $response ); |
|
258 | + wp_send_json($response); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | |
262 | 262 | public static function remove_invoice_item() { |
263 | 263 | global $wpi_userID, $wpinv_ip_address_country; |
264 | 264 | |
265 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
266 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
265 | + check_ajax_referer('invoice-item', '_nonce'); |
|
266 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
267 | 267 | die(-1); |
268 | 268 | } |
269 | 269 | |
270 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
271 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
272 | - $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
270 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
271 | + $invoice_id = absint($_POST['invoice_id']); |
|
272 | + $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
273 | 273 | |
274 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
274 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
275 | 275 | die(); |
276 | 276 | } |
277 | 277 | |
278 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
279 | - if ( empty( $invoice ) ) { |
|
278 | + $invoice = wpinv_get_invoice($invoice_id); |
|
279 | + if (empty($invoice)) { |
|
280 | 280 | die(); |
281 | 281 | } |
282 | 282 | |
283 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
283 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
284 | 284 | die(); // Don't allow modify items for paid invoice. |
285 | 285 | } |
286 | 286 | |
287 | - if ( !empty( $_POST['user_id'] ) ) { |
|
288 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
287 | + if (!empty($_POST['user_id'])) { |
|
288 | + $wpi_userID = absint($_POST['user_id']); |
|
289 | 289 | } |
290 | 290 | |
291 | - $item = new WPInv_Item( $item_id ); |
|
292 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
291 | + $item = new WPInv_Item($item_id); |
|
292 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
293 | 293 | die(); |
294 | 294 | } |
295 | 295 | |
@@ -297,9 +297,9 @@ discard block |
||
297 | 297 | |
298 | 298 | $data = array(); |
299 | 299 | $data['invoice_id'] = $invoice_id; |
300 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
300 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
301 | 301 | |
302 | - wpinv_set_checkout_session( $data ); |
|
302 | + wpinv_set_checkout_session($data); |
|
303 | 303 | |
304 | 304 | $args = array( |
305 | 305 | 'id' => $item_id, |
@@ -307,21 +307,21 @@ discard block |
||
307 | 307 | 'cart_index' => $cart_index |
308 | 308 | ); |
309 | 309 | |
310 | - $invoice->remove_item( $item_id, $args ); |
|
310 | + $invoice->remove_item($item_id, $args); |
|
311 | 311 | $invoice->save(); |
312 | 312 | |
313 | - if ( empty( $_POST['country'] ) ) { |
|
313 | + if (empty($_POST['country'])) { |
|
314 | 314 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
315 | 315 | } |
316 | - if ( empty( $_POST['state'] ) ) { |
|
316 | + if (empty($_POST['state'])) { |
|
317 | 317 | $_POST['state'] = $invoice->state; |
318 | 318 | } |
319 | 319 | |
320 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
321 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
320 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
321 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
322 | 322 | |
323 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
324 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
323 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
324 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
325 | 325 | |
326 | 326 | $wpinv_ip_address_country = $invoice->country; |
327 | 327 | |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | |
330 | 330 | $response = array(); |
331 | 331 | $response['success'] = true; |
332 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
332 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
333 | 333 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
334 | 334 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
335 | 335 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -341,55 +341,55 @@ discard block |
||
341 | 341 | |
342 | 342 | wpinv_set_checkout_session($checkout_session); |
343 | 343 | |
344 | - wp_send_json( $response ); |
|
344 | + wp_send_json($response); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | public static function create_invoice_item() { |
348 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
349 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
348 | + check_ajax_referer('invoice-item', '_nonce'); |
|
349 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
350 | 350 | die(-1); |
351 | 351 | } |
352 | 352 | |
353 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
353 | + $invoice_id = absint($_POST['invoice_id']); |
|
354 | 354 | |
355 | 355 | // Find the item |
356 | - if ( !is_numeric( $invoice_id ) ) { |
|
356 | + if (!is_numeric($invoice_id)) { |
|
357 | 357 | die(); |
358 | 358 | } |
359 | 359 | |
360 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
361 | - if ( empty( $invoice ) ) { |
|
360 | + $invoice = wpinv_get_invoice($invoice_id); |
|
361 | + if (empty($invoice)) { |
|
362 | 362 | die(); |
363 | 363 | } |
364 | 364 | |
365 | 365 | // Validate item before adding to invoice because recurring item must be paid individually. |
366 | - if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) { |
|
366 | + if (!empty($invoice->cart_details) && $invoice->get_recurring()) { |
|
367 | 367 | $response = array(); |
368 | 368 | $response['success'] = false; |
369 | - $response['msg'] = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ); |
|
370 | - wp_send_json( $response ); |
|
369 | + $response['msg'] = __('You can not add item because recurring item must be paid individually!', 'invoicing'); |
|
370 | + wp_send_json($response); |
|
371 | 371 | } |
372 | 372 | |
373 | - $save_item = wp_unslash( $_POST['_wpinv_quick'] ); |
|
373 | + $save_item = wp_unslash($_POST['_wpinv_quick']); |
|
374 | 374 | |
375 | 375 | $meta = array(); |
376 | 376 | $meta['type'] = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom'; |
377 | - $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0; |
|
377 | + $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0; |
|
378 | 378 | $meta['vat_rule'] = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital'; |
379 | 379 | $meta['vat_class'] = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard'; |
380 | 380 | |
381 | 381 | $data = array(); |
382 | 382 | $data['post_title'] = sanitize_text_field($save_item['name']); |
383 | 383 | $data['post_status'] = 'publish'; |
384 | - $data['post_excerpt'] = ! empty( $save_item['excerpt'] ) ? wp_kses_post( $save_item['excerpt'] ) : ''; |
|
384 | + $data['post_excerpt'] = !empty($save_item['excerpt']) ? wp_kses_post($save_item['excerpt']) : ''; |
|
385 | 385 | $data['meta'] = $meta; |
386 | 386 | |
387 | 387 | $item = new WPInv_Item(); |
388 | - $item->create( $data ); |
|
388 | + $item->create($data); |
|
389 | 389 | |
390 | - if ( !empty( $item ) ) { |
|
390 | + if (!empty($item)) { |
|
391 | 391 | $_POST['item_id'] = $item->ID; |
392 | - $_POST['qty'] = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1; |
|
392 | + $_POST['qty'] = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int) $save_item['qty'] : 1; |
|
393 | 393 | |
394 | 394 | self::add_invoice_item(); |
395 | 395 | } |
@@ -397,15 +397,15 @@ discard block |
||
397 | 397 | } |
398 | 398 | |
399 | 399 | public static function get_billing_details() { |
400 | - check_ajax_referer( 'get-billing-details', '_nonce' ); |
|
400 | + check_ajax_referer('get-billing-details', '_nonce'); |
|
401 | 401 | |
402 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
402 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
403 | 403 | die(-1); |
404 | 404 | } |
405 | 405 | |
406 | - $user_id = (int)$_POST['user_id']; |
|
406 | + $user_id = (int) $_POST['user_id']; |
|
407 | 407 | $billing_details = wpinv_get_user_address($user_id); |
408 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
408 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
409 | 409 | |
410 | 410 | if (isset($billing_details['user_id'])) { |
411 | 411 | unset($billing_details['user_id']); |
@@ -419,20 +419,20 @@ discard block |
||
419 | 419 | $response['success'] = true; |
420 | 420 | $response['data']['billing_details'] = $billing_details; |
421 | 421 | |
422 | - wp_send_json( $response ); |
|
422 | + wp_send_json($response); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | public static function admin_recalculate_totals() { |
426 | 426 | global $wpi_userID, $wpinv_ip_address_country; |
427 | 427 | |
428 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
429 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
428 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
429 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
430 | 430 | die(-1); |
431 | 431 | } |
432 | 432 | |
433 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
434 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
435 | - if ( empty( $invoice ) ) { |
|
433 | + $invoice_id = absint($_POST['invoice_id']); |
|
434 | + $invoice = wpinv_get_invoice($invoice_id); |
|
435 | + if (empty($invoice)) { |
|
436 | 436 | die(); |
437 | 437 | } |
438 | 438 | |
@@ -440,23 +440,23 @@ discard block |
||
440 | 440 | |
441 | 441 | $data = array(); |
442 | 442 | $data['invoice_id'] = $invoice_id; |
443 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
443 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
444 | 444 | |
445 | - wpinv_set_checkout_session( $data ); |
|
445 | + wpinv_set_checkout_session($data); |
|
446 | 446 | |
447 | - if ( !empty( $_POST['user_id'] ) ) { |
|
448 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
447 | + if (!empty($_POST['user_id'])) { |
|
448 | + $wpi_userID = absint($_POST['user_id']); |
|
449 | 449 | } |
450 | 450 | |
451 | - if ( empty( $_POST['country'] ) ) { |
|
451 | + if (empty($_POST['country'])) { |
|
452 | 452 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
453 | 453 | } |
454 | 454 | |
455 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
456 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
457 | - if ( isset( $_POST['state'] ) ) { |
|
458 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
459 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
455 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
456 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
457 | + if (isset($_POST['state'])) { |
|
458 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
459 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | $wpinv_ip_address_country = $invoice->country; |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | |
466 | 466 | $response = array(); |
467 | 467 | $response['success'] = true; |
468 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
468 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
469 | 469 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
470 | 470 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
471 | 471 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -477,25 +477,25 @@ discard block |
||
477 | 477 | |
478 | 478 | wpinv_set_checkout_session($checkout_session); |
479 | 479 | |
480 | - wp_send_json( $response ); |
|
480 | + wp_send_json($response); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | public static function admin_apply_discount() { |
484 | 484 | global $wpi_userID; |
485 | 485 | |
486 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
487 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
486 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
487 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
488 | 488 | die(-1); |
489 | 489 | } |
490 | 490 | |
491 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
492 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
493 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
491 | + $invoice_id = absint($_POST['invoice_id']); |
|
492 | + $discount_code = sanitize_text_field($_POST['code']); |
|
493 | + if (empty($invoice_id) || empty($discount_code)) { |
|
494 | 494 | die(); |
495 | 495 | } |
496 | 496 | |
497 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
498 | - if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) { |
|
497 | + $invoice = wpinv_get_invoice($invoice_id); |
|
498 | + if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) { |
|
499 | 499 | die(); |
500 | 500 | } |
501 | 501 | |
@@ -503,49 +503,49 @@ discard block |
||
503 | 503 | |
504 | 504 | $data = array(); |
505 | 505 | $data['invoice_id'] = $invoice_id; |
506 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
506 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
507 | 507 | |
508 | - wpinv_set_checkout_session( $data ); |
|
508 | + wpinv_set_checkout_session($data); |
|
509 | 509 | |
510 | 510 | $response = array(); |
511 | 511 | $response['success'] = false; |
512 | - $response['msg'] = __( 'This discount is invalid.', 'invoicing' ); |
|
512 | + $response['msg'] = __('This discount is invalid.', 'invoicing'); |
|
513 | 513 | $response['data']['code'] = $discount_code; |
514 | 514 | |
515 | - if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) { |
|
516 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
515 | + if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) { |
|
516 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
517 | 517 | |
518 | 518 | $response['success'] = true; |
519 | - $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' ); |
|
520 | - } else { |
|
519 | + $response['msg'] = __('Discount has been applied successfully.', 'invoicing'); |
|
520 | + } else { |
|
521 | 521 | $errors = wpinv_get_errors(); |
522 | - if ( !empty( $errors['wpinv-discount-error'] ) ) { |
|
522 | + if (!empty($errors['wpinv-discount-error'])) { |
|
523 | 523 | $response['msg'] = $errors['wpinv-discount-error']; |
524 | 524 | } |
525 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
525 | + wpinv_unset_error('wpinv-discount-error'); |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | wpinv_set_checkout_session($checkout_session); |
529 | 529 | |
530 | - wp_send_json( $response ); |
|
530 | + wp_send_json($response); |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | public static function admin_remove_discount() { |
534 | 534 | global $wpi_userID; |
535 | 535 | |
536 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
537 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
536 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
537 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
538 | 538 | die(-1); |
539 | 539 | } |
540 | 540 | |
541 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
542 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
543 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
541 | + $invoice_id = absint($_POST['invoice_id']); |
|
542 | + $discount_code = sanitize_text_field($_POST['code']); |
|
543 | + if (empty($invoice_id) || empty($discount_code)) { |
|
544 | 544 | die(); |
545 | 545 | } |
546 | 546 | |
547 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
548 | - if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) { |
|
547 | + $invoice = wpinv_get_invoice($invoice_id); |
|
548 | + if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) { |
|
549 | 549 | die(); |
550 | 550 | } |
551 | 551 | |
@@ -553,38 +553,38 @@ discard block |
||
553 | 553 | |
554 | 554 | $data = array(); |
555 | 555 | $data['invoice_id'] = $invoice_id; |
556 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
556 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
557 | 557 | |
558 | - wpinv_set_checkout_session( $data ); |
|
558 | + wpinv_set_checkout_session($data); |
|
559 | 559 | |
560 | 560 | $response = array(); |
561 | 561 | $response['success'] = false; |
562 | 562 | $response['msg'] = NULL; |
563 | 563 | |
564 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
564 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
565 | 565 | $response['success'] = true; |
566 | - $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' ); |
|
566 | + $response['msg'] = __('Discount has been removed successfully.', 'invoicing'); |
|
567 | 567 | |
568 | 568 | wpinv_set_checkout_session($checkout_session); |
569 | 569 | |
570 | - wp_send_json( $response ); |
|
570 | + wp_send_json($response); |
|
571 | 571 | } |
572 | 572 | |
573 | 573 | public static function check_email() { |
574 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
575 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
574 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
575 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
576 | 576 | die(-1); |
577 | 577 | } |
578 | 578 | |
579 | - $email = sanitize_text_field( $_POST['email'] ); |
|
579 | + $email = sanitize_text_field($_POST['email']); |
|
580 | 580 | |
581 | 581 | $response = array(); |
582 | - if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) { |
|
582 | + if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) { |
|
583 | 583 | $user_id = $user_data->ID; |
584 | 584 | $user_login = $user_data->user_login; |
585 | 585 | $display_name = $user_data->display_name ? $user_data->display_name : $user_login; |
586 | 586 | $billing_details = wpinv_get_user_address($user_id); |
587 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
587 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
588 | 588 | |
589 | 589 | if (isset($billing_details['user_id'])) { |
590 | 590 | unset($billing_details['user_id']); |
@@ -600,54 +600,54 @@ discard block |
||
600 | 600 | $response['data']['billing_details'] = $billing_details; |
601 | 601 | } |
602 | 602 | |
603 | - wp_send_json( $response ); |
|
603 | + wp_send_json($response); |
|
604 | 604 | } |
605 | 605 | |
606 | 606 | public static function run_tool() { |
607 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
608 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
607 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
608 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
609 | 609 | die(-1); |
610 | 610 | } |
611 | 611 | |
612 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
612 | + $tool = sanitize_text_field($_POST['tool']); |
|
613 | 613 | |
614 | - do_action( 'wpinv_run_tool' ); |
|
614 | + do_action('wpinv_run_tool'); |
|
615 | 615 | |
616 | - if ( !empty( $tool ) ) { |
|
617 | - do_action( 'wpinv_tool_' . $tool ); |
|
616 | + if (!empty($tool)) { |
|
617 | + do_action('wpinv_tool_' . $tool); |
|
618 | 618 | } |
619 | 619 | } |
620 | 620 | |
621 | 621 | public static function apply_discount() { |
622 | 622 | global $wpi_userID; |
623 | 623 | |
624 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
624 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
625 | 625 | |
626 | 626 | $response = array(); |
627 | 627 | |
628 | - if ( isset( $_POST['code'] ) ) { |
|
629 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
628 | + if (isset($_POST['code'])) { |
|
629 | + $discount_code = sanitize_text_field($_POST['code']); |
|
630 | 630 | |
631 | 631 | $response['success'] = false; |
632 | 632 | $response['msg'] = ''; |
633 | 633 | $response['data']['code'] = $discount_code; |
634 | 634 | |
635 | 635 | $invoice = wpinv_get_invoice_cart(); |
636 | - if ( empty( $invoice->ID ) ) { |
|
637 | - $response['msg'] = __( 'Invalid checkout request.', 'invoicing' ); |
|
638 | - wp_send_json( $response ); |
|
636 | + if (empty($invoice->ID)) { |
|
637 | + $response['msg'] = __('Invalid checkout request.', 'invoicing'); |
|
638 | + wp_send_json($response); |
|
639 | 639 | } |
640 | 640 | |
641 | 641 | $wpi_userID = $invoice->get_user_id(); |
642 | 642 | |
643 | - if ( wpinv_is_discount_valid( $discount_code, $wpi_userID ) ) { |
|
644 | - $discount = wpinv_get_discount_by_code( $discount_code ); |
|
645 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
646 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) ); |
|
647 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
648 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
643 | + if (wpinv_is_discount_valid($discount_code, $wpi_userID)) { |
|
644 | + $discount = wpinv_get_discount_by_code($discount_code); |
|
645 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
646 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID)); |
|
647 | + $total = wpinv_get_cart_total(null, $discounts); |
|
648 | + $cart_totals = wpinv_recalculate_tax(true); |
|
649 | 649 | |
650 | - if ( !empty( $cart_totals ) ) { |
|
650 | + if (!empty($cart_totals)) { |
|
651 | 651 | $response['success'] = true; |
652 | 652 | $response['data'] = $cart_totals; |
653 | 653 | $response['data']['code'] = $discount_code; |
@@ -656,29 +656,29 @@ discard block |
||
656 | 656 | } |
657 | 657 | } else { |
658 | 658 | $errors = wpinv_get_errors(); |
659 | - $response['msg'] = $errors['wpinv-discount-error']; |
|
660 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
659 | + $response['msg'] = $errors['wpinv-discount-error']; |
|
660 | + wpinv_unset_error('wpinv-discount-error'); |
|
661 | 661 | } |
662 | 662 | |
663 | 663 | // Allow for custom discount code handling |
664 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
664 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
665 | 665 | } |
666 | 666 | |
667 | - wp_send_json( $response ); |
|
667 | + wp_send_json($response); |
|
668 | 668 | } |
669 | 669 | |
670 | 670 | public static function remove_discount() { |
671 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
671 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
672 | 672 | |
673 | 673 | $response = array(); |
674 | 674 | |
675 | - if ( isset( $_POST['code'] ) ) { |
|
676 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
677 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
678 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
679 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
675 | + if (isset($_POST['code'])) { |
|
676 | + $discount_code = sanitize_text_field($_POST['code']); |
|
677 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
678 | + $total = wpinv_get_cart_total(null, $discounts); |
|
679 | + $cart_totals = wpinv_recalculate_tax(true); |
|
680 | 680 | |
681 | - if ( !empty( $cart_totals ) ) { |
|
681 | + if (!empty($cart_totals)) { |
|
682 | 682 | $response['success'] = true; |
683 | 683 | $response['data'] = $cart_totals; |
684 | 684 | $response['data']['code'] = $discount_code; |
@@ -687,10 +687,10 @@ discard block |
||
687 | 687 | } |
688 | 688 | |
689 | 689 | // Allow for custom discount code handling |
690 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
690 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
691 | 691 | } |
692 | 692 | |
693 | - wp_send_json( $response ); |
|
693 | + wp_send_json($response); |
|
694 | 694 | } |
695 | 695 | |
696 | 696 | /** |
@@ -702,66 +702,66 @@ discard block |
||
702 | 702 | global $invoicing; |
703 | 703 | |
704 | 704 | // Check nonce. |
705 | - if ( ! isset( $_POST['wpinv_payment_form'] ) || ! wp_verify_nonce( $_POST['wpinv_payment_form'], 'wpinv_payment_form' ) ) { |
|
706 | - wp_send_json_error( __( 'Security checks failed.', 'invoicing' ) ); |
|
705 | + if (!isset($_POST['wpinv_payment_form']) || !wp_verify_nonce($_POST['wpinv_payment_form'], 'wpinv_payment_form')) { |
|
706 | + wp_send_json_error(__('Security checks failed.', 'invoicing')); |
|
707 | 707 | } |
708 | 708 | |
709 | 709 | // Prepare submitted data... |
710 | - $data = wp_unslash( $_POST ); |
|
710 | + $data = wp_unslash($_POST); |
|
711 | 711 | $prepared = array(); |
712 | 712 | |
713 | 713 | // ... form fields... |
714 | - if ( empty( $data['form_id'] ) || 'publish' != get_post_status( $data['form_id'] ) ) { |
|
715 | - wp_send_json_error( __( 'This payment form is no longer active.', 'invoicing' ) ); |
|
714 | + if (empty($data['form_id']) || 'publish' != get_post_status($data['form_id'])) { |
|
715 | + wp_send_json_error(__('This payment form is no longer active.', 'invoicing')); |
|
716 | 716 | } |
717 | 717 | |
718 | - if ( empty( $data['billing_email'] ) || ! is_email( $data['billing_email'] ) ) { |
|
719 | - wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
|
718 | + if (empty($data['billing_email']) || !is_email($data['billing_email'])) { |
|
719 | + wp_send_json_error(__('Provide a valid billing email.', 'invoicing')); |
|
720 | 720 | } |
721 | 721 | |
722 | - $prepared['billing_email'] = sanitize_email( $data['billing_email'] ); |
|
722 | + $prepared['billing_email'] = sanitize_email($data['billing_email']); |
|
723 | 723 | |
724 | - $fields = $invoicing->form_elements->get_form_elements( $data['form_id'] ); |
|
724 | + $fields = $invoicing->form_elements->get_form_elements($data['form_id']); |
|
725 | 725 | |
726 | 726 | // ... and form items. |
727 | - $items = $invoicing->form_elements->get_form_items( $data['form_id'] ); |
|
727 | + $items = $invoicing->form_elements->get_form_items($data['form_id']); |
|
728 | 728 | $prepared_items = array(); |
729 | 729 | |
730 | - foreach( $items as $item ) { |
|
730 | + foreach ($items as $item) { |
|
731 | 731 | $prepared_items[] = array( |
732 | 732 | 'id' => $item['id'], |
733 | - 'item_price' => wpinv_sanitize_amount( $item['price'] ), |
|
734 | - 'custom_price' => wpinv_sanitize_amount( $item['price'] ), |
|
733 | + 'item_price' => wpinv_sanitize_amount($item['price']), |
|
734 | + 'custom_price' => wpinv_sanitize_amount($item['price']), |
|
735 | 735 | 'name' => $item['title'], |
736 | 736 | ); |
737 | 737 | } |
738 | 738 | |
739 | 739 | // Are all required fields provided? |
740 | - foreach ( $fields as $field ) { |
|
740 | + foreach ($fields as $field) { |
|
741 | 741 | |
742 | - if ( ! empty( $field['premade'] ) ) { |
|
742 | + if (!empty($field['premade'])) { |
|
743 | 743 | continue; |
744 | 744 | } |
745 | 745 | |
746 | - if ( ! empty( $field['required'] ) && empty( $data[ $field['id'] ] ) ) { |
|
747 | - wp_send_json_error( __( 'Some required fields have not been filled.', 'invoicing' ) ); |
|
746 | + if (!empty($field['required']) && empty($data[$field['id']])) { |
|
747 | + wp_send_json_error(__('Some required fields have not been filled.', 'invoicing')); |
|
748 | 748 | } |
749 | 749 | |
750 | - $prepared[ $field['id'] ] = wpinv_clean( $data[ $field['id'] ] ); |
|
750 | + $prepared[$field['id']] = wpinv_clean($data[$field['id']]); |
|
751 | 751 | } |
752 | 752 | |
753 | - $user = get_user_by( 'email', $prepared['billing_email'] ); |
|
753 | + $user = get_user_by('email', $prepared['billing_email']); |
|
754 | 754 | |
755 | - if ( empty( $user ) ) { |
|
756 | - $user = wpinv_create_user( $prepared['billing_email'] ); |
|
755 | + if (empty($user)) { |
|
756 | + $user = wpinv_create_user($prepared['billing_email']); |
|
757 | 757 | } |
758 | 758 | |
759 | - if ( is_wp_error( $user ) ) { |
|
760 | - wp_send_json_error( $user->get_error_message() ); |
|
759 | + if (is_wp_error($user)) { |
|
760 | + wp_send_json_error($user->get_error_message()); |
|
761 | 761 | } |
762 | 762 | |
763 | - if ( is_numeric( $user ) ) { |
|
764 | - $user = get_user_by( 'id', $user ); |
|
763 | + if (is_numeric($user)) { |
|
764 | + $user = get_user_by('id', $user); |
|
765 | 765 | } |
766 | 766 | |
767 | 767 | // Create the invoice. |
@@ -775,15 +775,15 @@ discard block |
||
775 | 775 | true |
776 | 776 | ); |
777 | 777 | |
778 | - if ( is_wp_error( $created ) ) { |
|
779 | - wp_send_json_error( $created->get_error_message() ); |
|
778 | + if (is_wp_error($created)) { |
|
779 | + wp_send_json_error($created->get_error_message()); |
|
780 | 780 | } |
781 | 781 | |
782 | - if ( empty( $created ) ) { |
|
783 | - wp_send_json_error( __( 'Could not create your invoice.', 'invoicing' ) ); |
|
782 | + if (empty($created)) { |
|
783 | + wp_send_json_error(__('Could not create your invoice.', 'invoicing')); |
|
784 | 784 | } |
785 | 785 | |
786 | - wp_send_json_success( $created->get_view_url( true ) ); |
|
786 | + wp_send_json_success($created->get_view_url(true)); |
|
787 | 787 | |
788 | 788 | } |
789 | 789 | |
@@ -795,53 +795,53 @@ discard block |
||
795 | 795 | public static function buy_items() { |
796 | 796 | $user_id = get_current_user_id(); |
797 | 797 | |
798 | - if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page |
|
799 | - wp_send_json( array( |
|
800 | - 'success' => wp_login_url( wp_get_referer() ) |
|
801 | - ) ); |
|
798 | + if (empty($user_id)) { // If not logged in then lets redirect to the login page |
|
799 | + wp_send_json(array( |
|
800 | + 'success' => wp_login_url(wp_get_referer()) |
|
801 | + )); |
|
802 | 802 | } else { |
803 | 803 | // Only check nonce if logged in as it could be cached when logged out. |
804 | - if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) { |
|
805 | - wp_send_json( array( |
|
806 | - 'error' => __( 'Security checks failed.', 'invoicing' ) |
|
807 | - ) ); |
|
804 | + if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) { |
|
805 | + wp_send_json(array( |
|
806 | + 'error' => __('Security checks failed.', 'invoicing') |
|
807 | + )); |
|
808 | 808 | wp_die(); |
809 | 809 | } |
810 | 810 | |
811 | 811 | // allow to set a custom price through post_id |
812 | 812 | $items = $_POST['items']; |
813 | - $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0; |
|
814 | - $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0; |
|
813 | + $related_post_id = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0; |
|
814 | + $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0; |
|
815 | 815 | |
816 | 816 | $cart_items = array(); |
817 | - if ( $items ) { |
|
818 | - $items = explode( ',', $items ); |
|
817 | + if ($items) { |
|
818 | + $items = explode(',', $items); |
|
819 | 819 | |
820 | - foreach( $items as $item ) { |
|
820 | + foreach ($items as $item) { |
|
821 | 821 | $item_id = $item; |
822 | 822 | $quantity = 1; |
823 | 823 | |
824 | - if ( strpos( $item, '|' ) !== false ) { |
|
825 | - $item_parts = explode( '|', $item ); |
|
824 | + if (strpos($item, '|') !== false) { |
|
825 | + $item_parts = explode('|', $item); |
|
826 | 826 | $item_id = $item_parts[0]; |
827 | 827 | $quantity = $item_parts[1]; |
828 | 828 | } |
829 | 829 | |
830 | - if ( $item_id && $quantity ) { |
|
830 | + if ($item_id && $quantity) { |
|
831 | 831 | $cart_items_arr = array( |
832 | - 'id' => (int)$item_id, |
|
833 | - 'quantity' => (int)$quantity |
|
832 | + 'id' => (int) $item_id, |
|
833 | + 'quantity' => (int) $quantity |
|
834 | 834 | ); |
835 | 835 | |
836 | 836 | // If there is a related post id then add it to meta |
837 | - if ( $related_post_id ) { |
|
837 | + if ($related_post_id) { |
|
838 | 838 | $cart_items_arr['meta'] = array( |
839 | 839 | 'post_id' => $related_post_id |
840 | 840 | ); |
841 | 841 | } |
842 | 842 | |
843 | 843 | // If there is a custom price then set it. |
844 | - if ( $custom_item_price ) { |
|
844 | + if ($custom_item_price) { |
|
845 | 845 | $cart_items_arr['custom_price'] = $custom_item_price; |
846 | 846 | } |
847 | 847 | |
@@ -857,37 +857,37 @@ discard block |
||
857 | 857 | * @param int $related_post_id The related post id if any. |
858 | 858 | * @since 1.0.0 |
859 | 859 | */ |
860 | - $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id ); |
|
860 | + $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id); |
|
861 | 861 | |
862 | 862 | // Make sure its not in the cart already, if it is then redirect to checkout. |
863 | 863 | $cart_invoice = wpinv_get_invoice_cart(); |
864 | 864 | |
865 | - if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) { |
|
866 | - wp_send_json( array( |
|
865 | + if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) { |
|
866 | + wp_send_json(array( |
|
867 | 867 | 'success' => $cart_invoice->get_checkout_payment_url() |
868 | - ) ); |
|
868 | + )); |
|
869 | 869 | wp_die(); |
870 | 870 | } |
871 | 871 | |
872 | 872 | // Check if user has invoice with same items waiting to be paid. |
873 | - $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' ); |
|
874 | - if ( !empty( $user_invoices ) ) { |
|
875 | - foreach( $user_invoices as $user_invoice ) { |
|
873 | + $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending'); |
|
874 | + if (!empty($user_invoices)) { |
|
875 | + foreach ($user_invoices as $user_invoice) { |
|
876 | 876 | $user_cart_details = array(); |
877 | - $invoice = wpinv_get_invoice( $user_invoice->ID ); |
|
877 | + $invoice = wpinv_get_invoice($user_invoice->ID); |
|
878 | 878 | $cart_details = $invoice->get_cart_details(); |
879 | 879 | |
880 | - if ( !empty( $cart_details ) ) { |
|
881 | - foreach ( $cart_details as $invoice_item ) { |
|
880 | + if (!empty($cart_details)) { |
|
881 | + foreach ($cart_details as $invoice_item) { |
|
882 | 882 | $ii_arr = array(); |
883 | - $ii_arr['id'] = (int)$invoice_item['id']; |
|
884 | - $ii_arr['quantity'] = (int)$invoice_item['quantity']; |
|
883 | + $ii_arr['id'] = (int) $invoice_item['id']; |
|
884 | + $ii_arr['quantity'] = (int) $invoice_item['quantity']; |
|
885 | 885 | |
886 | - if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) { |
|
886 | + if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) { |
|
887 | 887 | $ii_arr['meta'] = $invoice_item['meta']; |
888 | 888 | } |
889 | 889 | |
890 | - if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) { |
|
890 | + if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) { |
|
891 | 891 | $ii_arr['custom_price'] = $invoice_item['custom_price']; |
892 | 892 | } |
893 | 893 | |
@@ -895,17 +895,17 @@ discard block |
||
895 | 895 | } |
896 | 896 | } |
897 | 897 | |
898 | - if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) { |
|
899 | - wp_send_json( array( |
|
898 | + if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) { |
|
899 | + wp_send_json(array( |
|
900 | 900 | 'success' => $invoice->get_checkout_payment_url() |
901 | - ) ); |
|
901 | + )); |
|
902 | 902 | wp_die(); |
903 | 903 | } |
904 | 904 | } |
905 | 905 | } |
906 | 906 | |
907 | 907 | // Create invoice and send user to checkout |
908 | - if ( !empty( $cart_items ) ) { |
|
908 | + if (!empty($cart_items)) { |
|
909 | 909 | $invoice_data = array( |
910 | 910 | 'status' => 'wpi-pending', |
911 | 911 | 'created_via' => 'wpi', |
@@ -913,21 +913,21 @@ discard block |
||
913 | 913 | 'cart_details' => $cart_items, |
914 | 914 | ); |
915 | 915 | |
916 | - $invoice = wpinv_insert_invoice( $invoice_data, true ); |
|
916 | + $invoice = wpinv_insert_invoice($invoice_data, true); |
|
917 | 917 | |
918 | - if ( !empty( $invoice ) && isset( $invoice->ID ) ) { |
|
919 | - wp_send_json( array( |
|
918 | + if (!empty($invoice) && isset($invoice->ID)) { |
|
919 | + wp_send_json(array( |
|
920 | 920 | 'success' => $invoice->get_checkout_payment_url() |
921 | - ) ); |
|
921 | + )); |
|
922 | 922 | } else { |
923 | - wp_send_json( array( |
|
924 | - 'error' => __( 'Invoice failed to create', 'invoicing' ) |
|
925 | - ) ); |
|
923 | + wp_send_json(array( |
|
924 | + 'error' => __('Invoice failed to create', 'invoicing') |
|
925 | + )); |
|
926 | 926 | } |
927 | 927 | } else { |
928 | - wp_send_json( array( |
|
929 | - 'error' => __( 'Items not valid.', 'invoicing' ) |
|
930 | - ) ); |
|
928 | + wp_send_json(array( |
|
929 | + 'error' => __('Items not valid.', 'invoicing') |
|
930 | + )); |
|
931 | 931 | } |
932 | 932 | } |
933 | 933 |
@@ -1,22 +1,22 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -function wpinv_get_users_invoices( $user = 0, $number = 20, $pagination = false, $status = 'publish', $orderby = 'ID', $order = 'DESC' ) { |
|
6 | - if ( empty( $user ) ) { |
|
5 | +function wpinv_get_users_invoices($user = 0, $number = 20, $pagination = false, $status = 'publish', $orderby = 'ID', $order = 'DESC') { |
|
6 | + if (empty($user)) { |
|
7 | 7 | $user = get_current_user_id(); |
8 | 8 | } |
9 | 9 | |
10 | - if ( empty( $user ) ) { |
|
10 | + if (empty($user)) { |
|
11 | 11 | return false; |
12 | 12 | } |
13 | 13 | |
14 | - $args = apply_filters( 'wpinv_get_users_invoices_args', array( 'user' => $user, 'limit' => $number, 'status' => $status, 'paginate' => $pagination, 'orderby' => $orderby, 'order' => $order ) ); |
|
14 | + $args = apply_filters('wpinv_get_users_invoices_args', array('user' => $user, 'limit' => $number, 'status' => $status, 'paginate' => $pagination, 'orderby' => $orderby, 'order' => $order)); |
|
15 | 15 | |
16 | - return wpinv_get_invoices( $args ); |
|
16 | + return wpinv_get_invoices($args); |
|
17 | 17 | } |
18 | 18 | |
19 | -function wpinv_dropdown_users( $args = '' ) { |
|
19 | +function wpinv_dropdown_users($args = '') { |
|
20 | 20 | $defaults = array( |
21 | 21 | 'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '', |
22 | 22 | 'orderby' => 'display_name', 'order' => 'ASC', |
@@ -27,18 +27,18 @@ discard block |
||
27 | 27 | 'option_none_value' => -1 |
28 | 28 | ); |
29 | 29 | |
30 | - $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0; |
|
30 | + $defaults['selected'] = is_author() ? get_query_var('author') : 0; |
|
31 | 31 | |
32 | - $r = wp_parse_args( $args, $defaults ); |
|
32 | + $r = wp_parse_args($args, $defaults); |
|
33 | 33 | |
34 | - $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) ); |
|
34 | + $query_args = wp_array_slice_assoc($r, array('blog_id', 'include', 'exclude', 'orderby', 'order', 'who')); |
|
35 | 35 | |
36 | - $fields = array( 'ID', 'user_login', 'user_email' ); |
|
36 | + $fields = array('ID', 'user_login', 'user_email'); |
|
37 | 37 | |
38 | - $show = ! empty( $r['show'] ) ? $r['show'] : 'display_name'; |
|
39 | - if ( 'display_name_with_login' === $show ) { |
|
38 | + $show = !empty($r['show']) ? $r['show'] : 'display_name'; |
|
39 | + if ('display_name_with_login' === $show) { |
|
40 | 40 | $fields[] = 'display_name'; |
41 | - } else if ( 'display_name_with_email' === $show ) { |
|
41 | + } else if ('display_name_with_email' === $show) { |
|
42 | 42 | $fields[] = 'display_name'; |
43 | 43 | } else { |
44 | 44 | $fields[] = $show; |
@@ -50,99 +50,99 @@ discard block |
||
50 | 50 | $show_option_none = $r['show_option_none']; |
51 | 51 | $option_none_value = $r['option_none_value']; |
52 | 52 | |
53 | - $query_args = apply_filters( 'wpinv_dropdown_users_args', $query_args, $r ); |
|
53 | + $query_args = apply_filters('wpinv_dropdown_users_args', $query_args, $r); |
|
54 | 54 | |
55 | - $users = get_users( $query_args ); |
|
55 | + $users = get_users($query_args); |
|
56 | 56 | |
57 | 57 | $output = ''; |
58 | - if ( ! empty( $users ) && ( empty( $r['hide_if_only_one_author'] ) || count( $users ) > 1 ) ) { |
|
59 | - $name = esc_attr( $r['name'] ); |
|
60 | - if ( $r['multi'] && ! $r['id'] ) { |
|
58 | + if (!empty($users) && (empty($r['hide_if_only_one_author']) || count($users) > 1)) { |
|
59 | + $name = esc_attr($r['name']); |
|
60 | + if ($r['multi'] && !$r['id']) { |
|
61 | 61 | $id = ''; |
62 | 62 | } else { |
63 | - $id = $r['id'] ? " id='" . esc_attr( $r['id'] ) . "'" : " id='$name'"; |
|
63 | + $id = $r['id'] ? " id='" . esc_attr($r['id']) . "'" : " id='$name'"; |
|
64 | 64 | } |
65 | 65 | $output = "<select name='{$name}'{$id} class='" . $r['class'] . "'>\n"; |
66 | 66 | |
67 | - if ( $show_option_all ) { |
|
67 | + if ($show_option_all) { |
|
68 | 68 | $output .= "\t<option value='0'>$show_option_all</option>\n"; |
69 | 69 | } |
70 | 70 | |
71 | - if ( $show_option_none ) { |
|
72 | - $_selected = selected( $option_none_value, $r['selected'], false ); |
|
73 | - $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n"; |
|
71 | + if ($show_option_none) { |
|
72 | + $_selected = selected($option_none_value, $r['selected'], false); |
|
73 | + $output .= "\t<option value='" . esc_attr($option_none_value) . "'$_selected>$show_option_none</option>\n"; |
|
74 | 74 | } |
75 | 75 | |
76 | - if ( $r['include_selected'] && ( $r['selected'] > 0 ) ) { |
|
76 | + if ($r['include_selected'] && ($r['selected'] > 0)) { |
|
77 | 77 | $found_selected = false; |
78 | 78 | $r['selected'] = (int) $r['selected']; |
79 | - foreach ( (array) $users as $user ) { |
|
79 | + foreach ((array) $users as $user) { |
|
80 | 80 | $user->ID = (int) $user->ID; |
81 | - if ( $user->ID === $r['selected'] ) { |
|
81 | + if ($user->ID === $r['selected']) { |
|
82 | 82 | $found_selected = true; |
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
86 | - if ( ! $found_selected ) { |
|
87 | - $users[] = get_userdata( $r['selected'] ); |
|
86 | + if (!$found_selected) { |
|
87 | + $users[] = get_userdata($r['selected']); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
91 | - foreach ( (array) $users as $user ) { |
|
92 | - if ( 'display_name_with_login' === $show ) { |
|
91 | + foreach ((array) $users as $user) { |
|
92 | + if ('display_name_with_login' === $show) { |
|
93 | 93 | /* translators: 1: display name, 2: user_login */ |
94 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_login ); |
|
95 | - } elseif ( 'display_name_with_email' === $show ) { |
|
94 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_login); |
|
95 | + } elseif ('display_name_with_email' === $show) { |
|
96 | 96 | /* translators: 1: display name, 2: user_email */ |
97 | - if ( $user->display_name == $user->user_email ) { |
|
97 | + if ($user->display_name == $user->user_email) { |
|
98 | 98 | $display = $user->display_name; |
99 | 99 | } else { |
100 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_email ); |
|
100 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_email); |
|
101 | 101 | } |
102 | - } elseif ( ! empty( $user->$show ) ) { |
|
102 | + } elseif (!empty($user->$show)) { |
|
103 | 103 | $display = $user->$show; |
104 | 104 | } else { |
105 | 105 | $display = '(' . $user->user_login . ')'; |
106 | 106 | } |
107 | 107 | |
108 | - $_selected = selected( $user->ID, $r['selected'], false ); |
|
109 | - $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n"; |
|
108 | + $_selected = selected($user->ID, $r['selected'], false); |
|
109 | + $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n"; |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | $output .= "</select>"; |
113 | 113 | } |
114 | 114 | |
115 | - $html = apply_filters( 'wpinv_dropdown_users', $output ); |
|
115 | + $html = apply_filters('wpinv_dropdown_users', $output); |
|
116 | 116 | |
117 | - if ( $r['echo'] ) { |
|
117 | + if ($r['echo']) { |
|
118 | 118 | echo $html; |
119 | 119 | } |
120 | 120 | return $html; |
121 | 121 | } |
122 | 122 | |
123 | -function wpinv_guest_redirect( $redirect_to, $user_id = 0 ) { |
|
124 | - if ( (int)wpinv_get_option( 'guest_checkout' ) && $user_id > 0 ) { |
|
125 | - wpinv_login_user( $user_id ); |
|
123 | +function wpinv_guest_redirect($redirect_to, $user_id = 0) { |
|
124 | + if ((int) wpinv_get_option('guest_checkout') && $user_id > 0) { |
|
125 | + wpinv_login_user($user_id); |
|
126 | 126 | } else { |
127 | - $redirect_to = wp_login_url( $redirect_to ); |
|
127 | + $redirect_to = wp_login_url($redirect_to); |
|
128 | 128 | } |
129 | 129 | |
130 | - $redirect_to = apply_filters( 'wpinv_invoice_link_guest_redirect', $redirect_to, $user_id ); |
|
130 | + $redirect_to = apply_filters('wpinv_invoice_link_guest_redirect', $redirect_to, $user_id); |
|
131 | 131 | |
132 | - wp_redirect( $redirect_to ); |
|
132 | + wp_redirect($redirect_to); |
|
133 | 133 | } |
134 | 134 | |
135 | -function wpinv_login_user( $user_id ) { |
|
136 | - if ( is_user_logged_in() ) { |
|
135 | +function wpinv_login_user($user_id) { |
|
136 | + if (is_user_logged_in()) { |
|
137 | 137 | return true; |
138 | 138 | } |
139 | 139 | |
140 | - $user = get_user_by( 'id', $user_id ); |
|
140 | + $user = get_user_by('id', $user_id); |
|
141 | 141 | |
142 | - if ( !empty( $user ) && !is_wp_error( $user ) && !empty( $user->user_login ) ) { |
|
143 | - wp_set_current_user( $user_id, $user->user_login ); |
|
144 | - wp_set_auth_cookie( $user_id ); |
|
145 | - do_action( 'wp_login', $user->user_login ); |
|
142 | + if (!empty($user) && !is_wp_error($user) && !empty($user->user_login)) { |
|
143 | + wp_set_current_user($user_id, $user->user_login); |
|
144 | + wp_set_auth_cookie($user_id); |
|
145 | + do_action('wp_login', $user->user_login); |
|
146 | 146 | |
147 | 147 | return true; |
148 | 148 | } |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | * @return string capability to check against |
158 | 158 | * @param string $capalibilty Optional. The alternative capability to check against. |
159 | 159 | */ |
160 | -function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) { |
|
160 | +function wpinv_get_capability($capalibilty = 'manage_invoicing') { |
|
161 | 161 | |
162 | - if ( current_user_can( 'manage_options' ) ) { |
|
162 | + if (current_user_can('manage_options')) { |
|
163 | 163 | return 'manage_options'; |
164 | 164 | }; |
165 | 165 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | * @return bool |
174 | 174 | */ |
175 | 175 | function wpinv_current_user_can_manage_invoicing() { |
176 | - return current_user_can( wpinv_get_capability() ); |
|
176 | + return current_user_can(wpinv_get_capability()); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
@@ -182,17 +182,17 @@ discard block |
||
182 | 182 | * @since 1.0.19 |
183 | 183 | * @return int|WP_Error |
184 | 184 | */ |
185 | -function wpinv_create_user( $email ) { |
|
185 | +function wpinv_create_user($email) { |
|
186 | 186 | |
187 | 187 | // Prepare user values. |
188 | 188 | $args = array( |
189 | - 'user_login' => wpinv_generate_user_name( $email ), |
|
189 | + 'user_login' => wpinv_generate_user_name($email), |
|
190 | 190 | 'user_pass' => wp_generate_password(), |
191 | 191 | 'user_email' => $email, |
192 | 192 | 'role' => 'subscriber', |
193 | 193 | ); |
194 | 194 | |
195 | - return wp_insert_user( $args ); |
|
195 | + return wp_insert_user($args); |
|
196 | 196 | |
197 | 197 | } |
198 | 198 | |
@@ -202,22 +202,22 @@ discard block |
||
202 | 202 | * @since 1.0.19 |
203 | 203 | * @return bool|WP_User |
204 | 204 | */ |
205 | -function wpinv_generate_user_name( $prefix = '' ) { |
|
205 | +function wpinv_generate_user_name($prefix = '') { |
|
206 | 206 | |
207 | 207 | // If prefix is an email, retrieve the part before the email. |
208 | - $prefix = strtok( $prefix, '@' ); |
|
208 | + $prefix = strtok($prefix, '@'); |
|
209 | 209 | |
210 | 210 | // Trim to 4 characters max. |
211 | - $prefix = sanitize_user( substr( $prefix, 0, 4 ) ); |
|
211 | + $prefix = sanitize_user(substr($prefix, 0, 4)); |
|
212 | 212 | |
213 | - $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
214 | - if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
|
213 | + $illegal_logins = (array) apply_filters('illegal_user_logins', array()); |
|
214 | + if (empty($prefix) || in_array(strtolower($prefix), array_map('strtolower', $illegal_logins), true)) { |
|
215 | 215 | $prefix = 'paywp'; |
216 | 216 | } |
217 | 217 | |
218 | - $username = $prefix . '_' . zeroise( wp_rand( 0, 9999 ), 4 ); |
|
219 | - if ( username_exists( $username ) ) { |
|
220 | - return wpinv_generate_user_name( $prefix ); |
|
218 | + $username = $prefix . '_' . zeroise(wp_rand(0, 9999), 4); |
|
219 | + if (username_exists($username)) { |
|
220 | + return wpinv_generate_user_name($prefix); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | } |