简体   繁体   English

如何在Wordpress中向用户添加自定义联系人字段

[英]How to add custom contact fields to the user in wordpress

I have been trying to add some custom fields to the user profile but for some reason it does not work. 我一直在尝试向用户配置文件中添加一些自定义字段,但是由于某种原因它无法正常工作。

I added the following code to the functions.php: 我将以下代码添加到functions.php中:

 //FUNCTION for custom profile fields
function modify_contact_methods($user_contactmethods) {

    // Add new fields
    $user_contactmethods['user-address'] = 'Address';
    $user_contactmethods['user-telephone'] = 'Telephone';
    $user_contactmethods['user-avatar'] = 'Avatar';

    return $user_contactmethods;
}
add_filter('user_contactmethods', 'modify_contact_methods');

It looks fine to me but I still don't see the new fields in the user profile in admin. 对我来说看起来不错,但在admin的用户个人资料中我仍然看不到新字段。 Do I have to do anything besides this code to make it work? 为了使此代码正常工作,我是否需要做其他任何事情? Or maybe my code is wrong? 也许我的代码是错误的? Any help or tips would be appreciated. 任何帮助或提示,将不胜感激。

It seems correct. 看来是对的。 Have you checked by adding some priority in filter. 您是否通过在过滤器中添加一些优先级来进行检查。 You can do like this 你可以这样

add_filter('user_contactmethods', 'modify_contact_methods',99);

Use this plugin for add extra user fields in wordpress. 使用此插件可在wordpress中添加额外的用户字段。

Plugin for add extra user fields 用于添加额外用户字段的插件

extra-user-fields



http://wordpress.org/plugins/extra-user-fields/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM