Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php wordpress更新\用户\元莫名其妙地不工作_Php_Wordpress_Function - Fatal编程技术网

Php wordpress更新\用户\元莫名其妙地不工作

Php wordpress更新\用户\元莫名其妙地不工作,php,wordpress,function,Php,Wordpress,Function,不知何故,我的登录插件没有设置注册时的用户显示名称。因为我在我的个人资料页面中使用了display_name meta,所以我试图确保它被设置为某个值。代码如下: <?php global $current_user; get_currentuserinfo(); if ("" == trim($display_name)) { $result = update_user_meta($user_id, 'display_name', $user_iden

不知何故,我的登录插件没有设置注册时的用户显示名称。因为我在我的个人资料页面中使用了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。我不明白为什么

它是用户ID,带有大写字母。我想这可能就是问题所在


get_currentuserinfo返回的所有变量必须声明为全局变量。您可以声明所有这些属性或使用$current\u user。

请尝试使用$current\u user->id来代替$user\u id

问题是在更新\u user\u meta中显示\u名称不可用


要在注册时设置用户显示名称,您需要使用pre_user_display_name,如下所述:

谢谢您的回复。不幸的是,这并没有解决问题。请尝试将以下变量也声明为全局变量:$display\u name、$user\u ID、$user\u identity。否则,使用已声明的$current_user one,如下所示: