不知何故,我的登录插件没有在注册时设置用户display_name。由于我在个人资料页面中使用了display_name meta,因此我尝试确保将其设置为某个值。这是代码:
<?php global $current_user;
get_currentuserinfo();
if ("" == trim($display_name)) {
$result = update_user_meta($user_id, 'display_name', $user_identity);
if ($result == false) {
echo "hi";
}
}
?>
此代码导致“hi”。我无法弄清楚为什么。
答案 0 :(得分:0)
它是user_ID
,带帽。我认为这可能是问题所在。
get_currentuserinfo()
返回的所有变量必须声明为全局变量。您要么声明所有这些,要么使用$current_user
。
答案 1 :(得分:0)
而不是$user_id
,请尝试使用$current_user->ID
答案 2 :(得分:0)
问题是display_name在update_user_meta中不可用。
要在注册时设置用户显示名称,您需要使用pre_user_display_name,如下所述:How to Use pre_user_display_name to set the display name