WordPress后台有一独立的个人资料页,默认是英文用户格式,确实有点本地化不够强,水土不合。这时就有必要重新打造一下列表项目。
增减(自定义)用户个人资料的基本函数是$contactmethods[] 和unset($contactmethods[])。
示例:
一、增加一个手机号字段,删除一个google账号字段。 //设置个人资料相关选项 function my_profile( $contactmethods ) { $contactmethods['user_phone'] = '手机号'; unset($contactmethods['google']); return $contactmethods; } add_filter('user_contactmethods','my_profile');
二、获取新增的用户个人资料,输出某用户的手机号码
1直接输出
<?php the_author_meta(‘user_phone’); ?>
2、对返回值判断后输出
<?php if (get_the_author_meta('user_phone')!=""); ?>
注:the_author_meta()可以直接输出手机号码查询结果,get_the_author_meta()则带有reture返回值,可以增加一个判断条件。
总结:WordPress增减(自定义)及获取用户个人资料的基本方法,主要是熟悉contactmethods、unset、the_author_meta和get_the_author_meta四个函数的基本用法。当然,个人资料涉及到前后台权限的问题,实际生产环境中操作起来很是复杂,以上只是抛砖引玉,仅初学者供参考。