Moodle is a widely used open-source learning management system (LMS) that provides a platform for educators to create and manage online courses. As an administrator of a Moodle site, you may need to customize certain aspects of the system to suit your specific needs. One common requirement is adding a new column to the user list table in the Moodle administrator interface. This can be useful for displaying additional user information or custom data. In this article, we will guide you through the process of adding a new column to the Moodle administrator user list table.
Prerequisites
Before we begin, ensure that you have the following:
- Access to the Moodle administrator account.
- Basic understanding of PHP and MySQL.
- Familiarity with Moodle's file structure and customization methods.
Step 1: Locate the Appropriate File
To add a new column to the user list table, we need to modify the Moodle core code. This should be done with caution, as any changes made directly to the core code may be overwritten during Moodle updates. Here's how to locate the file we need to modify:
1. Log in to your Moodle administrator account.
2. Navigate to the `admin` folder in your Moodle installation directory.
3. Look for the file named `user.php` within the `admin` folder. This is the file we'll be modifying.
Step 2: Edit the `user.php` File
Now that we've located the `user.php` file, let's proceed with adding the new column. Follow these steps:
1. Make a backup copy of the `user.php` file before making any modifications. This ensures that you can revert to the original code if needed.
2. Open the `user.php` file in a text editor of your choice.
Step 3: Add the New Column Code
To add the new column, we'll need to modify the HTML table structure and the corresponding PHP code. Follow these steps:
1. Find the line that defines the `<table>` tag. It should look something like this: `<table class="admintable generaltable" id="adminusers">` or something like ` $table->attributes['class'] = 'admintable generaltable`.
2. Add a new table header cell looks like this `$table->head[] = 'Heading Title'`.
3. Scroll down further until you find the section that starts with `$row[] =`. This is the section for adding new rows.
4. Add a new table cell `<td>` just below the existing table cell. For example: `$row[] = $user->username;`. I added username data here.
5. Save the changes to the `user.php` file.
Step 4: Test and Verify
After saving the modified `user.php` file, you should test and verify that the new column appears correctly in the Moodle administrator user list table. Here's how:
1. Log in to your Moodle administrator account.
2. Navigate to the user list or user management section.
3. Check if the new column is displayed alongside the existing columns in the user list table.
4. Verify that the data or information you intended to display in the new column is correctly populated for each user.
Conclusion
By following the steps outlined in this article, you should be able to add a new column to the Moodle administrator user list table. Remember to exercise caution when modifying core files, as changes made directly to the core code may be overwritten during Moodle updates. Customizations like this can enhance the functionality of your Moodle site and provide additional insights into user data.

2 Comments
This comment has been removed by the author.
ReplyDeleteHow will I add a custom profile field to the row?
ReplyDelete