简体   繁体   English

带有用户名的WordPress自动填充表单

[英]WordPress autofill form with user name

I have a WordPress site with forms on it. 我有一个WordPress网站,上面有表格。 I am trying to autofill the name field in the form with the login name from WordPress. 我正在尝试使用WordPress的登录名自动填充表单中的名称字段。 How can I do this? 我怎样才能做到这一点? I tried some php get current user name but that did not work. 我尝试了一些php get current user name但是没有用。 Any help will be greatly appreciated. 任何帮助将不胜感激。

<?php
//get current username
global $ current_user; 
$current_user=wp_get_current_user();
$cuname=$current_user-> user_name; ?>

// in the  form
value="<?php echo $cuname; ?>" read only

您具有user_name ,但应为user_login

$cuname = $current_user->user_login

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM