Wordpress:在表单中显示$ current_user-> display_name只读输入字段
问题描述:
我想在只读的表单输入字段中显示wordpress登录用户名(显示名称)。
我已经通过Function Reference/wp get current user但没有成功。
找我的代码,我尝试:
public static function getFormHTML($form) {
global $wpdb, $display_name;
get_currentuserinfo();
$html = '<form>';
/*-------Below line in displaying user display name----------------*/
$html .= '<input name="currentusr" value="' . $current_user->display_name. '" type= "text" readonly />';
$html = '</form>';
我无法揣摩出我做错了..
请帮我解...
谢谢提前。
答
而不是使用readonly
,请尝试使用disabled
属性。例如:
$html .= '<input name="currentusr" value="' . $current_user->display_name . '" type="text" disabled />';
已尝试**禁用**但仍未显示**用户名** – user3423283
您从哪里获取您的'$ current_user'对象?我没有在你的代码中看到它。 – henrywright
嘿@henrywright,谢谢你提出的观点,我发现错误,因为我错误不包括'$ current_user = wp_get_current_user();'而不是'get_currentuserinfo();' – user3423283