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
Add a comment  | 

1 Answer 1

Reset to default 0

I 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