$field_data) {
if (isset($_POST[$meta_key])) {
$sanitized_value = sanitize_textarea_field($_POST[$meta_key]);
update_user_meta($user_id, $meta_key, $sanitized_value);
}
}
}
}
/**
* Get King Addons custom fields for a user
*/
private static function get_king_addons_custom_fields($user_id)
{
$custom_fields = [];
$all_meta = get_user_meta($user_id);
foreach ($all_meta as $meta_key => $meta_value) {
// Check if it's a King Addons custom field (but not a label)
if (strpos($meta_key, 'king_addons_custom_field_') === 0 && strpos($meta_key, '_label') === false) {
$field_value = is_array($meta_value) && count($meta_value) === 1 ? $meta_value[0] : $meta_value;
// Try to get the field label
$label_key = $meta_key . '_label';
$field_label = get_user_meta($user_id, $label_key, true);
$custom_fields[$meta_key] = [
'value' => $field_value,
'label' => !empty($field_label) ? $field_label : ucwords(str_replace(['king_addons_custom_field_', '_'], ['', ' '], $meta_key))
];
}
}
return $custom_fields;
}
}