Quantcast
Channel: phpBB.com
Viewing all articles
Browse latest Browse all 2343

Extension Requests • Add DISPLAY NAME function, so users can change their names

$
0
0
Obviously people are stuck with their usernames once they register. Is it possible to add a new field, Display Name, to the forum, so people can keep changing how their names are displayed?

I actually asked this ChatGPT and this is the answer, can someone take a look please?

Steps to Add a Display Name Field in phpBB
  • Add a New Field to the Users Table
You'll need to add a column to the phpbb_users table to store the display name.

Code:

ALTER TABLE phpbb_users ADD user_display_name VARCHAR(255) NOT NULL DEFAULT '';
  • Modify the User Registration & Profile Edit Templates
In styles/YOUR_STYLE/template/ucp_profile_profile_info.html, add an input field for "Display Name":

Code:

    <div class="input-group">        <label for="display_name">Display Name:</label>        <input type="text" name="display_name" id="display_name" value="{USER_DISPLAY_NAME}" />    </div>
Add a similar field in ucp_register.html if you want users to set it during registration.

  • Modify the User Profile Handling in PHP
Update includes/ucp/ucp_profile.php to save the display name:

Code:

case 'profile_info':    $display_name = request_var('display_name', '', true);    if (!empty($display_name)) {        $sql = 'UPDATE ' . USERS_TABLE . ' SET user_display_name = "' . $db->sql_escape($display_name) . '" WHERE user_id = ' . $user->data['user_id'];        $db->sql_query($sql);    }    break;
  • Modify Templates to Show Display Name Instead of Username
In styles/YOUR_STYLE/template/viewtopic_body.html, change:

Code:

{postrow.POST_AUTHOR_FULL}
To:

Code:

{postrow.USER_DISPLAY_NAME}
Update includes/functions_display.php to fetch the display name:

Code:

        if (!empty($row['user_display_name'])) {            $user_display_name = $row['user_display_name'];        } else {            $user_display_name = $row['username'];        }
  • Purge Cache & Test


Go to ACP > "Purge Cache" to refresh the forum.
Test registration, profile updates, and post displays.

This will allow users to set a display name, which will be shown instead of their username in posts.

Statistics: Posted by Zinnn — Tue Feb 11, 2025 1:26 pm



Viewing all articles
Browse latest Browse all 2343

Trending Articles