@@ -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_Item_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 item. |
@@ -270,35 +270,35 @@ discard block |
||
270 | 270 | } |
271 | 271 | |
272 | 272 | /** |
273 | - * Save meta box data. |
|
274 | - * |
|
275 | - * @param int $post_id |
|
276 | - */ |
|
277 | - public static function save( $post_id ) { |
|
273 | + * Save meta box data. |
|
274 | + * |
|
275 | + * @param int $post_id |
|
276 | + */ |
|
277 | + public static function save( $post_id ) { |
|
278 | 278 | |
279 | 279 | // Prepare the item. |
280 | 280 | $item = new WPInv_Item( $post_id ); |
281 | 281 | |
282 | 282 | // Load new data. |
283 | 283 | $item->set_props( |
284 | - array( |
|
285 | - 'price' => isset( $_POST['wpinv_item_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_item_price'] ) : null, |
|
286 | - 'vat_rule' => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null, |
|
287 | - 'vat_class' => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null, |
|
288 | - 'type' => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null, |
|
289 | - 'is_dynamic_pricing' => ! empty( $_POST['wpinv_name_your_price'] ), |
|
284 | + array( |
|
285 | + 'price' => isset( $_POST['wpinv_item_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_item_price'] ) : null, |
|
286 | + 'vat_rule' => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null, |
|
287 | + 'vat_class' => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null, |
|
288 | + 'type' => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null, |
|
289 | + 'is_dynamic_pricing' => ! empty( $_POST['wpinv_name_your_price'] ), |
|
290 | 290 | 'minimum_price' => isset( $_POST['wpinv_minimum_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_minimum_price'] ) : null, |
291 | - 'is_recurring' => ! empty( $_POST['wpinv_is_recurring'] ), |
|
292 | - 'recurring_period' => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null, |
|
293 | - 'recurring_interval' => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : 1, |
|
294 | - 'recurring_limit' => isset( $_POST['wpinv_recurring_limit'] ) ? (int) $_POST['wpinv_recurring_limit'] : null, |
|
295 | - 'is_free_trial' => isset( $_POST['wpinv_trial_interval'] ) ? ( 0 != (int) $_POST['wpinv_trial_interval'] ) : null, |
|
296 | - 'trial_period' => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null, |
|
297 | - 'trial_interval' => isset( $_POST['wpinv_trial_interval'] ) ? (int) $_POST['wpinv_trial_interval'] : null, |
|
298 | - ) |
|
291 | + 'is_recurring' => ! empty( $_POST['wpinv_is_recurring'] ), |
|
292 | + 'recurring_period' => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null, |
|
293 | + 'recurring_interval' => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : 1, |
|
294 | + 'recurring_limit' => isset( $_POST['wpinv_recurring_limit'] ) ? (int) $_POST['wpinv_recurring_limit'] : null, |
|
295 | + 'is_free_trial' => isset( $_POST['wpinv_trial_interval'] ) ? ( 0 != (int) $_POST['wpinv_trial_interval'] ) : null, |
|
296 | + 'trial_period' => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null, |
|
297 | + 'trial_interval' => isset( $_POST['wpinv_trial_interval'] ) ? (int) $_POST['wpinv_trial_interval'] : null, |
|
298 | + ) |
|
299 | 299 | ); |
300 | 300 | |
301 | - $item->save(); |
|
302 | - do_action( 'getpaid_item_metabox_save', $post_id, $item ); |
|
303 | - } |
|
301 | + $item->save(); |
|
302 | + do_action( 'getpaid_item_metabox_save', $post_id, $item ); |
|
303 | + } |
|
304 | 304 | } |
@@ -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 | } |
@@ -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 $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 |