I have developed a wordpress plugin that inserts a JS script in the head of every page of the site. I am trying to pass a couple variables to the script (in PHP) such as the name, the email, and the website of the author of the comment, when there's a comment.
I have tried to use the get_comment_author(), get_comment_author_url() and get_comment_author_email() but it always returns "Anonymous", even if I just entered a name, website and mail adress when posting a comment.
Here is the code:
add_action('wp_head', 'insert_script');
function insert_script(){
$name = get_comment_author();
$website = get_comment_author_url();
$email = get_comment_author_email();
echo " <script type='text/javascript'>
var _gigo= _gigo || {};
_gigo['firstname'] = '' ;
_gigo['lastname'] = '".$name."' ;
_gigo['company'] = '".$website."' ;
_gigo['email'] = '".$email."' ;
</script>";
}
Do you know why the functions return an anonymous author and how I could fix it ? Thanks in advance.