admin管理员组文章数量:1287829
I want to create my own form in order to get information on my site. For learning purposes, I do not want to use a plugin. So, please don't tell me to use one. I know they are easy to use, but I want to get under the hood in WordPress.
I would like to populate my form with email and name if the user is logged in, but I am a bit at a loss on how to do this. Maybe a javascript snippet or a bit of PHP?
I don't know which is better or the standard now. It's been a while and I really want to try doing this on my own.
Please any Gurus can you help?
I want to create my own form in order to get information on my site. For learning purposes, I do not want to use a plugin. So, please don't tell me to use one. I know they are easy to use, but I want to get under the hood in WordPress.
I would like to populate my form with email and name if the user is logged in, but I am a bit at a loss on how to do this. Maybe a javascript snippet or a bit of PHP?
I don't know which is better or the standard now. It's been a while and I really want to try doing this on my own.
Please any Gurus can you help?
Share Improve this question asked Sep 10, 2021 at 6:43 MacMac 1 1- Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Bot Commented Sep 13, 2021 at 15:28
1 Answer
Reset to default 0I am assuming you are using third party forms, if yes Then you have to use Javascript and PHP. You can paste this code in shortcode or you have to use hooks, as you are learning please go through this Link
PHP CODE
if ( is_user_logged_in() )
{
$current_user = wp_get_current_user();
$email = $current_user->user_email
}
See the documentation for wp_get_current_user()
Now as you have $email you can save that $email to JavaScript something like this
<script>var email = <?PHP echo $email ?></script>
Now using this var you can populate these user details to the form.
If you face any issue let me know.
本文标签: customizationNo plugin populate user information in to form
版权声明:本文标题:customization - No plugin populate user information in to form 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741327535a2372574.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论