get_results("SELECT * FROM {$wpdb->prefix}ace_register_fields ORDER BY sortby ASC"); $success = ''; $errors = []; require_once plugin_dir_path(__FILE__) . 'countries.php'; if ($_SERVER['REQUEST_METHOD'] === 'POST') { // PROFILE IMAGE UPLOAD if (!empty($_POST['update_profile']) && check_admin_referer('ace_update_profile')) { handle_profile_image_upload($current_user->ID, $_FILES['profile_img'], $errors, $success); // Save custom fields $sanitized = Ace_User_Management_Function::sanitize($_POST); $meta_fields = array_combine( array_map(fn($k) => $k . '_', array_keys($sanitized)), $sanitized ); if (update_user_meta($current_user->ID, 'user_extrafields', $meta_fields)) { foreach ($sanitized as $key => $val) { update_user_meta($current_user->ID, $key, sanitize_text_field($val)); } $success .= "
Profile updated successfully.
"; } } // PASSWORD CHANGE if (!empty($_POST['change_password']) && check_admin_referer('ace_change_password')) { handle_password_change($current_user->ID, $_POST['password'], $_POST['confirm_password'], $errors, $success); } // ACCOUNT INFO if (!empty($_POST['account_info']) && check_admin_referer('ace_account_info')) { handle_account_info_update($current_user->ID, $_POST, $errors, $success); } } $user_extrafields_value = get_user_meta($current_user->ID, 'user_extrafields', true); $custom_avatar_url = get_user_meta($current_user->ID, 'custom_avatar', true); $profile_image = $custom_avatar_url ?: get_avatar_url($current_user->ID); $billing_fields_data = get_billing_fields_data($current_user->ID); ?>

Profile Image
Allowed JPG, GIF, or PNG. Max size 800K
Username
input_name); $field_value = esc_attr($user_extrafields_value[$field_name . '_'] ?? ''); ?>
input_type === 'text'): ?> input_type === 'textarea'): ?> input_type === 'dropdown'): ?>
'Billing Name', 'billing_last_name' => 'Billing Address', 'billing_company' => 'Company', 'billing_city' => 'City', 'billing_postcode' => 'State/Province', 'billing_zipcode' => 'Postal Code', 'billing_country' => 'Country', 'billing_phone' => 'Phone', ]; foreach ($billing_fields as $name => $label): ?>
800 * 1024) { $errors[] = "File too large. Max size: 800KB."; } elseif (!move_uploaded_file($file['tmp_name'], $target_file)) { $errors[] = "Failed to upload image."; } else { $uploaded_url = $upload_dir['url'] . '/' . basename($file['name']); update_user_meta($user_id, 'custom_avatar', esc_url($uploaded_url)); $success .= "
Profile image updated successfully.
"; } } function handle_password_change($user_id, $password1, $password2, &$errors, &$success) { if (strlen($password1) < 6) { $errors[] = __('! Password must be at least 6 characters long', 'ace-user-management'); } elseif (!preg_match('/[!@#$%^&*(),.?":{}|<>]/', $password1)) { $errors[] = __('! Password must contain at least one special symbol', 'ace-user-management'); } elseif ($password1 !== $password2) { $errors[] = __('! Confirm password does not match', 'ace-user-management'); } else { wp_set_password($password1, $user_id); $success .= "
Password updated successfully.
"; echo ''; } } function handle_account_info_update($user_id, $data, &$errors, &$success) { $fields = [ 'billing_first_name', 'billing_last_name', 'billing_company', 'billing_city', 'billing_postcode', 'billing_zipcode', 'billing_country', 'billing_phone' ]; foreach ($fields as $field) { if (isset($data[$field])) { update_user_meta($user_id, $field, sanitize_text_field($data[$field])); } } $success .= "
Billing information updated.
"; } function get_billing_fields_data($user_id) { $fields = [ 'billing_first_name', 'billing_last_name', 'billing_company', 'billing_city', 'billing_postcode', 'billing_zipcode', 'billing_country', 'billing_phone' ]; $data = []; foreach ($fields as $field) { $data[$field] = get_user_meta($user_id, $field, true); } return $data; } function display_errors_and_success($errors, $success) { foreach ($errors as $err) { echo "
" . esc_html($err) . "
"; } echo $success; } ?>