# Setting Up Login and Registration

GravityOps Forum allows you to provide a seamless authentication experience by mapping Gravity Forms to the WordPress login and user registration processes.

---

## 1. Overview
Instead of redirecting users to the standard WordPress login page, you can embed login and registration forms directly within your forum. This keeps users on your site and provides a consistent design.

## 2. Configuration Steps

### Step 1: Create Your Forms
Create two separate Gravity Forms in your WordPress dashboard:
1.  **Login Form**: Should include at least a "Username or Email" and a "Password" field.
    -   **Pro Tip**: Configure the Password field to **Enable Password Visibility Toggle** to help users log in without errors.
2.  **Registration Form**: Should include "Username," "Email," and "Password" (required). You can also include fields for "Nickname" and "Display Name."
    -   **Pro Tip**: For the registration Password field, enable **Password Confirmation** to prevent users from accidentally registering with a typo in their password. You should also consider enabling the **Password Strength** meter.

### Step 2: Map the Forms
1.  Navigate to **Forms > GravityOps > Forum** and select the **Forms** tab.
2.  Click **Add New Assignment**.
3.  For the **Login Form**:
    -   Set **Form Type** to "Login" (entity type will automatically be set to "Global Default").
    -   Select your created Login Form.
    -   Map the **Username/Email** and **Password** fields.
    -   Click **Save Assignment** and now guest users will be able to log in.
4.  For the **Registration Form**:
    -   Set **Form Type** to "Registration" (entity type will automatically be set to "Global Default").
    -   Select your created Registration Form.
    -   Map the **Username**, **Email**, and **Password** fields.
    -   (Optional) Map the **Nickname** and **Display Name** fields.
    -   Click **Save Assignment** and now guest users will be able to register.

---

## 3. The User Experience
-   **Immediate Activation**: When a user registers, they are automatically logged in and can start participating immediately.
-   **Profile Updates**: Logged-in users can use the same registration form to update their profile information (Email, Nickname, Display Name, and Password). The Username field remains read-only for existing users.
-   **No Extra Emails**: Standard WordPress "New User" emails are suppressed because the user sets their own password during registration.
-   **Seamless Redirects**: If a user was trying to access a specific topic before logging in, they will be returned to that topic after successful authentication.

## 4. Security

- **Fixed Registration Role**: All accounts created through public registration are hard-locked to the **Subscriber** role. This cannot be changed.

## 5. Developer Customization

### Disabling Profile Updates
By default, the registration form allows logged-in users to update their profile. You can disable this behavior using the following filter:

```php
add_filter( 'gofrm_enable_profile_editing', '__return_false' );
```

### Profile Sub-pages
The user profile page can be extended with custom tabs. The plugin looks for a `profile_path` and fires the following hooks:
-   `gofrm_profile_subpage_{slug}`: Targeted hook for a specific sub-page.
-   `gofrm_profile_subpage`: General hook that passes the current slug.

### Custom Redirects
The system uses the `gofrm_redirect` query parameter to manage post-authentication navigation.

-   **Automatic Handling**: If a guest accesses a restricted URL, the system automatically appends the current URL to `gofrm_redirect` and redirects the user to the profile/login interface.
-   **Form Persistence**: The `gofrm_redirect` value is automatically passed into the Login and Registration forms and handled during submission.
-   **Manual Usage**: You can manually trigger the login interface with a specific redirect:
    `your-site.com/forum/profile/?gofrm_redirect=/your-custom-page/`
