Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.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_Utf 8_Wordpress_Gravity Forms Plugin - Fatal编程技术网

Php 如何在wordpress中获取用户名?

Php 如何在wordpress中获取用户名?,php,utf-8,wordpress,gravity-forms-plugin,Php,Utf 8,Wordpress,Gravity Forms Plugin,下面是我在wordpress functions.php中的代码。我想在gravity表单字段中显示用户信息顶部的函数起作用,但底部的函数不起作用,我也不知道用什么来显示名字 add_filter('gform_field_value_pm_id', 'populate_pm_id'); function populate_pm_id($value){ return $user_ID = get_current_user_id(); echo $user_ID = get_cu

下面是我在wordpress functions.php中的代码。我想在gravity表单字段中显示用户信息顶部的函数起作用,但底部的函数不起作用,我也不知道用什么来显示名字

add_filter('gform_field_value_pm_id', 'populate_pm_id');
function populate_pm_id($value){
    return $user_ID = get_current_user_id(); 
    echo $user_ID = get_current_user_id(); 

}

add_filter('gform_field_value_pm_firstname', 'populate_pm_firstname');
function populate_pm_firstname($value){
    return $user_info->first_name = get current_user_first_name(); 
    echo $user_info->first_name = get_current_user_first_name();

}

请尝试使用此代码获取用户名和姓氏

<?php 
      $user_info = get_userdata(get_current_user_id());
      $first_name = $user_info->first_name;
      $last_name = $user_info->last_name;
      echo "$first_name $last_name";
?>


似乎可以工作,但现在我得到一个相关的可捕获致命错误:WP_User类的对象无法在第766行的/WP includes/formatting.php中转换为字符串。我发现了一条与之相关的线索。似乎这与空返回冲突。谢谢!看起来它现在应该可以工作了,但我发现了一个相关的错误。如果你想看的话,我已经开始另一个线程。