@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | <?php |
45 | 45 | |
46 | 46 | if ( wpinv_is_gateway_active( $id ) ) { |
47 | - echo "<i class='text-success fa fa-check'></i>"; |
|
47 | + echo "<i class='text-success fa fa-check'></i>"; |
|
48 | 48 | } else { |
49 | - echo "<i class='text-dark fa fa-times'></i>"; |
|
49 | + echo "<i class='text-dark fa fa-times'></i>"; |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | ?> |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | $supports = apply_filters( 'getapid_gateway_supports_subscription', $supports, $id ); |
59 | 59 | |
60 | 60 | if ( $supports ) { |
61 | - echo "<i class='text-success fa fa-check'></i>"; |
|
61 | + echo "<i class='text-success fa fa-check'></i>"; |
|
62 | 62 | } else { |
63 | - echo "<i class='text-dark fa fa-times'></i>"; |
|
63 | + echo "<i class='text-dark fa fa-times'></i>"; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | ?> |
@@ -27,7 +27,7 @@ |
||
27 | 27 | <input type="checkbox" name="plugins[<?php echo esc_attr( $plugin['slug'] ); ?>]" value="<?php echo esc_attr( $plugin['file'] ); ?>" class="custom-control-input" |
28 | 28 | <?php |
29 | 29 | if ( is_plugin_active( $plugin['slug'] ) ) { |
30 | - echo 'checked';} |
|
30 | + echo 'checked';} |
|
31 | 31 | ?> |
32 | 32 | > |
33 | 33 | <label class="custom-control-label" for="ac-setting-updates"></label> |
@@ -12,273 +12,273 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Metaboxes { |
14 | 14 | |
15 | - /** |
|
16 | - * Only save metaboxes once. |
|
17 | - * |
|
18 | - * @var boolean |
|
19 | - */ |
|
20 | - private static $saved_meta_boxes = false; |
|
15 | + /** |
|
16 | + * Only save metaboxes once. |
|
17 | + * |
|
18 | + * @var boolean |
|
19 | + */ |
|
20 | + private static $saved_meta_boxes = false; |
|
21 | 21 | |
22 | 22 | /** |
23 | - * Hook in methods. |
|
24 | - */ |
|
25 | - public static function init() { |
|
23 | + * Hook in methods. |
|
24 | + */ |
|
25 | + public static function init() { |
|
26 | 26 | |
27 | - // Register metaboxes. |
|
28 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
27 | + // Register metaboxes. |
|
28 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
29 | 29 | |
30 | - // Remove metaboxes. |
|
31 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
30 | + // Remove metaboxes. |
|
31 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
32 | 32 | |
33 | - // Rename metaboxes. |
|
34 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
33 | + // Rename metaboxes. |
|
34 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
35 | 35 | |
36 | - // Save metaboxes. |
|
37 | - add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
38 | - } |
|
36 | + // Save metaboxes. |
|
37 | + add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Register core metaboxes. |
|
42 | - */ |
|
43 | - public static function add_meta_boxes( $post_type, $post ) { |
|
40 | + /** |
|
41 | + * Register core metaboxes. |
|
42 | + */ |
|
43 | + public static function add_meta_boxes( $post_type, $post ) { |
|
44 | 44 | |
45 | - // For invoices... |
|
46 | - self::add_invoice_meta_boxes( $post_type, $post ); |
|
45 | + // For invoices... |
|
46 | + self::add_invoice_meta_boxes( $post_type, $post ); |
|
47 | 47 | |
48 | - // For payment forms. |
|
49 | - self::add_payment_form_meta_boxes( $post_type, $post ); |
|
48 | + // For payment forms. |
|
49 | + self::add_payment_form_meta_boxes( $post_type, $post ); |
|
50 | 50 | |
51 | - // For invoice items. |
|
52 | - self::add_item_meta_boxes( $post_type ); |
|
51 | + // For invoice items. |
|
52 | + self::add_item_meta_boxes( $post_type ); |
|
53 | 53 | |
54 | - // For invoice discounts. |
|
55 | - if ( $post_type == 'wpi_discount' ) { |
|
56 | - add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
57 | - } |
|
54 | + // For invoice discounts. |
|
55 | + if ( $post_type == 'wpi_discount' ) { |
|
56 | + add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
57 | + } |
|
58 | 58 | |
59 | - } |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Register core metaboxes. |
|
63 | - */ |
|
64 | - protected static function add_payment_form_meta_boxes( $post_type, $post ) { |
|
61 | + /** |
|
62 | + * Register core metaboxes. |
|
63 | + */ |
|
64 | + protected static function add_payment_form_meta_boxes( $post_type, $post ) { |
|
65 | 65 | |
66 | - // For payment forms. |
|
67 | - if ( $post_type == 'wpi_payment_form' ) { |
|
66 | + // For payment forms. |
|
67 | + if ( $post_type == 'wpi_payment_form' ) { |
|
68 | 68 | |
69 | - // Design payment form. |
|
70 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
69 | + // Design payment form. |
|
70 | + add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
71 | 71 | |
72 | - // Payment form information. |
|
73 | - if ( $post->ID != wpinv_get_default_payment_form() ) { |
|
74 | - add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
75 | - } |
|
72 | + // Payment form information. |
|
73 | + if ( $post->ID != wpinv_get_default_payment_form() ) { |
|
74 | + add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
75 | + } |
|
76 | 76 | } |
77 | 77 | |
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Register core metaboxes. |
|
82 | - */ |
|
83 | - protected static function add_item_meta_boxes( $post_type ) { |
|
78 | + } |
|
84 | 79 | |
85 | - if ( $post_type == 'wpi_item' ) { |
|
86 | - |
|
87 | - // Item details. |
|
88 | - add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
89 | - |
|
90 | - // If taxes are enabled, register the tax metabox. |
|
91 | - if ( wpinv_use_taxes() ) { |
|
92 | - add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
93 | - } |
|
80 | + /** |
|
81 | + * Register core metaboxes. |
|
82 | + */ |
|
83 | + protected static function add_item_meta_boxes( $post_type ) { |
|
94 | 84 | |
95 | - // Item info. |
|
96 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
85 | + if ( $post_type == 'wpi_item' ) { |
|
97 | 86 | |
98 | - } |
|
87 | + // Item details. |
|
88 | + add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
99 | 89 | |
100 | - } |
|
90 | + // If taxes are enabled, register the tax metabox. |
|
91 | + if ( wpinv_use_taxes() ) { |
|
92 | + add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
93 | + } |
|
101 | 94 | |
102 | - /** |
|
103 | - * Register invoice metaboxes. |
|
104 | - */ |
|
105 | - protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
95 | + // Item info. |
|
96 | + add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
106 | 97 | |
107 | - // For invoices... |
|
108 | - if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
109 | - $invoice = new WPInv_Invoice( $post ); |
|
98 | + } |
|
110 | 99 | |
111 | - // Resend invoice. |
|
112 | - if ( ! $invoice->is_draft() ) { |
|
100 | + } |
|
113 | 101 | |
114 | - add_meta_box( |
|
115 | - 'wpinv-mb-resend-invoice', |
|
116 | - sprintf( |
|
117 | - __( 'Resend %s', 'invoicing' ), |
|
118 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
119 | - ), |
|
120 | - 'GetPaid_Meta_Box_Resend_Invoice::output', |
|
121 | - $post_type, |
|
122 | - 'side', |
|
123 | - 'low' |
|
124 | - ); |
|
102 | + /** |
|
103 | + * Register invoice metaboxes. |
|
104 | + */ |
|
105 | + protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
106 | + |
|
107 | + // For invoices... |
|
108 | + if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
109 | + $invoice = new WPInv_Invoice( $post ); |
|
110 | + |
|
111 | + // Resend invoice. |
|
112 | + if ( ! $invoice->is_draft() ) { |
|
113 | + |
|
114 | + add_meta_box( |
|
115 | + 'wpinv-mb-resend-invoice', |
|
116 | + sprintf( |
|
117 | + __( 'Resend %s', 'invoicing' ), |
|
118 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
119 | + ), |
|
120 | + 'GetPaid_Meta_Box_Resend_Invoice::output', |
|
121 | + $post_type, |
|
122 | + 'side', |
|
123 | + 'low' |
|
124 | + ); |
|
125 | + |
|
126 | + } |
|
127 | + |
|
128 | + // Subscriptions. |
|
129 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
130 | + if ( ! empty( $subscriptions ) ) { |
|
131 | + |
|
132 | + if ( is_array( $subscriptions ) ) { |
|
133 | + add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
134 | + } else { |
|
135 | + add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
136 | + } |
|
137 | + |
|
138 | + if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
139 | + add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
140 | + } |
|
141 | +} |
|
125 | 142 | |
126 | - } |
|
143 | + // Invoice details. |
|
144 | + add_meta_box( |
|
145 | + 'wpinv-details', |
|
146 | + sprintf( |
|
147 | + __( '%s Details', 'invoicing' ), |
|
148 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
149 | + ), |
|
150 | + 'GetPaid_Meta_Box_Invoice_Details::output', |
|
151 | + $post_type, |
|
152 | + 'side' |
|
153 | + ); |
|
154 | + |
|
155 | + // Payment details. |
|
156 | + add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
157 | + |
|
158 | + // Billing details. |
|
159 | + add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
160 | + |
|
161 | + // Invoice items. |
|
162 | + add_meta_box( |
|
163 | + 'wpinv-items', |
|
164 | + sprintf( |
|
165 | + __( '%s Items', 'invoicing' ), |
|
166 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
167 | + ), |
|
168 | + 'GetPaid_Meta_Box_Invoice_Items::output', |
|
169 | + $post_type, |
|
170 | + 'normal', |
|
171 | + 'high' |
|
172 | + ); |
|
173 | + |
|
174 | + // Invoice notes. |
|
175 | + add_meta_box( |
|
176 | + 'wpinv-notes', |
|
177 | + sprintf( |
|
178 | + __( '%s Notes', 'invoicing' ), |
|
179 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
180 | + ), |
|
181 | + 'WPInv_Meta_Box_Notes::output', |
|
182 | + $post_type, |
|
183 | + 'side', |
|
184 | + 'low' |
|
185 | + ); |
|
186 | + |
|
187 | + // Shipping Address. |
|
188 | + if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
189 | + add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
190 | + } |
|
191 | + |
|
192 | + // Payment form information. |
|
193 | + if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
194 | + add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
195 | + } |
|
196 | +} |
|
127 | 197 | |
128 | - // Subscriptions. |
|
129 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
130 | - if ( ! empty( $subscriptions ) ) { |
|
198 | + } |
|
131 | 199 | |
132 | - if ( is_array( $subscriptions ) ) { |
|
133 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
134 | - } else { |
|
135 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
136 | - } |
|
200 | + /** |
|
201 | + * Remove some metaboxes. |
|
202 | + */ |
|
203 | + public static function remove_meta_boxes() { |
|
204 | + remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
205 | + } |
|
137 | 206 | |
138 | - if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
139 | - add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
140 | - } |
|
141 | -} |
|
207 | + /** |
|
208 | + * Rename other metaboxes. |
|
209 | + */ |
|
210 | + public static function rename_meta_boxes() { |
|
142 | 211 | |
143 | - // Invoice details. |
|
144 | - add_meta_box( |
|
145 | - 'wpinv-details', |
|
146 | - sprintf( |
|
147 | - __( '%s Details', 'invoicing' ), |
|
148 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
149 | - ), |
|
150 | - 'GetPaid_Meta_Box_Invoice_Details::output', |
|
151 | - $post_type, |
|
152 | - 'side' |
|
153 | - ); |
|
154 | - |
|
155 | - // Payment details. |
|
156 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
157 | - |
|
158 | - // Billing details. |
|
159 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
160 | - |
|
161 | - // Invoice items. |
|
162 | - add_meta_box( |
|
163 | - 'wpinv-items', |
|
164 | - sprintf( |
|
165 | - __( '%s Items', 'invoicing' ), |
|
166 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
167 | - ), |
|
168 | - 'GetPaid_Meta_Box_Invoice_Items::output', |
|
169 | - $post_type, |
|
170 | - 'normal', |
|
171 | - 'high' |
|
172 | - ); |
|
173 | - |
|
174 | - // Invoice notes. |
|
175 | - add_meta_box( |
|
176 | - 'wpinv-notes', |
|
177 | - sprintf( |
|
178 | - __( '%s Notes', 'invoicing' ), |
|
179 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
180 | - ), |
|
181 | - 'WPInv_Meta_Box_Notes::output', |
|
182 | - $post_type, |
|
183 | - 'side', |
|
184 | - 'low' |
|
185 | - ); |
|
186 | - |
|
187 | - // Shipping Address. |
|
188 | - if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
189 | - add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
190 | - } |
|
191 | - |
|
192 | - // Payment form information. |
|
193 | - if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
194 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
195 | - } |
|
196 | -} |
|
212 | + } |
|
197 | 213 | |
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * Remove some metaboxes. |
|
202 | - */ |
|
203 | - public static function remove_meta_boxes() { |
|
204 | - remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Rename other metaboxes. |
|
209 | - */ |
|
210 | - public static function rename_meta_boxes() { |
|
211 | - |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * Check if we're saving, then trigger an action based on the post type. |
|
216 | - * |
|
217 | - * @param int $post_id Post ID. |
|
218 | - * @param object $post Post object. |
|
219 | - */ |
|
220 | - public static function save_meta_boxes( $post_id, $post ) { |
|
221 | - $post_id = absint( $post_id ); |
|
222 | - $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
223 | - |
|
224 | - // Do not save for ajax requests. |
|
225 | - if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
226 | - return; |
|
227 | - } |
|
228 | - |
|
229 | - // $post_id and $post are required |
|
230 | - if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
231 | - return; |
|
232 | - } |
|
233 | - |
|
234 | - // Dont' save meta boxes for revisions or autosaves. |
|
235 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
236 | - return; |
|
237 | - } |
|
238 | - |
|
239 | - // Check the nonce. |
|
240 | - if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
241 | - return; |
|
242 | - } |
|
243 | - |
|
244 | - // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
245 | - if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
246 | - return; |
|
247 | - } |
|
248 | - |
|
249 | - // Check user has permission to edit. |
|
250 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
251 | - return; |
|
252 | - } |
|
253 | - |
|
254 | - if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
255 | - |
|
256 | - // We need this save event to run once to avoid potential endless loops. |
|
257 | - self::$saved_meta_boxes = true; |
|
258 | - |
|
259 | - return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
260 | - |
|
261 | - } |
|
262 | - |
|
263 | - // Ensure this is our post type. |
|
264 | - $post_types_map = array( |
|
265 | - 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
266 | - 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
267 | - 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
268 | - ); |
|
269 | - |
|
270 | - // Is this our post type? |
|
271 | - if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
272 | - return; |
|
273 | - } |
|
274 | - |
|
275 | - // We need this save event to run once to avoid potential endless loops. |
|
276 | - self::$saved_meta_boxes = true; |
|
277 | - |
|
278 | - // Save the post. |
|
279 | - $class = $post_types_map[ $post->post_type ]; |
|
280 | - $class::save( $post_id, wp_kses_post_deep( $_POST ), $post ); |
|
281 | - |
|
282 | - } |
|
214 | + /** |
|
215 | + * Check if we're saving, then trigger an action based on the post type. |
|
216 | + * |
|
217 | + * @param int $post_id Post ID. |
|
218 | + * @param object $post Post object. |
|
219 | + */ |
|
220 | + public static function save_meta_boxes( $post_id, $post ) { |
|
221 | + $post_id = absint( $post_id ); |
|
222 | + $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
223 | + |
|
224 | + // Do not save for ajax requests. |
|
225 | + if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
226 | + return; |
|
227 | + } |
|
228 | + |
|
229 | + // $post_id and $post are required |
|
230 | + if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
231 | + return; |
|
232 | + } |
|
233 | + |
|
234 | + // Dont' save meta boxes for revisions or autosaves. |
|
235 | + if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
236 | + return; |
|
237 | + } |
|
238 | + |
|
239 | + // Check the nonce. |
|
240 | + if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
241 | + return; |
|
242 | + } |
|
243 | + |
|
244 | + // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
245 | + if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
246 | + return; |
|
247 | + } |
|
248 | + |
|
249 | + // Check user has permission to edit. |
|
250 | + if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
251 | + return; |
|
252 | + } |
|
253 | + |
|
254 | + if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
255 | + |
|
256 | + // We need this save event to run once to avoid potential endless loops. |
|
257 | + self::$saved_meta_boxes = true; |
|
258 | + |
|
259 | + return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
260 | + |
|
261 | + } |
|
262 | + |
|
263 | + // Ensure this is our post type. |
|
264 | + $post_types_map = array( |
|
265 | + 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
266 | + 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
267 | + 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
268 | + ); |
|
269 | + |
|
270 | + // Is this our post type? |
|
271 | + if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
272 | + return; |
|
273 | + } |
|
274 | + |
|
275 | + // We need this save event to run once to avoid potential endless loops. |
|
276 | + self::$saved_meta_boxes = true; |
|
277 | + |
|
278 | + // Save the post. |
|
279 | + $class = $post_types_map[ $post->post_type ]; |
|
280 | + $class::save( $post_id, wp_kses_post_deep( $_POST ), $post ); |
|
281 | + |
|
282 | + } |
|
283 | 283 | |
284 | 284 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
10 | - exit; // Exit if accessed directly |
|
10 | + exit; // Exit if accessed directly |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -15,22 +15,22 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Meta_Box_Invoice_Shipping_Address { |
17 | 17 | |
18 | - /** |
|
19 | - * Output the metabox. |
|
20 | - * |
|
21 | - * @param WP_Post $post |
|
22 | - */ |
|
23 | - public static function output( $post ) { |
|
18 | + /** |
|
19 | + * Output the metabox. |
|
20 | + * |
|
21 | + * @param WP_Post $post |
|
22 | + */ |
|
23 | + public static function output( $post ) { |
|
24 | 24 | |
25 | - // Retrieve shipping address. |
|
26 | - $shipping_address = get_post_meta( $post->ID, 'shipping_address', true ); |
|
25 | + // Retrieve shipping address. |
|
26 | + $shipping_address = get_post_meta( $post->ID, 'shipping_address', true ); |
|
27 | 27 | |
28 | - // Abort if it is invalid. |
|
29 | - if ( ! is_array( $shipping_address ) ) { |
|
30 | - return; |
|
31 | - } |
|
28 | + // Abort if it is invalid. |
|
29 | + if ( ! is_array( $shipping_address ) ) { |
|
30 | + return; |
|
31 | + } |
|
32 | 32 | |
33 | - ?> |
|
33 | + ?> |
|
34 | 34 | |
35 | 35 | <div class="bsui"> |
36 | 36 | |
@@ -68,31 +68,31 @@ discard block |
||
68 | 68 | |
69 | 69 | <?php |
70 | 70 | |
71 | - } |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Prepares a value. |
|
75 | - * |
|
76 | - * @param array $address |
|
77 | - * @param string $key |
|
78 | - * @return string |
|
79 | - */ |
|
80 | - public static function prepare_for_display( $address, $key ) { |
|
73 | + /** |
|
74 | + * Prepares a value. |
|
75 | + * |
|
76 | + * @param array $address |
|
77 | + * @param string $key |
|
78 | + * @return string |
|
79 | + */ |
|
80 | + public static function prepare_for_display( $address, $key ) { |
|
81 | 81 | |
82 | - // Prepare the value. |
|
83 | - $value = $address[ $key ]; |
|
82 | + // Prepare the value. |
|
83 | + $value = $address[ $key ]; |
|
84 | 84 | |
85 | - if ( $key == 'country' ) { |
|
86 | - $value = wpinv_country_name( $value ); |
|
87 | - } |
|
85 | + if ( $key == 'country' ) { |
|
86 | + $value = wpinv_country_name( $value ); |
|
87 | + } |
|
88 | 88 | |
89 | - if ( $key == 'state' ) { |
|
90 | - $country = isset( $address['country'] ) ? $address['country'] : wpinv_get_default_country(); |
|
91 | - $value = wpinv_state_name( $value, $country ); |
|
92 | - } |
|
89 | + if ( $key == 'state' ) { |
|
90 | + $country = isset( $address['country'] ) ? $address['country'] : wpinv_get_default_country(); |
|
91 | + $value = wpinv_state_name( $value, $country ); |
|
92 | + } |
|
93 | 93 | |
94 | - return esc_html( $value ); |
|
94 | + return esc_html( $value ); |
|
95 | 95 | |
96 | - } |
|
96 | + } |
|
97 | 97 | |
98 | 98 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | class GetPaid_Meta_Box_Discount_Details { |
18 | 18 | |
19 | 19 | /** |
20 | - * Output the metabox. |
|
21 | - * |
|
22 | - * @param WP_Post $post |
|
23 | - */ |
|
20 | + * Output the metabox. |
|
21 | + * |
|
22 | + * @param WP_Post $post |
|
23 | + */ |
|
24 | 24 | public static function output( $post ) { |
25 | 25 | |
26 | 26 | // Prepare the discount. |
@@ -396,35 +396,35 @@ discard block |
||
396 | 396 | } |
397 | 397 | |
398 | 398 | /** |
399 | - * Save meta box data. |
|
400 | - * |
|
401 | - * @param int $post_id |
|
402 | - */ |
|
403 | - public static function save( $post_id ) { |
|
399 | + * Save meta box data. |
|
400 | + * |
|
401 | + * @param int $post_id |
|
402 | + */ |
|
403 | + public static function save( $post_id ) { |
|
404 | 404 | |
405 | 405 | // Prepare the discount. |
406 | 406 | $discount = new WPInv_Discount( $post_id ); |
407 | 407 | |
408 | 408 | // Load new data. |
409 | 409 | $discount->set_props( |
410 | - array( |
|
411 | - 'code' => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null, |
|
412 | - 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null, |
|
413 | - 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
414 | - 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
415 | - 'is_single_use' => ! empty( $_POST['wpinv_discount_single_use'] ), |
|
410 | + array( |
|
411 | + 'code' => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null, |
|
412 | + 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null, |
|
413 | + 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
414 | + 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
415 | + 'is_single_use' => ! empty( $_POST['wpinv_discount_single_use'] ), |
|
416 | 416 | 'type' => isset( $_POST['wpinv_discount_type'] ) ? wpinv_clean( $_POST['wpinv_discount_type'] ) : null, |
417 | - 'is_recurring' => ! empty( $_POST['wpinv_discount_recurring'] ), |
|
418 | - 'items' => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(), |
|
419 | - 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(), |
|
417 | + 'is_recurring' => ! empty( $_POST['wpinv_discount_recurring'] ), |
|
418 | + 'items' => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(), |
|
419 | + 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(), |
|
420 | 420 | 'required_items' => isset( $_POST['wpinv_discount_required_items'] ) ? wpinv_clean( $_POST['wpinv_discount_required_items'] ) : array(), |
421 | - 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null, |
|
422 | - 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null, |
|
423 | - 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null, |
|
424 | - ) |
|
421 | + 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null, |
|
422 | + 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null, |
|
423 | + 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null, |
|
424 | + ) |
|
425 | 425 | ); |
426 | 426 | |
427 | - $discount->save(); |
|
428 | - do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
429 | - } |
|
427 | + $discount->save(); |
|
428 | + do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
429 | + } |
|
430 | 430 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | // Load WP_List_Table if not loaded |
13 | 13 | if ( ! class_exists( 'WP_List_Table' ) ) { |
14 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
14 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | /** |
@@ -23,369 +23,369 @@ discard block |
||
23 | 23 | */ |
24 | 24 | class WPInv_Customers_Table extends WP_List_Table { |
25 | 25 | |
26 | - /** |
|
27 | - * @var int Number of items per page |
|
28 | - * @since 1.0.19 |
|
29 | - */ |
|
30 | - public $per_page = 10; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var int Number of items |
|
34 | - * @since 1.0.19 |
|
35 | - */ |
|
36 | - public $total = 0; |
|
37 | - |
|
38 | - /** |
|
39 | - * Get things started |
|
40 | - * |
|
41 | - * @since 1.0.19 |
|
42 | - * @see WP_List_Table::__construct() |
|
43 | - */ |
|
44 | - public function __construct() { |
|
45 | - |
|
46 | - // Set parent defaults |
|
47 | - parent::__construct( |
|
26 | + /** |
|
27 | + * @var int Number of items per page |
|
28 | + * @since 1.0.19 |
|
29 | + */ |
|
30 | + public $per_page = 10; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var int Number of items |
|
34 | + * @since 1.0.19 |
|
35 | + */ |
|
36 | + public $total = 0; |
|
37 | + |
|
38 | + /** |
|
39 | + * Get things started |
|
40 | + * |
|
41 | + * @since 1.0.19 |
|
42 | + * @see WP_List_Table::__construct() |
|
43 | + */ |
|
44 | + public function __construct() { |
|
45 | + |
|
46 | + // Set parent defaults |
|
47 | + parent::__construct( |
|
48 | 48 | array( |
49 | - 'singular' => 'id', |
|
50 | - 'plural' => 'ids', |
|
51 | - 'ajax' => false, |
|
49 | + 'singular' => 'id', |
|
50 | + 'plural' => 'ids', |
|
51 | + 'ajax' => false, |
|
52 | 52 | ) |
53 | 53 | ); |
54 | 54 | |
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Gets the name of the primary column. |
|
59 | - * |
|
60 | - * @since 1.0.19 |
|
61 | - * @access protected |
|
62 | - * |
|
63 | - * @return string Name of the primary column. |
|
64 | - */ |
|
65 | - protected function get_primary_column_name() { |
|
66 | - return 'name'; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * This function renders most of the columns in the list table. |
|
71 | - * |
|
72 | - * @since 1.0.19 |
|
73 | - * |
|
74 | - * @param WP_User $item |
|
75 | - * @param string $column_name The name of the column |
|
76 | - * |
|
77 | - * @return string Column Name |
|
78 | - */ |
|
79 | - public function column_default( $item, $column_name ) { |
|
80 | - $value = esc_html( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) ); |
|
81 | - return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item ); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Displays the country column. |
|
86 | - * |
|
87 | - * @since 1.0.19 |
|
88 | - * |
|
89 | - * @param WP_User $user |
|
90 | - * |
|
91 | - * @return string Column Name |
|
92 | - */ |
|
93 | - public function column_country( $user ) { |
|
94 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
95 | - if ( $country ) { |
|
96 | - $country = wpinv_country_name( $country ); |
|
97 | - } |
|
98 | - return esc_html( $country ); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Displays the state column. |
|
103 | - * |
|
104 | - * @since 1.0.19 |
|
105 | - * |
|
106 | - * @param WP_User $user |
|
107 | - * |
|
108 | - * @return string Column Name |
|
109 | - */ |
|
110 | - public function column_state( $user ) { |
|
111 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
112 | - $state = $user->_wpinv_state; |
|
113 | - if ( $state ) { |
|
114 | - $state = wpinv_state_name( $state, $country ); |
|
115 | - } |
|
116 | - |
|
117 | - return esc_html( $state ); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Displays the signup column. |
|
122 | - * |
|
123 | - * @since 1.0.19 |
|
124 | - * |
|
125 | - * @param WP_User $user |
|
126 | - * |
|
127 | - * @return string Column Name |
|
128 | - */ |
|
129 | - public function column_signup( $user ) { |
|
130 | - return getpaid_format_date_value( $user->user_registered ); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Displays the total spent column. |
|
135 | - * |
|
136 | - * @since 1.0.19 |
|
137 | - * |
|
138 | - * @param WP_User $user |
|
139 | - * |
|
140 | - * @return string Column Name |
|
141 | - */ |
|
142 | - public function column_total( $user ) { |
|
143 | - return wpinv_price( $this->column_total_raw( $user ) ); |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Displays the total spent column. |
|
148 | - * |
|
149 | - * @since 1.0.19 |
|
150 | - * |
|
151 | - * @param WP_User $user |
|
152 | - * |
|
153 | - * @return float |
|
154 | - */ |
|
155 | - public function column_total_raw( $user ) { |
|
156 | - |
|
157 | - $args = array( |
|
158 | - 'data' => array( |
|
159 | - |
|
160 | - 'total' => array( |
|
161 | - 'type' => 'invoice_data', |
|
162 | - 'function' => 'SUM', |
|
163 | - 'name' => 'total_sales', |
|
164 | - ), |
|
165 | - |
|
166 | - ), |
|
167 | - 'where' => array( |
|
168 | - |
|
169 | - 'author' => array( |
|
170 | - 'type' => 'post_data', |
|
171 | - 'value' => absint( $user->ID ), |
|
172 | - 'key' => 'posts.post_author', |
|
173 | - 'operator' => '=', |
|
174 | - ), |
|
175 | - |
|
176 | - ), |
|
177 | - 'query_type' => 'get_var', |
|
178 | - 'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ), |
|
179 | - ); |
|
180 | - |
|
181 | - return wpinv_round_amount( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
182 | - |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Displays the total spent column. |
|
187 | - * |
|
188 | - * @since 1.0.19 |
|
189 | - * |
|
190 | - * @param WP_User $user |
|
191 | - * |
|
192 | - * @return string Column Name |
|
193 | - */ |
|
194 | - public function column_invoices( $user ) { |
|
195 | - |
|
196 | - $args = array( |
|
197 | - 'data' => array( |
|
198 | - |
|
199 | - 'ID' => array( |
|
200 | - 'type' => 'post_data', |
|
201 | - 'function' => 'COUNT', |
|
202 | - 'name' => 'count', |
|
203 | - 'distinct' => true, |
|
204 | - ), |
|
205 | - |
|
206 | - ), |
|
207 | - 'where' => array( |
|
208 | - |
|
209 | - 'author' => array( |
|
210 | - 'type' => 'post_data', |
|
211 | - 'value' => absint( $user->ID ), |
|
212 | - 'key' => 'posts.post_author', |
|
213 | - 'operator' => '=', |
|
214 | - ), |
|
215 | - |
|
216 | - ), |
|
217 | - 'query_type' => 'get_var', |
|
218 | - 'invoice_status' => array_keys( wpinv_get_invoice_statuses() ), |
|
219 | - ); |
|
220 | - |
|
221 | - return absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
222 | - |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Generates content for a single row of the table |
|
227 | - * @since 1.0.19 |
|
228 | - * |
|
229 | - * @param int $item The user id. |
|
230 | - */ |
|
231 | - public function single_row( $item ) { |
|
232 | - $item = get_user_by( 'id', $item ); |
|
233 | - |
|
234 | - if ( empty( $item ) ) { |
|
235 | - return; |
|
236 | - } |
|
237 | - |
|
238 | - echo '<tr>'; |
|
239 | - $this->single_row_columns( $item ); |
|
240 | - echo '</tr>'; |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * Displays the customers name |
|
245 | - * |
|
246 | - * @param WP_User $customer customer. |
|
247 | - * @return string |
|
248 | - */ |
|
249 | - public function column_name( $customer ) { |
|
250 | - |
|
251 | - // Customer view URL. |
|
252 | - $view_url = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) ); |
|
253 | - $row_actions = $this->row_actions( |
|
254 | - array( |
|
255 | - 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>', |
|
256 | - ) |
|
257 | - ); |
|
258 | - |
|
259 | - // Get user's address. |
|
260 | - $address = wpinv_get_user_address( $customer->ID ); |
|
261 | - |
|
262 | - // Customer email address. |
|
263 | - $email = sanitize_email( $customer->user_email ); |
|
264 | - |
|
265 | - // Customer's avatar. |
|
266 | - $avatar = esc_url( get_avatar_url( $email ) ); |
|
267 | - $avatar = "<img src='$avatar' height='32' width='32'/>"; |
|
268 | - |
|
269 | - // Customer's name. |
|
270 | - $name = esc_html( "{$address['first_name']} {$address['last_name']}" ); |
|
271 | - |
|
272 | - if ( ! empty( $name ) ) { |
|
273 | - $name = "<div style='overflow: hidden;height: 18px;'>$name</div>"; |
|
274 | - } |
|
275 | - |
|
276 | - $email = "<div class='row-title'><a href='$view_url'>$email</a></div>"; |
|
277 | - |
|
278 | - return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>"; |
|
279 | - |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * Retrieve the table columns |
|
284 | - * |
|
285 | - * @since 1.0.19 |
|
286 | - * @return array $columns Array of all the list table columns |
|
287 | - */ |
|
288 | - public function get_columns() { |
|
289 | - |
|
290 | - $columns = array( |
|
291 | - 'name' => __( 'Name', 'invoicing' ), |
|
292 | - 'country' => __( 'Country', 'invoicing' ), |
|
293 | - 'state' => __( 'State', 'invoicing' ), |
|
294 | - 'city' => __( 'City', 'invoicing' ), |
|
295 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
296 | - 'address' => __( 'Address', 'invoicing' ), |
|
297 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
298 | - 'company' => __( 'Company', 'invoicing' ), |
|
299 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
300 | - 'total' => __( 'Total Spend', 'invoicing' ), |
|
301 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
302 | - ); |
|
303 | - return apply_filters( 'wpinv_customers_table_columns', $columns ); |
|
304 | - |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Retrieve the current page number |
|
309 | - * |
|
310 | - * @since 1.0.19 |
|
311 | - * @return int Current page number |
|
312 | - */ |
|
313 | - public function get_paged() { |
|
314 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
315 | - } |
|
316 | - |
|
317 | - /** |
|
318 | - * Returns bulk actions. |
|
319 | - * |
|
320 | - * @since 1.0.19 |
|
321 | - * @return void |
|
322 | - */ |
|
323 | - public function bulk_actions( $which = '' ) { |
|
324 | - return array(); |
|
325 | - } |
|
326 | - |
|
327 | - /** |
|
328 | - * Prepares the display query |
|
329 | - */ |
|
330 | - public function prepare_query() { |
|
331 | - global $wpdb; |
|
332 | - |
|
333 | - $post_types = ''; |
|
334 | - |
|
335 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
336 | - $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
337 | - } |
|
338 | - |
|
339 | - $post_types = rtrim( $post_types, ' OR' ); |
|
340 | - |
|
341 | - // Maybe search. |
|
342 | - if ( ! empty( $_POST['s'] ) ) { |
|
343 | - $users = get_users( |
|
344 | - array( |
|
345 | - 'search' => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*', |
|
346 | - 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
347 | - 'fields' => 'ID', |
|
348 | - ) |
|
349 | - ); |
|
350 | - |
|
351 | - $users = implode( ', ', $users ); |
|
352 | - $post_types = "($post_types) AND ( post_author IN ( $users ) )"; |
|
353 | - } |
|
354 | - |
|
355 | - // Users with invoices. |
|
356 | - $customers = $wpdb->get_col( |
|
357 | - $wpdb->prepare( |
|
358 | - "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d", |
|
359 | - $this->get_paged() * 10 - 10, |
|
360 | - $this->per_page |
|
361 | - ) |
|
362 | - ); |
|
363 | - |
|
364 | - $this->items = $customers; |
|
365 | - $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" ); |
|
366 | - |
|
367 | - } |
|
368 | - |
|
369 | - /** |
|
370 | - * Setup the final data for the table |
|
371 | - * |
|
372 | - * @since 1.0.19 |
|
373 | - * @return void |
|
374 | - */ |
|
375 | - public function prepare_items() { |
|
376 | - $columns = $this->get_columns(); |
|
377 | - $hidden = array(); // No hidden columns |
|
378 | - $sortable = $this->get_sortable_columns(); |
|
379 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
380 | - $this->prepare_query(); |
|
381 | - |
|
382 | - $this->set_pagination_args( |
|
383 | - array( |
|
384 | - 'total_items' => $this->total, |
|
385 | - 'per_page' => $this->per_page, |
|
386 | - 'total_pages' => ceil( $this->total / $this->per_page ), |
|
387 | - ) |
|
388 | - ); |
|
389 | - |
|
390 | - } |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Gets the name of the primary column. |
|
59 | + * |
|
60 | + * @since 1.0.19 |
|
61 | + * @access protected |
|
62 | + * |
|
63 | + * @return string Name of the primary column. |
|
64 | + */ |
|
65 | + protected function get_primary_column_name() { |
|
66 | + return 'name'; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * This function renders most of the columns in the list table. |
|
71 | + * |
|
72 | + * @since 1.0.19 |
|
73 | + * |
|
74 | + * @param WP_User $item |
|
75 | + * @param string $column_name The name of the column |
|
76 | + * |
|
77 | + * @return string Column Name |
|
78 | + */ |
|
79 | + public function column_default( $item, $column_name ) { |
|
80 | + $value = esc_html( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) ); |
|
81 | + return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item ); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Displays the country column. |
|
86 | + * |
|
87 | + * @since 1.0.19 |
|
88 | + * |
|
89 | + * @param WP_User $user |
|
90 | + * |
|
91 | + * @return string Column Name |
|
92 | + */ |
|
93 | + public function column_country( $user ) { |
|
94 | + $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
95 | + if ( $country ) { |
|
96 | + $country = wpinv_country_name( $country ); |
|
97 | + } |
|
98 | + return esc_html( $country ); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Displays the state column. |
|
103 | + * |
|
104 | + * @since 1.0.19 |
|
105 | + * |
|
106 | + * @param WP_User $user |
|
107 | + * |
|
108 | + * @return string Column Name |
|
109 | + */ |
|
110 | + public function column_state( $user ) { |
|
111 | + $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
112 | + $state = $user->_wpinv_state; |
|
113 | + if ( $state ) { |
|
114 | + $state = wpinv_state_name( $state, $country ); |
|
115 | + } |
|
116 | + |
|
117 | + return esc_html( $state ); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Displays the signup column. |
|
122 | + * |
|
123 | + * @since 1.0.19 |
|
124 | + * |
|
125 | + * @param WP_User $user |
|
126 | + * |
|
127 | + * @return string Column Name |
|
128 | + */ |
|
129 | + public function column_signup( $user ) { |
|
130 | + return getpaid_format_date_value( $user->user_registered ); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Displays the total spent column. |
|
135 | + * |
|
136 | + * @since 1.0.19 |
|
137 | + * |
|
138 | + * @param WP_User $user |
|
139 | + * |
|
140 | + * @return string Column Name |
|
141 | + */ |
|
142 | + public function column_total( $user ) { |
|
143 | + return wpinv_price( $this->column_total_raw( $user ) ); |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Displays the total spent column. |
|
148 | + * |
|
149 | + * @since 1.0.19 |
|
150 | + * |
|
151 | + * @param WP_User $user |
|
152 | + * |
|
153 | + * @return float |
|
154 | + */ |
|
155 | + public function column_total_raw( $user ) { |
|
156 | + |
|
157 | + $args = array( |
|
158 | + 'data' => array( |
|
159 | + |
|
160 | + 'total' => array( |
|
161 | + 'type' => 'invoice_data', |
|
162 | + 'function' => 'SUM', |
|
163 | + 'name' => 'total_sales', |
|
164 | + ), |
|
165 | + |
|
166 | + ), |
|
167 | + 'where' => array( |
|
168 | + |
|
169 | + 'author' => array( |
|
170 | + 'type' => 'post_data', |
|
171 | + 'value' => absint( $user->ID ), |
|
172 | + 'key' => 'posts.post_author', |
|
173 | + 'operator' => '=', |
|
174 | + ), |
|
175 | + |
|
176 | + ), |
|
177 | + 'query_type' => 'get_var', |
|
178 | + 'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ), |
|
179 | + ); |
|
180 | + |
|
181 | + return wpinv_round_amount( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
182 | + |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Displays the total spent column. |
|
187 | + * |
|
188 | + * @since 1.0.19 |
|
189 | + * |
|
190 | + * @param WP_User $user |
|
191 | + * |
|
192 | + * @return string Column Name |
|
193 | + */ |
|
194 | + public function column_invoices( $user ) { |
|
195 | + |
|
196 | + $args = array( |
|
197 | + 'data' => array( |
|
198 | + |
|
199 | + 'ID' => array( |
|
200 | + 'type' => 'post_data', |
|
201 | + 'function' => 'COUNT', |
|
202 | + 'name' => 'count', |
|
203 | + 'distinct' => true, |
|
204 | + ), |
|
205 | + |
|
206 | + ), |
|
207 | + 'where' => array( |
|
208 | + |
|
209 | + 'author' => array( |
|
210 | + 'type' => 'post_data', |
|
211 | + 'value' => absint( $user->ID ), |
|
212 | + 'key' => 'posts.post_author', |
|
213 | + 'operator' => '=', |
|
214 | + ), |
|
215 | + |
|
216 | + ), |
|
217 | + 'query_type' => 'get_var', |
|
218 | + 'invoice_status' => array_keys( wpinv_get_invoice_statuses() ), |
|
219 | + ); |
|
220 | + |
|
221 | + return absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
222 | + |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Generates content for a single row of the table |
|
227 | + * @since 1.0.19 |
|
228 | + * |
|
229 | + * @param int $item The user id. |
|
230 | + */ |
|
231 | + public function single_row( $item ) { |
|
232 | + $item = get_user_by( 'id', $item ); |
|
233 | + |
|
234 | + if ( empty( $item ) ) { |
|
235 | + return; |
|
236 | + } |
|
237 | + |
|
238 | + echo '<tr>'; |
|
239 | + $this->single_row_columns( $item ); |
|
240 | + echo '</tr>'; |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Displays the customers name |
|
245 | + * |
|
246 | + * @param WP_User $customer customer. |
|
247 | + * @return string |
|
248 | + */ |
|
249 | + public function column_name( $customer ) { |
|
250 | + |
|
251 | + // Customer view URL. |
|
252 | + $view_url = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) ); |
|
253 | + $row_actions = $this->row_actions( |
|
254 | + array( |
|
255 | + 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>', |
|
256 | + ) |
|
257 | + ); |
|
258 | + |
|
259 | + // Get user's address. |
|
260 | + $address = wpinv_get_user_address( $customer->ID ); |
|
261 | + |
|
262 | + // Customer email address. |
|
263 | + $email = sanitize_email( $customer->user_email ); |
|
264 | + |
|
265 | + // Customer's avatar. |
|
266 | + $avatar = esc_url( get_avatar_url( $email ) ); |
|
267 | + $avatar = "<img src='$avatar' height='32' width='32'/>"; |
|
268 | + |
|
269 | + // Customer's name. |
|
270 | + $name = esc_html( "{$address['first_name']} {$address['last_name']}" ); |
|
271 | + |
|
272 | + if ( ! empty( $name ) ) { |
|
273 | + $name = "<div style='overflow: hidden;height: 18px;'>$name</div>"; |
|
274 | + } |
|
275 | + |
|
276 | + $email = "<div class='row-title'><a href='$view_url'>$email</a></div>"; |
|
277 | + |
|
278 | + return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>"; |
|
279 | + |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * Retrieve the table columns |
|
284 | + * |
|
285 | + * @since 1.0.19 |
|
286 | + * @return array $columns Array of all the list table columns |
|
287 | + */ |
|
288 | + public function get_columns() { |
|
289 | + |
|
290 | + $columns = array( |
|
291 | + 'name' => __( 'Name', 'invoicing' ), |
|
292 | + 'country' => __( 'Country', 'invoicing' ), |
|
293 | + 'state' => __( 'State', 'invoicing' ), |
|
294 | + 'city' => __( 'City', 'invoicing' ), |
|
295 | + 'zip' => __( 'ZIP', 'invoicing' ), |
|
296 | + 'address' => __( 'Address', 'invoicing' ), |
|
297 | + 'phone' => __( 'Phone', 'invoicing' ), |
|
298 | + 'company' => __( 'Company', 'invoicing' ), |
|
299 | + 'invoices' => __( 'Invoices', 'invoicing' ), |
|
300 | + 'total' => __( 'Total Spend', 'invoicing' ), |
|
301 | + 'signup' => __( 'Date created', 'invoicing' ), |
|
302 | + ); |
|
303 | + return apply_filters( 'wpinv_customers_table_columns', $columns ); |
|
304 | + |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Retrieve the current page number |
|
309 | + * |
|
310 | + * @since 1.0.19 |
|
311 | + * @return int Current page number |
|
312 | + */ |
|
313 | + public function get_paged() { |
|
314 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
315 | + } |
|
316 | + |
|
317 | + /** |
|
318 | + * Returns bulk actions. |
|
319 | + * |
|
320 | + * @since 1.0.19 |
|
321 | + * @return void |
|
322 | + */ |
|
323 | + public function bulk_actions( $which = '' ) { |
|
324 | + return array(); |
|
325 | + } |
|
326 | + |
|
327 | + /** |
|
328 | + * Prepares the display query |
|
329 | + */ |
|
330 | + public function prepare_query() { |
|
331 | + global $wpdb; |
|
332 | + |
|
333 | + $post_types = ''; |
|
334 | + |
|
335 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
336 | + $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
337 | + } |
|
338 | + |
|
339 | + $post_types = rtrim( $post_types, ' OR' ); |
|
340 | + |
|
341 | + // Maybe search. |
|
342 | + if ( ! empty( $_POST['s'] ) ) { |
|
343 | + $users = get_users( |
|
344 | + array( |
|
345 | + 'search' => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*', |
|
346 | + 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
347 | + 'fields' => 'ID', |
|
348 | + ) |
|
349 | + ); |
|
350 | + |
|
351 | + $users = implode( ', ', $users ); |
|
352 | + $post_types = "($post_types) AND ( post_author IN ( $users ) )"; |
|
353 | + } |
|
354 | + |
|
355 | + // Users with invoices. |
|
356 | + $customers = $wpdb->get_col( |
|
357 | + $wpdb->prepare( |
|
358 | + "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d", |
|
359 | + $this->get_paged() * 10 - 10, |
|
360 | + $this->per_page |
|
361 | + ) |
|
362 | + ); |
|
363 | + |
|
364 | + $this->items = $customers; |
|
365 | + $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" ); |
|
366 | + |
|
367 | + } |
|
368 | + |
|
369 | + /** |
|
370 | + * Setup the final data for the table |
|
371 | + * |
|
372 | + * @since 1.0.19 |
|
373 | + * @return void |
|
374 | + */ |
|
375 | + public function prepare_items() { |
|
376 | + $columns = $this->get_columns(); |
|
377 | + $hidden = array(); // No hidden columns |
|
378 | + $sortable = $this->get_sortable_columns(); |
|
379 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
380 | + $this->prepare_query(); |
|
381 | + |
|
382 | + $this->set_pagination_args( |
|
383 | + array( |
|
384 | + 'total_items' => $this->total, |
|
385 | + 'per_page' => $this->per_page, |
|
386 | + 'total_pages' => ceil( $this->total / $this->per_page ), |
|
387 | + ) |
|
388 | + ); |
|
389 | + |
|
390 | + } |
|
391 | 391 | } |
@@ -5,110 +5,110 @@ discard block |
||
5 | 5 | */ |
6 | 6 | |
7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
8 | - exit; // Exit if accessed directly |
|
8 | + exit; // Exit if accessed directly |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | if ( ! class_exists( 'GetPaid_Admin_Profile', false ) ) : |
12 | 12 | |
13 | - /** |
|
14 | - * GetPaid_Admin_Profile Class. |
|
15 | - */ |
|
16 | - class GetPaid_Admin_Profile { |
|
17 | - |
|
18 | - /** |
|
19 | - * Hook in tabs. |
|
20 | - */ |
|
21 | - public function __construct() { |
|
22 | - add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
23 | - add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
24 | - |
|
25 | - add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) ); |
|
26 | - add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) ); |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Get Address Fields for the edit user pages. |
|
31 | - * |
|
32 | - * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned |
|
33 | - */ |
|
34 | - public function get_customer_meta_fields() { |
|
35 | - |
|
36 | - $show_fields = apply_filters( |
|
37 | - 'getpaid_customer_meta_fields', |
|
38 | - array( |
|
39 | - 'billing' => array( |
|
40 | - 'title' => __( 'Billing Details (GetPaid)', 'invoicing' ), |
|
41 | - 'fields' => array( |
|
42 | - '_wpinv_first_name' => array( |
|
43 | - 'label' => __( 'First name', 'invoicing' ), |
|
44 | - 'description' => '', |
|
45 | - ), |
|
46 | - '_wpinv_last_name' => array( |
|
47 | - 'label' => __( 'Last name', 'invoicing' ), |
|
48 | - 'description' => '', |
|
49 | - ), |
|
50 | - '_wpinv_company' => array( |
|
51 | - 'label' => __( 'Company', 'invoicing' ), |
|
52 | - 'description' => '', |
|
53 | - ), |
|
54 | - '_wpinv_company_id' => array( |
|
55 | - 'label' => __( 'Company ID', 'invoicing' ), |
|
56 | - 'description' => '', |
|
57 | - ), |
|
58 | - '_wpinv_address' => array( |
|
59 | - 'label' => __( 'Address', 'invoicing' ), |
|
60 | - 'description' => '', |
|
61 | - ), |
|
62 | - '_wpinv_city' => array( |
|
63 | - 'label' => __( 'City', 'invoicing' ), |
|
64 | - 'description' => '', |
|
65 | - ), |
|
66 | - '_wpinv_zip' => array( |
|
67 | - 'label' => __( 'Postcode / ZIP', 'invoicing' ), |
|
68 | - 'description' => '', |
|
69 | - ), |
|
70 | - '_wpinv_country' => array( |
|
71 | - 'label' => __( 'Country / Region', 'invoicing' ), |
|
72 | - 'description' => '', |
|
73 | - 'class' => 'getpaid_js_field-country', |
|
74 | - 'type' => 'select', |
|
75 | - 'options' => array( '' => __( 'Select a country / region…', 'invoicing' ) ) + wpinv_get_country_list(), |
|
76 | - ), |
|
77 | - '_wpinv_state' => array( |
|
78 | - 'label' => __( 'State / County', 'invoicing' ), |
|
79 | - 'description' => __( 'State / County or state code', 'invoicing' ), |
|
80 | - 'class' => 'getpaid_js_field-state regular-text', |
|
81 | - ), |
|
82 | - '_wpinv_phone' => array( |
|
83 | - 'label' => __( 'Phone', 'invoicing' ), |
|
84 | - 'description' => '', |
|
85 | - ), |
|
86 | - '_wpinv_vat_number' => array( |
|
87 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
88 | - 'description' => '', |
|
89 | - ), |
|
90 | - ), |
|
91 | - ), |
|
92 | - ) |
|
93 | - ); |
|
94 | - return $show_fields; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Show Address Fields on edit user pages. |
|
99 | - * |
|
100 | - * @param WP_User $user |
|
101 | - */ |
|
102 | - public function add_customer_meta_fields( $user ) { |
|
103 | - |
|
104 | - if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) { |
|
105 | - return; |
|
106 | - } |
|
107 | - |
|
108 | - $show_fields = $this->get_customer_meta_fields(); |
|
109 | - |
|
110 | - foreach ( $show_fields as $fieldset_key => $fieldset ) : |
|
111 | - ?> |
|
13 | + /** |
|
14 | + * GetPaid_Admin_Profile Class. |
|
15 | + */ |
|
16 | + class GetPaid_Admin_Profile { |
|
17 | + |
|
18 | + /** |
|
19 | + * Hook in tabs. |
|
20 | + */ |
|
21 | + public function __construct() { |
|
22 | + add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
23 | + add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
24 | + |
|
25 | + add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) ); |
|
26 | + add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) ); |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Get Address Fields for the edit user pages. |
|
31 | + * |
|
32 | + * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned |
|
33 | + */ |
|
34 | + public function get_customer_meta_fields() { |
|
35 | + |
|
36 | + $show_fields = apply_filters( |
|
37 | + 'getpaid_customer_meta_fields', |
|
38 | + array( |
|
39 | + 'billing' => array( |
|
40 | + 'title' => __( 'Billing Details (GetPaid)', 'invoicing' ), |
|
41 | + 'fields' => array( |
|
42 | + '_wpinv_first_name' => array( |
|
43 | + 'label' => __( 'First name', 'invoicing' ), |
|
44 | + 'description' => '', |
|
45 | + ), |
|
46 | + '_wpinv_last_name' => array( |
|
47 | + 'label' => __( 'Last name', 'invoicing' ), |
|
48 | + 'description' => '', |
|
49 | + ), |
|
50 | + '_wpinv_company' => array( |
|
51 | + 'label' => __( 'Company', 'invoicing' ), |
|
52 | + 'description' => '', |
|
53 | + ), |
|
54 | + '_wpinv_company_id' => array( |
|
55 | + 'label' => __( 'Company ID', 'invoicing' ), |
|
56 | + 'description' => '', |
|
57 | + ), |
|
58 | + '_wpinv_address' => array( |
|
59 | + 'label' => __( 'Address', 'invoicing' ), |
|
60 | + 'description' => '', |
|
61 | + ), |
|
62 | + '_wpinv_city' => array( |
|
63 | + 'label' => __( 'City', 'invoicing' ), |
|
64 | + 'description' => '', |
|
65 | + ), |
|
66 | + '_wpinv_zip' => array( |
|
67 | + 'label' => __( 'Postcode / ZIP', 'invoicing' ), |
|
68 | + 'description' => '', |
|
69 | + ), |
|
70 | + '_wpinv_country' => array( |
|
71 | + 'label' => __( 'Country / Region', 'invoicing' ), |
|
72 | + 'description' => '', |
|
73 | + 'class' => 'getpaid_js_field-country', |
|
74 | + 'type' => 'select', |
|
75 | + 'options' => array( '' => __( 'Select a country / region…', 'invoicing' ) ) + wpinv_get_country_list(), |
|
76 | + ), |
|
77 | + '_wpinv_state' => array( |
|
78 | + 'label' => __( 'State / County', 'invoicing' ), |
|
79 | + 'description' => __( 'State / County or state code', 'invoicing' ), |
|
80 | + 'class' => 'getpaid_js_field-state regular-text', |
|
81 | + ), |
|
82 | + '_wpinv_phone' => array( |
|
83 | + 'label' => __( 'Phone', 'invoicing' ), |
|
84 | + 'description' => '', |
|
85 | + ), |
|
86 | + '_wpinv_vat_number' => array( |
|
87 | + 'label' => __( 'VAT Number', 'invoicing' ), |
|
88 | + 'description' => '', |
|
89 | + ), |
|
90 | + ), |
|
91 | + ), |
|
92 | + ) |
|
93 | + ); |
|
94 | + return $show_fields; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Show Address Fields on edit user pages. |
|
99 | + * |
|
100 | + * @param WP_User $user |
|
101 | + */ |
|
102 | + public function add_customer_meta_fields( $user ) { |
|
103 | + |
|
104 | + if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) { |
|
105 | + return; |
|
106 | + } |
|
107 | + |
|
108 | + $show_fields = $this->get_customer_meta_fields(); |
|
109 | + |
|
110 | + foreach ( $show_fields as $fieldset_key => $fieldset ) : |
|
111 | + ?> |
|
112 | 112 | <h2><?php echo esc_html( $fieldset['title'] ); ?></h2> |
113 | 113 | <table class="form-table" id="<?php echo esc_attr( 'getpaid-fieldset-' . $fieldset_key ); ?>"> |
114 | 114 | <?php foreach ( $fieldset['fields'] as $key => $field ) : ?> |
@@ -120,9 +120,9 @@ discard block |
||
120 | 120 | <?php if ( ! empty( $field['type'] ) && 'select' === $field['type'] ) : ?> |
121 | 121 | <select name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" class="<?php echo esc_attr( $field['class'] ); ?> wpi_select2" style="width: 25em;"> |
122 | 122 | <?php |
123 | - $selected = esc_attr( get_user_meta( $user->ID, $key, true ) ); |
|
124 | - foreach ( $field['options'] as $option_key => $option_value ) : |
|
125 | - ?> |
|
123 | + $selected = esc_attr( get_user_meta( $user->ID, $key, true ) ); |
|
124 | + foreach ( $field['options'] as $option_key => $option_value ) : |
|
125 | + ?> |
|
126 | 126 | <option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( $selected, $option_key, true ); ?>><?php echo esc_html( $option_value ); ?></option> |
127 | 127 | <?php endforeach; ?> |
128 | 128 | </select> |
@@ -137,52 +137,52 @@ discard block |
||
137 | 137 | <?php endforeach; ?> |
138 | 138 | </table> |
139 | 139 | <?php |
140 | - endforeach; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Save Address Fields on edit user pages. |
|
145 | - * |
|
146 | - * @param int $user_id User ID of the user being saved |
|
147 | - */ |
|
148 | - public function save_customer_meta_fields( $user_id ) { |
|
149 | - if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) { |
|
150 | - return; |
|
151 | - } |
|
152 | - |
|
153 | - $save_fields = $this->get_customer_meta_fields(); |
|
154 | - |
|
155 | - foreach ( $save_fields as $fieldset ) { |
|
156 | - |
|
157 | - foreach ( $fieldset['fields'] as $key => $field ) { |
|
158 | - |
|
159 | - if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) { |
|
160 | - update_user_meta( $user_id, $key, ! empty( $_POST[ $key ] ) ); |
|
161 | - } elseif ( isset( $_POST[ $key ] ) ) { |
|
162 | - update_user_meta( $user_id, $key, wpinv_clean( $_POST[ $key ] ) ); |
|
163 | - } |
|
164 | - } |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Get user meta for a given key, with fallbacks to core user info for pre-existing fields. |
|
170 | - * |
|
171 | - * @since 3.1.0 |
|
172 | - * @param int $user_id User ID of the user being edited |
|
173 | - * @param string $key Key for user meta field |
|
174 | - * @return string |
|
175 | - */ |
|
176 | - protected function get_user_meta( $user_id, $key ) { |
|
177 | - $value = get_user_meta( $user_id, $key, true ); |
|
178 | - $existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' ); |
|
179 | - if ( ! $value && in_array( $key, $existing_fields ) ) { |
|
180 | - $value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true ); |
|
181 | - } |
|
182 | - |
|
183 | - return $value; |
|
184 | - } |
|
185 | - } |
|
140 | + endforeach; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Save Address Fields on edit user pages. |
|
145 | + * |
|
146 | + * @param int $user_id User ID of the user being saved |
|
147 | + */ |
|
148 | + public function save_customer_meta_fields( $user_id ) { |
|
149 | + if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) { |
|
150 | + return; |
|
151 | + } |
|
152 | + |
|
153 | + $save_fields = $this->get_customer_meta_fields(); |
|
154 | + |
|
155 | + foreach ( $save_fields as $fieldset ) { |
|
156 | + |
|
157 | + foreach ( $fieldset['fields'] as $key => $field ) { |
|
158 | + |
|
159 | + if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) { |
|
160 | + update_user_meta( $user_id, $key, ! empty( $_POST[ $key ] ) ); |
|
161 | + } elseif ( isset( $_POST[ $key ] ) ) { |
|
162 | + update_user_meta( $user_id, $key, wpinv_clean( $_POST[ $key ] ) ); |
|
163 | + } |
|
164 | + } |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Get user meta for a given key, with fallbacks to core user info for pre-existing fields. |
|
170 | + * |
|
171 | + * @since 3.1.0 |
|
172 | + * @param int $user_id User ID of the user being edited |
|
173 | + * @param string $key Key for user meta field |
|
174 | + * @return string |
|
175 | + */ |
|
176 | + protected function get_user_meta( $user_id, $key ) { |
|
177 | + $value = get_user_meta( $user_id, $key, true ); |
|
178 | + $existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' ); |
|
179 | + if ( ! $value && in_array( $key, $existing_fields ) ) { |
|
180 | + $value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true ); |
|
181 | + } |
|
182 | + |
|
183 | + return $value; |
|
184 | + } |
|
185 | + } |
|
186 | 186 | |
187 | 187 | endif; |
188 | 188 |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | 'getpaid-nonce', |
58 | 58 | 'getpaid-nonce' |
59 | 59 | ); |
60 | - $anchor = __( 'Deactivate', 'invoicing' ); |
|
61 | - $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
60 | + $anchor = __( 'Deactivate', 'invoicing' ); |
|
61 | + $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
62 | 62 | $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
63 | 63 | |
64 | 64 | } elseif ( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) { |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | 'getpaid-nonce', |
74 | 74 | 'getpaid-nonce' |
75 | 75 | ); |
76 | - $anchor = __( 'Activate', 'invoicing' ); |
|
77 | - $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
76 | + $anchor = __( 'Activate', 'invoicing' ); |
|
77 | + $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
78 | 78 | $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
79 | 79 | |
80 | 80 | } |
@@ -91,8 +91,8 @@ discard block |
||
91 | 91 | 'getpaid-nonce' |
92 | 92 | ) |
93 | 93 | ); |
94 | - $anchor = __( 'Delete', 'invoicing' ); |
|
95 | - $title = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' ); |
|
94 | + $anchor = __( 'Delete', 'invoicing' ); |
|
95 | + $title = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' ); |
|
96 | 96 | $row_actions['delete'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
97 | 97 | |
98 | 98 | $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount ); |
@@ -118,13 +118,13 @@ discard block |
||
118 | 118 | $types = wpinv_get_discount_types(); |
119 | 119 | |
120 | 120 | foreach ( $types as $name => $type ) { |
121 | - echo '<option value="' . esc_attr( $name ) . '"'; |
|
121 | + echo '<option value="' . esc_attr( $name ) . '"'; |
|
122 | 122 | |
123 | - if ( isset( $_GET['discount_type'] ) ) { |
|
124 | - selected( $name, sanitize_text_field( $_GET['discount_type'] ) ); |
|
123 | + if ( isset( $_GET['discount_type'] ) ) { |
|
124 | + selected( $name, sanitize_text_field( $_GET['discount_type'] ) ); |
|
125 | 125 | } |
126 | 126 | |
127 | - echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
127 | + echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
128 | 128 | } |
129 | 129 | ?> |
130 | 130 | </select> |
@@ -151,15 +151,15 @@ discard block |
||
151 | 151 | // Filter vat rule type |
152 | 152 | if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) { |
153 | 153 | $meta_query[] = array( |
154 | - 'key' => '_wpi_discount_type', |
|
155 | - 'value' => sanitize_key( urldecode( $_GET['discount_type'] ) ), |
|
156 | - 'compare' => '=', |
|
157 | - ); |
|
158 | - } |
|
154 | + 'key' => '_wpi_discount_type', |
|
155 | + 'value' => sanitize_key( urldecode( $_GET['discount_type'] ) ), |
|
156 | + 'compare' => '=', |
|
157 | + ); |
|
158 | + } |
|
159 | 159 | |
160 | 160 | if ( ! empty( $meta_query ) ) { |
161 | 161 | $vars['meta_query'] = $meta_query; |
162 | - } |
|
162 | + } |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | return $vars; |
@@ -24,14 +24,14 @@ discard block |
||
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
27 | - * Highlights sub menus. |
|
28 | - */ |
|
29 | - public function set_admin_menu_class() { |
|
30 | - global $current_screen, $parent_file, $submenu_file; |
|
27 | + * Highlights sub menus. |
|
28 | + */ |
|
29 | + public function set_admin_menu_class() { |
|
30 | + global $current_screen, $parent_file, $submenu_file; |
|
31 | 31 | |
32 | 32 | if ( ! empty( $current_screen->id ) && in_array( $current_screen->id, array( 'wpi_discount', 'wpi_payment_form', 'wpi_invoice' ) ) ) { |
33 | - $parent_file = 'wpinv'; |
|
34 | - $submenu_file = 'edit.php?post_type=' . $current_screen->id; |
|
33 | + $parent_file = 'wpinv'; |
|
34 | + $submenu_file = 'edit.php?post_type=' . $current_screen->id; |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | } |
@@ -165,8 +165,8 @@ discard block |
||
165 | 165 | foreach ( wpinv_get_settings_tabs() as $tab_id => $tab_name ) { |
166 | 166 | $tab_url = add_query_arg( |
167 | 167 | array( |
168 | - 'settings-updated' => false, |
|
169 | - 'tab' => $tab_id, |
|
168 | + 'settings-updated' => false, |
|
169 | + 'tab' => $tab_id, |
|
170 | 170 | ), |
171 | 171 | 'admin.php?page=wpinv-settings' |
172 | 172 | ); |
@@ -193,9 +193,9 @@ discard block |
||
193 | 193 | $number++; |
194 | 194 | $tab_url = add_query_arg( |
195 | 195 | array( |
196 | - 'settings-updated' => false, |
|
197 | - 'tab' => $active_tab, |
|
198 | - 'section' => $section_id, |
|
196 | + 'settings-updated' => false, |
|
197 | + 'tab' => $active_tab, |
|
198 | + 'section' => $section_id, |
|
199 | 199 | ), |
200 | 200 | admin_url( 'admin.php?page=wpinv-settings' ) |
201 | 201 | ); |