First off I just wanted to say that this is my first question on StackOverflow, so I want to apologize now since I will probably make some mistakes writing this.
So I got a wordpress website with user login feature and I'm offering support through the Zendesk Web Widget which basically is a support contact form. I'm trying to pre-populate the Display Name & Email fields in the support form with the current logged-in user information.
Throught my research, I found that Wordpress already has a function for this : get_currentuserinfo(), and that I could pass the data to javascript by adding this to my functions.php child theme :
function get_user($type = 'ID')
{
global $current_user;
get_currentuserinfo();
switch ($type)
{
case 'ID':
return $current_user->ID;
break;
case 'displayname':
return $current_user->display_name;
break;
case 'username':
return $current_user->user_login;
break;
case 'firstname':
return $current_user->user_firstname;
break;
case 'lastname':
return $current_user->user_lastname;
break;
case 'level':
return $current_user->user_level;
break;
case 'email':
return $current_user->user_email;
break;
default:
return;
}
}
And by using echo get_user('displayname');
to use the display name in javascript.
Source : http://www.devdevote.com/cms/wordpress-hacks/get_user
So I made some attempts with it, but none worked out. I tried these :
Attempt 1 :
<script>
var $wpName = <?php echo get_user('displayname') ?>;
var $wpEmail = <?php echo get_user('email') ?>;
zE(function() {
zE.identify({
name: $wpName,
email: $wpEmail
});
});
</script>
Attempt 2 :
<script>
zE(function() {
zE.identify({
name: <?php echo get_user('displayname') ?>,
email: <?php echo get_user('email') ?>
});
});
</script>
Attempt 3 :
<script>
var $wpName = $current_user->user_firstname;
var $wpEmail = $current_user->user_email;
zE(function() {
zE.identify({
name: <?php echo get_user('displayname') ?>,
email: <?php echo get_user('email') ?>
});
});
</script>
Does anyone out here have an idea or just a clue on how to to do this ? I've been struggling all day trying to make this work, reading about 20 to 30 threads on the subject, but none had a working solution for me..
P.S. Once again I'm sorry if I made a mistake posting here or if I didn't write out my question well, this is my first time !