title: Passing Wordpress $current_user data to be used in embbebed javascript to pre-populate form fields
body: <p>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.</p>
  
  <p>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 &amp; Email fields in the support form with the current logged-in user information. </p>
  
  <p>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 : </p>
  
  <pre><code>function get_user($type = 'ID')
  {
       global $current_user;
       get_currentuserinfo();
  
       switch ($type)
       {
            case 'ID':
                 return $current_user-&gt;ID;
                 break;
            case 'displayname':
                 return $current_user-&gt;display_name;
                 break;
            case 'username':
                 return $current_user-&gt;user_login;
                 break;
            case 'firstname':
                 return $current_user-&gt;user_firstname;
                 break;
            case 'lastname':
                 return $current_user-&gt;user_lastname;
                 break;
            case 'level':
                 return $current_user-&gt;user_level;
                 break;
            case 'email':
                 return $current_user-&gt;user_email;
                 break;
            default:
                 return;
       }
  }
  </code></pre>
  
  <p>And by using <code>echo get_user('displayname');</code> to use the display name in javascript.</p>
  
  <blockquote>
    <p>Source : <a href="http://www.devdevote.com/cms/wordpress-hacks/get_user" rel="nofollow">http://www.devdevote.com/cms/wordpress-hacks/get_user</a></p>
  </blockquote>
  
  <p>So I made some attempts with it, but none worked out. I tried these : </p>
  
  <p>Attempt 1 : </p>
  
  <pre><code>&lt;script&gt;
      var $wpName = &lt;?php echo get_user('displayname') ?&gt;;
      var $wpEmail = &lt;?php echo get_user('email') ?&gt;;
  
      zE(function() {
          zE.identify({
              name: $wpName,
              email: $wpEmail
          });
  
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>Attempt 2 : </p>
  
  <pre><code>&lt;script&gt;
      zE(function() {
          zE.identify({
              name: &lt;?php echo get_user('displayname') ?&gt;,
              email: &lt;?php echo get_user('email') ?&gt;
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>Attempt 3 : </p>
  
  <pre><code>&lt;script&gt;
      var $wpName = $current_user-&gt;user_firstname;
      var $wpEmail = $current_user-&gt;user_email;
  
      zE(function() {
          zE.identify({
              name: &lt;?php echo get_user('displayname') ?&gt;,
              email: &lt;?php echo get_user('email') ?&gt;
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>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>
  
  <p>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 !</p>