admin管理员组文章数量:1122832
I have a site with extended profile fields. I can't find the particular way of adding an additional column as:
Username | Name | Email | Site Role | Discord (this is the additional column)
The extended profile has a text field called "Discord". How do I go on about making it display in one of the columns?
I have a site with extended profile fields. I can't find the particular way of adding an additional column as:
Username | Name | Email | Site Role | Discord (this is the additional column)
The extended profile has a text field called "Discord". How do I go on about making it display in one of the columns?
Share Improve this question edited Aug 5, 2023 at 13:06 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Aug 5, 2023 at 12:09 Shoaib QaziShoaib Qazi 31 bronze badge2 Answers
Reset to default 0To add an extra column to the user list in WordPress, you can follow these steps:
- Register a Settings Page: Start by creating a settings page where you can define the additional columns you want to add. This page will allow you to manage the custom columns effectively.
- Save Custom Column Names: On the settings page, provide a text input where you can enter the names of the custom columns you want to add. Separate the column names with commas.
- Display the Custom Column: To display the custom column in the user
list, you'll need to hook into the
manage_users_columns
filter. Use this filter to add your custom columns to the list of columns. - Populate Column Data: When displaying user data in your custom
column, you can use the
manage_users_custom_column
filter. This filter lets you customize the content of your custom column for each user. - Collect User Data: To collect data for the custom column, you'll need
to update user metadata. You can use actions like
user_register
(for new user registration) oredit_user_profile_update
(for profile updates) to save the data to user meta. - Editing User Profiles: When adding new users or editing existing profiles, you should provide input fields for the custom columns on the user creation/editing pages.
If you'd like a practical example to see how these steps come together, you can refer to this GitHub repository . This repository contains a sample plugin i have created that demonstrates how to add and manage additional columns in the user list using WordPress hooks and filters. It serves as a helpful reference for implementing this feature on your site.
By following these general steps and referring to the provided example, you can add custom columns to the user list in WordPress and display additional information tailored to your site's needs.
I actually wrote a tutorial on how to add custom columns to the WordPress users dashboard which is easy to follow if anyone is looking for a useful guide.
Here is the sample code for adding a Discord column specifically. The code does assume that the "key" for the discord field is simple "discord" and can be retrieved via get_user_meta.
// Adds the new discord column to the users dashboard.
function add_discord_column_to_users_dashboard( $columns ) {
$new_columns = [
'discord' => esc_html__( 'Discord', 'text_domain' ),
];
return array_merge( $columns, $new_columns );
}
add_filter( 'manage_users_columns' , 'add_discord_column_to_users_dashboard' );
// Populate our custom discord users dashboard column.
function populate_users_dashboard_discord_column( $output, $column_name, $user_id ) {
if ( 'discord' === $column_name ) {
$output = get_user_meta( $user_id, 'discord', true ) ?: '-';
}
return $output;
}
add_filter( 'manage_users_custom_column', 'populate_users_dashboard_discord_column', 10, 3 );
本文标签: Add Additional Column in quotUsersquot Dashboard AreaBP Extended Profiles (WordPress)
版权声明:本文标题:Add Additional Column in "Users" Dashboard Area - BP Extended Profiles (WordPress) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736296923a1929902.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论