This guide explains how to create and configure custom user fields in Discourse, including how to add them to the signup form, user profiles, and user directory.
Required user level: Administrator
Custom user fields allow you to collect additional information from your users beyond the standard profile fields. These fields can be displayed on user cards, user summary pages, and even retrieved using the Data Explorer plugin. This guide will walk you through the process of creating and configuring custom user fields.
Adding a user field
Go to Admin > Community > User Fields (discourse.example.com/admin/config/user-fields).
If you haven’t created any user fields yet, you’ll see this screen:
Optional - Optional fields may be left empty by users
For all users - When a field is required by all users, every account, including logged on users will be forced to fill it. This is very useful for cases such as a terms-of-service (ToS) requirement.
On signup - All new account will be required to fill the field.
Additionally, at the bottom of the creation form, you’ll find these options:
Editable after signup: Allows users to update the field from their profile page
Required at signup: Makes the field mandatory during account creation
Show on public profile: Displays the field value on the user’s summary page
Show on user card: Shows the field value on the user card
Searchable: Enables searching for users based on this field’s value in the user directory
Show on public profile
When enabled, the field value will be shown on the user’s profile page:
هل هناك إعداد يجب تعديله لتحديد الحد الأقصى لطول حقل مستخدم مخصص؟ حاليًا، في حقل “Test” هذا الذي أنشأته كحقل مستخدم اختباري، لا يمكنني إدخال حرف واحد في ملف تعريف المستخدم الخاص بي (أو حتى “Test”، كما هو موضح).
هل يمكنني ربط مطالبة مخصصة من Auth0 SSO الخاص بي بحقل مخصص؟ حاليًا، يدخل المستخدم معلومات الحقل في Auth0، ثم يضطر إلى إدخالها مرة أخرى عند التسجيل. أود تعيين القيمة إذا أمكن.
هل هناك طريقة للتحقق من اسم الحقل في قاعدة البيانات؟ على سبيل المثال، لدينا حقل الاسم الأول، جربت custom.firstname و custom.first_name و custom.firstName، ولم يؤدِ أي منها إلى ملء الحقول في شاشة التسجيل.
لقد تحققت من سجلات الأخطاء للتأكد من أن حقول الرمز المميز تأتي كما هو موضح أعلاه.
يجب أن يكون بناء الجملة custom.user_field_x، حيث x هو معرف الحقل الرقمي المعروض في /admin/config/user-fields/{x}/edit.
ميزة التعيين هذه غير متوفرة في إضافة Auth0 مباشرة.
ومع ذلك، لا تزال هناك خيارات لتحقيق ما تصفه:
إنشاء مكون سمة. يمكنك إضافة نص برمجي صغير للواجهة الأمامية يقوم تلقائيًا بمزامنة حقل مستخدم مخصص في Discourse مع قيمة مخزنة بالفعل في Auth0. على سبيل المثال، عند تسجيل دخول المستخدم وكان الحقل فارغًا، يمكن للنص البرمجي استدعاء نقطة نهاية آمنة (وظيفة سحابية صغيرة) تجلب قيمة الحقل من Auth0 وتحدث ملف تعريف Discourse عبر واجهة برمجة التطبيقات (API).
استخدام أدوات الأتمتة. يمكنك أيضًا استخدام خدمات الأتمتة الخارجية مثل Zapier أو Make لأداء هذه المزامنة خارج Discourse. الميزة هي أنك لا تحتاج إلى كتابة/صيانة التعليمات البرمجية ولكنك تدفع فقط مقابل خدمة الطرف الثالث.
تطوير مخصص. يمكننا توسيع إضافة Auth0 نفسها لدعم تعيين المطالبات المخصصة في حقول المستخدم عند تسجيل الدخول بشكل أصلي، أو بناء إضافة مخصصة تعمل بالتوازي مع إضافة Auth0.
العيب الواضح لنهج مكون السمة هو أنك ستحتاج إلى كتابة وصيانة التعليمات البرمجية المخصصة بنفسك، مع توخي الحذر أيضًا من الناحية الأمنية لتجنب إدخال أخطاء أو ثغرات محتملة. بصراحة، هذا ليس حلاً أوصي به لموقع إنتاجي مثل موقعك.
لو كنت مكانك، لفضلت الخيار الثاني، باستخدام أدوات الطرف الثالث، أو النظر في تقديم طلب ميزة أو طلب عمل مخصص (اعتمادًا على تقييم مديري المشاريع لدينا) لتعزيز إضافة Auth0 نفسها.
إذا كنت مهتمًا باستكشاف الخيار الأخير، يمكننا مواصلة المناقشة بشكل خاص.