Set custom field to non-editable
-
Hello, I’m looking for some help ??
I have a two custom fields for phone and company. All works well and is visible on the account page. I like to change the company field into a non-editable field.
The field is set to – not editable by user – in the registration form, though it seems that the custom code overwrites this setting and makes the custom field editable again for the user. I need company (bedrijf) to be not editable for the user, the same as the username is locked.
I’ve added this to my functions.php to add the extra meta fields:
// SHOW CUSTOM FIELDS ON ACCOUNT PAGE add_action('um_after_account_general', 'showUMExtraFields', 100); function showUMExtraFields() { $id = um_user('ID'); $output = ''; $names = array('phone_number', 'company_name'); $fields = array(); foreach( $names as $name ) $fields[ $name ] = UM()->builtin()->get_specific_field( $name ); $fields = apply_filters('um_account_secure_fields', $fields, $id); foreach( $fields as $key => $data ) $output .= UM()->fields()->edit_field( $key, $data ); echo $output; } add_action('um_account_pre_update_profile', 'getUMFormData', 100); function getUMFormData(){ $id = um_user('ID'); $names = array('phone_number', 'company_name'); foreach( $names as $name ) update_user_meta( $id, $name, $_POST[$name] ); }
Picture of account: https://ibb.co/5Md53kP
- The topic ‘Set custom field to non-editable’ is closed to new replies.