@@ -5,126 +5,126 @@ 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 | - if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) { |
|
| 104 | - return; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $show_fields = $this->get_customer_meta_fields(); |
|
| 108 | - |
|
| 109 | - $customer = getpaid_get_customer_by_user_id( (int) $user->ID ); |
|
| 110 | - |
|
| 111 | - foreach ( $show_fields as $fieldset_key => $fieldset ) : |
|
| 112 | - ?> |
|
| 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 | + if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) { |
|
| 104 | + return; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $show_fields = $this->get_customer_meta_fields(); |
|
| 108 | + |
|
| 109 | + $customer = getpaid_get_customer_by_user_id( (int) $user->ID ); |
|
| 110 | + |
|
| 111 | + foreach ( $show_fields as $fieldset_key => $fieldset ) : |
|
| 112 | + ?> |
|
| 113 | 113 | <h2><?php echo esc_html( $fieldset['title'] ); ?></h2> |
| 114 | 114 | <table class="form-table" id="<?php echo esc_attr( 'getpaid-fieldset-' . $fieldset_key ); ?>"> |
| 115 | 115 | <?php foreach ( $fieldset['fields'] as $key => $field ) : |
| 116 | - if ( ! empty( $customer ) ) { |
|
| 117 | - if ( strpos( $key, '_wpinv_' ) === 0 ) { |
|
| 118 | - $save_key = substr( $key , 7 ); |
|
| 119 | - } else { |
|
| 120 | - $save_key = $key; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - $value = $customer->get( $save_key ); |
|
| 124 | - } else { |
|
| 125 | - $value = $this->get_user_meta( $user->ID, $key ); |
|
| 126 | - } |
|
| 127 | - ?> |
|
| 116 | + if ( ! empty( $customer ) ) { |
|
| 117 | + if ( strpos( $key, '_wpinv_' ) === 0 ) { |
|
| 118 | + $save_key = substr( $key , 7 ); |
|
| 119 | + } else { |
|
| 120 | + $save_key = $key; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + $value = $customer->get( $save_key ); |
|
| 124 | + } else { |
|
| 125 | + $value = $this->get_user_meta( $user->ID, $key ); |
|
| 126 | + } |
|
| 127 | + ?> |
|
| 128 | 128 | <tr> |
| 129 | 129 | <th> |
| 130 | 130 | <label for="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $field['label'] ); ?></label> |
@@ -147,75 +147,75 @@ discard block |
||
| 147 | 147 | <?php endforeach; ?> |
| 148 | 148 | </table> |
| 149 | 149 | <?php |
| 150 | - endforeach; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Save Address Fields on edit user pages. |
|
| 155 | - * |
|
| 156 | - * @param int $user_id User ID of the user being saved |
|
| 157 | - */ |
|
| 158 | - public function save_customer_meta_fields( $user_id ) { |
|
| 159 | - if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) { |
|
| 160 | - return; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - $save_fields = $this->get_customer_meta_fields(); |
|
| 164 | - $save_data = array(); |
|
| 165 | - |
|
| 166 | - foreach ( $save_fields as $fieldset ) { |
|
| 167 | - foreach ( $fieldset['fields'] as $key => $field ) { |
|
| 168 | - if ( strpos( $key, '_wpinv_' ) === 0 ) { |
|
| 169 | - $save_key = substr( $key , 7 ); |
|
| 170 | - } else { |
|
| 171 | - $save_key = $key; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - if ( $save_key && isset( $field['type'] ) && 'checkbox' === $field['type'] ) { |
|
| 175 | - $save_data[ $save_key ] = ! empty( $_POST[ $key ] ) ? true : false; |
|
| 176 | - } else if ( $save_key && isset( $_POST[ $key ] ) ) { |
|
| 177 | - $save_data[ $save_key ] = wpinv_clean( $_POST[ $key ] ); |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - if ( empty( $save_data ) ) { |
|
| 183 | - return; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - $customer = getpaid_get_customer_by_user_id( (int) $user_id ); |
|
| 187 | - |
|
| 188 | - if ( empty( $customer ) ) { |
|
| 189 | - $customer = new GetPaid_Customer( 0 ); |
|
| 190 | - $customer->clone_user( (int) $user_id ); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - foreach ( $save_data as $key => $value ) { |
|
| 194 | - $customer->set( $key, $value ); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - $customer->save(); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Get user meta for a given key, with fallbacks to core user info for pre-existing fields. |
|
| 202 | - * |
|
| 203 | - * @since 3.1.0 |
|
| 204 | - * @param int $user_id User ID of the user being edited |
|
| 205 | - * @param string $key Key for user meta field |
|
| 206 | - * @return string |
|
| 207 | - */ |
|
| 208 | - protected function get_user_meta( $user_id, $key ) { |
|
| 209 | - $value = get_user_meta( $user_id, $key, true ); |
|
| 210 | - $existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' ); |
|
| 211 | - |
|
| 212 | - if ( ! $value && in_array( $key, $existing_fields ) ) { |
|
| 213 | - $value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true ); |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - return $value; |
|
| 217 | - } |
|
| 218 | - } |
|
| 150 | + endforeach; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Save Address Fields on edit user pages. |
|
| 155 | + * |
|
| 156 | + * @param int $user_id User ID of the user being saved |
|
| 157 | + */ |
|
| 158 | + public function save_customer_meta_fields( $user_id ) { |
|
| 159 | + if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) { |
|
| 160 | + return; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + $save_fields = $this->get_customer_meta_fields(); |
|
| 164 | + $save_data = array(); |
|
| 165 | + |
|
| 166 | + foreach ( $save_fields as $fieldset ) { |
|
| 167 | + foreach ( $fieldset['fields'] as $key => $field ) { |
|
| 168 | + if ( strpos( $key, '_wpinv_' ) === 0 ) { |
|
| 169 | + $save_key = substr( $key , 7 ); |
|
| 170 | + } else { |
|
| 171 | + $save_key = $key; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + if ( $save_key && isset( $field['type'] ) && 'checkbox' === $field['type'] ) { |
|
| 175 | + $save_data[ $save_key ] = ! empty( $_POST[ $key ] ) ? true : false; |
|
| 176 | + } else if ( $save_key && isset( $_POST[ $key ] ) ) { |
|
| 177 | + $save_data[ $save_key ] = wpinv_clean( $_POST[ $key ] ); |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + if ( empty( $save_data ) ) { |
|
| 183 | + return; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + $customer = getpaid_get_customer_by_user_id( (int) $user_id ); |
|
| 187 | + |
|
| 188 | + if ( empty( $customer ) ) { |
|
| 189 | + $customer = new GetPaid_Customer( 0 ); |
|
| 190 | + $customer->clone_user( (int) $user_id ); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + foreach ( $save_data as $key => $value ) { |
|
| 194 | + $customer->set( $key, $value ); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + $customer->save(); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Get user meta for a given key, with fallbacks to core user info for pre-existing fields. |
|
| 202 | + * |
|
| 203 | + * @since 3.1.0 |
|
| 204 | + * @param int $user_id User ID of the user being edited |
|
| 205 | + * @param string $key Key for user meta field |
|
| 206 | + * @return string |
|
| 207 | + */ |
|
| 208 | + protected function get_user_meta( $user_id, $key ) { |
|
| 209 | + $value = get_user_meta( $user_id, $key, true ); |
|
| 210 | + $existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' ); |
|
| 211 | + |
|
| 212 | + if ( ! $value && in_array( $key, $existing_fields ) ) { |
|
| 213 | + $value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true ); |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + return $value; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | 220 | endif; |
| 221 | 221 | |
@@ -4,11 +4,11 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 7 | +if (!defined('ABSPATH')) { |
|
| 8 | 8 | exit; // Exit if accessed directly |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | -if ( ! class_exists( 'GetPaid_Admin_Profile', false ) ) : |
|
| 11 | +if (!class_exists('GetPaid_Admin_Profile', false)) : |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * GetPaid_Admin_Profile Class. |
@@ -19,11 +19,11 @@ discard block |
||
| 19 | 19 | * Hook in tabs. |
| 20 | 20 | */ |
| 21 | 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 ); |
|
| 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 | 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' ) ); |
|
| 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 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -37,54 +37,54 @@ discard block |
||
| 37 | 37 | 'getpaid_customer_meta_fields', |
| 38 | 38 | array( |
| 39 | 39 | 'billing' => array( |
| 40 | - 'title' => __( 'Billing Details (GetPaid)', 'invoicing' ), |
|
| 40 | + 'title' => __('Billing Details (GetPaid)', 'invoicing'), |
|
| 41 | 41 | 'fields' => array( |
| 42 | 42 | '_wpinv_first_name' => array( |
| 43 | - 'label' => __( 'First name', 'invoicing' ), |
|
| 43 | + 'label' => __('First name', 'invoicing'), |
|
| 44 | 44 | 'description' => '', |
| 45 | 45 | ), |
| 46 | 46 | '_wpinv_last_name' => array( |
| 47 | - 'label' => __( 'Last name', 'invoicing' ), |
|
| 47 | + 'label' => __('Last name', 'invoicing'), |
|
| 48 | 48 | 'description' => '', |
| 49 | 49 | ), |
| 50 | 50 | '_wpinv_company' => array( |
| 51 | - 'label' => __( 'Company', 'invoicing' ), |
|
| 51 | + 'label' => __('Company', 'invoicing'), |
|
| 52 | 52 | 'description' => '', |
| 53 | 53 | ), |
| 54 | 54 | '_wpinv_company_id' => array( |
| 55 | - 'label' => __( 'Company ID', 'invoicing' ), |
|
| 55 | + 'label' => __('Company ID', 'invoicing'), |
|
| 56 | 56 | 'description' => '', |
| 57 | 57 | ), |
| 58 | 58 | '_wpinv_address' => array( |
| 59 | - 'label' => __( 'Address', 'invoicing' ), |
|
| 59 | + 'label' => __('Address', 'invoicing'), |
|
| 60 | 60 | 'description' => '', |
| 61 | 61 | ), |
| 62 | 62 | '_wpinv_city' => array( |
| 63 | - 'label' => __( 'City', 'invoicing' ), |
|
| 63 | + 'label' => __('City', 'invoicing'), |
|
| 64 | 64 | 'description' => '', |
| 65 | 65 | ), |
| 66 | 66 | '_wpinv_zip' => array( |
| 67 | - 'label' => __( 'Postcode / ZIP', 'invoicing' ), |
|
| 67 | + 'label' => __('Postcode / ZIP', 'invoicing'), |
|
| 68 | 68 | 'description' => '', |
| 69 | 69 | ), |
| 70 | 70 | '_wpinv_country' => array( |
| 71 | - 'label' => __( 'Country / Region', 'invoicing' ), |
|
| 71 | + 'label' => __('Country / Region', 'invoicing'), |
|
| 72 | 72 | 'description' => '', |
| 73 | 73 | 'class' => 'getpaid_js_field-country', |
| 74 | 74 | 'type' => 'select', |
| 75 | - 'options' => array( '' => __( 'Select a country / region…', 'invoicing' ) ) + wpinv_get_country_list(), |
|
| 75 | + 'options' => array('' => __('Select a country / region…', 'invoicing')) + wpinv_get_country_list(), |
|
| 76 | 76 | ), |
| 77 | 77 | '_wpinv_state' => array( |
| 78 | - 'label' => __( 'State / County', 'invoicing' ), |
|
| 79 | - 'description' => __( 'State / County or state code', 'invoicing' ), |
|
| 78 | + 'label' => __('State / County', 'invoicing'), |
|
| 79 | + 'description' => __('State / County or state code', 'invoicing'), |
|
| 80 | 80 | 'class' => 'getpaid_js_field-state regular-text', |
| 81 | 81 | ), |
| 82 | 82 | '_wpinv_phone' => array( |
| 83 | - 'label' => __( 'Phone', 'invoicing' ), |
|
| 83 | + 'label' => __('Phone', 'invoicing'), |
|
| 84 | 84 | 'description' => '', |
| 85 | 85 | ), |
| 86 | 86 | '_wpinv_vat_number' => array( |
| 87 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
| 87 | + 'label' => __('VAT Number', 'invoicing'), |
|
| 88 | 88 | 'description' => '', |
| 89 | 89 | ), |
| 90 | 90 | ), |
@@ -99,49 +99,49 @@ discard block |
||
| 99 | 99 | * |
| 100 | 100 | * @param WP_User $user |
| 101 | 101 | */ |
| 102 | - public function add_customer_meta_fields( $user ) { |
|
| 103 | - if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) { |
|
| 102 | + public function add_customer_meta_fields($user) { |
|
| 103 | + if (!apply_filters('getpaid_current_user_can_edit_customer_meta_fields', current_user_can('manage_options'), $user->ID)) { |
|
| 104 | 104 | return; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | $show_fields = $this->get_customer_meta_fields(); |
| 108 | 108 | |
| 109 | - $customer = getpaid_get_customer_by_user_id( (int) $user->ID ); |
|
| 109 | + $customer = getpaid_get_customer_by_user_id((int) $user->ID); |
|
| 110 | 110 | |
| 111 | - foreach ( $show_fields as $fieldset_key => $fieldset ) : |
|
| 111 | + foreach ($show_fields as $fieldset_key => $fieldset) : |
|
| 112 | 112 | ?> |
| 113 | - <h2><?php echo esc_html( $fieldset['title'] ); ?></h2> |
|
| 114 | - <table class="form-table" id="<?php echo esc_attr( 'getpaid-fieldset-' . $fieldset_key ); ?>"> |
|
| 115 | - <?php foreach ( $fieldset['fields'] as $key => $field ) : |
|
| 116 | - if ( ! empty( $customer ) ) { |
|
| 117 | - if ( strpos( $key, '_wpinv_' ) === 0 ) { |
|
| 118 | - $save_key = substr( $key , 7 ); |
|
| 113 | + <h2><?php echo esc_html($fieldset['title']); ?></h2> |
|
| 114 | + <table class="form-table" id="<?php echo esc_attr('getpaid-fieldset-' . $fieldset_key); ?>"> |
|
| 115 | + <?php foreach ($fieldset['fields'] as $key => $field) : |
|
| 116 | + if (!empty($customer)) { |
|
| 117 | + if (strpos($key, '_wpinv_') === 0) { |
|
| 118 | + $save_key = substr($key, 7); |
|
| 119 | 119 | } else { |
| 120 | 120 | $save_key = $key; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - $value = $customer->get( $save_key ); |
|
| 123 | + $value = $customer->get($save_key); |
|
| 124 | 124 | } else { |
| 125 | - $value = $this->get_user_meta( $user->ID, $key ); |
|
| 125 | + $value = $this->get_user_meta($user->ID, $key); |
|
| 126 | 126 | } |
| 127 | 127 | ?> |
| 128 | 128 | <tr> |
| 129 | 129 | <th> |
| 130 | - <label for="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $field['label'] ); ?></label> |
|
| 130 | + <label for="<?php echo esc_attr($key); ?>"><?php echo esc_html($field['label']); ?></label> |
|
| 131 | 131 | </th> |
| 132 | 132 | <td> |
| 133 | - <?php if ( ! empty( $field['type'] ) && 'select' === $field['type'] ) : ?> |
|
| 134 | - <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;"> |
|
| 135 | - <?php foreach ( $field['options'] as $option_key => $option_value ) : ?> |
|
| 136 | - <option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( $value, $option_key, true ); ?>><?php echo esc_html( $option_value ); ?></option> |
|
| 133 | + <?php if (!empty($field['type']) && 'select' === $field['type']) : ?> |
|
| 134 | + <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;"> |
|
| 135 | + <?php foreach ($field['options'] as $option_key => $option_value) : ?> |
|
| 136 | + <option value="<?php echo esc_attr($option_key); ?>" <?php selected($value, $option_key, true); ?>><?php echo esc_html($option_value); ?></option> |
|
| 137 | 137 | <?php endforeach; ?> |
| 138 | 138 | </select> |
| 139 | - <?php elseif ( ! empty( $field['type'] ) && 'checkbox' === $field['type'] ) : ?> |
|
| 140 | - <input type="checkbox" name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" value="1" class="<?php echo esc_attr( $field['class'] ); ?>" <?php checked( (int) $value, 1, true ); ?> /> |
|
| 139 | + <?php elseif (!empty($field['type']) && 'checkbox' === $field['type']) : ?> |
|
| 140 | + <input type="checkbox" name="<?php echo esc_attr($key); ?>" id="<?php echo esc_attr($key); ?>" value="1" class="<?php echo esc_attr($field['class']); ?>" <?php checked((int) $value, 1, true); ?> /> |
|
| 141 | 141 | <?php else : ?> |
| 142 | - <input type="text" name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $value ); ?>" class="<?php echo ( ! empty( $field['class'] ) ? esc_attr( $field['class'] ) : 'regular-text' ); ?>" /> |
|
| 142 | + <input type="text" name="<?php echo esc_attr($key); ?>" id="<?php echo esc_attr($key); ?>" value="<?php echo esc_attr($value); ?>" class="<?php echo (!empty($field['class']) ? esc_attr($field['class']) : 'regular-text'); ?>" /> |
|
| 143 | 143 | <?php endif; ?> |
| 144 | - <p class="description"><?php echo wp_kses_post( $field['description'] ); ?></p> |
|
| 144 | + <p class="description"><?php echo wp_kses_post($field['description']); ?></p> |
|
| 145 | 145 | </td> |
| 146 | 146 | </tr> |
| 147 | 147 | <?php endforeach; ?> |
@@ -155,43 +155,43 @@ discard block |
||
| 155 | 155 | * |
| 156 | 156 | * @param int $user_id User ID of the user being saved |
| 157 | 157 | */ |
| 158 | - public function save_customer_meta_fields( $user_id ) { |
|
| 159 | - if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) { |
|
| 158 | + public function save_customer_meta_fields($user_id) { |
|
| 159 | + if (!apply_filters('getpaid_current_user_can_edit_customer_meta_fields', current_user_can('manage_options'), $user_id)) { |
|
| 160 | 160 | return; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | $save_fields = $this->get_customer_meta_fields(); |
| 164 | 164 | $save_data = array(); |
| 165 | 165 | |
| 166 | - foreach ( $save_fields as $fieldset ) { |
|
| 167 | - foreach ( $fieldset['fields'] as $key => $field ) { |
|
| 168 | - if ( strpos( $key, '_wpinv_' ) === 0 ) { |
|
| 169 | - $save_key = substr( $key , 7 ); |
|
| 166 | + foreach ($save_fields as $fieldset) { |
|
| 167 | + foreach ($fieldset['fields'] as $key => $field) { |
|
| 168 | + if (strpos($key, '_wpinv_') === 0) { |
|
| 169 | + $save_key = substr($key, 7); |
|
| 170 | 170 | } else { |
| 171 | 171 | $save_key = $key; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - if ( $save_key && isset( $field['type'] ) && 'checkbox' === $field['type'] ) { |
|
| 175 | - $save_data[ $save_key ] = ! empty( $_POST[ $key ] ) ? true : false; |
|
| 176 | - } else if ( $save_key && isset( $_POST[ $key ] ) ) { |
|
| 177 | - $save_data[ $save_key ] = wpinv_clean( $_POST[ $key ] ); |
|
| 174 | + if ($save_key && isset($field['type']) && 'checkbox' === $field['type']) { |
|
| 175 | + $save_data[$save_key] = !empty($_POST[$key]) ? true : false; |
|
| 176 | + } else if ($save_key && isset($_POST[$key])) { |
|
| 177 | + $save_data[$save_key] = wpinv_clean($_POST[$key]); |
|
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - if ( empty( $save_data ) ) { |
|
| 182 | + if (empty($save_data)) { |
|
| 183 | 183 | return; |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | - $customer = getpaid_get_customer_by_user_id( (int) $user_id ); |
|
| 186 | + $customer = getpaid_get_customer_by_user_id((int) $user_id); |
|
| 187 | 187 | |
| 188 | - if ( empty( $customer ) ) { |
|
| 189 | - $customer = new GetPaid_Customer( 0 ); |
|
| 190 | - $customer->clone_user( (int) $user_id ); |
|
| 188 | + if (empty($customer)) { |
|
| 189 | + $customer = new GetPaid_Customer(0); |
|
| 190 | + $customer->clone_user((int) $user_id); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - foreach ( $save_data as $key => $value ) { |
|
| 194 | - $customer->set( $key, $value ); |
|
| 193 | + foreach ($save_data as $key => $value) { |
|
| 194 | + $customer->set($key, $value); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | $customer->save(); |
@@ -205,12 +205,12 @@ discard block |
||
| 205 | 205 | * @param string $key Key for user meta field |
| 206 | 206 | * @return string |
| 207 | 207 | */ |
| 208 | - protected function get_user_meta( $user_id, $key ) { |
|
| 209 | - $value = get_user_meta( $user_id, $key, true ); |
|
| 210 | - $existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' ); |
|
| 208 | + protected function get_user_meta($user_id, $key) { |
|
| 209 | + $value = get_user_meta($user_id, $key, true); |
|
| 210 | + $existing_fields = array('_wpinv_first_name', '_wpinv_last_name'); |
|
| 211 | 211 | |
| 212 | - if ( ! $value && in_array( $key, $existing_fields ) ) { |
|
| 213 | - $value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true ); |
|
| 212 | + if (!$value && in_array($key, $existing_fields)) { |
|
| 213 | + $value = get_user_meta($user_id, str_replace('_wpinv_', '', $key), true); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | return $value; |
@@ -138,8 +138,11 @@ |
||
| 138 | 138 | </select> |
| 139 | 139 | <?php elseif ( ! empty( $field['type'] ) && 'checkbox' === $field['type'] ) : ?> |
| 140 | 140 | <input type="checkbox" name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" value="1" class="<?php echo esc_attr( $field['class'] ); ?>" <?php checked( (int) $value, 1, true ); ?> /> |
| 141 | - <?php else : ?> |
|
| 142 | - <input type="text" name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $value ); ?>" class="<?php echo ( ! empty( $field['class'] ) ? esc_attr( $field['class'] ) : 'regular-text' ); ?>" /> |
|
| 141 | + <?php else { |
|
| 142 | + : ?> |
|
| 143 | + <input type="text" name="<?php echo esc_attr( $key ); |
|
| 144 | +} |
|
| 145 | +?>" id="<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $value ); ?>" class="<?php echo ( ! empty( $field['class'] ) ? esc_attr( $field['class'] ) : 'regular-text' ); ?>" /> |
|
| 143 | 146 | <?php endif; ?> |
| 144 | 147 | <p class="description"><?php echo wp_kses_post( $field['description'] ); ?></p> |
| 145 | 148 | </td> |