get_results("SELECT * FROM {$wpdb->prefix}ace_register_fields ORDER BY sortby ASC"); $success = ''; $errors = []; require_once plugin_dir_path(__FILE__) . 'countries.php'; if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') { if (!empty($_POST['update_profile']) && check_admin_referer('ace_update_profile')) { if (!empty($_FILES['profile_img']['name'])) { $file = $_FILES['profile_img']; $allowed_types = ['image/jpeg', 'image/gif', 'image/png']; $file_name = sanitize_file_name($file['name']); $file_type = $file['type']; $file_size = $file['size']; $upload_dir = wp_upload_dir(); $target_file = $upload_dir['path'] . '/' . basename($file['name']); // Validate file type and size if (!in_array($file['type'], $allowed_types)) { $errors[] = "Invalid file type. Allowed: JPG, GIF, PNG."; } elseif ($file['size'] > 800 * 1024) { // 800KB max size $errors[] = "File too large. Max size: 800KB."; } else { $uploaded_url = wp_upload_bits($file['name'], null, file_get_contents($file['tmp_name'])); if ($uploaded_url['error']) { $errors[] = "Failed to upload image: " . $uploaded_url['error']; } else { update_user_meta($current_user->ID, 'custom_avatar', esc_url($uploaded_url['url'])); $success .= "Profile image updated successfully."; } } } // 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')) { $pass1 = isset($_POST['password']) ? sanitize_text_field(wp_unslash($_POST['password'])) : ''; $pass2 = isset($_POST['confirm_password']) ? sanitize_text_field(wp_unslash($_POST['confirm_password'])) : ''; // Function to check if the password is strong function is_strong_password($password) { return preg_match('/^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/', $password); } if ($pass1 && $pass1 === $pass2) { if (!is_strong_password($pass1)) { $errors[] = "Your password must be at least 8 characters long, contain at least one letter, one number, and one special character."; } else { wp_set_password($pass1, $current_user->ID); wp_logout(); wp_redirect(wp_login_url()); exit; } } else { $errors[] = "Passwords do not match or are empty."; } } // ACCOUNT INFO if (!empty($_POST['account_info']) && check_admin_referer('ace_account_info')) { $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($_POST[$field])) { update_user_meta($current_user->ID, $field, sanitize_text_field(wp_unslash($_POST[$field]))); } } $success .= "Billing information updated."; } } // Get user meta and other info $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 = []; $billing_fields = [ 'billing_first_name', 'billing_last_name', 'billing_company', 'billing_city', 'billing_postcode', 'billing_zipcode', 'billing_country', 'billing_phone' ]; foreach ($billing_fields as $field) { $billing_fields_data[$field] = get_user_meta($current_user->ID, $field, true); } ?>

" . esc_html($err) . "
"; } // Display success messages if (!empty($success)) { echo "
" . esc_html($success) . "
"; } ?>
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): ?>