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 ( isset( $_FILES['profile_img'] ) && ! empty( $_FILES['profile_img']['name'] ) ) { $file = [ 'name' => sanitize_file_name( $_FILES['profile_img']['name'] ), 'type' => isset( $_FILES['profile_img']['type'] ) ? sanitize_mime_type( $_FILES['profile_img']['type'] ) : '', 'tmp_name' => isset( $_FILES['profile_img']['tmp_name'] ) ? sanitize_text_field( $_FILES['profile_img']['tmp_name'] ) : '', 'error' => isset( $_FILES['profile_img']['error'] ) ? intval( $_FILES['profile_img']['error'] ) : 0, 'size' => isset( $_FILES['profile_img']['size'] ) ? intval( $_FILES['profile_img']['size'] ) : 0, ]; $file_name = $file['name']; // Allowed mime types $allowed_mime = [ 'image/jpeg', 'image/gif', 'image/png' ]; // Validate file type using WordPress function $filetype = wp_check_filetype( $file_name ); if ( ! in_array( $filetype['type'], $allowed_mime, true ) ) { $errors[] = esc_html__( 'Invalid file type. Allowed: JPG, GIF, PNG.', 'ace-user-management' ); } elseif ( $file['size'] > 800 * 1024 ) { // Max 800KB $errors[] = esc_html__( 'File too large. Max size: 800KB.', 'ace-user-management' ); } else { // Use WordPress to handle upload safely $overrides = [ 'test_form' => false ]; $movefile = wp_handle_upload( $file, $overrides ); if ( $movefile && ! isset( $movefile['error'] ) ) { update_user_meta( $current_user->ID, 'custom_avatar', esc_url( $movefile['url'] ) ); $success[] = esc_html__( 'Profile image updated successfully.', 'ace-user-management' ); } else { $errors[] = isset( $movefile['error'] ) ? esc_html( $movefile['error'] ) : esc_html__( 'Failed to upload image.', 'ace-user-management' ); } } } // 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_safe_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] ?? get_user_meta(get_current_user_id(), $field_name, true)); ?>
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): ?>