如何在后台显示注册的自定义用户元?

时间:2013-10-17 作者:gstricklind

我正在考虑使用WordPress注册表的挂钩来添加一些自定义字段:https://codex.wordpress.org/Customizing_the_Registration_Form

我的问题是,如果可能的话,如何在后端用户>所有用户中显示这些自定义字段?例如,如果我有“邮政编码”和“地址”字段,我将如何在后端显示这些数据?谢谢

2 个回复
最合适的回答,由SO网友:gstricklind 整理而成

事实上,我发现这更直接、更简单:

//add columns to User panel list page
function add_user_columns($column) {
    $column[\'address\'] = \'Street Address\';
    $column[\'zipcode\'] = \'Zip Code\';

    return $column;
}
add_filter( \'manage_users_columns\', \'add_user_columns\' );

//add the data
function add_user_column_data( $val, $column_name, $user_id ) {
    $user = get_userdata($user_id);

    switch ($column_name) {
        case \'address\' :
            return $user->address;
            break;
        default:
    }
    return;
}
add_filter( \'manage_users_custom_column\', \'add_user_column_data\', 10, 3 );
有关自定义列挂钩的更多信息,请参见:http://tareq.wedevs.com/2011/07/add-your-custom-columns-to-wordpress-admin-panel-tables/

SO网友:brasofilo

要在用户页面中显示用户元数据,需要使用过滤器manage_users_custom_columnmanage_users_columns: Sortable Custom Columns in User Panel (users.php)?

要在用户/配置文件页面中添加字段,请执行以下操作(来自Checkboxes in registration form):

// PROFILE
add_action( \'show_user_profile\', \'user_field_wpse_87261\' );
add_action( \'personal_options_update\', \'save_profile_fields_87261\' );

// USER EDIT
add_action( \'edit_user_profile\', \'user_field_wpse_87261\' );
add_action( \'edit_user_profile_update\', \'save_profile_fields_87261\' );

结束

相关推荐

Extend the wp_users table

我想延长wp_users 我的WordPress数据库中的表为什么?我希望人们在我的网站上唱歌时能增加更多关于自己的信息。我知道如何扩展它,但我担心当WordPress需要更新时wp_users 表,即我添加的列,将被删除。我这里有任何人在扩展wp_users 桌子更新WordPress版本时,是否会更新此表?