我已经在这方面工作了一段时间了,我一辈子都搞不懂这一点。这是我目前的代码。
add_action(\'user_register\',\'create_new_user_profile\', 999);
function create_new_user_profile($user_id){
if (!$user_id>0)
return;
$user_info = get_userdata($user_id);
$profile_full_name = $user_info->first_name . " " . $user_info->last_name;
$profile_post = array(
\'post_title\' => $profile_full_name,
\'post_content\' => \'This is the profile post.\',
\'post_status\' => \'publish\',
\'post_type\' => \'Team\',
\'post_author\' => $user_id
);
$profile = wp_insert_post( $profile_post );
}
我尝试了几种方法并搜索了一段时间,当前代码返回了一个空字符串,但通过其他替代方法,我可以发布用户名或user\\u id作为标题,但我无法获得display\\u名称或我需要的名字和姓氏的组合。
最合适的回答,由SO网友:czerspalace 整理而成
这个get_userdata 功能是您需要的。因此,对于display\\u名称
$user_info = get_userdata($user_id);
$profile_display_name = $user_info->display_name;
至于名字和姓氏
$full_name = $user_info->first_name . " " . $user_info->last_name;